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.patch741
1 files changed, 741 insertions, 0 deletions
diff --git a/debian/patches/consolekit.patch b/debian/patches/consolekit.patch
new file mode 100644
index 000000000..e50c77f62
--- /dev/null
+++ b/debian/patches/consolekit.patch
@@ -0,0 +1,741 @@
1From f51fe0c55e54c12db952624e980d18f39c41e581 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: 2014-10-07
8
9Patch-Name: consolekit.patch
10---
11 Makefile.in | 3 +-
12 configure | 132 +++++++++++++++++++++++++++++++
13 configure.ac | 25 ++++++
14 consolekit.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 consolekit.h | 24 ++++++
16 monitor.c | 42 ++++++++++
17 monitor.h | 2 +
18 monitor_wrap.c | 30 +++++++
19 monitor_wrap.h | 4 +
20 session.c | 13 ++++
21 session.h | 6 ++
22 11 files changed, 521 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 086d8dd..c4cb8ea 100644
28--- a/Makefile.in
29+++ b/Makefile.in
30@@ -107,7 +107,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 ea5f200..7be478a 100755
42--- a/configure
43+++ b/configure
44@@ -739,6 +739,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@@ -1430,6 +1431,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@@ -17211,6 +17213,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@@ -19739,6 +19870,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 7f160f1..f5c65c5 100644
206--- a/configure.ac
207+++ b/configure.ac
208@@ -4113,6 +4113,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@@ -4914,6 +4938,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..0266f06
250--- /dev/null
251+++ b/consolekit.c
252@@ -0,0 +1,241 @@
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 "misc.h"
309+#include "servconf.h"
310+#include "canohost.h"
311+#include "session.h"
312+#include "consolekit.h"
313+
314+extern ServerOptions options;
315+extern u_int utmp_len;
316+
317+void
318+set_active(const char *cookie)
319+{
320+ DBusError err;
321+ DBusConnection *connection;
322+ DBusMessage *message = NULL, *reply = NULL;
323+ char *sid;
324+ DBusMessageIter iter, subiter;
325+ const char *interface, *property;
326+ dbus_bool_t active;
327+
328+ dbus_error_init(&err);
329+ connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
330+ if (!connection) {
331+ if (dbus_error_is_set(&err)) {
332+ error("unable to open DBus connection: %s",
333+ err.message);
334+ dbus_error_free(&err);
335+ }
336+ goto out;
337+ }
338+ dbus_connection_set_exit_on_disconnect(connection, FALSE);
339+
340+ message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
341+ "/org/freedesktop/ConsoleKit/Manager",
342+ "org.freedesktop.ConsoleKit.Manager",
343+ "GetSessionForCookie");
344+ if (!message)
345+ goto out;
346+ if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &cookie,
347+ DBUS_TYPE_INVALID)) {
348+ if (dbus_error_is_set(&err)) {
349+ error("unable to get current session: %s",
350+ err.message);
351+ dbus_error_free(&err);
352+ }
353+ goto out;
354+ }
355+
356+ dbus_error_init(&err);
357+ reply = dbus_connection_send_with_reply_and_block(connection, message,
358+ -1, &err);
359+ if (!reply) {
360+ if (dbus_error_is_set(&err)) {
361+ error("unable to get current session: %s",
362+ err.message);
363+ dbus_error_free(&err);
364+ }
365+ goto out;
366+ }
367+
368+ dbus_error_init(&err);
369+ if (!dbus_message_get_args(reply, &err,
370+ DBUS_TYPE_OBJECT_PATH, &sid,
371+ DBUS_TYPE_INVALID)) {
372+ if (dbus_error_is_set(&err)) {
373+ error("unable to get current session: %s",
374+ err.message);
375+ dbus_error_free(&err);
376+ }
377+ goto out;
378+ }
379+ dbus_message_unref(reply);
380+ dbus_message_unref(message);
381+ message = reply = NULL;
382+
383+ message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
384+ sid, "org.freedesktop.DBus.Properties", "Set");
385+ if (!message)
386+ goto out;
387+ interface = "org.freedesktop.ConsoleKit.Session";
388+ property = "active";
389+ if (!dbus_message_append_args(message,
390+ DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property,
391+ DBUS_TYPE_INVALID))
392+ goto out;
393+ dbus_message_iter_init_append(message, &iter);
394+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
395+ DBUS_TYPE_BOOLEAN_AS_STRING, &subiter))
396+ goto out;
397+ active = TRUE;
398+ if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_BOOLEAN,
399+ &active))
400+ goto out;
401+ if (!dbus_message_iter_close_container(&iter, &subiter))
402+ goto out;
403+
404+ dbus_error_init(&err);
405+ reply = dbus_connection_send_with_reply_and_block(connection, message,
406+ -1, &err);
407+ if (!reply) {
408+ if (dbus_error_is_set(&err)) {
409+ error("unable to make current session active: %s",
410+ err.message);
411+ dbus_error_free(&err);
412+ }
413+ goto out;
414+ }
415+
416+out:
417+ if (reply)
418+ dbus_message_unref(reply);
419+ if (message)
420+ dbus_message_unref(message);
421+}
422+
423+/*
424+ * We pass display separately rather than using s->display because the
425+ * latter is not available in the monitor when using privsep.
426+ */
427+
428+char *
429+consolekit_register(Session *s, const char *display)
430+{
431+ DBusError err;
432+ const char *tty = s->tty;
433+ const char *remote_host_name;
434+ dbus_bool_t is_local = FALSE;
435+ const char *cookie = NULL;
436+
437+ if (s->ckc) {
438+ debug("already registered with ConsoleKit");
439+ return xstrdup(ck_connector_get_cookie(s->ckc));
440+ }
441+
442+ s->ckc = ck_connector_new();
443+ if (!s->ckc) {
444+ error("ck_connector_new failed");
445+ return NULL;
446+ }
447+
448+ if (!tty)
449+ tty = "";
450+ if (!display)
451+ display = "";
452+ remote_host_name = get_remote_name_or_ip(utmp_len, options.use_dns);
453+ if (!remote_host_name)
454+ remote_host_name = "";
455+
456+ dbus_error_init(&err);
457+ if (!ck_connector_open_session_with_parameters(s->ckc, &err,
458+ "unix-user", &s->pw->pw_uid,
459+ "display-device", &tty,
460+ "x11-display", &display,
461+ "remote-host-name", &remote_host_name,
462+ "is-local", &is_local,
463+ NULL)) {
464+ if (dbus_error_is_set(&err)) {
465+ debug("%s", err.message);
466+ dbus_error_free(&err);
467+ } else {
468+ debug("insufficient privileges or D-Bus / ConsoleKit "
469+ "not available");
470+ }
471+ return NULL;
472+ }
473+
474+ debug("registered uid=%d on tty='%s' with ConsoleKit",
475+ s->pw->pw_uid, s->tty);
476+
477+ cookie = ck_connector_get_cookie(s->ckc);
478+ set_active(cookie);
479+ return xstrdup(cookie);
480+}
481+
482+void
483+consolekit_unregister(Session *s)
484+{
485+ if (s->ckc) {
486+ debug("unregistering ConsoleKit session %s",
487+ ck_connector_get_cookie(s->ckc));
488+ ck_connector_unref(s->ckc);
489+ s->ckc = NULL;
490+ }
491+}
492+
493+#endif /* USE_CONSOLEKIT */
494diff --git a/consolekit.h b/consolekit.h
495new file mode 100644
496index 0000000..8ce3716
497--- /dev/null
498+++ b/consolekit.h
499@@ -0,0 +1,24 @@
500+/*
501+ * Copyright (c) 2008 Colin Watson. All rights reserved.
502+ *
503+ * Permission to use, copy, modify, and distribute this software for any
504+ * purpose with or without fee is hereby granted, provided that the above
505+ * copyright notice and this permission notice appear in all copies.
506+ *
507+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
508+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
509+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
510+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
511+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
512+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
513+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
514+ */
515+
516+#ifdef USE_CONSOLEKIT
517+
518+struct Session;
519+
520+char * consolekit_register(struct Session *, const char *);
521+void consolekit_unregister(struct Session *);
522+
523+#endif /* USE_CONSOLEKIT */
524diff --git a/monitor.c b/monitor.c
525index 94b194d..cc15ce4 100644
526--- a/monitor.c
527+++ b/monitor.c
528@@ -100,6 +100,9 @@
529 #include "ssh2.h"
530 #include "roaming.h"
531 #include "authfd.h"
532+#ifdef USE_CONSOLEKIT
533+#include "consolekit.h"
534+#endif
535
536 #ifdef GSSAPI
537 static Gssctxt *gsscontext = NULL;
538@@ -190,6 +193,10 @@ int mm_answer_audit_command(int, Buffer *);
539
540 static int monitor_read_log(struct monitor *);
541
542+#ifdef USE_CONSOLEKIT
543+int mm_answer_consolekit_register(int, Buffer *);
544+#endif
545+
546 static Authctxt *authctxt;
547
548 #ifdef WITH_SSH1
549@@ -282,6 +289,9 @@ struct mon_table mon_dispatch_postauth20[] = {
550 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
551 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
552 #endif
553+#ifdef USE_CONSOLEKIT
554+ {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
555+#endif
556 {0, 0, NULL}
557 };
558
559@@ -327,6 +337,9 @@ struct mon_table mon_dispatch_postauth15[] = {
560 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
561 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
562 #endif
563+#ifdef USE_CONSOLEKIT
564+ {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
565+#endif
566 #endif /* WITH_SSH1 */
567 {0, 0, NULL}
568 };
569@@ -509,6 +522,9 @@ monitor_child_postauth(struct monitor *pmonitor)
570 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
571 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
572 }
573+#ifdef USE_CONSOLEKIT
574+ monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1);
575+#endif
576
577 for (;;)
578 monitor_read(pmonitor, mon_dispatch, NULL);
579@@ -2296,3 +2312,29 @@ mm_answer_gss_updatecreds(int socket, Buffer *m) {
580
581 #endif /* GSSAPI */
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 4d5e8fa..10ba59e 100644
611--- a/monitor.h
612+++ b/monitor.h
613@@ -70,6 +70,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 6dc890a..4c57d4d 100644
624--- a/monitor_wrap.c
625+++ b/monitor_wrap.c
626@@ -1363,3 +1363,33 @@ mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
627
628 #endif /* GSSAPI */
629
630+#ifdef USE_CONSOLEKIT
631+char *
632+mm_consolekit_register(Session *s, const char *display)
633+{
634+ Buffer m;
635+ char *cookie;
636+
637+ debug3("%s entering", __func__);
638+
639+ if (s->ttyfd == -1)
640+ return NULL;
641+ buffer_init(&m);
642+ buffer_put_cstring(&m, s->tty);
643+ buffer_put_cstring(&m, display != NULL ? display : "");
644+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m);
645+ buffer_clear(&m);
646+
647+ mm_request_receive_expect(pmonitor->m_recvfd,
648+ MONITOR_ANS_CONSOLEKIT_REGISTER, &m);
649+ cookie = buffer_get_string(&m, NULL);
650+ buffer_free(&m);
651+
652+ /* treat empty cookie as missing cookie */
653+ if (strlen(cookie) == 0) {
654+ free(cookie);
655+ cookie = NULL;
656+ }
657+ return (cookie);
658+}
659+#endif /* USE_CONSOLEKIT */
660diff --git a/monitor_wrap.h b/monitor_wrap.h
661index 9c2ee49..00e93fe 100644
662--- a/monitor_wrap.h
663+++ b/monitor_wrap.h
664@@ -111,4 +111,8 @@ void *mm_zalloc(struct mm_master *, u_int, u_int);
665 void mm_zfree(struct mm_master *, void *);
666 void mm_init_compression(struct mm_master *);
667
668+#ifdef USE_CONSOLEKIT
669+char *mm_consolekit_register(struct Session *, const char *);
670+#endif /* USE_CONSOLEKIT */
671+
672 #endif /* _MM_WRAP_H_ */
673diff --git a/session.c b/session.c
674index 6f389ac..6250c20 100644
675--- a/session.c
676+++ b/session.c
677@@ -93,6 +93,7 @@
678 #include "kex.h"
679 #include "monitor_wrap.h"
680 #include "sftp.h"
681+#include "consolekit.h"
682
683 #if defined(KRB5) && defined(USE_AFS)
684 #include <kafs.h>
685@@ -1143,6 +1144,9 @@ do_setup_env(Session *s, const char *shell)
686 #if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
687 char *path = NULL;
688 #endif
689+#ifdef USE_CONSOLEKIT
690+ const char *ckcookie = NULL;
691+#endif /* USE_CONSOLEKIT */
692
693 /* Initialize the environment. */
694 envsize = 100;
695@@ -1287,6 +1291,11 @@ do_setup_env(Session *s, const char *shell)
696 child_set_env(&env, &envsize, "KRB5CCNAME",
697 s->authctxt->krb5_ccname);
698 #endif
699+#ifdef USE_CONSOLEKIT
700+ ckcookie = PRIVSEP(consolekit_register(s, s->display));
701+ if (ckcookie)
702+ child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
703+#endif /* USE_CONSOLEKIT */
704 #ifdef USE_PAM
705 /*
706 * Pull in any environment variables that may have
707@@ -2350,6 +2359,10 @@ session_pty_cleanup2(Session *s)
708
709 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
710
711+#ifdef USE_CONSOLEKIT
712+ consolekit_unregister(s);
713+#endif /* USE_CONSOLEKIT */
714+
715 /* Record that the user has logged out. */
716 if (s->pid != 0)
717 record_logout(s->pid, s->tty, s->pw->pw_name);
718diff --git a/session.h b/session.h
719index ef6593c..a6b6983 100644
720--- a/session.h
721+++ b/session.h
722@@ -26,6 +26,8 @@
723 #ifndef SESSION_H
724 #define SESSION_H
725
726+struct _CkConnector;
727+
728 #define TTYSZ 64
729 typedef struct Session Session;
730 struct Session {
731@@ -61,6 +63,10 @@ struct Session {
732 char *name;
733 char *val;
734 } *env;
735+
736+#ifdef USE_CONSOLEKIT
737+ struct _CkConnector *ckc;
738+#endif /* USE_CONSOLEKIT */
739 };
740
741 void do_authenticated(Authctxt *);