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