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

10
lrzip.c
View file

@ -538,6 +538,10 @@ static void get_hash(rzip_control *control, int make_hash)
mlock(control->salt_pass, PASS_LEN); mlock(control->salt_pass, PASS_LEN);
mlock(control->hash, HASH_LEN); mlock(control->hash, HASH_LEN);
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 */ /* Disable stdin echo to screen */
tcgetattr(fileno(stdin), &termios_p); tcgetattr(fileno(stdin), &termios_p);
termios_p.c_lflag &= ~ECHO; termios_p.c_lflag &= ~ECHO;
@ -558,14 +562,14 @@ retry_pass:
termios_p.c_lflag |= ECHO; termios_p.c_lflag |= ECHO;
tcsetattr(fileno(stdin), 0, &termios_p); tcsetattr(fileno(stdin), 0, &termios_p);
memset(testphrase, 0, PASS_LEN); memset(testphrase, 0, PASS_LEN);
munlock(testphrase, PASS_LEN); }
free(testphrase);
memcpy(control->salt_pass, control->salt, SALT_LEN); memcpy(control->salt_pass, control->salt, SALT_LEN);
memcpy(control->salt_pass + SALT_LEN, passphrase, PASS_LEN - SALT_LEN); memcpy(control->salt_pass + SALT_LEN, passphrase, PASS_LEN - SALT_LEN);
lrz_stretch(control); lrz_stretch(control);
memset(passphrase, 0, PASS_LEN); memset(passphrase, 0, PASS_LEN);
munlock(passphrase, PASS_LEN); munlock(passphrase, PASS_LEN);
munlock(testphrase, PASS_LEN);
free(testphrase);
free(passphrase); free(passphrase);
} }

View file

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