diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:54:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:54:12 +0000 |
commit | b527294153be3b79563c82c66102adc0004736c0 (patch) | |
tree | 9b423a224848441885190b5ea7cf0feb23510c9d /servers/slapd/back-dnssrv | |
parent | Initial commit. (diff) | |
download | openldap-b527294153be3b79563c82c66102adc0004736c0.tar.xz openldap-b527294153be3b79563c82c66102adc0004736c0.zip |
Adding upstream version 2.6.7+dfsg.upstream/2.6.7+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | servers/slapd/back-dnssrv/Makefile.in | 46 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/bind.c | 79 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/compare.c | 46 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/config.c | 54 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/init.c | 115 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/proto-dnssrv.h | 46 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/referral.c | 129 | ||||
-rw-r--r-- | servers/slapd/back-dnssrv/search.c | 239 |
8 files changed, 754 insertions, 0 deletions
diff --git a/servers/slapd/back-dnssrv/Makefile.in b/servers/slapd/back-dnssrv/Makefile.in new file mode 100644 index 0000000..cf571e0 --- /dev/null +++ b/servers/slapd/back-dnssrv/Makefile.in @@ -0,0 +1,46 @@ +# Makefile.in for back-dnssrv +# $OpenLDAP$ +## This work is part of OpenLDAP Software <http://www.openldap.org/>. +## +## Copyright 1998-2022 The OpenLDAP Foundation. +## Portions Copyright 1998-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: +# The DNSSRV backend was written by Kurt D. Zeilenga. +# + +SRCS = init.c bind.c search.c config.c referral.c +OBJS = init.lo bind.lo search.lo config.lo referral.lo + +LDAP_INCDIR= ../../../include +LDAP_LIBDIR= ../../../libraries + +BUILD_OPT = "--enable-dnssrv" +BUILD_MOD = @BUILD_DNSSRV@ + +mod_DEFS = -DSLAPD_IMPORT +MOD_DEFS = $(@BUILD_DNSSRV@_DEFS) + +shared_LDAP_LIBS = $(LDAP_LIBLDAP_LA) $(LDAP_LIBLBER_LA) +NT_LINK_LIBS = -L.. -lslapd $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) +UNIX_LINK_LIBS = $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) + +LIBBASE = back_dnssrv + +XINCPATH = -I.. -I$(srcdir)/.. +XDEFS = $(MODULES_CPPFLAGS) + +all-local-lib: ../.backend + +../.backend: lib$(LIBBASE).a + @touch $@ + diff --git a/servers/slapd/back-dnssrv/bind.c b/servers/slapd/back-dnssrv/bind.c new file mode 100644 index 0000000..705c503 --- /dev/null +++ b/servers/slapd/back-dnssrv/bind.c @@ -0,0 +1,79 @@ +/* bind.c - DNS SRV backend bind function */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 The OpenLDAP Foundation. + * 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. + */ + + +#include "portable.h" + +#include <stdio.h> + +#include <ac/socket.h> +#include <ac/string.h> + +#include "slap.h" +#include "proto-dnssrv.h" + +int +dnssrv_back_bind( + Operation *op, + SlapReply *rs ) +{ + Debug( LDAP_DEBUG_TRACE, "DNSSRV: bind dn=\"%s\" (%d)\n", + BER_BVISNULL( &op->o_req_dn ) ? "" : op->o_req_dn.bv_val, + op->orb_method ); + + /* allow rootdn as a means to auth without the need to actually + * contact the proxied DSA */ + switch ( be_rootdn_bind( op, NULL ) ) { + case LDAP_SUCCESS: + /* frontend will send result */ + return rs->sr_err; + + default: + /* treat failure and like any other bind, otherwise + * it could reveal the DN of the rootdn */ + break; + } + + if ( !BER_BVISNULL( &op->orb_cred ) && + !BER_BVISEMPTY( &op->orb_cred ) ) + { + /* simple bind */ + Debug( LDAP_DEBUG_STATS, + "%s DNSSRV BIND dn=\"%s\" provided cleartext passwd\n", + op->o_log_prefix, + BER_BVISNULL( &op->o_req_dn ) ? "" : op->o_req_dn.bv_val ); + + send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, + "you shouldn't send strangers your password" ); + + } else { + /* unauthenticated bind */ + /* NOTE: we're not going to get here anyway: + * unauthenticated bind is dealt with by the frontend */ + Debug( LDAP_DEBUG_TRACE, "DNSSRV: BIND dn=\"%s\"\n", + BER_BVISNULL( &op->o_req_dn ) ? "" : op->o_req_dn.bv_val ); + + send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, + "anonymous bind expected" ); + } + + return 1; +} diff --git a/servers/slapd/back-dnssrv/compare.c b/servers/slapd/back-dnssrv/compare.c new file mode 100644 index 0000000..28a0f6c --- /dev/null +++ b/servers/slapd/back-dnssrv/compare.c @@ -0,0 +1,46 @@ +/* compare.c - DNS SRV backend compare function */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 The OpenLDAP Foundation. + * 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. + */ + +#include "portable.h" + +#include <stdio.h> + +#include <ac/string.h> +#include <ac/socket.h> + +#include "slap.h" +#include "proto-dnssrv.h" + +int +dnssrv_back_compare( + Operation *op, + SlapReply *rs +) +{ +#if 0 + assert( get_manageDSAit( op ) ); +#endif + send_ldap_error( op, rs, LDAP_OTHER, + "Operation not supported within naming context" ); + + /* not implemented */ + return 1; +} diff --git a/servers/slapd/back-dnssrv/config.c b/servers/slapd/back-dnssrv/config.c new file mode 100644 index 0000000..32e412e --- /dev/null +++ b/servers/slapd/back-dnssrv/config.c @@ -0,0 +1,54 @@ +/* config.c - DNS SRV backend configuration file routine */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 The OpenLDAP Foundation. + * 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. + */ + +#include "portable.h" + +#include <stdio.h> + +#include <ac/string.h> +#include <ac/socket.h> + +#include "slap.h" +#include "proto-dnssrv.h" + +#if 0 +int +dnssrv_back_db_config( + BackendDB *be, + const char *fname, + int lineno, + int argc, + char **argv ) +{ +#if 0 + struct ldapinfo *li = (struct ldapinfo *) be->be_private; + + if ( li == NULL ) { + fprintf( stderr, "%s: line %d: DNSSRV backend info is null!\n", + fname, lineno ); + return( 1 ); + } +#endif + + /* no configuration options (yet) */ + return SLAP_CONF_UNKNOWN; +} +#endif diff --git a/servers/slapd/back-dnssrv/init.c b/servers/slapd/back-dnssrv/init.c new file mode 100644 index 0000000..a253be7 --- /dev/null +++ b/servers/slapd/back-dnssrv/init.c @@ -0,0 +1,115 @@ +/* init.c - initialize ldap backend */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 The OpenLDAP Foundation. + * 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. + */ + +#include "portable.h" + +#include <stdio.h> + +#include <ac/socket.h> +#include <ac/param.h> +#include <ac/string.h> + +#include "slap.h" +#include "slap-config.h" +#include "proto-dnssrv.h" + +int +dnssrv_back_initialize( + BackendInfo *bi ) +{ + static char *controls[] = { + LDAP_CONTROL_MANAGEDSAIT, + NULL + }; + + bi->bi_controls = controls; + + bi->bi_open = dnssrv_back_open; + bi->bi_config = 0; + bi->bi_close = 0; + bi->bi_destroy = 0; + + bi->bi_db_init = 0; + bi->bi_db_destroy = 0; + bi->bi_db_config = 0 /* dnssrv_back_db_config */; + bi->bi_db_open = 0; + bi->bi_db_close = 0; + + bi->bi_chk_referrals = dnssrv_back_referrals; + + bi->bi_op_bind = dnssrv_back_bind; + bi->bi_op_search = dnssrv_back_search; + bi->bi_op_compare = 0 /* dnssrv_back_compare */; + bi->bi_op_modify = 0; + bi->bi_op_modrdn = 0; + bi->bi_op_add = 0; + bi->bi_op_delete = 0; + bi->bi_op_abandon = 0; + bi->bi_op_unbind = 0; + + bi->bi_extended = 0; + + bi->bi_connection_init = 0; + bi->bi_connection_destroy = 0; + + bi->bi_access_allowed = slap_access_always_allowed; + + return 0; +} + +AttributeDescription *ad_dc; +AttributeDescription *ad_associatedDomain; + +int +dnssrv_back_open( + BackendInfo *bi ) +{ + const char *text; + + (void)slap_str2ad( "dc", &ad_dc, &text ); + (void)slap_str2ad( "associatedDomain", &ad_associatedDomain, &text ); + + return 0; +} + +int +dnssrv_back_db_init( + Backend *be, + ConfigReply *cr) +{ + return 0; +} + +int +dnssrv_back_db_destroy( + Backend *be, + ConfigReply *cr ) +{ + return 0; +} + +#if SLAPD_DNSSRV == SLAPD_MOD_DYNAMIC + +/* conditionally define the init_module() function */ +SLAP_BACKEND_INIT_MODULE( dnssrv ) + +#endif /* SLAPD_DNSSRV == SLAPD_MOD_DYNAMIC */ + diff --git a/servers/slapd/back-dnssrv/proto-dnssrv.h b/servers/slapd/back-dnssrv/proto-dnssrv.h new file mode 100644 index 0000000..23b01aa --- /dev/null +++ b/servers/slapd/back-dnssrv/proto-dnssrv.h @@ -0,0 +1,46 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 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 + * <http://www.OpenLDAP.org/license.html>. + */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by Kurt D. Zeilenga for inclusion + * in OpenLDAP Software. + */ + +#ifndef PROTO_DNSSRV_H +#define PROTO_DNSSRV_H + +LDAP_BEGIN_DECL + +extern BI_init dnssrv_back_initialize; + +extern BI_open dnssrv_back_open; +extern BI_close dnssrv_back_close; +extern BI_destroy dnssrv_back_destroy; + +extern BI_db_init dnssrv_back_db_init; +extern BI_db_destroy dnssrv_back_db_destroy; +extern BI_db_config dnssrv_back_db_config; + +extern BI_op_bind dnssrv_back_bind; +extern BI_op_search dnssrv_back_search; +extern BI_op_compare dnssrv_back_compare; + +extern BI_chk_referrals dnssrv_back_referrals; + +extern AttributeDescription *ad_dc; +extern AttributeDescription *ad_associatedDomain; + +LDAP_END_DECL + +#endif /* PROTO_DNSSRV_H */ diff --git a/servers/slapd/back-dnssrv/referral.c b/servers/slapd/back-dnssrv/referral.c new file mode 100644 index 0000000..c3b801a --- /dev/null +++ b/servers/slapd/back-dnssrv/referral.c @@ -0,0 +1,129 @@ +/* referral.c - DNS SRV backend referral handler */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 The OpenLDAP Foundation. + * 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. + */ + +#include "portable.h" + +#include <stdio.h> + +#include <ac/string.h> +#include <ac/socket.h> + +#include "slap.h" +#include "proto-dnssrv.h" + +int +dnssrv_back_referrals( + Operation *op, + SlapReply *rs ) +{ + int i; + int rc = LDAP_OTHER; + char *domain = NULL; + char *hostlist = NULL; + char **hosts = NULL; + BerVarray urls = NULL; + + if ( BER_BVISEMPTY( &op->o_req_dn ) ) { + /* FIXME: need some means to determine whether the database + * is a glue instance */ + if ( SLAP_GLUE_INSTANCE( op->o_bd ) ) { + return LDAP_SUCCESS; + } + + rs->sr_text = "DNS SRV operation upon null (empty) DN disallowed"; + return LDAP_UNWILLING_TO_PERFORM; + } + + if( get_manageDSAit( op ) ) { + if( op->o_tag == LDAP_REQ_SEARCH ) { + return LDAP_SUCCESS; + } + + rs->sr_text = "DNS SRV problem processing manageDSAit control"; + return LDAP_OTHER; + } + + if( ldap_dn2domain( op->o_req_dn.bv_val, &domain ) || domain == NULL ) { + rs->sr_err = LDAP_REFERRAL; + rs->sr_ref = default_referral; + send_ldap_result( op, rs ); + rs->sr_ref = NULL; + return LDAP_REFERRAL; + } + + Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n", + op->o_req_dn.bv_val, domain ); + + i = ldap_domain2hostlist( domain, &hostlist ); + if ( i ) { + Debug( LDAP_DEBUG_TRACE, + "DNSSRV: domain2hostlist(%s) returned %d\n", + domain, i ); + rs->sr_text = "no DNS SRV RR available for DN"; + rc = LDAP_NO_SUCH_OBJECT; + goto done; + } + + hosts = ldap_str2charray( hostlist, " " ); + + if( hosts == NULL ) { + Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charray error\n" ); + rs->sr_text = "problem processing DNS SRV records for DN"; + goto done; + } + + for( i=0; hosts[i] != NULL; i++) { + struct berval url; + + url.bv_len = STRLENOF( "ldap://" ) + strlen( hosts[i] ); + url.bv_val = ch_malloc( url.bv_len + 1 ); + + strcpy( url.bv_val, "ldap://" ); + strcpy( &url.bv_val[STRLENOF( "ldap://" )], hosts[i] ); + + if ( ber_bvarray_add( &urls, &url ) < 0 ) { + free( url.bv_val ); + rs->sr_text = "problem processing DNS SRV records for DN"; + goto done; + } + } + + Debug( LDAP_DEBUG_STATS, + "%s DNSSRV p=%d dn=\"%s\" url=\"%s\"\n", + op->o_log_prefix, op->o_protocol, + op->o_req_dn.bv_val, urls[0].bv_val ); + + Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> url=\"%s\"\n", + op->o_req_dn.bv_val, urls[0].bv_val ); + + rs->sr_ref = urls; + send_ldap_error( op, rs, LDAP_REFERRAL, + "DNS SRV generated referrals" ); + rs->sr_ref = NULL; + rc = LDAP_REFERRAL; + +done: + if( domain != NULL ) ch_free( domain ); + if( hostlist != NULL ) ch_free( hostlist ); + if( hosts != NULL ) ldap_charray_free( hosts ); + ber_bvarray_free( urls ); + return rc; +} diff --git a/servers/slapd/back-dnssrv/search.c b/servers/slapd/back-dnssrv/search.c new file mode 100644 index 0000000..4403248 --- /dev/null +++ b/servers/slapd/back-dnssrv/search.c @@ -0,0 +1,239 @@ +/* search.c - DNS SRV backend search function */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2000-2022 The OpenLDAP Foundation. + * 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. + */ + +#include "portable.h" + +#include <stdio.h> + +#include <ac/socket.h> +#include <ac/string.h> +#include <ac/time.h> + +#include "slap.h" +#include "proto-dnssrv.h" + +int +dnssrv_back_search( + Operation *op, + SlapReply *rs ) +{ + int i; + int rc; + char *domain = NULL; + char *hostlist = NULL; + char **hosts = NULL; + char *refdn; + struct berval nrefdn = BER_BVNULL; + BerVarray urls = NULL; + int manageDSAit; + + rs->sr_ref = NULL; + + if ( BER_BVISEMPTY( &op->o_req_ndn ) ) { + /* 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() */ + if ( !SLAP_GLUE_INSTANCE( op->o_bd ) ) { + rs->sr_err = LDAP_UNWILLING_TO_PERFORM; + rs->sr_text = "DNS SRV operation upon null (empty) DN disallowed"; + + } else { + rs->sr_err = LDAP_SUCCESS; + } + goto done; + } + + manageDSAit = get_manageDSAit( op ); + /* + * FIXME: we may return a referral if manageDSAit is not set + */ + if ( !manageDSAit ) { + send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, + "manageDSAit must be set" ); + goto done; + } + + if( ldap_dn2domain( op->o_req_dn.bv_val, &domain ) || domain == NULL ) { + rs->sr_err = LDAP_REFERRAL; + rs->sr_ref = default_referral; + send_ldap_result( op, rs ); + rs->sr_ref = NULL; + goto done; + } + + Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n", + op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "", domain ); + + if( ( rc = ldap_domain2hostlist( domain, &hostlist ) ) ) { + Debug( LDAP_DEBUG_TRACE, "DNSSRV: domain2hostlist returned %d\n", + rc ); + send_ldap_error( op, rs, LDAP_NO_SUCH_OBJECT, + "no DNS SRV RR available for DN" ); + goto done; + } + + hosts = ldap_str2charray( hostlist, " " ); + + if( hosts == NULL ) { + Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charray error\n" ); + send_ldap_error( op, rs, LDAP_OTHER, + "problem processing DNS SRV records for DN" ); + goto done; + } + + for( i=0; hosts[i] != NULL; i++) { + struct berval url; + + url.bv_len = STRLENOF( "ldap://" ) + strlen(hosts[i]); + url.bv_val = ch_malloc( url.bv_len + 1 ); + + strcpy( url.bv_val, "ldap://" ); + strcpy( &url.bv_val[STRLENOF( "ldap://" )], hosts[i] ); + + if( ber_bvarray_add( &urls, &url ) < 0 ) { + free( url.bv_val ); + send_ldap_error( op, rs, LDAP_OTHER, + "problem processing DNS SRV records for DN" ); + goto done; + } + } + + Debug( LDAP_DEBUG_STATS, + "%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 ); + + Debug( LDAP_DEBUG_TRACE, + "DNSSRV: ManageDSAit scope=%d dn=\"%s\" -> url=\"%s\"\n", + op->oq_search.rs_scope, + op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "", + urls[0].bv_val ); + + rc = ldap_domain2dn(domain, &refdn); + + if( rc != LDAP_SUCCESS ) { + send_ldap_error( op, rs, LDAP_OTHER, + "DNS SRV problem processing manageDSAit control" ); + goto done; + + } else { + struct berval bv; + bv.bv_val = refdn; + bv.bv_len = strlen( refdn ); + + rc = dnNormalize( 0, NULL, NULL, &bv, &nrefdn, op->o_tmpmemctx ); + if( rc != LDAP_SUCCESS ) { + send_ldap_error( op, rs, LDAP_OTHER, + "DNS SRV problem processing manageDSAit control" ); + goto done; + } + } + + if( !dn_match( &nrefdn, &op->o_req_ndn ) ) { + /* requested dn is subordinate */ + + Debug( LDAP_DEBUG_TRACE, + "DNSSRV: dn=\"%s\" subordinate to refdn=\"%s\"\n", + op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "", + refdn == NULL ? "" : refdn ); + + rs->sr_matched = refdn; + rs->sr_err = LDAP_NO_SUCH_OBJECT; + send_ldap_result( op, rs ); + rs->sr_matched = NULL; + + } else if ( op->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL ) { + send_ldap_error( op, rs, LDAP_SUCCESS, NULL ); + + } else { + Entry e = { 0 }; + AttributeDescription *ad_objectClass + = slap_schema.si_ad_objectClass; + AttributeDescription *ad_ref = slap_schema.si_ad_ref; + e.e_name.bv_val = ch_strdup( op->o_req_dn.bv_val ); + e.e_name.bv_len = op->o_req_dn.bv_len; + e.e_nname.bv_val = ch_strdup( op->o_req_ndn.bv_val ); + e.e_nname.bv_len = op->o_req_ndn.bv_len; + + e.e_attrs = NULL; + e.e_private = NULL; + + attr_merge_one( &e, ad_objectClass, &slap_schema.si_oc_referral->soc_cname, NULL ); + attr_merge_one( &e, ad_objectClass, &slap_schema.si_oc_extensibleObject->soc_cname, NULL ); + + if ( ad_dc ) { + char *p; + struct berval bv; + + bv.bv_val = domain; + + p = strchr( bv.bv_val, '.' ); + + if ( p == bv.bv_val ) { + bv.bv_len = 1; + + } else if ( p != NULL ) { + bv.bv_len = p - bv.bv_val; + + } else { + bv.bv_len = strlen( bv.bv_val ); + } + + attr_merge_normalize_one( &e, ad_dc, &bv, NULL ); + } + + if ( ad_associatedDomain ) { + struct berval bv; + + ber_str2bv( domain, 0, 0, &bv ); + attr_merge_normalize_one( &e, ad_associatedDomain, &bv, NULL ); + } + + attr_merge_normalize_one( &e, ad_ref, urls, NULL ); + + rc = test_filter( op, &e, op->oq_search.rs_filter ); + + if( rc == LDAP_COMPARE_TRUE ) { + rs->sr_entry = &e; + rs->sr_attrs = op->oq_search.rs_attrs; + rs->sr_flags = REP_ENTRY_MODIFIABLE; + send_search_entry( op, rs ); + rs->sr_entry = NULL; + rs->sr_attrs = NULL; + rs->sr_flags = 0; + } + + entry_clean( &e ); + + rs->sr_err = LDAP_SUCCESS; + send_ldap_result( op, rs ); + } + + free( refdn ); + if ( nrefdn.bv_val ) free( nrefdn.bv_val ); + +done: + if( domain != NULL ) ch_free( domain ); + if( hostlist != NULL ) ch_free( hostlist ); + if( hosts != NULL ) ldap_charray_free( hosts ); + if( urls != NULL ) ber_bvarray_free( urls ); + return 0; +} |