From d9b1b44de005edf3b733f3fb6b34a6a290bb9c37 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 15 Oct 2014 16:03:46 -0400 Subject: [PATCH] Replace editline and readline with getpass. --- MasterPassword/C/build | 4 +--- MasterPassword/C/mpw.c | 28 +++++----------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/MasterPassword/C/build b/MasterPassword/C/build index 4d9b29dc..632dc318 100755 --- a/MasterPassword/C/build +++ b/MasterPassword/C/build @@ -16,8 +16,6 @@ set -e options=( # optional features. -DDEBUG # Turn on debugging verbosity. - #-DEDITLINE -ledit -ltermcap # Use editline for reading the master password. - -DREADLINE -lreadline # Use readline for reading the master password. ) @@ -74,7 +72,7 @@ echo "Building mpw..." cc() { if hash llvm-gcc 2>/dev/null; then - llvm-gcc -std=c11 "$@" + llvm-gcc "$@" else gcc -std=gnu99 "$@" fi diff --git a/MasterPassword/C/mpw.c b/MasterPassword/C/mpw.c index df723a74..389b4179 100644 --- a/MasterPassword/C/mpw.c +++ b/MasterPassword/C/mpw.c @@ -1,5 +1,4 @@ -#define _ISOC11_SOURCE 1 -#define __STDC_VERSION__ 201112L +#define _GNU_SOURCE #include #include @@ -190,32 +189,15 @@ int main(int argc, char *const argv[]) { break; } } - while (!masterPassword) { -#if defined(READLINE) - masterPassword = readline( "Your master password: " ); -#elif defined(EDITLINE) - EditLine *e = el_init("mpw", stdin, stdout, stderr); - int count = 0; - char *line = el_gets(e, &count); - masterPassword = strdup(strsep(&line, "\n")); - el_end(e); - - if (count < 0) { - fprintf(stderr, "Could not read master password: %d\n", errno); - continue; - } -#else - fprintf(stderr, "Missing master password for user: %s\n", userName); - return 1; -#endif - } + while (!masterPassword) + masterPassword = getpass( "Your master password: " ); trc("masterPassword: %s\n", masterPassword); // Calculate the master key salt. const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword); trc("key scope: %s\n", mpKeyScope); const uint32_t n_userNameLength = htonl(strlen(userName)); - size_t masterKeySaltLength = strlen(mpKeyScope) + sizeof(n_userNameLength) + strlen(userName); + const size_t masterKeySaltLength = strlen(mpKeyScope) + sizeof(n_userNameLength) + strlen(userName); char *masterKeySalt = malloc( masterKeySaltLength ); if (!masterKeySalt) { fprintf(stderr, "Could not allocate master key salt: %d\n", errno); @@ -251,7 +233,7 @@ int main(int argc, char *const argv[]) { trc("site scope: %s\n", mpSiteScope); const uint32_t n_siteNameLength = htonl(strlen(siteName)); const uint32_t n_siteCounter = htonl(siteCounter); - size_t sitePasswordInfoLength = strlen(mpSiteScope) + sizeof(n_siteNameLength) + strlen(siteName) + sizeof(n_siteCounter); + const size_t sitePasswordInfoLength = strlen(mpSiteScope) + sizeof(n_siteNameLength) + strlen(siteName) + sizeof(n_siteCounter); char *sitePasswordInfo = malloc( sitePasswordInfoLength ); if (!sitePasswordInfo) { fprintf(stderr, "Could not allocate site seed: %d\n", errno);