2005-09-22 18:35:08 +00:00
/*
Unix SMB / CIFS implementation .
Main winbindd samba3 server routines
Copyright ( C ) Stefan Metzmacher 2005
Copyright ( C ) Volker Lendecke 2005
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 Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
# include "smbd/service_stream.h"
# include "nsswitch/winbind_nss_config.h"
# include "nsswitch/winbindd_nss.h"
# include "winbind/wb_server.h"
# include "winbind/wb_samba3_protocol.h"
2005-09-25 21:01:56 +00:00
# include "winbind/wb_async_helpers.h"
# include "librpc/gen_ndr/nbt.h"
# include "libcli/raw/libcliraw.h"
# include "libcli/composite/composite.h"
2005-10-01 16:36:04 +00:00
# include "libcli/smb_composite/smb_composite.h"
2005-09-26 13:42:42 +00:00
# include "include/version.h"
2005-09-22 18:35:08 +00:00
NTSTATUS wbsrv_samba3_interface_version ( struct wbsrv_samba3_call * s3call )
{
s3call - > response . result = WINBINDD_OK ;
s3call - > response . data . interface_version = WINBIND_INTERFACE_VERSION ;
return NT_STATUS_OK ;
}
2005-09-26 13:42:42 +00:00
NTSTATUS wbsrv_samba3_info ( struct wbsrv_samba3_call * s3call )
{
s3call - > response . result = WINBINDD_OK ;
s3call - > response . data . info . winbind_separator = * lp_winbind_separator ( ) ;
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . info . samba_version , SAMBA_VERSION_STRING ) ;
return NT_STATUS_OK ;
}
NTSTATUS wbsrv_samba3_domain_name ( struct wbsrv_samba3_call * s3call )
{
s3call - > response . result = WINBINDD_OK ;
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . domain_name , lp_workgroup ( ) ) ;
return NT_STATUS_OK ;
}
NTSTATUS wbsrv_samba3_netbios_name ( struct wbsrv_samba3_call * s3call )
{
s3call - > response . result = WINBINDD_OK ;
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . netbios_name , lp_netbios_name ( ) ) ;
return NT_STATUS_OK ;
}
2005-09-22 18:35:08 +00:00
NTSTATUS wbsrv_samba3_priv_pipe_dir ( struct wbsrv_samba3_call * s3call )
{
s3call - > response . result = WINBINDD_OK ;
s3call - > response . extra_data = smbd_tmp_path ( s3call ,
WINBINDD_SAMBA3_PRIVILEGED_SOCKET ) ;
NT_STATUS_HAVE_NO_MEMORY ( s3call - > response . extra_data ) ;
return NT_STATUS_OK ;
}
NTSTATUS wbsrv_samba3_ping ( struct wbsrv_samba3_call * s3call )
{
s3call - > response . result = WINBINDD_OK ;
return NT_STATUS_OK ;
}
2005-09-25 21:01:56 +00:00
struct check_machacc_state {
struct wb_finddcs * io ;
2005-10-01 16:36:04 +00:00
struct smb_composite_connect * conn ;
2005-09-25 21:01:56 +00:00
} ;
2005-10-01 16:36:04 +00:00
static void wbsrv_samba3_check_machacc_receive_tree ( struct composite_context * action )
2005-09-25 21:01:56 +00:00
{
struct wbsrv_samba3_call * s3call =
2005-09-26 11:47:55 +00:00
talloc_get_type ( action - > async . private_data ,
2005-09-25 21:01:56 +00:00
struct wbsrv_samba3_call ) ;
struct check_machacc_state * state =
talloc_get_type ( s3call - > private_data ,
struct check_machacc_state ) ;
NTSTATUS status ;
2005-10-01 16:36:04 +00:00
status = smb_composite_connect_recv ( action , state ) ;
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . auth . nt_status_string ,
nt_errstr ( status ) ) ;
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . auth . error_string ,
nt_errstr ( status ) ) ;
s3call - > response . data . auth . pam_error = nt_status_to_pam ( status ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 5 , ( " Connect failed: %s \n " , nt_errstr ( status ) ) ) ;
goto done ;
}
s3call - > response . result = WINBINDD_OK ;
done :
if ( ! NT_STATUS_IS_OK ( status ) ) {
s3call - > response . result = WINBINDD_ERROR ;
}
status = wbsrv_send_reply ( s3call - > call ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
wbsrv_terminate_connection ( s3call - > call - > wbconn ,
" wbsrv_queue_reply() failed " ) ;
return ;
}
}
static void wbsrv_samba3_check_machacc_receive_dcs ( struct composite_context * action )
{
struct wbsrv_samba3_call * s3call =
talloc_get_type ( action - > async . private_data ,
struct wbsrv_samba3_call ) ;
struct check_machacc_state * state =
talloc_get_type ( s3call - > private_data ,
struct check_machacc_state ) ;
struct composite_context * ctx ;
NTSTATUS status ;
2005-09-25 21:01:56 +00:00
status = wb_finddcs_recv ( action , s3call ) ;
2005-09-26 13:02:47 +00:00
s3call - > response . data . auth . nt_status = NT_STATUS_V ( status ) ;
2005-10-01 16:36:04 +00:00
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . auth . nt_status_string ,
nt_errstr ( status ) ) ;
WBSRV_SAMBA3_SET_STRING ( s3call - > response . data . auth . error_string ,
nt_errstr ( status ) ) ;
2005-09-26 13:02:47 +00:00
s3call - > response . data . auth . pam_error = nt_status_to_pam ( status ) ;
2005-10-01 16:36:04 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
state - > conn = talloc ( state , struct smb_composite_connect ) ;
if ( state - > conn = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto done ;
}
state - > conn - > in . dest_host = state - > io - > out . dcs [ 0 ] . address ;
state - > conn - > in . port = 0 ;
state - > conn - > in . called_name = state - > io - > out . dcs [ 0 ] . name ;
state - > conn - > in . service = " IPC$ " ;
state - > conn - > in . service_type = " IPC " ;
state - > conn - > in . workgroup = lp_workgroup ( ) ;
state - > conn - > in . credentials = cli_credentials_init ( state - > conn ) ;
if ( state - > conn - > in . credentials = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto done ;
}
cli_credentials_set_conf ( state - > conn - > in . credentials ) ;
cli_credentials_set_anonymous ( state - > conn - > in . credentials ) ;
2005-10-02 10:02:35 +00:00
ctx = smb_composite_connect_send ( state - > conn , state ,
s3call - > call - > event_ctx ) ;
2005-10-01 16:36:04 +00:00
if ( ctx = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto done ;
}
ctx - > async . fn = wbsrv_samba3_check_machacc_receive_tree ;
ctx - > async . private_data = s3call ;
return ;
done :
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-09-25 21:01:56 +00:00
s3call - > response . result = WINBINDD_ERROR ;
}
status = wbsrv_send_reply ( s3call - > call ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
wbsrv_terminate_connection ( s3call - > call - > wbconn ,
" wbsrv_queue_reply() failed " ) ;
return ;
}
}
NTSTATUS wbsrv_samba3_check_machacc ( struct wbsrv_samba3_call * s3call )
{
struct composite_context * resolve_req ;
struct check_machacc_state * state ;
DEBUG ( 5 , ( " check_machacc called \n " ) ) ;
state = talloc ( s3call , struct check_machacc_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
state - > io = talloc ( s3call , struct wb_finddcs ) ;
NT_STATUS_HAVE_NO_MEMORY ( state - > io ) ;
s3call - > private_data = state ;
state - > io - > in . msg_ctx = s3call - > call - > wbconn - > conn - > msg_ctx ;
state - > io - > in . domain = lp_workgroup ( ) ;
resolve_req = wb_finddcs_send ( state - > io , s3call - > call - > event_ctx ) ;
NT_STATUS_HAVE_NO_MEMORY ( resolve_req ) ;
/* setup the callbacks */
2005-10-01 16:36:04 +00:00
resolve_req - > async . fn = wbsrv_samba3_check_machacc_receive_dcs ;
2005-09-26 11:47:55 +00:00
resolve_req - > async . private_data = s3call ;
2005-09-25 21:01:56 +00:00
/* tell the caller we reply later */
s3call - > call - > flags | = WBSRV_CALL_FLAGS_REPLY_ASYNC ;
return NT_STATUS_OK ;
}