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-2006 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
32 #include <ac/socket.h>
33 #include <ac/string.h>
40 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
42 static const struct berval acl_bv_ip_eq = BER_BVC( "IP=" );
44 static const struct berval acl_bv_path_eq = BER_BVC("PATH=");
45 #endif /* LDAP_PF_LOCAL */
47 static AccessControl * slap_acl_get(
48 AccessControl *ac, int *count,
49 Operation *op, Entry *e,
50 AttributeDescription *desc,
52 int nmatch, regmatch_t *matches,
53 AccessControlState *state );
55 static slap_control_t slap_acl_mask(
56 AccessControl *ac, slap_mask_t *mask,
57 Operation *op, Entry *e,
58 AttributeDescription *desc,
63 AccessControlState *state );
65 static int regex_matches(
66 struct berval *pat, char *str, char *buf,
67 int nmatch, regmatch_t *matches);
69 typedef struct AclSetCookie {
71 #define asc_op asc_cookie.set_op
75 SLAP_SET_GATHER acl_set_gather;
76 SLAP_SET_GATHER acl_set_gather2;
79 * access_allowed - check whether op->o_ndn is allowed the requested access
80 * to entry e, attribute attr, value val. if val is null, access to
81 * the whole attribute is assumed (all values).
83 * This routine loops through all access controls and calls
84 * slap_acl_mask() on each applicable access control.
85 * The loop exits when a definitive answer is reached or
86 * or no more controls remain.
93 * - can be legally called with op == NULL
94 * - can be legally called with op->o_bd == NULL
97 #ifdef SLAP_OVERLAY_ACCESS
99 slap_access_always_allowed(
102 AttributeDescription *desc,
104 slap_access_t access,
105 AccessControlState *state,
108 assert( maskp != NULL );
111 ACL_LVL_ASSIGN_MANAGE( *maskp );
120 AttributeDescription *desc,
122 slap_access_t access,
123 AccessControlState *state,
128 AccessControl *a = NULL;
131 char accessmaskbuf[ACCESSMASK_MAXLEN];
134 slap_control_t control;
135 slap_access_t access_level;
137 regmatch_t matches[MAXREMATCHES];
138 int st_same_attr = 0;
140 assert( op != NULL );
142 assert( desc != NULL );
143 assert( maskp != NULL );
145 access_level = ACL_LEVEL( access );
146 attr = desc->ad_cname.bv_val;
148 assert( attr != NULL );
152 /* grant database root access */
153 if ( be_isroot( op ) ) {
154 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
155 mask = ACL_LVL_MANAGE;
160 * no-user-modification operational attributes are ignored
161 * by ACL_WRITE checking as any found here are not provided
164 * NOTE: but they are not ignored for ACL_MANAGE, because
165 * if we get here it means a non-root user is trying to
166 * manage data, so we need to check its privileges.
168 if ( access_level == ACL_WRITE
169 && is_at_no_user_mod( desc->ad_type )
170 && desc != slap_schema.si_ad_entry
171 && desc != slap_schema.si_ad_children )
173 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
174 " %s access granted\n",
179 /* use backend default access if no backend acls */
180 if ( op->o_bd->be_acl == NULL ) {
183 Debug( LDAP_DEBUG_ACL,
184 "=> slap_access_allowed: backend default %s "
185 "access %s to \"%s\"\n",
186 access2str( access ),
187 op->o_bd->be_dfltaccess >= access_level ? "granted" : "denied",
188 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
189 ret = op->o_bd->be_dfltaccess >= access_level;
191 mask = ACL_PRIV_LEVEL;
192 for ( i = ACL_NONE; i <= op->o_bd->be_dfltaccess; i++ ) {
193 ACL_PRIV_SET( mask, ACL_ACCESS2PRIV( i ) );
202 if ( st_same_attr ) {
203 assert( state->as_vd_acl != NULL );
205 a = state->as_vd_acl;
206 count = state->as_vd_acl_count;
207 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
208 mask = state->as_vd_acl_mask;
209 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
214 if ( state ) state->as_vi_acl = NULL;
216 ACL_PRIV_ASSIGN( mask, *maskp );
218 memset( matches, '\0', sizeof( matches ) );
221 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
222 MAXREMATCHES, matches, state ) ) != NULL )
226 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
227 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
228 (int)matches[i].rm_so, (int)matches[i].rm_eo );
229 if ( matches[i].rm_so <= matches[0].rm_eo ) {
231 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
232 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
235 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
239 if ( state->as_vi_acl == a &&
240 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
242 Debug( LDAP_DEBUG_ACL,
243 "=> slap_access_allowed: result from state (%s)\n",
245 ret = state->as_result;
248 Debug( LDAP_DEBUG_ACL,
249 "=> slap_access_allowed: no res from state (%s)\n",
255 control = slap_acl_mask( a, &mask, op,
256 e, desc, val, MAXREMATCHES, matches, count, state );
258 if ( control != ACL_BREAK ) {
262 memset( matches, '\0', sizeof( matches ) );
265 if ( ACL_IS_INVALID( mask ) ) {
266 Debug( LDAP_DEBUG_ACL,
267 "=> slap_access_allowed: \"%s\" (%s) invalid!\n",
269 ACL_PRIV_ASSIGN( mask, *maskp );
271 } else if ( control == ACL_BREAK ) {
272 Debug( LDAP_DEBUG_ACL,
273 "=> slap_access_allowed: no more rules\n", 0, 0, 0 );
278 ret = ACL_GRANT( mask, access );
280 Debug( LDAP_DEBUG_ACL,
281 "=> slap_access_allowed: %s access %s by %s\n",
282 access2str( access ), ret ? "granted" : "denied",
283 accessmask2str( mask, accessmaskbuf, 1 ) );
286 ACL_PRIV_ASSIGN( *maskp, mask );
294 AttributeDescription *desc,
296 slap_access_t access,
297 AccessControlState *state,
304 * NOTE: control gets here if FIXME
305 * if an appropriate backend cannot be selected for the operation,
306 * we assume that the frontend should handle this
307 * FIXME: should select_backend() take care of this,
308 * and return frontendDB instead of NULL? maybe for some value
313 if ( op->o_bd == NULL ) {
314 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
315 if ( op->o_bd == NULL )
316 op->o_bd = frontendDB;
318 rc = slap_access_allowed( op, e, desc, val, access, state, maskp );
328 AttributeDescription *desc,
330 slap_access_t access,
331 AccessControlState *state,
335 AccessControl *a = NULL;
339 char accessmaskbuf[ACCESSMASK_MAXLEN];
342 slap_access_t access_level;
344 int st_same_attr = 0;
345 static AccessControlState state_init = ACL_STATE_INIT;
348 assert( desc != NULL );
350 access_level = ACL_LEVEL( access );
352 assert( access_level > ACL_NONE );
355 if ( maskp ) ACL_INVALIDATE( *maskp );
357 attr = desc->ad_cname.bv_val;
359 assert( attr != NULL );
362 if ( op->o_is_auth_check &&
363 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
367 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
368 desc == slap_schema.si_ad_entry )
375 if ( state->as_vd_ad == desc ) {
376 if ( state->as_recorded ) {
377 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
380 return state->as_result;
382 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
383 val != NULL && state->as_vd_acl == NULL )
385 return state->as_result;
393 state->as_vd_ad = desc;
396 Debug( LDAP_DEBUG_ACL,
397 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
398 access2str( access ), e->e_dn, attr );
405 if ( op->o_bd == NULL ) {
406 op->o_bd = LDAP_STAILQ_FIRST( &backendDB );
411 * FIXME: experimental; use first backend rules
412 * iff there is no global_acl (ITS#3100) */
413 if ( frontendDB->be_acl != NULL ) {
414 op->o_bd = frontendDB;
416 #endif /* LDAP_DEVEL */
418 assert( op->o_bd != NULL );
420 /* this is enforced in backend_add() */
421 if ( op->o_bd->bd_info->bi_access_allowed ) {
422 /* delegate to backend */
423 ret = op->o_bd->bd_info->bi_access_allowed( op, e,
424 desc, val, access, state, &mask );
427 /* use default (but pass through frontend
428 * for global ACL overlays) */
429 ret = frontendDB->bd_info->bi_access_allowed( op, e,
430 desc, val, access, state, &mask );
434 if ( ACL_IS_INVALID( mask ) ) {
435 Debug( LDAP_DEBUG_ACL,
436 "=> access_allowed: \"%s\" (%s) invalid!\n",
441 Debug( LDAP_DEBUG_ACL,
442 "=> access_allowed: no more rules\n", 0, 0, 0 );
448 Debug( LDAP_DEBUG_ACL,
449 "=> access_allowed: %s access %s by %s\n",
450 access2str( access ), ret ? "granted" : "denied",
451 accessmask2str( mask, accessmaskbuf, 1 ) );
454 if ( state != NULL ) {
455 /* If not value-dependent, save ACL in case of more attrs */
456 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
457 state->as_vi_acl = a;
458 state->as_result = ret;
460 state->as_recorded |= ACL_STATE_RECORDED;
462 if ( be_null ) op->o_bd = NULL;
463 if ( maskp ) ACL_PRIV_ASSIGN( *maskp, mask );
467 #else /* !SLAP_OVERLAY_ACCESS */
473 AttributeDescription *desc,
475 slap_access_t access,
476 AccessControlState *state,
481 AccessControl *a = NULL;
486 char accessmaskbuf[ACCESSMASK_MAXLEN];
489 slap_control_t control;
490 slap_access_t access_level;
492 regmatch_t matches[MAXREMATCHES];
493 int st_same_attr = 0;
494 static AccessControlState state_init = ACL_STATE_INIT;
497 assert( desc != NULL );
499 access_level = ACL_LEVEL( access );
501 assert( access_level > ACL_NONE );
502 if ( maskp ) ACL_INVALIDATE( *maskp );
504 attr = desc->ad_cname.bv_val;
506 assert( attr != NULL );
509 if ( op->o_is_auth_check &&
510 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
514 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
515 desc == slap_schema.si_ad_entry )
522 if ( state->as_vd_ad == desc ) {
523 if ( state->as_recorded ) {
524 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
527 return state->as_result;
529 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
530 val != NULL && state->as_vd_acl == NULL )
532 return state->as_result;
540 state->as_vd_ad=desc;
543 Debug( LDAP_DEBUG_ACL,
544 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
545 access2str( access ), e->e_dn, attr );
554 be = LDAP_STAILQ_FIRST(&backendDB);
558 * FIXME: experimental; use first backend rules
559 * iff there is no global_acl (ITS#3100) */
560 if ( frontendDB->be_acl == NULL )
566 assert( be != NULL );
568 /* grant database root access */
569 if ( be_isroot( op ) ) {
570 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
572 mask = ACL_LVL_MANAGE;
579 * no-user-modification operational attributes are ignored
580 * by ACL_WRITE checking as any found here are not provided
583 * NOTE: but they are not ignored for ACL_MANAGE, because
584 * if we get here it means a non-root user is trying to
585 * manage data, so we need to check its privileges.
587 if ( access_level == ACL_WRITE && is_at_no_user_mod( desc->ad_type )
588 && desc != slap_schema.si_ad_entry
589 && desc != slap_schema.si_ad_children )
591 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
592 " %s access granted\n",
597 /* use backend default access if no backend acls */
598 if ( be->be_acl == NULL ) {
599 Debug( LDAP_DEBUG_ACL,
600 "=> access_allowed: backend default %s "
601 "access %s to \"%s\"\n",
602 access2str( access ),
603 be->be_dfltaccess >= access_level ? "granted" : "denied",
604 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
605 ret = be->be_dfltaccess >= access_level;
610 mask = ACL_PRIV_LEVEL;
611 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
612 mask |= ACL_ACCESS2PRIV( i );
619 /* be is always non-NULL */
620 /* use global default access if no global acls */
621 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
622 Debug( LDAP_DEBUG_ACL,
623 "=> access_allowed: global default %s access %s to \"%s\"\n",
624 access2str( access ),
625 frontendDB->be_dfltaccess >= access_level ?
626 "granted" : "denied", op->o_dn.bv_val );
627 ret = frontendDB->be_dfltaccess >= access_level;
632 mask = ACL_PRIV_LEVEL;
633 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
634 mask |= ACL_ACCESS2PRIV( i );
645 if ( st_same_attr ) {
646 assert( state->as_vd_acl != NULL );
648 a = state->as_vd_acl;
649 count = state->as_vd_acl_count;
650 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
651 mask = state->as_vd_acl_mask;
652 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
657 if ( state ) state->as_vi_acl = NULL;
661 memset( matches, '\0', sizeof(matches) );
664 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
665 MAXREMATCHES, matches, state ) ) != NULL )
669 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
670 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
671 (int)matches[i].rm_so, (int)matches[i].rm_eo );
672 if ( matches[i].rm_so <= matches[0].rm_eo ) {
674 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
675 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
678 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
682 if ( state->as_vi_acl == a &&
683 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
685 Debug( LDAP_DEBUG_ACL,
686 "access_allowed: result from state (%s)\n",
688 ret = state->as_result;
691 Debug( LDAP_DEBUG_ACL,
692 "access_allowed: no res from state (%s)\n",
698 control = slap_acl_mask( a, &mask, op,
699 e, desc, val, MAXREMATCHES, matches, count, state );
701 if ( control != ACL_BREAK ) {
705 memset( matches, '\0', sizeof(matches) );
708 if ( ACL_IS_INVALID( mask ) ) {
709 Debug( LDAP_DEBUG_ACL,
710 "=> access_allowed: \"%s\" (%s) invalid!\n",
714 } else if ( control == ACL_BREAK ) {
715 Debug( LDAP_DEBUG_ACL,
716 "=> access_allowed: no more rules\n", 0, 0, 0 );
721 Debug( LDAP_DEBUG_ACL,
722 "=> access_allowed: %s access %s by %s\n",
723 access2str( access ),
724 ACL_GRANT(mask, access) ? "granted" : "denied",
725 accessmask2str( mask, accessmaskbuf, 1 ) );
727 ret = ACL_GRANT(mask, access);
730 if ( state != NULL ) {
731 /* If not value-dependent, save ACL in case of more attrs */
732 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
733 state->as_vi_acl = a;
734 state->as_result = ret;
736 state->as_recorded |= ACL_STATE_RECORDED;
738 if ( be_null ) op->o_bd = NULL;
739 if ( maskp ) *maskp = mask;
743 #endif /* SLAP_OVERLAY_ACCESS */
746 * slap_acl_get - return the acl applicable to entry e, attribute
747 * attr. the acl returned is suitable for use in subsequent calls to
748 * acl_access_allowed().
751 static AccessControl *
757 AttributeDescription *desc,
761 AccessControlState *state )
768 assert( count != NULL );
769 assert( desc != NULL );
771 attr = desc->ad_cname.bv_val;
773 assert( attr != NULL );
776 if( op->o_bd == NULL ) {
777 a = frontendDB->be_acl;
779 a = op->o_bd->be_acl;
790 dnlen = e->e_nname.bv_len;
792 for ( ; a != NULL; a = a->acl_next ) {
795 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
796 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
797 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
798 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
799 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
803 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
804 *count, a->acl_dn_pat.bv_val, 0 );
805 patlen = a->acl_dn_pat.bv_len;
806 if ( dnlen < patlen )
809 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
810 /* base dn -- entire object DN must match */
811 if ( dnlen != patlen )
814 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
815 ber_len_t rdnlen = 0;
818 if ( dnlen <= patlen )
822 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
827 rdnlen = dn_rdnlen( NULL, &e->e_nname );
828 if ( rdnlen != dnlen - patlen - sep )
831 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
832 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
835 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
836 if ( dnlen <= patlen )
838 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
842 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
846 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
850 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
851 matches[0].rm_so = matches[0].rm_eo = -1;
855 /* Is this ACL only for a specific value? */
856 if ( a->acl_attrval.bv_len ) {
861 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
862 state->as_recorded |= ACL_STATE_RECORDED_VD;
863 state->as_vd_acl = a;
864 state->as_vd_acl_count = *count;
865 state->as_vd_access = a->acl_access;
866 state->as_vd_access_count = 1;
867 ACL_INVALIDATE( state->as_vd_acl_mask );
870 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
871 Debug( LDAP_DEBUG_ACL,
872 "acl_get: valpat %s\n",
873 a->acl_attrval.bv_val, 0, 0 );
874 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
882 Debug( LDAP_DEBUG_ACL,
884 a->acl_attrval.bv_val, 0, 0 );
886 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
887 if (value_match( &match, desc,
888 a->acl_attrval_mr, 0,
889 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
896 patlen = a->acl_attrval.bv_len;
897 vdnlen = val->bv_len;
899 if ( vdnlen < patlen )
902 if ( a->acl_attrval_style == ACL_STYLE_BASE ) {
903 if ( vdnlen > patlen )
906 } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) {
907 ber_len_t rdnlen = 0;
909 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
912 rdnlen = dn_rdnlen( NULL, val );
913 if ( rdnlen != vdnlen - patlen - 1 )
916 } else if ( a->acl_attrval_style == ACL_STYLE_SUBTREE ) {
917 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
920 } else if ( a->acl_attrval_style == ACL_STYLE_CHILDREN ) {
921 if ( vdnlen <= patlen )
924 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
928 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ) )
934 if ( a->acl_filter != NULL ) {
935 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
936 if ( rc != LDAP_COMPARE_TRUE ) {
941 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
946 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
954 AttributeDescription *desc,
960 struct berval *opndn )
963 * if access applies to the entry itself, and the
964 * user is bound as somebody in the same namespace as
965 * the entry, OR the given dn matches the dn pattern
968 * NOTE: styles "anonymous", "users" and "self"
969 * have been moved to enum slap_style_t, whose
970 * value is set in a_dn_style; however, the string
971 * is maintaned in a_dn_pat.
973 if ( b->a_style == ACL_STYLE_ANONYMOUS ) {
974 if ( !BER_BVISEMPTY( opndn ) ) {
978 } else if ( b->a_style == ACL_STYLE_USERS ) {
979 if ( BER_BVISEMPTY( opndn ) ) {
987 /* must have DN syntax */
988 if ( desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) return 1;
990 /* check if the target is an attribute. */
991 if ( val == NULL ) return 1;
993 /* target is attribute, check if the attribute value
996 rc = value_match( &match, desc,
997 desc->ad_type->sat_equality, 0,
998 val, opndn, &dummy );
999 /* on match error or no match, fail the ACL clause */
1000 if ( rc != LDAP_SUCCESS || match != 0 )
1004 } else if ( b->a_style == ACL_STYLE_SELF ) {
1005 struct berval ndn, selfndn;
1008 if ( BER_BVISEMPTY( opndn ) || BER_BVISNULL( &e->e_nname ) ) {
1012 level = b->a_self_level;
1020 selfndn = e->e_nname;
1023 for ( ; level > 0; level-- ) {
1024 if ( BER_BVISEMPTY( &ndn ) ) {
1027 dnParent( &ndn, &ndn );
1030 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
1035 } else if ( b->a_style == ACL_STYLE_REGEX ) {
1036 if ( !ber_bvccmp( &b->a_pat, '*' ) ) {
1038 regmatch_t tmp_matches[2],
1039 *tmp_matchesp = tmp_matches;
1043 switch ( a->acl_dn_style ) {
1044 case ACL_STYLE_REGEX:
1045 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1046 tmp_matchesp = matches;
1047 tmp_nmatch = nmatch;
1050 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1052 case ACL_STYLE_BASE:
1053 tmp_matches[0].rm_so = 0;
1054 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1059 case ACL_STYLE_SUBTREE:
1060 case ACL_STYLE_CHILDREN:
1061 tmp_matches[0].rm_so = 0;
1062 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1063 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1064 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1078 if ( !regex_matches( &b->a_pat, opndn->bv_val,
1079 e->e_ndn, tmp_nmatch, tmp_matchesp ) )
1087 ber_len_t patlen, odnlen;
1090 if ( e->e_dn == NULL )
1093 if ( b->a_expand ) {
1095 char buf[ACL_BUF_SIZE];
1098 regmatch_t tmp_matches[2],
1099 *tmp_matchesp = tmp_matches;
1103 bv.bv_len = sizeof( buf ) - 1;
1106 switch ( a->acl_dn_style ) {
1107 case ACL_STYLE_REGEX:
1108 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1109 tmp_matchesp = matches;
1110 tmp_nmatch = nmatch;
1113 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1115 case ACL_STYLE_BASE:
1116 tmp_matches[0].rm_so = 0;
1117 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1122 case ACL_STYLE_SUBTREE:
1123 case ACL_STYLE_CHILDREN:
1124 tmp_matches[0].rm_so = 0;
1125 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1126 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1127 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1141 if ( acl_string_expand( &bv, &b->a_pat,
1143 tmp_nmatch, tmp_matchesp ) )
1148 if ( dnNormalize(0, NULL, NULL, &bv,
1149 &pat, op->o_tmpmemctx )
1152 /* did not expand to a valid dn */
1160 patlen = pat.bv_len;
1161 odnlen = opndn->bv_len;
1162 if ( odnlen < patlen ) {
1163 goto dn_match_cleanup;
1167 if ( b->a_style == ACL_STYLE_BASE ) {
1168 /* base dn -- entire object DN must match */
1169 if ( odnlen != patlen ) {
1170 goto dn_match_cleanup;
1173 } else if ( b->a_style == ACL_STYLE_ONE ) {
1174 ber_len_t rdnlen = 0;
1176 if ( odnlen <= patlen ) {
1177 goto dn_match_cleanup;
1180 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1181 goto dn_match_cleanup;
1184 rdnlen = dn_rdnlen( NULL, opndn );
1185 if ( rdnlen - ( odnlen - patlen - 1 ) != 0 ) {
1186 goto dn_match_cleanup;
1189 } else if ( b->a_style == ACL_STYLE_SUBTREE ) {
1190 if ( odnlen > patlen && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1191 goto dn_match_cleanup;
1194 } else if ( b->a_style == ACL_STYLE_CHILDREN ) {
1195 if ( odnlen <= patlen ) {
1196 goto dn_match_cleanup;
1199 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1200 goto dn_match_cleanup;
1203 } else if ( b->a_style == ACL_STYLE_LEVEL ) {
1204 int level = b->a_level;
1207 if ( odnlen <= patlen ) {
1208 goto dn_match_cleanup;
1211 if ( level > 0 && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) )
1213 goto dn_match_cleanup;
1217 for ( ; level > 0; level-- ) {
1218 if ( BER_BVISEMPTY( &ndn ) ) {
1219 goto dn_match_cleanup;
1221 dnParent( &ndn, &ndn );
1222 if ( ndn.bv_len < patlen ) {
1223 goto dn_match_cleanup;
1227 if ( ndn.bv_len != patlen ) {
1228 goto dn_match_cleanup;
1232 got_match = !strcmp( pat.bv_val, &opndn->bv_val[ odnlen - patlen ] );
1235 if ( pat.bv_val != b->a_pat.bv_val ) {
1236 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
1248 * Record value-dependent access control state
1250 #define ACL_RECORD_VALUE_STATE do { \
1251 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
1252 state->as_recorded |= ACL_STATE_RECORDED_VD; \
1253 state->as_vd_acl = a; \
1254 AC_MEMCPY( state->as_vd_acl_matches, matches, \
1255 sizeof( state->as_vd_acl_matches )) ; \
1256 state->as_vd_acl_count = count; \
1257 state->as_vd_access = b; \
1258 state->as_vd_access_count = i; \
1270 regmatch_t *matches,
1272 AccessControlState *state,
1273 slap_dn_access *bdn,
1274 struct berval *opndn )
1280 const char *attr = bdn->a_at->ad_cname.bv_val;
1282 assert( attr != NULL );
1284 if ( BER_BVISEMPTY( opndn ) ) {
1288 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n", attr, 0, 0 );
1291 /* see if asker is listed in dnattr */
1292 for ( at = attrs_find( e->e_attrs, bdn->a_at );
1294 at = attrs_find( at->a_next, bdn->a_at ) )
1296 if ( value_find_ex( bdn->a_at,
1297 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1298 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1300 &bv, op->o_tmpmemctx ) == 0 )
1309 /* have a dnattr match. if this is a self clause then
1310 * the target must also match the op dn.
1312 if ( bdn->a_self ) {
1313 /* check if the target is an attribute. */
1314 if ( val == NULL ) return 1;
1316 /* target is attribute, check if the attribute value
1319 rc = value_match( &match, bdn->a_at,
1320 bdn->a_at->ad_type->sat_equality, 0,
1322 /* on match error or no match, fail the ACL clause */
1323 if ( rc != LDAP_SUCCESS || match != 0 )
1328 /* no dnattr match, check if this is a self clause */
1329 if ( ! bdn->a_self )
1332 ACL_RECORD_VALUE_STATE;
1334 /* this is a self clause, check if the target is an
1340 /* target is attribute, check if the attribute value
1343 rc = value_match( &match, bdn->a_at,
1344 bdn->a_at->ad_type->sat_equality, 0,
1347 /* on match error or no match, fail the ACL clause */
1348 if ( rc != LDAP_SUCCESS || match != 0 )
1357 * slap_acl_mask - modifies mask based upon the given acl and the
1358 * requested access to entry e, attribute attr, value val. if val
1359 * is null, access to the whole attribute is assumed (all values).
1361 * returns 0 access NOT allowed
1365 static slap_control_t
1371 AttributeDescription *desc,
1374 regmatch_t *matches,
1376 AccessControlState *state )
1381 char accessmaskbuf[ACCESSMASK_MAXLEN];
1384 slap_mask_t a2pmask = ACL_ACCESS2PRIV( *mask );
1386 assert( a != NULL );
1387 assert( mask != NULL );
1388 assert( desc != NULL );
1390 attr = desc->ad_cname.bv_val;
1392 assert( attr != NULL );
1394 Debug( LDAP_DEBUG_ACL,
1395 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
1398 Debug( LDAP_DEBUG_ACL,
1399 "=> acl_mask: to %s by \"%s\", (%s) \n",
1400 val ? "value" : "all values",
1401 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
1402 accessmask2str( *mask, accessmaskbuf, 1 ) );
1405 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
1406 && state->as_vd_acl == a )
1408 b = state->as_vd_access;
1409 i = state->as_vd_access_count;
1416 for ( ; b != NULL; b = b->a_next, i++ ) {
1417 slap_mask_t oldmask, modmask;
1419 ACL_INVALIDATE( modmask );
1421 /* AND <who> clauses */
1422 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
1423 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
1424 b->a_dn_pat.bv_val, 0, 0);
1426 * if access applies to the entry itself, and the
1427 * user is bound as somebody in the same namespace as
1428 * the entry, OR the given dn matches the dn pattern
1431 * NOTE: styles "anonymous", "users" and "self"
1432 * have been moved to enum slap_style_t, whose
1433 * value is set in a_dn_style; however, the string
1434 * is maintaned in a_dn_pat.
1437 if ( acl_mask_dn( op, e, desc, val, a, nmatch, matches,
1438 &b->a_dn, &op->o_ndn ) )
1444 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
1447 Debug( LDAP_DEBUG_ACL, "<= check a_realdn_pat: %s\n",
1448 b->a_realdn_pat.bv_val, 0, 0);
1450 * if access applies to the entry itself, and the
1451 * user is bound as somebody in the same namespace as
1452 * the entry, OR the given dn matches the dn pattern
1455 * NOTE: styles "anonymous", "users" and "self"
1456 * have been moved to enum slap_style_t, whose
1457 * value is set in a_dn_style; however, the string
1458 * is maintaned in a_dn_pat.
1461 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1463 ndn = op->o_conn->c_ndn;
1468 if ( acl_mask_dn( op, e, desc, val, a, nmatch, matches,
1469 &b->a_realdn, &ndn ) )
1475 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1476 if ( ! op->o_conn->c_listener ) {
1479 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
1480 b->a_sockurl_pat.bv_val, 0, 0 );
1482 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
1483 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
1484 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
1485 e->e_ndn, nmatch, matches ) )
1490 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
1492 char buf[ACL_BUF_SIZE];
1494 bv.bv_len = sizeof( buf ) - 1;
1496 if ( acl_string_expand( &bv, &b->a_sockurl_pat,
1497 e->e_ndn, nmatch, matches ) )
1502 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1508 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1516 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1517 if ( !op->o_conn->c_peer_domain.bv_val ) {
1520 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1521 b->a_domain_pat.bv_val, 0, 0 );
1522 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1523 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1524 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1525 e->e_ndn, nmatch, matches ) )
1530 char buf[ACL_BUF_SIZE];
1532 struct berval cmp = op->o_conn->c_peer_domain;
1533 struct berval pat = b->a_domain_pat;
1535 if ( b->a_domain_expand ) {
1538 bv.bv_len = sizeof(buf) - 1;
1541 if ( acl_string_expand(&bv, &b->a_domain_pat,
1542 e->e_ndn, nmatch, matches) )
1549 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1550 int offset = cmp.bv_len - pat.bv_len;
1555 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1559 /* trim the domain */
1560 cmp.bv_val = &cmp.bv_val[ offset ];
1561 cmp.bv_len -= offset;
1564 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1571 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1572 if ( !op->o_conn->c_peer_name.bv_val ) {
1575 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1576 b->a_peername_pat.bv_val, 0, 0 );
1577 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1578 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1579 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1580 e->e_ndn, nmatch, matches ) )
1586 /* try exact match */
1587 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1588 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1592 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1594 char buf[ACL_BUF_SIZE];
1596 bv.bv_len = sizeof( buf ) - 1;
1598 if ( acl_string_expand( &bv, &b->a_peername_pat,
1599 e->e_ndn, nmatch, matches ) )
1604 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1608 /* extract IP and try exact match */
1609 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1611 char buf[] = "255.255.255.255";
1614 int port_number = -1;
1616 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1617 acl_bv_ip_eq.bv_val,
1618 acl_bv_ip_eq.bv_len ) != 0 )
1621 ip.bv_val = op->o_conn->c_peer_name.bv_val + acl_bv_ip_eq.bv_len;
1622 ip.bv_len = op->o_conn->c_peer_name.bv_len - acl_bv_ip_eq.bv_len;
1624 port = strrchr( ip.bv_val, ':' );
1626 ip.bv_len = port - ip.bv_val;
1628 if ( lutil_atoi( &port_number, port ) != 0 )
1632 /* the port check can be anticipated here */
1633 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1636 /* address longer than expected? */
1637 if ( ip.bv_len >= sizeof(buf) )
1640 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1641 buf[ ip.bv_len ] = '\0';
1643 addr = inet_addr( buf );
1645 /* unable to convert? */
1646 if ( addr == (unsigned long)(-1) )
1649 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1652 #ifdef LDAP_PF_LOCAL
1653 /* extract path and try exact match */
1654 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1657 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1658 acl_bv_path_eq.bv_val,
1659 acl_bv_path_eq.bv_len ) != 0 )
1662 path.bv_val = op->o_conn->c_peer_name.bv_val
1663 + acl_bv_path_eq.bv_len;
1664 path.bv_len = op->o_conn->c_peer_name.bv_len
1665 - acl_bv_path_eq.bv_len;
1667 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1670 #endif /* LDAP_PF_LOCAL */
1672 /* exact match (very unlikely...) */
1673 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1680 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1681 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1684 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1685 b->a_sockname_pat.bv_val, 0, 0 );
1686 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1687 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1688 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1689 e->e_ndn, nmatch, matches ) )
1694 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1696 char buf[ACL_BUF_SIZE];
1698 bv.bv_len = sizeof( buf ) - 1;
1700 if ( acl_string_expand( &bv, &b->a_sockname_pat,
1701 e->e_ndn, nmatch, matches ) )
1706 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1711 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1718 if ( b->a_dn_at != NULL ) {
1719 if ( acl_mask_dnattr( op, e, val, a, b, i,
1720 matches, count, state,
1721 &b->a_dn, &op->o_ndn ) )
1727 if ( b->a_realdn_at != NULL ) {
1730 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1732 ndn = op->o_conn->c_ndn;
1737 if ( acl_mask_dnattr( op, e, val, a, b, i,
1738 matches, count, state,
1739 &b->a_realdn, &ndn ) )
1745 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1747 struct berval ndn = BER_BVNULL;
1750 if ( op->o_ndn.bv_len == 0 ) {
1754 Debug( LDAP_DEBUG_ACL, "<= check a_group_pat: %s\n",
1755 b->a_group_pat.bv_val, 0, 0 );
1757 /* b->a_group is an unexpanded entry name, expanded it should be an
1758 * entry with objectclass group* and we test to see if odn is one of
1759 * the values in the attribute group
1761 /* see if asker is listed in dnattr */
1762 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1763 char buf[ACL_BUF_SIZE];
1765 regmatch_t tmp_matches[2],
1766 *tmp_matchesp = tmp_matches;
1768 bv.bv_len = sizeof(buf) - 1;
1773 switch ( a->acl_dn_style ) {
1774 case ACL_STYLE_REGEX:
1775 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1776 tmp_matchesp = matches;
1777 tmp_nmatch = nmatch;
1781 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1782 case ACL_STYLE_BASE:
1783 tmp_matches[0].rm_so = 0;
1784 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1789 case ACL_STYLE_SUBTREE:
1790 case ACL_STYLE_CHILDREN:
1791 tmp_matches[0].rm_so = 0;
1792 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1793 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1794 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1808 if ( acl_string_expand( &bv, &b->a_group_pat,
1810 tmp_nmatch, tmp_matchesp ) )
1815 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1816 op->o_tmpmemctx ) != LDAP_SUCCESS )
1818 /* did not expand to a valid dn */
1825 bv = b->a_group_pat;
1828 rc = backend_group( op, e, &bv, &op->o_ndn,
1829 b->a_group_oc, b->a_group_at );
1832 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1840 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1842 char buf[ACL_BUF_SIZE];
1844 Debug( LDAP_DEBUG_ACL, "<= check a_set_pat: %s\n",
1845 b->a_set_pat.bv_val, 0, 0 );
1847 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1849 regmatch_t tmp_matches[2],
1850 *tmp_matchesp = tmp_matches;
1853 bv.bv_len = sizeof( buf ) - 1;
1858 switch ( a->acl_dn_style ) {
1859 case ACL_STYLE_REGEX:
1860 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1861 tmp_matchesp = matches;
1862 tmp_nmatch = nmatch;
1866 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1867 case ACL_STYLE_BASE:
1868 tmp_matches[0].rm_so = 0;
1869 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1874 case ACL_STYLE_SUBTREE:
1875 case ACL_STYLE_CHILDREN:
1876 tmp_matches[0].rm_so = 0;
1877 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1878 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1879 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1893 if ( acl_string_expand( &bv, &b->a_set_pat,
1895 tmp_nmatch, tmp_matchesp ) )
1904 if ( acl_match_set( &bv, op, e, NULL ) == 0 ) {
1909 if ( b->a_authz.sai_ssf ) {
1910 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1911 b->a_authz.sai_ssf, op->o_ssf, 0 );
1912 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1917 if ( b->a_authz.sai_transport_ssf ) {
1918 Debug( LDAP_DEBUG_ACL,
1919 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1920 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1921 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1926 if ( b->a_authz.sai_tls_ssf ) {
1927 Debug( LDAP_DEBUG_ACL,
1928 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1929 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1930 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1935 if ( b->a_authz.sai_sasl_ssf ) {
1936 Debug( LDAP_DEBUG_ACL,
1937 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1938 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1939 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1945 if ( b->a_dynacl ) {
1947 slap_access_t tgrant, tdeny;
1949 Debug( LDAP_DEBUG_ACL, "<= check a_dynacl\n",
1952 /* this case works different from the others above.
1953 * since dynamic ACL's themselves give permissions, we need
1954 * to first check b->a_access_mask, the ACL's access level.
1956 /* first check if the right being requested
1957 * is allowed by the ACL clause.
1959 if ( ! ACL_PRIV_ISSET( b->a_access_mask, a2pmask ) ) {
1963 /* start out with nothing granted, nothing denied */
1967 for ( da = b->a_dynacl; da; da = da->da_next ) {
1968 slap_access_t grant,
1974 Debug( LDAP_DEBUG_ACL, " <= check a_dynacl: %s\n",
1975 da->da_name, 0, 0 );
1977 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1983 /* remove anything that the ACL clause does not allow */
1984 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1985 tdeny &= ACL_PRIV_MASK;
1987 /* see if we have anything to contribute */
1988 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1992 /* this could be improved by changing slap_acl_mask so that it can deal with
1993 * by clauses that return grant/deny pairs. Right now, it does either
1994 * additive or subtractive rights, but not both at the same time. So,
1995 * we need to combine the grant/deny pair into a single rights mask in
1996 * a smart way: if either grant or deny is "empty", then we use the
1997 * opposite as is, otherwise we remove any denied rights from the grant
1998 * rights mask and construct an additive mask.
2000 if (ACL_IS_INVALID(tdeny)) {
2001 modmask = tgrant | ACL_PRIV_ADDITIVE;
2003 } else if (ACL_IS_INVALID(tgrant)) {
2004 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2007 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2011 #else /* !SLAP_DYNACL */
2013 /* NOTE: this entire block can be eliminated when SLAP_DYNACL
2014 * moves outside of LDAP_DEVEL */
2015 #ifdef SLAPD_ACI_ENABLED
2016 if ( b->a_aci_at != NULL ) {
2018 slap_access_t grant, deny, tgrant, tdeny;
2019 struct berval parent_ndn;
2020 BerVarray bvals = NULL;
2023 char accessmaskbuf1[ACCESSMASK_MAXLEN];
2026 Debug( LDAP_DEBUG_ACL, " <= check a_aci_at: %s\n",
2027 b->a_aci_at->ad_cname.bv_val, 0, 0 );
2029 /* this case works different from the others above.
2030 * since aci's themselves give permissions, we need
2031 * to first check b->a_access_mask, the ACL's access level.
2034 if ( BER_BVISEMPTY( &e->e_nname ) ) {
2035 /* no ACIs in the root DSE */
2039 /* first check if the right being requested
2040 * is allowed by the ACL clause.
2042 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
2045 /* start out with nothing granted, nothing denied */
2049 /* get the aci attribute */
2050 at = attr_find( e->e_attrs, b->a_aci_at );
2053 /* FIXME: this breaks acl caching;
2054 * see also ACL_RECORD_VALUE_STATE below */
2055 ACL_RECORD_VALUE_STATE;
2057 /* the aci is an multi-valued attribute. The
2058 * rights are determined by OR'ing the individual
2059 * rights given by the acis.
2061 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2066 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0 )
2072 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2073 accessmask2str(tgrant, accessmaskbuf, 1),
2074 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2077 /* If the entry level aci didn't contain anything valid for the
2078 * current operation, climb up the tree and evaluate the
2079 * acis with scope set to subtree
2081 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
2082 dnParent( &e->e_nname, &parent_ndn );
2083 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
2084 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
2085 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
2093 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++ ) {
2095 /* FIXME: this breaks acl caching;
2096 * see also ACL_RECORD_VALUE_STATE above */
2097 ACL_RECORD_VALUE_STATE;
2099 if ( aci_mask( op, e, desc, val, &bvals[i],
2101 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2105 /* evaluation stops as soon as either a "deny" or a
2106 * "grant" directive matches.
2108 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
2112 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2113 accessmask2str(tgrant, accessmaskbuf, 1),
2114 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2118 case LDAP_NO_SUCH_ATTRIBUTE:
2119 /* just go on if the aci-Attribute is not present in
2122 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
2126 case LDAP_NO_SUCH_OBJECT:
2127 /* We have reached the base object */
2128 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
2139 dnParent( &parent_ndn, &parent_ndn );
2144 /* remove anything that the ACL clause does not allow */
2145 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2146 tdeny &= ACL_PRIV_MASK;
2148 /* see if we have anything to contribute */
2149 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2153 /* this could be improved by changing slap_acl_mask so that it can deal with
2154 * by clauses that return grant/deny pairs. Right now, it does either
2155 * additive or subtractive rights, but not both at the same time. So,
2156 * we need to combine the grant/deny pair into a single rights mask in
2157 * a smart way: if either grant or deny is "empty", then we use the
2158 * opposite as is, otherwise we remove any denied rights from the grant
2159 * rights mask and construct an additive mask.
2161 if (ACL_IS_INVALID(tdeny)) {
2162 modmask = tgrant | ACL_PRIV_ADDITIVE;
2164 } else if (ACL_IS_INVALID(tgrant)) {
2165 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2168 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2172 #endif /* SLAPD_ACI_ENABLED */
2173 #endif /* !SLAP_DYNACL */
2175 modmask = b->a_access_mask;
2178 Debug( LDAP_DEBUG_ACL,
2179 "<= acl_mask: [%d] applying %s (%s)\n",
2180 i, accessmask2str( modmask, accessmaskbuf, 1 ),
2181 b->a_type == ACL_CONTINUE
2183 : b->a_type == ACL_BREAK
2189 if( ACL_IS_ADDITIVE(modmask) ) {
2191 ACL_PRIV_SET( *mask, modmask );
2194 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2196 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
2197 /* substract privs */
2198 ACL_PRIV_CLR( *mask, modmask );
2201 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2210 Debug( LDAP_DEBUG_ACL,
2211 "<= acl_mask: [%d] mask: %s\n",
2212 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
2214 if( b->a_type == ACL_CONTINUE ) {
2217 } else if ( b->a_type == ACL_BREAK ) {
2225 /* implicit "by * none" clause */
2228 Debug( LDAP_DEBUG_ACL,
2229 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
2230 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
2235 * acl_check_modlist - check access control on the given entry to see if
2236 * it allows the given modifications by the user associated with op.
2237 * returns 1 if mods allowed ok
2238 * 0 mods not allowed
2245 Modifications *mlist )
2248 AccessControlState state = ACL_STATE_INIT;
2251 int ret = 1; /* default is access allowed */
2255 be = LDAP_STAILQ_FIRST(&backendDB);
2259 assert( be != NULL );
2261 /* short circuit root database access */
2262 if ( be_isroot( op ) ) {
2263 Debug( LDAP_DEBUG_ACL,
2264 "<= acl_access_allowed: granted to database root\n",
2269 /* use backend default access if no backend acls */
2270 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
2271 Debug( LDAP_DEBUG_ACL,
2272 "=> access_allowed: backend default %s access %s to \"%s\"\n",
2273 access2str( ACL_WRITE ),
2274 op->o_bd->be_dfltaccess >= ACL_WRITE
2275 ? "granted" : "denied",
2277 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
2281 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
2283 * Internal mods are ignored by ACL_WRITE checking
2285 if ( mlist->sml_flags & SLAP_MOD_INTERNAL ) {
2286 Debug( LDAP_DEBUG_ACL, "acl: internal mod %s:"
2287 " modify access granted\n",
2288 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2293 * no-user-modification operational attributes are ignored
2294 * by ACL_WRITE checking as any found here are not provided
2297 if ( is_at_no_user_mod( mlist->sml_desc->ad_type )
2298 && ! ( mlist->sml_flags & SLAP_MOD_MANAGING ) )
2300 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
2301 " modify access granted\n",
2302 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2306 switch ( mlist->sml_op ) {
2307 case LDAP_MOD_REPLACE:
2308 case LDAP_MOD_INCREMENT:
2310 * We must check both permission to delete the whole
2311 * attribute and permission to add the specific attributes.
2312 * This prevents abuse from selfwriters.
2314 if ( ! access_allowed( op, e,
2315 mlist->sml_desc, NULL,
2316 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2323 if ( mlist->sml_values == NULL ) break;
2325 /* fall thru to check value to add */
2328 assert( mlist->sml_values != NULL );
2330 for ( bv = mlist->sml_nvalues
2331 ? mlist->sml_nvalues : mlist->sml_values;
2332 bv->bv_val != NULL; bv++ )
2334 if ( ! access_allowed( op, e,
2335 mlist->sml_desc, bv,
2336 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WADD,
2345 case LDAP_MOD_DELETE:
2346 if ( mlist->sml_values == NULL ) {
2347 if ( ! access_allowed( op, e,
2348 mlist->sml_desc, NULL,
2349 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2357 for ( bv = mlist->sml_nvalues
2358 ? mlist->sml_nvalues : mlist->sml_values;
2359 bv->bv_val != NULL; bv++ )
2361 if ( ! access_allowed( op, e,
2362 mlist->sml_desc, bv,
2363 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2372 case SLAP_MOD_SOFTADD:
2373 /* allow adding attribute via modrdn thru */
2385 if (be_null) op->o_bd = NULL;
2391 struct berval *list,
2404 while ( len >= 0 && --ix >= 0 ) {
2405 while ( --len >= 0 && *p++ != sep )
2408 while ( len >= 0 && *p == ' ' ) {
2421 while ( --len >= 0 && *p != sep ) {
2425 while ( bv->bv_len > 0 && *--p == ' ' ) {
2432 typedef struct acl_set_gather_t {
2438 acl_set_cb_gather( Operation *op, SlapReply *rs )
2440 acl_set_gather_t *p = (acl_set_gather_t *)op->o_callback->sc_private;
2442 if ( rs->sr_type == REP_SEARCH ) {
2443 BerValue bvals[ 2 ];
2444 BerVarray bvalsp = NULL;
2447 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
2448 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
2450 if ( desc == slap_schema.si_ad_entryDN ) {
2452 bvals[ 0 ] = rs->sr_entry->e_nname;
2453 BER_BVZERO( &bvals[ 1 ] );
2458 a = attr_find( rs->sr_entry->e_attrs, desc );
2462 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
2465 bvalsp = a->a_nvals;
2471 p->bvals = slap_set_join( p->cookie, p->bvals,
2472 ( '|' | SLAP_SET_RREF ), bvalsp );
2476 assert( rs->sr_type == REP_RESULT );
2483 acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2485 AclSetCookie *cp = (AclSetCookie *)cookie;
2487 LDAPURLDesc *ludp = NULL;
2488 Operation op2 = { 0 };
2489 SlapReply rs = {REP_RESULT};
2490 AttributeName anlist[ 2 ], *anlistp = NULL;
2492 slap_callback cb = { NULL, acl_set_cb_gather, NULL, NULL };
2493 acl_set_gather_t p = { 0 };
2494 const char *text = NULL;
2495 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2497 /* this routine needs to return the bervals instead of
2498 * plain strings, since syntax is not known. It should
2499 * also return the syntax or some "comparison cookie".
2501 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2502 return acl_set_gather2( cookie, name, desc );
2505 rc = ldap_url_parse( name->bv_val, &ludp );
2506 if ( rc != LDAP_URL_SUCCESS ) {
2507 rc = LDAP_PROTOCOL_ERROR;
2511 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2513 /* host part must be empty */
2514 /* extensions parts must be empty */
2515 rc = LDAP_PROTOCOL_ERROR;
2519 /* Grab the searchbase and see if an appropriate database can be found */
2520 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2521 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2522 &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2523 BER_BVZERO( &op2.o_req_dn );
2524 if ( rc != LDAP_SUCCESS ) {
2528 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2529 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2530 rc = LDAP_NO_SUCH_OBJECT;
2534 /* Grab the filter */
2535 if ( ludp->lud_filter ) {
2536 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2537 cp->asc_op->o_tmpmemctx );
2540 op2.ors_filterstr = defaultFilter_bv;
2543 op2.ors_filter = str2filter_x( cp->asc_op, op2.ors_filterstr.bv_val );
2544 if ( op2.ors_filter == NULL ) {
2545 rc = LDAP_PROTOCOL_ERROR;
2549 /* Grab the scope */
2550 op2.ors_scope = ludp->lud_scope;
2552 /* Grap the attributes */
2553 if ( ludp->lud_attrs ) {
2554 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2557 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2558 cp->asc_op->o_tmpmemctx );
2560 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2561 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2562 anlistp[ nattrs ].an_desc = NULL;
2563 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2564 &anlistp[ nattrs ].an_desc, &text );
2565 if ( rc != LDAP_SUCCESS ) {
2574 anlistp[ nattrs ].an_name = desc->ad_cname;
2575 anlistp[ nattrs ].an_desc = desc;
2577 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2581 op2.o_hdr = cp->asc_op->o_hdr;
2582 op2.o_tag = LDAP_REQ_SEARCH;
2583 op2.o_ndn = op2.o_bd->be_rootndn;
2584 op2.o_callback = &cb;
2585 slap_op_time( &op2.o_time, &op2.o_tincr );
2586 op2.o_do_not_cache = 1;
2587 op2.o_is_auth_check = 0;
2588 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
2589 op2.ors_slimit = SLAP_NO_LIMIT;
2590 op2.ors_tlimit = SLAP_NO_LIMIT;
2591 op2.ors_attrs = anlistp;
2592 op2.ors_attrsonly = 0;
2593 op2.o_private = cp->asc_op->o_private;
2597 rc = op2.o_bd->be_search( &op2, &rs );
2603 if ( op2.ors_filter ) {
2604 filter_free_x( cp->asc_op, op2.ors_filter );
2606 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2607 slap_sl_free( op2.o_req_ndn.bv_val, cp->asc_op->o_tmpmemctx );
2609 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2610 slap_sl_free( op2.o_req_dn.bv_val, cp->asc_op->o_tmpmemctx );
2613 ldap_free_urldesc( ludp );
2615 if ( anlistp && anlistp != anlist ) {
2616 slap_sl_free( anlistp, cp->asc_op->o_tmpmemctx );
2623 acl_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2625 AclSetCookie *cp = (AclSetCookie *)cookie;
2626 BerVarray bvals = NULL;
2630 /* this routine needs to return the bervals instead of
2631 * plain strings, since syntax is not known. It should
2632 * also return the syntax or some "comparison cookie".
2634 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->asc_op->o_tmpmemctx );
2635 if ( rc == LDAP_SUCCESS ) {
2636 if ( desc == slap_schema.si_ad_entryDN ) {
2637 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2638 cp->asc_op->o_tmpmemctx );
2640 BER_BVZERO( &bvals[ 1 ] );
2644 backend_attribute( cp->asc_op,
2645 cp->asc_e, &ndn, desc, &bvals, ACL_NONE );
2648 if ( !BER_BVISNULL( &ndn ) ) {
2649 slap_sl_free( ndn.bv_val, cp->asc_op->o_tmpmemctx );
2658 struct berval *subj,
2661 struct berval *default_set_attribute )
2663 struct berval set = BER_BVNULL;
2665 AclSetCookie cookie;
2667 if ( default_set_attribute == NULL ) {
2668 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2671 struct berval subjdn, ndn = BER_BVNULL;
2672 struct berval setat;
2675 AttributeDescription *desc = NULL;
2677 /* format of string is "entry/setAttrName" */
2678 if ( acl_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2682 if ( acl_get_part( subj, 1, '/', &setat ) < 0 ) {
2683 setat = *default_set_attribute;
2687 * NOTE: dnNormalize honors the ber_len field
2688 * as the length of the dn to be normalized
2690 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2691 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2693 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2694 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2698 BER_BVZERO( &bvals[0] );
2699 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2701 bvals[0].bv_val = bvals[i-1].bv_val;
2702 BER_BVZERO( &bvals[i-1] );
2704 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2705 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2710 if ( !BER_BVISNULL( &set ) ) {
2713 rc = ( slap_set_filter(
2715 (SetCookie *)&cookie, &set,
2716 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2717 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2726 * dynamic ACL infrastructure
2728 static slap_dynacl_t *da_list = NULL;
2731 slap_dynacl_register( slap_dynacl_t *da )
2735 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2736 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2741 if ( tmp != NULL ) {
2745 if ( da->da_mask == NULL ) {
2749 da->da_private = NULL;
2750 da->da_next = da_list;
2756 static slap_dynacl_t *
2757 slap_dynacl_next( slap_dynacl_t *da )
2766 slap_dynacl_get( const char *name )
2770 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2771 if ( strcasecmp( da->da_name, name ) == 0 ) {
2778 #endif /* SLAP_DYNACL */
2781 * statically built-in dynamic ACL initialization
2783 static int (*acl_init_func[])( void ) = {
2784 #ifdef SLAPD_ACI_ENABLED
2787 #else /* !SLAP_DYNACL */
2789 #endif /* !SLAP_DYNACL */
2790 #endif /* SLAPD_ACI_ENABLED */
2800 for ( i = 0; acl_init_func[ i ] != NULL; i++ ) {
2801 rc = (*(acl_init_func[ i ]))();
2816 regmatch_t *matches)
2824 bv->bv_val[0] = '\0';
2825 bv->bv_len--; /* leave space for lone $ */
2828 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2829 sp < pat->bv_val + pat->bv_len ; sp++ )
2831 /* did we previously see a $ */
2833 if ( flag == 1 && *sp == '$' ) {
2838 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2841 } else if ( *sp >= '0' && *sp <= '9' ) {
2849 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2850 if ( *sp >= '0' && *sp <= '9' ) {
2851 n = 10*n + ( *sp - '0' );
2855 if ( *sp != /*'{'*/ '}' ) {
2861 if ( n >= nmatch ) {
2867 i = matches[n].rm_so;
2868 l = matches[n].rm_eo;
2869 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2887 /* must have ended with a single $ */
2895 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2896 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2903 struct berval *pat, /* pattern to expand and match against */
2904 char *str, /* string to match against pattern */
2905 char *buf, /* buffer with $N expansion variables */
2906 int nmatch, /* size of the matches array */
2907 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2911 char newbuf[ACL_BUF_SIZE];
2915 bv.bv_len = sizeof( newbuf ) - 1;
2922 acl_string_expand( &bv, pat, buf, nmatch, matches );
2923 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2925 char error[ACL_BUF_SIZE];
2926 regerror( rc, &re, error, sizeof( error ) );
2928 Debug( LDAP_DEBUG_TRACE,
2929 "compile( \"%s\", \"%s\") failed %s\n",
2930 pat->bv_val, str, error );
2934 rc = regexec( &re, str, 0, NULL, 0 );
2937 Debug( LDAP_DEBUG_TRACE,
2938 "=> regex_matches: string: %s\n", str, 0, 0 );
2939 Debug( LDAP_DEBUG_TRACE,
2940 "=> regex_matches: rc: %d %s\n",
2941 rc, !rc ? "matches" : "no matches", 0 );