1 /* acl.c - routines to parse and check acl's */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
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>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
32 #include <ac/socket.h>
33 #include <ac/string.h>
40 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
42 static const struct berval acl_bv_ip_eq = BER_BVC( "IP=" );
44 static const struct berval acl_bv_path_eq = BER_BVC("PATH=");
45 #endif /* LDAP_PF_LOCAL */
47 static AccessControl * slap_acl_get(
48 AccessControl *ac, int *count,
49 Operation *op, Entry *e,
50 AttributeDescription *desc,
52 int nmatch, regmatch_t *matches,
53 AccessControlState *state );
55 static slap_control_t slap_acl_mask(
56 AccessControl *ac, slap_mask_t *mask,
57 Operation *op, Entry *e,
58 AttributeDescription *desc,
63 AccessControlState *state );
65 static int regex_matches(
66 struct berval *pat, char *str, char *buf,
67 int nmatch, regmatch_t *matches);
69 typedef struct AclSetCookie {
71 #define asc_op asc_cookie.set_op
75 SLAP_SET_GATHER acl_set_gather;
76 SLAP_SET_GATHER acl_set_gather2;
79 * access_allowed - check whether op->o_ndn is allowed the requested access
80 * to entry e, attribute attr, value val. if val is null, access to
81 * the whole attribute is assumed (all values).
83 * This routine loops through all access controls and calls
84 * slap_acl_mask() on each applicable access control.
85 * The loop exits when a definitive answer is reached or
86 * or no more controls remain.
93 * - can be legally called with op == NULL
94 * - can be legally called with op->o_bd == NULL
97 #ifdef SLAP_OVERLAY_ACCESS
99 slap_access_always_allowed(
102 AttributeDescription *desc,
104 slap_access_t access,
105 AccessControlState *state,
108 assert( maskp != NULL );
111 ACL_LVL_ASSIGN_MANAGE( *maskp );
120 AttributeDescription *desc,
122 slap_access_t access,
123 AccessControlState *state,
128 AccessControl *a = NULL;
131 char accessmaskbuf[ACCESSMASK_MAXLEN];
134 slap_control_t control;
135 slap_access_t access_level;
137 regmatch_t matches[MAXREMATCHES];
138 int st_same_attr = 0;
140 assert( op != NULL );
142 assert( desc != NULL );
143 assert( maskp != NULL );
145 access_level = ACL_LEVEL( access );
146 attr = desc->ad_cname.bv_val;
148 assert( attr != NULL );
152 /* grant database root access */
153 if ( be_isroot( op ) ) {
154 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
155 mask = ACL_LVL_MANAGE;
160 * no-user-modification operational attributes are ignored
161 * by ACL_WRITE checking as any found here are not provided
164 * NOTE: but they are not ignored for ACL_MANAGE, because
165 * if we get here it means a non-root user is trying to
166 * manage data, so we need to check its privileges.
168 if ( access_level == ACL_WRITE
169 && is_at_no_user_mod( desc->ad_type )
170 && desc != slap_schema.si_ad_entry
171 && desc != slap_schema.si_ad_children )
173 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
174 " %s access granted\n",
179 /* use backend default access if no backend acls */
180 if ( op->o_bd->be_acl == NULL ) {
183 Debug( LDAP_DEBUG_ACL,
184 "=> slap_access_allowed: backend default %s "
185 "access %s to \"%s\"\n",
186 access2str( access ),
187 op->o_bd->be_dfltaccess >= access_level ? "granted" : "denied",
188 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
189 ret = op->o_bd->be_dfltaccess >= access_level;
191 mask = ACL_PRIV_LEVEL;
192 for ( i = ACL_NONE; i <= op->o_bd->be_dfltaccess; i++ ) {
193 ACL_PRIV_SET( mask, ACL_ACCESS2PRIV( i ) );
202 if ( st_same_attr ) {
203 assert( state->as_vd_acl != NULL );
205 a = state->as_vd_acl;
206 count = state->as_vd_acl_count;
207 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
208 mask = state->as_vd_acl_mask;
209 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
214 if ( state ) state->as_vi_acl = NULL;
216 ACL_PRIV_ASSIGN( mask, *maskp );
218 memset( matches, '\0', sizeof( matches ) );
221 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
222 MAXREMATCHES, matches, state ) ) != NULL )
226 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
227 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
228 (int)matches[i].rm_so, (int)matches[i].rm_eo );
229 if ( matches[i].rm_so <= matches[0].rm_eo ) {
231 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
232 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
235 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
239 if ( state->as_vi_acl == a &&
240 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
242 Debug( LDAP_DEBUG_ACL,
243 "=> slap_access_allowed: result from state (%s)\n",
245 ret = state->as_result;
248 Debug( LDAP_DEBUG_ACL,
249 "=> slap_access_allowed: no res from state (%s)\n",
255 control = slap_acl_mask( a, &mask, op,
256 e, desc, val, MAXREMATCHES, matches, count, state );
258 if ( control != ACL_BREAK ) {
262 memset( matches, '\0', sizeof( matches ) );
265 if ( ACL_IS_INVALID( mask ) ) {
266 Debug( LDAP_DEBUG_ACL,
267 "=> slap_access_allowed: \"%s\" (%s) invalid!\n",
269 ACL_PRIV_ASSIGN( mask, *maskp );
271 } else if ( control == ACL_BREAK ) {
272 Debug( LDAP_DEBUG_ACL,
273 "=> slap_access_allowed: no more rules\n", 0, 0, 0 );
278 ret = ACL_GRANT( mask, access );
280 Debug( LDAP_DEBUG_ACL,
281 "=> slap_access_allowed: %s access %s by %s\n",
282 access2str( access ), ret ? "granted" : "denied",
283 accessmask2str( mask, accessmaskbuf, 1 ) );
286 ACL_PRIV_ASSIGN( *maskp, mask );
294 AttributeDescription *desc,
296 slap_access_t access,
297 AccessControlState *state,
304 * NOTE: control gets here if FIXME
305 * if an appropriate backend cannot be selected for the operation,
306 * we assume that the frontend should handle this
307 * FIXME: should select_backend() take care of this,
308 * and return frontendDB instead of NULL? maybe for some value
313 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
314 if ( op->o_bd == NULL ) {
315 op->o_bd = frontendDB;
317 rc = slap_access_allowed( op, e, desc, val, access, state, maskp );
327 AttributeDescription *desc,
329 slap_access_t access,
330 AccessControlState *state,
334 AccessControl *a = NULL;
338 char accessmaskbuf[ACCESSMASK_MAXLEN];
341 slap_access_t access_level;
343 int st_same_attr = 0;
344 static AccessControlState state_init = ACL_STATE_INIT;
347 assert( desc != NULL );
349 access_level = ACL_LEVEL( access );
351 assert( access_level > ACL_NONE );
354 if ( maskp ) ACL_INVALIDATE( *maskp );
356 attr = desc->ad_cname.bv_val;
358 assert( attr != NULL );
361 if ( op->o_is_auth_check &&
362 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
366 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
367 desc == slap_schema.si_ad_entry )
374 if ( state->as_vd_ad == desc ) {
375 if ( state->as_recorded ) {
376 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
379 return state->as_result;
381 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
382 val != NULL && state->as_vd_acl == NULL )
384 return state->as_result;
392 state->as_vd_ad = desc;
395 Debug( LDAP_DEBUG_ACL,
396 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
397 access2str( access ), e->e_dn, attr );
404 if ( op->o_bd == NULL ) {
405 op->o_bd = LDAP_STAILQ_FIRST( &backendDB );
410 * FIXME: experimental; use first backend rules
411 * iff there is no global_acl (ITS#3100) */
412 if ( frontendDB->be_acl != NULL ) {
413 op->o_bd = frontendDB;
415 #endif /* LDAP_DEVEL */
417 assert( op->o_bd != NULL );
419 /* this is enforced in backend_add() */
420 if ( op->o_bd->bd_info->bi_access_allowed ) {
421 /* delegate to backend */
422 ret = op->o_bd->bd_info->bi_access_allowed( op, e,
423 desc, val, access, state, &mask );
426 BackendDB *be_orig = op->o_bd;
428 /* use default (but pass through frontend
429 * for global ACL overlays) */
430 op->o_bd = frontendDB;
431 ret = frontendDB->bd_info->bi_access_allowed( op, e,
432 desc, val, access, state, &mask );
437 if ( ACL_IS_INVALID( mask ) ) {
438 Debug( LDAP_DEBUG_ACL,
439 "=> access_allowed: \"%s\" (%s) invalid!\n",
444 Debug( LDAP_DEBUG_ACL,
445 "=> access_allowed: no more rules\n", 0, 0, 0 );
451 Debug( LDAP_DEBUG_ACL,
452 "=> access_allowed: %s access %s by %s\n",
453 access2str( access ), ret ? "granted" : "denied",
454 accessmask2str( mask, accessmaskbuf, 1 ) );
457 if ( state != NULL ) {
458 /* If not value-dependent, save ACL in case of more attrs */
459 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
460 state->as_vi_acl = a;
461 state->as_result = ret;
463 state->as_recorded |= ACL_STATE_RECORDED;
465 if ( be_null ) op->o_bd = NULL;
466 if ( maskp ) ACL_PRIV_ASSIGN( *maskp, mask );
470 #else /* !SLAP_OVERLAY_ACCESS */
476 AttributeDescription *desc,
478 slap_access_t access,
479 AccessControlState *state,
484 AccessControl *a = NULL;
489 char accessmaskbuf[ACCESSMASK_MAXLEN];
492 slap_control_t control;
493 slap_access_t access_level;
495 regmatch_t matches[MAXREMATCHES];
496 int st_same_attr = 0;
497 static AccessControlState state_init = ACL_STATE_INIT;
500 assert( desc != NULL );
502 access_level = ACL_LEVEL( access );
504 assert( access_level > ACL_NONE );
505 if ( maskp ) ACL_INVALIDATE( *maskp );
507 attr = desc->ad_cname.bv_val;
509 assert( attr != NULL );
512 if ( op->o_is_auth_check &&
513 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
517 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
518 desc == slap_schema.si_ad_entry )
525 if ( state->as_vd_ad == desc ) {
526 if ( state->as_recorded ) {
527 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
530 return state->as_result;
532 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
533 val != NULL && state->as_vd_acl == NULL )
535 return state->as_result;
543 state->as_vd_ad=desc;
546 Debug( LDAP_DEBUG_ACL,
547 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
548 access2str( access ), e->e_dn, attr );
557 be = LDAP_STAILQ_FIRST(&backendDB);
561 * FIXME: experimental; use first backend rules
562 * iff there is no global_acl (ITS#3100) */
563 if ( frontendDB->be_acl == NULL )
569 assert( be != NULL );
571 /* grant database root access */
572 if ( be_isroot( op ) ) {
573 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
575 mask = ACL_LVL_MANAGE;
582 * no-user-modification operational attributes are ignored
583 * by ACL_WRITE checking as any found here are not provided
586 * NOTE: but they are not ignored for ACL_MANAGE, because
587 * if we get here it means a non-root user is trying to
588 * manage data, so we need to check its privileges.
590 if ( access_level == ACL_WRITE && is_at_no_user_mod( desc->ad_type )
591 && desc != slap_schema.si_ad_entry
592 && desc != slap_schema.si_ad_children )
594 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
595 " %s access granted\n",
600 /* use backend default access if no backend acls */
601 if ( be->be_acl == NULL ) {
602 Debug( LDAP_DEBUG_ACL,
603 "=> access_allowed: backend default %s "
604 "access %s to \"%s\"\n",
605 access2str( access ),
606 be->be_dfltaccess >= access_level ? "granted" : "denied",
607 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
608 ret = be->be_dfltaccess >= access_level;
613 mask = ACL_PRIV_LEVEL;
614 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
615 mask |= ACL_ACCESS2PRIV( i );
622 /* be is always non-NULL */
623 /* use global default access if no global acls */
624 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
625 Debug( LDAP_DEBUG_ACL,
626 "=> access_allowed: global default %s access %s to \"%s\"\n",
627 access2str( access ),
628 frontendDB->be_dfltaccess >= access_level ?
629 "granted" : "denied", op->o_dn.bv_val );
630 ret = frontendDB->be_dfltaccess >= access_level;
635 mask = ACL_PRIV_LEVEL;
636 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
637 mask |= ACL_ACCESS2PRIV( i );
648 if ( st_same_attr ) {
649 assert( state->as_vd_acl != NULL );
651 a = state->as_vd_acl;
652 count = state->as_vd_acl_count;
653 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
654 mask = state->as_vd_acl_mask;
655 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
660 if ( state ) state->as_vi_acl = NULL;
664 memset( matches, '\0', sizeof(matches) );
667 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
668 MAXREMATCHES, matches, state ) ) != NULL )
672 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
673 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
674 (int)matches[i].rm_so, (int)matches[i].rm_eo );
675 if ( matches[i].rm_so <= matches[0].rm_eo ) {
677 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
678 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
681 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
685 if ( state->as_vi_acl == a &&
686 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
688 Debug( LDAP_DEBUG_ACL,
689 "access_allowed: result from state (%s)\n",
691 ret = state->as_result;
694 Debug( LDAP_DEBUG_ACL,
695 "access_allowed: no res from state (%s)\n",
701 control = slap_acl_mask( a, &mask, op,
702 e, desc, val, MAXREMATCHES, matches, count, state );
704 if ( control != ACL_BREAK ) {
708 memset( matches, '\0', sizeof(matches) );
711 if ( ACL_IS_INVALID( mask ) ) {
712 Debug( LDAP_DEBUG_ACL,
713 "=> access_allowed: \"%s\" (%s) invalid!\n",
717 } else if ( control == ACL_BREAK ) {
718 Debug( LDAP_DEBUG_ACL,
719 "=> access_allowed: no more rules\n", 0, 0, 0 );
724 Debug( LDAP_DEBUG_ACL,
725 "=> access_allowed: %s access %s by %s\n",
726 access2str( access ),
727 ACL_GRANT(mask, access) ? "granted" : "denied",
728 accessmask2str( mask, accessmaskbuf, 1 ) );
730 ret = ACL_GRANT(mask, access);
733 if ( state != NULL ) {
734 /* If not value-dependent, save ACL in case of more attrs */
735 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
736 state->as_vi_acl = a;
737 state->as_result = ret;
739 state->as_recorded |= ACL_STATE_RECORDED;
741 if ( be_null ) op->o_bd = NULL;
742 if ( maskp ) *maskp = mask;
746 #endif /* SLAP_OVERLAY_ACCESS */
749 * slap_acl_get - return the acl applicable to entry e, attribute
750 * attr. the acl returned is suitable for use in subsequent calls to
751 * acl_access_allowed().
754 static AccessControl *
760 AttributeDescription *desc,
764 AccessControlState *state )
771 assert( count != NULL );
772 assert( desc != NULL );
774 attr = desc->ad_cname.bv_val;
776 assert( attr != NULL );
779 if( op->o_bd == NULL ) {
780 a = frontendDB->be_acl;
782 a = op->o_bd->be_acl;
793 dnlen = e->e_nname.bv_len;
795 for ( ; a != NULL; a = a->acl_next ) {
798 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
799 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
800 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
801 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
802 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
806 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
807 *count, a->acl_dn_pat.bv_val, 0 );
808 patlen = a->acl_dn_pat.bv_len;
809 if ( dnlen < patlen )
812 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
813 /* base dn -- entire object DN must match */
814 if ( dnlen != patlen )
817 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
818 ber_len_t rdnlen = 0;
821 if ( dnlen <= patlen )
825 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
830 rdnlen = dn_rdnlen( NULL, &e->e_nname );
831 if ( rdnlen != dnlen - patlen - sep )
834 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
835 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
838 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
839 if ( dnlen <= patlen )
841 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
845 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
849 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
853 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
854 matches[0].rm_so = matches[0].rm_eo = -1;
858 /* Is this ACL only for a specific value? */
859 if ( a->acl_attrval.bv_len ) {
864 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
865 state->as_recorded |= ACL_STATE_RECORDED_VD;
866 state->as_vd_acl = a;
867 state->as_vd_acl_count = *count;
868 state->as_vd_access = a->acl_access;
869 state->as_vd_access_count = 1;
870 ACL_INVALIDATE( state->as_vd_acl_mask );
873 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
874 Debug( LDAP_DEBUG_ACL,
875 "acl_get: valpat %s\n",
876 a->acl_attrval.bv_val, 0, 0 );
877 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
885 Debug( LDAP_DEBUG_ACL,
887 a->acl_attrval.bv_val, 0, 0 );
889 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
890 if (value_match( &match, desc,
891 /* desc->ad_type->sat_equality */ a->acl_attrval_mr, 0,
892 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
899 patlen = a->acl_attrval.bv_len;
900 vdnlen = val->bv_len;
902 if ( vdnlen < patlen )
905 if ( a->acl_attrval_style == ACL_STYLE_BASE ) {
906 if ( vdnlen > patlen )
909 } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) {
910 ber_len_t rdnlen = 0;
912 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
915 rdnlen = dn_rdnlen( NULL, val );
916 if ( rdnlen != vdnlen - patlen - 1 )
919 } else if ( a->acl_attrval_style == ACL_STYLE_SUBTREE ) {
920 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
923 } else if ( a->acl_attrval_style == ACL_STYLE_CHILDREN ) {
924 if ( vdnlen <= patlen )
927 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
931 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
937 if ( a->acl_filter != NULL ) {
938 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
939 if ( rc != LDAP_COMPARE_TRUE ) {
944 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
949 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
961 struct berval *opndn )
964 * if access applies to the entry itself, and the
965 * user is bound as somebody in the same namespace as
966 * the entry, OR the given dn matches the dn pattern
969 * NOTE: styles "anonymous", "users" and "self"
970 * have been moved to enum slap_style_t, whose
971 * value is set in a_dn_style; however, the string
972 * is maintaned in a_dn_pat.
974 if ( b->a_style == ACL_STYLE_ANONYMOUS ) {
975 if ( !BER_BVISEMPTY( opndn ) ) {
979 } else if ( b->a_style == ACL_STYLE_USERS ) {
980 if ( BER_BVISEMPTY( opndn ) ) {
984 } else if ( b->a_style == ACL_STYLE_SELF ) {
985 struct berval ndn, selfndn;
988 if ( BER_BVISEMPTY( opndn ) || BER_BVISNULL( &e->e_nname ) ) {
992 level = b->a_self_level;
1000 selfndn = e->e_nname;
1003 for ( ; level > 0; level-- ) {
1004 if ( BER_BVISEMPTY( &ndn ) ) {
1007 dnParent( &ndn, &ndn );
1010 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
1015 } else if ( b->a_style == ACL_STYLE_REGEX ) {
1016 if ( !ber_bvccmp( &b->a_pat, '*' ) ) {
1018 regmatch_t tmp_matches[2],
1019 *tmp_matchesp = tmp_matches;
1023 switch ( a->acl_dn_style ) {
1024 case ACL_STYLE_REGEX:
1025 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1026 tmp_matchesp = matches;
1027 tmp_nmatch = nmatch;
1030 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1032 case ACL_STYLE_BASE:
1033 tmp_matches[0].rm_so = 0;
1034 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1039 case ACL_STYLE_SUBTREE:
1040 case ACL_STYLE_CHILDREN:
1041 tmp_matches[0].rm_so = 0;
1042 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1043 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1044 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1058 if ( !regex_matches( &b->a_pat, opndn->bv_val,
1059 e->e_ndn, tmp_nmatch, tmp_matchesp ) )
1067 ber_len_t patlen, odnlen;
1070 if ( e->e_dn == NULL )
1073 if ( b->a_expand ) {
1075 char buf[ACL_BUF_SIZE];
1078 regmatch_t tmp_matches[2],
1079 *tmp_matchesp = tmp_matches;
1083 bv.bv_len = sizeof( buf ) - 1;
1086 switch ( a->acl_dn_style ) {
1087 case ACL_STYLE_REGEX:
1088 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1089 tmp_matchesp = matches;
1090 tmp_nmatch = nmatch;
1093 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1095 case ACL_STYLE_BASE:
1096 tmp_matches[0].rm_so = 0;
1097 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1102 case ACL_STYLE_SUBTREE:
1103 case ACL_STYLE_CHILDREN:
1104 tmp_matches[0].rm_so = 0;
1105 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1106 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1107 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1121 if ( acl_string_expand( &bv, &b->a_pat,
1123 tmp_nmatch, tmp_matchesp ) )
1128 if ( dnNormalize(0, NULL, NULL, &bv,
1129 &pat, op->o_tmpmemctx )
1132 /* did not expand to a valid dn */
1140 patlen = pat.bv_len;
1141 odnlen = opndn->bv_len;
1142 if ( odnlen < patlen ) {
1143 goto dn_match_cleanup;
1147 if ( b->a_style == ACL_STYLE_BASE ) {
1148 /* base dn -- entire object DN must match */
1149 if ( odnlen != patlen ) {
1150 goto dn_match_cleanup;
1153 } else if ( b->a_style == ACL_STYLE_ONE ) {
1154 ber_len_t rdnlen = 0;
1156 if ( odnlen <= patlen ) {
1157 goto dn_match_cleanup;
1160 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1161 goto dn_match_cleanup;
1164 rdnlen = dn_rdnlen( NULL, opndn );
1165 if ( rdnlen - ( odnlen - patlen - 1 ) != 0 ) {
1166 goto dn_match_cleanup;
1169 } else if ( b->a_style == ACL_STYLE_SUBTREE ) {
1170 if ( odnlen > patlen && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1171 goto dn_match_cleanup;
1174 } else if ( b->a_style == ACL_STYLE_CHILDREN ) {
1175 if ( odnlen <= patlen ) {
1176 goto dn_match_cleanup;
1179 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1180 goto dn_match_cleanup;
1183 } else if ( b->a_style == ACL_STYLE_LEVEL ) {
1184 int level = b->a_level;
1187 if ( odnlen <= patlen ) {
1188 goto dn_match_cleanup;
1191 if ( level > 0 && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) )
1193 goto dn_match_cleanup;
1197 for ( ; level > 0; level-- ) {
1198 if ( BER_BVISEMPTY( &ndn ) ) {
1199 goto dn_match_cleanup;
1201 dnParent( &ndn, &ndn );
1202 if ( ndn.bv_len < patlen ) {
1203 goto dn_match_cleanup;
1207 if ( ndn.bv_len != patlen ) {
1208 goto dn_match_cleanup;
1212 got_match = !strcmp( pat.bv_val, &opndn->bv_val[ odnlen - patlen ] );
1215 if ( pat.bv_val != b->a_pat.bv_val ) {
1216 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
1228 * Record value-dependent access control state
1230 #define ACL_RECORD_VALUE_STATE do { \
1231 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
1232 state->as_recorded |= ACL_STATE_RECORDED_VD; \
1233 state->as_vd_acl = a; \
1234 AC_MEMCPY( state->as_vd_acl_matches, matches, \
1235 sizeof( state->as_vd_acl_matches )) ; \
1236 state->as_vd_acl_count = count; \
1237 state->as_vd_access = b; \
1238 state->as_vd_access_count = i; \
1250 regmatch_t *matches,
1252 AccessControlState *state,
1253 slap_dn_access *bdn,
1254 struct berval *opndn )
1260 const char *attr = bdn->a_at->ad_cname.bv_val;
1262 assert( attr != NULL );
1264 if ( BER_BVISEMPTY( opndn ) ) {
1268 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n", attr, 0, 0 );
1271 /* see if asker is listed in dnattr */
1272 for ( at = attrs_find( e->e_attrs, bdn->a_at );
1274 at = attrs_find( at->a_next, bdn->a_at ) )
1276 if ( value_find_ex( bdn->a_at,
1277 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1278 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1280 &bv, op->o_tmpmemctx ) == 0 )
1289 /* have a dnattr match. if this is a self clause then
1290 * the target must also match the op dn.
1292 if ( bdn->a_self ) {
1293 /* check if the target is an attribute. */
1294 if ( val == NULL ) return 1;
1296 /* target is attribute, check if the attribute value
1299 rc = value_match( &match, bdn->a_at,
1300 bdn->a_at->ad_type->sat_equality, 0,
1302 /* on match error or no match, fail the ACL clause */
1303 if ( rc != LDAP_SUCCESS || match != 0 )
1308 /* no dnattr match, check if this is a self clause */
1309 if ( ! bdn->a_self )
1312 ACL_RECORD_VALUE_STATE;
1314 /* this is a self clause, check if the target is an
1320 /* target is attribute, check if the attribute value
1323 rc = value_match( &match, bdn->a_at,
1324 bdn->a_at->ad_type->sat_equality, 0,
1327 /* on match error or no match, fail the ACL clause */
1328 if ( rc != LDAP_SUCCESS || match != 0 )
1337 * slap_acl_mask - modifies mask based upon the given acl and the
1338 * requested access to entry e, attribute attr, value val. if val
1339 * is null, access to the whole attribute is assumed (all values).
1341 * returns 0 access NOT allowed
1345 static slap_control_t
1351 AttributeDescription *desc,
1354 regmatch_t *matches,
1356 AccessControlState *state )
1361 char accessmaskbuf[ACCESSMASK_MAXLEN];
1364 slap_mask_t a2pmask = ACL_ACCESS2PRIV( *mask );
1366 assert( a != NULL );
1367 assert( mask != NULL );
1368 assert( desc != NULL );
1370 attr = desc->ad_cname.bv_val;
1372 assert( attr != NULL );
1374 Debug( LDAP_DEBUG_ACL,
1375 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
1378 Debug( LDAP_DEBUG_ACL,
1379 "=> acl_mask: to %s by \"%s\", (%s) \n",
1380 val ? "value" : "all values",
1381 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
1382 accessmask2str( *mask, accessmaskbuf, 1 ) );
1385 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
1386 && state->as_vd_acl == a )
1388 b = state->as_vd_access;
1389 i = state->as_vd_access_count;
1396 for ( ; b != NULL; b = b->a_next, i++ ) {
1397 slap_mask_t oldmask, modmask;
1399 ACL_INVALIDATE( modmask );
1401 /* AND <who> clauses */
1402 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
1403 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
1404 b->a_dn_pat.bv_val, 0, 0);
1406 * if access applies to the entry itself, and the
1407 * user is bound as somebody in the same namespace as
1408 * the entry, OR the given dn matches the dn pattern
1411 * NOTE: styles "anonymous", "users" and "self"
1412 * have been moved to enum slap_style_t, whose
1413 * value is set in a_dn_style; however, the string
1414 * is maintaned in a_dn_pat.
1417 if ( acl_mask_dn( op, e, a, nmatch, matches,
1418 &b->a_dn, &op->o_ndn ) )
1424 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
1427 Debug( LDAP_DEBUG_ACL, "<= check a_realdn_pat: %s\n",
1428 b->a_realdn_pat.bv_val, 0, 0);
1430 * if access applies to the entry itself, and the
1431 * user is bound as somebody in the same namespace as
1432 * the entry, OR the given dn matches the dn pattern
1435 * NOTE: styles "anonymous", "users" and "self"
1436 * have been moved to enum slap_style_t, whose
1437 * value is set in a_dn_style; however, the string
1438 * is maintaned in a_dn_pat.
1441 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1443 ndn = op->o_conn->c_ndn;
1448 if ( acl_mask_dn( op, e, a, nmatch, matches,
1449 &b->a_realdn, &ndn ) )
1455 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1456 if ( ! op->o_conn->c_listener ) {
1459 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
1460 b->a_sockurl_pat.bv_val, 0, 0 );
1462 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
1463 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
1464 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
1465 e->e_ndn, nmatch, matches ) )
1470 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
1472 char buf[ACL_BUF_SIZE];
1474 bv.bv_len = sizeof( buf ) - 1;
1476 if ( acl_string_expand( &bv, &b->a_sockurl_pat,
1477 e->e_ndn, nmatch, matches ) )
1482 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1488 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1496 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1497 if ( !op->o_conn->c_peer_domain.bv_val ) {
1500 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1501 b->a_domain_pat.bv_val, 0, 0 );
1502 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1503 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1504 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1505 e->e_ndn, nmatch, matches ) )
1510 char buf[ACL_BUF_SIZE];
1512 struct berval cmp = op->o_conn->c_peer_domain;
1513 struct berval pat = b->a_domain_pat;
1515 if ( b->a_domain_expand ) {
1518 bv.bv_len = sizeof(buf) - 1;
1521 if ( acl_string_expand(&bv, &b->a_domain_pat,
1522 e->e_ndn, nmatch, matches) )
1529 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1530 int offset = cmp.bv_len - pat.bv_len;
1535 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1539 /* trim the domain */
1540 cmp.bv_val = &cmp.bv_val[ offset ];
1541 cmp.bv_len -= offset;
1544 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1551 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1552 if ( !op->o_conn->c_peer_name.bv_val ) {
1555 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1556 b->a_peername_pat.bv_val, 0, 0 );
1557 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1558 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1559 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1560 e->e_ndn, nmatch, matches ) )
1566 /* try exact match */
1567 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1568 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1572 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1574 char buf[ACL_BUF_SIZE];
1576 bv.bv_len = sizeof( buf ) - 1;
1578 if ( acl_string_expand( &bv, &b->a_peername_pat,
1579 e->e_ndn, nmatch, matches ) )
1584 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1588 /* extract IP and try exact match */
1589 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1591 char buf[] = "255.255.255.255";
1594 int port_number = -1;
1596 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1597 acl_bv_ip_eq.bv_val,
1598 acl_bv_ip_eq.bv_len ) != 0 )
1601 ip.bv_val = op->o_conn->c_peer_name.bv_val + acl_bv_ip_eq.bv_len;
1602 ip.bv_len = op->o_conn->c_peer_name.bv_len - acl_bv_ip_eq.bv_len;
1604 port = strrchr( ip.bv_val, ':' );
1606 ip.bv_len = port - ip.bv_val;
1608 if ( lutil_atoi( &port_number, port ) != 0 )
1612 /* the port check can be anticipated here */
1613 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1616 /* address longer than expected? */
1617 if ( ip.bv_len >= sizeof(buf) )
1620 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1621 buf[ ip.bv_len ] = '\0';
1623 addr = inet_addr( buf );
1625 /* unable to convert? */
1626 if ( addr == (unsigned long)(-1) )
1629 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1632 #ifdef LDAP_PF_LOCAL
1633 /* extract path and try exact match */
1634 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1637 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1638 acl_bv_path_eq.bv_val,
1639 acl_bv_path_eq.bv_len ) != 0 )
1642 path.bv_val = op->o_conn->c_peer_name.bv_val
1643 + acl_bv_path_eq.bv_len;
1644 path.bv_len = op->o_conn->c_peer_name.bv_len
1645 - acl_bv_path_eq.bv_len;
1647 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1650 #endif /* LDAP_PF_LOCAL */
1652 /* exact match (very unlikely...) */
1653 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1660 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1661 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1664 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1665 b->a_sockname_pat.bv_val, 0, 0 );
1666 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1667 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1668 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1669 e->e_ndn, nmatch, matches ) )
1674 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1676 char buf[ACL_BUF_SIZE];
1678 bv.bv_len = sizeof( buf ) - 1;
1680 if ( acl_string_expand( &bv, &b->a_sockname_pat,
1681 e->e_ndn, nmatch, matches ) )
1686 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1691 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1698 if ( b->a_dn_at != NULL ) {
1699 if ( acl_mask_dnattr( op, e, val, a, b, i,
1700 matches, count, state,
1701 &b->a_dn, &op->o_ndn ) )
1707 if ( b->a_realdn_at != NULL ) {
1710 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1712 ndn = op->o_conn->c_ndn;
1717 if ( acl_mask_dnattr( op, e, val, a, b, i,
1718 matches, count, state,
1719 &b->a_realdn, &ndn ) )
1725 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1727 struct berval ndn = BER_BVNULL;
1730 if ( op->o_ndn.bv_len == 0 ) {
1734 Debug( LDAP_DEBUG_ACL, "<= check a_group_pat: %s\n",
1735 b->a_group_pat.bv_val, 0, 0 );
1737 /* b->a_group is an unexpanded entry name, expanded it should be an
1738 * entry with objectclass group* and we test to see if odn is one of
1739 * the values in the attribute group
1741 /* see if asker is listed in dnattr */
1742 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1743 char buf[ACL_BUF_SIZE];
1745 regmatch_t tmp_matches[2],
1746 *tmp_matchesp = tmp_matches;
1748 bv.bv_len = sizeof(buf) - 1;
1753 switch ( a->acl_dn_style ) {
1754 case ACL_STYLE_REGEX:
1755 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1756 tmp_matchesp = matches;
1757 tmp_nmatch = nmatch;
1761 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1762 case ACL_STYLE_BASE:
1763 tmp_matches[0].rm_so = 0;
1764 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1769 case ACL_STYLE_SUBTREE:
1770 case ACL_STYLE_CHILDREN:
1771 tmp_matches[0].rm_so = 0;
1772 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1773 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1774 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1788 if ( acl_string_expand( &bv, &b->a_group_pat,
1790 tmp_nmatch, tmp_matchesp ) )
1795 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1796 op->o_tmpmemctx ) != LDAP_SUCCESS )
1798 /* did not expand to a valid dn */
1805 bv = b->a_group_pat;
1808 rc = backend_group( op, e, &bv, &op->o_ndn,
1809 b->a_group_oc, b->a_group_at );
1812 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1820 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1822 char buf[ACL_BUF_SIZE];
1824 Debug( LDAP_DEBUG_ACL, "<= check a_set_pat: %s\n",
1825 b->a_set_pat.bv_val, 0, 0 );
1827 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1829 regmatch_t tmp_matches[2],
1830 *tmp_matchesp = tmp_matches;
1833 bv.bv_len = sizeof( buf ) - 1;
1838 switch ( a->acl_dn_style ) {
1839 case ACL_STYLE_REGEX:
1840 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1841 tmp_matchesp = matches;
1842 tmp_nmatch = nmatch;
1846 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1847 case ACL_STYLE_BASE:
1848 tmp_matches[0].rm_so = 0;
1849 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1854 case ACL_STYLE_SUBTREE:
1855 case ACL_STYLE_CHILDREN:
1856 tmp_matches[0].rm_so = 0;
1857 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1858 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1859 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1873 if ( acl_string_expand( &bv, &b->a_set_pat,
1875 tmp_nmatch, tmp_matchesp ) )
1884 if ( acl_match_set( &bv, op, e, NULL ) == 0 ) {
1889 if ( b->a_authz.sai_ssf ) {
1890 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1891 b->a_authz.sai_ssf, op->o_ssf, 0 );
1892 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1897 if ( b->a_authz.sai_transport_ssf ) {
1898 Debug( LDAP_DEBUG_ACL,
1899 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1900 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1901 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1906 if ( b->a_authz.sai_tls_ssf ) {
1907 Debug( LDAP_DEBUG_ACL,
1908 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1909 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1910 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1915 if ( b->a_authz.sai_sasl_ssf ) {
1916 Debug( LDAP_DEBUG_ACL,
1917 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1918 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1919 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1925 if ( b->a_dynacl ) {
1927 slap_access_t tgrant, tdeny;
1929 Debug( LDAP_DEBUG_ACL, "<= check a_dynacl\n",
1932 /* this case works different from the others above.
1933 * since dynamic ACL's themselves give permissions, we need
1934 * to first check b->a_access_mask, the ACL's access level.
1936 /* first check if the right being requested
1937 * is allowed by the ACL clause.
1939 if ( ! ACL_PRIV_ISSET( b->a_access_mask, a2pmask ) ) {
1943 /* start out with nothing granted, nothing denied */
1947 for ( da = b->a_dynacl; da; da = da->da_next ) {
1948 slap_access_t grant,
1954 Debug( LDAP_DEBUG_ACL, " <= check a_dynacl: %s\n",
1955 da->da_name, 0, 0 );
1957 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1963 /* remove anything that the ACL clause does not allow */
1964 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1965 tdeny &= ACL_PRIV_MASK;
1967 /* see if we have anything to contribute */
1968 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1972 /* this could be improved by changing slap_acl_mask so that it can deal with
1973 * by clauses that return grant/deny pairs. Right now, it does either
1974 * additive or subtractive rights, but not both at the same time. So,
1975 * we need to combine the grant/deny pair into a single rights mask in
1976 * a smart way: if either grant or deny is "empty", then we use the
1977 * opposite as is, otherwise we remove any denied rights from the grant
1978 * rights mask and construct an additive mask.
1980 if (ACL_IS_INVALID(tdeny)) {
1981 modmask = tgrant | ACL_PRIV_ADDITIVE;
1983 } else if (ACL_IS_INVALID(tgrant)) {
1984 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1987 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1991 #else /* !SLAP_DYNACL */
1993 /* NOTE: this entire block can be eliminated when SLAP_DYNACL
1994 * moves outside of LDAP_DEVEL */
1995 #ifdef SLAPD_ACI_ENABLED
1996 if ( b->a_aci_at != NULL ) {
1998 slap_access_t grant, deny, tgrant, tdeny;
1999 struct berval parent_ndn;
2000 BerVarray bvals = NULL;
2003 char accessmaskbuf1[ACCESSMASK_MAXLEN];
2006 Debug( LDAP_DEBUG_ACL, " <= check a_aci_at: %s\n",
2007 b->a_aci_at->ad_cname.bv_val, 0, 0 );
2009 /* this case works different from the others above.
2010 * since aci's themselves give permissions, we need
2011 * to first check b->a_access_mask, the ACL's access level.
2014 if ( BER_BVISEMPTY( &e->e_nname ) ) {
2015 /* no ACIs in the root DSE */
2019 /* first check if the right being requested
2020 * is allowed by the ACL clause.
2022 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
2025 /* start out with nothing granted, nothing denied */
2029 /* get the aci attribute */
2030 at = attr_find( e->e_attrs, b->a_aci_at );
2033 /* FIXME: this breaks acl caching;
2034 * see also ACL_RECORD_VALUE_STATE below */
2035 ACL_RECORD_VALUE_STATE;
2037 /* the aci is an multi-valued attribute. The
2038 * rights are determined by OR'ing the individual
2039 * rights given by the acis.
2041 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2046 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0 )
2052 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2053 accessmask2str(tgrant, accessmaskbuf, 1),
2054 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2057 /* If the entry level aci didn't contain anything valid for the
2058 * current operation, climb up the tree and evaluate the
2059 * acis with scope set to subtree
2061 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
2062 dnParent( &e->e_nname, &parent_ndn );
2063 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
2064 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
2065 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
2073 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++ ) {
2075 /* FIXME: this breaks acl caching;
2076 * see also ACL_RECORD_VALUE_STATE above */
2077 ACL_RECORD_VALUE_STATE;
2079 if ( aci_mask( op, e, desc, val, &bvals[i],
2081 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2085 /* evaluation stops as soon as either a "deny" or a
2086 * "grant" directive matches.
2088 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
2092 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2093 accessmask2str(tgrant, accessmaskbuf, 1),
2094 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2098 case LDAP_NO_SUCH_ATTRIBUTE:
2099 /* just go on if the aci-Attribute is not present in
2102 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
2106 case LDAP_NO_SUCH_OBJECT:
2107 /* We have reached the base object */
2108 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
2119 dnParent( &parent_ndn, &parent_ndn );
2124 /* remove anything that the ACL clause does not allow */
2125 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2126 tdeny &= ACL_PRIV_MASK;
2128 /* see if we have anything to contribute */
2129 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2133 /* this could be improved by changing slap_acl_mask so that it can deal with
2134 * by clauses that return grant/deny pairs. Right now, it does either
2135 * additive or subtractive rights, but not both at the same time. So,
2136 * we need to combine the grant/deny pair into a single rights mask in
2137 * a smart way: if either grant or deny is "empty", then we use the
2138 * opposite as is, otherwise we remove any denied rights from the grant
2139 * rights mask and construct an additive mask.
2141 if (ACL_IS_INVALID(tdeny)) {
2142 modmask = tgrant | ACL_PRIV_ADDITIVE;
2144 } else if (ACL_IS_INVALID(tgrant)) {
2145 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2148 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2152 #endif /* SLAPD_ACI_ENABLED */
2153 #endif /* !SLAP_DYNACL */
2155 modmask = b->a_access_mask;
2158 Debug( LDAP_DEBUG_ACL,
2159 "<= acl_mask: [%d] applying %s (%s)\n",
2160 i, accessmask2str( modmask, accessmaskbuf, 1 ),
2161 b->a_type == ACL_CONTINUE
2163 : b->a_type == ACL_BREAK
2169 if( ACL_IS_ADDITIVE(modmask) ) {
2171 ACL_PRIV_SET( *mask, modmask );
2174 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2176 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
2177 /* substract privs */
2178 ACL_PRIV_CLR( *mask, modmask );
2181 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2190 Debug( LDAP_DEBUG_ACL,
2191 "<= acl_mask: [%d] mask: %s\n",
2192 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
2194 if( b->a_type == ACL_CONTINUE ) {
2197 } else if ( b->a_type == ACL_BREAK ) {
2205 /* implicit "by * none" clause */
2208 Debug( LDAP_DEBUG_ACL,
2209 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
2210 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
2215 * acl_check_modlist - check access control on the given entry to see if
2216 * it allows the given modifications by the user associated with op.
2217 * returns 1 if mods allowed ok
2218 * 0 mods not allowed
2225 Modifications *mlist )
2228 AccessControlState state = ACL_STATE_INIT;
2231 int ret = 1; /* default is access allowed */
2235 be = LDAP_STAILQ_FIRST(&backendDB);
2239 assert( be != NULL );
2241 /* short circuit root database access */
2242 if ( be_isroot( op ) ) {
2243 Debug( LDAP_DEBUG_ACL,
2244 "<= acl_access_allowed: granted to database root\n",
2249 /* use backend default access if no backend acls */
2250 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
2251 Debug( LDAP_DEBUG_ACL,
2252 "=> access_allowed: backend default %s access %s to \"%s\"\n",
2253 access2str( ACL_WRITE ),
2254 op->o_bd->be_dfltaccess >= ACL_WRITE
2255 ? "granted" : "denied",
2257 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
2261 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
2263 * Internal mods are ignored by ACL_WRITE checking
2265 if ( mlist->sml_flags & SLAP_MOD_INTERNAL ) {
2266 Debug( LDAP_DEBUG_ACL, "acl: internal mod %s:"
2267 " modify access granted\n",
2268 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2273 * no-user-modification operational attributes are ignored
2274 * by ACL_WRITE checking as any found here are not provided
2277 if ( is_at_no_user_mod( mlist->sml_desc->ad_type )
2278 && ! ( mlist->sml_flags & SLAP_MOD_MANAGING ) )
2280 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
2281 " modify access granted\n",
2282 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2286 switch ( mlist->sml_op ) {
2287 case LDAP_MOD_REPLACE:
2289 * We must check both permission to delete the whole
2290 * attribute and permission to add the specific attributes.
2291 * This prevents abuse from selfwriters.
2293 if ( ! access_allowed( op, e,
2294 mlist->sml_desc, NULL,
2295 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2302 if ( mlist->sml_values == NULL ) break;
2304 /* fall thru to check value to add */
2307 assert( mlist->sml_values != NULL );
2309 for ( bv = mlist->sml_nvalues
2310 ? mlist->sml_nvalues : mlist->sml_values;
2311 bv->bv_val != NULL; bv++ )
2313 if ( ! access_allowed( op, e,
2314 mlist->sml_desc, bv,
2315 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WADD,
2324 case LDAP_MOD_DELETE:
2325 if ( mlist->sml_values == NULL ) {
2326 if ( ! access_allowed( op, e,
2327 mlist->sml_desc, NULL,
2328 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2336 for ( bv = mlist->sml_nvalues
2337 ? mlist->sml_nvalues : mlist->sml_values;
2338 bv->bv_val != NULL; bv++ )
2340 if ( ! access_allowed( op, e,
2341 mlist->sml_desc, bv,
2342 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2351 case SLAP_MOD_SOFTADD:
2352 /* allow adding attribute via modrdn thru */
2364 if (be_null) op->o_bd = NULL;
2370 struct berval *list,
2383 while ( len >= 0 && --ix >= 0 ) {
2384 while ( --len >= 0 && *p++ != sep )
2387 while ( len >= 0 && *p == ' ' ) {
2400 while ( --len >= 0 && *p != sep ) {
2404 while ( bv->bv_len > 0 && *--p == ' ' ) {
2411 typedef struct acl_set_gather_t {
2417 acl_set_cb_gather( Operation *op, SlapReply *rs )
2419 acl_set_gather_t *p = (acl_set_gather_t *)op->o_callback->sc_private;
2421 if ( rs->sr_type == REP_SEARCH ) {
2422 BerValue bvals[ 2 ];
2423 BerVarray bvalsp = NULL;
2426 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
2427 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
2429 if ( desc == slap_schema.si_ad_entryDN ) {
2431 bvals[ 0 ] = rs->sr_entry->e_nname;
2432 BER_BVZERO( &bvals[ 1 ] );
2437 a = attr_find( rs->sr_entry->e_attrs, desc );
2441 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
2444 bvalsp = a->a_nvals;
2450 p->bvals = slap_set_join( p->cookie, p->bvals,
2451 ( '|' | SLAP_SET_RREF ), bvalsp );
2455 assert( rs->sr_type == REP_RESULT );
2462 acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2464 AclSetCookie *cp = (AclSetCookie *)cookie;
2466 LDAPURLDesc *ludp = NULL;
2467 Operation op2 = { 0 };
2468 SlapReply rs = {REP_RESULT};
2469 AttributeName anlist[ 2 ], *anlistp = NULL;
2471 slap_callback cb = { NULL, acl_set_cb_gather, NULL, NULL };
2472 acl_set_gather_t p = { 0 };
2473 const char *text = NULL;
2474 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2476 /* this routine needs to return the bervals instead of
2477 * plain strings, since syntax is not known. It should
2478 * also return the syntax or some "comparison cookie".
2480 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2481 return acl_set_gather2( cookie, name, desc );
2484 rc = ldap_url_parse( name->bv_val, &ludp );
2485 if ( rc != LDAP_URL_SUCCESS ) {
2486 rc = LDAP_PROTOCOL_ERROR;
2490 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2492 /* host part must be empty */
2493 /* extensions parts must be empty */
2494 rc = LDAP_PROTOCOL_ERROR;
2498 /* Grab the searchbase and see if an appropriate database can be found */
2499 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2500 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2501 &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2502 BER_BVZERO( &op2.o_req_dn );
2503 if ( rc != LDAP_SUCCESS ) {
2507 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2508 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2509 rc = LDAP_NO_SUCH_OBJECT;
2513 /* Grab the filter */
2514 if ( ludp->lud_filter ) {
2515 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2516 cp->asc_op->o_tmpmemctx );
2519 op2.ors_filterstr = defaultFilter_bv;
2522 op2.ors_filter = str2filter_x( cp->asc_op, op2.ors_filterstr.bv_val );
2523 if ( op2.ors_filter == NULL ) {
2524 rc = LDAP_PROTOCOL_ERROR;
2528 /* Grab the scope */
2529 op2.ors_scope = ludp->lud_scope;
2531 /* Grap the attributes */
2532 if ( ludp->lud_attrs ) {
2533 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2536 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2537 cp->asc_op->o_tmpmemctx );
2539 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2540 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2541 anlistp[ nattrs ].an_desc = NULL;
2542 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2543 &anlistp[ nattrs ].an_desc, &text );
2544 if ( rc != LDAP_SUCCESS ) {
2553 anlistp[ nattrs ].an_name = desc->ad_cname;
2554 anlistp[ nattrs ].an_desc = desc;
2556 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2560 op2.o_hdr = cp->asc_op->o_hdr;
2561 op2.o_tag = LDAP_REQ_SEARCH;
2562 op2.o_ndn = op2.o_bd->be_rootndn;
2563 op2.o_callback = &cb;
2564 slap_op_time( &op2.o_time, &op2.o_tincr );
2565 op2.o_do_not_cache = 1;
2566 op2.o_is_auth_check = 0;
2567 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2568 op2.ors_slimit = SLAP_NO_LIMIT;
2569 op2.ors_tlimit = SLAP_NO_LIMIT;
2570 op2.ors_attrs = anlistp;
2571 op2.ors_attrsonly = 0;
2572 op2.o_private = cp->asc_op->o_private;
2576 rc = op2.o_bd->be_search( &op2, &rs );
2582 if ( op2.ors_filter ) {
2583 filter_free_x( cp->asc_op, op2.ors_filter );
2585 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2586 slap_sl_free( op2.o_req_ndn.bv_val, cp->asc_op->o_tmpmemctx );
2588 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2589 slap_sl_free( op2.o_req_dn.bv_val, cp->asc_op->o_tmpmemctx );
2592 ldap_free_urldesc( ludp );
2594 if ( anlistp && anlistp != anlist ) {
2595 slap_sl_free( anlistp, cp->asc_op->o_tmpmemctx );
2602 acl_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2604 AclSetCookie *cp = (AclSetCookie *)cookie;
2605 BerVarray bvals = NULL;
2609 /* this routine needs to return the bervals instead of
2610 * plain strings, since syntax is not known. It should
2611 * also return the syntax or some "comparison cookie".
2613 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->asc_op->o_tmpmemctx );
2614 if ( rc == LDAP_SUCCESS ) {
2615 if ( desc == slap_schema.si_ad_entryDN ) {
2616 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2617 cp->asc_op->o_tmpmemctx );
2619 BER_BVZERO( &bvals[ 1 ] );
2623 backend_attribute( cp->asc_op,
2624 cp->asc_e, &ndn, desc, &bvals, ACL_NONE );
2627 if ( !BER_BVISNULL( &ndn ) ) {
2628 slap_sl_free( ndn.bv_val, cp->asc_op->o_tmpmemctx );
2637 struct berval *subj,
2640 struct berval *default_set_attribute )
2642 struct berval set = BER_BVNULL;
2644 AclSetCookie cookie;
2646 if ( default_set_attribute == NULL ) {
2647 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2650 struct berval subjdn, ndn = BER_BVNULL;
2651 struct berval setat;
2654 AttributeDescription *desc = NULL;
2656 /* format of string is "entry/setAttrName" */
2657 if ( acl_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2661 if ( acl_get_part( subj, 1, '/', &setat ) < 0 ) {
2662 setat = *default_set_attribute;
2666 * NOTE: dnNormalize honors the ber_len field
2667 * as the length of the dn to be normalized
2669 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2670 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2672 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2673 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2677 BER_BVZERO( &bvals[0] );
2678 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2680 bvals[0].bv_val = bvals[i-1].bv_val;
2681 BER_BVZERO( &bvals[i-1] );
2683 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2684 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2689 if ( !BER_BVISNULL( &set ) ) {
2692 rc = ( slap_set_filter(
2694 (SetCookie *)&cookie, &set,
2695 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2696 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2705 * dynamic ACL infrastructure
2707 static slap_dynacl_t *da_list = NULL;
2710 slap_dynacl_register( slap_dynacl_t *da )
2714 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2715 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2720 if ( tmp != NULL ) {
2724 if ( da->da_mask == NULL ) {
2728 da->da_private = NULL;
2729 da->da_next = da_list;
2735 static slap_dynacl_t *
2736 slap_dynacl_next( slap_dynacl_t *da )
2745 slap_dynacl_get( const char *name )
2749 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2750 if ( strcasecmp( da->da_name, name ) == 0 ) {
2757 #endif /* SLAP_DYNACL */
2760 * statically built-in dynamic ACL initialization
2762 static int (*acl_init_func[])( void ) = {
2763 #ifdef SLAPD_ACI_ENABLED
2766 #else /* !SLAP_DYNACL */
2768 #endif /* !SLAP_DYNACL */
2769 #endif /* SLAPD_ACI_ENABLED */
2779 for ( i = 0; acl_init_func[ i ] != NULL; i++ ) {
2780 rc = (*(acl_init_func[ i ]))();
2795 regmatch_t *matches)
2803 bv->bv_val[0] = '\0';
2804 bv->bv_len--; /* leave space for lone $ */
2807 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2808 sp < pat->bv_val + pat->bv_len ; sp++ )
2810 /* did we previously see a $ */
2812 if ( flag == 1 && *sp == '$' ) {
2817 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2820 } else if ( *sp >= '0' && *sp <= '9' ) {
2828 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2829 if ( *sp >= '0' && *sp <= '9' ) {
2830 n = 10*n + ( *sp - '0' );
2834 if ( *sp != /*'{'*/ '}' ) {
2840 if ( n >= nmatch ) {
2846 i = matches[n].rm_so;
2847 l = matches[n].rm_eo;
2848 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2866 /* must have ended with a single $ */
2874 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2875 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2882 struct berval *pat, /* pattern to expand and match against */
2883 char *str, /* string to match against pattern */
2884 char *buf, /* buffer with $N expansion variables */
2885 int nmatch, /* size of the matches array */
2886 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2890 char newbuf[ACL_BUF_SIZE];
2894 bv.bv_len = sizeof( newbuf ) - 1;
2901 acl_string_expand( &bv, pat, buf, nmatch, matches );
2902 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2904 char error[ACL_BUF_SIZE];
2905 regerror( rc, &re, error, sizeof( error ) );
2907 Debug( LDAP_DEBUG_TRACE,
2908 "compile( \"%s\", \"%s\") failed %s\n",
2909 pat->bv_val, str, error );
2913 rc = regexec( &re, str, 0, NULL, 0 );
2916 Debug( LDAP_DEBUG_TRACE,
2917 "=> regex_matches: string: %s\n", str, 0, 0 );
2918 Debug( LDAP_DEBUG_TRACE,
2919 "=> regex_matches: rc: %d %s\n",
2920 rc, !rc ? "matches" : "no matches", 0 );