Initial import
[samba] / source / pam_smbpass / pam_smb_acct.c
1 /* Unix NT password database implementation, version 0.7.5.
2  *
3  * This program is free software; you can redistribute it and/or modify it under
4  * the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc., 675
15  * Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18 /* indicate the following groups are defined */
19 #define PAM_SM_ACCT
20
21 #include "includes.h"
22
23 #ifndef LINUX
24
25 /* This is only used in the Sun implementation. */
26 #include <security/pam_appl.h>
27
28 #endif  /* LINUX */
29
30 #include <security/pam_modules.h>
31
32 #include "general.h"
33
34 #include "support.h"
35
36
37 /*
38  * pam_sm_acct_mgmt() verifies whether or not the account is disabled.
39  *
40  */
41
42 int pam_sm_acct_mgmt( pam_handle_t *pamh, int flags,
43                       int argc, const char **argv )
44 {
45     unsigned int ctrl;
46     int retval;
47
48     const char *name;
49     SAM_ACCOUNT *sampass = NULL;
50     void (*oldsig_handler)(int);
51     extern BOOL in_client;
52
53     /* Samba initialization. */
54     setup_logging( "pam_smbpass", False );
55     in_client = True;
56
57     ctrl = set_ctrl( flags, argc, argv );
58
59     /* get the username */
60
61     retval = pam_get_user( pamh, &name, "Username: " );
62     if (retval != PAM_SUCCESS) {
63         if (on( SMB_DEBUG, ctrl )) {
64             _log_err( LOG_DEBUG, "acct: could not identify user" );
65         }
66         return retval;
67     }
68     if (on( SMB_DEBUG, ctrl )) {
69         _log_err( LOG_DEBUG, "acct: username [%s] obtained", name );
70     }
71
72     /* Getting into places that might use LDAP -- protect the app
73        from a SIGPIPE it's not expecting */
74     oldsig_handler = CatchSignal(SIGPIPE, SIGNAL_CAST SIG_IGN);
75     if (!initialize_password_db(True)) {
76         _log_err( LOG_ALERT, "Cannot access samba password database" );
77         CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
78         return PAM_AUTHINFO_UNAVAIL;
79     }
80
81     /* Get the user's record. */
82     pdb_init_sam(&sampass);
83     pdb_getsampwnam(sampass, name );
84
85     if (!sampass) {
86         CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
87         return PAM_USER_UNKNOWN;
88     }
89
90     if (pdb_get_acct_ctrl(sampass) & ACB_DISABLED) {
91         if (on( SMB_DEBUG, ctrl )) {
92             _log_err( LOG_DEBUG
93                       , "acct: account %s is administratively disabled", name );
94         }
95         make_remark( pamh, ctrl, PAM_ERROR_MSG
96                      , "Your account has been disabled; "
97                        "please see your system administrator." );
98
99         CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
100         return PAM_ACCT_EXPIRED;
101     }
102
103     /* TODO: support for expired passwords. */
104
105     CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
106     return PAM_SUCCESS;
107 }
108
109 /* static module data */
110 #ifdef PAM_STATIC
111 struct pam_module _pam_smbpass_acct_modstruct = {
112      "pam_smbpass",
113      NULL,
114      NULL,
115      pam_sm_acct_mgmt,
116      NULL,
117      NULL,
118      NULL
119 };
120 #endif
121