summarylogtreecommitdiffstats
path: root/patch
blob: 819ad807acb5302a6711a92ec5db0ee79759bfd2 (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
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
diff -r c2c082c4832e Makefile
--- a/Makefile	Tue Nov 15 13:02:40 2011 +0100
+++ b/Makefile	Fri Nov 18 10:31:51 2011 +0100
@@ -4,7 +4,7 @@
 .DEFAULT_GOAL = all
 .PHONY: all install install-strip installdirs uninstall clean
 
-prefix = /usr/local
+prefix = /usr
 
 exec_prefix = $(prefix)
 bindir      = $(exec_prefix)/bin
@@ -26,49 +26,33 @@
 .SUFFIXES: .o
 vpath %.c ./src
 
-PROGRAMS      = xlsh xlshd
+PROGRAMS      = xlsh
 
 XLSH_OBJ      = xlsh.o libxlsh.o
 XLSH_SOURCE   = xlsh.c libxlsh.c
 XLSH_HEADERS  = xlsh.h libxlsh.h config.h
 XLSH_LIBS     = -lreadline -lpam
 
-XLSHD_OBJ     = xlshd.o libxlsh.o
-XLSHD_SOURCE  = xlshd.c libxlsh.c
-XLSHD_HEADERS = config.h libxlsh.h
-
 all: $(PROGRAMS)
 
 xlsh: $(XLSH_OBJ)
 xlsh: LDLIBS=$(XLSH_LIBS)
 
-xlshd: $(XLSHD_OBJ)
-
 install: installdirs
 	$(INSTALL_PROGRAM) xlsh $(DESTDIR)$(sbindir)
-	$(INSTALL_PROGRAM) xlshd $(DESTDIR)$(sbindir)
-	$(INSTALL_DATA) etc/xlshrc $(DESTDIR)$(sysconfdir)/xlsh
-	$(INSTALL_DATA) etc/Xresources $(DESTDIR)$(sysconfdir)/xlsh
-	$(INSTALL_DATA) etc/pam.d/xlshd $(DESTDIR)$(sysconfdir)/pam.d
 
 install-strip: installdirs
 	$(INSTALL_PROGRAM_STRIP) xlsh $(DESTDIR)$(sbindir)
-	$(INSTALL_PROGRAM_STRIP) xlshd $(DESTDIR)$(sbindir)
-	$(INSTALL_DATA) etc/xlshrc $(DESTDIR)$(sysconfdir)/xlsh
-	$(INSTALL_DATA) etc/Xresources $(DESTDIR)$(sysconfdir)/xlsh
 
 installdirs:
 	$(INSTALL_DIR) $(DESTDIR)$(sbindir)
-	$(INSTALL_DIR) $(DESTDIR)$(sysconfdir)/xlsh
-	$(INSTALL_DIR) $(DESTDIR)$(sysconfdir)/pam.d
 
 uninstall:
 	rm -f ${DESTDIR}$(sbindir)/xlsh
-	rm -f ${DESTDIR}$(sbindir)/xlshd
 
 clean:
 	rm -f $(PROGRAMS)
-	rm -f $(XLSH_OBJ) $(XLSHD_OBJ)
+	rm -f $(XLSH_OBJ)
 
 %.o: %.c
 	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $< -o $@
diff -r c2c082c4832e include/config.h
--- a/include/config.h	Tue Nov 15 13:02:40 2011 +0100
+++ b/include/config.h	Fri Nov 18 10:31:51 2011 +0100
@@ -9,26 +9,36 @@
 
 // Tweak parameters to suit your needs before compiling.
 
+#define XLSH_X_SUPPORT 0
+
 #define XLSH_EXEC      "./.xsession"
-#define XLSH_PROMPT    "xlsh (%s)> "
+#define XLSH_PROMPT    "> "
 #define XLSH_TMPDIR    "/tmp"
 #define XLSH_SHELLS    "/etc/shells"
 #define XLSH_ISSUE     "/etc/issue"
 #define XLSH_PATH      "/bin:/usr/bin:/usr/local/bin"
 #define XLSH_REBOOT    "/sbin/shutdown -r now"
 #define XLSH_HALT      "/sbin/shutdown -h now"
+#if XLSH_X_SUPPORT
 #define XLSH_XRDB      "/usr/bin/xrdb -remove"
+#endif
 #define XLSH_XTTY      "/dev/console"
+#if XLSH_X_SUPPORT
 #define XLSH_XTTY_NAME "X11"
+#endif
 #define XLSH_DATEFMT   "%Y-%m-%d"
 #define XLSH_TIMEFMT   "%H:%M"
 #define XLSH_PAM_TTY   "login"
+#if XLSH_X_SUPPORT
 #define XLSH_PAM_X11   "xlshd"
+#endif
 
+#define XLSH_COMPLETION_LOGIN    0
 #define XLSH_COMPLETION_SHOWROOT 1
 #define XLSH_COMPLETION_MINUID   1000
 #define XLSH_COMPLETION_MAXUID   65534
 
+#if XLSH_X_SUPPORT
 #define XLSHD_TMPDIR   XLSH_TMPDIR
 #define XLSHD_SHELL    "/bin/sh"
 #define XLSHD_PIDFILE  "/var/run/xlshd.pid"
@@ -38,5 +48,6 @@
 #define XLSHD_XLSHRC   "/etc/xlsh/xlshrc"
 #define XLSHD_XWAIT    1
 #define XLSHD_XRETRY   2
+#endif
 
 #endif
diff -r c2c082c4832e include/libxlsh.h
--- a/include/libxlsh.h	Tue Nov 15 13:02:40 2011 +0100
+++ b/include/libxlsh.h	Fri Nov 18 10:31:51 2011 +0100
@@ -24,6 +24,7 @@
 
 size_t libxlsh_strnlen(const char* s, size_t maxlen);
 void   libxlsh_proc_sigmask(void);
+void   libxlsh_restore_sigmask(void);
 pid_t  libxlsh_proc_exec(const char* cmdline, int flags);
 pid_t  libxlsh_pid_read(const char* filename);
 int    libxlsh_pid_lock(const char* filename, pid_t pid, int flags);
diff -r c2c082c4832e include/xlsh.h
--- a/include/xlsh.h	Tue Nov 15 13:02:40 2011 +0100
+++ b/include/xlsh.h	Fri Nov 18 10:31:51 2011 +0100
@@ -58,7 +58,9 @@
 int xlsh_session_exec(pam_handle_t* handle, const char* session, const char* arg0);
 
 int xlsh_session_tty(const char* user, const char* shell);
+#if XLSH_X_SUPPORT
 int xlsh_session_x(const char* user, const char* shell);
+#endif
 
 int xlsh_sys_getinfo(xlsh_system_t* sysinfo);
 int xlsh_sys_issue(const char* issuefile);
diff -r c2c082c4832e src/libxlsh.c
--- a/src/libxlsh.c	Tue Nov 15 13:02:40 2011 +0100
+++ b/src/libxlsh.c	Fri Nov 18 10:31:51 2011 +0100
@@ -32,6 +32,11 @@
   sigprocmask(0, NULL, &xlsh_default_sigmask);
 }
 
