X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=servers%2Fslapd%2Fback-dnssrv%2Freferral.c;h=2ef38b8d058717b43b940bdcde0235b06ca3952a;hb=fcf97e84486e1159c0f57114e3b130cf49d7f89d;hp=4bd8fbe037827c2e57655f2fa87d86d335c9e1f6;hpb=23efa07a994c94c4e78a9495ac6e2981b87b4ba0;p=openldap diff --git a/servers/slapd/back-dnssrv/referral.c b/servers/slapd/back-dnssrv/referral.c index 4bd8fbe037..2ef38b8d05 100644 --- a/servers/slapd/back-dnssrv/referral.c +++ b/servers/slapd/back-dnssrv/referral.c @@ -1,8 +1,22 @@ /* referral.c - DNS SRV backend referral handler */ /* $OpenLDAP$ */ -/* - * Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 2000-2009 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 + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by Kurt D. Zeilenga for inclusion + * in OpenLDAP Software. */ #include "portable.h" @@ -13,16 +27,12 @@ #include #include "slap.h" -#include "external.h" +#include "proto-dnssrv.h" int dnssrv_back_referrals( - Backend *be, - Connection *conn, Operation *op, - struct berval *dn, - struct berval *ndn, - const char **text ) + SlapReply *rs ) { int i; int rc = LDAP_OTHER; @@ -31,8 +41,14 @@ dnssrv_back_referrals( char **hosts = NULL; BerVarray urls = NULL; - if( ndn->bv_len == 0 ) { - *text = "DNS SRV operation upon null (empty) DN disallowed"; + 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; } @@ -41,26 +57,27 @@ dnssrv_back_referrals( return LDAP_SUCCESS; } - *text = "DNS SRV problem processing manageDSAit control"; + rs->sr_text = "DNS SRV problem processing manageDSAit control"; return LDAP_OTHER; } - if( ldap_dn2domain( dn->bv_val, &domain ) ) { - send_ldap_result( conn, op, LDAP_REFERRAL, - NULL, NULL, default_referral, NULL ); + 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", - dn->bv_val, - domain == NULL ? "" : domain, - 0 ); + op->o_req_dn.bv_val, domain, 0 ); - if( ( rc = ldap_domain2hostlist( domain, &hostlist ) ) ) { + i = ldap_domain2hostlist( domain, &hostlist ); + if ( i ) { Debug( LDAP_DEBUG_TRACE, "DNSSRV: domain2hostlist(%s) returned %d\n", - domain, rc, 0 ); - *text = "no DNS SRV RR available for DN"; + domain, i, 0 ); + rs->sr_text = "no DNS SRV RR available for DN"; rc = LDAP_NO_SUCH_OBJECT; goto done; } @@ -69,36 +86,39 @@ dnssrv_back_referrals( if( hosts == NULL ) { Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charrary error\n", 0, 0, 0 ); - *text = "problem processing DNS SRV records for DN"; + 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 = sizeof("ldap://")-1 + strlen(hosts[i]); + 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[sizeof("ldap://")-1], hosts[i] ); + strcpy( &url.bv_val[STRLENOF( "ldap://" )], hosts[i] ); if ( ber_bvarray_add( &urls, &url ) < 0 ) { free( url.bv_val ); - *text = "problem processing DNS SRV records for DN"; + rs->sr_text = "problem processing DNS SRV records for DN"; goto done; } } Statslog( LDAP_DEBUG_STATS, - "conn=%lu op=%lu DNSSRV p=%d dn=\"%s\" url=\"%s\"\n", - op->o_connid, op->o_opid, op->o_protocol, - dn->bv_val, urls[0].bv_val ); + "%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, 0 ); Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> url=\"%s\"\n", - dn->bv_val, urls[0].bv_val, 0 ); + op->o_req_dn.bv_val, urls[0].bv_val, 0 ); - send_ldap_result( conn, op, rc = LDAP_REFERRAL, - NULL, "DNS SRV generated referrals", urls, NULL ); + 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 );