client.c: Added amanda fixes.
[Samba/ekacnet.git] / source / nameservresp.c
blob43548265a0749c54b37cd337f4153058bf2b48ab
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1997
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Revision History:
23 Module name: nameservresp.c
25 14 jan 96: lkcl@pires.co.uk
26 added multiple workgroup domain master support
28 05 jul 96: lkcl@pires.co.uk
29 created module nameservresp containing NetBIOS response functions
33 #include "includes.h"
35 extern int ClientNMB;
37 extern int DEBUGLEVEL;
39 extern pstring scope;
40 extern fstring myworkgroup;
41 extern struct in_addr ipzero;
42 extern struct in_addr wins_ip;
43 extern struct in_addr ipzero;
46 #define GET_TTL(ttl) ((ttl)?MIN(ttl,lp_max_ttl()):lp_max_ttl())
49 /****************************************************************************
50 response for a reg release received. samba has asked a WINS server if it
51 could release a name.
52 **************************************************************************/
53 static void response_name_release(struct nmb_name *ans_name,
54 struct subnet_record *d, struct packet_struct *p)
56 struct nmb_packet *nmb = &p->packet.nmb;
57 char *name = ans_name->name;
58 int type = ans_name->name_type;
60 DEBUG(4,("response name release received\n"));
62 if (nmb->header.rcode == 0 && nmb->answers->rdata)
64 /* IMPORTANT: see expire_netbios_response_entries() */
66 struct in_addr found_ip;
67 putip((char*)&found_ip,&nmb->answers->rdata[2]);
69 /* NOTE: we only release our own names at present */
70 if (ismyip(found_ip))
72 name_unregister_work(d,name,type);
74 else
76 DEBUG(2,("name release for different ip! %s %s\n",
77 inet_ntoa(found_ip), namestr(ans_name)));
80 else
82 DEBUG(2,("name release for %s rejected!\n", namestr(ans_name)));
84 /* XXXX PANIC! what to do if it's one of samba's own names? */
86 /* XXXX do we honestly care if our name release was rejected?
87 only if samba is issuing the release on behalf of some out-of-sync
88 server. if it's one of samba's SELF names, we don't care. */
93 /****************************************************************************
94 response for a reg request received
95 **************************************************************************/
96 static void response_name_reg(struct nmb_name *ans_name,
97 struct subnet_record *d, struct packet_struct *p)
99 struct nmb_packet *nmb = &p->packet.nmb;
100 BOOL bcast = nmb->header.nm_flags.bcast;
101 char *name = ans_name->name;
102 int type = ans_name->name_type;
104 DEBUG(4,("response name registration received!\n"));
106 #if 1
107 /* This code is neccesitated due to bugs in earlier versions of
108 Samba (up to 1.9.16p11). They respond to a broadcast
109 name registration of WORKGROUP<1b> when they should
110 not. Hence, until these versions are gone, we should
111 treat such errors as success for this particular
112 case only. jallison@whistle.com.
114 if ( ((d != wins_subnet) && (nmb->header.rcode == 6) && strequal(myworkgroup, name) &&
115 (type == 0x1b)) ||
116 (nmb->header.rcode == 0 && nmb->answers->rdata))
117 #else
118 if (nmb->header.rcode == 0 && nmb->answers->rdata)
119 #endif
121 /* IMPORTANT: see expire_netbios_response_entries() */
123 int nb_flags = nmb->answers->rdata[0];
124 int ttl = nmb->answers->ttl;
125 struct in_addr found_ip;
127 putip((char*)&found_ip,&nmb->answers->rdata[2]);
129 name_register_work(d,name,type,nb_flags,ttl,found_ip,bcast);
131 else
133 DEBUG(2,("name registration for %s rejected by ip %s!\n",
134 namestr(ans_name), inet_ntoa(p->ip)));
136 /* oh dear. we have problems. possibly unbecome a master browser. */
137 name_unregister_work(d,name,type);
141 /****************************************************************************
142 response from a name query server check. states of type NAME_QUERY_DOM_SRV_CHK,
143 NAME_QUERY_SRV_CHK, and NAME_QUERY_FIND_MST dealt with here.
144 ****************************************************************************/
145 static void response_server_check(struct nmb_name *ans_name,
146 struct response_record *n, struct subnet_record *d)
148 /* issue another state: this time to do a name status check */
150 enum state_type cmd = (n->state == NAME_QUERY_DOM_SRV_CHK) ?
151 NAME_STATUS_DOM_SRV_CHK : NAME_STATUS_SRV_CHK;
153 /* initiate a name status check on the server that replied
154 in addition, the workgroup being checked has been stored
155 in the response_record->my_name (see announce_master) we
156 also propagate this into the same field. */
157 queue_netbios_packet(d,ClientNMB,NMB_STATUS, cmd,
158 ans_name->name, ans_name->name_type,
159 0,0,0,n->my_name,NULL,
160 False,False,n->send_ip,n->reply_to_ip);
164 /****************************************************************************
165 interpret a node status response. this is pretty hacked: we need two bits of
166 info. a) the name of the workgroup b) the name of the server. it will also
167 add all the names it finds into the namelist.
168 ****************************************************************************/
169 static BOOL interpret_node_status(struct subnet_record *d,
170 char *p, struct nmb_name *name,int t,
171 char *serv_name, struct in_addr ip, BOOL bcast)
173 int numnames = CVAL(p,0);
174 BOOL found = False;
176 DEBUG(4,("received %d names\n",numnames));
178 p += 1;
180 if (serv_name) *serv_name = 0;
182 while (numnames--)
184 char qname[17];
185 int type;
186 fstring flags;
187 int nb_flags;
189 BOOL group = False;
190 BOOL add = False;
192 *flags = 0;
194 StrnCpy(qname,p,15);
195 type = CVAL(p,15);
196 nb_flags = p[16];
197 trim_string(qname,NULL," ");
199 p += 18;
201 if (NAME_GROUP (nb_flags)) { strcat(flags,"<GROUP> "); group=True;}
202 if (NAME_BFLAG (nb_flags)) { strcat(flags,"B "); }
203 if (NAME_PFLAG (nb_flags)) { strcat(flags,"P "); }
204 if (NAME_MFLAG (nb_flags)) { strcat(flags,"M "); }
205 if (NAME_HFLAG (nb_flags)) { strcat(flags,"H "); }
206 if (NAME_DEREG (nb_flags)) { strcat(flags,"<DEREGISTERING> "); }
207 if (NAME_CONFLICT (nb_flags)) { strcat(flags,"<CONFLICT> "); }
208 if (NAME_ACTIVE (nb_flags)) { strcat(flags,"<ACTIVE> "); add=True; }
209 if (NAME_PERMANENT(nb_flags)) { strcat(flags,"<PERMANENT> "); add=True;}
211 /* we want the server name */
212 if (serv_name && !*serv_name && !group && type == 0x20)
214 StrnCpy(serv_name,qname,15);
215 serv_name[15] = 0;
218 /* looking for a name and type? */
219 if (name && !found && (t == type))
221 /* take a guess at some of the name types we're going to ask for.
222 evaluate whether they are group names or no... */
223 if (((t == 0x1b || t == 0x1d || t == 0x20 ) && !group) ||
224 ((t == 0x1c || t == 0x1e ) && group))
226 found = True;
227 make_nmb_name(name,qname,type,scope);
231 DEBUG(4,("\t%s(0x%x)\t%s\n",qname,type,flags));
233 DEBUG(4,("num_good_sends=%d num_good_receives=%d\n",
234 IVAL(p,20),IVAL(p,24)));
235 return found;
239 /****************************************************************************
240 response from a name status check. states of type NAME_STATUS_DOM_SRV_CHK
241 and NAME_STATUS_SRV_CHK dealt with here.
242 ****************************************************************************/
243 static void response_name_status_check(struct in_addr ip,
244 struct nmb_packet *nmb, BOOL bcast,
245 struct response_record *n, struct subnet_record *d)
247 /* NMB_STATUS arrives: contains workgroup name and server name required.
248 amongst other things. */
250 struct nmb_name name;
251 fstring serv_name;
253 if (interpret_node_status(d,nmb->answers->rdata,
254 &name,0x20,serv_name,ip,bcast))
256 if (*serv_name)
258 /* response_record->my_name contains the
259 workgroup name to sync with. See
260 response_server_check() */
261 sync_server(n->state,serv_name,
262 n->my_name,name.name_type, d, n->send_ip);
265 else
267 DEBUG(1,("No 0x20 name type in interpret_node_status()\n"));
272 /****************************************************************************
273 response from a name query for secured WINS registration. a state of
274 NAME_REGISTER_CHALLENGE is dealt with here.
275 ****************************************************************************/
276 static void response_name_query_register(struct nmb_packet *nmb,
277 struct nmb_name *ans_name,
278 struct response_record *n, struct subnet_record *d)
280 struct in_addr register_ip;
281 BOOL new_owner;
283 DEBUG(4, ("Name query at %s ip %s - ",
284 namestr(&n->name), inet_ntoa(n->send_ip)));
286 if (!name_equal(&n->name, ans_name))
288 /* someone gave us the wrong name as a reply. oops. */
289 /* XXXX should say to them 'oi! release that name!' */
291 DEBUG(4,("unexpected name received: %s\n", namestr(ans_name)));
292 return;
295 if (nmb->header.rcode == 0 && nmb->answers->rdata)
297 /* we had sent out a name query to the current owner
298 of a name because someone else wanted it. now they
299 have responded saying that they still want the name,
300 so the other host can't have it.
303 /* first check all the details are correct */
305 int nb_flags = nmb->answers->rdata[0];
306 struct in_addr found_ip;
308 putip((char*)&found_ip,&nmb->answers->rdata[2]);
310 if (nb_flags != n->nb_flags)
312 /* someone gave us the wrong nb_flags as a reply. oops. */
313 /* XXXX should say to them 'oi! release that name!' */
315 DEBUG(4,("expected nb_flags: %d\n", n->nb_flags));
316 DEBUG(4,("unexpected nb_flags: %d\n", nb_flags));
317 return;
320 if (!ip_equal(n->send_ip, found_ip))
322 /* someone gave us the wrong ip as a reply. oops. */
323 /* XXXX should say to them 'oi! release that name!' */
325 DEBUG(4,("expected ip: %s\n", inet_ntoa(n->send_ip)));
326 DEBUG(4,("unexpected ip: %s\n", inet_ntoa(found_ip)));
327 return;
330 DEBUG(4, (" OK: %s\n", inet_ntoa(found_ip)));
332 /* fine: now tell the other host they can't have the name */
333 register_ip = n->send_ip;
334 new_owner = False;
336 else
338 DEBUG(4, (" NEGATIVE RESPONSE!\n"));
340 /* the owner didn't want the name: the other host can have it */
341 register_ip = n->reply_to_ip;
342 new_owner = True;
345 /* register the old or the new owners' ip */
346 add_name_respond(d, n->fd, d->myip, n->response_id,&n->name,n->nb_flags,
347 GET_TTL(0), register_ip,
348 new_owner, n->reply_to_ip);
352 /****************************************************************************
353 response from a name query to sync browse lists or to update our netbios
354 entry. states of type NAME_QUERY_SYNC and NAME_QUERY_CONFIRM
355 ****************************************************************************/
356 static void response_name_query_sync(struct nmb_packet *nmb,
357 struct nmb_name *ans_name, BOOL bcast,
358 struct response_record *n, struct subnet_record *d)
360 DEBUG(4, ("Name query at %s ip %s - ",
361 namestr(&n->name), inet_ntoa(n->send_ip)));
363 if (!name_equal(&n->name, ans_name))
365 /* someone gave us the wrong name as a reply. oops. */
366 DEBUG(4,("unexpected name received: %s\n", namestr(ans_name)));
367 return;
370 if (nmb->header.rcode == 0 && nmb->answers->rdata)
372 int nb_flags = nmb->answers->rdata[0];
373 struct in_addr found_ip;
375 putip((char*)&found_ip,&nmb->answers->rdata[2]);
377 if (!ip_equal(n->send_ip, found_ip))
379 /* someone gave us the wrong ip as a reply. oops. */
380 DEBUG(4,("expected ip: %s\n", inet_ntoa(n->send_ip)));
381 DEBUG(4,("unexpected ip: %s\n", inet_ntoa(found_ip)));
382 return;
385 DEBUG(4, (" OK: %s\n", inet_ntoa(found_ip)));
387 if (n->state == NAME_QUERY_SYNC_LOCAL ||
388 n->state == NAME_QUERY_SYNC_REMOTE)
390 struct work_record *work = NULL;
391 /* We cheat here as we know that the workgroup name has
392 been placed in the my_comment field of the
393 response_record struct by the code in
394 start_sync_browse_entry().
396 if ((work = find_workgroupstruct(d, n->my_comment, False)))
398 BOOL local_list_only = n->state == NAME_QUERY_SYNC_LOCAL;
400 /* the server is there: sync quick before it (possibly) dies! */
401 sync_browse_lists(d, work, ans_name->name, ans_name->name_type,
402 found_ip, local_list_only);
405 else
407 /* update our netbios name list (re-register it if necessary) */
408 add_netbios_entry(d, ans_name->name, ans_name->name_type,
409 nb_flags,GET_TTL(0),REGISTER,
410 found_ip,False,!bcast);
413 else
415 DEBUG(4, (" NEGATIVE RESPONSE!\n"));
417 if (n->state == NAME_QUERY_CONFIRM)
419 /* XXXX remove_netbios_entry()? */
420 /* lots of things we ought to do, here. if we get here,
421 then we're in a mess: our name database doesn't match
422 reality. sort it out
424 remove_netbios_name(d,n->name.name, n->name.name_type,
425 REGISTER,n->send_ip);
430 /****************************************************************************
431 response from a name query for DOMAIN<1b>
432 NAME_QUERY_DOMAIN is dealt with here - we are trying to become a domain
433 master browser and WINS replied - check it's our address.
434 ****************************************************************************/
435 static void response_name_query_domain(struct nmb_name *ans_name,
436 struct nmb_packet *nmb,
437 struct response_record *n, struct subnet_record *d)
439 DEBUG(4, ("response_name_query_domain: Got %s response from %s for query \
440 for %s\n", nmb->header.rcode == 0 ? "success" : "failure",
441 inet_ntoa(n->send_ip), namestr(ans_name)));
443 /* Check the name is correct and ip address returned is our own. If it is then we
444 just remove the response record.
446 if (name_equal(&n->name, ans_name) && (nmb->header.rcode == 0) && (nmb->answers->rdata))
448 struct in_addr found_ip;
450 putip((char*)&found_ip,&nmb->answers->rdata[2]);
451 /* Samba 1.9.16p11 servers seem to return the broadcast address for this
452 query. */
453 if (ismyip(found_ip) || ip_equal(wins_ip, found_ip) || ip_equal(ipzero, found_ip))
455 DEBUG(4, ("response_name_query_domain: WINS server returned our ip \
456 address. Pretending we never received response.\n"));
457 n->num_msgs = 0;
458 n->repeat_count = 0;
459 n->repeat_time = 0;
461 else
463 DEBUG(0,("response_name_query_domain: WINS server already has a \
464 domain master browser registered %s at address %s\n",
465 namestr(ans_name), inet_ntoa(found_ip)));
468 else
470 /* Negative/incorrect response. No domain master
471 browser was registered - pretend we didn't get this response.
473 n->num_msgs = 0;
474 n->repeat_count = 0;
475 n->repeat_time = 0;
480 /****************************************************************************
481 report the response record type
482 ****************************************************************************/
483 static void debug_rr_type(int rr_type)
485 switch (rr_type)
487 case NMB_STATUS: DEBUG(3,("Name status ")); break;
488 case NMB_QUERY : DEBUG(3,("Name query ")); break;
489 case NMB_REG : DEBUG(3,("Name registration ")); break;
490 case NMB_REL : DEBUG(3,("Name release ")); break;
491 default : DEBUG(1,("wrong response packet type received")); break;
495 /****************************************************************************
496 report the response record nmbd state
497 ****************************************************************************/
498 void debug_state_type(int state)
500 /* report the state type to help debugging */
501 switch (state)
503 case NAME_QUERY_DOM_SRV_CHK : DEBUG(4,("NAME_QUERY_DOM_SRV_CHK\n")); break;
504 case NAME_QUERY_SRV_CHK : DEBUG(4,("NAME_QUERY_SRV_CHK\n")); break;
505 case NAME_QUERY_FIND_MST : DEBUG(4,("NAME_QUERY_FIND_MST\n")); break;
506 case NAME_QUERY_MST_CHK : DEBUG(4,("NAME_QUERY_MST_CHK\n")); break;
507 case NAME_QUERY_CONFIRM : DEBUG(4,("NAME_QUERY_CONFIRM\n")); break;
508 case NAME_QUERY_SYNC_LOCAL : DEBUG(4,("NAME_QUERY_SYNC_LOCAL\n")); break;
509 case NAME_QUERY_SYNC_REMOTE : DEBUG(4,("NAME_QUERY_SYNC_REMOTE\n")); break;
510 /* case NAME_QUERY_ANNOUNCE_HOST: DEBUG(4,("NAME_QUERY_ANNCE_HOST\n"));break; */
511 case NAME_QUERY_DOMAIN : DEBUG(4,("NAME_QUERY_DOMAIN\n")); break;
513 case NAME_REGISTER : DEBUG(4,("NAME_REGISTER\n")); break;
514 case NAME_REGISTER_CHALLENGE : DEBUG(4,("NAME_REGISTER_CHALLENGE\n"));break;
516 case NAME_RELEASE : DEBUG(4,("NAME_RELEASE\n")); break;
518 case NAME_STATUS_DOM_SRV_CHK : DEBUG(4,("NAME_STATUS_DOM_SRV_CHK\n")); break;
519 case NAME_STATUS_SRV_CHK : DEBUG(4,("NAME_STATUS_SRV_CHK\n")); break;
521 default: break;
525 /****************************************************************************
526 report any problems with the fact that a response has been received.
528 (responses for certain types of operations are only expected from one host)
529 ****************************************************************************/
530 static BOOL response_problem_check(struct response_record *n,
531 struct nmb_packet *nmb, char *ans_name)
533 switch (nmb->answers->rr_type)
535 case NMB_REL:
537 if (n->num_msgs > 1)
539 DEBUG(1,("more than one release name response received!\n"));
540 return True;
542 break;
545 case NMB_REG:
547 if (n->num_msgs > 1)
549 DEBUG(1,("more than one register name response received!\n"));
550 return True;
552 break;
555 case NMB_QUERY:
557 if (n->num_msgs > 1)
559 if (nmb->header.rcode == 0 && nmb->answers->rdata)
561 int nb_flags = nmb->answers->rdata[0];
563 if ((!NAME_GROUP(nb_flags)))
565 /* oh dear. more than one person responded to a
566 unique name.
567 there is either a network problem, a
568 configuration problem
569 or a server is mis-behaving */
571 /* XXXX mark the name as in conflict, and then let the
572 person who just responded know that they
573 must also mark it
574 as in conflict, and therefore must NOT use it.
575 see rfc1001.txt 15.1.3.5 */
577 /* this may cause problems for some
578 early versions of nmbd */
580 switch (n->state)
582 case NAME_QUERY_FIND_MST:
584 /* query for ^1^2__MSBROWSE__^2^1 expect
585 lots of responses */
586 return False;
588 /* case NAME_QUERY_ANNOUNCE_HOST: */
589 case NAME_QUERY_DOM_SRV_CHK:
590 case NAME_QUERY_SRV_CHK:
591 case NAME_QUERY_MST_CHK:
593 if (!strequal(ans_name,n->name.name))
595 /* one subnet, one master browser
596 per workgroup */
597 /* XXXX force an election? */
599 DEBUG(3,("more than one master browser replied!\n"));
600 return True;
602 break;
604 default: break;
606 DEBUG(3,("Unique Name conflict detected!\n"));
607 return True;
610 else
612 /* we have received a negative reply,
613 having already received
614 at least one response (pos/neg).
615 something's really wrong! */
617 DEBUG(3,("wierd name query problem detected!\n"));
618 return True;
623 return False;
626 #if 0
627 /****************************************************************************
628 check that the response received is compatible with the response record
629 ****************************************************************************/
630 static BOOL response_compatible(struct response_record *n,
631 struct nmb_packet *nmb)
633 switch (n->state)
635 case NAME_RELEASE:
637 if (nmb->answers->rr_type != 0x20)
639 DEBUG(1,("Name release reply has wrong answer rr_type\n"));
640 return False;
642 break;
645 case NAME_REGISTER:
647 if (nmb->answers->rr_type != 0x20)
649 DEBUG(1,("Name register reply has wrong answer rr_type\n"));
650 return False;
652 break;
655 case NAME_REGISTER_CHALLENGE: /* this is a query: we then do a register */
656 case NAME_QUERY_CONFIRM:
657 /* case NAME_QUERY_ANNOUNCE_HOST: */
658 case NAME_QUERY_SYNC_LOCAL:
659 case NAME_QUERY_SYNC_REMOTE:
660 case NAME_QUERY_DOM_SRV_CHK:
661 case NAME_QUERY_SRV_CHK:
662 case NAME_QUERY_FIND_MST:
663 case NAME_QUERY_MST_CHK:
665 if (nmb->answers->rr_type != 0x20)
667 DEBUG(1,("Name query reply has wrong answer rr_type\n"));
668 return False;
670 break;
673 case NAME_STATUS_DOM_SRV_CHK:
674 case NAME_STATUS_SRV_CHK:
676 if (nmb->answers->rr_type != 0x21)
678 DEBUG(1,("Name status reply has wrong answer rr_type\n"));
679 return False;
681 break;
684 default:
686 DEBUG(1,("unknown state type received in response_netbios_packet\n"));
687 return False;
690 return True;
692 #endif
695 /****************************************************************************
696 process the response packet received
697 ****************************************************************************/
698 static void response_process(struct subnet_record *d, struct packet_struct *p,
699 struct response_record *n, struct nmb_packet *nmb,
700 BOOL bcast, struct nmb_name *ans_name)
702 switch (n->state)
704 case NAME_RELEASE:
706 response_name_release(ans_name, d, p);
707 break;
710 case NAME_REGISTER:
712 response_name_reg(ans_name, d, p);
713 break;
716 case NAME_REGISTER_CHALLENGE:
718 response_name_query_register(nmb, ans_name, n, d);
719 break;
722 case NAME_QUERY_DOM_SRV_CHK:
723 case NAME_QUERY_SRV_CHK:
724 case NAME_QUERY_FIND_MST:
726 response_server_check(ans_name, n, d);
727 break;
730 case NAME_STATUS_DOM_SRV_CHK:
731 case NAME_STATUS_SRV_CHK:
733 response_name_status_check(p->ip, nmb, bcast, n, d);
734 break;
737 case NAME_QUERY_CONFIRM:
738 case NAME_QUERY_SYNC_LOCAL:
739 case NAME_QUERY_SYNC_REMOTE:
741 response_name_query_sync(nmb, ans_name, bcast, n, d);
742 break;
744 case NAME_QUERY_MST_CHK:
746 /* no action required here. it's when NO responses are received
747 that we need to do something. see expire_name_query_entries() */
749 DEBUG(4, ("Master browser exists for %s at %s (just checking!)\n",
750 namestr(&n->name), inet_ntoa(n->send_ip)));
751 break;
754 case NAME_QUERY_DOMAIN:
756 /* We were asking to be a domain master browser, and someone
757 replied. If it was the WINS server and the IP it is
758 returning is our own - then remove the record and pretend
759 we didn't get a response. Else we do nothing and let
760 dead_netbios_entry deal with it.
761 We can only become domain master browser
762 when no broadcast responses are received and WINS
763 either contains no entry for the DOMAIN<1b> name or
764 contains our IP address.
766 response_name_query_domain(ans_name, nmb, n, d);
767 break;
769 default:
771 DEBUG(1,("unknown state type received in response_netbios_packet\n"));
772 break;
778 /****************************************************************************
779 response from a netbios packet.
780 ****************************************************************************/
781 void response_netbios_packet(struct packet_struct *p)
783 struct nmb_packet *nmb = &p->packet.nmb;
784 struct nmb_name *ans_name = NULL;
785 BOOL bcast = nmb->header.nm_flags.bcast;
786 struct response_record *n;
787 struct subnet_record *d = NULL;
789 if (!(n = find_response_record(&d,nmb->header.name_trn_id))) {
790 DEBUG(2,("unknown netbios response (received late or from nmblookup?)\n"));
791 return;
794 if (!d)
796 DEBUG(2,("response packet: subnet %s not known\n", inet_ntoa(p->ip)));
797 return;
800 /* args wrong way round: spotted by ccm@shentel.net */
801 if (!same_net(d->bcast_ip, p->ip, d->mask_ip)) /* copes with WINS 'subnet' */
803 DEBUG(2,("response from %s. ", inet_ntoa(p->ip)));
804 DEBUG(2,("expected on subnet %s. hmm.\n", inet_ntoa(d->bcast_ip)));
807 if (nmb->answers == NULL)
809 /* hm. the packet received was a response, but with no answer. wierd! */
810 DEBUG(2,("NMB packet response from %s (bcast=%s) - UNKNOWN\n",
811 inet_ntoa(p->ip), BOOLSTR(bcast)));
812 return;
815 ans_name = &nmb->answers->rr_name;
816 DEBUG(3,("response for %s from %s (bcast=%s)\n",
817 namestr(ans_name), inet_ntoa(p->ip), BOOLSTR(bcast)));
819 debug_rr_type(nmb->answers->rr_type);
821 n->num_msgs++; /* count number of responses received */
822 n->repeat_count = 0; /* don't resend: see expire_netbios_packets() */
824 debug_state_type(n->state);
826 /* problem checking: multiple responses etc */
827 if (response_problem_check(n, nmb, ans_name->name))
828 return;
830 /* now deal with the current state */
831 response_process(d, p, n, nmb, bcast, ans_name);