2004-08-16 20:52:57 +04:00
/*
Unix SMB / CIFS implementation .
2005-07-03 21:17:32 +04:00
Copyright ( C ) Stefan Metzmacher 2004
Copyright ( C ) Rafal Szczesniak 2005
2004-08-16 20:52:57 +04: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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2004-08-16 20:52:57 +04: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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-08-16 20:52:57 +04:00
*/
# include "includes.h"
2004-11-02 14:42:35 +03:00
# include "libnet/libnet.h"
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
# include "libcli/libcli.h"
2006-03-19 17:24:54 +03:00
# include "libcli/composite/composite.h"
2008-04-02 06:53:27 +04:00
# include "librpc/rpc/dcerpc_proto.h"
2006-03-15 02:35:30 +03:00
# include "librpc/gen_ndr/ndr_lsa_c.h"
2006-05-16 01:49:27 +04:00
# include "librpc/gen_ndr/ndr_samr.h"
2005-02-07 02:06:27 +03:00
2006-03-19 17:24:54 +03:00
struct rpc_connect_srv_state {
2006-07-14 02:13:47 +04:00
struct libnet_context * ctx ;
2006-03-19 17:24:54 +03:00
struct libnet_RpcConnect r ;
const char * binding ;
2007-07-19 01:24:37 +04:00
/* information about the progress */
void ( * monitor_fn ) ( struct monitor_msg * ) ;
2006-03-19 17:24:54 +03:00
} ;
static void continue_pipe_connect ( struct composite_context * ctx ) ;
2005-02-07 02:06:27 +03:00
/**
2006-03-19 17:24:54 +03:00
* Initiates connection to rpc pipe on remote server
2005-02-07 02:06:27 +03:00
*
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
2006-03-21 00:44:29 +03:00
* @ return composite context of this call
2005-02-07 02:06:27 +03:00
* */
2006-03-19 17:24:54 +03:00
static struct composite_context * libnet_RpcConnectSrv_send ( struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
2007-07-19 01:24:37 +04:00
struct libnet_RpcConnect * r ,
void ( * monitor ) ( struct monitor_msg * ) )
2004-08-19 17:32:06 +04:00
{
2006-03-19 17:24:54 +03:00
struct composite_context * c ;
struct rpc_connect_srv_state * s ;
2006-10-13 17:01:48 +04:00
struct dcerpc_binding * b ;
2006-03-19 17:24:54 +03:00
struct composite_context * pipe_connect_req ;
2006-03-21 00:44:29 +03:00
/* composite context allocation and setup */
2007-05-04 22:59:51 +04:00
c = composite_create ( ctx , ctx - > event_ctx ) ;
if ( c = = NULL ) return c ;
2006-03-19 17:24:54 +03:00
s = talloc_zero ( c , struct rpc_connect_srv_state ) ;
if ( composite_nomem ( s , c ) ) return c ;
c - > private_data = s ;
2007-07-19 01:24:37 +04:00
s - > monitor_fn = monitor ;
2006-03-19 17:24:54 +03:00
2006-07-14 02:13:47 +04:00
s - > ctx = ctx ;
2006-03-19 17:24:54 +03:00
s - > r = * r ;
2006-05-24 15:46:19 +04:00
ZERO_STRUCT ( s - > r . out ) ;
2005-11-21 01:00:47 +03:00
/* prepare binding string */
2005-09-25 16:26:07 +04:00
switch ( r - > level ) {
case LIBNET_RPC_CONNECT_SERVER :
2006-03-19 17:24:54 +03:00
s - > binding = talloc_asprintf ( s , " ncacn_np:%s " , r - > in . name ) ;
2005-09-25 16:26:07 +04:00
break ;
2006-10-13 17:01:48 +04:00
case LIBNET_RPC_CONNECT_SERVER_ADDRESS :
s - > binding = talloc_asprintf ( s , " ncacn_np:%s " , r - > in . address ) ;
break ;
2005-11-21 01:00:47 +03:00
2005-09-25 16:26:07 +04:00
case LIBNET_RPC_CONNECT_BINDING :
2006-03-19 17:24:54 +03:00
s - > binding = talloc_strdup ( s , r - > in . binding ) ;
2005-09-25 16:26:07 +04:00
break ;
2006-05-07 16:51:53 +04:00
2006-10-13 17:01:48 +04:00
case LIBNET_RPC_CONNECT_DC :
case LIBNET_RPC_CONNECT_PDC :
/* this should never happen - DC and PDC level has a separate
composite function */
2006-05-07 16:51:53 +04:00
case LIBNET_RPC_CONNECT_DC_INFO :
/* this should never happen - DC_INFO level has a separate
composite function */
composite_error ( c , NT_STATUS_INVALID_LEVEL ) ;
return c ;
2005-09-25 16:26:07 +04:00
}
2004-08-25 13:22:47 +04:00
2006-10-13 17:01:48 +04:00
/* parse binding string to the structure */
c - > status = dcerpc_parse_binding ( c , s - > binding , & b ) ;
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
DEBUG ( 0 , ( " Failed to parse dcerpc binding '%s' \n " , s - > binding ) ) ;
composite_error ( c , c - > status ) ;
return c ;
}
2009-06-18 06:33:46 +04:00
switch ( r - > level ) {
case LIBNET_RPC_CONNECT_SERVER :
case LIBNET_RPC_CONNECT_SERVER_ADDRESS :
b - > flags = r - > in . dcerpc_flags ;
2011-06-08 20:58:45 +04:00
break ;
default :
/* other types have already been checked before */
break ;
2009-06-18 06:33:46 +04:00
}
2010-09-15 03:53:29 +04:00
if ( DEBUGLEVEL > = 10 ) {
b - > flags | = DCERPC_DEBUG_PRINT_BOTH ;
}
2006-10-13 17:01:48 +04:00
if ( r - > level = = LIBNET_RPC_CONNECT_SERVER_ADDRESS ) {
2009-07-15 14:06:12 +04:00
b - > target_hostname = talloc_strdup ( b , r - > in . name ) ;
2006-10-13 17:01:48 +04:00
if ( composite_nomem ( b - > target_hostname , c ) ) {
return c ;
}
}
2005-11-21 01:00:47 +03:00
/* connect to remote dcerpc pipe */
2006-10-13 17:01:48 +04:00
pipe_connect_req = dcerpc_pipe_connect_b_send ( c , b , r - > in . dcerpc_iface ,
2007-12-07 04:37:04 +03:00
ctx - > cred , c - > event_ctx ,
ctx - > lp_ctx ) ;
2006-03-19 17:24:54 +03:00
if ( composite_nomem ( pipe_connect_req , c ) ) return c ;
2004-08-25 13:22:47 +04:00
2006-03-19 17:24:54 +03:00
composite_continue ( c , pipe_connect_req , continue_pipe_connect , c ) ;
return c ;
}
2004-08-25 13:22:47 +04:00
2006-03-19 17:24:54 +03:00
2006-03-21 00:44:29 +03:00
/*
Step 2 of RpcConnectSrv - get rpc connection
*/
2006-03-19 17:24:54 +03:00
static void continue_pipe_connect ( struct composite_context * ctx )
{
struct composite_context * c ;
struct rpc_connect_srv_state * s ;
c = talloc_get_type ( ctx - > async . private_data , struct composite_context ) ;
s = talloc_get_type ( c - > private_data , struct rpc_connect_srv_state ) ;
2006-03-21 00:44:29 +03:00
/* receive result of rpc pipe connection */
2006-10-13 17:01:48 +04:00
c - > status = dcerpc_pipe_connect_b_recv ( ctx , c , & s - > r . out . dcerpc_pipe ) ;
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
struct msg_net_rpc_connect data ;
struct dcerpc_binding * binding = s - > r . out . dcerpc_pipe - > binding ;
/* prepare monitor message and post it */
data . host = binding - > host ;
data . endpoint = binding - > endpoint ;
data . transport = binding - > transport ;
data . domain_name = binding - > target_hostname ;
2007-07-26 03:17:02 +04:00
msg . type = mon_NetRpcConnect ;
2007-07-19 01:24:37 +04:00
msg . data = ( void * ) & data ;
msg . data_size = sizeof ( data ) ;
s - > monitor_fn ( & msg ) ;
}
2006-07-14 02:13:47 +04:00
2007-07-19 01:24:37 +04:00
composite_done ( c ) ;
2004-08-25 13:22:47 +04:00
}
2005-02-07 02:06:27 +03:00
/**
2006-03-19 17:24:54 +03:00
* Receives result of connection to rpc pipe on remote server
*
* @ param c composite context
2005-02-07 02:06:27 +03:00
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
2006-03-19 17:24:54 +03:00
* @ return nt status of rpc connection
2005-02-07 02:06:27 +03:00
* */
2006-03-19 17:24:54 +03:00
static NTSTATUS libnet_RpcConnectSrv_recv ( struct composite_context * c ,
struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
struct libnet_RpcConnect * r )
2004-08-25 13:22:47 +04:00
{
2006-05-24 15:46:19 +04:00
NTSTATUS status ;
struct rpc_connect_srv_state * s = talloc_get_type ( c - > private_data ,
struct rpc_connect_srv_state ) ;
2006-03-19 17:24:54 +03:00
2006-05-24 15:46:19 +04:00
status = composite_wait ( c ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2006-03-21 00:44:29 +03:00
/* move the returned rpc pipe between memory contexts */
2006-03-19 17:24:54 +03:00
s = talloc_get_type ( c - > private_data , struct rpc_connect_srv_state ) ;
r - > out . dcerpc_pipe = talloc_steal ( mem_ctx , s - > r . out . dcerpc_pipe ) ;
2006-05-16 01:49:27 +04:00
/* reference created pipe structure to long-term libnet_context
so that it can be used by other api functions even after short - term
mem_ctx is freed */
2007-08-20 01:23:03 +04:00
if ( r - > in . dcerpc_iface = = & ndr_table_samr ) {
2006-08-22 00:52:14 +04:00
ctx - > samr . pipe = talloc_reference ( ctx , r - > out . dcerpc_pipe ) ;
2006-06-30 00:34:45 +04:00
2007-08-20 01:23:03 +04:00
} else if ( r - > in . dcerpc_iface = = & ndr_table_lsarpc ) {
2006-08-22 00:52:14 +04:00
ctx - > lsa . pipe = talloc_reference ( ctx , r - > out . dcerpc_pipe ) ;
2006-05-16 01:49:27 +04:00
}
2006-11-07 01:06:12 +03:00
r - > out . error_string = talloc_strdup ( mem_ctx , " Success " ) ;
2006-05-24 15:46:19 +04:00
} else {
2006-11-07 01:06:12 +03:00
r - > out . error_string = talloc_asprintf ( mem_ctx , " Error: %s " , nt_errstr ( status ) ) ;
2006-03-19 17:24:54 +03:00
}
talloc_free ( c ) ;
return status ;
}
struct rpc_connect_dc_state {
struct libnet_context * ctx ;
struct libnet_RpcConnect r ;
2005-07-02 18:28:15 +04:00
struct libnet_RpcConnect r2 ;
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
struct libnet_LookupDCs f ;
const char * connect_name ;
2006-07-14 02:13:47 +04:00
/* information about the progress */
void ( * monitor_fn ) ( struct monitor_msg * ) ;
2006-03-19 17:24:54 +03:00
} ;
2010-09-13 10:37:10 +04:00
static void continue_lookup_dc ( struct tevent_req * req ) ;
2006-03-19 17:24:54 +03:00
static void continue_rpc_connect ( struct composite_context * ctx ) ;
/**
* Initiates connection to rpc pipe on domain pdc
*
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
* @ return composite context of this call
* */
static struct composite_context * libnet_RpcConnectDC_send ( struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
2007-07-19 01:24:37 +04:00
struct libnet_RpcConnect * r ,
void ( * monitor ) ( struct monitor_msg * msg ) )
2006-03-19 17:24:54 +03:00
{
struct composite_context * c ;
struct rpc_connect_dc_state * s ;
2010-09-13 10:37:10 +04:00
struct tevent_req * lookup_dc_req ;
2006-03-19 17:24:54 +03:00
2006-03-21 00:44:29 +03:00
/* composite context allocation and setup */
2007-05-04 22:59:51 +04:00
c = composite_create ( ctx , ctx - > event_ctx ) ;
if ( c = = NULL ) return c ;
2006-03-19 17:24:54 +03:00
s = talloc_zero ( c , struct rpc_connect_dc_state ) ;
if ( composite_nomem ( s , c ) ) return c ;
c - > private_data = s ;
2007-07-19 01:24:37 +04:00
s - > monitor_fn = monitor ;
2006-03-19 17:24:54 +03:00
s - > ctx = ctx ;
2006-05-24 15:46:19 +04:00
s - > r = * r ;
ZERO_STRUCT ( s - > r . out ) ;
2004-08-19 19:04:14 +04:00
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
switch ( r - > level ) {
case LIBNET_RPC_CONNECT_PDC :
2006-03-19 17:24:54 +03:00
s - > f . in . name_type = NBT_NAME_PDC ;
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
break ;
2006-03-19 17:24:54 +03:00
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
case LIBNET_RPC_CONNECT_DC :
2006-03-19 17:24:54 +03:00
s - > f . in . name_type = NBT_NAME_LOGON ;
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
break ;
2006-03-19 17:24:54 +03:00
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
default :
break ;
}
2006-07-14 02:13:47 +04:00
2006-03-19 17:24:54 +03:00
s - > f . in . domain_name = r - > in . name ;
s - > f . out . num_dcs = 0 ;
s - > f . out . dcs = NULL ;
2004-08-19 17:32:06 +04:00
2005-11-21 01:00:47 +03:00
/* find the domain pdc first */
2006-03-19 17:24:54 +03:00
lookup_dc_req = libnet_LookupDCs_send ( ctx , c , & s - > f ) ;
if ( composite_nomem ( lookup_dc_req , c ) ) return c ;
2010-09-13 10:37:10 +04:00
tevent_req_set_callback ( lookup_dc_req , continue_lookup_dc , c ) ;
2006-03-19 17:24:54 +03:00
return c ;
}
2006-03-21 00:44:29 +03:00
/*
2006-10-13 17:01:48 +04:00
Step 2 of RpcConnectDC : get domain controller name and
2006-03-21 00:44:29 +03:00
initiate RpcConnect to it
*/
2010-09-13 10:37:10 +04:00
static void continue_lookup_dc ( struct tevent_req * req )
2006-03-19 17:24:54 +03:00
{
struct composite_context * c ;
struct rpc_connect_dc_state * s ;
struct composite_context * rpc_connect_req ;
2006-07-14 02:13:47 +04:00
struct monitor_msg msg ;
struct msg_net_lookup_dc data ;
2010-09-13 10:37:10 +04:00
c = tevent_req_callback_data ( req , struct composite_context ) ;
s = talloc_get_type_abort ( c - > private_data , struct rpc_connect_dc_state ) ;
2006-03-19 17:24:54 +03:00
2006-03-21 00:44:29 +03:00
/* receive result of domain controller lookup */
2010-09-13 10:37:10 +04:00
c - > status = libnet_LookupDCs_recv ( req , c , & s - > f ) ;
2006-03-19 17:24:54 +03:00
if ( ! composite_is_ok ( c ) ) return ;
2004-08-19 17:32:06 +04:00
2006-07-14 02:13:47 +04:00
/* decide on preferred address type depending on DC type */
2006-10-13 17:01:48 +04:00
s - > connect_name = s - > f . out . dcs [ 0 ] . name ;
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
/* prepare a monitor message and post it */
data . domain_name = s - > f . in . domain_name ;
data . hostname = s - > f . out . dcs [ 0 ] . name ;
data . address = s - > f . out . dcs [ 0 ] . address ;
2007-07-26 03:17:02 +04:00
msg . type = mon_NetLookupDc ;
2007-07-19 01:24:37 +04:00
msg . data = & data ;
msg . data_size = sizeof ( data ) ;
s - > monitor_fn ( & msg ) ;
}
2006-07-14 02:13:47 +04:00
2005-11-21 01:00:47 +03:00
/* ok, pdc has been found so do attempt to rpc connect */
2006-10-13 17:01:48 +04:00
s - > r2 . level = LIBNET_RPC_CONNECT_SERVER_ADDRESS ;
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
2006-03-19 17:24:54 +03:00
/* this will cause yet another name resolution, but at least
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
* we pass the right name down the stack now */
2006-10-13 17:01:48 +04:00
s - > r2 . in . name = talloc_strdup ( s , s - > connect_name ) ;
s - > r2 . in . address = talloc_steal ( s , s - > f . out . dcs [ 0 ] . address ) ;
2006-03-19 17:24:54 +03:00
s - > r2 . in . dcerpc_iface = s - > r . in . dcerpc_iface ;
2009-06-18 06:33:46 +04:00
s - > r2 . in . dcerpc_flags = s - > r . in . dcerpc_flags ;
2004-08-19 17:32:06 +04:00
2006-03-21 00:44:29 +03:00
/* send rpc connect request to the server */
2007-07-19 01:24:37 +04:00
rpc_connect_req = libnet_RpcConnectSrv_send ( s - > ctx , c , & s - > r2 , s - > monitor_fn ) ;
2006-03-19 17:24:54 +03:00
if ( composite_nomem ( rpc_connect_req , c ) ) return ;
2005-07-02 18:28:15 +04:00
2006-03-19 17:24:54 +03:00
composite_continue ( c , rpc_connect_req , continue_rpc_connect , c ) ;
}
2006-03-21 00:44:29 +03:00
/*
Step 3 of RpcConnectDC : get rpc connection to the server
*/
2006-03-19 17:24:54 +03:00
static void continue_rpc_connect ( struct composite_context * ctx )
{
struct composite_context * c ;
struct rpc_connect_dc_state * s ;
c = talloc_get_type ( ctx - > async . private_data , struct composite_context ) ;
s = talloc_get_type ( c - > private_data , struct rpc_connect_dc_state ) ;
2006-07-14 02:13:47 +04:00
c - > status = libnet_RpcConnectSrv_recv ( ctx , s - > ctx , c , & s - > r2 ) ;
2006-03-19 17:24:54 +03:00
/* error string is to be passed anyway */
s - > r . out . error_string = s - > r2 . out . error_string ;
if ( ! composite_is_ok ( c ) ) return ;
s - > r . out . dcerpc_pipe = s - > r2 . out . dcerpc_pipe ;
2006-11-29 00:01:10 +03:00
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
struct msg_net_rpc_connect data ;
struct dcerpc_binding * binding = s - > r . out . dcerpc_pipe - > binding ;
data . host = binding - > host ;
data . endpoint = binding - > endpoint ;
data . transport = binding - > transport ;
data . domain_name = binding - > target_hostname ;
2007-07-26 03:17:02 +04:00
msg . type = mon_NetRpcConnect ;
2007-07-19 01:24:37 +04:00
msg . data = ( void * ) & data ;
msg . data_size = sizeof ( data ) ;
s - > monitor_fn ( & msg ) ;
}
2006-07-14 02:13:47 +04:00
2006-03-19 17:24:54 +03:00
composite_done ( c ) ;
}
/**
* Receives result of connection to rpc pipe on domain pdc
*
* @ param c composite context
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
* @ return nt status of rpc connection
* */
static NTSTATUS libnet_RpcConnectDC_recv ( struct composite_context * c ,
struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
struct libnet_RpcConnect * r )
{
NTSTATUS status ;
2006-05-24 15:46:19 +04:00
struct rpc_connect_dc_state * s = talloc_get_type ( c - > private_data ,
struct rpc_connect_dc_state ) ;
2006-03-19 17:24:54 +03:00
2006-05-24 15:46:19 +04:00
status = composite_wait ( c ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2009-07-01 09:13:49 +04:00
/* move connected rpc pipe between memory contexts
The use of talloc_reparent ( talloc_parent ( ) , . . . ) is
bizarre , but it is needed because of the absolutely
atrocious use of talloc in this code . We need to
force the original parent to change , but finding
the original parent is well nigh impossible at this
point in the code ( yes , I tried ) .
*/
r - > out . dcerpc_pipe = talloc_reparent ( talloc_parent ( s - > r . out . dcerpc_pipe ) ,
mem_ctx , s - > r . out . dcerpc_pipe ) ;
2006-05-16 01:49:27 +04:00
/* reference created pipe structure to long-term libnet_context
so that it can be used by other api functions even after short - term
mem_ctx is freed */
2007-08-20 01:23:03 +04:00
if ( r - > in . dcerpc_iface = = & ndr_table_samr ) {
2006-08-22 00:52:14 +04:00
ctx - > samr . pipe = talloc_reference ( ctx , r - > out . dcerpc_pipe ) ;
2006-06-30 00:34:45 +04:00
2007-08-20 01:23:03 +04:00
} else if ( r - > in . dcerpc_iface = = & ndr_table_lsarpc ) {
2006-08-22 00:52:14 +04:00
ctx - > lsa . pipe = talloc_reference ( ctx , r - > out . dcerpc_pipe ) ;
2006-05-16 01:49:27 +04:00
}
2006-06-30 00:34:45 +04:00
2006-05-24 15:46:19 +04:00
} else {
2006-08-22 00:52:14 +04:00
r - > out . error_string = talloc_asprintf ( mem_ctx ,
" Failed to rpc connect: %s " ,
nt_errstr ( status ) ) ;
2006-03-19 17:24:54 +03:00
}
2004-08-19 17:32:06 +04:00
2006-03-19 17:24:54 +03:00
talloc_free ( c ) ;
2004-08-19 17:32:06 +04:00
return status ;
}
2005-02-07 02:06:27 +03:00
2006-03-19 17:24:54 +03:00
2006-05-04 18:52:03 +04:00
struct rpc_connect_dci_state {
struct libnet_context * ctx ;
struct libnet_RpcConnect r ;
struct libnet_RpcConnect rpc_conn ;
struct policy_handle lsa_handle ;
2006-01-13 15:52:56 +03:00
struct lsa_QosInfo qos ;
2006-05-04 18:52:03 +04:00
struct lsa_ObjectAttribute attr ;
2006-01-13 15:52:56 +03:00
struct lsa_OpenPolicy2 lsa_open_policy ;
2006-05-04 18:52:03 +04:00
struct dcerpc_pipe * lsa_pipe ;
2006-01-13 15:52:56 +03:00
struct lsa_QueryInfoPolicy2 lsa_query_info2 ;
struct lsa_QueryInfoPolicy lsa_query_info ;
struct dcerpc_binding * final_binding ;
struct dcerpc_pipe * final_pipe ;
2007-07-19 01:24:37 +04:00
/* information about the progress */
void ( * monitor_fn ) ( struct monitor_msg * ) ;
2006-05-04 18:52:03 +04:00
} ;
2006-01-13 15:52:56 +03:00
2006-05-04 18:52:03 +04:00
static void continue_dci_rpc_connect ( struct composite_context * ctx ) ;
2010-03-10 11:53:36 +03:00
static void continue_lsa_policy ( struct tevent_req * subreq ) ;
static void continue_lsa_query_info ( struct tevent_req * subreq ) ;
static void continue_lsa_query_info2 ( struct tevent_req * subreq ) ;
2006-05-04 18:52:03 +04:00
static void continue_epm_map_binding ( struct composite_context * ctx ) ;
static void continue_secondary_conn ( struct composite_context * ctx ) ;
2006-11-17 08:17:32 +03:00
static void continue_epm_map_binding_send ( struct composite_context * c ) ;
2006-05-04 18:52:03 +04:00
2006-05-04 21:37:57 +04:00
/**
* Initiates connection to rpc pipe on remote server or pdc . Received result
* contains info on the domain name , domain sid and realm .
*
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values . Must be a talloc context
* @ return composite context of this call
* */
static struct composite_context * libnet_RpcConnectDCInfo_send ( struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
2007-07-19 01:24:37 +04:00
struct libnet_RpcConnect * r ,
void ( * monitor ) ( struct monitor_msg * ) )
2006-05-04 21:37:57 +04:00
{
struct composite_context * c , * conn_req ;
struct rpc_connect_dci_state * s ;
2006-05-07 16:51:53 +04:00
/* composite context allocation and setup */
2007-05-04 22:59:51 +04:00
c = composite_create ( ctx , ctx - > event_ctx ) ;
if ( c = = NULL ) return c ;
2006-05-04 21:37:57 +04:00
s = talloc_zero ( c , struct rpc_connect_dci_state ) ;
if ( composite_nomem ( s , c ) ) return c ;
c - > private_data = s ;
2007-07-19 01:24:37 +04:00
s - > monitor_fn = monitor ;
2006-05-04 21:37:57 +04:00
s - > ctx = ctx ;
2006-05-24 15:46:19 +04:00
s - > r = * r ;
ZERO_STRUCT ( s - > r . out ) ;
2006-05-04 21:37:57 +04:00
2009-06-18 06:33:46 +04:00
2006-05-04 21:37:57 +04:00
/* proceed to pure rpc connection if the binding string is provided,
otherwise try to connect domain controller */
if ( r - > in . binding = = NULL ) {
2009-06-18 06:33:46 +04:00
/* Pass on any binding flags (such as anonymous fallback) that have been set */
s - > rpc_conn . in . dcerpc_flags = r - > in . dcerpc_flags ;
s - > rpc_conn . in . name = r - > in . name ;
s - > rpc_conn . level = LIBNET_RPC_CONNECT_DC ;
2006-05-04 21:37:57 +04:00
} else {
2009-06-18 06:33:46 +04:00
s - > rpc_conn . in . binding = r - > in . binding ;
s - > rpc_conn . level = LIBNET_RPC_CONNECT_BINDING ;
2006-05-04 21:37:57 +04:00
}
2006-05-07 16:51:53 +04:00
/* we need to query information on lsarpc interface first */
2007-08-20 01:23:03 +04:00
s - > rpc_conn . in . dcerpc_iface = & ndr_table_lsarpc ;
2006-05-04 21:37:57 +04:00
/* request connection to the lsa pipe on the pdc */
2007-07-19 01:24:37 +04:00
conn_req = libnet_RpcConnect_send ( ctx , c , & s - > rpc_conn , s - > monitor_fn ) ;
2006-05-04 21:37:57 +04:00
if ( composite_nomem ( c , conn_req ) ) return c ;
composite_continue ( c , conn_req , continue_dci_rpc_connect , c ) ;
return c ;
}
/*
Step 2 of RpcConnectDCInfo : receive opened rpc pipe and open
lsa policy handle
*/
2006-05-04 18:52:03 +04:00
static void continue_dci_rpc_connect ( struct composite_context * ctx )
{
struct composite_context * c ;
struct rpc_connect_dci_state * s ;
2010-03-10 11:53:36 +03:00
struct tevent_req * subreq ;
2006-05-04 18:52:03 +04:00
c = talloc_get_type ( ctx - > async . private_data , struct composite_context ) ;
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
c - > status = libnet_RpcConnect_recv ( ctx , s - > ctx , c , & s - > rpc_conn ) ;
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
composite_error ( c , c - > status ) ;
return ;
2006-01-13 15:52:56 +03:00
}
2006-05-04 18:52:03 +04:00
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
struct msg_net_rpc_connect data ;
struct dcerpc_binding * binding = s - > r . out . dcerpc_pipe - > binding ;
data . host = binding - > host ;
data . endpoint = binding - > endpoint ;
data . transport = binding - > transport ;
data . domain_name = binding - > target_hostname ;
2007-07-26 03:17:02 +04:00
msg . type = mon_NetRpcConnect ;
2007-07-19 01:24:37 +04:00
msg . data = ( void * ) & data ;
msg . data_size = sizeof ( data ) ;
s - > monitor_fn ( & msg ) ;
}
2006-05-07 16:51:53 +04:00
/* prepare to open a policy handle on lsa pipe */
2006-08-22 00:52:14 +04:00
s - > lsa_pipe = s - > ctx - > lsa . pipe ;
2006-01-13 15:52:56 +03:00
2006-05-07 16:51:53 +04:00
s - > qos . len = 0 ;
2006-05-04 18:52:03 +04:00
s - > qos . impersonation_level = 2 ;
2006-05-07 16:51:53 +04:00
s - > qos . context_mode = 1 ;
s - > qos . effective_only = 0 ;
2006-05-04 18:52:03 +04:00
s - > attr . sec_qos = & s - > qos ;
2006-05-07 16:51:53 +04:00
s - > lsa_open_policy . in . attr = & s - > attr ;
2006-05-04 18:52:03 +04:00
s - > lsa_open_policy . in . system_name = talloc_asprintf ( c , " \\ " ) ;
if ( composite_nomem ( s - > lsa_open_policy . in . system_name , c ) ) return ;
s - > lsa_open_policy . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2006-05-07 16:51:53 +04:00
s - > lsa_open_policy . out . handle = & s - > lsa_handle ;
2006-05-04 18:52:03 +04:00
2010-03-10 11:53:36 +03:00
subreq = dcerpc_lsa_OpenPolicy2_r_send ( s , c - > event_ctx ,
s - > lsa_pipe - > binding_handle ,
& s - > lsa_open_policy ) ;
if ( composite_nomem ( subreq , c ) ) return ;
2006-05-04 18:52:03 +04:00
2010-03-10 11:53:36 +03:00
tevent_req_set_callback ( subreq , continue_lsa_policy , c ) ;
2006-05-04 18:52:03 +04:00
}
2006-05-04 21:37:57 +04:00
/*
Step 3 of RpcConnectDCInfo : Get policy handle and query lsa info
for kerberos realm ( dns name ) and guid . The query may fail .
*/
2010-03-10 11:53:36 +03:00
static void continue_lsa_policy ( struct tevent_req * subreq )
2006-05-04 18:52:03 +04:00
{
struct composite_context * c ;
struct rpc_connect_dci_state * s ;
2010-03-10 11:53:36 +03:00
c = tevent_req_callback_data ( subreq , struct composite_context ) ;
2006-05-04 18:52:03 +04:00
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
2010-03-10 11:53:36 +03:00
c - > status = dcerpc_lsa_OpenPolicy2_r_recv ( subreq , s ) ;
TALLOC_FREE ( subreq ) ;
2006-05-04 18:52:03 +04:00
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
composite_error ( c , c - > status ) ;
return ;
2006-01-13 15:52:56 +03:00
}
2006-11-17 08:17:32 +03:00
if ( NT_STATUS_EQUAL ( s - > lsa_open_policy . out . result , NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED ) ) {
s - > r . out . realm = NULL ;
s - > r . out . guid = NULL ;
s - > r . out . domain_name = NULL ;
s - > r . out . domain_sid = NULL ;
2007-07-19 01:24:37 +04:00
2006-11-17 08:17:32 +03:00
/* Skip to the creating the actual connection, no info available on this transport */
continue_epm_map_binding_send ( c ) ;
return ;
2007-07-19 01:24:37 +04:00
2006-11-17 08:17:32 +03:00
} else if ( ! NT_STATUS_IS_OK ( s - > lsa_open_policy . out . result ) ) {
composite_error ( c , s - > lsa_open_policy . out . result ) ;
2006-06-14 20:08:43 +04:00
return ;
}
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
2007-07-26 03:17:02 +04:00
msg . type = mon_LsaOpenPolicy ;
2007-07-19 01:24:37 +04:00
msg . data = NULL ;
msg . data_size = 0 ;
s - > monitor_fn ( & msg ) ;
}
2006-05-07 16:51:53 +04:00
/* query lsa info for dns domain name and guid */
2006-05-04 18:52:03 +04:00
s - > lsa_query_info2 . in . handle = & s - > lsa_handle ;
s - > lsa_query_info2 . in . level = LSA_POLICY_INFO_DNS ;
2008-10-24 17:05:57 +04:00
s - > lsa_query_info2 . out . info = talloc_zero ( c , union lsa_PolicyInformation * ) ;
if ( composite_nomem ( s - > lsa_query_info2 . out . info , c ) ) return ;
2006-01-13 15:52:56 +03:00
2010-03-10 11:53:36 +03:00
subreq = dcerpc_lsa_QueryInfoPolicy2_r_send ( s , c - > event_ctx ,
s - > lsa_pipe - > binding_handle ,
& s - > lsa_query_info2 ) ;
if ( composite_nomem ( subreq , c ) ) return ;
2006-01-13 15:52:56 +03:00
2010-03-10 11:53:36 +03:00
tevent_req_set_callback ( subreq , continue_lsa_query_info2 , c ) ;
2006-05-04 18:52:03 +04:00
}
2006-05-04 21:37:57 +04:00
/*
Step 4 of RpcConnectDCInfo : Get realm and guid if provided ( rpc call
may result in failure ) and query lsa info for domain name and sid .
*/
2010-03-10 11:53:36 +03:00
static void continue_lsa_query_info2 ( struct tevent_req * subreq )
2006-05-04 18:52:03 +04:00
{
struct composite_context * c ;
struct rpc_connect_dci_state * s ;
2010-03-10 11:53:36 +03:00
c = tevent_req_callback_data ( subreq , struct composite_context ) ;
2006-05-04 18:52:03 +04:00
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
2010-03-10 11:53:36 +03:00
c - > status = dcerpc_lsa_QueryInfoPolicy2_r_recv ( subreq , s ) ;
TALLOC_FREE ( subreq ) ;
2006-05-07 16:51:53 +04:00
/* In case of error just null the realm and guid and proceed
to the next step . After all , it doesn ' t have to be AD domain
controller we talking to - NT - style PDC also counts */
2010-04-15 19:19:19 +04:00
if ( NT_STATUS_EQUAL ( c - > status , NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE ) ) {
2006-05-04 18:52:03 +04:00
s - > r . out . realm = NULL ;
s - > r . out . guid = NULL ;
} else {
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
s - > r . out . error_string = talloc_asprintf ( c ,
" lsa_QueryInfoPolicy2 failed: %s " ,
nt_errstr ( c - > status ) ) ;
composite_error ( c , c - > status ) ;
return ;
2006-01-13 15:52:56 +03:00
}
2006-05-04 18:52:03 +04:00
2006-06-14 20:08:43 +04:00
if ( ! NT_STATUS_IS_OK ( s - > lsa_query_info2 . out . result ) ) {
s - > r . out . error_string = talloc_asprintf ( c ,
" lsa_QueryInfoPolicy2 failed: %s " ,
nt_errstr ( s - > lsa_query_info2 . out . result ) ) ;
composite_error ( c , s - > lsa_query_info2 . out . result ) ;
return ;
}
2006-05-07 16:51:53 +04:00
/* Copy the dns domain name and guid from the query result */
2006-05-04 18:52:03 +04:00
/* this should actually be a conversion from lsa_StringLarge */
2008-10-24 17:05:57 +04:00
s - > r . out . realm = ( * s - > lsa_query_info2 . out . info ) - > dns . dns_domain . string ;
2006-05-04 18:52:03 +04:00
s - > r . out . guid = talloc ( c , struct GUID ) ;
if ( composite_nomem ( s - > r . out . guid , c ) ) {
s - > r . out . error_string = NULL ;
return ;
2006-01-13 15:52:56 +03:00
}
2008-10-24 17:05:57 +04:00
* s - > r . out . guid = ( * s - > lsa_query_info2 . out . info ) - > dns . domain_guid ;
2006-01-13 15:52:56 +03:00
}
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
2007-07-26 03:17:02 +04:00
msg . type = mon_LsaQueryPolicy ;
2007-07-19 01:24:37 +04:00
msg . data = NULL ;
msg . data_size = 0 ;
s - > monitor_fn ( & msg ) ;
}
2006-05-07 16:51:53 +04:00
/* query lsa info for domain name and sid */
2006-05-04 18:52:03 +04:00
s - > lsa_query_info . in . handle = & s - > lsa_handle ;
s - > lsa_query_info . in . level = LSA_POLICY_INFO_DOMAIN ;
2008-10-24 17:05:57 +04:00
s - > lsa_query_info . out . info = talloc_zero ( c , union lsa_PolicyInformation * ) ;
if ( composite_nomem ( s - > lsa_query_info . out . info , c ) ) return ;
2006-05-04 18:52:03 +04:00
2010-03-10 11:53:36 +03:00
subreq = dcerpc_lsa_QueryInfoPolicy_r_send ( s , c - > event_ctx ,
s - > lsa_pipe - > binding_handle ,
& s - > lsa_query_info ) ;
if ( composite_nomem ( subreq , c ) ) return ;
2006-05-04 18:52:03 +04:00
2010-03-10 11:53:36 +03:00
tevent_req_set_callback ( subreq , continue_lsa_query_info , c ) ;
2006-05-04 18:52:03 +04:00
}
2006-05-04 21:37:57 +04:00
/*
2006-11-17 08:17:32 +03:00
Step 5 of RpcConnectDCInfo : Get domain name and sid
2006-05-04 21:37:57 +04:00
*/
2010-03-10 11:53:36 +03:00
static void continue_lsa_query_info ( struct tevent_req * subreq )
2006-05-04 18:52:03 +04:00
{
2006-11-17 08:17:32 +03:00
struct composite_context * c ;
2006-05-04 18:52:03 +04:00
struct rpc_connect_dci_state * s ;
2010-03-10 11:53:36 +03:00
c = tevent_req_callback_data ( subreq , struct composite_context ) ;
2006-05-04 18:52:03 +04:00
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
2010-03-10 11:53:36 +03:00
c - > status = dcerpc_lsa_QueryInfoPolicy_r_recv ( subreq , s ) ;
TALLOC_FREE ( subreq ) ;
2006-05-04 18:52:03 +04:00
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
s - > r . out . error_string = talloc_asprintf ( c ,
" lsa_QueryInfoPolicy failed: %s " ,
nt_errstr ( c - > status ) ) ;
composite_error ( c , c - > status ) ;
return ;
2006-01-13 15:52:56 +03:00
}
2006-05-04 18:52:03 +04:00
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
2007-07-26 03:17:02 +04:00
msg . type = mon_LsaQueryPolicy ;
2007-07-19 01:24:37 +04:00
msg . data = NULL ;
msg . data_size = 0 ;
s - > monitor_fn ( & msg ) ;
}
2006-05-07 16:51:53 +04:00
/* Copy the domain name and sid from the query result */
2008-10-24 17:05:57 +04:00
s - > r . out . domain_sid = ( * s - > lsa_query_info . out . info ) - > domain . sid ;
s - > r . out . domain_name = ( * s - > lsa_query_info . out . info ) - > domain . name . string ;
2006-05-04 18:52:03 +04:00
2006-11-17 08:17:32 +03:00
continue_epm_map_binding_send ( c ) ;
}
/*
Step 5 ( continued ) of RpcConnectDCInfo : request endpoint
map binding .
2007-07-19 01:24:37 +04:00
We may short - cut to this step if we don ' t support LSA OpenPolicy on this transport
2006-11-17 08:17:32 +03:00
*/
static void continue_epm_map_binding_send ( struct composite_context * c )
{
struct rpc_connect_dci_state * s ;
struct composite_context * epm_map_req ;
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
2006-05-07 16:51:53 +04:00
/* prepare to get endpoint mapping for the requested interface */
2010-10-02 06:05:30 +04:00
s - > final_binding = talloc_zero ( s , struct dcerpc_binding ) ;
2006-05-04 18:52:03 +04:00
if ( composite_nomem ( s - > final_binding , c ) ) return ;
* s - > final_binding = * s - > lsa_pipe - > binding ;
2006-01-13 15:52:56 +03:00
/* Ensure we keep hold of the member elements */
2006-10-13 17:01:48 +04:00
if ( composite_nomem ( talloc_reference ( s - > final_binding , s - > lsa_pipe - > binding ) , c ) ) return ;
2006-05-04 18:52:03 +04:00
epm_map_req = dcerpc_epm_map_binding_send ( c , s - > final_binding , s - > r . in . dcerpc_iface ,
2007-12-07 04:37:04 +03:00
s - > lsa_pipe - > conn - > event_ctx , s - > ctx - > lp_ctx ) ;
2006-05-04 18:52:03 +04:00
if ( composite_nomem ( epm_map_req , c ) ) return ;
composite_continue ( c , epm_map_req , continue_epm_map_binding , c ) ;
}
2006-05-04 21:37:57 +04:00
/*
Step 6 of RpcConnectDCInfo : Receive endpoint mapping and create secondary
2006-05-07 16:51:53 +04:00
rpc connection derived from already used pipe but connected to the requested
one ( as specified in libnet_RpcConnect structure )
2006-05-04 21:37:57 +04:00
*/
2006-05-04 18:52:03 +04:00
static void continue_epm_map_binding ( struct composite_context * ctx )
{
struct composite_context * c , * sec_conn_req ;
struct rpc_connect_dci_state * s ;
c = talloc_get_type ( ctx - > async . private_data , struct composite_context ) ;
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
c - > status = dcerpc_epm_map_binding_recv ( ctx ) ;
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
s - > r . out . error_string = talloc_asprintf ( c ,
" failed to map pipe with endpoint mapper - %s " ,
nt_errstr ( c - > status ) ) ;
composite_error ( c , c - > status ) ;
return ;
2006-01-13 15:52:56 +03:00
}
2006-05-07 16:51:53 +04:00
/* create secondary connection derived from lsa pipe */
2006-05-04 18:52:03 +04:00
sec_conn_req = dcerpc_secondary_connection_send ( s - > lsa_pipe , s - > final_binding ) ;
if ( composite_nomem ( sec_conn_req , c ) ) return ;
composite_continue ( c , sec_conn_req , continue_secondary_conn , c ) ;
}
2006-05-04 21:37:57 +04:00
/*
2006-11-17 08:17:32 +03:00
Step 7 of RpcConnectDCInfo : Get actual pipe to be returned
2006-05-04 21:37:57 +04:00
and complete this composite call
*/
2006-05-04 18:52:03 +04:00
static void continue_secondary_conn ( struct composite_context * ctx )
{
struct composite_context * c ;
struct rpc_connect_dci_state * s ;
c = talloc_get_type ( ctx - > async . private_data , struct composite_context ) ;
s = talloc_get_type ( c - > private_data , struct rpc_connect_dci_state ) ;
c - > status = dcerpc_secondary_connection_recv ( ctx , & s - > final_pipe ) ;
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
s - > r . out . error_string = talloc_asprintf ( c ,
" secondary connection failed: %s " ,
nt_errstr ( c - > status ) ) ;
composite_error ( c , c - > status ) ;
return ;
}
s - > r . out . dcerpc_pipe = s - > final_pipe ;
2007-07-19 01:24:37 +04:00
/* post monitor message */
if ( s - > monitor_fn ) {
struct monitor_msg msg ;
struct msg_net_rpc_connect data ;
struct dcerpc_binding * binding = s - > r . out . dcerpc_pipe - > binding ;
/* prepare monitor message and post it */
data . host = binding - > host ;
data . endpoint = binding - > endpoint ;
data . transport = binding - > transport ;
data . domain_name = binding - > target_hostname ;
2007-07-26 03:17:02 +04:00
msg . type = mon_NetRpcConnect ;
2007-07-19 01:24:37 +04:00
msg . data = ( void * ) & data ;
msg . data_size = sizeof ( data ) ;
s - > monitor_fn ( & msg ) ;
}
2006-05-04 18:52:03 +04:00
composite_done ( c ) ;
}
2006-05-04 21:37:57 +04:00
/**
* Receives result of connection to rpc pipe and gets basic
* domain info ( name , sid , realm , guid )
*
* @ param c composite context
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing return values
* @ return nt status of rpc connection
* */
2006-05-04 18:52:03 +04:00
2006-05-04 21:37:57 +04:00
static NTSTATUS libnet_RpcConnectDCInfo_recv ( struct composite_context * c , struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx , struct libnet_RpcConnect * r )
2006-05-04 18:52:03 +04:00
{
NTSTATUS status ;
2006-05-24 15:46:19 +04:00
struct rpc_connect_dci_state * s = talloc_get_type ( c - > private_data ,
struct rpc_connect_dci_state ) ;
2006-05-04 18:52:03 +04:00
status = composite_wait ( c ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
r - > out . realm = talloc_steal ( mem_ctx , s - > r . out . realm ) ;
2006-05-05 17:57:17 +04:00
r - > out . guid = talloc_steal ( mem_ctx , s - > r . out . guid ) ;
2006-05-04 18:52:03 +04:00
r - > out . domain_name = talloc_steal ( mem_ctx , s - > r . out . domain_name ) ;
2006-05-05 17:57:17 +04:00
r - > out . domain_sid = talloc_steal ( mem_ctx , s - > r . out . domain_sid ) ;
2006-05-16 01:49:27 +04:00
2006-05-04 18:52:03 +04:00
r - > out . dcerpc_pipe = talloc_steal ( mem_ctx , s - > r . out . dcerpc_pipe ) ;
2006-05-05 17:57:17 +04:00
2006-05-16 01:49:27 +04:00
/* reference created pipe structure to long-term libnet_context
so that it can be used by other api functions even after short - term
mem_ctx is freed */
2007-08-20 01:23:03 +04:00
if ( r - > in . dcerpc_iface = = & ndr_table_samr ) {
2006-08-22 00:52:14 +04:00
ctx - > samr . pipe = talloc_reference ( ctx , r - > out . dcerpc_pipe ) ;
2010-03-08 18:27:14 +03:00
ctx - > samr . samr_handle = ctx - > samr . pipe - > binding_handle ;
2006-06-30 00:34:45 +04:00
2007-08-20 01:23:03 +04:00
} else if ( r - > in . dcerpc_iface = = & ndr_table_lsarpc ) {
2006-08-22 00:52:14 +04:00
ctx - > lsa . pipe = talloc_reference ( ctx , r - > out . dcerpc_pipe ) ;
2010-03-08 18:27:14 +03:00
ctx - > lsa . lsa_handle = ctx - > lsa . pipe - > binding_handle ;
2006-05-16 01:49:27 +04:00
}
2006-06-30 00:34:45 +04:00
2006-05-24 15:46:19 +04:00
} else {
2006-10-13 17:01:48 +04:00
if ( s - > r . out . error_string ) {
r - > out . error_string = talloc_steal ( mem_ctx , s - > r . out . error_string ) ;
2008-03-13 06:13:31 +03:00
} else if ( r - > in . binding = = NULL ) {
2006-10-13 17:01:48 +04:00
r - > out . error_string = talloc_asprintf ( mem_ctx , " Connection to DC failed: %s " , nt_errstr ( status ) ) ;
2008-03-13 06:13:31 +03:00
} else {
r - > out . error_string = talloc_asprintf ( mem_ctx , " Connection to DC %s failed: %s " ,
r - > in . binding , nt_errstr ( status ) ) ;
2006-10-13 17:01:48 +04:00
}
2006-05-04 18:52:03 +04:00
}
talloc_free ( c ) ;
return status ;
}
/**
2006-05-04 21:37:57 +04:00
* Initiates connection to rpc pipe on remote server or pdc , optionally
* providing domain info
2006-05-04 18:52:03 +04:00
*
* @ param ctx initialised libnet context
2006-05-04 21:37:57 +04:00
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
* @ return composite context of this call
2006-05-04 18:52:03 +04:00
* */
2006-05-04 21:37:57 +04:00
struct composite_context * libnet_RpcConnect_send ( struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
2007-07-19 01:24:37 +04:00
struct libnet_RpcConnect * r ,
void ( * monitor ) ( struct monitor_msg * ) )
2006-05-04 18:52:03 +04:00
{
struct composite_context * c ;
2006-05-04 21:37:57 +04:00
switch ( r - > level ) {
case LIBNET_RPC_CONNECT_SERVER :
2006-10-13 17:01:48 +04:00
case LIBNET_RPC_CONNECT_SERVER_ADDRESS :
2006-05-04 21:37:57 +04:00
case LIBNET_RPC_CONNECT_BINDING :
2007-07-19 01:24:37 +04:00
c = libnet_RpcConnectSrv_send ( ctx , mem_ctx , r , monitor ) ;
2006-05-04 21:37:57 +04:00
break ;
2006-05-07 16:51:53 +04:00
2006-05-04 21:37:57 +04:00
case LIBNET_RPC_CONNECT_PDC :
case LIBNET_RPC_CONNECT_DC :
2007-07-19 01:24:37 +04:00
c = libnet_RpcConnectDC_send ( ctx , mem_ctx , r , monitor ) ;
2006-05-04 21:37:57 +04:00
break ;
case LIBNET_RPC_CONNECT_DC_INFO :
2007-07-19 01:24:37 +04:00
c = libnet_RpcConnectDCInfo_send ( ctx , mem_ctx , r , monitor ) ;
2006-05-04 21:37:57 +04:00
break ;
default :
c = talloc_zero ( mem_ctx , struct composite_context ) ;
composite_error ( c , NT_STATUS_INVALID_LEVEL ) ;
}
return c ;
}
/**
* Receives result of connection to rpc pipe on remote server or pdc
*
* @ param c composite context
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
* @ return nt status of rpc connection
* */
NTSTATUS libnet_RpcConnect_recv ( struct composite_context * c , struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx , struct libnet_RpcConnect * r )
{
switch ( r - > level ) {
case LIBNET_RPC_CONNECT_SERVER :
case LIBNET_RPC_CONNECT_BINDING :
return libnet_RpcConnectSrv_recv ( c , ctx , mem_ctx , r ) ;
case LIBNET_RPC_CONNECT_PDC :
case LIBNET_RPC_CONNECT_DC :
return libnet_RpcConnectDC_recv ( c , ctx , mem_ctx , r ) ;
case LIBNET_RPC_CONNECT_DC_INFO :
return libnet_RpcConnectDCInfo_recv ( c , ctx , mem_ctx , r ) ;
default :
2006-05-24 15:46:19 +04:00
ZERO_STRUCT ( r - > out ) ;
2006-05-04 21:37:57 +04:00
return NT_STATUS_INVALID_LEVEL ;
}
}
/**
* Connect to a rpc pipe on a remote server - sync version
*
* @ param ctx initialised libnet context
* @ param mem_ctx memory context of this call
* @ param r data structure containing necessary parameters and return values
* @ return nt status of rpc connection
* */
NTSTATUS libnet_RpcConnect ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx ,
struct libnet_RpcConnect * r )
{
struct composite_context * c ;
2007-07-19 01:24:37 +04:00
c = libnet_RpcConnect_send ( ctx , mem_ctx , r , NULL ) ;
2006-05-04 21:37:57 +04:00
return libnet_RpcConnect_recv ( c , ctx , mem_ctx , r ) ;
2006-05-04 18:52:03 +04:00
}