summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 35c6fd6ea..598d55a58 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 5a9db2d05..57b68e256 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
@@ -17215,6 +17217,135 @@ fi
17215 17217
17216 17218
17217 17219
17220# Check whether user wants ConsoleKit support
17221CONSOLEKIT_MSG="no"
17222LIBCK_CONNECTOR=""
17223
17224# Check whether --with-consolekit was given.
17225if test "${with_consolekit+set}" = set; then :
17226 withval=$with_consolekit; if test "x$withval" != "xno" ; then
17227 if test -n "$ac_tool_prefix"; then
17228 # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
17229set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
17230{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
17231$as_echo_n "checking for $ac_word... " >&6; }
17232if ${ac_cv_path_PKGCONFIG+:} false; then :
17233 $as_echo_n "(cached) " >&6
17234else
17235 case $PKGCONFIG in
17236 [\\/]* | ?:[\\/]*)
17237 ac_cv_path_PKGCONFIG="$PKGCONFIG" # Let the user override the test with a path.
17238 ;;
17239 *)
17240 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
17241for as_dir in $PATH
17242do
17243 IFS=$as_save_IFS
17244 test -z "$as_dir" && as_dir=.
17245 for ac_exec_ext in '' $ac_executable_extensions; do
17246 if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
17247 ac_cv_path_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
17248 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
17249 break 2
17250 fi
17251done
17252 done
17253IFS=$as_save_IFS
17254
17255 ;;
17256esac
17257fi
17258PKGCONFIG=$ac_cv_path_PKGCONFIG
17259if test -n "$PKGCONFIG"; then
17260 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5
17261$as_echo "$PKGCONFIG" >&6; }
17262else
17263 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17264$as_echo "no" >&6; }
17265fi
17266
17267
17268fi
17269if test -z "$ac_cv_path_PKGCONFIG"; then
17270 ac_pt_PKGCONFIG=$PKGCONFIG
17271 # Extract the first word of "pkg-config", so it can be a program name with args.
17272set dummy pkg-config; ac_word=$2
17273{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
17274$as_echo_n "checking for $ac_word... " >&6; }
17275if ${ac_cv_path_ac_pt_PKGCONFIG+:} false; then :
17276 $as_echo_n "(cached) " >&6
17277else
17278 case $ac_pt_PKGCONFIG in
17279 [\\/]* | ?:[\\/]*)
17280 ac_cv_path_ac_pt_PKGCONFIG="$ac_pt_PKGCONFIG" # Let the user override the test with a path.
17281 ;;
17282 *)
17283 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
17284for as_dir in $PATH
17285do
17286 IFS=$as_save_IFS
17287 test -z "$as_dir" && as_dir=.
17288 for ac_exec_ext in '' $ac_executable_extensions; do
17289 if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
17290 ac_cv_path_ac_pt_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
17291 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
17292 break 2
17293 fi
17294done
17295 done
17296IFS=$as_save_IFS
17297
17298 ;;
17299esac
17300fi
17301ac_pt_PKGCONFIG=$ac_cv_path_ac_pt_PKGCONFIG
17302if test -n "$ac_pt_PKGCONFIG"; then
17303 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKGCONFIG" >&5
17304$as_echo "$ac_pt_PKGCONFIG" >&6; }
17305else
17306 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17307$as_echo "no" >&6; }
17308fi
17309
17310 if test "x$ac_pt_PKGCONFIG" = x; then
17311 PKGCONFIG="no"
17312 else
17313 case $cross_compiling:$ac_tool_warned in
17314yes:)
17315{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
17316$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
17317ac_tool_warned=yes ;;
17318esac
17319 PKGCONFIG=$ac_pt_PKGCONFIG
17320 fi
17321else
17322 PKGCONFIG="$ac_cv_path_PKGCONFIG"
17323fi
17324
17325 if test "$PKGCONFIG" != "no"; then
17326 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ck-connector" >&5
17327$as_echo_n "checking for ck-connector... " >&6; }
17328 if $PKGCONFIG --exists ck-connector; then
17329 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
17330 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
17331 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
17332 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
17333 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17334$as_echo "yes" >&6; }
17335
17336$as_echo "#define USE_CONSOLEKIT 1" >>confdefs.h
17337
17338 CONSOLEKIT_MSG="yes"
17339 else
17340 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17341$as_echo "no" >&6; }
17342 fi
17343 fi
17344 fi
17345
17346fi
17347
17348
17218# Looking for programs, paths and files 17349# Looking for programs, paths and files
17219 17350
17220PRIVSEP_PATH=/var/empty 17351PRIVSEP_PATH=/var/empty
@@ -19744,6 +19875,7 @@ echo " MD5 password support: $MD5_MSG"
19744echo " libedit support: $LIBEDIT_MSG" 19875echo " libedit support: $LIBEDIT_MSG"
19745echo " Solaris process contract support: $SPC_MSG" 19876echo " Solaris process contract support: $SPC_MSG"
19746echo " Solaris project support: $SP_MSG" 19877echo " Solaris project support: $SP_MSG"
19878echo " ConsoleKit support: $CONSOLEKIT_MSG"
19747echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 19879echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
19748echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 19880echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
19749echo " BSD Auth support: $BSD_AUTH_MSG" 19881echo " BSD Auth support: $BSD_AUTH_MSG"
diff --git a/configure.ac b/configure.ac
index 90eebf5fd..e2289cd37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4070,6 +4070,30 @@ AC_ARG_WITH([kerberos5],
4070AC_SUBST([GSSLIBS]) 4070AC_SUBST([GSSLIBS])
4071AC_SUBST([K5LIBS]) 4071AC_SUBST([K5LIBS])
4072 4072
4073# Check whether user wants ConsoleKit support
4074CONSOLEKIT_MSG="no"
4075LIBCK_CONNECTOR=""
4076AC_ARG_WITH(consolekit,
4077 [ --with-consolekit Enable ConsoleKit support],
4078 [ if test "x$withval" != "xno" ; then
4079 AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
4080 if test "$PKGCONFIG" != "no"; then
4081 AC_MSG_CHECKING([for ck-connector])
4082 if $PKGCONFIG --exists ck-connector; then
4083 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
4084 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
4085 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
4086 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
4087 AC_MSG_RESULT([yes])
4088 AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.])
4089 CONSOLEKIT_MSG="yes"
4090 else
4091 AC_MSG_RESULT([no])
4092 fi
4093 fi
4094 fi ]
4095)
4096
4073# Looking for programs, paths and files 4097# Looking for programs, paths and files
4074 4098
4075PRIVSEP_PATH=/var/empty 4099PRIVSEP_PATH=/var/empty
@@ -4871,6 +4895,7 @@ echo " MD5 password support: $MD5_MSG"
4871echo " libedit support: $LIBEDIT_MSG" 4895echo " libedit support: $LIBEDIT_MSG"
4872echo " Solaris process contract support: $SPC_MSG" 4896echo " Solaris process contract support: $SPC_MSG"
4873echo " Solaris project support: $SP_MSG" 4897echo " Solaris project support: $SP_MSG"
4898echo " ConsoleKit support: $CONSOLEKIT_MSG"
4874echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 4899echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
4875echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 4900echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
4876echo " BSD Auth support: $BSD_AUTH_MSG" 4901echo " 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 88f472e68..8ffea4f13 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);
@@ -2493,3 +2509,30 @@ mm_answer_jpake_check_confirm(int sock, Buffer *m)
2493} 2509}
2494 2510
2495#endif /* JPAKE */ 2511#endif /* JPAKE */
2512
2513#ifdef USE_CONSOLEKIT
2514int
2515mm_answer_consolekit_register(int sock, Buffer *m)
2516{
2517 Session *s;
2518 char *tty, *display;
2519 char *cookie = NULL;
2520
2521 debug3("%s entering", __func__);
2522
2523 tty = buffer_get_string(m, NULL);
2524 display = buffer_get_string(m, NULL);
2525 s = session_by_tty(tty);
2526 if (s != NULL)
2527 cookie = consolekit_register(s, display);
2528 buffer_clear(m);
2529 buffer_put_cstring(m, cookie != NULL ? cookie : "");
2530 mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m);
2531
2532 free(cookie);
2533 free(display);
2534 free(tty);
2535
2536 return (0);
2537}
2538#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 5ddd82aa6..14df2262c 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>
@@ -1155,6 +1156,9 @@ do_setup_env(Session *s, const char *shell)
1155#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN) 1156#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
1156 char *path = NULL; 1157 char *path = NULL;
1157#endif 1158#endif
1159#ifdef USE_CONSOLEKIT
1160 const char *ckcookie = NULL;
1161#endif /* USE_CONSOLEKIT */
1158 1162
1159 /* Initialize the environment. */ 1163 /* Initialize the environment. */
1160 envsize = 100; 1164 envsize = 100;
@@ -1299,6 +1303,11 @@ do_setup_env(Session *s, const char *shell)
1299 child_set_env(&env, &envsize, "KRB5CCNAME", 1303 child_set_env(&env, &envsize, "KRB5CCNAME",
1300 s->authctxt->krb5_ccname); 1304 s->authctxt->krb5_ccname);
1301#endif 1305#endif
1306#ifdef USE_CONSOLEKIT
1307 ckcookie = PRIVSEP(consolekit_register(s, s->display));
1308 if (ckcookie)
1309 child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
1310#endif /* USE_CONSOLEKIT */
1302#ifdef USE_PAM 1311#ifdef USE_PAM
1303 /* 1312 /*
1304 * Pull in any environment variables that may have 1313 * Pull in any environment variables that may have
@@ -2348,6 +2357,10 @@ session_pty_cleanup2(Session *s)
2348 2357
2349 debug("session_pty_cleanup: session %d release %s", s->self, s->tty); 2358 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
2350 2359
2360#ifdef USE_CONSOLEKIT
2361 consolekit_unregister(s);
2362#endif /* USE_CONSOLEKIT */
2363
2351 /* Record that the user has logged out. */ 2364 /* Record that the user has logged out. */
2352 if (s->pid != 0) 2365 if (s->pid != 0)
2353 record_logout(s->pid, s->tty, s->pw->pw_name); 2366 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 *);