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_ndn = 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_ndn = 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_ndn = 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:
846 /* Handle this just like a delete (see above) */
847 if ( !ml->sml_values ) {
853 /* NOTE: right now, the attributeType we use
854 * for member must have a normalized value */
855 assert( ml->sml_nvalues != NULL );
857 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
861 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
862 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
864 be_entry_release_r( op, e );
868 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
869 rc = rs->sr_err = mo->mo_dangling_err;
870 rs->sr_text = "adding non-existing object "
872 send_ldap_result( op, rs );
876 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
879 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
880 "member=\"%s\" does not exist (stripping...)\n",
881 op->o_log_prefix, op->o_req_dn.bv_val,
882 ml->sml_nvalues[ i ].bv_val );
884 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
885 ber_memfree( ml->sml_values[ i ].bv_val );
886 BER_BVZERO( &ml->sml_values[ i ] );
887 ber_memfree( ml->sml_nvalues[ i ].bv_val );
888 BER_BVZERO( &ml->sml_nvalues[ i ] );
894 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
895 sizeof( struct berval ) * ( j - i ) );
896 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
897 sizeof( struct berval ) * ( j - i ) );
902 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
904 slap_mod_free( &ml->sml_mod, 0 );
920 if ( mmlp != NULL ) {
921 Modifications *ml = *mmlp;
925 op->o_bd->bd_info = (BackendInfo *)on->on_info;
926 rc = be_entry_get_rw( op, &op->o_req_ndn,
927 NULL, NULL, 0, &target );
928 op->o_bd->bd_info = (BackendInfo *)on;
929 if ( rc != LDAP_SUCCESS ) {
930 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
931 send_ldap_result( op, rs );
935 switch ( ml->sml_op ) {
936 case LDAP_MOD_DELETE:
937 if ( ml->sml_nvalues != NULL ) {
938 AccessControlState acl_state = ACL_STATE_INIT;
940 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
943 op->o_bd->bd_info = (BackendInfo *)on->on_info;
944 /* access is checked with the original identity */
945 rc = access_allowed( op, target,
947 &ml->sml_nvalues[ i ],
951 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
953 send_ldap_result( op, rs );
957 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
959 op->o_bd->bd_info = (BackendInfo *)on;
960 if ( rc != LDAP_SUCCESS ) {
961 if ( get_relax( op ) ) {
965 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
966 rc = rs->sr_err = mo->mo_dangling_err;
967 rs->sr_text = "deleting non-existing object "
969 send_ldap_result( op, rs );
973 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
976 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
977 "memberof=\"%s\" does not exist (stripping...)\n",
978 op->o_log_prefix, op->o_req_ndn.bv_val,
979 ml->sml_nvalues[ i ].bv_val );
981 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
982 ber_memfree( ml->sml_values[ i ].bv_val );
983 BER_BVZERO( &ml->sml_values[ i ] );
984 if ( ml->sml_nvalues != ml->sml_values ) {
985 ber_memfree( ml->sml_nvalues[ i ].bv_val );
986 BER_BVZERO( &ml->sml_nvalues[ i ] );
993 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
994 sizeof( struct berval ) * ( j - i ) );
995 if ( ml->sml_nvalues != ml->sml_values ) {
996 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
997 sizeof( struct berval ) * ( j - i ) );
1005 /* access is checked with the original identity */
1006 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1007 rc = access_allowed( op, e, mo->mo_ad_member,
1010 be_entry_release_r( op, e );
1011 op->o_bd->bd_info = (BackendInfo *)on;
1014 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1015 rs->sr_text = "insufficient access to object referenced by memberof";
1016 send_ldap_result( op, rs );
1021 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1022 *mmlp = ml->sml_next;
1023 slap_mod_free( &ml->sml_mod, 0 );
1031 case LDAP_MOD_REPLACE:
1033 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1034 /* access is checked with the original identity */
1035 rc = access_allowed( op, target,
1039 op->o_bd->bd_info = (BackendInfo *)on;
1041 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1043 send_ldap_result( op, rs );
1047 if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
1052 case LDAP_MOD_ADD: {
1053 AccessControlState acl_state = ACL_STATE_INIT;
1055 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1058 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1059 /* access is checked with the original identity */
1060 rc = access_allowed( op, target,
1062 &ml->sml_nvalues[ i ],
1066 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1068 send_ldap_result( op, rs );
1072 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1073 NULL, NULL, 0, &e );
1074 op->o_bd->bd_info = (BackendInfo *)on;
1075 if ( rc != LDAP_SUCCESS ) {
1076 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1077 rc = rs->sr_err = mo->mo_dangling_err;
1078 rs->sr_text = "adding non-existing object "
1080 send_ldap_result( op, rs );
1084 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1087 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1088 "memberof=\"%s\" does not exist (stripping...)\n",
1089 op->o_log_prefix, op->o_req_ndn.bv_val,
1090 ml->sml_nvalues[ i ].bv_val );
1092 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1093 ber_memfree( ml->sml_values[ i ].bv_val );
1094 BER_BVZERO( &ml->sml_values[ i ] );
1095 if ( ml->sml_nvalues != ml->sml_values ) {
1096 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1097 BER_BVZERO( &ml->sml_nvalues[ i ] );
1104 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1105 sizeof( struct berval ) * ( j - i ) );
1106 if ( ml->sml_nvalues != ml->sml_values ) {
1107 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1108 sizeof( struct berval ) * ( j - i ) );
1116 /* access is checked with the original identity */
1117 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1118 rc = access_allowed( op, e, mo->mo_ad_member,
1121 be_entry_release_r( op, e );
1122 op->o_bd->bd_info = (BackendInfo *)on;
1125 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1126 rs->sr_text = "insufficient access to object referenced by memberof";
1127 send_ldap_result( op, rs );
1132 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1133 *mmlp = ml->sml_next;
1134 slap_mod_free( &ml->sml_mod, 0 );
1145 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1146 be_entry_release_r( op, target );
1147 op->o_bd->bd_info = (BackendInfo *)on;
1150 rc = SLAP_CB_CONTINUE;
1154 op->o_ndn = save_ndn;
1155 op->o_bd->bd_info = (BackendInfo *)on;
1161 * response callback that adds memberof values when a group is added.
1164 memberof_res_add( Operation *op, SlapReply *rs )
1166 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1167 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1171 if ( MEMBEROF_REVERSE( mo ) ) {
1174 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1176 Operation op2 = *op;
1177 SlapReply rs2 = { 0 };
1179 /* relax is required to allow to add
1180 * a non-existing member */
1181 op2.o_relax = SLAP_CONTROL_CRITICAL;
1183 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1185 /* the modification is attempted
1186 * with the original identity */
1187 (void)memberof_value_modify( &op2, &rs2,
1188 &ma->a_nvals[ i ], mo->mo_ad_member,
1189 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1194 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1197 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1199 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1201 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1202 (void)memberof_value_modify( op, rs,
1212 return SLAP_CB_CONTINUE;
1216 * response callback that deletes memberof values when a group is deleted.
1219 memberof_res_delete( Operation *op, SlapReply *rs )
1221 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1222 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1227 vals = memberof_saved_member_get( op, &saved_member_vals );
1228 if ( vals != NULL ) {
1229 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1230 (void)memberof_value_modify( op, rs,
1231 &vals[ i ], mo->mo_ad_memberof,
1232 &op->o_req_dn, &op->o_req_ndn,
1236 memberof_saved_member_set( op, &saved_memberof_vals, NULL );
1237 ber_bvarray_free( vals );
1240 if ( MEMBEROF_REFINT( mo ) ) {
1241 vals = memberof_saved_member_get( op, &saved_memberof_vals );
1242 if ( vals != NULL ) {
1243 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1244 (void)memberof_value_modify( op, rs,
1245 &vals[ i ], mo->mo_ad_member,
1246 &op->o_req_dn, &op->o_req_ndn,
1250 memberof_saved_member_set( op, &saved_member_vals, NULL );
1251 ber_bvarray_free( vals );
1255 return SLAP_CB_CONTINUE;
1259 * response callback that adds/deletes memberof values when a group
1263 memberof_res_modify( Operation *op, SlapReply *rs )
1265 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1266 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1269 Modifications *ml, *mml = NULL;
1271 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1273 if ( MEMBEROF_REVERSE( mo ) ) {
1274 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1275 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1282 if ( mml != NULL ) {
1283 BerVarray vals = mml->sml_nvalues;
1285 switch ( mml->sml_op ) {
1286 case LDAP_MOD_DELETE:
1287 if ( vals != NULL ) {
1288 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1289 memberof_value_modify( op, rs,
1290 &vals[ i ], mo->mo_ad_member,
1291 &op->o_req_dn, &op->o_req_ndn,
1298 case LDAP_MOD_REPLACE:
1299 /* delete all ... */
1300 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1301 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1302 mo->mo_ad_memberof, &vals, ACL_READ );
1303 op->o_bd->bd_info = (BackendInfo *)on;
1304 if ( rc == LDAP_SUCCESS ) {
1305 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1306 (void)memberof_value_modify( op, rs,
1307 &vals[ i ], mo->mo_ad_member,
1308 &op->o_req_dn, &op->o_req_ndn,
1311 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1314 if ( ml->sml_op == LDAP_MOD_DELETE || !mml->sml_values ) {
1320 assert( vals != NULL );
1322 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1323 memberof_value_modify( op, rs,
1324 &vals[ i ], mo->mo_ad_member,
1326 &op->o_req_dn, &op->o_req_ndn );
1335 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
1336 && ( iswhat & MEMBEROF_IS_GROUP ) )
1338 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1339 if ( ml->sml_desc != mo->mo_ad_member ) {
1343 switch ( ml->sml_op ) {
1344 case LDAP_MOD_DELETE:
1345 vals = ml->sml_nvalues;
1346 if ( vals != NULL ) {
1347 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1348 memberof_value_modify( op, rs,
1349 &vals[ i ], mo->mo_ad_memberof,
1350 &op->o_req_dn, &op->o_req_ndn,
1357 case LDAP_MOD_REPLACE:
1358 vals = memberof_saved_member_get( op, &saved_member_vals );
1360 /* delete all ... */
1361 if ( vals != NULL ) {
1362 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1363 (void)memberof_value_modify( op, rs,
1364 &vals[ i ], mo->mo_ad_memberof,
1365 &op->o_req_dn, &op->o_req_ndn,
1368 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1371 if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
1377 assert( ml->sml_nvalues != NULL );
1378 vals = ml->sml_nvalues;
1379 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1380 memberof_value_modify( op, rs,
1381 &vals[ i ], mo->mo_ad_memberof,
1383 &op->o_req_dn, &op->o_req_ndn );
1393 return SLAP_CB_CONTINUE;
1397 * response callback that adds/deletes member values when a group member
1401 memberof_res_rename( Operation *op, SlapReply *rs )
1403 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1404 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1406 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1410 struct berval save_dn, save_ndn;
1411 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1413 if ( MEMBEROF_REFINT( mo ) ) {
1414 iswhat |= MEMBEROF_IS_MEMBER;
1417 if ( op->orr_nnewSup ) {
1418 newPNDN = *op->orr_nnewSup;
1421 dnParent( &op->o_req_ndn, &newPNDN );
1424 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1426 save_dn = op->o_req_dn;
1427 save_ndn = op->o_req_ndn;
1429 op->o_req_dn = newNDN;
1430 op->o_req_ndn = newNDN;
1431 rc = memberof_isGroupOrMember( op, &iswhat );
1432 op->o_req_dn = save_dn;
1433 op->o_req_ndn = save_ndn;
1435 if ( rc != LDAP_SUCCESS || iswhat == MEMBEROF_IS_NONE ) {
1439 if ( op->orr_newSup ) {
1440 newPDN = *op->orr_newSup;
1443 dnParent( &op->o_req_dn, &newPDN );
1446 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1448 if ( iswhat & MEMBEROF_IS_GROUP ) {
1449 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1450 rc = backend_attribute( op, NULL, &newNDN,
1451 mo->mo_ad_member, &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_memberof,
1458 &op->o_req_dn, &op->o_req_ndn,
1461 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1465 if ( MEMBEROF_REFINT( mo ) && ( iswhat & MEMBEROF_IS_MEMBER ) ) {
1466 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1467 rc = backend_attribute( op, NULL, &newNDN,
1468 mo->mo_ad_memberof, &vals, ACL_READ );
1469 op->o_bd->bd_info = (BackendInfo *)on;
1471 if ( rc == LDAP_SUCCESS ) {
1472 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1473 (void)memberof_value_modify( op, rs,
1474 &vals[ i ], mo->mo_ad_member,
1475 &op->o_req_dn, &op->o_req_ndn,
1478 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1483 if ( !BER_BVISNULL( &newDN ) ) {
1484 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1486 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1488 return SLAP_CB_CONTINUE;
1492 memberof_response( Operation *op, SlapReply *rs )
1494 if ( rs->sr_err != LDAP_SUCCESS ) {
1495 return SLAP_CB_CONTINUE;
1498 switch ( op->o_tag ) {
1500 return memberof_res_add( op, rs );
1502 case LDAP_REQ_DELETE:
1503 return memberof_res_delete( op, rs );
1505 case LDAP_REQ_MODIFY:
1506 return memberof_res_modify( op, rs );
1508 case LDAP_REQ_MODDN:
1509 return memberof_res_rename( op, rs );
1512 return SLAP_CB_CONTINUE;
1521 slap_overinst *on = (slap_overinst *)be->bd_info;
1524 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1527 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1529 on->on_bi.bi_private = (void *)mo;
1550 static ConfigDriver mo_cf_gen;
1552 #define OID "1.3.6.1.4.1.7136.2.666.4"
1553 #define OIDAT OID ".1.1"
1554 #define OIDCFGAT OID ".1.2"
1555 #define OIDOC OID ".2.1"
1556 #define OIDCFGOC OID ".2.2"
1559 static ConfigTable mo_cfg[] = {
1560 { "memberof-dn", "modifiersName",
1561 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1562 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1563 "DESC 'DN to be used as modifiersName' "
1564 "SYNTAX OMsDN SINGLE-VALUE )",
1567 { "memberof-dangling", "ignore|drop|error",
1568 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1569 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1570 "DESC 'Behavior with respect to dangling members, "
1571 "constrained to ignore, drop, error' "
1572 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1575 { "memberof-refint", "true|FALSE",
1576 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1577 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1578 "DESC 'Take care of referential integrity' "
1579 "SYNTAX OMsBoolean SINGLE-VALUE )",
1582 { "memberof-group-oc", "objectClass",
1583 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1584 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1585 "DESC 'Group objectClass' "
1586 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1589 { "memberof-member-ad", "member attribute",
1590 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1591 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1592 "DESC 'member attribute' "
1593 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1596 { "memberof-memberof-ad", "memberOf attribute",
1597 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1598 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1599 "DESC 'memberOf attribute' "
1600 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1604 { "memberof-reverse", "true|FALSE",
1605 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1606 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1607 "DESC 'Take care of referential integrity "
1608 "also when directly modifying memberOf' "
1609 "SYNTAX OMsBoolean SINGLE-VALUE )",
1613 { "memberof-dangling-error", "error code",
1614 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1615 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1616 "DESC 'Error code returned in case of dangling back reference' "
1617 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1620 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1623 static ConfigOCs mo_ocs[] = {
1624 { "( OLcfgOvOc:18.1 "
1625 "NAME 'olcMemberOf' "
1626 "DESC 'Member-of configuration' "
1627 "SUP olcOverlayConfig "
1630 "$ olcMemberOfDangling "
1631 "$ olcMemberOfDanglingError"
1632 "$ olcMemberOfRefInt "
1633 "$ olcMemberOfGroupOC "
1634 "$ olcMemberOfMemberAD "
1635 "$ olcMemberOfMemberOfAD "
1637 "$ olcMemberOfReverse "
1641 Cft_Overlay, mo_cfg, NULL, NULL },
1645 static slap_verbmasks dangling_mode[] = {
1646 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1647 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1648 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1653 memberof_make_group_filter( memberof_t *mo )
1657 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1658 ch_free( mo->mo_groupFilterstr.bv_val );
1661 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1662 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1664 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1665 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1667 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1668 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1669 + mo->mo_oc_group->soc_cname.bv_len;
1670 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1672 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1674 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1682 memberof_make_member_filter( memberof_t *mo )
1686 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1687 ch_free( mo->mo_memberFilterstr.bv_val );
1690 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1691 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1693 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1694 + mo->mo_ad_memberof->ad_cname.bv_len;
1695 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1697 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1698 ptr = lutil_strcopy( ptr, "=*)" );
1704 mo_cf_gen( ConfigArgs *c )
1706 slap_overinst *on = (slap_overinst *)c->bi;
1707 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1711 if ( c->op == SLAP_CONFIG_EMIT ) {
1712 struct berval bv = BER_BVNULL;
1716 if ( mo->mo_dn.bv_val != NULL) {
1717 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1718 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1723 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1724 if ( BER_BVISNULL( &bv ) ) {
1725 /* there's something wrong... */
1730 value_add_one( &c->rvalue_vals, &bv );
1734 case MO_DANGLING_ERROR:
1735 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1736 char buf[ SLAP_TEXT_BUFLEN ];
1737 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1738 if ( BER_BVISNULL( &bv ) ) {
1739 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1740 if ( bv.bv_len < sizeof( buf ) ) {
1747 value_add_one( &c->rvalue_vals, &bv );
1754 c->value_int = MEMBEROF_REFINT( mo );
1759 c->value_int = MEMBEROF_REVERSE( mo );
1764 if ( mo->mo_oc_group != NULL ){
1765 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1770 if ( mo->mo_ad_member != NULL ){
1771 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1775 case MO_MEMBER_OF_AD:
1776 if ( mo->mo_ad_memberof != NULL ){
1777 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1788 } else if ( c->op == LDAP_MOD_DELETE ) {
1789 return 1; /* FIXME */
1794 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1795 ber_memfree( mo->mo_dn.bv_val );
1796 ber_memfree( mo->mo_ndn.bv_val );
1798 mo->mo_dn = c->value_dn;
1799 mo->mo_ndn = c->value_ndn;
1803 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1804 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1808 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1809 mo->mo_flags |= dangling_mode[ i ].mask;
1812 case MO_DANGLING_ERROR:
1813 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1814 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1815 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1816 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1822 if ( c->value_int ) {
1823 mo->mo_flags |= MEMBEROF_FREFINT;
1826 mo->mo_flags &= ~MEMBEROF_FREFINT;
1832 if ( c->value_int ) {
1833 mo->mo_flags |= MEMBEROF_FREVERSE;
1836 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1842 ObjectClass *oc = NULL;
1844 oc = oc_find( c->argv[ 1 ] );
1846 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1847 "unable to find group objectClass=\"%s\"",
1849 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1850 c->log, c->cr_msg, 0 );
1854 mo->mo_oc_group = oc;
1855 memberof_make_group_filter( mo );
1858 case MO_MEMBER_AD: {
1859 AttributeDescription *ad = NULL;
1860 const char *text = NULL;
1863 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1864 if ( rc != LDAP_SUCCESS ) {
1865 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1866 "unable to find member attribute=\"%s\": %s (%d)",
1867 c->argv[ 1 ], text, rc );
1868 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1869 c->log, c->cr_msg, 0 );
1873 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1874 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1876 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1877 "member attribute=\"%s\" must either "
1878 "have DN (%s) or nameUID (%s) syntax",
1879 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1880 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1881 c->log, c->cr_msg, 0 );
1885 mo->mo_ad_member = ad;
1888 case MO_MEMBER_OF_AD: {
1889 AttributeDescription *ad = NULL;
1890 const char *text = NULL;
1893 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1894 if ( rc != LDAP_SUCCESS ) {
1895 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1896 "unable to find memberof attribute=\"%s\": %s (%d)",
1897 c->argv[ 1 ], text, rc );
1898 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1899 c->log, c->cr_msg, 0 );
1903 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1904 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1906 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1907 "memberof attribute=\"%s\" must either "
1908 "have DN (%s) or nameUID (%s) syntax",
1909 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1910 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1911 c->log, c->cr_msg, 0 );
1915 mo->mo_ad_memberof = ad;
1916 memberof_make_member_filter( mo );
1933 slap_overinst *on = (slap_overinst *)be->bd_info;
1934 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1937 const char *text = NULL;
1939 if( ! mo->mo_ad_memberof ){
1940 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
1941 if ( rc != LDAP_SUCCESS ) {
1942 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1943 "unable to find attribute=\"%s\": %s (%d)\n",
1944 SLAPD_MEMBEROF_ATTR, text, rc );
1949 if( ! mo->mo_ad_member ){
1950 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &text );
1951 if ( rc != LDAP_SUCCESS ) {
1952 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1953 "unable to find attribute=\"%s\": %s (%d)\n",
1954 SLAPD_GROUP_ATTR, text, rc );
1959 if( ! mo->mo_oc_group ){
1960 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
1961 if ( mo->mo_oc_group == NULL ) {
1962 Debug( LDAP_DEBUG_ANY,
1963 "memberof_db_open: "
1964 "unable to find objectClass=\"%s\"\n",
1965 SLAPD_GROUP_CLASS, 0, 0 );
1970 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
1971 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
1972 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
1975 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1976 memberof_make_group_filter( mo );
1979 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1980 memberof_make_member_filter( mo );
1987 memberof_db_destroy(
1991 slap_overinst *on = (slap_overinst *)be->bd_info;
1992 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1995 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1996 ber_memfree( mo->mo_dn.bv_val );
1997 ber_memfree( mo->mo_ndn.bv_val );
2000 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
2001 ber_memfree( mo->mo_groupFilterstr.bv_val );
2004 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
2005 ber_memfree( mo->mo_memberFilterstr.bv_val );
2015 static AttributeDescription *ad_memberOf;
2019 AttributeDescription **adp;
2021 { "( 1.2.840.113556.1.2.102 "
2023 "DESC 'Group that the entry belongs to' "
2024 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2025 "EQUALITY distinguishedNameMatch " /* added */
2026 "USAGE dSAOperation " /* added; questioned */
2027 /* "NO-USER-MODIFICATION " */ /* add? */
2028 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2033 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2035 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2037 memberof_initialize( void )
2041 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2042 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2044 Debug( LDAP_DEBUG_ANY,
2045 "memberof_initialize: register_at #%d failed\n",
2051 memberof.on_bi.bi_type = "memberof";
2053 memberof.on_bi.bi_db_init = memberof_db_init;
2054 memberof.on_bi.bi_db_open = memberof_db_open;
2055 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2057 memberof.on_bi.bi_op_add = memberof_op_add;
2058 memberof.on_bi.bi_op_delete = memberof_op_delete;
2059 memberof.on_bi.bi_op_modify = memberof_op_modify;
2061 memberof.on_response = memberof_response;
2063 memberof.on_bi.bi_cf_ocs = mo_ocs;
2065 code = config_register_schema( mo_cfg, mo_ocs );
2066 if ( code ) return code;
2068 return overlay_register( &memberof );
2071 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2073 init_module( int argc, char *argv[] )
2075 return memberof_initialize();
2077 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2079 #endif /* SLAPD_OVER_MEMBEROF */