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)
182 * failover storage for member attribute values of groups being deleted
183 * handles [no]thread cases.
185 static BerVarray saved_member_vals;
186 static BerVarray saved_memberof_vals;
189 memberof_saved_member_free( void *key, void *data )
191 ber_bvarray_free( (BerVarray)data );
195 memberof_saved_member_get( Operation *op, void *keyp )
198 BerVarray *key = (BerVarray *)keyp;
200 assert( op != NULL );
202 if ( op->o_threadctx == NULL ) {
207 ldap_pvt_thread_pool_setkey( op->o_threadctx,
208 key, NULL, 0, &vals, NULL );
215 memberof_saved_member_set( Operation *op, void *keyp, BerVarray vals )
217 BerVarray saved_vals = NULL;
218 BerVarray *key = (BerVarray*)keyp;
220 assert( op != NULL );
223 ber_bvarray_dup_x( &saved_vals, vals, NULL );
226 if ( op->o_threadctx == NULL ) {
228 ber_bvarray_free( *key );
233 void *old_vals = NULL;
235 ldap_pvt_thread_pool_setkey( op->o_threadctx, key,
236 saved_vals, memberof_saved_member_free, &old_vals, NULL );
237 if ( old_vals != NULL ) {
238 ber_bvarray_free( old_vals );
243 typedef struct memberof_cookie_t {
244 AttributeDescription *ad;
250 memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
252 if ( rs->sr_type == REP_SEARCH ) {
253 memberof_cookie_t *mc;
255 mc = (memberof_cookie_t *)op->o_callback->sc_private;
263 * callback for internal search that saves the member attribute values
264 * of groups being deleted.
267 memberof_saveMember_cb( Operation *op, SlapReply *rs )
269 if ( rs->sr_type == REP_SEARCH ) {
270 memberof_cookie_t *mc;
272 BerVarray vals = NULL;
274 mc = (memberof_cookie_t *)op->o_callback->sc_private;
277 assert( rs->sr_entry != NULL );
278 assert( rs->sr_entry->e_attrs != NULL );
280 a = attr_find( rs->sr_entry->e_attrs, mc->ad );
285 memberof_saved_member_set( op, mc->key, vals );
287 if ( a && attr_find( a->a_next, mc->ad ) != NULL ) {
288 Debug( LDAP_DEBUG_ANY,
289 "%s: memberof_saveMember_cb(\"%s\"): "
290 "more than one occurrence of \"%s\" "
293 rs->sr_entry->e_name.bv_val,
294 mc->ad->ad_cname.bv_val );
302 * the delete hook performs an internal search that saves the member
303 * attribute values of groups being deleted.
306 memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp )
308 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
309 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
312 SlapReply rs2 = { REP_RESULT };
313 slap_callback cb = { 0 };
314 memberof_cookie_t mc;
315 AttributeName an[ 2 ];
317 memberof_is_t iswhat = MEMBEROF_IS_NONE;
319 assert( iswhatp != NULL );
320 assert( *iswhatp != MEMBEROF_IS_NONE );
323 if ( op->o_tag == LDAP_REQ_DELETE ) {
324 cb.sc_response = memberof_saveMember_cb;
327 cb.sc_response = memberof_isGroupOrMember_cb;
330 op2.o_tag = LDAP_REQ_SEARCH;
331 op2.o_callback = &cb;
332 op2.o_dn = op->o_bd->be_rootdn;
333 op2.o_ndn = op->o_bd->be_rootndn;
335 op2.ors_scope = LDAP_SCOPE_BASE;
336 op2.ors_deref = LDAP_DEREF_NEVER;
337 BER_BVZERO( &an[ 1 ].an_name );
339 op2.ors_attrsonly = 0;
340 op2.ors_limit = NULL;
342 op2.ors_tlimit = SLAP_NO_LIMIT;
344 if ( *iswhatp & MEMBEROF_IS_GROUP ) {
345 mc.ad = mo->mo_ad_member;
346 mc.key = &saved_member_vals;
348 an[ 0 ].an_desc = mo->mo_ad_member;
349 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
350 op2.ors_filterstr = mo->mo_groupFilterstr;
351 op2.ors_filter = &mo->mo_groupFilter;
353 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
354 (void)op->o_bd->be_search( &op2, &rs2 );
355 op2.o_bd->bd_info = (BackendInfo *)on;
358 iswhat |= MEMBEROF_IS_GROUP;
361 memberof_saved_member_set( op, mc.key, NULL );
365 if ( *iswhatp & MEMBEROF_IS_MEMBER ) {
366 mc.ad = mo->mo_ad_memberof;
367 mc.key = &saved_memberof_vals;
369 an[ 0 ].an_desc = mo->mo_ad_memberof;
370 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
371 op2.ors_filterstr = mo->mo_memberFilterstr;
372 op2.ors_filter = &mo->mo_memberFilter;
374 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
375 (void)op->o_bd->be_search( &op2, &rs2 );
376 op2.o_bd->bd_info = (BackendInfo *)on;
379 iswhat |= MEMBEROF_IS_MEMBER;
382 memberof_saved_member_set( op, mc.key, NULL );
392 * response callback that adds memberof values when a group is modified.
395 memberof_value_modify(
399 AttributeDescription *ad,
400 struct berval *old_dn,
401 struct berval *old_ndn,
402 struct berval *new_dn,
403 struct berval *new_ndn )
405 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
406 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
409 SlapReply rs2 = { REP_RESULT };
410 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
411 Modifications mod[ 2 ] = { { { 0 } } }, *ml;
412 struct berval values[ 4 ], nvalues[ 4 ];
415 op2.o_tag = LDAP_REQ_MODIFY;
418 op2.o_req_ndn = *ndn;
420 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
422 op2.o_callback = &cb;
423 op2.o_dn = op->o_bd->be_rootdn;
424 op2.o_ndn = op->o_bd->be_rootndn;
425 op2.orm_modlist = NULL;
427 if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
430 ml->sml_values = &values[ 0 ];
431 ml->sml_values[ 0 ] = mo->mo_dn;
432 BER_BVZERO( &ml->sml_values[ 1 ] );
433 ml->sml_nvalues = &nvalues[ 0 ];
434 ml->sml_nvalues[ 0 ] = mo->mo_ndn;
435 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
436 ml->sml_desc = slap_schema.si_ad_modifiersName;
437 ml->sml_type = ml->sml_desc->ad_cname;
438 ml->sml_op = LDAP_MOD_REPLACE;
439 ml->sml_flags = SLAP_MOD_INTERNAL;
440 ml->sml_next = op2.orm_modlist;
441 op2.orm_modlist = ml;
448 ml->sml_values = &values[ 2 ];
449 BER_BVZERO( &ml->sml_values[ 1 ] );
450 ml->sml_nvalues = &nvalues[ 2 ];
451 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
453 ml->sml_type = ml->sml_desc->ad_cname;
454 ml->sml_flags = SLAP_MOD_INTERNAL;
455 ml->sml_next = op2.orm_modlist;
456 op2.orm_modlist = ml;
458 if ( new_ndn != NULL ) {
459 assert( !BER_BVISNULL( new_dn ) );
460 assert( !BER_BVISNULL( new_ndn ) );
463 ml->sml_op = LDAP_MOD_ADD;
465 ml->sml_values[ 0 ] = *new_dn;
466 ml->sml_nvalues[ 0 ] = *new_ndn;
468 (void)op->o_bd->be_modify( &op2, &rs2 );
469 if ( rs2.sr_err != LDAP_SUCCESS ) {
470 char buf[ SLAP_TEXT_BUFLEN ];
471 snprintf( buf, sizeof( buf ),
472 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
473 ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err,
474 rs2.sr_text ? rs2.sr_text : "" );
475 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
476 op->o_log_prefix, buf, 0 );
479 assert( op2.orm_modlist == &mod[ mcnt ] );
480 assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
481 ml = op2.orm_modlist->sml_next;
483 assert( ml == &mod[ 0 ] );
487 slap_mods_free( ml, 1 );
490 mod[ 0 ].sml_next = NULL;
493 if ( old_ndn != NULL ) {
494 assert( !BER_BVISNULL( old_dn ) );
495 assert( !BER_BVISNULL( old_ndn ) );
498 ml->sml_op = LDAP_MOD_DELETE;
500 ml->sml_values[ 0 ] = *old_dn;
501 ml->sml_nvalues[ 0 ] = *old_ndn;
503 (void)op->o_bd->be_modify( &op2, &rs2 );
504 if ( rs2.sr_err != LDAP_SUCCESS ) {
505 char buf[ SLAP_TEXT_BUFLEN ];
506 snprintf( buf, sizeof( buf ),
507 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
508 ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err,
509 rs2.sr_text ? rs2.sr_text : "" );
510 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
511 op->o_log_prefix, buf, 0 );
514 assert( op2.orm_modlist == &mod[ mcnt ] );
515 ml = op2.orm_modlist->sml_next;
517 assert( ml == &mod[ 0 ] );
521 slap_mods_free( ml, 1 );
525 /* FIXME: if old_group_ndn doesn't exist, both delete __and__
526 * add will fail; better split in two operations, although
527 * not optimal in terms of performance. At least it would
528 * move towards self-repairing capabilities. */
530 op2.o_bd->bd_info = (BackendInfo *)on;
536 memberof_op_add( Operation *op, SlapReply *rs )
538 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
539 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
541 Attribute **ap, **map = NULL;
542 int rc = SLAP_CB_CONTINUE;
544 struct berval save_dn, save_ndn;
546 if ( op->ora_e->e_attrs == NULL ) {
547 /* FIXME: global overlay; need to deal with */
548 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
549 "consistency checks not implemented when overlay "
550 "is instantiated as global.\n",
551 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
552 return SLAP_CB_CONTINUE;
555 if ( MEMBEROF_REVERSE( mo ) ) {
556 for ( ap = &op->ora_e->e_attrs; *ap; ap = &(*ap)->a_next ) {
559 if ( a->a_desc == mo->mo_ad_memberof ) {
567 save_ndn = op->o_ndn;
569 if ( MEMBEROF_DANGLING_CHECK( mo )
571 && is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) )
573 op->o_dn = op->o_bd->be_rootdn;
574 op->o_dn = op->o_bd->be_rootndn;
575 op->o_bd->bd_info = (BackendInfo *)on->on_info;
577 for ( ap = &op->ora_e->e_attrs; *ap; ) {
580 if ( !is_ad_subtype( a->a_desc, mo->mo_ad_member ) ) {
585 assert( a->a_nvals != NULL );
587 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
590 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
592 if ( rc == LDAP_SUCCESS ) {
593 be_entry_release_r( op, e );
597 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
598 rc = rs->sr_err = mo->mo_dangling_err;
599 rs->sr_text = "adding non-existing object "
601 send_ldap_result( op, rs );
605 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
608 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
609 "member=\"%s\" does not exist (stripping...)\n",
610 op->o_log_prefix, op->ora_e->e_name.bv_val,
611 a->a_vals[ i ].bv_val );
613 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
614 ber_memfree( a->a_vals[ i ].bv_val );
615 BER_BVZERO( &a->a_vals[ i ] );
616 if ( a->a_nvals != a->a_vals ) {
617 ber_memfree( a->a_nvals[ i ].bv_val );
618 BER_BVZERO( &a->a_nvals[ i ] );
624 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
625 sizeof( struct berval ) * ( j - i ) );
626 if ( a->a_nvals != a->a_vals ) {
627 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
628 sizeof( struct berval ) * ( j - i ) );
634 /* If all values have been removed,
635 * remove the attribute itself. */
636 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
645 op->o_ndn = save_ndn;
646 op->o_bd->bd_info = (BackendInfo *)on;
651 AccessControlState acl_state = ACL_STATE_INIT;
653 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
656 op->o_bd->bd_info = (BackendInfo *)on->on_info;
657 /* access is checked with the original identity */
658 rc = access_allowed( op, op->ora_e, mo->mo_ad_memberof,
659 &a->a_nvals[ i ], ACL_WADD,
662 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
664 send_ldap_result( op, rs );
667 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
669 op->o_bd->bd_info = (BackendInfo *)on;
670 if ( rc != LDAP_SUCCESS ) {
671 if ( get_relax( op ) ) {
675 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
676 rc = rs->sr_err = mo->mo_dangling_err;
677 rs->sr_text = "adding non-existing object "
679 send_ldap_result( op, rs );
683 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
686 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
687 "memberof=\"%s\" does not exist (stripping...)\n",
688 op->o_log_prefix, op->ora_e->e_name.bv_val,
689 a->a_nvals[ i ].bv_val );
691 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
692 ber_memfree( a->a_vals[ i ].bv_val );
693 BER_BVZERO( &a->a_vals[ i ] );
694 if ( a->a_nvals != a->a_vals ) {
695 ber_memfree( a->a_nvals[ i ].bv_val );
696 BER_BVZERO( &a->a_nvals[ i ] );
702 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
703 sizeof( struct berval ) * ( j - i ) );
704 if ( a->a_nvals != a->a_vals ) {
705 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
706 sizeof( struct berval ) * ( j - i ) );
714 /* access is checked with the original identity */
715 op->o_bd->bd_info = (BackendInfo *)on->on_info;
716 rc = access_allowed( op, e, mo->mo_ad_member,
717 &op->o_req_ndn, ACL_WADD, NULL );
718 be_entry_release_r( op, e );
719 op->o_bd->bd_info = (BackendInfo *)on;
722 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
723 rs->sr_text = "insufficient access to object referenced by memberof";
724 send_ldap_result( op, rs );
729 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
735 rc = SLAP_CB_CONTINUE;
739 op->o_ndn = save_ndn;
740 op->o_bd->bd_info = (BackendInfo *)on;
746 memberof_op_delete( Operation *op, SlapReply *rs )
748 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
749 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
751 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
753 if ( MEMBEROF_REFINT( mo ) ) {
754 iswhat = MEMBEROF_IS_BOTH;
757 memberof_isGroupOrMember( op, &iswhat );
759 return SLAP_CB_CONTINUE;
763 memberof_op_modify( Operation *op, SlapReply *rs )
765 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
766 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
768 Modifications **mlp, **mmlp = NULL;
769 int rc = SLAP_CB_CONTINUE;
770 struct berval save_dn, save_ndn;
771 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
773 if ( MEMBEROF_REVERSE( mo ) ) {
774 for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
775 Modifications *ml = *mlp;
777 if ( ml->sml_desc == mo->mo_ad_memberof ) {
785 save_ndn = op->o_ndn;
787 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
788 && ( iswhat & MEMBEROF_IS_GROUP ) )
793 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
794 if ( ml->sml_desc == mo->mo_ad_member ) {
795 switch ( ml->sml_op ) {
796 case LDAP_MOD_DELETE:
797 case LDAP_MOD_REPLACE:
805 BerVarray vals = NULL;
807 op->o_dn = op->o_bd->be_rootdn;
808 op->o_dn = op->o_bd->be_rootndn;
809 op->o_bd->bd_info = (BackendInfo *)on->on_info;
810 rc = backend_attribute( op, NULL, &op->o_req_ndn,
811 mo->mo_ad_member, &vals, ACL_READ );
812 op->o_bd->bd_info = (BackendInfo *)on;
813 if ( rc == LDAP_SUCCESS && vals != NULL ) {
814 memberof_saved_member_set( op, &saved_member_vals, vals );
815 ber_bvarray_free_x( vals, op->o_tmpmemctx );
819 if ( MEMBEROF_DANGLING_CHECK( mo )
820 && !get_relax( op ) )
822 op->o_dn = op->o_bd->be_rootdn;
823 op->o_dn = op->o_bd->be_rootndn;
824 op->o_bd->bd_info = (BackendInfo *)on->on_info;
826 assert( op->orm_modlist != NULL );
828 for ( mlp = &op->orm_modlist; *mlp; ) {
829 Modifications *ml = *mlp;
832 if ( !is_ad_subtype( ml->sml_desc, mo->mo_ad_member ) ) {
837 switch ( ml->sml_op ) {
838 case LDAP_MOD_DELETE:
839 /* we don't care about cancellations: if the value
840 * exists, fine; if it doesn't, we let the underlying
841 * database fail as appropriate; */
845 case LDAP_MOD_REPLACE:
847 /* NOTE: right now, the attributeType we use
848 * for member must have a normalized value */
849 assert( ml->sml_nvalues != NULL );
851 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
855 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
856 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
858 be_entry_release_r( op, e );
862 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
863 rc = rs->sr_err = mo->mo_dangling_err;
864 rs->sr_text = "adding non-existing object "
866 send_ldap_result( op, rs );
870 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
873 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
874 "member=\"%s\" does not exist (stripping...)\n",
875 op->o_log_prefix, op->o_req_dn.bv_val,
876 ml->sml_nvalues[ i ].bv_val );
878 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
879 ber_memfree( ml->sml_values[ i ].bv_val );
880 BER_BVZERO( &ml->sml_values[ i ] );
881 ber_memfree( ml->sml_nvalues[ i ].bv_val );
882 BER_BVZERO( &ml->sml_nvalues[ i ] );
888 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
889 sizeof( struct berval ) * ( j - i ) );
890 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
891 sizeof( struct berval ) * ( j - i ) );
896 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
898 slap_mod_free( &ml->sml_mod, 0 );
914 if ( mmlp != NULL ) {
915 Modifications *ml = *mmlp;
919 op->o_bd->bd_info = (BackendInfo *)on->on_info;
920 rc = be_entry_get_rw( op, &op->o_req_ndn,
921 NULL, NULL, 0, &target );
922 op->o_bd->bd_info = (BackendInfo *)on;
923 if ( rc != LDAP_SUCCESS ) {
924 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
925 send_ldap_result( op, rs );
929 switch ( ml->sml_op ) {
930 case LDAP_MOD_DELETE:
931 if ( ml->sml_nvalues != NULL ) {
932 AccessControlState acl_state = ACL_STATE_INIT;
934 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
937 op->o_bd->bd_info = (BackendInfo *)on->on_info;
938 /* access is checked with the original identity */
939 rc = access_allowed( op, target,
941 &ml->sml_nvalues[ i ],
945 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
947 send_ldap_result( op, rs );
951 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
953 op->o_bd->bd_info = (BackendInfo *)on;
954 if ( rc != LDAP_SUCCESS ) {
955 if ( get_relax( op ) ) {
959 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
960 rc = rs->sr_err = mo->mo_dangling_err;
961 rs->sr_text = "deleting non-existing object "
963 send_ldap_result( op, rs );
967 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
970 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
971 "memberof=\"%s\" does not exist (stripping...)\n",
972 op->o_log_prefix, op->o_req_ndn.bv_val,
973 ml->sml_nvalues[ i ].bv_val );
975 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
976 ber_memfree( ml->sml_values[ i ].bv_val );
977 BER_BVZERO( &ml->sml_values[ i ] );
978 if ( ml->sml_nvalues != ml->sml_values ) {
979 ber_memfree( ml->sml_nvalues[ i ].bv_val );
980 BER_BVZERO( &ml->sml_nvalues[ i ] );
987 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
988 sizeof( struct berval ) * ( j - i ) );
989 if ( ml->sml_nvalues != ml->sml_values ) {
990 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
991 sizeof( struct berval ) * ( j - i ) );
999 /* access is checked with the original identity */
1000 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1001 rc = access_allowed( op, e, mo->mo_ad_member,
1004 be_entry_release_r( op, e );
1005 op->o_bd->bd_info = (BackendInfo *)on;
1008 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1009 rs->sr_text = "insufficient access to object referenced by memberof";
1010 send_ldap_result( op, rs );
1015 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1016 *mmlp = ml->sml_next;
1017 slap_mod_free( &ml->sml_mod, 0 );
1025 case LDAP_MOD_REPLACE:
1027 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1028 /* access is checked with the original identity */
1029 rc = access_allowed( op, target,
1033 op->o_bd->bd_info = (BackendInfo *)on;
1035 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1037 send_ldap_result( op, rs );
1041 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1046 case LDAP_MOD_ADD: {
1047 AccessControlState acl_state = ACL_STATE_INIT;
1049 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1052 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1053 /* access is checked with the original identity */
1054 rc = access_allowed( op, target,
1056 &ml->sml_nvalues[ i ],
1060 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1062 send_ldap_result( op, rs );
1066 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1067 NULL, NULL, 0, &e );
1068 op->o_bd->bd_info = (BackendInfo *)on;
1069 if ( rc != LDAP_SUCCESS ) {
1070 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1071 rc = rs->sr_err = mo->mo_dangling_err;
1072 rs->sr_text = "adding non-existing object "
1074 send_ldap_result( op, rs );
1078 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1081 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1082 "memberof=\"%s\" does not exist (stripping...)\n",
1083 op->o_log_prefix, op->o_req_ndn.bv_val,
1084 ml->sml_nvalues[ i ].bv_val );
1086 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1087 ber_memfree( ml->sml_values[ i ].bv_val );
1088 BER_BVZERO( &ml->sml_values[ i ] );
1089 if ( ml->sml_nvalues != ml->sml_values ) {
1090 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1091 BER_BVZERO( &ml->sml_nvalues[ i ] );
1098 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1099 sizeof( struct berval ) * ( j - i ) );
1100 if ( ml->sml_nvalues != ml->sml_values ) {
1101 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1102 sizeof( struct berval ) * ( j - i ) );
1110 /* access is checked with the original identity */
1111 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1112 rc = access_allowed( op, e, mo->mo_ad_member,
1115 be_entry_release_r( op, e );
1116 op->o_bd->bd_info = (BackendInfo *)on;
1119 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1120 rs->sr_text = "insufficient access to object referenced by memberof";
1121 send_ldap_result( op, rs );
1126 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1127 *mmlp = ml->sml_next;
1128 slap_mod_free( &ml->sml_mod, 0 );
1139 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1140 be_entry_release_r( op, target );
1141 op->o_bd->bd_info = (BackendInfo *)on;
1144 rc = SLAP_CB_CONTINUE;
1148 op->o_ndn = save_ndn;
1149 op->o_bd->bd_info = (BackendInfo *)on;
1155 * response callback that adds memberof values when a group is added.
1158 memberof_res_add( Operation *op, SlapReply *rs )
1160 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1161 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1165 if ( MEMBEROF_REVERSE( mo ) ) {
1168 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1170 Operation op2 = *op;
1171 SlapReply rs2 = { 0 };
1173 /* relax is required to allow to add
1174 * a non-existing member */
1175 op2.o_relax = SLAP_CONTROL_CRITICAL;
1177 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1179 /* the modification is attempted
1180 * with the original identity */
1181 (void)memberof_value_modify( &op2, &rs2,
1182 &ma->a_nvals[ i ], mo->mo_ad_member,
1183 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1188 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1191 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1193 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1195 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1196 (void)memberof_value_modify( op, rs,
1206 return SLAP_CB_CONTINUE;
1210 * response callback that deletes memberof values when a group is deleted.
1213 memberof_res_delete( Operation *op, SlapReply *rs )
1215 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1216 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1221 vals = memberof_saved_member_get( op, &saved_member_vals );
1222 if ( vals != NULL ) {
1223 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1224 (void)memberof_value_modify( op, rs,
1225 &vals[ i ], mo->mo_ad_memberof,
1226 &op->o_req_dn, &op->o_req_ndn,
1230 memberof_saved_member_set( op, &saved_memberof_vals, NULL );
1231 ber_bvarray_free( vals );
1234 if ( MEMBEROF_REFINT( mo ) ) {
1235 vals = memberof_saved_member_get( op, &saved_memberof_vals );
1236 if ( vals != NULL ) {
1237 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1238 (void)memberof_value_modify( op, rs,
1239 &vals[ i ], mo->mo_ad_member,
1240 &op->o_req_dn, &op->o_req_ndn,
1244 memberof_saved_member_set( op, &saved_member_vals, NULL );
1245 ber_bvarray_free( vals );
1249 return SLAP_CB_CONTINUE;
1253 * response callback that adds/deletes memberof values when a group
1257 memberof_res_modify( Operation *op, SlapReply *rs )
1259 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1260 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1263 Modifications *ml, *mml = NULL;
1265 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1267 if ( MEMBEROF_REVERSE( mo ) ) {
1268 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1269 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1276 if ( mml != NULL ) {
1277 BerVarray vals = mml->sml_nvalues;
1279 switch ( mml->sml_op ) {
1280 case LDAP_MOD_DELETE:
1281 if ( vals != NULL ) {
1282 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1283 memberof_value_modify( op, rs,
1284 &vals[ i ], mo->mo_ad_member,
1285 &op->o_req_dn, &op->o_req_ndn,
1292 case LDAP_MOD_REPLACE:
1293 /* delete all ... */
1294 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1295 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1296 mo->mo_ad_memberof, &vals, ACL_READ );
1297 op->o_bd->bd_info = (BackendInfo *)on;
1298 if ( rc == LDAP_SUCCESS ) {
1299 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1300 (void)memberof_value_modify( op, rs,
1301 &vals[ i ], mo->mo_ad_member,
1302 &op->o_req_dn, &op->o_req_ndn,
1305 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1308 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1314 assert( vals != NULL );
1316 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1317 memberof_value_modify( op, rs,
1318 &vals[ i ], mo->mo_ad_member,
1320 &op->o_req_dn, &op->o_req_ndn );
1329 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
1330 && ( iswhat & MEMBEROF_IS_GROUP ) )
1332 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1333 if ( ml->sml_desc != mo->mo_ad_member ) {
1337 switch ( ml->sml_op ) {
1338 case LDAP_MOD_DELETE:
1339 vals = ml->sml_nvalues;
1340 if ( vals != NULL ) {
1341 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1342 memberof_value_modify( op, rs,
1343 &vals[ i ], mo->mo_ad_memberof,
1344 &op->o_req_dn, &op->o_req_ndn,
1351 case LDAP_MOD_REPLACE:
1352 vals = memberof_saved_member_get( op, &saved_member_vals );
1354 /* delete all ... */
1355 if ( vals != NULL ) {
1356 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1357 (void)memberof_value_modify( op, rs,
1358 &vals[ i ], mo->mo_ad_memberof,
1359 &op->o_req_dn, &op->o_req_ndn,
1362 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1365 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1371 assert( ml->sml_nvalues != NULL );
1372 vals = ml->sml_nvalues;
1373 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1374 memberof_value_modify( op, rs,
1375 &vals[ i ], mo->mo_ad_memberof,
1377 &op->o_req_dn, &op->o_req_ndn );
1387 return SLAP_CB_CONTINUE;
1391 * response callback that adds/deletes member values when a group member
1395 memberof_res_rename( Operation *op, SlapReply *rs )
1397 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1398 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1400 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1404 struct berval save_dn, save_ndn;
1405 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1407 if ( MEMBEROF_REFINT( mo ) ) {
1408 iswhat |= MEMBEROF_IS_MEMBER;
1411 if ( op->orr_nnewSup ) {
1412 newPNDN = *op->orr_nnewSup;
1415 dnParent( &op->o_req_ndn, &newPNDN );
1418 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1420 save_dn = op->o_req_dn;
1421 save_ndn = op->o_req_ndn;
1423 op->o_req_dn = newNDN;
1424 op->o_req_ndn = newNDN;
1425 rc = memberof_isGroupOrMember( op, &iswhat );
1426 op->o_req_dn = save_dn;
1427 op->o_req_ndn = save_ndn;
1429 if ( rc != LDAP_SUCCESS || iswhat == MEMBEROF_IS_NONE ) {
1433 if ( op->orr_newSup ) {
1434 newPDN = *op->orr_newSup;
1437 dnParent( &op->o_req_dn, &newPDN );
1440 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1442 if ( iswhat & MEMBEROF_IS_GROUP ) {
1443 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1444 rc = backend_attribute( op, NULL, &newNDN,
1445 mo->mo_ad_member, &vals, ACL_READ );
1446 op->o_bd->bd_info = (BackendInfo *)on;
1448 if ( rc == LDAP_SUCCESS ) {
1449 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1450 (void)memberof_value_modify( op, rs,
1451 &vals[ i ], mo->mo_ad_memberof,
1452 &op->o_req_dn, &op->o_req_ndn,
1455 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1459 if ( MEMBEROF_REFINT( mo ) && ( iswhat & MEMBEROF_IS_MEMBER ) ) {
1460 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1461 rc = backend_attribute( op, NULL, &newNDN,
1462 mo->mo_ad_memberof, &vals, ACL_READ );
1463 op->o_bd->bd_info = (BackendInfo *)on;
1465 if ( rc == LDAP_SUCCESS ) {
1466 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1467 (void)memberof_value_modify( op, rs,
1468 &vals[ i ], mo->mo_ad_member,
1469 &op->o_req_dn, &op->o_req_ndn,
1472 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1477 if ( !BER_BVISNULL( &newDN ) ) {
1478 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1480 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1482 return SLAP_CB_CONTINUE;
1486 memberof_response( Operation *op, SlapReply *rs )
1488 if ( rs->sr_err != LDAP_SUCCESS ) {
1489 return SLAP_CB_CONTINUE;
1492 switch ( op->o_tag ) {
1494 return memberof_res_add( op, rs );
1496 case LDAP_REQ_DELETE:
1497 return memberof_res_delete( op, rs );
1499 case LDAP_REQ_MODIFY:
1500 return memberof_res_modify( op, rs );
1502 case LDAP_REQ_MODDN:
1503 return memberof_res_rename( op, rs );
1506 return SLAP_CB_CONTINUE;
1515 slap_overinst *on = (slap_overinst *)be->bd_info;
1518 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1521 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1523 on->on_bi.bi_private = (void *)mo;
1544 static ConfigDriver mo_cf_gen;
1546 #define OID "1.3.6.1.4.1.7136.2.666.4"
1547 #define OIDAT OID ".1.1"
1548 #define OIDCFGAT OID ".1.2"
1549 #define OIDOC OID ".2.1"
1550 #define OIDCFGOC OID ".2.2"
1553 static ConfigTable mo_cfg[] = {
1554 { "memberof-dn", "modifiersName",
1555 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1556 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1557 "DESC 'DN to be used as modifiersName' "
1558 "SYNTAX OMsDN SINGLE-VALUE )",
1561 { "memberof-dangling", "ignore|drop|error",
1562 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1563 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1564 "DESC 'Behavior with respect to dangling members, "
1565 "constrained to ignore, drop, error' "
1566 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1569 { "memberof-refint", "true|FALSE",
1570 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1571 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1572 "DESC 'Take care of referential integrity' "
1573 "SYNTAX OMsBoolean SINGLE-VALUE )",
1576 { "memberof-group-oc", "objectClass",
1577 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1578 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1579 "DESC 'Group objectClass' "
1580 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1583 { "memberof-member-ad", "member attribute",
1584 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1585 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1586 "DESC 'member attribute' "
1587 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1590 { "memberof-memberof-ad", "memberOf attribute",
1591 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1592 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1593 "DESC 'memberOf attribute' "
1594 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1598 { "memberof-reverse", "true|FALSE",
1599 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1600 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1601 "DESC 'Take care of referential integrity "
1602 "also when directly modifying memberOf' "
1603 "SYNTAX OMsBoolean SINGLE-VALUE )",
1607 { "memberof-dangling-error", "error code",
1608 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1609 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1610 "DESC 'Error code returned in case of dangling back reference' "
1611 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1614 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1617 static ConfigOCs mo_ocs[] = {
1618 { "( OLcfgOvOc:18.1 "
1619 "NAME 'olcMemberOf' "
1620 "DESC 'Member-of configuration' "
1621 "SUP olcOverlayConfig "
1624 "$ olcMemberOfDangling "
1625 "$ olcMemberOfDanglingError"
1626 "$ olcMemberOfRefInt "
1627 "$ olcMemberOfGroupOC "
1628 "$ olcMemberOfMemberAD "
1629 "$ olcMemberOfMemberOfAD "
1631 "$ olcMemberOfReverse "
1635 Cft_Overlay, mo_cfg, NULL, NULL },
1639 static slap_verbmasks dangling_mode[] = {
1640 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1641 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1642 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1647 memberof_make_group_filter( memberof_t *mo )
1651 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1652 ch_free( mo->mo_groupFilterstr.bv_val );
1655 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1656 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1658 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1659 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1661 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1662 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1663 + mo->mo_oc_group->soc_cname.bv_len;
1664 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1666 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1668 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1676 memberof_make_member_filter( memberof_t *mo )
1680 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1681 ch_free( mo->mo_memberFilterstr.bv_val );
1684 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1685 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1687 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1688 + mo->mo_ad_memberof->ad_cname.bv_len;
1689 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1691 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1692 ptr = lutil_strcopy( ptr, "=*)" );
1698 mo_cf_gen( ConfigArgs *c )
1700 slap_overinst *on = (slap_overinst *)c->bi;
1701 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1705 if ( c->op == SLAP_CONFIG_EMIT ) {
1706 struct berval bv = BER_BVNULL;
1710 if ( mo->mo_dn.bv_val != NULL) {
1711 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1712 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1717 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1718 if ( BER_BVISNULL( &bv ) ) {
1719 /* there's something wrong... */
1724 value_add_one( &c->rvalue_vals, &bv );
1728 case MO_DANGLING_ERROR:
1729 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1730 char buf[ SLAP_TEXT_BUFLEN ];
1731 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1732 if ( BER_BVISNULL( &bv ) ) {
1733 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1734 if ( bv.bv_len < sizeof( buf ) ) {
1741 value_add_one( &c->rvalue_vals, &bv );
1748 c->value_int = MEMBEROF_REFINT( mo );
1753 c->value_int = MEMBEROF_REVERSE( mo );
1758 if ( mo->mo_oc_group != NULL ){
1759 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1764 if ( mo->mo_ad_member != NULL ){
1765 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1769 case MO_MEMBER_OF_AD:
1770 if ( mo->mo_ad_memberof != NULL ){
1771 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1782 } else if ( c->op == LDAP_MOD_DELETE ) {
1783 return 1; /* FIXME */
1788 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1789 ber_memfree( mo->mo_dn.bv_val );
1790 ber_memfree( mo->mo_ndn.bv_val );
1792 mo->mo_dn = c->value_dn;
1793 mo->mo_ndn = c->value_ndn;
1797 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1798 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1802 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1803 mo->mo_flags |= dangling_mode[ i ].mask;
1806 case MO_DANGLING_ERROR:
1807 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1808 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1809 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1810 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1816 if ( c->value_int ) {
1817 mo->mo_flags |= MEMBEROF_FREFINT;
1820 mo->mo_flags &= ~MEMBEROF_FREFINT;
1826 if ( c->value_int ) {
1827 mo->mo_flags |= MEMBEROF_FREVERSE;
1830 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1836 ObjectClass *oc = NULL;
1838 oc = oc_find( c->argv[ 1 ] );
1840 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1841 "unable to find group objectClass=\"%s\"",
1843 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1844 c->log, c->cr_msg, 0 );
1848 mo->mo_oc_group = oc;
1849 memberof_make_group_filter( mo );
1852 case MO_MEMBER_AD: {
1853 AttributeDescription *ad = NULL;
1854 const char *text = NULL;
1857 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1858 if ( rc != LDAP_SUCCESS ) {
1859 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1860 "unable to find member attribute=\"%s\": %s (%d)",
1861 c->argv[ 1 ], text, rc );
1862 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1863 c->log, c->cr_msg, 0 );
1867 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1868 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1870 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1871 "member attribute=\"%s\" must either "
1872 "have DN (%s) or nameUID (%s) syntax",
1873 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1874 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1875 c->log, c->cr_msg, 0 );
1879 mo->mo_ad_member = ad;
1882 case MO_MEMBER_OF_AD: {
1883 AttributeDescription *ad = NULL;
1884 const char *text = NULL;
1887 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1888 if ( rc != LDAP_SUCCESS ) {
1889 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1890 "unable to find memberof attribute=\"%s\": %s (%d)",
1891 c->argv[ 1 ], text, rc );
1892 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1893 c->log, c->cr_msg, 0 );
1897 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1898 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1900 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1901 "memberof attribute=\"%s\" must either "
1902 "have DN (%s) or nameUID (%s) syntax",
1903 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1904 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1905 c->log, c->cr_msg, 0 );
1909 mo->mo_ad_memberof = ad;
1910 memberof_make_member_filter( mo );
1927 slap_overinst *on = (slap_overinst *)be->bd_info;
1928 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1931 const char *text = NULL;
1933 if( ! mo->mo_ad_memberof ){
1934 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
1935 if ( rc != LDAP_SUCCESS ) {
1936 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1937 "unable to find attribute=\"%s\": %s (%d)\n",
1938 SLAPD_MEMBEROF_ATTR, text, rc );
1943 if( ! mo->mo_ad_member ){
1944 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &text );
1945 if ( rc != LDAP_SUCCESS ) {
1946 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1947 "unable to find attribute=\"%s\": %s (%d)\n",
1948 SLAPD_GROUP_ATTR, text, rc );
1953 if( ! mo->mo_oc_group ){
1954 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
1955 if ( mo->mo_oc_group == NULL ) {
1956 Debug( LDAP_DEBUG_ANY,
1957 "memberof_db_open: "
1958 "unable to find objectClass=\"%s\"\n",
1959 SLAPD_GROUP_CLASS, 0, 0 );
1964 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
1965 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
1966 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
1969 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1970 memberof_make_group_filter( mo );
1973 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1974 memberof_make_member_filter( mo );
1981 memberof_db_destroy(
1985 slap_overinst *on = (slap_overinst *)be->bd_info;
1986 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1989 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1990 ber_memfree( mo->mo_dn.bv_val );
1991 ber_memfree( mo->mo_ndn.bv_val );
1994 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1995 ber_memfree( mo->mo_groupFilterstr.bv_val );
1998 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1999 ber_memfree( mo->mo_memberFilterstr.bv_val );
2009 static AttributeDescription *ad_memberOf;
2013 AttributeDescription **adp;
2015 { "( 1.2.840.113556.1.2.102 "
2017 "DESC 'Group that the entry belongs to' "
2018 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2019 "EQUALITY distinguishedNameMatch " /* added */
2020 "USAGE dSAOperation " /* added; questioned */
2021 /* "NO-USER-MODIFICATION " */ /* add? */
2022 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2027 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2029 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2031 memberof_initialize( void )
2035 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2036 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2038 Debug( LDAP_DEBUG_ANY,
2039 "memberof_initialize: register_at #%d failed\n",
2045 memberof.on_bi.bi_type = "memberof";
2047 memberof.on_bi.bi_db_init = memberof_db_init;
2048 memberof.on_bi.bi_db_open = memberof_db_open;
2049 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2051 memberof.on_bi.bi_op_add = memberof_op_add;
2052 memberof.on_bi.bi_op_delete = memberof_op_delete;
2053 memberof.on_bi.bi_op_modify = memberof_op_modify;
2055 memberof.on_response = memberof_response;
2057 memberof.on_bi.bi_cf_ocs = mo_ocs;
2059 code = config_register_schema( mo_cfg, mo_ocs );
2060 if ( code ) return code;
2062 return overlay_register( &memberof );
2065 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2067 init_module( int argc, char *argv[] )
2069 return memberof_initialize();
2071 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2073 #endif /* SLAPD_OVER_MEMBEROF */