summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@ubuntu.com>2014-02-09 16:09:57 +0000
committerColin Watson <cjwatson@debian.org>2014-02-09 16:18:07 +0000
commitcfae2bfa1e95cbb6c7a9799f13b82e8e804ca869 (patch)
tree5ae83026d7665faa8bb594f63ffb30333b8ccd0f
parentea2e0af0bc3a683edb32b508c03eb793617f6f31 (diff)
Add support for registering ConsoleKit sessions on login
Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1450 Last-Updated: 2013-09-14 Patch-Name: consolekit.patch
-rw-r--r--Makefile.in3
-rwxr-xr-xconfigure132
-rw-r--r--configure.ac25
-rw-r--r--consolekit.c240
-rw-r--r--consolekit.h24
-rw-r--r--monitor.c43
-rw-r--r--monitor.h2
-rw-r--r--monitor_wrap.c31
-rw-r--r--monitor_wrap.h4
-rw-r--r--session.c13
-rw-r--r--session.h6
11 files changed, 522 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in
index b8f509941..ca6eee5a8 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -96,7 +96,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
96 sftp-server.o sftp-common.o \ 96 sftp-server.o sftp-common.o \
97 roaming_common.o roaming_serv.o \ 97 roaming_common.o roaming_serv.o \
98 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \ 98 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
99 sandbox-seccomp-filter.o 99 sandbox-seccomp-filter.o \
100 consolekit.o
100 101
101MANPAGES = 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 102MANPAGES = 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
102MANPAGES_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 103MANPAGES_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
diff --git a/configure b/configure
index ceb1b5d6d..78bbcd008 100755
--- a/configure
+++ b/configure
@@ -738,6 +738,7 @@ with_privsep_user
738with_sandbox 738with_sandbox
739with_selinux 739with_selinux
740with_kerberos5 740with_kerberos5
741with_consolekit
741with_privsep_path 742with_privsep_path
742with_xauth 743with_xauth
743enable_strip 744enable_strip
@@ -1428,6 +1429,7 @@ Optional Packages:
1428 --with-sandbox=style Specify privilege separation sandbox (no, darwin, rlimit, systrace, seccomp_filter) 1429 --with-sandbox=style Specify privilege separation sandbox (no, darwin, rlimit, systrace, seccomp_filter)
1429 --with-selinux Enable SELinux support 1430 --with-selinux Enable SELinux support
1430 --with-kerberos5=PATH Enable Kerberos 5 support 1431 --with-kerberos5=PATH Enable Kerberos 5 support
1432 --with-consolekit Enable ConsoleKit support
1431 --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty) 1433 --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty)
1432 --with-xauth=PATH Specify path to xauth program 1434 --with-xauth=PATH Specify path to xauth program
1433 --with-maildir=/path/to/mail Specify your system mail directory 1435 --with-maildir=/path/to/mail Specify your system mail directory
@@ -16375,6 +16377,135 @@ fi
16375 16377
16376 16378
16377 16379
16380# Check whether user wants ConsoleKit support
16381CONSOLEKIT_MSG="no"
16382LIBCK_CONNECTOR=""
16383
16384# Check whether --with-consolekit was given.
16385if test "${with_consolekit+set}" = set; then :
16386 withval=$with_consolekit; if test "x$withval" != "xno" ; then
16387 if test -n "$ac_tool_prefix"; then
16388 # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
16389set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
16390{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
16391$as_echo_n "checking for $ac_word... " >&6; }
16392if ${ac_cv_path_PKGCONFIG+:} false; then :
16393 $as_echo_n "(cached) " >&6
16394else
16395 case $PKGCONFIG in
16396 [\\/]* | ?:[\\/]*)
16397 ac_cv_path_PKGCONFIG="$PKGCONFIG" # Let the user override the test with a path.
16398 ;;
16399 *)
16400 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
16401for as_dir in $PATH
16402do
16403 IFS=$as_save_IFS
16404 test -z "$as_dir" && as_dir=.
16405 for ac_exec_ext in '' $ac_executable_extensions; do
16406 if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
16407 ac_cv_path_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
16408 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
16409 break 2
16410 fi
16411done
16412 done
16413IFS=$as_save_IFS
16414
16415 ;;
16416esac
16417fi
16418PKGCONFIG=$ac_cv_path_PKGCONFIG
16419if test -n "$PKGCONFIG"; then
16420 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5
16421$as_echo "$PKGCONFIG" >&6; }
16422else
16423 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
16424$as_echo "no" >&6; }
16425fi
16426
16427
16428fi
16429if test -z "$ac_cv_path_PKGCONFIG"; then
16430 ac_pt_PKGCONFIG=$PKGCONFIG
16431 # Extract the first word of "pkg-config", so it can be a program name with args.
16432set dummy pkg-config; ac_word=$2
16433{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
16434$as_echo_n "checking for $ac_word... " >&6; }
16435if ${ac_cv_path_ac_pt_PKGCONFIG+:} false; then :
16436 $as_echo_n "(cached) " >&6
16437else
16438 case $ac_pt_PKGCONFIG in
16439 [\\/]* | ?:[\\/]*)
16440 ac_cv_path_ac_pt_PKGCONFIG="$ac_pt_PKGCONFIG" # Let the user override the test with a path.
16441 ;;
16442 *)
16443 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
16444for as_dir in $PATH
16445do
16446 IFS=$as_save_IFS
16447 test -z "$as_dir" && as_dir=.
16448 for ac_exec_ext in '' $ac_executable_extensions; do
16449 if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
16450 ac_cv_path_ac_pt_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
16451 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
16452 break 2
16453 fi
16454done
16455 done
16456IFS=$as_save_IFS
16457
16458 ;;
16459esac
16460fi
16461ac_pt_PKGCONFIG=$ac_cv_path_ac_pt_PKGCONFIG
16462if test -n "$ac_pt_PKGCONFIG"; then
16463 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKGCONFIG" >&5
16464$as_echo "$ac_pt_PKGCONFIG" >&6; }
16465else
16466 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
16467$as_echo "no" >&6; }
16468fi
16469
16470 if test "x$ac_pt_PKGCONFIG" = x; then
16471 PKGCONFIG="no"
16472 else
16473 case $cross_compiling:$ac_tool_warned in
16474yes:)
16475{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
16476$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
16477ac_tool_warned=yes ;;
16478esac
16479 PKGCONFIG=$ac_pt_PKGCONFIG
16480 fi
16481else
16482 PKGCONFIG="$ac_cv_path_PKGCONFIG"
16483fi
16484
16485 if test "$PKGCONFIG" != "no"; then
16486 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ck-connector" >&5
16487$as_echo_n "checking for ck-connector... " >&6; }
16488 if $PKGCONFIG --exists ck-connector; then
16489 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
16490 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
16491 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
16492 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
16493 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
16494$as_echo "yes" >&6; }
16495
16496$as_echo "#define USE_CONSOLEKIT 1" >>confdefs.h
16497
16498 CONSOLEKIT_MSG="yes"
16499 else
16500 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
16501$as_echo "no" >&6; }
16502 fi
16503 fi
16504 fi
16505
16506fi
16507
16508
16378# Looking for programs, paths and files 16509# Looking for programs, paths and files
16379 16510
16380PRIVSEP_PATH=/var/empty 16511PRIVSEP_PATH=/var/empty
@@ -18902,6 +19033,7 @@ echo " MD5 password support: $MD5_MSG"
18902echo " libedit support: $LIBEDIT_MSG" 19033echo " libedit support: $LIBEDIT_MSG"
18903echo " Solaris process contract support: $SPC_MSG" 19034echo " Solaris process contract support: $SPC_MSG"
18904echo " Solaris project support: $SP_MSG" 19035echo " Solaris project support: $SP_MSG"
19036echo " ConsoleKit support: $CONSOLEKIT_MSG"
18905echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 19037echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
18906echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 19038echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
18907echo " BSD Auth support: $BSD_AUTH_MSG" 19039echo " BSD Auth support: $BSD_AUTH_MSG"
diff --git a/configure.ac b/configure.ac
index 4c1a6589e..d7d500a33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3841,6 +3841,30 @@ AC_ARG_WITH([kerberos5],
3841AC_SUBST([GSSLIBS]) 3841AC_SUBST([GSSLIBS])
3842AC_SUBST([K5LIBS]) 3842AC_SUBST([K5LIBS])
3843 3843
3844# Check whether user wants ConsoleKit support
3845CONSOLEKIT_MSG="no"
3846LIBCK_CONNECTOR=""
3847AC_ARG_WITH(consolekit,
3848 [ --with-consolekit Enable ConsoleKit support],
3849 [ if test "x$withval" != "xno" ; then
3850 AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
3851 if test "$PKGCONFIG" != "no"; then
3852 AC_MSG_CHECKING([for ck-connector])
3853 if $PKGCONFIG --exists ck-connector; then
3854 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
3855 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
3856 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
3857 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
3858 AC_MSG_RESULT([yes])
3859 AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.])
3860 CONSOLEKIT_MSG="yes"
3861 else
3862 AC_MSG_RESULT([no])
3863 fi
3864 fi
3865 fi ]
3866)
3867
3844# Looking for programs, paths and files 3868# Looking for programs, paths and files
3845 3869
3846PRIVSEP_PATH=/var/empty 3870PRIVSEP_PATH=/var/empty
@@ -4641,6 +4665,7 @@ echo " MD5 password support: $MD5_MSG"
4641echo " libedit support: $LIBEDIT_MSG" 4665echo " libedit support: $LIBEDIT_MSG"
4642echo " Solaris process contract support: $SPC_MSG" 4666echo " Solaris process contract support: $SPC_MSG"
4643echo " Solaris project support: $SP_MSG" 4667echo " Solaris project support: $SP_MSG"
4668echo " ConsoleKit support: $CONSOLEKIT_MSG"
4644echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 4669echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
4645echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 4670echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
4646echo " BSD Auth support: $BSD_AUTH_MSG" 4671echo " BSD Auth support: $BSD_AUTH_MSG"
diff --git a/consolekit.c b/consolekit.c
new file mode 100644
index 000000000..f1039e652
--- /dev/null
+++ b/consolekit.c
@@ -0,0 +1,240 @@
1/*
2 * Copyright (c) 2008 Colin Watson. All rights reserved.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/*
17 * Loosely based on pam-ck-connector, which is:
18 *
19 * Copyright (c) 2007 David Zeuthen <davidz@redhat.com>
20 *
21 * Permission is hereby granted, free of charge, to any person
22 * obtaining a copy of this software and associated documentation
23 * files (the "Software"), to deal in the Software without
24 * restriction, including without limitation the rights to use,
25 * copy, modify, merge, publish, distribute, sublicense, and/or sell
26 * copies of the Software, and to permit persons to whom the
27 * Software is furnished to do so, subject to the following
28 * conditions:
29 *
30 * The above copyright notice and this permission notice shall be
31 * included in all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
35 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
36 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
37 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
38 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
39 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
40 * OTHER DEALINGS IN THE SOFTWARE.
41 */
42
43#include "includes.h"
44
45#ifdef USE_CONSOLEKIT
46
47#include <ck-connector.h>
48
49#include "openbsd-compat/sys-queue.h"
50#include "xmalloc.h"
51#include "channels.h"
52#include "key.h"
53#include "hostfile.h"
54#include "auth.h"
55#include "log.h"
56#include "servconf.h"
57#include "canohost.h"
58#include "session.h"
59#include "consolekit.h"
60
61extern ServerOptions options;
62extern u_int utmp_len;
63
64void
65set_active(const char *cookie)
66{
67 DBusError err;
68 DBusConnection *connection;
69 DBusMessage *message = NULL, *reply = NULL;
70 char *sid;
71 DBusMessageIter iter, subiter;
72 const char *interface, *property;
73 dbus_bool_t active;
74
75 dbus_error_init(&err);
76 connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
77 if (!connection) {
78 if (dbus_error_is_set(&err)) {
79 error("unable to open DBus connection: %s",
80 err.message);
81 dbus_error_free(&err);
82 }
83 goto out;
84 }
85 dbus_connection_set_exit_on_disconnect(connection, FALSE);
86
87 message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
88 "/org/freedesktop/ConsoleKit/Manager",
89 "org.freedesktop.ConsoleKit.Manager",
90 "GetSessionForCookie");
91 if (!message)
92 goto out;
93 if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &cookie,
94 DBUS_TYPE_INVALID)) {
95 if (dbus_error_is_set(&err)) {
96 error("unable to get current session: %s",
97 err.message);
98 dbus_error_free(&err);
99 }
100 goto out;
101 }
102
103 dbus_error_init(&err);
104 reply = dbus_connection_send_with_reply_and_block(connection, message,
105 -1, &err);
106 if (!reply) {
107 if (dbus_error_is_set(&err)) {
108 error("unable to get current session: %s",
109 err.message);
110 dbus_error_free(&err);
111 }
112 goto out;
113 }
114
115 dbus_error_init(&err);
116 if (!dbus_message_get_args(reply, &err,
117 DBUS_TYPE_OBJECT_PATH, &sid,
118 DBUS_TYPE_INVALID)) {
119 if (dbus_error_is_set(&err)) {
120 error("unable to get current session: %s",
121 err.message);
122 dbus_error_free(&err);
123 }
124 goto out;
125 }
126 dbus_message_unref(reply);
127 dbus_message_unref(message);
128 message = reply = NULL;
129
130 message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
131 sid, "org.freedesktop.DBus.Properties", "Set");
132 if (!message)
133 goto out;
134 interface = "org.freedesktop.ConsoleKit.Session";
135 property = "active";
136 if (!dbus_message_append_args(message,
137 DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property,
138 DBUS_TYPE_INVALID))
139 goto out;
140 dbus_message_iter_init_append(message, &iter);
141 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
142 DBUS_TYPE_BOOLEAN_AS_STRING, &subiter))
143 goto out;
144 active = TRUE;
145 if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_BOOLEAN,
146 &active))
147 goto out;
148 if (!dbus_message_iter_close_container(&iter, &subiter))
149 goto out;
150
151 dbus_error_init(&err);
152 reply = dbus_connection_send_with_reply_and_block(connection, message,
153 -1, &err);
154 if (!reply) {
155 if (dbus_error_is_set(&err)) {
156 error("unable to make current session active: %s",
157 err.message);
158 dbus_error_free(&err);
159 }
160 goto out;
161 }
162
163out:
164 if (reply)
165 dbus_message_unref(reply);
166 if (message)
167 dbus_message_unref(message);
168}
169
170/*
171 * We pass display separately rather than using s->display because the
172 * latter is not available in the monitor when using privsep.
173 */
174
175char *
176consolekit_register(Session *s, const char *display)
177{
178 DBusError err;
179 const char *tty = s->tty;
180 const char *remote_host_name;
181 dbus_bool_t is_local = FALSE;
182 const char *cookie = NULL;
183
184 if (s->ckc) {
185 debug("already registered with ConsoleKit");
186 return xstrdup(ck_connector_get_cookie(s->ckc));
187 }
188
189 s->ckc = ck_connector_new();
190 if (!s->ckc) {
191 error("ck_connector_new failed");
192 return NULL;
193 }
194
195 if (!tty)
196 tty = "";
197 if (!display)
198 display = "";
199 remote_host_name = get_remote_name_or_ip(utmp_len, options.use_dns);
200 if (!remote_host_name)
201 remote_host_name = "";
202
203 dbus_error_init(&err);
204 if (!ck_connector_open_session_with_parameters(s->ckc, &err,
205 "unix-user", &s->pw->pw_uid,
206 "display-device", &tty,
207 "x11-display", &display,
208 "remote-host-name", &remote_host_name,
209 "is-local", &is_local,
210 NULL)) {
211 if (dbus_error_is_set(&err)) {
212 debug("%s", err.message);
213 dbus_error_free(&err);
214 } else {
215 debug("insufficient privileges or D-Bus / ConsoleKit "
216 "not available");
217 }
218 return NULL;
219 }
220
221 debug("registered uid=%d on tty='%s' with ConsoleKit",
222 s->pw->pw_uid, s->tty);
223
224 cookie = ck_connector_get_cookie(s->ckc);
225 set_active(cookie);
226 return xstrdup(cookie);
227}
228
229void
230consolekit_unregister(Session *s)
231{
232 if (s->ckc) {
233 debug("unregistering ConsoleKit session %s",
234 ck_connector_get_cookie(s->ckc));
235 ck_connector_unref(s->ckc);
236 s->ckc = NULL;
237 }
238}
239
240#endif /* USE_CONSOLEKIT */
diff --git a/consolekit.h b/consolekit.h
new file mode 100644
index 000000000..8ce371690
--- /dev/null
+++ b/consolekit.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (c) 2008 Colin Watson. All rights reserved.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifdef USE_CONSOLEKIT
18
19struct Session;
20
21char * consolekit_register(struct Session *, const char *);
22void consolekit_unregister(struct Session *);
23
24#endif /* USE_CONSOLEKIT */
diff --git a/monitor.c b/monitor.c
index e8d63eb22..9bc4f0b2e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -98,6 +98,9 @@
98#include "jpake.h" 98#include "jpake.h"
99#include "roaming.h" 99#include "roaming.h"
100#include "authfd.h" 100#include "authfd.h"
101#ifdef USE_CONSOLEKIT
102#include "consolekit.h"
103#endif
101 104
102#ifdef GSSAPI 105#ifdef GSSAPI
103static Gssctxt *gsscontext = NULL; 106static Gssctxt *gsscontext = NULL;
@@ -193,6 +196,10 @@ int mm_answer_audit_command(int, Buffer *);
193 196
194static int monitor_read_log(struct monitor *); 197static int monitor_read_log(struct monitor *);
195 198
199#ifdef USE_CONSOLEKIT
200int mm_answer_consolekit_register(int, Buffer *);
201#endif
202
196static Authctxt *authctxt; 203static Authctxt *authctxt;
197static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */ 204static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
198 205
@@ -285,6 +292,9 @@ struct mon_table mon_dispatch_postauth20[] = {
285 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, 292 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
286 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command}, 293 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
287#endif 294#endif
295#ifdef USE_CONSOLEKIT
296 {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
297#endif
288 {0, 0, NULL} 298 {0, 0, NULL}
289}; 299};
290 300
@@ -327,6 +337,9 @@ struct mon_table mon_dispatch_postauth15[] = {
327 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, 337 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
328 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command}, 338 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
329#endif 339#endif
340#ifdef USE_CONSOLEKIT
341 {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
342#endif
330 {0, 0, NULL} 343 {0, 0, NULL}
331}; 344};
332 345
@@ -514,6 +527,9 @@ monitor_child_postauth(struct monitor *pmonitor)
514 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); 527 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
515 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1); 528 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
516 } 529 }
530#ifdef USE_CONSOLEKIT
531 monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1);
532#endif
517 533
518 for (;;) 534 for (;;)
519 monitor_read(pmonitor, mon_dispatch, NULL); 535 monitor_read(pmonitor, mon_dispatch, NULL);
@@ -2492,3 +2508,30 @@ mm_answer_jpake_check_confirm(int sock, Buffer *m)
2492} 2508}
2493 2509
2494#endif /* JPAKE */ 2510#endif /* JPAKE */
2511
2512#ifdef USE_CONSOLEKIT
2513int
2514mm_answer_consolekit_register(int sock, Buffer *m)
2515{
2516 Session *s;
2517 char *tty, *display;
2518 char *cookie = NULL;
2519
2520 debug3("%s entering", __func__);
2521
2522 tty = buffer_get_string(m, NULL);
2523 display = buffer_get_string(m, NULL);
2524 s = session_by_tty(tty);
2525 if (s != NULL)
2526 cookie = consolekit_register(s, display);
2527 buffer_clear(m);
2528 buffer_put_cstring(m, cookie != NULL ? cookie : "");
2529 mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m);
2530
2531 free(cookie);
2532 free(display);
2533 free(tty);
2534
2535 return (0);
2536}
2537#endif /* USE_CONSOLEKIT */
diff --git a/monitor.h b/monitor.h
index 3c13706a8..cd8342823 100644
--- a/monitor.h
+++ b/monitor.h
@@ -75,6 +75,8 @@ enum monitor_reqtype {
75 75
76 MONITOR_REQ_AUTHROLE = 154, 76 MONITOR_REQ_AUTHROLE = 154,
77 77
78 MONITOR_REQ_CONSOLEKIT_REGISTER = 156, MONITOR_ANS_CONSOLEKIT_REGISTER = 157,
79
78}; 80};
79 81
80struct mm_master; 82struct mm_master;
diff --git a/monitor_wrap.c b/monitor_wrap.c
index 69bc324b5..670b62dfb 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -1516,3 +1516,34 @@ mm_jpake_check_confirm(const BIGNUM *k,
1516 return success; 1516 return success;
1517} 1517}
1518#endif /* JPAKE */ 1518#endif /* JPAKE */
1519
1520#ifdef USE_CONSOLEKIT
1521char *
1522mm_consolekit_register(Session *s, const char *display)
1523{
1524 Buffer m;
1525 char *cookie;
1526
1527 debug3("%s entering", __func__);
1528
1529 if (s->ttyfd == -1)
1530 return NULL;
1531 buffer_init(&m);
1532 buffer_put_cstring(&m, s->tty);
1533 buffer_put_cstring(&m, display != NULL ? display : "");
1534 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m);
1535 buffer_clear(&m);
1536
1537 mm_request_receive_expect(pmonitor->m_recvfd,
1538 MONITOR_ANS_CONSOLEKIT_REGISTER, &m);
1539 cookie = buffer_get_string(&m, NULL);
1540 buffer_free(&m);
1541
1542 /* treat empty cookie as missing cookie */
1543 if (strlen(cookie) == 0) {
1544 free(cookie);
1545 cookie = NULL;
1546 }
1547 return (cookie);
1548}
1549#endif /* USE_CONSOLEKIT */
diff --git a/monitor_wrap.h b/monitor_wrap.h
index 4d12e2956..360fb9f57 100644
--- a/monitor_wrap.h
+++ b/monitor_wrap.h
@@ -131,4 +131,8 @@ void *mm_zalloc(struct mm_master *, u_int, u_int);
131void mm_zfree(struct mm_master *, void *); 131void mm_zfree(struct mm_master *, void *);
132void mm_init_compression(struct mm_master *); 132void mm_init_compression(struct mm_master *);
133 133
134#ifdef USE_CONSOLEKIT
135char *mm_consolekit_register(struct Session *, const char *);
136#endif /* USE_CONSOLEKIT */
137
134#endif /* _MM_WRAP_H_ */ 138#endif /* _MM_WRAP_H_ */
diff --git a/session.c b/session.c
index b4d74d984..15bdb1bee 100644
--- a/session.c
+++ b/session.c
@@ -92,6 +92,7 @@
92#include "kex.h" 92#include "kex.h"
93#include "monitor_wrap.h" 93#include "monitor_wrap.h"
94#include "sftp.h" 94#include "sftp.h"
95#include "consolekit.h"
95 96
96#if defined(KRB5) && defined(USE_AFS) 97#if defined(KRB5) && defined(USE_AFS)
97#include <kafs.h> 98#include <kafs.h>
@@ -1132,6 +1133,9 @@ do_setup_env(Session *s, const char *shell)
1132#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN) 1133#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
1133 char *path = NULL; 1134 char *path = NULL;
1134#endif 1135#endif
1136#ifdef USE_CONSOLEKIT
1137 const char *ckcookie = NULL;
1138#endif /* USE_CONSOLEKIT */
1135 1139
1136 /* Initialize the environment. */ 1140 /* Initialize the environment. */
1137 envsize = 100; 1141 envsize = 100;
@@ -1276,6 +1280,11 @@ do_setup_env(Session *s, const char *shell)
1276 child_set_env(&env, &envsize, "KRB5CCNAME", 1280 child_set_env(&env, &envsize, "KRB5CCNAME",
1277 s->authctxt->krb5_ccname); 1281 s->authctxt->krb5_ccname);
1278#endif 1282#endif
1283#ifdef USE_CONSOLEKIT
1284 ckcookie = PRIVSEP(consolekit_register(s, s->display));
1285 if (ckcookie)
1286 child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
1287#endif /* USE_CONSOLEKIT */
1279#ifdef USE_PAM 1288#ifdef USE_PAM
1280 /* 1289 /*
1281 * Pull in any environment variables that may have 1290 * Pull in any environment variables that may have
@@ -2320,6 +2329,10 @@ session_pty_cleanup2(Session *s)
2320 2329
2321 debug("session_pty_cleanup: session %d release %s", s->self, s->tty); 2330 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
2322 2331
2332#ifdef USE_CONSOLEKIT
2333 consolekit_unregister(s);
2334#endif /* USE_CONSOLEKIT */
2335
2323 /* Record that the user has logged out. */ 2336 /* Record that the user has logged out. */
2324 if (s->pid != 0) 2337 if (s->pid != 0)
2325 record_logout(s->pid, s->tty, s->pw->pw_name); 2338 record_logout(s->pid, s->tty, s->pw->pw_name);
diff --git a/session.h b/session.h
index cb4f19600..7e51b6ae1 100644
--- a/session.h
+++ b/session.h
@@ -26,6 +26,8 @@
26#ifndef SESSION_H 26#ifndef SESSION_H
27#define SESSION_H 27#define SESSION_H
28 28
29struct _CkConnector;
30
29#define TTYSZ 64 31#define TTYSZ 64
30typedef struct Session Session; 32typedef struct Session Session;
31struct Session { 33struct Session {
@@ -60,6 +62,10 @@ struct Session {
60 char *name; 62 char *name;
61 char *val; 63 char *val;
62 } *env; 64 } *env;
65
66#ifdef USE_CONSOLEKIT
67 struct _CkConnector *ckc;
68#endif /* USE_CONSOLEKIT */
63}; 69};
64 70
65void do_authenticated(Authctxt *); 71void do_authenticated(Authctxt *);