]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
Defined some ObjectClass->soc_flags values, changed is_entry_*objectclass
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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         struct berval   *gr_ndn,
31         struct berval   *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
41         const char *group_oc_name = NULL;
42         const char *group_at_name = group_at->ad_cname.bv_val;
43
44         if( group_oc->soc_names && group_oc->soc_names[0] ) {
45                 group_oc_name = group_oc->soc_names[0];
46         } else {
47                 group_oc_name = group_oc->soc_oid;
48         }
49
50 #ifdef NEW_LOGGING
51         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
52                 "ldbm_back_group: check (%s) member of (%s), oc %s\n",
53                 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name ));
54 #else
55         Debug( LDAP_DEBUG_ARGS,
56                 "=> ldbm_back_group: gr dn: \"%s\"\n",
57                 gr_ndn->bv_val, 0, 0 ); 
58
59         Debug( LDAP_DEBUG_ARGS,
60                 "=> ldbm_back_group: op dn: \"%s\"\n",
61                 op_ndn->bv_val, 0, 0 ); 
62         Debug( LDAP_DEBUG_ARGS,
63                 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n", 
64                 group_oc_name, group_at_name, 0 ); 
65
66         Debug( LDAP_DEBUG_ARGS,
67                 "=> ldbm_back_group: tr dn: \"%s\"\n",
68                 target->e_ndn, 0, 0 ); 
69 #endif
70
71         if (dn_match(&target->e_nname, gr_ndn)) {
72                 /* we already have a LOCKED copy of the entry */
73                 e = target;
74 #ifdef NEW_LOGGING
75                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
76                         "ldbm_back_group: target is group (%s)\n",
77                         gr_ndn->bv_val ));
78 #else
79                 Debug( LDAP_DEBUG_ARGS,
80                         "=> ldbm_back_group: target is group: \"%s\"\n",
81                         gr_ndn->bv_val, 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->bv_val ));
92 #else
93                         Debug( LDAP_DEBUG_ACL,
94                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
95                                 gr_ndn->bv_val, 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->bv_val ));
104 #else
105                 Debug( LDAP_DEBUG_ACL,
106                         "=> ldbm_back_group: found group: \"%s\"\n",
107                         gr_ndn->bv_val, 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",
124                         gr_ndn->bv_val ));
125 #else
126                 Debug( LDAP_DEBUG_ACL,
127                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
128 #endif
129
130                 goto return_results;
131         }
132
133         if( is_entry_referral( e ) ) {
134 #ifdef NEW_LOGGING
135                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
136                         "ldbm_back_group: group (%s) is a referral.\n",
137                         gr_ndn->bv_val ));
138 #else
139                 Debug( LDAP_DEBUG_ACL,
140                         "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
141 #endif
142
143                 goto return_results;
144         }
145
146         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
147 #ifdef NEW_LOGGING
148                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
149                         "ldbm_back_group: failed to find %s in objectClass.\n",
150                         group_oc_name ));
151 #else
152                 Debug( LDAP_DEBUG_ACL,
153                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
154                                 group_oc_name, 0, 0 ); 
155 #endif
156
157                 goto return_results;
158         }
159
160         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
161 #ifdef NEW_LOGGING
162                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
163                         "ldbm_back_group: failed to find %s\n", group_at_name ));
164 #else
165                 Debug( LDAP_DEBUG_ACL,
166                         "<= ldbm_back_group: failed to find %s\n",
167                         group_at_name, 0, 0 ); 
168 #endif
169
170                 goto return_results;
171         }
172
173 #ifdef NEW_LOGGING
174         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
175                    "ldbm_back_group: found objectClass %s and %s\n",
176                    group_oc_name, group_at_name ));
177 #else
178         Debug( LDAP_DEBUG_ACL,
179                 "<= ldbm_back_group: found objectClass %s and %s\n",
180                 group_oc_name, group_at_name, 0 ); 
181 #endif
182
183
184         if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
185 #ifdef NEW_LOGGING
186                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
187                         "ldbm_back_group: \"%s\" not in \"%s\": %s\n",
188                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
189 #else
190                 Debug( LDAP_DEBUG_ACL,
191                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
192                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
193 #endif
194
195                 goto return_results;
196         }
197
198
199 #ifdef NEW_LOGGING
200         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
201                 "ldbm_back_group: %s is in %s: %s\n",
202                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
203 #else
204         Debug( LDAP_DEBUG_ACL,
205                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
206                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
207 #endif
208
209
210         rc = 0;
211
212 return_results:
213         if( target != e ) {
214                 /* free entry and reader lock */
215                 cache_return_entry_r( &li->li_cache, e );                 
216         }
217
218 #ifdef NEW_LOGGING
219         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
220                 "ldbm_back_group: rc=%d\n", rc ));
221 #else
222         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
223 #endif
224
225         return(rc);
226 }
227