aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-12-23 23:39:52 -0800
committerTrumeet <yuuta@yuuta.moe>2022-12-23 23:39:52 -0800
commit213ef024f69c2509a774540d5a3e2d5a28c47dac (patch)
tree22524219497e2a2e564b9562c875efdc9f7ebdfb
parentce8e5821dff2673d23fe4f6ba394ab07afd0e73f (diff)
downloadsecdesk-213ef024f69c2509a774540d5a3e2d5a28c47dac.tar
secdesk-213ef024f69c2509a774540d5a3e2d5a28c47dac.tar.gz
secdesk-213ef024f69c2509a774540d5a3e2d5a28c47dac.tar.bz2
secdesk-213ef024f69c2509a774540d5a3e2d5a28c47dac.zip
Use readpassphrase(3) to read password
-rw-r--r--CMakeLists.txt1
-rw-r--r--consent.c14
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 <stdio.h>
#include <errno.h>
+#include <bsd/readpassphrase.h>
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;