From 03ab6ba2c4efd9c9c5b92d8fb1f51ad51e255a08 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Fri, 23 Dec 2022 22:51:08 -0800 Subject: Improve prompt --- consent.c | 24 +++++++++++++----------- main.c | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/consent.c b/consent.c index 61710b0..882ac79 100644 --- a/consent.c +++ b/consent.c @@ -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; } diff --git a/main.c b/main.c index 0865bb4..8c537d3 100644 --- a/main.c +++ b/main.c @@ -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; } -- cgit v1.2.3