11
11
SIGQUIT, SIGHUP, SIGTERM */
12
12
#include <stddef.h> /* NULL, size_t */
13
13
#include <sys/types.h> /* ssize_t */
14
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE,
14
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE */
16
15
#include <stdio.h> /* fprintf(), stderr, getline(),
17
16
stdin, feof(), perror(), fputc(),
18
stdout, getopt_long */
19
18
#include <errno.h> /* errno, EINVAL */
20
19
#include <iso646.h> /* or, not */
21
20
#include <stdbool.h> /* bool, false, true */
22
#include <string.h> /* strlen, rindex, strncmp, strcmp */
23
#include <getopt.h> /* getopt_long */
25
22
volatile bool quit_now = false;
28
24
void termination_handler(int signum){
32
28
int main(int argc, char **argv){
35
31
struct termios t_new, t_old;
36
32
char *buffer = NULL;
38
33
int status = EXIT_SUCCESS;
39
34
struct sigaction old_action,
40
35
new_action = { .sa_handler = termination_handler,
44
static struct option long_options[] = {
45
{"debug", no_argument, (int *)&debug, 1},
46
{"prefix", required_argument, 0, 'p'},
50
ret = getopt_long (argc, argv, "p:", long_options, &option_index);
63
fprintf(stderr, "bad arguments\n");
69
fprintf(stderr, "Starting %s\n", argv[0]);
72
fprintf(stderr, "Storing current terminal attributes\n");
75
38
if (tcgetattr(STDIN_FILENO, &t_old) != 0){
76
39
return EXIT_FAILURE;
93
56
sigaction(SIGTERM, NULL, &old_action);
94
57
if (old_action.sa_handler != SIG_IGN)
95
58
sigaction(SIGTERM, &new_action, NULL);
99
fprintf(stderr, "Removing echo flag from terminal attributes\n");
103
61
t_new.c_lflag &= ~ECHO;
105
63
perror("tcsetattr-echo");
106
64
return EXIT_FAILURE;
110
fprintf(stderr, "Waiting for input from stdin \n");
114
69
status = EXIT_FAILURE;
119
fprintf(stderr, "%s Password: ", prefix);
121
fprintf(stderr, "Password: ");
72
fprintf(stderr, "Password: ");
123
73
ret = getline(&buffer, &n, stdin);
125
75
fprintf(stdout, "%s", buffer);
137
87
fputc('\n', stderr);
141
fprintf(stderr, "Restoring terminal attributes\n");
143
90
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_old) != 0){
144
91
perror("tcsetattr+echo");
148
fprintf(stderr, "%s is exiting\n", argv[0]);