2000-01-03 10:33:22 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2021-01-12 03:25:53 +08:00
|
|
|
* Copyright 1998-2021 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* 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>.
|
2000-01-03 10:33:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-04-25 18:38:03 +08:00
|
|
|
* locate LDAP servers using DNS SRV records.
|
|
|
|
* Location code based on MIT Kerberos KDC location code.
|
2000-01-03 10:33:22 +08:00
|
|
|
*/
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/param.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_NAMESER_H
|
|
|
|
#include <arpa/nameser.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_RESOLV_H
|
|
|
|
#include <resolv.h>
|
|
|
|
#endif
|
|
|
|
|
2000-04-25 18:38:03 +08:00
|
|
|
int ldap_dn2domain(
|
|
|
|
LDAP_CONST char *dn_in,
|
|
|
|
char **domainp)
|
|
|
|
{
|
2002-08-18 03:42:59 +08:00
|
|
|
int i, j;
|
|
|
|
char *ndomain;
|
2003-04-11 09:02:08 +08:00
|
|
|
LDAPDN dn = NULL;
|
|
|
|
LDAPRDN rdn = NULL;
|
2002-08-18 03:42:59 +08:00
|
|
|
LDAPAVA *ava = NULL;
|
2004-04-07 09:11:32 +08:00
|
|
|
struct berval domain = BER_BVNULL;
|
2003-01-19 21:35:53 +08:00
|
|
|
static const struct berval DC = BER_BVC("DC");
|
|
|
|
static const struct berval DCOID = BER_BVC("0.9.2342.19200300.100.1.25");
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2002-06-06 08:26:50 +08:00
|
|
|
assert( dn_in != NULL );
|
|
|
|
assert( domainp != NULL );
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2003-04-11 09:02:08 +08:00
|
|
|
*domainp = NULL;
|
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
if ( ldap_str2dn( dn_in, &dn, LDAP_DN_FORMAT_LDAP ) != LDAP_SUCCESS ) {
|
2000-05-11 05:48:18 +08:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2003-04-11 09:02:08 +08:00
|
|
|
if( dn ) for( i=0; dn[i] != NULL; i++ ) {
|
|
|
|
rdn = dn[i];
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2003-04-11 09:02:08 +08:00
|
|
|
for( j=0; rdn[j] != NULL; j++ ) {
|
|
|
|
ava = rdn[j];
|
2000-05-27 02:05:27 +08:00
|
|
|
|
2003-04-11 09:02:08 +08:00
|
|
|
if( rdn[j+1] == NULL &&
|
|
|
|
(ava->la_flags & LDAP_AVA_STRING) &&
|
|
|
|
ava->la_value.bv_len &&
|
2002-08-18 03:42:59 +08:00
|
|
|
( ber_bvstrcasecmp( &ava->la_attr, &DC ) == 0
|
2004-07-19 05:32:38 +08:00
|
|
|
|| ber_bvcmp( &ava->la_attr, &DCOID ) == 0 ) )
|
2000-05-11 05:48:18 +08:00
|
|
|
{
|
2002-08-18 03:42:59 +08:00
|
|
|
if( domain.bv_len == 0 ) {
|
|
|
|
ndomain = LDAP_REALLOC( domain.bv_val,
|
|
|
|
ava->la_value.bv_len + 1);
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
if( ndomain == NULL ) {
|
|
|
|
goto return_error;
|
|
|
|
}
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
domain.bv_val = ndomain;
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
AC_MEMCPY( domain.bv_val, ava->la_value.bv_val,
|
|
|
|
ava->la_value.bv_len );
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
domain.bv_len = ava->la_value.bv_len;
|
|
|
|
domain.bv_val[domain.bv_len] = '\0';
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2000-06-06 07:56:26 +08:00
|
|
|
} else {
|
2002-08-18 03:42:59 +08:00
|
|
|
ndomain = LDAP_REALLOC( domain.bv_val,
|
|
|
|
ava->la_value.bv_len + sizeof(".") + domain.bv_len );
|
|
|
|
|
|
|
|
if( ndomain == NULL ) {
|
|
|
|
goto return_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
domain.bv_val = ndomain;
|
|
|
|
domain.bv_val[domain.bv_len++] = '.';
|
|
|
|
AC_MEMCPY( &domain.bv_val[domain.bv_len],
|
|
|
|
ava->la_value.bv_val, ava->la_value.bv_len );
|
|
|
|
domain.bv_len += ava->la_value.bv_len;
|
|
|
|
domain.bv_val[domain.bv_len] = '\0';
|
2000-06-06 07:56:26 +08:00
|
|
|
}
|
2002-08-18 03:42:59 +08:00
|
|
|
} else {
|
|
|
|
domain.bv_len = 0;
|
2000-05-11 05:48:18 +08:00
|
|
|
}
|
2002-08-18 03:42:59 +08:00
|
|
|
}
|
|
|
|
}
|
2000-05-27 02:05:27 +08:00
|
|
|
|
2000-05-11 05:48:18 +08:00
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
if( domain.bv_len == 0 && domain.bv_val != NULL ) {
|
|
|
|
LDAP_FREE( domain.bv_val );
|
|
|
|
domain.bv_val = NULL;
|
2000-05-27 02:05:27 +08:00
|
|
|
}
|
|
|
|
|
2002-08-18 03:42:59 +08:00
|
|
|
ldap_dnfree( dn );
|
|
|
|
*domainp = domain.bv_val;
|
2000-05-11 05:48:18 +08:00
|
|
|
return 0;
|
2002-08-18 03:42:59 +08:00
|
|
|
|
|
|
|
return_error:
|
|
|
|
ldap_dnfree( dn );
|
|
|
|
LDAP_FREE( domain.bv_val );
|
|
|
|
return -1;
|
2000-04-25 18:38:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ldap_domain2dn(
|
|
|
|
LDAP_CONST char *domain_in,
|
|
|
|
char **dnp)
|
2000-01-03 10:33:22 +08:00
|
|
|
{
|
2002-10-09 04:37:30 +08:00
|
|
|
char *domain, *s, *tok_r, *dn, *dntmp;
|
|
|
|
size_t loc;
|
2000-01-03 10:33:22 +08:00
|
|
|
|
2002-06-06 08:26:50 +08:00
|
|
|
assert( domain_in != NULL );
|
|
|
|
assert( dnp != NULL );
|
|
|
|
|
2002-10-09 04:37:30 +08:00
|
|
|
domain = LDAP_STRDUP(domain_in);
|
|
|
|
if (domain == NULL) {
|
2002-06-06 08:26:50 +08:00
|
|
|
return LDAP_NO_MEMORY;
|
2000-01-03 10:33:22 +08:00
|
|
|
}
|
2002-10-09 04:37:30 +08:00
|
|
|
dn = NULL;
|
|
|
|
loc = 0;
|
|
|
|
|
|
|
|
for (s = ldap_pvt_strtok(domain, ".", &tok_r);
|
|
|
|
s != NULL;
|
|
|
|
s = ldap_pvt_strtok(NULL, ".", &tok_r))
|
|
|
|
{
|
|
|
|
size_t len = strlen(s);
|
|
|
|
|
|
|
|
dntmp = (char *) LDAP_REALLOC(dn, loc + sizeof(",dc=") + len );
|
2002-10-10 16:59:19 +08:00
|
|
|
if (dntmp == NULL) {
|
|
|
|
if (dn != NULL)
|
2002-10-09 04:37:30 +08:00
|
|
|
LDAP_FREE(dn);
|
|
|
|
LDAP_FREE(domain);
|
|
|
|
return LDAP_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
dn = dntmp;
|
|
|
|
|
|
|
|
if (loc > 0) {
|
|
|
|
/* not first time. */
|
|
|
|
strcpy(dn + loc, ",");
|
|
|
|
loc++;
|
|
|
|
}
|
|
|
|
strcpy(dn + loc, "dc=");
|
|
|
|
loc += sizeof("dc=")-1;
|
|
|
|
|
|
|
|
strcpy(dn + loc, s);
|
|
|
|
loc += len;
|
2000-01-03 10:33:22 +08:00
|
|
|
}
|
|
|
|
|
2002-10-09 04:37:30 +08:00
|
|
|
LDAP_FREE(domain);
|
|
|
|
*dnp = dn;
|
|
|
|
return LDAP_SUCCESS;
|
2000-01-03 10:33:22 +08:00
|
|
|
}
|
|
|
|
|
2011-08-24 05:02:03 +08:00
|
|
|
#ifdef HAVE_RES_QUERY
|
|
|
|
#define DNSBUFSIZ (64*1024)
|
2014-07-22 13:05:25 +08:00
|
|
|
#define MAXHOST 254 /* RFC 1034, max length is 253 chars */
|
2011-08-24 05:02:03 +08:00
|
|
|
typedef struct srv_record {
|
|
|
|
u_short priority;
|
|
|
|
u_short weight;
|
|
|
|
u_short port;
|
2014-07-22 13:05:25 +08:00
|
|
|
char hostname[MAXHOST];
|
2011-08-24 05:02:03 +08:00
|
|
|
} srv_record;
|
|
|
|
|
2014-07-22 13:05:25 +08:00
|
|
|
/* Linear Congruential Generator - we don't need
|
|
|
|
* high quality randomness, and we don't want to
|
|
|
|
* interfere with anyone else's use of srand().
|
|
|
|
*
|
|
|
|
* The PRNG here cycles thru 941,955 numbers.
|
|
|
|
*/
|
|
|
|
static float srv_seed;
|
|
|
|
|
|
|
|
static void srv_srand(int seed) {
|
|
|
|
srv_seed = (float)seed / (float)RAND_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float srv_rand() {
|
|
|
|
float val = 9821.0 * srv_seed + .211327;
|
|
|
|
srv_seed = val - (int)val;
|
|
|
|
return srv_seed;
|
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
|
|
|
|
static int srv_cmp(const void *aa, const void *bb){
|
2014-07-22 13:05:25 +08:00
|
|
|
srv_record *a=(srv_record *)aa;
|
|
|
|
srv_record *b=(srv_record *)bb;
|
|
|
|
int i = a->priority - b->priority;
|
|
|
|
if (i) return i;
|
|
|
|
return b->weight - a->weight;
|
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
|
2014-07-22 13:05:25 +08:00
|
|
|
static void srv_shuffle(srv_record *a, int n) {
|
|
|
|
int i, j, total = 0, r, p;
|
|
|
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
total += a[i].weight;
|
|
|
|
|
|
|
|
/* Do a shuffle per RFC2782 Page 4 */
|
2015-12-06 20:33:17 +08:00
|
|
|
for (p=n; p>1; a++, p--) {
|
|
|
|
if (!total) {
|
|
|
|
/* all remaining weights are zero,
|
|
|
|
do a straight Fisher-Yates shuffle */
|
|
|
|
j = srv_rand() * p;
|
|
|
|
} else {
|
|
|
|
r = srv_rand() * total;
|
|
|
|
for (j=0; j<p; j++) {
|
|
|
|
r -= a[j].weight;
|
|
|
|
if (r < 0) {
|
|
|
|
total -= a[j].weight;
|
|
|
|
break;
|
2014-07-22 13:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-06 20:33:17 +08:00
|
|
|
if (j && j<p) {
|
|
|
|
srv_record t = a[0];
|
|
|
|
a[0] = a[j];
|
|
|
|
a[j] = t;
|
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_RES_QUERY */
|
|
|
|
|
2000-01-03 10:33:22 +08:00
|
|
|
/*
|
2000-04-25 18:38:03 +08:00
|
|
|
* Lookup and return LDAP servers for domain (using the DNS
|
|
|
|
* SRV record _ldap._tcp.domain).
|
2000-01-03 10:33:22 +08:00
|
|
|
*/
|
2000-04-25 18:38:03 +08:00
|
|
|
int ldap_domain2hostlist(
|
|
|
|
LDAP_CONST char *domain,
|
|
|
|
char **list )
|
2000-01-03 10:33:22 +08:00
|
|
|
{
|
2000-06-06 07:56:26 +08:00
|
|
|
#ifdef HAVE_RES_QUERY
|
2000-01-03 10:33:22 +08:00
|
|
|
char *request;
|
|
|
|
char *hostlist = NULL;
|
2011-08-24 05:02:03 +08:00
|
|
|
srv_record *hostent_head=NULL;
|
2014-07-22 13:05:25 +08:00
|
|
|
int i, j;
|
2000-01-03 10:33:22 +08:00
|
|
|
int rc, len, cur = 0;
|
2002-08-25 01:03:24 +08:00
|
|
|
unsigned char reply[DNSBUFSIZ];
|
2011-08-24 05:02:03 +08:00
|
|
|
int hostent_count=0;
|
2000-01-03 10:33:22 +08:00
|
|
|
|
2002-06-05 23:46:26 +08:00
|
|
|
assert( domain != NULL );
|
|
|
|
assert( list != NULL );
|
|
|
|
if( *domain == '\0' ) {
|
2000-04-25 18:38:03 +08:00
|
|
|
return LDAP_PARAM_ERROR;
|
|
|
|
}
|
|
|
|
|
2000-01-03 10:33:22 +08:00
|
|
|
request = LDAP_MALLOC(strlen(domain) + sizeof("_ldap._tcp."));
|
|
|
|
if (request == NULL) {
|
2002-01-08 04:18:38 +08:00
|
|
|
return LDAP_NO_MEMORY;
|
2000-01-03 10:33:22 +08:00
|
|
|
}
|
|
|
|
sprintf(request, "_ldap._tcp.%s", domain);
|
|
|
|
|
2010-10-13 16:43:15 +08:00
|
|
|
LDAP_MUTEX_LOCK(&ldap_int_resolv_mutex);
|
2000-01-03 10:33:22 +08:00
|
|
|
|
2000-05-30 03:47:48 +08:00
|
|
|
rc = LDAP_UNAVAILABLE;
|
2003-11-22 02:56:52 +08:00
|
|
|
#ifdef NS_HFIXEDSZ
|
|
|
|
/* Bind 8/9 interface */
|
2003-10-15 11:39:05 +08:00
|
|
|
len = res_query(request, ns_c_in, ns_t_srv, reply, sizeof(reply));
|
2004-03-17 12:45:56 +08:00
|
|
|
# ifndef T_SRV
|
|
|
|
# define T_SRV ns_t_srv
|
|
|
|
# endif
|
2003-11-22 02:56:52 +08:00
|
|
|
#else
|
2004-03-17 12:45:56 +08:00
|
|
|
/* Bind 4 interface */
|
|
|
|
# ifndef T_SRV
|
|
|
|
# define T_SRV 33
|
|
|
|
# endif
|
|
|
|
|
2003-11-22 02:56:52 +08:00
|
|
|
len = res_query(request, C_IN, T_SRV, reply, sizeof(reply));
|
|
|
|
#endif
|
2000-01-03 10:33:22 +08:00
|
|
|
if (len >= 0) {
|
|
|
|
unsigned char *p;
|
2002-08-25 01:03:24 +08:00
|
|
|
char host[DNSBUFSIZ];
|
2000-01-03 10:33:22 +08:00
|
|
|
int status;
|
2011-08-24 05:02:03 +08:00
|
|
|
u_short port, priority, weight;
|
2000-01-03 10:33:22 +08:00
|
|
|
|
|
|
|
/* Parse out query */
|
|
|
|
p = reply;
|
2004-01-18 03:11:20 +08:00
|
|
|
|
2003-11-22 02:56:52 +08:00
|
|
|
#ifdef NS_HFIXEDSZ
|
|
|
|
/* Bind 8/9 interface */
|
2003-10-15 11:30:15 +08:00
|
|
|
p += NS_HFIXEDSZ;
|
2004-01-18 03:11:20 +08:00
|
|
|
#elif defined(HFIXEDSZ)
|
|
|
|
/* Bind 4 interface w/ HFIXEDSZ */
|
2003-11-22 02:56:52 +08:00
|
|
|
p += HFIXEDSZ;
|
2004-01-18 03:11:20 +08:00
|
|
|
#else
|
|
|
|
/* Bind 4 interface w/o HFIXEDSZ */
|
|
|
|
p += sizeof(HEADER);
|
2003-11-22 02:56:52 +08:00
|
|
|
#endif
|
2004-01-18 03:11:20 +08:00
|
|
|
|
2000-01-03 10:33:22 +08:00
|
|
|
status = dn_expand(reply, reply + len, p, host, sizeof(host));
|
|
|
|
if (status < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
p += status;
|
|
|
|
p += 4;
|
|
|
|
|
|
|
|
while (p < reply + len) {
|
|
|
|
int type, class, ttl, size;
|
|
|
|
status = dn_expand(reply, reply + len, p, host, sizeof(host));
|
|
|
|
if (status < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
p += status;
|
|
|
|
type = (p[0] << 8) | p[1];
|
|
|
|
p += 2;
|
|
|
|
class = (p[0] << 8) | p[1];
|
|
|
|
p += 2;
|
|
|
|
ttl = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
|
|
|
|
p += 4;
|
|
|
|
size = (p[0] << 8) | p[1];
|
|
|
|
p += 2;
|
|
|
|
if (type == T_SRV) {
|
|
|
|
status = dn_expand(reply, reply + len, p + 6, host, sizeof(host));
|
|
|
|
if (status < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
|
|
|
|
/* Get priority weight and port */
|
|
|
|
priority = (p[0] << 8) | p[1];
|
|
|
|
weight = (p[2] << 8) | p[3];
|
2000-01-03 10:33:22 +08:00
|
|
|
port = (p[4] << 8) | p[5];
|
|
|
|
|
2006-08-06 01:08:40 +08:00
|
|
|
if ( port == 0 || host[ 0 ] == '\0' ) {
|
|
|
|
goto add_size;
|
|
|
|
}
|
|
|
|
|
2011-08-24 05:02:03 +08:00
|
|
|
hostent_head = (srv_record *) LDAP_REALLOC(hostent_head, (hostent_count+1)*(sizeof(srv_record)));
|
|
|
|
if(hostent_head==NULL){
|
|
|
|
rc=LDAP_NO_MEMORY;
|
2000-01-03 10:33:22 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
hostent_head[hostent_count].priority=priority;
|
2014-07-22 10:34:31 +08:00
|
|
|
hostent_head[hostent_count].weight=weight;
|
2011-08-24 05:02:03 +08:00
|
|
|
hostent_head[hostent_count].port=port;
|
2015-01-14 22:35:35 +08:00
|
|
|
strncpy(hostent_head[hostent_count].hostname, host, MAXHOST-1);
|
|
|
|
hostent_head[hostent_count].hostname[MAXHOST-1] = '\0';
|
2014-07-22 13:05:25 +08:00
|
|
|
hostent_count++;
|
2000-01-03 10:33:22 +08:00
|
|
|
}
|
2006-08-06 01:08:40 +08:00
|
|
|
add_size:;
|
2000-01-03 10:33:22 +08:00
|
|
|
p += size;
|
|
|
|
}
|
2015-01-14 22:35:35 +08:00
|
|
|
if (!hostent_head) goto out;
|
2011-08-24 05:02:03 +08:00
|
|
|
qsort(hostent_head, hostent_count, sizeof(srv_record), srv_cmp);
|
|
|
|
|
2014-07-22 13:05:25 +08:00
|
|
|
if (!srv_seed)
|
|
|
|
srv_srand(time(0L));
|
|
|
|
|
|
|
|
/* shuffle records of same priority */
|
|
|
|
j = 0;
|
|
|
|
priority = hostent_head[0].priority;
|
|
|
|
for (i=1; i<hostent_count; i++) {
|
|
|
|
if (hostent_head[i].priority != priority) {
|
|
|
|
priority = hostent_head[i].priority;
|
|
|
|
if (i-j > 1)
|
|
|
|
srv_shuffle(hostent_head+j, i-j);
|
|
|
|
j = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i-j > 1)
|
|
|
|
srv_shuffle(hostent_head+j, i-j);
|
|
|
|
|
2011-08-24 05:02:03 +08:00
|
|
|
for(i=0; i<hostent_count; i++){
|
|
|
|
int buflen;
|
2014-07-22 10:34:31 +08:00
|
|
|
buflen = strlen(hostent_head[i].hostname) + STRLENOF(":65535 ");
|
2011-08-24 05:02:03 +08:00
|
|
|
hostlist = (char *) LDAP_REALLOC(hostlist, cur+buflen+1);
|
|
|
|
if (hostlist == NULL) {
|
|
|
|
rc = LDAP_NO_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if(cur>0){
|
|
|
|
hostlist[cur++]=' ';
|
|
|
|
}
|
2015-07-12 18:14:33 +08:00
|
|
|
cur += sprintf(&hostlist[cur], "%s:%hu", hostent_head[i].hostname, hostent_head[i].port);
|
2011-08-24 05:02:03 +08:00
|
|
|
}
|
2014-07-22 13:05:25 +08:00
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
|
2000-01-03 10:33:22 +08:00
|
|
|
if (hostlist == NULL) {
|
|
|
|
/* No LDAP servers found in DNS. */
|
|
|
|
rc = LDAP_UNAVAILABLE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = LDAP_SUCCESS;
|
2000-04-25 18:38:03 +08:00
|
|
|
*list = hostlist;
|
2000-01-03 10:33:22 +08:00
|
|
|
|
|
|
|
out:
|
2010-10-13 16:43:15 +08:00
|
|
|
LDAP_MUTEX_UNLOCK(&ldap_int_resolv_mutex);
|
2000-01-03 10:33:22 +08:00
|
|
|
|
|
|
|
if (request != NULL) {
|
|
|
|
LDAP_FREE(request);
|
|
|
|
}
|
2011-08-24 05:02:03 +08:00
|
|
|
if (hostent_head != NULL) {
|
|
|
|
LDAP_FREE(hostent_head);
|
|
|
|
}
|
2000-04-25 18:38:03 +08:00
|
|
|
if (rc != LDAP_SUCCESS && hostlist != NULL) {
|
2000-01-03 10:33:22 +08:00
|
|
|
LDAP_FREE(hostlist);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
#else
|
|
|
|
return LDAP_NOT_SUPPORTED;
|
2000-06-06 07:56:26 +08:00
|
|
|
#endif /* HAVE_RES_QUERY */
|
2000-01-03 10:33:22 +08:00
|
|
|
}
|