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() */
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() */
45
#include <string.h> /* memcmp() */
46
#include <errno.h> /* errno */
53
47
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
55
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
57
#include <stdarg.h> /* va_list, va_start(), ... */
59
50
sig_atomic_t interrupted_by_signal = 0;
60
51
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
53
static void termination_handler(int signum){
85
54
if(interrupted_by_signal){
237
174
sigemptyset(&new_action.sa_mask);
238
175
ret = sigaddset(&new_action.sa_mask, SIGINT);
240
error_plus(0, errno, "sigaddset");
241
exitstatus = EX_OSERR;
244
180
ret = sigaddset(&new_action.sa_mask, SIGHUP);
246
error_plus(0, errno, "sigaddset");
247
exitstatus = EX_OSERR;
250
185
ret = sigaddset(&new_action.sa_mask, SIGTERM);
252
error_plus(0, errno, "sigaddset");
253
exitstatus = EX_OSERR;
256
190
ret = sigaction(SIGINT, NULL, &old_action);
258
error_plus(0, errno, "sigaction");
259
exitstatus = EX_OSERR;
262
195
if(old_action.sa_handler != SIG_IGN){
263
196
ret = sigaction(SIGINT, &new_action, NULL);
265
error_plus(0, errno, "sigaction");
266
exitstatus = EX_OSERR;
270
202
ret = sigaction(SIGHUP, NULL, &old_action);
272
error_plus(0, errno, "sigaction");
273
exitstatus = EX_OSERR;
276
207
if(old_action.sa_handler != SIG_IGN){
277
208
ret = sigaction(SIGHUP, &new_action, NULL);
279
error_plus(0, errno, "sigaction");
280
exitstatus = EX_OSERR;
284
214
ret = sigaction(SIGTERM, NULL, &old_action);
286
error_plus(0, errno, "sigaction");
287
exitstatus = EX_OSERR;
290
219
if(old_action.sa_handler != SIG_IGN){
291
220
ret = sigaction(SIGTERM, &new_action, NULL);
293
error_plus(0, errno, "sigaction");
294
exitstatus = EX_OSERR;
316
243
if(not interrupted_by_signal){
317
244
const char splashy_command[] = "/sbin/splashy_update";
318
245
execl(splashy_command, splashy_command, prompt, (char *)NULL);
320
error_plus(0, errno, "execl");
326
_exit(EX_UNAVAILABLE);
341
case ELIBBAD: /* Linux only */
348
249
_exit(EXIT_FAILURE);
405
306
the real user ID (_mandos) */
406
307
ret = setuid(geteuid());
408
error_plus(0, errno, "setuid");
412
313
ret = chdir("/");
414
error_plus(0, errno, "chdir");
416
317
/* if(fork() != 0){ */
417
318
/* _exit(EXIT_SUCCESS); */
419
320
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
421
error_plus(0, errno, "dup2");
425
326
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
428
error_plus(0, errno, "execl");
434
_exit(EX_UNAVAILABLE);
451
336
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
452
337
&signal_action, NULL));
454
error_plus(0, errno, "sigaction");
457
342
ret = raise(signal_received);
458
343
} while(ret != 0 and errno == EINTR);
460
error_plus(0, errno, "raise");
463
348
TEMP_FAILURE_RETRY(pause());