2005-06-19 02:10:32 +04:00
/*
Unix SMB / CIFS implementation .
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 .
*/
/*
a composite function for name resolving
*/
# include "includes.h"
# include "lib/events/events.h"
2005-06-19 02:29:41 +04:00
# include "libnet/libnet.h"
2005-06-19 02:10:32 +04:00
# include "libcli/composite/composite.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 "lib/messaging/messaging.h"
# include "lib/messaging/irpc.h"
2006-03-07 14:07:23 +03:00
# include "libcli/resolve/resolve.h"
2006-03-07 16:36:26 +03:00
# include "libcli/finddcs.h"
2005-06-19 02:10:32 +04:00
struct lookup_state {
struct composite_context * resolve_ctx ;
struct nbt_name hostname ;
} ;
2005-06-22 00:22:38 +04:00
/**
* Sends asynchronous Lookup request
*
* @ param io arguments and result of the call
*/
2005-07-02 18:32:49 +04:00
struct composite_context * libnet_Lookup_send ( struct libnet_context * ctx ,
struct libnet_Lookup * io )
2005-06-19 02:10:32 +04:00
{
struct composite_context * c ;
struct lookup_state * s ;
2005-07-02 18:32:49 +04:00
const char * * methods ;
2005-06-19 02:10:32 +04:00
if ( ! io ) return NULL ;
/* allocate context and state structures */
c = talloc_zero ( NULL , struct composite_context ) ;
if ( c = = NULL ) goto failed ;
s = talloc_zero ( c , struct lookup_state ) ;
if ( s = = NULL ) goto failed ;
/* prepare event context */
2005-11-19 02:27:58 +03:00
c - > event_ctx = event_context_find ( c ) ;
2005-06-19 02:10:32 +04:00
if ( c - > event_ctx = = NULL ) goto failed ;
/* parameters */
s - > hostname . name = talloc_strdup ( s , io - > in . hostname ) ;
s - > hostname . type = io - > in . type ;
s - > hostname . scope = NULL ;
2005-07-02 18:32:49 +04:00
/* name resolution methods */
if ( io - > in . methods ) {
methods = io - > in . methods ;
} else {
methods = ( const char * * ) ctx - > name_res_methods ;
}
2005-09-26 15:47:55 +04:00
c - > private_data = s ;
c - > state = COMPOSITE_STATE_IN_PROGRESS ;
2005-06-19 02:10:32 +04:00
/* send resolve request */
2005-07-02 18:32:49 +04:00
s - > resolve_ctx = resolve_name_send ( & s - > hostname , c - > event_ctx , methods ) ;
2005-06-19 02:10:32 +04:00
return c ;
failed :
talloc_free ( c ) ;
return NULL ;
}
2005-06-22 00:22:38 +04:00
/**
* Waits for and receives results of asynchronous Lookup call
*
* @ param c composite context returned by asynchronous Lookup call
* @ param mem_ctx memory context of the call
* @ param io pointer to results ( and arguments ) of the call
* @ return nt status code of execution
*/
2005-06-19 02:10:32 +04:00
NTSTATUS libnet_Lookup_recv ( struct composite_context * c , TALLOC_CTX * mem_ctx ,
2005-06-19 02:29:41 +04:00
struct libnet_Lookup * io )
2005-06-19 02:10:32 +04:00
{
NTSTATUS status ;
struct lookup_state * s ;
2005-11-19 02:27:58 +03:00
const char * address ;
2005-06-19 02:10:32 +04:00
2005-09-26 15:47:55 +04:00
s = talloc_get_type ( c - > private_data , struct lookup_state ) ;
2005-06-19 02:10:32 +04:00
2005-11-19 02:27:58 +03:00
status = resolve_name_recv ( s - > resolve_ctx , mem_ctx , & address ) ;
2005-11-16 22:55:27 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-11-19 02:27:58 +03:00
io - > out . address = str_list_make ( mem_ctx , address , NULL ) ;
NT_STATUS_HAVE_NO_MEMORY ( io - > out . address ) ;
2005-11-16 22:55:27 +03:00
}
2005-06-19 02:10:32 +04:00
return status ;
}
2005-06-22 00:22:38 +04:00
/**
* Synchronous version of Lookup call
*
* @ param mem_ctx memory context for the call
* @ param io arguments and results of the call
* @ return nt status code of execution
*/
2005-07-02 18:32:49 +04:00
NTSTATUS libnet_Lookup ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx ,
struct libnet_Lookup * io )
2005-06-19 02:10:32 +04:00
{
2005-07-02 18:32:49 +04:00
struct composite_context * c = libnet_Lookup_send ( ctx , io ) ;
2005-06-19 02:10:32 +04:00
return libnet_Lookup_recv ( c , mem_ctx , io ) ;
}
2005-06-22 00:22:38 +04:00
/*
* Shortcut functions to find common types of name
* ( and skip nbt name type argument )
*/
/**
* Sends asynchronous LookupHost request
*/
2005-07-02 18:32:49 +04:00
struct composite_context * libnet_LookupHost_send ( struct libnet_context * ctx ,
struct libnet_Lookup * io )
2005-06-22 00:22:38 +04:00
{
io - > in . type = NBT_NAME_SERVER ;
2005-07-02 18:32:49 +04:00
return libnet_Lookup_send ( ctx , io ) ;
2005-06-22 00:22:38 +04:00
}
/**
* Synchronous version of LookupHost call
*/
2005-07-02 18:32:49 +04:00
NTSTATUS libnet_LookupHost ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx ,
struct libnet_Lookup * io )
2005-06-22 00:22:38 +04:00
{
2005-07-02 18:32:49 +04:00
struct composite_context * c = libnet_LookupHost_send ( ctx , io ) ;
2005-06-22 00:22:38 +04:00
return libnet_Lookup_recv ( c , mem_ctx , io ) ;
}
/**
2006-06-30 00:26:11 +04:00
* Sends asynchronous LookupDCs request
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
struct composite_context * libnet_LookupDCs_send ( struct libnet_context * ctx ,
TALLOC_CTX * mem_ctx ,
struct libnet_LookupDCs * io )
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
struct composite_context * c ;
2006-06-30 00:26:11 +04:00
struct messaging_context * msg_ctx = messaging_client_init ( mem_ctx , ctx - > event_ctx ) ;
c = finddcs_send ( mem_ctx , io - > in . domain_name , io - > in . name_type ,
NULL , ctx - > name_res_methods , ctx - > event_ctx , msg_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
return c ;
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
/**
* Waits for and receives results of asynchronous Lookup call
*
* @ param c composite context returned by asynchronous Lookup call
* @ param mem_ctx memory context of the call
* @ param io pointer to results ( and arguments ) of the call
* @ return nt status code of execution
*/
NTSTATUS libnet_LookupDCs_recv ( struct composite_context * c , TALLOC_CTX * mem_ctx ,
struct libnet_LookupDCs * io )
{
NTSTATUS status ;
status = finddcs_recv ( c , mem_ctx , & io - > out . num_dcs , & io - > out . dcs ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
return status ;
}
2005-06-22 00:22:38 +04:00
/**
* Synchronous version of LookupPdc
*/
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
NTSTATUS libnet_LookupDCs ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx ,
struct libnet_LookupDCs * io )
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
struct composite_context * c = libnet_LookupDCs_send ( ctx , mem_ctx , io ) ;
return libnet_LookupDCs_recv ( c , mem_ctx , io ) ;
2005-06-22 00:22:38 +04:00
}