summaryrefslogtreecommitdiff
path: root/debian/patches/consolekit.patch
diff options
context:
space:
mode:
Diffstat (limited to 'debian/patches/consolekit.patch')
-rw-r--r--debian/patches/consolekit.patch720
1 files changed, 720 insertions, 0 deletions
diff --git a/debian/patches/consolekit.patch b/debian/patches/consolekit.patch
new file mode 100644
index 000000000..fd064a848
--- /dev/null
+++ b/debian/patches/consolekit.patch
@@ -0,0 +1,720 @@
1Description: Add support for registering ConsoleKit sessions on login
2Author: Colin Watson <cjwatson@ubuntu.com>
3Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1450
4Last-Updated: 2013-09-14
5
6Index: b/Makefile.in
7===================================================================
8--- a/Makefile.in
9+++ b/Makefile.in
10@@ -96,7 +96,8 @@
11 sftp-server.o sftp-common.o \
12 roaming_common.o roaming_serv.o \
13 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
14- sandbox-seccomp-filter.o
15+ sandbox-seccomp-filter.o \
16+ consolekit.o
17
18 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 ssh-vulnkey.1.out sshd_config.5.out ssh_config.5.out
19 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 ssh-vulnkey.1 sshd_config.5 ssh_config.5
20Index: b/configure.ac
21===================================================================
22--- a/configure.ac
23+++ b/configure.ac
24@@ -3841,6 +3841,30 @@
25 AC_SUBST([GSSLIBS])
26 AC_SUBST([K5LIBS])
27
28+# Check whether user wants ConsoleKit support
29+CONSOLEKIT_MSG="no"
30+LIBCK_CONNECTOR=""
31+AC_ARG_WITH(consolekit,
32+ [ --with-consolekit Enable ConsoleKit support],
33+ [ if test "x$withval" != "xno" ; then
34+ AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
35+ if test "$PKGCONFIG" != "no"; then
36+ AC_MSG_CHECKING([for ck-connector])
37+ if $PKGCONFIG --exists ck-connector; then
38+ CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
39+ CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
40+ CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
41+ SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
42+ AC_MSG_RESULT([yes])
43+ AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.])
44+ CONSOLEKIT_MSG="yes"
45+ else
46+ AC_MSG_RESULT([no])
47+ fi
48+ fi
49+ fi ]
50+)
51+
52 # Looking for programs, paths and files
53
54 PRIVSEP_PATH=/var/empty
55@@ -4641,6 +4665,7 @@
56 echo " libedit support: $LIBEDIT_MSG"
57 echo " Solaris process contract support: $SPC_MSG"
58 echo " Solaris project support: $SP_MSG"
59+echo " ConsoleKit support: $CONSOLEKIT_MSG"
60 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
61 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
62 echo " BSD Auth support: $BSD_AUTH_MSG"
63Index: b/configure
64===================================================================
65--- a/configure
66+++ b/configure
67@@ -738,6 +738,7 @@
68 with_sandbox
69 with_selinux
70 with_kerberos5
71+with_consolekit
72 with_privsep_path
73 with_xauth
74 enable_strip
75@@ -1428,6 +1429,7 @@
76 --with-sandbox=style Specify privilege separation sandbox (no, darwin, rlimit, systrace, seccomp_filter)
77 --with-selinux Enable SELinux support
78 --with-kerberos5=PATH Enable Kerberos 5 support
79+ --with-consolekit Enable ConsoleKit support
80 --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty)
81 --with-xauth=PATH Specify path to xauth program
82 --with-maildir=/path/to/mail Specify your system mail directory
83@@ -16375,6 +16377,135 @@
84
85
86
87+# Check whether user wants ConsoleKit support
88+CONSOLEKIT_MSG="no"
89+LIBCK_CONNECTOR=""
90+
91+# Check whether --with-consolekit was given.
92+if test "${with_consolekit+set}" = set; then :
93+ withval=$with_consolekit; if test "x$withval" != "xno" ; then
94+ if test -n "$ac_tool_prefix"; then
95+ # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
96+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
97+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
98+$as_echo_n "checking for $ac_word... " >&6; }
99+if ${ac_cv_path_PKGCONFIG+:} false; then :
100+ $as_echo_n "(cached) " >&6
101+else
102+ case $PKGCONFIG in
103+ [\\/]* | ?:[\\/]*)
104+ ac_cv_path_PKGCONFIG="$PKGCONFIG" # Let the user override the test with a path.
105+ ;;
106+ *)
107+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
108+for as_dir in $PATH
109+do
110+ IFS=$as_save_IFS
111+ test -z "$as_dir" && as_dir=.
112+ for ac_exec_ext in '' $ac_executable_extensions; do
113+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
114+ ac_cv_path_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
115+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
116+ break 2
117+ fi
118+done
119+ done
120+IFS=$as_save_IFS
121+
122+ ;;
123+esac
124+fi
125+PKGCONFIG=$ac_cv_path_PKGCONFIG
126+if test -n "$PKGCONFIG"; then
127+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5
128+$as_echo "$PKGCONFIG" >&6; }
129+else
130+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
131+$as_echo "no" >&6; }
132+fi
133+
134+
135+fi
136+if test -z "$ac_cv_path_PKGCONFIG"; then
137+ ac_pt_PKGCONFIG=$PKGCONFIG
138+ # Extract the first word of "pkg-config", so it can be a program name with args.
139+set dummy pkg-config; ac_word=$2
140+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
141+$as_echo_n "checking for $ac_word... " >&6; }
142+if ${ac_cv_path_ac_pt_PKGCONFIG+:} false; then :
143+ $as_echo_n "(cached) " >&6
144+else
145+ case $ac_pt_PKGCONFIG in
146+ [\\/]* | ?:[\\/]*)
147+ ac_cv_path_ac_pt_PKGCONFIG="$ac_pt_PKGCONFIG" # Let the user override the test with a path.
148+ ;;
149+ *)
150+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
151+for as_dir in $PATH
152+do
153+ IFS=$as_save_IFS
154+ test -z "$as_dir" && as_dir=.
155+ for ac_exec_ext in '' $ac_executable_extensions; do
156+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
157+ ac_cv_path_ac_pt_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
158+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
159+ break 2
160+ fi
161+done
162+ done
163+IFS=$as_save_IFS
164+
165+ ;;
166+esac
167+fi
168+ac_pt_PKGCONFIG=$ac_cv_path_ac_pt_PKGCONFIG
169+if test -n "$ac_pt_PKGCONFIG"; then
170+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKGCONFIG" >&5
171+$as_echo "$ac_pt_PKGCONFIG" >&6; }
172+else
173+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
174+$as_echo "no" >&6; }
175+fi
176+
177+ if test "x$ac_pt_PKGCONFIG" = x; then
178+ PKGCONFIG="no"
179+ else
180+ case $cross_compiling:$ac_tool_warned in
181+yes:)
182+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
183+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
184+ac_tool_warned=yes ;;
185+esac
186+ PKGCONFIG=$ac_pt_PKGCONFIG
187+ fi
188+else
189+ PKGCONFIG="$ac_cv_path_PKGCONFIG"
190+fi
191+
192+ if test "$PKGCONFIG" != "no"; then
193+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ck-connector" >&5
194+$as_echo_n "checking for ck-connector... " >&6; }
195+ if $PKGCONFIG --exists ck-connector; then
196+ CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
197+ CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
198+ CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
199+ SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
200+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
201+$as_echo "yes" >&6; }
202+
203+$as_echo "#define USE_CONSOLEKIT 1" >>confdefs.h
204+
205+ CONSOLEKIT_MSG="yes"
206+ else
207+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
208+$as_echo "no" >&6; }
209+ fi
210+ fi
211+ fi
212+
213+fi
214+
215+
216 # Looking for programs, paths and files
217
218 PRIVSEP_PATH=/var/empty
219@@ -18902,6 +19033,7 @@
220 echo " libedit support: $LIBEDIT_MSG"
221 echo " Solaris process contract support: $SPC_MSG"
222 echo " Solaris project support: $SP_MSG"
223+echo " ConsoleKit support: $CONSOLEKIT_MSG"
224 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
225 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
226 echo " BSD Auth support: $BSD_AUTH_MSG"
227Index: b/consolekit.c
228===================================================================
229--- /dev/null
230+++ b/consolekit.c
231@@ -0,0 +1,240 @@
232+/*
233+ * Copyright (c) 2008 Colin Watson. All rights reserved.
234+ *
235+ * Permission to use, copy, modify, and distribute this software for any
236+ * purpose with or without fee is hereby granted, provided that the above
237+ * copyright notice and this permission notice appear in all copies.
238+ *
239+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
240+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
241+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
242+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
243+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
244+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
245+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
246+ */
247+/*
248+ * Loosely based on pam-ck-connector, which is:
249+ *
250+ * Copyright (c) 2007 David Zeuthen <davidz@redhat.com>
251+ *
252+ * Permission is hereby granted, free of charge, to any person
253+ * obtaining a copy of this software and associated documentation
254+ * files (the "Software"), to deal in the Software without
255+ * restriction, including without limitation the rights to use,
256+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
257+ * copies of the Software, and to permit persons to whom the
258+ * Software is furnished to do so, subject to the following
259+ * conditions:
260+ *
261+ * The above copyright notice and this permission notice shall be
262+ * included in all copies or substantial portions of the Software.
263+ *
264+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
265+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
266+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
267+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
268+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
269+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
270+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
271+ * OTHER DEALINGS IN THE SOFTWARE.
272+ */
273+
274+#include "includes.h"
275+
276+#ifdef USE_CONSOLEKIT
277+
278+#include <ck-connector.h>
279+
280+#include "openbsd-compat/sys-queue.h"
281+#include "xmalloc.h"
282+#include "channels.h"
283+#include "key.h"
284+#include "hostfile.h"
285+#include "auth.h"
286+#include "log.h"
287+#include "servconf.h"
288+#include "canohost.h"
289+#include "session.h"
290+#include "consolekit.h"
291+
292+extern ServerOptions options;
293+extern u_int utmp_len;
294+
295+void
296+set_active(const char *cookie)
297+{
298+ DBusError err;
299+ DBusConnection *connection;
300+ DBusMessage *message = NULL, *reply = NULL;
301+ char *sid;
302+ DBusMessageIter iter, subiter;
303+ const char *interface, *property;
304+ dbus_bool_t active;
305+
306+ dbus_error_init(&err);
307+ connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
308+ if (!connection) {
309+ if (dbus_error_is_set(&err)) {
310+ error("unable to open DBus connection: %s",
311+ err.message);
312+ dbus_error_free(&err);
313+ }
314+ goto out;
315+ }
316+ dbus_connection_set_exit_on_disconnect(connection, FALSE);
317+
318+ message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
319+ "/org/freedesktop/ConsoleKit/Manager",
320+ "org.freedesktop.ConsoleKit.Manager",
321+ "GetSessionForCookie");
322+ if (!message)
323+ goto out;
324+ if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &cookie,
325+ DBUS_TYPE_INVALID)) {
326+ if (dbus_error_is_set(&err)) {
327+ error("unable to get current session: %s",
328+ err.message);
329+ dbus_error_free(&err);
330+ }
331+ goto out;
332+ }
333+
334+ dbus_error_init(&err);
335+ reply = dbus_connection_send_with_reply_and_block(connection, message,
336+ -1, &err);
337+ if (!reply) {
338+ if (dbus_error_is_set(&err)) {
339+ error("unable to get current session: %s",
340+ err.message);
341+ dbus_error_free(&err);
342+ }
343+ goto out;
344+ }
345+
346+ dbus_error_init(&err);
347+ if (!dbus_message_get_args(reply, &err,
348+ DBUS_TYPE_OBJECT_PATH, &sid,
349+ DBUS_TYPE_INVALID)) {
350+ if (dbus_error_is_set(&err)) {
351+ error("unable to get current session: %s",
352+ err.message);
353+ dbus_error_free(&err);
354+ }
355+ goto out;
356+ }
357+ dbus_message_unref(reply);
358+ dbus_message_unref(message);
359+ message = reply = NULL;
360+
361+ message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
362+ sid, "org.freedesktop.DBus.Properties", "Set");
363+ if (!message)
364+ goto out;
365+ interface = "org.freedesktop.ConsoleKit.Session";
366+ property = "active";
367+ if (!dbus_message_append_args(message,
368+ DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property,
369+ DBUS_TYPE_INVALID))
370+ goto out;
371+ dbus_message_iter_init_append(message, &iter);
372+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
373+ DBUS_TYPE_BOOLEAN_AS_STRING, &subiter))
374+ goto out;
375+ active = TRUE;
376+ if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_BOOLEAN,
377+ &active))
378+ goto out;
379+ if (!dbus_message_iter_close_container(&iter, &subiter))
380+ goto out;
381+
382+ dbus_error_init(&err);
383+ reply = dbus_connection_send_with_reply_and_block(connection, message,
384+ -1, &err);
385+ if (!reply) {
386+ if (dbus_error_is_set(&err)) {
387+ error("unable to make current session active: %s",
388+ err.message);
389+ dbus_error_free(&err);
390+ }
391+ goto out;
392+ }
393+
394+out:
395+ if (reply)
396+ dbus_message_unref(reply);
397+ if (message)
398+ dbus_message_unref(message);
399+}
400+
401+/*
402+ * We pass display separately rather than using s->display because the
403+ * latter is not available in the monitor when using privsep.
404+ */
405+
406+char *
407+consolekit_register(Session *s, const char *display)
408+{
409+ DBusError err;
410+ const char *tty = s->tty;
411+ const char *remote_host_name;
412+ dbus_bool_t is_local = FALSE;
413+ const char *cookie = NULL;
414+
415+ if (s->ckc) {
416+ debug("already registered with ConsoleKit");
417+ return xstrdup(ck_connector_get_cookie(s->ckc));
418+ }
419+
420+ s->ckc = ck_connector_new();
421+ if (!s->ckc) {
422+ error("ck_connector_new failed");
423+ return NULL;
424+ }
425+
426+ if (!tty)
427+ tty = "";
428+ if (!display)
429+ display = "";
430+ remote_host_name = get_remote_name_or_ip(utmp_len, options.use_dns);
431+ if (!remote_host_name)
432+ remote_host_name = "";
433+
434+ dbus_error_init(&err);
435+ if (!ck_connector_open_session_with_parameters(s->ckc, &err,
436+ "unix-user", &s->pw->pw_uid,
437+ "display-device", &tty,
438+ "x11-display", &display,
439+ "remote-host-name", &remote_host_name,
440+ "is-local", &is_local,
441+ NULL)) {
442+ if (dbus_error_is_set(&err)) {
443+ debug("%s", err.message);
444+ dbus_error_free(&err);
445+ } else {
446+ debug("insufficient privileges or D-Bus / ConsoleKit "
447+ "not available");
448+ }
449+ return NULL;
450+ }
451+
452+ debug("registered uid=%d on tty='%s' with ConsoleKit",
453+ s->pw->pw_uid, s->tty);
454+
455+ cookie = ck_connector_get_cookie(s->ckc);
456+ set_active(cookie);
457+ return xstrdup(cookie);
458+}
459+
460+void
461+consolekit_unregister(Session *s)
462+{
463+ if (s->ckc) {
464+ debug("unregistering ConsoleKit session %s",
465+ ck_connector_get_cookie(s->ckc));
466+ ck_connector_unref(s->ckc);
467+ s->ckc = NULL;
468+ }
469+}
470+
471+#endif /* USE_CONSOLEKIT */
472Index: b/consolekit.h
473===================================================================
474--- /dev/null
475+++ b/consolekit.h
476@@ -0,0 +1,24 @@
477+/*
478+ * Copyright (c) 2008 Colin Watson. All rights reserved.
479+ *
480+ * Permission to use, copy, modify, and distribute this software for any
481+ * purpose with or without fee is hereby granted, provided that the above
482+ * copyright notice and this permission notice appear in all copies.
483+ *
484+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
485+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
486+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
487+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
488+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
489+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
490+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
491+ */
492+
493+#ifdef USE_CONSOLEKIT
494+
495+struct Session;
496+
497+char * consolekit_register(struct Session *, const char *);
498+void consolekit_unregister(struct Session *);
499+
500+#endif /* USE_CONSOLEKIT */
501Index: b/monitor.c
502===================================================================
503--- a/monitor.c
504+++ b/monitor.c
505@@ -98,6 +98,9 @@
506 #include "jpake.h"
507 #include "roaming.h"
508 #include "authfd.h"
509+#ifdef USE_CONSOLEKIT
510+#include "consolekit.h"
511+#endif
512
513 #ifdef GSSAPI
514 static Gssctxt *gsscontext = NULL;
515@@ -193,6 +196,10 @@
516
517 static int monitor_read_log(struct monitor *);
518
519+#ifdef USE_CONSOLEKIT
520+int mm_answer_consolekit_register(int, Buffer *);
521+#endif
522+
523 static Authctxt *authctxt;
524 static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
525
526@@ -285,6 +292,9 @@
527 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
528 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
529 #endif
530+#ifdef USE_CONSOLEKIT
531+ {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
532+#endif
533 {0, 0, NULL}
534 };
535
536@@ -327,6 +337,9 @@
537 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
538 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
539 #endif
540+#ifdef USE_CONSOLEKIT
541+ {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
542+#endif
543 {0, 0, NULL}
544 };
545
546@@ -514,6 +527,9 @@
547 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
548 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
549 }
550+#ifdef USE_CONSOLEKIT
551+ monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1);
552+#endif
553
554 for (;;)
555 monitor_read(pmonitor, mon_dispatch, NULL);
556@@ -2492,3 +2508,30 @@
557 }
558
559 #endif /* JPAKE */
560+
561+#ifdef USE_CONSOLEKIT
562+int
563+mm_answer_consolekit_register(int sock, Buffer *m)
564+{
565+ Session *s;
566+ char *tty, *display;
567+ char *cookie = NULL;
568+
569+ debug3("%s entering", __func__);
570+
571+ tty = buffer_get_string(m, NULL);
572+ display = buffer_get_string(m, NULL);
573+ s = session_by_tty(tty);
574+ if (s != NULL)
575+ cookie = consolekit_register(s, display);
576+ buffer_clear(m);
577+ buffer_put_cstring(m, cookie != NULL ? cookie : "");
578+ mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m);
579+
580+ free(cookie);
581+ free(display);
582+ free(tty);
583+
584+ return (0);
585+}
586+#endif /* USE_CONSOLEKIT */
587Index: b/monitor.h
588===================================================================
589--- a/monitor.h
590+++ b/monitor.h
591@@ -75,6 +75,8 @@
592
593 MONITOR_REQ_AUTHROLE = 154,
594
595+ MONITOR_REQ_CONSOLEKIT_REGISTER = 156, MONITOR_ANS_CONSOLEKIT_REGISTER = 157,
596+
597 };
598
599 struct mm_master;
600Index: b/monitor_wrap.c
601===================================================================
602--- a/monitor_wrap.c
603+++ b/monitor_wrap.c
604@@ -1516,3 +1516,34 @@
605 return success;
606 }
607 #endif /* JPAKE */
608+
609+#ifdef USE_CONSOLEKIT
610+char *
611+mm_consolekit_register(Session *s, const char *display)
612+{
613+ Buffer m;
614+ char *cookie;
615+
616+ debug3("%s entering", __func__);
617+
618+ if (s->ttyfd == -1)
619+ return NULL;
620+ buffer_init(&m);
621+ buffer_put_cstring(&m, s->tty);
622+ buffer_put_cstring(&m, display != NULL ? display : "");
623+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m);
624+ buffer_clear(&m);
625+
626+ mm_request_receive_expect(pmonitor->m_recvfd,
627+ MONITOR_ANS_CONSOLEKIT_REGISTER, &m);
628+ cookie = buffer_get_string(&m, NULL);
629+ buffer_free(&m);
630+
631+ /* treat empty cookie as missing cookie */
632+ if (strlen(cookie) == 0) {
633+ free(cookie);
634+ cookie = NULL;
635+ }
636+ return (cookie);
637+}
638+#endif /* USE_CONSOLEKIT */
639Index: b/monitor_wrap.h
640===================================================================
641--- a/monitor_wrap.h
642+++ b/monitor_wrap.h
643@@ -131,4 +131,8 @@
644 void mm_zfree(struct mm_master *, void *);
645 void mm_init_compression(struct mm_master *);
646
647+#ifdef USE_CONSOLEKIT
648+char *mm_consolekit_register(struct Session *, const char *);
649+#endif /* USE_CONSOLEKIT */
650+
651 #endif /* _MM_WRAP_H_ */
652Index: b/session.c
653===================================================================
654--- a/session.c
655+++ b/session.c
656@@ -92,6 +92,7 @@
657 #include "kex.h"
658 #include "monitor_wrap.h"
659 #include "sftp.h"
660+#include "consolekit.h"
661
662 #if defined(KRB5) && defined(USE_AFS)
663 #include <kafs.h>
664@@ -1132,6 +1133,9 @@
665 #if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
666 char *path = NULL;
667 #endif
668+#ifdef USE_CONSOLEKIT
669+ const char *ckcookie = NULL;
670+#endif /* USE_CONSOLEKIT */
671
672 /* Initialize the environment. */
673 envsize = 100;
674@@ -1276,6 +1280,11 @@
675 child_set_env(&env, &envsize, "KRB5CCNAME",
676 s->authctxt->krb5_ccname);
677 #endif
678+#ifdef USE_CONSOLEKIT
679+ ckcookie = PRIVSEP(consolekit_register(s, s->display));
680+ if (ckcookie)
681+ child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
682+#endif /* USE_CONSOLEKIT */
683 #ifdef USE_PAM
684 /*
685 * Pull in any environment variables that may have
686@@ -2320,6 +2329,10 @@
687
688 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
689
690+#ifdef USE_CONSOLEKIT
691+ consolekit_unregister(s);
692+#endif /* USE_CONSOLEKIT */
693+
694 /* Record that the user has logged out. */
695 if (s->pid != 0)
696 record_logout(s->pid, s->tty, s->pw->pw_name);
697Index: b/session.h
698===================================================================
699--- a/session.h
700+++ b/session.h
701@@ -26,6 +26,8 @@
702 #ifndef SESSION_H
703 #define SESSION_H
704
705+struct _CkConnector;
706+
707 #define TTYSZ 64
708 typedef struct Session Session;
709 struct Session {
710@@ -60,6 +62,10 @@
711 char *name;
712 char *val;
713 } *env;
714+
715+#ifdef USE_CONSOLEKIT
716+ struct _CkConnector *ckc;
717+#endif /* USE_CONSOLEKIT */
718 };
719
720 void do_authenticated(Authctxt *);