1 /* memberof.c - back-reference for group membership */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2007 Pierangelo Masarati <ando@sys-net.it>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software, sponsored by SysNet s.r.l.
23 #ifdef SLAPD_OVER_MEMBEROF
27 #include "ac/string.h"
28 #include "ac/socket.h"
37 * GROUP a group object (an entry with GROUP_OC
39 * MEMBER a member object (an entry whose DN is
40 * listed as MEMBER_AT value of a GROUP)
41 * GROUP_OC the objectClass of the group object
42 * (default: groupOfNames)
43 * MEMBER_AT the membership attribute, DN-valued;
44 * note: nameAndOptionalUID is tolerated
45 * as soon as the optionalUID is absent
47 * MEMBER_OF reverse membership attribute
51 * - if the entry that is being added is a GROUP,
52 * the MEMBER_AT defined as values of the add operation
53 * get the MEMBER_OF value directly from the request.
55 * if configured to do so, the MEMBER objects do not exist,
56 * and no relax control is issued, either:
58 * - drop non-existing members
59 * (by default: don't muck with values)
61 * - if (configured to do so,) the referenced GROUP exists,
62 * the relax control is set and the user has
63 * "manage" privileges, allow to add MEMBER_OF values to
67 * - if the entry being modified is a GROUP_OC and the
68 * MEMBER_AT attribute is modified, the MEMBER_OF value
69 * of the (existing) MEMBER_AT entries that are affected
70 * is modified according to the request:
71 * - if a MEMBER is removed from the group,
72 * delete the corresponding MEMBER_OF
73 * - if a MEMBER is added to a group,
74 * add the corresponding MEMBER_OF
76 * We need to determine, from the database, if it is
77 * a GROUP_OC, and we need to check, from the
78 * modification list, if the MEMBER_AT attribute is being
79 * affected, and what MEMBER_AT values are affected.
81 * if configured to do so, the entries corresponding to
82 * the MEMBER_AT values do not exist, and no relax control
85 * - drop non-existing members
86 * (by default: don't muck with values)
88 * - if configured to do so, the referenced GROUP exists,
89 * (the relax control is set) and the user has
90 * "manage" privileges, allow to add MEMBER_OF values to
91 * generic entries; the change is NOT automatically reflected
92 * in the MEMBER attribute of the GROUP referenced
93 * by the value of MEMBER_OF; a separate modification,
94 * with or without relax control, needs to be performed.
97 * - if the entry being renamed is a GROUP, the MEMBER_OF
98 * value of the (existing) MEMBER objects is modified
99 * accordingly based on the newDN of the GROUP.
101 * We need to determine, from the database, if it is
102 * a GROUP; the list of MEMBER objects is obtained from
105 * Non-existing MEMBER objects are ignored, since the
106 * MEMBER_AT is not being addressed by the operation.
108 * - if the entry being renamed has the MEMBER_OF attribute,
109 * the corresponding MEMBER value must be modified in the
110 * respective group entries.
114 * - if the entry being deleted is a GROUP, the (existing)
115 * MEMBER objects are modified accordingly; a copy of the
116 * values of the MEMBER_AT is saved and, if the delete
117 * succeeds, the MEMBER_OF value of the (existing) MEMBER
118 * objects is deleted.
120 * We need to determine, from the database, if it is
123 * Non-existing MEMBER objects are ignored, since the entry
126 * - if the entry being deleted has the MEMBER_OF attribute,
127 * the corresponding value of the MEMBER_AT must be deleted
128 * from the respective GROUP entries.
131 #define SLAPD_MEMBEROF_ATTR "memberOf"
133 static slap_overinst memberof;
135 typedef struct memberof_t {
137 struct berval mo_ndn;
139 ObjectClass *mo_oc_group;
140 AttributeDescription *mo_ad_member;
141 AttributeDescription *mo_ad_memberof;
143 struct berval mo_groupFilterstr;
144 AttributeAssertion mo_groupAVA;
145 Filter mo_groupFilter;
147 struct berval mo_memberFilterstr;
148 Filter mo_memberFilter;
151 #define MEMBEROF_NONE 0x00U
152 #define MEMBEROF_FDANGLING_DROP 0x01U
153 #define MEMBEROF_FDANGLING_ERROR 0x02U
154 #define MEMBEROF_FDANGLING_MASK (MEMBEROF_FDANGLING_DROP|MEMBEROF_FDANGLING_ERROR)
155 #define MEMBEROF_FREFINT 0x04U
156 #define MEMBEROF_FREVERSE 0x08U
158 ber_int_t mo_dangling_err;
160 #define MEMBEROF_CHK(mo,f) \
161 (((mo)->mo_flags & (f)) == (f))
162 #define MEMBEROF_DANGLING_CHECK(mo) \
163 ((mo)->mo_flags & MEMBEROF_FDANGLING_MASK)
164 #define MEMBEROF_DANGLING_DROP(mo) \
165 MEMBEROF_CHK((mo),MEMBEROF_FDANGLING_DROP)
166 #define MEMBEROF_DANGLING_ERROR(mo) \
167 MEMBEROF_CHK((mo),MEMBEROF_FDANGLING_ERROR)
168 #define MEMBEROF_REFINT(mo) \
169 MEMBEROF_CHK((mo),MEMBEROF_FREFINT)
170 #define MEMBEROF_REVERSE(mo) \
171 MEMBEROF_CHK((mo),MEMBEROF_FREVERSE)
174 typedef enum memberof_is_t {
175 MEMBEROF_IS_NONE = 0x00,
176 MEMBEROF_IS_GROUP = 0x01,
177 MEMBEROF_IS_MEMBER = 0x02,
178 MEMBEROF_IS_BOTH = (MEMBEROF_IS_GROUP|MEMBEROF_IS_MEMBER)
181 typedef struct memberof_cookie_t {
182 AttributeDescription *ad;
187 typedef struct memberof_cbinfo_t {
195 memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
197 if ( rs->sr_type == REP_SEARCH ) {
198 memberof_cookie_t *mc;
200 mc = (memberof_cookie_t *)op->o_callback->sc_private;
208 * callback for internal search that saves the member attribute values
209 * of groups being deleted.
212 memberof_saveMember_cb( Operation *op, SlapReply *rs )
214 if ( rs->sr_type == REP_SEARCH ) {
215 memberof_cookie_t *mc;
218 mc = (memberof_cookie_t *)op->o_callback->sc_private;
221 assert( rs->sr_entry != NULL );
222 assert( rs->sr_entry->e_attrs != NULL );
224 a = attr_find( rs->sr_entry->e_attrs, mc->ad );
226 ber_bvarray_dup_x( &mc->vals, a->a_nvals, op->o_tmpmemctx );
228 assert( attr_find( a->a_next, mc->ad ) == NULL );
236 * the delete hook performs an internal search that saves the member
237 * attribute values of groups being deleted.
240 memberof_isGroupOrMember( Operation *op, memberof_cbinfo_t *mci )
242 slap_overinst *on = mci->on;
243 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
246 slap_callback cb = { 0 };
247 BackendInfo *bi = op->o_bd->bd_info;
248 AttributeName an[ 2 ];
250 memberof_is_t iswhat = MEMBEROF_IS_NONE;
251 memberof_cookie_t mc;
253 assert( mci->what != MEMBEROF_IS_NONE );
256 if ( op->o_tag == LDAP_REQ_DELETE ) {
257 cb.sc_response = memberof_saveMember_cb;
260 cb.sc_response = memberof_isGroupOrMember_cb;
263 op2.o_tag = LDAP_REQ_SEARCH;
264 op2.o_callback = &cb;
265 op2.o_dn = op->o_bd->be_rootdn;
266 op2.o_ndn = op->o_bd->be_rootndn;
268 op2.ors_scope = LDAP_SCOPE_BASE;
269 op2.ors_deref = LDAP_DEREF_NEVER;
270 BER_BVZERO( &an[ 1 ].an_name );
272 op2.ors_attrsonly = 0;
273 op2.ors_limit = NULL;
275 op2.ors_tlimit = SLAP_NO_LIMIT;
277 if ( mci->what & MEMBEROF_IS_GROUP ) {
278 SlapReply rs2 = { REP_RESULT };
280 mc.ad = mo->mo_ad_member;
283 an[ 0 ].an_desc = mo->mo_ad_member;
284 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
285 op2.ors_filterstr = mo->mo_groupFilterstr;
286 op2.ors_filter = &mo->mo_groupFilter;
288 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
289 (void)op->o_bd->be_search( &op2, &rs2 );
290 op2.o_bd->bd_info = bi;
293 iswhat |= MEMBEROF_IS_GROUP;
294 if ( mc.vals ) mci->member = mc.vals;
299 if ( mci->what & MEMBEROF_IS_MEMBER ) {
300 SlapReply rs2 = { REP_RESULT };
302 mc.ad = mo->mo_ad_memberof;
305 an[ 0 ].an_desc = mo->mo_ad_memberof;
306 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
307 op2.ors_filterstr = mo->mo_memberFilterstr;
308 op2.ors_filter = &mo->mo_memberFilter;
310 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
311 (void)op->o_bd->be_search( &op2, &rs2 );
312 op2.o_bd->bd_info = bi;
315 iswhat |= MEMBEROF_IS_MEMBER;
316 if ( mc.vals ) mci->memberof = mc.vals;
327 * response callback that adds memberof values when a group is modified.
330 memberof_value_modify(
333 AttributeDescription *ad,
334 struct berval *old_dn,
335 struct berval *old_ndn,
336 struct berval *new_dn,
337 struct berval *new_ndn )
339 memberof_cbinfo_t *mci = op->o_callback->sc_private;
340 slap_overinst *on = mci->on;
341 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
344 SlapReply rs2 = { REP_RESULT };
345 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
346 Modifications mod[ 2 ] = { { { 0 } } }, *ml;
347 struct berval values[ 4 ], nvalues[ 4 ];
350 op2.o_tag = LDAP_REQ_MODIFY;
353 op2.o_req_ndn = *ndn;
355 op2.o_callback = &cb;
356 op2.o_dn = op->o_bd->be_rootdn;
357 op2.o_ndn = op->o_bd->be_rootndn;
358 op2.orm_modlist = NULL;
360 if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
363 ml->sml_values = &values[ 0 ];
364 ml->sml_values[ 0 ] = mo->mo_dn;
365 BER_BVZERO( &ml->sml_values[ 1 ] );
366 ml->sml_nvalues = &nvalues[ 0 ];
367 ml->sml_nvalues[ 0 ] = mo->mo_ndn;
368 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
369 ml->sml_desc = slap_schema.si_ad_modifiersName;
370 ml->sml_type = ml->sml_desc->ad_cname;
371 ml->sml_op = LDAP_MOD_REPLACE;
372 ml->sml_flags = SLAP_MOD_INTERNAL;
373 ml->sml_next = op2.orm_modlist;
374 op2.orm_modlist = ml;
381 ml->sml_values = &values[ 2 ];
382 BER_BVZERO( &ml->sml_values[ 1 ] );
383 ml->sml_nvalues = &nvalues[ 2 ];
384 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
386 ml->sml_type = ml->sml_desc->ad_cname;
387 ml->sml_flags = SLAP_MOD_INTERNAL;
388 ml->sml_next = op2.orm_modlist;
389 op2.orm_modlist = ml;
390 op2.orm_no_opattrs = 0;
392 if ( new_ndn != NULL ) {
393 BackendInfo *bi = op2.o_bd->bd_info;
396 assert( !BER_BVISNULL( new_dn ) );
397 assert( !BER_BVISNULL( new_ndn ) );
400 ml->sml_op = LDAP_MOD_ADD;
402 ml->sml_values[ 0 ] = *new_dn;
403 ml->sml_nvalues[ 0 ] = *new_ndn;
405 oex.oe_key = (void *)&memberof;
406 LDAP_SLIST_INSERT_HEAD(&op2.o_extra, &oex, oe_next);
407 BER_BVZERO( &op2.o_csn );
408 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
409 slap_op_time( &op2.o_time, &op2.o_tincr );
410 (void)op->o_bd->be_modify( &op2, &rs2 );
411 op2.o_bd->bd_info = bi;
412 LDAP_SLIST_REMOVE(&op2.o_extra, &oex, OpExtra, oe_next);
413 if ( rs2.sr_err != LDAP_SUCCESS ) {
414 char buf[ SLAP_TEXT_BUFLEN ];
415 snprintf( buf, sizeof( buf ),
416 "memberof_value_modify DN=\"%s\" add %s=\"%s\" failed err=%d",
417 op2.o_req_dn.bv_val, ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err );
418 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
419 op->o_log_prefix, buf, 0 );
422 assert( op2.orm_modlist == &mod[ mcnt ] );
423 assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
424 ml = op2.orm_modlist->sml_next;
426 assert( ml == &mod[ 0 ] );
430 slap_mods_free( ml, 1 );
433 mod[ 0 ].sml_next = NULL;
436 if ( old_ndn != NULL ) {
437 BackendInfo *bi = op2.o_bd->bd_info;
440 assert( !BER_BVISNULL( old_dn ) );
441 assert( !BER_BVISNULL( old_ndn ) );
444 ml->sml_op = LDAP_MOD_DELETE;
446 ml->sml_values[ 0 ] = *old_dn;
447 ml->sml_nvalues[ 0 ] = *old_ndn;
449 oex.oe_key = (void *)&memberof;
450 LDAP_SLIST_INSERT_HEAD(&op2.o_extra, &oex, oe_next);
451 BER_BVZERO( &op2.o_csn );
452 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
453 slap_op_time( &op2.o_time, &op2.o_tincr );
454 (void)op->o_bd->be_modify( &op2, &rs2 );
455 op2.o_bd->bd_info = bi;
456 LDAP_SLIST_REMOVE(&op2.o_extra, &oex, OpExtra, oe_next);
457 if ( rs2.sr_err != LDAP_SUCCESS ) {
458 char buf[ SLAP_TEXT_BUFLEN ];
459 snprintf( buf, sizeof( buf ),
460 "memberof_value_modify DN=\"%s\" delete %s=\"%s\" failed err=%d",
461 op2.o_req_dn.bv_val, ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err );
462 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
463 op->o_log_prefix, buf, 0 );
466 assert( op2.orm_modlist == &mod[ mcnt ] );
467 ml = op2.orm_modlist->sml_next;
469 assert( ml == &mod[ 0 ] );
473 slap_mods_free( ml, 1 );
477 /* FIXME: if old_group_ndn doesn't exist, both delete __and__
478 * add will fail; better split in two operations, although
479 * not optimal in terms of performance. At least it would
480 * move towards self-repairing capabilities. */
484 memberof_cleanup( Operation *op, SlapReply *rs )
486 slap_callback *sc = op->o_callback;
487 memberof_cbinfo_t *mci = sc->sc_private;
489 op->o_callback = sc->sc_next;
491 ber_bvarray_free_x( mci->memberof, op->o_tmpmemctx );
493 ber_bvarray_free_x( mci->member, op->o_tmpmemctx );
494 op->o_tmpfree( sc, op->o_tmpmemctx );
498 static int memberof_res_add( Operation *op, SlapReply *rs );
499 static int memberof_res_delete( Operation *op, SlapReply *rs );
500 static int memberof_res_modify( Operation *op, SlapReply *rs );
501 static int memberof_res_modrdn( Operation *op, SlapReply *rs );
504 memberof_op_add( Operation *op, SlapReply *rs )
506 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
507 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
509 Attribute **ap, **map = NULL;
510 int rc = SLAP_CB_CONTINUE;
512 struct berval save_dn, save_ndn;
514 memberof_cbinfo_t *mci;
517 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
518 if ( oex->oe_key == (void *)&memberof )
519 return SLAP_CB_CONTINUE;
522 if ( op->ora_e->e_attrs == NULL ) {
523 /* FIXME: global overlay; need to deal with */
524 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
525 "consistency checks not implemented when overlay "
526 "is instantiated as global.\n",
527 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
528 return SLAP_CB_CONTINUE;
531 if ( MEMBEROF_REVERSE( mo ) ) {
532 for ( ap = &op->ora_e->e_attrs; *ap; ap = &(*ap)->a_next ) {
535 if ( a->a_desc == mo->mo_ad_memberof ) {
543 save_ndn = op->o_ndn;
545 if ( MEMBEROF_DANGLING_CHECK( mo )
547 && is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) )
549 op->o_dn = op->o_bd->be_rootdn;
550 op->o_ndn = op->o_bd->be_rootndn;
551 op->o_bd->bd_info = (BackendInfo *)on->on_info;
553 for ( ap = &op->ora_e->e_attrs; *ap; ) {
556 if ( !is_ad_subtype( a->a_desc, mo->mo_ad_member ) ) {
561 assert( a->a_nvals != NULL );
563 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
566 /* ITS#6670 Ignore member pointing to this entry */
567 if ( dn_match( &a->a_nvals[i], &save_ndn ))
570 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
572 if ( rc == LDAP_SUCCESS ) {
573 be_entry_release_r( op, e );
577 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
578 rc = rs->sr_err = mo->mo_dangling_err;
579 rs->sr_text = "adding non-existing object "
581 send_ldap_result( op, rs );
585 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
588 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
589 "member=\"%s\" does not exist (stripping...)\n",
590 op->o_log_prefix, op->ora_e->e_name.bv_val,
591 a->a_vals[ i ].bv_val );
593 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
594 ber_memfree( a->a_vals[ i ].bv_val );
595 BER_BVZERO( &a->a_vals[ i ] );
596 if ( a->a_nvals != a->a_vals ) {
597 ber_memfree( a->a_nvals[ i ].bv_val );
598 BER_BVZERO( &a->a_nvals[ i ] );
604 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
605 sizeof( struct berval ) * ( j - i ) );
606 if ( a->a_nvals != a->a_vals ) {
607 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
608 sizeof( struct berval ) * ( j - i ) );
615 /* If all values have been removed,
616 * remove the attribute itself. */
617 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
626 op->o_ndn = save_ndn;
627 op->o_bd->bd_info = (BackendInfo *)on;
632 AccessControlState acl_state = ACL_STATE_INIT;
634 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
637 op->o_bd->bd_info = (BackendInfo *)on->on_info;
638 /* access is checked with the original identity */
639 rc = access_allowed( op, op->ora_e, mo->mo_ad_memberof,
640 &a->a_nvals[ i ], ACL_WADD,
643 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
645 send_ldap_result( op, rs );
648 /* ITS#6670 Ignore member pointing to this entry */
649 if ( dn_match( &a->a_nvals[i], &save_ndn ))
652 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
654 op->o_bd->bd_info = (BackendInfo *)on;
655 if ( rc != LDAP_SUCCESS ) {
656 if ( get_relax( op ) ) {
660 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
661 rc = rs->sr_err = mo->mo_dangling_err;
662 rs->sr_text = "adding non-existing object "
664 send_ldap_result( op, rs );
668 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
671 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
672 "memberof=\"%s\" does not exist (stripping...)\n",
673 op->o_log_prefix, op->ora_e->e_name.bv_val,
674 a->a_nvals[ i ].bv_val );
676 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
677 ber_memfree( a->a_vals[ i ].bv_val );
678 BER_BVZERO( &a->a_vals[ i ] );
679 if ( a->a_nvals != a->a_vals ) {
680 ber_memfree( a->a_nvals[ i ].bv_val );
681 BER_BVZERO( &a->a_nvals[ i ] );
687 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
688 sizeof( struct berval ) * ( j - i ) );
689 if ( a->a_nvals != a->a_vals ) {
690 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
691 sizeof( struct berval ) * ( j - i ) );
699 /* access is checked with the original identity */
700 op->o_bd->bd_info = (BackendInfo *)on->on_info;
701 rc = access_allowed( op, e, mo->mo_ad_member,
702 &op->o_req_ndn, ACL_WADD, NULL );
703 be_entry_release_r( op, e );
704 op->o_bd->bd_info = (BackendInfo *)on;
707 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
708 rs->sr_text = "insufficient access to object referenced by memberof";
709 send_ldap_result( op, rs );
714 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
720 rc = SLAP_CB_CONTINUE;
722 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
723 sc->sc_private = sc+1;
724 sc->sc_response = memberof_res_add;
725 sc->sc_cleanup = memberof_cleanup;
726 mci = sc->sc_private;
729 mci->memberof = NULL;
730 sc->sc_next = op->o_callback;
735 op->o_ndn = save_ndn;
736 op->o_bd->bd_info = (BackendInfo *)on;
742 memberof_op_delete( Operation *op, SlapReply *rs )
744 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
745 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
748 memberof_cbinfo_t *mci;
751 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
752 if ( oex->oe_key == (void *)&memberof )
753 return SLAP_CB_CONTINUE;
756 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
757 sc->sc_private = sc+1;
758 sc->sc_response = memberof_res_delete;
759 sc->sc_cleanup = memberof_cleanup;
760 mci = sc->sc_private;
763 mci->memberof = NULL;
764 mci->what = MEMBEROF_IS_GROUP;
765 if ( MEMBEROF_REFINT( mo ) ) {
766 mci->what = MEMBEROF_IS_BOTH;
769 memberof_isGroupOrMember( op, mci );
771 sc->sc_next = op->o_callback;
774 return SLAP_CB_CONTINUE;
778 memberof_op_modify( Operation *op, SlapReply *rs )
780 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
781 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
783 Modifications **mlp, **mmlp = NULL;
784 int rc = SLAP_CB_CONTINUE, save_member = 0;
785 struct berval save_dn, save_ndn;
787 memberof_cbinfo_t *mci, mcis;
790 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
791 if ( oex->oe_key == (void *)&memberof )
792 return SLAP_CB_CONTINUE;
795 if ( MEMBEROF_REVERSE( mo ) ) {
796 for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
797 Modifications *ml = *mlp;
799 if ( ml->sml_desc == mo->mo_ad_memberof ) {
807 save_ndn = op->o_ndn;
809 mcis.what = MEMBEROF_IS_GROUP;
811 if ( memberof_isGroupOrMember( op, &mcis ) == LDAP_SUCCESS
812 && ( mcis.what & MEMBEROF_IS_GROUP ) )
816 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
817 if ( ml->sml_desc == mo->mo_ad_member ) {
818 switch ( ml->sml_op ) {
819 case LDAP_MOD_DELETE:
820 case LDAP_MOD_REPLACE:
828 if ( MEMBEROF_DANGLING_CHECK( mo )
829 && !get_relax( op ) )
831 op->o_dn = op->o_bd->be_rootdn;
832 op->o_ndn = op->o_bd->be_rootndn;
833 op->o_bd->bd_info = (BackendInfo *)on->on_info;
835 assert( op->orm_modlist != NULL );
837 for ( mlp = &op->orm_modlist; *mlp; ) {
838 Modifications *ml = *mlp;
841 if ( !is_ad_subtype( ml->sml_desc, mo->mo_ad_member ) ) {
846 switch ( ml->sml_op ) {
847 case LDAP_MOD_DELETE:
848 /* we don't care about cancellations: if the value
849 * exists, fine; if it doesn't, we let the underlying
850 * database fail as appropriate; */
854 case LDAP_MOD_REPLACE:
855 /* Handle this just like a delete (see above) */
856 if ( !ml->sml_values ) {
862 /* NOTE: right now, the attributeType we use
863 * for member must have a normalized value */
864 assert( ml->sml_nvalues != NULL );
866 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
870 /* ITS#6670 Ignore member pointing to this entry */
871 if ( dn_match( &ml->sml_nvalues[i], &save_ndn ))
874 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
875 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
877 be_entry_release_r( op, e );
881 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
882 rc = rs->sr_err = mo->mo_dangling_err;
883 rs->sr_text = "adding non-existing object "
885 send_ldap_result( op, rs );
889 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
892 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
893 "member=\"%s\" does not exist (stripping...)\n",
894 op->o_log_prefix, op->o_req_dn.bv_val,
895 ml->sml_nvalues[ i ].bv_val );
897 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
898 ber_memfree( ml->sml_values[ i ].bv_val );
899 BER_BVZERO( &ml->sml_values[ i ] );
900 ber_memfree( ml->sml_nvalues[ i ].bv_val );
901 BER_BVZERO( &ml->sml_nvalues[ i ] );
907 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
908 sizeof( struct berval ) * ( j - i ) );
909 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
910 sizeof( struct berval ) * ( j - i ) );
915 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
917 slap_mod_free( &ml->sml_mod, 0 );
933 if ( mmlp != NULL ) {
934 Modifications *ml = *mmlp;
938 op->o_bd->bd_info = (BackendInfo *)on->on_info;
939 rc = be_entry_get_rw( op, &op->o_req_ndn,
940 NULL, NULL, 0, &target );
941 op->o_bd->bd_info = (BackendInfo *)on;
942 if ( rc != LDAP_SUCCESS ) {
943 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
944 send_ldap_result( op, rs );
948 switch ( ml->sml_op ) {
949 case LDAP_MOD_DELETE:
950 if ( ml->sml_nvalues != NULL ) {
951 AccessControlState acl_state = ACL_STATE_INIT;
953 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
956 op->o_bd->bd_info = (BackendInfo *)on->on_info;
957 /* access is checked with the original identity */
958 rc = access_allowed( op, target,
960 &ml->sml_nvalues[ i ],
964 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
966 send_ldap_result( op, rs );
970 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
972 op->o_bd->bd_info = (BackendInfo *)on;
973 if ( rc != LDAP_SUCCESS ) {
974 if ( get_relax( op ) ) {
978 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
979 rc = rs->sr_err = mo->mo_dangling_err;
980 rs->sr_text = "deleting non-existing object "
982 send_ldap_result( op, rs );
986 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
989 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
990 "memberof=\"%s\" does not exist (stripping...)\n",
991 op->o_log_prefix, op->o_req_ndn.bv_val,
992 ml->sml_nvalues[ i ].bv_val );
994 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
995 ber_memfree( ml->sml_values[ i ].bv_val );
996 BER_BVZERO( &ml->sml_values[ i ] );
997 if ( ml->sml_nvalues != ml->sml_values ) {
998 ber_memfree( ml->sml_nvalues[ i ].bv_val );
999 BER_BVZERO( &ml->sml_nvalues[ i ] );
1006 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1007 sizeof( struct berval ) * ( j - i ) );
1008 if ( ml->sml_nvalues != ml->sml_values ) {
1009 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1010 sizeof( struct berval ) * ( j - i ) );
1018 /* access is checked with the original identity */
1019 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1020 rc = access_allowed( op, e, mo->mo_ad_member,
1023 be_entry_release_r( op, e );
1024 op->o_bd->bd_info = (BackendInfo *)on;
1027 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1028 rs->sr_text = "insufficient access to object referenced by memberof";
1029 send_ldap_result( op, rs );
1034 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1035 *mmlp = ml->sml_next;
1036 slap_mod_free( &ml->sml_mod, 0 );
1044 case LDAP_MOD_REPLACE:
1046 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1047 /* access is checked with the original identity */
1048 rc = access_allowed( op, target,
1052 op->o_bd->bd_info = (BackendInfo *)on;
1054 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1056 send_ldap_result( op, rs );
1060 if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
1065 case LDAP_MOD_ADD: {
1066 AccessControlState acl_state = ACL_STATE_INIT;
1068 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1071 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1072 /* access is checked with the original identity */
1073 rc = access_allowed( op, target,
1075 &ml->sml_nvalues[ i ],
1079 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1081 send_ldap_result( op, rs );
1085 /* ITS#6670 Ignore member pointing to this entry */
1086 if ( dn_match( &ml->sml_nvalues[i], &save_ndn ))
1089 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1090 NULL, NULL, 0, &e );
1091 op->o_bd->bd_info = (BackendInfo *)on;
1092 if ( rc != LDAP_SUCCESS ) {
1093 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1094 rc = rs->sr_err = mo->mo_dangling_err;
1095 rs->sr_text = "adding non-existing object "
1097 send_ldap_result( op, rs );
1101 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1104 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1105 "memberof=\"%s\" does not exist (stripping...)\n",
1106 op->o_log_prefix, op->o_req_ndn.bv_val,
1107 ml->sml_nvalues[ i ].bv_val );
1109 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1110 ber_memfree( ml->sml_values[ i ].bv_val );
1111 BER_BVZERO( &ml->sml_values[ i ] );
1112 if ( ml->sml_nvalues != ml->sml_values ) {
1113 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1114 BER_BVZERO( &ml->sml_nvalues[ i ] );
1121 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1122 sizeof( struct berval ) * ( j - i ) );
1123 if ( ml->sml_nvalues != ml->sml_values ) {
1124 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1125 sizeof( struct berval ) * ( j - i ) );
1133 /* access is checked with the original identity */
1134 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1135 rc = access_allowed( op, e, mo->mo_ad_member,
1138 be_entry_release_r( op, e );
1139 op->o_bd->bd_info = (BackendInfo *)on;
1142 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1143 rs->sr_text = "insufficient access to object referenced by memberof";
1144 send_ldap_result( op, rs );
1149 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1150 *mmlp = ml->sml_next;
1151 slap_mod_free( &ml->sml_mod, 0 );
1162 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1163 be_entry_release_r( op, target );
1164 op->o_bd->bd_info = (BackendInfo *)on;
1167 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
1168 sc->sc_private = sc+1;
1169 sc->sc_response = memberof_res_modify;
1170 sc->sc_cleanup = memberof_cleanup;
1171 mci = sc->sc_private;
1174 mci->memberof = NULL;
1175 mci->what = mcis.what;
1177 if ( save_member ) {
1178 op->o_dn = op->o_bd->be_rootdn;
1179 op->o_ndn = op->o_bd->be_rootndn;
1180 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1181 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1182 mo->mo_ad_member, &mci->member, ACL_READ );
1183 op->o_bd->bd_info = (BackendInfo *)on;
1186 sc->sc_next = op->o_callback;
1187 op->o_callback = sc;
1189 rc = SLAP_CB_CONTINUE;
1193 op->o_ndn = save_ndn;
1194 op->o_bd->bd_info = (BackendInfo *)on;
1200 memberof_op_modrdn( Operation *op, SlapReply *rs )
1202 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1204 memberof_cbinfo_t *mci;
1207 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
1208 if ( oex->oe_key == (void *)&memberof )
1209 return SLAP_CB_CONTINUE;
1212 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
1213 sc->sc_private = sc+1;
1214 sc->sc_response = memberof_res_modrdn;
1215 sc->sc_cleanup = memberof_cleanup;
1216 mci = sc->sc_private;
1219 mci->memberof = NULL;
1221 sc->sc_next = op->o_callback;
1222 op->o_callback = sc;
1224 return SLAP_CB_CONTINUE;
1228 * response callback that adds memberof values when a group is added.
1231 memberof_res_add( Operation *op, SlapReply *rs )
1233 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1234 slap_overinst *on = mci->on;
1235 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1239 if ( rs->sr_err != LDAP_SUCCESS ) {
1240 return SLAP_CB_CONTINUE;
1243 if ( MEMBEROF_REVERSE( mo ) ) {
1246 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1248 /* relax is required to allow to add
1249 * a non-existing member */
1250 op->o_relax = SLAP_CONTROL_CRITICAL;
1252 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1254 /* ITS#6670 Ignore member pointing to this entry */
1255 if ( dn_match( &ma->a_nvals[i], &op->o_req_ndn ))
1258 /* the modification is attempted
1259 * with the original identity */
1260 memberof_value_modify( op,
1261 &ma->a_nvals[ i ], mo->mo_ad_member,
1262 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1267 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1270 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1272 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1274 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1275 /* ITS#6670 Ignore member pointing to this entry */
1276 if ( dn_match( &a->a_nvals[i], &op->o_req_ndn ))
1279 memberof_value_modify( op,
1289 return SLAP_CB_CONTINUE;
1293 * response callback that deletes memberof values when a group is deleted.
1296 memberof_res_delete( Operation *op, SlapReply *rs )
1298 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1299 slap_overinst *on = mci->on;
1300 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1305 if ( rs->sr_err != LDAP_SUCCESS ) {
1306 return SLAP_CB_CONTINUE;
1310 if ( vals != NULL ) {
1311 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1312 memberof_value_modify( op,
1313 &vals[ i ], mo->mo_ad_memberof,
1314 &op->o_req_dn, &op->o_req_ndn,
1319 if ( MEMBEROF_REFINT( mo ) ) {
1320 vals = mci->memberof;
1321 if ( vals != NULL ) {
1322 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1323 memberof_value_modify( op,
1324 &vals[ i ], mo->mo_ad_member,
1325 &op->o_req_dn, &op->o_req_ndn,
1331 return SLAP_CB_CONTINUE;
1335 * response callback that adds/deletes memberof values when a group
1339 memberof_res_modify( Operation *op, SlapReply *rs )
1341 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1342 slap_overinst *on = mci->on;
1343 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1346 Modifications *ml, *mml = NULL;
1349 if ( rs->sr_err != LDAP_SUCCESS ) {
1350 return SLAP_CB_CONTINUE;
1353 if ( MEMBEROF_REVERSE( mo ) ) {
1354 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1355 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1362 if ( mml != NULL ) {
1363 BerVarray vals = mml->sml_nvalues;
1365 switch ( mml->sml_op ) {
1366 case LDAP_MOD_DELETE:
1367 if ( vals != NULL ) {
1368 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1369 memberof_value_modify( op,
1370 &vals[ i ], mo->mo_ad_member,
1371 &op->o_req_dn, &op->o_req_ndn,
1378 case LDAP_MOD_REPLACE:
1379 /* delete all ... */
1380 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1381 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1382 mo->mo_ad_memberof, &vals, ACL_READ );
1383 op->o_bd->bd_info = (BackendInfo *)on;
1384 if ( rc == LDAP_SUCCESS ) {
1385 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1386 memberof_value_modify( op,
1387 &vals[ i ], mo->mo_ad_member,
1388 &op->o_req_dn, &op->o_req_ndn,
1391 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1394 if ( ml->sml_op == LDAP_MOD_DELETE || !mml->sml_values ) {
1400 assert( vals != NULL );
1402 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1403 memberof_value_modify( op,
1404 &vals[ i ], mo->mo_ad_member,
1406 &op->o_req_dn, &op->o_req_ndn );
1415 if ( mci->what & MEMBEROF_IS_GROUP )
1417 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1418 if ( ml->sml_desc != mo->mo_ad_member ) {
1422 switch ( ml->sml_op ) {
1423 case LDAP_MOD_DELETE:
1424 vals = ml->sml_nvalues;
1425 if ( vals != NULL ) {
1426 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1427 memberof_value_modify( op,
1428 &vals[ i ], mo->mo_ad_memberof,
1429 &op->o_req_dn, &op->o_req_ndn,
1436 case LDAP_MOD_REPLACE:
1439 /* delete all ... */
1440 if ( vals != NULL ) {
1441 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1442 memberof_value_modify( op,
1443 &vals[ i ], mo->mo_ad_memberof,
1444 &op->o_req_dn, &op->o_req_ndn,
1449 if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
1455 assert( ml->sml_nvalues != NULL );
1456 vals = ml->sml_nvalues;
1457 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1458 memberof_value_modify( op,
1459 &vals[ i ], mo->mo_ad_memberof,
1461 &op->o_req_dn, &op->o_req_ndn );
1471 return SLAP_CB_CONTINUE;
1475 * response callback that adds/deletes member values when a group member
1479 memberof_res_modrdn( Operation *op, SlapReply *rs )
1481 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1482 slap_overinst *on = mci->on;
1483 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1485 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1489 struct berval save_dn, save_ndn;
1491 if ( rs->sr_err != LDAP_SUCCESS ) {
1492 return SLAP_CB_CONTINUE;
1495 mci->what = MEMBEROF_IS_GROUP;
1496 if ( MEMBEROF_REFINT( mo ) ) {
1497 mci->what |= MEMBEROF_IS_MEMBER;
1500 if ( op->orr_nnewSup ) {
1501 newPNDN = *op->orr_nnewSup;
1504 dnParent( &op->o_req_ndn, &newPNDN );
1507 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1509 save_dn = op->o_req_dn;
1510 save_ndn = op->o_req_ndn;
1512 op->o_req_dn = newNDN;
1513 op->o_req_ndn = newNDN;
1514 rc = memberof_isGroupOrMember( op, mci );
1515 op->o_req_dn = save_dn;
1516 op->o_req_ndn = save_ndn;
1518 if ( rc != LDAP_SUCCESS || mci->what == MEMBEROF_IS_NONE ) {
1522 if ( op->orr_newSup ) {
1523 newPDN = *op->orr_newSup;
1526 dnParent( &op->o_req_dn, &newPDN );
1529 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1531 if ( mci->what & MEMBEROF_IS_GROUP ) {
1532 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1533 rc = backend_attribute( op, NULL, &newNDN,
1534 mo->mo_ad_member, &vals, ACL_READ );
1535 op->o_bd->bd_info = (BackendInfo *)on;
1537 if ( rc == LDAP_SUCCESS ) {
1538 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1539 memberof_value_modify( op,
1540 &vals[ i ], mo->mo_ad_memberof,
1541 &op->o_req_dn, &op->o_req_ndn,
1544 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1548 if ( MEMBEROF_REFINT( mo ) && ( mci->what & MEMBEROF_IS_MEMBER ) ) {
1549 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1550 rc = backend_attribute( op, NULL, &newNDN,
1551 mo->mo_ad_memberof, &vals, ACL_READ );
1552 op->o_bd->bd_info = (BackendInfo *)on;
1554 if ( rc == LDAP_SUCCESS ) {
1555 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1556 memberof_value_modify( op,
1557 &vals[ i ], mo->mo_ad_member,
1558 &op->o_req_dn, &op->o_req_ndn,
1561 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1566 if ( !BER_BVISNULL( &newDN ) ) {
1567 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1569 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1571 return SLAP_CB_CONTINUE;
1580 slap_overinst *on = (slap_overinst *)be->bd_info;
1583 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1586 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1588 on->on_bi.bi_private = (void *)mo;
1609 static ConfigDriver mo_cf_gen;
1611 #define OID "1.3.6.1.4.1.7136.2.666.4"
1612 #define OIDAT OID ".1.1"
1613 #define OIDCFGAT OID ".1.2"
1614 #define OIDOC OID ".2.1"
1615 #define OIDCFGOC OID ".2.2"
1618 static ConfigTable mo_cfg[] = {
1619 { "memberof-dn", "modifiersName",
1620 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1621 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1622 "DESC 'DN to be used as modifiersName' "
1623 "SYNTAX OMsDN SINGLE-VALUE )",
1626 { "memberof-dangling", "ignore|drop|error",
1627 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1628 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1629 "DESC 'Behavior with respect to dangling members, "
1630 "constrained to ignore, drop, error' "
1631 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1634 { "memberof-refint", "true|FALSE",
1635 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1636 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1637 "DESC 'Take care of referential integrity' "
1638 "SYNTAX OMsBoolean SINGLE-VALUE )",
1641 { "memberof-group-oc", "objectClass",
1642 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1643 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1644 "DESC 'Group objectClass' "
1645 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1648 { "memberof-member-ad", "member attribute",
1649 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1650 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1651 "DESC 'member attribute' "
1652 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1655 { "memberof-memberof-ad", "memberOf attribute",
1656 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1657 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1658 "DESC 'memberOf attribute' "
1659 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1663 { "memberof-reverse", "true|FALSE",
1664 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1665 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1666 "DESC 'Take care of referential integrity "
1667 "also when directly modifying memberOf' "
1668 "SYNTAX OMsBoolean SINGLE-VALUE )",
1672 { "memberof-dangling-error", "error code",
1673 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1674 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1675 "DESC 'Error code returned in case of dangling back reference' "
1676 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1679 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1682 static ConfigOCs mo_ocs[] = {
1683 { "( OLcfgOvOc:18.1 "
1684 "NAME 'olcMemberOf' "
1685 "DESC 'Member-of configuration' "
1686 "SUP olcOverlayConfig "
1689 "$ olcMemberOfDangling "
1690 "$ olcMemberOfDanglingError"
1691 "$ olcMemberOfRefInt "
1692 "$ olcMemberOfGroupOC "
1693 "$ olcMemberOfMemberAD "
1694 "$ olcMemberOfMemberOfAD "
1696 "$ olcMemberOfReverse "
1700 Cft_Overlay, mo_cfg, NULL, NULL },
1704 static slap_verbmasks dangling_mode[] = {
1705 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1706 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1707 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1712 memberof_make_group_filter( memberof_t *mo )
1716 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1717 ch_free( mo->mo_groupFilterstr.bv_val );
1720 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1721 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1723 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1724 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1726 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1727 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1728 + mo->mo_oc_group->soc_cname.bv_len;
1729 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1731 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1733 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1741 memberof_make_member_filter( memberof_t *mo )
1745 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1746 ch_free( mo->mo_memberFilterstr.bv_val );
1749 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1750 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1752 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1753 + mo->mo_ad_memberof->ad_cname.bv_len;
1754 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1756 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1757 ptr = lutil_strcopy( ptr, "=*)" );
1763 mo_cf_gen( ConfigArgs *c )
1765 slap_overinst *on = (slap_overinst *)c->bi;
1766 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1770 if ( c->op == SLAP_CONFIG_EMIT ) {
1771 struct berval bv = BER_BVNULL;
1775 if ( mo->mo_dn.bv_val != NULL) {
1776 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1777 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1782 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1783 if ( BER_BVISNULL( &bv ) ) {
1784 /* there's something wrong... */
1789 value_add_one( &c->rvalue_vals, &bv );
1793 case MO_DANGLING_ERROR:
1794 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1795 char buf[ SLAP_TEXT_BUFLEN ];
1796 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1797 if ( BER_BVISNULL( &bv ) ) {
1798 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1799 if ( bv.bv_len < sizeof( buf ) ) {
1806 value_add_one( &c->rvalue_vals, &bv );
1813 c->value_int = MEMBEROF_REFINT( mo );
1818 c->value_int = MEMBEROF_REVERSE( mo );
1823 if ( mo->mo_oc_group != NULL ){
1824 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1829 if ( mo->mo_ad_member != NULL ){
1830 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1834 case MO_MEMBER_OF_AD:
1835 if ( mo->mo_ad_memberof != NULL ){
1836 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1847 } else if ( c->op == LDAP_MOD_DELETE ) {
1848 return 1; /* FIXME */
1853 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1854 ber_memfree( mo->mo_dn.bv_val );
1855 ber_memfree( mo->mo_ndn.bv_val );
1857 mo->mo_dn = c->value_dn;
1858 mo->mo_ndn = c->value_ndn;
1862 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1863 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1867 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1868 mo->mo_flags |= dangling_mode[ i ].mask;
1871 case MO_DANGLING_ERROR:
1872 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1873 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1874 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1875 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1881 if ( c->value_int ) {
1882 mo->mo_flags |= MEMBEROF_FREFINT;
1885 mo->mo_flags &= ~MEMBEROF_FREFINT;
1891 if ( c->value_int ) {
1892 mo->mo_flags |= MEMBEROF_FREVERSE;
1895 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1901 ObjectClass *oc = NULL;
1903 oc = oc_find( c->argv[ 1 ] );
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1906 "unable to find group objectClass=\"%s\"",
1908 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1909 c->log, c->cr_msg, 0 );
1913 mo->mo_oc_group = oc;
1914 memberof_make_group_filter( mo );
1917 case MO_MEMBER_AD: {
1918 AttributeDescription *ad = NULL;
1919 const char *text = NULL;
1922 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1923 if ( rc != LDAP_SUCCESS ) {
1924 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1925 "unable to find member attribute=\"%s\": %s (%d)",
1926 c->argv[ 1 ], text, rc );
1927 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1928 c->log, c->cr_msg, 0 );
1932 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1933 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1935 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1936 "member attribute=\"%s\" must either "
1937 "have DN (%s) or nameUID (%s) syntax",
1938 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1939 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1940 c->log, c->cr_msg, 0 );
1944 mo->mo_ad_member = ad;
1947 case MO_MEMBER_OF_AD: {
1948 AttributeDescription *ad = NULL;
1949 const char *text = NULL;
1952 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1953 if ( rc != LDAP_SUCCESS ) {
1954 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1955 "unable to find memberof attribute=\"%s\": %s (%d)",
1956 c->argv[ 1 ], text, rc );
1957 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1958 c->log, c->cr_msg, 0 );
1962 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1963 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1965 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1966 "memberof attribute=\"%s\" must either "
1967 "have DN (%s) or nameUID (%s) syntax",
1968 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1969 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1970 c->log, c->cr_msg, 0 );
1974 mo->mo_ad_memberof = ad;
1975 memberof_make_member_filter( mo );
1992 slap_overinst *on = (slap_overinst *)be->bd_info;
1993 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1996 const char *text = NULL;
1998 if( ! mo->mo_ad_memberof ){
1999 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
2000 if ( rc != LDAP_SUCCESS ) {
2001 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
2002 "unable to find attribute=\"%s\": %s (%d)\n",
2003 SLAPD_MEMBEROF_ATTR, text, rc );
2008 if( ! mo->mo_ad_member ){
2009 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &text );
2010 if ( rc != LDAP_SUCCESS ) {
2011 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
2012 "unable to find attribute=\"%s\": %s (%d)\n",
2013 SLAPD_GROUP_ATTR, text, rc );
2018 if( ! mo->mo_oc_group ){
2019 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
2020 if ( mo->mo_oc_group == NULL ) {
2021 Debug( LDAP_DEBUG_ANY,
2022 "memberof_db_open: "
2023 "unable to find objectClass=\"%s\"\n",
2024 SLAPD_GROUP_CLASS, 0, 0 );
2029 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
2030 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
2031 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
2034 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
2035 memberof_make_group_filter( mo );
2038 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
2039 memberof_make_member_filter( mo );
2046 memberof_db_destroy(
2050 slap_overinst *on = (slap_overinst *)be->bd_info;
2051 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
2054 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
2055 ber_memfree( mo->mo_dn.bv_val );
2056 ber_memfree( mo->mo_ndn.bv_val );
2059 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
2060 ber_memfree( mo->mo_groupFilterstr.bv_val );
2063 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
2064 ber_memfree( mo->mo_memberFilterstr.bv_val );
2074 static AttributeDescription *ad_memberOf;
2078 AttributeDescription **adp;
2080 { "( 1.2.840.113556.1.2.102 "
2082 "DESC 'Group that the entry belongs to' "
2083 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2084 "EQUALITY distinguishedNameMatch " /* added */
2085 "USAGE dSAOperation " /* added; questioned */
2086 /* "NO-USER-MODIFICATION " */ /* add? */
2087 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2092 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2094 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2096 memberof_initialize( void )
2100 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2101 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2103 Debug( LDAP_DEBUG_ANY,
2104 "memberof_initialize: register_at #%d failed\n",
2110 memberof.on_bi.bi_type = "memberof";
2112 memberof.on_bi.bi_db_init = memberof_db_init;
2113 memberof.on_bi.bi_db_open = memberof_db_open;
2114 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2116 memberof.on_bi.bi_op_add = memberof_op_add;
2117 memberof.on_bi.bi_op_delete = memberof_op_delete;
2118 memberof.on_bi.bi_op_modify = memberof_op_modify;
2119 memberof.on_bi.bi_op_modrdn = memberof_op_modrdn;
2121 memberof.on_bi.bi_cf_ocs = mo_ocs;
2123 code = config_register_schema( mo_cfg, mo_ocs );
2124 if ( code ) return code;
2126 return overlay_register( &memberof );
2129 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2131 init_module( int argc, char *argv[] )
2133 return memberof_initialize();
2135 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2137 #endif /* SLAPD_OVER_MEMBEROF */