add password callback hook

This commit is contained in:
discomfitor 2011-08-11 03:41:22 -04:00 committed by Con Kolivas
parent cbff8faef7
commit 08d2294e5e
2 changed files with 25 additions and 19 deletions

42
lrzip.c
View file

@ -538,34 +538,38 @@ static void get_hash(rzip_control *control, int make_hash)
mlock(control->salt_pass, PASS_LEN);
mlock(control->hash, HASH_LEN);
/* Disable stdin echo to screen */
tcgetattr(fileno(stdin), &termios_p);
termios_p.c_lflag &= ~ECHO;
tcsetattr(fileno(stdin), 0, &termios_p);
if (control->pass_cb) {
control->pass_cb(control->pass_data, passphrase, PASS_LEN);
if (!passphrase[0]) fatal(control, "Supplied password was null!");
} else {
/* Disable stdin echo to screen */
tcgetattr(fileno(stdin), &termios_p);
termios_p.c_lflag &= ~ECHO;
tcsetattr(fileno(stdin), 0, &termios_p);
retry_pass:
print_output("Enter passphrase: ");
control->salt_pass_len = get_pass(control, passphrase) + SALT_LEN;
print_output("\n");
if (make_hash) {
print_output("Re-enter passphrase: ");
get_pass(control, testphrase);
print_output("Enter passphrase: ");
control->salt_pass_len = get_pass(control, passphrase) + SALT_LEN;
print_output("\n");
if (strcmp(passphrase, testphrase)) {
print_output("Passwords do not match. Try again.\n");
goto retry_pass;
if (make_hash) {
print_output("Re-enter passphrase: ");
get_pass(control, testphrase);
print_output("\n");
if (strcmp(passphrase, testphrase)) {
print_output("Passwords do not match. Try again.\n");
goto retry_pass;
}
}
termios_p.c_lflag |= ECHO;
tcsetattr(fileno(stdin), 0, &termios_p);
memset(testphrase, 0, PASS_LEN);
}
termios_p.c_lflag |= ECHO;
tcsetattr(fileno(stdin), 0, &termios_p);
memset(testphrase, 0, PASS_LEN);
munlock(testphrase, PASS_LEN);
free(testphrase);
memcpy(control->salt_pass, control->salt, SALT_LEN);
memcpy(control->salt_pass + SALT_LEN, passphrase, PASS_LEN - SALT_LEN);
lrz_stretch(control);
memset(passphrase, 0, PASS_LEN);
munlock(passphrase, PASS_LEN);
munlock(testphrase, PASS_LEN);
free(testphrase);
free(passphrase);
}

View file

@ -311,6 +311,8 @@ struct rzip_control {
int fd_hist;
i64 encloops;
i64 secs;
void (*pass_cb)(void *, char *, size_t); /* callback to get password in lib */
void *pass_data;
uchar salt[SALT_LEN];
uchar *salt_pass;
int salt_pass_len;