2
0

A bunch of cross-platform fixes for mpw.c + make config file optional and read master password from input instead.

This commit is contained in:
Maarten Billemont 2014-10-15 14:00:44 -04:00
parent 0d66d4660e
commit 5268039c3d
2 changed files with 74 additions and 27 deletions

View File

@ -1,8 +1,28 @@
#!/usr/bin/env bash
# Run with -DDEBUG to enable trace-level output.
#
# TROUBLESHOOTING
# - See the 'options' array. Comment/uncomment lines as you see fit.
# - If you see 'undefined reference to `clock_gettime'', try ./build -lrt instead.
#
# BUGS
# masterpassword@lyndir.com
#
# AUTHOR
# Maarten Billemont
#
cd "${BASH_SOURCE%/*}"
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.
)
### DEPENDENCIES
if ! [[ -e lib/scrypt/scrypt-scryptenc.o ]]; then
# libscrypt not built.
pushd lib/scrypt
@ -52,23 +72,32 @@ fi
echo
echo "Building mpw..."
# libscrypt built.
deps=(
cc() {
if hash llvm-gcc; then
llvm-gcc -Qunused-arguments "$@"
else
gcc "$@"
fi
}
### MPW
options+=(
# include paths.
-I"lib/scrypt/lib" -I"lib/scrypt/libcperciva"
# library paths.
-L"." -L"lib/scrypt"
# link libraries.
-l "scrypt-crypto_aesctr.o"
-l "scrypt-sha256.o"
-l "scrypt-crypto_scrypt-nosse.o"
-l "scrypt-memlimit.o"
-l "scrypt-scryptenc_cpuperf.o"
-l "scrypt-scryptenc.o"
-l "crypto"
"lib/scrypt/scrypt-crypto_aesctr.o"
"lib/scrypt/scrypt-sha256.o"
"lib/scrypt/scrypt-crypto_scrypt-nosse.o"
"lib/scrypt/scrypt-memlimit.o"
"lib/scrypt/scrypt-scryptenc_cpuperf.o"
"lib/scrypt/scrypt-scryptenc.o"
-l"crypto"
)
# build mpw.
gcc "${deps[@]}" -Qunused-arguments -c types.c -o types.o "$@"
gcc "${deps[@]}" -Qunused-arguments -l"types.o" mpw.c -o mpw "$@"
cc "${options[@]}" -std=c99 -c types.c -o types.o "$@"
cc "${options[@]}" -std=c99 -l"types.o" mpw.c -o mpw "$@"
echo "done! Now run ./install or use ./mpw"

View File

@ -23,6 +23,12 @@
#include <crypto/crypto_scrypt.h>
#include "types.h"
#if defined(READLINE)
#include <readline/readline.h>
#elif defined(EDITLINE)
#include <histedit.h>
#endif
#define MP_N 32768
#define MP_r 8
#define MP_p 2
@ -98,8 +104,7 @@ int main(int argc, char *const argv[]) {
const char *siteCounterString = getenv( MP_env_sitecounter );
// Read the options.
char opt;
while ((opt = getopt(argc, argv, "u:t:c:v:h")) != -1)
for (int opt; (opt = getopt(argc, argv, "u:t:c:v:h")) != -1;)
switch (opt) {
case 'h':
usage();
@ -172,22 +177,35 @@ int main(int argc, char *const argv[]) {
}
trc("mpwConfigPath: %s\n", mpwConfigPath);
FILE *mpwConfig = fopen(mpwConfigPath, "r");
if (!mpwConfig) {
fprintf(stderr, "Couldn't open configuration file: %s: %d\n", mpwConfigPath, errno);
return 1;
}
free(mpwConfigPath);
char *line = NULL;
size_t linecap = 0;
ssize_t linelen;
while ((linelen = getline(&line, &linecap, mpwConfig)) > 0)
if (strcmp(strsep(&line, ":"), userName) == 0) {
masterPassword = strsep(&line, "\n");
break;
if (mpwConfig) {
char *line = NULL;
size_t linecap = 0;
ssize_t linelen;
while ((linelen = getline(&line, &linecap, mpwConfig)) > 0)
if (strcmp(strsep(&line, ":"), userName) == 0) {
masterPassword = strsep(&line, "\n");
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 = strsep(&line, "\n");
el_end(e);
if (count < 0) {
fprintf(stderr, "Could not read master password: %d\n", errno);
continue;
}
if (!masterPassword) {
#else
fprintf(stderr, "Missing master password for user: %s\n", userName);
return 1;
#endif
}
trc("masterPassword: %s\n", masterPassword);