/* * Created by yuuta on 12/23/22. */ #include "common.h" #include "log.h" #include #include 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; }