/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

  • Committer: Teddy Hogeborn
  • Date: 2026-05-17 23:56:03 UTC
  • Revision ID: teddy@recompile.se-20260517235603-5ygymkxkh32rxjkf
Remove white space at end of most lines

Remove white space at end of most lines.  Except for where it is
significant, like in shell script "here documents" where the delimiter
word is prefixed by "-", in block comments, and in config file example
settings.  Also not in README files, the INSTALL file, the DBUS-API
file, or the COPYING file (the last of which was copied verbatim from
FSF).

* dbus-mandos.conf: Remove white space at end of lines.
* debian/mandos-client.postinst: - '' -
* debian/mandos-client.templates: - '' -
* debian/mandos.postinst: - '' -
* dracut-module/password-agent.c: - '' -
* dracut-module/password-agent.xml: - '' -
* intro.xml: - '' -
* legalnotice.xml: - '' -
* mandos-clients.conf.xml: - '' -
* mandos-ctl.xml: - '' -
* mandos-keygen: - '' -
* mandos-keygen.xml: - '' -
* mandos-monitor.xml: - '' -
* mandos-options.xml: - '' -
* mandos.conf.xml: - '' -
* mandos.xml: - '' -
* network-hooks.d/wireless: - '' -
* plugin-helpers/mandos-client-iprouteadddel.c: - '' -
* plugin-runner.c: - '' -
* plugin-runner.xml: - '' -
* plugins.d/askpass-fifo.c: - '' -
* plugins.d/askpass-fifo.xml: - '' -
* plugins.d/mandos-client.c: - '' -
* plugins.d/mandos-client.xml: - '' -
* plugins.d/password-prompt.c: - '' -
* plugins.d/password-prompt.xml: - '' -
* plugins.d/plymouth.c: - '' -
* plugins.d/plymouth.xml: - '' -
* plugins.d/splashy.c: - '' -
* plugins.d/splashy.xml: - '' -
* plugins.d/usplash.c: - '' -
* plugins.d/usplash.xml: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
  va_list ap;
72
72
  char *text;
73
73
  int ret;
74
 
  
 
74
 
75
75
  va_start(ap, formatstring);
76
76
  ret = vasprintf(&text, formatstring, ap);
77
77
  if(ret == -1){
112
112
    }
113
113
    *fifo_fd_r = ret;
114
114
  }
115
 
  
 
115
 
116
116
  const char *cmd_line;
117
117
  size_t cmd_line_len;
118
118
  char *cmd_line_alloc = NULL;
132
132
    cmd_line = cmd_line_alloc;
133
133
    cmd_line_len = (size_t)ret + 1;
134
134
  }
135
 
  
 
135
 
136
136
  size_t written = 0;
137
137
  ssize_t sret = 0;
138
138
  while(written < cmd_line_len){
148
148
    written += (size_t)sret;
149
149
  }
150
150
  free(cmd_line_alloc);
151
 
  
 
151
 
152
152
  return true;
153
153
}
154
154
 
159
159
  const char *const cryptsource = getenv("cryptsource");
160
160
  const char *const crypttarget = getenv("crypttarget");
161
161
  const char prompt_start[] = "Enter passphrase to unlock the disk";
162
 
  
 
162
 
163
163
  if(cryptsource == NULL){
164
164
    if(crypttarget == NULL){
165
165
      ret = asprintf(&prompt, "%s: ", prompt_start);
219
219
        error_plus(0, errno, "asprintf");
220
220
        goto fail_find_usplash;
221
221
      }
222
 
      
 
222
 
223
223
      /* Check that it refers to a symlink owned by root:root */
224
224
      struct stat exe_stat;
225
225
      ret = lstat(exe_link, &exe_stat);
238
238
        free(exe_link);
239
239
        continue;
240
240
      }
241
 
        
 
241
 
242
242
      sret = readlink(exe_link, exe_target, sizeof(exe_target));
243
243
      free(exe_link);
244
244
    }
311
311
    *cmdline_len_r = cmdline_len;
312
312
    return pid;
313
313
  }
314
 
  
 
314
 
315
315
 fail_find_usplash:
316
 
  
 
316
 
317
317
  free(cmdline);
318
318
  if(proc_dir != NULL){
319
319
    int e = errno;
334
334
  pid_t usplash_pid = -1;
335
335
  bool usplash_accessed = false;
336
336
  int status = EXIT_FAILURE;    /* Default failure exit status */
337
 
  
 
337
 
338
338
  char *prompt = makeprompt();
339
339
  if(prompt == NULL){
340
340
    status = EX_OSERR;
341
341
    goto failure;
342
342
  }
343
 
  
 
343
 
344
344
  /* Find usplash process */
345
345
  char *cmdline = NULL;
346
346
  size_t cmdline_len = 0;
349
349
    status = EX_UNAVAILABLE;
350
350
    goto failure;
351
351
  }
352
 
  
 
352
 
353
353
  /* Set up the signal handler */
354
354
  {
355
355
    struct sigaction old_action,
429
429
      }
430
430
    }
431
431
  }
432
 
  
 
432
 
433
433
  usplash_accessed = true;
434
434
  /* Write command to FIFO */
435
435
  if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
439
439
    }
440
440
    goto failure;
441
441
  }
442
 
  
 
442
 
443
443
  if(interrupted_by_signal){
444
444
    goto failure;
445
445
  }
446
 
  
 
446
 
447
447
  if(not usplash_write(&fifo_fd, "INPUTQUIET", prompt)){
448
448
    if(errno != EINTR){
449
449
      error_plus(0, errno, "usplash_write");
451
451
    }
452
452
    goto failure;
453
453
  }
