diff options
author | Thorsten Kukuk <kukuk@suse.com> | 2022-02-23 12:15:33 +0100 |
---|---|---|
committer | Thorsten Kukuk <5908016+thkukuk@users.noreply.github.com> | 2022-02-24 10:20:44 +0100 |
commit | b95a6d48c9d4a6490ee8cf638098407ac482495a (patch) | |
tree | 7d05694ca4f2587de6d39ffbe297a860685f14c9 | |
parent | 2f289878b6a7bd888fdfcfe4286b87006074da11 (diff) | |
download | pam-b95a6d48c9d4a6490ee8cf638098407ac482495a.tar.gz pam-b95a6d48c9d4a6490ee8cf638098407ac482495a.tar.bz2 pam-b95a6d48c9d4a6490ee8cf638098407ac482495a.zip |
pam_nologin: don't print empty message
-rw-r--r-- | modules/pam_nologin/pam_nologin.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/modules/pam_nologin/pam_nologin.c b/modules/pam_nologin/pam_nologin.c index b7f9bab0..d7f83e0c 100644 --- a/modules/pam_nologin/pam_nologin.c +++ b/modules/pam_nologin/pam_nologin.c @@ -79,7 +79,6 @@ static int perform_check(pam_handle_t *pamh, struct opt_s *opts) if (fd >= 0) { - char *mtmp=NULL; int msg_style = PAM_TEXT_INFO; struct passwd *user_pwd; struct stat st; @@ -99,21 +98,25 @@ static int perform_check(pam_handle_t *pamh, struct opt_s *opts) goto clean_up_fd; } - mtmp = malloc(st.st_size+1); - if (!mtmp) { - pam_syslog(pamh, LOG_CRIT, "out of memory"); - retval = PAM_BUF_ERR; - goto clean_up_fd; - } - - if (pam_modutil_read(fd, mtmp, st.st_size) == st.st_size) { - mtmp[st.st_size] = '\0'; - (void) pam_prompt (pamh, msg_style, NULL, "%s", mtmp); + /* Don't print anything if the message is empty, will only + disturb the output with empty lines */ + if (st.st_size > 0) { + char *mtmp = malloc(st.st_size+1); + if (!mtmp) { + pam_syslog(pamh, LOG_CRIT, "out of memory"); + retval = PAM_BUF_ERR; + goto clean_up_fd; + } + + if (pam_modutil_read(fd, mtmp, st.st_size) == st.st_size) { + mtmp[st.st_size] = '\0'; + (void) pam_prompt (pamh, msg_style, NULL, "%s", mtmp); + } + else + retval = PAM_SYSTEM_ERR; + + free(mtmp); } - else - retval = PAM_SYSTEM_ERR; - - free(mtmp); clean_up_fd: |