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_getkey( op->o_threadctx,
208 key, (void **)&vals, NULL );
209 ldap_pvt_thread_pool_setkey( op->o_threadctx,
217 memberof_saved_member_set( Operation *op, void *keyp, BerVarray vals )
219 BerVarray saved_vals = NULL;
220 BerVarray *key = (BerVarray*)keyp;
222 assert( op != NULL );
225 ber_bvarray_dup_x( &saved_vals, vals, NULL );
228 if ( op->o_threadctx == NULL ) {
230 ber_bvarray_free( *key );
235 BerVarray old_vals = NULL;
237 ldap_pvt_thread_pool_getkey( op->o_threadctx,
238 key, (void **)&old_vals, NULL );
239 if ( old_vals != NULL ) {
240 ber_bvarray_free( old_vals );
243 ldap_pvt_thread_pool_setkey( op->o_threadctx, key,
244 saved_vals, memberof_saved_member_free );
248 typedef struct memberof_cookie_t {
249 AttributeDescription *ad;
255 memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
257 if ( rs->sr_type == REP_SEARCH ) {
258 memberof_cookie_t *mc;
260 mc = (memberof_cookie_t *)op->o_callback->sc_private;
268 * callback for internal search that saves the member attribute values
269 * of groups being deleted.
272 memberof_saveMember_cb( Operation *op, SlapReply *rs )
274 if ( rs->sr_type == REP_SEARCH ) {
275 memberof_cookie_t *mc;
277 BerVarray vals = NULL;
279 mc = (memberof_cookie_t *)op->o_callback->sc_private;
282 assert( rs->sr_entry != NULL );
283 assert( rs->sr_entry->e_attrs != NULL );
285 a = attr_find( rs->sr_entry->e_attrs, mc->ad );
290 memberof_saved_member_set( op, mc->key, vals );
292 if ( a && attr_find( a->a_next, mc->ad ) != NULL ) {
293 Debug( LDAP_DEBUG_ANY,
294 "%s: memberof_saveMember_cb(\"%s\"): "
295 "more than one occurrence of \"%s\" "
298 rs->sr_entry->e_name.bv_val,
299 mc->ad->ad_cname.bv_val );
307 * the delete hook performs an internal search that saves the member
308 * attribute values of groups being deleted.
311 memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp )
313 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
314 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
317 SlapReply rs2 = { REP_RESULT };
318 slap_callback cb = { 0 };
319 memberof_cookie_t mc;
320 AttributeName an[ 2 ];
322 memberof_is_t iswhat = MEMBEROF_IS_NONE;
324 assert( iswhatp != NULL );
325 assert( *iswhatp != MEMBEROF_IS_NONE );
328 if ( op->o_tag == LDAP_REQ_DELETE ) {
329 cb.sc_response = memberof_saveMember_cb;
332 cb.sc_response = memberof_isGroupOrMember_cb;
335 op2.o_tag = LDAP_REQ_SEARCH;
336 op2.o_callback = &cb;
337 op2.o_dn = op->o_bd->be_rootdn;
338 op2.o_ndn = op->o_bd->be_rootndn;
340 op2.ors_scope = LDAP_SCOPE_BASE;
341 op2.ors_deref = LDAP_DEREF_NEVER;
342 BER_BVZERO( &an[ 1 ].an_name );
344 op2.ors_attrsonly = 0;
345 op2.ors_limit = NULL;
347 op2.ors_tlimit = SLAP_NO_LIMIT;
349 if ( *iswhatp & MEMBEROF_IS_GROUP ) {
350 mc.ad = mo->mo_ad_member;
351 mc.key = &saved_member_vals;
353 an[ 0 ].an_desc = mo->mo_ad_member;
354 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
355 op2.ors_filterstr = mo->mo_groupFilterstr;
356 op2.ors_filter = &mo->mo_groupFilter;
358 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
359 (void)op->o_bd->be_search( &op2, &rs2 );
360 op2.o_bd->bd_info = (BackendInfo *)on;
363 iswhat |= MEMBEROF_IS_GROUP;
366 memberof_saved_member_set( op, mc.key, NULL );
370 if ( *iswhatp & MEMBEROF_IS_MEMBER ) {
371 mc.ad = mo->mo_ad_memberof;
372 mc.key = &saved_memberof_vals;
374 an[ 0 ].an_desc = mo->mo_ad_memberof;
375 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
376 op2.ors_filterstr = mo->mo_memberFilterstr;
377 op2.ors_filter = &mo->mo_memberFilter;
379 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
380 (void)op->o_bd->be_search( &op2, &rs2 );
381 op2.o_bd->bd_info = (BackendInfo *)on;
384 iswhat |= MEMBEROF_IS_MEMBER;
387 memberof_saved_member_set( op, mc.key, NULL );
397 * response callback that adds memberof values when a group is modified.
400 memberof_value_modify(
404 AttributeDescription *ad,
405 struct berval *old_dn,
406 struct berval *old_ndn,
407 struct berval *new_dn,
408 struct berval *new_ndn )
410 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
411 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
414 SlapReply rs2 = { REP_RESULT };
415 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
416 Modifications mod[ 2 ] = { { { 0 } } }, *ml;
417 struct berval values[ 4 ], nvalues[ 4 ];
420 op2.o_tag = LDAP_REQ_MODIFY;
423 op2.o_req_ndn = *ndn;
425 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
427 op2.o_callback = &cb;
428 op2.o_dn = op->o_bd->be_rootdn;
429 op2.o_ndn = op->o_bd->be_rootndn;
430 op2.orm_modlist = NULL;
432 if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
435 ml->sml_values = &values[ 0 ];
436 ml->sml_values[ 0 ] = mo->mo_dn;
437 BER_BVZERO( &ml->sml_values[ 1 ] );
438 ml->sml_nvalues = &nvalues[ 0 ];
439 ml->sml_nvalues[ 0 ] = mo->mo_ndn;
440 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
441 ml->sml_desc = slap_schema.si_ad_modifiersName;
442 ml->sml_type = ml->sml_desc->ad_cname;
443 ml->sml_op = LDAP_MOD_REPLACE;
444 ml->sml_flags = SLAP_MOD_INTERNAL;
445 ml->sml_next = op2.orm_modlist;
446 op2.orm_modlist = ml;
453 ml->sml_values = &values[ 2 ];
454 BER_BVZERO( &ml->sml_values[ 1 ] );
455 ml->sml_nvalues = &nvalues[ 2 ];
456 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
458 ml->sml_type = ml->sml_desc->ad_cname;
459 ml->sml_flags = SLAP_MOD_INTERNAL;
460 ml->sml_next = op2.orm_modlist;
461 op2.orm_modlist = ml;
463 if ( new_ndn != NULL ) {
464 assert( !BER_BVISNULL( new_dn ) );
465 assert( !BER_BVISNULL( new_ndn ) );
468 ml->sml_op = LDAP_MOD_ADD;
470 ml->sml_values[ 0 ] = *new_dn;
471 ml->sml_nvalues[ 0 ] = *new_ndn;
473 (void)op->o_bd->be_modify( &op2, &rs2 );
474 if ( rs2.sr_err != LDAP_SUCCESS ) {
475 char buf[ SLAP_TEXT_BUFLEN ];
476 snprintf( buf, sizeof( buf ),
477 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
478 ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err, rs2.sr_text );
479 Debug( LDAP_DEBUG_ANY, "%s: %s\n", op->o_log_prefix, buf, 0 );
482 assert( op2.orm_modlist == &mod[ mcnt ] );
483 assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
484 ml = op2.orm_modlist->sml_next;
486 assert( ml == &mod[ 0 ] );
490 slap_mods_free( ml, 1 );
494 if ( old_ndn != NULL ) {
495 assert( !BER_BVISNULL( old_dn ) );
496 assert( !BER_BVISNULL( old_ndn ) );
499 ml->sml_op = LDAP_MOD_DELETE;
501 ml->sml_values[ 0 ] = *old_dn;
502 ml->sml_nvalues[ 0 ] = *old_ndn;
504 (void)op->o_bd->be_modify( &op2, &rs2 );
505 if ( rs2.sr_err != LDAP_SUCCESS ) {
506 char buf[ SLAP_TEXT_BUFLEN ];
507 snprintf( buf, sizeof( buf ),
508 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
509 ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err, rs2.sr_text );
510 Debug( LDAP_DEBUG_ANY, "%s: %s\n", op->o_log_prefix, buf, 0 );
513 assert( op2.orm_modlist == &mod[ mcnt ] );
514 ml = op2.orm_modlist->sml_next;
516 assert( ml == &mod[ 0 ] );
520 slap_mods_free( ml, 1 );
524 /* FIXME: if old_group_ndn doesn't exist, both delete __and__
525 * add will fail; better split in two operations, although
526 * not optimal in terms of performance. At least it would
527 * move towards self-repairing capabilities. */
529 op2.o_bd->bd_info = (BackendInfo *)on;
535 memberof_op_add( Operation *op, SlapReply *rs )
537 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
538 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
540 Attribute **ap, **map = NULL;
541 int rc = SLAP_CB_CONTINUE;
543 struct berval save_dn, save_ndn;
545 if ( op->ora_e->e_attrs == NULL ) {
546 /* FIXME: global overlay; need to deal with */
547 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
548 "consistency checks not implemented when overlay "
549 "is instantiated as global.\n",
550 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
551 return SLAP_CB_CONTINUE;
554 if ( MEMBEROF_REVERSE( mo ) ) {
555 for ( ap = &op->ora_e->e_attrs; *ap; ap = &(*ap)->a_next ) {
558 if ( a->a_desc == mo->mo_ad_memberof ) {
566 save_ndn = op->o_ndn;
568 if ( MEMBEROF_DANGLING_CHECK( mo )
570 && is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) )
572 op->o_dn = op->o_bd->be_rootdn;
573 op->o_dn = op->o_bd->be_rootndn;
574 op->o_bd->bd_info = (BackendInfo *)on->on_info;
576 for ( ap = &op->ora_e->e_attrs; *ap; ) {
579 if ( !is_ad_subtype( a->a_desc, mo->mo_ad_member ) ) {
584 assert( a->a_nvals != NULL );
586 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
589 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
591 if ( rc == LDAP_SUCCESS ) {
592 be_entry_release_r( op, e );
596 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
597 rc = rs->sr_err = mo->mo_dangling_err;
598 rs->sr_text = "adding non-existing object "
600 send_ldap_result( op, rs );
604 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
607 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
608 "member=\"%s\" does not exist (stripping...)\n",
609 op->o_log_prefix, op->ora_e->e_name.bv_val,
610 a->a_vals[ i ].bv_val );
612 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
613 ber_memfree( a->a_vals[ i ].bv_val );
614 BER_BVZERO( &a->a_vals[ i ] );
615 if ( a->a_nvals != a->a_vals ) {
616 ber_memfree( a->a_nvals[ i ].bv_val );
617 BER_BVZERO( &a->a_nvals[ i ] );
623 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
624 sizeof( struct berval ) * ( j - i ) );
625 if ( a->a_nvals != a->a_vals ) {
626 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
627 sizeof( struct berval ) * ( j - i ) );
633 /* If all values have been removed,
634 * remove the attribute itself. */
635 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
644 op->o_ndn = save_ndn;
645 op->o_bd->bd_info = (BackendInfo *)on;
650 AccessControlState acl_state = ACL_STATE_INIT;
652 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
655 op->o_bd->bd_info = (BackendInfo *)on->on_info;
656 /* access is checked with the original identity */
657 rc = access_allowed( op, op->ora_e, mo->mo_ad_memberof,
658 &a->a_nvals[ i ], ACL_WADD,
661 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
663 send_ldap_result( op, rs );
666 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
668 op->o_bd->bd_info = (BackendInfo *)on;
669 if ( rc != LDAP_SUCCESS ) {
670 if ( get_relax( op ) ) {
674 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
675 rc = rs->sr_err = mo->mo_dangling_err;
676 rs->sr_text = "adding non-existing object "
678 send_ldap_result( op, rs );
682 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
685 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
686 "memberof=\"%s\" does not exist (stripping...)\n",
687 op->o_log_prefix, op->ora_e->e_name.bv_val,
688 a->a_nvals[ i ].bv_val );
690 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
691 ber_memfree( a->a_vals[ i ].bv_val );
692 BER_BVZERO( &a->a_vals[ i ] );
693 if ( a->a_nvals != a->a_vals ) {
694 ber_memfree( a->a_nvals[ i ].bv_val );
695 BER_BVZERO( &a->a_nvals[ i ] );
701 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
702 sizeof( struct berval ) * ( j - i ) );
703 if ( a->a_nvals != a->a_vals ) {
704 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
705 sizeof( struct berval ) * ( j - i ) );
713 /* access is checked with the original identity */
714 op->o_bd->bd_info = (BackendInfo *)on->on_info;
715 rc = access_allowed( op, e, mo->mo_ad_member,
716 &op->o_req_ndn, ACL_WADD, NULL );
717 be_entry_release_r( op, e );
718 op->o_bd->bd_info = (BackendInfo *)on;
721 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
722 rs->sr_text = "insufficient access to object referenced by memberof";
723 send_ldap_result( op, rs );
728 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
734 rc = SLAP_CB_CONTINUE;
738 op->o_ndn = save_ndn;
739 op->o_bd->bd_info = (BackendInfo *)on;
745 memberof_op_delete( Operation *op, SlapReply *rs )
747 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
748 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
750 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
752 if ( MEMBEROF_REFINT( mo ) ) {
753 iswhat = MEMBEROF_IS_BOTH;
756 memberof_isGroupOrMember( op, &iswhat );
758 return SLAP_CB_CONTINUE;
762 memberof_op_modify( Operation *op, SlapReply *rs )
764 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
765 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
767 Modifications **mlp, **mmlp = NULL;
768 int rc = SLAP_CB_CONTINUE;
769 struct berval save_dn, save_ndn;
770 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
772 if ( MEMBEROF_REVERSE( mo ) ) {
773 for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
774 Modifications *ml = *mlp;
776 if ( ml->sml_desc == mo->mo_ad_memberof ) {
784 save_ndn = op->o_ndn;
786 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
787 && ( iswhat & MEMBEROF_IS_GROUP ) )
792 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
793 if ( ml->sml_desc == mo->mo_ad_member ) {
794 switch ( ml->sml_op ) {
795 case LDAP_MOD_DELETE:
796 case LDAP_MOD_REPLACE:
804 BerVarray vals = NULL;
806 op->o_dn = op->o_bd->be_rootdn;
807 op->o_dn = op->o_bd->be_rootndn;
808 op->o_bd->bd_info = (BackendInfo *)on->on_info;
809 rc = backend_attribute( op, NULL, &op->o_req_ndn,
810 mo->mo_ad_member, &vals, ACL_READ );
811 op->o_bd->bd_info = (BackendInfo *)on;
812 if ( rc == LDAP_SUCCESS && vals != NULL ) {
813 memberof_saved_member_set( op, &saved_member_vals, vals );
814 ber_bvarray_free_x( vals, op->o_tmpmemctx );
818 if ( MEMBEROF_DANGLING_CHECK( mo )
819 && !get_relax( op ) )
821 op->o_dn = op->o_bd->be_rootdn;
822 op->o_dn = op->o_bd->be_rootndn;
823 op->o_bd->bd_info = (BackendInfo *)on->on_info;
825 assert( op->orm_modlist != NULL );
827 for ( mlp = &op->orm_modlist; *mlp; ) {
828 Modifications *ml = *mlp;
831 if ( !is_ad_subtype( ml->sml_desc, mo->mo_ad_member ) ) {
836 switch ( ml->sml_op ) {
837 case LDAP_MOD_DELETE:
838 /* we don't care about cancellations: if the value
839 * exists, fine; if it doesn't, we let the underlying
840 * database fail as appropriate; */
844 case LDAP_MOD_REPLACE:
846 /* NOTE: right now, the attributeType we use
847 * for member must have a normalized value */
848 assert( ml->sml_nvalues != NULL );
850 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
854 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
855 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
857 be_entry_release_r( op, e );
861 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
862 rc = rs->sr_err = mo->mo_dangling_err;
863 rs->sr_text = "adding non-existing object "
865 send_ldap_result( op, rs );
869 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
872 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
873 "member=\"%s\" does not exist (stripping...)\n",
874 op->o_log_prefix, op->o_req_dn.bv_val,
875 ml->sml_nvalues[ i ].bv_val );
877 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
878 ber_memfree( ml->sml_values[ i ].bv_val );
879 BER_BVZERO( &ml->sml_values[ i ] );
880 ber_memfree( ml->sml_nvalues[ i ].bv_val );
881 BER_BVZERO( &ml->sml_nvalues[ i ] );
887 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
888 sizeof( struct berval ) * ( j - i ) );
889 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
890 sizeof( struct berval ) * ( j - i ) );
895 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
897 slap_mod_free( &ml->sml_mod, 0 );
913 if ( mmlp != NULL ) {
914 Modifications *ml = *mmlp;
918 op->o_bd->bd_info = (BackendInfo *)on->on_info;
919 rc = be_entry_get_rw( op, &op->o_req_ndn,
920 NULL, NULL, 0, &target );
921 op->o_bd->bd_info = (BackendInfo *)on;
922 if ( rc != LDAP_SUCCESS ) {
923 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
924 send_ldap_result( op, rs );
928 switch ( ml->sml_op ) {
929 case LDAP_MOD_DELETE:
930 if ( ml->sml_nvalues != NULL ) {
931 AccessControlState acl_state = ACL_STATE_INIT;
933 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
936 op->o_bd->bd_info = (BackendInfo *)on->on_info;
937 /* access is checked with the original identity */
938 rc = access_allowed( op, target,
940 &ml->sml_nvalues[ i ],
944 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
946 send_ldap_result( op, rs );
950 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
952 op->o_bd->bd_info = (BackendInfo *)on;
953 if ( rc != LDAP_SUCCESS ) {
954 if ( get_relax( op ) ) {
958 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
959 rc = rs->sr_err = mo->mo_dangling_err;
960 rs->sr_text = "deleting non-existing object "
962 send_ldap_result( op, rs );
966 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
969 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
970 "memberof=\"%s\" does not exist (stripping...)\n",
971 op->o_log_prefix, op->o_req_ndn.bv_val,
972 ml->sml_nvalues[ i ].bv_val );
974 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
975 ber_memfree( ml->sml_values[ i ].bv_val );
976 BER_BVZERO( &ml->sml_values[ i ] );
977 if ( ml->sml_nvalues != ml->sml_values ) {
978 ber_memfree( ml->sml_nvalues[ i ].bv_val );
979 BER_BVZERO( &ml->sml_nvalues[ i ] );
986 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
987 sizeof( struct berval ) * ( j - i ) );
988 if ( ml->sml_nvalues != ml->sml_values ) {
989 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
990 sizeof( struct berval ) * ( j - i ) );
998 /* access is checked with the original identity */
999 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1000 rc = access_allowed( op, e, mo->mo_ad_member,
1003 be_entry_release_r( op, e );
1004 op->o_bd->bd_info = (BackendInfo *)on;
1007 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1008 rs->sr_text = "insufficient access to object referenced by memberof";
1009 send_ldap_result( op, rs );
1014 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1015 *mmlp = ml->sml_next;
1016 slap_mod_free( &ml->sml_mod, 0 );
1024 case LDAP_MOD_REPLACE:
1026 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1027 /* access is checked with the original identity */
1028 rc = access_allowed( op, target,
1032 op->o_bd->bd_info = (BackendInfo *)on;
1034 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1036 send_ldap_result( op, rs );
1040 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1045 case LDAP_MOD_ADD: {
1046 AccessControlState acl_state = ACL_STATE_INIT;
1048 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1051 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1052 /* access is checked with the original identity */
1053 rc = access_allowed( op, target,
1055 &ml->sml_nvalues[ i ],
1059 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1061 send_ldap_result( op, rs );
1065 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1066 NULL, NULL, 0, &e );
1067 op->o_bd->bd_info = (BackendInfo *)on;
1068 if ( rc != LDAP_SUCCESS ) {
1069 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1070 rc = rs->sr_err = mo->mo_dangling_err;
1071 rs->sr_text = "adding non-existing object "
1073 send_ldap_result( op, rs );
1077 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1080 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1081 "memberof=\"%s\" does not exist (stripping...)\n",
1082 op->o_log_prefix, op->o_req_ndn.bv_val,
1083 ml->sml_nvalues[ i ].bv_val );
1085 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1086 ber_memfree( ml->sml_values[ i ].bv_val );
1087 BER_BVZERO( &ml->sml_values[ i ] );
1088 if ( ml->sml_nvalues != ml->sml_values ) {
1089 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1090 BER_BVZERO( &ml->sml_nvalues[ i ] );
1097 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1098 sizeof( struct berval ) * ( j - i ) );
1099 if ( ml->sml_nvalues != ml->sml_values ) {
1100 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1101 sizeof( struct berval ) * ( j - i ) );
1109 /* access is checked with the original identity */
1110 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1111 rc = access_allowed( op, e, mo->mo_ad_member,
1114 be_entry_release_r( op, e );
1115 op->o_bd->bd_info = (BackendInfo *)on;
1118 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1119 rs->sr_text = "insufficient access to object referenced by memberof";
1120 send_ldap_result( op, rs );
1125 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1126 *mmlp = ml->sml_next;
1127 slap_mod_free( &ml->sml_mod, 0 );
1138 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1139 be_entry_release_r( op, target );
1140 op->o_bd->bd_info = (BackendInfo *)on;
1143 rc = SLAP_CB_CONTINUE;
1147 op->o_ndn = save_ndn;
1148 op->o_bd->bd_info = (BackendInfo *)on;
1154 * response callback that adds memberof values when a group is added.
1157 memberof_res_add( Operation *op, SlapReply *rs )
1159 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1160 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1164 if ( MEMBEROF_REVERSE( mo ) ) {
1167 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1169 Operation op2 = *op;
1170 SlapReply rs2 = { 0 };
1172 /* relax is required to allow to add
1173 * a non-existing member */
1174 op2.o_relax = SLAP_CONTROL_CRITICAL;
1176 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1178 /* the modification is attempted
1179 * with the original identity */
1180 (void)memberof_value_modify( &op2, &rs2,
1181 &ma->a_nvals[ i ], mo->mo_ad_member,
1182 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1187 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1190 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1192 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1194 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1195 (void)memberof_value_modify( op, rs,
1205 return SLAP_CB_CONTINUE;
1209 * response callback that deletes memberof values when a group is deleted.
1212 memberof_res_delete( Operation *op, SlapReply *rs )
1214 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1215 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1220 vals = memberof_saved_member_get( op, &saved_member_vals );
1221 if ( vals != NULL ) {
1222 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1223 (void)memberof_value_modify( op, rs,
1224 &vals[ i ], mo->mo_ad_memberof,
1225 &op->o_req_dn, &op->o_req_ndn,
1229 memberof_saved_member_set( op, &saved_memberof_vals, NULL );
1230 ber_bvarray_free( vals );
1233 if ( MEMBEROF_REFINT( mo ) ) {
1234 vals = memberof_saved_member_get( op, &saved_memberof_vals );
1235 if ( vals != NULL ) {
1236 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1237 (void)memberof_value_modify( op, rs,
1238 &vals[ i ], mo->mo_ad_member,
1239 &op->o_req_dn, &op->o_req_ndn,
1243 memberof_saved_member_set( op, &saved_member_vals, NULL );
1244 ber_bvarray_free( vals );
1248 return SLAP_CB_CONTINUE;
1252 * response callback that adds/deletes memberof values when a group
1256 memberof_res_modify( Operation *op, SlapReply *rs )
1258 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1259 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1262 Modifications *ml, *mml = NULL;
1264 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1266 if ( MEMBEROF_REVERSE( mo ) ) {
1267 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1268 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1275 if ( mml != NULL ) {
1276 BerVarray vals = mml->sml_nvalues;
1278 switch ( mml->sml_op ) {
1279 case LDAP_MOD_DELETE:
1280 if ( vals != NULL ) {
1281 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1282 memberof_value_modify( op, rs,
1283 &vals[ i ], mo->mo_ad_member,
1284 &op->o_req_dn, &op->o_req_ndn,
1291 case LDAP_MOD_REPLACE:
1292 /* delete all ... */
1293 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1294 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1295 mo->mo_ad_memberof, &vals, ACL_READ );
1296 op->o_bd->bd_info = (BackendInfo *)on;
1297 if ( rc == LDAP_SUCCESS ) {
1298 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1299 (void)memberof_value_modify( op, rs,
1300 &vals[ i ], mo->mo_ad_member,
1301 &op->o_req_dn, &op->o_req_ndn,
1304 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1307 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1313 assert( vals != NULL );
1315 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1316 memberof_value_modify( op, rs,
1317 &vals[ i ], mo->mo_ad_member,
1319 &op->o_req_dn, &op->o_req_ndn );
1328 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
1329 && ( iswhat & MEMBEROF_IS_GROUP ) )
1331 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1332 if ( ml->sml_desc != mo->mo_ad_member ) {
1336 switch ( ml->sml_op ) {
1337 case LDAP_MOD_DELETE:
1338 vals = ml->sml_nvalues;
1339 if ( vals != NULL ) {
1340 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1341 memberof_value_modify( op, rs,
1342 &vals[ i ], mo->mo_ad_memberof,
1343 &op->o_req_dn, &op->o_req_ndn,
1350 case LDAP_MOD_REPLACE:
1351 vals = memberof_saved_member_get( op, &saved_member_vals );
1353 /* delete all ... */
1354 if ( vals != NULL ) {
1355 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1356 (void)memberof_value_modify( op, rs,
1357 &vals[ i ], mo->mo_ad_memberof,
1358 &op->o_req_dn, &op->o_req_ndn,
1361 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1364 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1370 assert( ml->sml_nvalues != NULL );
1371 vals = ml->sml_nvalues;
1372 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1373 memberof_value_modify( op, rs,
1374 &vals[ i ], mo->mo_ad_memberof,
1376 &op->o_req_dn, &op->o_req_ndn );
1386 return SLAP_CB_CONTINUE;
1390 * response callback that adds/deletes member values when a group member
1394 memberof_res_rename( Operation *op, SlapReply *rs )
1396 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1397 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1399 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1403 struct berval save_dn, save_ndn;
1404 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1406 if ( MEMBEROF_REFINT( mo ) ) {
1407 iswhat |= MEMBEROF_IS_MEMBER;
1410 if ( op->orr_nnewSup ) {
1411 newPNDN = *op->orr_nnewSup;
1414 dnParent( &op->o_req_ndn, &newPNDN );
1417 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1419 save_dn = op->o_req_dn;
1420 save_ndn = op->o_req_ndn;
1422 op->o_req_dn = newNDN;
1423 op->o_req_ndn = newNDN;
1424 rc = memberof_isGroupOrMember( op, &iswhat );
1425 op->o_req_dn = save_dn;
1426 op->o_req_ndn = save_ndn;
1428 if ( rc != LDAP_SUCCESS || iswhat == MEMBEROF_IS_NONE ) {
1432 if ( op->orr_newSup ) {
1433 newPDN = *op->orr_newSup;
1436 dnParent( &op->o_req_dn, &newPDN );
1439 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1441 if ( iswhat & MEMBEROF_IS_GROUP ) {
1442 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1443 rc = backend_attribute( op, NULL, &newNDN,
1444 mo->mo_ad_member, &vals, ACL_READ );
1445 op->o_bd->bd_info = (BackendInfo *)on;
1447 if ( rc == LDAP_SUCCESS ) {
1448 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1449 (void)memberof_value_modify( op, rs,
1450 &vals[ i ], mo->mo_ad_memberof,
1451 &op->o_req_dn, &op->o_req_ndn,
1454 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1458 if ( MEMBEROF_REFINT( mo ) && ( iswhat & MEMBEROF_IS_MEMBER ) ) {
1459 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1460 rc = backend_attribute( op, NULL, &newNDN,
1461 mo->mo_ad_memberof, &vals, ACL_READ );
1462 op->o_bd->bd_info = (BackendInfo *)on;
1464 if ( rc == LDAP_SUCCESS ) {
1465 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1466 (void)memberof_value_modify( op, rs,
1467 &vals[ i ], mo->mo_ad_member,
1468 &op->o_req_dn, &op->o_req_ndn,
1471 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1476 if ( !BER_BVISNULL( &newDN ) ) {
1477 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1479 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1481 return SLAP_CB_CONTINUE;
1485 memberof_response( Operation *op, SlapReply *rs )
1487 if ( rs->sr_err != LDAP_SUCCESS ) {
1488 return SLAP_CB_CONTINUE;
1491 switch ( op->o_tag ) {
1493 return memberof_res_add( op, rs );
1495 case LDAP_REQ_DELETE:
1496 return memberof_res_delete( op, rs );
1498 case LDAP_REQ_MODIFY:
1499 return memberof_res_modify( op, rs );
1501 case LDAP_REQ_MODDN:
1502 return memberof_res_rename( op, rs );
1505 return SLAP_CB_CONTINUE;
1514 slap_overinst *on = (slap_overinst *)be->bd_info;
1515 memberof_t tmp_mo = { 0 }, *mo;
1517 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1520 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1522 on->on_bi.bi_private = (void *)mo;
1543 static ConfigDriver mo_cf_gen;
1545 #define OID "1.3.6.1.4.1.7136.2.666.4"
1546 #define OIDAT OID ".1.1"
1547 #define OIDCFGAT OID ".1.2"
1548 #define OIDOC OID ".2.1"
1549 #define OIDCFGOC OID ".2.2"
1552 static ConfigTable mo_cfg[] = {
1553 { "memberof-dn", "modifiersName",
1554 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1555 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1556 "DESC 'DN to be used as modifiersName' "
1557 "SYNTAX OMsDN SINGLE-VALUE )",
1560 { "memberof-dangling", "ignore|drop|error",
1561 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1562 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1563 "DESC 'Behavior with respect to dangling members, "
1564 "constrained to ignore, drop, error' "
1565 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1568 { "memberof-refint", "true|FALSE",
1569 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1570 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1571 "DESC 'Take care of referential integrity' "
1572 "SYNTAX OMsBoolean SINGLE-VALUE )",
1575 { "memberof-group-oc", "objectClass",
1576 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1577 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1578 "DESC 'Group objectClass' "
1579 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1582 { "memberof-member-ad", "member attribute",
1583 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1584 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1585 "DESC 'member attribute' "
1586 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1589 { "memberof-memberof-ad", "memberOf attribute",
1590 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1591 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1592 "DESC 'memberOf attribute' "
1593 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1597 { "memberof-reverse", "true|FALSE",
1598 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1599 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1600 "DESC 'Take care of referential integrity "
1601 "also when directly modifying memberOf' "
1602 "SYNTAX OMsBoolean SINGLE-VALUE )",
1606 { "memberof-dangling-error", "error code",
1607 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1608 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1609 "DESC 'Error code returned in case of dangling back reference' "
1610 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1613 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1616 static ConfigOCs mo_ocs[] = {
1617 { "( OLcfgOvOc:18.1 "
1618 "NAME 'olcMemberOf' "
1619 "DESC 'Member-of configuration' "
1620 "SUP olcOverlayConfig "
1623 "$ olcMemberOfDangling "
1624 "$ olcMemberOfDanglingError"
1625 "$ olcMemberOfRefInt "
1626 "$ olcMemberOfGroupOC "
1627 "$ olcMemberOfMemberAD "
1628 "$ olcMemberOfMemberOfAD "
1630 "$ olcMemberOfReverse "
1634 Cft_Overlay, mo_cfg, NULL, NULL },
1638 static slap_verbmasks dangling_mode[] = {
1639 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1640 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1641 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1646 memberof_make_group_filter( memberof_t *mo )
1650 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1651 ch_free( mo->mo_groupFilterstr.bv_val );
1654 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1655 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1657 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1658 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1660 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1661 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1662 + mo->mo_oc_group->soc_cname.bv_len;
1663 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1665 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1667 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1675 memberof_make_member_filter( memberof_t *mo )
1679 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1680 ch_free( mo->mo_memberFilterstr.bv_val );
1683 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1684 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1686 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1687 + mo->mo_ad_memberof->ad_cname.bv_len;
1688 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1690 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1691 ptr = lutil_strcopy( ptr, "=*)" );
1697 mo_cf_gen( ConfigArgs *c )
1699 slap_overinst *on = (slap_overinst *)c->bi;
1700 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1704 if ( c->op == SLAP_CONFIG_EMIT ) {
1705 struct berval bv = BER_BVNULL;
1709 if ( mo->mo_dn.bv_val != NULL) {
1710 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1711 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1716 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1717 if ( BER_BVISNULL( &bv ) ) {
1718 /* there's something wrong... */
1723 value_add_one( &c->rvalue_vals, &bv );
1727 case MO_DANGLING_ERROR:
1728 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1729 char buf[ SLAP_TEXT_BUFLEN ];
1730 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1731 if ( BER_BVISNULL( &bv ) ) {
1732 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1733 if ( bv.bv_len < sizeof( buf ) ) {
1740 value_add_one( &c->rvalue_vals, &bv );
1747 c->value_int = MEMBEROF_REFINT( mo );
1752 c->value_int = MEMBEROF_REVERSE( mo );
1757 if ( mo->mo_oc_group != NULL ){
1758 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1763 if ( mo->mo_ad_member != NULL ){
1764 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1768 case MO_MEMBER_OF_AD:
1769 if ( mo->mo_ad_memberof != NULL ){
1770 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1781 } else if ( c->op == LDAP_MOD_DELETE ) {
1782 return 1; /* FIXME */
1787 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1788 ber_memfree( mo->mo_dn.bv_val );
1789 ber_memfree( mo->mo_ndn.bv_val );
1791 mo->mo_dn = c->value_dn;
1792 mo->mo_ndn = c->value_ndn;
1796 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1797 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1801 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1802 mo->mo_flags |= dangling_mode[ i ].mask;
1805 case MO_DANGLING_ERROR:
1806 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1807 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1808 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1809 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1815 if ( c->value_int ) {
1816 mo->mo_flags |= MEMBEROF_FREFINT;
1819 mo->mo_flags &= ~MEMBEROF_FREFINT;
1825 if ( c->value_int ) {
1826 mo->mo_flags |= MEMBEROF_FREVERSE;
1829 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1835 ObjectClass *oc = NULL;
1837 oc = oc_find( c->argv[ 1 ] );
1839 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1840 "unable to find group objectClass=\"%s\"",
1842 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1843 c->log, c->cr_msg, 0 );
1847 mo->mo_oc_group = oc;
1848 memberof_make_group_filter( mo );
1851 case MO_MEMBER_AD: {
1852 AttributeDescription *ad = NULL;
1853 const char *text = NULL;
1856 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1857 if ( rc != LDAP_SUCCESS ) {
1858 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1859 "unable to find member attribute=\"%s\": %s (%d)",
1860 c->argv[ 1 ], text, rc );
1861 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1862 c->log, c->cr_msg, 0 );
1866 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1867 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1869 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1870 "member attribute=\"%s\" must either "
1871 "have DN (%s) or nameUID (%s) syntax",
1872 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1873 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1874 c->log, c->cr_msg, 0 );
1878 mo->mo_ad_member = ad;
1881 case MO_MEMBER_OF_AD: {
1882 AttributeDescription *ad = NULL;
1883 const char *text = NULL;
1886 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1887 if ( rc != LDAP_SUCCESS ) {
1888 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1889 "unable to find memberof attribute=\"%s\": %s (%d)",
1890 c->argv[ 1 ], text, rc );
1891 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1892 c->log, c->cr_msg, 0 );
1896 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1897 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1899 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1900 "memberof attribute=\"%s\" must either "
1901 "have DN (%s) or nameUID (%s) syntax",
1902 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1903 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1904 c->log, c->cr_msg, 0 );
1908 mo->mo_ad_memberof = ad;
1909 memberof_make_member_filter( mo );
1926 slap_overinst *on = (slap_overinst *)be->bd_info;
1927 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1930 const char *text = NULL;
1932 if( ! mo->mo_ad_memberof ){
1933 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
1934 if ( rc != LDAP_SUCCESS ) {
1935 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1936 "unable to find attribute=\"%s\": %s (%d)\n",
1937 SLAPD_MEMBEROF_ATTR, text, rc );
1942 if( ! mo->mo_ad_member ){
1943 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &text );
1944 if ( rc != LDAP_SUCCESS ) {
1945 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1946 "unable to find attribute=\"%s\": %s (%d)\n",
1947 SLAPD_GROUP_ATTR, text, rc );
1952 if( ! mo->mo_oc_group ){
1953 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
1954 if ( mo->mo_oc_group == NULL ) {
1955 Debug( LDAP_DEBUG_ANY,
1956 "memberof_db_open: "
1957 "unable to find objectClass=\"%s\"\n",
1958 SLAPD_GROUP_CLASS, 0, 0 );
1963 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
1964 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
1965 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
1968 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1969 memberof_make_group_filter( mo );
1972 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1973 memberof_make_member_filter( mo );
1980 memberof_db_destroy(
1984 slap_overinst *on = (slap_overinst *)be->bd_info;
1985 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1988 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1989 ber_memfree( mo->mo_dn.bv_val );
1990 ber_memfree( mo->mo_ndn.bv_val );
1993 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1994 ber_memfree( mo->mo_groupFilterstr.bv_val );
1997 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1998 ber_memfree( mo->mo_memberFilterstr.bv_val );
2008 static AttributeDescription *ad_memberOf;
2012 AttributeDescription **adp;
2014 { "( 1.2.840.113556.1.2.102 "
2016 "DESC 'Group that the entry belongs to' "
2017 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2018 "EQUALITY distinguishedNameMatch " /* added */
2019 "USAGE dSAOperation " /* added; questioned */
2020 /* "NO-USER-MODIFICATION " */ /* add? */
2021 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2026 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2028 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2030 memberof_initialize( void )
2034 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2035 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2037 Debug( LDAP_DEBUG_ANY,
2038 "memberof_initialize: register_at #%d failed\n",
2044 memberof.on_bi.bi_type = "memberof";
2046 memberof.on_bi.bi_db_init = memberof_db_init;
2047 memberof.on_bi.bi_db_open = memberof_db_open;
2048 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2050 memberof.on_bi.bi_op_add = memberof_op_add;
2051 memberof.on_bi.bi_op_delete = memberof_op_delete;
2052 memberof.on_bi.bi_op_modify = memberof_op_modify;
2054 memberof.on_response = memberof_response;
2056 memberof.on_bi.bi_cf_ocs = mo_ocs;
2058 code = config_register_schema( mo_cfg, mo_ocs );
2059 if ( code ) return code;
2061 return overlay_register( &memberof );
2064 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2066 init_module( int argc, char *argv[] )
2068 return memberof_initialize();
2070 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2072 #endif /* SLAPD_OVER_MEMBEROF */