2
0

Replace editline and readline with getpass.

This commit is contained in:
Maarten Billemont 2014-10-15 16:03:46 -04:00
parent c3c2de5d14
commit d9b1b44de0
2 changed files with 6 additions and 26 deletions

View File

@ -16,8 +16,6 @@ set -e
options=( options=(
# optional features. # optional features.
-DDEBUG # Turn on debugging verbosity. -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() { cc() {
if hash llvm-gcc 2>/dev/null; then if hash llvm-gcc 2>/dev/null; then
llvm-gcc -std=c11 "$@" llvm-gcc "$@"
else else
gcc -std=gnu99 "$@" gcc -std=gnu99 "$@"
fi fi

View File

@ -1,5 +1,4 @@
#define _ISOC11_SOURCE 1 #define _GNU_SOURCE
#define __STDC_VERSION__ 201112L
#include <stdio.h> #include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -190,32 +189,15 @@ int main(int argc, char *const argv[]) {
break; break;
} }
} }
while (!masterPassword) { while (!masterPassword)
#if defined(READLINE) masterPassword = getpass( "Your master password: " );
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
}
trc("masterPassword: %s\n", masterPassword); trc("masterPassword: %s\n", masterPassword);
// Calculate the master key salt. // Calculate the master key salt.
const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword); const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword);
trc("key scope: %s\n", mpKeyScope); trc("key scope: %s\n", mpKeyScope);
const uint32_t n_userNameLength = htonl(strlen(userName)); 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 ); char *masterKeySalt = malloc( masterKeySaltLength );
if (!masterKeySalt) { if (!masterKeySalt) {
fprintf(stderr, "Could not allocate master key salt: %d\n", errno); 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); trc("site scope: %s\n", mpSiteScope);
const uint32_t n_siteNameLength = htonl(strlen(siteName)); const uint32_t n_siteNameLength = htonl(strlen(siteName));
const uint32_t n_siteCounter = htonl(siteCounter); 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 ); char *sitePasswordInfo = malloc( sitePasswordInfoLength );
if (!sitePasswordInfo) { if (!sitePasswordInfo) {
fprintf(stderr, "Could not allocate site seed: %d\n", errno); fprintf(stderr, "Could not allocate site seed: %d\n", errno);