454
 
  
 
454
 
455
455
  if(interrupted_by_signal){
456
456
    goto failure;
457
457
  }
458
 
  
 
458
 
459
459
  free(prompt);
460
460
  prompt = NULL;
461
 
  
 
461
 
462
462
  /* Read reply from usplash */
463
463
  /* Open FIFO */
464
464
  outfifo_fd = open("/dev/.initramfs/usplash_outfifo", O_RDONLY);
469
469
    }
470
470
    goto failure;
471
471
  }
472
 
  
 
472
 
473
473
  if(interrupted_by_signal){
474
474
    goto failure;
475
475
  }
476
 
  
 
476
 
477
477
  /* Read from FIFO */
478
478
  size_t buf_allocated = 0;
479
479
  const size_t blocksize = 1024;
504
504
    if(interrupted_by_signal){
505
505
      break;
506
506
    }
507
 
    
 
507
 
508
508
    buf_len += (size_t)sret;
509
509
  } while(sret != 0);
510
510
  ret = close(outfifo_fd);
516
516
    goto failure;
517
517
  }
518
518
  outfifo_fd = -1;
519
 
  
 
519
 
520
520
  if(interrupted_by_signal){
521
521
    goto failure;
522
522
  }
523
 
  
 
523
 
524
524
  if(not usplash_write(&fifo_fd, "TIMEOUT", "15")){
525
525
    if(errno != EINTR){
526
526
      error_plus(0, errno, "usplash_write");
528
528
    }
529
529
    goto failure;
530
530
  }
531
 
  
 
531
 
532
532
  if(interrupted_by_signal){
533
533
    goto failure;
534
534
  }
535
 
  
 
535
 
536
536
  ret = close(fifo_fd);
537
537
  if(ret == -1){
538
538
    if(errno != EINTR){
542
542
    goto failure;
543
543
  }
544
544
  fifo_fd = -1;
545
 
  
 
545
 
546
546
  /* Print password to stdout */
547
547
  size_t written = 0;
548
548
  while(written < buf_len){
556
556
        goto failure;
557
557
      }
558
558
    } while(sret == -1);
559
 
    
 
559
 
560
560
    if(interrupted_by_signal){
561
561
      goto failure;
562
562
    }
564
564
  }
565
565
  free(buf);
566
566
  buf = NULL;
567
 
  
 
567
 
568
568
  if(interrupted_by_signal){
569
569
    goto failure;
570
570
  }
571
 
  
 
571
 
572
572
  free(cmdline);
573
573
  return EXIT_SUCCESS;
574
 
  
 
574
 
575
575
 failure:
576
 
  
 
576
 
577
577
  free(buf);
578
 
  
 
578
 
579
579
  free(prompt);
580
 
  
 
580
 
581
581
  /* If usplash was never accessed, we can stop now */
582
582
  if(not usplash_accessed){
583
583
    return status;
584
584
  }
585
 
  
 
585
 
586
586
  /* Close FIFO */
587
587
  if(fifo_fd != -1){
588
588
    ret = close(fifo_fd);
591
591
    }
592
592
    fifo_fd = -1;
593
593
  }
594
 
  
 
594
 
595
595
  /* Close output FIFO */
596
596
  if(outfifo_fd != -1){
597
597
    ret = close(outfifo_fd);
599
599
      error_plus(0, errno, "close");
600
600
    }
601
601
  }
602
 
  
 
602
 
603
603
  /* Create argv for new usplash*/
604
604
  char **cmdline_argv = malloc((argz_count(cmdline, cmdline_len) + 1)
605
605
                               * sizeof(char *)); /* Count args */
608
608
    return status;
609
609
  }
610
610
  argz_extract(cmdline, cmdline_len, cmdline_argv); /* Create argv */
611
 
  
 
611
 
612
612
  /* Kill old usplash */
613
613
  kill(usplash_pid, SIGTERM);
614
614
  sleep(2);
616
616
    kill(usplash_pid, SIGKILL);
617
617
    sleep(1);
618
618
  }
619
 
  
 
619
 
620
620
  pid_t new_usplash_pid = fork();
621
621
  if(new_usplash_pid == 0){
622
622
    /* Child; will become new usplash process */
623
 
    
 
623
 
624
624
    /* Make the effective user ID (root) the only user ID instead of
625
625
       the real user ID (_mandos) */
626
626
    ret = setuid(geteuid());
627
627
    if(ret == -1){
628
628
      error_plus(0, errno, "setuid");
629
629
    }
630
 
    
 
630
 
631
631
    setsid();
632
632
    ret = chdir("/");
633
633
    if(ret == -1){
642
642
      error_plus(0, errno, "dup2");
643
643
      _exit(EX_OSERR);
644
644
    }
645
 
    
 
645
 
646
646
    execv(usplash_name, cmdline_argv);
647
647
    if(not interrupted_by_signal){
648
648
      error_plus(0, errno, "execv");
659
659
      error_plus(0, errno, "usplash_write");
660
660
    }
661
661
  }
662
 
  
 
662
 
663
663
  /* Close FIFO (again) */
664
664
  if(fifo_fd != -1){
665
665
    ret = close(fifo_fd);
668
668
    }
669
669
    fifo_fd = -1;
670
670
  }
671
 
  
 
671
 
672
672
  if(interrupted_by_signal){
673
673
    struct sigaction signal_action = { .sa_handler = SIG_DFL };
674
674
    sigemptyset(&signal_action.sa_mask);
686
686
    }
687
687
    TEMP_FAILURE_RETRY(pause());
688
688
  }
689
 
  
 
689
 
690
690
  return status;
691
691
}