]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
nmbd: Move my_netbios_names() to nmbd
authorVolker Lendecke <vl@samba.org>
Sat, 13 Mar 2021 20:56:53 +0000 (21:56 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 16 Mar 2021 17:09:32 +0000 (17:09 +0000)
nmbd is the heaviest user of this. The only other user was
is_myname(), which is used in quite a few places in source3.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/util_names.c
source3/nmbd/nmbd.c
source3/nmbd/nmbd_mynames.c
source3/nmbd/nmbd_proto.h

index 2164ff0b43768595902f5c3b23606f5bac9c9c7b..5bb5f2c36da95f7b1cbc510df3d1dc750162e2ea 100644 (file)
@@ -312,7 +312,6 @@ enum protocol_types get_Protocol(void);
 void set_Protocol(enum protocol_types  p);
 void gfree_names(void);
 void gfree_all( void );
-const char *my_netbios_names(int i);
 bool set_netbios_aliases(const char **str_array);
 bool init_names(void);
 bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf,
index 097328906b7342f47692f70c74da705c4908750a..ade9a0570c213ef6f8fafd97ad1e1f38e671b11d 100644 (file)
@@ -83,11 +83,6 @@ void gfree_names(void)
        free_netbios_names_array();
 }
 
-const char *my_netbios_names(int i)
-{
-       return smb_my_netbios_names[i];
-}
-
 bool set_netbios_aliases(const char **str_array)
 {
        size_t namecount;
index ab1bb88892cb301bd02f6a99b4832450670d287b..1f7e81a5473565eac1335f1d46dbc55f2453e604 100644 (file)
@@ -436,6 +436,7 @@ static void msg_reload_nmbd_services(struct messaging_context *msg,
        reload_nmbd_services( True );
        reopen_logs();
        reload_interfaces(0);
+       nmbd_init_my_netbios_names();
 }
 
 static void msg_nmbd_send_packet(struct messaging_context *msg,
@@ -990,8 +991,9 @@ static bool open_sockets(bool isdaemon, int port)
        if ( !reload_nmbd_services(False) )
                return(-1);
 
-       if(!init_names())
+       if (!nmbd_init_my_netbios_names()) {
                return -1;
+       }
 
        reload_nmbd_services( True );
 
index f3578b1f1b37c915aedef5e5a3f8c300f6a2b61e..b95c2e2f17df68b89df027df3fae75fca4b0f19d 100644 (file)
 
 extern uint16_t samba_nb_type; /* Samba's NetBIOS type. */
 
+static const char **mynames = NULL;
+
+static bool add_unique_netbios_name(const char *name)
+{
+       size_t i, num_names = talloc_array_length(mynames);
+       char *str = NULL;
+       const char **tmp = NULL;
+
+       for (i=0; i<num_names; i++) {
+               if (strequal(name, mynames[i])) {
+                       return true;
+               }
+       }
+
+       str = talloc_strdup(NULL, name);
+       if (str == NULL) {
+               return false;
+       }
+
+       tmp = talloc_realloc(NULL, mynames, const char *, num_names+1);
+       if (tmp == NULL) {
+               TALLOC_FREE(str);
+               return false;
+       }
+       tmp[num_names] = talloc_move(tmp, &str);
+       mynames = tmp;
+       return true;
+}
+
+bool nmbd_init_my_netbios_names(void)
+{
+       const char *name = lp_netbios_name();
+       const char **aliases = lp_netbios_aliases();
+
+       TALLOC_FREE(mynames);
+
+       if (name[0] != '\0') {
+               bool ok = add_unique_netbios_name(name);
+               if (!ok) {
+                       return false;
+               }
+       }
+
+       if (aliases == NULL) {
+               return true;
+       }
+
+       while (*aliases != NULL) {
+               bool ok = add_unique_netbios_name(*aliases);
+               if (!ok) {
+                       return false;
+               }
+               aliases += 1;
+       }
+
+       return true;
+}
+
+const char *my_netbios_names(int i)
+{
+       size_t num_names = talloc_array_length(mynames);
+
+       if ((i >= 0) && (i < num_names)) {
+               return mynames[i];
+       }
+
+       return NULL;
+}
+
 /****************************************************************************
  Fail funtion when registering my netbios names.
 **************************************************************************/
index 4ff5de0fbb37f3907d4b9b6c5546644d69f3652e..4cfb58980f87679d745a89f284eb1d7356416e79 100644 (file)
@@ -118,6 +118,8 @@ void add_logon_names(void);
 
 /* The following definitions come from nmbd/nmbd_mynames.c  */
 
+bool nmbd_init_my_netbios_names(void);
+const char *my_netbios_names(int i);
 void register_my_workgroup_one_subnet(struct subnet_record *subrec);
 bool register_my_workgroup_and_names(void);
 void release_wins_names(void);