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