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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 extern BOOL found_lm_clients;
30 /* XXXX note: This function is currently unsuitable for use, as it
31 does not properly check that a server is in a fit state to become
32 a backup browser before asking it to be one.
33 The code is left here to be worked on at a later date.
36 /****************************************************************************
37 Tell a server to become a backup browser
38 **************************************************************************/
40 void tell_become_backup(void)
42 struct subnet_record *subrec;
43 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
45 struct work_record *work;
46 for (work = subrec->workgrouplist; work; work = work->next)
48 struct server_record *servrec;
52 for (servrec = work->serverlist; servrec; servrec = servrec->next)
56 if (is_myname(servrec->serv.name))
59 if (servrec->serv.type & SV_TYPE_BACKUP_BROWSER)
65 if (servrec->serv.type & SV_TYPE_MASTER_BROWSER)
68 if (!(servrec->serv.type & SV_TYPE_POTENTIAL_BROWSER))
71 DEBUG(3,("num servers: %d num backups: %d\n",
72 num_servers, num_backups));
74 /* make first server a backup server. thereafter make every
75 tenth server a backup server */
76 if (num_backups != 0 && (num_servers+9) / num_backups > 10)
79 DEBUG(2,("sending become backup to %s %s for %s\n",
80 servrec->serv.name, inet_ntoa(subrec->bcast_ip),
83 /* type 11 request from MYNAME(20) to WG(1e) for SERVER */
84 do_announce_request(servrec->serv.name, work->work_group,
85 ANN_BecomeBackup, 0x20, 0x1e, subrec->bcast_ip);
92 /*******************************************************************
93 Process an incoming host announcement packet.
94 *******************************************************************/
96 void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
98 struct dgram_packet *dgram = &p->packet.dgram;
99 int ttl = IVAL(buf,1)/1000;
100 nstring announce_name;
101 uint32 servertype = IVAL(buf,23);
103 struct work_record *work;
104 struct server_record *servrec;
108 START_PROFILE(host_announce);
110 pull_ascii_fstring(comment, buf+31);
113 pull_ascii_nstring(announce_name, buf+5);
114 pull_ascii_nstring(source_name, dgram->source_name.name);
116 DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \
117 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
118 nmb_namestr(&dgram->dest_name),announce_name));
120 DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n",
121 ttl, servertype,comment));
123 /* Filter servertype to remove impossible bits. */
124 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
126 /* A host announcement must be sent to the name WORKGROUP<1d>. */
127 if(dgram->dest_name.name_type != 0x1d) {
128 DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \
129 (was %02x) should be 0x1d. Allowing packet anyway.\n",
130 inet_ntoa(p->ip), dgram->dest_name.name_type));
131 /* Change it so it was. */
132 dgram->dest_name.name_type = 0x1d;
135 /* For a host announce the workgroup name is the destination name. */
136 pull_ascii_nstring(work_name, dgram->dest_name.name);
139 * Syntax servers version 5.1 send HostAnnounce packets to
140 * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
141 * instead of WORKGROUP<1d> name. So to fix this we check if
142 * the workgroup name is our own name, and if so change it
143 * to be our primary workgroup name.
146 if(strequal(work_name, global_myname()))
147 nstrcpy(work_name,lp_workgroup());
150 * We are being very agressive here in adding a workgroup
151 * name on the basis of a host announcing itself as being
152 * in that workgroup. Maybe we should wait for the workgroup
153 * announce instead ? JRA.
156 work = find_workgroup_on_subnet(subrec, work_name);
158 if(servertype != 0) {
160 /* We have no record of this workgroup. Add it. */
161 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
165 if((servrec = find_server_in_workgroup( work, announce_name))==NULL) {
166 /* If this server is not already in the workgroup, add it. */
167 create_server_on_workgroup(work, announce_name,
168 servertype|SV_TYPE_LOCAL_LIST_ONLY,
171 /* Update the record. */
172 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
173 update_server_ttl( servrec, ttl);
174 fstrcpy(servrec->serv.comment,comment);
178 * This server is announcing it is going down. Remove it from the
181 if(!is_myname(announce_name) && (work != NULL) &&
182 ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) {
183 remove_server_from_workgroup( work, servrec);
187 subrec->work_changed = True;
190 END_PROFILE(host_announce);
193 /*******************************************************************
194 Process an incoming WORKGROUP announcement packet.
195 *******************************************************************/
197 void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
199 struct dgram_packet *dgram = &p->packet.dgram;
200 int ttl = IVAL(buf,1)/1000;
201 nstring workgroup_announce_name;
203 uint32 servertype = IVAL(buf,23);
204 struct work_record *work;
208 START_PROFILE(workgroup_announce);
210 pull_ascii_nstring(workgroup_announce_name,buf+5);
211 pull_ascii_nstring(master_name,buf+31);
213 pull_ascii_nstring(source_name,dgram->source_name.name);
214 pull_ascii_nstring(dest_name,dgram->dest_name.name);
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(dest_name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) {
225 DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n",
226 inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
230 if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) {
231 /* We have no record of this workgroup. Add it. */
232 if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL)
235 /* Update the workgroup death_time. */
236 update_workgroup_ttl(work, ttl);
239 if(*work->local_master_browser_name == '\0') {
240 /* Set the master browser name. */
241 set_workgroup_local_master_browser_name( work, master_name );
244 subrec->work_changed = True;
248 END_PROFILE(workgroup_announce);
251 /*******************************************************************
252 Process an incoming local master browser announcement packet.
253 *******************************************************************/
255 void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
257 struct dgram_packet *dgram = &p->packet.dgram;
258 int ttl = IVAL(buf,1)/1000;
260 uint32 servertype = IVAL(buf,23);
263 struct work_record *work;
264 struct server_record *servrec;
267 START_PROFILE(local_master_announce);
269 pull_ascii_nstring(server_name,buf+5);
270 pull_ascii_fstring(comment, buf+31);
272 pull_ascii_nstring(source_name, dgram->source_name.name);
273 pull_ascii_nstring(work_name, dgram->dest_name.name);
275 DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \
276 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
277 nmb_namestr(&dgram->dest_name),server_name));
279 DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n",
280 ttl, servertype, comment));
282 /* A local master announcement must be sent to the name WORKGROUP<1e>. */
283 if(dgram->dest_name.name_type != 0x1e) {
284 DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \
285 (was %02x) should be 0x1e. Ignoring packet.\n",
286 inet_ntoa(p->ip), dgram->dest_name.name_type));
290 /* Filter servertype to remove impossible bits. */
291 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
293 /* For a local master announce the workgroup name is the destination name. */
295 if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) {
296 /* Don't bother adding if it's a local master release announce. */
300 /* We have no record of this workgroup. Add it. */
301 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
305 /* If we think we're the local master browser for this workgroup,
306 we should never have got this packet. We don't see our own
309 if(AM_LOCAL_MASTER_BROWSER(work)) {
310 DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \
311 a local master browser for workgroup %s and we think we are master. Forcing election.\n",
312 server_name, inet_ntoa(p->ip), work_name));
314 /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when
315 they have become a local master browser once, they will never
316 stop sending local master announcements. To fix this we send
317 them a reset browser packet, with level 0x2 on the __SAMBA__
318 name that only they should be listening to. */
320 send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip);
322 /* We should demote ourself and force an election. */
324 unbecome_local_master_browser( subrec, work, True);
326 /* The actual election requests are handled in nmbd_election.c */
330 /* Find the server record on this workgroup. If it doesn't exist, add it. */
332 if(servertype != 0) {
333 if((servrec = find_server_in_workgroup( work, server_name))==NULL) {
334 /* If this server is not already in the workgroup, add it. */
335 create_server_on_workgroup(work, server_name,
336 servertype|SV_TYPE_LOCAL_LIST_ONLY,
339 /* Update the record. */
340 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
341 update_server_ttl(servrec, ttl);
342 fstrcpy(servrec->serv.comment,comment);
345 set_workgroup_local_master_browser_name( work, server_name );
348 * This server is announcing it is going down. Remove it from the
351 if(!is_myname(server_name) && (work != NULL) &&
352 ((servrec = find_server_in_workgroup( work, server_name))!=NULL)) {
353 remove_server_from_workgroup( work, servrec);
357 subrec->work_changed = True;
360 END_PROFILE(local_master_announce);
363 /*******************************************************************
364 Process a domain master announcement frame.
365 Domain master browsers receive these from local masters. The Domain
366 master should then issue a sync with the local master, asking for
367 that machines local server list.
368 ******************************************************************/
370 void process_master_browser_announce(struct subnet_record *subrec,
371 struct packet_struct *p,char *buf)
373 nstring local_master_name;
374 struct work_record *work;
375 struct browse_cache_record *browrec;
377 START_PROFILE(master_browser_announce);
379 pull_ascii_nstring(local_master_name,buf);
381 DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n",
382 local_master_name, inet_ntoa(p->ip)));
384 if (!lp_domain_master()) {
385 DEBUG(0,("process_master_browser_announce: Not configured as domain \
386 master - ignoring master announce.\n"));
390 if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL) {
391 DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n",
392 lp_workgroup(), subrec->subnet_name));
396 if(!AM_DOMAIN_MASTER_BROWSER(work)) {
397 DEBUG(0,("process_master_browser_announce: Local master announce made to us from \
398 %s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip)));
402 /* Add this host as a local master browser entry on the browse lists.
403 This causes a sync request to be made to it at a later date.
406 if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL) {
408 create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip);
410 update_browser_death_time(browrec);
415 END_PROFILE(master_browser_announce);
418 /*******************************************************************
419 Process an incoming LanMan host announcement packet.
420 *******************************************************************/
422 void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
424 struct dgram_packet *dgram = &p->packet.dgram;
425 uint32 servertype = IVAL(buf,1);
426 int osmajor=CVAL(buf,5); /* major version of node software */
427 int osminor=CVAL(buf,6); /* minor version of node software */
428 int ttl = SVAL(buf,7);
429 nstring announce_name;
430 struct work_record *work;
431 struct server_record *servrec;
437 START_PROFILE(lm_host_announce);
438 s = skip_string(s,1);
439 pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE);
441 pull_ascii_nstring(announce_name,buf+9);
442 pull_ascii_nstring(source_name,dgram->source_name.name);
443 /* For a LanMan host announce the workgroup name is the destination name. */
444 pull_ascii_nstring(work_name,dgram->dest_name.name);
446 DEBUG(3,("process_lm_host_announce: LM Announcement from %s IP %s to \
447 %s for server %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
448 nmb_namestr(&dgram->dest_name),announce_name));
450 DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n",
451 osmajor, osminor, ttl, servertype,comment));
453 if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) {
454 DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \
455 originate from OS/2 Warp client. Ignoring packet.\n"));
456 /* Could have been from a Windows machine (with its LM Announce enabled),
457 or a Samba server. Then don't disrupt the current browse list. */
461 /* Filter servertype to remove impossible bits. */
462 servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
464 /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */
465 if(dgram->dest_name.name_type != 0x00) {
466 DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \
467 (was %02x) should be 0x00. Allowing packet anyway.\n",
468 inet_ntoa(p->ip), dgram->dest_name.name_type));
469 /* Change it so it was. */
470 dgram->dest_name.name_type = 0x00;
474 * Syntax servers version 5.1 send HostAnnounce packets to
475 * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
476 * instead of WORKGROUP<1d> name. So to fix this we check if
477 * the workgroup name is our own name, and if so change it
478 * to be our primary workgroup name. This code is probably
479 * not needed in the LanMan announce code, but it won't hurt.
482 if(strequal(work_name, global_myname()))
483 nstrcpy(work_name,lp_workgroup());
486 * We are being very agressive here in adding a workgroup
487 * name on the basis of a host announcing itself as being
488 * in that workgroup. Maybe we should wait for the workgroup
489 * announce instead ? JRA.
492 work = find_workgroup_on_subnet(subrec, work_name);
494 if(servertype != 0) {
496 /* We have no record of this workgroup. Add it. */
497 if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
501 if((servrec = find_server_in_workgroup( work, announce_name))==NULL) {
502 /* If this server is not already in the workgroup, add it. */
503 create_server_on_workgroup(work, announce_name,
504 servertype|SV_TYPE_LOCAL_LIST_ONLY,
507 /* Update the record. */
508 servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
509 update_server_ttl( servrec, ttl);
510 fstrcpy(servrec->serv.comment,comment);
514 * This server is announcing it is going down. Remove it from the
517 if(!is_myname(announce_name) && (work != NULL) &&
518 ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) {
519 remove_server_from_workgroup( work, servrec);
523 subrec->work_changed = True;
524 found_lm_clients = True;
528 END_PROFILE(lm_host_announce);
531 /****************************************************************************
532 Send a backup list response.
533 *****************************************************************************/
535 static void send_backup_list_response(struct subnet_record *subrec,
536 struct work_record *work,
537 struct nmb_name *send_to_name,
538 unsigned char max_number_requested,
539 uint32 token, struct in_addr sendto_ip,
544 unsigned int count = 0;
545 nstring send_to_namestr;
547 struct server_record *servrec;
551 memset(outbuf,'\0',sizeof(outbuf));
553 DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
554 work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
558 SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
564 SIVAL(p,0,token); /* The sender's unique info. */
567 /* We always return at least one name - our own. */
569 fstrcpy(myname, global_myname());
572 push_pstring_base(p, myname, outbuf);
574 p = skip_string(p,1);
576 /* Look for backup browsers in this workgroup. */
579 /* we don't currently send become_backup requests so we should never
580 send any other servers names out as backups for our
581 workgroup. That's why this is commented out (tridge) */
584 * NB. Note that the struct work_record here is not neccessarily
585 * attached to the subnet *subrec.
588 for (servrec = work->serverlist; servrec; servrec = servrec->next)
590 int len = PTR_DIFF(p, outbuf);
591 if((sizeof(outbuf) - len) < 16)
594 if(count >= (unsigned int)max_number_requested)
597 if(strnequal(servrec->serv.name, global_myname(),15))
600 if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER))
603 StrnCpy(p, servrec->serv.name, 15);
607 DEBUG(5,("send_backup_list_response: Adding server %s number %d\n",
610 p = skip_string(p,1);
614 SCVAL(countptr, 0, count);
616 pull_ascii_nstring(send_to_namestr, send_to_name->name);
618 DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n",
619 send_to_namestr, inet_ntoa(sendto_ip), count));
621 send_mailslot(True, BROWSE_MAILSLOT,
622 outbuf,PTR_DIFF(p,outbuf),
625 sendto_ip, subrec->myip, port);
628 /*******************************************************************
629 Process a send backup list request packet.
631 A client sends a backup list request to ask for a list of servers on
632 the net that maintain server lists for a domain. A server is then
633 chosen from this list to send NetServerEnum commands to to list
636 ********************************************************************/
638 void process_get_backup_list_request(struct subnet_record *subrec,
639 struct packet_struct *p,char *buf)
641 struct dgram_packet *dgram = &p->packet.dgram;
642 struct work_record *work;
643 unsigned char max_number_requested = CVAL(buf,0);
644 uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */
645 int name_type = dgram->dest_name.name_type;
646 nstring workgroup_name;
647 struct subnet_record *search_subrec = subrec;
649 START_PROFILE(get_backup_list);
650 pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
652 DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n",
653 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
654 nmb_namestr(&dgram->dest_name)));
656 /* We have to be a master browser, or a domain master browser
657 for the requested workgroup. That means it must be our
660 if(strequal(workgroup_name, lp_workgroup()) == False) {
661 DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n",
666 if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) {
667 DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \
668 subnet %s.\n", workgroup_name, search_subrec->subnet_name));
673 * If the packet was sent to WORKGROUP<1b> instead
674 * of WORKGROUP<1d> then it was unicast to us a domain master
675 * browser. Change search subrec to unicast.
678 if(name_type == 0x1b) {
679 /* We must be a domain master browser in order to
680 process this packet. */
682 if(!AM_DOMAIN_MASTER_BROWSER(work)) {
683 DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
684 and I am not a domain master browser.\n", workgroup_name));
688 search_subrec = unicast_subnet;
689 } else if (name_type == 0x1d) {
690 /* We must be a local master browser in order to process this packet. */
692 if(!AM_LOCAL_MASTER_BROWSER(work)) {
693 DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
694 and I am not a local master browser.\n", workgroup_name));
698 DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n",
703 send_backup_list_response(subrec, work, &dgram->source_name,
704 max_number_requested, token, p->ip, p->port);
708 END_PROFILE(get_backup_list);
711 /*******************************************************************
712 Process a reset browser state packet.
715 0x1 - Stop being a master browser and become a backup browser.
716 0x2 - Discard browse lists, stop being a master browser, try again.
717 0x4 - Stop being a master browser forever.
719 ******************************************************************/
721 void process_reset_browser(struct subnet_record *subrec,
722 struct packet_struct *p,char *buf)
724 struct dgram_packet *dgram = &p->packet.dgram;
725 int state = CVAL(buf,0);
726 struct subnet_record *sr;
728 START_PROFILE(reset_browser);
730 DEBUG(1,("process_reset_browser: received diagnostic browser reset \
731 request from %s IP %s state=0x%X\n",
732 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state));
734 /* Stop being a local master browser on all our broadcast subnets. */
736 for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr)) {
737 struct work_record *work;
738 for (work = sr->workgrouplist; work; work = work->next) {
739 if (AM_LOCAL_MASTER_BROWSER(work))
740 unbecome_local_master_browser(sr, work, True);
745 /* Discard our browse lists. */
748 * Calling expire_workgroups_and_servers with a -1
749 * time causes all servers not marked with a PERMANENT_TTL
750 * on the workgroup lists to be discarded, and all
751 * workgroups with empty server lists to be discarded.
752 * This means we keep our own server names and workgroup
753 * as these have a PERMANENT_TTL.
756 expire_workgroups_and_servers(-1);
759 /* Request to stop browsing altogether. */
761 DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n"));
763 END_PROFILE(reset_browser);
766 /*******************************************************************
767 Process an announcement request packet.
768 We don't respond immediately, we just check it's a request for
769 our workgroup and then set the flag telling the announce code
770 in nmbd_sendannounce.c:announce_my_server_names that an
771 announcement is needed soon.
772 ******************************************************************/
774 void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
776 struct dgram_packet *dgram = &p->packet.dgram;
777 struct work_record *work;
778 nstring workgroup_name;
780 START_PROFILE(announce_request);
782 pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
783 DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n",
784 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
785 nmb_namestr(&dgram->dest_name)));
787 /* We only send announcement requests on our workgroup. */
788 if(strequal(workgroup_name, lp_workgroup()) == False) {
789 DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n",
794 if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) {
795 DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
800 work->needannounce = True;
803 END_PROFILE(lm_host_announce);
806 /*******************************************************************
807 Process a LanMan announcement request packet.
808 We don't respond immediately, we just check it's a request for
809 our workgroup and then set the flag telling that we have found
810 a LanMan client (DOS or OS/2) and that we will have to start
811 sending LanMan announcements (unless specifically disabled
812 through the "lm announce" parameter in smb.conf)
813 ******************************************************************/
815 void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
817 struct dgram_packet *dgram = &p->packet.dgram;
818 nstring workgroup_name;
820 START_PROFILE(lm_announce_request);
822 pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
823 DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n",
824 nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
825 nmb_namestr(&dgram->dest_name)));
827 /* We only send announcement requests on our workgroup. */
828 if(strequal(workgroup_name, lp_workgroup()) == False) {
829 DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n",
834 if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) {
835 DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
840 found_lm_clients = True;
844 END_PROFILE(lm_host_announce);