3
3
* Password-prompt - Read a password from the terminal and print it
5
* Copyright © 2008-2010 Teddy Hogeborn
6
* Copyright © 2008-2010 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
19
19
* along with this program. If not, see
20
20
* <http://www.gnu.org/licenses/>.
22
* Contact the authors at <mandos@fukt.bsnet.se>.
22
* Contact the authors at <mandos@recompile.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()
44
stdin, feof(), fputc(), vfprintf(),
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 */
53
#include <sys/stat.h> /* struct stat, lstat(), open() */
54
#include <string.h> /* strlen, rindex, memcmp, strerror()
55
56
#include <argp.h> /* struct argp_option, struct
56
57
argp_state, struct argp,
57
58
argp_parse(), error_t,
60
61
#include <sysexits.h> /* EX_SOFTWARE, EX_OSERR,
61
62
EX_UNAVAILABLE, EX_IOERR, EX_OK */
62
63
#include <fcntl.h> /* open() */
64
#include <stdarg.h> /* va_list, va_start(), ... */
64
66
volatile sig_atomic_t quit_now = 0;
65
67
int signal_received;
66
68
bool debug = false;
67
69
const char *argp_program_version = "password-prompt " VERSION;
68
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
70
/* Needed for conflic resolution */
71
const char plymouthd_name[] = "plymouthd";
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);
74
98
static void termination_handler(int signum){
103
127
char *cmdline_filename;
104
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline", proc_entry->d_name);
128
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
106
131
error(0, errno, "asprintf");
110
/* Open /proc/<pid>/cmdline */
135
/* Open /proc/<pid>/cmdline */
111
136
cl_fd = open(cmdline_filename, O_RDONLY);
112
137
free(cmdline_filename);
114
error(0, errno, "open");
140
error(0, errno, "open");
165
192
cmdline_base = cmdline;
168
if(strcmp(cmdline_base, plymouthd_name) != 0){
195
if(strcmp(cmdline_base, plymouth_name) != 0){
197
fprintf(stderr, "\"%s\" is not \"%s\"\n", cmdline_base,
204
fprintf(stderr, "\"%s\" equals \"%s\"\n", cmdline_base,
176
struct dirent **direntries;
211
struct dirent **direntries = NULL;
178
213
ret = scandir("/proc", &direntries, is_plymouth, alphasort);
180
215
error(1, errno, "scandir");
268
304
if (conflict_detection()){
270
fprintf(stderr, "Stopping %s because of conflict", argv[0]);
306
fprintf(stderr, "Stopping %s because of conflict\n", argv[0]);
272
308
return EXIT_FAILURE;
478
/* if(sret == 0), then the only sensible thing to do is to retry to
514
/* if(sret == 0), then the only sensible thing to do is to retry
515
to read from stdin */
480
516
fputc('\n', stderr);
481
517
if(debug and not quit_now){
482
518
/* If quit_now is nonzero, we were interrupted by a signal, and