1 /* pam_nologin module */
4 * $Id: pam_nologin.c,v 1.2 2000/12/04 19:02:34 baggins Exp $
5 * $FreeBSD: src/contrib/libpam/modules/pam_nologin/pam_nologin.c,v 1.3.2.2 2001/06/11 15:28:22 markm Exp $
7 * Written by Michael K. Johnson <johnsonm@redhat.com> 1996/10/24
15 #include <sys/types.h>
19 #include <security/_pam_macros.h>
21 * here, we make a definition for the externally accessible function
22 * in this file (this definition is required for static a module
23 * but strongly encouraged generally) it is used to instruct the
24 * modules include file to define the function prototypes.
29 #include <security/pam_modules.h>
31 /* --- authentication management functions (only) --- */
34 int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
37 int retval = PAM_SUCCESS;
41 struct passwd *user_pwd;
42 struct pam_conv *conversation;
43 struct pam_message message;
44 struct pam_message *pmessage = &message;
45 struct pam_response *resp = NULL;
48 if ((fd = open("/etc/nologin", O_RDONLY, 0)) >= 0) {
49 /* root can still log in; lusers cannot */
50 if ((pam_get_user(pamh, &username, NULL) != PAM_SUCCESS)
52 return PAM_SERVICE_ERR;
54 user_pwd = getpwnam(username);
55 if (user_pwd && user_pwd->pw_uid == 0) {
56 message.msg_style = PAM_TEXT_INFO;
59 retval = PAM_USER_UNKNOWN;
61 retval = PAM_AUTH_ERR;
63 message.msg_style = PAM_ERROR_MSG;
66 /* fill in message buffer with contents of /etc/nologin */
67 if (fstat(fd, &st) < 0) /* give up trying to display message */
69 message.msg = mtmp = malloc(st.st_size+1);
70 /* if malloc failed... */
71 if (!message.msg) return retval;
72 read(fd, mtmp, st.st_size);
73 mtmp[st.st_size] = '\000';
75 /* Use conversation function to give user contents of /etc/nologin */
76 pam_get_item(pamh, PAM_CONV, (const void **)&conversation);
77 conversation->conv(1, (const struct pam_message **)&pmessage,
78 &resp, conversation->appdata_ptr);
81 _pam_drop_reply(resp, 1);
88 int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc,
95 /* end of module definition */
97 PAM_MODULE_ENTRY("pam_nologin");