2000-05-11 02:17:38 +08:00
|
|
|
/* search.c - DNS SRV backend search function */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 01:28:33 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 2000-2005 The OpenLDAP Foundation.
|
2003-11-27 01:28:33 +08:00
|
|
|
* Portions Copyright 2000-2003 Kurt D. Zeilenga.
|
|
|
|
* 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>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was originally developed by Kurt D. Zeilenga for inclusion
|
|
|
|
* in OpenLDAP Software.
|
2000-05-11 02:17:38 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
2004-11-11 08:38:11 +08:00
|
|
|
#include "proto-dnssrv.h"
|
2000-05-11 02:17:38 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
dnssrv_back_search(
|
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs )
|
2000-05-11 02:17:38 +08:00
|
|
|
{
|
2000-06-16 11:50:02 +08:00
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
char *domain = NULL;
|
|
|
|
char *hostlist = NULL;
|
|
|
|
char **hosts = NULL;
|
2001-12-28 15:30:34 +08:00
|
|
|
char *refdn;
|
2004-04-07 12:11:43 +08:00
|
|
|
struct berval nrefdn = BER_BVNULL;
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray urls = NULL;
|
2003-04-08 19:20:18 +08:00
|
|
|
int manageDSAit;
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2003-04-08 19:20:18 +08:00
|
|
|
rs->sr_ref = NULL;
|
|
|
|
|
2005-01-29 07:19:02 +08:00
|
|
|
if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
|
|
|
|
#ifdef LDAP_DEVEL
|
|
|
|
#if 0
|
|
|
|
/* FIXME: need some means to determine whether the database
|
|
|
|
* is a glue instance; if we got here with empty DN, then
|
|
|
|
* we passed this same test in dnssrv_back_referrals() */
|
2005-01-31 06:05:11 +08:00
|
|
|
if ( !SLAP_GLUE_INSTANCE( op->o_bd ) ) {
|
|
|
|
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
rs->sr_err = "DNS SRV operation upon null (empty) DN disallowed";
|
|
|
|
} else
|
2005-01-29 07:19:02 +08:00
|
|
|
#endif
|
2005-01-31 06:05:11 +08:00
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
goto done;
|
2005-01-29 07:19:02 +08:00
|
|
|
#endif /* LDAP_DEVEL */
|
|
|
|
}
|
|
|
|
|
2003-04-08 19:20:18 +08:00
|
|
|
manageDSAit = get_manageDSAit( op );
|
|
|
|
/*
|
|
|
|
* FIXME: we may return a referral if manageDSAit is not set
|
|
|
|
*/
|
2005-01-29 07:19:02 +08:00
|
|
|
if ( !manageDSAit ) {
|
2003-04-08 19:20:18 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
|
|
|
|
"manageDSAit must be set" );
|
|
|
|
goto done;
|
|
|
|
}
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( ldap_dn2domain( op->o_req_dn.bv_val, &domain ) || domain == NULL ) {
|
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
2004-10-06 13:51:38 +08:00
|
|
|
rs->sr_ref = default_referral;
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2003-04-08 19:20:18 +08:00
|
|
|
rs->sr_ref = NULL;
|
2000-06-16 11:50:02 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "", domain, 0 );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2002-04-08 17:43:22 +08:00
|
|
|
if( ( rc = ldap_domain2hostlist( domain, &hostlist ) ) ) {
|
2000-06-16 11:50:02 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "DNSSRV: domain2hostlist returned %d\n",
|
|
|
|
rc, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_NO_SUCH_OBJECT,
|
|
|
|
"no DNS SRV RR available for DN" );
|
2000-06-16 11:50:02 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-24 08:55:24 +08:00
|
|
|
hosts = ldap_str2charray( hostlist, " " );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
|
|
|
if( hosts == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charrary error\n", 0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"problem processing DNS SRV records for DN" );
|
2000-06-16 11:50:02 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; hosts[i] != NULL; i++) {
|
2002-01-02 21:03:06 +08:00
|
|
|
struct berval url;
|
2000-06-16 11:50:02 +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-16 11:50:02 +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-16 11:50:02 +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 );
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"problem processing DNS SRV records for DN" );
|
2000-06-16 11:50:02 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
2004-09-27 07:00:00 +08:00
|
|
|
"%s DNSSRV p=%d dn=\"%s\" url=\"%s\"\n",
|
|
|
|
op->o_log_prefix, op->o_protocol,
|
|
|
|
op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "", urls[0].bv_val, 0 );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2000-06-17 13:53:23 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"DNSSRV: ManageDSAit scope=%d dn=\"%s\" -> url=\"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->oq_search.rs_scope,
|
|
|
|
op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
|
2002-01-02 21:03:06 +08:00
|
|
|
urls[0].bv_val );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
|
|
|
rc = ldap_domain2dn(domain, &refdn);
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"DNS SRV problem processing manageDSAit control" );
|
2000-06-16 11:50:02 +08:00
|
|
|
goto done;
|
|
|
|
|
2001-12-28 15:30:34 +08:00
|
|
|
} else {
|
|
|
|
struct berval bv;
|
|
|
|
bv.bv_val = refdn;
|
|
|
|
bv.bv_len = strlen( refdn );
|
|
|
|
|
2003-04-30 02:28:14 +08:00
|
|
|
rc = dnNormalize( 0, NULL, NULL, &bv, &nrefdn, op->o_tmpmemctx );
|
2001-12-28 15:30:34 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"DNS SRV problem processing manageDSAit control" );
|
2001-12-28 15:30:34 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( !dn_match( &nrefdn, &op->o_req_ndn ) ) {
|
2000-06-16 11:50:02 +08:00
|
|
|
/* requested dn is subordinate */
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2003-03-30 17:03:54 +08:00
|
|
|
"DNSSRV: dn=\"%s\" subordinate to refdn=\"%s\"\n",
|
|
|
|
op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "",
|
2001-12-27 05:25:04 +08:00
|
|
|
refdn == NULL ? "" : refdn,
|
|
|
|
NULL );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = refdn;
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
send_ldap_result( op, rs );
|
2003-04-08 19:20:18 +08:00
|
|
|
rs->sr_matched = NULL;
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
} else if ( op->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL ) {
|
|
|
|
send_ldap_error( op, rs, LDAP_SUCCESS, NULL );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
Entry *e = ch_calloc( 1, sizeof(Entry) );
|
|
|
|
AttributeDescription *ad_objectClass
|
|
|
|
= slap_schema.si_ad_objectClass;
|
|
|
|
AttributeDescription *ad_ref = slap_schema.si_ad_ref;
|
2003-03-30 17:03:54 +08:00
|
|
|
e->e_name.bv_val = strdup( op->o_req_dn.bv_val );
|
|
|
|
e->e_name.bv_len = op->o_req_dn.bv_len;
|
|
|
|
e->e_nname.bv_val = strdup( op->o_req_ndn.bv_val );
|
|
|
|
e->e_nname.bv_len = op->o_req_ndn.bv_len;
|
2000-06-16 11:50:02 +08:00
|
|
|
|
|
|
|
e->e_attrs = NULL;
|
|
|
|
e->e_private = NULL;
|
|
|
|
|
2005-01-31 07:12:27 +08:00
|
|
|
attr_mergeit_one( e, ad_objectClass, &slap_schema.si_oc_top->soc_cname );
|
|
|
|
attr_mergeit_one( e, ad_objectClass, &slap_schema.si_oc_referral->soc_cname );
|
|
|
|
attr_mergeit_one( e, ad_objectClass, &slap_schema.si_oc_extensibleObject->soc_cname );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2005-01-29 07:19:02 +08:00
|
|
|
if ( ad_dc ) {
|
2005-01-31 07:12:27 +08:00
|
|
|
char *p;
|
|
|
|
struct berval bv;
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2005-01-31 07:12:27 +08:00
|
|
|
bv.bv_val = domain;
|
|
|
|
|
|
|
|
p = strchr( bv.bv_val, '.' );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2005-01-31 07:12:27 +08:00
|
|
|
if ( p == bv.bv_val ) {
|
|
|
|
bv.bv_len = 1;
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2005-01-29 07:19:02 +08:00
|
|
|
} else if ( p != NULL ) {
|
2005-01-31 07:12:27 +08:00
|
|
|
bv.bv_len = p - bv.bv_val;
|
2005-01-29 07:19:02 +08:00
|
|
|
}
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2005-01-31 07:12:27 +08:00
|
|
|
attr_mergeit_one( e, ad_dc, &bv );
|
2005-01-29 07:19:02 +08:00
|
|
|
}
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2005-01-29 07:19:02 +08:00
|
|
|
if ( ad_associatedDomain ) {
|
2005-01-31 07:12:27 +08:00
|
|
|
struct berval bv;
|
|
|
|
|
|
|
|
ber_str2bv( domain, 0, 0, &bv );
|
|
|
|
attr_mergeit_one( e, ad_associatedDomain, &bv );
|
2000-06-16 11:50:02 +08:00
|
|
|
}
|
|
|
|
|
2003-02-26 23:59:36 +08:00
|
|
|
attr_mergeit( e, ad_ref, urls );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_filter( op, e, op->oq_search.rs_filter );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
|
|
|
if( rc == LDAP_COMPARE_TRUE ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_entry = e;
|
|
|
|
rs->sr_attrs = op->oq_search.rs_attrs;
|
2004-03-17 19:50:15 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MODIFIABLE;
|
2003-03-30 17:03:54 +08:00
|
|
|
send_search_entry( op, rs );
|
2003-04-08 19:20:18 +08:00
|
|
|
rs->sr_entry = NULL;
|
|
|
|
rs->sr_attrs = NULL;
|
2000-06-16 11:50:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
entry_free( e );
|
2003-03-30 17:03:54 +08:00
|
|
|
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
send_ldap_result( op, rs );
|
2000-06-16 11:50:02 +08:00
|
|
|
}
|
|
|
|
|
2001-12-29 12:48:00 +08:00
|
|
|
if ( refdn ) free( refdn );
|
|
|
|
if ( nrefdn.bv_val ) free( nrefdn.bv_val );
|
2000-06-16 11:50:02 +08:00
|
|
|
|
|
|
|
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
|
|
|
if( urls != NULL ) ber_bvarray_free( urls );
|
2000-06-16 11:50:02 +08:00
|
|
|
return 0;
|
2000-05-11 02:17:38 +08:00
|
|
|
}
|
2003-04-08 19:20:18 +08:00
|
|
|
|