diff options
author | Trumeet <yuuta@yuuta.moe> | 2022-12-23 22:51:08 -0800 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2022-12-23 22:51:08 -0800 |
commit | 03ab6ba2c4efd9c9c5b92d8fb1f51ad51e255a08 (patch) | |
tree | dc3ff5409e4bb39d9745b09c27fc9d45822cc64e | |
parent | 184dab1c74db05d59d63bfaabedf0ef4e6bf61c9 (diff) | |
download | secdesk-03ab6ba2c4efd9c9c5b92d8fb1f51ad51e255a08.tar secdesk-03ab6ba2c4efd9c9c5b92d8fb1f51ad51e255a08.tar.gz secdesk-03ab6ba2c4efd9c9c5b92d8fb1f51ad51e255a08.tar.bz2 secdesk-03ab6ba2c4efd9c9c5b92d8fb1f51ad51e255a08.zip |
Improve prompt
-rw-r--r-- | consent.c | 24 | ||||
-rw-r--r-- | main.c | 2 |
2 files changed, 14 insertions, 12 deletions
@@ -10,27 +10,29 @@ int main_consent(int secure) { if (!secure) { - printf("WARNING: The terminal you are about to enter passwords is insecure.\n"); + fprintf(stderr, "WARNING: The terminal you are about to enter passwords is insecure.\n"); } else { - printf("\033[r\033[H\033[J"); + fprintf(stderr, "\033[r\033[H\033[J"); } - printf("Program %s from user %d (process %d: '%s'), is asking for authorization.\n", + fprintf(stderr, "Program %s from user %d (process %d: '%s'), is asking for authorization.\n" + "It prompts that:\n\n%s\n\n", a_env.exe, a_env.usr, a_env.pid, - "todo"); + "todo", + a_env.prompt); switch (a_env.mode) { case mode_consent: { - printf("Consent '%s'? (Y / N) ", a_env.prompt); + fprintf(stderr, "Consent? (Y / N) "); char buf[5]; if (read(STDIN_FILENO, buf, sizeof(buf) - 1) < 0) { int r = errno; LOGFV("read: %m", r); if (secure) { - printf("Cannot read response: %m. Press any key to return.\n", + fprintf(stderr, "Cannot read response: %m. Press any key to return.\n", errno); fgetc(stdin); - printf("\033[r\033[H\033[J"); + fprintf(stderr, "\033[r\033[H\033[J"); } return r; } @@ -42,18 +44,18 @@ int main_consent(int secure) { break; } case mode_password: { - printf("Enter password for '%s'. " + fprintf(stderr, "Please enter password. " "The program will know your password.\n" - "Password: ", a_env.prompt); + "Password: "); char buf[10]; if (!fgets(buf, sizeof(buf) - 1, stdin)) { int r = errno; LOGFV("read: %m", r); if (secure) { - printf("Cannot read your response: %m. Press any key to return.\n", + fprintf(stderr, "Cannot read your response: %m. Press any key to return.\n", errno); fgetc(stdin); - printf("\033[r\033[H\033[J"); + fprintf(stderr, "\033[r\033[H\033[J"); } return r; } @@ -37,7 +37,7 @@ int main(int argc, char **argv) { if ((a_env.prompt = argv[2])) { char *p = argv[2]; do { - if ((*p) < 32 || (*p) > 126) { + if (*p != '\n' && (*p) < 32 || (*p) > 126) { fprintf(stderr, "The given prompt is illegal.\n"); return 64; } |