3
3
* Password-prompt - Read a password from the terminal and print it
5
* Copyright © 2008-2017 Teddy Hogeborn
6
* Copyright © 2008-2017 Björn Påhlsson
5
* Copyright © 2008-2011 Teddy Hogeborn
6
* Copyright © 2008-2011 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
83
83
va_start(ap, formatstring);
84
84
ret = vasprintf(&text, formatstring, ap);
86
86
fprintf(stderr, "Mandos plugin %s: ",
87
87
program_invocation_short_name);
88
88
vfprintf(stderr, formatstring, ap);
89
fprintf(stderr, ": %s\n", strerror(errnum));
89
fprintf(stderr, ": ");
90
fprintf(stderr, "%s\n", strerror(errnum));
90
91
error(status, errno, "vasprintf while printing error");
109
110
from the terminal. Password-prompt will exit if it detects
110
111
plymouth since plymouth performs the same functionality.
112
__attribute__((nonnull))
113
113
int is_plymouth(const struct dirent *proc_entry){
120
proc_id = strtoumax(proc_entry->d_name, &tmp, 10);
120
maxvalue = strtoumax(proc_entry->d_name, &tmp, 10);
122
122
if(errno != 0 or *tmp != '\0'
123
or proc_id != (uintmax_t)((pid_t)proc_id)){
123
or maxvalue != (uintmax_t)((pid_t)maxvalue)){
129
129
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
130
130
proc_entry->d_name);
132
error_plus(0, errno, "asprintf");
132
error(0, errno, "asprintf");
155
155
if(cmdline_len + blocksize + 1 > cmdline_allocated){
156
156
tmp = realloc(cmdline, cmdline_allocated + blocksize + 1);
158
error_plus(0, errno, "realloc");
158
error(0, errno, "realloc");
168
168
sret = read(cl_fd, cmdline + cmdline_len,
169
169
cmdline_allocated - cmdline_len);
171
error_plus(0, errno, "read");
171
error(0, errno, "read");
212
212
struct dirent **direntries = NULL;
214
214
ret = scandir("/proc", &direntries, is_plymouth, alphasort);
216
error_plus(1, errno, "scandir");
216
error(1, errno, "scandir");
224
218
free(direntries);
309
302
fprintf(stderr, "Starting %s\n", argv[0]);
312
if(conflict_detection()){
305
if (conflict_detection()){
314
307
fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
323
316
if(tcgetattr(STDIN_FILENO, &t_old) != 0){
325
error_plus(0, errno, "tcgetattr");
318
error(0, errno, "tcgetattr");
335
328
sigemptyset(&new_action.sa_mask);
336
329
ret = sigaddset(&new_action.sa_mask, SIGINT);
338
error_plus(0, errno, "sigaddset");
331
error(0, errno, "sigaddset");
341
334
ret = sigaddset(&new_action.sa_mask, SIGHUP);
343
error_plus(0, errno, "sigaddset");
336
error(0, errno, "sigaddset");
346
339
ret = sigaddset(&new_action.sa_mask, SIGTERM);
348
error_plus(0, errno, "sigaddset");
341
error(0, errno, "sigaddset");
351
344
/* Need to check if the handler is SIG_IGN before handling:
355
348
ret = sigaction(SIGINT, NULL, &old_action);
357
error_plus(0, errno, "sigaction");
350
error(0, errno, "sigaction");
360
353
if(old_action.sa_handler != SIG_IGN){
361
354
ret = sigaction(SIGINT, &new_action, NULL);
363
error_plus(0, errno, "sigaction");
356
error(0, errno, "sigaction");
367
360
ret = sigaction(SIGHUP, NULL, &old_action);
369
error_plus(0, errno, "sigaction");
362
error(0, errno, "sigaction");
372
365
if(old_action.sa_handler != SIG_IGN){
373
366
ret = sigaction(SIGHUP, &new_action, NULL);
375
error_plus(0, errno, "sigaction");
368
error(0, errno, "sigaction");
379
372
ret = sigaction(SIGTERM, NULL, &old_action);
381
error_plus(0, errno, "sigaction");
374
error(0, errno, "sigaction");
384
377
if(old_action.sa_handler != SIG_IGN){
385
378
ret = sigaction(SIGTERM, &new_action, NULL);
387
error_plus(0, errno, "sigaction");
380
error(0, errno, "sigaction");
398
391
t_new.c_lflag &= ~(tcflag_t)ECHO;
399
392
if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_new) != 0){
401
error_plus(0, errno, "tcsetattr-echo");
394
error(0, errno, "tcsetattr-echo");
468
461
sret = write(STDOUT_FILENO, buffer + written, n - written);
471
error_plus(0, errno, "write");
464
error(0, errno, "write");
490
483
sret = close(STDOUT_FILENO);
493
error_plus(0, errno, "close");
486
error(0, errno, "close");
496
489
status = EX_OSFILE;
508
501
if(errno != EINTR and not feof(stdin)){
509
error_plus(0, errno, "getline");
502
error(0, errno, "getline");
512
505
status = EX_UNAVAILABLE;
536
528
fprintf(stderr, "Restoring terminal attributes\n");
538
530
if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
539
error_plus(0, errno, "tcsetattr+echo");
531
error(0, errno, "tcsetattr+echo");
544
536
old_action.sa_handler = SIG_DFL;
545
537
ret = sigaction(signal_received, &old_action, NULL);
547
error_plus(0, errno, "sigaction");
539
error(0, errno, "sigaction");
549
541
raise(signal_received);