1 /* group.c - bdb2 backend acl group routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
15 #ifdef SLAPD_ACLGROUPS
16 /* return 0 IFF op_dn is a value in member attribute
17 * of entry with gr_dn AND that entry has an objectClass
18 * value of groupOfNames
21 bdb2i_back_group_internal(
26 char *objectclassValue,
30 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 Attribute *objectClass;
37 Debug( LDAP_DEBUG_TRACE,
38 "=> bdb2i_back_group: gr dn: \"%s\"\n",
40 Debug( LDAP_DEBUG_TRACE,
41 "=> bdb2i_back_group: op dn: \"%s\"\n",
43 Debug( LDAP_DEBUG_TRACE,
44 "=> bdb2i_back_group: objectClass: \"%s\" attrName: \"%s\"\n",
45 objectclassValue, groupattrName, 0 );
47 Debug( LDAP_DEBUG_TRACE,
48 "=> bdb2i_back_group: tr dn: \"%s\"\n",
49 target->e_ndn, 0, 0 );
51 if (strcmp(target->e_ndn, gr_ndn) == 0) {
52 /* we already have a LOCKED copy of the entry */
54 Debug( LDAP_DEBUG_ARGS,
55 "=> bdb2i_back_group: target is group: \"%s\"\n",
58 /* can we find group entry with reader lock */
59 if ((e = bdb2i_dn2entry_r(be, gr_ndn, &matched )) == NULL) {
60 Debug( LDAP_DEBUG_TRACE,
61 "=> bdb2i_back_group: cannot find group: \"%s\" matched: \"%s\"\n",
62 gr_ndn, (matched ? matched : ""), 0 );
67 Debug( LDAP_DEBUG_ARGS,
68 "=> bdb2i_back_group: found group: \"%s\"\n",
73 /* check for deleted */
75 /* find it's objectClass and member attribute values
76 * make sure this is a group entry
77 * finally test if we can find op_dn in the member attribute value list *
81 if ((objectClass = attr_find(e->e_attrs, "objectclass")) == NULL) {
82 Debug( LDAP_DEBUG_TRACE, "<= bdb2i_back_group: failed to find objectClass\n", 0, 0, 0 );
84 else if ((member = attr_find(e->e_attrs, groupattrName)) == NULL) {
85 Debug( LDAP_DEBUG_TRACE, "<= bdb2i_back_group: failed to find %s\n", groupattrName, 0, 0 );
88 struct berval bvObjectClass;
89 struct berval bvMembers;
91 Debug( LDAP_DEBUG_ARGS, "<= bdb2i_back_group: found objectClass and %s\n", groupattrName, 0, 0 );
93 bvObjectClass.bv_val = objectclassValue;
94 bvObjectClass.bv_len = strlen( bvObjectClass.bv_val );
96 bvMembers.bv_val = op_ndn;
97 bvMembers.bv_len = strlen( op_ndn );
99 if (value_find(objectClass->a_vals, &bvObjectClass, SYNTAX_CIS, 1) != 0) {
100 Debug( LDAP_DEBUG_TRACE,
101 "<= bdb2i_back_group: failed to find %s in objectClass\n",
102 objectclassValue, 0, 0 );
104 else if (value_find(member->a_vals, &bvMembers, SYNTAX_CIS, 1) != 0) {
105 Debug( LDAP_DEBUG_ACL,
106 "<= bdb2i_back_group: \"%s\" not in \"%s\": %s\n",
107 op_ndn, gr_ndn, groupattrName );
110 Debug( LDAP_DEBUG_ACL,
111 "<= bdb2i_back_group: \"%s\" is in \"%s\": %s\n",
112 op_ndn, gr_ndn, groupattrName );
118 /* free entry and reader lock */
119 bdb2i_cache_return_entry_r( &li->li_cache, e );
122 Debug( LDAP_DEBUG_ARGS, "bdb2i_back_group: rc: %d\n", rc, 0, 0 );
133 char *objectclassValue,
138 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
140 struct timeval time1, time2;
144 gettimeofday( &time1, NULL );
146 if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
152 ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn,
153 objectclassValue, groupattrName );
155 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
157 if ( bdb2i_do_timing ) {
159 gettimeofday( &time2, NULL);
160 elapsed_time = bdb2i_elapsed( time1, time2 );
161 Debug( LDAP_DEBUG_ANY, "GRP elapsed=%s\n",
162 elapsed_time, 0, 0 );
163 free( elapsed_time );
170 #endif /* SLAPD_ACLGROUPS */