4 * Modified for pam_motd by Ben Collins <bcollins@debian.org>
9 * Written by Michael K. Johnson <johnsonm@redhat.com> 1996/10/24
20 #include <sys/types.h>
25 #include <security/_pam_macros.h>
26 #include <security/pam_ext.h>
28 * here, we make a definition for the externally accessible function
29 * in this file (this definition is required for static a module
30 * but strongly encouraged generally) it is used to instruct the
31 * modules include file to define the function prototypes.
34 #define PAM_SM_SESSION
35 #define DEFAULT_MOTD "/etc/motd"
37 #include <security/pam_modules.h>
38 #include <security/pam_modutil.h>
40 /* --- session management functions (only) --- */
43 pam_sm_close_session (pam_handle_t *pamh UNUSED, int flags UNUSED,
44 int argc UNUSED, const char **argv UNUSED)
49 static char default_motd[] = DEFAULT_MOTD;
52 int pam_sm_open_session(pam_handle_t *pamh, int flags,
53 int argc, const char **argv)
55 int retval = PAM_IGNORE;
57 const char *motd_path = NULL;
60 if (flags & PAM_SILENT) {
64 for (; argc-- > 0; ++argv) {
65 if (!strncmp(*argv,"motd=",5)) {
67 motd_path = 5 + *argv;
68 if (*motd_path != '\0') {
69 D(("set motd path: %s", motd_path));
72 pam_syslog(pamh, LOG_ERR,
73 "motd= specification missing argument - ignored");
77 pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv);
80 if (motd_path == NULL)
81 motd_path = default_motd;
83 while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
86 /* fill in message buffer with contents of motd */
87 if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
90 if (!(mtmp = malloc(st.st_size+1)))
93 if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
96 if (mtmp[st.st_size-1] == '\n')
97 mtmp[st.st_size-1] = '\0';
99 mtmp[st.st_size] = '\0';
101 pam_info (pamh, "%s", mtmp);
116 /* static module data */
118 struct pam_module _pam_motd_modstruct = {
124 pam_sm_close_session,
130 /* end of module definition */