2005-01-21 14:18:56 +03:00
/*
Unix SMB / CIFS implementation .
broadcast name resolution module
Copyright ( C ) Andrew Tridgell 2005
2007-12-14 00:46:44 +03:00
Copyright ( C ) Jelmer Vernooij 2007
2005-01-21 14:18:56 +03: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
2005-01-21 14:18:56 +03: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/>.
2005-01-21 14:18:56 +03:00
*/
# include "includes.h"
2006-03-07 14:07:23 +03:00
# include "libcli/resolve/resolve.h"
# include "system/network.h"
2006-08-17 17:37:04 +04:00
# include "lib/socket/netif.h"
2007-12-07 01:57:22 +03:00
# include "param/param.h"
2005-01-21 14:18:56 +03:00
2007-12-14 00:46:44 +03:00
struct resolve_bcast_data {
struct interface * ifaces ;
uint16_t nbt_port ;
2008-02-21 19:17:37 +03:00
int nbt_timeout ;
2007-12-14 00:46:44 +03:00
} ;
2007-12-07 01:57:22 +03:00
/**
2005-01-21 14:18:56 +03:00
broadcast name resolution method - async send
*/
2018-01-13 19:41:01 +03:00
static struct composite_context * resolve_name_bcast_send (
TALLOC_CTX * mem_ctx ,
struct tevent_context * event_ctx ,
void * userdata , uint32_t flags ,
uint16_t port ,
struct nbt_name * name )
2005-01-21 14:18:56 +03:00
{
2007-12-12 00:23:14 +03:00
int num_interfaces ;
2005-01-21 16:13:24 +03:00
const char * * address_list ;
2005-01-31 11:30:44 +03:00
struct composite_context * c ;
2006-02-15 07:18:11 +03:00
int i , count = 0 ;
2007-12-14 00:46:44 +03:00
struct resolve_bcast_data * data = talloc_get_type ( userdata , struct resolve_bcast_data ) ;
2007-12-12 00:23:14 +03:00
2011-05-02 09:57:19 +04:00
num_interfaces = iface_list_count ( data - > ifaces ) ;
2005-01-21 14:18:56 +03:00
2006-11-09 04:11:45 +03:00
address_list = talloc_array ( mem_ctx , const char * , num_interfaces + 1 ) ;
2005-01-21 16:13:24 +03:00
if ( address_list = = NULL ) return NULL ;
2005-01-21 14:18:56 +03:00
2005-01-21 16:13:24 +03:00
for ( i = 0 ; i < num_interfaces ; i + + ) {
2011-09-28 04:02:08 +04:00
bool ipv4 = iface_list_n_is_v4 ( data - > ifaces , i ) ;
const char * bcast ;
if ( ! ipv4 ) {
continue ;
}
bcast = iface_list_n_bcast ( data - > ifaces , i ) ;
if ( bcast = = NULL ) {
continue ;
}
2006-02-15 07:18:11 +03:00
address_list [ count ] = talloc_strdup ( address_list , bcast ) ;
if ( address_list [ count ] = = NULL ) {
2005-01-21 16:13:24 +03:00
talloc_free ( address_list ) ;
return NULL ;
}
2006-02-15 07:18:11 +03:00
count + + ;
2005-01-21 14:18:56 +03:00
}
2006-02-15 07:18:11 +03:00
address_list [ count ] = NULL ;
2005-01-21 14:18:56 +03:00
2008-12-17 19:25:40 +03:00
c = resolve_name_nbtlist_send ( mem_ctx , event_ctx , flags , port , name ,
2008-12-13 13:03:52 +03:00
address_list , data - > ifaces , data - > nbt_port ,
data - > nbt_timeout , true , false ) ;
2005-01-21 16:13:24 +03:00
talloc_free ( address_list ) ;
2005-01-21 14:18:56 +03:00
2005-01-21 16:13:24 +03:00
return c ;
2005-01-21 14:18:56 +03:00
}
/*
broadcast name resolution method - recv side
*/
2018-01-13 19:41:01 +03:00
static NTSTATUS resolve_name_bcast_recv ( struct composite_context * c ,
TALLOC_CTX * mem_ctx ,
struct socket_address * * * addrs ,
char * * * names )
2005-01-21 14:18:56 +03:00
{
2008-12-13 22:50:36 +03:00
NTSTATUS status = resolve_name_nbtlist_recv ( c , mem_ctx , addrs , names ) ;
2008-09-30 19:42:12 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_IO_TIMEOUT ) ) {
/* this makes much more sense for a bcast name resolution
timeout */
status = NT_STATUS_OBJECT_NAME_NOT_FOUND ;
}
return status ;
2005-01-21 14:18:56 +03:00
}
2008-02-21 19:17:37 +03:00
bool resolve_context_add_bcast_method ( struct resolve_context * ctx , struct interface * ifaces , uint16_t nbt_port , int nbt_timeout )
2007-12-14 00:46:44 +03:00
{
struct resolve_bcast_data * data = talloc ( ctx , struct resolve_bcast_data ) ;
data - > ifaces = ifaces ;
data - > nbt_port = nbt_port ;
2008-02-21 19:17:37 +03:00
data - > nbt_timeout = nbt_timeout ;
2007-12-14 00:46:44 +03:00
return resolve_context_add_method ( ctx , resolve_name_bcast_send , resolve_name_bcast_recv , data ) ;
}
bool resolve_context_add_bcast_method_lp ( struct resolve_context * ctx , struct loadparm_context * lp_ctx )
2007-12-10 20:41:19 +03:00
{
2007-12-12 00:23:14 +03:00
struct interface * ifaces ;
2011-06-02 09:40:28 +04:00
load_interface_list ( ctx , lp_ctx , & ifaces ) ;
2010-07-16 08:32:42 +04:00
return resolve_context_add_bcast_method ( ctx , ifaces , lpcfg_nbt_port ( lp_ctx ) , lpcfg_parm_int ( lp_ctx , NULL , " nbt " , " timeout " , 1 ) ) ;
2007-12-10 20:41:19 +03:00
}