summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/lib/util_names.c5
-rw-r--r--source3/nmbd/nmbd.c4
-rw-r--r--source3/nmbd/nmbd_mynames.c69
-rw-r--r--source3/nmbd/nmbd_proto.h2
5 files changed, 74 insertions, 7 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 2164ff0b437..5bb5f2c36da 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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,
diff --git a/source3/lib/util_names.c b/source3/lib/util_names.c
index 097328906b7..ade9a0570c2 100644
--- a/source3/lib/util_names.c
+++ b/source3/lib/util_names.c
@@ -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;
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index ab1bb88892c..1f7e81a5473 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -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 );
diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c
index f3578b1f1b3..b95c2e2f17d 100644
--- a/source3/nmbd/nmbd_mynames.c
+++ b/source3/nmbd/nmbd_mynames.c
@@ -25,6 +25,75 @@
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.
**************************************************************************/
diff --git a/source3/nmbd/nmbd_proto.h b/source3/nmbd/nmbd_proto.h
index 4ff5de0fbb3..4cfb58980f8 100644
--- a/source3/nmbd/nmbd_proto.h
+++ b/source3/nmbd/nmbd_proto.h
@@ -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);