2005-12-31 13:41:59 +03: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
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"
# 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 14:07:23 +03:00
# include "libcli/resolve/resolve.h"
2005-12-31 13:41:59 +03:00
2005-12-31 14:32:55 +03:00
struct wins_dns_proxy_state {
struct nbt_name_socket * nbtsock ;
struct nbt_name_packet * packet ;
2006-01-10 01:12:53 +03:00
struct socket_address * src ;
2005-12-31 14:32:55 +03: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-10 01:12:53 +03:00
nbtd_name_query_reply ( s - > nbtsock , s - > packet , s - > src , name ,
2005-12-31 14:32:55 +03:00
0 , nb_flags , addresses ) ;
return ;
notfound :
2006-01-10 01:12:53 +03:00
nbtd_negative_name_query_reply ( s - > nbtsock , s - > packet , s - > src ) ;
2005-12-31 14:32:55 +03:00
}
2005-12-31 13:41:59 +03:00
/*
dns proxy query a name
*/
void nbtd_wins_dns_proxy_query ( struct nbt_name_socket * nbtsock ,
struct nbt_name_packet * packet ,
2006-01-10 01:12:53 +03:00
struct socket_address * src )
2005-12-31 13:41:59 +03:00
{
2005-12-31 14:32:55 +03:00
struct nbt_name * name = & packet - > questions [ 0 ] . name ;
struct nbtd_interface * iface = talloc_get_type ( nbtsock - > incoming . private ,
struct nbtd_interface ) ;
struct wins_dns_proxy_state * s ;
struct composite_context * creq ;
const char * methods [ ] = {
" host " ,
NULL
} ;
s = talloc ( nbtsock , struct wins_dns_proxy_state ) ;
if ( ! s ) goto failed ;
s - > nbtsock = nbtsock ;
s - > packet = talloc_steal ( s , packet ) ;
2006-01-10 01:12:53 +03:00
s - > src = src ;
if ( ! talloc_reference ( s , src ) ) {
goto failed ;
}
2005-12-31 14:32:55 +03:00
creq = resolve_name_send ( name , iface - > nbtsrv - > task - > event_ctx , methods ) ;
if ( ! creq ) goto failed ;
creq - > async . fn = nbtd_wins_dns_proxy_handler ;
creq - > async . private_data = s ;
return ;
failed :
2005-12-31 13:41:59 +03:00
nbtd_negative_name_query_reply ( nbtsock , packet , src ) ;
}