From 1bfc24dda0f391b88d7617c6947d03216abb0d80 Mon Sep 17 00:00:00 2001 From: Marcio Barbosa Date: Wed, 6 Jul 2016 09:56:26 -0300 Subject: [PATCH] pam: avoid warning messages In order to avoid some warning messages, do not ignore the code returned by some functions. Change-Id: Ie01fa98b54010d566fb5b980b001d58989ef9a67 Reviewed-on: https://gerrit.openafs.org/12298 Reviewed-by: Benjamin Kaduk Tested-by: BuildBot --- src/pam/afs_util.c | 32 +++++++++++++++++++++++++++----- src/pam/test_pam.c | 12 ++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/pam/afs_util.c b/src/pam/afs_util.c index 08cc0fd..1560a6f 100644 --- a/src/pam/afs_util.c +++ b/src/pam/afs_util.c @@ -83,7 +83,8 @@ do_klog(const char *user, const char *password, const char *lifetime, char *argv[32]; int argc = 0; char *klog_prog; - int ret = 1; + int ret = 1; /* ret different than zero means failure */ + int fd, nbytes; #if defined(AFS_KERBEROS_ENV) klog_prog = KLOGKRB; @@ -124,11 +125,22 @@ do_klog(const char *user, const char *password, const char *lifetime, goto out; case (0): /* child */ close(0); - dup(pipedes[0]); + fd = dup(pipedes[0]); close(pipedes[0]); + if (fd == -1) { + syslog(LOG_ERR, "do_klog: dup failed for pipedes[0]: %s", + strerror(errno)); + exit(1); + } close(1); - dup(pipedes[1]); + fd = dup(pipedes[1]); close(pipedes[1]); + if (fd == -1) { + close(0); + syslog(LOG_ERR, "do_klog: dup failed for pipedes[1]: %s", + strerror(errno)); + exit(1); + } execv(klog_prog, argv); /* notreached */ syslog(LOG_ERR, "execv failed: %s", strerror(errno)); @@ -136,8 +148,18 @@ do_klog(const char *user, const char *password, const char *lifetime, close(1); goto out; default: - write(pipedes[1], password, strlen(password)); - write(pipedes[1], "\n", 1); + nbytes = write(pipedes[1], password, strlen(password)); + if (nbytes == -1) { + syslog(LOG_ERR, + "do_klog: could not write the password into the input of the pipe: %s", + strerror(errno)); + } + nbytes = write(pipedes[1], "\n", 1); + if (nbytes == -1) { + syslog(LOG_ERR, + "do_klog: could not write the end-of-line code into the input of the pipe: %s", + strerror(errno)); + } close(pipedes[0]); close(pipedes[1]); if (pid != wait(&status)) diff --git a/src/pam/test_pam.c b/src/pam/test_pam.c index e3004a5..1133c25 100644 --- a/src/pam/test_pam.c +++ b/src/pam/test_pam.c @@ -95,7 +95,12 @@ main(int argc, char *argv[]) putenv((char *)new_envstring); putenv((char *)new_homestring); - chdir("/tmp"); + + if ((retcode = chdir("/tmp")) != 0) { + fprintf(stderr, "chdir returned %d.\n", retcode); + exit(1); + } + printf("Type exit to back out.\n"); return execl("/bin/csh", "/bin/csh", NULL); } @@ -135,7 +140,10 @@ my_conv(int num_msg, PAM_CONST struct pam_message **msg, struct pam_response **r fputs(m->msg, stdout); if (r) { r->resp = malloc(PAM_MAX_RESP_SIZE); - fgets(r->resp, PAM_MAX_RESP_SIZE, stdin); + if (fgets(r->resp, PAM_MAX_RESP_SIZE, stdin) == NULL) { + fprintf(stderr, "fgets did not work as expected\n"); + exit(1); + } r->resp[PAM_MAX_RESP_SIZE - 1] = '\0'; p = &r->resp[strlen(r->resp) - 1]; while (*p == '\n' && p >= r->resp) -- 1.9.4