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