~bug-zappers/ubuntu/lucid/samba/bugzapping

« back to all changes in this revision

Viewing changes to source/nmbd/nmbd_nodestatus.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-10-15 12:31:58 UTC
  • Revision ID: james.westby@ubuntu.com-20041015123158-aokykzdqkdgy6dfx
Tags: upstream-3.0.7
ImportĀ upstreamĀ versionĀ 3.0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   Unix SMB/CIFS implementation.
 
3
   NBT netbios routines and daemon - version 2
 
4
   Copyright (C) Andrew Tridgell 1994-1998
 
5
   Copyright (C) Luke Kenneth Casson Leighton 1994-1998
 
6
   Copyright (C) Jeremy Allison 1994-2003
 
7
   
 
8
   This program is free software; you can redistribute it and/or modify
 
9
   it under the terms of the GNU General Public License as published by
 
10
   the Free Software Foundation; either version 2 of the License, or
 
11
   (at your option) any later version.
 
12
   
 
13
   This program is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
   GNU General Public License for more details.
 
17
   
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this program; if not, write to the Free Software
 
20
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
   
 
22
*/
 
23
 
 
24
#include "includes.h"
 
25
 
 
26
/****************************************************************************
 
27
 Deal with a successful node status response.
 
28
****************************************************************************/
 
29
 
 
30
static void node_status_response(struct subnet_record *subrec,
 
31
                       struct response_record *rrec, struct packet_struct *p)
 
32
{
 
33
        struct nmb_packet *nmb = &p->packet.nmb;
 
34
        struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name;
 
35
        struct nmb_name *answer_name = &nmb->answers->rr_name;
 
36
 
 
37
        /* Sanity check. Ensure that the answer name in the incoming packet is the
 
38
                same as the requested name in the outgoing packet. */
 
39
 
 
40
        if(!nmb_name_equal(question_name, answer_name)) {
 
41
                DEBUG(0,("node_status_response: Answer name %s differs from question \
 
42
name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name)));
 
43
                return;
 
44
        }
 
45
 
 
46
        DEBUG(5,("node_status_response: response from name %s on subnet %s.\n",
 
47
                nmb_namestr(answer_name), subrec->subnet_name));
 
48
 
 
49
        /* Just send the whole answer resource record for the success function to parse. */
 
50
        if(rrec->success_fn)
 
51
                (*(node_status_success_function)rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip);
 
52
 
 
53
        /* Ensure we don't retry. */
 
54
        remove_response_record(subrec, rrec);
 
55
}
 
56
 
 
57
/****************************************************************************
 
58
 Deal with a timeout when requesting a node status.
 
59
****************************************************************************/
 
60
 
 
61
static void node_status_timeout_response(struct subnet_record *subrec,
 
62
                       struct response_record *rrec)
 
63
{
 
64
        struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
 
65
        struct nmb_name *question_name = &sent_nmb->question.question_name;
 
66
 
 
67
        DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n",
 
68
                nmb_namestr(question_name), subrec->subnet_name));
 
69
 
 
70
        if( rrec->fail_fn)
 
71
                (*rrec->fail_fn)(subrec, rrec);
 
72
 
 
73
        /* Ensure we don't retry. */
 
74
        remove_response_record(subrec, rrec);
 
75
}
 
76
 
 
77
/****************************************************************************
 
78
 Try and do a node status to a name - given the name & IP address.
 
79
****************************************************************************/
 
80
 
 
81
BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname,
 
82
                 struct in_addr send_ip, node_status_success_function success_fn, 
 
83
                 node_status_fail_function fail_fn, struct userdata_struct *userdata)
 
84
{
 
85
        if(queue_node_status( subrec, node_status_response, node_status_timeout_response,
 
86
                                success_fn, fail_fn, userdata, nmbname, send_ip)==NULL) {
 
87
                DEBUG(0,("node_status: Failed to send packet trying to get node status for \
 
88
name %s, IP address %s\n", nmb_namestr(nmbname), inet_ntoa(send_ip)));
 
89
                return True;
 
90
        } 
 
91
        return False;
 
92
}