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 ldap_pvt_thread_pool_setkey( op->o_threadctx, key,
236 saved_vals, memberof_saved_member_free );
240 typedef struct memberof_cookie_t {
241 AttributeDescription *ad;
247 memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
249 if ( rs->sr_type == REP_SEARCH ) {
250 memberof_cookie_t *mc;
252 mc = (memberof_cookie_t *)op->o_callback->sc_private;
260 * callback for internal search that saves the member attribute values
261 * of groups being deleted.
264 memberof_saveMember_cb( Operation *op, SlapReply *rs )
266 if ( rs->sr_type == REP_SEARCH ) {
267 memberof_cookie_t *mc;
269 BerVarray vals = NULL;
271 mc = (memberof_cookie_t *)op->o_callback->sc_private;
274 assert( rs->sr_entry != NULL );
275 assert( rs->sr_entry->e_attrs != NULL );
277 a = attr_find( rs->sr_entry->e_attrs, mc->ad );
282 memberof_saved_member_set( op, mc->key, vals );
284 if ( a && attr_find( a->a_next, mc->ad ) != NULL ) {
285 Debug( LDAP_DEBUG_ANY,
286 "%s: memberof_saveMember_cb(\"%s\"): "
287 "more than one occurrence of \"%s\" "
290 rs->sr_entry->e_name.bv_val,
291 mc->ad->ad_cname.bv_val );
299 * the delete hook performs an internal search that saves the member
300 * attribute values of groups being deleted.
303 memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp )
305 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
306 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
309 SlapReply rs2 = { REP_RESULT };
310 slap_callback cb = { 0 };
311 memberof_cookie_t mc;
312 AttributeName an[ 2 ];
314 memberof_is_t iswhat = MEMBEROF_IS_NONE;
316 assert( iswhatp != NULL );
317 assert( *iswhatp != MEMBEROF_IS_NONE );
320 if ( op->o_tag == LDAP_REQ_DELETE ) {
321 cb.sc_response = memberof_saveMember_cb;
324 cb.sc_response = memberof_isGroupOrMember_cb;
327 op2.o_tag = LDAP_REQ_SEARCH;
328 op2.o_callback = &cb;
329 op2.o_dn = op->o_bd->be_rootdn;
330 op2.o_ndn = op->o_bd->be_rootndn;
332 op2.ors_scope = LDAP_SCOPE_BASE;
333 op2.ors_deref = LDAP_DEREF_NEVER;
334 BER_BVZERO( &an[ 1 ].an_name );
336 op2.ors_attrsonly = 0;
337 op2.ors_limit = NULL;
339 op2.ors_tlimit = SLAP_NO_LIMIT;
341 if ( *iswhatp & MEMBEROF_IS_GROUP ) {
342 mc.ad = mo->mo_ad_member;
343 mc.key = &saved_member_vals;
345 an[ 0 ].an_desc = mo->mo_ad_member;
346 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
347 op2.ors_filterstr = mo->mo_groupFilterstr;
348 op2.ors_filter = &mo->mo_groupFilter;
350 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
351 (void)op->o_bd->be_search( &op2, &rs2 );
352 op2.o_bd->bd_info = (BackendInfo *)on;
355 iswhat |= MEMBEROF_IS_GROUP;
358 memberof_saved_member_set( op, mc.key, NULL );
362 if ( *iswhatp & MEMBEROF_IS_MEMBER ) {
363 mc.ad = mo->mo_ad_memberof;
364 mc.key = &saved_memberof_vals;
366 an[ 0 ].an_desc = mo->mo_ad_memberof;
367 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
368 op2.ors_filterstr = mo->mo_memberFilterstr;
369 op2.ors_filter = &mo->mo_memberFilter;
371 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
372 (void)op->o_bd->be_search( &op2, &rs2 );
373 op2.o_bd->bd_info = (BackendInfo *)on;
376 iswhat |= MEMBEROF_IS_MEMBER;
379 memberof_saved_member_set( op, mc.key, NULL );
389 * response callback that adds memberof values when a group is modified.
392 memberof_value_modify(
396 AttributeDescription *ad,
397 struct berval *old_dn,
398 struct berval *old_ndn,
399 struct berval *new_dn,
400 struct berval *new_ndn )
402 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
403 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
406 SlapReply rs2 = { REP_RESULT };
407 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
408 Modifications mod[ 2 ] = { { { 0 } } }, *ml;
409 struct berval values[ 4 ], nvalues[ 4 ];
412 op2.o_tag = LDAP_REQ_MODIFY;
415 op2.o_req_ndn = *ndn;
417 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
419 op2.o_callback = &cb;
420 op2.o_dn = op->o_bd->be_rootdn;
421 op2.o_ndn = op->o_bd->be_rootndn;
422 op2.orm_modlist = NULL;
424 if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
427 ml->sml_values = &values[ 0 ];
428 ml->sml_values[ 0 ] = mo->mo_dn;
429 BER_BVZERO( &ml->sml_values[ 1 ] );
430 ml->sml_nvalues = &nvalues[ 0 ];
431 ml->sml_nvalues[ 0 ] = mo->mo_ndn;
432 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
433 ml->sml_desc = slap_schema.si_ad_modifiersName;
434 ml->sml_type = ml->sml_desc->ad_cname;
435 ml->sml_op = LDAP_MOD_REPLACE;
436 ml->sml_flags = SLAP_MOD_INTERNAL;
437 ml->sml_next = op2.orm_modlist;
438 op2.orm_modlist = ml;
445 ml->sml_values = &values[ 2 ];
446 BER_BVZERO( &ml->sml_values[ 1 ] );
447 ml->sml_nvalues = &nvalues[ 2 ];
448 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
450 ml->sml_type = ml->sml_desc->ad_cname;
451 ml->sml_flags = SLAP_MOD_INTERNAL;
452 ml->sml_next = op2.orm_modlist;
453 op2.orm_modlist = ml;
455 if ( new_ndn != NULL ) {
456 assert( !BER_BVISNULL( new_dn ) );
457 assert( !BER_BVISNULL( new_ndn ) );
460 ml->sml_op = LDAP_MOD_ADD;
462 ml->sml_values[ 0 ] = *new_dn;
463 ml->sml_nvalues[ 0 ] = *new_ndn;
465 (void)op->o_bd->be_modify( &op2, &rs2 );
466 if ( rs2.sr_err != LDAP_SUCCESS ) {
467 char buf[ SLAP_TEXT_BUFLEN ];
468 snprintf( buf, sizeof( buf ),
469 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
470 ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err, rs2.sr_text );
471 Debug( LDAP_DEBUG_ANY, "%s: %s\n", op->o_log_prefix, buf, 0 );
474 assert( op2.orm_modlist == &mod[ mcnt ] );
475 assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
476 ml = op2.orm_modlist->sml_next;
478 assert( ml == &mod[ 0 ] );
482 slap_mods_free( ml, 1 );
486 if ( old_ndn != NULL ) {
487 assert( !BER_BVISNULL( old_dn ) );
488 assert( !BER_BVISNULL( old_ndn ) );
491 ml->sml_op = LDAP_MOD_DELETE;
493 ml->sml_values[ 0 ] = *old_dn;
494 ml->sml_nvalues[ 0 ] = *old_ndn;
496 (void)op->o_bd->be_modify( &op2, &rs2 );
497 if ( rs2.sr_err != LDAP_SUCCESS ) {
498 char buf[ SLAP_TEXT_BUFLEN ];
499 snprintf( buf, sizeof( buf ),
500 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
501 ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err, rs2.sr_text );
502 Debug( LDAP_DEBUG_ANY, "%s: %s\n", op->o_log_prefix, buf, 0 );
505 assert( op2.orm_modlist == &mod[ mcnt ] );
506 ml = op2.orm_modlist->sml_next;
508 assert( ml == &mod[ 0 ] );
512 slap_mods_free( ml, 1 );
516 /* FIXME: if old_group_ndn doesn't exist, both delete __and__
517 * add will fail; better split in two operations, although
518 * not optimal in terms of performance. At least it would
519 * move towards self-repairing capabilities. */
521 op2.o_bd->bd_info = (BackendInfo *)on;
527 memberof_op_add( Operation *op, SlapReply *rs )
529 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
530 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
532 Attribute **ap, **map = NULL;
533 int rc = SLAP_CB_CONTINUE;
535 struct berval save_dn, save_ndn;
537 if ( op->ora_e->e_attrs == NULL ) {
538 /* FIXME: global overlay; need to deal with */
539 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
540 "consistency checks not implemented when overlay "
541 "is instantiated as global.\n",
542 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
543 return SLAP_CB_CONTINUE;
546 if ( MEMBEROF_REVERSE( mo ) ) {
547 for ( ap = &op->ora_e->e_attrs; *ap; ap = &(*ap)->a_next ) {
550 if ( a->a_desc == mo->mo_ad_memberof ) {
558 save_ndn = op->o_ndn;
560 if ( MEMBEROF_DANGLING_CHECK( mo )
562 && is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) )
564 op->o_dn = op->o_bd->be_rootdn;
565 op->o_dn = op->o_bd->be_rootndn;
566 op->o_bd->bd_info = (BackendInfo *)on->on_info;
568 for ( ap = &op->ora_e->e_attrs; *ap; ) {
571 if ( !is_ad_subtype( a->a_desc, mo->mo_ad_member ) ) {
576 assert( a->a_nvals != NULL );
578 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
581 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
583 if ( rc == LDAP_SUCCESS ) {
584 be_entry_release_r( op, e );
588 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
589 rc = rs->sr_err = mo->mo_dangling_err;
590 rs->sr_text = "adding non-existing object "
592 send_ldap_result( op, rs );
596 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
599 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
600 "member=\"%s\" does not exist (stripping...)\n",
601 op->o_log_prefix, op->ora_e->e_name.bv_val,
602 a->a_vals[ i ].bv_val );
604 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
605 ber_memfree( a->a_vals[ i ].bv_val );
606 BER_BVZERO( &a->a_vals[ i ] );
607 if ( a->a_nvals != a->a_vals ) {
608 ber_memfree( a->a_nvals[ i ].bv_val );
609 BER_BVZERO( &a->a_nvals[ i ] );
615 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
616 sizeof( struct berval ) * ( j - i ) );
617 if ( a->a_nvals != a->a_vals ) {
618 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
619 sizeof( struct berval ) * ( j - i ) );
625 /* If all values have been removed,
626 * remove the attribute itself. */
627 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
636 op->o_ndn = save_ndn;
637 op->o_bd->bd_info = (BackendInfo *)on;
642 AccessControlState acl_state = ACL_STATE_INIT;
644 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
647 op->o_bd->bd_info = (BackendInfo *)on->on_info;
648 /* access is checked with the original identity */
649 rc = access_allowed( op, op->ora_e, mo->mo_ad_memberof,
650 &a->a_nvals[ i ], ACL_WADD,
653 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
655 send_ldap_result( op, rs );
658 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
660 op->o_bd->bd_info = (BackendInfo *)on;
661 if ( rc != LDAP_SUCCESS ) {
662 if ( get_relax( op ) ) {
666 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
667 rc = rs->sr_err = mo->mo_dangling_err;
668 rs->sr_text = "adding non-existing object "
670 send_ldap_result( op, rs );
674 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
677 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
678 "memberof=\"%s\" does not exist (stripping...)\n",
679 op->o_log_prefix, op->ora_e->e_name.bv_val,
680 a->a_nvals[ i ].bv_val );
682 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
683 ber_memfree( a->a_vals[ i ].bv_val );
684 BER_BVZERO( &a->a_vals[ i ] );
685 if ( a->a_nvals != a->a_vals ) {
686 ber_memfree( a->a_nvals[ i ].bv_val );
687 BER_BVZERO( &a->a_nvals[ i ] );
693 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
694 sizeof( struct berval ) * ( j - i ) );
695 if ( a->a_nvals != a->a_vals ) {
696 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
697 sizeof( struct berval ) * ( j - i ) );
705 /* access is checked with the original identity */
706 op->o_bd->bd_info = (BackendInfo *)on->on_info;
707 rc = access_allowed( op, e, mo->mo_ad_member,
708 &op->o_req_ndn, ACL_WADD, NULL );
709 be_entry_release_r( op, e );
710 op->o_bd->bd_info = (BackendInfo *)on;
713 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
714 rs->sr_text = "insufficient access to object referenced by memberof";
715 send_ldap_result( op, rs );
720 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
726 rc = SLAP_CB_CONTINUE;
730 op->o_ndn = save_ndn;
731 op->o_bd->bd_info = (BackendInfo *)on;
737 memberof_op_delete( Operation *op, SlapReply *rs )
739 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
740 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
742 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
744 if ( MEMBEROF_REFINT( mo ) ) {
745 iswhat = MEMBEROF_IS_BOTH;
748 memberof_isGroupOrMember( op, &iswhat );
750 return SLAP_CB_CONTINUE;
754 memberof_op_modify( Operation *op, SlapReply *rs )
756 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
757 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
759 Modifications **mlp, **mmlp = NULL;
760 int rc = SLAP_CB_CONTINUE;
761 struct berval save_dn, save_ndn;
762 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
764 if ( MEMBEROF_REVERSE( mo ) ) {
765 for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
766 Modifications *ml = *mlp;
768 if ( ml->sml_desc == mo->mo_ad_memberof ) {
776 save_ndn = op->o_ndn;
778 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
779 && ( iswhat & MEMBEROF_IS_GROUP ) )
784 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
785 if ( ml->sml_desc == mo->mo_ad_member ) {
786 switch ( ml->sml_op ) {
787 case LDAP_MOD_DELETE:
788 case LDAP_MOD_REPLACE:
796 BerVarray vals = NULL;
798 op->o_dn = op->o_bd->be_rootdn;
799 op->o_dn = op->o_bd->be_rootndn;
800 op->o_bd->bd_info = (BackendInfo *)on->on_info;
801 rc = backend_attribute( op, NULL, &op->o_req_ndn,
802 mo->mo_ad_member, &vals, ACL_READ );
803 op->o_bd->bd_info = (BackendInfo *)on;
804 if ( rc == LDAP_SUCCESS && vals != NULL ) {
805 memberof_saved_member_set( op, &saved_member_vals, vals );
806 ber_bvarray_free_x( vals, op->o_tmpmemctx );
810 if ( MEMBEROF_DANGLING_CHECK( mo )
811 && !get_relax( op ) )
813 op->o_dn = op->o_bd->be_rootdn;
814 op->o_dn = op->o_bd->be_rootndn;
815 op->o_bd->bd_info = (BackendInfo *)on->on_info;
817 assert( op->orm_modlist != NULL );
819 for ( mlp = &op->orm_modlist; *mlp; ) {
820 Modifications *ml = *mlp;
823 if ( !is_ad_subtype( ml->sml_desc, mo->mo_ad_member ) ) {
828 switch ( ml->sml_op ) {
829 case LDAP_MOD_DELETE:
830 /* we don't care about cancellations: if the value
831 * exists, fine; if it doesn't, we let the underlying
832 * database fail as appropriate; */
836 case LDAP_MOD_REPLACE:
838 /* NOTE: right now, the attributeType we use
839 * for member must have a normalized value */
840 assert( ml->sml_nvalues != NULL );
842 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
846 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
847 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
849 be_entry_release_r( op, e );
853 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
854 rc = rs->sr_err = mo->mo_dangling_err;
855 rs->sr_text = "adding non-existing object "
857 send_ldap_result( op, rs );
861 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
864 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
865 "member=\"%s\" does not exist (stripping...)\n",
866 op->o_log_prefix, op->o_req_dn.bv_val,
867 ml->sml_nvalues[ i ].bv_val );
869 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
870 ber_memfree( ml->sml_values[ i ].bv_val );
871 BER_BVZERO( &ml->sml_values[ i ] );
872 ber_memfree( ml->sml_nvalues[ i ].bv_val );
873 BER_BVZERO( &ml->sml_nvalues[ i ] );
879 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
880 sizeof( struct berval ) * ( j - i ) );
881 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
882 sizeof( struct berval ) * ( j - i ) );
887 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
889 slap_mod_free( &ml->sml_mod, 0 );
905 if ( mmlp != NULL ) {
906 Modifications *ml = *mmlp;
910 op->o_bd->bd_info = (BackendInfo *)on->on_info;
911 rc = be_entry_get_rw( op, &op->o_req_ndn,
912 NULL, NULL, 0, &target );
913 op->o_bd->bd_info = (BackendInfo *)on;
914 if ( rc != LDAP_SUCCESS ) {
915 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
916 send_ldap_result( op, rs );
920 switch ( ml->sml_op ) {
921 case LDAP_MOD_DELETE:
922 if ( ml->sml_nvalues != NULL ) {
923 AccessControlState acl_state = ACL_STATE_INIT;
925 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
928 op->o_bd->bd_info = (BackendInfo *)on->on_info;
929 /* access is checked with the original identity */
930 rc = access_allowed( op, target,
932 &ml->sml_nvalues[ i ],
936 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
938 send_ldap_result( op, rs );
942 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
944 op->o_bd->bd_info = (BackendInfo *)on;
945 if ( rc != LDAP_SUCCESS ) {
946 if ( get_relax( op ) ) {
950 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
951 rc = rs->sr_err = mo->mo_dangling_err;
952 rs->sr_text = "deleting non-existing object "
954 send_ldap_result( op, rs );
958 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
961 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
962 "memberof=\"%s\" does not exist (stripping...)\n",
963 op->o_log_prefix, op->o_req_ndn.bv_val,
964 ml->sml_nvalues[ i ].bv_val );
966 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
967 ber_memfree( ml->sml_values[ i ].bv_val );
968 BER_BVZERO( &ml->sml_values[ i ] );
969 if ( ml->sml_nvalues != ml->sml_values ) {
970 ber_memfree( ml->sml_nvalues[ i ].bv_val );
971 BER_BVZERO( &ml->sml_nvalues[ i ] );
978 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
979 sizeof( struct berval ) * ( j - i ) );
980 if ( ml->sml_nvalues != ml->sml_values ) {
981 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
982 sizeof( struct berval ) * ( j - i ) );
990 /* access is checked with the original identity */
991 op->o_bd->bd_info = (BackendInfo *)on->on_info;
992 rc = access_allowed( op, e, mo->mo_ad_member,
995 be_entry_release_r( op, e );
996 op->o_bd->bd_info = (BackendInfo *)on;
999 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1000 rs->sr_text = "insufficient access to object referenced by memberof";
1001 send_ldap_result( op, rs );
1006 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1007 *mmlp = ml->sml_next;
1008 slap_mod_free( &ml->sml_mod, 0 );
1016 case LDAP_MOD_REPLACE:
1018 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1019 /* access is checked with the original identity */
1020 rc = access_allowed( op, target,
1024 op->o_bd->bd_info = (BackendInfo *)on;
1026 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1028 send_ldap_result( op, rs );
1032 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1037 case LDAP_MOD_ADD: {
1038 AccessControlState acl_state = ACL_STATE_INIT;
1040 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1043 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1044 /* access is checked with the original identity */
1045 rc = access_allowed( op, target,
1047 &ml->sml_nvalues[ i ],
1051 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1053 send_ldap_result( op, rs );
1057 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1058 NULL, NULL, 0, &e );
1059 op->o_bd->bd_info = (BackendInfo *)on;
1060 if ( rc != LDAP_SUCCESS ) {
1061 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1062 rc = rs->sr_err = mo->mo_dangling_err;
1063 rs->sr_text = "adding non-existing object "
1065 send_ldap_result( op, rs );
1069 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1072 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1073 "memberof=\"%s\" does not exist (stripping...)\n",
1074 op->o_log_prefix, op->o_req_ndn.bv_val,
1075 ml->sml_nvalues[ i ].bv_val );
1077 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1078 ber_memfree( ml->sml_values[ i ].bv_val );
1079 BER_BVZERO( &ml->sml_values[ i ] );
1080 if ( ml->sml_nvalues != ml->sml_values ) {
1081 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1082 BER_BVZERO( &ml->sml_nvalues[ i ] );
1089 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1090 sizeof( struct berval ) * ( j - i ) );
1091 if ( ml->sml_nvalues != ml->sml_values ) {
1092 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1093 sizeof( struct berval ) * ( j - i ) );
1101 /* access is checked with the original identity */
1102 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1103 rc = access_allowed( op, e, mo->mo_ad_member,
1106 be_entry_release_r( op, e );
1107 op->o_bd->bd_info = (BackendInfo *)on;
1110 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1111 rs->sr_text = "insufficient access to object referenced by memberof";
1112 send_ldap_result( op, rs );
1117 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1118 *mmlp = ml->sml_next;
1119 slap_mod_free( &ml->sml_mod, 0 );
1130 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1131 be_entry_release_r( op, target );
1132 op->o_bd->bd_info = (BackendInfo *)on;
1135 rc = SLAP_CB_CONTINUE;
1139 op->o_ndn = save_ndn;
1140 op->o_bd->bd_info = (BackendInfo *)on;
1146 * response callback that adds memberof values when a group is added.
1149 memberof_res_add( Operation *op, SlapReply *rs )
1151 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1152 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1156 if ( MEMBEROF_REVERSE( mo ) ) {
1159 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1161 Operation op2 = *op;
1162 SlapReply rs2 = { 0 };
1164 /* relax is required to allow to add
1165 * a non-existing member */
1166 op2.o_relax = SLAP_CONTROL_CRITICAL;
1168 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1170 /* the modification is attempted
1171 * with the original identity */
1172 (void)memberof_value_modify( &op2, &rs2,
1173 &ma->a_nvals[ i ], mo->mo_ad_member,
1174 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1179 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1182 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1184 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1186 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1187 (void)memberof_value_modify( op, rs,
1197 return SLAP_CB_CONTINUE;
1201 * response callback that deletes memberof values when a group is deleted.
1204 memberof_res_delete( Operation *op, SlapReply *rs )
1206 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1207 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1212 vals = memberof_saved_member_get( op, &saved_member_vals );
1213 if ( vals != NULL ) {
1214 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1215 (void)memberof_value_modify( op, rs,
1216 &vals[ i ], mo->mo_ad_memberof,
1217 &op->o_req_dn, &op->o_req_ndn,
1221 ber_bvarray_free( vals );
1224 if ( MEMBEROF_REFINT( mo ) ) {
1225 vals = memberof_saved_member_get( op, &saved_memberof_vals );
1226 if ( vals != NULL ) {
1227 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1228 (void)memberof_value_modify( op, rs,
1229 &vals[ i ], mo->mo_ad_member,
1230 &op->o_req_dn, &op->o_req_ndn,
1234 ber_bvarray_free( vals );
1238 return SLAP_CB_CONTINUE;
1242 * response callback that adds/deletes memberof values when a group
1246 memberof_res_modify( Operation *op, SlapReply *rs )
1248 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1249 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1252 Modifications *ml, *mml = NULL;
1254 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1256 if ( MEMBEROF_REVERSE( mo ) ) {
1257 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1258 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1265 if ( mml != NULL ) {
1266 BerVarray vals = mml->sml_nvalues;
1268 switch ( mml->sml_op ) {
1269 case LDAP_MOD_DELETE:
1270 if ( vals != NULL ) {
1271 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1272 memberof_value_modify( op, rs,
1273 &vals[ i ], mo->mo_ad_member,
1274 &op->o_req_dn, &op->o_req_ndn,
1281 case LDAP_MOD_REPLACE:
1282 /* delete all ... */
1283 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1284 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1285 mo->mo_ad_memberof, &vals, ACL_READ );
1286 op->o_bd->bd_info = (BackendInfo *)on;
1287 if ( rc == LDAP_SUCCESS ) {
1288 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1289 (void)memberof_value_modify( op, rs,
1290 &vals[ i ], mo->mo_ad_member,
1291 &op->o_req_dn, &op->o_req_ndn,
1294 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1297 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1303 assert( vals != NULL );
1305 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1306 memberof_value_modify( op, rs,
1307 &vals[ i ], mo->mo_ad_member,
1309 &op->o_req_dn, &op->o_req_ndn );
1318 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
1319 && ( iswhat & MEMBEROF_IS_GROUP ) )
1321 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1322 if ( ml->sml_desc != mo->mo_ad_member ) {
1326 switch ( ml->sml_op ) {
1327 case LDAP_MOD_DELETE:
1328 vals = ml->sml_nvalues;
1329 if ( vals != NULL ) {
1330 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1331 memberof_value_modify( op, rs,
1332 &vals[ i ], mo->mo_ad_memberof,
1333 &op->o_req_dn, &op->o_req_ndn,
1340 case LDAP_MOD_REPLACE:
1341 vals = memberof_saved_member_get( op, &saved_member_vals );
1343 /* delete all ... */
1344 if ( vals != NULL ) {
1345 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1346 (void)memberof_value_modify( op, rs,
1347 &vals[ i ], mo->mo_ad_memberof,
1348 &op->o_req_dn, &op->o_req_ndn,
1351 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1354 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1360 assert( ml->sml_nvalues != NULL );
1361 vals = ml->sml_nvalues;
1362 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1363 memberof_value_modify( op, rs,
1364 &vals[ i ], mo->mo_ad_memberof,
1366 &op->o_req_dn, &op->o_req_ndn );
1376 return SLAP_CB_CONTINUE;
1380 * response callback that adds/deletes member values when a group member
1384 memberof_res_rename( Operation *op, SlapReply *rs )
1386 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1387 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1389 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1393 struct berval save_dn, save_ndn;
1394 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1396 if ( MEMBEROF_REFINT( mo ) ) {
1397 iswhat |= MEMBEROF_IS_MEMBER;
1400 if ( op->orr_nnewSup ) {
1401 newPNDN = *op->orr_nnewSup;
1404 dnParent( &op->o_req_ndn, &newPNDN );
1407 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1409 save_dn = op->o_req_dn;
1410 save_ndn = op->o_req_ndn;
1412 op->o_req_dn = newNDN;
1413 op->o_req_ndn = newNDN;
1414 rc = memberof_isGroupOrMember( op, &iswhat );
1415 op->o_req_dn = save_dn;
1416 op->o_req_ndn = save_ndn;
1418 if ( rc != LDAP_SUCCESS || iswhat == MEMBEROF_IS_NONE ) {
1422 if ( op->orr_newSup ) {
1423 newPDN = *op->orr_newSup;
1426 dnParent( &op->o_req_dn, &newPDN );
1429 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1431 if ( iswhat & MEMBEROF_IS_GROUP ) {
1432 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1433 rc = backend_attribute( op, NULL, &newNDN,
1434 mo->mo_ad_member, &vals, ACL_READ );
1435 op->o_bd->bd_info = (BackendInfo *)on;
1437 if ( rc == LDAP_SUCCESS ) {
1438 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1439 (void)memberof_value_modify( op, rs,
1440 &vals[ i ], mo->mo_ad_memberof,
1441 &op->o_req_dn, &op->o_req_ndn,
1444 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1448 if ( MEMBEROF_REFINT( mo ) && ( iswhat & MEMBEROF_IS_MEMBER ) ) {
1449 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1450 rc = backend_attribute( op, NULL, &newNDN,
1451 mo->mo_ad_memberof, &vals, ACL_READ );
1452 op->o_bd->bd_info = (BackendInfo *)on;
1454 if ( rc == LDAP_SUCCESS ) {
1455 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1456 (void)memberof_value_modify( op, rs,
1457 &vals[ i ], mo->mo_ad_member,
1458 &op->o_req_dn, &op->o_req_ndn,
1461 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1466 if ( !BER_BVISNULL( &newDN ) ) {
1467 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1469 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1471 return SLAP_CB_CONTINUE;
1475 memberof_response( Operation *op, SlapReply *rs )
1477 if ( rs->sr_err != LDAP_SUCCESS ) {
1478 return SLAP_CB_CONTINUE;
1481 switch ( op->o_tag ) {
1483 return memberof_res_add( op, rs );
1485 case LDAP_REQ_DELETE:
1486 return memberof_res_delete( op, rs );
1488 case LDAP_REQ_MODIFY:
1489 return memberof_res_modify( op, rs );
1491 case LDAP_REQ_MODDN:
1492 return memberof_res_rename( op, rs );
1495 return SLAP_CB_CONTINUE;
1504 slap_overinst *on = (slap_overinst *)be->bd_info;
1505 memberof_t tmp_mo = { 0 }, *mo;
1507 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1510 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1512 on->on_bi.bi_private = (void *)mo;
1533 static ConfigDriver mo_cf_gen;
1535 #define OID "1.3.6.1.4.1.7136.2.666.4"
1536 #define OIDAT OID ".1.1"
1537 #define OIDCFGAT OID ".1.2"
1538 #define OIDOC OID ".2.1"
1539 #define OIDCFGOC OID ".2.2"
1542 static ConfigTable mo_cfg[] = {
1543 { "memberof-dn", "modifiersName",
1544 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1545 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1546 "DESC 'DN to be used as modifiersName' "
1547 "SYNTAX OMsDN SINGLE-VALUE )",
1550 { "memberof-dangling", "ignore|drop|error",
1551 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1552 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1553 "DESC 'Behavior with respect to dangling members, "
1554 "constrained to ignore, drop, error' "
1555 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1558 { "memberof-refint", "true|FALSE",
1559 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1560 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1561 "DESC 'Take care of referential integrity' "
1562 "SYNTAX OMsBoolean SINGLE-VALUE )",
1565 { "memberof-group-oc", "objectClass",
1566 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1567 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1568 "DESC 'Group objectClass' "
1569 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1572 { "memberof-member-ad", "member attribute",
1573 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1574 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1575 "DESC 'member attribute' "
1576 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1579 { "memberof-memberof-ad", "memberOf attribute",
1580 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1581 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1582 "DESC 'memberOf attribute' "
1583 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1587 { "memberof-reverse", "true|FALSE",
1588 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1589 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1590 "DESC 'Take care of referential integrity "
1591 "also when directly modifying memberOf' "
1592 "SYNTAX OMsBoolean SINGLE-VALUE )",
1596 { "memberof-dangling-error", "error code",
1597 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1598 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1599 "DESC 'Error code returned in case of dangling back reference' "
1600 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1603 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1606 static ConfigOCs mo_ocs[] = {
1607 { "( OLcfgOvOc:18.1 "
1608 "NAME 'olcMemberOf' "
1609 "DESC 'Member-of configuration' "
1610 "SUP olcOverlayConfig "
1613 "$ olcMemberOfDangling "
1614 "$ olcMemberOfDanglingError"
1615 "$ olcMemberOfRefInt "
1616 "$ olcMemberOfGroupOC "
1617 "$ olcMemberOfMemberAD "
1618 "$ olcMemberOfMemberOfAD "
1620 "$ olcMemberOfReverse "
1624 Cft_Overlay, mo_cfg, NULL, NULL },
1628 static slap_verbmasks dangling_mode[] = {
1629 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1630 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1631 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1636 memberof_make_group_filter( memberof_t *mo )
1640 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1641 ch_free( mo->mo_groupFilterstr.bv_val );
1644 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1645 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1647 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1648 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1650 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1651 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1652 + mo->mo_oc_group->soc_cname.bv_len;
1653 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1655 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1657 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1665 memberof_make_member_filter( memberof_t *mo )
1669 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1670 ch_free( mo->mo_memberFilterstr.bv_val );
1673 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1674 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1676 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1677 + mo->mo_ad_memberof->ad_cname.bv_len;
1678 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1680 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1681 ptr = lutil_strcopy( ptr, "=*)" );
1687 mo_cf_gen( ConfigArgs *c )
1689 slap_overinst *on = (slap_overinst *)c->bi;
1690 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1694 if ( c->op == SLAP_CONFIG_EMIT ) {
1695 struct berval bv = BER_BVNULL;
1699 if ( mo->mo_dn.bv_val != NULL) {
1700 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1701 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1706 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1707 if ( BER_BVISNULL( &bv ) ) {
1708 /* there's something wrong... */
1713 value_add_one( &c->rvalue_vals, &bv );
1717 case MO_DANGLING_ERROR:
1718 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1719 char buf[ SLAP_TEXT_BUFLEN ];
1720 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1721 if ( BER_BVISNULL( &bv ) ) {
1722 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1723 if ( bv.bv_len < sizeof( buf ) ) {
1730 value_add_one( &c->rvalue_vals, &bv );
1737 c->value_int = MEMBEROF_REFINT( mo );
1742 c->value_int = MEMBEROF_REVERSE( mo );
1747 if ( mo->mo_oc_group != NULL ){
1748 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1753 if ( mo->mo_ad_member != NULL ){
1754 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1758 case MO_MEMBER_OF_AD:
1759 if ( mo->mo_ad_memberof != NULL ){
1760 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1771 } else if ( c->op == LDAP_MOD_DELETE ) {
1772 return 1; /* FIXME */
1777 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1778 ber_memfree( mo->mo_dn.bv_val );
1779 ber_memfree( mo->mo_ndn.bv_val );
1781 mo->mo_dn = c->value_dn;
1782 mo->mo_ndn = c->value_ndn;
1786 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1787 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1791 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1792 mo->mo_flags |= dangling_mode[ i ].mask;
1795 case MO_DANGLING_ERROR:
1796 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1797 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1798 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1799 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1805 if ( c->value_int ) {
1806 mo->mo_flags |= MEMBEROF_FREFINT;
1809 mo->mo_flags &= ~MEMBEROF_FREFINT;
1815 if ( c->value_int ) {
1816 mo->mo_flags |= MEMBEROF_FREVERSE;
1819 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1825 ObjectClass *oc = NULL;
1827 oc = oc_find( c->argv[ 1 ] );
1829 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1830 "unable to find group objectClass=\"%s\"",
1832 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1833 c->log, c->cr_msg, 0 );
1837 mo->mo_oc_group = oc;
1838 memberof_make_group_filter( mo );
1841 case MO_MEMBER_AD: {
1842 AttributeDescription *ad = NULL;
1843 const char *text = NULL;
1846 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1847 if ( rc != LDAP_SUCCESS ) {
1848 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1849 "unable to find member attribute=\"%s\": %s (%d)",
1850 c->argv[ 1 ], text, rc );
1851 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1852 c->log, c->cr_msg, 0 );
1856 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1857 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1859 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1860 "member attribute=\"%s\" must either "
1861 "have DN (%s) or nameUID (%s) syntax",
1862 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1863 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1864 c->log, c->cr_msg, 0 );
1868 mo->mo_ad_member = ad;
1871 case MO_MEMBER_OF_AD: {
1872 AttributeDescription *ad = NULL;
1873 const char *text = NULL;
1876 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1877 if ( rc != LDAP_SUCCESS ) {
1878 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1879 "unable to find memberof attribute=\"%s\": %s (%d)",
1880 c->argv[ 1 ], text, rc );
1881 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1882 c->log, c->cr_msg, 0 );
1886 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1887 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1889 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1890 "memberof attribute=\"%s\" must either "
1891 "have DN (%s) or nameUID (%s) syntax",
1892 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1893 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1894 c->log, c->cr_msg, 0 );
1898 mo->mo_ad_memberof = ad;
1899 memberof_make_member_filter( mo );
1916 slap_overinst *on = (slap_overinst *)be->bd_info;
1917 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1920 const char *text = NULL;
1922 if( ! mo->mo_ad_memberof ){
1923 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
1924 if ( rc != LDAP_SUCCESS ) {
1925 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1926 "unable to find attribute=\"%s\": %s (%d)\n",
1927 SLAPD_MEMBEROF_ATTR, text, rc );
1932 if( ! mo->mo_ad_member ){
1933 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &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_GROUP_ATTR, text, rc );
1942 if( ! mo->mo_oc_group ){
1943 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
1944 if ( mo->mo_oc_group == NULL ) {
1945 Debug( LDAP_DEBUG_ANY,
1946 "memberof_db_open: "
1947 "unable to find objectClass=\"%s\"\n",
1948 SLAPD_GROUP_CLASS, 0, 0 );
1953 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
1954 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
1955 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
1958 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1959 memberof_make_group_filter( mo );
1962 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1963 memberof_make_member_filter( mo );
1970 memberof_db_destroy(
1974 slap_overinst *on = (slap_overinst *)be->bd_info;
1975 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1978 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1979 ber_memfree( mo->mo_dn.bv_val );
1980 ber_memfree( mo->mo_ndn.bv_val );
1983 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1984 ber_memfree( mo->mo_groupFilterstr.bv_val );
1987 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1988 ber_memfree( mo->mo_memberFilterstr.bv_val );
1998 static AttributeDescription *ad_memberOf;
2002 AttributeDescription **adp;
2004 { "( 1.2.840.113556.1.2.102 "
2006 "DESC 'Group that the entry belongs to' "
2007 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2008 "EQUALITY distinguishedNameMatch " /* added */
2009 "USAGE dSAOperation " /* added; questioned */
2010 /* "NO-USER-MODIFICATION " */ /* add? */
2011 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2016 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2018 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2020 memberof_initialize( void )
2024 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2025 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2027 Debug( LDAP_DEBUG_ANY,
2028 "memberof_initialize: register_at #%d failed\n",
2034 memberof.on_bi.bi_type = "memberof";
2036 memberof.on_bi.bi_db_init = memberof_db_init;
2037 memberof.on_bi.bi_db_open = memberof_db_open;
2038 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2040 memberof.on_bi.bi_op_add = memberof_op_add;
2041 memberof.on_bi.bi_op_delete = memberof_op_delete;
2042 memberof.on_bi.bi_op_modify = memberof_op_modify;
2044 memberof.on_response = memberof_response;
2046 memberof.on_bi.bi_cf_ocs = mo_ocs;
2048 code = config_register_schema( mo_cfg, mo_ocs );
2049 if ( code ) return code;
2051 return overlay_register( &memberof );
2054 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2056 init_module( int argc, char *argv[] )
2058 return memberof_initialize();
2060 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2062 #endif /* SLAPD_OVER_MEMBEROF */