<commit_before>#include "e.h"
#ifdef HAVE_PAM
# include <security/pam_appl.h>
# include <pwd.h>
#endif

#define E_DESKLOCK_STATE_DEFAULT  0
#define E_DESKLOCK_STATE_CHECKING 1
#define E_DESKLOCK_STATE_INVALID  2

#define ELOCK_POPUP_LAYER         10000
#define PASSWD_LEN                256

/**************************** private data ******************************/
typedef struct _E_Desklock_Data       E_Desklock_Data;
typedef struct _E_Desklock_Popup_Data E_Desklock_Popup_Data;
#ifdef HAVE_PAM
typedef struct _E_Desklock_Auth       E_Desklock_Auth;
#endif

typedef struct _E_Desklock_Run  E_Desklock_Run;

struct _E_Desklock_Popup_Data
{
   E_Popup     *popup_wnd;
   Evas_Object *bg_object;
   Evas_Object *login_box;
};

struct _E_Desklock_Data
{
   Eina_List     *elock_wnd_list;
   Ecore_X_Window elock_wnd;
   Eina_List     *handlers;
   Ecore_Event_Handler *move_handler;
   Ecore_X_Window elock_grab_break_wnd;
   char           passwd[PASSWD_LEN];
   int            state;
   Eina_Bool     selected : 1;
};

struct _E_Desklock_Run
{
   E_Order *desk_run;
   int position;
};

#ifdef HAVE_PAM
struct _E_Desklock_Auth
{
   struct
   {
      struct pam_conv conv;
      pam_handle_t   *handle;
   } pam;

   char user[4096];
   char passwd[4096];
};
#endif

static E_Desklock_Data *edd = NULL;
static E_Zone *last_active_zone = NULL;
#ifdef HAVE_PAM
static Ecore_Event_Handler *_e_desklock_exit_handler = NULL;
static pid_t _e_desklock_child_pid = -1;
#endif
static Ecore_Exe *_e_custom_desklock_exe = NULL;
static Ecore_Event_Handler *_e_custom_desklock_exe_handler = NULL;
static Ecore_Poller *_e_desklock_idle_poller = NULL;
static int _e_desklock_user_idle = 0;
static double _e_desklock_autolock_time = 0.0;
static E_Dialog *_e_desklock_ask_presentation_dia = NULL;
static int _e_desklock_ask_presentation_count = 0;

static Ecore_Event_Handler *_e_desklock_run_handler = NULL;
static Ecore_Job *job = NULL;
static Eina_List *tasks = NULL;


/***********************************************************************/