+void libxlsh_restore_sigmask(void)
+{
+  sigprocmask(SIG_SETMASK, &xlsh_default_sigmask, NULL);
+}
+
 pid_t libxlsh_proc_exec(const char* cmdline, int flags)
 {
   pid_t pid;
diff -r c2c082c4832e src/xlsh.c
--- a/src/xlsh.c	Tue Nov 15 13:02:40 2011 +0100
+++ b/src/xlsh.c	Fri Nov 18 10:31:51 2011 +0100
@@ -51,7 +51,9 @@
   { NULL, NULL, NULL },
 };
 
+#if XLSH_X_SUPPORT
 static int xlsh_X = 0;
+#endif
 
 static void xlsh_usage(char* argv0)
 {
@@ -99,18 +101,22 @@
     return XLSH_EARG;
   }
 
+#if XLSH_X_SUPPORT
   if(xlsh_X) {
     if(!arg_shell)
       arg_shell = xlsh_config[XLSH_ID_EXEC].value;
     return xlsh_session_x(arg_user, arg_shell);
   }
   else
+#endif
     return xlsh_session_tty(arg_user, arg_shell);
 }
 
 int xlsh_func_reboot(int argc, char** argv)
 {
+#if XLSH_X_SUPPORT
   pid_t xlshd_pid;
+#endif
 
   printf("Initiating system reboot ...\n");
   if(libxlsh_proc_exec(XLSH_REBOOT, XLSH_DETACH) == -1) {
@@ -118,28 +124,34 @@
     return XLSH_ERROR;
   }
 
+#if XLSH_X_SUPPORT
   xlshd_pid = libxlsh_pid_read(XLSHD_PIDFILE);
   if(xlshd_pid > 0)
     kill(xlshd_pid, SIGTERM);
-
+#endif
+  
   pause();
   return XLSH_EDONE;
 }
 
 int xlsh_func_shutdown(int argc, char** argv)
 {
+#if XLSH_X_SUPPORT
   pid_t xlshd_pid;
-
+#endif
+  
   printf("Initiating system shutdown ...\n");
   if(libxlsh_proc_exec(XLSH_HALT, XLSH_DETACH) == -1) {
     fprintf(stderr, "Failed to execute: %s\n", XLSH_HALT);
     return XLSH_ERROR;
   }
 
+#if XLSH_X_SUPPORT
   xlshd_pid = libxlsh_pid_read(XLSHD_PIDFILE);
   if(xlshd_pid > 0)
     kill(xlshd_pid, SIGTERM);
-
+#endif
+  
   pause();
   return XLSH_EDONE;
 }
