]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/entry.c
rework op/rs structures to deal with opeartional attributes
[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                 if ( e->e_private ) {
56                         free( e->e_private );
57                         e->e_private = NULL;
58                 }
59                 entry_free( e );
60         }
61
62         return 0;
63 }
64
65 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
66  */
67 int ldbm_back_entry_get(
68         Operation *op,
69         struct berval *ndn,
70         ObjectClass *oc,
71         AttributeDescription *at,
72         int rw,
73         Entry **ent )
74 {
75         struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
76         Entry *e;
77         int     rc;
78         const char *at_name = at ? at->ad_cname.bv_val : "(null)";
79
80 #ifdef NEW_LOGGING
81         LDAP_LOG( BACK_LDBM, ARGS, 
82                 "ldbm_back_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 );
83         LDAP_LOG( BACK_LDBM, ARGS, 
84                 "ldbm_back_entry_get: oc: \"%s\", at: \"%s\"\n",
85                 oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);
86 #else
87         Debug( LDAP_DEBUG_ARGS,
88                 "=> ldbm_back_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 ); 
89         Debug( LDAP_DEBUG_ARGS,
90                 "=> ldbm_back_entry_get: oc: \"%s\", at: \"%s\"\n",
91                 oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);
92 #endif
93
94         /* don't grab the giant lock - our caller has already gotten it. */
95
96         /* can we find entry */
97         e = dn2entry_rw( op->o_bd, ndn, NULL, rw );
98         if (e == NULL) {
99 #ifdef NEW_LOGGING
100                 LDAP_LOG( BACK_LDBM, INFO, 
101                         "ldbm_back_entry_get: cannot find entry (%s)\n", 
102                         ndn->bv_val, 0, 0 );
103 #else
104                 Debug( LDAP_DEBUG_ACL,
105                         "=> ldbm_back_entry_get: cannot find entry: \"%s\"\n",
106                                 ndn->bv_val, 0, 0 ); 
107 #endif
108                 return LDAP_NO_SUCH_OBJECT; 
109         }
110         
111 #ifdef NEW_LOGGING
112         LDAP_LOG( BACK_LDBM, DETAIL1, "ldbm_back_entry_get: found entry (%s)\n",
113                 ndn->bv_val, 0, 0 );
114 #else
115         Debug( LDAP_DEBUG_ACL,
116                 "=> ldbm_back_entry_get: found entry: \"%s\"\n",
117                 ndn->bv_val, 0, 0 ); 
118 #endif
119
120 #ifdef BDB_ALIASES
121         /* find attribute values */
122         if( is_entry_alias( e ) ) {
123 #ifdef NEW_LOGGING
124                 LDAP_LOG( BACK_LDBM, INFO, 
125                         "ldbm_back_entry_get: entry (%s) is an alias\n", e->e_name.bv_val, 0, 0 );
126 #else
127                 Debug( LDAP_DEBUG_ACL,
128                         "<= ldbm_back_entry_get: entry is an alias\n", 0, 0, 0 );
129 #endif
130                 rc = LDAP_ALIAS_PROBLEM;
131                 goto return_results;
132         }
133 #endif
134
135         if( is_entry_referral( e ) ) {
136 #ifdef NEW_LOGGING
137                 LDAP_LOG( BACK_LDBM, INFO, 
138                         "ldbm_back_entry_get: entry (%s) is a referral.\n", e->e_name.bv_val, 0, 0);
139 #else
140                 Debug( LDAP_DEBUG_ACL,
141                         "<= ldbm_back_entry_get: entry is a referral\n", 0, 0, 0 );
142 #endif
143                 rc = LDAP_REFERRAL;
144                 goto return_results;
145         }
146
147         if ( oc && !is_entry_objectclass( e, oc, 0 )) {
148 #ifdef NEW_LOGGING
149                 LDAP_LOG( BACK_LDBM, INFO, 
150                         "ldbm_back_entry_get: failed to find objectClass.\n", 0, 0, 0 );
151 #else
152                 Debug( LDAP_DEBUG_ACL,
153                         "<= ldbm_back_entry_get: failed to find objectClass\n",
154                         0, 0, 0 ); 
155 #endif
156                 rc = LDAP_NO_SUCH_ATTRIBUTE;
157                 goto return_results;
158         }
159
160         rc = LDAP_SUCCESS;
161
162 return_results:
163         if( rc != LDAP_SUCCESS ) {
164                 /* free entry */
165                 cache_return_entry_rw(&li->li_cache, e, rw);
166         } else {
167                 *ent = e;
168         }
169
170 #ifdef NEW_LOGGING
171         LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_entry_get: rc=%d\n", rc, 0, 0 );
172 #else
173         Debug( LDAP_DEBUG_TRACE,
174                 "ldbm_back_entry_get: rc=%d\n",
175                 rc, 0, 0 ); 
176 #endif
177         return(rc);
178 }