Revert "buildtools: Rename perl vendorarch configure option."
[Samba.git] / source3 / pam_smbpass / pam_smb_acct.c
blobbd4615f646e7f6517521acdaa781ef480c97db5f
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)
6 * any later version.
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.
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 */
18 #define PAM_SM_ACCT
20 #include "includes.h"
22 #ifndef LINUX
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>
29 #endif
31 #endif /* LINUX */
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>
37 #endif
39 #include "general.h"
41 #include "support.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 )
52 unsigned int ctrl;
53 int retval;
55 const char *name;
56 struct samu *sampass = NULL;
57 void (*oldsig_handler)(int);
58 TALLOC_CTX *frame = talloc_stackframe();
60 /* Samba initialization. */
61 load_case_tables_library();
63 ctrl = set_ctrl(pamh, flags, argc, argv );
65 /* get the username */
67 retval = pam_get_user( pamh, &name, "Username: " );
68 if (retval != PAM_SUCCESS) {
69 if (on( SMB_DEBUG, ctrl )) {
70 _log_err(pamh, LOG_DEBUG, "acct: could not identify user" );
72 TALLOC_FREE(frame);
73 return retval;
75 if (on( SMB_DEBUG, ctrl )) {
76 _log_err(pamh, LOG_DEBUG, "acct: username [%s] obtained", name );
79 if (geteuid() != 0) {
80 _log_err(pamh, LOG_DEBUG, "Cannot access samba password database, not running as root.");
81 TALLOC_FREE(frame);
82 return PAM_AUTHINFO_UNAVAIL;
85 /* Getting into places that might use LDAP -- protect the app
86 from a SIGPIPE it's not expecting */
87 oldsig_handler = CatchSignal(SIGPIPE, SIG_IGN);
88 if (!initialize_password_db(True, NULL)) {
89 _log_err(pamh, LOG_ALERT, "Cannot access samba password database" );
90 CatchSignal(SIGPIPE, oldsig_handler);
91 TALLOC_FREE(frame);
92 return PAM_AUTHINFO_UNAVAIL;
95 /* Get the user's record. */
97 if (!(sampass = samu_new( NULL ))) {
98 CatchSignal(SIGPIPE, oldsig_handler);
99 /* malloc fail. */
100 TALLOC_FREE(frame);
101 return nt_status_to_pam(NT_STATUS_NO_MEMORY);
104 if (!pdb_getsampwnam(sampass, name )) {
105 _log_err(pamh, LOG_DEBUG, "acct: could not identify user");
106 CatchSignal(SIGPIPE, oldsig_handler);
107 TALLOC_FREE(frame);
108 return PAM_USER_UNKNOWN;
111 /* check for lookup failure */
112 if (!strlen(pdb_get_username(sampass)) ) {
113 CatchSignal(SIGPIPE, oldsig_handler);
114 TALLOC_FREE(frame);
115 return PAM_USER_UNKNOWN;
118 if (pdb_get_acct_ctrl(sampass) & ACB_DISABLED) {
119 if (on( SMB_DEBUG, ctrl )) {
120 _log_err(pamh, LOG_DEBUG,
121 "acct: account %s is administratively disabled", name);
123 make_remark( pamh, ctrl, PAM_ERROR_MSG
124 , "Your account has been disabled; "
125 "please see your system administrator." );
127 CatchSignal(SIGPIPE, oldsig_handler);
128 TALLOC_FREE(frame);
129 return PAM_ACCT_EXPIRED;
132 /* TODO: support for expired passwords. */
134 CatchSignal(SIGPIPE, oldsig_handler);
135 TALLOC_FREE(frame);
136 return PAM_SUCCESS;
139 /* static module data */
140 #ifdef PAM_STATIC
141 struct pam_module _pam_smbpass_acct_modstruct = {
142 "pam_smbpass",
143 NULL,
144 NULL,
145 pam_sm_acct_mgmt,
146 NULL,
147 NULL,
148 NULL
150 #endif