]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10297 Defer hostname resolution til first use
authorOndřej Kuzník <ondra@mistotebe.net>
Mon, 28 Apr 2025 13:36:24 +0000 (14:36 +0100)
committerOndřej Kuzník <ondra@mistotebe.net>
Fri, 9 May 2025 08:31:26 +0000 (09:31 +0100)
libraries/libldap/init.c
libraries/libldap/ldap-int.h
libraries/libldap/os-ip.c
libraries/libldap/tls_g.c
libraries/libldap/tls_mt.c
libraries/libldap/tls_o.c

index 213276b4b58011399664224cc7a8b501df489b75..90fc34c5a6e304bc51f698c4ab54e19a25f4e04d 100644 (file)
@@ -631,6 +631,25 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl
 
 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
 char * ldap_int_hostname = NULL;
+
+void
+ldap_int_resolve_hostname(void)
+{
+       static int resolved = 0;
+
+       LDAP_MUTEX_LOCK( &ldap_int_hostname_mutex );
+       if ( !resolved ) {
+               char    *name = ldap_int_hostname;
+
+               ldap_int_hostname = ldap_pvt_get_fqdn( name );
+
+               if ( name != NULL && name != ldap_int_hostname ) {
+                       LDAP_FREE( name );
+               }
+               resolved = 1;
+       }
+       LDAP_MUTEX_UNLOCK( &ldap_int_hostname_mutex );
+}
 #endif
 
 #ifdef LDAP_R_COMPILE
@@ -688,20 +707,6 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
 }
 #endif
 
-#if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
-       LDAP_MUTEX_LOCK( &ldap_int_hostname_mutex );
-       {
-               char    *name = ldap_int_hostname;
-
-               ldap_int_hostname = ldap_pvt_get_fqdn( name );
-
-               if ( name != NULL && name != ldap_int_hostname ) {
-                       LDAP_FREE( name );
-               }
-       }
-       LDAP_MUTEX_UNLOCK( &ldap_int_hostname_mutex );
-#endif
-
 #ifndef HAVE_POLL
        if ( ldap_int_tblsize == 0 ) ldap_int_ip_init();
 #endif
index 7e754775e8f45b30f9201698f6f104c565aef555..435b8590663a2d70bba587c55e873d4f60433311 100644 (file)
@@ -743,6 +743,7 @@ LDAP_F (int) ldap_int_poll( LDAP *ld, ber_socket_t s,
 
 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
 LDAP_V (char *) ldap_int_hostname;
+LDAP_F (void) ldap_int_resolve_hostname(void);
 LDAP_F (char *) ldap_host_connected_to( Sockbuf *sb,
        const char *host );
 #endif
index 6c86edd0558e41ec3c489a3a839d30ab18558574..629b540352484f85cb1b50e4b191e00de4fef832 100644 (file)
@@ -890,6 +890,8 @@ ldap_host_connected_to( Sockbuf *sb, const char *host )
         * this is necessary for kerberos to work right, since the official
         * hostname is used as the kerberos instance.
         */
+       if ( !ldap_int_hostname )
+               ldap_int_resolve_hostname();
 
        switch (sa->sa_family) {
 #ifdef LDAP_PF_LOCAL
index de5b7f7c84b7ea596a2f7596a0ded3b6baf1376f..d4e7ee0bf77354e11c2c08f8182f05faf0ff5f88 100644 (file)
@@ -597,6 +597,9 @@ tlsg_session_chkhost( LDAP *ld, tls_session *session, const char *name_in )
        int len1 = 0, len2 = 0;
        int ntype = IS_DNS;
 
+       if ( !ldap_int_hostname )
+               ldap_int_resolve_hostname();
+
        if( ldap_int_hostname &&
                ( !name_in || !strcasecmp( name_in, "localhost" ) ) )
        {
index a92c300aded12a27ceabf5590ebbd1852a1a20db..b707bcc5195e05835744881fab8ba6878a521e57 100644 (file)
@@ -463,6 +463,9 @@ tlsmt_session_chkhost( LDAP *ld, tls_session *sess, const char *name_in )
        struct in_addr addr;
 #endif
 
+       if ( !ldap_int_hostname )
+               ldap_int_resolve_hostname();
+
        if( ldap_int_hostname &&
                ( !name_in || !strcasecmp( name_in, "localhost" ) ) )
        {
index 71677847a9452edec9403379848e1b8493dc9257..155f685c9932cd983e670266a181fc3735ffe000 100644 (file)
@@ -830,6 +830,9 @@ tlso_session_chkhost( LDAP *ld, tls_session *sess, const char *name_in )
        struct in_addr addr;
 #endif
 
+       if ( !ldap_int_hostname )
+               ldap_int_resolve_hostname();
+
        if( ldap_int_hostname &&
                ( !name_in || !strcasecmp( name_in, "localhost" ) ) )
        {