]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
Fixup bdb_entry_release now that entry_decode uses two memory blocks
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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 /* return 0 IFF op_dn is a value in member attribute
21  * of entry with gr_dn AND that entry has an objectClass
22  * value of groupOfNames
23  */
24 int
25 ldbm_back_group(
26         Backend *be,
27         Connection *conn,
28         Operation *op,
29         Entry   *target,
30         const char      *gr_ndn,
31         const char      *op_ndn,
32         ObjectClass *group_oc,
33         AttributeDescription *group_at
34 )
35 {
36         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
37         Entry        *e;
38         int          rc = 1;
39         Attribute   *attr;
40         struct berval bv;
41
42         const char *group_oc_name = NULL;
43         const char *group_at_name = group_at->ad_cname.bv_val;
44
45         if( group_oc->soc_names && group_oc->soc_names[0] ) {
46                 group_oc_name = group_oc->soc_names[0];
47         } else {
48                 group_oc_name = group_oc->soc_oid;
49         }
50
51 #ifdef NEW_LOGGING
52         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
53                    "ldbm_back_group: check (%s) member of (%s), oc %s\n",
54                    op_ndn, gr_ndn, group_oc_name ));
55 #else
56         Debug( LDAP_DEBUG_ARGS,
57                 "=> ldbm_back_group: gr dn: \"%s\"\n",
58                 gr_ndn, 0, 0 ); 
59
60         Debug( LDAP_DEBUG_ARGS,
61                 "=> ldbm_back_group: op dn: \"%s\"\n",
62                 op_ndn, 0, 0 ); 
63         Debug( LDAP_DEBUG_ARGS,
64                 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n", 
65                 group_oc_name, group_at_name, 0 ); 
66
67         Debug( LDAP_DEBUG_ARGS,
68                 "=> ldbm_back_group: tr dn: \"%s\"\n",
69                 target->e_ndn, 0, 0 ); 
70 #endif
71
72         if (strcmp(target->e_ndn, gr_ndn) == 0) {
73                 /* we already have a LOCKED copy of the entry */
74                 e = target;
75 #ifdef NEW_LOGGING
76                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
77                            "ldbm_back_group: target is group (%s)\n", gr_ndn ));
78 #else
79                 Debug( LDAP_DEBUG_ARGS,
80                         "=> ldbm_back_group: target is group: \"%s\"\n",
81                         gr_ndn, 0, 0 );
82 #endif
83
84
85         } else {
86                 /* can we find group entry with reader lock */
87                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
88 #ifdef NEW_LOGGING
89                         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
90                                    "ldbm_back_group: cannot find group (%s)\n",
91                                    gr_ndn ));
92 #else
93                         Debug( LDAP_DEBUG_ACL,
94                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
95                                         gr_ndn, 0, 0 ); 
96 #endif
97
98                         return( 1 );
99                 }
100                 
101 #ifdef NEW_LOGGING
102                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
103                            "ldbm_back_group: found group (%s)\n", gr_ndn ));
104 #else
105                 Debug( LDAP_DEBUG_ACL,
106                         "=> ldbm_back_group: found group: \"%s\"\n",
107                         gr_ndn, 0, 0 ); 
108 #endif
109
110     }
111
112         /* find it's objectClass and member attribute values
113          * make sure this is a group entry
114          * finally test if we can find op_dn in the member attribute value list *
115          */
116         
117         rc = 1;
118         
119         
120         if( is_entry_alias( e ) ) {
121 #ifdef NEW_LOGGING
122                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
123                            "ldbm_back_group: group (%s) is an alias\n", gr_ndn ));
124 #else
125                 Debug( LDAP_DEBUG_ACL,
126                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
127 #endif
128
129                 goto return_results;
130         }
131
132         if( is_entry_referral( e ) ) {
133 #ifdef NEW_LOGGING
134                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
135                            "ldbm_back_group: group (%s) is a referral.\n", gr_ndn ));
136 #else
137                 Debug( LDAP_DEBUG_ACL,
138                         "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
139 #endif
140
141                 goto return_results;
142         }
143
144         if( !is_entry_objectclass( e, group_oc ) ) {
145 #ifdef NEW_LOGGING
146                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
147                            "ldbm_back_group: failed to find %s in objectClass.\n",
148                            group_oc_name ));
149 #else
150                 Debug( LDAP_DEBUG_ACL,
151                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
152                                 group_oc_name, 0, 0 ); 
153 #endif
154
155                 goto return_results;
156         }
157
158         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
159 #ifdef NEW_LOGGING
160                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
161                            "ldbm_back_group: failed to find %s\n", group_at_name ));
162 #else
163                 Debug( LDAP_DEBUG_ACL,
164                         "<= ldbm_back_group: failed to find %s\n",
165                         group_at_name, 0, 0 ); 
166 #endif
167
168                 goto return_results;
169         }
170
171 #ifdef NEW_LOGGING
172         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
173                    "ldbm_back_group: found objectClass %s and %s\n",
174                    group_oc_name, group_at_name ));
175 #else
176         Debug( LDAP_DEBUG_ACL,
177                 "<= ldbm_back_group: found objectClass %s and %s\n",
178                 group_oc_name, group_at_name, 0 ); 
179 #endif
180
181
182         bv.bv_val = (char *) op_ndn;
183         bv.bv_len = strlen( op_ndn );         
184
185         if( value_find( group_at, attr->a_vals, &bv ) != LDAP_SUCCESS ) {
186 #ifdef NEW_LOGGING
187                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
188                            "ldbm_back_group: \"%s\" not in \"%s\": %s\n",
189                            op_ndn, gr_ndn, group_at_name ));
190 #else
191                 Debug( LDAP_DEBUG_ACL,
192                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
193                         op_ndn, gr_ndn, group_at_name ); 
194 #endif
195
196                 goto return_results;
197         }
198
199
200
201 #ifdef NEW_LOGGING
202         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
203                    "ldbm_back_group: %s is in %s: %s\n",
204                    op_ndn, gr_ndn, group_at_name ));
205 #else
206         Debug( LDAP_DEBUG_ACL,
207                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
208                 op_ndn, gr_ndn, group_at_name ); 
209 #endif
210
211
212         rc = 0;
213
214 return_results:
215         if( target != e ) {
216                 /* free entry and reader lock */
217                 cache_return_entry_r( &li->li_cache, e );                 
218         }
219
220 #ifdef NEW_LOGGING
221         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
222                    "ldbm_back_group: rc=%d\n", rc ));
223 #else
224         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
225 #endif
226
227         return(rc);
228 }
229