1 /* Unix NT password database implementation, version 0.7.5.
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 3 of the License, or (at your option)
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
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
17 /* indicate the following groups are defined */
24 /* This is only used in the Sun implementation. */
25 #if defined(HAVE_SECURITY_PAM_APPL_H)
26 #include <security/pam_appl.h>
27 #elif defined(HAVE_PAM_PAM_APPL_H)
28 #include <pam/pam_appl.h>
33 #if defined(HAVE_SECURITY_PAM_MODULES_H)
34 #include <security/pam_modules.h>
35 #elif defined(HAVE_PAM_PAM_MODULES_H)
36 #include <pam/pam_modules.h>
45 * pam_sm_acct_mgmt() verifies whether or not the account is disabled.
49 int pam_sm_acct_mgmt( pam_handle_t
*pamh
, int flags
,
50 int argc
, const char **argv
)
56 struct samu
*sampass
= NULL
;
57 void (*oldsig_handler
)(int);
59 /* Samba initialization. */
61 setup_logging( "pam_smbpass", False
);
62 lp_set_in_client(True
);
64 ctrl
= set_ctrl( flags
, argc
, argv
);
66 /* get the username */
68 retval
= pam_get_user( pamh
, &name
, "Username: " );
69 if (retval
!= PAM_SUCCESS
) {
70 if (on( SMB_DEBUG
, ctrl
)) {
71 _log_err( LOG_DEBUG
, "acct: could not identify user" );
75 if (on( SMB_DEBUG
, ctrl
)) {
76 _log_err( LOG_DEBUG
, "acct: username [%s] obtained", name
);
80 _log_err( LOG_DEBUG
, "Cannot access samba password database, not running as root.");
81 return PAM_AUTHINFO_UNAVAIL
;
84 /* Getting into places that might use LDAP -- protect the app
85 from a SIGPIPE it's not expecting */
86 oldsig_handler
= CatchSignal(SIGPIPE
, SIGNAL_CAST SIG_IGN
);
87 if (!initialize_password_db(True
, NULL
)) {
88 _log_err( LOG_ALERT
, "Cannot access samba password database" );
89 CatchSignal(SIGPIPE
, SIGNAL_CAST oldsig_handler
);
90 return PAM_AUTHINFO_UNAVAIL
;
93 /* Get the user's record. */
95 if (!(sampass
= samu_new( NULL
))) {
96 CatchSignal(SIGPIPE
, SIGNAL_CAST oldsig_handler
);
98 return nt_status_to_pam(NT_STATUS_NO_MEMORY
);
101 if (!pdb_getsampwnam(sampass
, name
)) {
102 _log_err( LOG_DEBUG
, "acct: could not identify user" );
103 CatchSignal(SIGPIPE
, SIGNAL_CAST oldsig_handler
);
104 return PAM_USER_UNKNOWN
;
107 /* check for lookup failure */
108 if (!strlen(pdb_get_username(sampass
)) ) {
109 CatchSignal(SIGPIPE
, SIGNAL_CAST oldsig_handler
);
110 return PAM_USER_UNKNOWN
;
113 if (pdb_get_acct_ctrl(sampass
) & ACB_DISABLED
) {
114 if (on( SMB_DEBUG
, ctrl
)) {
116 , "acct: account %s is administratively disabled", name
);
118 make_remark( pamh
, ctrl
, PAM_ERROR_MSG
119 , "Your account has been disabled; "
120 "please see your system administrator." );
122 CatchSignal(SIGPIPE
, SIGNAL_CAST oldsig_handler
);
123 return PAM_ACCT_EXPIRED
;
126 /* TODO: support for expired passwords. */
128 CatchSignal(SIGPIPE
, SIGNAL_CAST oldsig_handler
);
132 /* static module data */
134 struct pam_module _pam_smbpass_acct_modstruct
= {