static Eina_Bool _e_desklock_cb_key_down(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_mouse_move(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_custom_desklock_exit(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_idle_poller(void *data);
static Eina_Bool _e_desklock_cb_window_stack(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_zone_add(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_zone_del(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_zone_move_resize(void *data, int type, void *event);

static Eina_Bool _e_desklock_cb_run(void *data, int type, void *event);

static void      _e_desklock_popup_free(E_Desklock_Popup_Data *edp);
static void      _e_desklock_popup_add(E_Zone *zone);
static void      _e_desklock_login_box_add(E_Desklock_Popup_Data *edp);
static void      _e_desklock_select(void);
static void      _e_desklock_unselect(void);
static void      _e_desklock_null(void);
static void      _e_desklock_passwd_update(void);
static void      _e_desklock_backspace(void);
static void      _e_desklock_delete(void);
static int       _e_desklock_zone_num_get(void);
static int       _e_desklock_check_auth(void);
static void      _e_desklock_state_set(int state);

static Eina_Bool _e_desklock_state = EINA_FALSE;
#ifdef HAVE_PAM
static Eina_Bool _e_desklock_cb_exit(void *data, int type, void *event);
static int       _desklock_auth(char *passwd);
static int       _desklock_pam_init(E_Desklock_Auth *da);
static int       _desklock_auth_pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
static char     *_desklock_auth_get_current_user(void);
static char     *_desklock_auth_get_current_host(void);
#endif

static void      _e_desklock_ask_presentation_mode(void);

EAPI int E_EVENT_DESKLOCK = 0;

EINTERN int
e_desklock_init(void)
{
   /* A poller to tick every 256 ticks, watching for an idle user */
   _e_desklock_idle_poller = ecore_poller_add(ECORE_POLLER_CORE, 256,
                                              _e_desklock_cb_idle_poller, NULL);

   if (e_config->desklock_background)
     e_filereg_register(e_config->desklock_background);

   E_EVENT_DESKLOCK = ecore_event_type_new();

   _e_desklock_run_handler = ecore_event_handler_add(E_EVENT_DESKLOCK,
						     _e_desklock_cb_run, NULL);

   return 1;
}

EINTERN int
e_desklock_shutdown(void)
{
   Eina_Bool waslocked = EINA_FALSE;
   E_Desklock_Run *task;

   if (edd) waslocked = EINA_TRUE;
   if (!x_fatal)
     e_desklock_hide();
   if (e_config->desklock_background)
     e_filereg_deregister(e_config->desklock_background);

   if (waslocked) e_util_env_set("E_DESKLOCK_LOCKED", "locked");

   ecore_event_handler_del(_e_desklock_run_handler);
   _e_desklock_run_handler = NULL;

   if (job) ecore_job_del(job);
   job = NULL;

   EINA_LIST_FREE(tasks, task)
     {
        e_object_del(E_OBJECT(task->desk_run));
        free(task);
     }

   return 1;
}

static const char *
_user_wallpaper_get(void)<commit_msg>register and unregister desklock backgrounds on init/shutdown<commit_after>#include "e.h"
#ifdef HAVE_PAM
# include <security/pam_appl.h>
# include <pwd.h>
#endif

#define E_DESKLOCK_STATE_DEFAULT  0
#define E_DESKLOCK_STATE_CHECKING 1
#define E_DESKLOCK_STATE_INVALID  2

#define ELOCK_POPUP_LAYER         10000
#define PASSWD_LEN                256

/**************************** private data ******************************/
typedef struct _E_Desklock_Data       E_Desklock_Data;
typedef struct _E_Desklock_Popup_Data E_Desklock_Popup_Data;
#ifdef HAVE_PAM
typedef struct _E_Desklock_Auth       E_Desklock_Auth;
#endif

typedef struct _E_Desklock_Run  E_Desklock_Run;

struct _E_Desklock_Popup_Data
{
   E_Popup     *popup_wnd;
   Evas_Object *bg_object;
   Evas_Object *login_box;
};

struct _E_Desklock_Data
{
   Eina_List     *elock_wnd_list;
   Ecore_X_Window elock_wnd;
   Eina_List     *handlers;
   Ecore_Event_Handler *move_handler;
   Ecore_X_Window elock_grab_break_wnd;
   char           passwd[PASSWD_LEN];
   int            state;
   Eina_Bool     selected : 1;
};

struct _E_Desklock_Run
{
   E_Order *desk_run;
   int position;
};

#ifdef HAVE_PAM
struct _E_Desklock_Auth
{
   struct
   {
      struct pam_conv conv;
      pam_handle_t   *handle;
   } pam;

   char user[4096];
   char passwd[4096];
};
#endif

static E_Desklock_Data *edd = NULL;
static E_Zone *last_active_zone = NULL;
#ifdef HAVE_PAM
static Ecore_Event_Handler *_e_desklock_exit_handler = NULL;
static pid_t _e_desklock_child_pid = -1;
#endif
static Ecore_Exe *_e_custom_desklock_exe = NULL;
static Ecore_Event_Handler *_e_custom_desklock_exe_handler = NULL;
static Ecore_Poller *_e_desklock_idle_poller = NULL;
static int _e_desklock_user_idle = 0;
static double _e_desklock_autolock_time = 0.0;
static E_Dialog *_e_desklock_ask_presentation_dia = NULL;
static int _e_desklock_ask_presentation_count = 0;

static Ecore_Event_Handler *_e_desklock_run_handler = NULL;
static Ecore_Job *job = NULL;
static Eina_List *tasks = NULL;


/***********************************************************************/

static Eina_Bool _e_desklock_cb_key_down(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_mouse_move(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_custom_desklock_exit(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_idle_poller(void *data);
static Eina_Bool _e_desklock_cb_window_stack(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_zone_add(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_zone_del(void *data, int type, void *event);
static Eina_Bool _e_desklock_cb_zone_move_resize(void *data, int type, void *event);

static Eina_Bool _e_desklock_cb_run(void *data, int type, void *event);

static void      _e_desklock_popup_free(E_Desklock_Popup_Data *edp);
static void      _e_desklock_popup_add(E_Zone *zone);
static void      _e_desklock_login_box_add(E_Desklock_Popup_Data *edp);
static void      _e_desklock_select(void);
static void      _e_desklock_unselect(void);
static void      _e_desklock_null(void);
static void      _e_desklock_passwd_update(void);
static void      _e_desklock_backspace(void);
static void      _e_desklock_delete(void);
static int       _e_desklock_zone_num_get(void);
static int       _e_desklock_check_auth(void);
static void      _e_desklock_state_set(int state);

static Eina_Bool _e_desklock_state = EINA_FALSE;
#ifdef HAVE_PAM
static Eina_Bool _e_desklock_cb_exit(void *data, int type, void *event);
static int       _desklock_auth(char *passwd);
static int       _desklock_pam_init(E_Desklock_Auth *da);
static int       _desklock_auth_pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
static char     *_desklock_auth_get_current_user(void);
static char     *_desklock_auth_get_current_host(void);
#endif

static void      _e_desklock_ask_presentation_mode(void);

EAPI int E_EVENT_DESKLOCK = 0;

EINTERN int
e_desklock_init(void)
{
   Eina_List *l;
   E_Config_Desklock_Background *bg;
   /* A poller to tick every 256 ticks, watching for an idle user */
   _e_desklock_idle_poller = ecore_poller_add(ECORE_POLLER_CORE, 256,
                                              _e_desklock_cb_idle_poller, NULL);

   if (e_config->desklock_background)
     e_filereg_register(e_config->desklock_background);
   EINA_LIST_FOREACH(e_config->desklock_backgrounds, l, bg)
     e_filereg_register(bg->file);

   E_EVENT_DESKLOCK = ecore_event_type_new();

   _e_desklock_run_handler = ecore_event_handler_add(E_EVENT_DESKLOCK,
						     _e_desklock_cb_run, NULL);

   return 1;
}

EINTERN int
e_desklock_shutdown(void)
{
   Eina_Bool waslocked = EINA_FALSE;
   E_Desklock_Run *task;
   Eina_List *l;
   E_Config_Desklock_Background *bg;

   if (edd) waslocked = EINA_TRUE;
   if (!x_fatal)
     e_desklock_hide();
   if (e_config->desklock_background)
     e_filereg_deregister(e_config->desklock_background);

   if (waslocked) e_util_env_set("E_DESKLOCK_LOCKED", "locked");

   ecore_event_handler_del(_e_desklock_run_handler);
   _e_desklock_run_handler = NULL;

   if (job) ecore_job_del(job);
   job = NULL;

   if (e_config->desklock_background)
     e_filereg_deregister(e_config->desklock_background);
   EINA_LIST_FOREACH(e_config->desklock_backgrounds, l, bg)
     e_filereg_deregister(bg->file);

   EINA_LIST_FREE(tasks, task)
     {
        e_object_del(E_OBJECT(task->desk_run));
        free(task);
     }

   return 1;
}

static const char *
_user_wallpaper_get(void)
{'fraction_non_alphanumeric': 0.09718191180601067, 'fraction_numerical': 0.006366445089411104, 'mean_word_length': 4.934444444444445, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079470', 'n_tokens_mistral': 4185, 'n_tokens_neox': 4055, 'n_words': 786}