]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/referral.c
Delete extranous assert()
[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;
27         Entry *matched = NULL;
28
29         if( op->o_tag == LDAP_REQ_SEARCH ) {
30                 /* let search take care of itself */
31                 return rc;
32         }
33
34         if( get_manageDSAit( op ) ) {
35                 /* let op take care of DSA management */
36                 return rc;
37         } 
38
39         /* get entry */
40         rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
41
42         switch(rc) {
43         case DB_NOTFOUND:
44                 rc = 0;
45         case 0:
46                 break;
47         case LDAP_BUSY:
48                 if (e != NULL) {
49                         bdb_cache_return_entry_r(&bdb->bi_cache, e);
50                 }
51                 if (matched != NULL) {
52                         bdb_cache_return_entry_r(&bdb->bi_cache, matched);
53                 }
54                 send_ldap_result( conn, op, LDAP_BUSY,
55                         NULL, "ldap server busy", NULL, NULL );
56                 return LDAP_BUSY;
57         default:
58 #ifdef NEW_LOGGING
59                 LDAP_LOG (( "referral", LDAP_LEVEL_ERR,
60                         "bdb_referrals: dn2entry failed: %s (%d)\n",
61                         db_strerror(rc), rc ));
62 #else
63                 Debug( LDAP_DEBUG_TRACE,
64                         "bdb_referrals: dn2entry failed: %s (%d)\n",
65                         db_strerror(rc), rc, 0 ); 
66 #endif
67                 if (e != NULL) {
68                         bdb_cache_return_entry_r(&bdb->bi_cache, e);
69                 }
70                 if (matched != NULL) {
71                         bdb_cache_return_entry_r(&bdb->bi_cache, matched);
72                 }
73                 send_ldap_result( conn, op, rc=LDAP_OTHER,
74                         NULL, "internal error", NULL, NULL );
75                 return rc;
76         }
77
78         if ( e == NULL ) {
79                 char *matched_dn = NULL;
80                 BerVarray refs = NULL;
81
82                 if ( matched != NULL ) {
83                         matched_dn = ch_strdup( matched->e_dn );
84
85 #ifdef NEW_LOGGING
86                 LDAP_LOG (( "referral", LDAP_LEVEL_DETAIL1,
87                         "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
88                         (long) op->o_tag, dn->bv_val, matched_dn ));
89 #else
90                         Debug( LDAP_DEBUG_TRACE,
91                                 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
92                                 (long) op->o_tag, dn->bv_val, matched_dn );
93 #endif
94
95                         if( is_entry_referral( matched ) ) {
96                                 rc = LDAP_OTHER;
97                                 refs = get_entry_referrals( be, conn, op, matched );
98                         }
99
100                         bdb_cache_return_entry_r (&bdb->bi_cache, matched);
101                         matched = NULL;
102                 } else if ( default_referral != NULL ) {
103                         rc = LDAP_OTHER;
104                         refs = referral_rewrite( default_referral,
105                                 NULL, dn, LDAP_SCOPE_DEFAULT );
106                 }
107
108                 if( refs != NULL ) {
109                         /* send referrals */
110                         send_ldap_result( conn, op, rc = LDAP_REFERRAL,
111                                 matched_dn, NULL, refs, NULL );
112                         ber_bvarray_free( refs );
113                 } else if ( rc != LDAP_SUCCESS ) {
114                         send_ldap_result( conn, op, rc, matched_dn,
115                                 matched_dn ? "bad referral object" : NULL,
116                                 NULL, NULL );
117                 }
118
119                 free( matched_dn );
120                 return rc;
121         }
122
123         if ( is_entry_referral( e ) ) {
124                 /* entry is a referral */
125                 BerVarray refs = get_entry_referrals( be, conn, op, e );
126                 BerVarray rrefs = referral_rewrite(
127                         refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
128
129 #ifdef NEW_LOGGING
130                 LDAP_LOG (( "referral", LDAP_LEVEL_DETAIL1,
131                         "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
132                         (long) op->o_tag, dn->bv_val, e->e_dn ));
133 #else
134                 Debug( LDAP_DEBUG_TRACE,
135                         "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
136                         (long) op->o_tag, dn->bv_val, e->e_dn );
137 #endif
138
139                 if( rrefs != NULL ) {
140                         send_ldap_result( conn, op, rc = LDAP_REFERRAL,
141                                 e->e_dn, NULL, rrefs, NULL );
142                         ber_bvarray_free( rrefs );
143                 } else {
144                         send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
145                                 "bad referral object", NULL, NULL );
146                 }
147
148                 ber_bvarray_free( refs );
149         }
150
151         bdb_cache_return_entry_r(&bdb->bi_cache, e);
152         return rc;
153 }