diff --git a/source3/include/proto.h b/source3/include/proto.h index 72ac69e72f2..e03486f07ab 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -159,7 +159,6 @@ int smbrunsecret(const char *cmd, const char *secret); /* The following definitions come from lib/substitute.c */ -void free_local_machine_name(void); bool set_local_machine_name(const char *local_name, bool perm); const char *get_local_machine_name(void); bool set_remote_machine_name(const char *remote_name, bool perm); diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 7d1e55f568b..f49e983ba7c 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -24,6 +24,12 @@ #include "secrets.h" #include "auth.h" +/* Max DNS name is 253 + '\0' */ +#define MACHINE_NAME_SIZE 254 + +static char local_machine[MACHINE_NAME_SIZE]; +static char remote_machine[MACHINE_NAME_SIZE]; + userdom_struct current_user_info; fstring remote_proto="UNKNOWN"; @@ -32,41 +38,25 @@ fstring remote_proto="UNKNOWN"; * @param local_name the name we are being called * @param if this is the 'final' name for us, not be be changed again */ - -static char *local_machine; - -void free_local_machine_name(void) -{ - TALLOC_FREE(local_machine); -} - bool set_local_machine_name(const char *local_name, bool perm) { static bool already_perm = false; - char *tmp_local_machine = NULL; + char tmp[MACHINE_NAME_SIZE]; if (already_perm) { return true; } - tmp_local_machine = talloc_strdup(NULL, local_name); - if (!tmp_local_machine) { - return false; - } - trim_char(tmp_local_machine,' ',' '); + strlcpy(tmp, local_name, sizeof(tmp)); + trim_char(tmp, ' ', ' '); - TALLOC_FREE(local_machine); - local_machine = talloc_alpha_strcpy(NULL, - tmp_local_machine, - SAFE_NETBIOS_CHARS); - if (local_machine == NULL) { - return false; - } + alpha_strcpy(local_machine, + tmp, + SAFE_NETBIOS_CHARS, + sizeof(local_machine) - 1); if (!strlower_m(local_machine)) { - TALLOC_FREE(tmp_local_machine); return false; } - TALLOC_FREE(tmp_local_machine); already_perm = perm; @@ -75,7 +65,7 @@ bool set_local_machine_name(const char *local_name, bool perm) const char *get_local_machine_name(void) { - if (!local_machine || !*local_machine) { + if (local_machine[0] == '\0') { return lp_netbios_name(); } @@ -84,39 +74,29 @@ const char *get_local_machine_name(void) /** * Set the 'remote' machine name + * * @param remote_name the name our client wants to be called by * @param if this is the 'final' name for them, not be be changed again */ - -static char *remote_machine; - bool set_remote_machine_name(const char *remote_name, bool perm) { static bool already_perm = False; - char *tmp_remote_machine; + char tmp[MACHINE_NAME_SIZE]; if (already_perm) { return true; } - tmp_remote_machine = talloc_strdup(NULL, remote_name); - if (!tmp_remote_machine) { - return false; - } - trim_char(tmp_remote_machine,' ',' '); + strlcpy(tmp, remote_name, sizeof(tmp)); + trim_char(tmp, ' ', ' '); - TALLOC_FREE(remote_machine); - remote_machine = talloc_alpha_strcpy(NULL, - tmp_remote_machine, - SAFE_NETBIOS_CHARS); - if (remote_machine == NULL) { - return false; - } + alpha_strcpy(remote_machine, + tmp, + SAFE_NETBIOS_CHARS, + sizeof(remote_machine) - 1); if (!strlower_m(remote_machine)) { - TALLOC_FREE(tmp_remote_machine); return false; } - TALLOC_FREE(tmp_remote_machine); already_perm = perm; @@ -125,7 +105,7 @@ bool set_remote_machine_name(const char *remote_name, bool perm) const char *get_remote_machine_name(void) { - return remote_machine ? remote_machine : ""; + return remote_machine; } static char sub_peeraddr[INET6_ADDRSTRLEN]; diff --git a/source3/lib/util_names.c b/source3/lib/util_names.c index dc5c530346c..f33a8a7d1ab 100644 --- a/source3/lib/util_names.c +++ b/source3/lib/util_names.c @@ -81,7 +81,6 @@ static bool set_my_netbios_names(const char *name, int i) void gfree_names(void) { free_netbios_names_array(); - free_local_machine_name(); } const char *my_netbios_names(int i)