@@ -242,9 +254,11 @@
   if(pam_start(service, user, &conv, &pam_handle) != PAM_SUCCESS)
     return XLSH_ERROR;
   
+#if XLSH_X_SUPPORT
   if(xlsh_X)
     pam_set_item(pam_handle, PAM_TTY, XLSH_XTTY);
   else
+#endif
     pam_set_item(pam_handle, PAM_TTY, ttyname(0));
 
   if(pam_authenticate(pam_handle, 0) != PAM_SUCCESS) {
@@ -318,6 +332,7 @@
     setenv("HOME", pwinfo->pw_dir, 1);
     setenv("PATH", xlsh_config[XLSH_ID_PATH].value, 1);
     
+#if XLSH_X_SUPPORT
     if(xlsh_X) {
       setenv("SHELL", pwinfo->pw_shell, 1);
       setenv("DISPLAY", xlsh_config[XLSH_ID_DISPLAY].value, 1);
@@ -325,11 +340,13 @@
 	wait(&proc_wait);
     }
     else
+#endif
       setenv("SHELL", session, 1);
 		
     if(*terminal)
       setenv("TERM", terminal, 1);
 
+    libxlsh_restore_sigmask();
     execlp(session, _arg0, (char*)0);
     exit(EXIT_FAILURE);
   }
@@ -382,6 +399,7 @@
   return XLSH_EDONE;
 }
 
+#if XLSH_X_SUPPORT
 int xlsh_session_x(const char* user, const char* shell)
 {
   pid_t proc_session;
@@ -446,6 +464,7 @@
     
   return XLSH_EOK;
 }
+#endif
 
 // Configuration
 void xlsh_config_init(char* exec_arg)
@@ -516,6 +535,7 @@
   return NULL;
 }
 
+#if XLSH_COMPLETION_LOGIN
 static char* xlsh_cmd_match_user(const char* text, int state)
 {
   static size_t len;
@@ -540,6 +560,7 @@
   endpwent();
   return NULL;
 }
+#endif
 
 static char** xlsh_cmd_complete(const char* text, int start, int end)
 {
@@ -552,8 +573,12 @@
     return rl_completion_matches(const_cast.c,
 				 xlsh_cmd_match_command);
   else
+#if XLSH_COMPLETION_LOGIN
     return rl_completion_matches(const_cast.c,
 				 xlsh_cmd_match_user);
+#else
+    return NULL;
+#endif
 }
 
 int xlsh_cmd_loop(void)
@@ -569,7 +594,7 @@
   int retvalue = XLSH_EOK;
 
   xlsh_sys_getinfo(&sysinfo);
-  snprintf(prompt, 256, XLSH_PROMPT, sysinfo.ttyname);
+  snprintf(prompt, 256, XLSH_PROMPT);
 
   rl_attempted_completion_function = xlsh_cmd_complete;
   while((line = xlsh_cmd_readline(prompt))) {
@@ -623,6 +648,7 @@
     strcpy(tty_path, XLSH_XTTY);
   strncpy(sysinfo->ttypath, tty_path + 5, sizeof(sysinfo->ttypath));
   
+#if XLSH_X_SUPPORT
   if(xlsh_X) {
     disp_name = getenv("DISPLAY");
     if(disp_name[0] == ':')
@@ -631,6 +657,7 @@
     tty_name = tty_path;
   }
   else
+#endif
     tty_name = tty_path + 5;
   strncpy(sysinfo->ttyname, tty_name, sizeof(sysinfo->ttyname));
   
@@ -721,8 +748,10 @@
   sigaddset(&sigmask, SIGHUP);
   sigprocmask(SIG_BLOCK, &sigmask, NULL);
 
+#if XLSH_X_SUPPORT
   if(getenv("DISPLAY"))
     xlsh_X = 1;
+#endif
   
   xlsh_config_init(opt_exec);
   xlsh_sys_issue(xlsh_config[XLSH_ID_ISSUE].value);