From 4fb1f5c31195aa58b8f918eb649282344a9e853c Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Wed, 3 Jun 2009 01:39:54 +0000
Subject: [PATCH] Add global_host_bv, why do we still have bare char *s lying
 around...

---
 servers/slapd/config.c     | 1 +
 servers/slapd/daemon.c     | 8 ++++----
 servers/slapd/main.c       | 1 +
 servers/slapd/proto-slap.h | 1 +
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/servers/slapd/config.c b/servers/slapd/config.c
index 1f651d1c40..20669ba1fd 100644
--- a/servers/slapd/config.c
+++ b/servers/slapd/config.c
@@ -64,6 +64,7 @@ int		global_gentlehup = 0;
 int		global_idletimeout = 0;
 int		global_writetimeout = 0;
 char	*global_host = NULL;
+struct berval global_host_bv = BER_BVNULL;
 char	*global_realm = NULL;
 char	*sasl_host = NULL;
 char		**default_passwd_hash = NULL;
diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c
index 23193d1498..55681f4712 100644
--- a/servers/slapd/daemon.c
+++ b/servers/slapd/daemon.c
@@ -687,16 +687,16 @@ slapd_slp_init( const char* urls )
 	for ( i = 0; slapd_srvurls[i] != NULL; i++ ) {
 		if ( strcmp( slapd_srvurls[i], "ldap:///" ) == 0 ) {
 			slapd_srvurls[i] = (char *) ch_realloc( slapd_srvurls[i],
-				strlen( global_host ) +
+				global_host_bv.bv_len +
 				sizeof( LDAP_SRVTYPE_PREFIX ) );
 			strcpy( lutil_strcopy(slapd_srvurls[i],
-				LDAP_SRVTYPE_PREFIX ), global_host );
+				LDAP_SRVTYPE_PREFIX ), global_host_bv.bv_val );
 		} else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0 ) {
 			slapd_srvurls[i] = (char *) ch_realloc( slapd_srvurls[i],
-				strlen( global_host ) +
+				global_host_bv.bv_len +
 				sizeof( LDAPS_SRVTYPE_PREFIX ) );
 			strcpy( lutil_strcopy(slapd_srvurls[i],
-				LDAPS_SRVTYPE_PREFIX ), global_host );
+				LDAPS_SRVTYPE_PREFIX ), global_host_bv.bv_val );
 		}
 	}
 
diff --git a/servers/slapd/main.c b/servers/slapd/main.c
index e2ffda2c7c..14fadd6b1a 100644
--- a/servers/slapd/main.c
+++ b/servers/slapd/main.c
@@ -700,6 +700,7 @@ unhandled_option:;
 	Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
 
 	global_host = ldap_pvt_get_fqdn( NULL );
+	ber_str2bv( global_host, 0, 0, &global_host_bv );
 
 	if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
 		rc = 1;
diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h
index a56a5fc011..e8b73c71b5 100644
--- a/servers/slapd/proto-slap.h
+++ b/servers/slapd/proto-slap.h
@@ -1937,6 +1937,7 @@ LDAP_SLAPD_V (int)		global_gentlehup;
 LDAP_SLAPD_V (int)		global_idletimeout;
 LDAP_SLAPD_V (int)		global_writetimeout;
 LDAP_SLAPD_V (char *)	global_host;
+LDAP_SLAPD_V (struct berval)	global_host_bv;
 LDAP_SLAPD_V (char *)	global_realm;
 LDAP_SLAPD_V (char *)	sasl_host;
 LDAP_SLAPD_V (char *)	slap_sasl_auxprops;
-- 
GitLab