2005-10-15 22:01:15 +00:00
/*
Unix SMB / CIFS implementation .
2007-05-25 08:04:39 +00:00
Connect to the SAMR pipe , and return connection and domain handles .
2005-10-15 22:01:15 +00:00
Copyright ( C ) Volker Lendecke 2005
2007-05-25 08:04:39 +00:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2007
2005-10-15 22:01:15 +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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-10-15 22:01:15 +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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-10-15 22:01:15 +00:00
*/
# include "includes.h"
# include "libcli/composite/composite.h"
2006-04-02 12:02:01 +00:00
# include "libcli/security/security.h"
2006-03-14 23:35:30 +00:00
# include "librpc/gen_ndr/ndr_samr_c.h"
2007-05-25 08:04:39 +00:00
# include "winbind/wb_server.h"
2005-10-15 22:01:15 +00:00
/* Helper to initialize SAMR with a specific auth methods. Verify by opening
* the SAM handle */
struct connect_samr_state {
struct composite_context * ctx ;
struct dom_sid * sid ;
struct dcerpc_pipe * samr_pipe ;
struct policy_handle * connect_handle ;
struct policy_handle * domain_handle ;
struct samr_Connect2 c ;
struct samr_OpenDomain o ;
} ;
static void connect_samr_recv_pipe ( struct composite_context * ctx ) ;
2010-03-10 10:02:50 +01:00
static void connect_samr_recv_conn ( struct tevent_req * subreq ) ;
static void connect_samr_recv_open ( struct tevent_req * subreq ) ;
2005-10-15 22:01:15 +00:00
2007-05-25 08:04:39 +00:00
struct composite_context * wb_connect_samr_send ( TALLOC_CTX * mem_ctx ,
struct wbsrv_domain * domain )
2005-10-15 22:01:15 +00:00
{
struct composite_context * result , * ctx ;
struct connect_samr_state * state ;
2007-05-25 08:04:39 +00:00
result = composite_create ( mem_ctx , domain - > netlogon_pipe - > conn - > event_ctx ) ;
2005-10-15 22:01:15 +00:00
if ( result = = NULL ) goto failed ;
state = talloc ( result , struct connect_samr_state ) ;
if ( state = = NULL ) goto failed ;
state - > ctx = result ;
result - > private_data = state ;
2007-05-25 08:04:39 +00:00
state - > sid = dom_sid_dup ( state , domain - > info - > sid ) ;
2005-10-15 22:01:15 +00:00
if ( state - > sid = = NULL ) goto failed ;
2007-05-25 08:04:39 +00:00
/* this will make the secondary connection on the same IPC$ share,
secured with SPNEGO , NTLMSSP or SCHANNEL */
2007-07-16 11:27:29 +00:00
ctx = dcerpc_secondary_auth_connection_send ( domain - > netlogon_pipe ,
domain - > samr_binding ,
2007-08-19 21:23:03 +00:00
& ndr_table_samr ,
2007-12-07 02:37:04 +01:00
domain - > libnet_ctx - > cred ,
domain - > libnet_ctx - > lp_ctx ) ;
2007-05-25 08:04:39 +00:00
composite_continue ( state - > ctx , ctx , connect_samr_recv_pipe , state ) ;
2005-10-15 22:01:15 +00:00
return result ;
failed :
talloc_free ( result ) ;
return NULL ;
}
static void connect_samr_recv_pipe ( struct composite_context * ctx )
{
2005-11-20 17:34:56 +00:00
struct connect_samr_state * state =
talloc_get_type ( ctx - > async . private_data ,
struct connect_samr_state ) ;
2010-03-10 10:02:50 +01:00
struct tevent_req * subreq ;
2005-11-20 17:34:56 +00:00
2007-07-16 11:27:29 +00:00
state - > ctx - > status = dcerpc_secondary_auth_connection_recv ( ctx , state ,
& state - > samr_pipe ) ;
2005-11-20 17:34:56 +00:00
if ( ! composite_is_ok ( state - > ctx ) ) return ;
2005-10-15 22:01:15 +00:00
state - > connect_handle = talloc ( state , struct policy_handle ) ;
if ( composite_nomem ( state - > connect_handle , state - > ctx ) ) return ;
state - > c . in . system_name =
talloc_asprintf ( state , " \\ \\ %s " ,
dcerpc_server_name ( state - > samr_pipe ) ) ;
state - > c . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
state - > c . out . connect_handle = state - > connect_handle ;
2010-03-10 10:02:50 +01:00
subreq = dcerpc_samr_Connect2_r_send ( state ,
state - > ctx - > event_ctx ,
state - > samr_pipe - > binding_handle ,
& state - > c ) ;
if ( composite_nomem ( subreq , state - > ctx ) ) return ;
tevent_req_set_callback ( subreq , connect_samr_recv_conn , state ) ;
2005-10-15 22:01:15 +00:00
}
2010-03-10 10:02:50 +01:00
static void connect_samr_recv_conn ( struct tevent_req * subreq )
2005-10-15 22:01:15 +00:00
{
struct connect_samr_state * state =
2010-03-10 10:02:50 +01:00
tevent_req_callback_data ( subreq ,
struct connect_samr_state ) ;
2005-10-15 22:01:15 +00:00
2010-03-10 10:02:50 +01:00
state - > ctx - > status = dcerpc_samr_Connect2_r_recv ( subreq , state ) ;
TALLOC_FREE ( subreq ) ;
2005-10-15 22:01:15 +00:00
if ( ! composite_is_ok ( state - > ctx ) ) return ;
state - > ctx - > status = state - > c . out . result ;
if ( ! composite_is_ok ( state - > ctx ) ) return ;
state - > domain_handle = talloc ( state , struct policy_handle ) ;
if ( composite_nomem ( state - > domain_handle , state - > ctx ) ) return ;
state - > o . in . connect_handle = state - > connect_handle ;
state - > o . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
state - > o . in . sid = state - > sid ;
state - > o . out . domain_handle = state - > domain_handle ;
2010-03-10 10:02:50 +01:00
subreq = dcerpc_samr_OpenDomain_r_send ( state ,
state - > ctx - > event_ctx ,
state - > samr_pipe - > binding_handle ,
& state - > o ) ;
if ( composite_nomem ( subreq , state - > ctx ) ) return ;
tevent_req_set_callback ( subreq , connect_samr_recv_open , state ) ;
2005-10-15 22:01:15 +00:00
}
2010-03-10 10:02:50 +01:00
static void connect_samr_recv_open ( struct tevent_req * subreq )
2005-10-15 22:01:15 +00:00
{
struct connect_samr_state * state =
2010-03-10 10:02:50 +01:00
tevent_req_callback_data ( subreq ,
struct connect_samr_state ) ;
2005-10-15 22:01:15 +00:00
2010-03-10 10:02:50 +01:00
state - > ctx - > status = dcerpc_samr_OpenDomain_r_recv ( subreq , state ) ;
TALLOC_FREE ( subreq ) ;
2005-10-15 22:01:15 +00:00
if ( ! composite_is_ok ( state - > ctx ) ) return ;
state - > ctx - > status = state - > o . out . result ;
if ( ! composite_is_ok ( state - > ctx ) ) return ;
composite_done ( state - > ctx ) ;
}
2007-05-25 08:04:39 +00:00
NTSTATUS wb_connect_samr_recv ( struct composite_context * c ,
2005-10-15 22:01:15 +00:00
TALLOC_CTX * mem_ctx ,
struct dcerpc_pipe * * samr_pipe ,
2007-07-23 02:56:51 +00:00
struct policy_handle * connect_handle ,
struct policy_handle * domain_handle )
2005-10-15 22:01:15 +00:00
{
NTSTATUS status = composite_wait ( c ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
struct connect_samr_state * state =
talloc_get_type ( c - > private_data ,
struct connect_samr_state ) ;
* samr_pipe = talloc_steal ( mem_ctx , state - > samr_pipe ) ;
2007-07-23 02:56:51 +00:00
* connect_handle = * state - > connect_handle ;
* domain_handle = * state - > domain_handle ;
2005-10-15 22:01:15 +00:00
}
talloc_free ( c ) ;
return status ;
}