]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/referral.c
Delete CDB (no transactions) support
[openldap] / servers / slapd / back-bdb / referral.c
1 /* referral.c - BDB backend referral handler */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9 #include <stdio.h>
10 #include <ac/string.h>
11
12 #include "back-bdb.h"
13 #include "external.h"
14
15 int
16 bdb_referrals(
17         BackendDB       *be,
18         Connection      *conn,
19         Operation       *op,
20         struct berval *dn,
21         struct berval *ndn,
22         const char **text )
23 {
24         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
25         int rc = LDAP_SUCCESS;
26         Entry *e = NULL, *matched;
27
28         if( op->o_tag == LDAP_REQ_SEARCH ) {
29                 /* let search take care of itself */
30                 return rc;
31         }
32
33         if( get_manageDSAit( op ) ) {
34                 /* let op take care of DSA management */
35                 return rc;
36         } 
37
38         /* get entry */
39         rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
40
41         switch(rc) {
42         case DB_NOTFOUND:
43                 rc = 0;
44         case 0:
45                 break;
46         default:
47                 Debug( LDAP_DEBUG_TRACE,
48                         "bdb_referrals: dn2entry failed: %s (%d)\n",
49                         db_strerror(rc), rc, 0 ); 
50                 if (e != NULL) {
51                         bdb_cache_return_entry_r(&bdb->bi_cache, e);
52                 }
53                 if (matched != NULL) {
54                         bdb_cache_return_entry_r(&bdb->bi_cache, matched);
55                 }
56                 send_ldap_result( conn, op, rc=LDAP_OTHER,
57                         NULL, "internal error", NULL, NULL );
58                 return rc;
59         }
60
61         if ( e == NULL ) {
62                 char *matched_dn = NULL;
63                 BerVarray refs = NULL;
64
65                 if ( matched != NULL ) {
66                         matched_dn = ch_strdup( matched->e_dn );
67
68                         Debug( LDAP_DEBUG_TRACE,
69                                 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
70                                 (long) op->o_tag, dn->bv_val, matched_dn );
71
72                         if( is_entry_referral( matched ) ) {
73                                 rc = LDAP_OTHER;
74                                 refs = get_entry_referrals( be, conn, op, matched );
75                         }
76
77                         bdb_cache_return_entry_r (&bdb->bi_cache, matched);
78                         matched = NULL;
79                 } else if ( default_referral != NULL ) {
80                         rc = LDAP_OTHER;
81                         refs = referral_rewrite( default_referral,
82                                 NULL, dn, LDAP_SCOPE_DEFAULT );
83                 }
84
85                 if( refs != NULL ) {
86                         /* send referrals */
87                         send_ldap_result( conn, op, rc = LDAP_REFERRAL,
88                                 matched_dn, NULL, refs, NULL );
89                         ber_bvarray_free( refs );
90                 } else if ( rc != LDAP_SUCCESS ) {
91                         send_ldap_result( conn, op, rc, matched_dn,
92                                 matched_dn ? "bad referral object" : NULL,
93                                 NULL, NULL );
94                 }
95
96                 free( matched_dn );
97                 return rc;
98         }
99
100         if ( is_entry_referral( e ) ) {
101                 /* entry is a referral */
102                 BerVarray refs = get_entry_referrals( be, conn, op, e );
103                 BerVarray rrefs = referral_rewrite(
104                         refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
105
106                 Debug( LDAP_DEBUG_TRACE,
107                         "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
108                         (long) op->o_tag, dn->bv_val, e->e_dn );
109
110                 if( rrefs != NULL ) {
111                         send_ldap_result( conn, op, rc = LDAP_REFERRAL,
112                                 e->e_dn, NULL, rrefs, NULL );
113                         ber_bvarray_free( rrefs );
114                 } else {
115                         send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
116                                 "bad referral object", NULL, NULL );
117                 }
118
119                 ber_bvarray_free( refs );
120         }
121
122         bdb_cache_return_entry_r(&bdb->bi_cache, e);
123         return rc;
124 }