]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
Merge in all devel changes since 2.0-alpha2.
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 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         const char      *objectclassValue,
31         const char      *groupattrName
32 )
33 {
34         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
35         Entry        *e;
36         int          rc = 1;
37
38         Attribute   *attr;
39         struct berval bv;
40
41         Debug( LDAP_DEBUG_ARGS,
42                 "=> ldbm_back_group: gr dn: \"%s\"\n",
43                 gr_ndn, 0, 0 ); 
44         Debug( LDAP_DEBUG_ARGS,
45                 "=> ldbm_back_group: op dn: \"%s\"\n",
46                 op_ndn, 0, 0 ); 
47         Debug( LDAP_DEBUG_ARGS,
48                 "=> ldbm_back_group: objectClass: \"%s\" attrName: \"%s\"\n", 
49                 objectclassValue, groupattrName, 0 ); 
50
51         Debug( LDAP_DEBUG_ARGS,
52                 "=> ldbm_back_group: tr dn: \"%s\"\n",
53                 target->e_ndn, 0, 0 ); 
54
55         if (strcmp(target->e_ndn, gr_ndn) == 0) {
56                 /* we already have a LOCKED copy of the entry */
57                 e = target;
58                 Debug( LDAP_DEBUG_ARGS,
59                         "=> ldbm_back_group: target is group: \"%s\"\n",
60                         gr_ndn, 0, 0 );
61
62         } else {
63                 /* can we find group entry with reader lock */
64                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
65                         Debug( LDAP_DEBUG_ACL,
66                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
67                                         gr_ndn, 0, 0 ); 
68                         return( 1 );
69                 }
70                 
71                 Debug( LDAP_DEBUG_ACL,
72                         "=> ldbm_back_group: found group: \"%s\"\n",
73                         gr_ndn, 0, 0 ); 
74     }
75
76         /* find it's objectClass and member attribute values
77          * make sure this is a group entry
78          * finally test if we can find op_dn in the member attribute value list *
79          */
80         
81         rc = 1;
82         
83         if ((attr = attr_find(e->e_attrs, "objectclass")) == NULL)  {
84                 Debug( LDAP_DEBUG_ACL,
85                         "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
86                 goto return_results;
87         }
88         
89         bv.bv_val = "ALIAS";
90         bv.bv_len = sizeof("ALIAS")-1;
91
92         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
93                 Debug( LDAP_DEBUG_ACL,
94                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
95                 goto return_results;
96         }
97
98         bv.bv_val = "REFERRAL";
99         bv.bv_len = sizeof("REFERRAL")-1;
100
101         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
102                 Debug( LDAP_DEBUG_ACL,
103                         "<= ldbm_back_group: group is a referral\n",
104                         0, 0, 0 );
105                 goto return_results;
106         }
107
108         bv.bv_val = (char *) objectclassValue;
109         bv.bv_len = strlen( bv.bv_val );         
110
111         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
112                 Debug( LDAP_DEBUG_ACL,
113                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
114                                 objectclassValue, 0, 0 ); 
115                 goto return_results;
116         }
117
118         if ((attr = attr_find(e->e_attrs, groupattrName)) == NULL) {
119                 Debug( LDAP_DEBUG_ACL,
120                         "<= ldbm_back_group: failed to find %s\n",
121                         groupattrName, 0, 0 ); 
122                 goto return_results;
123         }
124
125         Debug( LDAP_DEBUG_ACL,
126                 "<= ldbm_back_group: found objectClass %s and %s\n",
127                 objectclassValue, groupattrName, 0 ); 
128
129         bv.bv_val = (char *) op_ndn;
130         bv.bv_len = strlen( op_ndn );         
131
132         if( value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 )
133         {
134                 Debug( LDAP_DEBUG_ACL,
135                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
136                         op_ndn, gr_ndn, groupattrName ); 
137                 goto return_results;
138         }
139
140         Debug( LDAP_DEBUG_ACL,
141                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
142                 op_ndn, gr_ndn, groupattrName ); 
143
144         rc = 0;
145
146 return_results:
147         if( target != e ) {
148                 /* free entry and reader lock */
149                 cache_return_entry_r( &li->li_cache, e );                 
150         }
151
152         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
153         return(rc);
154 }
155