2005-06-19 02:37:11 +04:00
/*
Unix SMB / CIFS implementation .
Test suite for libnet calls .
Copyright ( C ) Rafal Szczesniak 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"
2005-07-02 18:37:21 +04:00
# include "lib/cmdline/popt_common.h"
2005-06-19 02:37:11 +04:00
# include "libnet/libnet.h"
2006-03-18 18:42:57 +03:00
# include "librpc/gen_ndr/nbt.h"
2006-07-09 16:57:40 +04:00
# include "librpc/rpc/dcerpc.h"
2006-07-09 17:56:11 +04:00
# include "libcli/libcli.h"
2006-03-25 19:01:28 +03:00
# include "torture/torture.h"
2005-06-19 02:37:11 +04:00
2006-03-25 19:01:28 +03:00
BOOL torture_lookup ( struct torture_context * torture )
2005-06-19 02:37:11 +04:00
{
2005-07-03 17:58:47 +04:00
BOOL ret ;
2005-06-19 02:37:11 +04:00
NTSTATUS status ;
TALLOC_CTX * mem_ctx ;
2005-07-02 18:37:21 +04:00
struct libnet_context * ctx ;
2005-06-19 02:37:11 +04:00
struct libnet_Lookup lookup ;
2006-07-09 16:57:40 +04:00
struct dcerpc_binding * bind ;
const char * bindstr ;
2005-06-19 02:37:11 +04:00
2005-06-22 00:22:38 +04:00
mem_ctx = talloc_init ( " test_lookup " ) ;
2005-06-19 02:37:11 +04:00
2005-07-02 18:37:21 +04:00
ctx = libnet_context_init ( NULL ) ;
ctx - > cred = cmdline_credentials ;
2006-10-18 18:23:19 +04:00
lookup . in . hostname = torture_setting_string ( torture , " host " , NULL ) ;
2006-07-09 16:57:40 +04:00
if ( lookup . in . hostname = = NULL ) {
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-07-09 16:57:40 +04:00
status = dcerpc_parse_binding ( mem_ctx , bindstr , & bind ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
lookup . in . hostname = bind - > host ;
}
}
2005-06-22 00:22:38 +04:00
lookup . in . type = NBT_NAME_CLIENT ;
2006-01-12 11:47:21 +03:00
lookup . in . methods = NULL ;
2006-07-09 17:18:15 +04:00
lookup . out . address = NULL ;
2005-06-19 02:37:11 +04:00
2005-07-02 18:37:21 +04:00
status = libnet_Lookup ( ctx , mem_ctx , & lookup ) ;
2005-06-19 02:37:11 +04:00
2005-06-22 00:22:38 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Couldn't lookup name %s: %s \n " , lookup . in . hostname , nt_errstr ( status ) ) ;
2005-07-03 17:58:47 +04:00
ret = False ;
goto done ;
2005-06-22 00:22:38 +04:00
}
2005-07-03 17:58:47 +04:00
ret = True ;
2006-07-09 17:18:15 +04:00
printf ( " Name [%s] found at adrress: %s. \n " , lookup . in . hostname , * lookup . out . address ) ;
2005-07-03 17:58:47 +04:00
done :
talloc_free ( mem_ctx ) ;
return ret ;
2005-06-22 00:22:38 +04:00
}
2006-03-25 19:01:28 +03:00
BOOL torture_lookup_host ( struct torture_context * torture )
2005-06-22 00:22:38 +04:00
{
2005-07-03 17:58:47 +04:00
BOOL ret ;
2005-06-22 00:22:38 +04:00
NTSTATUS status ;
TALLOC_CTX * mem_ctx ;
2005-07-02 18:37:21 +04:00
struct libnet_context * ctx ;
2005-06-22 00:22:38 +04:00
struct libnet_Lookup lookup ;
2006-07-09 16:57:40 +04:00
struct dcerpc_binding * bind ;
const char * bindstr ;
2005-06-22 00:22:38 +04:00
mem_ctx = talloc_init ( " test_lookup_host " ) ;
2005-07-02 18:37:21 +04:00
ctx = libnet_context_init ( NULL ) ;
ctx - > cred = cmdline_credentials ;
2006-10-18 18:23:19 +04:00
lookup . in . hostname = torture_setting_string ( torture , " host " , NULL ) ;
2006-07-09 16:57:40 +04:00
if ( lookup . in . hostname = = NULL ) {
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-07-09 16:57:40 +04:00
status = dcerpc_parse_binding ( mem_ctx , bindstr , & bind ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
lookup . in . hostname = bind - > host ;
}
}
2006-01-12 11:47:21 +03:00
lookup . in . methods = NULL ;
2006-07-09 17:18:15 +04:00
lookup . out . address = NULL ;
2005-06-22 00:22:38 +04:00
2005-07-02 18:37:21 +04:00
status = libnet_LookupHost ( ctx , mem_ctx , & lookup ) ;
2005-06-22 00:22:38 +04:00
2005-06-19 02:37:11 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Couldn't lookup host %s: %s \n " , lookup . in . hostname , nt_errstr ( status ) ) ;
2005-07-03 17:58:47 +04:00
ret = False ;
goto done ;
2005-06-19 02:37:11 +04:00
}
2005-07-03 17:58:47 +04:00
ret = True ;
2006-07-09 17:18:15 +04:00
printf ( " Host [%s] found at adrress: %s. \n " , lookup . in . hostname , * lookup . out . address ) ;
2005-07-03 17:58:47 +04:00
done :
talloc_free ( mem_ctx ) ;
return ret ;
2005-06-19 02:37:11 +04:00
}
2005-06-22 00:22:38 +04:00
2006-03-25 19:01:28 +03:00
BOOL torture_lookup_pdc ( struct torture_context * torture )
2005-06-22 00:22:38 +04:00
{
2005-07-03 17:58:47 +04:00
BOOL ret ;
2005-06-22 00:22:38 +04:00
NTSTATUS status ;
TALLOC_CTX * mem_ctx ;
2005-07-02 18:37:21 +04:00
struct libnet_context * ctx ;
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 * lookup ;
2006-07-09 17:56:11 +04:00
int i ;
2005-06-22 00:22:38 +04:00
mem_ctx = talloc_init ( " test_lookup_pdc " ) ;
2005-07-02 18:37:21 +04:00
ctx = libnet_context_init ( NULL ) ;
ctx - > cred = cmdline_credentials ;
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
talloc_steal ( ctx , mem_ctx ) ;
2005-07-03 17:58:47 +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
lookup = talloc ( mem_ctx , struct libnet_LookupDCs ) ;
if ( ! lookup ) {
ret = False ;
goto done ;
}
lookup - > in . domain_name = lp_workgroup ( ) ;
lookup - > in . name_type = NBT_NAME_PDC ;
2005-06-22 00:22:38 +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
status = libnet_LookupDCs ( ctx , mem_ctx , lookup ) ;
2005-06-22 00:22:38 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-07-09 17:56:11 +04:00
printf ( " Couldn't lookup pdc %s: %s \n " , lookup - > in . domain_name ,
nt_errstr ( status ) ) ;
2005-07-03 17:58:47 +04:00
ret = False ;
goto done ;
2005-06-22 00:22:38 +04:00
}
2005-07-03 17:58:47 +04:00
ret = True ;
2006-07-09 17:56:11 +04:00
printf ( " DCs of domain [%s] found. \n " , lookup - > in . domain_name ) ;
for ( i = 0 ; i < lookup - > out . num_dcs ; i + + ) {
printf ( " \t DC[%d]: name=%s, address=%s \n " , i , lookup - > out . dcs [ i ] . name ,
lookup - > out . dcs [ i ] . address ) ;
}
2005-07-03 17:58:47 +04:00
done :
talloc_free ( mem_ctx ) ;
return ret ;
2005-06-22 00:22:38 +04:00
}
2006-08-28 00:39:50 +04:00
BOOL torture_lookup_sam_name ( struct torture_context * torture )
{
NTSTATUS status ;
TALLOC_CTX * mem_ctx ;
struct libnet_context * ctx ;
struct libnet_LookupName r ;
ctx = libnet_context_init ( NULL ) ;
ctx - > cred = cmdline_credentials ;
mem_ctx = talloc_init ( " torture lookup sam name " ) ;
if ( mem_ctx = = NULL ) return False ;
r . in . name = " Administrator " ;
r . in . domain_name = lp_workgroup ( ) ;
status = libnet_LookupName ( ctx , mem_ctx , & r ) ;
talloc_free ( mem_ctx ) ;
talloc_free ( ctx ) ;
return True ;
}