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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
diff -pur slim-1.3.5.orig/app.cpp slim-1.3.5/app.cpp
--- slim-1.3.5.orig/app.cpp 2012-12-31 06:03:42.000000000 -0700
+++ slim-1.3.5/app.cpp 2013-03-25 05:14:36.000000000 -0600
@@ -139,6 +139,9 @@ App::App(int argc, char** argv)
force_nodaemon = false;
firstlogin = true;
Dpy = NULL;
+ existing_server = false;
+ displayName = string(DISPLAY);
+ screenName = displayName + SCREEN;
/* Parse command line
Note: we force a option for nodaemon switch to handle "-nodaemon" */
@@ -183,11 +186,17 @@ App::App(int argc, char** argv)
}
#endif /* XNEST_DEBUG */
+ char *p = getenv("DISPLAY");
+ if (p && p[0]) {
+ displayName = p;
+ screenName = displayName + SCREEN;
+ existing_server = true;
+ ReadServerAuth();
+ }
+
}
void App::Run() {
- DisplayName = DISPLAY;
-
#ifdef XNEST_DEBUG
char* p = getenv("DISPLAY");
if (p && p[0]) {
@@ -221,11 +230,12 @@ void App::Run() {
#ifdef USE_PAM
try{
pam.start("slim");
- pam.set_item(PAM::Authenticator::TTY, DisplayName);
+ pam.set_item(PAM::Authenticator::TTY, screenName.c_str());
pam.set_item(PAM::Authenticator::Requestor, "root");
}
catch(PAM::Exception& e){
logStream << APPNAME << ": " << e << endl;
+ if (existing_server) exit(OPENFAILED_DISPLAY);
exit(ERR_EXIT);
};
#endif
@@ -238,6 +248,7 @@ void App::Run() {
if (themeName == "default") {
logStream << APPNAME << ": Failed to open default theme file "
<< themefile << endl;
+ if (existing_server) exit(OPENFAILED_DISPLAY);
exit(ERR_EXIT);
} else {
logStream << APPNAME << ": Invalid theme in config: "
@@ -249,12 +260,12 @@ void App::Run() {
}
}
- if (!testing) {
+ if (!testing && !existing_server) {
/* Create lock file */
LoginApp->GetLock();
/* Start x-server */
- setenv("DISPLAY", DisplayName, 1);
+ setenv("DISPLAY", screenName.c_str(), 1);
signal(SIGQUIT, CatchSignal);
signal(SIGTERM, CatchSignal);
signal(SIGKILL, CatchSignal);
@@ -288,10 +299,11 @@ void App::Run() {
}
/* Open display */
- if((Dpy = XOpenDisplay(DisplayName)) == 0) {
+ if((Dpy = XOpenDisplay(screenName.c_str())) == 0) {
logStream << APPNAME << ": could not open display '"
- << DisplayName << "'" << endl;
+ << screenName << "'" << endl;
if (!testing) StopServer();
+ if (existing_server) exit(OPENFAILED_DISPLAY);
exit(ERR_EXIT);
}
@@ -424,6 +436,7 @@ bool App::AuthenticateUser(bool focuspas
}
catch(PAM::Exception& e){
logStream << APPNAME << ": " << e << endl;
+ if (existing_server) exit(REMANAGE_DISPLAY);
exit(ERR_EXIT);
};
return true;
@@ -516,6 +529,7 @@ void App::Login() {
}
catch(PAM::Exception& e){
logStream << APPNAME << ": " << e << endl;
+ if (existing_server) exit(REMANAGE_DISPLAY);
exit(ERR_EXIT);
};
#else
@@ -548,12 +562,13 @@ void App::Login() {
pam.setenv("USER", pw->pw_name);
pam.setenv("LOGNAME", pw->pw_name);
pam.setenv("PATH", cfg->getOption("default_path").c_str());
- pam.setenv("DISPLAY", DisplayName);
+ pam.setenv("DISPLAY", screenName);
pam.setenv("MAIL", maildir.c_str());
pam.setenv("XAUTHORITY", xauthority.c_str());
}
catch(PAM::Exception& e){
logStream << APPNAME << ": " << e << endl;
+ if (existing_server) exit(REMANAGE_DISPLAY);
exit(ERR_EXIT);
}
#endif
@@ -561,10 +576,11 @@ void App::Login() {
#ifdef USE_CONSOLEKIT
/* Setup the ConsoleKit session */
try {
- ck.open_session(DisplayName, pw->pw_uid);
+ ck.open_session(screenName, pw->pw_uid);
}
catch(Ck::Exception &e) {
logStream << APPNAME << ": " << e << endl;
+ if (existing_server) exit(REMANAGE_DISPLAY);
exit(ERR_EXIT);
}
#endif
@@ -607,7 +623,7 @@ void App::Login() {
child_env[n++]=StrConcat("USER=", pw->pw_name);
child_env[n++]=StrConcat("LOGNAME=", pw->pw_name);
child_env[n++]=StrConcat("PATH=", cfg->getOption("default_path").c_str());
- child_env[n++]=StrConcat("DISPLAY=", DisplayName);
+ child_env[n++]=StrConcat("DISPLAY=", screenName);
child_env[n++]=StrConcat("MAIL=", maildir.c_str());
child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str());
# ifdef USE_CONSOLEKIT
@@ -618,7 +634,7 @@ void App::Login() {
#endif
/* Login process starts here */
- SwitchUser Su(pw, cfg, DisplayName, child_env);
+ SwitchUser Su(pw, cfg, displayName, child_env);
string session = LoginPanel->getSession();
string loginCommand = cfg->getOption("login_cmd");
replaceVariables(loginCommand, SESSION_VAR, session);
@@ -628,6 +644,7 @@ void App::Login() {
replaceVariables(sessStart, USER_VAR, pw->pw_name);
system(sessStart.c_str());
}
+ putenv(StrConcat("XAUTHORITY=", xauthority.c_str()));
Su.Login(loginCommand.c_str(), mcookie.c_str());
_exit(OK_EXIT);
}
@@ -641,7 +658,7 @@ void App::Login() {
int status;
while (wpid != pid) {
wpid = wait(&status);
- if (wpid == ServerPID)
+ if (ServerPID != -1 && wpid == ServerPID)
xioerror(Dpy); /* Server died, simulate IO error */
}
if (WIFEXITED(status) && WEXITSTATUS(status)) {
@@ -712,6 +729,7 @@ void App::Reboot() {
StopServer();
RemoveLock();
system(cfg->getOption("reboot_cmd").c_str());
+ if (existing_server) exit(UNMANAGE_DISPLAY);
exit(OK_EXIT);
}
@@ -734,6 +752,7 @@ void App::Halt() {
StopServer();
RemoveLock();
system(cfg->getOption("halt_cmd").c_str());
+ if (existing_server) exit(UNMANAGE_DISPLAY);
exit(OK_EXIT);
}
@@ -782,6 +801,7 @@ void App::Exit() {
RemoveLock();
}
delete cfg;
+ if (existing_server) exit(REMANAGE_DISPLAY);
exit(OK_EXIT);
}
@@ -802,6 +822,7 @@ void App::RestartServer() {
StopServer();
RemoveLock();
while (waitpid(-1, NULL, WNOHANG) > 0); /* Collects all dead childrens */
+ if (existing_server) exit(RESERVER_DISPLAY);
Run();
}
@@ -871,7 +892,7 @@ int App::WaitForServer() {
int cycles;
for(cycles = 0; cycles < ncycles; cycles++) {
- if((Dpy = XOpenDisplay(DisplayName))) {
+ if((Dpy = XOpenDisplay(screenName.c_str()))) {
XSetIOErrorHandler(xioerror);
return 1;
} else {
@@ -1121,6 +1142,7 @@ void App::GetLock() {
/* Remove lockfile and close logs */
void App::RemoveLock() {
+ if (existing_server) return;
remove(cfg->getOption("lockfile").c_str());
}
@@ -1132,6 +1154,7 @@ bool App::isServerStarted() {
/* Redirect stdout and stderr to log file */
void App::OpenLog() {
+ if (existing_server) return;
if ( !logStream.openLog( cfg->getOption("logfile").c_str() ) ) {
logStream << APPNAME << ": Could not accesss log file: " << cfg->getOption("logfile") << endl;
RemoveLock();
@@ -1142,6 +1165,7 @@ void App::OpenLog() {
/* Relases stdout/err */
void App::CloseLog(){
+ if (existing_server) return;
/* Simply closing the log */
logStream.closeLog();
}
@@ -1213,7 +1237,7 @@ void App::CreateServerAuth() {
authfile = cfg->getOption("authfile");
remove(authfile.c_str());
putenv(StrConcat("XAUTHORITY=", authfile.c_str()));
- Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
+ Util::add_mcookie(mcookie, displayName.c_str(), cfg->getOption("xauth_path"),
authfile);
}
@@ -1233,3 +1257,40 @@ void App::UpdatePid() {
lockfile << getpid() << std::endl;
lockfile.close();
}
+
+void App::ReadServerAuth() {
+ /* read authorization from XAUTHORITY file */
+ char *xauth = getenv("XAUTHORITY");
+ if (!xauth || !xauth[0]) {
+ logStream << APPNAME << ": XAUTHORITY not defined in environment" << std::endl;
+ exit(OPENFAILED_DISPLAY);
+ }
+ FILE *authf = fopen(xauth,"r");
+ if (!authf) {
+ logStream << APPNAME << ": " << strerror(errno) << endl;
+ exit(OPENFAILED_DISPLAY);
+ }
+ /* XDM only fills out one entry */
+ Xauth *auth_in = XauReadAuth(authf);
+ if (!auth_in) {
+ logStream << APPNAME << ": no authority in file " << xauth << endl;
+ fclose(authf);
+ exit(OPENFAILED_DISPLAY);
+ }
+ char buf[256];
+ for (int i=0;i<auth_in->data_length&&i<128;i++) {
+ char c1, c2;
+ c1 = c2 = auth_in->data[i];
+ c1 >>= 4;
+ c1 &= 0x0f;
+ c2 &= 0x0f;
+ c1 = (c1 < 10) ? ('0' + c1) : ('a' + (c1 - 10));
+ c2 = (c2 < 10) ? ('0' + c2) : ('a' + (c2 - 10));
+ buf[(i<<1)+0] = c1;
+ buf[(i<<1)+1] = c2;
+ buf[(i<<1)+2] = 0;
+ }
+ mcookie = buf;
+ XauDisposeAuth(auth_in);
+ fclose(authf);
+}
Only in slim-1.3.5: .app.cpp.swo
diff -pur slim-1.3.5.orig/app.h slim-1.3.5/app.h
--- slim-1.3.5.orig/app.h 2012-12-31 06:03:42.000000000 -0700
+++ slim-1.3.5/app.h 2013-03-02 02:01:49.000000000 -0700
@@ -13,6 +13,7 @@
#define _APP_H_
#include <X11/Xlib.h>
+#include <X11/Xauth.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
@@ -61,6 +62,7 @@ private:
void CreateServerAuth();
char *StrConcat(const char *str1, const char *str2);
void UpdatePid();
+ void ReadServerAuth();
bool AuthenticateUser(bool focuspass);
@@ -80,7 +82,8 @@ private:
int Scr;
Panel *LoginPanel;
int ServerPID;
- const char *DisplayName;
+ std::string displayName;
+ std::string screenName;
bool serverStarted;
#ifdef USE_PAM
@@ -104,6 +107,7 @@ private:
bool firstlogin;
bool daemonmode;
bool force_nodaemon;
+ bool existing_server;
/* For testing themes */
char *testtheme;
bool testing;
diff -pur slim-1.3.5.orig/CMakeLists.txt slim-1.3.5/CMakeLists.txt
--- slim-1.3.5.orig/CMakeLists.txt 2012-12-31 06:03:42.000000000 -0700
+++ slim-1.3.5/CMakeLists.txt 2013-03-01 23:31:54.000000000 -0700
@@ -158,6 +158,7 @@ target_link_libraries(${PROJECT_NAME}
${X11_Xft_LIB}
${X11_Xrender_LIB}
${X11_Xmu_LIB}
+ ${X11_Xau_LIB}
${FREETYPE_LIBRARY}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
diff -pur slim-1.3.5.orig/const.h slim-1.3.5/const.h
--- slim-1.3.5.orig/const.h 2012-12-31 06:03:42.000000000 -0700
+++ slim-1.3.5/const.h 2013-02-28 07:49:06.000000000 -0700
@@ -13,7 +13,8 @@
#define _CONST_H_
#define APPNAME "slim"
-#define DISPLAY ":0.0"
+#define DISPLAY ":0"
+#define SCREEN ".0"
#define CONSOLE_STR "console"
#define HALT_STR "halt"
@@ -30,6 +31,12 @@
#define OK_EXIT 0
#define ERR_EXIT 1
+#define OBEYSESS_DISPLAY 0
+#define REMANAGE_DISPLAY 1
+#define UNMANAGE_DISPLAY 2
+#define RESERVER_DISPLAY 3
+#define OPENFAILED_DISPLAY 4
+
/* duration for showing error messages,
* as "login command failed", in seconds
*/
Only in slim-1.3.5: .image.cpp.swp
diff -pur slim-1.3.5.orig/log.h slim-1.3.5/log.h
--- slim-1.3.5.orig/log.h 2012-12-31 06:03:42.000000000 -0700
+++ slim-1.3.5/log.h 2013-02-27 02:13:47.000000000 -0700
@@ -9,6 +9,7 @@
#endif
#include "const.h"
#include <fstream>
+#include <iostream>
using namespace std;
@@ -22,17 +23,29 @@ public:
template<typename Type>
LogUnit & operator<<(const Type & text) {
- logFile << text; logFile.flush();
+ if (logFile.is_open()) {
+ logFile << text; logFile.flush();
+ } else {
+ cerr << text;
+ }
return *this;
}
LogUnit & operator<<(ostream & (*fp)(ostream&)) {
- logFile << fp; logFile.flush();
+ if (logFile.is_open()) {
+ logFile << fp; logFile.flush();
+ } else {
+ cerr << fp;
+ }
return *this;
}
LogUnit & operator<<(ios_base & (*fp)(ios_base&)) {
- logFile << fp; logFile.flush();
+ if (logFile.is_open()) {
+ logFile << fp; logFile.flush();
+ } else {
+ cerr << fp;
+ }
return *this;
}
} logStream;
diff -pur slim-1.3.5.orig/switchuser.cpp slim-1.3.5/switchuser.cpp
--- slim-1.3.5.orig/switchuser.cpp 2012-12-31 06:03:42.000000000 -0700
+++ slim-1.3.5/switchuser.cpp 2013-02-28 09:22:15.000000000 -0700
@@ -54,7 +54,6 @@ void SwitchUser::SetClientAuth(const cha
bool r;
string home = string(Pw->pw_dir);
string authfile = home + "/.Xauthority";
- remove(authfile.c_str());
- r = Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
+ r = Util::add_mcookie(mcookie, displayName.c_str(), cfg->getOption("xauth_path"),
authfile);
}
|