1997-12-13 17:16:07 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1997-12-13 17:16:07 +03:00
NBT netbios routines and daemon - version 2
1998-01-22 16:27:43 +03:00
Copyright ( C ) Andrew Tridgell 1994 - 1998
Copyright ( C ) Luke Kenneth Casson Leighton 1994 - 1998
2003-08-27 05:25:01 +04:00
Copyright ( C ) Jeremy Allison 1994 - 2003
1997-12-13 17:16:07 +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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1997-12-13 17:16:07 +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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1997-12-13 17:16:07 +03:00
*/
# include "includes.h"
2010-08-18 17:22:09 +04:00
# include "nmbd/nmbd.h"
1997-12-13 17:16:07 +03:00
/****************************************************************************
Deal with a successful node status response .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-08-27 05:25:01 +04:00
1997-12-13 17:16:07 +03:00
static void node_status_response ( struct subnet_record * subrec ,
struct response_record * rrec , struct packet_struct * p )
{
2003-08-27 05:25:01 +04:00
struct nmb_packet * nmb = & p - > packet . nmb ;
struct nmb_name * question_name = & rrec - > packet - > packet . nmb . question . question_name ;
struct nmb_name * answer_name = & nmb - > answers - > rr_name ;
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
/* Sanity check. Ensure that the answer name in the incoming packet is the
same as the requested name in the outgoing packet . */
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
if ( ! nmb_name_equal ( question_name , answer_name ) ) {
DEBUG ( 0 , ( " node_status_response: Answer name %s differs from question \
1998-11-14 04:04:13 +03:00
name % s . \ n " , nmb_namestr(answer_name), nmb_namestr(question_name)));
2003-08-27 05:25:01 +04:00
return ;
}
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
DEBUG ( 5 , ( " node_status_response: response from name %s on subnet %s. \n " ,
nmb_namestr ( answer_name ) , subrec - > subnet_name ) ) ;
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
/* Just send the whole answer resource record for the success function to parse. */
if ( rrec - > success_fn )
( * ( node_status_success_function ) rrec - > success_fn ) ( subrec , rrec - > userdata , nmb - > answers , p - > ip ) ;
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
/* Ensure we don't retry. */
remove_response_record ( subrec , rrec ) ;
1997-12-13 17:16:07 +03:00
}
/****************************************************************************
Deal with a timeout when requesting a node status .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-08-27 05:25:01 +04:00
1997-12-13 17:16:07 +03:00
static void node_status_timeout_response ( struct subnet_record * subrec ,
struct response_record * rrec )
{
2003-08-27 05:25:01 +04:00
struct nmb_packet * sent_nmb = & rrec - > packet - > packet . nmb ;
struct nmb_name * question_name = & sent_nmb - > question . question_name ;
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
DEBUG ( 5 , ( " node_status_timeout_response: failed to get node status from name %s on subnet %s \n " ,
nmb_namestr ( question_name ) , subrec - > subnet_name ) ) ;
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
if ( rrec - > fail_fn )
( * rrec - > fail_fn ) ( subrec , rrec ) ;
1997-12-13 17:16:07 +03:00
2003-08-27 05:25:01 +04:00
/* Ensure we don't retry. */
remove_response_record ( subrec , rrec ) ;
1997-12-13 17:16:07 +03:00
}
/****************************************************************************
Try and do a node status to a name - given the name & IP address .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool node_status ( struct subnet_record * subrec , struct nmb_name * nmbname ,
1997-12-13 17:16:07 +03:00
struct in_addr send_ip , node_status_success_function success_fn ,
node_status_fail_function fail_fn , struct userdata_struct * userdata )
{
2003-08-27 05:25:01 +04:00
if ( queue_node_status ( subrec , node_status_response , node_status_timeout_response ,
success_fn , fail_fn , userdata , nmbname , send_ip ) = = NULL ) {
DEBUG ( 0 , ( " node_status: Failed to send packet trying to get node status for \
1998-11-14 04:04:13 +03:00
name % s , IP address % s \ n " , nmb_namestr(nmbname), inet_ntoa(send_ip)));
2003-08-27 05:25:01 +04:00
return True ;
}
return False ;
1997-12-13 17:16:07 +03:00
}