1
0
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:
Klas Lindfors 2016-03-31 10:12:18 +02:00
parent 7639f4684a
commit 0a1051f6df

View File

@ -145,6 +145,7 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u
char *fn; char *fn;
struct passwd *p; struct passwd *p;
FILE *f = NULL; FILE *f = NULL;
struct stat st;
state.iterations = iterations; state.iterations = iterations;
state.slot = slot; 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){ if (!output_dir){
struct stat st;
char fullpath[256]; char fullpath[256];
snprintf(fullpath, 256,"%s/.yubico",p->pw_dir); 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; 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)) { if (generate_random(state.challenge, CR_CHALLENGE_SIZE)) {
fprintf (stderr, "FAILED getting %i bytes of random data\n", CR_CHALLENGE_SIZE); fprintf (stderr, "FAILED getting %i bytes of random data\n", CR_CHALLENGE_SIZE);
goto out; goto out;