pax_global_header00006660000000000000000000000064121326113440014507gustar00rootroot0000000000000052 comment=34db65d21bf49d70acc2133e41bd2f39dca19c4e gnome-pkcs11-eventmgr-1.0/000075500000000000000000000000001213261134400153775ustar00rootroot00000000000000gnome-pkcs11-eventmgr-1.0/.gear/000075500000000000000000000000001213261134400163735ustar00rootroot00000000000000gnome-pkcs11-eventmgr-1.0/.gear/rules000064400000000000000000000000071213261134400174450ustar00rootroot00000000000000tar: . gnome-pkcs11-eventmgr-1.0/Makefile.am000064400000000000000000000000161213261134400174300ustar00rootroot00000000000000SUBDIRS = src gnome-pkcs11-eventmgr-1.0/configure.ac000064400000000000000000000006131213261134400176650ustar00rootroot00000000000000AC_INIT([GNOME PKCS11 Event Manager], [1.0], [raorn@altlinux.org]) AC_CONFIG_SRCDIR([src/main.c]) AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip]) AC_PREREQ(2.60) AC_PROG_CC PKG_CHECK_MODULES([GDK], [gdk-2.0]) PKG_CHECK_MODULES([GCONF], [gconf-2.0]) PKG_CHECK_MODULES([DBUS], [dbus-glib-1]) PKG_CHECK_MODULES([P11], [libp11]) AC_CONFIG_FILES([ Makefile src/Makefile ]) AC_OUTPUT gnome-pkcs11-eventmgr-1.0/gnome-pkcs11-eventmgr.spec000064400000000000000000000013021213261134400223010ustar00rootroot00000000000000# vim: set ft=spec: -*- rpm-spec -*- Name: gnome-pkcs11-eventmgr Version: 1.0 Release: alt1.qa1 Summary: Simple PKCS#11 event manager for GNOME Group: Graphical desktop/GNOME License: GPL Source: %name-%version.tar # Automatically added by buildreq on Wed Sep 09 2009 BuildRequires: libGConf-devel libdbus-glib-devel libgtk+2-devel libp11-devel %description Simple PKCS#11 event manager for GNOME. %prep %setup %build %autoreconf %configure %make_build %install %makeinstall_std %files %_bindir/* %changelog * Mon Apr 15 2013 Dmitry V. Levin (QA) 1.0-alt1.qa1 - NMU: rebuilt for debuginfo. * Wed Sep 09 2009 Alexey I. Froloff 1.0-alt1 - Initial build gnome-pkcs11-eventmgr-1.0/src/000075500000000000000000000000001213261134400161665ustar00rootroot00000000000000gnome-pkcs11-eventmgr-1.0/src/Makefile.am000064400000000000000000000006121213261134400202210ustar00rootroot00000000000000bin_PROGRAMS = gnome-pkcs11-eventmgr gnome_pkcs11_eventmgr_SOURCES = main.c \ panel-dbus-service.c \ panel-dbus-service.h \ panel-session-manager.c \ panel-session-manager.h \ panel-util.c \ panel-util.h gnome_pkcs11_eventmgr_CPPFLAGS = @GDK_CFLAGS@ @GCONF_CFLAGS@ @DBUS_CFLAGS@ @P11_CFLAGS@ gnome_pkcs11_eventmgr_LDADD = @GDK_LIBS@ @GCONF_LIBS@ @DBUS_LIBS@ @P11_LIBS@ gnome-pkcs11-eventmgr-1.0/src/main.c000064400000000000000000000116271213261134400172650ustar00rootroot00000000000000 #include #include #include #include #include #include #include "panel-dbus-service.h" #include "panel-session-manager.h" static GMainLoop *loop; static GConfClient *gconf; static PanelSessionManager *session; volatile guint poll_time; volatile guint logout_time; volatile guint poll_timeout = 0; volatile guint logout_timeout = 0; gchar *pkcs11_module; volatile PKCS11_CTX *pkcs11_ctx; volatile PKCS11_SLOT *pkcs11_slots; volatile int pkcs11_nslots; volatile gboolean module_loaded; volatile gboolean card_present; void pkcs11_free_slots() { if (pkcs11_ctx && pkcs11_slots) { PKCS11_release_all_slots(pkcs11_ctx, pkcs11_slots, pkcs11_nslots); pkcs11_slots = NULL; pkcs11_nslots = 0; } } int pkcs11_get_token() { pkcs11_free_slots(); if (PKCS11_enumerate_slots(pkcs11_ctx, &pkcs11_slots, &pkcs11_nslots) || pkcs11_slots == NULL || pkcs11_nslots == 0) { pkcs11_free_slots(); return -1; } if (PKCS11_find_token(pkcs11_ctx, pkcs11_slots, pkcs11_nslots) == NULL) return 0; return 1; } gboolean pkcs11_logout(gpointer data) { panel_session_manager_request_logout(session, PANEL_SESSION_MANAGER_LOGOUT_MODE_FORCE); g_main_loop_quit(loop); return FALSE; } void pkcs11_lock() { if (logout_timeout) g_source_remove(logout_timeout); logout_timeout = logout_time > 0 ? g_timeout_add(logout_time * 1000, pkcs11_logout, NULL) : 0; panel_lock_screen_action(gdk_screen_get_default(), "lock"); } void pkcs11_unlock() { if (logout_timeout) g_source_remove(logout_timeout); logout_timeout = 0; panel_lock_screen_action(gdk_screen_get_default(), "deactivate"); } gboolean pkcs11_poll(gpointer data) { int token_state; token_state = pkcs11_get_token(); switch((card_present ? 1000 : 0) + token_state) { case 0: /* not present, not available -> no change */ break; case 1001: /* card present, still available -> no change */ break; case 1000: /* card present, not available -> removed */ fprintf(stderr, "Card removed.\n"); PKCS11_CTX_unload(pkcs11_ctx); module_loaded = FALSE; if (PKCS11_CTX_load(pkcs11_ctx, pkcs11_module)) { g_main_loop_quit(loop); return FALSE; } module_loaded = TRUE; card_present = FALSE; pkcs11_lock(); break; case 1: /* not present, available -> inserted */ fprintf(stderr, "Card inserted.\n"); card_present = TRUE; pkcs11_unlock(); break; default: /* error */ g_main_loop_quit(loop); return FALSE; } return TRUE; } void pkcs11_gconf_notify(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data) { const char *key; const GConfValue *value; if (entry == NULL || (key = gconf_entry_get_key(entry)) == NULL) return; if (!strcmp(key, "/apps/pkcs11-eventmgr/poll_time")) { if ((value = gconf_entry_get_value(entry)) == NULL) return; poll_time = gconf_value_get_int(value); if (poll_timeout) g_source_remove(poll_timeout); poll_timeout = g_timeout_add(poll_time, pkcs11_poll, NULL); } else if (!strcmp(key, "/apps/pkcs11-eventmgr/logout_time")) { logout_time = gconf_value_get_int(value); } return; } int main(int argc, char *argv[]) { int ret=1; g_type_init(); gdk_init(&argc, &argv); if ((gconf = gconf_client_get_default()) == NULL) { fprintf(stderr, "GConf\n"); goto out; } if ((session = panel_session_manager_get()) == NULL) { fprintf(stderr, "Session\n"); goto out; } if ((loop = g_main_loop_new(NULL, FALSE)) == NULL) { fprintf(stderr, "MainLoop\n"); goto out; } poll_time = gconf_client_get_int(gconf, "/apps/pkcs11-eventmgr/poll_time", NULL); logout_time = gconf_client_get_int(gconf, "/apps/pkcs11-eventmgr/logout_time", NULL); pkcs11_module = gconf_client_get_string(gconf, "/apps/pkcs11-eventmgr/module", NULL); if (poll_time == 0) poll_time = 500; fprintf(stderr, "Startup with %d/%d/\"%s\"\n", poll_time, logout_time, pkcs11_module); if ((pkcs11_ctx = PKCS11_CTX_new()) == NULL) { fprintf(stderr, "PKCS#11 CTX\n"); goto out_mainloop; } module_loaded = FALSE; if (PKCS11_CTX_load(pkcs11_ctx, pkcs11_module)) { fprintf(stderr, "PKCS#11 Load\n"); goto out_pkcs11_ctx; } module_loaded = TRUE; if (PKCS11_enumerate_slots(pkcs11_ctx, &pkcs11_slots, &pkcs11_nslots) || pkcs11_slots == 0 || pkcs11_nslots == 0) { fprintf(stderr, "PKCS#11 Slots\n"); goto out_pkcs11_module; } if (PKCS11_find_token(pkcs11_ctx, pkcs11_slots, pkcs11_nslots) == NULL) { fprintf(stderr, "PKCS#11 Token\n"); goto out_pkcs11_slots; } card_present = TRUE; poll_timeout = g_timeout_add(poll_time, pkcs11_poll, NULL); gconf_client_notify_add(gconf, "/apps/pkcs11-eventmgr", pkcs11_gconf_notify, NULL, NULL, NULL); g_main_loop_run(loop); ret = 0; out_pkcs11_slots: pkcs11_free_slots(); out_pkcs11_module: if (module_loaded) PKCS11_CTX_unload(pkcs11_ctx); out_pkcs11_ctx: PKCS11_CTX_free(pkcs11_ctx); out_mainloop: g_main_loop_unref(loop); out: fprintf(stderr, "exit(%d)\n", ret); exit(ret); } gnome-pkcs11-eventmgr-1.0/src/panel-dbus-service.c000064400000000000000000000200171213261134400220220ustar00rootroot00000000000000/* * panel-dbus-service.c: a simple base object to use a DBus service. Only * useful when subclassed. * * Copyright (C) 2008 Novell, Inc. * * Based on code from panel-power-manager.c: * Copyright (C) 2006 Ray Strode * (not sure the copyright header was complete) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Authors: * Vincent Untz */ #include #include #include #include #include "panel-dbus-service.h" struct _PanelDBusServicePrivate { DBusGConnection *dbus_connection; DBusGProxy *bus_proxy; DBusGProxy *service_proxy; guint32 is_connected : 1; const char *service_name; const char *service_path; const char *service_interface; }; static void panel_dbus_service_finalize (GObject *object); static void panel_dbus_service_class_install_properties (PanelDBusServiceClass *service_class); static void panel_dbus_service_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); enum { PROP_0 = 0, PROP_IS_CONNECTED }; G_DEFINE_TYPE (PanelDBusService, panel_dbus_service, G_TYPE_OBJECT); static void panel_dbus_service_class_init (PanelDBusServiceClass *service_class) { GObjectClass *object_class; object_class = G_OBJECT_CLASS (service_class); object_class->finalize = panel_dbus_service_finalize; panel_dbus_service_class_install_properties (service_class); g_type_class_add_private (service_class, sizeof (PanelDBusServicePrivate)); } static void panel_dbus_service_class_install_properties (PanelDBusServiceClass *service_class) { GObjectClass *object_class; GParamSpec *param_spec; object_class = G_OBJECT_CLASS (service_class); object_class->get_property = panel_dbus_service_get_property; param_spec = g_param_spec_boolean ("is-connected", "Is connected", "Whether the panel is connected to " "a DBus service", FALSE, G_PARAM_READABLE); g_object_class_install_property (object_class, PROP_IS_CONNECTED, param_spec); } static void panel_dbus_service_init (PanelDBusService *service) { service->priv = G_TYPE_INSTANCE_GET_PRIVATE (service, PANEL_TYPE_DBUS_SERVICE, PanelDBusServicePrivate); service->priv->dbus_connection = NULL; service->priv->bus_proxy = NULL; service->priv->service_proxy = NULL; service->priv->is_connected = FALSE; service->priv->service_name = NULL; service->priv->service_path = NULL; service->priv->service_interface = NULL; } static void panel_dbus_service_finalize (GObject *object) { PanelDBusService *service; service = PANEL_DBUS_SERVICE (object); if (service->priv->dbus_connection != NULL) { dbus_g_connection_unref (service->priv->dbus_connection); service->priv->dbus_connection = NULL; } if (service->priv->bus_proxy != NULL) { g_object_unref (service->priv->bus_proxy); service->priv->bus_proxy = NULL; } if (service->priv->service_proxy != NULL) { g_object_unref (service->priv->service_proxy); service->priv->service_proxy = NULL; } G_OBJECT_CLASS (panel_dbus_service_parent_class)->finalize (object); } static void panel_dbus_service_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { PanelDBusService *service; service = PANEL_DBUS_SERVICE (object); switch (prop_id) { case PROP_IS_CONNECTED: g_value_set_boolean (value, service->priv->is_connected); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void panel_dbus_service_on_name_owner_changed (DBusGProxy *bus_proxy, const char *name, const char *prev_owner, const char *new_owner, PanelDBusService *service) { g_assert (service->priv->service_name != NULL); if (name && strcmp (name, service->priv->service_name) != 0) return; if (service->priv->service_proxy != NULL) { g_object_unref (service->priv->service_proxy); service->priv->service_proxy = NULL; } panel_dbus_service_ensure_connection (service, NULL); } gboolean panel_dbus_service_ensure_connection (PanelDBusService *service, GError **error) { GError *connection_error; gboolean is_connected; g_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE); if (!service->priv->service_name || !service->priv->service_path || !service->priv->service_interface) return FALSE; connection_error = NULL; if (service->priv->dbus_connection == NULL) { service->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &connection_error); if (service->priv->dbus_connection == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } } if (service->priv->bus_proxy == NULL) { service->priv->bus_proxy = dbus_g_proxy_new_for_name_owner (service->priv->dbus_connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &connection_error); if (service->priv->bus_proxy == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } dbus_g_proxy_add_signal (service->priv->bus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (service->priv->bus_proxy, "NameOwnerChanged", G_CALLBACK (panel_dbus_service_on_name_owner_changed), service, NULL); } if (service->priv->service_proxy == NULL) { service->priv->service_proxy = dbus_g_proxy_new_for_name_owner ( service->priv->dbus_connection, service->priv->service_name, service->priv->service_path, service->priv->service_interface, &connection_error); if (service->priv->service_proxy == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } } is_connected = TRUE; out: if (service->priv->is_connected != is_connected) { service->priv->is_connected = is_connected; g_object_notify (G_OBJECT (service), "is-connected"); } if (!is_connected) { if (service->priv->dbus_connection == NULL) { if (service->priv->bus_proxy != NULL) { g_object_unref (service->priv->bus_proxy); service->priv->bus_proxy = NULL; } if (service->priv->service_proxy != NULL) { g_object_unref (service->priv->service_proxy); service->priv->service_proxy = NULL; } } else if (service->priv->bus_proxy == NULL) { if (service->priv->service_proxy != NULL) { g_object_unref (service->priv->service_proxy); service->priv->service_proxy = NULL; } } } return is_connected; } void panel_dbus_service_define_service (PanelDBusService *service, const char *name, const char *path, const char *interface) { g_return_if_fail (PANEL_IS_DBUS_SERVICE (service)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (service->priv->service_name == NULL); g_assert (service->priv->service_path == NULL); g_assert (service->priv->service_interface == NULL); service->priv->service_name = name; service->priv->service_path = path; service->priv->service_interface = interface; } DBusGProxy * panel_dbus_service_get_proxy (PanelDBusService *service) { g_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), NULL); return service->priv->service_proxy; } gnome-pkcs11-eventmgr-1.0/src/panel-dbus-service.h000064400000000000000000000051141213261134400220300ustar00rootroot00000000000000/* * panel-dbus-service.h: a simple base object to use a DBus service. Only * useful when subclassed. * * Copyright (C) 2008 Novell, Inc. * * Based on code from panel-power-manager.h: * Copyright (C) 2006 Ray Strode * (not sure the copyright header was complete) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Authors: * Vincent Untz */ #ifndef PANEL_DBUS_SERVICE_H #define PANEL_DBUS_SERVICE_H #include #include G_BEGIN_DECLS #define PANEL_TYPE_DBUS_SERVICE (panel_dbus_service_get_type ()) #define PANEL_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_DBUS_SERVICE, PanelDBusService)) #define PANEL_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_DBUS_SERVICE, PanelDBusServiceClass)) #define PANEL_IS_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_DBUS_SERVICE)) #define PANEL_IS_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_DBUS_SERVICE)) #define PANEL_DBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_DBUS_SERVICE, PanelDBusServiceClass)) typedef struct _PanelDBusService PanelDBusService; typedef struct _PanelDBusServiceClass PanelDBusServiceClass; typedef struct _PanelDBusServicePrivate PanelDBusServicePrivate; struct _PanelDBusService { GObject parent; /*< private > */ PanelDBusServicePrivate *priv; }; struct _PanelDBusServiceClass { GObjectClass parent_class; }; GType panel_dbus_service_get_type (void); void panel_dbus_service_define_service (PanelDBusService *service, const char *name, const char *path, const char *interface); gboolean panel_dbus_service_ensure_connection (PanelDBusService *service, GError **error); DBusGProxy *panel_dbus_service_get_proxy (PanelDBusService *service); G_END_DECLS #endif /* PANEL_DBUS_SERVICE_H */ gnome-pkcs11-eventmgr-1.0/src/panel-session-manager.c000064400000000000000000000063001213261134400225210ustar00rootroot00000000000000/* * panel-session.c: * * Copyright (C) 2008 Novell, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Authors: * Vincent Untz */ #include #include "panel-dbus-service.h" #include "panel-session-manager.h" static GObject *panel_session_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties); G_DEFINE_TYPE (PanelSessionManager, panel_session_manager, PANEL_TYPE_DBUS_SERVICE); static void panel_session_manager_class_init (PanelSessionManagerClass *klass) { GObjectClass *object_class; object_class = G_OBJECT_CLASS (klass); object_class->constructor = panel_session_manager_constructor; } static void panel_session_manager_init (PanelSessionManager *manager) { } static GObject * panel_session_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GObject *obj; GError *error; obj = G_OBJECT_CLASS (panel_session_manager_parent_class)->constructor ( type, n_construct_properties, construct_properties); panel_dbus_service_define_service (PANEL_DBUS_SERVICE (obj), "org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager"); error = NULL; if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (obj), &error)) { g_message ("Could not connect to session manager: %s", error->message); g_error_free (error); } return obj; } void panel_session_manager_request_logout (PanelSessionManager *manager, PanelSessionManagerLogoutType mode) { GError *error; DBusGProxy *proxy; g_return_if_fail (PANEL_IS_SESSION_MANAGER (manager)); error = NULL; if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager), &error)) { g_warning ("Could not connect to session manager: %s", error->message); g_error_free (error); return; } proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager)); if (!dbus_g_proxy_call (proxy, "Logout", &error, G_TYPE_UINT, mode, G_TYPE_INVALID, G_TYPE_INVALID) && error != NULL) { g_warning ("Could not ask session manager to log out: %s", error->message); g_error_free (error); } } PanelSessionManager * panel_session_manager_get (void) { static PanelSessionManager *manager = NULL; if (manager == NULL) { manager = g_object_new (PANEL_TYPE_SESSION_MANAGER, NULL); } return manager; } gnome-pkcs11-eventmgr-1.0/src/panel-session-manager.h000064400000000000000000000046301213261134400225320ustar00rootroot00000000000000/* * panel-session.h: * * Copyright (C) 2008 Novell, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Authors: * Vincent Untz */ #ifndef PANEL_SESSION_MANAGER_H #define PANEL_SESSION_MANAGER_H #include #include "panel-dbus-service.h" G_BEGIN_DECLS #define PANEL_TYPE_SESSION_MANAGER (panel_session_manager_get_type ()) #define PANEL_SESSION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_SESSION_MANAGER, PanelSessionManager)) #define PANEL_SESSION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_SESSION_MANAGER, PanelSessionManagerClass)) #define PANEL_IS_SESSION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_SESSION_MANAGER)) #define PANEL_IS_SESSION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_SESSION_MANAGER)) #define PANEL_SESSION_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_SESSION_MANAGER, PanelSessionManagerClass)) typedef struct _PanelSessionManager PanelSessionManager; typedef struct _PanelSessionManagerClass PanelSessionManagerClass; struct _PanelSessionManager { PanelDBusService parent; }; struct _PanelSessionManagerClass { PanelDBusServiceClass parent_class; }; GType panel_session_manager_get_type (void); /* Keep in sync with the values defined in gnome-session/session.h */ typedef enum { PANEL_SESSION_MANAGER_LOGOUT_MODE_NORMAL = 0, PANEL_SESSION_MANAGER_LOGOUT_MODE_NO_CONFIRMATION, PANEL_SESSION_MANAGER_LOGOUT_MODE_FORCE } PanelSessionManagerLogoutType; PanelSessionManager *panel_session_manager_get (void); void panel_session_manager_request_logout (PanelSessionManager *session, PanelSessionManagerLogoutType mode); G_END_DECLS #endif /* PANEL_SESSION_MANAGER_H */ gnome-pkcs11-eventmgr-1.0/src/panel-util.c000064400000000000000000000041731213261134400204110ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * GNOME panel utils * (C) 1997, 1998, 1999, 2000 The Free Software Foundation * Copyright 2000 Helix Code, Inc. * Copyright 2000,2001 Eazel, Inc. * Copyright 2001 George Lebl * Copyright 2002 Sun Microsystems Inc. * * Authors: George Lebl * Jacob Berkman * Mark McLoughlin */ #include #include #include #include #include #include #include "panel-util.h" gboolean panel_is_program_in_path (const char *program) { char *tmp = g_find_program_in_path (program); if (tmp != NULL) { g_free (tmp); return TRUE; } else { return FALSE; } } static char * panel_lock_screen_action_get_command (const char *action) { char *command = NULL; gboolean use_gscreensaver = FALSE; if (panel_is_program_in_path ("gnome-screensaver-command") && panel_is_program_in_path ("gnome-screensaver-preferences")) use_gscreensaver = TRUE; else if (!panel_is_program_in_path ("xscreensaver-command")) return NULL; if (strcmp (action, "prefs") == 0) { if (use_gscreensaver) { command = g_strdup ("gnome-screensaver-preferences"); } else if (panel_is_program_in_path ("xscreensaver-demo")) { command = g_strdup ("xscreensaver-demo"); } else { command = NULL; } } else if (strcmp (action, "activate") == 0 || strcmp (action, "lock") == 0) { /* Neither gnome-screensaver or xscreensaver allow root * to lock the screen */ if (geteuid () == 0) { command = NULL; } else { if (use_gscreensaver) { command = g_strdup_printf ("gnome-screensaver-command --%s", action); } else { command = g_strdup_printf ("xscreensaver-command -%s", action); } } } return command; } void panel_lock_screen_action (GdkScreen *screen, const char *action) { char *command = NULL; g_return_if_fail (GDK_IS_SCREEN (screen)); g_return_if_fail (action != NULL); command = panel_lock_screen_action_get_command (action); if (!command) return; gdk_spawn_command_line_on_screen (screen, command, NULL); g_free (command); } gnome-pkcs11-eventmgr-1.0/src/panel-util.h000064400000000000000000000004241213261134400204110ustar00rootroot00000000000000#ifndef PANEL_UTIL_H #define PANEL_UTIL_H gboolean panel_is_program_in_path (const char *program); void panel_lock_screen_action (GdkScreen *screen, const char *action); #endif /* PANEL_UTIL_H */