1 From bded570432d7017c47882758b037e77f1ec8e79e Mon Sep 17 00:00:00 2001
2 From: William Jon McCann <william.jon.mccann@gmail.com>
3 Date: Sun, 27 Sep 2009 06:37:26 -0700
4 Subject: [PATCH] udev-acl: catch up with ConsoleKit 0.4.1
9 extras/udev-acl/udev-acl.c | 204 +++++++++++++++++++++++++++++++++-----------
10 3 files changed, 160 insertions(+), 51 deletions(-)
12 diff --git a/Makefile.am b/Makefile.am
13 index 846152d..af321d8 100644
16 @@ -422,8 +422,8 @@ dist_udevrules_DATA += extras/udev-acl/70-acl.rules
17 libexec_PROGRAMS += extras/udev-acl/udev-acl
20 - mkdir -p $(DESTDIR)$(prefix)/lib/ConsoleKit/run-session.d
21 - ln -sf $(libexecdir)/udev-acl $(DESTDIR)$(prefix)/lib/ConsoleKit/run-session.d/udev-acl.ck
22 + mkdir -p $(DESTDIR)$(prefix)/lib/ConsoleKit/run-seat.d
23 + ln -sf $(libexecdir)/udev-acl $(DESTDIR)$(prefix)/lib/ConsoleKit/run-seat.d/udev-acl.ck
25 INSTALL_EXEC_HOOKS += udevacl-install-hook
27 diff --git a/NEWS b/NEWS
28 index 8019bb1..27b778f 100644
31 @@ -24,6 +24,9 @@ be added to the compat rules file.
32 Symlinks to udevadm with the old command names are no longer resolved to
35 +The udev-acl tool got adopted to changes in ConsoleKit. Version 0.4.11 is
41 diff --git a/extras/udev-acl/udev-acl.c b/extras/udev-acl/udev-acl.c
42 index 3eb29fe..e670ce7 100644
43 --- a/extras/udev-acl/udev-acl.c
44 +++ b/extras/udev-acl/udev-acl.c
56 static int set_facl(const char* filename, uid_t uid, int add)
59 @@ -152,44 +159,123 @@ static GSList *uids_with_local_active_session(const char *own_id)
62 /* ConsoleKit calls us with special variables */
63 -static int consolekit_called(const char *action, uid_t *uid, const char **own_session, int *add)
64 +static int consolekit_called(const char *ck_action, uid_t *uid, uid_t *uid2, const char **remove_session_id, int *action)
68 + int a = ACTION_NONE;
72 - const char *session;
74 - if (action == NULL || strcmp(action, "session_active_changed") != 0)
77 + const char *old_session = NULL;
79 - s = getenv("CK_SESSION_IS_LOCAL");
81 + if (ck_action == NULL || strcmp(ck_action, "seat_active_session_changed") != 0)
83 - if (strcmp(s, "true") != 0)
86 - s = getenv("CK_SESSION_IS_ACTIVE");
88 + /* We can have one of: remove, add, change, no-change */
89 + s = getenv("CK_SEAT_OLD_SESSION_ID");
90 + s2 = getenv("CK_SEAT_SESSION_ID");
91 + if (s == NULL && s2 == NULL) {
93 - if (strcmp(s, "true") == 0)
97 + } else if (s2 == NULL) {
99 + } else if (s == NULL) {
105 - session = getenv("CK_SESSION_ID");
106 - if (session == NULL)
110 + s = getenv("CK_SEAT_SESSION_USER_UID");
113 + u = strtoul(s, NULL, 10);
117 + s = getenv("CK_SEAT_SESSION_IS_LOCAL");
120 + if (strcmp(s, "true") != 0)
124 + case ACTION_REMOVE:
125 + s = getenv("CK_SEAT_OLD_SESSION_USER_UID");
128 + u = strtoul(s, NULL, 10);
132 + s = getenv("CK_SEAT_OLD_SESSION_IS_LOCAL");
135 + if (strcmp(s, "true") != 0)
138 + old_session = getenv("CK_SEAT_OLD_SESSION_ID");
139 + if (old_session == NULL)
143 + case ACTION_CHANGE:
144 + s = getenv("CK_SEAT_OLD_SESSION_USER_UID");
147 + u = strtoul(s, NULL, 10);
150 + s = getenv("CK_SEAT_SESSION_USER_UID");
153 + u2 = strtoul(s, NULL, 10);
157 + s = getenv("CK_SEAT_OLD_SESSION_IS_LOCAL");
158 + s2 = getenv("CK_SEAT_SESSION_IS_LOCAL");
159 + if (s == NULL || s2 == NULL)
161 + /* don't process non-local session changes */
162 + if (strcmp(s, "true") != 0 && strcmp(s2, "true") != 0)
165 + if (strcmp(s, "true") == 0 && strcmp(s, "true") == 0) {
166 + /* process the change */
168 + /* special case: we noop if we are
169 + * changing between local sessions for
173 + old_session = getenv("CK_SEAT_OLD_SESSION_ID");
174 + if (old_session == NULL)
176 + } else if (strcmp(s, "true") == 0) {
177 + /* only process the removal */
179 + old_session = getenv("CK_SEAT_OLD_SESSION_ID");
180 + if (old_session == NULL)
182 + } else if (strcmp(s2, "true") == 0) {
183 + /* only process the addition */
188 - s = getenv("CK_SESSION_USER_UID");
191 - u = strtoul(s, NULL, 10);
198 + g_assert_not_reached ();
202 - *own_session = session;
203 + *remove_session_id = old_session;
211 @@ -223,6 +309,21 @@ static void apply_acl_to_devices(uid_t uid, int add)
216 +remove_uid (uid_t uid, const char *remove_session_id)
219 + * Remove ACL for given uid from all matching devices
220 + * when there is currently no local active session.
224 + list = uids_with_local_active_session(remove_session_id);
225 + if (!uid_in_list(list, uid))
226 + apply_acl_to_devices(uid, 0);
227 + g_slist_free(list);
230 int main (int argc, char* argv[])
232 static const struct option options[] = {
233 @@ -233,10 +334,11 @@ int main (int argc, char* argv[])
234 { "help", no_argument, NULL, 'h' },
239 const char *device = NULL;
241 - const char* own_session = NULL;
243 + const char* remove_session_id = NULL;
246 /* valgrind is more important to us than a slice allocator */
247 @@ -252,9 +354,9 @@ int main (int argc, char* argv[])
250 if (strcmp(optarg, "add") == 0 || strcmp(optarg, "change") == 0)
252 + action = ACTION_ADD;
253 else if (strcmp(optarg, "remove") == 0)
255 + action = ACTION_REMOVE;
259 @@ -274,10 +376,10 @@ int main (int argc, char* argv[])
263 - if (add < 0 && device == NULL && uid == 0)
264 - consolekit_called(argv[optind], &uid, &own_session, &add);
265 + if (action < 0 && device == NULL && uid == 0)
266 + consolekit_called(argv[optind], &uid, &uid2, &remove_session_id, &action);
270 fprintf(stderr, "missing action\n\n");
273 @@ -290,20 +392,24 @@ int main (int argc, char* argv[])
280 /* Add ACL for given uid to all matching devices. */
281 apply_acl_to_devices(uid, 1);
284 - * Remove ACL for given uid from all matching devices
285 - * when there is currently no local active session.
289 - list = uids_with_local_active_session(own_session);
290 - if (!uid_in_list(list, uid))
291 - apply_acl_to_devices(uid, 0);
292 - g_slist_free(list);
294 + case ACTION_REMOVE:
295 + remove_uid(uid, remove_session_id);
297 + case ACTION_CHANGE:
298 + remove_uid(uid, remove_session_id);
299 + apply_acl_to_devices(uid2, 1);
305 + g_assert_not_reached();
308 } else if (device != NULL) {
310 @@ -321,8 +427,8 @@ int main (int argc, char* argv[])
313 u = GPOINTER_TO_UINT(l->data);
314 - if (add || !uid_in_list(list, u))
315 - set_facl(device, u, add);
316 + if (action == ACTION_ADD || !uid_in_list(list, u))
317 + set_facl(device, u, action == ACTION_ADD);