1 /* referral.c - DNS SRV backend referral handler */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-dnssrv/referral.c,v 1.26.2.4 2008/02/11 23:26:46 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 The OpenLDAP Foundation.
6 * Portions Copyright 2000-2003 Kurt D. Zeilenga.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was originally developed by Kurt D. Zeilenga for inclusion
19 * in OpenLDAP Software.
26 #include <ac/string.h>
27 #include <ac/socket.h>
30 #include "proto-dnssrv.h"
33 dnssrv_back_referrals(
40 char *hostlist
= NULL
;
42 BerVarray urls
= NULL
;
44 if ( BER_BVISEMPTY( &op
->o_req_dn
) ) {
45 /* FIXME: need some means to determine whether the database
46 * is a glue instance */
47 if ( SLAP_GLUE_INSTANCE( op
->o_bd
) ) {
51 rs
->sr_text
= "DNS SRV operation upon null (empty) DN disallowed";
52 return LDAP_UNWILLING_TO_PERFORM
;
55 if( get_manageDSAit( op
) ) {
56 if( op
->o_tag
== LDAP_REQ_SEARCH
) {
60 rs
->sr_text
= "DNS SRV problem processing manageDSAit control";
64 if( ldap_dn2domain( op
->o_req_dn
.bv_val
, &domain
) || domain
== NULL
) {
65 rs
->sr_err
= LDAP_REFERRAL
;
66 rs
->sr_ref
= default_referral
;
67 send_ldap_result( op
, rs
);
72 Debug( LDAP_DEBUG_TRACE
, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n",
73 op
->o_req_dn
.bv_val
, domain
, 0 );
75 i
= ldap_domain2hostlist( domain
, &hostlist
);
77 Debug( LDAP_DEBUG_TRACE
,
78 "DNSSRV: domain2hostlist(%s) returned %d\n",
80 rs
->sr_text
= "no DNS SRV RR available for DN";
81 rc
= LDAP_NO_SUCH_OBJECT
;
85 hosts
= ldap_str2charray( hostlist
, " " );
88 Debug( LDAP_DEBUG_TRACE
, "DNSSRV: str2charrary error\n", 0, 0, 0 );
89 rs
->sr_text
= "problem processing DNS SRV records for DN";
93 for( i
=0; hosts
[i
] != NULL
; i
++) {
96 url
.bv_len
= STRLENOF( "ldap://" ) + strlen( hosts
[i
] );
97 url
.bv_val
= ch_malloc( url
.bv_len
+ 1 );
99 strcpy( url
.bv_val
, "ldap://" );
100 strcpy( &url
.bv_val
[STRLENOF( "ldap://" )], hosts
[i
] );
102 if ( ber_bvarray_add( &urls
, &url
) < 0 ) {
104 rs
->sr_text
= "problem processing DNS SRV records for DN";
109 Statslog( LDAP_DEBUG_STATS
,
110 "%s DNSSRV p=%d dn=\"%s\" url=\"%s\"\n",
111 op
->o_log_prefix
, op
->o_protocol
,
112 op
->o_req_dn
.bv_val
, urls
[0].bv_val
, 0 );
114 Debug( LDAP_DEBUG_TRACE
, "DNSSRV: dn=\"%s\" -> url=\"%s\"\n",
115 op
->o_req_dn
.bv_val
, urls
[0].bv_val
, 0 );
118 send_ldap_error( op
, rs
, LDAP_REFERRAL
,
119 "DNS SRV generated referrals" );
124 if( domain
!= NULL
) ch_free( domain
);
125 if( hostlist
!= NULL
) ch_free( hostlist
);
126 if( hosts
!= NULL
) ldap_charray_free( hosts
);
127 ber_bvarray_free( urls
);