4 * Modified for pam_motd by Ben Collins <bcollins@debian.org>
7 * $Id: pam_motd.c,v 1.1.1.1 2000/06/20 22:11:46 agmorgan Exp $
8 * $FreeBSD: src/contrib/libpam/modules/pam_motd/pam_motd.c,v 1.1.1.1.2.2 2001/06/11 15:28:20 markm Exp $
9 * $DragonFly: src/contrib/libpam/modules/pam_motd/Attic/pam_motd.c,v 1.2 2003/06/17 04:24:03 dillon Exp $
11 * Written by Michael K. Johnson <johnsonm@redhat.com> 1996/10/24
20 #include <sys/types.h>
24 #include <security/_pam_macros.h>
26 * here, we make a definition for the externally accessible function
27 * in this file (this definition is required for static a module
28 * but strongly encouraged generally) it is used to instruct the
29 * modules include file to define the function prototypes.
32 #define PAM_SM_SESSION
33 #define DEFAULT_MOTD "/etc/motd"
35 #include <security/pam_modules.h>
37 /* --- session management functions (only) --- */
40 int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc,
47 int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
50 int retval = PAM_IGNORE;
52 char *mtmp=NULL, *motd_path=NULL;
53 struct pam_conv *conversation;
54 struct pam_message message;
55 struct pam_message *pmessage = &message;
56 struct pam_response *resp = NULL;
59 if (flags & PAM_SILENT) {
63 for (; argc-- > 0; ++argv) {
64 if (!strncmp(*argv,"motd=",5)) {
65 motd_path = (char *) strdup(5+*argv);
66 if (motd_path != NULL) {
67 D(("set motd path: %s", motd_path));
69 D(("failed to duplicate motd path - ignored"));
74 if (motd_path == NULL)
75 motd_path = DEFAULT_MOTD;
77 message.msg_style = PAM_TEXT_INFO;
79 if ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
80 /* fill in message buffer with contents of motd */
81 if ((fstat(fd, &st) < 0) || !st.st_size)
83 message.msg = mtmp = malloc(st.st_size+1);
84 /* if malloc failed... */
85 if (!message.msg) return retval;
86 read(fd, mtmp, st.st_size);
87 if (mtmp[st.st_size-1] == '\n')
88 mtmp[st.st_size-1] = '\0';
90 mtmp[st.st_size] = '\0';
92 /* Use conversation function to give user contents of motd */
93 pam_get_item(pamh, PAM_CONV, (const void **)&conversation);
94 conversation->conv(1, (const struct pam_message **)&pmessage,
95 &resp, conversation->appdata_ptr);
98 _pam_drop_reply(resp, 1);
107 /* static module data */
109 struct pam_module _pam_motd_modstruct = {
115 pam_sm_close_session,
121 /* end of module definition */