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,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() */
 
 
32
#include <stdio.h>              /* asprintf(), perror() */
 
33
33
#include <stdlib.h>             /* EXIT_FAILURE, free(),
 
35
35
#include <sys/types.h>          /* pid_t, DIR, struct dirent,
 
 
43
43
                                   STDOUT_FILENO, _exit(),
 
45
45
#include <string.h>             /* memcmp() */
 
46
 
#include <errno.h>              /* errno, EACCES, ENOTDIR, ELOOP,
 
47
 
                                   ENOENT, ENAMETOOLONG, EMFILE,
 
48
 
                                   ENFILE, ENOMEM, ENOEXEC, EINVAL,
 
49
 
                                   E2BIG, EFAULT, EIO, ETXTBSY,
 
50
 
                                   EISDIR, ELIBBAD, EPERM, EINTR,
 
52
 
#include <error.h>              /* error() */
 
 
46
#include <errno.h>              /* errno */
 
53
47
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
 
55
 
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
 
58
50
sig_atomic_t interrupted_by_signal = 0;
 
59
51
int signal_received;
 
 
109
99
    const char splashy_name[] = "/sbin/splashy";
 
110
100
    proc_dir = opendir("/proc");
 
111
101
    if(proc_dir == NULL){
 
113
 
      error(0, errno, "opendir");
 
120
 
        exitstatus = EX_OSFILE;
 
126
 
        exitstatus = EX_OSERR;
 
131
105
    for(struct dirent *proc_ent = readdir(proc_dir);
 
 
214
174
    sigemptyset(&new_action.sa_mask);
 
215
175
    ret = sigaddset(&new_action.sa_mask, SIGINT);
 
217
 
      error(0, errno, "sigaddset");
 
218
 
      exitstatus = EX_OSERR;
 
221
180
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
 
223
 
      error(0, errno, "sigaddset");
 
224
 
      exitstatus = EX_OSERR;
 
227
185
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
 
229
 
      error(0, errno, "sigaddset");
 
230
 
      exitstatus = EX_OSERR;
 
233
190
    ret = sigaction(SIGINT, NULL, &old_action);
 
235
 
      error(0, errno, "sigaction");
 
236
 
      exitstatus = EX_OSERR;
 
239
195
    if(old_action.sa_handler != SIG_IGN){
 
240
196
      ret = sigaction(SIGINT, &new_action, NULL);
 
242
 
        error(0, errno, "sigaction");
 
243
 
        exitstatus = EX_OSERR;
 
247
202
    ret = sigaction(SIGHUP, NULL, &old_action);
 
249
 
      error(0, errno, "sigaction");
 
250
 
      exitstatus = EX_OSERR;
 
253
207
    if(old_action.sa_handler != SIG_IGN){
 
254
208
      ret = sigaction(SIGHUP, &new_action, NULL);
 
256
 
        error(0, errno, "sigaction");
 
257
 
        exitstatus = EX_OSERR;
 
261
214
    ret = sigaction(SIGTERM, NULL, &old_action);
 
263
 
      error(0, errno, "sigaction");
 
264
 
      exitstatus = EX_OSERR;
 
267
219
    if(old_action.sa_handler != SIG_IGN){
 
268
220
      ret = sigaction(SIGTERM, &new_action, NULL);
 
270
 
        error(0, errno, "sigaction");
 
271
 
        exitstatus = EX_OSERR;
 
 
293
243
    if(not interrupted_by_signal){
 
294
244
      const char splashy_command[] = "/sbin/splashy_update";
 
295
245
      execl(splashy_command, splashy_command, prompt, (char *)NULL);
 
297
 
      error(0, errno, "execl");
 
303
 
        _exit(EX_UNAVAILABLE);
 
323
249
    _exit(EXIT_FAILURE);
 
 
380
306
         the real user ID (_mandos) */
 
381
307
      ret = setuid(geteuid());
 
383
 
        error(0, errno, "setuid");
 
387
313
      ret = chdir("/");
 
389
 
        error(0, errno, "chdir");
 
391
317
/*       if(fork() != 0){ */
 
392
318
/*      _exit(EXIT_SUCCESS); */
 
394
320
      ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
 
396
 
        error(0, errno, "dup2");
 
400
326
      execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
 
403
 
        error(0, errno, "execl");
 
409
 
          _exit(EX_UNAVAILABLE);
 
 
426
336
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
 
427
337
                                            &signal_action, NULL));
 
429
 
      error(0, errno, "sigaction");
 
432
342
      ret = raise(signal_received);
 
433
343
    } while(ret != 0 and errno == EINTR);
 
435
 
      error(0, errno, "raise");
 
438
348
    TEMP_FAILURE_RETRY(pause());