3
3
* Splashy - Read a password from splashy and output it
5
* Copyright © 2008-2011 Teddy Hogeborn
6
* Copyright © 2008-2011 Björn Påhlsson
5
* Copyright © 2008,2009 Teddy Hogeborn
6
* Copyright © 2008,2009 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(), vasprintf(), vprintf(), fprintf() */
32
#include <stdio.h> /* asprintf(), perror() */
33
33
#include <stdlib.h> /* EXIT_FAILURE, free(),
35
35
#include <sys/types.h> /* pid_t, DIR, struct dirent,
42
42
sleep(), dup2() STDERR_FILENO,
43
43
STDOUT_FILENO, _exit(),
45
#include <string.h> /* memcmp(), strerror() */
45
#include <string.h> /* memcmp() */
46
46
#include <errno.h> /* errno, EACCES, ENOTDIR, ELOOP,
47
47
ENOENT, ENAMETOOLONG, EMFILE,
48
48
ENFILE, ENOMEM, ENOEXEC, EINVAL,
49
49
E2BIG, EFAULT, EIO, ETXTBSY,
50
50
EISDIR, ELIBBAD, EPERM, EINTR,
52
#include <error.h> /* error() */
53
52
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
55
54
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
57
#include <stdarg.h> /* va_list, va_start(), ... */
59
57
sig_atomic_t interrupted_by_signal = 0;
60
58
int signal_received;
62
/* Function to use when printing errors */
63
void error_plus(int status, int errnum, const char *formatstring, ...){
68
va_start(ap, formatstring);
69
ret = vasprintf(&text, formatstring, ap);
71
fprintf(stderr, "Mandos plugin %s: ", program_invocation_short_name);
72
vfprintf(stderr, formatstring, ap);
73
fprintf(stderr, ": ");
74
fprintf(stderr, "%s\n", strerror(errnum));
75
error(status, errno, "vasprintf while printing error");
78
fprintf(stderr, "Mandos plugin ");
79
error(status, errnum, "%s", text);
84
60
static void termination_handler(int signum){
85
61
if(interrupted_by_signal){
237
213
sigemptyset(&new_action.sa_mask);
238
214
ret = sigaddset(&new_action.sa_mask, SIGINT);
240
error_plus(0, errno, "sigaddset");
241
217
exitstatus = EX_OSERR;
244
220
ret = sigaddset(&new_action.sa_mask, SIGHUP);
246
error_plus(0, errno, "sigaddset");
247
223
exitstatus = EX_OSERR;
250
226
ret = sigaddset(&new_action.sa_mask, SIGTERM);
252
error_plus(0, errno, "sigaddset");
253
229
exitstatus = EX_OSERR;
256
232
ret = sigaction(SIGINT, NULL, &old_action);
258
error_plus(0, errno, "sigaction");
259
235
exitstatus = EX_OSERR;
262
238
if(old_action.sa_handler != SIG_IGN){
263
239
ret = sigaction(SIGINT, &new_action, NULL);
265
error_plus(0, errno, "sigaction");
266
242
exitstatus = EX_OSERR;
270
246
ret = sigaction(SIGHUP, NULL, &old_action);
272
error_plus(0, errno, "sigaction");
273
249
exitstatus = EX_OSERR;
276
252
if(old_action.sa_handler != SIG_IGN){
277
253
ret = sigaction(SIGHUP, &new_action, NULL);
279
error_plus(0, errno, "sigaction");
280
256
exitstatus = EX_OSERR;
284
260
ret = sigaction(SIGTERM, NULL, &old_action);
286
error_plus(0, errno, "sigaction");
287
263
exitstatus = EX_OSERR;
290
266
if(old_action.sa_handler != SIG_IGN){
291
267
ret = sigaction(SIGTERM, &new_action, NULL);
293
error_plus(0, errno, "sigaction");
294
270
exitstatus = EX_OSERR;
405
379
the real user ID (_mandos) */
406
380
ret = setuid(geteuid());
408
error_plus(0, errno, "setuid");
412
386
ret = chdir("/");
414
error_plus(0, errno, "chdir");
416
390
/* if(fork() != 0){ */
417
391
/* _exit(EXIT_SUCCESS); */
419
393
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
421
error_plus(0, errno, "dup2");
425
399
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
428
error_plus(0, errno, "execl");
451
425
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
452
426
&signal_action, NULL));
454
error_plus(0, errno, "sigaction");
457
431
ret = raise(signal_received);
458
432
} while(ret != 0 and errno == EINTR);
460
error_plus(0, errno, "raise");
463
437
TEMP_FAILURE_RETRY(pause());