summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Hughart <mekius@mekius.net>2012-09-13 03:58:34 +0000
committerNicholas Hughart <mekius@mekius.net>2012-09-13 03:58:34 +0000
commitedaec8f53dd3dc9850cf2c0b6fcc4b91c6992c72 (patch)
tree31f87e4c4f5298dd0fe19d55369a8a2f316b963a
parent3a5fa5d356213d9007289559eb24023571af3492 (diff)
Handle ConsoleKit and systemd-login sessions.
The code to do this isn't beautiful, but I hope to be able to remove the ConsoleKit code eventually. ConsoleKit is deprecated and is slated to be replaced by systemd-login. The way the code is now, it will lookup sessions from both and attempt to register with each. It will only exit if both methods fail. I've added some extra debugging as well in case people run into issues still. I cannot test systemd-login sessions as my polkit is built to use ConsoleKit. SVN revision: 76573
-rw-r--r--ChangeLog5
-rw-r--r--configure.ac19
-rw-r--r--src/bin/Empower.h2
-rw-r--r--src/bin/Makefile.am7
-rw-r--r--src/bin/main.c12
-rw-r--r--src/bin/pka.c153
-rw-r--r--src/bin/pka.h12
7 files changed, 130 insertions, 80 deletions
diff --git a/ChangeLog b/ChangeLog
index d1fdce6..5d9b211 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,5 @@
17-21-12 -- Version 3.0.0 17-21-12 -- Version 2.0.999
2 - Empower is now a PolicyKit authentication agent. It maintains 2 - Empower is now a PolicyKit authentication agent.
3 the askpass support.
47-10-09 -- Version 2.0.0 37-10-09 -- Version 2.0.0
5 - Remove ETK version 4 - Remove ETK version
6 - Add Elementary version 5 - Add Elementary version
diff --git a/configure.ac b/configure.ac
index 2e48904..c980f09 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,9 +1,24 @@
1dnl Process this file with autoconf to produce a configure script. 1##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
2##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
3m4_define([v_maj], [2])
4m4_define([v_min], [0])
5m4_define([v_mic], [999])
6m4_define([v_rev], m4_esyscmd([(svnversion "${SVN_REPO_PATH:-.}" | grep -v '\(export\|Unversioned directory\)' || echo 0) | awk -F : '{printf("%s\n", $1);}' | tr -d ' :MSP\n']))
7m4_if(v_rev, [0], [m4_define([v_rev], m4_esyscmd([git log 2> /dev/null | (grep -m1 git-svn-id || echo 0) | sed -e 's/.*@\([0-9]*\).*/\1/' | tr -d '\n']))])
8##-- When released, remove the dnl on the below line
9dnl m4_undefine([v_rev])
10##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
11m4_ifdef([v_rev], [m4_define([v_ver], [v_maj.v_min.v_mic.v_rev])], [m4_define([v_ver], [v_maj.v_min.v_mic])])
12m4_define([lt_rev], m4_eval(v_maj + v_min))
13m4_define([lt_cur], v_mic)
14m4_define([lt_age], v_min)
15##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
16##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
2 17
3# get rid of that stupid cache mechanism 18# get rid of that stupid cache mechanism
4rm -f config.cache 19rm -f config.cache
5 20
6AC_INIT([empower], [3.0.0], [mekius@mekius.net]) 21AC_INIT([empower], [v_ver], [mekius@mekius.net])
7AC_PREREQ([2.52]) 22AC_PREREQ([2.52])
8AC_CONFIG_SRCDIR([configure.ac]) 23AC_CONFIG_SRCDIR([configure.ac])
9AC_CONFIG_MACRO_DIR([m4]) 24AC_CONFIG_MACRO_DIR([m4])
diff --git a/src/bin/Empower.h b/src/bin/Empower.h
index 774a9f1..fe1746a 100644
--- a/src/bin/Empower.h
+++ b/src/bin/Empower.h
@@ -97,6 +97,7 @@ struct _Empower_Auth_Info
97enum _Empower_Auth_State 97enum _Empower_Auth_State
98{ 98{
99 INVALID, 99 INVALID,
100 REGISTERING,
100 REGISTERED, 101 REGISTERED,
101 UNREGISTERED 102 UNREGISTERED
102}; 103};
@@ -109,5 +110,6 @@ int empower_log_domain;
109#define CRI(...) EINA_LOG_DOM_CRIT(empower_log_domain, __VA_ARGS__) 110#define CRI(...) EINA_LOG_DOM_CRIT(empower_log_domain, __VA_ARGS__)
110 111
111int empower_uid; 112int empower_uid;
113int empower_pid;
112 114
113#endif 115#endif
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 0034b77..c253153 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -2,17 +2,18 @@
2 2
3AM_CPPFLAGS = -I$(top_srcdir) \ 3AM_CPPFLAGS = -I$(top_srcdir) \
4 -DPACKAGE_BIN_DIR=\"$(bindir)\" \ 4 -DPACKAGE_BIN_DIR=\"$(bindir)\" \
5 -DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" 5 -DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" \
6 -Wall -Werror
6 7
7bin_PROGRAMS = empower 8bin_PROGRAMS = empower
8 9
9empower_SOURCES = main.c gui.c pka.c marshal.c 10empower_SOURCES = main.c gui.c pka.c marshal.c ckit.c logind.c
10 11
11empower_CFLAGS = @EMPOWER_CFLAGS@ 12empower_CFLAGS = @EMPOWER_CFLAGS@
12 13
13empower_LDADD = $(LTLIBINTL) \ 14empower_LDADD = $(LTLIBINTL) \
14 @EMPOWER_LIBS@ 15 @EMPOWER_LIBS@
15 16
16EXTRA_DIST = Empower.h gui.h pka.h marshal.h 17EXTRA_DIST = Empower.h gui.h pka.h marshal.h ckit.h logind.h
17 18
18MAINTAINERCLEANFILES = Makefile.in config.h.in 19MAINTAINERCLEANFILES = Makefile.in config.h.in
diff --git a/src/bin/main.c b/src/bin/main.c
index 5ed5cd1..561b565 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -13,6 +13,14 @@ int elm_main(int argc, char** argv)
13 bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR); 13 bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
14 textdomain(PACKAGE); 14 textdomain(PACKAGE);
15 15
16 // Grab UID of the process. This will be used to set
17 // the default user when the UI is first shown.
18 empower_uid = getuid();
19
20 // Grab PID of the process. This is used to retrieve
21 // the appropriate session ID.
22 empower_pid = getpid();
23
16 if(!eina_init()) 24 if(!eina_init())
17 { 25 {
18 printf(_("Unable to init Eina!")); 26 printf(_("Unable to init Eina!"));
@@ -55,10 +63,6 @@ int elm_main(int argc, char** argv)
55 // Allow use of svg icons 63 // Allow use of svg icons
56 efreet_icon_extension_add(".svg"); 64 efreet_icon_extension_add(".svg");
57 65
58 // Grab UID of the process. This will be used to set
59 // the default user when the UI is first shown.
60 empower_uid = getuid();
61
62 elm_run(); 66 elm_run();
63 67
64 elm_shutdown(); 68 elm_shutdown();
diff --git a/src/bin/pka.c b/src/bin/pka.c
index 708d7ff..7d7bea4 100644
--- a/src/bin/pka.c
+++ b/src/bin/pka.c
@@ -1,17 +1,30 @@
1#include "pka.h" 1#include "pka.h"
2#include "marshal.h" 2#include "marshal.h"
3#include "ckit.h"
4#include "logind.h"
5
6#define POLKIT_BUS "org.freedesktop.PolicyKit1"
7#define POLKIT_PATH "/org/freedesktop/PolicyKit1/Authority"
8#define POLKIT_INTERFACE "org.freedesktop.PolicyKit1.Authority"
9
10#define AGENT_BUS "auth.empower"
11#define AGENT_PATH "/auth/empower/Agent"
12#define AGENT_INTERFACE "org.freedesktop.PolicyKit1.AuthenticationAgent"
3 13
4static E_DBus_Connection *_pka_system_conn = NULL; 14static E_DBus_Connection *_pka_system_conn = NULL;
5static E_DBus_Object *_pka_system_obj = NULL; 15static E_DBus_Object *_pka_system_obj = NULL;
6static DBusPendingCall *_pka_register_call = NULL; 16static DBusPendingCall *_pka_register_call = NULL;
7static Eina_List *_pka_pending_auths = NULL; 17static Eina_List *_pka_pending_auths = NULL;
8const char *_pka_agent_path = AGENT_PATH; 18const char *_pka_agent_path = AGENT_PATH;
9const char *_pka_session_id = "";
10 19
11static Empower_Auth_State _pka_state; 20static Empower_Auth_State _pka_state;
12 21
22// Storage for any session ID's retrieved from consolekit/logind
23//const char *_pka_session_id = NULL;
24static const char *_pka_session_ids[2] = {NULL, NULL};
25static unsigned int _pka_session_idx = 0;
26
13// Method Call Callbacks 27// Method Call Callbacks
14static void _pka_session_id_done(void *data, DBusMessage *msg, DBusError *error);
15static void _pka_register_done(void *data, DBusMessage *msg, DBusError *error); 28static void _pka_register_done(void *data, DBusMessage *msg, DBusError *error);
16static void _pka_unregister_done(void *data, DBusMessage *msg, DBusError *error); 29static void _pka_unregister_done(void *data, DBusMessage *msg, DBusError *error);
17 30
@@ -19,15 +32,17 @@ static void _pka_unregister_done(void *data, DBusMessage *msg, DBu
19static DBusMessage *_pka_message_beginauthentication(E_DBus_Object *obj, DBusMessage *msg); 32static DBusMessage *_pka_message_beginauthentication(E_DBus_Object *obj, DBusMessage *msg);
20static DBusMessage *_pka_message_cancelauthentication(E_DBus_Object *obj, DBusMessage *msg); 33static DBusMessage *_pka_message_cancelauthentication(E_DBus_Object *obj, DBusMessage *msg);
21 34
22// Misc 35// Helper Callbacks
23static void _pka_beginauthentication_finish(Empower_Auth_Info *info);
24static Eina_Bool _pka_helper_stdout(void *data, int type, void *event); 36static Eina_Bool _pka_helper_stdout(void *data, int type, void *event);
25static Eina_Bool _pka_helper_stderr(void *data, int type, void *event); 37static Eina_Bool _pka_helper_stderr(void *data, int type, void *event);
26 38
39// Misc
40static void _pka_beginauthentication_finish(Empower_Auth_Info *info);
41static Eina_Bool _pka_session_idler(void *data);
42
27Eina_Bool pka_init() 43Eina_Bool pka_init()
28{ 44{
29 E_DBus_Interface *iface; 45 E_DBus_Interface *iface;
30 DBusMessage *msg;
31 46
32 _pka_state = INVALID; 47 _pka_state = INVALID;
33 48
@@ -74,14 +89,13 @@ Eina_Bool pka_init()
74 return EINA_FALSE; 89 return EINA_FALSE;
75 } 90 }
76 91
77 DBG("Getting session ID from ConsoleKit"); 92 // FIXME: Eventually ckit support can be dropped as it's deprecated. This
78 _pka_session_id = NULL; 93 // interface can then hopefully be simplified as we won't need to
79 msg = dbus_message_new_method_call(CONKIT_BUS, CONKIT_PATH, CONKIT_INTERFACE, "GetCurrentSession"); 94 // check for session ids from multiple places.
95 ckit_init(_pka_system_conn);
96 logind_init(_pka_system_conn);
80 97
81 if (!msg) 98 ecore_idle_enterer_add(_pka_session_idler, NULL);
82 return EINA_FALSE;
83
84 e_dbus_message_send(_pka_system_conn, msg, _pka_session_id_done, -1, NULL);
85 99
86 return EINA_TRUE; 100 return EINA_TRUE;
87} 101}
@@ -100,7 +114,7 @@ Eina_Bool pka_shutdown()
100 return EINA_FALSE; 114 return EINA_FALSE;
101 } 115 }
102 116
103 if (!_pka_session_id) 117 if (_pka_session_idx > (sizeof(_pka_session_ids)/sizeof(_pka_session_ids[0])))
104 return EINA_TRUE; 118 return EINA_TRUE;
105 119
106 msg = dbus_message_new_method_call(POLKIT_BUS, POLKIT_PATH, POLKIT_INTERFACE, "UnregisterAuthenticationAgent"); 120 msg = dbus_message_new_method_call(POLKIT_BUS, POLKIT_PATH, POLKIT_INTERFACE, "UnregisterAuthenticationAgent");
@@ -109,7 +123,7 @@ Eina_Bool pka_shutdown()
109 return EINA_FALSE; 123 return EINA_FALSE;
110 124
111 subject.kind = EMPOWER_SUBJECT_SESSION; 125 subject.kind = EMPOWER_SUBJECT_SESSION;
112 subject.details.session.id = _pka_session_id; 126 subject.details.session.id = _pka_session_ids[_pka_session_idx];
113 127
114 dbus_message_iter_init_append(msg, &itr); 128 dbus_message_iter_init_append(msg, &itr);
115 marshal_subject(&itr, &subject); 129 marshal_subject(&itr, &subject);
@@ -117,8 +131,6 @@ Eina_Bool pka_shutdown()
117 131
118 _pka_register_call = e_dbus_message_send(_pka_system_conn, msg, _pka_unregister_done, -1, NULL); 132 _pka_register_call = e_dbus_message_send(_pka_system_conn, msg, _pka_unregister_done, -1, NULL);
119 133
120 eina_stringshare_del(_pka_session_id);
121
122 return EINA_TRUE; 134 return EINA_TRUE;
123} 135}
124 136
@@ -173,52 +185,18 @@ pka_cancel(Empower_Auth_Info *info)
173 return EINA_FALSE; 185 return EINA_FALSE;
174} 186}
175 187
176static void _pka_session_id_done(void *data, DBusMessage *msg, DBusError *error)
177{
178 Empower_Subject subject;
179 const char *s;
180 DBusMessage *newmsg;
181 DBusMessageIter itr;
182
183 if (error->message)
184 {
185 ERR("Failed to get session ID (%s)", error->message);
186 }
187
188 dbus_message_iter_init(msg, &itr);
189 dbus_message_iter_get_basic(&itr, &s);
190 _pka_session_id = eina_stringshare_add(s);
191
192 DBG("Session Received: %s", _pka_session_id);
193
194 DBG("Attempting to register AuthenticationAgent");
195 newmsg = dbus_message_new_method_call(POLKIT_BUS, POLKIT_PATH, POLKIT_INTERFACE, "RegisterAuthenticationAgent");
196
197 if (!newmsg)
198 return;
199
200 subject.kind = EMPOWER_SUBJECT_SESSION;
201 subject.details.session.id = _pka_session_id;
202 s = eina_stringshare_add(setlocale(LC_CTYPE, NULL));
203
204 dbus_message_iter_init_append(newmsg, &itr);
205 marshal_subject(&itr, &subject);
206 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &s);
207 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &_pka_agent_path);
208
209 _pka_register_call = e_dbus_message_send(_pka_system_conn, newmsg, _pka_register_done, -1, NULL);
210
211 eina_stringshare_del(s);
212}
213
214static void _pka_register_done(void *data, DBusMessage *msg, DBusError *error) 188static void _pka_register_done(void *data, DBusMessage *msg, DBusError *error)
215{ 189{
216 _pka_register_call = NULL; 190 _pka_register_call = NULL;
217 191
218 if (error->message) 192 if (error->message)
219 { 193 {
220 ERR("Failed to register Authentication Agent (%s)", error->message); 194 ERR("Failed to register Autentication Agent with session '%s', (%s)", _pka_session_ids[_pka_session_idx], error->message);
221 _pka_state = UNREGISTERED; 195
196 // Try the next session ID just in case it was a session error.
197 _pka_session_idx++;
198 _pka_state = INVALID;
199
222 return; 200 return;
223 } 201 }
224 202
@@ -229,12 +207,20 @@ static void _pka_register_done(void *data, DBusMessage *msg, DBusError *error)
229 207
230static void _pka_unregister_done(void *data, DBusMessage *msg, DBusError *error) 208static void _pka_unregister_done(void *data, DBusMessage *msg, DBusError *error)
231{ 209{
210 unsigned int i;
211
232 e_dbus_object_free(_pka_system_obj); 212 e_dbus_object_free(_pka_system_obj);
233 e_dbus_connection_close(_pka_system_conn); 213 e_dbus_connection_close(_pka_system_conn);
234 free(_pka_system_conn); 214 free(_pka_system_conn);
235 215
236 e_dbus_shutdown(); 216 e_dbus_shutdown();
237 217
218 for (i = 0; i < (sizeof(_pka_session_ids)/sizeof(_pka_session_ids[0])); ++i)
219 {
220 if (_pka_session_ids[i])
221 eina_stringshare_del(_pka_session_ids[i]);
222 }
223
238 _pka_state = UNREGISTERED; 224 _pka_state = UNREGISTERED;
239} 225}
240 226
@@ -382,3 +368,58 @@ static Eina_Bool _pka_helper_stderr(void *data, int type, void *event)
382 DBG("HELPER ERR: %s", msg); 368 DBG("HELPER ERR: %s", msg);
383 return EINA_FALSE; 369 return EINA_FALSE;
384} 370}
371
372static Eina_Bool _pka_session_idler(void *data)
373{
374 Empower_Subject subject;
375 const char *s;
376 DBusMessage *newmsg;
377 DBusMessageIter itr;
378
379 // If we've registered then we can stop trying different session IDs.
380 if (_pka_state == REGISTERED)
381 return ECORE_CALLBACK_CANCEL;
382
383 // If we've run out of session IDs, throw an error and claim unregistered to
384 // cause Empower to exit.
385 if (_pka_session_idx >= (sizeof(_pka_session_ids)/sizeof(_pka_session_ids[0])))
386 {
387 ERR("Could not register Empower as an authentication agent");
388 _pka_state = UNREGISTERED;
389
390 return ECORE_CALLBACK_CANCEL;
391 }
392
393 _pka_session_ids[0] = ckit_session_get();
394 _pka_session_ids[1] = logind_session_get();
395
396 if ((_pka_state == INVALID) && (_pka_session_ids[_pka_session_idx] != NULL))
397 {
398 DBG("Attempting to register with session id %s", _pka_session_ids[_pka_session_idx]);
399 newmsg = dbus_message_new_method_call(POLKIT_BUS, POLKIT_PATH, POLKIT_INTERFACE, "RegisterAuthenticationAgent");
400
401 if (!newmsg)
402 {
403 ERR("Failed to allocate memory!");
404 return ECORE_CALLBACK_CANCEL;
405 }
406
407 subject.kind = EMPOWER_SUBJECT_SESSION;
408 subject.details.session.id = _pka_session_ids[_pka_session_idx];
409 s = eina_stringshare_add(setlocale(LC_CTYPE, NULL));
410
411 dbus_message_iter_init_append(newmsg, &itr);
412 marshal_subject(&itr, &subject);
413 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &s);
414 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &_pka_agent_path);
415
416 _pka_register_call = e_dbus_message_send(_pka_system_conn, newmsg, _pka_register_done, -1, NULL);
417
418 eina_stringshare_del(s);
419
420 _pka_state = REGISTERING;
421 }
422
423 return ECORE_CALLBACK_RENEW;
424}
425
diff --git a/src/bin/pka.h b/src/bin/pka.h
index 2bf5418..4b9a300 100644
--- a/src/bin/pka.h
+++ b/src/bin/pka.h
@@ -3,18 +3,6 @@
3 3
4#include "Empower.h" 4#include "Empower.h"
5 5
6#define CONKIT_BUS "org.freedesktop.ConsoleKit"
7#define CONKIT_PATH "/org/freedesktop/ConsoleKit/Manager"
8#define CONKIT_INTERFACE "org.freedesktop.ConsoleKit.Manager"
9
10#define POLKIT_BUS "org.freedesktop.PolicyKit1"
11#define POLKIT_PATH "/org/freedesktop/PolicyKit1/Authority"
12#define POLKIT_INTERFACE "org.freedesktop.PolicyKit1.Authority"
13
14#define AGENT_BUS "auth.empower"
15#define AGENT_PATH "/auth/empower/Agent"
16#define AGENT_INTERFACE "org.freedesktop.PolicyKit1.AuthenticationAgent"
17
18Eina_Bool pka_init(); 6Eina_Bool pka_init();
19Eina_Bool pka_shutdown(); 7Eina_Bool pka_shutdown();
20Empower_Auth_State pka_state(); 8Empower_Auth_State pka_state();