diff options
Diffstat (limited to 'debian/patches/consolekit.patch')
-rw-r--r-- | debian/patches/consolekit.patch | 576 |
1 files changed, 576 insertions, 0 deletions
diff --git a/debian/patches/consolekit.patch b/debian/patches/consolekit.patch new file mode 100644 index 000000000..0438b8f74 --- /dev/null +++ b/debian/patches/consolekit.patch | |||
@@ -0,0 +1,576 @@ | |||
1 | From 8b3111d597316954caaf8ddf2e7746491976c248 Mon Sep 17 00:00:00 2001 | ||
2 | From: Colin Watson <cjwatson@ubuntu.com> | ||
3 | Date: Sun, 9 Feb 2014 16:09:57 +0000 | ||
4 | Subject: Add support for registering ConsoleKit sessions on login | ||
5 | |||
6 | Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1450 | ||
7 | Last-Updated: 2015-08-19 | ||
8 | |||
9 | Patch-Name: consolekit.patch | ||
10 | --- | ||
11 | Makefile.in | 3 +- | ||
12 | configure.ac | 25 ++++++ | ||
13 | consolekit.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
14 | consolekit.h | 24 ++++++ | ||
15 | monitor.c | 42 ++++++++++ | ||
16 | monitor.h | 2 + | ||
17 | monitor_wrap.c | 30 +++++++ | ||
18 | monitor_wrap.h | 4 + | ||
19 | session.c | 13 ++++ | ||
20 | session.h | 6 ++ | ||
21 | 10 files changed, 389 insertions(+), 1 deletion(-) | ||
22 | create mode 100644 consolekit.c | ||
23 | create mode 100644 consolekit.h | ||
24 | |||
25 | diff --git a/Makefile.in b/Makefile.in | ||
26 | index 3d2a328..c406aec 100644 | ||
27 | --- a/Makefile.in | ||
28 | +++ b/Makefile.in | ||
29 | @@ -111,7 +111,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \ | ||
30 | sftp-server.o sftp-common.o \ | ||
31 | roaming_common.o roaming_serv.o \ | ||
32 | sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \ | ||
33 | - sandbox-seccomp-filter.o sandbox-capsicum.o | ||
34 | + sandbox-seccomp-filter.o sandbox-capsicum.o \ | ||
35 | + consolekit.o | ||
36 | |||
37 | MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out | ||
38 | MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5 | ||
39 | diff --git a/configure.ac b/configure.ac | ||
40 | index 5f606ea..f7ce777 100644 | ||
41 | --- a/configure.ac | ||
42 | +++ b/configure.ac | ||
43 | @@ -4180,6 +4180,30 @@ AC_ARG_WITH([kerberos5], | ||
44 | AC_SUBST([GSSLIBS]) | ||
45 | AC_SUBST([K5LIBS]) | ||
46 | |||
47 | +# Check whether user wants ConsoleKit support | ||
48 | +CONSOLEKIT_MSG="no" | ||
49 | +LIBCK_CONNECTOR="" | ||
50 | +AC_ARG_WITH(consolekit, | ||
51 | + [ --with-consolekit Enable ConsoleKit support], | ||
52 | + [ if test "x$withval" != "xno" ; then | ||
53 | + AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no]) | ||
54 | + if test "$PKGCONFIG" != "no"; then | ||
55 | + AC_MSG_CHECKING([for ck-connector]) | ||
56 | + if $PKGCONFIG --exists ck-connector; then | ||
57 | + CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector` | ||
58 | + CKCON_LIBS=`$PKGCONFIG --libs ck-connector` | ||
59 | + CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS" | ||
60 | + SSHDLIBS="$SSHDLIBS $CKCON_LIBS" | ||
61 | + AC_MSG_RESULT([yes]) | ||
62 | + AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.]) | ||
63 | + CONSOLEKIT_MSG="yes" | ||
64 | + else | ||
65 | + AC_MSG_RESULT([no]) | ||
66 | + fi | ||
67 | + fi | ||
68 | + fi ] | ||
69 | +) | ||
70 | + | ||
71 | # Looking for programs, paths and files | ||
72 | |||
73 | PRIVSEP_PATH=/var/empty | ||
74 | @@ -4981,6 +5005,7 @@ echo " MD5 password support: $MD5_MSG" | ||
75 | echo " libedit support: $LIBEDIT_MSG" | ||
76 | echo " Solaris process contract support: $SPC_MSG" | ||
77 | echo " Solaris project support: $SP_MSG" | ||
78 | +echo " ConsoleKit support: $CONSOLEKIT_MSG" | ||
79 | echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" | ||
80 | echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" | ||
81 | echo " BSD Auth support: $BSD_AUTH_MSG" | ||
82 | diff --git a/consolekit.c b/consolekit.c | ||
83 | new file mode 100644 | ||
84 | index 0000000..0266f06 | ||
85 | --- /dev/null | ||
86 | +++ b/consolekit.c | ||
87 | @@ -0,0 +1,241 @@ | ||
88 | +/* | ||
89 | + * Copyright (c) 2008 Colin Watson. All rights reserved. | ||
90 | + * | ||
91 | + * Permission to use, copy, modify, and distribute this software for any | ||
92 | + * purpose with or without fee is hereby granted, provided that the above | ||
93 | + * copyright notice and this permission notice appear in all copies. | ||
94 | + * | ||
95 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
96 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
97 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
98 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
99 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
100 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
101 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
102 | + */ | ||
103 | +/* | ||
104 | + * Loosely based on pam-ck-connector, which is: | ||
105 | + * | ||
106 | + * Copyright (c) 2007 David Zeuthen <davidz@redhat.com> | ||
107 | + * | ||
108 | + * Permission is hereby granted, free of charge, to any person | ||
109 | + * obtaining a copy of this software and associated documentation | ||
110 | + * files (the "Software"), to deal in the Software without | ||
111 | + * restriction, including without limitation the rights to use, | ||
112 | + * copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
113 | + * copies of the Software, and to permit persons to whom the | ||
114 | + * Software is furnished to do so, subject to the following | ||
115 | + * conditions: | ||
116 | + * | ||
117 | + * The above copyright notice and this permission notice shall be | ||
118 | + * included in all copies or substantial portions of the Software. | ||
119 | + * | ||
120 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
121 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
122 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
123 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
124 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
125 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
126 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
127 | + * OTHER DEALINGS IN THE SOFTWARE. | ||
128 | + */ | ||
129 | + | ||
130 | +#include "includes.h" | ||
131 | + | ||
132 | +#ifdef USE_CONSOLEKIT | ||
133 | + | ||
134 | +#include <ck-connector.h> | ||
135 | + | ||
136 | +#include "openbsd-compat/sys-queue.h" | ||
137 | +#include "xmalloc.h" | ||
138 | +#include "channels.h" | ||
139 | +#include "key.h" | ||
140 | +#include "hostfile.h" | ||
141 | +#include "auth.h" | ||
142 | +#include "log.h" | ||
143 | +#include "misc.h" | ||
144 | +#include "servconf.h" | ||
145 | +#include "canohost.h" | ||
146 | +#include "session.h" | ||
147 | +#include "consolekit.h" | ||
148 | + | ||
149 | +extern ServerOptions options; | ||
150 | +extern u_int utmp_len; | ||
151 | + | ||
152 | +void | ||
153 | +set_active(const char *cookie) | ||
154 | +{ | ||
155 | + DBusError err; | ||
156 | + DBusConnection *connection; | ||
157 | + DBusMessage *message = NULL, *reply = NULL; | ||
158 | + char *sid; | ||
159 | + DBusMessageIter iter, subiter; | ||
160 | + const char *interface, *property; | ||
161 | + dbus_bool_t active; | ||
162 | + | ||
163 | + dbus_error_init(&err); | ||
164 | + connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); | ||
165 | + if (!connection) { | ||
166 | + if (dbus_error_is_set(&err)) { | ||
167 | + error("unable to open DBus connection: %s", | ||
168 | + err.message); | ||
169 | + dbus_error_free(&err); | ||
170 | + } | ||
171 | + goto out; | ||
172 | + } | ||
173 | + dbus_connection_set_exit_on_disconnect(connection, FALSE); | ||
174 | + | ||
175 | + message = dbus_message_new_method_call("org.freedesktop.ConsoleKit", | ||
176 | + "/org/freedesktop/ConsoleKit/Manager", | ||
177 | + "org.freedesktop.ConsoleKit.Manager", | ||
178 | + "GetSessionForCookie"); | ||
179 | + if (!message) | ||
180 | + goto out; | ||
181 | + if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &cookie, | ||
182 | + DBUS_TYPE_INVALID)) { | ||
183 | + if (dbus_error_is_set(&err)) { | ||
184 | + error("unable to get current session: %s", | ||
185 | + err.message); | ||
186 | + dbus_error_free(&err); | ||
187 | + } | ||
188 | + goto out; | ||
189 | + } | ||
190 | + | ||
191 | + dbus_error_init(&err); | ||
192 | + reply = dbus_connection_send_with_reply_and_block(connection, message, | ||
193 | + -1, &err); | ||
194 | + if (!reply) { | ||
195 | + if (dbus_error_is_set(&err)) { | ||
196 | + error("unable to get current session: %s", | ||
197 | + err.message); | ||
198 | + dbus_error_free(&err); | ||
199 | + } | ||
200 | + goto out; | ||
201 | + } | ||
202 | + | ||
203 | + dbus_error_init(&err); | ||
204 | + if (!dbus_message_get_args(reply, &err, | ||
205 | + DBUS_TYPE_OBJECT_PATH, &sid, | ||
206 | + DBUS_TYPE_INVALID)) { | ||
207 | + if (dbus_error_is_set(&err)) { | ||
208 | + error("unable to get current session: %s", | ||
209 | + err.message); | ||
210 | + dbus_error_free(&err); | ||
211 | + } | ||
212 | + goto out; | ||
213 | + } | ||
214 | + dbus_message_unref(reply); | ||
215 | + dbus_message_unref(message); | ||
216 | + message = reply = NULL; | ||
217 | + | ||
218 | + message = dbus_message_new_method_call("org.freedesktop.ConsoleKit", | ||
219 | + sid, "org.freedesktop.DBus.Properties", "Set"); | ||
220 | + if (!message) | ||
221 | + goto out; | ||
222 | + interface = "org.freedesktop.ConsoleKit.Session"; | ||
223 | + property = "active"; | ||
224 | + if (!dbus_message_append_args(message, | ||
225 | + DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, | ||
226 | + DBUS_TYPE_INVALID)) | ||
227 | + goto out; | ||
228 | + dbus_message_iter_init_append(message, &iter); | ||
229 | + if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, | ||
230 | + DBUS_TYPE_BOOLEAN_AS_STRING, &subiter)) | ||
231 | + goto out; | ||
232 | + active = TRUE; | ||
233 | + if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_BOOLEAN, | ||
234 | + &active)) | ||
235 | + goto out; | ||
236 | + if (!dbus_message_iter_close_container(&iter, &subiter)) | ||
237 | + goto out; | ||
238 | + | ||
239 | + dbus_error_init(&err); | ||
240 | + reply = dbus_connection_send_with_reply_and_block(connection, message, | ||
241 | + -1, &err); | ||
242 | + if (!reply) { | ||
243 | + if (dbus_error_is_set(&err)) { | ||
244 | + error("unable to make current session active: %s", | ||
245 | + err.message); | ||
246 | + dbus_error_free(&err); | ||
247 | + } | ||
248 | + goto out; | ||
249 | + } | ||
250 | + | ||
251 | +out: | ||
252 | + if (reply) | ||
253 | + dbus_message_unref(reply); | ||
254 | + if (message) | ||
255 | + dbus_message_unref(message); | ||
256 | +} | ||
257 | + | ||
258 | +/* | ||
259 | + * We pass display separately rather than using s->display because the | ||
260 | + * latter is not available in the monitor when using privsep. | ||
261 | + */ | ||
262 | + | ||
263 | +char * | ||
264 | +consolekit_register(Session *s, const char *display) | ||
265 | +{ | ||
266 | + DBusError err; | ||
267 | + const char *tty = s->tty; | ||
268 | + const char *remote_host_name; | ||
269 | + dbus_bool_t is_local = FALSE; | ||
270 | + const char *cookie = NULL; | ||
271 | + | ||
272 | + if (s->ckc) { | ||
273 | + debug("already registered with ConsoleKit"); | ||
274 | + return xstrdup(ck_connector_get_cookie(s->ckc)); | ||
275 | + } | ||
276 | + | ||
277 | + s->ckc = ck_connector_new(); | ||
278 | + if (!s->ckc) { | ||
279 | + error("ck_connector_new failed"); | ||
280 | + return NULL; | ||
281 | + } | ||
282 | + | ||
283 | + if (!tty) | ||
284 | + tty = ""; | ||
285 | + if (!display) | ||
286 | + display = ""; | ||
287 | + remote_host_name = get_remote_name_or_ip(utmp_len, options.use_dns); | ||
288 | + if (!remote_host_name) | ||
289 | + remote_host_name = ""; | ||
290 | + | ||
291 | + dbus_error_init(&err); | ||
292 | + if (!ck_connector_open_session_with_parameters(s->ckc, &err, | ||
293 | + "unix-user", &s->pw->pw_uid, | ||
294 | + "display-device", &tty, | ||
295 | + "x11-display", &display, | ||
296 | + "remote-host-name", &remote_host_name, | ||
297 | + "is-local", &is_local, | ||
298 | + NULL)) { | ||
299 | + if (dbus_error_is_set(&err)) { | ||
300 | + debug("%s", err.message); | ||
301 | + dbus_error_free(&err); | ||
302 | + } else { | ||
303 | + debug("insufficient privileges or D-Bus / ConsoleKit " | ||
304 | + "not available"); | ||
305 | + } | ||
306 | + return NULL; | ||
307 | + } | ||
308 | + | ||
309 | + debug("registered uid=%d on tty='%s' with ConsoleKit", | ||
310 | + s->pw->pw_uid, s->tty); | ||
311 | + | ||
312 | + cookie = ck_connector_get_cookie(s->ckc); | ||
313 | + set_active(cookie); | ||
314 | + return xstrdup(cookie); | ||
315 | +} | ||
316 | + | ||
317 | +void | ||
318 | +consolekit_unregister(Session *s) | ||
319 | +{ | ||
320 | + if (s->ckc) { | ||
321 | + debug("unregistering ConsoleKit session %s", | ||
322 | + ck_connector_get_cookie(s->ckc)); | ||
323 | + ck_connector_unref(s->ckc); | ||
324 | + s->ckc = NULL; | ||
325 | + } | ||
326 | +} | ||
327 | + | ||
328 | +#endif /* USE_CONSOLEKIT */ | ||
329 | diff --git a/consolekit.h b/consolekit.h | ||
330 | new file mode 100644 | ||
331 | index 0000000..8ce3716 | ||
332 | --- /dev/null | ||
333 | +++ b/consolekit.h | ||
334 | @@ -0,0 +1,24 @@ | ||
335 | +/* | ||
336 | + * Copyright (c) 2008 Colin Watson. All rights reserved. | ||
337 | + * | ||
338 | + * Permission to use, copy, modify, and distribute this software for any | ||
339 | + * purpose with or without fee is hereby granted, provided that the above | ||
340 | + * copyright notice and this permission notice appear in all copies. | ||
341 | + * | ||
342 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
343 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
344 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
345 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
346 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
347 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
348 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
349 | + */ | ||
350 | + | ||
351 | +#ifdef USE_CONSOLEKIT | ||
352 | + | ||
353 | +struct Session; | ||
354 | + | ||
355 | +char * consolekit_register(struct Session *, const char *); | ||
356 | +void consolekit_unregister(struct Session *); | ||
357 | + | ||
358 | +#endif /* USE_CONSOLEKIT */ | ||
359 | diff --git a/monitor.c b/monitor.c | ||
360 | index 6ff05e4..ce7ba07 100644 | ||
361 | --- a/monitor.c | ||
362 | +++ b/monitor.c | ||
363 | @@ -104,6 +104,9 @@ | ||
364 | #include "authfd.h" | ||
365 | #include "match.h" | ||
366 | #include "ssherr.h" | ||
367 | +#ifdef USE_CONSOLEKIT | ||
368 | +#include "consolekit.h" | ||
369 | +#endif | ||
370 | |||
371 | #ifdef GSSAPI | ||
372 | static Gssctxt *gsscontext = NULL; | ||
373 | @@ -169,6 +172,10 @@ int mm_answer_audit_command(int, Buffer *); | ||
374 | |||
375 | static int monitor_read_log(struct monitor *); | ||
376 | |||
377 | +#ifdef USE_CONSOLEKIT | ||
378 | +int mm_answer_consolekit_register(int, Buffer *); | ||
379 | +#endif | ||
380 | + | ||
381 | static Authctxt *authctxt; | ||
382 | |||
383 | #ifdef WITH_SSH1 | ||
384 | @@ -261,6 +268,9 @@ struct mon_table mon_dispatch_postauth20[] = { | ||
385 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, | ||
386 | {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command}, | ||
387 | #endif | ||
388 | +#ifdef USE_CONSOLEKIT | ||
389 | + {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register}, | ||
390 | +#endif | ||
391 | {0, 0, NULL} | ||
392 | }; | ||
393 | |||
394 | @@ -306,6 +316,9 @@ struct mon_table mon_dispatch_postauth15[] = { | ||
395 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, | ||
396 | {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command}, | ||
397 | #endif | ||
398 | +#ifdef USE_CONSOLEKIT | ||
399 | + {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register}, | ||
400 | +#endif | ||
401 | #endif /* WITH_SSH1 */ | ||
402 | {0, 0, NULL} | ||
403 | }; | ||
404 | @@ -488,6 +501,9 @@ monitor_child_postauth(struct monitor *pmonitor) | ||
405 | monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); | ||
406 | monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1); | ||
407 | } | ||
408 | +#ifdef USE_CONSOLEKIT | ||
409 | + monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1); | ||
410 | +#endif | ||
411 | |||
412 | for (;;) | ||
413 | monitor_read(pmonitor, mon_dispatch, NULL); | ||
414 | @@ -2187,3 +2203,29 @@ mm_answer_gss_updatecreds(int socket, Buffer *m) { | ||
415 | |||
416 | #endif /* GSSAPI */ | ||
417 | |||
418 | +#ifdef USE_CONSOLEKIT | ||
419 | +int | ||
420 | +mm_answer_consolekit_register(int sock, Buffer *m) | ||
421 | +{ | ||
422 | + Session *s; | ||
423 | + char *tty, *display; | ||
424 | + char *cookie = NULL; | ||
425 | + | ||
426 | + debug3("%s entering", __func__); | ||
427 | + | ||
428 | + tty = buffer_get_string(m, NULL); | ||
429 | + display = buffer_get_string(m, NULL); | ||
430 | + s = session_by_tty(tty); | ||
431 | + if (s != NULL) | ||
432 | + cookie = consolekit_register(s, display); | ||
433 | + buffer_clear(m); | ||
434 | + buffer_put_cstring(m, cookie != NULL ? cookie : ""); | ||
435 | + mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m); | ||
436 | + | ||
437 | + free(cookie); | ||
438 | + free(display); | ||
439 | + free(tty); | ||
440 | + | ||
441 | + return (0); | ||
442 | +} | ||
443 | +#endif /* USE_CONSOLEKIT */ | ||
444 | diff --git a/monitor.h b/monitor.h | ||
445 | index 2d82b8b..fd8d92c 100644 | ||
446 | --- a/monitor.h | ||
447 | +++ b/monitor.h | ||
448 | @@ -70,6 +70,8 @@ enum monitor_reqtype { | ||
449 | |||
450 | MONITOR_REQ_AUTHROLE = 154, | ||
451 | |||
452 | + MONITOR_REQ_CONSOLEKIT_REGISTER = 156, MONITOR_ANS_CONSOLEKIT_REGISTER = 157, | ||
453 | + | ||
454 | }; | ||
455 | |||
456 | struct mm_master; | ||
457 | diff --git a/monitor_wrap.c b/monitor_wrap.c | ||
458 | index 5aa9c47..a5f4e9d 100644 | ||
459 | --- a/monitor_wrap.c | ||
460 | +++ b/monitor_wrap.c | ||
461 | @@ -1150,3 +1150,33 @@ mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store) | ||
462 | |||
463 | #endif /* GSSAPI */ | ||
464 | |||
465 | +#ifdef USE_CONSOLEKIT | ||
466 | +char * | ||
467 | +mm_consolekit_register(Session *s, const char *display) | ||
468 | +{ | ||
469 | + Buffer m; | ||
470 | + char *cookie; | ||
471 | + | ||
472 | + debug3("%s entering", __func__); | ||
473 | + | ||
474 | + if (s->ttyfd == -1) | ||
475 | + return NULL; | ||
476 | + buffer_init(&m); | ||
477 | + buffer_put_cstring(&m, s->tty); | ||
478 | + buffer_put_cstring(&m, display != NULL ? display : ""); | ||
479 | + mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m); | ||
480 | + buffer_clear(&m); | ||
481 | + | ||
482 | + mm_request_receive_expect(pmonitor->m_recvfd, | ||
483 | + MONITOR_ANS_CONSOLEKIT_REGISTER, &m); | ||
484 | + cookie = buffer_get_string(&m, NULL); | ||
485 | + buffer_free(&m); | ||
486 | + | ||
487 | + /* treat empty cookie as missing cookie */ | ||
488 | + if (strlen(cookie) == 0) { | ||
489 | + free(cookie); | ||
490 | + cookie = NULL; | ||
491 | + } | ||
492 | + return (cookie); | ||
493 | +} | ||
494 | +#endif /* USE_CONSOLEKIT */ | ||
495 | diff --git a/monitor_wrap.h b/monitor_wrap.h | ||
496 | index 4d1e899..f99c31c 100644 | ||
497 | --- a/monitor_wrap.h | ||
498 | +++ b/monitor_wrap.h | ||
499 | @@ -108,4 +108,8 @@ int mm_skey_respond(void *, u_int, char **); | ||
500 | /* zlib allocation hooks */ | ||
501 | void mm_init_compression(struct mm_master *); | ||
502 | |||
503 | +#ifdef USE_CONSOLEKIT | ||
504 | +char *mm_consolekit_register(struct Session *, const char *); | ||
505 | +#endif /* USE_CONSOLEKIT */ | ||
506 | + | ||
507 | #endif /* _MM_WRAP_H_ */ | ||
508 | diff --git a/session.c b/session.c | ||
509 | index d4b7725..785833f 100644 | ||
510 | --- a/session.c | ||
511 | +++ b/session.c | ||
512 | @@ -94,6 +94,7 @@ | ||
513 | #include "kex.h" | ||
514 | #include "monitor_wrap.h" | ||
515 | #include "sftp.h" | ||
516 | +#include "consolekit.h" | ||
517 | |||
518 | #if defined(KRB5) && defined(USE_AFS) | ||
519 | #include <kafs.h> | ||
520 | @@ -1144,6 +1145,9 @@ do_setup_env(Session *s, const char *shell) | ||
521 | #if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN) | ||
522 | char *path = NULL; | ||
523 | #endif | ||
524 | +#ifdef USE_CONSOLEKIT | ||
525 | + const char *ckcookie = NULL; | ||
526 | +#endif /* USE_CONSOLEKIT */ | ||
527 | |||
528 | /* Initialize the environment. */ | ||
529 | envsize = 100; | ||
530 | @@ -1288,6 +1292,11 @@ do_setup_env(Session *s, const char *shell) | ||
531 | child_set_env(&env, &envsize, "KRB5CCNAME", | ||
532 | s->authctxt->krb5_ccname); | ||
533 | #endif | ||
534 | +#ifdef USE_CONSOLEKIT | ||
535 | + ckcookie = PRIVSEP(consolekit_register(s, s->display)); | ||
536 | + if (ckcookie) | ||
537 | + child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie); | ||
538 | +#endif /* USE_CONSOLEKIT */ | ||
539 | #ifdef USE_PAM | ||
540 | /* | ||
541 | * Pull in any environment variables that may have | ||
542 | @@ -2351,6 +2360,10 @@ session_pty_cleanup2(Session *s) | ||
543 | |||
544 | debug("session_pty_cleanup: session %d release %s", s->self, s->tty); | ||
545 | |||
546 | +#ifdef USE_CONSOLEKIT | ||
547 | + consolekit_unregister(s); | ||
548 | +#endif /* USE_CONSOLEKIT */ | ||
549 | + | ||
550 | /* Record that the user has logged out. */ | ||
551 | if (s->pid != 0) | ||
552 | record_logout(s->pid, s->tty, s->pw->pw_name); | ||
553 | diff --git a/session.h b/session.h | ||
554 | index ef6593c..a6b6983 100644 | ||
555 | --- a/session.h | ||
556 | +++ b/session.h | ||
557 | @@ -26,6 +26,8 @@ | ||
558 | #ifndef SESSION_H | ||
559 | #define SESSION_H | ||
560 | |||
561 | +struct _CkConnector; | ||
562 | + | ||
563 | #define TTYSZ 64 | ||
564 | typedef struct Session Session; | ||
565 | struct Session { | ||
566 | @@ -61,6 +63,10 @@ struct Session { | ||
567 | char *name; | ||
568 | char *val; | ||
569 | } *env; | ||
570 | + | ||
571 | +#ifdef USE_CONSOLEKIT | ||
572 | + struct _CkConnector *ckc; | ||
573 | +#endif /* USE_CONSOLEKIT */ | ||
574 | }; | ||
575 | |||
576 | void do_authenticated(Authctxt *); | ||