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() */
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() */
45
#include <string.h> /* memcmp() */
46
46
#include <errno.h> /* errno, EACCES, ENOTDIR, ELOOP,
47
47
ENOENT, ENAMETOOLONG, EMFILE,
48
48
ENFILE, ENOMEM, ENOEXEC, EINVAL,
55
55
#include <sysexits.h> /* EX_OSERR, EX_OSFILE,
57
#include <stdarg.h> /* va_list, va_start(), ... */
59
58
sig_atomic_t interrupted_by_signal = 0;
60
59
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
61
static void termination_handler(int signum){
85
62
if(interrupted_by_signal){
237
214
sigemptyset(&new_action.sa_mask);
238
215
ret = sigaddset(&new_action.sa_mask, SIGINT);
240
error_plus(0, errno, "sigaddset");
217
error(0, errno, "sigaddset");
241
218
exitstatus = EX_OSERR;
244
221
ret = sigaddset(&new_action.sa_mask, SIGHUP);
246
error_plus(0, errno, "sigaddset");
223
error(0, errno, "sigaddset");
247
224
exitstatus = EX_OSERR;
250
227
ret = sigaddset(&new_action.sa_mask, SIGTERM);
252
error_plus(0, errno, "sigaddset");
229
error(0, errno, "sigaddset");
253
230
exitstatus = EX_OSERR;
256
233
ret = sigaction(SIGINT, NULL, &old_action);
258
error_plus(0, errno, "sigaction");
235
error(0, errno, "sigaction");
259
236
exitstatus = EX_OSERR;
262
239
if(old_action.sa_handler != SIG_IGN){
263
240
ret = sigaction(SIGINT, &new_action, NULL);
265
error_plus(0, errno, "sigaction");
242
error(0, errno, "sigaction");
266
243
exitstatus = EX_OSERR;
270
247
ret = sigaction(SIGHUP, NULL, &old_action);
272
error_plus(0, errno, "sigaction");
249
error(0, errno, "sigaction");
273
250
exitstatus = EX_OSERR;
276
253
if(old_action.sa_handler != SIG_IGN){
277
254
ret = sigaction(SIGHUP, &new_action, NULL);
279
error_plus(0, errno, "sigaction");
256
error(0, errno, "sigaction");
280
257
exitstatus = EX_OSERR;
284
261
ret = sigaction(SIGTERM, NULL, &old_action);
286
error_plus(0, errno, "sigaction");
263
error(0, errno, "sigaction");
287
264
exitstatus = EX_OSERR;
290
267
if(old_action.sa_handler != SIG_IGN){
291
268
ret = sigaction(SIGTERM, &new_action, NULL);
293
error_plus(0, errno, "sigaction");
270
error(0, errno, "sigaction");
294
271
exitstatus = EX_OSERR;
405
380
the real user ID (_mandos) */
406
381
ret = setuid(geteuid());
408
error_plus(0, errno, "setuid");
383
error(0, errno, "setuid");
412
387
ret = chdir("/");
414
error_plus(0, errno, "chdir");
389
error(0, errno, "chdir");
416
391
/* if(fork() != 0){ */
417
392
/* _exit(EXIT_SUCCESS); */
419
394
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
421
error_plus(0, errno, "dup2");
396
error(0, errno, "dup2");
425
400
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
428
error_plus(0, errno, "execl");
403
error(0, errno, "execl");
451
426
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
452
427
&signal_action, NULL));
454
error_plus(0, errno, "sigaction");
429
error(0, errno, "sigaction");
457
432
ret = raise(signal_received);
458
433
} while(ret != 0 and errno == EINTR);
460
error_plus(0, errno, "raise");
435
error(0, errno, "raise");
463
438
TEMP_FAILURE_RETRY(pause());