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