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_setkey_x( op->o_threadctx, key,
238 saved_vals, memberof_saved_member_free, &old_vals, NULL );
239 if ( old_vals != NULL ) {
240 ber_bvarray_free( old_vals );
245 typedef struct memberof_cookie_t {
246 AttributeDescription *ad;
252 memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
254 if ( rs->sr_type == REP_SEARCH ) {
255 memberof_cookie_t *mc;
257 mc = (memberof_cookie_t *)op->o_callback->sc_private;
265 * callback for internal search that saves the member attribute values
266 * of groups being deleted.
269 memberof_saveMember_cb( Operation *op, SlapReply *rs )
271 if ( rs->sr_type == REP_SEARCH ) {
272 memberof_cookie_t *mc;
274 BerVarray vals = NULL;
276 mc = (memberof_cookie_t *)op->o_callback->sc_private;
279 assert( rs->sr_entry != NULL );
280 assert( rs->sr_entry->e_attrs != NULL );
282 a = attr_find( rs->sr_entry->e_attrs, mc->ad );
287 memberof_saved_member_set( op, mc->key, vals );
289 if ( a && attr_find( a->a_next, mc->ad ) != NULL ) {
290 Debug( LDAP_DEBUG_ANY,
291 "%s: memberof_saveMember_cb(\"%s\"): "
292 "more than one occurrence of \"%s\" "
295 rs->sr_entry->e_name.bv_val,
296 mc->ad->ad_cname.bv_val );
304 * the delete hook performs an internal search that saves the member
305 * attribute values of groups being deleted.
308 memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp )
310 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
311 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
314 SlapReply rs2 = { REP_RESULT };
315 slap_callback cb = { 0 };
316 memberof_cookie_t mc;
317 AttributeName an[ 2 ];
319 memberof_is_t iswhat = MEMBEROF_IS_NONE;
321 assert( iswhatp != NULL );
322 assert( *iswhatp != MEMBEROF_IS_NONE );
325 if ( op->o_tag == LDAP_REQ_DELETE ) {
326 cb.sc_response = memberof_saveMember_cb;
329 cb.sc_response = memberof_isGroupOrMember_cb;
332 op2.o_tag = LDAP_REQ_SEARCH;
333 op2.o_callback = &cb;
334 op2.o_dn = op->o_bd->be_rootdn;
335 op2.o_ndn = op->o_bd->be_rootndn;
337 op2.ors_scope = LDAP_SCOPE_BASE;
338 op2.ors_deref = LDAP_DEREF_NEVER;
339 BER_BVZERO( &an[ 1 ].an_name );
341 op2.ors_attrsonly = 0;
342 op2.ors_limit = NULL;
344 op2.ors_tlimit = SLAP_NO_LIMIT;
346 if ( *iswhatp & MEMBEROF_IS_GROUP ) {
347 mc.ad = mo->mo_ad_member;
348 mc.key = &saved_member_vals;
350 an[ 0 ].an_desc = mo->mo_ad_member;
351 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
352 op2.ors_filterstr = mo->mo_groupFilterstr;
353 op2.ors_filter = &mo->mo_groupFilter;
355 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
356 (void)op->o_bd->be_search( &op2, &rs2 );
357 op2.o_bd->bd_info = (BackendInfo *)on;
360 iswhat |= MEMBEROF_IS_GROUP;
363 memberof_saved_member_set( op, mc.key, NULL );
367 if ( *iswhatp & MEMBEROF_IS_MEMBER ) {
368 mc.ad = mo->mo_ad_memberof;
369 mc.key = &saved_memberof_vals;
371 an[ 0 ].an_desc = mo->mo_ad_memberof;
372 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
373 op2.ors_filterstr = mo->mo_memberFilterstr;
374 op2.ors_filter = &mo->mo_memberFilter;
376 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
377 (void)op->o_bd->be_search( &op2, &rs2 );
378 op2.o_bd->bd_info = (BackendInfo *)on;
381 iswhat |= MEMBEROF_IS_MEMBER;
384 memberof_saved_member_set( op, mc.key, NULL );
394 * response callback that adds memberof values when a group is modified.
397 memberof_value_modify(
401 AttributeDescription *ad,
402 struct berval *old_dn,
403 struct berval *old_ndn,
404 struct berval *new_dn,
405 struct berval *new_ndn )
407 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
408 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
411 SlapReply rs2 = { REP_RESULT };
412 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
413 Modifications mod[ 2 ] = { { { 0 } } }, *ml;
414 struct berval values[ 4 ], nvalues[ 4 ];
417 op2.o_tag = LDAP_REQ_MODIFY;
420 op2.o_req_ndn = *ndn;
422 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
424 op2.o_callback = &cb;
425 op2.o_dn = op->o_bd->be_rootdn;
426 op2.o_ndn = op->o_bd->be_rootndn;
427 op2.orm_modlist = NULL;
429 if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
432 ml->sml_values = &values[ 0 ];
433 ml->sml_values[ 0 ] = mo->mo_dn;
434 BER_BVZERO( &ml->sml_values[ 1 ] );
435 ml->sml_nvalues = &nvalues[ 0 ];
436 ml->sml_nvalues[ 0 ] = mo->mo_ndn;
437 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
438 ml->sml_desc = slap_schema.si_ad_modifiersName;
439 ml->sml_type = ml->sml_desc->ad_cname;
440 ml->sml_op = LDAP_MOD_REPLACE;
441 ml->sml_flags = SLAP_MOD_INTERNAL;
442 ml->sml_next = op2.orm_modlist;
443 op2.orm_modlist = ml;
450 ml->sml_values = &values[ 2 ];
451 BER_BVZERO( &ml->sml_values[ 1 ] );
452 ml->sml_nvalues = &nvalues[ 2 ];
453 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
455 ml->sml_type = ml->sml_desc->ad_cname;
456 ml->sml_flags = SLAP_MOD_INTERNAL;
457 ml->sml_next = op2.orm_modlist;
458 op2.orm_modlist = ml;
460 if ( new_ndn != NULL ) {
461 assert( !BER_BVISNULL( new_dn ) );
462 assert( !BER_BVISNULL( new_ndn ) );
465 ml->sml_op = LDAP_MOD_ADD;
467 ml->sml_values[ 0 ] = *new_dn;
468 ml->sml_nvalues[ 0 ] = *new_ndn;
470 (void)op->o_bd->be_modify( &op2, &rs2 );
471 if ( rs2.sr_err != LDAP_SUCCESS ) {
472 char buf[ SLAP_TEXT_BUFLEN ];
473 snprintf( buf, sizeof( buf ),
474 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
475 ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err,
476 rs2.sr_text ? rs2.sr_text : "" );
477 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
478 op->o_log_prefix, buf, 0 );
481 assert( op2.orm_modlist == &mod[ mcnt ] );
482 assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
483 ml = op2.orm_modlist->sml_next;
485 assert( ml == &mod[ 0 ] );
489 slap_mods_free( ml, 1 );
492 mod[ 0 ].sml_next = NULL;
495 if ( old_ndn != NULL ) {
496 assert( !BER_BVISNULL( old_dn ) );
497 assert( !BER_BVISNULL( old_ndn ) );
500 ml->sml_op = LDAP_MOD_DELETE;
502 ml->sml_values[ 0 ] = *old_dn;
503 ml->sml_nvalues[ 0 ] = *old_ndn;
505 (void)op->o_bd->be_modify( &op2, &rs2 );
506 if ( rs2.sr_err != LDAP_SUCCESS ) {
507 char buf[ SLAP_TEXT_BUFLEN ];
508 snprintf( buf, sizeof( buf ),
509 "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
510 ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err,
511 rs2.sr_text ? rs2.sr_text : "" );
512 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
513 op->o_log_prefix, buf, 0 );
516 assert( op2.orm_modlist == &mod[ mcnt ] );
517 ml = op2.orm_modlist->sml_next;
519 assert( ml == &mod[ 0 ] );
523 slap_mods_free( ml, 1 );
527 /* FIXME: if old_group_ndn doesn't exist, both delete __and__
528 * add will fail; better split in two operations, although
529 * not optimal in terms of performance. At least it would
530 * move towards self-repairing capabilities. */
532 op2.o_bd->bd_info = (BackendInfo *)on;
538 memberof_op_add( Operation *op, SlapReply *rs )
540 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
541 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
543 Attribute **ap, **map = NULL;
544 int rc = SLAP_CB_CONTINUE;
546 struct berval save_dn, save_ndn;
548 if ( op->ora_e->e_attrs == NULL ) {
549 /* FIXME: global overlay; need to deal with */
550 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
551 "consistency checks not implemented when overlay "
552 "is instantiated as global.\n",
553 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
554 return SLAP_CB_CONTINUE;
557 if ( MEMBEROF_REVERSE( mo ) ) {
558 for ( ap = &op->ora_e->e_attrs; *ap; ap = &(*ap)->a_next ) {
561 if ( a->a_desc == mo->mo_ad_memberof ) {
569 save_ndn = op->o_ndn;
571 if ( MEMBEROF_DANGLING_CHECK( mo )
573 && is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) )
575 op->o_dn = op->o_bd->be_rootdn;
576 op->o_dn = op->o_bd->be_rootndn;
577 op->o_bd->bd_info = (BackendInfo *)on->on_info;
579 for ( ap = &op->ora_e->e_attrs; *ap; ) {
582 if ( !is_ad_subtype( a->a_desc, mo->mo_ad_member ) ) {
587 assert( a->a_nvals != NULL );
589 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
592 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
594 if ( rc == LDAP_SUCCESS ) {
595 be_entry_release_r( op, e );
599 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
600 rc = rs->sr_err = mo->mo_dangling_err;
601 rs->sr_text = "adding non-existing object "
603 send_ldap_result( op, rs );
607 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
610 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
611 "member=\"%s\" does not exist (stripping...)\n",
612 op->o_log_prefix, op->ora_e->e_name.bv_val,
613 a->a_vals[ i ].bv_val );
615 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
616 ber_memfree( a->a_vals[ i ].bv_val );
617 BER_BVZERO( &a->a_vals[ i ] );
618 if ( a->a_nvals != a->a_vals ) {
619 ber_memfree( a->a_nvals[ i ].bv_val );
620 BER_BVZERO( &a->a_nvals[ i ] );
626 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
627 sizeof( struct berval ) * ( j - i ) );
628 if ( a->a_nvals != a->a_vals ) {
629 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
630 sizeof( struct berval ) * ( j - i ) );
636 /* If all values have been removed,
637 * remove the attribute itself. */
638 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
647 op->o_ndn = save_ndn;
648 op->o_bd->bd_info = (BackendInfo *)on;
653 AccessControlState acl_state = ACL_STATE_INIT;
655 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
658 op->o_bd->bd_info = (BackendInfo *)on->on_info;
659 /* access is checked with the original identity */
660 rc = access_allowed( op, op->ora_e, mo->mo_ad_memberof,
661 &a->a_nvals[ i ], ACL_WADD,
664 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
666 send_ldap_result( op, rs );
669 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
671 op->o_bd->bd_info = (BackendInfo *)on;
672 if ( rc != LDAP_SUCCESS ) {
673 if ( get_relax( op ) ) {
677 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
678 rc = rs->sr_err = mo->mo_dangling_err;
679 rs->sr_text = "adding non-existing object "
681 send_ldap_result( op, rs );
685 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
688 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
689 "memberof=\"%s\" does not exist (stripping...)\n",
690 op->o_log_prefix, op->ora_e->e_name.bv_val,
691 a->a_nvals[ i ].bv_val );
693 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
694 ber_memfree( a->a_vals[ i ].bv_val );
695 BER_BVZERO( &a->a_vals[ i ] );
696 if ( a->a_nvals != a->a_vals ) {
697 ber_memfree( a->a_nvals[ i ].bv_val );
698 BER_BVZERO( &a->a_nvals[ i ] );
704 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
705 sizeof( struct berval ) * ( j - i ) );
706 if ( a->a_nvals != a->a_vals ) {
707 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
708 sizeof( struct berval ) * ( j - i ) );
716 /* access is checked with the original identity */
717 op->o_bd->bd_info = (BackendInfo *)on->on_info;
718 rc = access_allowed( op, e, mo->mo_ad_member,
719 &op->o_req_ndn, ACL_WADD, NULL );
720 be_entry_release_r( op, e );
721 op->o_bd->bd_info = (BackendInfo *)on;
724 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
725 rs->sr_text = "insufficient access to object referenced by memberof";
726 send_ldap_result( op, rs );
731 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
737 rc = SLAP_CB_CONTINUE;
741 op->o_ndn = save_ndn;
742 op->o_bd->bd_info = (BackendInfo *)on;
748 memberof_op_delete( Operation *op, SlapReply *rs )
750 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
751 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
753 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
755 if ( MEMBEROF_REFINT( mo ) ) {
756 iswhat = MEMBEROF_IS_BOTH;
759 memberof_isGroupOrMember( op, &iswhat );
761 return SLAP_CB_CONTINUE;
765 memberof_op_modify( Operation *op, SlapReply *rs )
767 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
768 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
770 Modifications **mlp, **mmlp = NULL;
771 int rc = SLAP_CB_CONTINUE;
772 struct berval save_dn, save_ndn;
773 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
775 if ( MEMBEROF_REVERSE( mo ) ) {
776 for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
777 Modifications *ml = *mlp;
779 if ( ml->sml_desc == mo->mo_ad_memberof ) {
787 save_ndn = op->o_ndn;
789 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
790 && ( iswhat & MEMBEROF_IS_GROUP ) )
795 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
796 if ( ml->sml_desc == mo->mo_ad_member ) {
797 switch ( ml->sml_op ) {
798 case LDAP_MOD_DELETE:
799 case LDAP_MOD_REPLACE:
807 BerVarray vals = NULL;
809 op->o_dn = op->o_bd->be_rootdn;
810 op->o_dn = op->o_bd->be_rootndn;
811 op->o_bd->bd_info = (BackendInfo *)on->on_info;
812 rc = backend_attribute( op, NULL, &op->o_req_ndn,
813 mo->mo_ad_member, &vals, ACL_READ );
814 op->o_bd->bd_info = (BackendInfo *)on;
815 if ( rc == LDAP_SUCCESS && vals != NULL ) {
816 memberof_saved_member_set( op, &saved_member_vals, vals );
817 ber_bvarray_free_x( vals, op->o_tmpmemctx );
821 if ( MEMBEROF_DANGLING_CHECK( mo )
822 && !get_relax( op ) )
824 op->o_dn = op->o_bd->be_rootdn;
825 op->o_dn = op->o_bd->be_rootndn;
826 op->o_bd->bd_info = (BackendInfo *)on->on_info;
828 assert( op->orm_modlist != NULL );
830 for ( mlp = &op->orm_modlist; *mlp; ) {
831 Modifications *ml = *mlp;
834 if ( !is_ad_subtype( ml->sml_desc, mo->mo_ad_member ) ) {
839 switch ( ml->sml_op ) {
840 case LDAP_MOD_DELETE:
841 /* we don't care about cancellations: if the value
842 * exists, fine; if it doesn't, we let the underlying
843 * database fail as appropriate; */
847 case LDAP_MOD_REPLACE:
849 /* NOTE: right now, the attributeType we use
850 * for member must have a normalized value */
851 assert( ml->sml_nvalues != NULL );
853 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
857 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
858 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
860 be_entry_release_r( op, e );
864 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
865 rc = rs->sr_err = mo->mo_dangling_err;
866 rs->sr_text = "adding non-existing object "
868 send_ldap_result( op, rs );
872 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
875 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
876 "member=\"%s\" does not exist (stripping...)\n",
877 op->o_log_prefix, op->o_req_dn.bv_val,
878 ml->sml_nvalues[ i ].bv_val );
880 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
881 ber_memfree( ml->sml_values[ i ].bv_val );
882 BER_BVZERO( &ml->sml_values[ i ] );
883 ber_memfree( ml->sml_nvalues[ i ].bv_val );
884 BER_BVZERO( &ml->sml_nvalues[ i ] );
890 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
891 sizeof( struct berval ) * ( j - i ) );
892 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
893 sizeof( struct berval ) * ( j - i ) );
898 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
900 slap_mod_free( &ml->sml_mod, 0 );
916 if ( mmlp != NULL ) {
917 Modifications *ml = *mmlp;
921 op->o_bd->bd_info = (BackendInfo *)on->on_info;
922 rc = be_entry_get_rw( op, &op->o_req_ndn,
923 NULL, NULL, 0, &target );
924 op->o_bd->bd_info = (BackendInfo *)on;
925 if ( rc != LDAP_SUCCESS ) {
926 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
927 send_ldap_result( op, rs );
931 switch ( ml->sml_op ) {
932 case LDAP_MOD_DELETE:
933 if ( ml->sml_nvalues != NULL ) {
934 AccessControlState acl_state = ACL_STATE_INIT;
936 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
939 op->o_bd->bd_info = (BackendInfo *)on->on_info;
940 /* access is checked with the original identity */
941 rc = access_allowed( op, target,
943 &ml->sml_nvalues[ i ],
947 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
949 send_ldap_result( op, rs );
953 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
955 op->o_bd->bd_info = (BackendInfo *)on;
956 if ( rc != LDAP_SUCCESS ) {
957 if ( get_relax( op ) ) {
961 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
962 rc = rs->sr_err = mo->mo_dangling_err;
963 rs->sr_text = "deleting non-existing object "
965 send_ldap_result( op, rs );
969 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
972 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
973 "memberof=\"%s\" does not exist (stripping...)\n",
974 op->o_log_prefix, op->o_req_ndn.bv_val,
975 ml->sml_nvalues[ i ].bv_val );
977 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
978 ber_memfree( ml->sml_values[ i ].bv_val );
979 BER_BVZERO( &ml->sml_values[ i ] );
980 if ( ml->sml_nvalues != ml->sml_values ) {
981 ber_memfree( ml->sml_nvalues[ i ].bv_val );
982 BER_BVZERO( &ml->sml_nvalues[ i ] );
989 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
990 sizeof( struct berval ) * ( j - i ) );
991 if ( ml->sml_nvalues != ml->sml_values ) {
992 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
993 sizeof( struct berval ) * ( j - i ) );
1001 /* access is checked with the original identity */
1002 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1003 rc = access_allowed( op, e, mo->mo_ad_member,
1006 be_entry_release_r( op, e );
1007 op->o_bd->bd_info = (BackendInfo *)on;
1010 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1011 rs->sr_text = "insufficient access to object referenced by memberof";
1012 send_ldap_result( op, rs );
1017 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1018 *mmlp = ml->sml_next;
1019 slap_mod_free( &ml->sml_mod, 0 );
1027 case LDAP_MOD_REPLACE:
1029 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1030 /* access is checked with the original identity */
1031 rc = access_allowed( op, target,
1035 op->o_bd->bd_info = (BackendInfo *)on;
1037 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1039 send_ldap_result( op, rs );
1043 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1048 case LDAP_MOD_ADD: {
1049 AccessControlState acl_state = ACL_STATE_INIT;
1051 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1054 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1055 /* access is checked with the original identity */
1056 rc = access_allowed( op, target,
1058 &ml->sml_nvalues[ i ],
1062 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1064 send_ldap_result( op, rs );
1068 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1069 NULL, NULL, 0, &e );
1070 op->o_bd->bd_info = (BackendInfo *)on;
1071 if ( rc != LDAP_SUCCESS ) {
1072 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1073 rc = rs->sr_err = mo->mo_dangling_err;
1074 rs->sr_text = "adding non-existing object "
1076 send_ldap_result( op, rs );
1080 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1083 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1084 "memberof=\"%s\" does not exist (stripping...)\n",
1085 op->o_log_prefix, op->o_req_ndn.bv_val,
1086 ml->sml_nvalues[ i ].bv_val );
1088 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1089 ber_memfree( ml->sml_values[ i ].bv_val );
1090 BER_BVZERO( &ml->sml_values[ i ] );
1091 if ( ml->sml_nvalues != ml->sml_values ) {
1092 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1093 BER_BVZERO( &ml->sml_nvalues[ i ] );
1100 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1101 sizeof( struct berval ) * ( j - i ) );
1102 if ( ml->sml_nvalues != ml->sml_values ) {
1103 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1104 sizeof( struct berval ) * ( j - i ) );
1112 /* access is checked with the original identity */
1113 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1114 rc = access_allowed( op, e, mo->mo_ad_member,
1117 be_entry_release_r( op, e );
1118 op->o_bd->bd_info = (BackendInfo *)on;
1121 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1122 rs->sr_text = "insufficient access to object referenced by memberof";
1123 send_ldap_result( op, rs );
1128 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1129 *mmlp = ml->sml_next;
1130 slap_mod_free( &ml->sml_mod, 0 );
1141 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1142 be_entry_release_r( op, target );
1143 op->o_bd->bd_info = (BackendInfo *)on;
1146 rc = SLAP_CB_CONTINUE;
1150 op->o_ndn = save_ndn;
1151 op->o_bd->bd_info = (BackendInfo *)on;
1157 * response callback that adds memberof values when a group is added.
1160 memberof_res_add( Operation *op, SlapReply *rs )
1162 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1163 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1167 if ( MEMBEROF_REVERSE( mo ) ) {
1170 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1172 Operation op2 = *op;
1173 SlapReply rs2 = { 0 };
1175 /* relax is required to allow to add
1176 * a non-existing member */
1177 op2.o_relax = SLAP_CONTROL_CRITICAL;
1179 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1181 /* the modification is attempted
1182 * with the original identity */
1183 (void)memberof_value_modify( &op2, &rs2,
1184 &ma->a_nvals[ i ], mo->mo_ad_member,
1185 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1190 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1193 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1195 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1197 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1198 (void)memberof_value_modify( op, rs,
1208 return SLAP_CB_CONTINUE;
1212 * response callback that deletes memberof values when a group is deleted.
1215 memberof_res_delete( Operation *op, SlapReply *rs )
1217 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1218 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1223 vals = memberof_saved_member_get( op, &saved_member_vals );
1224 if ( vals != NULL ) {
1225 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1226 (void)memberof_value_modify( op, rs,
1227 &vals[ i ], mo->mo_ad_memberof,
1228 &op->o_req_dn, &op->o_req_ndn,
1232 memberof_saved_member_set( op, &saved_memberof_vals, NULL );
1233 ber_bvarray_free( vals );
1236 if ( MEMBEROF_REFINT( mo ) ) {
1237 vals = memberof_saved_member_get( op, &saved_memberof_vals );
1238 if ( vals != NULL ) {
1239 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1240 (void)memberof_value_modify( op, rs,
1241 &vals[ i ], mo->mo_ad_member,
1242 &op->o_req_dn, &op->o_req_ndn,
1246 memberof_saved_member_set( op, &saved_member_vals, NULL );
1247 ber_bvarray_free( vals );
1251 return SLAP_CB_CONTINUE;
1255 * response callback that adds/deletes memberof values when a group
1259 memberof_res_modify( Operation *op, SlapReply *rs )
1261 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1262 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1265 Modifications *ml, *mml = NULL;
1267 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1269 if ( MEMBEROF_REVERSE( mo ) ) {
1270 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1271 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1278 if ( mml != NULL ) {
1279 BerVarray vals = mml->sml_nvalues;
1281 switch ( mml->sml_op ) {
1282 case LDAP_MOD_DELETE:
1283 if ( vals != NULL ) {
1284 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1285 memberof_value_modify( op, rs,
1286 &vals[ i ], mo->mo_ad_member,
1287 &op->o_req_dn, &op->o_req_ndn,
1294 case LDAP_MOD_REPLACE:
1295 /* delete all ... */
1296 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1297 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1298 mo->mo_ad_memberof, &vals, ACL_READ );
1299 op->o_bd->bd_info = (BackendInfo *)on;
1300 if ( rc == LDAP_SUCCESS ) {
1301 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1302 (void)memberof_value_modify( op, rs,
1303 &vals[ i ], mo->mo_ad_member,
1304 &op->o_req_dn, &op->o_req_ndn,
1307 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1310 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1316 assert( vals != NULL );
1318 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1319 memberof_value_modify( op, rs,
1320 &vals[ i ], mo->mo_ad_member,
1322 &op->o_req_dn, &op->o_req_ndn );
1331 if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
1332 && ( iswhat & MEMBEROF_IS_GROUP ) )
1334 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1335 if ( ml->sml_desc != mo->mo_ad_member ) {
1339 switch ( ml->sml_op ) {
1340 case LDAP_MOD_DELETE:
1341 vals = ml->sml_nvalues;
1342 if ( vals != NULL ) {
1343 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1344 memberof_value_modify( op, rs,
1345 &vals[ i ], mo->mo_ad_memberof,
1346 &op->o_req_dn, &op->o_req_ndn,
1353 case LDAP_MOD_REPLACE:
1354 vals = memberof_saved_member_get( op, &saved_member_vals );
1356 /* delete all ... */
1357 if ( vals != NULL ) {
1358 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1359 (void)memberof_value_modify( op, rs,
1360 &vals[ i ], mo->mo_ad_memberof,
1361 &op->o_req_dn, &op->o_req_ndn,
1364 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1367 if ( ml->sml_op == LDAP_MOD_DELETE ) {
1373 assert( ml->sml_nvalues != NULL );
1374 vals = ml->sml_nvalues;
1375 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1376 memberof_value_modify( op, rs,
1377 &vals[ i ], mo->mo_ad_memberof,
1379 &op->o_req_dn, &op->o_req_ndn );
1389 return SLAP_CB_CONTINUE;
1393 * response callback that adds/deletes member values when a group member
1397 memberof_res_rename( Operation *op, SlapReply *rs )
1399 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1400 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1402 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1406 struct berval save_dn, save_ndn;
1407 memberof_is_t iswhat = MEMBEROF_IS_GROUP;
1409 if ( MEMBEROF_REFINT( mo ) ) {
1410 iswhat |= MEMBEROF_IS_MEMBER;
1413 if ( op->orr_nnewSup ) {
1414 newPNDN = *op->orr_nnewSup;
1417 dnParent( &op->o_req_ndn, &newPNDN );
1420 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1422 save_dn = op->o_req_dn;
1423 save_ndn = op->o_req_ndn;
1425 op->o_req_dn = newNDN;
1426 op->o_req_ndn = newNDN;
1427 rc = memberof_isGroupOrMember( op, &iswhat );
1428 op->o_req_dn = save_dn;
1429 op->o_req_ndn = save_ndn;
1431 if ( rc != LDAP_SUCCESS || iswhat == MEMBEROF_IS_NONE ) {
1435 if ( op->orr_newSup ) {
1436 newPDN = *op->orr_newSup;
1439 dnParent( &op->o_req_dn, &newPDN );
1442 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1444 if ( iswhat & MEMBEROF_IS_GROUP ) {
1445 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1446 rc = backend_attribute( op, NULL, &newNDN,
1447 mo->mo_ad_member, &vals, ACL_READ );
1448 op->o_bd->bd_info = (BackendInfo *)on;
1450 if ( rc == LDAP_SUCCESS ) {
1451 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1452 (void)memberof_value_modify( op, rs,
1453 &vals[ i ], mo->mo_ad_memberof,
1454 &op->o_req_dn, &op->o_req_ndn,
1457 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1461 if ( MEMBEROF_REFINT( mo ) && ( iswhat & MEMBEROF_IS_MEMBER ) ) {
1462 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1463 rc = backend_attribute( op, NULL, &newNDN,
1464 mo->mo_ad_memberof, &vals, ACL_READ );
1465 op->o_bd->bd_info = (BackendInfo *)on;
1467 if ( rc == LDAP_SUCCESS ) {
1468 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1469 (void)memberof_value_modify( op, rs,
1470 &vals[ i ], mo->mo_ad_member,
1471 &op->o_req_dn, &op->o_req_ndn,
1474 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1479 if ( !BER_BVISNULL( &newDN ) ) {
1480 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1482 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1484 return SLAP_CB_CONTINUE;
1488 memberof_response( Operation *op, SlapReply *rs )
1490 if ( rs->sr_err != LDAP_SUCCESS ) {
1491 return SLAP_CB_CONTINUE;
1494 switch ( op->o_tag ) {
1496 return memberof_res_add( op, rs );
1498 case LDAP_REQ_DELETE:
1499 return memberof_res_delete( op, rs );
1501 case LDAP_REQ_MODIFY:
1502 return memberof_res_modify( op, rs );
1504 case LDAP_REQ_MODDN:
1505 return memberof_res_rename( op, rs );
1508 return SLAP_CB_CONTINUE;
1517 slap_overinst *on = (slap_overinst *)be->bd_info;
1518 memberof_t tmp_mo = { 0 }, *mo;
1520 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1523 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1525 on->on_bi.bi_private = (void *)mo;
1546 static ConfigDriver mo_cf_gen;
1548 #define OID "1.3.6.1.4.1.7136.2.666.4"
1549 #define OIDAT OID ".1.1"
1550 #define OIDCFGAT OID ".1.2"
1551 #define OIDOC OID ".2.1"
1552 #define OIDCFGOC OID ".2.2"
1555 static ConfigTable mo_cfg[] = {
1556 { "memberof-dn", "modifiersName",
1557 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1558 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1559 "DESC 'DN to be used as modifiersName' "
1560 "SYNTAX OMsDN SINGLE-VALUE )",
1563 { "memberof-dangling", "ignore|drop|error",
1564 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1565 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1566 "DESC 'Behavior with respect to dangling members, "
1567 "constrained to ignore, drop, error' "
1568 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1571 { "memberof-refint", "true|FALSE",
1572 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1573 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1574 "DESC 'Take care of referential integrity' "
1575 "SYNTAX OMsBoolean SINGLE-VALUE )",
1578 { "memberof-group-oc", "objectClass",
1579 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1580 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1581 "DESC 'Group objectClass' "
1582 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1585 { "memberof-member-ad", "member attribute",
1586 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1587 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1588 "DESC 'member attribute' "
1589 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1592 { "memberof-memberof-ad", "memberOf attribute",
1593 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1594 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1595 "DESC 'memberOf attribute' "
1596 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1600 { "memberof-reverse", "true|FALSE",
1601 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1602 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1603 "DESC 'Take care of referential integrity "
1604 "also when directly modifying memberOf' "
1605 "SYNTAX OMsBoolean SINGLE-VALUE )",
1609 { "memberof-dangling-error", "error code",
1610 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1611 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1612 "DESC 'Error code returned in case of dangling back reference' "
1613 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1616 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1619 static ConfigOCs mo_ocs[] = {
1620 { "( OLcfgOvOc:18.1 "
1621 "NAME 'olcMemberOf' "
1622 "DESC 'Member-of configuration' "
1623 "SUP olcOverlayConfig "
1626 "$ olcMemberOfDangling "
1627 "$ olcMemberOfDanglingError"
1628 "$ olcMemberOfRefInt "
1629 "$ olcMemberOfGroupOC "
1630 "$ olcMemberOfMemberAD "
1631 "$ olcMemberOfMemberOfAD "
1633 "$ olcMemberOfReverse "
1637 Cft_Overlay, mo_cfg, NULL, NULL },
1641 static slap_verbmasks dangling_mode[] = {
1642 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1643 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1644 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1649 memberof_make_group_filter( memberof_t *mo )
1653 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1654 ch_free( mo->mo_groupFilterstr.bv_val );
1657 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1658 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1660 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1661 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1663 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1664 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1665 + mo->mo_oc_group->soc_cname.bv_len;
1666 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1668 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1670 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1678 memberof_make_member_filter( memberof_t *mo )
1682 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1683 ch_free( mo->mo_memberFilterstr.bv_val );
1686 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1687 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1689 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1690 + mo->mo_ad_memberof->ad_cname.bv_len;
1691 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1693 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1694 ptr = lutil_strcopy( ptr, "=*)" );
1700 mo_cf_gen( ConfigArgs *c )
1702 slap_overinst *on = (slap_overinst *)c->bi;
1703 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1707 if ( c->op == SLAP_CONFIG_EMIT ) {
1708 struct berval bv = BER_BVNULL;
1712 if ( mo->mo_dn.bv_val != NULL) {
1713 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1714 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1719 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1720 if ( BER_BVISNULL( &bv ) ) {
1721 /* there's something wrong... */
1726 value_add_one( &c->rvalue_vals, &bv );
1730 case MO_DANGLING_ERROR:
1731 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1732 char buf[ SLAP_TEXT_BUFLEN ];
1733 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1734 if ( BER_BVISNULL( &bv ) ) {
1735 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1736 if ( bv.bv_len < sizeof( buf ) ) {
1743 value_add_one( &c->rvalue_vals, &bv );
1750 c->value_int = MEMBEROF_REFINT( mo );
1755 c->value_int = MEMBEROF_REVERSE( mo );
1760 if ( mo->mo_oc_group != NULL ){
1761 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1766 if ( mo->mo_ad_member != NULL ){
1767 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1771 case MO_MEMBER_OF_AD:
1772 if ( mo->mo_ad_memberof != NULL ){
1773 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1784 } else if ( c->op == LDAP_MOD_DELETE ) {
1785 return 1; /* FIXME */
1790 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1791 ber_memfree( mo->mo_dn.bv_val );
1792 ber_memfree( mo->mo_ndn.bv_val );
1794 mo->mo_dn = c->value_dn;
1795 mo->mo_ndn = c->value_ndn;
1799 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1800 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1804 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1805 mo->mo_flags |= dangling_mode[ i ].mask;
1808 case MO_DANGLING_ERROR:
1809 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1810 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1811 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1812 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1818 if ( c->value_int ) {
1819 mo->mo_flags |= MEMBEROF_FREFINT;
1822 mo->mo_flags &= ~MEMBEROF_FREFINT;
1828 if ( c->value_int ) {
1829 mo->mo_flags |= MEMBEROF_FREVERSE;
1832 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1838 ObjectClass *oc = NULL;
1840 oc = oc_find( c->argv[ 1 ] );
1842 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1843 "unable to find group objectClass=\"%s\"",
1845 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1846 c->log, c->cr_msg, 0 );
1850 mo->mo_oc_group = oc;
1851 memberof_make_group_filter( mo );
1854 case MO_MEMBER_AD: {
1855 AttributeDescription *ad = NULL;
1856 const char *text = NULL;
1859 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1860 if ( rc != LDAP_SUCCESS ) {
1861 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1862 "unable to find member attribute=\"%s\": %s (%d)",
1863 c->argv[ 1 ], text, rc );
1864 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1865 c->log, c->cr_msg, 0 );
1869 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1870 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1872 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1873 "member attribute=\"%s\" must either "
1874 "have DN (%s) or nameUID (%s) syntax",
1875 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1876 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1877 c->log, c->cr_msg, 0 );
1881 mo->mo_ad_member = ad;
1884 case MO_MEMBER_OF_AD: {
1885 AttributeDescription *ad = NULL;
1886 const char *text = NULL;
1889 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1890 if ( rc != LDAP_SUCCESS ) {
1891 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1892 "unable to find memberof attribute=\"%s\": %s (%d)",
1893 c->argv[ 1 ], text, rc );
1894 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1895 c->log, c->cr_msg, 0 );
1899 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1900 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1902 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1903 "memberof attribute=\"%s\" must either "
1904 "have DN (%s) or nameUID (%s) syntax",
1905 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1906 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1907 c->log, c->cr_msg, 0 );
1911 mo->mo_ad_memberof = ad;
1912 memberof_make_member_filter( mo );
1929 slap_overinst *on = (slap_overinst *)be->bd_info;
1930 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1933 const char *text = NULL;
1935 if( ! mo->mo_ad_memberof ){
1936 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
1937 if ( rc != LDAP_SUCCESS ) {
1938 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1939 "unable to find attribute=\"%s\": %s (%d)\n",
1940 SLAPD_MEMBEROF_ATTR, text, rc );
1945 if( ! mo->mo_ad_member ){
1946 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &text );
1947 if ( rc != LDAP_SUCCESS ) {
1948 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
1949 "unable to find attribute=\"%s\": %s (%d)\n",
1950 SLAPD_GROUP_ATTR, text, rc );
1955 if( ! mo->mo_oc_group ){
1956 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
1957 if ( mo->mo_oc_group == NULL ) {
1958 Debug( LDAP_DEBUG_ANY,
1959 "memberof_db_open: "
1960 "unable to find objectClass=\"%s\"\n",
1961 SLAPD_GROUP_CLASS, 0, 0 );
1966 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
1967 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
1968 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
1971 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1972 memberof_make_group_filter( mo );
1975 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1976 memberof_make_member_filter( mo );
1983 memberof_db_destroy(
1987 slap_overinst *on = (slap_overinst *)be->bd_info;
1988 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1991 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1992 ber_memfree( mo->mo_dn.bv_val );
1993 ber_memfree( mo->mo_ndn.bv_val );
1996 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1997 ber_memfree( mo->mo_groupFilterstr.bv_val );
2000 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
2001 ber_memfree( mo->mo_memberFilterstr.bv_val );
2011 static AttributeDescription *ad_memberOf;
2015 AttributeDescription **adp;
2017 { "( 1.2.840.113556.1.2.102 "
2019 "DESC 'Group that the entry belongs to' "
2020 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2021 "EQUALITY distinguishedNameMatch " /* added */
2022 "USAGE dSAOperation " /* added; questioned */
2023 /* "NO-USER-MODIFICATION " */ /* add? */
2024 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2029 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2031 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2033 memberof_initialize( void )
2037 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2038 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2040 Debug( LDAP_DEBUG_ANY,
2041 "memberof_initialize: register_at #%d failed\n",
2047 memberof.on_bi.bi_type = "memberof";
2049 memberof.on_bi.bi_db_init = memberof_db_init;
2050 memberof.on_bi.bi_db_open = memberof_db_open;
2051 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2053 memberof.on_bi.bi_op_add = memberof_op_add;
2054 memberof.on_bi.bi_op_delete = memberof_op_delete;
2055 memberof.on_bi.bi_op_modify = memberof_op_modify;
2057 memberof.on_response = memberof_response;
2059 memberof.on_bi.bi_cf_ocs = mo_ocs;
2061 code = config_register_schema( mo_cfg, mo_ocs );
2062 if ( code ) return code;
2064 return overlay_register( &memberof );
2067 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2069 init_module( int argc, char *argv[] )
2071 return memberof_initialize();
2073 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2075 #endif /* SLAPD_OVER_MEMBEROF */