bzr branch
http://bzr.recompile.se/loggerhead/mandos/trunk
237.1.2
by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax |
1 |
/* -*- coding: utf-8 -*- */
|
2 |
/*
|
|
261
by Teddy Hogeborn
* plugins.d/askpass-fifo.c: Fix name in header. |
3 |
* Splashy - Read a password from splashy and output it
|
237.1.2
by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax |
4 |
*
|
246
by Teddy Hogeborn
* README: Update copyright year; add "2009". |
5 |
* Copyright © 2008,2009 Teddy Hogeborn
|
6 |
* Copyright © 2008,2009 Björn Påhlsson
|
|
237.1.2
by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax |
7 |
*
|
8 |
* This program is free software: you can redistribute it and/or
|
|
9 |
* modify it under the terms of the GNU General Public License as
|
|
10 |
* published by the Free Software Foundation, either version 3 of the
|
|
11 |
* License, or (at your option) any later version.
|
|
12 |
*
|
|
13 |
* This program is distributed in the hope that it will be useful, but
|
|
14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 |
* General Public License for more details.
|
|
17 |
*
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
19 |
* along with this program. If not, see
|
|
20 |
* <http://www.gnu.org/licenses/>.
|
|
21 |
*
|
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
22 |
* Contact the authors at <mandos@fukt.bsnet.se>.
|
237.1.2
by Teddy Hogeborn
Further steps towards a D-Bus server interface, plus minor syntax |
23 |
*/
|
24 |
||
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
25 |
#define _GNU_SOURCE /* TEMP_FAILURE_RETRY(), asprintf() */ |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
26 |
#include <signal.h> /* sig_atomic_t, struct sigaction, |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
27 |
sigemptyset(), sigaddset(), SIGINT, |
28 |
SIGHUP, SIGTERM, sigaction, |
|
29 |
SIG_IGN, kill(), SIGKILL */ |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
30 |
#include <stddef.h> /* NULL */ |
31 |
#include <stdlib.h> /* getenv() */ |
|
311
by Teddy Hogeborn
Overflows are not detected by sscanf(), so stop using it: |
32 |
#include <stdio.h> /* asprintf(), perror() */ |
264
by Teddy Hogeborn
* plugin-runner.c (main): Use "sscanf" instead of "strtol"; using the |
33 |
#include <stdlib.h> /* EXIT_FAILURE, free(), |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
34 |
EXIT_SUCCESS */ |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
35 |
#include <sys/types.h> /* pid_t, DIR, struct dirent, |
36 |
ssize_t */ |
|
37 |
#include <dirent.h> /* opendir(), readdir(), closedir() */ |
|
311
by Teddy Hogeborn
Overflows are not detected by sscanf(), so stop using it: |
38 |
#include <inttypes.h> /* intmax_t, strtoimax() */ |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
39 |
#include <sys/stat.h> /* struct stat, lstat(), S_ISLNK */ |
40 |
#include <iso646.h> /* not, or, and */ |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
41 |
#include <unistd.h> /* readlink(), fork(), execl(), |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
42 |
sleep(), dup2() STDERR_FILENO, |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
43 |
STDOUT_FILENO, _exit(), |
44 |
pause() */ |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
45 |
#include <string.h> /* memcmp() */ |
390
by Teddy Hogeborn
* plugins.d/askpass-fifo.c: Do close(STDOUT_FILENO) before exiting to |
46 |
#include <errno.h> /* errno, EACCES, ENOTDIR, ELOOP, |
47 |
ENOENT, ENAMETOOLONG, EMFILE, |
|
48 |
ENFILE, ENOMEM, ENOEXEC, EINVAL, |
|
49 |
E2BIG, EFAULT, EIO, ETXTBSY, |
|
50 |
EISDIR, ELIBBAD, EPERM, EINTR, |
|
51 |
ECHILD */ |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
52 |
#include <sys/wait.h> /* waitpid(), WIFEXITED(), |
53 |
WEXITSTATUS() */ |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
54 |
#include <sysexits.h> /* EX_OSERR, EX_OSFILE, |
55 |
EX_UNAVAILABLE */ |
|
56 |
||
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
57 |
sig_atomic_t interrupted_by_signal = 0; |
362
by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR |
58 |
int signal_received; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
59 |
|
362
by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR |
60 |
static void termination_handler(int signum){ |
61 |
if(interrupted_by_signal){ |
|
62 |
return; |
|
63 |
} |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
64 |
interrupted_by_signal = 1; |
362
by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR |
65 |
signal_received = signum; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
66 |
}
|
67 |
||
208
by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash". |
68 |
int main(__attribute__((unused))int argc, |
69 |
__attribute__((unused))char **argv){ |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
70 |
int ret = 0; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
71 |
char *prompt = NULL; |
72 |
DIR *proc_dir = NULL; |
|
73 |
pid_t splashy_pid = 0; |
|
74 |
pid_t splashy_command_pid = 0; |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
75 |
int exitstatus = EXIT_FAILURE; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
76 |
|
77 |
/* Create prompt string */ |
|
78 |
{ |
|
79 |
const char *const cryptsource = getenv("cryptsource"); |
|
80 |
const char *const crypttarget = getenv("crypttarget"); |
|
81 |
const char *const prompt_start = "getpass " |
|
82 |
"Enter passphrase to unlock the disk"; |
|
83 |
|
|
84 |
if(cryptsource == NULL){ |
|
85 |
if(crypttarget == NULL){ |
|
86 |
ret = asprintf(&prompt, "%s: ", prompt_start); |
|
87 |
} else { |
|
88 |
ret = asprintf(&prompt, "%s (%s): ", prompt_start, |
|
89 |
crypttarget); |
|
90 |
} |
|
91 |
} else { |
|
92 |
if(crypttarget == NULL){ |
|
93 |
ret = asprintf(&prompt, "%s %s: ", prompt_start, cryptsource); |
|
94 |
} else { |
|
95 |
ret = asprintf(&prompt, "%s %s (%s): ", prompt_start, |
|
96 |
cryptsource, crypttarget); |
|
97 |
} |
|
98 |
} |
|
99 |
if(ret == -1){ |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
100 |
prompt = NULL; |
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
101 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
102 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
103 |
} |
104 |
} |
|
105 |
|
|
106 |
/* Find splashy process */ |
|
107 |
{ |
|
108 |
const char splashy_name[] = "/sbin/splashy"; |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
109 |
proc_dir = opendir("/proc"); |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
110 |
if(proc_dir == NULL){ |
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
111 |
int e = errno; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
112 |
perror("opendir"); |
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
113 |
switch(e){ |
114 |
case EACCES: |
|
115 |
case ENOTDIR: |
|
116 |
case ELOOP: |
|
117 |
case ENOENT: |
|
118 |
default: |
|
119 |
exitstatus = EX_OSFILE; |
|
120 |
break; |
|
121 |
case ENAMETOOLONG: |
|
122 |
case EMFILE: |
|
123 |
case ENFILE: |
|
124 |
case ENOMEM: |
|
125 |
exitstatus = EX_OSERR; |
|
126 |
break; |
|
127 |
} |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
128 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
129 |
} |
130 |
for(struct dirent *proc_ent = readdir(proc_dir); |
|
131 |
proc_ent != NULL; |
|
132 |
proc_ent = readdir(proc_dir)){ |
|
264
by Teddy Hogeborn
* plugin-runner.c (main): Use "sscanf" instead of "strtol"; using the |
133 |
pid_t pid; |
268
by Teddy Hogeborn
Fixes for sscanf usage: |
134 |
{ |
135 |
intmax_t tmpmax; |
|
311
by Teddy Hogeborn
Overflows are not detected by sscanf(), so stop using it: |
136 |
char *tmp; |
137 |
errno = 0; |
|
138 |
tmpmax = strtoimax(proc_ent->d_name, &tmp, 10); |
|
139 |
if(errno != 0 or tmp == proc_ent->d_name or *tmp != '\0' |
|
140 |
or tmpmax != (pid_t)tmpmax){ |
|
268
by Teddy Hogeborn
Fixes for sscanf usage: |
141 |
/* Not a process */ |
142 |
continue; |
|
143 |
} |
|
144 |
pid = (pid_t)tmpmax; |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
145 |
} |
146 |
/* Find the executable name by doing readlink() on the |
|
147 |
/proc/<pid>/exe link */
|
|
148 |
char exe_target[sizeof(splashy_name)]; |
|
208
by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash". |
149 |
ssize_t sret; |
150 |
{ |
|
151 |
char *exe_link; |
|
152 |
ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name); |
|
153 |
if(ret == -1){ |
|
154 |
perror("asprintf"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
155 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
156 |
goto failure; |
208
by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash". |
157 |
} |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
158 |
|
159 |
/* Check that it refers to a symlink owned by root:root */ |
|
160 |
struct stat exe_stat; |
|
161 |
ret = lstat(exe_link, &exe_stat); |
|
162 |
if(ret == -1){ |
|
262
by Teddy Hogeborn
* plugins.d/splashy.c (main): Do not abort if a process vanishes while |
163 |
if(errno == ENOENT){ |
164 |
free(exe_link); |
|
165 |
continue; |
|
166 |
} |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
167 |
int e = errno; |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
168 |
perror("lstat"); |
169 |
free(exe_link); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
170 |
switch(e){ |
171 |
case EACCES: |
|
172 |
case ENOTDIR: |
|
173 |
case ELOOP: |
|
174 |
default: |
|
175 |
exitstatus = EX_OSFILE; |
|
176 |
break; |
|
177 |
case ENAMETOOLONG: |
|
178 |
exitstatus = EX_OSERR; |
|
179 |
break; |
|
180 |
} |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
181 |
goto failure; |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
182 |
} |
183 |
if(not S_ISLNK(exe_stat.st_mode) |
|
184 |
or exe_stat.st_uid != 0 |
|
185 |
or exe_stat.st_gid != 0){ |
|
186 |
free(exe_link); |
|
187 |
continue; |
|
188 |
} |
|
189 |
|
|
208
by Teddy Hogeborn
* Makefile (PLUGINS): Added "plugins.d/usplash". |
190 |
sret = readlink(exe_link, exe_target, sizeof(exe_target)); |
191 |
free(exe_link); |
|
192 |
} |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
193 |
if((sret == ((ssize_t)sizeof(exe_target)-1)) |
194 |
and (memcmp(splashy_name, exe_target, |
|
195 |
sizeof(exe_target)-1) == 0)){ |
|
196 |
splashy_pid = pid; |
|
197 |
break; |
|
198 |
} |
|
199 |
} |
|
200 |
closedir(proc_dir); |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
201 |
proc_dir = NULL; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
202 |
} |
203 |
if(splashy_pid == 0){ |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
204 |
exitstatus = EX_UNAVAILABLE; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
205 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
206 |
} |
207 |
|
|
208 |
/* Set up the signal handler */ |
|
209 |
{ |
|
210 |
struct sigaction old_action, |
|
211 |
new_action = { .sa_handler = termination_handler, |
|
212 |
.sa_flags = 0 }; |
|
213 |
sigemptyset(&new_action.sa_mask); |
|
369
by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added |
214 |
ret = sigaddset(&new_action.sa_mask, SIGINT); |
215 |
if(ret == -1){ |
|
216 |
perror("sigaddset"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
217 |
exitstatus = EX_OSERR; |
369
by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added |
218 |
goto failure; |
219 |
} |
|
220 |
ret = sigaddset(&new_action.sa_mask, SIGHUP); |
|
221 |
if(ret == -1){ |
|
222 |
perror("sigaddset"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
223 |
exitstatus = EX_OSERR; |
369
by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added |
224 |
goto failure; |
225 |
} |
|
226 |
ret = sigaddset(&new_action.sa_mask, SIGTERM); |
|
362
by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR |
227 |
if(ret == -1){ |
228 |
perror("sigaddset"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
229 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
230 |
goto failure; |
362
by Teddy Hogeborn
* plugin-runner.c (getplugin, add_environment, main): Handle EINTR |
231 |
} |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
232 |
ret = sigaction(SIGINT, NULL, &old_action); |
233 |
if(ret == -1){ |
|
234 |
perror("sigaction"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
235 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
236 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
237 |
} |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
238 |
if(old_action.sa_handler != SIG_IGN){ |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
239 |
ret = sigaction(SIGINT, &new_action, NULL); |
240 |
if(ret == -1){ |
|
241 |
perror("sigaction"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
242 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
243 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
244 |
} |
245 |
} |
|
246 |
ret = sigaction(SIGHUP, NULL, &old_action); |
|
247 |
if(ret == -1){ |
|
248 |
perror("sigaction"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
249 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
250 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
251 |
} |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
252 |
if(old_action.sa_handler != SIG_IGN){ |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
253 |
ret = sigaction(SIGHUP, &new_action, NULL); |
254 |
if(ret == -1){ |
|
255 |
perror("sigaction"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
256 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
257 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
258 |
} |
259 |
} |
|
260 |
ret = sigaction(SIGTERM, NULL, &old_action); |
|
261 |
if(ret == -1){ |
|
262 |
perror("sigaction"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
263 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
264 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
265 |
} |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
266 |
if(old_action.sa_handler != SIG_IGN){ |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
267 |
ret = sigaction(SIGTERM, &new_action, NULL); |
268 |
if(ret == -1){ |
|
269 |
perror("sigaction"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
270 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
271 |
goto failure; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
272 |
} |
273 |
} |
|
274 |
} |
|
275 |
|
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
276 |
if(interrupted_by_signal){ |
277 |
goto failure; |
|
278 |
} |
|
279 |
|
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
280 |
/* Fork off the splashy command to prompt for password */ |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
281 |
splashy_command_pid = fork(); |
282 |
if(splashy_command_pid != 0 and interrupted_by_signal){ |
|
283 |
goto failure; |
|
284 |
} |
|
285 |
if(splashy_command_pid == -1){ |
|
286 |
perror("fork"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
287 |
exitstatus = EX_OSERR; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
288 |
goto failure; |
289 |
} |
|
290 |
/* Child */ |
|
291 |
if(splashy_command_pid == 0){ |
|
292 |
if(not interrupted_by_signal){ |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
293 |
const char splashy_command[] = "/sbin/splashy_update"; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
294 |
execl(splashy_command, splashy_command, prompt, (char *)NULL); |
390
by Teddy Hogeborn
* plugins.d/askpass-fifo.c: Do close(STDOUT_FILENO) before exiting to |
295 |
int e = errno; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
296 |
perror("execl"); |
390
by Teddy Hogeborn
* plugins.d/askpass-fifo.c: Do close(STDOUT_FILENO) before exiting to |
297 |
switch(e){ |
298 |
case EACCES: |
|
299 |
case ENOENT: |
|
300 |
case ENOEXEC: |
|
301 |
case EINVAL: |
|
302 |
_exit(EX_UNAVAILABLE); |
|
303 |
case ENAMETOOLONG: |
|
304 |
case E2BIG: |
|
305 |
case ENOMEM: |
|
306 |
case EFAULT: |
|
307 |
case EIO: |
|
308 |
case EMFILE: |
|
309 |
case ENFILE: |
|
310 |
case ETXTBSY: |
|
311 |
default: |
|
312 |
_exit(EX_OSERR); |
|
313 |
case ENOTDIR: |
|
314 |
case ELOOP: |
|
315 |
case EISDIR: |
|
316 |
case ELIBBAD: |
|
317 |
case EPERM: |
|
318 |
_exit(EX_OSFILE); |
|
319 |
} |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
320 |
} |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
321 |
free(prompt); |
322 |
_exit(EXIT_FAILURE); |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
323 |
} |
324 |
|
|
325 |
/* Parent */ |
|
326 |
free(prompt); |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
327 |
prompt = NULL; |
328 |
|
|
329 |
if(interrupted_by_signal){ |
|
330 |
goto failure; |
|
331 |
} |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
332 |
|
333 |
/* Wait for command to complete */ |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
334 |
{ |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
335 |
int status; |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
336 |
do { |
337 |
ret = waitpid(splashy_command_pid, &status, 0); |
|
338 |
} while(ret == -1 and errno == EINTR |
|
339 |
and not interrupted_by_signal); |
|
340 |
if(interrupted_by_signal){ |
|
341 |
goto failure; |
|
342 |
} |
|
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
343 |
if(ret == -1){ |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
344 |
perror("waitpid"); |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
345 |
if(errno == ECHILD){ |
346 |
splashy_command_pid = 0; |
|
347 |
} |
|
348 |
} else { |
|
349 |
/* The child process has exited */ |
|
350 |
splashy_command_pid = 0; |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
351 |
if(WIFEXITED(status) and WEXITSTATUS(status) == 0){ |
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
352 |
return EXIT_SUCCESS; |
353 |
} |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
354 |
} |
355 |
} |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
356 |
|
357 |
failure: |
|
358 |
|
|
359 |
free(prompt); |
|
360 |
|
|
361 |
if(proc_dir != NULL){ |
|
362 |
TEMP_FAILURE_RETRY(closedir(proc_dir)); |
|
363 |
} |
|
364 |
|
|
365 |
if(splashy_command_pid != 0){ |
|
366 |
TEMP_FAILURE_RETRY(kill(splashy_command_pid, SIGTERM)); |
|
223
by Teddy Hogeborn
* .bzrignore (plugins.d/askpass-fifo): Added. |
367 |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
368 |
TEMP_FAILURE_RETRY(kill(splashy_pid, SIGTERM)); |
369 |
sleep(2); |
|
370 |
while(TEMP_FAILURE_RETRY(kill(splashy_pid, 0)) == 0){ |
|
371 |
TEMP_FAILURE_RETRY(kill(splashy_pid, SIGKILL)); |
|
372 |
sleep(1); |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
373 |
} |
369
by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added |
374 |
pid_t new_splashy_pid = (pid_t)TEMP_FAILURE_RETRY(fork()); |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
375 |
if(new_splashy_pid == 0){ |
376 |
/* Child; will become new splashy process */ |
|
377 |
|
|
378 |
/* Make the effective user ID (root) the only user ID instead of |
|
379 |
the real user ID (_mandos) */
|
|
380 |
ret = setuid(geteuid()); |
|
381 |
if(ret == -1){ |
|
382 |
perror("setuid"); |
|
383 |
} |
|
384 |
|
|
385 |
setsid(); |
|
386 |
ret = chdir("/"); |
|
387 |
if(ret == -1){ |
|
388 |
perror("chdir"); |
|
389 |
} |
|
390 |
/* if(fork() != 0){ */
|
|
391 |
/* _exit(EXIT_SUCCESS); */
|
|
392 |
/* } */
|
|
393 |
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */ |
|
394 |
if(ret == -1){ |
|
395 |
perror("dup2"); |
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
396 |
_exit(EX_OSERR); |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
397 |
} |
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
398 |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
399 |
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL); |
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
400 |
{ |
401 |
int e = errno; |
|
402 |
perror("execl"); |
|
403 |
switch(e){ |
|
404 |
case EACCES: |
|
405 |
case ENOENT: |
|
406 |
case ENOEXEC: |
|
407 |
default: |
|
408 |
_exit(EX_UNAVAILABLE); |
|
409 |
case ENAMETOOLONG: |
|
410 |
case E2BIG: |
|
411 |
case ENOMEM: |
|
412 |
_exit(EX_OSERR); |
|
413 |
case ENOTDIR: |
|
414 |
case ELOOP: |
|
415 |
_exit(EX_OSFILE); |
|
416 |
} |
|
417 |
} |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
418 |
} |
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
419 |
} |
420 |
|
|
421 |
if(interrupted_by_signal){ |
|
422 |
struct sigaction signal_action; |
|
423 |
sigemptyset(&signal_action.sa_mask); |
|
424 |
signal_action.sa_handler = SIG_DFL; |
|
369
by Teddy Hogeborn
* init.d-mandos (Required-Start, Required-Stop): Bug fix: Added |
425 |
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received, |
426 |
&signal_action, NULL)); |
|
363
by Teddy Hogeborn
* plugin-runner.c: Minor stylistic changes. |
427 |
if(ret == -1){ |
428 |
perror("sigaction"); |
|
429 |
} |
|
430 |
do { |
|
431 |
ret = raise(signal_received); |
|
432 |
} while(ret != 0 and errno == EINTR); |
|
433 |
if(ret != 0){ |
|
434 |
perror("raise"); |
|
435 |
abort(); |
|
436 |
} |
|
437 |
TEMP_FAILURE_RETRY(pause()); |
|
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
438 |
} |
439 |
|
|
389
by Teddy Hogeborn
* plugins.d/splashy.c: Use exit codes from <sysexits.h>. |
440 |
return exitstatus; |
205
by Teddy Hogeborn
* Makefile (PLUGINS, uninstall-client, |
441 |
}
|