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 #!/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%/*}" cd "${BASH_SOURCE%/*}"
set -e 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 if ! [[ -e lib/scrypt/scrypt-scryptenc.o ]]; then
# libscrypt not built. # libscrypt not built.
pushd lib/scrypt pushd lib/scrypt
@ -52,23 +72,32 @@ fi
echo echo
echo "Building mpw..." echo "Building mpw..."
# libscrypt built. cc() {
deps=( if hash llvm-gcc; then
llvm-gcc -Qunused-arguments "$@"
else
gcc "$@"
fi
}
### MPW
options+=(
# include paths. # include paths.
-I"lib/scrypt/lib" -I"lib/scrypt/libcperciva" -I"lib/scrypt/lib" -I"lib/scrypt/libcperciva"
# library paths. # library paths.
-L"." -L"lib/scrypt" -L"." -L"lib/scrypt"
# link libraries. # link libraries.
-l "scrypt-crypto_aesctr.o" "lib/scrypt/scrypt-crypto_aesctr.o"
-l "scrypt-sha256.o" "lib/scrypt/scrypt-sha256.o"
-l "scrypt-crypto_scrypt-nosse.o" "lib/scrypt/scrypt-crypto_scrypt-nosse.o"
-l "scrypt-memlimit.o" "lib/scrypt/scrypt-memlimit.o"
-l "scrypt-scryptenc_cpuperf.o" "lib/scrypt/scrypt-scryptenc_cpuperf.o"
-l "scrypt-scryptenc.o" "lib/scrypt/scrypt-scryptenc.o"
-l"crypto" -l"crypto"
) )
# build mpw. cc "${options[@]}" -std=c99 -c types.c -o types.o "$@"
gcc "${deps[@]}" -Qunused-arguments -c types.c -o types.o "$@" cc "${options[@]}" -std=c99 -l"types.o" mpw.c -o mpw "$@"
gcc "${deps[@]}" -Qunused-arguments -l"types.o" mpw.c -o mpw "$@"
echo "done! Now run ./install or use ./mpw" echo "done! Now run ./install or use ./mpw"

View File

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