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-2017 Teddy Hogeborn
6
* Copyright © 2008-2017 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() */
32
#include <stdio.h> /* asprintf(), vasprintf(), vprintf(),
33
34
#include <stdlib.h> /* EXIT_FAILURE, free(),
35
36
#include <sys/types.h> /* pid_t, DIR, struct dirent,
42
43
sleep(), dup2() STDERR_FILENO,
43
44
STDOUT_FILENO, _exit(),
45
#include <string.h> /* memcmp() */
46
#include <string.h> /* memcmp(), strerror() */
46
47
#include <errno.h> /* errno, EACCES, ENOTDIR, ELOOP,
47
48
ENOENT, ENAMETOOLONG, EMFILE,
48
49
ENFILE, ENOMEM, ENOEXEC, EINVAL,
55
56
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
58
#include <stdarg.h> /* va_list, va_start(), ... */
58
60
sig_atomic_t interrupted_by_signal = 0;
59
61
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);
61
88
static void termination_handler(int signum){
62
89
if(interrupted_by_signal){
214
241
sigemptyset(&new_action.sa_mask);
215
242
ret = sigaddset(&new_action.sa_mask, SIGINT);
217
error(0, errno, "sigaddset");
244
error_plus(0, errno, "sigaddset");
218
245
exitstatus = EX_OSERR;
221
248
ret = sigaddset(&new_action.sa_mask, SIGHUP);
223
error(0, errno, "sigaddset");
250
error_plus(0, errno, "sigaddset");
224
251
exitstatus = EX_OSERR;
227
254
ret = sigaddset(&new_action.sa_mask, SIGTERM);
229
error(0, errno, "sigaddset");
256
error_plus(0, errno, "sigaddset");
230
257
exitstatus = EX_OSERR;
233
260
ret = sigaction(SIGINT, NULL, &old_action);
235
error(0, errno, "sigaction");
262
error_plus(0, errno, "sigaction");
236
263
exitstatus = EX_OSERR;
239
266
if(old_action.sa_handler != SIG_IGN){
240
267
ret = sigaction(SIGINT, &new_action, NULL);
242
error(0, errno, "sigaction");
269
error_plus(0, errno, "sigaction");
243
270
exitstatus = EX_OSERR;
247
274
ret = sigaction(SIGHUP, NULL, &old_action);
249
error(0, errno, "sigaction");
276
error_plus(0, errno, "sigaction");
250
277
exitstatus = EX_OSERR;
253
280
if(old_action.sa_handler != SIG_IGN){
254
281
ret = sigaction(SIGHUP, &new_action, NULL);
256
error(0, errno, "sigaction");
283
error_plus(0, errno, "sigaction");
257
284
exitstatus = EX_OSERR;
261
288
ret = sigaction(SIGTERM, NULL, &old_action);
263
error(0, errno, "sigaction");
290
error_plus(0, errno, "sigaction");
264
291
exitstatus = EX_OSERR;
267
294
if(old_action.sa_handler != SIG_IGN){
268
295
ret = sigaction(SIGTERM, &new_action, NULL);
270
error(0, errno, "sigaction");
297
error_plus(0, errno, "sigaction");
271
298
exitstatus = EX_OSERR;
382
409
the real user ID (_mandos) */
383
410
ret = setuid(geteuid());
385
error(0, errno, "setuid");
412
error_plus(0, errno, "setuid");
389
416
ret = chdir("/");
391
error(0, errno, "chdir");
418
error_plus(0, errno, "chdir");
393
420
/* if(fork() != 0){ */
394
421
/* _exit(EXIT_SUCCESS); */
396
423
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
398
error(0, errno, "dup2");
425
error_plus(0, errno, "dup2");
402
429
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
405
error(0, errno, "execl");
432
error_plus(0, errno, "execl");
428
455
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
429
456
&signal_action, NULL));
431
error(0, errno, "sigaction");
458
error_plus(0, errno, "sigaction");
434
461
ret = raise(signal_received);
435
462
} while(ret != 0 and errno == EINTR);
437
error(0, errno, "raise");
464
error_plus(0, errno, "raise");
440
467
TEMP_FAILURE_RETRY(pause());