]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/dnssrv.c
Add #include <openssl/safestack.h> to fix ITS#1412
[openldap] / libraries / libldap / dnssrv.c
index a6f4e24b9c0e65fb2069f39af6cda46fd283628d..f67cdbbe9df29905de1a18a7b9f948784d193250 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -38,8 +38,8 @@ int ldap_dn2domain(
        char **domainp)
 {
        int i;
-       chardomain = NULL;
-       char ** dn;
+       char *domain = NULL;
+       char **dn;
 
        if( dn_in == NULL || domainp == NULL ) {
                return -1;
@@ -61,12 +61,15 @@ int ldap_dn2domain(
                        return -3;
                }
 
-#define LDAP_DC "dc="
-#define LDAP_DCOID "0.9.2342.19200300.100.1.25="
 
                if( rdn[1] == NULL ) {
+                       /*
+                        * single-valued RDN
+                        */
                        char *dc;
-                       /* single RDN */
+
+#define LDAP_DC "dc="
+#define LDAP_DCOID "0.9.2342.19200300.100.1.25="
 
                        if( strncasecmp( rdn[0],
                                LDAP_DC, sizeof(LDAP_DC)-1 ) == 0 )
@@ -79,7 +82,7 @@ int ldap_dn2domain(
                                dc = &rdn[0][sizeof(LDAP_DCOID)-1];
 
                        } else {
-                               dc == NULL;
+                               dc = NULL;
                        }
 
                        if( dc != NULL ) {
@@ -96,7 +99,7 @@ int ldap_dn2domain(
 
                                ndomain = LDAP_REALLOC( domain,
                                        ( domain == NULL ? 0 : strlen(domain) )
-                                       + strlen(dc) + 2 );
+                                       + strlen(dc) + sizeof(".") );
 
                                if( ndomain == NULL ) {
                                        LDAP_FREE( rdn );
@@ -106,20 +109,33 @@ int ldap_dn2domain(
                                        return -5;
                                }
 
-                               if( domain != NULL ) {
+                               if( domain == NULL ) {
+                                       ndomain[0] = '\0';
+                               } else {
                                        strcat( ndomain, "." );
                                }
+
                                strcat( ndomain, dc );
+
                                domain = ndomain;
                                continue;
                        }
                }
 
+               /*
+                * multi-valued RDN or fall thru
+                */
+
                LDAP_VFREE( rdn );
                LDAP_FREE( domain );
                domain = NULL;
        } 
 
+       if( domain != NULL &&  *domain == '\0' ) {
+               LDAP_FREE( domain );
+               domain = NULL;
+       }
+
        *domainp = domain;
        return 0;
 }
@@ -178,9 +194,8 @@ int ldap_domain2hostlist(
        LDAP_CONST char *domain,
        char **list )
 {
-#ifdef HAVE_RES_SEARCH
+#ifdef HAVE_RES_QUERY
     char *request;
-    char *dn;
     char *hostlist = NULL;
     int rc, len, cur = 0;
     unsigned char reply[1024];
@@ -204,7 +219,8 @@ int ldap_domain2hostlist(
     ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
 #endif
 
-    len = res_search(request, C_IN, T_SRV, reply, sizeof(reply));
+    rc = LDAP_UNAVAILABLE;
+    len = res_query(request, C_IN, T_SRV, reply, sizeof(reply));
     if (len >= 0) {
        unsigned char *p;
        char host[1024];
@@ -286,5 +302,5 @@ int ldap_domain2hostlist(
     return rc;
 #else
     return LDAP_NOT_SUPPORTED;
-#endif                         /* HAVE_RES_SEARCH */
+#endif /* HAVE_RES_QUERY */
 }