3
3
* Password-prompt - Read a password from the terminal and print it
5
* Copyright © 2008-2016 Teddy Hogeborn
6
* Copyright © 2008-2016 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");
218
218
free(direntries);
303
302
fprintf(stderr, "Starting %s\n", argv[0]);
306
if(conflict_detection()){
305
if (conflict_detection()){
308
307
fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
317
316
if(tcgetattr(STDIN_FILENO, &t_old) != 0){
319
error_plus(0, errno, "tcgetattr");
318
error(0, errno, "tcgetattr");
329
328
sigemptyset(&new_action.sa_mask);
330
329
ret = sigaddset(&new_action.sa_mask, SIGINT);
332
error_plus(0, errno, "sigaddset");
331
error(0, errno, "sigaddset");
335
334
ret = sigaddset(&new_action.sa_mask, SIGHUP);
337
error_plus(0, errno, "sigaddset");
336
error(0, errno, "sigaddset");
340
339
ret = sigaddset(&new_action.sa_mask, SIGTERM);
342
error_plus(0, errno, "sigaddset");
341
error(0, errno, "sigaddset");
345
344
/* Need to check if the handler is SIG_IGN before handling:
349
348
ret = sigaction(SIGINT, NULL, &old_action);
351
error_plus(0, errno, "sigaction");
350
error(0, errno, "sigaction");
354
353
if(old_action.sa_handler != SIG_IGN){
355
354
ret = sigaction(SIGINT, &new_action, NULL);
357
error_plus(0, errno, "sigaction");
356
error(0, errno, "sigaction");
361
360
ret = sigaction(SIGHUP, NULL, &old_action);
363
error_plus(0, errno, "sigaction");
362
error(0, errno, "sigaction");
366
365
if(old_action.sa_handler != SIG_IGN){
367
366
ret = sigaction(SIGHUP, &new_action, NULL);
369
error_plus(0, errno, "sigaction");
368
error(0, errno, "sigaction");
373
372
ret = sigaction(SIGTERM, NULL, &old_action);
375
error_plus(0, errno, "sigaction");
374
error(0, errno, "sigaction");
378
377
if(old_action.sa_handler != SIG_IGN){
379
378
ret = sigaction(SIGTERM, &new_action, NULL);
381
error_plus(0, errno, "sigaction");
380
error(0, errno, "sigaction");
392
391
t_new.c_lflag &= ~(tcflag_t)ECHO;
393
392
if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_new) != 0){
395
error_plus(0, errno, "tcsetattr-echo");
394
error(0, errno, "tcsetattr-echo");
462
461
sret = write(STDOUT_FILENO, buffer + written, n - written);
465
error_plus(0, errno, "write");
464
error(0, errno, "write");
484
483
sret = close(STDOUT_FILENO);
487
error_plus(0, errno, "close");
486
error(0, errno, "close");
490
489
status = EX_OSFILE;
502
501
if(errno != EINTR and not feof(stdin)){
503
error_plus(0, errno, "getline");
502
error(0, errno, "getline");
506
505
status = EX_UNAVAILABLE;
530
528
fprintf(stderr, "Restoring terminal attributes\n");
532
530
if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
533
error_plus(0, errno, "tcsetattr+echo");
531
error(0, errno, "tcsetattr+echo");
538
536
old_action.sa_handler = SIG_DFL;
539
537
ret = sigaction(signal_received, &old_action, NULL);
541
error_plus(0, errno, "sigaction");
539
error(0, errno, "sigaction");
543
541
raise(signal_received);