first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[gd/samba/.git] / source / nmbd / nmbd_incomingdgrams.c
index 36242d9ac2c8663ec13d33734c72291460b9b5b7..b8be579779f9de425da407a480bec67ecdfa2977 100644 (file)
@@ -114,7 +114,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p
   
   DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \
 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              namestr(&dgram->dest_name),announce_name));
+              nmb_namestr(&dgram->dest_name),announce_name));
 
   DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n",
           ttl, servertype,comment));
@@ -213,7 +213,7 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru
 
   DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \
 %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              namestr(&dgram->dest_name),workgroup_announce_name));
+              nmb_namestr(&dgram->dest_name),workgroup_announce_name));
 
   DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n",
            ttl, servertype, master_name));
@@ -222,7 +222,7 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru
   if (!strequal(dgram->dest_name.name, MSBROWSE) || (dgram->dest_name.name_type != 0x1))
   {
     DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n",
-              inet_ntoa(p->ip), namestr(&dgram->dest_name)));
+              inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
     return;
   }
 
@@ -267,7 +267,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s
 
   DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \
 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              namestr(&dgram->dest_name),server_name));
+              nmb_namestr(&dgram->dest_name),server_name));
 
   DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n",
            ttl, servertype, comment));
@@ -440,7 +440,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct
 
   DEBUG(3,("process_lm_host_announce: LM Announcement from %s<%02x> IP %s to \
 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              namestr(&dgram->dest_name),announce_name));
+              nmb_namestr(&dgram->dest_name),announce_name));
 
   DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n",
           osmajor, osminor, ttl, servertype,comment));
@@ -544,15 +544,16 @@ static void send_backup_list_response(struct subnet_record *subrec,
                                      int port)
 {                     
   char outbuf[1024];
-  char *p, *countptr, *nameptr;
+  char *p, *countptr;
   unsigned int count = 0;
-  int len;
+#if 0
   struct server_record *servrec;
+#endif
 
-  bzero(outbuf,sizeof(outbuf));
+  memset(outbuf,'\0',sizeof(outbuf));
 
   DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
-          work->work_group, namestr(send_to_name), inet_ntoa(sendto_ip)));
+          work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
   
   p = outbuf;
   
@@ -565,8 +566,6 @@ static void send_backup_list_response(struct subnet_record *subrec,
   SIVAL(p,0,token); /* The sender's unique info. */
   p += 4;
   
-  nameptr = p;
-
   /* We always return at least one name - our own. */
   count = 1;
   StrnCpy(p,global_myname,15);
@@ -574,9 +573,20 @@ static void send_backup_list_response(struct subnet_record *subrec,
   p = skip_string(p,1);
 
   /* Look for backup browsers in this workgroup. */
+
+#if 0
+  /* we don't currently send become_backup requests so we should never
+     send any other servers names out as backups for our
+     workgroup. That's why this is commented out (tridge) */
+
+  /*
+   * NB. Note that the struct work_record here is not neccessarily
+   * attached to the subnet *subrec.
+   */
+
   for (servrec = work->serverlist; servrec; servrec = servrec->next)
   { 
-    len = PTR_DIFF(p, outbuf);
+    int len = PTR_DIFF(p, outbuf);
     if((sizeof(outbuf) - len) < 16)
       break;
 
@@ -598,11 +608,10 @@ static void send_backup_list_response(struct subnet_record *subrec,
 
     p = skip_string(p,1);
   }
+#endif
 
   SCVAL(countptr, 0, count);
 
-  len = PTR_DIFF(p, outbuf);
-
   DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n",
           send_to_name->name, inet_ntoa(sendto_ip), count));
 
@@ -632,10 +641,11 @@ void process_get_backup_list_request(struct subnet_record *subrec,
   uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */
   int name_type = dgram->dest_name.name_type;
   char *workgroup_name = dgram->dest_name.name;
+  struct subnet_record *search_subrec = subrec;
 
   DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n",
-           namestr(&dgram->source_name), inet_ntoa(p->ip),
-           namestr(&dgram->dest_name)));
+           nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+           nmb_namestr(&dgram->dest_name)));
   
   /* We have to be a master browser, or a domain master browser
      for the requested workgroup. That means it must be our
@@ -648,13 +658,19 @@ void process_get_backup_list_request(struct subnet_record *subrec,
     return;
   }
 
-  if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL)
+  if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL)
   {
     DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \
-subnet %s.\n", workgroup_name, subrec->subnet_name));
+subnet %s.\n", workgroup_name, search_subrec->subnet_name));
     return;
   }
 
+  /* 
+   * If the packet was sent to WORKGROUP<1b> instead
+   * of WORKGROUP<1d> then it was unicast to us a domain master
+   * browser. Change search subrec to unicast.
+   */
+
   if(name_type == 0x1b)
   {
     /* We must be a domain master browser in order to
@@ -666,6 +682,8 @@ subnet %s.\n", workgroup_name, subrec->subnet_name));
 and I am not a domain master browser.\n", workgroup_name));
       return;
     }
+
+    search_subrec = unicast_subnet;
   }
   else if (name_type == 0x1d)
   {
@@ -709,7 +727,7 @@ void process_reset_browser(struct subnet_record *subrec,
 
   DEBUG(1,("process_reset_browser: received diagnostic browser reset \
 request from %s IP %s state=0x%X\n",
-             namestr(&dgram->source_name), inet_ntoa(p->ip), state));
+             nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state));
 
   /* Stop being a local master browser on all our broadcast subnets. */
   if (state & 0x1)
@@ -760,8 +778,8 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct
   char *workgroup_name = dgram->dest_name.name;
  
   DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n",
-           namestr(&dgram->source_name), inet_ntoa(p->ip),
-           namestr(&dgram->dest_name)));
+           nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+           nmb_namestr(&dgram->dest_name)));
   
   /* We only send announcement requests on our workgroup. */
   if(strequal(workgroup_name, global_myworkgroup) == False)
@@ -793,12 +811,11 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct
 void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
   struct dgram_packet *dgram = &p->packet.dgram;
-  struct work_record *work;
   char *workgroup_name = dgram->dest_name.name;
 
   DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n",
-           namestr(&dgram->source_name), inet_ntoa(p->ip),
-           namestr(&dgram->dest_name)));
+           nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+           nmb_namestr(&dgram->dest_name)));
 
   /* We only send announcement requests on our workgroup. */
   if(strequal(workgroup_name, global_myworkgroup) == False)
@@ -808,7 +825,7 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str
     return;
   }
 
-  if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL)
+  if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL)
   {
     DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
             workgroup_name));