3
3
* Splashy - Read a password from splashy and output it
5
* Copyright © 2008-2012 Teddy Hogeborn
6
* Copyright © 2008-2012 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(),
32
#include <stdio.h> /* asprintf(), perror() */
34
33
#include <stdlib.h> /* EXIT_FAILURE, free(),
36
35
#include <sys/types.h> /* pid_t, DIR, struct dirent,
43
42
sleep(), dup2() STDERR_FILENO,
44
43
STDOUT_FILENO, _exit(),
46
#include <string.h> /* memcmp(), strerror() */
47
#include <errno.h> /* errno, EACCES, ENOTDIR, ELOOP,
48
ENOENT, ENAMETOOLONG, EMFILE,
49
ENFILE, ENOMEM, ENOEXEC, EINVAL,
50
E2BIG, EFAULT, EIO, ETXTBSY,
51
EISDIR, ELIBBAD, EPERM, EINTR,
53
#include <error.h> /* error() */
45
#include <string.h> /* memcmp() */
46
#include <errno.h> /* errno */
54
47
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
56
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
58
#include <stdarg.h> /* va_list, va_start(), ... */
60
50
sig_atomic_t interrupted_by_signal = 0;
61
51
int signal_received;
63
/* Function to use when printing errors */
64
__attribute__((format (gnu_printf, 3, 4)))
65
void error_plus(int status, int errnum, const char *formatstring,
71
va_start(ap, formatstring);
72
ret = vasprintf(&text, formatstring, ap);
74
fprintf(stderr, "Mandos plugin %s: ",
75
program_invocation_short_name);
76
vfprintf(stderr, formatstring, ap);
77
fprintf(stderr, ": ");
78
fprintf(stderr, "%s\n", strerror(errnum));
79
error(status, errno, "vasprintf while printing error");
82
fprintf(stderr, "Mandos plugin ");
83
error(status, errnum, "%s", text);
88
53
static void termination_handler(int signum){
89
54
if(interrupted_by_signal){
239
172
new_action = { .sa_handler = termination_handler,
241
174
sigemptyset(&new_action.sa_mask);
242
ret = sigaddset(&new_action.sa_mask, SIGINT);
244
error_plus(0, errno, "sigaddset");
245
exitstatus = EX_OSERR;
248
ret = sigaddset(&new_action.sa_mask, SIGHUP);
250
error_plus(0, errno, "sigaddset");
251
exitstatus = EX_OSERR;
254
ret = sigaddset(&new_action.sa_mask, SIGTERM);
256
error_plus(0, errno, "sigaddset");
257
exitstatus = EX_OSERR;
175
sigaddset(&new_action.sa_mask, SIGINT);
180
sigaddset(&new_action.sa_mask, SIGHUP);
185
sigaddset(&new_action.sa_mask, SIGTERM);
260
190
ret = sigaction(SIGINT, NULL, &old_action);
262
error_plus(0, errno, "sigaction");
263
exitstatus = EX_OSERR;
266
195
if(old_action.sa_handler != SIG_IGN){
267
196
ret = sigaction(SIGINT, &new_action, NULL);
269
error_plus(0, errno, "sigaction");
270
exitstatus = EX_OSERR;
274
202
ret = sigaction(SIGHUP, NULL, &old_action);
276
error_plus(0, errno, "sigaction");
277
exitstatus = EX_OSERR;
280
207
if(old_action.sa_handler != SIG_IGN){
281
208
ret = sigaction(SIGHUP, &new_action, NULL);
283
error_plus(0, errno, "sigaction");
284
exitstatus = EX_OSERR;
288
214
ret = sigaction(SIGTERM, NULL, &old_action);
290
error_plus(0, errno, "sigaction");
291
exitstatus = EX_OSERR;
294
219
if(old_action.sa_handler != SIG_IGN){
295
220
ret = sigaction(SIGTERM, &new_action, NULL);
297
error_plus(0, errno, "sigaction");
298
exitstatus = EX_OSERR;
320
243
if(not interrupted_by_signal){
321
244
const char splashy_command[] = "/sbin/splashy_update";
322
245
execl(splashy_command, splashy_command, prompt, (char *)NULL);
324
error_plus(0, errno, "execl");
330
_exit(EX_UNAVAILABLE);
345
case ELIBBAD: /* Linux only */
352
249
_exit(EXIT_FAILURE);
409
306
the real user ID (_mandos) */
410
307
ret = setuid(geteuid());
412
error_plus(0, errno, "setuid");
416
313
ret = chdir("/");
418
error_plus(0, errno, "chdir");
420
317
/* if(fork() != 0){ */
421
318
/* _exit(EXIT_SUCCESS); */
423
320
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
425
error_plus(0, errno, "dup2");
429
326
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
432
error_plus(0, errno, "execl");
438
_exit(EX_UNAVAILABLE);
452
333
struct sigaction signal_action;
453
334
sigemptyset(&signal_action.sa_mask);
454
335
signal_action.sa_handler = SIG_DFL;
455
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
456
&signal_action, NULL));
336
ret = TEMP_FAILURE_RETRY(sigaction(signal_received,
337
&signal_action, NULL));
458
error_plus(0, errno, "sigaction");
461
342
ret = raise(signal_received);
462
343
} while(ret != 0 and errno == EINTR);
464
error_plus(0, errno, "raise");
467
348
TEMP_FAILURE_RETRY(pause());