mirror of
https://github.com/Yubico/yubico-pam.git
synced 2024-11-29 00:24:11 +01:00
check that file doesn't exist before we try to write it
This commit is contained in:
parent
7639f4684a
commit
0a1051f6df
@ -145,6 +145,7 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u
|
||||
char *fn;
|
||||
struct passwd *p;
|
||||
FILE *f = NULL;
|
||||
struct stat st;
|
||||
|
||||
state.iterations = iterations;
|
||||
state.slot = slot;
|
||||
@ -162,7 +163,6 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u
|
||||
*/
|
||||
|
||||
if (!output_dir){
|
||||
struct stat st;
|
||||
char fullpath[256];
|
||||
snprintf(fullpath, 256,"%s/.yubico",p->pw_dir);
|
||||
|
||||
@ -190,6 +190,11 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (stat(fn, &st) == 0) {
|
||||
fprintf(stderr, "File %s already exists, refusing to overwrite.\n", fn);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (generate_random(state.challenge, CR_CHALLENGE_SIZE)) {
|
||||
fprintf (stderr, "FAILED getting %i bytes of random data\n", CR_CHALLENGE_SIZE);
|
||||
goto out;
|
||||
|
Loading…
Reference in New Issue
Block a user