diff --git a/pam_kwallet.c b/pam_kwallet.c --- a/pam_kwallet.c +++ b/pam_kwallet.c @@ -436,13 +436,14 @@ // Fork twice to daemonize kwallet setsid(); - pid_t pid = fork(); - if (pid != 0) { - if (pid == -1) { - exit(EXIT_FAILURE); - } else { - exit(0); - } + const pid_t pid = fork(); + switch (pid) { + case 0: + break; + case -1: + exit(EXIT_FAILURE); + default: + exit(0); } //TODO use a pam argument for full path kwalletd @@ -529,9 +530,9 @@ return; } - pid_t pid; + const pid_t pid = fork(); int status; - switch (pid = fork ()) { + switch (pid) { case -1: pam_syslog(pamh, LOG_ERR, "%s: Couldn't fork to execv kwalletd", logPrefix); return; @@ -540,7 +541,7 @@ case 0: execute_kwallet(pamh, userInfo, toWalletPipe, fullSocket); /* Should never be reached */ - break; + return; //Parent default: @@ -666,10 +667,12 @@ static void createNewSalt(pam_handle_t *pamh, const char *path, struct passwd *userInfo) { - const int pid = fork(); - if (pid == -1) { + const pid_t pid = fork(); + switch (pid) { + case -1: pam_syslog(pamh, LOG_ERR, "%s: Couldn't fork to create salt file", logPrefix); - } else if (pid == 0) { + break; + case 0: { // Child process if (drop_privileges(userInfo) < 0) { syslog(LOG_ERR, "%s: could not set gid/uid/euid/egit for salt file creation", logPrefix); @@ -696,13 +699,15 @@ fclose(fd); exit(0); // success - } else { + } + default: { // pam process, just wait for child to finish int status; waitpid(pid, &status, 0); if (status != 0) { pam_syslog(pamh, LOG_ERR, "%s: Couldn't create salt file", logPrefix); } + } } }