3
3
* Splashy - Read a password from splashy and output it
5
* Copyright © 2008,2009 Teddy Hogeborn
6
* Copyright © 2008,2009 Björn Påhlsson
5
* Copyright © 2008-2011 Teddy Hogeborn
6
* Copyright © 2008-2011 Björn Påhlsson
8
8
* This program is free software: you can redistribute it and/or
9
9
* modify it under the terms of the GNU General Public License as
29
29
SIG_IGN, kill(), SIGKILL */
30
30
#include <stddef.h> /* NULL */
31
31
#include <stdlib.h> /* getenv() */
32
#include <stdio.h> /* asprintf(), perror() */
32
#include <stdio.h> /* asprintf() */
33
33
#include <stdlib.h> /* EXIT_FAILURE, free(),
35
35
#include <sys/types.h> /* pid_t, DIR, struct dirent,
43
43
STDOUT_FILENO, _exit(),
45
45
#include <string.h> /* memcmp() */
46
#include <errno.h> /* errno */
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,
52
#include <error.h> /* error() */
47
53
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
50
55
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
209
214
sigemptyset(&new_action.sa_mask);
210
215
ret = sigaddset(&new_action.sa_mask, SIGINT);
217
error(0, errno, "sigaddset");
213
218
exitstatus = EX_OSERR;
216
221
ret = sigaddset(&new_action.sa_mask, SIGHUP);
223
error(0, errno, "sigaddset");
219
224
exitstatus = EX_OSERR;
222
227
ret = sigaddset(&new_action.sa_mask, SIGTERM);
229
error(0, errno, "sigaddset");
225
230
exitstatus = EX_OSERR;
228
233
ret = sigaction(SIGINT, NULL, &old_action);
235
error(0, errno, "sigaction");
231
236
exitstatus = EX_OSERR;
234
239
if(old_action.sa_handler != SIG_IGN){
235
240
ret = sigaction(SIGINT, &new_action, NULL);
242
error(0, errno, "sigaction");
238
243
exitstatus = EX_OSERR;
242
247
ret = sigaction(SIGHUP, NULL, &old_action);
249
error(0, errno, "sigaction");
245
250
exitstatus = EX_OSERR;
248
253
if(old_action.sa_handler != SIG_IGN){
249
254
ret = sigaction(SIGHUP, &new_action, NULL);
256
error(0, errno, "sigaction");
252
257
exitstatus = EX_OSERR;
256
261
ret = sigaction(SIGTERM, NULL, &old_action);
263
error(0, errno, "sigaction");
259
264
exitstatus = EX_OSERR;
262
267
if(old_action.sa_handler != SIG_IGN){
263
268
ret = sigaction(SIGTERM, &new_action, NULL);
270
error(0, errno, "sigaction");
266
271
exitstatus = EX_OSERR;
288
293
if(not interrupted_by_signal){
289
294
const char splashy_command[] = "/sbin/splashy_update";
290
295
execl(splashy_command, splashy_command, prompt, (char *)NULL);
297
error(0, errno, "execl");
303
_exit(EX_UNAVAILABLE);
318
case ELIBBAD: /* Linux only */
294
325
_exit(EXIT_FAILURE);
351
382
the real user ID (_mandos) */
352
383
ret = setuid(geteuid());
385
error(0, errno, "setuid");
358
389
ret = chdir("/");
391
error(0, errno, "chdir");
362
393
/* if(fork() != 0){ */
363
394
/* _exit(EXIT_SUCCESS); */
365
396
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
398
error(0, errno, "dup2");
371
402
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
405
error(0, errno, "execl");
397
428
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
398
429
&signal_action, NULL));
431
error(0, errno, "sigaction");
403
434
ret = raise(signal_received);
404
435
} while(ret != 0 and errno == EINTR);
437
error(0, errno, "raise");
409
440
TEMP_FAILURE_RETRY(pause());