1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Created by yuuta on 12/23/22.
*/
#include "common.h"
#include "log.h"
#include <stdio.h>
#include <errno.h>
int main_consent(int secure) {
if (!secure) {
printf("WARNING: The terminal you are about to enter passwords is insecure.\n");
} else {
printf("\033[r\033[H\033[J");
}
printf("Program %s (process %d: '%s'), is requesting your authorization.\n",
"/TODO",
a_env.pid,
"todo");
switch (a_env.mode) {
case mode_consent: {
printf("Do you consent '%s'? (Y / N) ", a_env.prompt);
char buf[5];
if (read(STDIN_FILENO, buf, sizeof(buf) - 1) < 0) {
int r = errno;
LOGFV("read: %m", r);
printf("Cannot read your response: %m. Press any key to return.\n",
errno);
fgetc(stdin);
if (secure) {
printf("\033[r\033[H\033[J");
}
return r;
}
if (buf[0] == 'Y' || buf[0] == 'y') {
dprintf(p_env.out, "1");
} else {
dprintf(p_env.out, "0");
}
break;
}
case mode_password: {
printf("Enter your password for '%s'. "
"The program will know your password.\n"
"Password: ", a_env.prompt);
char buf[10];
if (read(STDIN_FILENO, buf, sizeof(buf) - 1) < 0) {
int r = errno;
LOGFV("read: %m", r);
printf("Cannot read your response: %m. Press any key to return.\n",
errno);
fgetc(stdin);
if (secure) {
printf("\033[r\033[H\033[J");
}
return r;
}
buf[sizeof(buf) - 1] = '\0';
dprintf(p_env.out, "%s", buf);
break;
}
case mode_auth: {
// TODO
fgetc(stdin);
break;
}
}
if (secure) {
printf("\033[r\033[H\033[J");
}
return 0;
}
|