updated on Thu Jan 19 00:16:31 UTC 2012
[aur-mirror.git] / udev-acl / udev-acl.patch
blob49ec6694886ff0a4afb110ebd191531ba15f52c4
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
6 ---
7 Makefile.am | 4 +-
8 NEWS | 3 +
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
14 --- a/Makefile.am
15 +++ b/Makefile.am
16 @@ -422,8 +422,8 @@ dist_udevrules_DATA += extras/udev-acl/70-acl.rules
17 libexec_PROGRAMS += extras/udev-acl/udev-acl
19 udevacl-install-hook:
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
29 --- a/NEWS
30 +++ b/NEWS
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
33 the udevadm commands.
35 +The udev-acl tool got adopted to changes in ConsoleKit. Version 0.4.11 is
36 +required now.
38 udev 146
39 ========
40 Bugfixes.
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
45 @@ -29,6 +29,13 @@
47 static int debug;
49 +enum{
50 + ACTION_NONE = 0,
51 + ACTION_REMOVE,
52 + ACTION_ADD,
53 + ACTION_CHANGE
54 +};
56 static int set_facl(const char* filename, uid_t uid, int add)
58 int get;
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)
66 - int a;
67 - uid_t u;
68 + int a = ACTION_NONE;
69 + uid_t u = 0;
70 + uid_t u2 = 0;
71 const char *s;
72 - const char *session;
74 - if (action == NULL || strcmp(action, "session_active_changed") != 0)
75 - return -1;
76 + const char *s2;
77 + const char *old_session = NULL;
79 - s = getenv("CK_SESSION_IS_LOCAL");
80 - if (s == NULL)
81 + if (ck_action == NULL || strcmp(ck_action, "seat_active_session_changed") != 0)
82 return -1;
83 - if (strcmp(s, "true") != 0)
84 - return 0;
86 - s = getenv("CK_SESSION_IS_ACTIVE");
87 - if (s == NULL)
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) {
92 return -1;
93 - if (strcmp(s, "true") == 0)
94 - a = 1;
95 - else
96 - a = 0;
97 + } else if (s2 == NULL) {
98 + a = ACTION_REMOVE;
99 + } else if (s == NULL) {
100 + a = ACTION_ADD;
101 + } else {
102 + a = ACTION_CHANGE;
105 - session = getenv("CK_SESSION_ID");
106 - if (session == NULL)
107 - return -1;
108 + switch (a) {
109 + case ACTION_ADD:
110 + s = getenv("CK_SEAT_SESSION_USER_UID");
111 + if (s == NULL)
112 + return -1;
113 + u = strtoul(s, NULL, 10);
114 + if (u == 0)
115 + return 0;
117 + s = getenv("CK_SEAT_SESSION_IS_LOCAL");
118 + if (s == NULL)
119 + return -1;
120 + if (strcmp(s, "true") != 0)
121 + return 0;
123 + break;
124 + case ACTION_REMOVE:
125 + s = getenv("CK_SEAT_OLD_SESSION_USER_UID");
126 + if (s == NULL)
127 + return -1;
128 + u = strtoul(s, NULL, 10);
129 + if (u == 0)
130 + return 0;
132 + s = getenv("CK_SEAT_OLD_SESSION_IS_LOCAL");
133 + if (s == NULL)
134 + return -1;
135 + if (strcmp(s, "true") != 0)
136 + return 0;
138 + old_session = getenv("CK_SEAT_OLD_SESSION_ID");
139 + if (old_session == NULL)
140 + return -1;
142 + break;
143 + case ACTION_CHANGE:
144 + s = getenv("CK_SEAT_OLD_SESSION_USER_UID");
145 + if (s == NULL)
146 + return -1;
147 + u = strtoul(s, NULL, 10);
148 + if (u == 0)
149 + return 0;
150 + s = getenv("CK_SEAT_SESSION_USER_UID");
151 + if (s == NULL)
152 + return -1;
153 + u2 = strtoul(s, NULL, 10);
154 + if (u2 == 0)
155 + return 0;
157 + s = getenv("CK_SEAT_OLD_SESSION_IS_LOCAL");
158 + s2 = getenv("CK_SEAT_SESSION_IS_LOCAL");
159 + if (s == NULL || s2 == NULL)
160 + return -1;
161 + /* don't process non-local session changes */
162 + if (strcmp(s, "true") != 0 && strcmp(s2, "true") != 0)
163 + return 0;
165 + if (strcmp(s, "true") == 0 && strcmp(s, "true") == 0) {
166 + /* process the change */
167 + if (u == u2) {
168 + /* special case: we noop if we are
169 + * changing between local sessions for
170 + * the same uid */
171 + a = ACTION_NONE;
173 + old_session = getenv("CK_SEAT_OLD_SESSION_ID");
174 + if (old_session == NULL)
175 + return -1;
176 + } else if (strcmp(s, "true") == 0) {
177 + /* only process the removal */
178 + a = ACTION_REMOVE;
179 + old_session = getenv("CK_SEAT_OLD_SESSION_ID");
180 + if (old_session == NULL)
181 + return -1;
182 + } else if (strcmp(s2, "true") == 0) {
183 + /* only process the addition */
184 + a = ACTION_ADD;
185 + u = u2;
188 - s = getenv("CK_SESSION_USER_UID");
189 - if (s == NULL)
190 - return -1;
191 - u = strtoul(s, NULL, 10);
192 - if (u == 0)
193 - return 0;
194 + break;
195 + case ACTION_NONE:
196 + break;
197 + default:
198 + g_assert_not_reached ();
199 + break;
202 - *own_session = session;
203 + *remove_session_id = old_session;
204 *uid = u;
205 - *add = a;
206 + *uid2 = u2;
207 + *action = a;
208 return 0;
211 @@ -223,6 +309,21 @@ static void apply_acl_to_devices(uid_t uid, int add)
212 udev_unref(udev);
215 +static void
216 +remove_uid (uid_t uid, const char *remove_session_id)
218 + /*
219 + * Remove ACL for given uid from all matching devices
220 + * when there is currently no local active session.
221 + */
222 + GSList *list;
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' },
237 - int add = -1;
238 + int action = -1;
239 const char *device = NULL;
240 uid_t uid = 0;
241 - const char* own_session = NULL;
242 + uid_t uid2 = 0;
243 + const char* remove_session_id = NULL;
244 int rc = 0;
246 /* valgrind is more important to us than a slice allocator */
247 @@ -252,9 +354,9 @@ int main (int argc, char* argv[])
248 switch (option) {
249 case 'a':
250 if (strcmp(optarg, "add") == 0 || strcmp(optarg, "change") == 0)
251 - add = 1;
252 + action = ACTION_ADD;
253 else if (strcmp(optarg, "remove") == 0)
254 - add = 0;
255 + action = ACTION_REMOVE;
256 else
257 goto out;
258 break;
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);
268 - if (add < 0) {
269 + if (action < 0) {
270 fprintf(stderr, "missing action\n\n");
271 rc = 2;
272 goto out;
273 @@ -290,20 +392,24 @@ int main (int argc, char* argv[])
276 if (uid != 0) {
277 - if (add) {
278 + switch (action) {
279 + case ACTION_ADD:
280 /* Add ACL for given uid to all matching devices. */
281 apply_acl_to_devices(uid, 1);
282 - } else {
283 - /*
284 - * Remove ACL for given uid from all matching devices
285 - * when there is currently no local active session.
286 - */
287 - GSList *list;
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);
293 + break;
294 + case ACTION_REMOVE:
295 + remove_uid(uid, remove_session_id);
296 + break;
297 + case ACTION_CHANGE:
298 + remove_uid(uid, remove_session_id);
299 + apply_acl_to_devices(uid2, 1);
300 + break;
301 + case ACTION_NONE:
302 + goto out;
303 + break;
304 + default:
305 + g_assert_not_reached();
306 + break;
308 } else if (device != NULL) {
310 @@ -321,8 +427,8 @@ int main (int argc, char* argv[])
311 uid_t u;
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);
319 g_slist_free(list);
320 } else {
322 1.6.5.1