2006-12-28 21:42:04 -08:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
2006-02-19 15:53:35 -08:00
|
|
|
#include "e.h"
|
2006-03-31 09:26:38 -08:00
|
|
|
#ifdef HAVE_PAM
|
2006-04-17 20:08:43 -07:00
|
|
|
# include <security/pam_appl.h>
|
|
|
|
# include <pwd.h>
|
|
|
|
# include <limits.h>
|
2006-03-31 09:26:38 -08:00
|
|
|
#endif
|
|
|
|
|
2006-02-19 15:53:35 -08:00
|
|
|
#define ELOCK_POPUP_LAYER 10000
|
|
|
|
#define PASSWD_LEN 256
|
|
|
|
|
2006-02-22 06:35:04 -08:00
|
|
|
/**************************** private data ******************************/
|
2006-02-26 13:42:19 -08:00
|
|
|
typedef struct _E_Desklock_Data E_Desklock_Data;
|
|
|
|
typedef struct _E_Desklock_Popup_Data E_Desklock_Popup_Data;
|
2006-04-17 20:14:29 -07:00
|
|
|
#ifdef HAVE_PAM
|
|
|
|
typedef struct _E_Desklock_Auth E_Desklock_Auth;
|
|
|
|
#endif
|
2006-02-19 15:53:35 -08:00
|
|
|
|
2006-02-26 13:42:19 -08:00
|
|
|
struct _E_Desklock_Popup_Data
|
|
|
|
{
|
2006-03-02 16:02:32 -08:00
|
|
|
E_Popup *popup_wnd;
|
|
|
|
Evas_Object *bg_object;
|
|
|
|
Evas_Object *login_box;
|
2006-02-26 13:42:19 -08:00
|
|
|
};
|
2006-02-22 06:35:04 -08:00
|
|
|
|
|
|
|
struct _E_Desklock_Data
|
|
|
|
{
|
2006-02-26 22:35:56 -08:00
|
|
|
Evas_List *elock_wnd_list;
|
|
|
|
Ecore_X_Window elock_wnd;
|
|
|
|
Evas_List *handlers;
|
2006-03-03 20:11:51 -08:00
|
|
|
Ecore_X_Window elock_grab_break_wnd;
|
2006-02-26 22:35:56 -08:00
|
|
|
char passwd[PASSWD_LEN];
|
2006-02-22 06:35:04 -08:00
|
|
|
};
|
2006-04-17 20:14:29 -07:00
|
|
|
#ifdef HAVE_PAM
|
|
|
|
struct _E_Desklock_Auth
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct pam_conv conv;
|
|
|
|
pam_handle_t *handle;
|
|
|
|
} pam;
|
|
|
|
|
|
|
|
char user[PATH_MAX];
|
|
|
|
char passwd[PATH_MAX];
|
|
|
|
};
|
|
|
|
#endif
|
2006-02-19 15:53:35 -08:00
|
|
|
|
2006-04-17 20:14:29 -07:00
|
|
|
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
|
2006-12-28 18:56:26 -08:00
|
|
|
static Ecore_Exe *_e_custom_saver_exe = NULL;
|
|
|
|
static Ecore_Event_Handler *_e_custom_saver_exe_handler = NULL;
|
2006-02-19 15:53:35 -08:00
|
|
|
|
2006-02-22 06:35:04 -08:00
|
|
|
/***********************************************************************/
|
|
|
|
|
2006-02-19 15:53:35 -08:00
|
|
|
static int _e_desklock_cb_key_down(void *data, int type, void *event);
|
|
|
|
static int _e_desklock_cb_mouse_down(void *data, int type, void *event);
|
|
|
|
static int _e_desklock_cb_mouse_up(void *data, int type, void *event);
|
|
|
|
static int _e_desklock_cb_mouse_wheel(void *data, int type, void *event);
|
2006-03-02 16:02:32 -08:00
|
|
|
static int _e_desklock_cb_mouse_move(void *data, int type, void *event);
|
2006-12-28 18:56:26 -08:00
|
|
|
static int _e_desklock_cb_custom_saver_exit(void *data, int type, void *event);
|
2006-02-19 15:53:35 -08:00
|
|
|
|
|
|
|
static void _e_desklock_passwd_update();
|
|
|
|
static void _e_desklock_backspace();
|
|
|
|
static void _e_desklock_delete();
|
2006-03-02 16:02:32 -08:00
|
|
|
static int _e_desklock_zone_num_get();
|
2006-02-19 15:53:35 -08:00
|
|
|
|
2006-03-31 09:26:38 -08:00
|
|
|
static int _e_desklock_check_auth();
|
|
|
|
|
2006-04-17 20:14:29 -07:00
|
|
|
#ifdef HAVE_PAM
|
|
|
|
static int _e_desklock_cb_exit(void *data, int type, void *event);
|
2006-08-21 09:00:43 -07:00
|
|
|
static int _desklock_auth(char *passwd);
|
2006-04-17 20:14:29 -07:00
|
|
|
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
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_desklock_init(void)
|
|
|
|
{
|
2006-12-28 18:56:26 -08:00
|
|
|
|
2006-04-17 20:14:29 -07:00
|
|
|
if (e_config->desklock_disable_screensaver)
|
|
|
|
ecore_x_screensaver_timeout_set(0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e_config->desklock_use_timeout)
|
2006-12-28 18:56:26 -08:00
|
|
|
ecore_x_screensaver_timeout_set(e_config->desklock_timeout);
|
2006-04-17 20:14:29 -07:00
|
|
|
}
|
2006-12-28 21:42:04 -08:00
|
|
|
|
2006-12-28 18:56:26 -08:00
|
|
|
/*
|
|
|
|
* Effectively hide the X screensaver yet allow
|
|
|
|
* it to generate the timer events for us.
|
|
|
|
*/
|
|
|
|
ecore_x_screensaver_blank_set(!e_config->desklock_use_custom_screensaver);
|
|
|
|
ecore_x_screensaver_expose_set(!e_config->desklock_use_custom_screensaver);
|
|
|
|
|
2006-10-20 19:32:14 -07:00
|
|
|
if (e_config->desklock_background)
|
2006-12-28 21:42:04 -08:00
|
|
|
e_filereg_register(e_config->desklock_background);
|
2006-12-28 18:56:26 -08:00
|
|
|
|
2006-04-17 20:14:29 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_desklock_shutdown(void)
|
|
|
|
{
|
|
|
|
e_desklock_hide();
|
2006-10-20 19:32:14 -07:00
|
|
|
if (e_config->desklock_background)
|
2006-12-28 21:42:04 -08:00
|
|
|
e_filereg_deregister(e_config->desklock_background);
|
2006-10-20 19:32:14 -07:00
|
|
|
|
2006-04-17 20:14:29 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-02-19 15:53:35 -08:00
|
|
|
EAPI int
|
|
|
|
e_desklock_show(void)
|
|
|
|
{
|
2006-03-02 16:02:32 -08:00
|
|
|
Evas_List *managers, *l, *l2, *l3;
|
|
|
|
E_Desklock_Popup_Data *edp;
|
|
|
|
Evas_Coord mw, mh;
|
|
|
|
E_Zone *current_zone;
|
|
|
|
int zone_counter;
|
|
|
|
int total_zone_num;
|
2006-12-28 18:56:26 -08:00
|
|
|
|
2006-02-26 22:35:56 -08:00
|
|
|
|
2006-12-28 18:56:26 -08:00
|
|
|
if (_e_custom_saver_exe) return 0;
|
|
|
|
|
|
|
|
if (e_config->desklock_use_custom_screensaver)
|
|
|
|
{
|
|
|
|
_e_custom_saver_exe_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
|
|
|
|
_e_desklock_cb_custom_saver_exit,
|
|
|
|
NULL);
|
|
|
|
e_util_library_path_strip();
|
|
|
|
_e_custom_saver_exe = ecore_exe_run(e_config->desklock_custom_screensaver_cmd, NULL);
|
|
|
|
e_util_library_path_restore();
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-02 22:00:18 -08:00
|
|
|
|
2006-12-28 18:56:26 -08:00
|
|
|
if (edd) return 0;
|
|
|
|
|
2006-03-31 09:26:38 -08:00
|
|
|
#ifdef HAVE_PAM
|
2006-04-17 20:08:43 -07:00
|
|
|
if (e_config->desklock_auth_method == 1)
|
2006-02-26 22:35:56 -08:00
|
|
|
{
|
2006-03-31 09:26:38 -08:00
|
|
|
#endif
|
|
|
|
if (!e_config->desklock_personal_passwd)
|
|
|
|
{
|
|
|
|
E_Zone *zone;
|
|
|
|
|
|
|
|
zone = e_util_zone_current_get(e_manager_current_get());
|
|
|
|
if (zone)
|
|
|
|
{
|
|
|
|
E_Config_Dialog *cfd;
|
|
|
|
|
|
|
|
cfd = e_int_config_desklock(zone->container);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#ifdef HAVE_PAM
|
2006-02-26 22:35:56 -08:00
|
|
|
}
|
2006-03-31 09:26:38 -08:00
|
|
|
#endif
|
2006-02-26 22:35:56 -08:00
|
|
|
|
2006-03-03 20:11:51 -08:00
|
|
|
edd = E_NEW(E_Desklock_Data, 1);
|
|
|
|
if (!edd) return 0;
|
|
|
|
edd->elock_wnd = ecore_x_window_input_new(e_manager_current_get()->root,
|
|
|
|
0, 0, 1, 1);
|
|
|
|
ecore_x_window_show(edd->elock_wnd);
|
|
|
|
managers = e_manager_list();
|
|
|
|
if (!e_grabinput_get(edd->elock_wnd, 0, edd->elock_wnd))
|
2006-02-26 22:35:56 -08:00
|
|
|
{
|
2006-03-03 20:11:51 -08:00
|
|
|
for (l = managers; l; l = l->next)
|
|
|
|
{
|
|
|
|
E_Manager *man;
|
|
|
|
Ecore_X_Window *windows;
|
|
|
|
int wnum;
|
|
|
|
|
|
|
|
man = l->data;
|
|
|
|
windows = ecore_x_window_children_get(man->root, &wnum);
|
|
|
|
if (windows)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < wnum; i++)
|
|
|
|
{
|
|
|
|
Ecore_X_Window_Attributes att;
|
2006-03-04 04:38:18 -08:00
|
|
|
memset(&att, 0, sizeof(Ecore_X_Window_Attributes));
|
2006-03-03 20:11:51 -08:00
|
|
|
|
|
|
|
ecore_x_window_attributes_get(windows[i], &att);
|
|
|
|
if (att.visible)
|
|
|
|
{
|
|
|
|
ecore_x_window_hide(windows[i]);
|
|
|
|
if (e_grabinput_get(edd->elock_wnd, 0, edd->elock_wnd))
|
|
|
|
{
|
|
|
|
edd->elock_grab_break_wnd = windows[i];
|
|
|
|
free(windows);
|
|
|
|
goto works;
|
|
|
|
}
|
|
|
|
ecore_x_window_show(windows[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(windows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* everything failed - cant lock */
|
|
|
|
e_util_dialog_show(_("Lock Failed"),
|
|
|
|
_("Locking the desktop failed because some application<br>"
|
2006-04-29 21:31:42 -07:00
|
|
|
"has grabbed either the keyboard or the mouse or both<br>"
|
2006-03-03 20:11:51 -08:00
|
|
|
"and their grab is unable to be broken."));
|
|
|
|
ecore_x_window_del(edd->elock_wnd);
|
|
|
|
free(edd);
|
|
|
|
edd = NULL;
|
|
|
|
return 0;
|
2006-02-26 22:35:56 -08:00
|
|
|
}
|
2006-03-03 20:11:51 -08:00
|
|
|
works:
|
|
|
|
|
2006-03-02 16:02:32 -08:00
|
|
|
last_active_zone = current_zone =
|
|
|
|
e_zone_current_get(e_container_current_get(e_manager_current_get()));
|
2006-02-26 22:35:56 -08:00
|
|
|
|
2006-03-02 16:02:32 -08:00
|
|
|
zone_counter = 0;
|
|
|
|
total_zone_num = _e_desklock_zone_num_get();
|
2006-02-26 22:35:56 -08:00
|
|
|
for (l = managers; l; l = l->next)
|
|
|
|
{
|
|
|
|
E_Manager *man;
|
|
|
|
|
|
|
|
man = l->data;
|
|
|
|
for (l2 = man->containers; l2; l2 = l2->next)
|
|
|
|
{
|
|
|
|
E_Container *con;
|
|
|
|
|
|
|
|
con = l2->data;
|
|
|
|
for (l3 = con->zones; l3; l3 = l3->next)
|
|
|
|
{
|
|
|
|
E_Zone *zone;
|
|
|
|
|
|
|
|
zone = l3->data;
|
|
|
|
edp = E_NEW(E_Desklock_Popup_Data, 1);
|
|
|
|
if (edp)
|
|
|
|
{
|
|
|
|
edp->popup_wnd = e_popup_new(zone, 0, 0, zone->w, zone->h);
|
|
|
|
evas_event_feed_mouse_move(edp->popup_wnd->evas, -1000000, -1000000,
|
|
|
|
ecore_x_current_time_get(), NULL);
|
|
|
|
|
|
|
|
e_popup_layer_set(edp->popup_wnd, ELOCK_POPUP_LAYER);
|
2006-03-03 20:11:51 -08:00
|
|
|
ecore_evas_raise(edp->popup_wnd->ecore_evas);
|
2006-02-26 22:35:56 -08:00
|
|
|
|
|
|
|
evas_event_freeze(edp->popup_wnd->evas);
|
|
|
|
edp->bg_object = edje_object_add(edp->popup_wnd->evas);
|
2006-03-02 16:02:32 -08:00
|
|
|
|
2006-03-02 22:00:18 -08:00
|
|
|
if ((!e_config->desklock_background) ||
|
|
|
|
(!strcmp(e_config->desklock_background, "theme_desklock_background")))
|
2006-03-02 16:02:32 -08:00
|
|
|
{
|
|
|
|
e_theme_edje_object_set(edp->bg_object,
|
|
|
|
"base/theme/desklock",
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desklock/background");
|
2006-03-02 16:02:32 -08:00
|
|
|
}
|
|
|
|
else if (!strcmp(e_config->desklock_background, "theme_background"))
|
|
|
|
{
|
2006-03-02 22:00:18 -08:00
|
|
|
e_theme_edje_object_set(edp->bg_object,
|
|
|
|
"base/theme/backgrounds",
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desktop/background");
|
2006-03-02 16:02:32 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e_util_edje_collection_exists(e_config->desklock_background,
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desklock/background"))
|
2006-03-02 16:02:32 -08:00
|
|
|
{
|
|
|
|
edje_object_file_set(edp->bg_object, e_config->desklock_background,
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desklock/background");
|
2006-03-02 16:02:32 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!edje_object_file_set(edp->bg_object,
|
|
|
|
e_config->desklock_background,
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desktop/background"))
|
2006-03-02 16:02:32 -08:00
|
|
|
{
|
|
|
|
edje_object_file_set(edp->bg_object,
|
|
|
|
e_theme_edje_file_get("base/theme/desklock",
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desklock/background"),
|
|
|
|
"e/desklock/background");
|
2006-03-02 16:02:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-26 22:35:56 -08:00
|
|
|
evas_object_move(edp->bg_object, 0, 0);
|
|
|
|
evas_object_resize(edp->bg_object, zone->w, zone->h);
|
|
|
|
evas_object_show(edp->bg_object);
|
2006-03-02 16:02:32 -08:00
|
|
|
edp->login_box = edje_object_add(edp->popup_wnd->evas);
|
|
|
|
e_theme_edje_object_set(edp->login_box,
|
2006-03-02 22:00:18 -08:00
|
|
|
"base/theme/desklock",
|
2006-08-22 20:39:02 -07:00
|
|
|
"e/desklock/login_box");
|
2006-08-22 00:39:11 -07:00
|
|
|
edje_object_part_text_set(edp->login_box, "e.text.title",
|
2006-03-02 22:00:18 -08:00
|
|
|
_("Please enter your unlock password"));
|
2006-08-22 00:39:11 -07:00
|
|
|
edje_object_part_swallow(edp->bg_object, "e.swallow.login_box", edp->login_box);
|
2006-03-02 16:02:32 -08:00
|
|
|
edje_object_size_min_calc(edp->login_box, &mw, &mh);
|
|
|
|
evas_object_move(edp->login_box, (int)((zone->w - mw)/2),
|
|
|
|
(int)((zone->h - mh)/2));
|
2006-04-17 20:08:43 -07:00
|
|
|
|
2006-03-02 16:02:32 -08:00
|
|
|
if (total_zone_num > 1)
|
2006-04-17 20:08:43 -07:00
|
|
|
{
|
|
|
|
if (e_config->desklock_login_box_zone == -1)
|
|
|
|
evas_object_show(edp->login_box);
|
|
|
|
else if(e_config->desklock_login_box_zone == -2 && zone == current_zone)
|
|
|
|
evas_object_show(edp->login_box);
|
|
|
|
else if(e_config->desklock_login_box_zone == zone_counter )
|
|
|
|
evas_object_show(edp->login_box);
|
|
|
|
}
|
2006-03-02 16:02:32 -08:00
|
|
|
else
|
|
|
|
evas_object_show(edp->login_box);
|
|
|
|
/**/
|
2006-02-26 22:35:56 -08:00
|
|
|
|
|
|
|
e_popup_edje_bg_object_set(edp->popup_wnd, edp->bg_object);
|
|
|
|
evas_event_thaw(edp->popup_wnd->evas);
|
|
|
|
|
|
|
|
e_popup_show(edp->popup_wnd);
|
|
|
|
|
|
|
|
edd->elock_wnd_list = evas_list_append(edd->elock_wnd_list, edp);
|
|
|
|
}
|
2006-03-02 16:02:32 -08:00
|
|
|
|
2006-12-28 21:42:04 -08:00
|
|
|
zone_counter++;
|
2006-02-26 22:35:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handlers */
|
|
|
|
edd->handlers = evas_list_append(edd->handlers,
|
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_KEY_DOWN,
|
|
|
|
_e_desklock_cb_key_down, NULL));
|
|
|
|
edd->handlers = evas_list_append(edd->handlers,
|
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_MOUSE_BUTTON_DOWN,
|
|
|
|
_e_desklock_cb_mouse_down, NULL));
|
|
|
|
edd->handlers = evas_list_append(edd->handlers,
|
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_MOUSE_BUTTON_UP,
|
|
|
|
_e_desklock_cb_mouse_up, NULL));
|
|
|
|
edd->handlers = evas_list_append(edd->handlers,
|
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_MOUSE_WHEEL,
|
|
|
|
_e_desklock_cb_mouse_wheel,
|
|
|
|
NULL));
|
2006-03-02 16:02:32 -08:00
|
|
|
if (total_zone_num > 1 && e_config->desklock_login_box_zone == -2 )
|
|
|
|
edd->handlers = evas_list_append(edd->handlers,
|
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_MOUSE_MOVE,
|
|
|
|
_e_desklock_cb_mouse_move,
|
|
|
|
NULL));
|
2006-02-26 22:35:56 -08:00
|
|
|
_e_desklock_passwd_update();
|
|
|
|
return 1;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
e_desklock_hide(void)
|
|
|
|
{
|
2006-02-26 22:35:56 -08:00
|
|
|
E_Desklock_Popup_Data *edp;
|
|
|
|
|
2006-12-28 18:56:26 -08:00
|
|
|
if ((!edd) && (!_e_custom_saver_exe)) return;
|
2006-03-03 20:11:51 -08:00
|
|
|
|
2006-12-28 18:56:26 -08:00
|
|
|
if (e_config->desklock_use_custom_screensaver)
|
2006-12-28 21:42:04 -08:00
|
|
|
{
|
|
|
|
_e_custom_saver_exe = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2006-12-28 18:56:26 -08:00
|
|
|
|
2006-03-03 20:11:51 -08:00
|
|
|
if (edd->elock_grab_break_wnd)
|
|
|
|
ecore_x_window_show(edd->elock_grab_break_wnd);
|
2006-02-26 22:35:56 -08:00
|
|
|
while (edd->elock_wnd_list)
|
|
|
|
{
|
|
|
|
edp = edd->elock_wnd_list->data;
|
|
|
|
if (edp)
|
|
|
|
{
|
|
|
|
e_popup_hide(edp->popup_wnd);
|
|
|
|
|
|
|
|
evas_event_freeze(edp->popup_wnd->evas);
|
|
|
|
evas_object_del(edp->bg_object);
|
2006-03-02 16:02:32 -08:00
|
|
|
evas_object_del(edp->login_box);
|
2006-02-26 22:35:56 -08:00
|
|
|
evas_event_thaw(edp->popup_wnd->evas);
|
|
|
|
|
|
|
|
e_object_del(E_OBJECT(edp->popup_wnd));
|
|
|
|
E_FREE(edp);
|
|
|
|
}
|
|
|
|
edd->elock_wnd_list = evas_list_remove_list(edd->elock_wnd_list, edd->elock_wnd_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (edd->handlers)
|
|
|
|
{
|
|
|
|
ecore_event_handler_del(edd->handlers->data);
|
|
|
|
edd->handlers = evas_list_remove_list(edd->handlers, edd->handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
e_grabinput_release(edd->elock_wnd, edd->elock_wnd);
|
|
|
|
ecore_x_window_del(edd->elock_wnd);
|
|
|
|
|
|
|
|
E_FREE(edd);
|
|
|
|
edd = NULL;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_e_desklock_cb_key_down(void *data, int type, void *event)
|
|
|
|
{
|
2006-02-26 22:35:56 -08:00
|
|
|
Ecore_X_Event_Key_Down *ev;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
if (ev->win != edd->elock_wnd) return 1;
|
|
|
|
|
|
|
|
if (!strcmp(ev->keysymbol, "Escape"))
|
2006-02-19 15:53:35 -08:00
|
|
|
;
|
2006-02-26 22:35:56 -08:00
|
|
|
else if (!strcmp(ev->keysymbol, "KP_Enter"))
|
2006-04-17 20:08:43 -07:00
|
|
|
_e_desklock_check_auth();
|
2006-02-26 22:35:56 -08:00
|
|
|
else if (!strcmp(ev->keysymbol, "Return"))
|
2006-04-17 20:08:43 -07:00
|
|
|
_e_desklock_check_auth();
|
2006-02-26 22:35:56 -08:00
|
|
|
else if (!strcmp(ev->keysymbol, "BackSpace"))
|
|
|
|
_e_desklock_backspace();
|
|
|
|
else if (!strcmp(ev->keysymbol, "Delete"))
|
|
|
|
_e_desklock_delete();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// here we have to grab a password
|
|
|
|
if (ev->key_compose)
|
|
|
|
{
|
|
|
|
if ((strlen(edd->passwd) < (PASSWD_LEN - strlen(ev->key_compose))))
|
|
|
|
{
|
|
|
|
strcat(edd->passwd, ev->key_compose);
|
|
|
|
_e_desklock_passwd_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_e_desklock_cb_mouse_down(void *data, int type, void *event)
|
|
|
|
{
|
2006-02-26 22:35:56 -08:00
|
|
|
return 1;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
2006-04-17 20:08:43 -07:00
|
|
|
|
2006-02-19 15:53:35 -08:00
|
|
|
static int
|
|
|
|
_e_desklock_cb_mouse_up(void *data, int type, void *event)
|
|
|
|
{
|
2006-02-26 22:35:56 -08:00
|
|
|
return 1;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
2006-04-17 20:08:43 -07:00
|
|
|
|
2006-02-19 15:53:35 -08:00
|
|
|
static int
|
|
|
|
_e_desklock_cb_mouse_wheel(void *data, int type, void *event)
|
|
|
|
{
|
2006-02-26 22:35:56 -08:00
|
|
|
return 1;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
2006-03-02 16:02:32 -08:00
|
|
|
|
|
|
|
static int
|
2006-04-17 20:08:43 -07:00
|
|
|
_e_desklock_cb_mouse_move(void *data, int type, void *event)
|
2006-02-19 15:53:35 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
E_Desklock_Popup_Data *edp;
|
|
|
|
E_Zone *current_zone;
|
|
|
|
Evas_List *l;
|
|
|
|
|
|
|
|
current_zone = e_zone_current_get(e_container_current_get(e_manager_current_get()));
|
|
|
|
|
|
|
|
if (current_zone == last_active_zone)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (l = edd->elock_wnd_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
edp = l->data;
|
|
|
|
|
|
|
|
if (!edp) continue;
|
|
|
|
|
|
|
|
if (edp->popup_wnd->zone == last_active_zone)
|
|
|
|
evas_object_hide(edp->login_box);
|
|
|
|
else if (edp->popup_wnd->zone == current_zone)
|
|
|
|
evas_object_show(edp->login_box);
|
|
|
|
}
|
|
|
|
last_active_zone = current_zone;
|
2006-02-26 22:35:56 -08:00
|
|
|
return 1;
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_desklock_passwd_update()
|
|
|
|
{
|
2006-07-31 21:14:34 -07:00
|
|
|
char passwd_hidden[PASSWD_LEN] = "", *p, *pp;
|
2006-02-26 22:35:56 -08:00
|
|
|
E_Desklock_Popup_Data *edp;
|
|
|
|
Evas_List *l;
|
|
|
|
|
|
|
|
if (!edd) return;
|
|
|
|
|
2006-07-31 21:14:34 -07:00
|
|
|
for (p = edd->passwd, pp = passwd_hidden; *p; p++, pp++) *pp = '*';
|
|
|
|
*pp = 0;
|
2006-02-26 22:35:56 -08:00
|
|
|
|
|
|
|
for (l = edd->elock_wnd_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
edp = l->data;
|
2006-08-22 00:39:11 -07:00
|
|
|
edje_object_part_text_set(edp->login_box, "e.text.password", passwd_hidden);
|
2006-02-26 22:35:56 -08:00
|
|
|
}
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_desklock_backspace()
|
|
|
|
{
|
2006-07-31 21:14:34 -07:00
|
|
|
int len, val, pos;
|
|
|
|
|
|
|
|
if (!edd) return;
|
2006-02-26 22:35:56 -08:00
|
|
|
|
|
|
|
len = strlen(edd->passwd);
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
pos = evas_string_char_prev_get(edd->passwd, len, &val);
|
|
|
|
if ((pos < len) && (pos >= 0))
|
|
|
|
{
|
|
|
|
edd->passwd[pos] = 0;
|
|
|
|
_e_desklock_passwd_update();
|
|
|
|
}
|
|
|
|
}
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
2006-02-26 22:35:56 -08:00
|
|
|
|
2006-02-19 15:53:35 -08:00
|
|
|
static void
|
|
|
|
_e_desklock_delete()
|
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
_e_desklock_backspace();
|
2006-02-19 15:53:35 -08:00
|
|
|
}
|
2006-02-26 13:42:19 -08:00
|
|
|
|
2006-03-02 16:02:32 -08:00
|
|
|
static int
|
|
|
|
_e_desklock_zone_num_get()
|
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
int num;
|
|
|
|
Evas_List *l, *l2;
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
for (l = e_manager_list(); l; l = l->next)
|
|
|
|
{
|
|
|
|
E_Manager *man = l->data;
|
|
|
|
|
|
|
|
for (l2 = man->containers; l2; l2 = l2->next)
|
|
|
|
{
|
|
|
|
E_Container *con = l2->data;
|
|
|
|
|
|
|
|
num += evas_list_count(con->zones);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
2006-03-02 16:02:32 -08:00
|
|
|
}
|
2006-02-26 13:42:19 -08:00
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
static int
|
|
|
|
_e_desklock_check_auth()
|
2006-03-31 09:26:38 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
if (!edd) return 0;
|
2006-03-31 09:26:38 -08:00
|
|
|
#ifdef HAVE_PAM
|
2006-04-17 20:08:43 -07:00
|
|
|
if (e_config->desklock_auth_method == 0)
|
|
|
|
return _desklock_auth(edd->passwd);
|
|
|
|
else if (e_config->desklock_auth_method == 1)
|
|
|
|
{
|
2006-04-17 20:14:29 -07:00
|
|
|
#endif
|
2006-04-17 20:08:43 -07:00
|
|
|
if ((e_config->desklock_personal_passwd) &&
|
|
|
|
(!strcmp(edd->passwd == NULL ? "" : edd->passwd,
|
|
|
|
e_config->desklock_personal_passwd == NULL ? "" :
|
|
|
|
e_config->desklock_personal_passwd)))
|
|
|
|
{
|
2006-04-17 20:14:29 -07:00
|
|
|
/* password ok */
|
2006-07-31 21:14:34 -07:00
|
|
|
/* security - null out passwd string once we are done with it */
|
2006-04-17 20:08:43 -07:00
|
|
|
memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
|
|
|
|
e_desklock_hide();
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-31 09:26:38 -08:00
|
|
|
#ifdef HAVE_PAM
|
2006-04-17 20:08:43 -07:00
|
|
|
}
|
2006-03-31 09:26:38 -08:00
|
|
|
#endif
|
2006-04-17 20:08:43 -07:00
|
|
|
/* passowrd is definitely wrong */
|
|
|
|
memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
|
|
|
|
_e_desklock_passwd_update();
|
|
|
|
return 0;
|
2006-03-31 09:26:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_PAM
|
2006-04-17 20:08:43 -07:00
|
|
|
static int
|
|
|
|
_e_desklock_cb_exit(void *data, int type, void *event)
|
2006-03-31 09:26:38 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
Ecore_Exe_Event_Del *ev;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
if (ev->pid == _e_desklock_child_pid)
|
|
|
|
{
|
|
|
|
_e_desklock_child_pid = -1;
|
|
|
|
/* ok */
|
|
|
|
if (ev->exit_code == 0)
|
|
|
|
{
|
2006-07-31 21:14:34 -07:00
|
|
|
/* security - null out passwd string once we are done with it */
|
2006-04-17 20:08:43 -07:00
|
|
|
memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
|
|
|
|
e_desklock_hide();
|
|
|
|
}
|
|
|
|
/* error */
|
|
|
|
else if (ev->exit_code < 128)
|
|
|
|
{
|
2006-07-31 21:14:34 -07:00
|
|
|
/* security - null out passwd string once we are done with it */
|
2006-04-17 20:08:43 -07:00
|
|
|
memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
|
|
|
|
e_desklock_hide();
|
|
|
|
e_util_dialog_show(_("Authentication System Error"),
|
|
|
|
_("Authentication via PAM had errors setting up the<br>"
|
|
|
|
"authentication session. The error code was <hilight>%i</hilight>.<br>"
|
|
|
|
"This is bad and should not be happening. Please report this bug.")
|
|
|
|
, ev->exit_code);
|
|
|
|
}
|
|
|
|
/* failed auth */
|
|
|
|
else
|
|
|
|
{
|
2006-07-31 21:14:34 -07:00
|
|
|
/* security - null out passwd string once we are done with it */
|
2006-04-17 20:08:43 -07:00
|
|
|
memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
|
|
|
|
_e_desklock_passwd_update();
|
|
|
|
}
|
|
|
|
ecore_event_handler_del(_e_desklock_exit_handler);
|
|
|
|
_e_desklock_exit_handler = NULL;
|
|
|
|
}
|
|
|
|
return 1;
|
2006-03-31 09:26:38 -08:00
|
|
|
}
|
2006-04-17 20:08:43 -07:00
|
|
|
|
|
|
|
static int
|
2006-08-21 09:00:43 -07:00
|
|
|
_desklock_auth(char *passwd)
|
2006-03-31 09:26:38 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
if ((_e_desklock_child_pid = fork()))
|
|
|
|
{
|
|
|
|
/* parent */
|
|
|
|
_e_desklock_exit_handler =
|
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _e_desklock_cb_exit,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* child */
|
|
|
|
int pamerr;
|
2006-04-17 20:14:29 -07:00
|
|
|
E_Desklock_Auth da;
|
2006-07-31 21:14:34 -07:00
|
|
|
char *current_user, *p;
|
2006-08-12 06:25:29 -07:00
|
|
|
struct sigaction action;
|
|
|
|
|
2006-08-15 13:20:33 -07:00
|
|
|
action.sa_handler = SIG_DFL;
|
2006-08-12 06:25:29 -07:00
|
|
|
action.sa_flags = SA_ONSTACK | SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
sigaction(SIGSEGV, &action, NULL);
|
|
|
|
sigaction(SIGILL, &action, NULL);
|
|
|
|
sigaction(SIGFPE, &action, NULL);
|
|
|
|
sigaction(SIGBUS, &action, NULL);
|
|
|
|
sigaction(SIGABRT, &action, NULL);
|
|
|
|
|
2006-07-10 12:33:00 -07:00
|
|
|
current_user = _desklock_auth_get_current_user();
|
2006-06-20 04:35:15 -07:00
|
|
|
strncpy(da.user, current_user, PATH_MAX);
|
2006-04-17 20:08:43 -07:00
|
|
|
strncpy(da.passwd, passwd, PATH_MAX);
|
2006-07-31 21:14:34 -07:00
|
|
|
/* security - null out passwd string once we are done with it */
|
2006-08-21 09:00:43 -07:00
|
|
|
for (p = passwd; *p; p++) *p = 0;
|
2006-04-17 20:08:43 -07:00
|
|
|
da.pam.handle = NULL;
|
|
|
|
da.pam.conv.conv = NULL;
|
|
|
|
da.pam.conv.appdata_ptr = NULL;
|
|
|
|
|
|
|
|
pamerr = _desklock_pam_init(&da);
|
2006-06-20 04:35:15 -07:00
|
|
|
if (pamerr != PAM_SUCCESS)
|
|
|
|
{
|
2006-07-27 23:45:00 -07:00
|
|
|
free(current_user);
|
|
|
|
exit(pamerr);
|
2006-06-20 04:35:15 -07:00
|
|
|
}
|
2006-04-17 20:08:43 -07:00
|
|
|
pamerr = pam_authenticate(da.pam.handle, 0);
|
|
|
|
pam_end(da.pam.handle, pamerr);
|
2006-07-31 21:14:34 -07:00
|
|
|
/* security - null out passwd string once we are done with it */
|
2006-04-17 20:08:43 -07:00
|
|
|
memset(da.passwd, 0, sizeof(da.passwd));
|
2006-06-20 04:35:15 -07:00
|
|
|
if (pamerr == PAM_SUCCESS)
|
|
|
|
{
|
2006-07-27 23:45:00 -07:00
|
|
|
free(current_user);
|
|
|
|
exit(0);
|
2006-06-20 04:35:15 -07:00
|
|
|
}
|
|
|
|
free(current_user);
|
2006-04-17 20:08:43 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
2006-06-08 12:11:54 -07:00
|
|
|
return 1;
|
2006-03-31 09:26:38 -08:00
|
|
|
}
|
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
static char *
|
|
|
|
_desklock_auth_get_current_user(void)
|
2006-03-31 09:26:38 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
char *user;
|
|
|
|
struct passwd *pwent = NULL;
|
2006-03-31 09:26:38 -08:00
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
pwent = getpwuid(getuid());
|
|
|
|
user = strdup(pwent->pw_name);
|
|
|
|
return user;
|
|
|
|
}
|
2006-03-31 09:26:38 -08:00
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
static int
|
2006-04-17 20:14:29 -07:00
|
|
|
_desklock_pam_init(E_Desklock_Auth *da)
|
2006-04-17 20:08:43 -07:00
|
|
|
{
|
|
|
|
int pamerr;
|
2006-08-12 06:25:29 -07:00
|
|
|
const char *pam_prof;
|
2006-06-20 04:35:15 -07:00
|
|
|
char *current_host;
|
|
|
|
char *current_user;
|
2006-04-17 20:08:43 -07:00
|
|
|
|
|
|
|
if (!da) return -1;
|
|
|
|
|
|
|
|
da->pam.conv.conv = _desklock_auth_pam_conv;
|
|
|
|
da->pam.conv.appdata_ptr = da;
|
|
|
|
da->pam.handle = NULL;
|
2006-08-12 06:25:29 -07:00
|
|
|
|
2006-09-19 02:59:03 -07:00
|
|
|
/* try other pam profiles - and system-auth (login for fbsd users) is a fallback */
|
2006-09-19 05:26:31 -07:00
|
|
|
pam_prof = "login";
|
2006-08-12 06:25:29 -07:00
|
|
|
if (ecore_file_exists("/etc/pam.d/enlightenment")) pam_prof = "enlightenment";
|
|
|
|
if (ecore_file_exists("/etc/pam.d/xscreensaver")) pam_prof = "xscreensaver";
|
|
|
|
if (ecore_file_exists("/etc/pam.d/kscreensaver")) pam_prof = "kscreensaver";
|
2006-09-19 05:26:31 -07:00
|
|
|
if (ecore_file_exists("/etc/pam.d/system-auth")) pam_prof = "system-auth";
|
2006-04-17 20:08:43 -07:00
|
|
|
|
2006-08-12 06:25:29 -07:00
|
|
|
if ((pamerr = pam_start(pam_prof, da->user, &(da->pam.conv),
|
2006-04-17 20:08:43 -07:00
|
|
|
&(da->pam.handle))) != PAM_SUCCESS)
|
|
|
|
return pamerr;
|
2006-06-20 04:35:15 -07:00
|
|
|
|
|
|
|
current_user = _desklock_auth_get_current_user();
|
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
if ((pamerr = pam_set_item(da->pam.handle, PAM_USER,
|
2006-06-20 04:35:15 -07:00
|
|
|
current_user)) != PAM_SUCCESS)
|
|
|
|
{
|
|
|
|
free(current_user);
|
|
|
|
return pamerr;
|
|
|
|
}
|
2006-04-17 20:08:43 -07:00
|
|
|
|
2006-06-20 04:35:15 -07:00
|
|
|
current_host = _desklock_auth_get_current_host();
|
2006-04-17 20:08:43 -07:00
|
|
|
if ((pamerr = pam_set_item(da->pam.handle, PAM_RHOST,
|
2006-06-20 04:35:15 -07:00
|
|
|
current_host)) != PAM_SUCCESS)
|
|
|
|
{
|
|
|
|
free(current_user);
|
|
|
|
free(current_host);
|
|
|
|
return pamerr;
|
|
|
|
}
|
2006-04-17 20:08:43 -07:00
|
|
|
|
2006-06-20 04:35:15 -07:00
|
|
|
free(current_user);
|
|
|
|
free(current_host);
|
2006-04-17 20:08:43 -07:00
|
|
|
return 0;
|
2006-03-31 09:26:38 -08:00
|
|
|
}
|
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
static int
|
|
|
|
_desklock_auth_pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
|
2006-03-31 09:26:38 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
int replies = 0;
|
2006-04-17 20:14:29 -07:00
|
|
|
E_Desklock_Auth *da = (E_Desklock_Auth *)appdata_ptr;
|
2006-04-17 20:08:43 -07:00
|
|
|
struct pam_response *reply = NULL;
|
|
|
|
|
|
|
|
reply = (struct pam_response *)malloc(sizeof(struct pam_response) *num_msg);
|
|
|
|
|
|
|
|
if (!reply)
|
|
|
|
return PAM_CONV_ERR;
|
|
|
|
|
|
|
|
for (replies = 0; replies < num_msg; replies++)
|
|
|
|
{
|
|
|
|
switch (msg[replies]->msg_style)
|
|
|
|
{
|
|
|
|
case PAM_PROMPT_ECHO_ON:
|
|
|
|
reply[replies].resp_retcode = PAM_SUCCESS;
|
2006-08-21 08:35:17 -07:00
|
|
|
reply[replies].resp = strdup(da->user);
|
2006-04-17 20:08:43 -07:00
|
|
|
break;
|
|
|
|
case PAM_PROMPT_ECHO_OFF:
|
|
|
|
reply[replies].resp_retcode = PAM_SUCCESS;
|
2006-08-21 08:35:17 -07:00
|
|
|
reply[replies].resp = strdup(da->passwd);
|
2006-04-17 20:08:43 -07:00
|
|
|
break;
|
|
|
|
case PAM_ERROR_MSG:
|
|
|
|
case PAM_TEXT_INFO:
|
|
|
|
reply[replies].resp_retcode = PAM_SUCCESS;
|
|
|
|
reply[replies].resp = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(reply);
|
|
|
|
return PAM_CONV_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*resp = reply;
|
|
|
|
return PAM_SUCCESS;
|
2006-03-31 09:26:38 -08:00
|
|
|
}
|
|
|
|
|
2006-04-17 20:08:43 -07:00
|
|
|
static char *
|
|
|
|
_desklock_auth_get_current_host(void)
|
2006-03-31 09:26:38 -08:00
|
|
|
{
|
2006-04-17 20:08:43 -07:00
|
|
|
return strdup("localhost");
|
2006-03-31 09:26:38 -08:00
|
|
|
}
|
|
|
|
#endif
|
2006-12-28 18:56:26 -08:00
|
|
|
|
|
|
|
static int
|
|
|
|
_e_desklock_cb_custom_saver_exit(void *data, int type, void *event)
|
|
|
|
{
|
|
|
|
Ecore_Exe_Event_Del *ev;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
if (ev->exe != _e_custom_saver_exe) return 1;
|
|
|
|
|
|
|
|
if (ev->exit_code != 0)
|
2006-12-28 21:42:04 -08:00
|
|
|
{
|
|
|
|
/* do something profound here... like notify someone */
|
|
|
|
}
|
2006-12-28 18:56:26 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Miserable HACK alert!!!
|
|
|
|
* Seems I must reset this. Some reason yet unknown, my
|
|
|
|
* intended values are getting reset!?!
|
|
|
|
*/
|
|
|
|
ecore_x_screensaver_timeout_set(e_config->desklock_timeout);
|
|
|
|
ecore_x_screensaver_blank_set(!e_config->desklock_use_custom_screensaver);
|
|
|
|
ecore_x_screensaver_expose_set(!e_config->desklock_use_custom_screensaver);
|
|
|
|
|
|
|
|
e_desklock_hide();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|