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 */
45 const struct berval aci_bv[] = {
73 #endif /* LDAP_PF_LOCAL */
75 BER_BVC(SLAPD_GROUP_CLASS),
76 BER_BVC(SLAPD_GROUP_ATTR),
77 BER_BVC(SLAPD_ROLE_CLASS),
78 BER_BVC(SLAPD_ROLE_ATTR),
80 BER_BVC(SLAPD_ACI_SET_ATTR)
83 static AccessControl * slap_acl_get(
84 AccessControl *ac, int *count,
85 Operation *op, Entry *e,
86 AttributeDescription *desc,
88 int nmatch, regmatch_t *matches,
89 AccessControlState *state );
91 static slap_control_t slap_acl_mask(
92 AccessControl *ac, slap_mask_t *mask,
93 Operation *op, Entry *e,
94 AttributeDescription *desc,
99 AccessControlState *state );
101 static int regex_matches(
102 struct berval *pat, char *str, char *buf,
103 int nmatch, regmatch_t *matches);
105 typedef struct AclSetCookie {
106 SetCookie asc_cookie;
107 #define asc_op asc_cookie.set_op
111 SLAP_SET_GATHER acl_set_gather;
112 SLAP_SET_GATHER acl_set_gather2;
115 * access_allowed - check whether op->o_ndn is allowed the requested access
116 * to entry e, attribute attr, value val. if val is null, access to
117 * the whole attribute is assumed (all values).
119 * This routine loops through all access controls and calls
120 * slap_acl_mask() on each applicable access control.
121 * The loop exits when a definitive answer is reached or
122 * or no more controls remain.
129 * - can be legally called with op == NULL
130 * - can be legally called with op->o_bd == NULL
133 #ifdef SLAP_OVERLAY_ACCESS
135 slap_access_always_allowed(
138 AttributeDescription *desc,
140 slap_access_t access,
141 AccessControlState *state,
144 assert( maskp != NULL );
147 ACL_LVL_ASSIGN_MANAGE( *maskp );
156 AttributeDescription *desc,
158 slap_access_t access,
159 AccessControlState *state,
164 AccessControl *a = NULL;
167 char accessmaskbuf[ACCESSMASK_MAXLEN];
170 slap_control_t control;
171 slap_access_t access_level;
173 regmatch_t matches[MAXREMATCHES];
174 int st_same_attr = 0;
176 assert( op != NULL );
178 assert( desc != NULL );
179 assert( maskp != NULL );
181 access_level = ACL_LEVEL( access );
182 attr = desc->ad_cname.bv_val;
184 assert( attr != NULL );
188 /* grant database root access */
189 if ( be_isroot( op ) ) {
190 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
191 mask = ACL_LVL_MANAGE;
196 * no-user-modification operational attributes are ignored
197 * by ACL_WRITE checking as any found here are not provided
200 * NOTE: but they are not ignored for ACL_MANAGE, because
201 * if we get here it means a non-root user is trying to
202 * manage data, so we need to check its privileges.
204 if ( access_level == ACL_WRITE
205 && is_at_no_user_mod( desc->ad_type )
206 && desc != slap_schema.si_ad_entry
207 && desc != slap_schema.si_ad_children )
209 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
210 " %s access granted\n",
215 /* use backend default access if no backend acls */
216 if ( op->o_bd->be_acl == NULL ) {
219 Debug( LDAP_DEBUG_ACL,
220 "=> slap_access_allowed: backend default %s "
221 "access %s to \"%s\"\n",
222 access2str( access ),
223 op->o_bd->be_dfltaccess >= access_level ? "granted" : "denied",
224 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
225 ret = op->o_bd->be_dfltaccess >= access_level;
227 mask = ACL_PRIV_LEVEL;
228 for ( i = ACL_NONE; i <= op->o_bd->be_dfltaccess; i++ ) {
229 ACL_PRIV_SET( mask, ACL_ACCESS2PRIV( i ) );
238 if ( st_same_attr ) {
239 assert( state->as_vd_acl != NULL );
241 a = state->as_vd_acl;
242 count = state->as_vd_acl_count;
243 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
244 mask = state->as_vd_acl_mask;
245 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
250 if ( state ) state->as_vi_acl = NULL;
252 ACL_PRIV_ASSIGN( mask, *maskp );
254 memset( matches, '\0', sizeof( matches ) );
257 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
258 MAXREMATCHES, matches, state ) ) != NULL )
262 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
263 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
264 (int)matches[i].rm_so, (int)matches[i].rm_eo );
265 if ( matches[i].rm_so <= matches[0].rm_eo ) {
267 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
268 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
271 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
275 if ( state->as_vi_acl == a &&
276 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
278 Debug( LDAP_DEBUG_ACL,
279 "=> slap_access_allowed: result from state (%s)\n",
281 ret = state->as_result;
284 Debug( LDAP_DEBUG_ACL,
285 "=> slap_access_allowed: no res from state (%s)\n",
291 control = slap_acl_mask( a, &mask, op,
292 e, desc, val, MAXREMATCHES, matches, count, state );
294 if ( control != ACL_BREAK ) {
298 memset( matches, '\0', sizeof( matches ) );
301 if ( ACL_IS_INVALID( mask ) ) {
302 Debug( LDAP_DEBUG_ACL,
303 "=> slap_access_allowed: \"%s\" (%s) invalid!\n",
305 ACL_PRIV_ASSIGN( mask, *maskp );
307 } else if ( control == ACL_BREAK ) {
308 Debug( LDAP_DEBUG_ACL,
309 "=> slap_access_allowed: no more rules\n", 0, 0, 0 );
314 ret = ACL_GRANT( mask, access );
316 Debug( LDAP_DEBUG_ACL,
317 "=> slap_access_allowed: %s access %s by %s\n",
318 access2str( access ), ret ? "granted" : "denied",
319 accessmask2str( mask, accessmaskbuf, 1 ) );
322 ACL_PRIV_ASSIGN( *maskp, mask );
330 AttributeDescription *desc,
332 slap_access_t access,
333 AccessControlState *state,
340 * NOTE: control gets here if FIXME
341 * if an appropriate backend cannot be selected for the operation,
342 * we assume that the frontend should handle this
343 * FIXME: should select_backend() take care of this,
344 * and return frontendDB instead of NULL? maybe for some value
349 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
350 if ( op->o_bd == NULL ) {
351 op->o_bd = frontendDB;
353 rc = slap_access_allowed( op, e, desc, val, access, state, maskp );
363 AttributeDescription *desc,
365 slap_access_t access,
366 AccessControlState *state,
370 AccessControl *a = NULL;
374 char accessmaskbuf[ACCESSMASK_MAXLEN];
377 slap_access_t access_level;
379 int st_same_attr = 0;
380 static AccessControlState state_init = ACL_STATE_INIT;
383 assert( desc != NULL );
385 access_level = ACL_LEVEL( access );
387 assert( access_level > ACL_NONE );
390 if ( maskp ) ACL_INVALIDATE( *maskp );
392 attr = desc->ad_cname.bv_val;
394 assert( attr != NULL );
397 if ( op->o_is_auth_check &&
398 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
402 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
403 desc == slap_schema.si_ad_entry )
410 if ( state->as_vd_ad == desc ) {
411 if ( state->as_recorded ) {
412 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
415 return state->as_result;
417 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
418 val != NULL && state->as_vd_acl == NULL )
420 return state->as_result;
428 state->as_vd_ad = desc;
431 Debug( LDAP_DEBUG_ACL,
432 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
433 access2str( access ), e->e_dn, attr );
440 if ( op->o_bd == NULL ) {
441 op->o_bd = LDAP_STAILQ_FIRST( &backendDB );
446 * FIXME: experimental; use first backend rules
447 * iff there is no global_acl (ITS#3100) */
448 if ( frontendDB->be_acl != NULL ) {
449 op->o_bd = frontendDB;
451 #endif /* LDAP_DEVEL */
453 assert( op->o_bd != NULL );
455 /* this is enforced in backend_add() */
456 if ( op->o_bd->bd_info->bi_access_allowed ) {
457 /* delegate to backend */
458 ret = op->o_bd->bd_info->bi_access_allowed( op, e,
459 desc, val, access, state, &mask );
462 BackendDB *be_orig = op->o_bd;
464 /* use default (but pass through frontend
465 * for global ACL overlays) */
466 op->o_bd = frontendDB;
467 ret = frontendDB->bd_info->bi_access_allowed( op, e,
468 desc, val, access, state, &mask );
473 if ( ACL_IS_INVALID( mask ) ) {
474 Debug( LDAP_DEBUG_ACL,
475 "=> access_allowed: \"%s\" (%s) invalid!\n",
480 Debug( LDAP_DEBUG_ACL,
481 "=> access_allowed: no more rules\n", 0, 0, 0 );
487 Debug( LDAP_DEBUG_ACL,
488 "=> access_allowed: %s access %s by %s\n",
489 access2str( access ), ret ? "granted" : "denied",
490 accessmask2str( mask, accessmaskbuf, 1 ) );
493 if ( state != NULL ) {
494 /* If not value-dependent, save ACL in case of more attrs */
495 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
496 state->as_vi_acl = a;
497 state->as_result = ret;
499 state->as_recorded |= ACL_STATE_RECORDED;
501 if ( be_null ) op->o_bd = NULL;
502 if ( maskp ) ACL_PRIV_ASSIGN( *maskp, mask );
506 #else /* !SLAP_OVERLAY_ACCESS */
512 AttributeDescription *desc,
514 slap_access_t access,
515 AccessControlState *state,
520 AccessControl *a = NULL;
525 char accessmaskbuf[ACCESSMASK_MAXLEN];
528 slap_control_t control;
529 slap_access_t access_level;
531 regmatch_t matches[MAXREMATCHES];
532 int st_same_attr = 0;
533 static AccessControlState state_init = ACL_STATE_INIT;
536 assert( desc != NULL );
538 access_level = ACL_LEVEL( access );
540 assert( access_level > ACL_NONE );
541 if ( maskp ) ACL_INVALIDATE( *maskp );
543 attr = desc->ad_cname.bv_val;
545 assert( attr != NULL );
548 if ( op->o_is_auth_check &&
549 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
553 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
554 desc == slap_schema.si_ad_entry )
561 if ( state->as_vd_ad == desc ) {
562 if ( state->as_recorded ) {
563 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
566 return state->as_result;
568 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
569 val != NULL && state->as_vd_acl == NULL )
571 return state->as_result;
579 state->as_vd_ad=desc;
582 Debug( LDAP_DEBUG_ACL,
583 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
584 access2str( access ), e->e_dn, attr );
593 be = LDAP_STAILQ_FIRST(&backendDB);
597 * FIXME: experimental; use first backend rules
598 * iff there is no global_acl (ITS#3100) */
599 if ( frontendDB->be_acl == NULL )
605 assert( be != NULL );
607 /* grant database root access */
608 if ( be_isroot( op ) ) {
609 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
611 mask = ACL_LVL_MANAGE;
618 * no-user-modification operational attributes are ignored
619 * by ACL_WRITE checking as any found here are not provided
622 * NOTE: but they are not ignored for ACL_MANAGE, because
623 * if we get here it means a non-root user is trying to
624 * manage data, so we need to check its privileges.
626 if ( access_level == ACL_WRITE && is_at_no_user_mod( desc->ad_type )
627 && desc != slap_schema.si_ad_entry
628 && desc != slap_schema.si_ad_children )
630 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
631 " %s access granted\n",
636 /* use backend default access if no backend acls */
637 if ( be->be_acl == NULL ) {
638 Debug( LDAP_DEBUG_ACL,
639 "=> access_allowed: backend default %s "
640 "access %s to \"%s\"\n",
641 access2str( access ),
642 be->be_dfltaccess >= access_level ? "granted" : "denied",
643 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
644 ret = be->be_dfltaccess >= access_level;
649 mask = ACL_PRIV_LEVEL;
650 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
651 mask |= ACL_ACCESS2PRIV( i );
658 /* be is always non-NULL */
659 /* use global default access if no global acls */
660 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
661 Debug( LDAP_DEBUG_ACL,
662 "=> access_allowed: global default %s access %s to \"%s\"\n",
663 access2str( access ),
664 frontendDB->be_dfltaccess >= access_level ?
665 "granted" : "denied", op->o_dn.bv_val );
666 ret = frontendDB->be_dfltaccess >= access_level;
671 mask = ACL_PRIV_LEVEL;
672 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
673 mask |= ACL_ACCESS2PRIV( i );
684 if ( st_same_attr ) {
685 assert( state->as_vd_acl != NULL );
687 a = state->as_vd_acl;
688 count = state->as_vd_acl_count;
689 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
690 mask = state->as_vd_acl_mask;
691 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
696 if ( state ) state->as_vi_acl = NULL;
700 memset( matches, '\0', sizeof(matches) );
703 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
704 MAXREMATCHES, matches, state ) ) != NULL )
708 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
709 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
710 (int)matches[i].rm_so, (int)matches[i].rm_eo );
711 if ( matches[i].rm_so <= matches[0].rm_eo ) {
713 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
714 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
717 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
721 if ( state->as_vi_acl == a &&
722 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
724 Debug( LDAP_DEBUG_ACL,
725 "access_allowed: result from state (%s)\n",
727 ret = state->as_result;
730 Debug( LDAP_DEBUG_ACL,
731 "access_allowed: no res from state (%s)\n",
737 control = slap_acl_mask( a, &mask, op,
738 e, desc, val, MAXREMATCHES, matches, count, state );
740 if ( control != ACL_BREAK ) {
744 memset( matches, '\0', sizeof(matches) );
747 if ( ACL_IS_INVALID( mask ) ) {
748 Debug( LDAP_DEBUG_ACL,
749 "=> access_allowed: \"%s\" (%s) invalid!\n",
753 } else if ( control == ACL_BREAK ) {
754 Debug( LDAP_DEBUG_ACL,
755 "=> access_allowed: no more rules\n", 0, 0, 0 );
760 Debug( LDAP_DEBUG_ACL,
761 "=> access_allowed: %s access %s by %s\n",
762 access2str( access ),
763 ACL_GRANT(mask, access) ? "granted" : "denied",
764 accessmask2str( mask, accessmaskbuf, 1 ) );
766 ret = ACL_GRANT(mask, access);
769 if ( state != NULL ) {
770 /* If not value-dependent, save ACL in case of more attrs */
771 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
772 state->as_vi_acl = a;
773 state->as_result = ret;
775 state->as_recorded |= ACL_STATE_RECORDED;
777 if ( be_null ) op->o_bd = NULL;
778 if ( maskp ) *maskp = mask;
782 #endif /* SLAP_OVERLAY_ACCESS */
785 * slap_acl_get - return the acl applicable to entry e, attribute
786 * attr. the acl returned is suitable for use in subsequent calls to
787 * acl_access_allowed().
790 static AccessControl *
796 AttributeDescription *desc,
800 AccessControlState *state )
807 assert( count != NULL );
808 assert( desc != NULL );
810 attr = desc->ad_cname.bv_val;
812 assert( attr != NULL );
815 if( op->o_bd == NULL ) {
816 a = frontendDB->be_acl;
818 a = op->o_bd->be_acl;
829 dnlen = e->e_nname.bv_len;
831 for ( ; a != NULL; a = a->acl_next ) {
834 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
835 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
836 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
837 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
838 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
842 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
843 *count, a->acl_dn_pat.bv_val, 0 );
844 patlen = a->acl_dn_pat.bv_len;
845 if ( dnlen < patlen )
848 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
849 /* base dn -- entire object DN must match */
850 if ( dnlen != patlen )
853 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
854 int rdnlen = -1, sep = 0;
856 if ( dnlen <= patlen )
860 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
865 rdnlen = dn_rdnlen( NULL, &e->e_nname );
866 if ( rdnlen != dnlen - patlen - sep )
869 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
870 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
873 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
874 if ( dnlen <= patlen )
876 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
880 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
884 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
888 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
889 matches[0].rm_so = matches[0].rm_eo = -1;
893 /* Is this ACL only for a specific value? */
894 if ( a->acl_attrval.bv_len ) {
899 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
900 state->as_recorded |= ACL_STATE_RECORDED_VD;
901 state->as_vd_acl = a;
902 state->as_vd_acl_count = *count;
903 state->as_vd_access = a->acl_access;
904 state->as_vd_access_count = 1;
905 ACL_INVALIDATE( state->as_vd_acl_mask );
908 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
909 Debug( LDAP_DEBUG_ACL,
910 "acl_get: valpat %s\n",
911 a->acl_attrval.bv_val, 0, 0 );
912 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
920 Debug( LDAP_DEBUG_ACL,
922 a->acl_attrval.bv_val, 0, 0 );
924 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
925 if (value_match( &match, desc,
926 /* desc->ad_type->sat_equality */ a->acl_attrval_mr, 0,
927 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
934 patlen = a->acl_attrval.bv_len;
935 vdnlen = val->bv_len;
937 if ( vdnlen < patlen )
940 if ( a->acl_attrval_style == ACL_STYLE_BASE ) {
941 if ( vdnlen > patlen )
944 } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) {
947 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
950 rdnlen = dn_rdnlen( NULL, val );
951 if ( rdnlen != vdnlen - patlen - 1 )
954 } else if ( a->acl_attrval_style == ACL_STYLE_SUBTREE ) {
955 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
958 } else if ( a->acl_attrval_style == ACL_STYLE_CHILDREN ) {
959 if ( vdnlen <= patlen )
962 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
966 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
972 if ( a->acl_filter != NULL ) {
973 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
974 if ( rc != LDAP_COMPARE_TRUE ) {
979 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
984 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
996 struct berval *opndn )
999 * if access applies to the entry itself, and the
1000 * user is bound as somebody in the same namespace as
1001 * the entry, OR the given dn matches the dn pattern
1004 * NOTE: styles "anonymous", "users" and "self"
1005 * have been moved to enum slap_style_t, whose
1006 * value is set in a_dn_style; however, the string
1007 * is maintaned in a_dn_pat.
1009 if ( b->a_style == ACL_STYLE_ANONYMOUS ) {
1010 if ( !BER_BVISEMPTY( opndn ) ) {
1014 } else if ( b->a_style == ACL_STYLE_USERS ) {
1015 if ( BER_BVISEMPTY( opndn ) ) {
1019 } else if ( b->a_style == ACL_STYLE_SELF ) {
1020 struct berval ndn, selfndn;
1023 if ( BER_BVISEMPTY( opndn ) || BER_BVISNULL( &e->e_nname ) ) {
1027 level = b->a_self_level;
1035 selfndn = e->e_nname;
1038 for ( ; level > 0; level-- ) {
1039 if ( BER_BVISEMPTY( &ndn ) ) {
1042 dnParent( &ndn, &ndn );
1045 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
1050 } else if ( b->a_style == ACL_STYLE_REGEX ) {
1051 if ( !ber_bvccmp( &b->a_pat, '*' ) ) {
1053 regmatch_t tmp_matches[2],
1054 *tmp_matchesp = tmp_matches;
1058 switch ( a->acl_dn_style ) {
1059 case ACL_STYLE_REGEX:
1060 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1061 tmp_matchesp = matches;
1062 tmp_nmatch = nmatch;
1065 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1067 case ACL_STYLE_BASE:
1068 tmp_matches[0].rm_so = 0;
1069 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1074 case ACL_STYLE_SUBTREE:
1075 case ACL_STYLE_CHILDREN:
1076 tmp_matches[0].rm_so = 0;
1077 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1078 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1079 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1093 if ( !regex_matches( &b->a_pat, opndn->bv_val,
1094 e->e_ndn, tmp_nmatch, tmp_matchesp ) )
1102 ber_len_t patlen, odnlen;
1105 if ( e->e_dn == NULL )
1108 if ( b->a_expand ) {
1110 char buf[ACL_BUF_SIZE];
1113 regmatch_t tmp_matches[2],
1114 *tmp_matchesp = tmp_matches;
1118 bv.bv_len = sizeof( buf ) - 1;
1121 switch ( a->acl_dn_style ) {
1122 case ACL_STYLE_REGEX:
1123 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1124 tmp_matchesp = matches;
1125 tmp_nmatch = nmatch;
1128 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1130 case ACL_STYLE_BASE:
1131 tmp_matches[0].rm_so = 0;
1132 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1137 case ACL_STYLE_SUBTREE:
1138 case ACL_STYLE_CHILDREN:
1139 tmp_matches[0].rm_so = 0;
1140 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1141 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1142 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1156 if ( acl_string_expand( &bv, &b->a_pat,
1158 tmp_nmatch, tmp_matchesp ) )
1163 if ( dnNormalize(0, NULL, NULL, &bv,
1164 &pat, op->o_tmpmemctx )
1167 /* did not expand to a valid dn */
1175 patlen = pat.bv_len;
1176 odnlen = opndn->bv_len;
1177 if ( odnlen < patlen ) {
1178 goto dn_match_cleanup;
1182 if ( b->a_style == ACL_STYLE_BASE ) {
1183 /* base dn -- entire object DN must match */
1184 if ( odnlen != patlen ) {
1185 goto dn_match_cleanup;
1188 } else if ( b->a_style == ACL_STYLE_ONE ) {
1191 if ( odnlen <= patlen ) {
1192 goto dn_match_cleanup;
1195 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1196 goto dn_match_cleanup;
1199 rdnlen = dn_rdnlen( NULL, opndn );
1200 if ( rdnlen - ( odnlen - patlen - 1 ) != 0 ) {
1201 goto dn_match_cleanup;
1204 } else if ( b->a_style == ACL_STYLE_SUBTREE ) {
1205 if ( odnlen > patlen && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1206 goto dn_match_cleanup;
1209 } else if ( b->a_style == ACL_STYLE_CHILDREN ) {
1210 if ( odnlen <= patlen ) {
1211 goto dn_match_cleanup;
1214 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1215 goto dn_match_cleanup;
1218 } else if ( b->a_style == ACL_STYLE_LEVEL ) {
1219 int level = b->a_level;
1222 if ( odnlen <= patlen ) {
1223 goto dn_match_cleanup;
1226 if ( level > 0 && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) )
1228 goto dn_match_cleanup;
1232 for ( ; level > 0; level-- ) {
1233 if ( BER_BVISEMPTY( &ndn ) ) {
1234 goto dn_match_cleanup;
1236 dnParent( &ndn, &ndn );
1237 if ( ndn.bv_len < patlen ) {
1238 goto dn_match_cleanup;
1242 if ( ndn.bv_len != patlen ) {
1243 goto dn_match_cleanup;
1247 got_match = !strcmp( pat.bv_val, &opndn->bv_val[ odnlen - patlen ] );
1250 if ( pat.bv_val != b->a_pat.bv_val ) {
1251 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
1263 * Record value-dependent access control state
1265 #define ACL_RECORD_VALUE_STATE do { \
1266 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
1267 state->as_recorded |= ACL_STATE_RECORDED_VD; \
1268 state->as_vd_acl = a; \
1269 AC_MEMCPY( state->as_vd_acl_matches, matches, \
1270 sizeof( state->as_vd_acl_matches )) ; \
1271 state->as_vd_acl_count = count; \
1272 state->as_vd_access = b; \
1273 state->as_vd_access_count = i; \
1285 regmatch_t *matches,
1287 AccessControlState *state,
1288 slap_dn_access *bdn,
1289 struct berval *opndn )
1295 const char *attr = bdn->a_at->ad_cname.bv_val;
1297 assert( attr != NULL );
1299 if ( BER_BVISEMPTY( opndn ) ) {
1303 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n", attr, 0, 0 );
1306 /* see if asker is listed in dnattr */
1307 for ( at = attrs_find( e->e_attrs, bdn->a_at );
1309 at = attrs_find( at->a_next, bdn->a_at ) )
1311 if ( value_find_ex( bdn->a_at,
1312 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1313 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1315 &bv, op->o_tmpmemctx ) == 0 )
1324 /* have a dnattr match. if this is a self clause then
1325 * the target must also match the op dn.
1327 if ( bdn->a_self ) {
1328 /* check if the target is an attribute. */
1329 if ( val == NULL ) return 1;
1331 /* target is attribute, check if the attribute value
1334 rc = value_match( &match, bdn->a_at,
1335 bdn->a_at->ad_type->sat_equality, 0,
1337 /* on match error or no match, fail the ACL clause */
1338 if ( rc != LDAP_SUCCESS || match != 0 )
1343 /* no dnattr match, check if this is a self clause */
1344 if ( ! bdn->a_self )
1347 ACL_RECORD_VALUE_STATE;
1349 /* this is a self clause, check if the target is an
1355 /* target is attribute, check if the attribute value
1358 rc = value_match( &match, bdn->a_at,
1359 bdn->a_at->ad_type->sat_equality, 0,
1362 /* on match error or no match, fail the ACL clause */
1363 if ( rc != LDAP_SUCCESS || match != 0 )
1372 * slap_acl_mask - modifies mask based upon the given acl and the
1373 * requested access to entry e, attribute attr, value val. if val
1374 * is null, access to the whole attribute is assumed (all values).
1376 * returns 0 access NOT allowed
1380 static slap_control_t
1386 AttributeDescription *desc,
1389 regmatch_t *matches,
1391 AccessControlState *state )
1396 char accessmaskbuf[ACCESSMASK_MAXLEN];
1397 #if !defined( SLAP_DYNACL ) && defined( SLAPD_ACI_ENABLED )
1398 char accessmaskbuf1[ACCESSMASK_MAXLEN];
1399 #endif /* !SLAP_DYNACL && SLAPD_ACI_ENABLED */
1402 slap_mask_t a2pmask = ACL_ACCESS2PRIV( *mask );
1404 assert( a != NULL );
1405 assert( mask != NULL );
1406 assert( desc != NULL );
1408 attr = desc->ad_cname.bv_val;
1410 assert( attr != NULL );
1412 Debug( LDAP_DEBUG_ACL,
1413 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
1416 Debug( LDAP_DEBUG_ACL,
1417 "=> acl_mask: to %s by \"%s\", (%s) \n",
1418 val ? "value" : "all values",
1419 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
1420 accessmask2str( *mask, accessmaskbuf, 1 ) );
1423 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
1424 && state->as_vd_acl == a )
1426 b = state->as_vd_access;
1427 i = state->as_vd_access_count;
1434 for ( ; b != NULL; b = b->a_next, i++ ) {
1435 slap_mask_t oldmask, modmask;
1437 ACL_INVALIDATE( modmask );
1439 /* AND <who> clauses */
1440 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
1441 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
1442 b->a_dn_pat.bv_val, 0, 0);
1444 * if access applies to the entry itself, and the
1445 * user is bound as somebody in the same namespace as
1446 * the entry, OR the given dn matches the dn pattern
1449 * NOTE: styles "anonymous", "users" and "self"
1450 * have been moved to enum slap_style_t, whose
1451 * value is set in a_dn_style; however, the string
1452 * is maintaned in a_dn_pat.
1455 if ( acl_mask_dn( op, e, a, nmatch, matches,
1456 &b->a_dn, &op->o_ndn ) )
1462 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
1465 Debug( LDAP_DEBUG_ACL, "<= check a_realdn_pat: %s\n",
1466 b->a_realdn_pat.bv_val, 0, 0);
1468 * if access applies to the entry itself, and the
1469 * user is bound as somebody in the same namespace as
1470 * the entry, OR the given dn matches the dn pattern
1473 * NOTE: styles "anonymous", "users" and "self"
1474 * have been moved to enum slap_style_t, whose
1475 * value is set in a_dn_style; however, the string
1476 * is maintaned in a_dn_pat.
1479 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1481 ndn = op->o_conn->c_ndn;
1486 if ( acl_mask_dn( op, e, a, nmatch, matches,
1487 &b->a_realdn, &ndn ) )
1493 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1494 if ( ! op->o_conn->c_listener ) {
1497 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
1498 b->a_sockurl_pat.bv_val, 0, 0 );
1500 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
1501 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
1502 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
1503 e->e_ndn, nmatch, matches ) )
1508 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
1510 char buf[ACL_BUF_SIZE];
1512 bv.bv_len = sizeof( buf ) - 1;
1514 if ( acl_string_expand( &bv, &b->a_sockurl_pat,
1515 e->e_ndn, nmatch, matches ) )
1520 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1526 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1534 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1535 if ( !op->o_conn->c_peer_domain.bv_val ) {
1538 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1539 b->a_domain_pat.bv_val, 0, 0 );
1540 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1541 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1542 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1543 e->e_ndn, nmatch, matches ) )
1548 char buf[ACL_BUF_SIZE];
1550 struct berval cmp = op->o_conn->c_peer_domain;
1551 struct berval pat = b->a_domain_pat;
1553 if ( b->a_domain_expand ) {
1556 bv.bv_len = sizeof(buf) - 1;
1559 if ( acl_string_expand(&bv, &b->a_domain_pat,
1560 e->e_ndn, nmatch, matches) )
1567 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1568 int offset = cmp.bv_len - pat.bv_len;
1573 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1577 /* trim the domain */
1578 cmp.bv_val = &cmp.bv_val[ offset ];
1579 cmp.bv_len -= offset;
1582 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1589 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1590 if ( !op->o_conn->c_peer_name.bv_val ) {
1593 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1594 b->a_peername_pat.bv_val, 0, 0 );
1595 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1596 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1597 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1598 e->e_ndn, nmatch, matches ) )
1604 /* try exact match */
1605 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1606 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1610 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1612 char buf[ACL_BUF_SIZE];
1614 bv.bv_len = sizeof( buf ) - 1;
1616 if ( acl_string_expand( &bv, &b->a_peername_pat,
1617 e->e_ndn, nmatch, matches ) )
1622 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1626 /* extract IP and try exact match */
1627 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1629 char buf[] = "255.255.255.255";
1632 int port_number = -1;
1634 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1635 aci_bv[ ACI_BV_IP_EQ ].bv_val,
1636 aci_bv[ ACI_BV_IP_EQ ].bv_len ) != 0 )
1639 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv[ ACI_BV_IP_EQ ].bv_len;
1640 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv[ ACI_BV_IP_EQ ].bv_len;
1642 port = strrchr( ip.bv_val, ':' );
1646 ip.bv_len = port - ip.bv_val;
1648 port_number = strtol( port, &next, 10 );
1649 if ( next[0] != '\0' )
1653 /* the port check can be anticipated here */
1654 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1657 /* address longer than expected? */
1658 if ( ip.bv_len >= sizeof(buf) )
1661 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1662 buf[ ip.bv_len ] = '\0';
1664 addr = inet_addr( buf );
1666 /* unable to convert? */
1667 if ( addr == (unsigned long)(-1) )
1670 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1673 #ifdef LDAP_PF_LOCAL
1674 /* extract path and try exact match */
1675 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1678 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1679 aci_bv[ ACI_BV_PATH_EQ ].bv_val,
1680 aci_bv[ ACI_BV_PATH_EQ ].bv_len ) != 0 )
1683 path.bv_val = op->o_conn->c_peer_name.bv_val
1684 + aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1685 path.bv_len = op->o_conn->c_peer_name.bv_len
1686 - aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1688 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1691 #endif /* LDAP_PF_LOCAL */
1693 /* exact match (very unlikely...) */
1694 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1701 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1702 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1705 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1706 b->a_sockname_pat.bv_val, 0, 0 );
1707 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1708 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1709 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1710 e->e_ndn, nmatch, matches ) )
1715 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1717 char buf[ACL_BUF_SIZE];
1719 bv.bv_len = sizeof( buf ) - 1;
1721 if ( acl_string_expand( &bv, &b->a_sockname_pat,
1722 e->e_ndn, nmatch, matches ) )
1727 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1732 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1739 if ( b->a_dn_at != NULL ) {
1740 if ( acl_mask_dnattr( op, e, val, a, b, i,
1741 matches, count, state,
1742 &b->a_dn, &op->o_ndn ) )
1748 if ( b->a_realdn_at != NULL ) {
1751 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1753 ndn = op->o_conn->c_ndn;
1758 if ( acl_mask_dnattr( op, e, val, a, b, i,
1759 matches, count, state,
1760 &b->a_realdn, &ndn ) )
1766 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1768 struct berval ndn = BER_BVNULL;
1771 if ( op->o_ndn.bv_len == 0 ) {
1775 Debug( LDAP_DEBUG_ACL, "<= check a_group_pat: %s\n",
1776 b->a_group_pat.bv_val, 0, 0 );
1778 /* b->a_group is an unexpanded entry name, expanded it should be an
1779 * entry with objectclass group* and we test to see if odn is one of
1780 * the values in the attribute group
1782 /* see if asker is listed in dnattr */
1783 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1784 char buf[ACL_BUF_SIZE];
1786 regmatch_t tmp_matches[2],
1787 *tmp_matchesp = tmp_matches;
1789 bv.bv_len = sizeof(buf) - 1;
1794 switch ( a->acl_dn_style ) {
1795 case ACL_STYLE_REGEX:
1796 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1797 tmp_matchesp = matches;
1798 tmp_nmatch = nmatch;
1802 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1803 case ACL_STYLE_BASE:
1804 tmp_matches[0].rm_so = 0;
1805 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1810 case ACL_STYLE_SUBTREE:
1811 case ACL_STYLE_CHILDREN:
1812 tmp_matches[0].rm_so = 0;
1813 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1814 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1815 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1829 if ( acl_string_expand( &bv, &b->a_group_pat,
1831 tmp_nmatch, tmp_matchesp ) )
1836 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1837 op->o_tmpmemctx ) != LDAP_SUCCESS )
1839 /* did not expand to a valid dn */
1846 bv = b->a_group_pat;
1849 rc = backend_group( op, e, &bv, &op->o_ndn,
1850 b->a_group_oc, b->a_group_at );
1853 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1861 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1863 char buf[ACL_BUF_SIZE];
1865 Debug( LDAP_DEBUG_ACL, "<= check a_set_pat: %s\n",
1866 b->a_set_pat.bv_val, 0, 0 );
1868 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1870 regmatch_t tmp_matches[2],
1871 *tmp_matchesp = tmp_matches;
1874 bv.bv_len = sizeof( buf ) - 1;
1879 switch ( a->acl_dn_style ) {
1880 case ACL_STYLE_REGEX:
1881 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1882 tmp_matchesp = matches;
1883 tmp_nmatch = nmatch;
1887 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1888 case ACL_STYLE_BASE:
1889 tmp_matches[0].rm_so = 0;
1890 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1895 case ACL_STYLE_SUBTREE:
1896 case ACL_STYLE_CHILDREN:
1897 tmp_matches[0].rm_so = 0;
1898 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1899 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1900 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1914 if ( acl_string_expand( &bv, &b->a_set_pat,
1916 tmp_nmatch, tmp_matchesp ) )
1925 if ( acl_match_set( &bv, op, e, 0 ) == 0 ) {
1930 if ( b->a_authz.sai_ssf ) {
1931 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1932 b->a_authz.sai_ssf, op->o_ssf, 0 );
1933 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1938 if ( b->a_authz.sai_transport_ssf ) {
1939 Debug( LDAP_DEBUG_ACL,
1940 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1941 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1942 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1947 if ( b->a_authz.sai_tls_ssf ) {
1948 Debug( LDAP_DEBUG_ACL,
1949 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1950 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1951 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1956 if ( b->a_authz.sai_sasl_ssf ) {
1957 Debug( LDAP_DEBUG_ACL,
1958 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1959 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1960 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1966 if ( b->a_dynacl ) {
1968 slap_access_t tgrant, tdeny;
1970 Debug( LDAP_DEBUG_ACL, "<= check a_dynacl\n",
1973 /* this case works different from the others above.
1974 * since aci's themselves give permissions, we need
1975 * to first check b->a_access_mask, the ACL's access level.
1977 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1978 /* no ACIs in the root DSE */
1982 /* first check if the right being requested
1983 * is allowed by the ACL clause.
1985 if ( ! ACL_PRIV_ISSET( b->a_access_mask, a2pmask ) ) {
1989 /* start out with nothing granted, nothing denied */
1993 for ( da = b->a_dynacl; da; da = da->da_next ) {
1994 slap_access_t grant,
2000 Debug( LDAP_DEBUG_ACL, " <= check a_dynacl: %s\n",
2001 da->da_name, 0, 0 );
2003 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
2009 /* remove anything that the ACL clause does not allow */
2010 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2011 tdeny &= ACL_PRIV_MASK;
2013 /* see if we have anything to contribute */
2014 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2018 /* this could be improved by changing slap_acl_mask so that it can deal with
2019 * by clauses that return grant/deny pairs. Right now, it does either
2020 * additive or subtractive rights, but not both at the same time. So,
2021 * we need to combine the grant/deny pair into a single rights mask in
2022 * a smart way: if either grant or deny is "empty", then we use the
2023 * opposite as is, otherwise we remove any denied rights from the grant
2024 * rights mask and construct an additive mask.
2026 if (ACL_IS_INVALID(tdeny)) {
2027 modmask = tgrant | ACL_PRIV_ADDITIVE;
2029 } else if (ACL_IS_INVALID(tgrant)) {
2030 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2033 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2037 #else /* !SLAP_DYNACL */
2039 #ifdef SLAPD_ACI_ENABLED
2040 if ( b->a_aci_at != NULL ) {
2042 slap_access_t grant, deny, tgrant, tdeny;
2043 struct berval parent_ndn;
2044 BerVarray bvals = NULL;
2047 Debug( LDAP_DEBUG_ACL, " <= check a_aci_at: %s\n",
2048 b->a_aci_at->ad_cname.bv_val, 0, 0 );
2050 /* this case works different from the others above.
2051 * since aci's themselves give permissions, we need
2052 * to first check b->a_access_mask, the ACL's access level.
2055 if ( BER_BVISEMPTY( &e->e_nname ) ) {
2056 /* no ACIs in the root DSE */
2060 /* first check if the right being requested
2061 * is allowed by the ACL clause.
2063 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
2066 /* start out with nothing granted, nothing denied */
2070 /* get the aci attribute */
2071 at = attr_find( e->e_attrs, b->a_aci_at );
2074 /* FIXME: this breaks acl caching;
2075 * see also ACL_RECORD_VALUE_STATE below */
2076 ACL_RECORD_VALUE_STATE;
2078 /* the aci is an multi-valued attribute. The
2079 * rights are determined by OR'ing the individual
2080 * rights given by the acis.
2082 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2087 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0 )
2093 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2094 accessmask2str(tgrant, accessmaskbuf, 1),
2095 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2098 /* If the entry level aci didn't contain anything valid for the
2099 * current operation, climb up the tree and evaluate the
2100 * acis with scope set to subtree
2102 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
2103 dnParent( &e->e_nname, &parent_ndn );
2104 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
2105 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
2106 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
2114 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++ ) {
2116 /* FIXME: this breaks acl caching;
2117 * see also ACL_RECORD_VALUE_STATE above */
2118 ACL_RECORD_VALUE_STATE;
2120 if ( aci_mask( op, e, desc, val, &bvals[i],
2122 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2126 /* evaluation stops as soon as either a "deny" or a
2127 * "grant" directive matches.
2129 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
2133 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2134 accessmask2str(tgrant, accessmaskbuf, 1),
2135 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2139 case LDAP_NO_SUCH_ATTRIBUTE:
2140 /* just go on if the aci-Attribute is not present in
2143 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
2147 case LDAP_NO_SUCH_OBJECT:
2148 /* We have reached the base object */
2149 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
2160 dnParent( &parent_ndn, &parent_ndn );
2165 /* remove anything that the ACL clause does not allow */
2166 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2167 tdeny &= ACL_PRIV_MASK;
2169 /* see if we have anything to contribute */
2170 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2174 /* this could be improved by changing slap_acl_mask so that it can deal with
2175 * by clauses that return grant/deny pairs. Right now, it does either
2176 * additive or subtractive rights, but not both at the same time. So,
2177 * we need to combine the grant/deny pair into a single rights mask in
2178 * a smart way: if either grant or deny is "empty", then we use the
2179 * opposite as is, otherwise we remove any denied rights from the grant
2180 * rights mask and construct an additive mask.
2182 if (ACL_IS_INVALID(tdeny)) {
2183 modmask = tgrant | ACL_PRIV_ADDITIVE;
2185 } else if (ACL_IS_INVALID(tgrant)) {
2186 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2189 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2193 #endif /* SLAPD_ACI_ENABLED */
2194 #endif /* !SLAP_DYNACL */
2196 modmask = b->a_access_mask;
2199 Debug( LDAP_DEBUG_ACL,
2200 "<= acl_mask: [%d] applying %s (%s)\n",
2201 i, accessmask2str( modmask, accessmaskbuf, 1 ),
2202 b->a_type == ACL_CONTINUE
2204 : b->a_type == ACL_BREAK
2210 if( ACL_IS_ADDITIVE(modmask) ) {
2212 ACL_PRIV_SET( *mask, modmask );
2215 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2217 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
2218 /* substract privs */
2219 ACL_PRIV_CLR( *mask, modmask );
2222 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2231 Debug( LDAP_DEBUG_ACL,
2232 "<= acl_mask: [%d] mask: %s\n",
2233 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
2235 if( b->a_type == ACL_CONTINUE ) {
2238 } else if ( b->a_type == ACL_BREAK ) {
2246 /* implicit "by * none" clause */
2249 Debug( LDAP_DEBUG_ACL,
2250 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
2251 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
2256 * acl_check_modlist - check access control on the given entry to see if
2257 * it allows the given modifications by the user associated with op.
2258 * returns 1 if mods allowed ok
2259 * 0 mods not allowed
2266 Modifications *mlist )
2269 AccessControlState state = ACL_STATE_INIT;
2272 int ret = 1; /* default is access allowed */
2276 be = LDAP_STAILQ_FIRST(&backendDB);
2280 assert( be != NULL );
2282 /* short circuit root database access */
2283 if ( be_isroot( op ) ) {
2284 Debug( LDAP_DEBUG_ACL,
2285 "<= acl_access_allowed: granted to database root\n",
2290 /* use backend default access if no backend acls */
2291 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
2292 Debug( LDAP_DEBUG_ACL,
2293 "=> access_allowed: backend default %s access %s to \"%s\"\n",
2294 access2str( ACL_WRITE ),
2295 op->o_bd->be_dfltaccess >= ACL_WRITE
2296 ? "granted" : "denied",
2298 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
2302 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
2304 * Internal mods are ignored by ACL_WRITE checking
2306 if ( mlist->sml_flags & SLAP_MOD_INTERNAL ) {
2307 Debug( LDAP_DEBUG_ACL, "acl: internal mod %s:"
2308 " modify access granted\n",
2309 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2314 * no-user-modification operational attributes are ignored
2315 * by ACL_WRITE checking as any found here are not provided
2318 if ( is_at_no_user_mod( mlist->sml_desc->ad_type )
2319 && ! ( mlist->sml_flags & SLAP_MOD_MANAGING ) )
2321 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
2322 " modify access granted\n",
2323 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2327 switch ( mlist->sml_op ) {
2328 case LDAP_MOD_REPLACE:
2330 * We must check both permission to delete the whole
2331 * attribute and permission to add the specific attributes.
2332 * This prevents abuse from selfwriters.
2334 if ( ! access_allowed( op, e,
2335 mlist->sml_desc, NULL,
2336 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2343 if ( mlist->sml_values == NULL ) break;
2345 /* fall thru to check value to add */
2348 assert( mlist->sml_values != NULL );
2350 for ( bv = mlist->sml_nvalues
2351 ? mlist->sml_nvalues : mlist->sml_values;
2352 bv->bv_val != NULL; bv++ )
2354 if ( ! access_allowed( op, e,
2355 mlist->sml_desc, bv,
2356 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WADD,
2365 case LDAP_MOD_DELETE:
2366 if ( mlist->sml_values == NULL ) {
2367 if ( ! access_allowed( op, e,
2368 mlist->sml_desc, NULL,
2369 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2377 for ( bv = mlist->sml_nvalues
2378 ? mlist->sml_nvalues : mlist->sml_values;
2379 bv->bv_val != NULL; bv++ )
2381 if ( ! access_allowed( op, e,
2382 mlist->sml_desc, bv,
2383 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2392 case SLAP_MOD_SOFTADD:
2393 /* allow adding attribute via modrdn thru */
2405 if (be_null) op->o_bd = NULL;
2411 struct berval *list,
2424 while ( len >= 0 && --ix >= 0 ) {
2425 while ( --len >= 0 && *p++ != sep )
2428 while ( len >= 0 && *p == ' ' ) {
2441 while ( --len >= 0 && *p != sep ) {
2445 while ( bv->bv_len > 0 && *--p == ' ' ) {
2452 typedef struct acl_set_gather_t {
2458 acl_set_cb_gather( Operation *op, SlapReply *rs )
2460 acl_set_gather_t *p = (acl_set_gather_t *)op->o_callback->sc_private;
2462 if ( rs->sr_type == REP_SEARCH ) {
2463 BerValue bvals[ 2 ];
2464 BerVarray bvalsp = NULL;
2467 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
2468 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
2470 if ( desc == slap_schema.si_ad_entryDN ) {
2472 bvals[ 0 ] = rs->sr_entry->e_nname;
2473 BER_BVZERO( &bvals[ 1 ] );
2478 a = attr_find( rs->sr_entry->e_attrs, desc );
2482 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
2485 bvalsp = a->a_nvals;
2491 p->bvals = slap_set_join( p->cookie, p->bvals,
2492 ( '|' | SLAP_SET_RREF ), bvalsp );
2496 assert( rs->sr_type == REP_RESULT );
2503 acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2505 AclSetCookie *cp = (AclSetCookie *)cookie;
2507 LDAPURLDesc *ludp = NULL;
2508 Operation op2 = { 0 };
2509 SlapReply rs = {REP_RESULT};
2510 AttributeName anlist[ 2 ], *anlistp = NULL;
2512 slap_callback cb = { NULL, acl_set_cb_gather, NULL, NULL };
2513 acl_set_gather_t p = { 0 };
2514 const char *text = NULL;
2515 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2517 /* this routine needs to return the bervals instead of
2518 * plain strings, since syntax is not known. It should
2519 * also return the syntax or some "comparison cookie".
2521 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2522 return acl_set_gather2( cookie, name, desc );
2525 rc = ldap_url_parse( name->bv_val, &ludp );
2526 if ( rc != LDAP_URL_SUCCESS ) {
2527 rc = LDAP_PROTOCOL_ERROR;
2531 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2533 /* host part must be empty */
2534 /* extensions parts must be empty */
2535 rc = LDAP_PROTOCOL_ERROR;
2539 /* Grab the searchbase and see if an appropriate database can be found */
2540 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2541 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2542 &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2543 BER_BVZERO( &op2.o_req_dn );
2544 if ( rc != LDAP_SUCCESS ) {
2548 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2549 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2550 rc = LDAP_NO_SUCH_OBJECT;
2554 /* Grab the filter */
2555 if ( ludp->lud_filter ) {
2556 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2557 cp->asc_op->o_tmpmemctx );
2560 op2.ors_filterstr = defaultFilter_bv;
2563 op2.ors_filter = str2filter_x( cp->asc_op, op2.ors_filterstr.bv_val );
2564 if ( op2.ors_filter == NULL ) {
2565 rc = LDAP_PROTOCOL_ERROR;
2569 /* Grab the scope */
2570 op2.ors_scope = ludp->lud_scope;
2572 /* Grap the attributes */
2573 if ( ludp->lud_attrs ) {
2574 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2577 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2578 cp->asc_op->o_tmpmemctx );
2580 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2581 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2582 anlistp[ nattrs ].an_desc = NULL;
2583 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2584 &anlistp[ nattrs ].an_desc, &text );
2585 if ( rc != LDAP_SUCCESS ) {
2594 anlistp[ nattrs ].an_name = desc->ad_cname;
2595 anlistp[ nattrs ].an_desc = desc;
2597 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2601 op2.o_hdr = cp->asc_op->o_hdr;
2602 op2.o_tag = LDAP_REQ_SEARCH;
2603 op2.o_ndn = op2.o_bd->be_rootndn;
2604 op2.o_callback = &cb;
2605 op2.o_time = slap_get_time();
2606 op2.o_do_not_cache = 1;
2607 op2.o_is_auth_check = 0;
2608 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2609 op2.ors_slimit = SLAP_NO_LIMIT;
2610 op2.ors_tlimit = SLAP_NO_LIMIT;
2611 op2.ors_attrs = anlistp;
2612 op2.ors_attrsonly = 0;
2613 op2.o_private = cp->asc_op->o_private;
2617 rc = op2.o_bd->be_search( &op2, &rs );
2623 if ( op2.ors_filter ) {
2624 filter_free_x( cp->asc_op, op2.ors_filter );
2626 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2627 slap_sl_free( op2.o_req_ndn.bv_val, cp->asc_op->o_tmpmemctx );
2629 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2630 slap_sl_free( op2.o_req_dn.bv_val, cp->asc_op->o_tmpmemctx );
2633 ldap_free_urldesc( ludp );
2635 if ( anlistp && anlistp != anlist ) {
2636 slap_sl_free( anlistp, cp->asc_op->o_tmpmemctx );
2643 acl_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2645 AclSetCookie *cp = (AclSetCookie *)cookie;
2646 BerVarray bvals = NULL;
2650 /* this routine needs to return the bervals instead of
2651 * plain strings, since syntax is not known. It should
2652 * also return the syntax or some "comparison cookie".
2654 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->asc_op->o_tmpmemctx );
2655 if ( rc == LDAP_SUCCESS ) {
2656 if ( desc == slap_schema.si_ad_entryDN ) {
2657 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2658 cp->asc_op->o_tmpmemctx );
2660 BER_BVZERO( &bvals[ 1 ] );
2664 backend_attribute( cp->asc_op,
2665 cp->asc_e, &ndn, desc, &bvals, ACL_NONE );
2668 if ( !BER_BVISNULL( &ndn ) ) {
2669 slap_sl_free( ndn.bv_val, cp->asc_op->o_tmpmemctx );
2678 struct berval *subj,
2683 struct berval set = BER_BVNULL;
2685 AclSetCookie cookie;
2687 if ( setref == 0 ) {
2688 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2691 struct berval subjdn, ndn = BER_BVNULL;
2692 struct berval setat;
2695 AttributeDescription *desc = NULL;
2697 /* format of string is "entry/setAttrName" */
2698 if ( acl_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2702 if ( acl_get_part( subj, 1, '/', &setat ) < 0 ) {
2703 setat = aci_bv[ ACI_BV_SET_ATTR ];
2707 * NOTE: dnNormalize honors the ber_len field
2708 * as the length of the dn to be normalized
2710 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2711 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2713 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2714 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2718 BER_BVZERO( &bvals[0] );
2719 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2721 bvals[0].bv_val = bvals[i-1].bv_val;
2722 BER_BVZERO( &bvals[i-1] );
2724 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2725 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2730 if ( !BER_BVISNULL( &set ) ) {
2733 rc = ( slap_set_filter(
2735 (SetCookie *)&cookie, &set,
2736 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2737 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2746 * dynamic ACL infrastructure
2748 static slap_dynacl_t *da_list = NULL;
2751 slap_dynacl_register( slap_dynacl_t *da )
2755 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2756 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2761 if ( tmp != NULL ) {
2765 if ( da->da_mask == NULL ) {
2769 da->da_private = NULL;
2770 da->da_next = da_list;
2776 static slap_dynacl_t *
2777 slap_dynacl_next( slap_dynacl_t *da )
2786 slap_dynacl_get( const char *name )
2790 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2791 if ( strcasecmp( da->da_name, name ) == 0 ) {
2798 #endif /* SLAP_DYNACL */
2805 #ifdef SLAPD_ACI_ENABLED
2807 rc = dynacl_aci_init();
2808 #else /* !SLAP_DYNACL */
2810 #endif /* !SLAP_DYNACL */
2814 #endif /* SLAPD_ACI_ENABLED */
2825 regmatch_t *matches)
2833 bv->bv_val[0] = '\0';
2834 bv->bv_len--; /* leave space for lone $ */
2837 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2838 sp < pat->bv_val + pat->bv_len ; sp++ )
2840 /* did we previously see a $ */
2842 if ( flag == 1 && *sp == '$' ) {
2847 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2850 } else if ( *sp >= '0' && *sp <= '9' ) {
2858 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2859 if ( *sp >= '0' && *sp <= '9' ) {
2860 n = 10*n + ( *sp - '0' );
2864 if ( *sp != /*'{'*/ '}' ) {
2870 if ( n >= nmatch ) {
2876 i = matches[n].rm_so;
2877 l = matches[n].rm_eo;
2878 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2896 /* must have ended with a single $ */
2904 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2905 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2912 struct berval *pat, /* pattern to expand and match against */
2913 char *str, /* string to match against pattern */
2914 char *buf, /* buffer with $N expansion variables */
2915 int nmatch, /* size of the matches array */
2916 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2920 char newbuf[ACL_BUF_SIZE];
2924 bv.bv_len = sizeof( newbuf ) - 1;
2931 acl_string_expand( &bv, pat, buf, nmatch, matches );
2932 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2934 char error[ACL_BUF_SIZE];
2935 regerror( rc, &re, error, sizeof( error ) );
2937 Debug( LDAP_DEBUG_TRACE,
2938 "compile( \"%s\", \"%s\") failed %s\n",
2939 pat->bv_val, str, error );
2943 rc = regexec( &re, str, 0, NULL, 0 );
2946 Debug( LDAP_DEBUG_TRACE,
2947 "=> regex_matches: string: %s\n", str, 0, 0 );
2948 Debug( LDAP_DEBUG_TRACE,
2949 "=> regex_matches: rc: %d %s\n",
2950 rc, !rc ? "matches" : "no matches", 0 );