]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
512f8e6b80c5a4f698b6ae0be0e595bdc5647fef
[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         Entry   *target,
28         const char      *gr_ndn,
29         const char      *op_ndn,
30         ObjectClass *group_oc,
31         AttributeDescription *group_at
32 )
33 {
34         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
35         Entry        *e;
36         int          rc = 1;
37         Attribute   *attr;
38         struct berval bv;
39
40         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
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         Debug( LDAP_DEBUG_ARGS,
51                 "=> ldbm_back_group: gr dn: \"%s\"\n",
52                 gr_ndn, 0, 0 ); 
53         Debug( LDAP_DEBUG_ARGS,
54                 "=> ldbm_back_group: op dn: \"%s\"\n",
55                 op_ndn, 0, 0 ); 
56         Debug( LDAP_DEBUG_ARGS,
57                 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n", 
58                 group_oc_name, group_at_name, 0 ); 
59
60         Debug( LDAP_DEBUG_ARGS,
61                 "=> ldbm_back_group: tr dn: \"%s\"\n",
62                 target->e_ndn, 0, 0 ); 
63
64         if (strcmp(target->e_ndn, gr_ndn) == 0) {
65                 /* we already have a LOCKED copy of the entry */
66                 e = target;
67                 Debug( LDAP_DEBUG_ARGS,
68                         "=> ldbm_back_group: target is group: \"%s\"\n",
69                         gr_ndn, 0, 0 );
70
71         } else {
72                 /* can we find group entry with reader lock */
73                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
74                         Debug( LDAP_DEBUG_ACL,
75                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
76                                         gr_ndn, 0, 0 ); 
77                         return( 1 );
78                 }
79                 
80                 Debug( LDAP_DEBUG_ACL,
81                         "=> ldbm_back_group: found group: \"%s\"\n",
82                         gr_ndn, 0, 0 ); 
83     }
84
85         /* find it's objectClass and member attribute values
86          * make sure this is a group entry
87          * finally test if we can find op_dn in the member attribute value list *
88          */
89         
90         rc = 1;
91         
92         
93         if( is_entry_alias( e ) ) {
94                 Debug( LDAP_DEBUG_ACL,
95                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
96                 goto return_results;
97         }
98
99         if( is_entry_referral( e ) ) {
100                 Debug( LDAP_DEBUG_ACL,
101                         "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
102                 goto return_results;
103         }
104
105         if( !is_entry_objectclass( e, group_oc ) ) {
106                 Debug( LDAP_DEBUG_ACL,
107                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
108                                 group_oc_name, 0, 0 ); 
109                 goto return_results;
110         }
111
112         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
113                 Debug( LDAP_DEBUG_ACL,
114                         "<= ldbm_back_group: failed to find %s\n",
115                         group_at_name, 0, 0 ); 
116                 goto return_results;
117         }
118
119         Debug( LDAP_DEBUG_ACL,
120                 "<= ldbm_back_group: found objectClass %s and %s\n",
121                 group_oc_name, group_at_name, 0 ); 
122
123         bv.bv_val = (char *) op_ndn;
124         bv.bv_len = strlen( op_ndn );         
125
126         if( value_find( group_at, attr->a_vals, &bv ) != LDAP_SUCCESS ) {
127                 Debug( LDAP_DEBUG_ACL,
128                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
129                         op_ndn, gr_ndn, group_at_name ); 
130                 goto return_results;
131         }
132
133
134
135         Debug( LDAP_DEBUG_ACL,
136                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
137                 op_ndn, gr_ndn, group_at_name ); 
138
139         rc = 0;
140
141 return_results:
142         if( target != e ) {
143                 /* free entry and reader lock */
144                 cache_return_entry_r( &li->li_cache, e );                 
145         }
146
147         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
148         return(rc);
149 }
150