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 ber_len_t rdnlen = 0;
857 if ( dnlen <= patlen )
861 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
866 rdnlen = dn_rdnlen( NULL, &e->e_nname );
867 if ( rdnlen != dnlen - patlen - sep )
870 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
871 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
874 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
875 if ( dnlen <= patlen )
877 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
881 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
885 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
889 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
890 matches[0].rm_so = matches[0].rm_eo = -1;
894 /* Is this ACL only for a specific value? */
895 if ( a->acl_attrval.bv_len ) {
900 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
901 state->as_recorded |= ACL_STATE_RECORDED_VD;
902 state->as_vd_acl = a;
903 state->as_vd_acl_count = *count;
904 state->as_vd_access = a->acl_access;
905 state->as_vd_access_count = 1;
906 ACL_INVALIDATE( state->as_vd_acl_mask );
909 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
910 Debug( LDAP_DEBUG_ACL,
911 "acl_get: valpat %s\n",
912 a->acl_attrval.bv_val, 0, 0 );
913 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
921 Debug( LDAP_DEBUG_ACL,
923 a->acl_attrval.bv_val, 0, 0 );
925 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
926 if (value_match( &match, desc,
927 /* desc->ad_type->sat_equality */ a->acl_attrval_mr, 0,
928 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
935 patlen = a->acl_attrval.bv_len;
936 vdnlen = val->bv_len;
938 if ( vdnlen < patlen )
941 if ( a->acl_attrval_style == ACL_STYLE_BASE ) {
942 if ( vdnlen > patlen )
945 } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) {
946 ber_len_t rdnlen = 0;
948 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
951 rdnlen = dn_rdnlen( NULL, val );
952 if ( rdnlen != vdnlen - patlen - 1 )
955 } else if ( a->acl_attrval_style == ACL_STYLE_SUBTREE ) {
956 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
959 } else if ( a->acl_attrval_style == ACL_STYLE_CHILDREN ) {
960 if ( vdnlen <= patlen )
963 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
967 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
973 if ( a->acl_filter != NULL ) {
974 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
975 if ( rc != LDAP_COMPARE_TRUE ) {
980 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
985 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
997 struct berval *opndn )
1000 * if access applies to the entry itself, and the
1001 * user is bound as somebody in the same namespace as
1002 * the entry, OR the given dn matches the dn pattern
1005 * NOTE: styles "anonymous", "users" and "self"
1006 * have been moved to enum slap_style_t, whose
1007 * value is set in a_dn_style; however, the string
1008 * is maintaned in a_dn_pat.
1010 if ( b->a_style == ACL_STYLE_ANONYMOUS ) {
1011 if ( !BER_BVISEMPTY( opndn ) ) {
1015 } else if ( b->a_style == ACL_STYLE_USERS ) {
1016 if ( BER_BVISEMPTY( opndn ) ) {
1020 } else if ( b->a_style == ACL_STYLE_SELF ) {
1021 struct berval ndn, selfndn;
1024 if ( BER_BVISEMPTY( opndn ) || BER_BVISNULL( &e->e_nname ) ) {
1028 level = b->a_self_level;
1036 selfndn = e->e_nname;
1039 for ( ; level > 0; level-- ) {
1040 if ( BER_BVISEMPTY( &ndn ) ) {
1043 dnParent( &ndn, &ndn );
1046 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
1051 } else if ( b->a_style == ACL_STYLE_REGEX ) {
1052 if ( !ber_bvccmp( &b->a_pat, '*' ) ) {
1054 regmatch_t tmp_matches[2],
1055 *tmp_matchesp = tmp_matches;
1059 switch ( a->acl_dn_style ) {
1060 case ACL_STYLE_REGEX:
1061 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1062 tmp_matchesp = matches;
1063 tmp_nmatch = nmatch;
1066 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1068 case ACL_STYLE_BASE:
1069 tmp_matches[0].rm_so = 0;
1070 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1075 case ACL_STYLE_SUBTREE:
1076 case ACL_STYLE_CHILDREN:
1077 tmp_matches[0].rm_so = 0;
1078 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1079 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1080 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1094 if ( !regex_matches( &b->a_pat, opndn->bv_val,
1095 e->e_ndn, tmp_nmatch, tmp_matchesp ) )
1103 ber_len_t patlen, odnlen;
1106 if ( e->e_dn == NULL )
1109 if ( b->a_expand ) {
1111 char buf[ACL_BUF_SIZE];
1114 regmatch_t tmp_matches[2],
1115 *tmp_matchesp = tmp_matches;
1119 bv.bv_len = sizeof( buf ) - 1;
1122 switch ( a->acl_dn_style ) {
1123 case ACL_STYLE_REGEX:
1124 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1125 tmp_matchesp = matches;
1126 tmp_nmatch = nmatch;
1129 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1131 case ACL_STYLE_BASE:
1132 tmp_matches[0].rm_so = 0;
1133 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1138 case ACL_STYLE_SUBTREE:
1139 case ACL_STYLE_CHILDREN:
1140 tmp_matches[0].rm_so = 0;
1141 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1142 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1143 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1157 if ( acl_string_expand( &bv, &b->a_pat,
1159 tmp_nmatch, tmp_matchesp ) )
1164 if ( dnNormalize(0, NULL, NULL, &bv,
1165 &pat, op->o_tmpmemctx )
1168 /* did not expand to a valid dn */
1176 patlen = pat.bv_len;
1177 odnlen = opndn->bv_len;
1178 if ( odnlen < patlen ) {
1179 goto dn_match_cleanup;
1183 if ( b->a_style == ACL_STYLE_BASE ) {
1184 /* base dn -- entire object DN must match */
1185 if ( odnlen != patlen ) {
1186 goto dn_match_cleanup;
1189 } else if ( b->a_style == ACL_STYLE_ONE ) {
1190 ber_len_t rdnlen = 0;
1192 if ( odnlen <= patlen ) {
1193 goto dn_match_cleanup;
1196 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1197 goto dn_match_cleanup;
1200 rdnlen = dn_rdnlen( NULL, opndn );
1201 if ( rdnlen - ( odnlen - patlen - 1 ) != 0 ) {
1202 goto dn_match_cleanup;
1205 } else if ( b->a_style == ACL_STYLE_SUBTREE ) {
1206 if ( odnlen > patlen && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1207 goto dn_match_cleanup;
1210 } else if ( b->a_style == ACL_STYLE_CHILDREN ) {
1211 if ( odnlen <= patlen ) {
1212 goto dn_match_cleanup;
1215 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1216 goto dn_match_cleanup;
1219 } else if ( b->a_style == ACL_STYLE_LEVEL ) {
1220 int level = b->a_level;
1223 if ( odnlen <= patlen ) {
1224 goto dn_match_cleanup;
1227 if ( level > 0 && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) )
1229 goto dn_match_cleanup;
1233 for ( ; level > 0; level-- ) {
1234 if ( BER_BVISEMPTY( &ndn ) ) {
1235 goto dn_match_cleanup;
1237 dnParent( &ndn, &ndn );
1238 if ( ndn.bv_len < patlen ) {
1239 goto dn_match_cleanup;
1243 if ( ndn.bv_len != patlen ) {
1244 goto dn_match_cleanup;
1248 got_match = !strcmp( pat.bv_val, &opndn->bv_val[ odnlen - patlen ] );
1251 if ( pat.bv_val != b->a_pat.bv_val ) {
1252 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
1264 * Record value-dependent access control state
1266 #define ACL_RECORD_VALUE_STATE do { \
1267 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
1268 state->as_recorded |= ACL_STATE_RECORDED_VD; \
1269 state->as_vd_acl = a; \
1270 AC_MEMCPY( state->as_vd_acl_matches, matches, \
1271 sizeof( state->as_vd_acl_matches )) ; \
1272 state->as_vd_acl_count = count; \
1273 state->as_vd_access = b; \
1274 state->as_vd_access_count = i; \
1286 regmatch_t *matches,
1288 AccessControlState *state,
1289 slap_dn_access *bdn,
1290 struct berval *opndn )
1296 const char *attr = bdn->a_at->ad_cname.bv_val;
1298 assert( attr != NULL );
1300 if ( BER_BVISEMPTY( opndn ) ) {
1304 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n", attr, 0, 0 );
1307 /* see if asker is listed in dnattr */
1308 for ( at = attrs_find( e->e_attrs, bdn->a_at );
1310 at = attrs_find( at->a_next, bdn->a_at ) )
1312 if ( value_find_ex( bdn->a_at,
1313 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1314 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1316 &bv, op->o_tmpmemctx ) == 0 )
1325 /* have a dnattr match. if this is a self clause then
1326 * the target must also match the op dn.
1328 if ( bdn->a_self ) {
1329 /* check if the target is an attribute. */
1330 if ( val == NULL ) return 1;
1332 /* target is attribute, check if the attribute value
1335 rc = value_match( &match, bdn->a_at,
1336 bdn->a_at->ad_type->sat_equality, 0,
1338 /* on match error or no match, fail the ACL clause */
1339 if ( rc != LDAP_SUCCESS || match != 0 )
1344 /* no dnattr match, check if this is a self clause */
1345 if ( ! bdn->a_self )
1348 ACL_RECORD_VALUE_STATE;
1350 /* this is a self clause, check if the target is an
1356 /* target is attribute, check if the attribute value
1359 rc = value_match( &match, bdn->a_at,
1360 bdn->a_at->ad_type->sat_equality, 0,
1363 /* on match error or no match, fail the ACL clause */
1364 if ( rc != LDAP_SUCCESS || match != 0 )
1373 * slap_acl_mask - modifies mask based upon the given acl and the
1374 * requested access to entry e, attribute attr, value val. if val
1375 * is null, access to the whole attribute is assumed (all values).
1377 * returns 0 access NOT allowed
1381 static slap_control_t
1387 AttributeDescription *desc,
1390 regmatch_t *matches,
1392 AccessControlState *state )
1397 char accessmaskbuf[ACCESSMASK_MAXLEN];
1398 #if !defined( SLAP_DYNACL ) && defined( SLAPD_ACI_ENABLED )
1399 char accessmaskbuf1[ACCESSMASK_MAXLEN];
1400 #endif /* !SLAP_DYNACL && SLAPD_ACI_ENABLED */
1403 slap_mask_t a2pmask = ACL_ACCESS2PRIV( *mask );
1405 assert( a != NULL );
1406 assert( mask != NULL );
1407 assert( desc != NULL );
1409 attr = desc->ad_cname.bv_val;
1411 assert( attr != NULL );
1413 Debug( LDAP_DEBUG_ACL,
1414 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
1417 Debug( LDAP_DEBUG_ACL,
1418 "=> acl_mask: to %s by \"%s\", (%s) \n",
1419 val ? "value" : "all values",
1420 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
1421 accessmask2str( *mask, accessmaskbuf, 1 ) );
1424 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
1425 && state->as_vd_acl == a )
1427 b = state->as_vd_access;
1428 i = state->as_vd_access_count;
1435 for ( ; b != NULL; b = b->a_next, i++ ) {
1436 slap_mask_t oldmask, modmask;
1438 ACL_INVALIDATE( modmask );
1440 /* AND <who> clauses */
1441 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
1442 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
1443 b->a_dn_pat.bv_val, 0, 0);
1445 * if access applies to the entry itself, and the
1446 * user is bound as somebody in the same namespace as
1447 * the entry, OR the given dn matches the dn pattern
1450 * NOTE: styles "anonymous", "users" and "self"
1451 * have been moved to enum slap_style_t, whose
1452 * value is set in a_dn_style; however, the string
1453 * is maintaned in a_dn_pat.
1456 if ( acl_mask_dn( op, e, a, nmatch, matches,
1457 &b->a_dn, &op->o_ndn ) )
1463 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
1466 Debug( LDAP_DEBUG_ACL, "<= check a_realdn_pat: %s\n",
1467 b->a_realdn_pat.bv_val, 0, 0);
1469 * if access applies to the entry itself, and the
1470 * user is bound as somebody in the same namespace as
1471 * the entry, OR the given dn matches the dn pattern
1474 * NOTE: styles "anonymous", "users" and "self"
1475 * have been moved to enum slap_style_t, whose
1476 * value is set in a_dn_style; however, the string
1477 * is maintaned in a_dn_pat.
1480 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1482 ndn = op->o_conn->c_ndn;
1487 if ( acl_mask_dn( op, e, a, nmatch, matches,
1488 &b->a_realdn, &ndn ) )
1494 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1495 if ( ! op->o_conn->c_listener ) {
1498 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
1499 b->a_sockurl_pat.bv_val, 0, 0 );
1501 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
1502 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
1503 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
1504 e->e_ndn, nmatch, matches ) )
1509 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
1511 char buf[ACL_BUF_SIZE];
1513 bv.bv_len = sizeof( buf ) - 1;
1515 if ( acl_string_expand( &bv, &b->a_sockurl_pat,
1516 e->e_ndn, nmatch, matches ) )
1521 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1527 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1535 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1536 if ( !op->o_conn->c_peer_domain.bv_val ) {
1539 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1540 b->a_domain_pat.bv_val, 0, 0 );
1541 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1542 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1543 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1544 e->e_ndn, nmatch, matches ) )
1549 char buf[ACL_BUF_SIZE];
1551 struct berval cmp = op->o_conn->c_peer_domain;
1552 struct berval pat = b->a_domain_pat;
1554 if ( b->a_domain_expand ) {
1557 bv.bv_len = sizeof(buf) - 1;
1560 if ( acl_string_expand(&bv, &b->a_domain_pat,
1561 e->e_ndn, nmatch, matches) )
1568 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1569 int offset = cmp.bv_len - pat.bv_len;
1574 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1578 /* trim the domain */
1579 cmp.bv_val = &cmp.bv_val[ offset ];
1580 cmp.bv_len -= offset;
1583 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1590 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1591 if ( !op->o_conn->c_peer_name.bv_val ) {
1594 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1595 b->a_peername_pat.bv_val, 0, 0 );
1596 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1597 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1598 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1599 e->e_ndn, nmatch, matches ) )
1605 /* try exact match */
1606 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1607 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1611 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1613 char buf[ACL_BUF_SIZE];
1615 bv.bv_len = sizeof( buf ) - 1;
1617 if ( acl_string_expand( &bv, &b->a_peername_pat,
1618 e->e_ndn, nmatch, matches ) )
1623 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1627 /* extract IP and try exact match */
1628 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1630 char buf[] = "255.255.255.255";
1633 int port_number = -1;
1635 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1636 aci_bv[ ACI_BV_IP_EQ ].bv_val,
1637 aci_bv[ ACI_BV_IP_EQ ].bv_len ) != 0 )
1640 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv[ ACI_BV_IP_EQ ].bv_len;
1641 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv[ ACI_BV_IP_EQ ].bv_len;
1643 port = strrchr( ip.bv_val, ':' );
1647 ip.bv_len = port - ip.bv_val;
1649 port_number = strtol( port, &next, 10 );
1650 if ( next[0] != '\0' )
1654 /* the port check can be anticipated here */
1655 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1658 /* address longer than expected? */
1659 if ( ip.bv_len >= sizeof(buf) )
1662 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1663 buf[ ip.bv_len ] = '\0';
1665 addr = inet_addr( buf );
1667 /* unable to convert? */
1668 if ( addr == (unsigned long)(-1) )
1671 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1674 #ifdef LDAP_PF_LOCAL
1675 /* extract path and try exact match */
1676 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1679 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1680 aci_bv[ ACI_BV_PATH_EQ ].bv_val,
1681 aci_bv[ ACI_BV_PATH_EQ ].bv_len ) != 0 )
1684 path.bv_val = op->o_conn->c_peer_name.bv_val
1685 + aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1686 path.bv_len = op->o_conn->c_peer_name.bv_len
1687 - aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1689 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1692 #endif /* LDAP_PF_LOCAL */
1694 /* exact match (very unlikely...) */
1695 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1702 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1703 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1706 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1707 b->a_sockname_pat.bv_val, 0, 0 );
1708 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1709 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1710 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1711 e->e_ndn, nmatch, matches ) )
1716 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1718 char buf[ACL_BUF_SIZE];
1720 bv.bv_len = sizeof( buf ) - 1;
1722 if ( acl_string_expand( &bv, &b->a_sockname_pat,
1723 e->e_ndn, nmatch, matches ) )
1728 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1733 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1740 if ( b->a_dn_at != NULL ) {
1741 if ( acl_mask_dnattr( op, e, val, a, b, i,
1742 matches, count, state,
1743 &b->a_dn, &op->o_ndn ) )
1749 if ( b->a_realdn_at != NULL ) {
1752 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1754 ndn = op->o_conn->c_ndn;
1759 if ( acl_mask_dnattr( op, e, val, a, b, i,
1760 matches, count, state,
1761 &b->a_realdn, &ndn ) )
1767 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1769 struct berval ndn = BER_BVNULL;
1772 if ( op->o_ndn.bv_len == 0 ) {
1776 Debug( LDAP_DEBUG_ACL, "<= check a_group_pat: %s\n",
1777 b->a_group_pat.bv_val, 0, 0 );
1779 /* b->a_group is an unexpanded entry name, expanded it should be an
1780 * entry with objectclass group* and we test to see if odn is one of
1781 * the values in the attribute group
1783 /* see if asker is listed in dnattr */
1784 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1785 char buf[ACL_BUF_SIZE];
1787 regmatch_t tmp_matches[2],
1788 *tmp_matchesp = tmp_matches;
1790 bv.bv_len = sizeof(buf) - 1;
1795 switch ( a->acl_dn_style ) {
1796 case ACL_STYLE_REGEX:
1797 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1798 tmp_matchesp = matches;
1799 tmp_nmatch = nmatch;
1803 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1804 case ACL_STYLE_BASE:
1805 tmp_matches[0].rm_so = 0;
1806 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1811 case ACL_STYLE_SUBTREE:
1812 case ACL_STYLE_CHILDREN:
1813 tmp_matches[0].rm_so = 0;
1814 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1815 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1816 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1830 if ( acl_string_expand( &bv, &b->a_group_pat,
1832 tmp_nmatch, tmp_matchesp ) )
1837 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1838 op->o_tmpmemctx ) != LDAP_SUCCESS )
1840 /* did not expand to a valid dn */
1847 bv = b->a_group_pat;
1850 rc = backend_group( op, e, &bv, &op->o_ndn,
1851 b->a_group_oc, b->a_group_at );
1854 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1862 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1864 char buf[ACL_BUF_SIZE];
1866 Debug( LDAP_DEBUG_ACL, "<= check a_set_pat: %s\n",
1867 b->a_set_pat.bv_val, 0, 0 );
1869 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1871 regmatch_t tmp_matches[2],
1872 *tmp_matchesp = tmp_matches;
1875 bv.bv_len = sizeof( buf ) - 1;
1880 switch ( a->acl_dn_style ) {
1881 case ACL_STYLE_REGEX:
1882 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1883 tmp_matchesp = matches;
1884 tmp_nmatch = nmatch;
1888 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1889 case ACL_STYLE_BASE:
1890 tmp_matches[0].rm_so = 0;
1891 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1896 case ACL_STYLE_SUBTREE:
1897 case ACL_STYLE_CHILDREN:
1898 tmp_matches[0].rm_so = 0;
1899 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1900 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1901 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1915 if ( acl_string_expand( &bv, &b->a_set_pat,
1917 tmp_nmatch, tmp_matchesp ) )
1926 if ( acl_match_set( &bv, op, e, 0 ) == 0 ) {
1931 if ( b->a_authz.sai_ssf ) {
1932 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1933 b->a_authz.sai_ssf, op->o_ssf, 0 );
1934 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1939 if ( b->a_authz.sai_transport_ssf ) {
1940 Debug( LDAP_DEBUG_ACL,
1941 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1942 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1943 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1948 if ( b->a_authz.sai_tls_ssf ) {
1949 Debug( LDAP_DEBUG_ACL,
1950 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1951 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1952 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1957 if ( b->a_authz.sai_sasl_ssf ) {
1958 Debug( LDAP_DEBUG_ACL,
1959 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1960 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1961 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1967 if ( b->a_dynacl ) {
1969 slap_access_t tgrant, tdeny;
1971 Debug( LDAP_DEBUG_ACL, "<= check a_dynacl\n",
1974 /* this case works different from the others above.
1975 * since aci's themselves give permissions, we need
1976 * to first check b->a_access_mask, the ACL's access level.
1978 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1979 /* no ACIs in the root DSE */
1983 /* first check if the right being requested
1984 * is allowed by the ACL clause.
1986 if ( ! ACL_PRIV_ISSET( b->a_access_mask, a2pmask ) ) {
1990 /* start out with nothing granted, nothing denied */
1994 for ( da = b->a_dynacl; da; da = da->da_next ) {
1995 slap_access_t grant,
2001 Debug( LDAP_DEBUG_ACL, " <= check a_dynacl: %s\n",
2002 da->da_name, 0, 0 );
2004 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
2010 /* remove anything that the ACL clause does not allow */
2011 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2012 tdeny &= ACL_PRIV_MASK;
2014 /* see if we have anything to contribute */
2015 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2019 /* this could be improved by changing slap_acl_mask so that it can deal with
2020 * by clauses that return grant/deny pairs. Right now, it does either
2021 * additive or subtractive rights, but not both at the same time. So,
2022 * we need to combine the grant/deny pair into a single rights mask in
2023 * a smart way: if either grant or deny is "empty", then we use the
2024 * opposite as is, otherwise we remove any denied rights from the grant
2025 * rights mask and construct an additive mask.
2027 if (ACL_IS_INVALID(tdeny)) {
2028 modmask = tgrant | ACL_PRIV_ADDITIVE;
2030 } else if (ACL_IS_INVALID(tgrant)) {
2031 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2034 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2038 #else /* !SLAP_DYNACL */
2040 #ifdef SLAPD_ACI_ENABLED
2041 if ( b->a_aci_at != NULL ) {
2043 slap_access_t grant, deny, tgrant, tdeny;
2044 struct berval parent_ndn;
2045 BerVarray bvals = NULL;
2048 Debug( LDAP_DEBUG_ACL, " <= check a_aci_at: %s\n",
2049 b->a_aci_at->ad_cname.bv_val, 0, 0 );
2051 /* this case works different from the others above.
2052 * since aci's themselves give permissions, we need
2053 * to first check b->a_access_mask, the ACL's access level.
2056 if ( BER_BVISEMPTY( &e->e_nname ) ) {
2057 /* no ACIs in the root DSE */
2061 /* first check if the right being requested
2062 * is allowed by the ACL clause.
2064 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
2067 /* start out with nothing granted, nothing denied */
2071 /* get the aci attribute */
2072 at = attr_find( e->e_attrs, b->a_aci_at );
2075 /* FIXME: this breaks acl caching;
2076 * see also ACL_RECORD_VALUE_STATE below */
2077 ACL_RECORD_VALUE_STATE;
2079 /* the aci is an multi-valued attribute. The
2080 * rights are determined by OR'ing the individual
2081 * rights given by the acis.
2083 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2088 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0 )
2094 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2095 accessmask2str(tgrant, accessmaskbuf, 1),
2096 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2099 /* If the entry level aci didn't contain anything valid for the
2100 * current operation, climb up the tree and evaluate the
2101 * acis with scope set to subtree
2103 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
2104 dnParent( &e->e_nname, &parent_ndn );
2105 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
2106 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
2107 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
2115 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++ ) {
2117 /* FIXME: this breaks acl caching;
2118 * see also ACL_RECORD_VALUE_STATE above */
2119 ACL_RECORD_VALUE_STATE;
2121 if ( aci_mask( op, e, desc, val, &bvals[i],
2123 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2127 /* evaluation stops as soon as either a "deny" or a
2128 * "grant" directive matches.
2130 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
2134 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2135 accessmask2str(tgrant, accessmaskbuf, 1),
2136 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2140 case LDAP_NO_SUCH_ATTRIBUTE:
2141 /* just go on if the aci-Attribute is not present in
2144 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
2148 case LDAP_NO_SUCH_OBJECT:
2149 /* We have reached the base object */
2150 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
2161 dnParent( &parent_ndn, &parent_ndn );
2166 /* remove anything that the ACL clause does not allow */
2167 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2168 tdeny &= ACL_PRIV_MASK;
2170 /* see if we have anything to contribute */
2171 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2175 /* this could be improved by changing slap_acl_mask so that it can deal with
2176 * by clauses that return grant/deny pairs. Right now, it does either
2177 * additive or subtractive rights, but not both at the same time. So,
2178 * we need to combine the grant/deny pair into a single rights mask in
2179 * a smart way: if either grant or deny is "empty", then we use the
2180 * opposite as is, otherwise we remove any denied rights from the grant
2181 * rights mask and construct an additive mask.
2183 if (ACL_IS_INVALID(tdeny)) {
2184 modmask = tgrant | ACL_PRIV_ADDITIVE;
2186 } else if (ACL_IS_INVALID(tgrant)) {
2187 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2190 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2194 #endif /* SLAPD_ACI_ENABLED */
2195 #endif /* !SLAP_DYNACL */
2197 modmask = b->a_access_mask;
2200 Debug( LDAP_DEBUG_ACL,
2201 "<= acl_mask: [%d] applying %s (%s)\n",
2202 i, accessmask2str( modmask, accessmaskbuf, 1 ),
2203 b->a_type == ACL_CONTINUE
2205 : b->a_type == ACL_BREAK
2211 if( ACL_IS_ADDITIVE(modmask) ) {
2213 ACL_PRIV_SET( *mask, modmask );
2216 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2218 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
2219 /* substract privs */
2220 ACL_PRIV_CLR( *mask, modmask );
2223 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2232 Debug( LDAP_DEBUG_ACL,
2233 "<= acl_mask: [%d] mask: %s\n",
2234 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
2236 if( b->a_type == ACL_CONTINUE ) {
2239 } else if ( b->a_type == ACL_BREAK ) {
2247 /* implicit "by * none" clause */
2250 Debug( LDAP_DEBUG_ACL,
2251 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
2252 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
2257 * acl_check_modlist - check access control on the given entry to see if
2258 * it allows the given modifications by the user associated with op.
2259 * returns 1 if mods allowed ok
2260 * 0 mods not allowed
2267 Modifications *mlist )
2270 AccessControlState state = ACL_STATE_INIT;
2273 int ret = 1; /* default is access allowed */
2277 be = LDAP_STAILQ_FIRST(&backendDB);
2281 assert( be != NULL );
2283 /* short circuit root database access */
2284 if ( be_isroot( op ) ) {
2285 Debug( LDAP_DEBUG_ACL,
2286 "<= acl_access_allowed: granted to database root\n",
2291 /* use backend default access if no backend acls */
2292 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
2293 Debug( LDAP_DEBUG_ACL,
2294 "=> access_allowed: backend default %s access %s to \"%s\"\n",
2295 access2str( ACL_WRITE ),
2296 op->o_bd->be_dfltaccess >= ACL_WRITE
2297 ? "granted" : "denied",
2299 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
2303 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
2305 * Internal mods are ignored by ACL_WRITE checking
2307 if ( mlist->sml_flags & SLAP_MOD_INTERNAL ) {
2308 Debug( LDAP_DEBUG_ACL, "acl: internal mod %s:"
2309 " modify access granted\n",
2310 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2315 * no-user-modification operational attributes are ignored
2316 * by ACL_WRITE checking as any found here are not provided
2319 if ( is_at_no_user_mod( mlist->sml_desc->ad_type )
2320 && ! ( mlist->sml_flags & SLAP_MOD_MANAGING ) )
2322 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
2323 " modify access granted\n",
2324 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2328 switch ( mlist->sml_op ) {
2329 case LDAP_MOD_REPLACE:
2331 * We must check both permission to delete the whole
2332 * attribute and permission to add the specific attributes.
2333 * This prevents abuse from selfwriters.
2335 if ( ! access_allowed( op, e,
2336 mlist->sml_desc, NULL,
2337 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2344 if ( mlist->sml_values == NULL ) break;
2346 /* fall thru to check value to add */
2349 assert( mlist->sml_values != NULL );
2351 for ( bv = mlist->sml_nvalues
2352 ? mlist->sml_nvalues : mlist->sml_values;
2353 bv->bv_val != NULL; bv++ )
2355 if ( ! access_allowed( op, e,
2356 mlist->sml_desc, bv,
2357 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WADD,
2366 case LDAP_MOD_DELETE:
2367 if ( mlist->sml_values == NULL ) {
2368 if ( ! access_allowed( op, e,
2369 mlist->sml_desc, NULL,
2370 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2378 for ( bv = mlist->sml_nvalues
2379 ? mlist->sml_nvalues : mlist->sml_values;
2380 bv->bv_val != NULL; bv++ )
2382 if ( ! access_allowed( op, e,
2383 mlist->sml_desc, bv,
2384 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2393 case SLAP_MOD_SOFTADD:
2394 /* allow adding attribute via modrdn thru */
2406 if (be_null) op->o_bd = NULL;
2412 struct berval *list,
2425 while ( len >= 0 && --ix >= 0 ) {
2426 while ( --len >= 0 && *p++ != sep )
2429 while ( len >= 0 && *p == ' ' ) {
2442 while ( --len >= 0 && *p != sep ) {
2446 while ( bv->bv_len > 0 && *--p == ' ' ) {
2453 typedef struct acl_set_gather_t {
2459 acl_set_cb_gather( Operation *op, SlapReply *rs )
2461 acl_set_gather_t *p = (acl_set_gather_t *)op->o_callback->sc_private;
2463 if ( rs->sr_type == REP_SEARCH ) {
2464 BerValue bvals[ 2 ];
2465 BerVarray bvalsp = NULL;
2468 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
2469 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
2471 if ( desc == slap_schema.si_ad_entryDN ) {
2473 bvals[ 0 ] = rs->sr_entry->e_nname;
2474 BER_BVZERO( &bvals[ 1 ] );
2479 a = attr_find( rs->sr_entry->e_attrs, desc );
2483 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
2486 bvalsp = a->a_nvals;
2492 p->bvals = slap_set_join( p->cookie, p->bvals,
2493 ( '|' | SLAP_SET_RREF ), bvalsp );
2497 assert( rs->sr_type == REP_RESULT );
2504 acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2506 AclSetCookie *cp = (AclSetCookie *)cookie;
2508 LDAPURLDesc *ludp = NULL;
2509 Operation op2 = { 0 };
2510 SlapReply rs = {REP_RESULT};
2511 AttributeName anlist[ 2 ], *anlistp = NULL;
2513 slap_callback cb = { NULL, acl_set_cb_gather, NULL, NULL };
2514 acl_set_gather_t p = { 0 };
2515 const char *text = NULL;
2516 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2518 /* this routine needs to return the bervals instead of
2519 * plain strings, since syntax is not known. It should
2520 * also return the syntax or some "comparison cookie".
2522 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2523 return acl_set_gather2( cookie, name, desc );
2526 rc = ldap_url_parse( name->bv_val, &ludp );
2527 if ( rc != LDAP_URL_SUCCESS ) {
2528 rc = LDAP_PROTOCOL_ERROR;
2532 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2534 /* host part must be empty */
2535 /* extensions parts must be empty */
2536 rc = LDAP_PROTOCOL_ERROR;
2540 /* Grab the searchbase and see if an appropriate database can be found */
2541 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2542 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2543 &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2544 BER_BVZERO( &op2.o_req_dn );
2545 if ( rc != LDAP_SUCCESS ) {
2549 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2550 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2551 rc = LDAP_NO_SUCH_OBJECT;
2555 /* Grab the filter */
2556 if ( ludp->lud_filter ) {
2557 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2558 cp->asc_op->o_tmpmemctx );
2561 op2.ors_filterstr = defaultFilter_bv;
2564 op2.ors_filter = str2filter_x( cp->asc_op, op2.ors_filterstr.bv_val );
2565 if ( op2.ors_filter == NULL ) {
2566 rc = LDAP_PROTOCOL_ERROR;
2570 /* Grab the scope */
2571 op2.ors_scope = ludp->lud_scope;
2573 /* Grap the attributes */
2574 if ( ludp->lud_attrs ) {
2575 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2578 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2579 cp->asc_op->o_tmpmemctx );
2581 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2582 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2583 anlistp[ nattrs ].an_desc = NULL;
2584 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2585 &anlistp[ nattrs ].an_desc, &text );
2586 if ( rc != LDAP_SUCCESS ) {
2595 anlistp[ nattrs ].an_name = desc->ad_cname;
2596 anlistp[ nattrs ].an_desc = desc;
2598 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2602 op2.o_hdr = cp->asc_op->o_hdr;
2603 op2.o_tag = LDAP_REQ_SEARCH;
2604 op2.o_ndn = op2.o_bd->be_rootndn;
2605 op2.o_callback = &cb;
2606 op2.o_time = slap_get_time();
2607 op2.o_do_not_cache = 1;
2608 op2.o_is_auth_check = 0;
2609 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2610 op2.ors_slimit = SLAP_NO_LIMIT;
2611 op2.ors_tlimit = SLAP_NO_LIMIT;
2612 op2.ors_attrs = anlistp;
2613 op2.ors_attrsonly = 0;
2614 op2.o_private = cp->asc_op->o_private;
2618 rc = op2.o_bd->be_search( &op2, &rs );
2624 if ( op2.ors_filter ) {
2625 filter_free_x( cp->asc_op, op2.ors_filter );
2627 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2628 slap_sl_free( op2.o_req_ndn.bv_val, cp->asc_op->o_tmpmemctx );
2630 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2631 slap_sl_free( op2.o_req_dn.bv_val, cp->asc_op->o_tmpmemctx );
2634 ldap_free_urldesc( ludp );
2636 if ( anlistp && anlistp != anlist ) {
2637 slap_sl_free( anlistp, cp->asc_op->o_tmpmemctx );
2644 acl_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2646 AclSetCookie *cp = (AclSetCookie *)cookie;
2647 BerVarray bvals = NULL;
2651 /* this routine needs to return the bervals instead of
2652 * plain strings, since syntax is not known. It should
2653 * also return the syntax or some "comparison cookie".
2655 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->asc_op->o_tmpmemctx );
2656 if ( rc == LDAP_SUCCESS ) {
2657 if ( desc == slap_schema.si_ad_entryDN ) {
2658 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2659 cp->asc_op->o_tmpmemctx );
2661 BER_BVZERO( &bvals[ 1 ] );
2665 backend_attribute( cp->asc_op,
2666 cp->asc_e, &ndn, desc, &bvals, ACL_NONE );
2669 if ( !BER_BVISNULL( &ndn ) ) {
2670 slap_sl_free( ndn.bv_val, cp->asc_op->o_tmpmemctx );
2679 struct berval *subj,
2684 struct berval set = BER_BVNULL;
2686 AclSetCookie cookie;
2688 if ( setref == 0 ) {
2689 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2692 struct berval subjdn, ndn = BER_BVNULL;
2693 struct berval setat;
2696 AttributeDescription *desc = NULL;
2698 /* format of string is "entry/setAttrName" */
2699 if ( acl_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2703 if ( acl_get_part( subj, 1, '/', &setat ) < 0 ) {
2704 setat = aci_bv[ ACI_BV_SET_ATTR ];
2708 * NOTE: dnNormalize honors the ber_len field
2709 * as the length of the dn to be normalized
2711 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2712 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2714 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2715 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2719 BER_BVZERO( &bvals[0] );
2720 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2722 bvals[0].bv_val = bvals[i-1].bv_val;
2723 BER_BVZERO( &bvals[i-1] );
2725 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2726 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2731 if ( !BER_BVISNULL( &set ) ) {
2734 rc = ( slap_set_filter(
2736 (SetCookie *)&cookie, &set,
2737 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2738 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2747 * dynamic ACL infrastructure
2749 static slap_dynacl_t *da_list = NULL;
2752 slap_dynacl_register( slap_dynacl_t *da )
2756 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2757 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2762 if ( tmp != NULL ) {
2766 if ( da->da_mask == NULL ) {
2770 da->da_private = NULL;
2771 da->da_next = da_list;
2777 static slap_dynacl_t *
2778 slap_dynacl_next( slap_dynacl_t *da )
2787 slap_dynacl_get( const char *name )
2791 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2792 if ( strcasecmp( da->da_name, name ) == 0 ) {
2799 #endif /* SLAP_DYNACL */
2806 #ifdef SLAPD_ACI_ENABLED
2808 rc = dynacl_aci_init();
2809 #else /* !SLAP_DYNACL */
2811 #endif /* !SLAP_DYNACL */
2815 #endif /* SLAPD_ACI_ENABLED */
2826 regmatch_t *matches)
2834 bv->bv_val[0] = '\0';
2835 bv->bv_len--; /* leave space for lone $ */
2838 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2839 sp < pat->bv_val + pat->bv_len ; sp++ )
2841 /* did we previously see a $ */
2843 if ( flag == 1 && *sp == '$' ) {
2848 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2851 } else if ( *sp >= '0' && *sp <= '9' ) {
2859 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2860 if ( *sp >= '0' && *sp <= '9' ) {
2861 n = 10*n + ( *sp - '0' );
2865 if ( *sp != /*'{'*/ '}' ) {
2871 if ( n >= nmatch ) {
2877 i = matches[n].rm_so;
2878 l = matches[n].rm_eo;
2879 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2897 /* must have ended with a single $ */
2905 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2906 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2913 struct berval *pat, /* pattern to expand and match against */
2914 char *str, /* string to match against pattern */
2915 char *buf, /* buffer with $N expansion variables */
2916 int nmatch, /* size of the matches array */
2917 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2921 char newbuf[ACL_BUF_SIZE];
2925 bv.bv_len = sizeof( newbuf ) - 1;
2932 acl_string_expand( &bv, pat, buf, nmatch, matches );
2933 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2935 char error[ACL_BUF_SIZE];
2936 regerror( rc, &re, error, sizeof( error ) );
2938 Debug( LDAP_DEBUG_TRACE,
2939 "compile( \"%s\", \"%s\") failed %s\n",
2940 pat->bv_val, str, error );
2944 rc = regexec( &re, str, 0, NULL, 0 );
2947 Debug( LDAP_DEBUG_TRACE,
2948 "=> regex_matches: string: %s\n", str, 0, 0 );
2949 Debug( LDAP_DEBUG_TRACE,
2950 "=> regex_matches: rc: %d %s\n",
2951 rc, !rc ? "matches" : "no matches", 0 );