]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/entry.c
Do not return pointers into BerElement we do not own
[openldap] / servers / slapd / back-ldbm / entry.c
1 /* entry.c - ldbm backend entry_release routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
18
19
20 int
21 ldbm_back_entry_release_rw(
22         Operation *op,
23         Entry   *e,
24         int     rw
25 )
26 {
27         struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
28
29         if ( slapMode == SLAP_SERVER_MODE ) {
30                 /* free entry and reader or writer lock */
31                 cache_return_entry_rw( &li->li_cache, e, rw ); 
32                 /* only do_add calls here with a write lock.
33                  * get_entry doesn't obtain the giant lock, because its
34                  * caller has already obtained it.
35                  */
36                 if( rw ) {
37                         ldap_pvt_thread_rdwr_wunlock( &li->li_giant_rwlock );
38                 }
39 #if 0
40                 else {
41                         ldap_pvt_thread_rdwr_runlock( &li->li_giant_rwlock );
42                 }
43 #endif
44
45         } else {
46                 entry_free( e );
47         }
48
49         return 0;
50 }
51
52 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
53  */
54 int ldbm_back_entry_get(
55         Operation *op,
56         struct berval *ndn,
57         ObjectClass *oc,
58         AttributeDescription *at,
59         int rw,
60         Entry **ent )
61 {
62         struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
63         Entry *e;
64         int     rc;
65         const char *at_name = at->ad_cname.bv_val;
66
67 #ifdef NEW_LOGGING
68         LDAP_LOG( BACK_BDB, ARGS, 
69                 "ldbm_back_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 );
70         LDAP_LOG( BACK_BDB, ARGS, 
71                 "ldbm_back_entry_get: oc: \"%s\", at: \"%s\"\n",
72                 oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);
73 #else
74         Debug( LDAP_DEBUG_ARGS,
75                 "=> ldbm_back_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 ); 
76         Debug( LDAP_DEBUG_ARGS,
77                 "=> ldbm_back_entry_get: oc: \"%s\", at: \"%s\"\n",
78                 oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);
79 #endif
80
81         /* don't grab the giant lock - our caller has already gotten it. */
82
83         /* can we find entry */
84         e = dn2entry_rw( op->o_bd, ndn, NULL, rw );
85         if (e == NULL) {
86 #ifdef NEW_LOGGING
87                 LDAP_LOG( BACK_BDB, INFO, 
88                         "ldbm_back_entry_get: cannot find entry (%s)\n", 
89                         ndn->bv_val, 0, 0 );
90 #else
91                 Debug( LDAP_DEBUG_ACL,
92                         "=> ldbm_back_entry_get: cannot find entry: \"%s\"\n",
93                                 ndn->bv_val, 0, 0 ); 
94 #endif
95                 return LDAP_NO_SUCH_OBJECT; 
96         }
97         
98 #ifdef NEW_LOGGING
99         LDAP_LOG( BACK_BDB, DETAIL1, "ldbm_back_entry_get: found entry (%s)\n",
100                 ndn->bv_val, 0, 0 );
101 #else
102         Debug( LDAP_DEBUG_ACL,
103                 "=> ldbm_back_entry_get: found entry: \"%s\"\n",
104                 ndn->bv_val, 0, 0 ); 
105 #endif
106
107 #ifdef BDB_ALIASES
108         /* find attribute values */
109         if( is_entry_alias( e ) ) {
110 #ifdef NEW_LOGGING
111                 LDAP_LOG( BACK_BDB, INFO, 
112                         "ldbm_back_entry_get: entry (%s) is an alias\n", e->e_name.bv_val, 0, 0 );
113 #else
114                 Debug( LDAP_DEBUG_ACL,
115                         "<= ldbm_back_entry_get: entry is an alias\n", 0, 0, 0 );
116 #endif
117                 rc = LDAP_ALIAS_PROBLEM;
118                 goto return_results;
119         }
120 #endif
121
122         if( is_entry_referral( e ) ) {
123 #ifdef NEW_LOGGING
124                 LDAP_LOG( BACK_BDB, INFO, 
125                         "ldbm_back_entry_get: entry (%s) is a referral.\n", e->e_name.bv_val, 0, 0);
126 #else
127                 Debug( LDAP_DEBUG_ACL,
128                         "<= ldbm_back_entry_get: entry is a referral\n", 0, 0, 0 );
129 #endif
130                 rc = LDAP_REFERRAL;
131                 goto return_results;
132         }
133
134         if ( oc && !is_entry_objectclass( e, oc, 0 )) {
135 #ifdef NEW_LOGGING
136                 LDAP_LOG( BACK_BDB, INFO, 
137                         "ldbm_back_entry_get: failed to find objectClass.\n", 0, 0, 0 );
138 #else
139                 Debug( LDAP_DEBUG_ACL,
140                         "<= ldbm_back_entry_get: failed to find objectClass\n",
141                         0, 0, 0 ); 
142 #endif
143                 rc = LDAP_NO_SUCH_ATTRIBUTE;
144                 goto return_results;
145         }
146
147         rc = LDAP_SUCCESS;
148
149 return_results:
150         if( rc != LDAP_SUCCESS ) {
151                 /* free entry */
152                 cache_return_entry_rw(&li->li_cache, e, rw);
153         } else {
154                 *ent = e;
155         }
156
157 #ifdef NEW_LOGGING
158         LDAP_LOG( BACK_BDB, ENTRY, "ldbm_back_entry_get: rc=%d\n", rc, 0, 0 );
159 #else
160         Debug( LDAP_DEBUG_TRACE,
161                 "ldbm_back_entry_get: rc=%d\n",
162                 rc, 0, 0 ); 
163 #endif
164         return(rc);
165 }