]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
When recreating a database from an ldif file created by ldbmcat,
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
13
14
15 /* return 0 IFF op_dn is a value in member attribute
16  * of entry with gr_dn AND that entry has an objectClass
17  * value of groupOfNames
18  */
19 int
20 ldbm_back_group(
21         Backend *be,
22         Entry   *target,
23         char    *gr_ndn,
24         char    *op_ndn,
25         char    *objectclassValue,
26         char    *groupattrName
27 )
28 {
29         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
30         Entry        *e;
31         int          rc = 1;
32
33         Attribute   *attr;
34         struct berval bv;
35
36         Debug( LDAP_DEBUG_ARGS,
37                 "=> ldbm_back_group: gr dn: \"%s\"\n",
38                 gr_ndn, 0, 0 ); 
39         Debug( LDAP_DEBUG_ARGS,
40                 "=> ldbm_back_group: op dn: \"%s\"\n",
41                 op_ndn, 0, 0 ); 
42         Debug( LDAP_DEBUG_ARGS,
43                 "=> ldbm_back_group: objectClass: \"%s\" attrName: \"%s\"\n", 
44                 objectclassValue, groupattrName, 0 ); 
45
46         Debug( LDAP_DEBUG_ARGS,
47                 "=> ldbm_back_group: tr dn: \"%s\"\n",
48                 target->e_ndn, 0, 0 ); 
49
50         if (strcmp(target->e_ndn, gr_ndn) == 0) {
51                 /* we already have a LOCKED copy of the entry */
52                 e = target;
53                 Debug( LDAP_DEBUG_ARGS,
54                         "=> ldbm_back_group: target is group: \"%s\"\n",
55                         gr_ndn, 0, 0 );
56
57         } else {
58                 /* can we find group entry with reader lock */
59                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
60                         Debug( LDAP_DEBUG_ACL,
61                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
62                                         gr_ndn, 0, 0 ); 
63                         return( 1 );
64                 }
65                 
66                 Debug( LDAP_DEBUG_ACL,
67                         "=> ldbm_back_group: found group: \"%s\"\n",
68                         gr_ndn, 0, 0 ); 
69     }
70
71         /* find it's objectClass and member attribute values
72          * make sure this is a group entry
73          * finally test if we can find op_dn in the member attribute value list *
74          */
75         
76         rc = 1;
77         
78         if ((attr = attr_find(e->e_attrs, "objectclass")) == NULL)  {
79                 Debug( LDAP_DEBUG_ACL,
80                         "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
81                 goto return_results;
82         }
83         
84         bv.bv_val = "ALIAS";
85         bv.bv_len = sizeof("ALIAS")-1;
86
87         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
88                 Debug( LDAP_DEBUG_ACL,
89                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
90                 goto return_results;
91         }
92
93         bv.bv_val = "REFERRAL";
94         bv.bv_len = sizeof("REFERRAL")-1;
95
96         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
97                 Debug( LDAP_DEBUG_ACL,
98                         "<= ldbm_back_group: group is a referral\n",
99                         0, 0, 0 );
100                 goto return_results;
101         }
102
103         bv.bv_val = objectclassValue;
104         bv.bv_len = strlen( bv.bv_val );         
105
106         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
107                 Debug( LDAP_DEBUG_ACL,
108                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
109                                 objectclassValue, 0, 0 ); 
110                 goto return_results;
111         }
112
113         if ((attr = attr_find(e->e_attrs, groupattrName)) == NULL) {
114                 Debug( LDAP_DEBUG_ACL,
115                         "<= ldbm_back_group: failed to find %s\n",
116                         groupattrName, 0, 0 ); 
117                 goto return_results;
118         }
119
120         Debug( LDAP_DEBUG_ACL,
121                 "<= ldbm_back_group: found objectClass %s and %s\n",
122                 objectclassValue, groupattrName, 0 ); 
123
124         bv.bv_val = op_ndn;
125         bv.bv_len = strlen( op_ndn );         
126
127         if( value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 )
128         {
129                 Debug( LDAP_DEBUG_ACL,
130                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
131                         op_ndn, gr_ndn, groupattrName ); 
132                 goto return_results;
133         }
134
135         Debug( LDAP_DEBUG_ACL,
136                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
137                 op_ndn, gr_ndn, groupattrName ); 
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