Try to get the compiler not to complain about assignments and truth values...
[Samba/ekacnet.git] / source / nmbd / nmbd_incomingdgrams.c
blobd10e6ec0b0d48d2184e7c908d47ebad2564967f6
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
7 Copyright (C) Jeremy Allison 1994-1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 extern pstring global_myname;
28 extern fstring global_myworkgroup;
29 extern BOOL found_lm_clients;
31 #if 0
33 /* XXXX note: This function is currently unsuitable for use, as it
34 does not properly check that a server is in a fit state to become
35 a backup browser before asking it to be one.
36 The code is left here to be worked on at a later date.
39 /****************************************************************************
40 Tell a server to become a backup browser
41 **************************************************************************/
43 void tell_become_backup(void)
45 struct subnet_record *subrec;
46 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
48 struct work_record *work;
49 for (work = subrec->workgrouplist; work; work = work->next)
51 struct server_record *servrec;
52 int num_servers = 0;
53 int num_backups = 0;
55 for (servrec = work->serverlist; servrec; servrec = servrec->next)
57 num_servers++;
59 if (is_myname(servrec->serv.name))
60 continue;
62 if (servrec->serv.type & SV_TYPE_BACKUP_BROWSER)
64 num_backups++;
65 continue;
68 if (servrec->serv.type & SV_TYPE_MASTER_BROWSER)
69 continue;
71 if (!(servrec->serv.type & SV_TYPE_POTENTIAL_BROWSER))
72 continue;
74 DEBUG(3,("num servers: %d num backups: %d\n",
75 num_servers, num_backups));
77 /* make first server a backup server. thereafter make every
78 tenth server a backup server */
79 if (num_backups != 0 && (num_servers+9) / num_backups > 10)
80 continue;
82 DEBUG(2,("sending become backup to %s %s for %s\n",
83 servrec->serv.name, inet_ntoa(subrec->bcast_ip),
84 work->work_group));
86 /* type 11 request from MYNAME(20) to WG(1e) for SERVER */
87 do_announce_request(servrec->serv.name, work->work_group,
88 ANN_BecomeBackup, 0x20, 0x1e, subrec->bcast_ip);
93 #endif
95 /*******************************************************************
96 Process an incoming host announcement packet.
97 *******************************************************************/
99 void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
101 struct dgram_packet *dgram = &p->packet.dgram;
102 int ttl = IVAL(buf,1)/1000;
103 char *announce_name = buf+5;
104 uint32 servertype = IVAL(buf,23);
105 char *comment = buf+31;
106 struct work_record *work;
107 struct server_record *servrec;
108 char *work_name;
109 char *source_name = dgram->source_name.name;
111 START_PROFILE(host_announce);
112 comment[43] = 0;
114 DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \
115 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
116 nmb_namestr(&dgram->dest_name),announce_name));
118 DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n",
119 ttl, servertype,comment));
121 /* Filter servertype to remove impossible bits. */
122 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
124 /* A host announcement must be sent to the name WORKGROUP<1d>. */
125 if(dgram->dest_name.name_type != 0x1d)
127 DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \
128 (was %02x) should be 0x1d. Allowing packet anyway.\n",
129 inet_ntoa(p->ip), dgram->dest_name.name_type));
130 /* Change it so it was. */
131 dgram->dest_name.name_type = 0x1d;
134 /* For a host announce the workgroup name is the destination name. */
135 work_name = dgram->dest_name.name;
138 * Syntax servers version 5.1 send HostAnnounce packets to
139 * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
140 * instead of WORKGROUP<1d> name. So to fix this we check if
141 * the workgroup name is our own name, and if so change it
142 * to be our primary workgroup name.
145 if(strequal(work_name, global_myname))
146 work_name = global_myworkgroup;
149 * We are being very agressive here in adding a workgroup
150 * name on the basis of a host announcing itself as being
151 * in that workgroup. Maybe we should wait for the workgroup
152 * announce instead ? JRA.
155 work = find_workgroup_on_subnet(subrec, work_name);
157 if(servertype != 0)
159 if (work ==NULL )
161 /* We have no record of this workgroup. Add it. */
162 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
163 goto done;
166 if((servrec = find_server_in_workgroup( work, announce_name))==NULL)
168 /* If this server is not already in the workgroup, add it. */
169 create_server_on_workgroup(work, announce_name,
170 servertype|SV_TYPE_LOCAL_LIST_ONLY,
171 ttl, comment);
173 else
175 /* Update the record. */
176 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
177 update_server_ttl( servrec, ttl);
178 StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
181 else
184 * This server is announcing it is going down. Remove it from the
185 * workgroup.
187 if(!is_myname(announce_name) && (work != NULL) &&
188 ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)
191 remove_server_from_workgroup( work, servrec);
194 subrec->work_changed = True;
195 done:
196 END_PROFILE(host_announce);
199 /*******************************************************************
200 Process an incoming WORKGROUP announcement packet.
201 *******************************************************************/
203 void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
205 struct dgram_packet *dgram = &p->packet.dgram;
206 int ttl = IVAL(buf,1)/1000;
207 char *workgroup_announce_name = buf+5;
208 uint32 servertype = IVAL(buf,23);
209 char *master_name = buf+31;
210 struct work_record *work;
211 char *source_name = dgram->source_name.name;
213 START_PROFILE(workgroup_announce);
214 master_name[43] = 0;
216 DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \
217 %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
218 nmb_namestr(&dgram->dest_name),workgroup_announce_name));
220 DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n",
221 ttl, servertype, master_name));
223 /* Workgroup announcements must only go to the MSBROWSE name. */
224 if (!strequal(dgram->dest_name.name, MSBROWSE) || (dgram->dest_name.name_type != 0x1))
226 DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n",
227 inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
228 goto done;
231 if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL)
233 /* We have no record of this workgroup. Add it. */
234 if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL)
235 goto done;
237 else
239 /* Update the workgroup death_time. */
240 update_workgroup_ttl(work, ttl);
243 if(*work->local_master_browser_name == '\0')
245 /* Set the master browser name. */
246 set_workgroup_local_master_browser_name( work, master_name );
249 subrec->work_changed = True;
250 done:
251 END_PROFILE(workgroup_announce);
254 /*******************************************************************
255 Process an incoming local master browser announcement packet.
256 *******************************************************************/
258 void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
260 struct dgram_packet *dgram = &p->packet.dgram;
261 int ttl = IVAL(buf,1)/1000;
262 char *server_name = buf+5;
263 uint32 servertype = IVAL(buf,23);
264 char *comment = buf+31;
265 char *work_name;
266 struct work_record *work;
267 struct server_record *servrec;
268 char *source_name = dgram->source_name.name;
270 START_PROFILE(local_master_announce);
271 comment[43] = 0;
273 DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \
274 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
275 nmb_namestr(&dgram->dest_name),server_name));
277 DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n",
278 ttl, servertype, comment));
280 /* A local master announcement must be sent to the name WORKGROUP<1e>. */
281 if(dgram->dest_name.name_type != 0x1e)
283 DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \
284 (was %02x) should be 0x1e. Ignoring packet.\n",
285 inet_ntoa(p->ip), dgram->dest_name.name_type));
286 goto done;
289 /* Filter servertype to remove impossible bits. */
290 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
292 /* For a local master announce the workgroup name is the destination name. */
293 work_name = dgram->dest_name.name;
295 if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL)
297 /* Don't bother adding if it's a local master release announce. */
298 if(servertype == 0)
299 goto done;
301 /* We have no record of this workgroup. Add it. */
302 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
303 goto done;
306 /* If we think we're the local master browser for this workgroup,
307 we should never have got this packet. We don't see our own
308 packets.
310 if(AM_LOCAL_MASTER_BROWSER(work))
312 DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \
313 a local master browser for workgroup %s and we think we are master. Forcing election.\n",
314 server_name, inet_ntoa(p->ip), work_name));
316 /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when
317 they have become a local master browser once, they will never
318 stop sending local master announcements. To fix this we send
319 them a reset browser packet, with level 0x2 on the __SAMBA__
320 name that only they should be listening to. */
322 send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip);
324 /* We should demote ourself and force an election. */
326 unbecome_local_master_browser( subrec, work, True);
328 /* The actual election requests are handled in
329 nmbd_election.c */
330 goto done;
333 /* Find the server record on this workgroup. If it doesn't exist, add it. */
335 if(servertype != 0)
337 if((servrec = find_server_in_workgroup( work, server_name))==NULL)
339 /* If this server is not already in the workgroup, add it. */
340 create_server_on_workgroup(work, server_name,
341 servertype|SV_TYPE_LOCAL_LIST_ONLY,
342 ttl, comment);
344 else
346 /* Update the record. */
347 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
348 update_server_ttl(servrec, ttl);
349 StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
352 set_workgroup_local_master_browser_name( work, server_name );
354 else
357 * This server is announcing it is going down. Remove it from the
358 * workgroup.
360 if(!is_myname(server_name) && (work != NULL) &&
361 ((servrec = find_server_in_workgroup( work, server_name))!=NULL)
364 remove_server_from_workgroup( work, servrec);
368 subrec->work_changed = True;
369 done:
370 END_PROFILE(local_master_announce);
373 /*******************************************************************
374 Process a domain master announcement frame.
375 Domain master browsers receive these from local masters. The Domain
376 master should then issue a sync with the local master, asking for
377 that machines local server list.
378 ******************************************************************/
380 void process_master_browser_announce(struct subnet_record *subrec,
381 struct packet_struct *p,char *buf)
383 char *local_master_name = buf;
384 struct work_record *work;
385 struct browse_cache_record *browrec;
387 START_PROFILE(master_browser_announce);
388 local_master_name[15] = 0;
390 DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n",
391 local_master_name, inet_ntoa(p->ip)));
393 if (!lp_domain_master())
395 DEBUG(0,("process_master_browser_announce: Not configured as domain \
396 master - ignoring master announce.\n"));
397 goto done;
400 if((work = find_workgroup_on_subnet(subrec, global_myworkgroup)) == NULL)
402 DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n",
403 global_myworkgroup, subrec->subnet_name));
404 goto done;
407 if(!AM_DOMAIN_MASTER_BROWSER(work))
409 DEBUG(0,("process_master_browser_announce: Local master announce made to us from \
410 %s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip)));
411 goto done;
414 /* Add this host as a local master browser entry on the browse lists.
415 This causes a sync request to be made to it at a later date.
418 if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL)
420 /* Add it. */
421 create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip);
423 else
424 update_browser_death_time(browrec);
425 done:
426 END_PROFILE(master_browser_announce);
429 /*******************************************************************
430 Process an incoming LanMan host announcement packet.
431 *******************************************************************/
433 void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
435 struct dgram_packet *dgram = &p->packet.dgram;
436 uint32 servertype = IVAL(buf,1);
437 int osmajor=CVAL(buf,5); /* major version of node software */
438 int osminor=CVAL(buf,6); /* minor version of node software */
439 int ttl = SVAL(buf,7);
440 char *announce_name = buf+9;
441 struct work_record *work;
442 struct server_record *servrec;
443 char *work_name;
444 char *source_name = dgram->source_name.name;
445 pstring comment;
446 char *s = buf+9;
448 START_PROFILE(lm_host_announce);
449 s = skip_string(s,1);
450 StrnCpy(comment, s, 43);
452 DEBUG(3,("process_lm_host_announce: LM Announcement from %s<%02x> IP %s to \
453 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
454 nmb_namestr(&dgram->dest_name),announce_name));
456 DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n",
457 osmajor, osminor, ttl, servertype,comment));
459 if ((osmajor < 36) || (osmajor > 38) || (osminor !=0))
461 DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \
462 originate from OS/2 Warp client. Ignoring packet.\n"));
463 /* Could have been from a Windows machine (with its LM Announce enabled),
464 or a Samba server. Then don't disrupt the current browse list. */
465 goto done;
468 /* Filter servertype to remove impossible bits. */
469 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
471 /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */
472 if(dgram->dest_name.name_type != 0x00)
474 DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \
475 (was %02x) should be 0x00. Allowing packet anyway.\n",
476 inet_ntoa(p->ip), dgram->dest_name.name_type));
477 /* Change it so it was. */
478 dgram->dest_name.name_type = 0x00;
481 /* For a LanMan host announce the workgroup name is the destination name. */
482 work_name = dgram->dest_name.name;
485 * Syntax servers version 5.1 send HostAnnounce packets to
486 * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
487 * instead of WORKGROUP<1d> name. So to fix this we check if
488 * the workgroup name is our own name, and if so change it
489 * to be our primary workgroup name. This code is probably
490 * not needed in the LanMan announce code, but it won't hurt.
493 if(strequal(work_name, global_myname))
494 work_name = global_myworkgroup;
497 * We are being very agressive here in adding a workgroup
498 * name on the basis of a host announcing itself as being
499 * in that workgroup. Maybe we should wait for the workgroup
500 * announce instead ? JRA.
503 work = find_workgroup_on_subnet(subrec, work_name);
505 if(servertype != 0)
507 if (work == NULL)
509 /* We have no record of this workgroup. Add it. */
510 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
511 goto done;
514 if((servrec = find_server_in_workgroup( work, announce_name))==NULL)
516 /* If this server is not already in the workgroup, add it. */
517 create_server_on_workgroup(work, announce_name,
518 servertype|SV_TYPE_LOCAL_LIST_ONLY,
519 ttl, comment);
521 else
523 /* Update the record. */
524 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
525 update_server_ttl( servrec, ttl);
526 StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
529 else
532 * This server is announcing it is going down. Remove it from the
533 * workgroup.
535 if(!is_myname(announce_name) && (work != NULL) &&
536 ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)
539 remove_server_from_workgroup( work, servrec);
543 subrec->work_changed = True;
544 found_lm_clients = True;
545 done:
546 END_PROFILE(lm_host_announce);
549 /****************************************************************************
550 Send a backup list response.
551 *****************************************************************************/
552 static void send_backup_list_response(struct subnet_record *subrec,
553 struct work_record *work,
554 struct nmb_name *send_to_name,
555 unsigned char max_number_requested,
556 uint32 token, struct in_addr sendto_ip,
557 int port)
559 char outbuf[1024];
560 char *p, *countptr;
561 unsigned int count = 0;
562 #if 0
563 struct server_record *servrec;
564 #endif
566 memset(outbuf,'\0',sizeof(outbuf));
568 DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
569 work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
571 p = outbuf;
573 SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
574 p++;
576 countptr = p;
577 p++;
579 SIVAL(p,0,token); /* The sender's unique info. */
580 p += 4;
582 /* We always return at least one name - our own. */
583 count = 1;
584 StrnCpy(p,global_myname,15);
585 strupper(p);
586 p = skip_string(p,1);
588 /* Look for backup browsers in this workgroup. */
590 #if 0
591 /* we don't currently send become_backup requests so we should never
592 send any other servers names out as backups for our
593 workgroup. That's why this is commented out (tridge) */
596 * NB. Note that the struct work_record here is not neccessarily
597 * attached to the subnet *subrec.
600 for (servrec = work->serverlist; servrec; servrec = servrec->next)
602 int len = PTR_DIFF(p, outbuf);
603 if((sizeof(outbuf) - len) < 16)
604 break;
606 if(count >= (unsigned int)max_number_requested)
607 break;
609 if(strnequal(servrec->serv.name, global_myname,15))
610 continue;
612 if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER))
613 continue;
615 StrnCpy(p, servrec->serv.name, 15);
616 strupper(p);
617 count++;
619 DEBUG(5,("send_backup_list_response: Adding server %s number %d\n",
620 p, count));
622 p = skip_string(p,1);
624 #endif
626 SCVAL(countptr, 0, count);
628 DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n",
629 send_to_name->name, inet_ntoa(sendto_ip), count));
631 send_mailslot(True, BROWSE_MAILSLOT,
632 outbuf,PTR_DIFF(p,outbuf),
633 global_myname, 0,
634 send_to_name->name,0,
635 sendto_ip, subrec->myip, port);
638 /*******************************************************************
639 Process a send backup list request packet.
641 A client sends a backup list request to ask for a list of servers on
642 the net that maintain server lists for a domain. A server is then
643 chosen from this list to send NetServerEnum commands to to list
644 available servers.
646 ********************************************************************/
648 void process_get_backup_list_request(struct subnet_record *subrec,
649 struct packet_struct *p,char *buf)
651 struct dgram_packet *dgram = &p->packet.dgram;
652 struct work_record *work;
653 unsigned char max_number_requested = CVAL(buf,0);
654 uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */
655 int name_type = dgram->dest_name.name_type;
656 char *workgroup_name = dgram->dest_name.name;
657 struct subnet_record *search_subrec = subrec;
659 START_PROFILE(get_backup_list);
660 DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n",
661 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
662 nmb_namestr(&dgram->dest_name)));
664 /* We have to be a master browser, or a domain master browser
665 for the requested workgroup. That means it must be our
666 workgroup. */
668 if(strequal(workgroup_name, global_myworkgroup) == False)
670 DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n",
671 workgroup_name));
672 goto done;
675 if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL)
677 DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \
678 subnet %s.\n", workgroup_name, search_subrec->subnet_name));
679 goto done;
683 * If the packet was sent to WORKGROUP<1b> instead
684 * of WORKGROUP<1d> then it was unicast to us a domain master
685 * browser. Change search subrec to unicast.
688 if(name_type == 0x1b)
690 /* We must be a domain master browser in order to
691 process this packet. */
693 if(!AM_DOMAIN_MASTER_BROWSER(work))
695 DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
696 and I am not a domain master browser.\n", workgroup_name));
697 goto done;
700 search_subrec = unicast_subnet;
702 else if (name_type == 0x1d)
704 /* We must be a local master browser in order to
705 process this packet. */
707 if(!AM_LOCAL_MASTER_BROWSER(work))
709 DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
710 and I am not a local master browser.\n", workgroup_name));
711 goto done;
714 else
716 DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n",
717 name_type));
718 goto done;
721 send_backup_list_response(subrec, work, &dgram->source_name,
722 max_number_requested, token, p->ip, p->port);
723 done:
724 END_PROFILE(get_backup_list);
727 /*******************************************************************
728 Process a reset browser state packet.
730 Diagnostic packet:
731 0x1 - Stop being a master browser and become a backup browser.
732 0x2 - Discard browse lists, stop being a master browser, try again.
733 0x4 - Stop being a master browser forever.
735 ******************************************************************/
737 void process_reset_browser(struct subnet_record *subrec,
738 struct packet_struct *p,char *buf)
740 struct dgram_packet *dgram = &p->packet.dgram;
741 int state = CVAL(buf,0);
742 struct subnet_record *sr;
744 START_PROFILE(reset_browser);
745 DEBUG(1,("process_reset_browser: received diagnostic browser reset \
746 request from %s IP %s state=0x%X\n",
747 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state));
749 /* Stop being a local master browser on all our broadcast subnets. */
750 if (state & 0x1)
752 for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr))
754 struct work_record *work;
755 for (work = sr->workgrouplist; work; work = work->next)
757 if (AM_LOCAL_MASTER_BROWSER(work))
758 unbecome_local_master_browser(sr, work, True);
763 /* Discard our browse lists. */
764 if (state & 0x2)
767 * Calling expire_workgroups_and_servers with a -1
768 * time causes all servers not marked with a PERMANENT_TTL
769 * on the workgroup lists to be discarded, and all
770 * workgroups with empty server lists to be discarded.
771 * This means we keep our own server names and workgroup
772 * as these have a PERMANENT_TTL.
775 expire_workgroups_and_servers(-1);
778 /* Request to stop browsing altogether. */
779 if (state & 0x4)
780 DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n"));
782 END_PROFILE(reset_browser);
785 /*******************************************************************
786 Process an announcement request packet.
787 We don't respond immediately, we just check it's a request for
788 our workgroup and then set the flag telling the announce code
789 in nmbd_sendannounce.c:announce_my_server_names that an
790 announcement is needed soon.
791 ******************************************************************/
793 void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
795 struct dgram_packet *dgram = &p->packet.dgram;
796 struct work_record *work;
797 char *workgroup_name = dgram->dest_name.name;
799 START_PROFILE(announce_request);
800 DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n",
801 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
802 nmb_namestr(&dgram->dest_name)));
804 /* We only send announcement requests on our workgroup. */
805 if(strequal(workgroup_name, global_myworkgroup) == False)
807 DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n",
808 workgroup_name));
809 goto done;
812 if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL)
814 DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
815 workgroup_name));
816 goto done;
819 work->needannounce = True;
820 done:
821 END_PROFILE(lm_host_announce);
824 /*******************************************************************
825 Process a LanMan announcement request packet.
826 We don't respond immediately, we just check it's a request for
827 our workgroup and then set the flag telling that we have found
828 a LanMan client (DOS or OS/2) and that we will have to start
829 sending LanMan announcements (unless specifically disabled
830 through the "lm announce" parameter in smb.conf)
831 ******************************************************************/
833 void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
835 struct dgram_packet *dgram = &p->packet.dgram;
836 char *workgroup_name = dgram->dest_name.name;
838 START_PROFILE(lm_announce_request);
839 DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n",
840 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
841 nmb_namestr(&dgram->dest_name)));
843 /* We only send announcement requests on our workgroup. */
844 if(strequal(workgroup_name, global_myworkgroup) == False)
846 DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n",
847 workgroup_name));
848 goto done;
851 if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL)
853 DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
854 workgroup_name));
855 goto done;
858 found_lm_clients = True;
859 done:
860 END_PROFILE(lm_host_announce);