]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/group.c
Added bdb_attribute and bdb_group ACL support routines
[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         const char      *gr_ndn,
31         const char      *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         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                    "bdb_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                 "=> bdb_group: gr dn: \"%s\"\n",
59                 gr_ndn, 0, 0 ); 
60
61         Debug( LDAP_DEBUG_ARGS,
62                 "=> bdb_group: op dn: \"%s\"\n",
63                 op_ndn, 0, 0 ); 
64         Debug( LDAP_DEBUG_ARGS,
65                 "=> bdb_group: oc: \"%s\" at: \"%s\"\n", 
66                 group_oc_name, group_at_name, 0 ); 
67
68         Debug( LDAP_DEBUG_ARGS,
69                 "=> bdb_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                            "bdb_group: target is group (%s)\n", gr_ndn ));
79 #else
80                 Debug( LDAP_DEBUG_ARGS,
81                         "=> bdb_group: target is group: \"%s\"\n",
82                         gr_ndn, 0, 0 );
83 #endif
84         } else {
85                 /* can we find group entry */
86                 rc = bdb_dn2entry( be, NULL, gr_ndn, &e, NULL, 0 );
87                 if( rc ) {
88                         return( 1 );
89                 }
90                 if (e == NULL) {
91 #ifdef NEW_LOGGING
92                         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
93                                    "bdb_group: cannot find group (%s)\n",
94                                    gr_ndn ));
95 #else
96                         Debug( LDAP_DEBUG_ACL,
97                                 "=> bdb_group: cannot find group: \"%s\"\n",
98                                         gr_ndn, 0, 0 ); 
99 #endif
100                         return( 1 );
101                 }
102 #ifdef NEW_LOGGING
103                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
104                            "bdb_group: found group (%s)\n", gr_ndn ));
105 #else
106                 Debug( LDAP_DEBUG_ACL,
107                         "=> bdb_group: found group: \"%s\"\n",
108                         gr_ndn, 0, 0 ); 
109 #endif
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                            "bdb_group: group (%s) is an alias\n", gr_ndn ));
124 #else
125                 Debug( LDAP_DEBUG_ACL,
126                         "<= bdb_group: group is an alias\n", 0, 0, 0 );
127 #endif
128                 goto return_results;
129         }
130
131         if( is_entry_referral( e ) ) {
132 #ifdef NEW_LOGGING
133                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
134                            "bdb_group: group (%s) is a referral.\n", gr_ndn ));
135 #else
136                 Debug( LDAP_DEBUG_ACL,
137                         "<= bdb_group: group is a referral\n", 0, 0, 0 );
138 #endif
139                 goto return_results;
140         }
141
142         if( !is_entry_objectclass( e, group_oc ) ) {
143 #ifdef NEW_LOGGING
144                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
145                            "bdb_group: failed to find %s in objectClass.\n",
146                            group_oc_name ));
147 #else
148                 Debug( LDAP_DEBUG_ACL,
149                         "<= bdb_group: failed to find %s in objectClass\n", 
150                                 group_oc_name, 0, 0 ); 
151 #endif
152                 goto return_results;
153         }
154
155         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
156 #ifdef NEW_LOGGING
157                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
158                            "bdb_group: failed to find %s\n", group_at_name ));
159 #else
160                 Debug( LDAP_DEBUG_ACL,
161                         "<= bdb_group: failed to find %s\n",
162                         group_at_name, 0, 0 ); 
163 #endif
164                 goto return_results;
165         }
166
167 #ifdef NEW_LOGGING
168         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
169                    "bdb_group: found objectClass %s and %s\n",
170                    group_oc_name, group_at_name ));
171 #else
172         Debug( LDAP_DEBUG_ACL,
173                 "<= bdb_group: found objectClass %s and %s\n",
174                 group_oc_name, group_at_name, 0 ); 
175 #endif
176
177         bv.bv_val = (char *) op_ndn;
178         bv.bv_len = strlen( op_ndn );         
179
180         if( value_find( group_at, attr->a_vals, &bv ) != LDAP_SUCCESS ) {
181 #ifdef NEW_LOGGING
182                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
183                            "bdb_group: \"%s\" not in \"%s\": %s\n",
184                            op_ndn, gr_ndn, group_at_name ));
185 #else
186                 Debug( LDAP_DEBUG_ACL,
187                         "<= bdb_group: \"%s\" not in \"%s\": %s\n", 
188                         op_ndn, gr_ndn, group_at_name ); 
189 #endif
190                 goto return_results;
191         }
192
193 #ifdef NEW_LOGGING
194         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
195                    "bdb_group: %s is in %s: %s\n",
196                    op_ndn, gr_ndn, group_at_name ));
197 #else
198         Debug( LDAP_DEBUG_ACL,
199                 "<= bdb_group: \"%s\" is in \"%s\": %s\n", 
200                 op_ndn, gr_ndn, group_at_name ); 
201 #endif
202
203         rc = 0;
204
205 return_results:
206         if( target != e ) {
207                 /* free entry */
208                 bdb_entry_return( be, e );
209         }
210
211 #ifdef NEW_LOGGING
212         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
213                    "bdb_group: rc=%d\n", rc ));
214 #else
215         Debug( LDAP_DEBUG_TRACE, "bdb_group: rc=%d\n", rc, 0, 0 ); 
216 #endif
217
218         return(rc);
219 }
220