1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

nmbd: Move my_netbios_names() to nmbd

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>
This commit is contained in:
Volker Lendecke 2021-03-13 21:56:53 +01:00 committed by Jeremy Allison
parent 5831e8f230
commit 57d548b502
5 changed files with 74 additions and 7 deletions

View 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,

View 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;

View 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 );

View File

@ -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.
**************************************************************************/

View 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);