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