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
382
the real user ID (_mandos) */
406
383
ret = setuid(geteuid());
408
error_plus(0, errno, "setuid");
385
error(0, errno, "setuid");
412
389
ret = chdir("/");
414
error_plus(0, errno, "chdir");
391
error(0, errno, "chdir");
416
393
/* if(fork() != 0){ */
417
394
/* _exit(EXIT_SUCCESS); */
419
396
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
421
error_plus(0, errno, "dup2");
398
error(0, errno, "dup2");
425
402
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
428
error_plus(0, errno, "execl");
405
error(0, errno, "execl");
451
428
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
452
429
&signal_action, NULL));
454
error_plus(0, errno, "sigaction");
431
error(0, errno, "sigaction");
457
434
ret = raise(signal_received);
458
435
} while(ret != 0 and errno == EINTR);
460
error_plus(0, errno, "raise");
437
error(0, errno, "raise");
463
440
TEMP_FAILURE_RETRY(pause());