]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
Update groups to use struct berval DNs.
[openldap] / servers / slapd / back-bdb / group.c
1 /* group.c - bdb 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-bdb.h"
17 #include "proto-bdb.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 bdb_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 bdbinfo *li = (struct bdbinfo *) be->be_private;
37         Entry *e;
38         int     rc = 1;
39         Attribute *attr;
40
41         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
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                 "bdb_group: check (%s) member of (%s), oc %s\n",
54                 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name ));
55 #else
56         Debug( LDAP_DEBUG_ARGS,
57                 "=> bdb_group: gr dn: \"%s\"\n",
58                 gr_ndn->bv_val, 0, 0 ); 
59
60         Debug( LDAP_DEBUG_ARGS,
61                 "=> bdb_group: op dn: \"%s\"\n",
62                 op_ndn->bv_val, 0, 0 ); 
63         Debug( LDAP_DEBUG_ARGS,
64                 "=> bdb_group: oc: \"%s\" at: \"%s\"\n", 
65                 group_oc_name, group_at_name, 0 ); 
66
67         Debug( LDAP_DEBUG_ARGS,
68                 "=> bdb_group: tr dn: \"%s\"\n",
69                 target->e_ndn, 0, 0 ); 
70 #endif
71
72         if (strcmp(target->e_ndn, gr_ndn->bv_val) == 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                         "bdb_group: target is group (%s)\n", gr_ndn->bv_val ));
78 #else
79                 Debug( LDAP_DEBUG_ARGS,
80                         "=> bdb_group: target is group: \"%s\"\n",
81                         gr_ndn->bv_val, 0, 0 );
82 #endif
83         } else {
84                 /* can we find group entry */
85                 rc = bdb_dn2entry( be, NULL, gr_ndn, &e, NULL, 0 );
86                 if( rc ) {
87                         return( 1 );
88                 }
89                 if (e == NULL) {
90 #ifdef NEW_LOGGING
91                         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
92                                 "bdb_group: cannot find group (%s)\n",
93                                 gr_ndn->bv_val ));
94 #else
95                         Debug( LDAP_DEBUG_ACL,
96                                 "=> bdb_group: cannot find group: \"%s\"\n",
97                                         gr_ndn->bv_val, 0, 0 ); 
98 #endif
99                         return( 1 );
100                 }
101 #ifdef NEW_LOGGING
102                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
103                         "bdb_group: found group (%s)\n", gr_ndn->bv_val ));
104 #else
105                 Debug( LDAP_DEBUG_ACL,
106                         "=> bdb_group: found group: \"%s\"\n",
107                         gr_ndn->bv_val, 0, 0 ); 
108 #endif
109         }
110
111         /* find it's objectClass and member attribute values
112          * make sure this is a group entry
113          * finally test if we can find op_dn in the member attribute value list
114          */
115         rc = 1;
116
117         if( is_entry_alias( e ) ) {
118 #ifdef NEW_LOGGING
119                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
120                         "bdb_group: group (%s) is an alias\n", gr_ndn->bv_val ));
121 #else
122                 Debug( LDAP_DEBUG_ACL,
123                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
124 #endif
125                 goto return_results;
126         }
127
128         if( is_entry_referral( e ) ) {
129 #ifdef NEW_LOGGING
130                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
131                         "bdb_group: group (%s) is a referral.\n", gr_ndn->bv_val ));
132 #else
133                 Debug( LDAP_DEBUG_ACL,
134                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
135 #endif
136                 goto return_results;
137         }
138
139         if( !is_entry_objectclass( e, group_oc ) ) {
140 #ifdef NEW_LOGGING
141                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
142                         "bdb_group: failed to find %s in objectClass.\n",
143                         group_oc_name ));
144 #else
145                 Debug( LDAP_DEBUG_ACL,
146                         "<= bdb_group: failed to find %s in objectClass\n", 
147                                 group_oc_name, 0, 0 ); 
148 #endif
149                 goto return_results;
150         }
151
152         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
153 #ifdef NEW_LOGGING
154                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
155                         "bdb_group: failed to find %s\n", group_at_name ));
156 #else
157                 Debug( LDAP_DEBUG_ACL,
158                         "<= bdb_group: failed to find %s\n",
159                         group_at_name, 0, 0 ); 
160 #endif
161                 goto return_results;
162         }
163
164 #ifdef NEW_LOGGING
165         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
166                 "bdb_group: found objectClass %s and %s\n",
167                 group_oc_name, group_at_name ));
168 #else
169         Debug( LDAP_DEBUG_ACL,
170                 "<= bdb_group: found objectClass %s and %s\n",
171                 group_oc_name, group_at_name, 0 ); 
172 #endif
173
174         if( value_find( group_at, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
175 #ifdef NEW_LOGGING
176                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
177                         "bdb_group: \"%s\" not in \"%s\": %s\n",
178                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
179 #else
180                 Debug( LDAP_DEBUG_ACL,
181                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
182                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
183 #endif
184                 goto return_results;
185         }
186
187 #ifdef NEW_LOGGING
188         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
189                 "bdb_group: %s is in %s: %s\n",
190                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ));
191 #else
192         Debug( LDAP_DEBUG_ACL,
193                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
194                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
195 #endif
196
197         rc = 0;
198
199 return_results:
200         if( target != e ) {
201                 /* free entry */
202                 bdb_entry_return( be, e );
203         }
204
205 #ifdef NEW_LOGGING
206         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
207                 "bdb_group: rc=%d\n", rc ));
208 #else
209         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
210 #endif
211
212         return(rc);
213 }
214