diff options
author | Steve Langasek <steve.langasek@ubuntu.com> | 2019-01-03 12:48:14 -0800 |
---|---|---|
committer | Steve Langasek <steve.langasek@ubuntu.com> | 2019-01-03 12:48:14 -0800 |
commit | d5b06b67bbeeed7c05c0eb2e05d6a972ad050d1c (patch) | |
tree | ba5654cffacfd2002eefc5bc3764a7971afff1dc /Linux-PAM/modules/pam_motd/pam_motd.c | |
parent | 4c51da22e068907adb7857d50f5109a467c94d7c (diff) | |
parent | 7cbfa335c57d068d59508c844f3957165cccfb9b (diff) | |
download | pam-d5b06b67bbeeed7c05c0eb2e05d6a972ad050d1c.tar.gz pam-d5b06b67bbeeed7c05c0eb2e05d6a972ad050d1c.tar.bz2 pam-d5b06b67bbeeed7c05c0eb2e05d6a972ad050d1c.zip |
New upstream version 0.99.7.1
Diffstat (limited to 'Linux-PAM/modules/pam_motd/pam_motd.c')
-rw-r--r-- | Linux-PAM/modules/pam_motd/pam_motd.c | 125 |
1 files changed, 61 insertions, 64 deletions
diff --git a/Linux-PAM/modules/pam_motd/pam_motd.c b/Linux-PAM/modules/pam_motd/pam_motd.c index ce695f92..abf10a2f 100644 --- a/Linux-PAM/modules/pam_motd/pam_motd.c +++ b/Linux-PAM/modules/pam_motd/pam_motd.c @@ -4,13 +4,13 @@ * Modified for pam_motd by Ben Collins <bcollins@debian.org> * * Based off of: - * $Id: pam_motd.c,v 1.3 2004/09/22 09:37:49 kukuk Exp $ - * + * $Id: pam_motd.c,v 1.12 2005/10/04 11:35:18 ldv Exp $ + * * Written by Michael K. Johnson <johnsonm@redhat.com> 1996/10/24 * */ -#include <security/_pam_aconf.h> +#include "config.h" #include <stdio.h> #include <string.h> @@ -20,8 +20,10 @@ #include <sys/types.h> #include <sys/stat.h> #include <pwd.h> +#include <syslog.h> #include <security/_pam_macros.h> +#include <security/pam_ext.h> /* * here, we make a definition for the externally accessible function * in this file (this definition is required for static a module @@ -33,82 +35,77 @@ #define DEFAULT_MOTD "/etc/motd" #include <security/pam_modules.h> -#include <security/_pam_modutil.h> +#include <security/pam_modutil.h> /* --- session management functions (only) --- */ -PAM_EXTERN -int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, - const char **argv) +PAM_EXTERN int +pam_sm_close_session (pam_handle_t *pamh UNUSED, int flags UNUSED, + int argc UNUSED, const char **argv UNUSED) { return PAM_IGNORE; } +static char default_motd[] = DEFAULT_MOTD; + PAM_EXTERN -int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, - const char **argv) +int pam_sm_open_session(pam_handle_t *pamh, int flags, + int argc, const char **argv) { - int retval = PAM_IGNORE; - int fd; - char *mtmp=NULL; - const char *motd_path=NULL; - struct pam_conv *conversation; - struct pam_message message; - struct pam_message *pmessage = &message; - struct pam_response *resp = NULL; - struct stat st; - - if (flags & PAM_SILENT) { + int retval = PAM_IGNORE; + int fd; + const char *motd_path = NULL; + char *mtmp = NULL; + + if (flags & PAM_SILENT) { return retval; - } + } for (; argc-- > 0; ++argv) { if (!strncmp(*argv,"motd=",5)) { - motd_path = (char *) strdup(5+*argv); - if (motd_path != NULL) { - D(("set motd path: %s (and a memory leak)", motd_path)); - } else { - D(("failed to duplicate motd path - ignored")); - } + motd_path = 5 + *argv; + if (*motd_path != '\0') { + D(("set motd path: %s", motd_path)); + } else { + motd_path = NULL; + pam_syslog(pamh, LOG_ERR, + "motd= specification missing argument - ignored"); + } } - } - - if (motd_path == NULL) - motd_path = DEFAULT_MOTD; - - message.msg_style = PAM_TEXT_INFO; - - if ((fd = open(motd_path, O_RDONLY, 0)) >= 0) { - /* fill in message buffer with contents of motd */ - if ((fstat(fd, &st) < 0) || !st.st_size) { - close(fd); - return retval; - } - message.msg = mtmp = malloc(st.st_size+1); - /* if malloc failed... */ - if (!message.msg) { - close(fd); - return retval; - } - if (_pammodutil_read(fd, mtmp, st.st_size) == st.st_size) { - if (mtmp[st.st_size-1] == '\n') - mtmp[st.st_size-1] = '\0'; - else - mtmp[st.st_size] = '\0'; - close(fd); - - /* Use conversation function to give user contents of motd */ - if (pam_get_item(pamh, PAM_CONV, (const void **)&conversation) == - PAM_SUCCESS && conversation) { - conversation->conv(1, (const struct pam_message **)&pmessage, - &resp, conversation->appdata_ptr); - if (resp) - _pam_drop_reply(resp, 1); - } - } - free(mtmp); - } + else + pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv); + } + + if (motd_path == NULL) + motd_path = default_motd; + + while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) { + struct stat st; + + /* fill in message buffer with contents of motd */ + if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000) + break; + + if (!(mtmp = malloc(st.st_size+1))) + break; + + if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size) + break; + + if (mtmp[st.st_size-1] == '\n') + mtmp[st.st_size-1] = '\0'; + else + mtmp[st.st_size] = '\0'; + + pam_info (pamh, "%s", mtmp); + break; + } + + _pam_drop (mtmp); + + if (fd >= 0) + close(fd); return retval; } |