summaryrefslogtreecommitdiff
path: root/extra/xorg-xdm/xdm-consolekit.patch
blob: 7d85b97e0dd5091fee987eea32ed9066328a8f27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
--- a/configure.ac
+++ b/configure.ac
@@ -362,6 +362,20 @@
 
 AM_CONDITIONAL(DYNAMIC_GREETER, test x$DYNAMIC_GREETER = xyes)
 
+# ConsoleKit support
+AC_ARG_WITH(consolekit, AC_HELP_STRING([--with-consolekit], [Use ConsoleKit]),
+	[USE_CONSOLEKIT=$withval], [USE_CONSOLEKIT=yes])
+if test x"$USE_CONSOLEKIT" != xno; then
+	PKG_CHECK_MODULES(CK_CONNECTOR, ck-connector,
+		[USE_CONSOLEKIT=yes], [USE_CONSOLEKIT=no])
+	if test x"$USE_CONSOLEKIT" = xyes; then
+		AC_DEFINE([USE_CONSOLEKIT], 1, [Define to 1 to use ConsoleKit])
+		XDM_CFLAGS="$XDM_CFLAGS $CK_CONNECTOR_CFLAGS -DUSE_CONSOLEKIT"
+		XDM_LIBS="$XDM_LIBS $CK_CONNECTOR_LIBS"
+	fi
+fi
+dnl AM_CONDITIONAL(USE_CONSOLEKIT, test$USE_CONSOLEKIT = xyes)
+
 #
 #  XDM
 #
--- a/xdm/session.c
+++ b/xdm/session.c
@@ -66,6 +66,11 @@
 #endif
 #endif /* USE_PAM */
 
+#ifdef USE_CONSOLEKIT
+#include <ck-connector.h>
+#include <dbus/dbus.h>
+#endif
+
 #ifdef __SCO__
 #include <prot.h>
 #endif
@@ -472,6 +477,97 @@
     }
 }
 
+#ifdef USE_CONSOLEKIT
+
+static CkConnector *connector;
+
+static int openCKSession(struct verify_info *verify, struct display *d)
+{
+    int ret;
+    DBusError error;
+    char  *remote_host_name = "";
+    dbus_bool_t is_local;
+    char *display_name = "";
+    char *display_device = "";
+    char devtmp[16];
+
+    if (!use_consolekit)
+	return 1;
+
+    is_local = d->displayType.location == Local;
+    if (d->peerlen > 0 && d->peer)
+	remote_host_name = d->peer;
+    if (d->name)
+	display_name = d->name;
+    /* how can we get the corresponding tty at best...? */
+    if (d->windowPath) {
+	display_device = strchr(d->windowPath, ':');
+	if (display_device && display_device[1])
+	    display_device++;
+	else
+	    display_device = d->windowPath;
+	snprintf(devtmp, sizeof(devtmp), "/dev/tty%s", display_device);
+	display_device = devtmp;
+    }
+
+    connector = ck_connector_new();
+    if (!connector) {
+	LogOutOfMem("ck_connector");
+	return 0;
+    }
+
+    dbus_error_init(&error);
+    ret = ck_connector_open_session_with_parameters(
+		connector, &error,
+		"unix-user", &verify->uid,
+		"x11-display", &display_name,
+		"x11-display-device", &display_device,
+		"remote-host-name", &remote_host_name,
+		"is-local", &is_local,
+		NULL);
+    if (!ret) {
+	if (dbus_error_is_set(&error)) {
+	    LogError("Dbus error: %s\n", error.message);
+	    dbus_error_free(&error);
+	} else {
+	    LogError("ConsoleKit error\n");
+	}
+	LogError("console-kit-daemon not running?\n");
+	ck_connector_unref(connector);
+	connector = NULL;
+	return 0;
+    }
+
+    verify->userEnviron = setEnv(verify->userEnviron,
+		"XDG_SESSION_COOKIE", ck_connector_get_cookie(connector));
+    return 1;
+}
+
+static void closeCKSession(void)
+{
+    DBusError error;
+
+    if (!connector)
+	return;
+
+    dbus_error_init(&error);
+    if (!ck_connector_close_session(connector, &error)) {
+	if (dbus_error_is_set(&error)) {
+	    LogError("Dbus error: %s\n", error.message);
+	    dbus_error_free(&error);
+	} else {
+	    LogError("ConsoleKit close error\n");
+	}
+	LogError("console-kit-daemon not running?\n");
+    }
+    ck_connector_unref(connector);
+    connector = NULL;
+}
+#else
+#define openCKSession(v,d)	1
+#define closeCKSession()
+#endif
+
 void
 SessionExit (struct display *d, int status, int removeAuth)
 {
@@ -486,6 +580,8 @@
     }
 #endif
 
