]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/dnssrv.c
Sync with HEAD
[openldap] / libraries / libldap / dnssrv.c
index 69a7ec5bb39f4a3404b85027f4a4df7c504ab5c8..1cfa8412a90c7275b20b1983d8f73e658de994c8 100644 (file)
@@ -1,7 +1,16 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 /*
 #include <resolv.h>
 #endif
 
-/* Sometimes this is not defined. */
-#ifndef T_SRV
-#define T_SRV            33
-#endif                         /* T_SRV */
-
 int ldap_dn2domain(
        LDAP_CONST char *dn_in,
        char **domainp)
 {
        int i, j;
        char *ndomain;
-       LDAPDN *dn = NULL;
-       LDAPRDN *rdn = NULL;
+       LDAPDN dn = NULL;
+       LDAPRDN rdn = NULL;
        LDAPAVA *ava = NULL;
        struct berval domain = { 0, NULL };
-       const static struct berval DC = BER_BVC("DC");
-       const static struct berval DCOID = BER_BVC("0.9.2342.19200300.100.1.25");
+       static const struct berval DC = BER_BVC("DC");
+       static const struct berval DCOID = BER_BVC("0.9.2342.19200300.100.1.25");
 
        assert( dn_in != NULL );
        assert( domainp != NULL );
 
+       *domainp = NULL;
+
        if ( ldap_str2dn( dn_in, &dn, LDAP_DN_FORMAT_LDAP ) != LDAP_SUCCESS ) {
                return -2;
        }
 
-       if( dn ) for( i=0; (*dn)[i] != NULL; i++ ) {
-               rdn = (*dn)[i];
+       if( dn ) for( i=0; dn[i] != NULL; i++ ) {
+               rdn = dn[i];
 
-               for( j=0; (*rdn)[j] != NULL; j++ ) {
-                       ava = (*rdn)[j];
+               for( j=0; rdn[j] != NULL; j++ ) {
+                       ava = rdn[j];
 
-                       if( (*dn)[i][j][1] == NULL &&
-                               !ava->la_flags && ava->la_value.bv_len &&
+                       if( rdn[j+1] == NULL &&
+                               (ava->la_flags & LDAP_AVA_STRING) &&
+                               ava->la_value.bv_len &&
                                ( ber_bvstrcasecmp( &ava->la_attr, &DC ) == 0
                                || ber_bvstrcasecmp( &ava->la_attr, &DCOID ) == 0 ) )
                        {
@@ -200,7 +207,16 @@ int ldap_domain2hostlist(
 #endif
 
     rc = LDAP_UNAVAILABLE;
+#ifdef NS_HFIXEDSZ
+       /* Bind 8/9 interface */
+    len = res_query(request, ns_c_in, ns_t_srv, reply, sizeof(reply));
+#else
+       /* Bind 4 interface */
+#      ifndef T_SRV
+#              define T_SRV 33
+#      endif
     len = res_query(request, C_IN, T_SRV, reply, sizeof(reply));
+#endif
     if (len >= 0) {
        unsigned char *p;
        char host[DNSBUFSIZ];
@@ -210,7 +226,13 @@ int ldap_domain2hostlist(
 
        /* Parse out query */
        p = reply;
-       p += sizeof(HEADER);
+#ifdef NS_HFIXEDSZ
+       /* Bind 8/9 interface */
+       p += NS_HFIXEDSZ;
+#else
+       /* Bind 4 interface */
+       p += HFIXEDSZ;
+#endif
        status = dn_expand(reply, reply + len, p, host, sizeof(host));
        if (status < 0) {
            goto out;