summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@ubuntu.com>2014-02-09 16:09:57 +0000
committerColin Watson <cjwatson@debian.org>2015-08-19 16:33:32 +0100
commit8b3111d597316954caaf8ddf2e7746491976c248 (patch)
tree2640968377507c4cb89aa8f044984ae5dfb8df85
parent9a440da8025dbc120803ee09c2a7ac8c638d31c2 (diff)
Add support for registering ConsoleKit sessions on login
Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1450 Last-Updated: 2015-08-19 Patch-Name: consolekit.patch
-rw-r--r--Makefile.in3
-rw-r--r--configure.ac25
-rw-r--r--consolekit.c241
-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
10 files changed, 389 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in
index 3d2a328e7..c406aecef 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -111,7 +111,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
111 sftp-server.o sftp-common.o \ 111 sftp-server.o sftp-common.o \
112 roaming_common.o roaming_serv.o \ 112 roaming_common.o roaming_serv.o \
113 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \ 113 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
114 sandbox-seccomp-filter.o sandbox-capsicum.o 114 sandbox-seccomp-filter.o sandbox-capsicum.o \
115 consolekit.o
115 116
116MANPAGES = 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 117MANPAGES = 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
117MANPAGES_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 118MANPAGES_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.ac b/configure.ac
index 5f606ea12..f7ce777a5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4180,6 +4180,30 @@ AC_ARG_WITH([kerberos5],
4180AC_SUBST([GSSLIBS]) 4180AC_SUBST([GSSLIBS])
4181AC_SUBST([K5LIBS]) 4181AC_SUBST([K5LIBS])
4182 4182
4183# Check whether user wants ConsoleKit support
4184CONSOLEKIT_MSG="no"
4185LIBCK_CONNECTOR=""
4186AC_ARG_WITH(consolekit,
4187 [ --with-consolekit Enable ConsoleKit support],
4188 [ if test "x$withval" != "xno" ; then
4189 AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
4190 if test "$PKGCONFIG" != "no"; then
4191 AC_MSG_CHECKING([for ck-connector])
4192 if $PKGCONFIG --exists ck-connector; then
4193 CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
4194 CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
4195 CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
4196 SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
4197 AC_MSG_RESULT([yes])
4198 AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.])
4199 CONSOLEKIT_MSG="yes"
4200 else
4201 AC_MSG_RESULT([no])
4202 fi
4203 fi
4204 fi ]
4205)
4206
4183# Looking for programs, paths and files 4207# Looking for programs, paths and files
4184 4208
4185PRIVSEP_PATH=/var/empty 4209PRIVSEP_PATH=/var/empty
@@ -4981,6 +5005,7 @@ echo " MD5 password support: $MD5_MSG"
4981echo " libedit support: $LIBEDIT_MSG" 5005echo " libedit support: $LIBEDIT_MSG"
4982echo " Solaris process contract support: $SPC_MSG" 5006echo " Solaris process contract support: $SPC_MSG"
4983echo " Solaris project support: $SP_MSG" 5007echo " Solaris project support: $SP_MSG"
5008echo " ConsoleKit support: $CONSOLEKIT_MSG"
4984echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG" 5009echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
4985echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG" 5010echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
4986echo " BSD Auth support: $BSD_AUTH_MSG" 5011echo " BSD Auth support: $BSD_AUTH_MSG"
diff --git a/consolekit.c b/consolekit.c
new file mode 100644
index 000000000..0266f06a2
--- /dev/null
+++ b/consolekit.c
@@ -0,0 +1,241 @@
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 "misc.h"
57#include "servconf.h"
58#include "canohost.h"
59#include "session.h"
60#include "consolekit.h"
61
62extern ServerOptions options;
63extern u_int utmp_len;
64
65void
66set_active(const char *cookie)
67{
68 DBusError err;
69 DBusConnection *connection;
70 DBusMessage *message = NULL, *reply = NULL;
71 char *sid;
72 DBusMessageIter iter, subiter;
73 const char *interface, *property;
74 dbus_bool_t active;
75
76 dbus_error_init(&err);
77 connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
78 if (!connection) {
79 if (dbus_error_is_set(&err)) {
80 error("unable to open DBus connection: %s",
81 err.message);
82 dbus_error_free(&err);
83 }
84 goto out;
85 }
86 dbus_connection_set_exit_on_disconnect(connection, FALSE);
87
88 message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
89 "/org/freedesktop/ConsoleKit/Manager",
90 "org.freedesktop.ConsoleKit.Manager",
91 "GetSessionForCookie");
92 if (!message)
93 goto out;
94 if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &cookie,
95 DBUS_TYPE_INVALID)) {
96 if (dbus_error_is_set(&err)) {
97 error("unable to get current session: %s",
98 err.message);
99 dbus_error_free(&err);
100 }
101 goto out;
102 }
103
104 dbus_error_init(&err);
105 reply = dbus_connection_send_with_reply_and_block(connection, message,
106 -1, &err);
107 if (!reply) {
108 if (dbus_error_is_set(&err)) {
109 error("unable to get current session: %s",
110 err.message);
111 dbus_error_free(&err);
112 }
113 goto out;
114 }
115
116 dbus_error_init(&err);
117 if (!dbus_message_get_args(reply, &err,
118 DBUS_TYPE_OBJECT_PATH, &sid,
119 DBUS_TYPE_INVALID)) {
120 if (dbus_error_is_set(&err)) {
121 error("unable to get current session: %s",
122 err.message);
123 dbus_error_free(&err);
124 }
125 goto out;
126 }
127 dbus_message_unref(reply);
128 dbus_message_unref(message);
129 message = reply = NULL;
130
131 message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
132 sid, "org.freedesktop.DBus.Properties", "Set");
133 if (!message)
134 goto out;
135 interface = "org.freedesktop.ConsoleKit.Session";
136 property = "active";
137 if (!dbus_message_append_args(message,
138 DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property,
139 DBUS_TYPE_INVALID))
140 goto out;
141 dbus_message_iter_init_append(message, &iter);
142 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
143 DBUS_TYPE_BOOLEAN_AS_STRING, &subiter))
144 goto out;
145 active = TRUE;
146 if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_BOOLEAN,
147 &active))
148 goto out;
149 if (!dbus_message_iter_close_container(&iter, &subiter))
150 goto out;
151
152 dbus_error_init(&err);
153 reply = dbus_connection_send_with_reply_and_block(connection, message,
154 -1, &err);
155 if (!reply) {
156 if (dbus_error_is_set(&err)) {
157 error("unable to make current session active: %s",
158 err.message);
159 dbus_error_free(&err);
160 }
161 goto out;
162 }
163
164out:
165 if (reply)
166 dbus_message_unref(reply);
167 if (message)
168 dbus_message_unref(message);
169}
170
171/*
172 * We pass display separately rather than using s->display because the
173 * latter is not available in the monitor when using privsep.
174 */
175
176char *
177consolekit_register(Session *s, const char *display)
178{
179 DBusError err;
180 const char *tty = s->tty;
181 const char *remote_host_name;
182 dbus_bool_t is_local = FALSE;
183 const char *cookie = NULL;
184
185 if (s->ckc) {
186 debug("already registered with ConsoleKit");
187 return xstrdup(ck_connector_get_cookie(s->ckc));
188 }
189
190 s->ckc = ck_connector_new();
191 if (!s->ckc) {
192 error("ck_connector_new failed");
193 return NULL;
194 }
195
196 if (!tty)
197 tty = "";
198 if (!display)
199 display = "";
200 remote_host_name = get_remote_name_or_ip(utmp_len, options.use_dns);
201 if (!remote_host_name)
202 remote_host_name = "";
203
204 dbus_error_init(&err);
205 if (!ck_connector_open_session_with_parameters(s->ckc, &err,
206 "unix-user", &s->pw->pw_uid,
207 "display-device", &tty,
208 "x11-display", &display,
209 "remote-host-name", &remote_host_name,
210 "is-local", &is_local,
211 NULL)) {
212 if (dbus_error_is_set(&err)) {
213 debug("%s", err.message);
214 dbus_error_free(&err);
215 } else {
216 debug("insufficient privileges or D-Bus / ConsoleKit "
217 "not available");
218 }
219 return NULL;
220 }
221
222 debug("registered uid=%d on tty='%s' with ConsoleKit",
223 s->pw->pw_uid, s->tty);
224
225 cookie = ck_connector_get_cookie(s->ckc);
226 set_active(cookie);
227 return xstrdup(cookie);
228}
229
230void
231consolekit_unregister(Session *s)
232{
233 if (s->ckc) {
234 debug("unregistering ConsoleKit session %s",
235 ck_connector_get_cookie(s->ckc));
236 ck_connector_unref(s->ckc);
237 s->ckc = NULL;
238 }
239}
240
241#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 6ff05e433..ce7ba079c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -104,6 +104,9 @@
104#include "authfd.h" 104#include "authfd.h"
105#include "match.h" 105#include "match.h"
106#include "ssherr.h" 106#include "ssherr.h"
107#ifdef USE_CONSOLEKIT
108#include "consolekit.h"
109#endif
107 110
108#ifdef GSSAPI 111#ifdef GSSAPI
109static Gssctxt *gsscontext = NULL; 112static Gssctxt *gsscontext = NULL;
@@ -169,6 +172,10 @@ int mm_answer_audit_command(int, Buffer *);
169 172
170static int monitor_read_log(struct monitor *); 173static int monitor_read_log(struct monitor *);
171 174
175#ifdef USE_CONSOLEKIT
176int mm_answer_consolekit_register(int, Buffer *);
177#endif
178
172static Authctxt *authctxt; 179static Authctxt *authctxt;
173 180
174#ifdef WITH_SSH1 181#ifdef WITH_SSH1
@@ -261,6 +268,9 @@ struct mon_table mon_dispatch_postauth20[] = {
261 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, 268 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
262 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command}, 269 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
263#endif 270#endif
271#ifdef USE_CONSOLEKIT
272 {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
273#endif
264 {0, 0, NULL} 274 {0, 0, NULL}
265}; 275};
266 276
@@ -306,6 +316,9 @@ struct mon_table mon_dispatch_postauth15[] = {
306 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, 316 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
307 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command}, 317 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
308#endif 318#endif
319#ifdef USE_CONSOLEKIT
320 {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
321#endif
309#endif /* WITH_SSH1 */ 322#endif /* WITH_SSH1 */
310 {0, 0, NULL} 323 {0, 0, NULL}
311}; 324};
@@ -488,6 +501,9 @@ monitor_child_postauth(struct monitor *pmonitor)
488 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); 501 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
489 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1); 502 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
490 } 503 }
504#ifdef USE_CONSOLEKIT
505 monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1);
506#endif
491 507
492 for (;;) 508 for (;;)
493 monitor_read(pmonitor, mon_dispatch, NULL); 509 monitor_read(pmonitor, mon_dispatch, NULL);
@@ -2187,3 +2203,29 @@ mm_answer_gss_updatecreds(int socket, Buffer *m) {
2187 2203
2188#endif /* GSSAPI */ 2204#endif /* GSSAPI */
2189 2205
2206#ifdef USE_CONSOLEKIT
2207int
2208mm_answer_consolekit_register(int sock, Buffer *m)
2209{
2210 Session *s;
2211 char *tty, *display;
2212 char *cookie = NULL;
2213
2214 debug3("%s entering", __func__);
2215
2216 tty = buffer_get_string(m, NULL);
2217 display = buffer_get_string(m, NULL);
2218 s = session_by_tty(tty);
2219 if (s != NULL)
2220 cookie = consolekit_register(s, display);
2221 buffer_clear(m);
2222 buffer_put_cstring(m, cookie != NULL ? cookie : "");
2223 mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m);
2224
2225 free(cookie);
2226 free(display);
2227 free(tty);
2228
2229 return (0);
2230}
2231#endif /* USE_CONSOLEKIT */
diff --git a/monitor.h b/monitor.h
index 2d82b8b84..fd8d92cd0 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 5aa9c4758..a5f4e9d3c 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -1150,3 +1150,33 @@ mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
1150 1150
1151#endif /* GSSAPI */ 1151#endif /* GSSAPI */
1152 1152
1153#ifdef USE_CONSOLEKIT
1154char *
1155mm_consolekit_register(Session *s, const char *display)
1156{
1157 Buffer m;
1158 char *cookie;
1159
1160 debug3("%s entering", __func__);
1161
1162 if (s->ttyfd == -1)
1163 return NULL;
1164 buffer_init(&m);
1165 buffer_put_cstring(&m, s->tty);
1166 buffer_put_cstring(&m, display != NULL ? display : "");
1167 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m);
1168 buffer_clear(&m);
1169
1170 mm_request_receive_expect(pmonitor->m_recvfd,
1171 MONITOR_ANS_CONSOLEKIT_REGISTER, &m);
1172 cookie = buffer_get_string(&m, NULL);
1173 buffer_free(&m);
1174
1175 /* treat empty cookie as missing cookie */
1176 if (strlen(cookie) == 0) {
1177 free(cookie);
1178 cookie = NULL;
1179 }
1180 return (cookie);
1181}
1182#endif /* USE_CONSOLEKIT */
diff --git a/monitor_wrap.h b/monitor_wrap.h
index 4d1e89974..f99c31c43 100644
--- a/monitor_wrap.h
+++ b/monitor_wrap.h
@@ -108,4 +108,8 @@ int mm_skey_respond(void *, u_int, char **);
108/* zlib allocation hooks */ 108/* zlib allocation hooks */
109void mm_init_compression(struct mm_master *); 109void mm_init_compression(struct mm_master *);
110 110
111#ifdef USE_CONSOLEKIT
112char *mm_consolekit_register(struct Session *, const char *);
113#endif /* USE_CONSOLEKIT */
114
111#endif /* _MM_WRAP_H_ */ 115#endif /* _MM_WRAP_H_ */
diff --git a/session.c b/session.c
index d4b7725fa..785833f09 100644
--- a/session.c
+++ b/session.c
@@ -94,6 +94,7 @@
94#include "kex.h" 94#include "kex.h"
95#include "monitor_wrap.h" 95#include "monitor_wrap.h"
96#include "sftp.h" 96#include "sftp.h"
97#include "consolekit.h"
97 98
98#if defined(KRB5) && defined(USE_AFS) 99#if defined(KRB5) && defined(USE_AFS)
99#include <kafs.h> 100#include <kafs.h>
@@ -1144,6 +1145,9 @@ do_setup_env(Session *s, const char *shell)
1144#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN) 1145#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
1145 char *path = NULL; 1146 char *path = NULL;
1146#endif 1147#endif
1148#ifdef USE_CONSOLEKIT
1149 const char *ckcookie = NULL;
1150#endif /* USE_CONSOLEKIT */
1147 1151
1148 /* Initialize the environment. */ 1152 /* Initialize the environment. */
1149 envsize = 100; 1153 envsize = 100;
@@ -1288,6 +1292,11 @@ do_setup_env(Session *s, const char *shell)
1288 child_set_env(&env, &envsize, "KRB5CCNAME", 1292 child_set_env(&env, &envsize, "KRB5CCNAME",
1289 s->authctxt->krb5_ccname); 1293 s->authctxt->krb5_ccname);
1290#endif 1294#endif
1295#ifdef USE_CONSOLEKIT
1296 ckcookie = PRIVSEP(consolekit_register(s, s->display));
1297 if (ckcookie)
1298 child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
1299#endif /* USE_CONSOLEKIT */
1291#ifdef USE_PAM 1300#ifdef USE_PAM
1292 /* 1301 /*
1293 * Pull in any environment variables that may have 1302 * Pull in any environment variables that may have
@@ -2351,6 +2360,10 @@ session_pty_cleanup2(Session *s)
2351 2360
2352 debug("session_pty_cleanup: session %d release %s", s->self, s->tty); 2361 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
2353 2362
2363#ifdef USE_CONSOLEKIT
2364 consolekit_unregister(s);
2365#endif /* USE_CONSOLEKIT */
2366
2354 /* Record that the user has logged out. */ 2367 /* Record that the user has logged out. */
2355 if (s->pid != 0) 2368 if (s->pid != 0)
2356 record_logout(s->pid, s->tty, s->pw->pw_name); 2369 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 *);