/* * Created by yuuta on 12/23/22. */ #include "common.h" #include "log.h" #include #include #include int main_consent(int secure) { if (!secure) { fprintf(stderr, "WARNING: The terminal you are about to enter passwords is insecure.\n"); } else { fprintf(stderr, "\033[r\033[H\033[J"); } 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", a_env.prompt); switch (a_env.mode) { case mode_consent: { 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) { fprintf(stderr, "Cannot read response: %m. Press any key to return.\n", errno); fgetc(stdin); fprintf(stderr, "\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: { fprintf(stderr, "Please enter password. " "The program will know your password.\n"); char buf[10]; if (!readpassphrase("Password: ", buf, sizeof(buf), 0)) { LOGF("Cannot read passphrase."); if (secure) { fprintf(stderr, "Cannot read your response. Press any key to return.\n"); fgetc(stdin); fprintf(stderr, "\033[r\033[H\033[J"); } return 1; } 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; }