]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/entry.c
f8da8e07e841de2366aa7a6004a4e6851594a8e2
[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-2005 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         Debug( LDAP_DEBUG_ARGS,
81                 "=> ldbm_back_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 ); 
82         Debug( LDAP_DEBUG_ARGS,
83                 "=> ldbm_back_entry_get: oc: \"%s\", at: \"%s\"\n",
84                 oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);
85
86         /* don't grab the giant lock - our caller has already gotten it. */
87
88         /* can we find entry */
89         e = dn2entry_rw( op->o_bd, ndn, NULL, rw );
90         if (e == NULL) {
91                 Debug( LDAP_DEBUG_ACL,
92                         "=> ldbm_back_entry_get: cannot find entry: \"%s\"\n",
93                                 ndn->bv_val, 0, 0 ); 
94                 return LDAP_NO_SUCH_OBJECT; 
95         }
96         
97         Debug( LDAP_DEBUG_ACL,
98                 "=> ldbm_back_entry_get: found entry: \"%s\"\n",
99                 ndn->bv_val, 0, 0 ); 
100
101 #ifdef BDB_ALIASES
102         /* find attribute values */
103         if( is_entry_alias( e ) ) {
104                 Debug( LDAP_DEBUG_ACL,
105                         "<= ldbm_back_entry_get: entry is an alias\n", 0, 0, 0 );
106                 rc = LDAP_ALIAS_PROBLEM;
107                 goto return_results;
108         }
109 #endif
110
111         if( is_entry_referral( e ) ) {
112                 Debug( LDAP_DEBUG_ACL,
113                         "<= ldbm_back_entry_get: entry is a referral\n", 0, 0, 0 );
114                 rc = LDAP_REFERRAL;
115                 goto return_results;
116         }
117
118         if ( oc && !is_entry_objectclass( e, oc, 0 )) {
119                 Debug( LDAP_DEBUG_ACL,
120                         "<= ldbm_back_entry_get: failed to find objectClass %s\n",
121                         oc->soc_cname.bv_val, 0, 0 ); 
122                 rc = LDAP_NO_SUCH_ATTRIBUTE;
123                 goto return_results;
124         }
125
126         rc = LDAP_SUCCESS;
127
128 return_results:
129         if( rc != LDAP_SUCCESS ) {
130                 /* free entry */
131                 cache_return_entry_rw(&li->li_cache, e, rw);
132         } else {
133                 *ent = e;
134         }
135
136         Debug( LDAP_DEBUG_TRACE,
137                 "ldbm_back_entry_get: rc=%d\n",
138                 rc, 0, 0 ); 
139         return(rc);
140 }