X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libraries%2Flibldap%2Fdnssrv.c;h=16b15447cac2bfefc717104998aa5b065cb6fb87;hb=8fd5fa0ed82c3a9e980f75a84933e3c3ae0cd5f0;hp=d9bbcbe81edc6d3ab5364b065ffb9f35545a5db1;hpb=1874658ae379b81683dfa70cdc8a531cf972b40f;p=openldap diff --git a/libraries/libldap/dnssrv.c b/libraries/libldap/dnssrv.c index d9bbcbe81e..16b15447ca 100644 --- a/libraries/libldap/dnssrv.c +++ b/libraries/libldap/dnssrv.c @@ -1,7 +1,16 @@ /* $OpenLDAP$ */ -/* - * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2011 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 + * . */ /* @@ -28,11 +37,6 @@ #include #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) @@ -42,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"); @@ -65,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, @@ -198,12 +202,23 @@ int ldap_domain2hostlist( } sprintf(request, "_ldap._tcp.%s", domain); -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex); -#endif + LDAP_MUTEX_LOCK(&ldap_int_resolv_mutex); rc = LDAP_UNAVAILABLE; +#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) { unsigned char *p; char host[DNSBUFSIZ]; @@ -213,7 +228,18 @@ int ldap_domain2hostlist( /* Parse out query */ p = reply; + +#ifdef NS_HFIXEDSZ + /* Bind 8/9 interface */ + p += NS_HFIXEDSZ; +#elif defined(HFIXEDSZ) + /* Bind 4 interface w/ HFIXEDSZ */ + p += HFIXEDSZ; +#else + /* Bind 4 interface w/o HFIXEDSZ */ p += sizeof(HEADER); +#endif + status = dn_expand(reply, reply + len, p, host, sizeof(host)); if (status < 0) { goto out; @@ -247,8 +273,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; @@ -257,8 +287,9 @@ int ldap_domain2hostlist( /* not first time around */ hostlist[cur++] = ' '; } - cur += sprintf(&hostlist[cur], "%s:%hd", host, port); + cur += sprintf(&hostlist[cur], "%s:%hu", host, port); } +add_size:; p += size; } } @@ -272,9 +303,7 @@ int ldap_domain2hostlist( *list = hostlist; out: -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex); -#endif + LDAP_MUTEX_UNLOCK(&ldap_int_resolv_mutex); if (request != NULL) { LDAP_FREE(request);