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)
181 typedef struct memberof_cookie_t {
182 AttributeDescription *ad;
187 typedef struct memberof_cbinfo_t {
195 memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
197 if ( rs->sr_type == REP_SEARCH ) {
198 memberof_cookie_t *mc;
200 mc = (memberof_cookie_t *)op->o_callback->sc_private;
208 * callback for internal search that saves the member attribute values
209 * of groups being deleted.
212 memberof_saveMember_cb( Operation *op, SlapReply *rs )
214 if ( rs->sr_type == REP_SEARCH ) {
215 memberof_cookie_t *mc;
218 mc = (memberof_cookie_t *)op->o_callback->sc_private;
221 assert( rs->sr_entry != NULL );
222 assert( rs->sr_entry->e_attrs != NULL );
224 a = attr_find( rs->sr_entry->e_attrs, mc->ad );
226 ber_bvarray_dup_x( &mc->vals, a->a_nvals, op->o_tmpmemctx );
228 assert( attr_find( a->a_next, mc->ad ) == NULL );
236 * the delete hook performs an internal search that saves the member
237 * attribute values of groups being deleted.
240 memberof_isGroupOrMember( Operation *op, memberof_cbinfo_t *mci )
242 slap_overinst *on = mci->on;
243 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
246 SlapReply rs2 = { REP_RESULT };
247 slap_callback cb = { 0 };
248 BackendInfo *bi = op->o_bd->bd_info;
249 AttributeName an[ 2 ];
251 memberof_is_t iswhat = MEMBEROF_IS_NONE;
252 memberof_cookie_t mc;
254 assert( mci->what != MEMBEROF_IS_NONE );
257 if ( op->o_tag == LDAP_REQ_DELETE ) {
258 cb.sc_response = memberof_saveMember_cb;
261 cb.sc_response = memberof_isGroupOrMember_cb;
264 op2.o_tag = LDAP_REQ_SEARCH;
265 op2.o_callback = &cb;
266 op2.o_dn = op->o_bd->be_rootdn;
267 op2.o_ndn = op->o_bd->be_rootndn;
269 op2.ors_scope = LDAP_SCOPE_BASE;
270 op2.ors_deref = LDAP_DEREF_NEVER;
271 BER_BVZERO( &an[ 1 ].an_name );
273 op2.ors_attrsonly = 0;
274 op2.ors_limit = NULL;
276 op2.ors_tlimit = SLAP_NO_LIMIT;
278 if ( mci->what & MEMBEROF_IS_GROUP ) {
279 mc.ad = mo->mo_ad_member;
282 an[ 0 ].an_desc = mo->mo_ad_member;
283 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
284 op2.ors_filterstr = mo->mo_groupFilterstr;
285 op2.ors_filter = &mo->mo_groupFilter;
287 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
288 (void)op->o_bd->be_search( &op2, &rs2 );
289 op2.o_bd->bd_info = bi;
292 iswhat |= MEMBEROF_IS_GROUP;
293 if ( mc.vals ) mci->member = mc.vals;
298 if ( mci->what & MEMBEROF_IS_MEMBER ) {
299 mc.ad = mo->mo_ad_memberof;
302 an[ 0 ].an_desc = mo->mo_ad_memberof;
303 an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
304 op2.ors_filterstr = mo->mo_memberFilterstr;
305 op2.ors_filter = &mo->mo_memberFilter;
307 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
308 (void)op->o_bd->be_search( &op2, &rs2 );
309 op2.o_bd->bd_info = bi;
312 iswhat |= MEMBEROF_IS_MEMBER;
313 if ( mc.vals ) mci->memberof = mc.vals;
324 * response callback that adds memberof values when a group is modified.
327 memberof_value_modify(
331 AttributeDescription *ad,
332 struct berval *old_dn,
333 struct berval *old_ndn,
334 struct berval *new_dn,
335 struct berval *new_ndn )
337 memberof_cbinfo_t *mci = op->o_callback->sc_private;
338 slap_overinst *on = mci->on;
339 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
342 SlapReply rs2 = { REP_RESULT };
343 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
344 Modifications mod[ 2 ] = { { { 0 } } }, *ml;
345 struct berval values[ 4 ], nvalues[ 4 ];
348 op2.o_tag = LDAP_REQ_MODIFY;
351 op2.o_req_ndn = *ndn;
353 op2.o_callback = &cb;
354 op2.o_dn = op->o_bd->be_rootdn;
355 op2.o_ndn = op->o_bd->be_rootndn;
356 op2.orm_modlist = NULL;
358 if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
361 ml->sml_values = &values[ 0 ];
362 ml->sml_values[ 0 ] = mo->mo_dn;
363 BER_BVZERO( &ml->sml_values[ 1 ] );
364 ml->sml_nvalues = &nvalues[ 0 ];
365 ml->sml_nvalues[ 0 ] = mo->mo_ndn;
366 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
367 ml->sml_desc = slap_schema.si_ad_modifiersName;
368 ml->sml_type = ml->sml_desc->ad_cname;
369 ml->sml_op = LDAP_MOD_REPLACE;
370 ml->sml_flags = SLAP_MOD_INTERNAL;
371 ml->sml_next = op2.orm_modlist;
372 op2.orm_modlist = ml;
379 ml->sml_values = &values[ 2 ];
380 BER_BVZERO( &ml->sml_values[ 1 ] );
381 ml->sml_nvalues = &nvalues[ 2 ];
382 BER_BVZERO( &ml->sml_nvalues[ 1 ] );
384 ml->sml_type = ml->sml_desc->ad_cname;
385 ml->sml_flags = SLAP_MOD_INTERNAL;
386 ml->sml_next = op2.orm_modlist;
387 op2.orm_modlist = ml;
388 op2.orm_no_opattrs = 0;
390 if ( new_ndn != NULL ) {
391 BackendInfo *bi = op2.o_bd->bd_info;
394 assert( !BER_BVISNULL( new_dn ) );
395 assert( !BER_BVISNULL( new_ndn ) );
398 ml->sml_op = LDAP_MOD_ADD;
400 ml->sml_values[ 0 ] = *new_dn;
401 ml->sml_nvalues[ 0 ] = *new_ndn;
403 oex.oe_key = (void *)&memberof;
404 LDAP_SLIST_INSERT_HEAD(&op2.o_extra, &oex, oe_next);
405 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
406 (void)op->o_bd->be_modify( &op2, &rs2 );
407 op2.o_bd->bd_info = bi;
408 LDAP_SLIST_REMOVE(&op2.o_extra, &oex, OpExtra, oe_next);
409 if ( rs2.sr_err != LDAP_SUCCESS ) {
410 char buf[ SLAP_TEXT_BUFLEN ];
411 snprintf( buf, sizeof( buf ),
412 "memberof_value_modify DN=\"%s\" add %s=\"%s\" failed err=%d",
413 op2.o_req_dn.bv_val, ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err );
414 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
415 op->o_log_prefix, buf, 0 );
418 assert( op2.orm_modlist == &mod[ mcnt ] );
419 assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
420 ml = op2.orm_modlist->sml_next;
422 assert( ml == &mod[ 0 ] );
426 slap_mods_free( ml, 1 );
429 mod[ 0 ].sml_next = NULL;
432 if ( old_ndn != NULL ) {
433 BackendInfo *bi = op2.o_bd->bd_info;
436 assert( !BER_BVISNULL( old_dn ) );
437 assert( !BER_BVISNULL( old_ndn ) );
440 ml->sml_op = LDAP_MOD_DELETE;
442 ml->sml_values[ 0 ] = *old_dn;
443 ml->sml_nvalues[ 0 ] = *old_ndn;
445 oex.oe_key = (void *)&memberof;
446 LDAP_SLIST_INSERT_HEAD(&op2.o_extra, &oex, oe_next);
447 op2.o_bd->bd_info = (BackendInfo *)on->on_info;
448 (void)op->o_bd->be_modify( &op2, &rs2 );
449 op2.o_bd->bd_info = bi;
450 LDAP_SLIST_REMOVE(&op2.o_extra, &oex, OpExtra, oe_next);
451 if ( rs2.sr_err != LDAP_SUCCESS ) {
452 char buf[ SLAP_TEXT_BUFLEN ];
453 snprintf( buf, sizeof( buf ),
454 "memberof_value_modify DN=\"%s\" delete %s=\"%s\" failed err=%d",
455 op2.o_req_dn.bv_val, ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err );
456 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
457 op->o_log_prefix, buf, 0 );
460 assert( op2.orm_modlist == &mod[ mcnt ] );
461 ml = op2.orm_modlist->sml_next;
463 assert( ml == &mod[ 0 ] );
467 slap_mods_free( ml, 1 );
471 /* FIXME: if old_group_ndn doesn't exist, both delete __and__
472 * add will fail; better split in two operations, although
473 * not optimal in terms of performance. At least it would
474 * move towards self-repairing capabilities. */
480 memberof_cleanup( Operation *op, SlapReply *rs )
482 slap_callback *sc = op->o_callback;
483 memberof_cbinfo_t *mci = sc->sc_private;
485 op->o_callback = sc->sc_next;
487 ber_bvarray_free_x( mci->memberof, op->o_tmpmemctx );
489 ber_bvarray_free_x( mci->member, op->o_tmpmemctx );
490 op->o_tmpfree( sc, op->o_tmpmemctx );
494 static int memberof_res_add( Operation *op, SlapReply *rs );
495 static int memberof_res_delete( Operation *op, SlapReply *rs );
496 static int memberof_res_modify( Operation *op, SlapReply *rs );
497 static int memberof_res_modrdn( Operation *op, SlapReply *rs );
500 memberof_op_add( Operation *op, SlapReply *rs )
502 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
503 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
505 Attribute **ap, **map = NULL;
506 int rc = SLAP_CB_CONTINUE;
508 struct berval save_dn, save_ndn;
510 memberof_cbinfo_t *mci;
513 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
514 if ( oex->oe_key == (void *)&memberof )
515 return SLAP_CB_CONTINUE;
518 if ( op->ora_e->e_attrs == NULL ) {
519 /* FIXME: global overlay; need to deal with */
520 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
521 "consistency checks not implemented when overlay "
522 "is instantiated as global.\n",
523 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
524 return SLAP_CB_CONTINUE;
527 if ( MEMBEROF_REVERSE( mo ) ) {
528 for ( ap = &op->ora_e->e_attrs; *ap; ap = &(*ap)->a_next ) {
531 if ( a->a_desc == mo->mo_ad_memberof ) {
539 save_ndn = op->o_ndn;
541 if ( MEMBEROF_DANGLING_CHECK( mo )
543 && is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) )
545 op->o_dn = op->o_bd->be_rootdn;
546 op->o_ndn = op->o_bd->be_rootndn;
547 op->o_bd->bd_info = (BackendInfo *)on->on_info;
549 for ( ap = &op->ora_e->e_attrs; *ap; ) {
552 if ( !is_ad_subtype( a->a_desc, mo->mo_ad_member ) ) {
557 assert( a->a_nvals != NULL );
559 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
562 /* ITS#6670 Ignore member pointing to this entry */
563 if ( dn_match( &a->a_nvals[i], &save_ndn ))
566 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
568 if ( rc == LDAP_SUCCESS ) {
569 be_entry_release_r( op, e );
573 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
574 rc = rs->sr_err = mo->mo_dangling_err;
575 rs->sr_text = "adding non-existing object "
577 send_ldap_result( op, rs );
581 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
584 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
585 "member=\"%s\" does not exist (stripping...)\n",
586 op->o_log_prefix, op->ora_e->e_name.bv_val,
587 a->a_vals[ i ].bv_val );
589 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
590 ber_memfree( a->a_vals[ i ].bv_val );
591 BER_BVZERO( &a->a_vals[ i ] );
592 if ( a->a_nvals != a->a_vals ) {
593 ber_memfree( a->a_nvals[ i ].bv_val );
594 BER_BVZERO( &a->a_nvals[ i ] );
600 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
601 sizeof( struct berval ) * ( j - i ) );
602 if ( a->a_nvals != a->a_vals ) {
603 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
604 sizeof( struct berval ) * ( j - i ) );
611 /* If all values have been removed,
612 * remove the attribute itself. */
613 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
622 op->o_ndn = save_ndn;
623 op->o_bd->bd_info = (BackendInfo *)on;
628 AccessControlState acl_state = ACL_STATE_INIT;
630 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
633 op->o_bd->bd_info = (BackendInfo *)on->on_info;
634 /* access is checked with the original identity */
635 rc = access_allowed( op, op->ora_e, mo->mo_ad_memberof,
636 &a->a_nvals[ i ], ACL_WADD,
639 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
641 send_ldap_result( op, rs );
644 /* ITS#6670 Ignore member pointing to this entry */
645 if ( dn_match( &a->a_nvals[i], &save_ndn ))
648 rc = be_entry_get_rw( op, &a->a_nvals[ i ],
650 op->o_bd->bd_info = (BackendInfo *)on;
651 if ( rc != LDAP_SUCCESS ) {
652 if ( get_relax( op ) ) {
656 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
657 rc = rs->sr_err = mo->mo_dangling_err;
658 rs->sr_text = "adding non-existing object "
660 send_ldap_result( op, rs );
664 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
667 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_add(\"%s\"): "
668 "memberof=\"%s\" does not exist (stripping...)\n",
669 op->o_log_prefix, op->ora_e->e_name.bv_val,
670 a->a_nvals[ i ].bv_val );
672 for ( j = i + 1; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ );
673 ber_memfree( a->a_vals[ i ].bv_val );
674 BER_BVZERO( &a->a_vals[ i ] );
675 if ( a->a_nvals != a->a_vals ) {
676 ber_memfree( a->a_nvals[ i ].bv_val );
677 BER_BVZERO( &a->a_nvals[ i ] );
683 AC_MEMCPY( &a->a_vals[ i ], &a->a_vals[ i + 1 ],
684 sizeof( struct berval ) * ( j - i ) );
685 if ( a->a_nvals != a->a_vals ) {
686 AC_MEMCPY( &a->a_nvals[ i ], &a->a_nvals[ i + 1 ],
687 sizeof( struct berval ) * ( j - i ) );
695 /* access is checked with the original identity */
696 op->o_bd->bd_info = (BackendInfo *)on->on_info;
697 rc = access_allowed( op, e, mo->mo_ad_member,
698 &op->o_req_ndn, ACL_WADD, NULL );
699 be_entry_release_r( op, e );
700 op->o_bd->bd_info = (BackendInfo *)on;
703 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
704 rs->sr_text = "insufficient access to object referenced by memberof";
705 send_ldap_result( op, rs );
710 if ( BER_BVISNULL( &a->a_nvals[ 0 ] ) ) {
716 rc = SLAP_CB_CONTINUE;
718 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
719 sc->sc_private = sc+1;
720 sc->sc_response = memberof_res_add;
721 sc->sc_cleanup = memberof_cleanup;
722 mci = sc->sc_private;
725 mci->memberof = NULL;
726 sc->sc_next = op->o_callback;
731 op->o_ndn = save_ndn;
732 op->o_bd->bd_info = (BackendInfo *)on;
738 memberof_op_delete( Operation *op, SlapReply *rs )
740 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
741 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
744 memberof_cbinfo_t *mci;
747 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
748 if ( oex->oe_key == (void *)&memberof )
749 return SLAP_CB_CONTINUE;
752 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
753 sc->sc_private = sc+1;
754 sc->sc_response = memberof_res_delete;
755 sc->sc_cleanup = memberof_cleanup;
756 mci = sc->sc_private;
759 mci->memberof = NULL;
760 mci->what = MEMBEROF_IS_GROUP;
761 if ( MEMBEROF_REFINT( mo ) ) {
762 mci->what = MEMBEROF_IS_BOTH;
765 memberof_isGroupOrMember( op, mci );
767 sc->sc_next = op->o_callback;
770 return SLAP_CB_CONTINUE;
774 memberof_op_modify( Operation *op, SlapReply *rs )
776 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
777 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
779 Modifications **mlp, **mmlp = NULL;
780 int rc = SLAP_CB_CONTINUE, save_member = 0;
781 struct berval save_dn, save_ndn;
783 memberof_cbinfo_t *mci, mcis;
786 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
787 if ( oex->oe_key == (void *)&memberof )
788 return SLAP_CB_CONTINUE;
791 if ( MEMBEROF_REVERSE( mo ) ) {
792 for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
793 Modifications *ml = *mlp;
795 if ( ml->sml_desc == mo->mo_ad_memberof ) {
803 save_ndn = op->o_ndn;
805 mcis.what = MEMBEROF_IS_GROUP;
807 if ( memberof_isGroupOrMember( op, &mcis ) == LDAP_SUCCESS
808 && ( mcis.what & MEMBEROF_IS_GROUP ) )
812 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
813 if ( ml->sml_desc == mo->mo_ad_member ) {
814 switch ( ml->sml_op ) {
815 case LDAP_MOD_DELETE:
816 case LDAP_MOD_REPLACE:
824 if ( MEMBEROF_DANGLING_CHECK( mo )
825 && !get_relax( op ) )
827 op->o_dn = op->o_bd->be_rootdn;
828 op->o_ndn = op->o_bd->be_rootndn;
829 op->o_bd->bd_info = (BackendInfo *)on->on_info;
831 assert( op->orm_modlist != NULL );
833 for ( mlp = &op->orm_modlist; *mlp; ) {
834 Modifications *ml = *mlp;
837 if ( !is_ad_subtype( ml->sml_desc, mo->mo_ad_member ) ) {
842 switch ( ml->sml_op ) {
843 case LDAP_MOD_DELETE:
844 /* we don't care about cancellations: if the value
845 * exists, fine; if it doesn't, we let the underlying
846 * database fail as appropriate; */
850 case LDAP_MOD_REPLACE:
851 /* Handle this just like a delete (see above) */
852 if ( !ml->sml_values ) {
858 /* NOTE: right now, the attributeType we use
859 * for member must have a normalized value */
860 assert( ml->sml_nvalues != NULL );
862 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
866 /* ITS#6670 Ignore member pointing to this entry */
867 if ( dn_match( &ml->sml_nvalues[i], &save_ndn ))
870 if ( be_entry_get_rw( op, &ml->sml_nvalues[ i ],
871 NULL, NULL, 0, &e ) == LDAP_SUCCESS )
873 be_entry_release_r( op, e );
877 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
878 rc = rs->sr_err = mo->mo_dangling_err;
879 rs->sr_text = "adding non-existing object "
881 send_ldap_result( op, rs );
885 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
888 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
889 "member=\"%s\" does not exist (stripping...)\n",
890 op->o_log_prefix, op->o_req_dn.bv_val,
891 ml->sml_nvalues[ i ].bv_val );
893 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
894 ber_memfree( ml->sml_values[ i ].bv_val );
895 BER_BVZERO( &ml->sml_values[ i ] );
896 ber_memfree( ml->sml_nvalues[ i ].bv_val );
897 BER_BVZERO( &ml->sml_nvalues[ i ] );
903 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
904 sizeof( struct berval ) * ( j - i ) );
905 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
906 sizeof( struct berval ) * ( j - i ) );
911 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
913 slap_mod_free( &ml->sml_mod, 0 );
929 if ( mmlp != NULL ) {
930 Modifications *ml = *mmlp;
934 op->o_bd->bd_info = (BackendInfo *)on->on_info;
935 rc = be_entry_get_rw( op, &op->o_req_ndn,
936 NULL, NULL, 0, &target );
937 op->o_bd->bd_info = (BackendInfo *)on;
938 if ( rc != LDAP_SUCCESS ) {
939 rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
940 send_ldap_result( op, rs );
944 switch ( ml->sml_op ) {
945 case LDAP_MOD_DELETE:
946 if ( ml->sml_nvalues != NULL ) {
947 AccessControlState acl_state = ACL_STATE_INIT;
949 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
952 op->o_bd->bd_info = (BackendInfo *)on->on_info;
953 /* access is checked with the original identity */
954 rc = access_allowed( op, target,
956 &ml->sml_nvalues[ i ],
960 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
962 send_ldap_result( op, rs );
966 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
968 op->o_bd->bd_info = (BackendInfo *)on;
969 if ( rc != LDAP_SUCCESS ) {
970 if ( get_relax( op ) ) {
974 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
975 rc = rs->sr_err = mo->mo_dangling_err;
976 rs->sr_text = "deleting non-existing object "
978 send_ldap_result( op, rs );
982 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
985 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
986 "memberof=\"%s\" does not exist (stripping...)\n",
987 op->o_log_prefix, op->o_req_ndn.bv_val,
988 ml->sml_nvalues[ i ].bv_val );
990 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
991 ber_memfree( ml->sml_values[ i ].bv_val );
992 BER_BVZERO( &ml->sml_values[ i ] );
993 if ( ml->sml_nvalues != ml->sml_values ) {
994 ber_memfree( ml->sml_nvalues[ i ].bv_val );
995 BER_BVZERO( &ml->sml_nvalues[ i ] );
1002 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1003 sizeof( struct berval ) * ( j - i ) );
1004 if ( ml->sml_nvalues != ml->sml_values ) {
1005 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1006 sizeof( struct berval ) * ( j - i ) );
1014 /* access is checked with the original identity */
1015 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1016 rc = access_allowed( op, e, mo->mo_ad_member,
1019 be_entry_release_r( op, e );
1020 op->o_bd->bd_info = (BackendInfo *)on;
1023 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1024 rs->sr_text = "insufficient access to object referenced by memberof";
1025 send_ldap_result( op, rs );
1030 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1031 *mmlp = ml->sml_next;
1032 slap_mod_free( &ml->sml_mod, 0 );
1040 case LDAP_MOD_REPLACE:
1042 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1043 /* access is checked with the original identity */
1044 rc = access_allowed( op, target,
1048 op->o_bd->bd_info = (BackendInfo *)on;
1050 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1052 send_ldap_result( op, rs );
1056 if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
1061 case LDAP_MOD_ADD: {
1062 AccessControlState acl_state = ACL_STATE_INIT;
1064 for ( i = 0; !BER_BVISNULL( &ml->sml_nvalues[ i ] ); i++ ) {
1067 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1068 /* access is checked with the original identity */
1069 rc = access_allowed( op, target,
1071 &ml->sml_nvalues[ i ],
1075 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1077 send_ldap_result( op, rs );
1081 /* ITS#6670 Ignore member pointing to this entry */
1082 if ( dn_match( &ml->sml_nvalues[i], &save_ndn ))
1085 rc = be_entry_get_rw( op, &ml->sml_nvalues[ i ],
1086 NULL, NULL, 0, &e );
1087 op->o_bd->bd_info = (BackendInfo *)on;
1088 if ( rc != LDAP_SUCCESS ) {
1089 if ( MEMBEROF_DANGLING_ERROR( mo ) ) {
1090 rc = rs->sr_err = mo->mo_dangling_err;
1091 rs->sr_text = "adding non-existing object "
1093 send_ldap_result( op, rs );
1097 if ( MEMBEROF_DANGLING_DROP( mo ) ) {
1100 Debug( LDAP_DEBUG_ANY, "%s: memberof_op_modify(\"%s\"): "
1101 "memberof=\"%s\" does not exist (stripping...)\n",
1102 op->o_log_prefix, op->o_req_ndn.bv_val,
1103 ml->sml_nvalues[ i ].bv_val );
1105 for ( j = i + 1; !BER_BVISNULL( &ml->sml_nvalues[ j ] ); j++ );
1106 ber_memfree( ml->sml_values[ i ].bv_val );
1107 BER_BVZERO( &ml->sml_values[ i ] );
1108 if ( ml->sml_nvalues != ml->sml_values ) {
1109 ber_memfree( ml->sml_nvalues[ i ].bv_val );
1110 BER_BVZERO( &ml->sml_nvalues[ i ] );
1117 AC_MEMCPY( &ml->sml_values[ i ], &ml->sml_values[ i + 1 ],
1118 sizeof( struct berval ) * ( j - i ) );
1119 if ( ml->sml_nvalues != ml->sml_values ) {
1120 AC_MEMCPY( &ml->sml_nvalues[ i ], &ml->sml_nvalues[ i + 1 ],
1121 sizeof( struct berval ) * ( j - i ) );
1129 /* access is checked with the original identity */
1130 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1131 rc = access_allowed( op, e, mo->mo_ad_member,
1134 be_entry_release_r( op, e );
1135 op->o_bd->bd_info = (BackendInfo *)on;
1138 rc = rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
1139 rs->sr_text = "insufficient access to object referenced by memberof";
1140 send_ldap_result( op, rs );
1145 if ( BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
1146 *mmlp = ml->sml_next;
1147 slap_mod_free( &ml->sml_mod, 0 );
1158 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1159 be_entry_release_r( op, target );
1160 op->o_bd->bd_info = (BackendInfo *)on;
1163 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
1164 sc->sc_private = sc+1;
1165 sc->sc_response = memberof_res_modify;
1166 sc->sc_cleanup = memberof_cleanup;
1167 mci = sc->sc_private;
1170 mci->memberof = NULL;
1171 mci->what = mcis.what;
1173 if ( save_member ) {
1174 op->o_dn = op->o_bd->be_rootdn;
1175 op->o_ndn = op->o_bd->be_rootndn;
1176 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1177 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1178 mo->mo_ad_member, &mci->member, ACL_READ );
1179 op->o_bd->bd_info = (BackendInfo *)on;
1182 sc->sc_next = op->o_callback;
1183 op->o_callback = sc;
1185 rc = SLAP_CB_CONTINUE;
1189 op->o_ndn = save_ndn;
1190 op->o_bd->bd_info = (BackendInfo *)on;
1196 memberof_op_modrdn( Operation *op, SlapReply *rs )
1198 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1200 memberof_cbinfo_t *mci;
1203 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
1204 if ( oex->oe_key == (void *)&memberof )
1205 return SLAP_CB_CONTINUE;
1208 sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
1209 sc->sc_private = sc+1;
1210 sc->sc_response = memberof_res_modrdn;
1211 sc->sc_cleanup = memberof_cleanup;
1212 mci = sc->sc_private;
1215 mci->memberof = NULL;
1217 sc->sc_next = op->o_callback;
1218 op->o_callback = sc;
1220 return SLAP_CB_CONTINUE;
1224 * response callback that adds memberof values when a group is added.
1227 memberof_res_add( Operation *op, SlapReply *rs )
1229 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1230 slap_overinst *on = mci->on;
1231 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1235 if ( rs->sr_err != LDAP_SUCCESS ) {
1236 return SLAP_CB_CONTINUE;
1239 if ( MEMBEROF_REVERSE( mo ) ) {
1242 ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
1244 char relax = op->o_relax;
1246 /* relax is required to allow to add
1247 * a non-existing member */
1248 op->o_relax = SLAP_CONTROL_CRITICAL;
1250 for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
1252 /* ITS#6670 Ignore member pointing to this entry */
1253 if ( dn_match( &ma->a_nvals[i], &op->o_req_ndn ))
1256 /* the modification is attempted
1257 * with the original identity */
1258 (void)memberof_value_modify( op, rs,
1259 &ma->a_nvals[ i ], mo->mo_ad_member,
1260 NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
1265 if ( is_entry_objectclass_or_sub( op->ora_e, mo->mo_oc_group ) ) {
1268 for ( a = attrs_find( op->ora_e->e_attrs, mo->mo_ad_member );
1270 a = attrs_find( a->a_next, mo->mo_ad_member ) )
1272 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
1273 /* ITS#6670 Ignore member pointing to this entry */
1274 if ( dn_match( &a->a_nvals[i], &op->o_req_ndn ))
1277 (void)memberof_value_modify( op, rs,
1287 return SLAP_CB_CONTINUE;
1291 * response callback that deletes memberof values when a group is deleted.
1294 memberof_res_delete( Operation *op, SlapReply *rs )
1296 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1297 slap_overinst *on = mci->on;
1298 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1303 if ( rs->sr_err != LDAP_SUCCESS ) {
1304 return SLAP_CB_CONTINUE;
1308 if ( vals != NULL ) {
1309 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1310 (void)memberof_value_modify( op, rs,
1311 &vals[ i ], mo->mo_ad_memberof,
1312 &op->o_req_dn, &op->o_req_ndn,
1317 if ( MEMBEROF_REFINT( mo ) ) {
1318 vals = mci->memberof;
1319 if ( vals != NULL ) {
1320 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1321 (void)memberof_value_modify( op, rs,
1322 &vals[ i ], mo->mo_ad_member,
1323 &op->o_req_dn, &op->o_req_ndn,
1329 return SLAP_CB_CONTINUE;
1333 * response callback that adds/deletes memberof values when a group
1337 memberof_res_modify( Operation *op, SlapReply *rs )
1339 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1340 slap_overinst *on = mci->on;
1341 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1344 Modifications *ml, *mml = NULL;
1347 if ( rs->sr_err != LDAP_SUCCESS ) {
1348 return SLAP_CB_CONTINUE;
1351 if ( MEMBEROF_REVERSE( mo ) ) {
1352 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1353 if ( ml->sml_desc == mo->mo_ad_memberof ) {
1360 if ( mml != NULL ) {
1361 BerVarray vals = mml->sml_nvalues;
1363 switch ( mml->sml_op ) {
1364 case LDAP_MOD_DELETE:
1365 if ( vals != NULL ) {
1366 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1367 memberof_value_modify( op, rs,
1368 &vals[ i ], mo->mo_ad_member,
1369 &op->o_req_dn, &op->o_req_ndn,
1376 case LDAP_MOD_REPLACE:
1377 /* delete all ... */
1378 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1379 rc = backend_attribute( op, NULL, &op->o_req_ndn,
1380 mo->mo_ad_memberof, &vals, ACL_READ );
1381 op->o_bd->bd_info = (BackendInfo *)on;
1382 if ( rc == LDAP_SUCCESS ) {
1383 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1384 (void)memberof_value_modify( op, rs,
1385 &vals[ i ], mo->mo_ad_member,
1386 &op->o_req_dn, &op->o_req_ndn,
1389 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1392 if ( ml->sml_op == LDAP_MOD_DELETE || !mml->sml_values ) {
1398 assert( vals != NULL );
1400 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1401 memberof_value_modify( op, rs,
1402 &vals[ i ], mo->mo_ad_member,
1404 &op->o_req_dn, &op->o_req_ndn );
1413 if ( mci->what & MEMBEROF_IS_GROUP )
1415 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
1416 if ( ml->sml_desc != mo->mo_ad_member ) {
1420 switch ( ml->sml_op ) {
1421 case LDAP_MOD_DELETE:
1422 vals = ml->sml_nvalues;
1423 if ( vals != NULL ) {
1424 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1425 memberof_value_modify( op, rs,
1426 &vals[ i ], mo->mo_ad_memberof,
1427 &op->o_req_dn, &op->o_req_ndn,
1434 case LDAP_MOD_REPLACE:
1437 /* delete all ... */
1438 if ( vals != NULL ) {
1439 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1440 (void)memberof_value_modify( op, rs,
1441 &vals[ i ], mo->mo_ad_memberof,
1442 &op->o_req_dn, &op->o_req_ndn,
1447 if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
1453 assert( ml->sml_nvalues != NULL );
1454 vals = ml->sml_nvalues;
1455 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1456 memberof_value_modify( op, rs,
1457 &vals[ i ], mo->mo_ad_memberof,
1459 &op->o_req_dn, &op->o_req_ndn );
1469 return SLAP_CB_CONTINUE;
1473 * response callback that adds/deletes member values when a group member
1477 memberof_res_modrdn( Operation *op, SlapReply *rs )
1479 memberof_cbinfo_t *mci = op->o_callback->sc_private;
1480 slap_overinst *on = mci->on;
1481 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1483 struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
1487 struct berval save_dn, save_ndn;
1489 if ( rs->sr_err != LDAP_SUCCESS ) {
1490 return SLAP_CB_CONTINUE;
1493 mci->what = MEMBEROF_IS_GROUP;
1494 if ( MEMBEROF_REFINT( mo ) ) {
1495 mci->what |= MEMBEROF_IS_MEMBER;
1498 if ( op->orr_nnewSup ) {
1499 newPNDN = *op->orr_nnewSup;
1502 dnParent( &op->o_req_ndn, &newPNDN );
1505 build_new_dn( &newNDN, &newPNDN, &op->orr_nnewrdn, op->o_tmpmemctx );
1507 save_dn = op->o_req_dn;
1508 save_ndn = op->o_req_ndn;
1510 op->o_req_dn = newNDN;
1511 op->o_req_ndn = newNDN;
1512 rc = memberof_isGroupOrMember( op, mci );
1513 op->o_req_dn = save_dn;
1514 op->o_req_ndn = save_ndn;
1516 if ( rc != LDAP_SUCCESS || mci->what == MEMBEROF_IS_NONE ) {
1520 if ( op->orr_newSup ) {
1521 newPDN = *op->orr_newSup;
1524 dnParent( &op->o_req_dn, &newPDN );
1527 build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx );
1529 if ( mci->what & MEMBEROF_IS_GROUP ) {
1530 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1531 rc = backend_attribute( op, NULL, &newNDN,
1532 mo->mo_ad_member, &vals, ACL_READ );
1533 op->o_bd->bd_info = (BackendInfo *)on;
1535 if ( rc == LDAP_SUCCESS ) {
1536 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1537 (void)memberof_value_modify( op, rs,
1538 &vals[ i ], mo->mo_ad_memberof,
1539 &op->o_req_dn, &op->o_req_ndn,
1542 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1546 if ( MEMBEROF_REFINT( mo ) && ( mci->what & MEMBEROF_IS_MEMBER ) ) {
1547 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1548 rc = backend_attribute( op, NULL, &newNDN,
1549 mo->mo_ad_memberof, &vals, ACL_READ );
1550 op->o_bd->bd_info = (BackendInfo *)on;
1552 if ( rc == LDAP_SUCCESS ) {
1553 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1554 (void)memberof_value_modify( op, rs,
1555 &vals[ i ], mo->mo_ad_member,
1556 &op->o_req_dn, &op->o_req_ndn,
1559 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1564 if ( !BER_BVISNULL( &newDN ) ) {
1565 op->o_tmpfree( newDN.bv_val, op->o_tmpmemctx );
1567 op->o_tmpfree( newNDN.bv_val, op->o_tmpmemctx );
1569 return SLAP_CB_CONTINUE;
1578 slap_overinst *on = (slap_overinst *)be->bd_info;
1581 mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
1584 mo->mo_dangling_err = LDAP_CONSTRAINT_VIOLATION;
1586 on->on_bi.bi_private = (void *)mo;
1607 static ConfigDriver mo_cf_gen;
1609 #define OID "1.3.6.1.4.1.7136.2.666.4"
1610 #define OIDAT OID ".1.1"
1611 #define OIDCFGAT OID ".1.2"
1612 #define OIDOC OID ".2.1"
1613 #define OIDCFGOC OID ".2.2"
1616 static ConfigTable mo_cfg[] = {
1617 { "memberof-dn", "modifiersName",
1618 2, 2, 0, ARG_MAGIC|ARG_DN|MO_DN, mo_cf_gen,
1619 "( OLcfgOvAt:18.0 NAME 'olcMemberOfDN' "
1620 "DESC 'DN to be used as modifiersName' "
1621 "SYNTAX OMsDN SINGLE-VALUE )",
1624 { "memberof-dangling", "ignore|drop|error",
1625 2, 2, 0, ARG_MAGIC|MO_DANGLING, mo_cf_gen,
1626 "( OLcfgOvAt:18.1 NAME 'olcMemberOfDangling' "
1627 "DESC 'Behavior with respect to dangling members, "
1628 "constrained to ignore, drop, error' "
1629 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1632 { "memberof-refint", "true|FALSE",
1633 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REFINT, mo_cf_gen,
1634 "( OLcfgOvAt:18.2 NAME 'olcMemberOfRefInt' "
1635 "DESC 'Take care of referential integrity' "
1636 "SYNTAX OMsBoolean SINGLE-VALUE )",
1639 { "memberof-group-oc", "objectClass",
1640 2, 2, 0, ARG_MAGIC|MO_GROUP_OC, mo_cf_gen,
1641 "( OLcfgOvAt:18.3 NAME 'olcMemberOfGroupOC' "
1642 "DESC 'Group objectClass' "
1643 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1646 { "memberof-member-ad", "member attribute",
1647 2, 2, 0, ARG_MAGIC|MO_MEMBER_AD, mo_cf_gen,
1648 "( OLcfgOvAt:18.4 NAME 'olcMemberOfMemberAD' "
1649 "DESC 'member attribute' "
1650 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1653 { "memberof-memberof-ad", "memberOf attribute",
1654 2, 2, 0, ARG_MAGIC|MO_MEMBER_OF_AD, mo_cf_gen,
1655 "( OLcfgOvAt:18.5 NAME 'olcMemberOfMemberOfAD' "
1656 "DESC 'memberOf attribute' "
1657 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1661 { "memberof-reverse", "true|FALSE",
1662 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|MO_REVERSE, mo_cf_gen,
1663 "( OLcfgOvAt:18.6 NAME 'olcMemberOfReverse' "
1664 "DESC 'Take care of referential integrity "
1665 "also when directly modifying memberOf' "
1666 "SYNTAX OMsBoolean SINGLE-VALUE )",
1670 { "memberof-dangling-error", "error code",
1671 2, 2, 0, ARG_MAGIC|MO_DANGLING_ERROR, mo_cf_gen,
1672 "( OLcfgOvAt:18.7 NAME 'olcMemberOfDanglingError' "
1673 "DESC 'Error code returned in case of dangling back reference' "
1674 "SYNTAX OMsDirectoryString SINGLE-VALUE )",
1677 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1680 static ConfigOCs mo_ocs[] = {
1681 { "( OLcfgOvOc:18.1 "
1682 "NAME 'olcMemberOf' "
1683 "DESC 'Member-of configuration' "
1684 "SUP olcOverlayConfig "
1687 "$ olcMemberOfDangling "
1688 "$ olcMemberOfDanglingError"
1689 "$ olcMemberOfRefInt "
1690 "$ olcMemberOfGroupOC "
1691 "$ olcMemberOfMemberAD "
1692 "$ olcMemberOfMemberOfAD "
1694 "$ olcMemberOfReverse "
1698 Cft_Overlay, mo_cfg, NULL, NULL },
1702 static slap_verbmasks dangling_mode[] = {
1703 { BER_BVC( "ignore" ), MEMBEROF_NONE },
1704 { BER_BVC( "drop" ), MEMBEROF_FDANGLING_DROP },
1705 { BER_BVC( "error" ), MEMBEROF_FDANGLING_ERROR },
1710 memberof_make_group_filter( memberof_t *mo )
1714 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
1715 ch_free( mo->mo_groupFilterstr.bv_val );
1718 mo->mo_groupFilter.f_choice = LDAP_FILTER_EQUALITY;
1719 mo->mo_groupFilter.f_ava = &mo->mo_groupAVA;
1721 mo->mo_groupFilter.f_av_desc = slap_schema.si_ad_objectClass;
1722 mo->mo_groupFilter.f_av_value = mo->mo_oc_group->soc_cname;
1724 mo->mo_groupFilterstr.bv_len = STRLENOF( "(=)" )
1725 + slap_schema.si_ad_objectClass->ad_cname.bv_len
1726 + mo->mo_oc_group->soc_cname.bv_len;
1727 ptr = mo->mo_groupFilterstr.bv_val = ch_malloc( mo->mo_groupFilterstr.bv_len + 1 );
1729 ptr = lutil_strcopy( ptr, slap_schema.si_ad_objectClass->ad_cname.bv_val );
1731 ptr = lutil_strcopy( ptr, mo->mo_oc_group->soc_cname.bv_val );
1739 memberof_make_member_filter( memberof_t *mo )
1743 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
1744 ch_free( mo->mo_memberFilterstr.bv_val );
1747 mo->mo_memberFilter.f_choice = LDAP_FILTER_PRESENT;
1748 mo->mo_memberFilter.f_desc = mo->mo_ad_memberof;
1750 mo->mo_memberFilterstr.bv_len = STRLENOF( "(=*)" )
1751 + mo->mo_ad_memberof->ad_cname.bv_len;
1752 ptr = mo->mo_memberFilterstr.bv_val = ch_malloc( mo->mo_memberFilterstr.bv_len + 1 );
1754 ptr = lutil_strcopy( ptr, mo->mo_ad_memberof->ad_cname.bv_val );
1755 ptr = lutil_strcopy( ptr, "=*)" );
1761 mo_cf_gen( ConfigArgs *c )
1763 slap_overinst *on = (slap_overinst *)c->bi;
1764 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1768 if ( c->op == SLAP_CONFIG_EMIT ) {
1769 struct berval bv = BER_BVNULL;
1773 if ( mo->mo_dn.bv_val != NULL) {
1774 value_add_one( &c->rvalue_vals, &mo->mo_dn );
1775 value_add_one( &c->rvalue_nvals, &mo->mo_ndn );
1780 enum_to_verb( dangling_mode, (mo->mo_flags & MEMBEROF_FDANGLING_MASK), &bv );
1781 if ( BER_BVISNULL( &bv ) ) {
1782 /* there's something wrong... */
1787 value_add_one( &c->rvalue_vals, &bv );
1791 case MO_DANGLING_ERROR:
1792 if ( mo->mo_flags & MEMBEROF_FDANGLING_ERROR ) {
1793 char buf[ SLAP_TEXT_BUFLEN ];
1794 enum_to_verb( slap_ldap_response_code, mo->mo_dangling_err, &bv );
1795 if ( BER_BVISNULL( &bv ) ) {
1796 bv.bv_len = snprintf( buf, sizeof( buf ), "0x%x", mo->mo_dangling_err );
1797 if ( bv.bv_len < sizeof( buf ) ) {
1804 value_add_one( &c->rvalue_vals, &bv );
1811 c->value_int = MEMBEROF_REFINT( mo );
1816 c->value_int = MEMBEROF_REVERSE( mo );
1821 if ( mo->mo_oc_group != NULL ){
1822 value_add_one( &c->rvalue_vals, &mo->mo_oc_group->soc_cname );
1827 if ( mo->mo_ad_member != NULL ){
1828 value_add_one( &c->rvalue_vals, &mo->mo_ad_member->ad_cname );
1832 case MO_MEMBER_OF_AD:
1833 if ( mo->mo_ad_memberof != NULL ){
1834 value_add_one( &c->rvalue_vals, &mo->mo_ad_memberof->ad_cname );
1845 } else if ( c->op == LDAP_MOD_DELETE ) {
1846 return 1; /* FIXME */
1851 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
1852 ber_memfree( mo->mo_dn.bv_val );
1853 ber_memfree( mo->mo_ndn.bv_val );
1855 mo->mo_dn = c->value_dn;
1856 mo->mo_ndn = c->value_ndn;
1860 i = verb_to_mask( c->argv[ 1 ], dangling_mode );
1861 if ( BER_BVISNULL( &dangling_mode[ i ].word ) ) {
1865 mo->mo_flags &= ~MEMBEROF_FDANGLING_MASK;
1866 mo->mo_flags |= dangling_mode[ i ].mask;
1869 case MO_DANGLING_ERROR:
1870 i = verb_to_mask( c->argv[ 1 ], slap_ldap_response_code );
1871 if ( !BER_BVISNULL( &slap_ldap_response_code[ i ].word ) ) {
1872 mo->mo_dangling_err = slap_ldap_response_code[ i ].mask;
1873 } else if ( lutil_atoix( &mo->mo_dangling_err, c->argv[ 1 ], 0 ) ) {
1879 if ( c->value_int ) {
1880 mo->mo_flags |= MEMBEROF_FREFINT;
1883 mo->mo_flags &= ~MEMBEROF_FREFINT;
1889 if ( c->value_int ) {
1890 mo->mo_flags |= MEMBEROF_FREVERSE;
1893 mo->mo_flags &= ~MEMBEROF_FREVERSE;
1899 ObjectClass *oc = NULL;
1901 oc = oc_find( c->argv[ 1 ] );
1903 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1904 "unable to find group objectClass=\"%s\"",
1906 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1907 c->log, c->cr_msg, 0 );
1911 mo->mo_oc_group = oc;
1912 memberof_make_group_filter( mo );
1915 case MO_MEMBER_AD: {
1916 AttributeDescription *ad = NULL;
1917 const char *text = NULL;
1920 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1921 if ( rc != LDAP_SUCCESS ) {
1922 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1923 "unable to find member attribute=\"%s\": %s (%d)",
1924 c->argv[ 1 ], text, rc );
1925 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1926 c->log, c->cr_msg, 0 );
1930 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1931 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1933 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1934 "member attribute=\"%s\" must either "
1935 "have DN (%s) or nameUID (%s) syntax",
1936 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1937 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1938 c->log, c->cr_msg, 0 );
1942 mo->mo_ad_member = ad;
1945 case MO_MEMBER_OF_AD: {
1946 AttributeDescription *ad = NULL;
1947 const char *text = NULL;
1950 rc = slap_str2ad( c->argv[ 1 ], &ad, &text );
1951 if ( rc != LDAP_SUCCESS ) {
1952 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1953 "unable to find memberof attribute=\"%s\": %s (%d)",
1954 c->argv[ 1 ], text, rc );
1955 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1956 c->log, c->cr_msg, 0 );
1960 if ( !is_at_syntax( ad->ad_type, SLAPD_DN_SYNTAX ) /* e.g. "member" */
1961 && !is_at_syntax( ad->ad_type, SLAPD_NAMEUID_SYNTAX ) ) /* e.g. "uniqueMember" */
1963 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1964 "memberof attribute=\"%s\" must either "
1965 "have DN (%s) or nameUID (%s) syntax",
1966 c->argv[ 1 ], SLAPD_DN_SYNTAX, SLAPD_NAMEUID_SYNTAX );
1967 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n",
1968 c->log, c->cr_msg, 0 );
1972 mo->mo_ad_memberof = ad;
1973 memberof_make_member_filter( mo );
1990 slap_overinst *on = (slap_overinst *)be->bd_info;
1991 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
1994 const char *text = NULL;
1996 if( ! mo->mo_ad_memberof ){
1997 rc = slap_str2ad( SLAPD_MEMBEROF_ATTR, &mo->mo_ad_memberof, &text );
1998 if ( rc != LDAP_SUCCESS ) {
1999 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
2000 "unable to find attribute=\"%s\": %s (%d)\n",
2001 SLAPD_MEMBEROF_ATTR, text, rc );
2006 if( ! mo->mo_ad_member ){
2007 rc = slap_str2ad( SLAPD_GROUP_ATTR, &mo->mo_ad_member, &text );
2008 if ( rc != LDAP_SUCCESS ) {
2009 Debug( LDAP_DEBUG_ANY, "memberof_db_open: "
2010 "unable to find attribute=\"%s\": %s (%d)\n",
2011 SLAPD_GROUP_ATTR, text, rc );
2016 if( ! mo->mo_oc_group ){
2017 mo->mo_oc_group = oc_find( SLAPD_GROUP_CLASS );
2018 if ( mo->mo_oc_group == NULL ) {
2019 Debug( LDAP_DEBUG_ANY,
2020 "memberof_db_open: "
2021 "unable to find objectClass=\"%s\"\n",
2022 SLAPD_GROUP_CLASS, 0, 0 );
2027 if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
2028 ber_dupbv( &mo->mo_dn, &be->be_rootdn );
2029 ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
2032 if ( BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
2033 memberof_make_group_filter( mo );
2036 if ( BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
2037 memberof_make_member_filter( mo );
2044 memberof_db_destroy(
2048 slap_overinst *on = (slap_overinst *)be->bd_info;
2049 memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
2052 if ( !BER_BVISNULL( &mo->mo_dn ) ) {
2053 ber_memfree( mo->mo_dn.bv_val );
2054 ber_memfree( mo->mo_ndn.bv_val );
2057 if ( !BER_BVISNULL( &mo->mo_groupFilterstr ) ) {
2058 ber_memfree( mo->mo_groupFilterstr.bv_val );
2061 if ( !BER_BVISNULL( &mo->mo_memberFilterstr ) ) {
2062 ber_memfree( mo->mo_memberFilterstr.bv_val );
2072 static AttributeDescription *ad_memberOf;
2076 AttributeDescription **adp;
2078 { "( 1.2.840.113556.1.2.102 "
2080 "DESC 'Group that the entry belongs to' "
2081 "SYNTAX '1.3.6.1.4.1.1466.115.121.1.12' "
2082 "EQUALITY distinguishedNameMatch " /* added */
2083 "USAGE dSAOperation " /* added; questioned */
2084 /* "NO-USER-MODIFICATION " */ /* add? */
2085 "X-ORIGIN 'iPlanet Delegated Administrator' )",
2090 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2092 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2094 memberof_initialize( void )
2098 for ( i = 0; as[ i ].desc != NULL; i++ ) {
2099 code = register_at( as[ i ].desc, as[ i ].adp, 0 );
2101 Debug( LDAP_DEBUG_ANY,
2102 "memberof_initialize: register_at #%d failed\n",
2108 memberof.on_bi.bi_type = "memberof";
2110 memberof.on_bi.bi_db_init = memberof_db_init;
2111 memberof.on_bi.bi_db_open = memberof_db_open;
2112 memberof.on_bi.bi_db_destroy = memberof_db_destroy;
2114 memberof.on_bi.bi_op_add = memberof_op_add;
2115 memberof.on_bi.bi_op_delete = memberof_op_delete;
2116 memberof.on_bi.bi_op_modify = memberof_op_modify;
2117 memberof.on_bi.bi_op_modrdn = memberof_op_modrdn;
2119 memberof.on_bi.bi_cf_ocs = mo_ocs;
2121 code = config_register_schema( mo_cfg, mo_ocs );
2122 if ( code ) return code;
2124 return overlay_register( &memberof );
2127 #if SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC
2129 init_module( int argc, char *argv[] )
2131 return memberof_initialize();
2133 #endif /* SLAPD_OVER_MEMBEROF == SLAPD_MOD_DYNAMIC */
2135 #endif /* SLAPD_OVER_MEMBEROF */