nfs4acls: Introduce a helper variable
[Samba.git] / source3 / nmbd / nmbd_incomingdgrams.c
blob9a69252997bba9c1227ad73d46ab3fbb49a1a7b4
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-1998
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "../librpc/gen_ndr/svcctl.h"
25 #include "nmbd/nmbd.h"
27 extern bool found_lm_clients;
29 #if 0
31 /* XXXX note: This function is currently unsuitable for use, as it
32 does not properly check that a server is in a fit state to become
33 a backup browser before asking it to be one.
34 The code is left here to be worked on at a later date.
37 /****************************************************************************
38 Tell a server to become a backup browser
39 **************************************************************************/
41 void tell_become_backup(void)
43 struct subnet_record *subrec;
44 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
46 struct work_record *work;
47 for (work = subrec->workgrouplist; work; work = work->next)
49 struct server_record *servrec;
50 int num_servers = 0;
51 int num_backups = 0;
53 for (servrec = work->serverlist; servrec; servrec = servrec->next)
55 num_servers++;
57 if (is_myname(servrec->serv.name))
58 continue;
60 if (servrec->serv.type & SV_TYPE_BACKUP_BROWSER)
62 num_backups++;
63 continue;
66 if (servrec->serv.type & SV_TYPE_MASTER_BROWSER)
67 continue;
69 if (!(servrec->serv.type & SV_TYPE_POTENTIAL_BROWSER))
70 continue;
72 DEBUG(3,("num servers: %d num backups: %d\n",
73 num_servers, num_backups));
75 /* make first server a backup server. thereafter make every
76 tenth server a backup server */
77 if (num_backups != 0 && (num_servers+9) / num_backups > 10)
78 continue;
80 DEBUG(2,("sending become backup to %s %s for %s\n",
81 servrec->serv.name, inet_ntoa(subrec->bcast_ip),
82 work->work_group));
84 /* type 11 request from MYNAME(20) to WG(1e) for SERVER */
85 do_announce_request(servrec->serv.name, work->work_group,
86 ANN_BecomeBackup, 0x20, 0x1e, subrec->bcast_ip);
91 #endif
93 /*******************************************************************
94 Process an incoming host announcement packet.
95 *******************************************************************/
97 void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
99 struct dgram_packet *dgram = &p->packet.dgram;
100 int ttl = IVAL(buf,1)/1000;
101 unstring announce_name;
102 uint32_t servertype = IVAL(buf,23);
103 fstring comment;
104 struct work_record *work;
105 struct server_record *servrec;
106 unstring work_name;
107 unstring source_name;
109 pull_ascii_fstring(comment, buf+31);
111 pull_ascii_nstring(announce_name, sizeof(announce_name), buf+5);
112 pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name);
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) {
126 DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \
127 (was %02x) should be 0x1d. Allowing packet anyway.\n",
128 inet_ntoa(p->ip), dgram->dest_name.name_type));
129 /* Change it so it was. */
130 dgram->dest_name.name_type = 0x1d;
133 /* For a host announce the workgroup name is the destination name. */
134 pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name);
137 * Syntax servers version 5.1 send HostAnnounce packets to
138 * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
139 * instead of WORKGROUP<1d> name. So to fix this we check if
140 * the workgroup name is our own name, and if so change it
141 * to be our primary workgroup name.
144 if(strequal(work_name, lp_netbios_name()))
145 unstrcpy(work_name,lp_workgroup());
148 * We are being very agressive here in adding a workgroup
149 * name on the basis of a host announcing itself as being
150 * in that workgroup. Maybe we should wait for the workgroup
151 * announce instead ? JRA.
154 work = find_workgroup_on_subnet(subrec, work_name);
156 if(servertype != 0) {
157 if (work ==NULL ) {
158 /* We have no record of this workgroup. Add it. */
159 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
160 goto done;
163 if((servrec = find_server_in_workgroup( work, announce_name))==NULL) {
164 /* If this server is not already in the workgroup, add it. */
165 create_server_on_workgroup(work, announce_name,
166 servertype|SV_TYPE_LOCAL_LIST_ONLY,
167 ttl, comment);
168 } else {
169 /* Update the record. */
170 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
171 update_server_ttl( servrec, ttl);
172 strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment));
174 } else {
176 * This server is announcing it is going down. Remove it from the
177 * workgroup.
179 if(!is_myname(announce_name) && (work != NULL) &&
180 ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) {
181 remove_server_from_workgroup( work, servrec);
185 subrec->work_changed = True;
186 done:
187 return;
190 /*******************************************************************
191 Process an incoming WORKGROUP announcement packet.
192 *******************************************************************/
194 void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
196 struct dgram_packet *dgram = &p->packet.dgram;
197 int ttl = IVAL(buf,1)/1000;
198 unstring workgroup_announce_name;
199 unstring master_name;
200 uint32_t servertype = IVAL(buf,23);
201 struct work_record *work;
202 unstring source_name;
203 unstring dest_name;
205 pull_ascii_nstring(workgroup_announce_name,sizeof(workgroup_announce_name),buf+5);
206 pull_ascii_nstring(master_name,sizeof(master_name),buf+31);
207 pull_ascii_nstring(source_name,sizeof(source_name),dgram->source_name.name);
208 pull_ascii_nstring(dest_name,sizeof(dest_name),dgram->dest_name.name);
210 DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \
211 %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
212 nmb_namestr(&dgram->dest_name),workgroup_announce_name));
214 DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n",
215 ttl, servertype, master_name));
217 /* Workgroup announcements must only go to the MSBROWSE name. */
218 if (!strequal(dest_name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) {
219 DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n",
220 inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
221 goto done;
224 if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) {
225 /* We have no record of this workgroup. Add it. */
226 if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL)
227 goto done;
228 } else {
229 /* Update the workgroup death_time. */
230 update_workgroup_ttl(work, ttl);
233 if(*work->local_master_browser_name == '\0') {
234 /* Set the master browser name. */
235 set_workgroup_local_master_browser_name( work, master_name );
238 subrec->work_changed = True;
240 done:
241 return;
244 /*******************************************************************
245 Process an incoming local master browser announcement packet.
246 *******************************************************************/
248 void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
250 struct dgram_packet *dgram = &p->packet.dgram;
251 int ttl = IVAL(buf,1)/1000;
252 unstring server_name;
253 uint32_t servertype = IVAL(buf,23);
254 fstring comment;
255 unstring work_name;
256 struct work_record *work = NULL;
257 struct server_record *servrec;
258 unstring source_name;
260 pull_ascii_nstring(server_name,sizeof(server_name),buf+5);
261 pull_ascii_fstring(comment, buf+31);
262 pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name);
263 pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name);
265 DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \
266 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
267 nmb_namestr(&dgram->dest_name),server_name));
269 DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n",
270 ttl, servertype, comment));
272 /* A local master announcement must be sent to the name WORKGROUP<1e>. */
273 if(dgram->dest_name.name_type != 0x1e) {
274 DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \
275 (was %02x) should be 0x1e. Ignoring packet.\n",
276 inet_ntoa(p->ip), dgram->dest_name.name_type));
277 goto done;
280 /* Filter servertype to remove impossible bits. */
281 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
283 /* For a local master announce the workgroup name is the destination name. */
285 if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) {
286 /* Don't bother adding if it's a local master release announce. */
287 if(servertype == 0)
288 goto done;
290 /* We have no record of this workgroup. Add it. */
291 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
292 goto done;
295 /* If we think we're the local master browser for this workgroup,
296 we should never have got this packet. We don't see our own
297 packets.
299 if(AM_LOCAL_MASTER_BROWSER(work)) {
300 DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \
301 a local master browser for workgroup %s and we think we are master. Forcing election.\n",
302 server_name, inet_ntoa(p->ip), work_name));
304 /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when
305 they have become a local master browser once, they will never
306 stop sending local master announcements. To fix this we send
307 them a reset browser packet, with level 0x2 on the __SAMBA__
308 name that only they should be listening to. */
310 send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip);
312 /* We should demote ourself and force an election. */
314 unbecome_local_master_browser( subrec, work, True);
316 /* The actual election requests are handled in nmbd_election.c */
317 goto done;
320 /* Find the server record on this workgroup. If it doesn't exist, add it. */
322 if(servertype != 0) {
323 if((servrec = find_server_in_workgroup( work, server_name))==NULL) {
324 /* If this server is not already in the workgroup, add it. */
325 create_server_on_workgroup(work, server_name,
326 servertype|SV_TYPE_LOCAL_LIST_ONLY,
327 ttl, comment);
328 } else {
329 /* Update the record. */
330 if (servrec->serv.type !=
331 (servertype|SV_TYPE_LOCAL_LIST_ONLY)) {
332 servrec->serv.type =
333 servertype|SV_TYPE_LOCAL_LIST_ONLY;
334 subrec->work_changed = true;
336 if (!strequal(servrec->serv.comment,comment)) {
337 strlcpy(servrec->serv.comment,
338 comment,
339 sizeof(servrec->serv.comment));
340 subrec->work_changed = true;
342 update_server_ttl(servrec, ttl);
345 if (!strequal(work->local_master_browser_name, server_name)) {
346 set_workgroup_local_master_browser_name( work, server_name );
347 subrec->work_changed = true;
349 } else {
351 * This server is announcing it is going down. Remove it from the
352 * workgroup.
354 if(!is_myname(server_name) &&
355 ((servrec = find_server_in_workgroup( work, server_name))!=NULL)) {
356 remove_server_from_workgroup( work, servrec);
360 done:
361 return;
364 /*******************************************************************
365 Process a domain master announcement frame.
366 Domain master browsers receive these from local masters. The Domain
367 master should then issue a sync with the local master, asking for
368 that machines local server list.
369 ******************************************************************/
371 void process_master_browser_announce(struct subnet_record *subrec,
372 struct packet_struct *p,const char *buf)
374 unstring local_master_name;
375 struct work_record *work;
376 struct browse_cache_record *browrec;
378 pull_ascii_nstring(local_master_name,sizeof(local_master_name),buf);
380 DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n",
381 local_master_name, inet_ntoa(p->ip)));
383 if (!lp_domain_master()) {
384 DEBUG(0,("process_master_browser_announce: Not configured as domain \
385 master - ignoring master announce.\n"));
386 goto done;
389 if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL) {
390 DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n",
391 lp_workgroup(), subrec->subnet_name));
392 goto done;
395 if(!AM_DOMAIN_MASTER_BROWSER(work)) {
396 DEBUG(0,("process_master_browser_announce: Local master announce made to us from \
397 %s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip)));
398 goto done;
401 /* Add this host as a local master browser entry on the browse lists.
402 This causes a sync request to be made to it at a later date.
405 if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL) {
406 /* Add it. */
407 create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip);
408 } else {
409 update_browser_death_time(browrec);
412 done:
413 return;
416 /*******************************************************************
417 Process an incoming LanMan host announcement packet.
418 *******************************************************************/
420 void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf, int len)
422 struct dgram_packet *dgram = &p->packet.dgram;
423 uint32_t servertype = IVAL(buf,1);
424 int osmajor=CVAL(buf,5); /* major version of node software */
425 int osminor=CVAL(buf,6); /* minor version of node software */
426 int ttl = SVAL(buf,7);
427 unstring announce_name;
428 struct work_record *work;
429 struct server_record *servrec;
430 unstring work_name;
431 unstring source_name;
432 fstring comment;
433 char *s = get_safe_str_ptr(buf,len,discard_const_p(char, buf),9);
435 if (!s) {
436 goto done;
438 s = skip_string(buf,len,s);
439 if (!s) {
440 goto done;
442 pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE);
444 pull_ascii_nstring(announce_name,sizeof(announce_name),buf+9);
445 pull_ascii_nstring(source_name,sizeof(source_name),dgram->source_name.name);
446 /* For a LanMan host announce the workgroup name is the destination name. */
447 pull_ascii_nstring(work_name,sizeof(work_name),dgram->dest_name.name);
449 DEBUG(3,("process_lm_host_announce: LM Announcement from %s IP %s to \
450 %s for server %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
451 nmb_namestr(&dgram->dest_name),announce_name));
453 DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n",
454 osmajor, osminor, ttl, servertype,comment));
456 if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) {
457 DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \
458 originate from OS/2 Warp client. Ignoring packet.\n"));
459 /* Could have been from a Windows machine (with its LM Announce enabled),
460 or a Samba server. Then don't disrupt the current browse list. */
461 goto done;
464 /* Filter servertype to remove impossible bits. */
465 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
467 /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */
468 if(dgram->dest_name.name_type != 0x00) {
469 DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \
470 (was %02x) should be 0x00. Allowing packet anyway.\n",
471 inet_ntoa(p->ip), dgram->dest_name.name_type));
472 /* Change it so it was. */
473 dgram->dest_name.name_type = 0x00;
477 * Syntax servers version 5.1 send HostAnnounce packets to
478 * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
479 * instead of WORKGROUP<1d> name. So to fix this we check if
480 * the workgroup name is our own name, and if so change it
481 * to be our primary workgroup name. This code is probably
482 * not needed in the LanMan announce code, but it won't hurt.
485 if(strequal(work_name, lp_netbios_name()))
486 unstrcpy(work_name,lp_workgroup());
489 * We are being very agressive here in adding a workgroup
490 * name on the basis of a host announcing itself as being
491 * in that workgroup. Maybe we should wait for the workgroup
492 * announce instead ? JRA.
495 work = find_workgroup_on_subnet(subrec, work_name);
497 if(servertype != 0) {
498 if (work == NULL) {
499 /* We have no record of this workgroup. Add it. */
500 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
501 goto done;
504 if((servrec = find_server_in_workgroup( work, announce_name))==NULL) {
505 /* If this server is not already in the workgroup, add it. */
506 create_server_on_workgroup(work, announce_name,
507 servertype|SV_TYPE_LOCAL_LIST_ONLY,
508 ttl, comment);
509 } else {
510 /* Update the record. */
511 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
512 update_server_ttl( servrec, ttl);
513 strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment));
515 } else {
517 * This server is announcing it is going down. Remove it from the
518 * workgroup.
520 if(!is_myname(announce_name) && (work != NULL) &&
521 ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) {
522 remove_server_from_workgroup( work, servrec);
526 subrec->work_changed = True;
527 found_lm_clients = True;
529 done:
530 return;
533 /****************************************************************************
534 Send a backup list response.
535 *****************************************************************************/
537 static void send_backup_list_response(struct subnet_record *subrec,
538 struct work_record *work,
539 struct nmb_name *send_to_name,
540 unsigned char max_number_requested,
541 uint32_t token, struct in_addr sendto_ip,
542 int port)
544 char outbuf[1024];
545 char *p, *countptr;
546 unsigned int count = 0;
547 unstring send_to_namestr;
548 #if 0
549 struct server_record *servrec;
550 #endif
551 unstring myname;
553 memset(outbuf,'\0',sizeof(outbuf));
555 DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
556 work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
558 p = outbuf;
560 SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
561 p++;
563 countptr = p;
564 p++;
566 SIVAL(p,0,token); /* The sender's unique info. */
567 p += 4;
569 /* We always return at least one name - our own. */
570 count = 1;
571 unstrcpy(myname, lp_netbios_name());
572 if (!strupper_m(myname)) {
573 DEBUG(4,("strupper_m %s failed\n", myname));
574 return;
576 myname[15]='\0';
577 push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
579 p = skip_string(outbuf,sizeof(outbuf),p);
581 /* Look for backup browsers in this workgroup. */
583 #if 0
584 /* we don't currently send become_backup requests so we should never
585 send any other servers names out as backups for our
586 workgroup. That's why this is commented out (tridge) */
589 * NB. Note that the struct work_record here is not neccessarily
590 * attached to the subnet *subrec.
593 for (servrec = work->serverlist; servrec; servrec = servrec->next)
595 int len = PTR_DIFF(p, outbuf);
596 if((sizeof(outbuf) - len) < 16)
597 break;
599 if(count >= (unsigned int)max_number_requested)
600 break;
602 if(strnequal(servrec->serv.name, lp_netbios_name(),15))
603 continue;
605 if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER))
606 continue;
608 StrnCpy(p, servrec->serv.name, 15);
609 strupper_m(p);
610 count++;
612 DEBUG(5,("send_backup_list_response: Adding server %s number %d\n",
613 p, count));
615 p = skip_string(outbuf,sizeof(outbuf),p);
617 #endif
619 SCVAL(countptr, 0, count);
621 pull_ascii_nstring(send_to_namestr, sizeof(send_to_namestr), send_to_name->name);
623 DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n",
624 send_to_namestr, inet_ntoa(sendto_ip), count));
626 send_mailslot(True, BROWSE_MAILSLOT,
627 outbuf,PTR_DIFF(p,outbuf),
628 lp_netbios_name(), 0,
629 send_to_namestr,0,
630 sendto_ip, subrec->myip, port);
633 /*******************************************************************
634 Process a send backup list request packet.
636 A client sends a backup list request to ask for a list of servers on
637 the net that maintain server lists for a domain. A server is then
638 chosen from this list to send NetServerEnum commands to to list
639 available servers.
641 ********************************************************************/
643 void process_get_backup_list_request(struct subnet_record *subrec,
644 struct packet_struct *p,const char *buf)
646 struct dgram_packet *dgram = &p->packet.dgram;
647 struct work_record *work;
648 unsigned char max_number_requested = CVAL(buf,0);
649 uint32_t token = IVAL(buf,1); /* Sender's key index for the workgroup. */
650 int name_type = dgram->dest_name.name_type;
651 unstring workgroup_name;
652 struct subnet_record *search_subrec = subrec;
654 pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name);
656 DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n",
657 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
658 nmb_namestr(&dgram->dest_name)));
660 /* We have to be a master browser, or a domain master browser
661 for the requested workgroup. That means it must be our
662 workgroup. */
664 if(strequal(workgroup_name, lp_workgroup()) == False) {
665 DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n",
666 workgroup_name));
667 goto done;
670 if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) {
671 DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \
672 subnet %s.\n", workgroup_name, search_subrec->subnet_name));
673 goto done;
677 * If the packet was sent to WORKGROUP<1b> instead
678 * of WORKGROUP<1d> then it was unicast to us a domain master
679 * browser. Change search subrec to unicast.
682 if(name_type == 0x1b) {
683 /* We must be a domain master browser in order to
684 process this packet. */
686 if(!AM_DOMAIN_MASTER_BROWSER(work)) {
687 DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
688 and I am not a domain master browser.\n", workgroup_name));
689 goto done;
692 search_subrec = unicast_subnet;
693 } else if (name_type == 0x1d) {
694 /* We must be a local master browser in order to process this packet. */
696 if(!AM_LOCAL_MASTER_BROWSER(work)) {
697 DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
698 and I am not a local master browser.\n", workgroup_name));
699 goto done;
701 } else {
702 DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n",
703 name_type));
704 goto done;
707 send_backup_list_response(subrec, work, &dgram->source_name,
708 max_number_requested, token, p->ip, p->port);
710 done:
711 return;
714 /*******************************************************************
715 Process a reset browser state packet.
717 Diagnostic packet:
718 0x1 - Stop being a master browser and become a backup browser.
719 0x2 - Discard browse lists, stop being a master browser, try again.
720 0x4 - Stop being a master browser forever.
722 ******************************************************************/
724 void process_reset_browser(struct subnet_record *subrec,
725 struct packet_struct *p,const char *buf)
727 struct dgram_packet *dgram = &p->packet.dgram;
728 int state = CVAL(buf,0);
729 struct subnet_record *sr;
731 DEBUG(1,("process_reset_browser: received diagnostic browser reset \
732 request from %s IP %s state=0x%X\n",
733 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state));
735 /* Stop being a local master browser on all our broadcast subnets. */
736 if (state & 0x1) {
737 for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr)) {
738 struct work_record *work;
739 for (work = sr->workgrouplist; work; work = work->next) {
740 if (AM_LOCAL_MASTER_BROWSER(work))
741 unbecome_local_master_browser(sr, work, True);
746 /* Discard our browse lists. */
747 if (state & 0x2) {
749 * Calling expire_workgroups_and_servers with a -1
750 * time causes all servers not marked with a PERMANENT_TTL
751 * on the workgroup lists to be discarded, and all
752 * workgroups with empty server lists to be discarded.
753 * This means we keep our own server names and workgroup
754 * as these have a PERMANENT_TTL.
757 expire_workgroups_and_servers(-1);
760 /* Request to stop browsing altogether. */
761 if (state & 0x4)
762 DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n"));
765 /*******************************************************************
766 Process an announcement request packet.
767 We don't respond immediately, we just check it's a request for
768 our workgroup and then set the flag telling the announce code
769 in nmbd_sendannounce.c:announce_my_server_names that an
770 announcement is needed soon.
771 ******************************************************************/
773 void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
775 struct dgram_packet *dgram = &p->packet.dgram;
776 struct work_record *work;
777 unstring workgroup_name;
779 pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name);
780 DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n",
781 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
782 nmb_namestr(&dgram->dest_name)));
784 /* We only send announcement requests on our workgroup. */
785 if(strequal(workgroup_name, lp_workgroup()) == False) {
786 DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n",
787 workgroup_name));
788 goto done;
791 if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) {
792 DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
793 workgroup_name));
794 goto done;
797 work->needannounce = True;
798 done:
799 return;
802 /*******************************************************************
803 Process a LanMan announcement request packet.
804 We don't respond immediately, we just check it's a request for
805 our workgroup and then set the flag telling that we have found
806 a LanMan client (DOS or OS/2) and that we will have to start
807 sending LanMan announcements (unless specifically disabled
808 through the "lm announce" parameter in smb.conf)
809 ******************************************************************/
811 void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, const char *buf, int len)
813 struct dgram_packet *dgram = &p->packet.dgram;
814 unstring workgroup_name;
816 pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name);
817 DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n",
818 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
819 nmb_namestr(&dgram->dest_name)));
821 /* We only send announcement requests on our workgroup. */
822 if(strequal(workgroup_name, lp_workgroup()) == False) {
823 DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n",
824 workgroup_name));
825 goto done;
828 if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) {
829 DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
830 workgroup_name));
831 goto done;
834 found_lm_clients = True;
836 done:
837 return;