Fix to stop PERMANENT_NAMES being added when nmbd starts up and WINS
authorJeremy Allison <jra@samba.org>
Fri, 29 Mar 2002 00:57:35 +0000 (00:57 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 29 Mar 2002 00:57:35 +0000 (00:57 +0000)
server is down. Keep adding refreshible names instead.
Jeremy.
(This used to be commit f25fcd99fa0d0ec2095d9db42145d236c14748e0)

source3/nmbd/nmbd_mynames.c

index a3311fec472a1b1a4557f4d9fe99287386fd95a1..aac188db2bfb68c0c4f4095fda0f9c2210b29ad8 100644 (file)
@@ -79,6 +79,35 @@ Exiting.\n", global_myworkgroup, subrec->subnet_name));
        initiate_myworkgroup_startup(subrec, work);
 }
 
+/*******************************************************************
+ Utility function to add a name to the unicast subnet, or add in
+ our IP address if it already exists.
+******************************************************************/
+
+static void insert_refresh_name_into_unicast( struct subnet_record *subrec,
+                                                struct nmb_name *nmbname, uint16 nb_type )
+{
+  struct name_record *namerec;
+
+  if (!we_are_a_wins_client()) {
+    insert_permanent_name_into_unicast(subrec, nmbname, nb_type);
+    return;
+  }
+
+  if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL)
+  {
+    /* The name needs to be created on the unicast subnet. */
+    (void)add_name_to_subnet( unicast_subnet, nmbname->name,
+                              nmbname->name_type, nb_type,
+                              MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip);
+  }
+  else
+  {
+    /* The name already exists on the unicast subnet. Add our local
+       IP for the given broadcast subnet to the name. */
+    add_ip_to_name_record( namerec, subrec->myip);
+  }
+}
 
 /****************************************************************************
   Add my workgroup and my given names to the subnet lists.
@@ -114,13 +143,13 @@ BOOL register_my_workgroup_and_names(void)
       struct nmb_name nmbname;
 
       make_nmb_name(&nmbname, my_netbios_names[i],0x20);
-      insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type);
+      insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
 
       make_nmb_name(&nmbname, my_netbios_names[i],0x3);
-      insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type);
+      insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
 
       make_nmb_name(&nmbname, my_netbios_names[i],0x0);
-      insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type);
+      insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
     }
   }
 
@@ -137,10 +166,10 @@ BOOL register_my_workgroup_and_names(void)
     struct nmb_name nmbname;
 
     make_nmb_name(&nmbname, global_myworkgroup, 0x0);
-    insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
+    insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
 
     make_nmb_name(&nmbname, global_myworkgroup, 0x1e);
-    insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
+    insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
   }
 
   /*