]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/dnssrv.c
Silence warning in print_deref(): cast lutil_b64_ntop() arg to unsigned char*
[openldap] / libraries / libldap / dnssrv.c
index 99c69c21de36448c9ded3aca8ea8eeaa56d7a8e4..f43d4f4b0d6af3ef16257284dcab330beb694a10 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2009 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,7 @@ int ldap_dn2domain(
        LDAPDN dn = NULL;
        LDAPRDN rdn = NULL;
        LDAPAVA *ava = NULL;
-       struct berval domain = { 0, NULL };
+       struct berval domain = BER_BVNULL;
        static const struct berval DC = BER_BVC("DC");
        static const struct berval DCOID = BER_BVC("0.9.2342.19200300.100.1.25");
 
@@ -69,7 +69,7 @@ int ldap_dn2domain(
                                (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 ) )
+                               || ber_bvcmp( &ava->la_attr, &DCOID ) == 0 ) )
                        {
                                if( domain.bv_len == 0 ) {
                                        ndomain = LDAP_REALLOC( domain.bv_val,
@@ -174,11 +174,6 @@ int ldap_domain2dn(
        return LDAP_SUCCESS;
 }
 
-/* Bind 4 interface */
-#ifndef T_SRV
-#      define T_SRV 33
-#endif
-
 /*
  * Lookup and return LDAP servers for domain (using the DNS
  * SRV record _ldap._tcp.domain).
@@ -215,7 +210,15 @@ int ldap_domain2hostlist(
 #ifdef NS_HFIXEDSZ
        /* Bind 8/9 interface */
     len = res_query(request, ns_c_in, ns_t_srv, reply, sizeof(reply));
+#      ifndef T_SRV
+#              define T_SRV ns_t_srv
+#      endif
 #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) {
@@ -272,8 +275,12 @@ int ldap_domain2hostlist(
                /* weight = (p[2] << 8) | p[3]; */
                port = (p[4] << 8) | p[5];
 
-               buflen = strlen(host) + sizeof(":65355 ");
-               hostlist = (char *) LDAP_REALLOC(hostlist, cur + buflen);
+               if ( port == 0 || host[ 0 ] == '\0' ) {
+                   goto add_size;
+               }
+
+               buflen = strlen(host) + STRLENOF(":65355 ");
+               hostlist = (char *) LDAP_REALLOC(hostlist, cur + buflen + 1);
                if (hostlist == NULL) {
                    rc = LDAP_NO_MEMORY;
                    goto out;
@@ -284,6 +291,7 @@ int ldap_domain2hostlist(
                }
                cur += sprintf(&hostlist[cur], "%s:%hd", host, port);
            }
+add_size:;
            p += size;
        }
     }