/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/splashy.c

  • Committer: Teddy Hogeborn
  • Date: 2009-11-09 07:35:16 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091109073516-v1vem352uz0vuwrd
* dbus-mandos.conf: New; to be copied to
                    "/etc/dbus-1/system.d/mandos.conf".

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Splashy - Read a password from splashy and output it
4
4
 * 
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
7
7
 * 
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(),
34
34
                                   EXIT_SUCCESS */
35
35
#include <sys/types.h>          /* pid_t, DIR, struct dirent,
49
49
                                   E2BIG, EFAULT, EIO, ETXTBSY,
50
50
                                   EISDIR, ELIBBAD, EPERM, EINTR,
51
51
                                   ECHILD */
52
 
#include <error.h>              /* error() */
53
52
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
54
53
                                   WEXITSTATUS() */
55
54
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
110
109
    proc_dir = opendir("/proc");
111
110
    if(proc_dir == NULL){
112
111
      int e = errno;
113
 
      error(0, errno, "opendir");
 
112
      perror("opendir");
114
113
      switch(e){
115
114
      case EACCES:
116
115
      case ENOTDIR:
152
151
        char *exe_link;
153
152
        ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
154
153
        if(ret == -1){
155
 
          error(0, errno, "asprintf");
 
154
          perror("asprintf");
156
155
          exitstatus = EX_OSERR;
157
156
          goto failure;
158
157
        }
166
165
            continue;
167
166
          }
168
167
          int e = errno;
169
 
          error(0, errno, "lstat");
 
168
          perror("lstat");
170
169
          free(exe_link);
171
170
          switch(e){
172
171
          case EACCES:
214
213
    sigemptyset(&new_action.sa_mask);
215
214
    ret = sigaddset(&new_action.sa_mask, SIGINT);
216
215
    if(ret == -1){
217
 
      error(0, errno, "sigaddset");
 
216
      perror("sigaddset");
218
217
      exitstatus = EX_OSERR;
219
218
      goto failure;
220
219
    }
221
220
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
222
221
    if(ret == -1){
223
 
      error(0, errno, "sigaddset");
 
222
      perror("sigaddset");
224
223
      exitstatus = EX_OSERR;
225
224
      goto failure;
226
225
    }
227
226
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
228
227
    if(ret == -1){
229
 
      error(0, errno, "sigaddset");
 
228
      perror("sigaddset");
230
229
      exitstatus = EX_OSERR;
231
230
      goto failure;
232
231
    }
233
232
    ret = sigaction(SIGINT, NULL, &old_action);
234
233
    if(ret == -1){
235
 
      error(0, errno, "sigaction");
 
234
      perror("sigaction");
236
235
      exitstatus = EX_OSERR;
237
236
      goto failure;
238
237
    }
239
238
    if(old_action.sa_handler != SIG_IGN){
240
239
      ret = sigaction(SIGINT, &new_action, NULL);
241
240
      if(ret == -1){
242
 
        error(0, errno, "sigaction");
 
241
        perror("sigaction");
243
242
        exitstatus = EX_OSERR;
244
243
        goto failure;
245
244
      }
246
245
    }
247
246
    ret = sigaction(SIGHUP, NULL, &old_action);
248
247
    if(ret == -1){
249
 
      error(0, errno, "sigaction");
 
248
      perror("sigaction");
250
249
      exitstatus = EX_OSERR;
251
250
      goto failure;
252
251
    }
253
252
    if(old_action.sa_handler != SIG_IGN){
254
253
      ret = sigaction(SIGHUP, &new_action, NULL);
255
254
      if(ret == -1){
256
 
        error(0, errno, "sigaction");
 
255
        perror("sigaction");
257
256
        exitstatus = EX_OSERR;
258
257
        goto failure;
259
258
      }
260
259
    }
261
260
    ret = sigaction(SIGTERM, NULL, &old_action);
262
261
    if(ret == -1){
263
 
      error(0, errno, "sigaction");
 
262
      perror("sigaction");
264
263
      exitstatus = EX_OSERR;
265
264
      goto failure;
266
265
    }
267
266
    if(old_action.sa_handler != SIG_IGN){
268
267
      ret = sigaction(SIGTERM, &new_action, NULL);
269
268
      if(ret == -1){
270
 
        error(0, errno, "sigaction");
 
269
        perror("sigaction");
271
270
        exitstatus = EX_OSERR;
272
271
        goto failure;
273
272
      }
284
283
    goto failure;
285
284
  }
286
285
  if(splashy_command_pid == -1){
287
 
    error(0, errno, "fork");
 
286
    perror("fork");
288
287
    exitstatus = EX_OSERR;
289
288
    goto failure;
290
289
  }
294
293
      const char splashy_command[] = "/sbin/splashy_update";
295
294
      execl(splashy_command, splashy_command, prompt, (char *)NULL);
296
295
      int e = errno;
297
 
      error(0, errno, "execl");
 
296
      perror("execl");
298
297
      switch(e){
299
298
      case EACCES:
300
299
      case ENOENT:
314
313
      case ENOTDIR:
315
314
      case ELOOP:
316
315
      case EISDIR:
317
 
#ifdef ELIBBAD
318
 
      case ELIBBAD:             /* Linux only */
319
 
#endif
 
316
      case ELIBBAD:
320
317
      case EPERM:
321
318
        _exit(EX_OSFILE);
322
319
      }
344
341
      goto failure;
345
342
    }
346
343
    if(ret == -1){
347
 
      error(0, errno, "waitpid");
 
344
      perror("waitpid");
348
345
      if(errno == ECHILD){
349
346
        splashy_command_pid = 0;
350
347
      }
382
379
         the real user ID (_mandos) */
383
380
      ret = setuid(geteuid());
384
381
      if(ret == -1){
385
 
        error(0, errno, "setuid");
 
382
        perror("setuid");
386
383
      }
387
384
      
388
385
      setsid();
389
386
      ret = chdir("/");
390
387
      if(ret == -1){
391
 
        error(0, errno, "chdir");
 
388
        perror("chdir");
392
389
      }
393
390
/*       if(fork() != 0){ */
394
391
/*      _exit(EXIT_SUCCESS); */
395
392
/*       } */
396
393
      ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
397
394
      if(ret == -1){
398
 
        error(0, errno, "dup2");
 
395
        perror("dup2");
399
396
        _exit(EX_OSERR);
400
397
      }
401
398
      
402
399
      execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
403
400
      {
404
401
        int e = errno;
405
 
        error(0, errno, "execl");
 
402
        perror("execl");
406
403
        switch(e){
407
404
        case EACCES:
408
405
        case ENOENT:
428
425
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
429
426
                                            &signal_action, NULL));
430
427
    if(ret == -1){
431
 
      error(0, errno, "sigaction");
 
428
      perror("sigaction");
432
429
    }
433
430
    do {
434
431
      ret = raise(signal_received);
435
432
    } while(ret != 0 and errno == EINTR);
436
433
    if(ret != 0){
437
 
      error(0, errno, "raise");
 
434
      perror("raise");
438
435
      abort();
439
436
    }
440
437
    TEMP_FAILURE_RETRY(pause());