From 213ef024f69c2509a774540d5a3e2d5a28c47dac Mon Sep 17 00:00:00 2001 From: Trumeet Date: Fri, 23 Dec 2022 23:39:52 -0800 Subject: Use readpassphrase(3) to read password --- CMakeLists.txt | 1 + consent.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a9a6f9..c6b6e48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,3 +4,4 @@ project(secdesk C) set(CMAKE_C_STANDARD 11) add_executable(secdesk main.c log.c log.h common.h consent.c sd.c) +target_link_libraries(secdesk PRIVATE bsd) \ No newline at end of file diff --git a/consent.c b/consent.c index 882ac79..cc94e43 100644 --- a/consent.c +++ b/consent.c @@ -7,6 +7,7 @@ #include #include +#include int main_consent(int secure) { if (!secure) { @@ -45,19 +46,16 @@ int main_consent(int secure) { } case mode_password: { fprintf(stderr, "Please enter password. " - "The program will know your password.\n" - "Password: "); + "The program will know your password.\n"); char buf[10]; - if (!fgets(buf, sizeof(buf) - 1, stdin)) { - int r = errno; - LOGFV("read: %m", r); + if (!readpassphrase("Password: ", buf, sizeof(buf), 0)) { + LOGF("Cannot read passphrase."); if (secure) { - fprintf(stderr, "Cannot read your response: %m. Press any key to return.\n", - errno); + fprintf(stderr, "Cannot read your response. Press any key to return.\n"); fgetc(stdin); fprintf(stderr, "\033[r\033[H\033[J"); } - return r; + return 1; } dprintf(p_env.out, "%s", buf); break; -- cgit v1.2.3