summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@ubuntu.com>2014-02-09 16:09:57 +0000
committerColin Watson <cjwatson@debian.org>2014-03-20 00:32:21 +0000
commit7a26d16efb4ee303c8d66ee82caf9d0686f4a074 (patch)
tree131e8962617e1f41402ba2468ad331dd888c101a
parentef912859a4300360164292abe47b5516c8ee4a13 (diff)
Add support for registering ConsoleKit sessions on login
Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1450 Last-Updated: 2014-03-20 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.c42
-rw-r--r--monitor.h2
-rw-r--r--monitor_wrap.c30
-rw-r--r--monitor_wrap.h4
-rw-r--r--session.c13
-rw-r--r--session.h6
11 files changed, 520 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in
index ee1d2c3b8..3d96c0550 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -97,7 +97,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
97 sftp-server.o sftp-common.o \ 97 sftp-server.o sftp-common.o \
98 roaming_common.o roaming_serv.o \ 98 roaming_common.o roaming_serv.o \
99 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \ 99 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
100 sandbox-seccomp-filter.o sandbox-capsicum.o 100 sandbox-seccomp-filter.o sandbox-capsicum.o \
101 consolekit.o
101 102
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 sshd_config.5.out ssh_config.5.out 103MANPAGES = 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
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 sshd_config.5 ssh_config.5 104MANPAGES_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
diff --git a/configure b/configure
index b6b5b6d8d..e2f12cdff 100755
--- a/configure
+++ b/configure
@@ -740,6 +740,7 @@ with_privsep_user
740with_sandbox 740with_sandbox
741with_selinux 741with_selinux
742with_kerberos5 742with_kerberos5
743with_consolekit
743with_privsep_path 744with_privsep_path
744with_xauth 745with_xauth
745enable_strip 746enable_strip
@@ -1432,6 +1433,7 @@ Optional Packages:
1432 --with-sandbox=style Specify privilege separation sandbox (no, darwin, rlimit, systrace, seccomp_filter, capsicum) 1433 --with-sandbox=style Specify privilege separation sandbox (no, darwin, rlimit, systrace, seccomp_filter, capsicum)
1433 --with-selinux Enable SELinux support 1434 --with-selinux Enable SELinux support
1434 --with-kerberos5=PATH Enable Kerberos 5 support 1435 --with-kerberos5=PATH Enable Kerberos 5 support
1436 --with-consolekit Enable ConsoleKit support
1435 --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty) 1437 --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty)
1436 --with-xauth=PATH Specify path to xauth program 1438 --with-xauth=PATH Specify path to xauth program
1437 --with-maildir=/path/to/mail Specify your system mail directory 1439 --with-maildir=/path/to/mail Specify your system mail directory
@@ -17217,6 +17219,135 @@ fi
17217 17219
17218 17220
17219 17221
17222# Check whether user wants ConsoleKit support
17223CONSOLEKIT_MSG="no"
17224LIBCK_CONNECTOR=""
17225
17226# Check whether --with-consolekit was given.
17227if test "${with_consolekit+set}" = set; then :
17228 withval=$with_consolekit; if test "x$withval" != "xno" ; then
17229 if test -n "$ac_tool_prefix"; then
17230 # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
17231set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
17232{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
17233$as_echo_n "checking for $ac_word... " >&6; }
17234if ${ac_cv_path_PKGCONFIG+:} false; then :
17235 $as_echo_n "(cached) " >&6
17236else
17237 case $PKGCONFIG in
17238 [\\/]* | ?:[\\/]*)
17239 ac_cv_path_PKGCONFIG="$PKGCONFIG" # Let the user override the test with a path.
17240 ;;
17241 *)
17242 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
17243for as_dir in $PATH
17244do
17245 IFS=$as_save_IFS
17246 test -z "$as_dir" && as_dir=.
17247 for ac_exec_ext in '' $ac_executable_extensions; do
17248 if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
17249 ac_cv_path_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
17250 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
17251 break 2
17252 fi
17253done
17254 done
17255IFS=$as_save_IFS
17256
17257 ;;
17258esac
17259fi
17260PKGCONFIG=$ac_cv_path_PKGCONFIG
17261if test -n "$PKGCONFIG"; then
17262 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5
17263$as_echo "$PKGCONFIG" >&6; }
17264else
17265 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17266$as_echo "no" >&6; }
17267fi
17268
17269
17270fi
17271if test -z "$ac_cv_path_PKGCONFIG"; then
17272 ac_pt_PKGCONFIG=$PKGCONFIG
17273 # Extract the first word of "pkg-config", so it can be a program name with args.
17274set dummy pkg-config; ac_word=$2
17275{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
17276$as_echo_n "checking for $ac_word... " >&6; }
17277if ${ac_cv_path_ac_pt_PKGCONFIG+:} false; then :
17278 $as_echo_n "(cached) " >&6
17279else
17280 case $ac_pt_PKGCONFIG in
17281 [\\/]* | ?:[\\/]*)
17282 ac_cv_path_ac_pt_PKGCONFIG="$ac_pt_PKGCONFIG" # Let the user override the test with a path.
17283 ;;
17284 *)
17285 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
17286for as_dir in $PATH
17287do
17288 IFS=$as_save_IFS
17289 test -z "$as_dir" && as_dir=.
17290 for ac_exec_ext in '' $ac_executable_extensions; do
17291 if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
17292 ac_cv_path_ac_pt_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
17293 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
17294 break 2
17295 fi
17296done
17297 done
17298IFS=$as_save_IFS
17299
17300 ;;
17301esac
17302fi
17303ac_pt_PKGCONFIG=$ac_cv_path_ac_pt_PKGCONFIG
17304if test -n "$ac_pt_PKGCONFIG"; then
17305 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKGCONFIG" >&5
17306$as_echo "$ac_pt_PKGCONFIG" >&6; }
17307else
17308 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17309$as_echo "no" >&6; }
17310fi
17311
17312 if test "x$ac_pt_PKGCONFIG" = x; then
17313 PKGCONFIG="no"
17314 else
17315 case $cross_compiling:$ac_tool_warned in
17316yes:)
17317{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
17318$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
17319ac_tool_warned=yes ;;
17320esac
17321 PKGCONFIG=$ac_pt_PKGCONFIG
17322 fi
17323else
17324 PKGCONFIG="$ac_cv_path_PKGCONFIG"
17325fi
17326
17327 if test "$PKGCONFIG" != "no"; then
17328 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ck-connector" >&5
17329$as_echo_n "checking for ck-connector... " >&6; }
17330 if $PKGCONFIG --exists ck-connector; then
17331 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
17332 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
17333 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
17334 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
17335 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17336$as_echo "yes" >&6; }
17337
17338$as_echo "#define USE_CONSOLEKIT 1" >>confdefs.h
17339
17340 CONSOLEKIT_MSG="yes"
17341 else
17342 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17343$as_echo "no" >&6; }
17344 fi
17345 fi
17346 fi
17347
17348fi
17349
17350
17220# Looking for programs, paths and files 17351# Looking for programs, paths and files
17221 17352
17222PRIVSEP_PATH=/var/empty 17353PRIVSEP_PATH=/var/empty
@@ -19746,6 +19877,7 @@ echo " MD5 password support: $MD5_MSG"
19746echo " libedit support: $LIBEDIT_MSG" 19877echo " libedit support: $LIBEDIT_MSG"
19747echo " Solaris process contract support: $SPC_MSG" 19878echo " Solaris process contract support: $SPC_MSG"
19748echo " Solaris project support: $SP_MSG" 19879echo " Solaris project support: $SP_MSG"
19880echo " ConsoleKit support: $CONSOLEKIT_MSG"
19749echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 19881echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
19750echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 19882echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
19751echo " BSD Auth support: $BSD_AUTH_MSG" 19883echo " BSD Auth support: $BSD_AUTH_MSG"
diff --git a/configure.ac b/configure.ac
index d235fb06b..86692714b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4072,6 +4072,30 @@ AC_ARG_WITH([kerberos5],
4072AC_SUBST([GSSLIBS]) 4072AC_SUBST([GSSLIBS])
4073AC_SUBST([K5LIBS]) 4073AC_SUBST([K5LIBS])
4074 4074
4075# Check whether user wants ConsoleKit support
4076CONSOLEKIT_MSG="no"
4077LIBCK_CONNECTOR=""
4078AC_ARG_WITH(consolekit,
4079 [ --with-consolekit Enable ConsoleKit support],
4080 [ if test "x$withval" != "xno" ; then
4081 AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
4082 if test "$PKGCONFIG" != "no"; then
4083 AC_MSG_CHECKING([for ck-connector])
4084 if $PKGCONFIG --exists ck-connector; then
4085 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
4086 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
4087 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
4088 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
4089 AC_MSG_RESULT([yes])
4090 AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.])
4091 CONSOLEKIT_MSG="yes"
4092 else
4093 AC_MSG_RESULT([no])
4094 fi
4095 fi
4096 fi ]
4097)
4098
4075# Looking for programs, paths and files 4099# Looking for programs, paths and files
4076 4100
4077PRIVSEP_PATH=/var/empty 4101PRIVSEP_PATH=/var/empty
@@ -4873,6 +4897,7 @@ echo " MD5 password support: $MD5_MSG"
4873echo " libedit support: $LIBEDIT_MSG" 4897echo " libedit support: $LIBEDIT_MSG"
4874echo " Solaris process contract support: $SPC_MSG" 4898echo " Solaris process contract support: $SPC_MSG"
4875echo " Solaris project support: $SP_MSG" 4899echo " Solaris project support: $SP_MSG"
4900echo " ConsoleKit support: $CONSOLEKIT_MSG"
4876echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 4901echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
4877echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 4902echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
4878echo " BSD Auth support: $BSD_AUTH_MSG" 4903echo " 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 11eac63c2..7c105e687 100644
--- a/monitor.c
+++ b/monitor.c
@@ -97,6 +97,9 @@
97#include "ssh2.h" 97#include "ssh2.h"
98#include "roaming.h" 98#include "roaming.h"
99#include "authfd.h" 99#include "authfd.h"
100#ifdef USE_CONSOLEKIT
101#include "consolekit.h"
102#endif
100 103
101#ifdef GSSAPI 104#ifdef GSSAPI
102static Gssctxt *gsscontext = NULL; 105static Gssctxt *gsscontext = NULL;
@@ -187,6 +190,10 @@ int mm_answer_audit_command(int, Buffer *);
187 190
188static int monitor_read_log(struct monitor *); 191static int monitor_read_log(struct monitor *);
189 192
193#ifdef USE_CONSOLEKIT
194int mm_answer_consolekit_register(int, Buffer *);
195#endif
196
190static Authctxt *authctxt; 197static Authctxt *authctxt;
191static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */ 198static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
192 199
@@ -272,6 +279,9 @@ struct mon_table mon_dispatch_postauth20[] = {
272 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, 279 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
273 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command}, 280 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
274#endif 281#endif
282#ifdef USE_CONSOLEKIT
283 {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
284#endif
275 {0, 0, NULL} 285 {0, 0, NULL}
276}; 286};
277 287
@@ -314,6 +324,9 @@ struct mon_table mon_dispatch_postauth15[] = {
314 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, 324 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
315 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command}, 325 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
316#endif 326#endif
327#ifdef USE_CONSOLEKIT
328 {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
329#endif
317 {0, 0, NULL} 330 {0, 0, NULL}
318}; 331};
319 332
@@ -492,6 +505,9 @@ monitor_child_postauth(struct monitor *pmonitor)
492 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); 505 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
493 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1); 506 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
494 } 507 }
508#ifdef USE_CONSOLEKIT
509 monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1);
510#endif
495 511
496 for (;;) 512 for (;;)
497 monitor_read(pmonitor, mon_dispatch, NULL); 513 monitor_read(pmonitor, mon_dispatch, NULL);
@@ -2269,3 +2285,29 @@ mm_answer_gss_updatecreds(int socket, Buffer *m) {
2269 2285
2270#endif /* GSSAPI */ 2286#endif /* GSSAPI */
2271 2287
2288#ifdef USE_CONSOLEKIT
2289int
2290mm_answer_consolekit_register(int sock, Buffer *m)
2291{
2292 Session *s;
2293 char *tty, *display;
2294 char *cookie = NULL;
2295
2296 debug3("%s entering", __func__);
2297
2298 tty = buffer_get_string(m, NULL);
2299 display = buffer_get_string(m, NULL);
2300 s = session_by_tty(tty);
2301 if (s != NULL)
2302 cookie = consolekit_register(s, display);
2303 buffer_clear(m);
2304 buffer_put_cstring(m, cookie != NULL ? cookie : "");
2305 mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m);
2306
2307 free(cookie);
2308 free(display);
2309 free(tty);
2310
2311 return (0);
2312}
2313#endif /* USE_CONSOLEKIT */
diff --git a/monitor.h b/monitor.h
index 4d5e8fabe..10ba59ea9 100644
--- a/monitor.h
+++ b/monitor.h
@@ -70,6 +70,8 @@ enum monitor_reqtype {
70 70
71 MONITOR_REQ_AUTHROLE = 154, 71 MONITOR_REQ_AUTHROLE = 154,
72 72
73 MONITOR_REQ_CONSOLEKIT_REGISTER = 156, MONITOR_ANS_CONSOLEKIT_REGISTER = 157,
74
73}; 75};
74 76
75struct mm_master; 77struct mm_master;
diff --git a/monitor_wrap.c b/monitor_wrap.c
index f75dc9d71..a8fb07b52 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -1353,3 +1353,33 @@ mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
1353 1353
1354#endif /* GSSAPI */ 1354#endif /* GSSAPI */
1355 1355
1356#ifdef USE_CONSOLEKIT
1357char *
1358mm_consolekit_register(Session *s, const char *display)
1359{
1360 Buffer m;
1361 char *cookie;
1362
1363 debug3("%s entering", __func__);
1364
1365 if (s->ttyfd == -1)
1366 return NULL;
1367 buffer_init(&m);
1368 buffer_put_cstring(&m, s->tty);
1369 buffer_put_cstring(&m, display != NULL ? display : "");
1370 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m);
1371 buffer_clear(&m);
1372
1373 mm_request_receive_expect(pmonitor->m_recvfd,
1374 MONITOR_ANS_CONSOLEKIT_REGISTER, &m);
1375 cookie = buffer_get_string(&m, NULL);
1376 buffer_free(&m);
1377
1378 /* treat empty cookie as missing cookie */
1379 if (strlen(cookie) == 0) {
1380 free(cookie);
1381 cookie = NULL;
1382 }
1383 return (cookie);
1384}
1385#endif /* USE_CONSOLEKIT */
diff --git a/monitor_wrap.h b/monitor_wrap.h
index 9c2ee49ba..00e93fe9c 100644
--- a/monitor_wrap.h
+++ b/monitor_wrap.h
@@ -111,4 +111,8 @@ void *mm_zalloc(struct mm_master *, u_int, u_int);
111void mm_zfree(struct mm_master *, void *); 111void mm_zfree(struct mm_master *, void *);
112void mm_init_compression(struct mm_master *); 112void mm_init_compression(struct mm_master *);
113 113
114#ifdef USE_CONSOLEKIT
115char *mm_consolekit_register(struct Session *, const char *);
116#endif /* USE_CONSOLEKIT */
117
114#endif /* _MM_WRAP_H_ */ 118#endif /* _MM_WRAP_H_ */
diff --git a/session.c b/session.c
index 6848df42f..9d43fc3c7 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>
@@ -1160,6 +1161,9 @@ do_setup_env(Session *s, const char *shell)
1160#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN) 1161#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
1161 char *path = NULL; 1162 char *path = NULL;
1162#endif 1163#endif
1164#ifdef USE_CONSOLEKIT
1165 const char *ckcookie = NULL;
1166#endif /* USE_CONSOLEKIT */
1163 1167
1164 /* Initialize the environment. */ 1168 /* Initialize the environment. */
1165 envsize = 100; 1169 envsize = 100;
@@ -1304,6 +1308,11 @@ do_setup_env(Session *s, const char *shell)
1304 child_set_env(&env, &envsize, "KRB5CCNAME", 1308 child_set_env(&env, &envsize, "KRB5CCNAME",
1305 s->authctxt->krb5_ccname); 1309 s->authctxt->krb5_ccname);
1306#endif 1310#endif
1311#ifdef USE_CONSOLEKIT
1312 ckcookie = PRIVSEP(consolekit_register(s, s->display));
1313 if (ckcookie)
1314 child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
1315#endif /* USE_CONSOLEKIT */
1307#ifdef USE_PAM 1316#ifdef USE_PAM
1308 /* 1317 /*
1309 * Pull in any environment variables that may have 1318 * Pull in any environment variables that may have
@@ -2353,6 +2362,10 @@ session_pty_cleanup2(Session *s)
2353 2362
2354 debug("session_pty_cleanup: session %d release %s", s->self, s->tty); 2363 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
2355 2364
2365#ifdef USE_CONSOLEKIT
2366 consolekit_unregister(s);
2367#endif /* USE_CONSOLEKIT */
2368
2356 /* Record that the user has logged out. */ 2369 /* Record that the user has logged out. */
2357 if (s->pid != 0) 2370 if (s->pid != 0)
2358 record_logout(s->pid, s->tty, s->pw->pw_name); 2371 record_logout(s->pid, s->tty, s->pw->pw_name);
diff --git a/session.h b/session.h
index ef6593c34..a6b69837b 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 {
@@ -61,6 +63,10 @@ struct Session {
61 char *name; 63 char *name;
62 char *val; 64 char *val;
63 } *env; 65 } *env;
66
67#ifdef USE_CONSOLEKIT
68 struct _CkConnector *ckc;
69#endif /* USE_CONSOLEKIT */
64}; 70};
65 71
66void do_authenticated(Authctxt *); 72void do_authenticated(Authctxt *);