Convert all uses of uint8/16/32 to _t in nmbd and the include file.
[samba.git] / source3 / nmbd / nmbd_mynames.c
index f02fbe1640f411c08c19e897cf1dddbdb45a5c7f..f3578b1f1b37c915aedef5e5a3f8c300f6a2b61e 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
 */
 
 #include "includes.h"
+#include "nmbd/nmbd.h"
 
-extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
+extern uint16_t samba_nb_type; /* Samba's NetBIOS type. */
 
 /****************************************************************************
  Fail funtion when registering my netbios names.
@@ -83,7 +83,7 @@ Exiting.\n", lp_workgroup(), subrec->subnet_name));
 ******************************************************************/
 
 static void insert_refresh_name_into_unicast( struct subnet_record *subrec,
-                                                struct nmb_name *nmbname, uint16 nb_type )
+                                                struct nmb_name *nmbname, uint16_t nb_type )
 {
        struct name_record *namerec;
 
@@ -93,8 +93,8 @@ static void insert_refresh_name_into_unicast( struct subnet_record *subrec,
        }
 
        if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) {
-               nstring name;
-               pull_ascii_nstring(name, nmbname->name);
+               unstring name;
+               pull_ascii_nstring(name, sizeof(name), nmbname->name);
                /* The name needs to be created on the unicast subnet. */
                (void)add_name_to_subnet( unicast_subnet, name,
                                nmbname->name_type, nb_type,
@@ -111,10 +111,11 @@ static void insert_refresh_name_into_unicast( struct subnet_record *subrec,
   Also add the magic Samba names.
 **************************************************************************/
 
-BOOL register_my_workgroup_and_names(void)
+bool register_my_workgroup_and_names(void)
 {
        struct subnet_record *subrec;
        int i;
+       const char **cluster_addresses = NULL;
 
        for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
                register_my_workgroup_one_subnet(subrec);
@@ -145,6 +146,37 @@ BOOL register_my_workgroup_and_names(void)
                }
        }
 
+       /*
+        * add in any cluster addresses. We need to response to these,
+        * but not listen on them. This allows us to run nmbd on every
+        * node in the cluster, and have all of them register with a
+        * WINS server correctly
+        */
+       if (lp_clustering()) {
+               cluster_addresses = lp_cluster_addresses();
+       }
+       if (cluster_addresses) {
+               int a, n;
+               unsigned name_types[] = {0x20, 0x3, 0x0};
+               
+               for (i=0; my_netbios_names(i); i++) {
+                       for(subrec = FIRST_SUBNET; subrec; subrec = subrec->next) {
+                               for (n=0;n<ARRAY_SIZE(name_types);n++) {
+                                       struct name_record *namerec;
+                                       struct nmb_name nmbname;
+                                       struct in_addr ip;
+                                       make_nmb_name(&nmbname, my_netbios_names(i), name_types[n]);
+                                       namerec = find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME);
+                                       if (namerec == NULL) continue;
+                                       for (a=0;cluster_addresses[a];a++) {
+                                               ip = interpret_addr2(cluster_addresses[a]);
+                                               add_ip_to_name_record(namerec, ip);
+                                       }
+                               }
+                       }
+               }
+       }
+
        /*
         * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet
         * also for the same reasons.
@@ -182,8 +214,8 @@ void release_wins_names(void)
        struct subnet_record *subrec = unicast_subnet;
        struct name_record *namerec, *nextnamerec;
 
-       for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = nextnamerec) {
-               nextnamerec = (struct name_record *)ubi_trNext( namerec );
+       for (namerec = subrec->namelist; namerec; namerec = nextnamerec) {
+               nextnamerec = namerec->next;
                if( (namerec->data.source == SELF_NAME)
                    && !NAME_IS_DEREGISTERING(namerec) )
                        release_name( subrec, namerec, standard_success_release,
@@ -202,9 +234,7 @@ void refresh_my_names(time_t t)
        if (wins_srv_count() < 1)
                return;
 
-       for (namerec = (struct name_record *)ubi_trFirst(unicast_subnet->namelist);
-            namerec;
-            namerec = (struct name_record *)ubi_trNext(namerec)) {
+       for (namerec = unicast_subnet->namelist; namerec; namerec = namerec->next) {
                /* Each SELF name has an individual time to be refreshed. */
                if ((namerec->data.source == SELF_NAME) &&
                    (namerec->data.refresh_time < t) &&