2005-12-31 10:41:59 +00:00
/*
Unix SMB / CIFS implementation .
wins server dns proxy
Copyright ( C ) Stefan Metzmacher 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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-12-31 10:41:59 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-12-31 10:41:59 +00:00
*/
# include "includes.h"
# include "nbt_server/nbt_server.h"
# include "nbt_server/wins/winsdb.h"
# include "nbt_server/wins/winsserver.h"
# include "system/time.h"
# include "libcli/composite/composite.h"
# include "smbd/service_task.h"
2006-03-07 11:07:23 +00:00
# include "libcli/resolve/resolve.h"
2005-12-31 10:41:59 +00:00
2005-12-31 11:32:55 +00:00
struct wins_dns_proxy_state {
struct nbt_name_socket * nbtsock ;
struct nbt_name_packet * packet ;
2006-01-09 22:12:53 +00:00
struct socket_address * src ;
2005-12-31 11:32:55 +00:00
} ;
static void nbtd_wins_dns_proxy_handler ( struct composite_context * creq )
{
NTSTATUS status ;
struct wins_dns_proxy_state * s = talloc_get_type ( creq - > async . private_data ,
struct wins_dns_proxy_state ) ;
struct nbt_name * name = & s - > packet - > questions [ 0 ] . name ;
const char * address ;
const char * * addresses ;
uint16_t nb_flags = 0 ; /* TODO: ... */
status = resolve_name_recv ( creq , s - > packet , & address ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto notfound ;
}
addresses = str_list_add ( NULL , address ) ;
talloc_steal ( s - > packet , addresses ) ;
if ( ! addresses ) goto notfound ;
2006-01-09 22:12:53 +00:00
nbtd_name_query_reply ( s - > nbtsock , s - > packet , s - > src , name ,
2005-12-31 11:32:55 +00:00
0 , nb_flags , addresses ) ;
return ;
notfound :
2006-01-09 22:12:53 +00:00
nbtd_negative_name_query_reply ( s - > nbtsock , s - > packet , s - > src ) ;
2005-12-31 11:32:55 +00:00
}
2005-12-31 10:41:59 +00:00
/*
dns proxy query a name
*/
void nbtd_wins_dns_proxy_query ( struct nbt_name_socket * nbtsock ,
struct nbt_name_packet * packet ,
2006-01-09 22:12:53 +00:00
struct socket_address * src )
2005-12-31 10:41:59 +00:00
{
2005-12-31 11:32:55 +00:00
struct nbt_name * name = & packet - > questions [ 0 ] . name ;
2008-09-23 09:02:16 +02:00
struct nbtd_interface * iface = talloc_get_type ( nbtsock - > incoming . private_data ,
2005-12-31 11:32:55 +00:00
struct nbtd_interface ) ;
struct wins_dns_proxy_state * s ;
struct composite_context * creq ;
2007-12-11 22:23:14 +01:00
struct resolve_context * resolve_ctx ;
2005-12-31 11:32:55 +00:00
s = talloc ( nbtsock , struct wins_dns_proxy_state ) ;
if ( ! s ) goto failed ;
s - > nbtsock = nbtsock ;
s - > packet = talloc_steal ( s , packet ) ;
2006-01-09 22:12:53 +00:00
s - > src = src ;
if ( ! talloc_reference ( s , src ) ) {
goto failed ;
}
2005-12-31 11:32:55 +00:00
2007-12-11 22:23:14 +01:00
resolve_ctx = resolve_context_init ( s ) ;
if ( resolve_ctx = = NULL ) goto failed ;
resolve_context_add_host_method ( resolve_ctx ) ;
2009-09-19 08:23:03 -07:00
creq = resolve_name_send ( resolve_ctx , s , name , iface - > nbtsrv - > task - > event_ctx ) ;
2005-12-31 11:32:55 +00:00
if ( ! creq ) goto failed ;
creq - > async . fn = nbtd_wins_dns_proxy_handler ;
creq - > async . private_data = s ;
return ;
failed :
2005-12-31 10:41:59 +00:00
nbtd_negative_name_query_reply ( nbtsock , packet , src ) ;
}