2001-04-25 00:00:12 +04:00
/* Unix NT password database implementation, version 0.7.5.
*
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU General Public License as published by the Free
2007-07-09 23:25:36 +04:00
* Software Foundation ; either version 3 of the License , or ( at your option )
2001-04-25 00:00:12 +04:00
* any later version .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License for
* more details .
*
* You should have received a copy of the GNU General Public License along with
2007-07-10 09:23:25 +04:00
* this program ; if not , see < http : //www.gnu.org/licenses/>.
2001-04-25 00:00:12 +04:00
*/
/* indicate the following groups are defined */
# define PAM_SM_ACCT
# include "includes.h"
# ifndef LINUX
/* This is only used in the Sun implementation. */
2007-05-24 00:31:28 +04:00
# if defined(HAVE_SECURITY_PAM_APPL_H)
2001-04-25 00:00:12 +04:00
# include <security/pam_appl.h>
2007-05-24 00:31:28 +04:00
# elif defined(HAVE_PAM_PAM_APPL_H)
# include <pam/pam_appl.h>
# endif
2001-04-25 00:00:12 +04:00
# endif /* LINUX */
2007-05-24 00:31:28 +04:00
# if defined(HAVE_SECURITY_PAM_MODULES_H)
2001-04-25 00:00:12 +04:00
# include <security/pam_modules.h>
2007-05-24 00:31:28 +04:00
# elif defined(HAVE_PAM_PAM_MODULES_H)
# include <pam/pam_modules.h>
# endif
2001-04-25 00:00:12 +04:00
# include "general.h"
# include "support.h"
2002-07-15 14:35:28 +04:00
2001-04-25 00:00:12 +04:00
/*
* pam_sm_acct_mgmt ( ) verifies whether or not the account is disabled .
*
*/
int pam_sm_acct_mgmt ( pam_handle_t * pamh , int flags ,
int argc , const char * * argv )
{
2006-06-15 05:54:09 +04:00
unsigned int ctrl ;
int retval ;
const char * name ;
struct samu * sampass = NULL ;
void ( * oldsig_handler ) ( int ) ;
/* Samba initialization. */
load_case_tables ( ) ;
2008-03-06 18:41:42 +03:00
lp_set_in_client ( True ) ;
2006-06-15 05:54:09 +04:00
2009-05-26 17:40:21 +04:00
ctrl = set_ctrl ( pamh , flags , argc , argv ) ;
2006-06-15 05:54:09 +04:00
/* get the username */
retval = pam_get_user ( pamh , & name , " Username: " ) ;
if ( retval ! = PAM_SUCCESS ) {
if ( on ( SMB_DEBUG , ctrl ) ) {
2009-05-26 17:40:21 +04:00
_log_err ( pamh , LOG_DEBUG , " acct: could not identify user " ) ;
2006-06-15 05:54:09 +04:00
}
return retval ;
}
if ( on ( SMB_DEBUG , ctrl ) ) {
2009-05-26 17:40:21 +04:00
_log_err ( pamh , LOG_DEBUG , " acct: username [%s] obtained " , name ) ;
2006-06-15 05:54:09 +04:00
}
2007-12-13 04:26:49 +03:00
if ( geteuid ( ) ! = 0 ) {
2009-05-26 17:40:21 +04:00
_log_err ( pamh , LOG_DEBUG , " Cannot access samba password database, not running as root. " ) ;
2007-12-13 04:26:49 +03:00
return PAM_AUTHINFO_UNAVAIL ;
}
2006-06-15 05:54:09 +04:00
/* Getting into places that might use LDAP -- protect the app
from a SIGPIPE it ' s not expecting */
2010-02-19 17:25:09 +03:00
oldsig_handler = CatchSignal ( SIGPIPE , SIG_IGN ) ;
2007-05-25 00:26:07 +04:00
if ( ! initialize_password_db ( True , NULL ) ) {
2009-05-26 17:40:21 +04:00
_log_err ( pamh , LOG_ALERT , " Cannot access samba password database " ) ;
2010-02-19 17:25:09 +03:00
CatchSignal ( SIGPIPE , oldsig_handler ) ;
2006-06-15 05:54:09 +04:00
return PAM_AUTHINFO_UNAVAIL ;
}
/* Get the user's record. */
if ( ! ( sampass = samu_new ( NULL ) ) ) {
2010-02-19 17:25:09 +03:00
CatchSignal ( SIGPIPE , oldsig_handler ) ;
2006-06-15 05:54:09 +04:00
/* malloc fail. */
return nt_status_to_pam ( NT_STATUS_NO_MEMORY ) ;
}
if ( ! pdb_getsampwnam ( sampass , name ) ) {
2009-05-26 17:40:21 +04:00
_log_err ( pamh , LOG_DEBUG , " acct: could not identify user " ) ;
2010-02-19 17:25:09 +03:00
CatchSignal ( SIGPIPE , oldsig_handler ) ;
2006-06-15 05:54:09 +04:00
return PAM_USER_UNKNOWN ;
}
/* check for lookup failure */
if ( ! strlen ( pdb_get_username ( sampass ) ) ) {
2010-02-19 17:25:09 +03:00
CatchSignal ( SIGPIPE , oldsig_handler ) ;
2006-06-15 05:54:09 +04:00
return PAM_USER_UNKNOWN ;
}
if ( pdb_get_acct_ctrl ( sampass ) & ACB_DISABLED ) {
if ( on ( SMB_DEBUG , ctrl ) ) {
2009-05-26 17:40:21 +04:00
_log_err ( pamh , LOG_DEBUG ,
" acct: account %s is administratively disabled " , name ) ;
2006-06-15 05:54:09 +04:00
}
make_remark ( pamh , ctrl , PAM_ERROR_MSG
, " Your account has been disabled; "
" please see your system administrator. " ) ;
2010-02-19 17:25:09 +03:00
CatchSignal ( SIGPIPE , oldsig_handler ) ;
2006-06-15 05:54:09 +04:00
return PAM_ACCT_EXPIRED ;
}
/* TODO: support for expired passwords. */
2010-02-19 17:25:09 +03:00
CatchSignal ( SIGPIPE , oldsig_handler ) ;
2006-06-15 05:54:09 +04:00
return PAM_SUCCESS ;
2001-04-25 00:00:12 +04:00
}
/* static module data */
# ifdef PAM_STATIC
struct pam_module _pam_smbpass_acct_modstruct = {
" pam_smbpass " ,
NULL ,
NULL ,
pam_sm_acct_mgmt ,
NULL ,
NULL ,
NULL
} ;
# endif