openldap/servers/slapd/back-dnssrv/referral.c

130 lines
3.2 KiB
C
Raw Normal View History

2000-06-17 03:10:43 +08:00
/* referral.c - DNS SRV backend referral handler */
/* $OpenLDAP$ */
2003-11-27 01:28:33 +08:00
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2020-01-10 00:50:21 +08:00
* Copyright 2000-2020 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-06-17 03:10:43 +08:00
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
2004-11-11 08:38:11 +08:00
#include "proto-dnssrv.h"
2000-06-17 03:10:43 +08:00
int
dnssrv_back_referrals(
Operation *op,
SlapReply *rs )
2000-06-17 03:10:43 +08:00
{
int i;
int rc = LDAP_OTHER;
char *domain = NULL;
char *hostlist = NULL;
char **hosts = NULL;
BerVarray urls = NULL;
2000-06-17 03:10:43 +08:00
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";
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;
}
rs->sr_text = "DNS SRV problem processing manageDSAit control";
2000-06-17 03:10:43 +08:00
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;
2000-06-17 03:10:43 +08:00
return LDAP_REFERRAL;
}
Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n",
op->o_req_dn.bv_val, domain );
2000-06-17 03:10:43 +08:00
2005-04-09 06:11:56 +08:00
i = ldap_domain2hostlist( domain, &hostlist );
if ( i ) {
2001-12-27 02:04:06 +08:00
Debug( LDAP_DEBUG_TRACE,
"DNSSRV: domain2hostlist(%s) returned %d\n",
domain, i );
rs->sr_text = "no DNS SRV RR available for DN";
2000-06-17 03:10:43 +08:00
rc = LDAP_NO_SUCH_OBJECT;
goto done;
}
hosts = ldap_str2charray( hostlist, " " );
2000-06-17 03:10:43 +08:00
if( hosts == NULL ) {
Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charray error\n" );
rs->sr_text = "problem processing DNS SRV records for DN";
2000-06-17 03:10:43 +08:00
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
2005-04-10 00:50:07 +08:00
url.bv_len = STRLENOF( "ldap://" ) + strlen( hosts[i] );
2002-01-02 21:03:06 +08:00
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://" );
2005-04-10 00:50:07 +08:00
strcpy( &url.bv_val[STRLENOF( "ldap://" )], hosts[i] );
2000-06-17 03:10:43 +08:00
if ( ber_bvarray_add( &urls, &url ) < 0 ) {
2002-01-02 21:03:06 +08:00
free( url.bv_val );
rs->sr_text = "problem processing DNS SRV records for DN";
2000-06-17 03:10:43 +08:00
goto done;
}
}
Debug( 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_val, urls[0].bv_val );
2000-06-17 03:10:43 +08:00
Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> url=\"%s\"\n",
op->o_req_dn.bv_val, urls[0].bv_val );
2000-06-17 03:10:43 +08:00
rs->sr_ref = urls;
send_ldap_error( op, rs, LDAP_REFERRAL,
"DNS SRV generated referrals" );
2005-04-09 05:38:38 +08:00
rs->sr_ref = NULL;
2005-04-09 06:06:06 +08:00
rc = LDAP_REFERRAL;
2000-06-17 03:10:43 +08:00
done:
if( domain != NULL ) ch_free( domain );
if( hostlist != NULL ) ch_free( hostlist );
if( hosts != NULL ) ldap_charray_free( hosts );
ber_bvarray_free( urls );
2005-04-09 06:06:06 +08:00
return rc;
2000-06-17 03:10:43 +08:00
}