3
3
* Password-prompt - Read a password from the terminal and print it
5
* Copyright © 2008-2011 Teddy Hogeborn
6
* Copyright © 2008-2011 Björn Påhlsson
5
* Copyright © 2008-2010 Teddy Hogeborn
6
* Copyright © 2008-2010 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
19
19
* along with this program. If not, see
20
20
* <http://www.gnu.org/licenses/>.
22
* Contact the authors at <mandos@recompile.se>.
22
* Contact the authors at <mandos@fukt.bsnet.se>.
25
25
#define _GNU_SOURCE /* getline(), asprintf() */
27
#include <termios.h> /* struct termios, tcsetattr(),
27
#include <termios.h> /* struct termios, tcsetattr(),
28
28
TCSAFLUSH, tcgetattr(), ECHO */
29
29
#include <unistd.h> /* struct termios, tcsetattr(),
30
30
STDIN_FILENO, TCSAFLUSH,
41
41
getenv(), free() */
42
42
#include <dirent.h> /* scandir(), alphasort() */
43
43
#include <stdio.h> /* fprintf(), stderr, getline(),
44
stdin, feof(), fputc(), vfprintf(),
44
stdin, feof(), fputc()
46
46
#include <errno.h> /* errno, EBADF, ENOTTY, EINVAL,
47
47
EFAULT, EFBIG, EIO, ENOSPC, EINTR
50
50
#include <iso646.h> /* or, not */
51
51
#include <stdbool.h> /* bool, false, true */
52
52
#include <inttypes.h> /* strtoumax() */
53
#include <sys/stat.h> /* struct stat, lstat(), open() */
54
#include <string.h> /* strlen, rindex, memcmp, strerror()
53
#include <sys/stat.h> /* struct stat, lstat(), open() */
54
#include <string.h> /* strlen, rindex, memcmp */
56
55
#include <argp.h> /* struct argp_option, struct
57
56
argp_state, struct argp,
58
57
argp_parse(), error_t,
61
60
#include <sysexits.h> /* EX_SOFTWARE, EX_OSERR,
62
61
EX_UNAVAILABLE, EX_IOERR, EX_OK */
63
62
#include <fcntl.h> /* open() */
64
#include <stdarg.h> /* va_list, va_start(), ... */
66
64
volatile sig_atomic_t quit_now = 0;
67
65
int signal_received;
68
66
bool debug = false;
69
67
const char *argp_program_version = "password-prompt " VERSION;
70
const char *argp_program_bug_address = "<mandos@recompile.se>";
72
/* Needed for conflict resolution */
73
const char plymouth_name[] = "plymouthd";
75
/* Function to use when printing errors */
76
void error_plus(int status, int errnum, const char *formatstring,
82
va_start(ap, formatstring);
83
ret = vasprintf(&text, formatstring, ap);
85
fprintf(stderr, "Mandos plugin %s: ",
86
program_invocation_short_name);
87
vfprintf(stderr, formatstring, ap);
88
fprintf(stderr, ": ");
89
fprintf(stderr, "%s\n", strerror(errnum));
90
error(status, errno, "vasprintf while printing error");
93
fprintf(stderr, "Mandos plugin ");
94
error(status, errnum, "%s", text);
68
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
70
/* Needed for conflic resolution */
71
const char plymouthd_name[] = "plymouthd";
98
74
static void termination_handler(int signum){
127
103
char *cmdline_filename;
128
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
104
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline", proc_entry->d_name);
131
106
error(0, errno, "asprintf");
135
/* Open /proc/<pid>/cmdline */
110
/* Open /proc/<pid>/cmdline */
136
111
cl_fd = open(cmdline_filename, O_RDONLY);
137
112
free(cmdline_filename);
140
error(0, errno, "open");
114
error(0, errno, "open");
192
165
cmdline_base = cmdline;
195
if(strcmp(cmdline_base, plymouth_name) != 0){
197
fprintf(stderr, "\"%s\" is not \"%s\"\n", cmdline_base,
168
if(strcmp(cmdline_base, plymouthd_name) != 0){
204
fprintf(stderr, "\"%s\" equals \"%s\"\n", cmdline_base,
211
struct dirent **direntries = NULL;
176
struct dirent **direntries;
213
178
ret = scandir("/proc", &direntries, is_plymouth, alphasort);
215
180
error(1, errno, "scandir");
304
268
if (conflict_detection()){
306
fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
270
fprintf(stderr, "Stopping %s because of conflict", argv[0]);
308
272
return EXIT_FAILURE;
514
/* if(sret == 0), then the only sensible thing to do is to retry
515
to read from stdin */
478
/* if(sret == 0), then the only sensible thing to do is to retry to
516
480
fputc('\n', stderr);
517
481
if(debug and not quit_now){
518
482
/* If quit_now is nonzero, we were interrupted by a signal, and