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 $
10 * Written by Michael K. Johnson <johnsonm@redhat.com> 1996/10/24
19 #include <sys/types.h>
23 #include <security/_pam_macros.h>
25 * here, we make a definition for the externally accessible function
26 * in this file (this definition is required for static a module
27 * but strongly encouraged generally) it is used to instruct the
28 * modules include file to define the function prototypes.
31 #define PAM_SM_SESSION
32 #define DEFAULT_MOTD "/etc/motd"
34 #include <security/pam_modules.h>
36 /* --- session management functions (only) --- */
39 int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc,
46 int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
49 int retval = PAM_IGNORE;
51 char *mtmp=NULL, *motd_path=NULL;
52 struct pam_conv *conversation;
53 struct pam_message message;
54 struct pam_message *pmessage = &message;
55 struct pam_response *resp = NULL;
58 if (flags & PAM_SILENT) {
62 for (; argc-- > 0; ++argv) {
63 if (!strncmp(*argv,"motd=",5)) {
64 motd_path = (char *) strdup(5+*argv);
65 if (motd_path != NULL) {
66 D(("set motd path: %s", motd_path));
68 D(("failed to duplicate motd path - ignored"));
73 if (motd_path == NULL)
74 motd_path = DEFAULT_MOTD;
76 message.msg_style = PAM_TEXT_INFO;
78 if ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
79 /* fill in message buffer with contents of motd */
80 if ((fstat(fd, &st) < 0) || !st.st_size)
82 message.msg = mtmp = malloc(st.st_size+1);
83 /* if malloc failed... */
84 if (!message.msg) return retval;
85 read(fd, mtmp, st.st_size);
86 if (mtmp[st.st_size-1] == '\n')
87 mtmp[st.st_size-1] = '\0';
89 mtmp[st.st_size] = '\0';
91 /* Use conversation function to give user contents of motd */
92 pam_get_item(pamh, PAM_CONV, (const void **)&conversation);
93 conversation->conv(1, (const struct pam_message **)&pmessage,
94 &resp, conversation->appdata_ptr);
97 _pam_drop_reply(resp, 1);
106 /* static module data */
108 struct pam_module _pam_motd_modstruct = {
114 pam_sm_close_session,
120 /* end of module definition */