File: referral.c

package info (click to toggle)
openldap2.3 2.3.30-5%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 18,316 kB
  • ctags: 15,854
  • sloc: ansic: 210,071; sh: 28,305; cpp: 4,231; sql: 1,661; makefile: 1,515; perl: 870
file content (127 lines) | stat: -rw-r--r-- 3,315 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* referral.c - LDBM backend referral handler */
/* $OpenLDAP: pkg/ldap/servers/slapd/back-ldbm/referral.c,v 1.24.2.3 2006/01/06 19:46:16 kurt Exp $ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
 * Copyright 1998-2006 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>.
 */

#include "portable.h"

#include <stdio.h>

#include <ac/string.h>
#include <ac/socket.h>

#include "slap.h"
#include "back-ldbm.h"

int
ldbm_back_referrals(
    Operation	*op,
    SlapReply	*rs )
{
	struct ldbminfo	*li = (struct ldbminfo *) op->o_bd->be_private;
	Entry		*e, *matched;
	int		rc = LDAP_SUCCESS;

	if( op->o_tag == LDAP_REQ_SEARCH ) {
		/* let search take care of itself */
		return LDAP_SUCCESS;
	}

	if( get_manageDSAit( op ) ) {
		/* let op take care of DSA management */
		return LDAP_SUCCESS;
	} 

	/* grab giant lock for reading */
	ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);

	/* get entry with reader lock */
	e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched );
	if ( e == NULL ) {
		if ( matched != NULL ) {
			rs->sr_matched = ch_strdup( matched->e_dn );

			Debug( LDAP_DEBUG_TRACE,
				"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
				op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );

			if ( is_entry_referral( matched ) ) {
				rc = rs->sr_err = LDAP_OTHER;
				rs->sr_ref = get_entry_referrals( op, matched );
			}

			cache_return_entry_r( &li->li_cache, matched );

		} else if ( !be_issuffix( op->o_bd, &op->o_req_ndn ) && default_referral != NULL ) {
			rc = rs->sr_err = LDAP_OTHER;
			rs->sr_ref = referral_rewrite( default_referral,
				NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
		}

		ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);

		if ( rs->sr_ref != NULL ) {
			/* send referrals */
			rc = rs->sr_err = LDAP_REFERRAL;

		} else {
			rs->sr_text = rs->sr_matched ? "bad referral object" : "bad default referral";
		}

		if ( rc != LDAP_SUCCESS ) {
			send_ldap_result( op, rs );
		}

		if ( rs->sr_matched ) free( (char *)rs->sr_matched );
		if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
		rs->sr_text = NULL;
		rs->sr_ref = NULL;
		rs->sr_matched = NULL;

		return rc;
	}

	if ( is_entry_referral( e ) ) {
		/* entry is a referral */
		BerVarray refs = get_entry_referrals( op, e );
		rs->sr_ref = referral_rewrite(
			refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );

		Debug( LDAP_DEBUG_TRACE,
			"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
			op->o_tag, op->o_req_dn.bv_val, e->e_dn );

		rs->sr_matched = e->e_name.bv_val;
		if( rs->sr_ref != NULL ) {
			rc = rs->sr_err = LDAP_REFERRAL;
			rs->sr_text = NULL;

		} else {
			rc = rs->sr_err = LDAP_OTHER;
			rs->sr_text = "bad referral object";
		}
		send_ldap_result( op, rs );

		if ( refs != NULL ) ber_bvarray_free( refs );
		rs->sr_err = rc;
		rs->sr_ref = NULL;
		rs->sr_text = NULL;
		rs->sr_matched = NULL;
	}

	cache_return_entry_r( &li->li_cache, e );
	ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);

	return rc;
}