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-2010 Teddy Hogeborn
6
* Copyright © 2008-2010 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() */
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() */
45
#include <string.h> /* memcmp() */
47
46
#include <errno.h> /* errno, EACCES, ENOTDIR, ELOOP,
48
47
ENOENT, ENAMETOOLONG, EMFILE,
49
48
ENFILE, ENOMEM, ENOEXEC, EINVAL,
56
55
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
58
#include <stdarg.h> /* va_list, va_start(), ... */
60
58
sig_atomic_t interrupted_by_signal = 0;
61
59
int signal_received;
63
/* Function to use when printing errors */
64
void error_plus(int status, int errnum, const char *formatstring,
70
va_start(ap, formatstring);
71
ret = vasprintf(&text, formatstring, ap);
73
fprintf(stderr, "Mandos plugin %s: ",
74
program_invocation_short_name);
75
vfprintf(stderr, formatstring, ap);
76
fprintf(stderr, ": ");
77
fprintf(stderr, "%s\n", strerror(errnum));
78
error(status, errno, "vasprintf while printing error");
81
fprintf(stderr, "Mandos plugin ");
82
error(status, errnum, "%s", text);
87
61
static void termination_handler(int signum){
88
62
if(interrupted_by_signal){
240
214
sigemptyset(&new_action.sa_mask);
241
215
ret = sigaddset(&new_action.sa_mask, SIGINT);
243
error_plus(0, errno, "sigaddset");
217
error(0, errno, "sigaddset");
244
218
exitstatus = EX_OSERR;
247
221
ret = sigaddset(&new_action.sa_mask, SIGHUP);
249
error_plus(0, errno, "sigaddset");
223
error(0, errno, "sigaddset");
250
224
exitstatus = EX_OSERR;
253
227
ret = sigaddset(&new_action.sa_mask, SIGTERM);
255
error_plus(0, errno, "sigaddset");
229
error(0, errno, "sigaddset");
256
230
exitstatus = EX_OSERR;
259
233
ret = sigaction(SIGINT, NULL, &old_action);
261
error_plus(0, errno, "sigaction");
235
error(0, errno, "sigaction");
262
236
exitstatus = EX_OSERR;
265
239
if(old_action.sa_handler != SIG_IGN){
266
240
ret = sigaction(SIGINT, &new_action, NULL);
268
error_plus(0, errno, "sigaction");
242
error(0, errno, "sigaction");
269
243
exitstatus = EX_OSERR;
273
247
ret = sigaction(SIGHUP, NULL, &old_action);
275
error_plus(0, errno, "sigaction");
249
error(0, errno, "sigaction");
276
250
exitstatus = EX_OSERR;
279
253
if(old_action.sa_handler != SIG_IGN){
280
254
ret = sigaction(SIGHUP, &new_action, NULL);
282
error_plus(0, errno, "sigaction");
256
error(0, errno, "sigaction");
283
257
exitstatus = EX_OSERR;
287
261
ret = sigaction(SIGTERM, NULL, &old_action);
289
error_plus(0, errno, "sigaction");
263
error(0, errno, "sigaction");
290
264
exitstatus = EX_OSERR;
293
267
if(old_action.sa_handler != SIG_IGN){
294
268
ret = sigaction(SIGTERM, &new_action, NULL);
296
error_plus(0, errno, "sigaction");
270
error(0, errno, "sigaction");
297
271
exitstatus = EX_OSERR;
408
382
the real user ID (_mandos) */
409
383
ret = setuid(geteuid());
411
error_plus(0, errno, "setuid");
385
error(0, errno, "setuid");
415
389
ret = chdir("/");
417
error_plus(0, errno, "chdir");
391
error(0, errno, "chdir");
419
393
/* if(fork() != 0){ */
420
394
/* _exit(EXIT_SUCCESS); */
422
396
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
424
error_plus(0, errno, "dup2");
398
error(0, errno, "dup2");
428
402
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
431
error_plus(0, errno, "execl");
405
error(0, errno, "execl");
454
428
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
455
429
&signal_action, NULL));
457
error_plus(0, errno, "sigaction");
431
error(0, errno, "sigaction");
460
434
ret = raise(signal_received);
461
435
} while(ret != 0 and errno == EINTR);
463
error_plus(0, errno, "raise");
437
error(0, errno, "raise");
466
440
TEMP_FAILURE_RETRY(pause());