/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/usplash.c

todo

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <dirent.h>             /* opendir(), readdir(), closedir() */
48
48
#include <inttypes.h>           /* intmax_t, strtoimax() */
49
49
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
50
 
#include <sysexits.h>           /* EX_OSERR, EX_UNAVAILABLE */
51
50
 
52
51
sig_atomic_t interrupted_by_signal = 0;
53
52
int signal_received;
298
297
  size_t buf_len = 0;
299
298
  pid_t usplash_pid = -1;
300
299
  bool usplash_accessed = false;
301
 
  int status = EXIT_FAILURE;    /* Default failure exit status */
302
300
  
303
301
  char *prompt = makeprompt();
304
302
  if(prompt == NULL){
305
 
    status = EX_OSERR;
306
303
    goto failure;
307
304
  }
308
305
  
311
308
  size_t cmdline_len = 0;
312
309
  usplash_pid = find_usplash(&cmdline, &cmdline_len);
313
310
  if(usplash_pid == 0){
314
 
    status = EX_UNAVAILABLE;
315
311
    goto failure;
316
312
  }
317
313
  
324
320
    ret = sigaddset(&new_action.sa_mask, SIGINT);
325
321
    if(ret == -1){
326
322
      perror("sigaddset");
327
 
      status = EX_OSERR;
328
323
      goto failure;
329
324
    }
330
325
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
331
326
    if(ret == -1){
332
327
      perror("sigaddset");
333
 
      status = EX_OSERR;
334
328
      goto failure;
335
329
    }
336
330
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
337
331
    if(ret == -1){
338
332
      perror("sigaddset");
339
 
      status = EX_OSERR;
340
333
      goto failure;
341
334
    }
342
335
    ret = sigaction(SIGINT, NULL, &old_action);
343
336
    if(ret == -1){
344
337
      if(errno != EINTR){
345
338
        perror("sigaction");
346
 
        status = EX_OSERR;
347
339
      }
348
340
      goto failure;
349
341
    }
352
344
      if(ret == -1){
353
345
        if(errno != EINTR){
354
346
          perror("sigaction");
355
 
          status = EX_OSERR;
356
347
        }
357
348
        goto failure;
358
349
      }
361
352
    if(ret == -1){
362
353
      if(errno != EINTR){
363
354
        perror("sigaction");
364
 
        status = EX_OSERR;
365
355
      }
366
356
      goto failure;
367
357
    }
370
360
      if(ret == -1){
371
361
        if(errno != EINTR){
372
362
          perror("sigaction");
373
 
          status = EX_OSERR;
374
363
        }
375
364
        goto failure;
376
365
      }
379
368
    if(ret == -1){
380
369
      if(errno != EINTR){
381
370
        perror("sigaction");
382
 
        status = EX_OSERR;
383
371
      }
384
372
      goto failure;
385
373
    }
388
376
      if(ret == -1){
389
377
        if(errno != EINTR){
390
378
          perror("sigaction");
391
 
          status = EX_OSERR;
392
379
        }
393
380
        goto failure;
394
381
      }
400
387
  if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
401
388
    if(errno != EINTR){
402
389
      perror("usplash_write");
403
 
      status = EX_OSERR;
404
390
    }
405
391
    goto failure;
406
392
  }
412
398
  if(not usplash_write(&fifo_fd, "INPUTQUIET", prompt)){
413
399
    if(errno != EINTR){
414
400
      perror("usplash_write");
415
 
      status = EX_OSERR;
416
401
    }
417
402
    goto failure;
418
403
  }
430
415
  if(outfifo_fd == -1){
431
416
    if(errno != EINTR){
432
417
      perror("open");
433
 
      status = EX_OSERR;
434
418
    }
435
419
    goto failure;
436
420
  }
449
433
      if(tmp == NULL){
450
434
        if(errno != EINTR){
451
435
          perror("realloc");
452
 
          status = EX_OSERR;
453
436
        }
454
437
        goto failure;
455
438
      }
461
444
    if(sret == -1){
462
445
      if(errno != EINTR){
463
446
        perror("read");
464
 
        status = EX_OSERR;
465
447
      }
466
448
      TEMP_FAILURE_RETRY(close(outfifo_fd));
467
449
      goto failure;
476
458
  if(ret == -1){
477
459
    if(errno != EINTR){
478
460
      perror("close");
479
 
      status = EX_OSERR;
480
461
    }
481
462
    goto failure;
482
463
  }
489
470
  if(not usplash_write(&fifo_fd, "TIMEOUT", "15")){
490
471
    if(errno != EINTR){
491
472
      perror("usplash_write");
492
 
      status = EX_OSERR;
493
473
    }
494
474
    goto failure;
495
475
  }
502
482
  if(ret == -1){
503
483
    if(errno != EINTR){
504
484
      perror("close");
505
 
      status = EX_OSERR;
506
485
    }
507
486
    goto failure;
508
487
  }
516
495
      if(sret == -1){
517
496
        if(errno != EINTR){
518
497
          perror("write");
519
 
          status = EX_OSERR;
520
498
        }
521
499
        goto failure;
522
500
      }
545
523
  
546
524
  /* If usplash was never accessed, we can stop now */
547
525
  if(not usplash_accessed){
548
 
    return status;
 
526
    return EXIT_FAILURE;
549
527
  }
550
528
  
551
529
  /* Close FIFO */
577
555
      if(tmp == NULL){
578
556
        perror("realloc");
579
557
        free(cmdline_argv);
580
 
        return status;
 
558
        return EXIT_FAILURE;
581
559
      }
582
560
      cmdline_argv = tmp;
583
561
      cmdline_argv[cmdline_argc] = cmdline + position;
613
591
    ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
614
592
    if(ret == -1){
615
593
      perror("dup2");
616
 
      _exit(EX_OSERR);
 
594
      _exit(EXIT_FAILURE);
617
595
    }
618
596
    
619
597
    execv(usplash_name, cmdline_argv);
622
600
    }
623
601
    free(cmdline);
624
602
    free(cmdline_argv);
625
 
    _exit(EX_OSERR);
 
603
    _exit(EXIT_FAILURE);
626
604
  }
627
605
  free(cmdline);
628
606
  free(cmdline_argv);
660
638
    TEMP_FAILURE_RETRY(pause());
661
639
  }
662
640
  
663
 
  return status;
 
641
  return EXIT_FAILURE;
664
642
}