+    closeCKSession();
+
     /* make sure the server gets reset after the session is over */
     if (d->serverPid >= 2 && d->resetSignal)
 	kill (d->serverPid, d->resetSignal);
@@ -568,6 +664,10 @@
 #ifdef USE_PAM
     if (pamh) pam_open_session(pamh, 0);
 #endif
+
+    if (!openCKSession(verify, d))
+	return 0;
+
     switch (pid = fork ()) {
     case 0:
 	CleanUpChild ();
--- a/include/dm.h
+++ b/include/dm.h
@@ -325,6 +325,9 @@
 extern char	*prngdSocket;
 extern int	prngdPort;
 # endif
+#ifdef USE_CONSOLEKIT
+extern int	use_consolekit;
+#endif
 
 extern char	*greeterLib;
 extern char	*willing;
--- a/xdm/resource.c
+++ b/xdm/resource.c
@@ -68,6 +68,9 @@
 char	*prngdSocket;
 int	prngdPort;
 #endif
+#ifdef USE_CONSOLEKIT
+int	use_consolekit;
+#endif
 
 char	*greeterLib;
 char	*willing;
@@ -258,6 +261,10 @@
 				"false"} ,
 { "willing",	"Willing",	DM_STRING,	&willing,
 				""} ,
+#ifdef USE_CONSOLEKIT
+{ "consoleKit",	"ConsoleKit",	DM_BOOL,	(char **) &use_consolekit,
+				"true"} ,
+#endif
 };
 
 # define NUM_DM_RESOURCES	(sizeof DmResources / sizeof DmResources[0])
@@ -440,7 +447,11 @@
 {"-debug",	"*debugLevel",		XrmoptionSepArg,	(caddr_t) NULL },
 {"-xrm",	NULL,			XrmoptionResArg,	(caddr_t) NULL },
 {"-daemon",	".daemonMode",		XrmoptionNoArg,		"true"         },
-{"-nodaemon",	".daemonMode",		XrmoptionNoArg,		"false"        }
+{"-nodaemon",	".daemonMode",		XrmoptionNoArg,		"false"        },
+#ifdef USE_CONSOLEKIT
+{"-consolekit",	".consoleKit",		XrmoptionNoArg,		"true"  },
+{"-noconsolekit", ".consoleKit",	XrmoptionNoArg,		"false" }
+#endif
 };
 
 static int	originalArgc;
--- a/man/xdm.man
+++ b/man/xdm.man
@@ -51,6 +51,8 @@
 ] [
 .B \-session
 .I session_program
+] [
+.B \-noconsolekit
 ]
 .SH DESCRIPTION
 .I Xdm
@@ -218,6 +220,10 @@
 .IP "\fB\-xrm\fP \fIresource_specification\fP"
 Allows an arbitrary resource to be specified, as in most
 X Toolkit applications.
+.IP "\fB\-noconsolekit\fP"
+Specifies ``false'' as the value for the \fBDisplayManager.consoleKit\fP
+resource.
+This suppresses the session management using ConsoleKit.
 .SH RESOURCES
 At many stages the actions of
 .I xdm