From: Volker Lendecke Date: Wed, 3 Feb 2021 09:15:00 +0000 (+0100) Subject: lib: Decouple is_myname() from init_names() X-Git-Tag: tevent-0.11.0~1539 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=088386bbedabc11c1f406a3867e1b06b2fdb560f;p=thirdparty%2Fsamba.git lib: Decouple is_myname() from init_names() In a new binary I forgot "init_names()" in main and it crashed in auth3. We should not have to call init_names() everywhere I guess. The my_netbios_names() array is free of duplicates, but as we don't expect more than a handful of netbios aliases this does not matter for just checking existence of a name. And moreover, a properly configured smb.conf doesn't have tons of dups in "netbios aliases" anyway. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/util.c b/source3/lib/util.c index 46e0748cdd3..f4091e1759a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1107,21 +1107,38 @@ int map_process_lock_to_ofd_lock(int op) Returns true if it is equal, false otherwise. ********************************************************************/ +static bool nb_name_equal(const char *s1, const char *s2) +{ + int cmp = strncasecmp_m(s1, s2, MAX_NETBIOSNAME_LEN-1); + return (cmp == 0); +} + bool is_myname(const char *s) { - int n; - bool ret = False; + const char **aliases = NULL; + bool ok = false; - for (n=0; my_netbios_names(n); n++) { - const char *nbt_name = my_netbios_names(n); + ok = nb_name_equal(lp_netbios_name(), s); + if (ok) { + goto done; + } - if (strncasecmp_m(nbt_name, s, MAX_NETBIOSNAME_LEN-1) == 0) { - ret=True; - break; + aliases = lp_netbios_aliases(); + if (aliases == NULL) { + goto done; + } + + while (*aliases != NULL) { + ok = nb_name_equal(*aliases, s); + if (ok) { + goto done; } + aliases += 1; } - DEBUG(8, ("is_myname(\"%s\") returns %d\n", s, ret)); - return(ret); + +done: + DBG_DEBUG("is_myname(\"%s\") returns %d\n", s, (int)ok); + return ok; } /*******************************************************************