[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Feb 7 18:27:02 UTC 2020


The branch, master has been updated
       via  859a86b37ea s3: lib: Now remote_machine is static, we can depend on it being non-NULL.
       via  7a7b597b3df s3:lib: Remove unneded call to set_local_machine_name()
       via  daaf550e194 s3:lib: Use a static buffer for (local|remote)_machine
      from  3894f878183 libcli:smb: Don't use forward declartions for GnuTLS typedefs

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 859a86b37ea0740e21d763049351f55a9aa93343
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 6 13:36:41 2020 -0800

    s3: lib: Now remote_machine is static, we can depend on it being non-NULL.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Feb  7 18:26:15 UTC 2020 on sn-devel-184

commit 7a7b597b3dfcbabf5de92222aef207421cd6b4ea
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Feb 6 13:31:52 2020 +0100

    s3:lib: Remove unneded call to set_local_machine_name()
    
    We return the netbios name by default if not set.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit daaf550e194b6163a17295ac984ee6f0012c6d99
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Feb 6 13:22:33 2020 +0100

    s3:lib: Use a static buffer for (local|remote)_machine
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/include/proto.h  |  1 -
 source3/lib/substitute.c | 70 +++++++++++++++++-------------------------------
 source3/lib/util_names.c |  3 ---
 3 files changed, 24 insertions(+), 50 deletions(-)


Changeset truncated at 500 lines:

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..833af10b6f0 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];
@@ -552,9 +532,7 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
 			break;
 		case 'm' :
 			a_string = realloc_string_sub(a_string, "%m",
-						      remote_machine
-						      ? remote_machine
-						      : "");
+						      remote_machine);
 			break;
 		case 'v' :
 			a_string = realloc_string_sub(a_string, "%v", samba_version_string());
diff --git a/source3/lib/util_names.c b/source3/lib/util_names.c
index dc5c530346c..15236c913df 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)
@@ -147,8 +146,6 @@ bool init_names(void)
 		return False;
 	}
 
-	set_local_machine_name(lp_netbios_name(),false);
-
 	DEBUG( 5, ("Netbios name list:-\n") );
 	for( n=0; my_netbios_names(n); n++ ) {
 		DEBUGADD( 5, ("my_netbios_names[%d]=\"%s\"\n",


-- 
Samba Shared Repository



More information about the samba-cvs mailing list