2001-11-24 12:16:27 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
2001-11-24 12:16:27 +00:00
Winbind authentication mechnism
Copyright ( C ) Tim Potter 2000
2002-09-25 15:19:00 +00:00
Copyright ( C ) Andrew Bartlett 2001 - 2002
2001-11-24 12:16:27 +00:00
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
2007-07-09 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2001-11-24 12:16:27 +00:00
( at your option ) 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
2007-07-10 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2001-11-24 12:16:27 +00:00
*/
# include "includes.h"
2002-07-15 10:35:28 +00:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_AUTH
2001-11-24 12:16:27 +00:00
/* Authenticate a user with a challenge/response */
2002-01-05 04:55:41 +00:00
static NTSTATUS check_winbind_security ( const struct auth_context * auth_context ,
void * my_private_data ,
2002-01-01 03:10:32 +00:00
TALLOC_CTX * mem_ctx ,
const auth_usersupplied_info * user_info ,
auth_serversupplied_info * * server_info )
2001-11-24 12:16:27 +00:00
{
NTSTATUS nt_status ;
2008-02-04 18:18:36 +01:00
wbcErr wbc_status ;
struct wbcAuthUserParams params ;
struct wbcAuthUserInfo * info = NULL ;
struct wbcAuthErrorInfo * err = NULL ;
2001-11-24 12:16:27 +00:00
if ( ! user_info ) {
2002-08-17 17:00:51 +00:00
return NT_STATUS_INVALID_PARAMETER ;
2001-11-24 12:16:27 +00:00
}
2002-01-05 04:55:41 +00:00
if ( ! auth_context ) {
2001-11-26 04:05:28 +00:00
DEBUG ( 3 , ( " Password for user %s cannot be checked because we have no auth_info to get the challenge from. \n " ,
2006-02-03 22:19:41 +00:00
user_info - > internal_username ) ) ;
2003-07-03 14:36:42 +00:00
return NT_STATUS_INVALID_PARAMETER ;
2001-11-24 12:16:27 +00:00
}
2006-02-03 22:19:41 +00:00
if ( strequal ( user_info - > domain , get_global_sam_name ( ) ) ) {
2003-12-19 00:33:09 +00:00
DEBUG ( 3 , ( " check_winbind_security: Not using winbind, requested domain [%s] was for this SAM. \n " ,
2006-02-03 22:19:41 +00:00
user_info - > domain ) ) ;
2003-07-03 14:36:42 +00:00
return NT_STATUS_NOT_IMPLEMENTED ;
}
2001-11-24 12:16:27 +00:00
/* Send off request */
2008-02-04 18:18:36 +01:00
params . account_name = user_info - > smb_name ;
params . domain_name = user_info - > domain ;
params . workstation_name = user_info - > wksta_name ;
2001-11-24 12:16:27 +00:00
2008-02-04 18:18:36 +01:00
params . flags = 0 ;
params . parameter_control = user_info - > logon_parameters ;
2001-11-24 12:16:27 +00:00
2008-02-04 18:18:36 +01:00
params . level = WBC_AUTH_USER_LEVEL_RESPONSE ;
2005-11-08 06:19:34 +00:00
2008-02-04 18:18:36 +01:00
memcpy ( params . password . response . challenge ,
auth_context - > challenge . data ,
sizeof ( params . password . response . challenge ) ) ;
2002-01-25 10:16:20 +00:00
2008-02-04 18:18:36 +01:00
params . password . response . nt_length = user_info - > nt_resp . length ;
params . password . response . nt_data = user_info - > nt_resp . data ;
params . password . response . lm_length = user_info - > lm_resp . length ;
params . password . response . lm_data = user_info - > lm_resp . data ;
2003-07-03 14:36:42 +00:00
/* we are contacting the privileged pipe */
become_root ( ) ;
2008-02-04 18:18:36 +01:00
wbc_status = wbcAuthenticateUserEx ( & params , & info , & err ) ;
2003-07-03 14:36:42 +00:00
unbecome_root ( ) ;
2001-11-24 12:16:27 +00:00
2008-03-26 01:25:57 +01:00
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
DEBUG ( 10 , ( " check_winbind_security: wbcAuthenticateUserEx failed: %s \n " ,
wbcErrorString ( wbc_status ) ) ) ;
}
2008-02-04 18:18:36 +01:00
if ( wbc_status = = WBC_ERR_NO_MEMORY ) {
return NT_STATUS_NO_MEMORY ;
}
if ( wbc_status = = WBC_ERR_WINBIND_NOT_AVAILABLE ) {
2006-08-20 17:55:06 +00:00
struct auth_methods * auth_method =
( struct auth_methods * ) my_private_data ;
2003-05-27 16:46:51 +00:00
if ( auth_method )
return auth_method - > auth ( auth_context , auth_method - > private_data ,
mem_ctx , user_info , server_info ) ;
else
/* log an error since this should not happen */
DEBUG ( 0 , ( " check_winbind_security: ERROR! my_private_data == NULL! \n " ) ) ;
2003-04-24 11:56:09 +00:00
}
2008-02-04 18:18:36 +01:00
if ( wbc_status = = WBC_ERR_AUTH_ERROR ) {
nt_status = NT_STATUS ( err - > nt_status ) ;
wbcFreeMemory ( err ) ;
return nt_status ;
}
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
return NT_STATUS_LOGON_FAILURE ;
}
nt_status = make_server_info_wbcAuthUserInfo ( mem_ctx ,
user_info - > smb_name ,
user_info - > domain ,
info , server_info ) ;
wbcFreeMemory ( info ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
2008-05-06 17:37:00 +02:00
( * server_info ) - > nss_token | = user_info - > was_mapped ;
2001-11-24 12:16:27 +00:00
return nt_status ;
}
2002-01-05 04:55:41 +00:00
/* module initialisation */
2003-06-04 16:40:50 +00:00
static NTSTATUS auth_init_winbind ( struct auth_context * auth_context , const char * param , auth_methods * * auth_method )
2001-11-24 12:16:27 +00:00
{
2003-05-26 16:38:35 +00:00
if ( ! make_auth_methods ( auth_context , auth_method ) ) {
return NT_STATUS_NO_MEMORY ;
}
2001-11-24 12:16:27 +00:00
2002-07-15 10:35:28 +00:00
( * auth_method ) - > name = " winbind " ;
2001-11-24 12:16:27 +00:00
( * auth_method ) - > auth = check_winbind_security ;
2003-04-24 11:56:09 +00:00
if ( param & & * param ) {
/* we load the 'fallback' module - if winbind isn't here, call this
module */
2006-09-19 01:25:52 +00:00
auth_methods * priv ;
if ( ! load_auth_module ( auth_context , param , & priv ) ) {
2003-04-24 11:56:09 +00:00
return NT_STATUS_UNSUCCESSFUL ;
}
2006-09-19 01:25:52 +00:00
( * auth_method ) - > private_data = ( void * ) priv ;
2003-04-24 11:56:09 +00:00
}
2002-07-15 10:35:28 +00:00
return NT_STATUS_OK ;
2001-11-24 12:16:27 +00:00
}
2003-04-16 12:13:07 +00:00
2003-04-28 17:48:48 +00:00
NTSTATUS auth_winbind_init ( void )
2003-04-16 12:13:07 +00:00
{
2003-04-28 17:48:48 +00:00
return smb_register_auth ( AUTH_INTERFACE_VERSION , " winbind " , auth_init_winbind ) ;
2003-04-16 12:13:07 +00:00
}