Skip to content

Commit d9b1b44

Browse files
committed
Replace editline and readline with getpass.
1 parent c3c2de5 commit d9b1b44

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

MasterPassword/C/build

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ set -e
1616
options=(
1717
# optional features.
1818
-DDEBUG # Turn on debugging verbosity.
19-
#-DEDITLINE -ledit -ltermcap # Use editline for reading the master password.
20-
-DREADLINE -lreadline # Use readline for reading the master password.
2119
)
2220

2321

@@ -74,7 +72,7 @@ echo "Building mpw..."
7472

7573
cc() {
7674
if hash llvm-gcc 2>/dev/null; then
77-
llvm-gcc -std=c11 "$@"
75+
llvm-gcc "$@"
7876
else
7977
gcc -std=gnu99 "$@"
8078
fi

MasterPassword/C/mpw.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#define _ISOC11_SOURCE 1
2-
#define __STDC_VERSION__ 201112L
1+
#define _GNU_SOURCE
32

43
#include <stdio.h>
54
#include <sys/ioctl.h>
@@ -190,32 +189,15 @@ int main(int argc, char *const argv[]) {
190189
break;
191190
}
192191
}
193-
while (!masterPassword) {
194-
#if defined(READLINE)
195-
masterPassword = readline( "Your master password: " );
196-
#elif defined(EDITLINE)
197-
EditLine *e = el_init("mpw", stdin, stdout, stderr);
198-
int count = 0;
199-
char *line = el_gets(e, &count);
200-
masterPassword = strdup(strsep(&line, "\n"));
201-
el_end(e);
202-
203-
if (count < 0) {
204-
fprintf(stderr, "Could not read master password: %d\n", errno);
205-
continue;
206-
}
207-
#else
208-
fprintf(stderr, "Missing master password for user: %s\n", userName);
209-
return 1;
210-
#endif
211-
}
192+
while (!masterPassword)
193+
masterPassword = getpass( "Your master password: " );
212194
trc("masterPassword: %s\n", masterPassword);
213195

214196
// Calculate the master key salt.
215197
const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword);
216198
trc("key scope: %s\n", mpKeyScope);
217199
const uint32_t n_userNameLength = htonl(strlen(userName));
218-
size_t masterKeySaltLength = strlen(mpKeyScope) + sizeof(n_userNameLength) + strlen(userName);
200+
const size_t masterKeySaltLength = strlen(mpKeyScope) + sizeof(n_userNameLength) + strlen(userName);
219201
char *masterKeySalt = malloc( masterKeySaltLength );
220202
if (!masterKeySalt) {
221203
fprintf(stderr, "Could not allocate master key salt: %d\n", errno);
@@ -251,7 +233,7 @@ int main(int argc, char *const argv[]) {
251233
trc("site scope: %s\n", mpSiteScope);
252234
const uint32_t n_siteNameLength = htonl(strlen(siteName));
253235
const uint32_t n_siteCounter = htonl(siteCounter);
254-
size_t sitePasswordInfoLength = strlen(mpSiteScope) + sizeof(n_siteNameLength) + strlen(siteName) + sizeof(n_siteCounter);
236+
const size_t sitePasswordInfoLength = strlen(mpSiteScope) + sizeof(n_siteNameLength) + strlen(siteName) + sizeof(n_siteCounter);
255237
char *sitePasswordInfo = malloc( sitePasswordInfoLength );
256238
if (!sitePasswordInfo) {
257239
fprintf(stderr, "Could not allocate site seed: %d\n", errno);

0 commit comments

Comments
 (0)