From 5ac4918bdd70474c3f01adbe12f92fbf69659114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20M=C3=B6llers?= Date: Mon, 20 Feb 2017 14:32:37 +0100 Subject: [PATCH 1/3] Add error handling in case exec fails We should print error message if exec fails, for some reason. --- src/useradd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/useradd.c b/src/useradd.c index d973ca32..1a565cf0 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -1817,7 +1817,9 @@ static void tallylog_reset (char *user_name) pname++; /* Skip the '/' */ execl(pam_tally2, pname, "--user", user_name, "--reset", "--quiet", NULL); /* If we come here, something has gone terribly wrong */ - failed = 1; + perror(pam_tally2); + exit(42); /* don't continue, we now have 2 processes running! */ + /* NOTREACHED */ break; default: /* parent */ if (waitpid(childpid, &status, 0) == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) From 90c0525c7e261f12d46b19ece4a694e7475dd52e Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Mon, 20 Feb 2017 14:46:18 +0100 Subject: [PATCH 2/3] Remove unnecessary static variable usage --- src/useradd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/useradd.c b/src/useradd.c index 1a565cf0..8b30a766 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -1794,7 +1794,7 @@ static void lastlog_reset (uid_t uid) static void tallylog_reset (char *user_name) { - static const char pam_tally2[] = "/sbin/pam_tally2"; + const char pam_tally2[] = "/sbin/pam_tally2"; const char *pname; pid_t childpid; int failed; From 759f94e17a5000d0a7bce5de1c21b6261d31a7d9 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Mon, 20 Feb 2017 14:49:30 +0100 Subject: [PATCH 3/3] Remove extra parenthesis --- src/useradd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/useradd.c b/src/useradd.c index 8b30a766..6d944056 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -2287,7 +2287,7 @@ int main (int argc, char **argv) * a valid existing user name, * so we canot call it before close_files() */ - if ((!lflg) && (getpwuid (user_id) != NULL)) { + if (!lflg && getpwuid (user_id) != NULL) { tallylog_reset (user_name); }