diff --git a/pam_kwallet.c b/pam_kwallet.c --- a/pam_kwallet.c +++ b/pam_kwallet.c @@ -676,6 +676,14 @@ exit(-1); } + // Don't re-create it if it already exists + struct stat info; + if (stat(path, &info) == 0 && + info.st_size != 0 && + S_ISREG(info.st_mode)) { + exit(0); + } + unlink(path);//in case the file already exists char *dir = strdup(path); @@ -730,6 +738,14 @@ exit(-1); } + struct stat info; + if (stat(path, &info) != 0 || info.st_size == 0 || !S_ISREG(info.st_mode)) { + syslog(LOG_ERR, "%s: Failed to ensure %s looks like a salt file", logPrefix, path); + free(path); + close(readSaltPipe[1]); + exit(-1); + } + FILE *fd = fopen(path, "r"); if (fd == NULL) { syslog(LOG_ERR, "%s: Couldn't open file: %s because: %d-%s", logPrefix, path, errno, strerror(errno)); @@ -801,15 +817,7 @@ char *path = (char*) malloc(pathSize); sprintf(path, "%s/%s/%s", userInfo->pw_dir, kdehome, fixpath); - if (stat(path, &info) != 0 || info.st_size == 0 || !S_ISREG(info.st_mode)) { - createNewSalt(pamh, path, userInfo); - } - - if (stat(path, &info) != 0 || info.st_size == 0 || !S_ISREG(info.st_mode)) { - syslog(LOG_ERR, "%s: Failed to ensure %s looks like a salt file", logPrefix, path); - free(path); - return 1; - } + createNewSalt(pamh, path, userInfo); char salt[KWALLET_PAM_SALTSIZE] = {}; const int readSaltSuccess = readSaltFile(pamh, path, userInfo, salt);