2000-06-17 03:10:43 +08:00
|
|
|
/* referral.c - DNS SRV backend referral handler */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2000-06-17 03:10:43 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "external.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
dnssrv_back_referrals(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
2001-12-27 02:04:06 +08:00
|
|
|
struct berval *dn,
|
|
|
|
struct berval *ndn,
|
2000-06-17 03:10:43 +08:00
|
|
|
const char **text )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc = LDAP_OTHER;
|
|
|
|
char *domain = NULL;
|
|
|
|
char *hostlist = NULL;
|
|
|
|
char **hosts = NULL;
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray urls = NULL;
|
2000-06-17 03:10:43 +08:00
|
|
|
|
2001-12-27 02:04:06 +08:00
|
|
|
if( ndn->bv_len == 0 ) {
|
2001-01-25 01:25:30 +08:00
|
|
|
*text = "DNS SRV operation upon null (empty) DN disallowed";
|
2000-06-17 03:10:43 +08:00
|
|
|
return LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( get_manageDSAit( op ) ) {
|
|
|
|
if( op->o_tag == LDAP_REQ_SEARCH ) {
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
*text = "DNS SRV problem processing manageDSAit control";
|
|
|
|
return LDAP_OTHER;
|
|
|
|
}
|
|
|
|
|
2001-12-27 02:04:06 +08:00
|
|
|
if( ldap_dn2domain( dn->bv_val, &domain ) ) {
|
2000-06-17 03:10:43 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
NULL, NULL, default_referral, NULL );
|
|
|
|
return LDAP_REFERRAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n",
|
2001-12-27 02:04:06 +08:00
|
|
|
dn->bv_val,
|
2000-06-17 03:10:43 +08:00
|
|
|
domain == NULL ? "" : domain,
|
|
|
|
0 );
|
|
|
|
|
2002-04-08 17:43:22 +08:00
|
|
|
if( ( rc = ldap_domain2hostlist( domain, &hostlist ) ) ) {
|
2001-12-27 02:04:06 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"DNSSRV: domain2hostlist(%s) returned %d\n",
|
|
|
|
domain, rc, 0 );
|
2000-06-17 03:10:43 +08:00
|
|
|
*text = "no DNS SRV RR available for DN";
|
|
|
|
rc = LDAP_NO_SUCH_OBJECT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-24 08:55:24 +08:00
|
|
|
hosts = ldap_str2charray( hostlist, " " );
|
2000-06-17 03:10:43 +08:00
|
|
|
|
|
|
|
if( hosts == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charrary error\n", 0, 0, 0 );
|
|
|
|
*text = "problem processing DNS SRV records for DN";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; hosts[i] != NULL; i++) {
|
2002-01-02 21:03:06 +08:00
|
|
|
struct berval url;
|
2000-06-17 03:10:43 +08:00
|
|
|
|
2002-01-02 21:03:06 +08:00
|
|
|
url.bv_len = sizeof("ldap://")-1 + strlen(hosts[i]);
|
|
|
|
url.bv_val = ch_malloc( url.bv_len + 1 );
|
2000-06-17 03:10:43 +08:00
|
|
|
|
2002-01-02 21:03:06 +08:00
|
|
|
strcpy( url.bv_val, "ldap://" );
|
|
|
|
strcpy( &url.bv_val[sizeof("ldap://")-1], hosts[i] );
|
2000-06-17 03:10:43 +08:00
|
|
|
|
2002-01-14 09:43:17 +08:00
|
|
|
if ( ber_bvarray_add( &urls, &url ) < 0 ) {
|
2002-01-02 21:03:06 +08:00
|
|
|
free( url.bv_val );
|
2000-06-17 03:10:43 +08:00
|
|
|
*text = "problem processing DNS SRV records for DN";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
2002-04-08 17:43:22 +08:00
|
|
|
"conn=%lu op=%lu DNSSRV p=%d dn=\"%s\" url=\"%s\"\n",
|
2001-12-27 02:04:06 +08:00
|
|
|
op->o_connid, op->o_opid, op->o_protocol,
|
2002-01-02 21:03:06 +08:00
|
|
|
dn->bv_val, urls[0].bv_val );
|
2000-06-17 03:10:43 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> url=\"%s\"\n",
|
2002-01-02 21:03:06 +08:00
|
|
|
dn->bv_val, urls[0].bv_val, 0 );
|
2000-06-17 03:10:43 +08:00
|
|
|
|
|
|
|
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
|
|
|
|
NULL, "DNS SRV generated referrals", urls, NULL );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if( domain != NULL ) ch_free( domain );
|
|
|
|
if( hostlist != NULL ) ch_free( hostlist );
|
2002-08-24 08:55:24 +08:00
|
|
|
if( hosts != NULL ) ldap_charray_free( hosts );
|
2002-01-14 09:43:17 +08:00
|
|
|
ber_bvarray_free( urls );
|
2000-06-17 03:10:43 +08:00
|
|
|
return rc;
|
|
|
|
}
|