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 {
110 SLAP_SET_GATHER acl_set_gather;
111 SLAP_SET_GATHER acl_set_gather2;
114 * access_allowed - check whether op->o_ndn is allowed the requested access
115 * to entry e, attribute attr, value val. if val is null, access to
116 * the whole attribute is assumed (all values).
118 * This routine loops through all access controls and calls
119 * slap_acl_mask() on each applicable access control.
120 * The loop exits when a definitive answer is reached or
121 * or no more controls remain.
128 * - can be legally called with op == NULL
129 * - can be legally called with op->o_bd == NULL
132 #ifdef SLAP_OVERLAY_ACCESS
134 slap_access_always_allowed(
137 AttributeDescription *desc,
139 slap_access_t access,
140 AccessControlState *state,
143 assert( maskp != NULL );
145 ACL_PRIV_SET( *maskp, ACL_ACCESS2PRIV( access ) );
154 AttributeDescription *desc,
156 slap_access_t access,
157 AccessControlState *state,
162 AccessControl *a = NULL;
165 char accessmaskbuf[ACCESSMASK_MAXLEN];
168 slap_control_t control;
169 slap_access_t access_level;
171 regmatch_t matches[MAXREMATCHES];
172 int st_same_attr = 0;
174 assert( op != NULL );
176 assert( desc != NULL );
177 assert( maskp != NULL );
179 access_level = ACL_LEVEL( access );
180 attr = desc->ad_cname.bv_val;
182 assert( attr != NULL );
184 /* grant database root access */
185 if ( be_isroot( op ) ) {
186 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
187 mask = ACL_LVL_MANAGE;
192 * no-user-modification operational attributes are ignored
193 * by ACL_WRITE checking as any found here are not provided
196 * NOTE: but they are not ignored for ACL_MANAGE, because
197 * if we get here it means a non-root user is trying to
198 * manage data, so we need to check its privileges.
200 if ( access_level == ACL_WRITE && is_at_no_user_mod( desc->ad_type )
201 && desc != slap_schema.si_ad_entry
202 && desc != slap_schema.si_ad_children )
204 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
205 " %s access granted\n",
210 /* use backend default access if no backend acls */
211 if ( op->o_bd->be_acl == NULL ) {
214 Debug( LDAP_DEBUG_ACL,
215 "=> slap_access_allowed: backend default %s "
216 "access %s to \"%s\"\n",
217 access2str( access ),
218 op->o_bd->be_dfltaccess >= access_level ? "granted" : "denied",
219 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
220 ret = op->o_bd->be_dfltaccess >= access_level;
222 mask = ACL_PRIV_LEVEL;
223 for ( i = ACL_NONE; i <= op->o_bd->be_dfltaccess; i++ ) {
224 ACL_PRIV_SET( mask, ACL_ACCESS2PRIV( i ) );
233 if ( st_same_attr ) {
234 assert( state->as_vd_acl != NULL );
236 a = state->as_vd_acl;
237 count = state->as_vd_acl_count;
238 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
239 mask = state->as_vd_acl_mask;
240 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
245 if ( state ) state->as_vi_acl = NULL;
247 ACL_PRIV_ASSIGN( mask, *maskp );
249 memset( matches, '\0', sizeof( matches ) );
252 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
253 MAXREMATCHES, matches, state ) ) != NULL )
257 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
258 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
259 (int)matches[i].rm_so, (int)matches[i].rm_eo );
260 if ( matches[i].rm_so <= matches[0].rm_eo ) {
262 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
263 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
266 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
270 if ( state->as_vi_acl == a &&
271 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
273 Debug( LDAP_DEBUG_ACL,
274 "=> slap_access_allowed: result from state (%s)\n",
276 ret = state->as_result;
279 Debug( LDAP_DEBUG_ACL,
280 "=> slap_access_allowed: no res from state (%s)\n",
286 control = slap_acl_mask( a, &mask, op,
287 e, desc, val, MAXREMATCHES, matches, count, state );
289 if ( control != ACL_BREAK ) {
293 memset( matches, '\0', sizeof( matches ) );
296 if ( ACL_IS_INVALID( mask ) ) {
297 Debug( LDAP_DEBUG_ACL,
298 "=> slap_access_allowed: \"%s\" (%s) invalid!\n",
300 ACL_PRIV_ASSIGN( mask, *maskp );
302 } else if ( control == ACL_BREAK ) {
303 Debug( LDAP_DEBUG_ACL,
304 "=> slap_access_allowed: no more rules\n", 0, 0, 0 );
309 ret = ACL_GRANT( mask, access );
311 Debug( LDAP_DEBUG_ACL,
312 "=> slap_access_allowed: %s access %s by %s\n",
313 access2str( access ), ret ? "granted" : "denied",
314 accessmask2str( mask, accessmaskbuf, 1 ) );
317 ACL_PRIV_ASSIGN( *maskp, mask );
325 AttributeDescription *desc,
327 slap_access_t access,
328 AccessControlState *state,
335 * NOTE: control gets here if FIXME
336 * if an appropriate backend cannot be selected for the operation,
337 * we assume that the frontend should handle this
338 * FIXME: should select_backend() take care of this,
339 * and return frontendDB instead of NULL? maybe for some value
344 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
345 if ( op->o_bd == NULL ) {
346 op->o_bd = frontendDB;
348 rc = slap_access_allowed( op, e, desc, val, access, state, maskp );
358 AttributeDescription *desc,
360 slap_access_t access,
361 AccessControlState *state,
365 AccessControl *a = NULL;
369 char accessmaskbuf[ACCESSMASK_MAXLEN];
372 slap_access_t access_level;
374 int st_same_attr = 0;
375 static AccessControlState state_init = ACL_STATE_INIT;
378 assert( desc != NULL );
380 access_level = ACL_LEVEL( access );
382 assert( access_level > ACL_NONE );
385 if ( maskp ) ACL_INVALIDATE( *maskp );
387 attr = desc->ad_cname.bv_val;
389 assert( attr != NULL );
392 if ( op->o_is_auth_check &&
393 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
397 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
398 desc == slap_schema.si_ad_entry )
405 if ( state->as_vd_ad == desc ) {
406 if ( state->as_recorded ) {
407 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
410 return state->as_result;
412 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
413 val != NULL && state->as_vd_acl == NULL )
415 return state->as_result;
423 state->as_vd_ad = desc;
426 Debug( LDAP_DEBUG_ACL,
427 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
428 access2str( access ), e->e_dn, attr );
435 if ( op->o_bd == NULL ) {
436 op->o_bd = LDAP_STAILQ_FIRST( &backendDB );
441 * FIXME: experimental; use first backend rules
442 * iff there is no global_acl (ITS#3100) */
443 if ( frontendDB->be_acl != NULL ) {
444 op->o_bd = frontendDB;
446 #endif /* LDAP_DEVEL */
448 assert( op->o_bd != NULL );
450 /* this is enforced in backend_add() */
451 if ( op->o_bd->bd_info->bi_access_allowed ) {
452 /* delegate to backend */
453 ret = op->o_bd->bd_info->bi_access_allowed( op, e,
454 desc, val, access, state, &mask );
457 BackendDB *be_orig = op->o_bd;
459 /* use default (but pass through frontend
460 * for global ACL overlays) */
461 op->o_bd = frontendDB;
462 ret = frontendDB->bd_info->bi_access_allowed( op, e,
463 desc, val, access, state, &mask );
468 if ( ACL_IS_INVALID( mask ) ) {
469 Debug( LDAP_DEBUG_ACL,
470 "=> access_allowed: \"%s\" (%s) invalid!\n",
475 Debug( LDAP_DEBUG_ACL,
476 "=> access_allowed: no more rules\n", 0, 0, 0 );
482 Debug( LDAP_DEBUG_ACL,
483 "=> access_allowed: %s access %s by %s\n",
484 access2str( access ), ret ? "granted" : "denied",
485 accessmask2str( mask, accessmaskbuf, 1 ) );
488 if ( state != NULL ) {
489 /* If not value-dependent, save ACL in case of more attrs */
490 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
491 state->as_vi_acl = a;
492 state->as_result = ret;
494 state->as_recorded |= ACL_STATE_RECORDED;
496 if ( be_null ) op->o_bd = NULL;
497 if ( maskp ) ACL_PRIV_ASSIGN( *maskp, mask );
501 #else /* !SLAP_OVERLAY_ACCESS */
507 AttributeDescription *desc,
509 slap_access_t access,
510 AccessControlState *state,
515 AccessControl *a = NULL;
520 char accessmaskbuf[ACCESSMASK_MAXLEN];
523 slap_control_t control;
524 slap_access_t access_level;
526 regmatch_t matches[MAXREMATCHES];
527 int st_same_attr = 0;
528 static AccessControlState state_init = ACL_STATE_INIT;
531 assert( desc != NULL );
533 access_level = ACL_LEVEL( access );
535 assert( access_level > ACL_NONE );
536 if ( maskp ) ACL_INVALIDATE( *maskp );
538 attr = desc->ad_cname.bv_val;
540 assert( attr != NULL );
543 if ( op->o_is_auth_check &&
544 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
548 } else if ( get_manageDIT( op ) && access_level == ACL_WRITE &&
549 desc == slap_schema.si_ad_entry )
556 if ( state->as_vd_ad == desc ) {
557 if ( state->as_recorded ) {
558 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
561 return state->as_result;
563 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
564 val != NULL && state->as_vd_acl == NULL )
566 return state->as_result;
574 state->as_vd_ad=desc;
577 Debug( LDAP_DEBUG_ACL,
578 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
579 access2str( access ), e->e_dn, attr );
588 be = LDAP_STAILQ_FIRST(&backendDB);
592 * FIXME: experimental; use first backend rules
593 * iff there is no global_acl (ITS#3100) */
594 if ( frontendDB->be_acl == NULL )
600 assert( be != NULL );
602 /* grant database root access */
603 if ( be_isroot( op ) ) {
604 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
606 mask = ACL_LVL_MANAGE;
613 * no-user-modification operational attributes are ignored
614 * by ACL_WRITE checking as any found here are not provided
617 * NOTE: but they are not ignored for ACL_MANAGE, because
618 * if we get here it means a non-root user is trying to
619 * manage data, so we need to check its privileges.
621 if ( access_level == ACL_WRITE && is_at_no_user_mod( desc->ad_type )
622 && desc != slap_schema.si_ad_entry
623 && desc != slap_schema.si_ad_children )
625 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
626 " %s access granted\n",
631 /* use backend default access if no backend acls */
632 if ( be->be_acl == NULL ) {
633 Debug( LDAP_DEBUG_ACL,
634 "=> access_allowed: backend default %s "
635 "access %s to \"%s\"\n",
636 access2str( access ),
637 be->be_dfltaccess >= access_level ? "granted" : "denied",
638 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
639 ret = be->be_dfltaccess >= access_level;
644 mask = ACL_PRIV_LEVEL;
645 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
646 mask |= ACL_ACCESS2PRIV( i );
653 /* be is always non-NULL */
654 /* use global default access if no global acls */
655 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
656 Debug( LDAP_DEBUG_ACL,
657 "=> access_allowed: global default %s access %s to \"%s\"\n",
658 access2str( access ),
659 frontendDB->be_dfltaccess >= access_level ?
660 "granted" : "denied", op->o_dn.bv_val );
661 ret = frontendDB->be_dfltaccess >= access_level;
666 mask = ACL_PRIV_LEVEL;
667 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
668 mask |= ACL_ACCESS2PRIV( i );
679 if ( st_same_attr ) {
680 assert( state->as_vd_acl != NULL );
682 a = state->as_vd_acl;
683 count = state->as_vd_acl_count;
684 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
685 mask = state->as_vd_acl_mask;
686 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
691 if ( state ) state->as_vi_acl = NULL;
695 memset( matches, '\0', sizeof(matches) );
698 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
699 MAXREMATCHES, matches, state ) ) != NULL )
703 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
704 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
705 (int)matches[i].rm_so, (int)matches[i].rm_eo );
706 if ( matches[i].rm_so <= matches[0].rm_eo ) {
708 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
709 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
712 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
716 if ( state->as_vi_acl == a &&
717 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
719 Debug( LDAP_DEBUG_ACL,
720 "access_allowed: result from state (%s)\n",
722 ret = state->as_result;
725 Debug( LDAP_DEBUG_ACL,
726 "access_allowed: no res from state (%s)\n",
732 control = slap_acl_mask( a, &mask, op,
733 e, desc, val, MAXREMATCHES, matches, count, state );
735 if ( control != ACL_BREAK ) {
739 memset( matches, '\0', sizeof(matches) );
742 if ( ACL_IS_INVALID( mask ) ) {
743 Debug( LDAP_DEBUG_ACL,
744 "=> access_allowed: \"%s\" (%s) invalid!\n",
748 } else if ( control == ACL_BREAK ) {
749 Debug( LDAP_DEBUG_ACL,
750 "=> access_allowed: no more rules\n", 0, 0, 0 );
755 Debug( LDAP_DEBUG_ACL,
756 "=> access_allowed: %s access %s by %s\n",
757 access2str( access ),
758 ACL_GRANT(mask, access) ? "granted" : "denied",
759 accessmask2str( mask, accessmaskbuf, 1 ) );
761 ret = ACL_GRANT(mask, access);
764 if ( state != NULL ) {
765 /* If not value-dependent, save ACL in case of more attrs */
766 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
767 state->as_vi_acl = a;
768 state->as_result = ret;
770 state->as_recorded |= ACL_STATE_RECORDED;
772 if ( be_null ) op->o_bd = NULL;
773 if ( maskp ) *maskp = mask;
777 #endif /* SLAP_OVERLAY_ACCESS */
780 * slap_acl_get - return the acl applicable to entry e, attribute
781 * attr. the acl returned is suitable for use in subsequent calls to
782 * acl_access_allowed().
785 static AccessControl *
791 AttributeDescription *desc,
795 AccessControlState *state )
802 assert( count != NULL );
803 assert( desc != NULL );
805 attr = desc->ad_cname.bv_val;
807 assert( attr != NULL );
810 if( op->o_bd == NULL ) {
811 a = frontendDB->be_acl;
813 a = op->o_bd->be_acl;
824 dnlen = e->e_nname.bv_len;
826 for ( ; a != NULL; a = a->acl_next ) {
829 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
830 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
831 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
832 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
833 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
837 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
838 *count, a->acl_dn_pat.bv_val, 0 );
839 patlen = a->acl_dn_pat.bv_len;
840 if ( dnlen < patlen )
843 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
844 /* base dn -- entire object DN must match */
845 if ( dnlen != patlen )
848 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
849 int rdnlen = -1, sep = 0;
851 if ( dnlen <= patlen )
855 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
860 rdnlen = dn_rdnlen( NULL, &e->e_nname );
861 if ( rdnlen != dnlen - patlen - sep )
864 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
865 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
868 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
869 if ( dnlen <= patlen )
871 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
875 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
879 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
883 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
884 matches[0].rm_so = matches[0].rm_eo = -1;
888 /* Is this ACL only for a specific value? */
889 if ( a->acl_attrval.bv_len ) {
894 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
895 state->as_recorded |= ACL_STATE_RECORDED_VD;
896 state->as_vd_acl = a;
897 state->as_vd_acl_count = *count;
898 state->as_vd_access = a->acl_access;
899 state->as_vd_access_count = 1;
900 ACL_INVALIDATE( state->as_vd_acl_mask );
903 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
904 Debug( LDAP_DEBUG_ACL,
905 "acl_get: valpat %s\n",
906 a->acl_attrval.bv_val, 0, 0 );
907 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
915 Debug( LDAP_DEBUG_ACL,
917 a->acl_attrval.bv_val, 0, 0 );
919 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
920 if (value_match( &match, desc,
921 /* desc->ad_type->sat_equality */ a->acl_attrval_mr, 0,
922 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
929 patlen = a->acl_attrval.bv_len;
930 vdnlen = val->bv_len;
932 if ( vdnlen < patlen )
935 if ( a->acl_attrval_style == ACL_STYLE_BASE ) {
936 if ( vdnlen > patlen )
939 } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) {
942 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
945 rdnlen = dn_rdnlen( NULL, val );
946 if ( rdnlen != vdnlen - patlen - 1 )
949 } else if ( a->acl_attrval_style == ACL_STYLE_SUBTREE ) {
950 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
953 } else if ( a->acl_attrval_style == ACL_STYLE_CHILDREN ) {
954 if ( vdnlen <= patlen )
957 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
961 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
967 if ( a->acl_filter != NULL ) {
968 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
969 if ( rc != LDAP_COMPARE_TRUE ) {
974 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
979 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
991 struct berval *opndn )
994 * if access applies to the entry itself, and the
995 * user is bound as somebody in the same namespace as
996 * the entry, OR the given dn matches the dn pattern
999 * NOTE: styles "anonymous", "users" and "self"
1000 * have been moved to enum slap_style_t, whose
1001 * value is set in a_dn_style; however, the string
1002 * is maintaned in a_dn_pat.
1004 if ( b->a_style == ACL_STYLE_ANONYMOUS ) {
1005 if ( !BER_BVISEMPTY( opndn ) ) {
1009 } else if ( b->a_style == ACL_STYLE_USERS ) {
1010 if ( BER_BVISEMPTY( opndn ) ) {
1014 } else if ( b->a_style == ACL_STYLE_SELF ) {
1015 struct berval ndn, selfndn;
1018 if ( BER_BVISEMPTY( opndn ) || BER_BVISNULL( &e->e_nname ) ) {
1022 level = b->a_self_level;
1030 selfndn = e->e_nname;
1033 for ( ; level > 0; level-- ) {
1034 if ( BER_BVISEMPTY( &ndn ) ) {
1037 dnParent( &ndn, &ndn );
1040 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
1045 } else if ( b->a_style == ACL_STYLE_REGEX ) {
1046 if ( !ber_bvccmp( &b->a_pat, '*' ) ) {
1048 regmatch_t tmp_matches[2],
1049 *tmp_matchesp = tmp_matches;
1053 switch ( a->acl_dn_style ) {
1054 case ACL_STYLE_REGEX:
1055 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1056 tmp_matchesp = matches;
1057 tmp_nmatch = nmatch;
1060 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1062 case ACL_STYLE_BASE:
1063 tmp_matches[0].rm_so = 0;
1064 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1069 case ACL_STYLE_SUBTREE:
1070 case ACL_STYLE_CHILDREN:
1071 tmp_matches[0].rm_so = 0;
1072 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1073 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1074 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1088 if ( !regex_matches( &b->a_pat, opndn->bv_val,
1089 e->e_ndn, tmp_nmatch, tmp_matchesp ) )
1097 ber_len_t patlen, odnlen;
1100 if ( e->e_dn == NULL )
1103 if ( b->a_expand ) {
1105 char buf[ACL_BUF_SIZE];
1108 regmatch_t tmp_matches[2],
1109 *tmp_matchesp = tmp_matches;
1113 bv.bv_len = sizeof( buf ) - 1;
1116 switch ( a->acl_dn_style ) {
1117 case ACL_STYLE_REGEX:
1118 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1119 tmp_matchesp = matches;
1120 tmp_nmatch = nmatch;
1123 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1125 case ACL_STYLE_BASE:
1126 tmp_matches[0].rm_so = 0;
1127 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1132 case ACL_STYLE_SUBTREE:
1133 case ACL_STYLE_CHILDREN:
1134 tmp_matches[0].rm_so = 0;
1135 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1136 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1137 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1151 if ( acl_string_expand( &bv, &b->a_pat,
1153 tmp_nmatch, tmp_matchesp ) )
1158 if ( dnNormalize(0, NULL, NULL, &bv,
1159 &pat, op->o_tmpmemctx )
1162 /* did not expand to a valid dn */
1170 patlen = pat.bv_len;
1171 odnlen = opndn->bv_len;
1172 if ( odnlen < patlen ) {
1173 goto dn_match_cleanup;
1177 if ( b->a_style == ACL_STYLE_BASE ) {
1178 /* base dn -- entire object DN must match */
1179 if ( odnlen != patlen ) {
1180 goto dn_match_cleanup;
1183 } else if ( b->a_style == ACL_STYLE_ONE ) {
1186 if ( odnlen <= patlen ) {
1187 goto dn_match_cleanup;
1190 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1191 goto dn_match_cleanup;
1194 rdnlen = dn_rdnlen( NULL, opndn );
1195 if ( rdnlen != odnlen - patlen - 1 ) {
1196 goto dn_match_cleanup;
1199 } else if ( b->a_style == ACL_STYLE_SUBTREE ) {
1200 if ( odnlen > patlen && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1201 goto dn_match_cleanup;
1204 } else if ( b->a_style == ACL_STYLE_CHILDREN ) {
1205 if ( odnlen <= patlen ) {
1206 goto dn_match_cleanup;
1209 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1210 goto dn_match_cleanup;
1213 } else if ( b->a_style == ACL_STYLE_LEVEL ) {
1217 if ( odnlen <= patlen ) {
1218 goto dn_match_cleanup;
1221 if ( level > 0 && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) )
1223 goto dn_match_cleanup;
1228 for ( ; level > 0; level-- ) {
1229 if ( BER_BVISEMPTY( &ndn ) ) {
1230 goto dn_match_cleanup;
1232 dnParent( &ndn, &ndn );
1233 if ( ndn.bv_len < patlen ) {
1234 goto dn_match_cleanup;
1238 if ( ndn.bv_len != patlen ) {
1239 goto dn_match_cleanup;
1243 got_match = !strcmp( pat.bv_val, &opndn->bv_val[ odnlen - patlen ] );
1246 if ( pat.bv_val != b->a_pat.bv_val ) {
1247 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
1259 * Record value-dependent access control state
1261 #define ACL_RECORD_VALUE_STATE do { \
1262 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
1263 state->as_recorded |= ACL_STATE_RECORDED_VD; \
1264 state->as_vd_acl = a; \
1265 AC_MEMCPY( state->as_vd_acl_matches, matches, \
1266 sizeof( state->as_vd_acl_matches )) ; \
1267 state->as_vd_acl_count = count; \
1268 state->as_vd_access = b; \
1269 state->as_vd_access_count = i; \
1281 regmatch_t *matches,
1283 AccessControlState *state,
1284 slap_dn_access *bdn,
1285 struct berval *opndn )
1291 const char *attr = bdn->a_at->ad_cname.bv_val;
1293 assert( attr != NULL );
1295 if ( BER_BVISEMPTY( opndn ) ) {
1299 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n", attr, 0, 0 );
1302 /* see if asker is listed in dnattr */
1303 for ( at = attrs_find( e->e_attrs, bdn->a_at );
1305 at = attrs_find( at->a_next, bdn->a_at ) )
1307 if ( value_find_ex( bdn->a_at,
1308 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1309 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1311 &bv, op->o_tmpmemctx ) == 0 )
1320 /* have a dnattr match. if this is a self clause then
1321 * the target must also match the op dn.
1323 if ( bdn->a_self ) {
1324 /* check if the target is an attribute. */
1325 if ( val == NULL ) return 1;
1327 /* target is attribute, check if the attribute value
1330 rc = value_match( &match, bdn->a_at,
1331 bdn->a_at->ad_type->sat_equality, 0,
1333 /* on match error or no match, fail the ACL clause */
1334 if ( rc != LDAP_SUCCESS || match != 0 )
1339 /* no dnattr match, check if this is a self clause */
1340 if ( ! bdn->a_self )
1343 ACL_RECORD_VALUE_STATE;
1345 /* this is a self clause, check if the target is an
1351 /* target is attribute, check if the attribute value
1354 rc = value_match( &match, bdn->a_at,
1355 bdn->a_at->ad_type->sat_equality, 0,
1358 /* on match error or no match, fail the ACL clause */
1359 if ( rc != LDAP_SUCCESS || match != 0 )
1368 * slap_acl_mask - modifies mask based upon the given acl and the
1369 * requested access to entry e, attribute attr, value val. if val
1370 * is null, access to the whole attribute is assumed (all values).
1372 * returns 0 access NOT allowed
1376 static slap_control_t
1382 AttributeDescription *desc,
1385 regmatch_t *matches,
1387 AccessControlState *state )
1392 char accessmaskbuf[ACCESSMASK_MAXLEN];
1393 #if !defined( SLAP_DYNACL ) && defined( SLAPD_ACI_ENABLED )
1394 char accessmaskbuf1[ACCESSMASK_MAXLEN];
1395 #endif /* !SLAP_DYNACL && SLAPD_ACI_ENABLED */
1398 slap_mask_t a2pmask = ACL_ACCESS2PRIV( *mask );
1400 assert( a != NULL );
1401 assert( mask != NULL );
1402 assert( desc != NULL );
1404 attr = desc->ad_cname.bv_val;
1406 assert( attr != NULL );
1408 Debug( LDAP_DEBUG_ACL,
1409 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
1412 Debug( LDAP_DEBUG_ACL,
1413 "=> acl_mask: to %s by \"%s\", (%s) \n",
1414 val ? "value" : "all values",
1415 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
1416 accessmask2str( *mask, accessmaskbuf, 1 ) );
1419 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
1420 && state->as_vd_acl == a )
1422 b = state->as_vd_access;
1423 i = state->as_vd_access_count;
1430 for ( ; b != NULL; b = b->a_next, i++ ) {
1431 slap_mask_t oldmask, modmask;
1433 ACL_INVALIDATE( modmask );
1435 /* AND <who> clauses */
1436 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
1437 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
1438 b->a_dn_pat.bv_val, 0, 0);
1440 * if access applies to the entry itself, and the
1441 * user is bound as somebody in the same namespace as
1442 * the entry, OR the given dn matches the dn pattern
1445 * NOTE: styles "anonymous", "users" and "self"
1446 * have been moved to enum slap_style_t, whose
1447 * value is set in a_dn_style; however, the string
1448 * is maintaned in a_dn_pat.
1451 if ( acl_mask_dn( op, e, a, nmatch, matches,
1452 &b->a_dn, &op->o_ndn ) )
1458 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
1461 Debug( LDAP_DEBUG_ACL, "<= check a_realdn_pat: %s\n",
1462 b->a_realdn_pat.bv_val, 0, 0);
1464 * if access applies to the entry itself, and the
1465 * user is bound as somebody in the same namespace as
1466 * the entry, OR the given dn matches the dn pattern
1469 * NOTE: styles "anonymous", "users" and "self"
1470 * have been moved to enum slap_style_t, whose
1471 * value is set in a_dn_style; however, the string
1472 * is maintaned in a_dn_pat.
1475 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1477 ndn = op->o_conn->c_ndn;
1482 if ( acl_mask_dn( op, e, a, nmatch, matches,
1483 &b->a_realdn, &ndn ) )
1489 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1490 if ( ! op->o_conn->c_listener ) {
1493 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
1494 b->a_sockurl_pat.bv_val, 0, 0 );
1496 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
1497 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
1498 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
1499 e->e_ndn, nmatch, matches ) )
1504 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
1506 char buf[ACL_BUF_SIZE];
1508 bv.bv_len = sizeof( buf ) - 1;
1510 if ( acl_string_expand( &bv, &b->a_sockurl_pat,
1511 e->e_ndn, nmatch, matches ) )
1516 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1522 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1530 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1531 if ( !op->o_conn->c_peer_domain.bv_val ) {
1534 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1535 b->a_domain_pat.bv_val, 0, 0 );
1536 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1537 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1538 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1539 e->e_ndn, nmatch, matches ) )
1544 char buf[ACL_BUF_SIZE];
1546 struct berval cmp = op->o_conn->c_peer_domain;
1547 struct berval pat = b->a_domain_pat;
1549 if ( b->a_domain_expand ) {
1552 bv.bv_len = sizeof(buf) - 1;
1555 if ( acl_string_expand(&bv, &b->a_domain_pat,
1556 e->e_ndn, nmatch, matches) )
1563 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1564 int offset = cmp.bv_len - pat.bv_len;
1569 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1573 /* trim the domain */
1574 cmp.bv_val = &cmp.bv_val[ offset ];
1575 cmp.bv_len -= offset;
1578 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1585 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1586 if ( !op->o_conn->c_peer_name.bv_val ) {
1589 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1590 b->a_peername_pat.bv_val, 0, 0 );
1591 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1592 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1593 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1594 e->e_ndn, nmatch, matches ) )
1600 /* try exact match */
1601 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1602 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1606 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1608 char buf[ACL_BUF_SIZE];
1610 bv.bv_len = sizeof( buf ) - 1;
1612 if ( acl_string_expand( &bv, &b->a_peername_pat,
1613 e->e_ndn, nmatch, matches ) )
1618 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1622 /* extract IP and try exact match */
1623 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1625 char buf[] = "255.255.255.255";
1628 int port_number = -1;
1630 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1631 aci_bv[ ACI_BV_IP_EQ ].bv_val,
1632 aci_bv[ ACI_BV_IP_EQ ].bv_len ) != 0 )
1635 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv[ ACI_BV_IP_EQ ].bv_len;
1636 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv[ ACI_BV_IP_EQ ].bv_len;
1638 port = strrchr( ip.bv_val, ':' );
1642 ip.bv_len = port - ip.bv_val;
1644 port_number = strtol( port, &next, 10 );
1645 if ( next[0] != '\0' )
1649 /* the port check can be anticipated here */
1650 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1653 /* address longer than expected? */
1654 if ( ip.bv_len >= sizeof(buf) )
1657 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1658 buf[ ip.bv_len ] = '\0';
1660 addr = inet_addr( buf );
1662 /* unable to convert? */
1663 if ( addr == (unsigned long)(-1) )
1666 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1669 #ifdef LDAP_PF_LOCAL
1670 /* extract path and try exact match */
1671 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1674 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1675 aci_bv[ ACI_BV_PATH_EQ ].bv_val,
1676 aci_bv[ ACI_BV_PATH_EQ ].bv_len ) != 0 )
1679 path.bv_val = op->o_conn->c_peer_name.bv_val
1680 + aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1681 path.bv_len = op->o_conn->c_peer_name.bv_len
1682 - aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1684 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1687 #endif /* LDAP_PF_LOCAL */
1689 /* exact match (very unlikely...) */
1690 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1697 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1698 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1701 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1702 b->a_sockname_pat.bv_val, 0, 0 );
1703 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1704 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1705 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1706 e->e_ndn, nmatch, matches ) )
1711 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1713 char buf[ACL_BUF_SIZE];
1715 bv.bv_len = sizeof( buf ) - 1;
1717 if ( acl_string_expand( &bv, &b->a_sockname_pat,
1718 e->e_ndn, nmatch, matches ) )
1723 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1728 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1735 if ( b->a_dn_at != NULL ) {
1736 if ( acl_mask_dnattr( op, e, val, a, b, i,
1737 matches, count, state,
1738 &b->a_dn, &op->o_ndn ) )
1744 if ( b->a_realdn_at != NULL ) {
1747 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1749 ndn = op->o_conn->c_ndn;
1754 if ( acl_mask_dnattr( op, e, val, a, b, i,
1755 matches, count, state,
1756 &b->a_realdn, &ndn ) )
1762 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1764 struct berval ndn = BER_BVNULL;
1767 if ( op->o_ndn.bv_len == 0 ) {
1771 Debug( LDAP_DEBUG_ACL, "<= check a_group_pat: %s\n",
1772 b->a_group_pat.bv_val, 0, 0 );
1774 /* b->a_group is an unexpanded entry name, expanded it should be an
1775 * entry with objectclass group* and we test to see if odn is one of
1776 * the values in the attribute group
1778 /* see if asker is listed in dnattr */
1779 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1780 char buf[ACL_BUF_SIZE];
1782 regmatch_t tmp_matches[2],
1783 *tmp_matchesp = tmp_matches;
1785 bv.bv_len = sizeof(buf) - 1;
1790 switch ( a->acl_dn_style ) {
1791 case ACL_STYLE_REGEX:
1792 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1793 tmp_matchesp = matches;
1794 tmp_nmatch = nmatch;
1798 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1799 case ACL_STYLE_BASE:
1800 tmp_matches[0].rm_so = 0;
1801 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1806 case ACL_STYLE_SUBTREE:
1807 case ACL_STYLE_CHILDREN:
1808 tmp_matches[0].rm_so = 0;
1809 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1810 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1811 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1825 if ( acl_string_expand( &bv, &b->a_group_pat,
1827 tmp_nmatch, tmp_matchesp ) )
1832 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1833 op->o_tmpmemctx ) != LDAP_SUCCESS )
1835 /* did not expand to a valid dn */
1842 bv = b->a_group_pat;
1845 rc = backend_group( op, e, &bv, &op->o_ndn,
1846 b->a_group_oc, b->a_group_at );
1849 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1857 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1859 char buf[ACL_BUF_SIZE];
1861 Debug( LDAP_DEBUG_ACL, "<= check a_set_pat: %s\n",
1862 b->a_set_pat.bv_val, 0, 0 );
1864 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1866 regmatch_t tmp_matches[2],
1867 *tmp_matchesp = tmp_matches;
1870 bv.bv_len = sizeof( buf ) - 1;
1875 switch ( a->acl_dn_style ) {
1876 case ACL_STYLE_REGEX:
1877 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1878 tmp_matchesp = matches;
1879 tmp_nmatch = nmatch;
1883 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1884 case ACL_STYLE_BASE:
1885 tmp_matches[0].rm_so = 0;
1886 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1891 case ACL_STYLE_SUBTREE:
1892 case ACL_STYLE_CHILDREN:
1893 tmp_matches[0].rm_so = 0;
1894 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1895 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1896 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1910 if ( acl_string_expand( &bv, &b->a_set_pat,
1912 tmp_nmatch, tmp_matchesp ) )
1921 if ( acl_match_set( &bv, op, e, 0 ) == 0 ) {
1926 if ( b->a_authz.sai_ssf ) {
1927 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1928 b->a_authz.sai_ssf, op->o_ssf, 0 );
1929 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1934 if ( b->a_authz.sai_transport_ssf ) {
1935 Debug( LDAP_DEBUG_ACL,
1936 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1937 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1938 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1943 if ( b->a_authz.sai_tls_ssf ) {
1944 Debug( LDAP_DEBUG_ACL,
1945 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1946 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1947 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1952 if ( b->a_authz.sai_sasl_ssf ) {
1953 Debug( LDAP_DEBUG_ACL,
1954 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1955 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1956 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1962 if ( b->a_dynacl ) {
1964 slap_access_t tgrant, tdeny;
1966 Debug( LDAP_DEBUG_ACL, "<= check a_dynacl\n",
1969 /* this case works different from the others above.
1970 * since aci's themselves give permissions, we need
1971 * to first check b->a_access_mask, the ACL's access level.
1973 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1974 /* no ACIs in the root DSE */
1978 /* first check if the right being requested
1979 * is allowed by the ACL clause.
1981 if ( ! ACL_PRIV_ISSET( b->a_access_mask, a2pmask ) ) {
1985 /* start out with nothing granted, nothing denied */
1989 for ( da = b->a_dynacl; da; da = da->da_next ) {
1990 slap_access_t grant,
1996 Debug( LDAP_DEBUG_ACL, " <= check a_dynacl: %s\n",
1997 da->da_name, 0, 0 );
1999 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
2005 /* remove anything that the ACL clause does not allow */
2006 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2007 tdeny &= ACL_PRIV_MASK;
2009 /* see if we have anything to contribute */
2010 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2014 /* this could be improved by changing slap_acl_mask so that it can deal with
2015 * by clauses that return grant/deny pairs. Right now, it does either
2016 * additive or subtractive rights, but not both at the same time. So,
2017 * we need to combine the grant/deny pair into a single rights mask in
2018 * a smart way: if either grant or deny is "empty", then we use the
2019 * opposite as is, otherwise we remove any denied rights from the grant
2020 * rights mask and construct an additive mask.
2022 if (ACL_IS_INVALID(tdeny)) {
2023 modmask = tgrant | ACL_PRIV_ADDITIVE;
2025 } else if (ACL_IS_INVALID(tgrant)) {
2026 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2029 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2033 #else /* !SLAP_DYNACL */
2035 #ifdef SLAPD_ACI_ENABLED
2036 if ( b->a_aci_at != NULL ) {
2038 slap_access_t grant, deny, tgrant, tdeny;
2039 struct berval parent_ndn;
2040 BerVarray bvals = NULL;
2043 Debug( LDAP_DEBUG_ACL, " <= check a_aci_at: %s\n",
2044 b->a_aci_at->ad_cname.bv_val, 0, 0 );
2046 /* this case works different from the others above.
2047 * since aci's themselves give permissions, we need
2048 * to first check b->a_access_mask, the ACL's access level.
2051 if ( BER_BVISEMPTY( &e->e_nname ) ) {
2052 /* no ACIs in the root DSE */
2056 /* first check if the right being requested
2057 * is allowed by the ACL clause.
2059 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
2062 /* start out with nothing granted, nothing denied */
2066 /* get the aci attribute */
2067 at = attr_find( e->e_attrs, b->a_aci_at );
2070 /* FIXME: this breaks acl caching;
2071 * see also ACL_RECORD_VALUE_STATE below */
2072 ACL_RECORD_VALUE_STATE;
2074 /* the aci is an multi-valued attribute. The
2075 * rights are determined by OR'ing the individual
2076 * rights given by the acis.
2078 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2083 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0 )
2089 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2090 accessmask2str(tgrant, accessmaskbuf, 1),
2091 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2094 /* If the entry level aci didn't contain anything valid for the
2095 * current operation, climb up the tree and evaluate the
2096 * acis with scope set to subtree
2098 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
2099 dnParent( &e->e_nname, &parent_ndn );
2100 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
2101 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
2102 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
2110 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++ ) {
2112 /* FIXME: this breaks acl caching;
2113 * see also ACL_RECORD_VALUE_STATE above */
2114 ACL_RECORD_VALUE_STATE;
2116 if ( aci_mask( op, e, desc, val, &bvals[i],
2118 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2122 /* evaluation stops as soon as either a "deny" or a
2123 * "grant" directive matches.
2125 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
2129 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2130 accessmask2str(tgrant, accessmaskbuf, 1),
2131 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2135 case LDAP_NO_SUCH_ATTRIBUTE:
2136 /* just go on if the aci-Attribute is not present in
2139 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
2143 case LDAP_NO_SUCH_OBJECT:
2144 /* We have reached the base object */
2145 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
2156 dnParent( &parent_ndn, &parent_ndn );
2161 /* remove anything that the ACL clause does not allow */
2162 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2163 tdeny &= ACL_PRIV_MASK;
2165 /* see if we have anything to contribute */
2166 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2170 /* this could be improved by changing slap_acl_mask so that it can deal with
2171 * by clauses that return grant/deny pairs. Right now, it does either
2172 * additive or subtractive rights, but not both at the same time. So,
2173 * we need to combine the grant/deny pair into a single rights mask in
2174 * a smart way: if either grant or deny is "empty", then we use the
2175 * opposite as is, otherwise we remove any denied rights from the grant
2176 * rights mask and construct an additive mask.
2178 if (ACL_IS_INVALID(tdeny)) {
2179 modmask = tgrant | ACL_PRIV_ADDITIVE;
2181 } else if (ACL_IS_INVALID(tgrant)) {
2182 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2185 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2189 #endif /* SLAPD_ACI_ENABLED */
2190 #endif /* !SLAP_DYNACL */
2192 modmask = b->a_access_mask;
2195 Debug( LDAP_DEBUG_ACL,
2196 "<= acl_mask: [%d] applying %s (%s)\n",
2197 i, accessmask2str( modmask, accessmaskbuf, 1 ),
2198 b->a_type == ACL_CONTINUE
2200 : b->a_type == ACL_BREAK
2206 if( ACL_IS_ADDITIVE(modmask) ) {
2208 ACL_PRIV_SET( *mask, modmask );
2211 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2213 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
2214 /* substract privs */
2215 ACL_PRIV_CLR( *mask, modmask );
2218 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2227 Debug( LDAP_DEBUG_ACL,
2228 "<= acl_mask: [%d] mask: %s\n",
2229 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
2231 if( b->a_type == ACL_CONTINUE ) {
2234 } else if ( b->a_type == ACL_BREAK ) {
2242 /* implicit "by * none" clause */
2245 Debug( LDAP_DEBUG_ACL,
2246 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
2247 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
2252 * acl_check_modlist - check access control on the given entry to see if
2253 * it allows the given modifications by the user associated with op.
2254 * returns 1 if mods allowed ok
2255 * 0 mods not allowed
2262 Modifications *mlist )
2265 AccessControlState state = ACL_STATE_INIT;
2268 int ret = 1; /* default is access allowed */
2272 be = LDAP_STAILQ_FIRST(&backendDB);
2276 assert( be != NULL );
2278 /* short circuit root database access */
2279 if ( be_isroot( op ) ) {
2280 Debug( LDAP_DEBUG_ACL,
2281 "<= acl_access_allowed: granted to database root\n",
2286 /* use backend default access if no backend acls */
2287 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
2288 Debug( LDAP_DEBUG_ACL,
2289 "=> access_allowed: backend default %s access %s to \"%s\"\n",
2290 access2str( ACL_WRITE ),
2291 op->o_bd->be_dfltaccess >= ACL_WRITE
2292 ? "granted" : "denied",
2294 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
2298 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
2300 * Internal mods are ignored by ACL_WRITE checking
2302 if ( mlist->sml_flags & SLAP_MOD_INTERNAL ) {
2303 Debug( LDAP_DEBUG_ACL, "acl: internal mod %s:"
2304 " modify access granted\n",
2305 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2310 * no-user-modification operational attributes are ignored
2311 * by ACL_WRITE checking as any found here are not provided
2314 if ( is_at_no_user_mod( mlist->sml_desc->ad_type )
2315 && ! ( mlist->sml_flags & SLAP_MOD_MANAGING ) )
2317 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
2318 " modify access granted\n",
2319 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2323 switch ( mlist->sml_op ) {
2324 case LDAP_MOD_REPLACE:
2326 * We must check both permission to delete the whole
2327 * attribute and permission to add the specific attributes.
2328 * This prevents abuse from selfwriters.
2330 if ( ! access_allowed( op, e,
2331 mlist->sml_desc, NULL,
2332 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2339 if ( mlist->sml_values == NULL ) break;
2341 /* fall thru to check value to add */
2344 assert( mlist->sml_values != NULL );
2346 for ( bv = mlist->sml_nvalues
2347 ? mlist->sml_nvalues : mlist->sml_values;
2348 bv->bv_val != NULL; bv++ )
2350 if ( ! access_allowed( op, e,
2351 mlist->sml_desc, bv,
2352 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WADD,
2361 case LDAP_MOD_DELETE:
2362 if ( mlist->sml_values == NULL ) {
2363 if ( ! access_allowed( op, e,
2364 mlist->sml_desc, NULL,
2365 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2373 for ( bv = mlist->sml_nvalues
2374 ? mlist->sml_nvalues : mlist->sml_values;
2375 bv->bv_val != NULL; bv++ )
2377 if ( ! access_allowed( op, e,
2378 mlist->sml_desc, bv,
2379 ( mlist->sml_flags & SLAP_MOD_MANAGING ) ? ACL_MANAGE : ACL_WDEL,
2388 case SLAP_MOD_SOFTADD:
2389 /* allow adding attribute via modrdn thru */
2401 if (be_null) op->o_bd = NULL;
2407 struct berval *list,
2420 while ( len >= 0 && --ix >= 0 ) {
2421 while ( --len >= 0 && *p++ != sep )
2424 while ( len >= 0 && *p == ' ' ) {
2437 while ( --len >= 0 && *p != sep ) {
2441 while ( bv->bv_len > 0 && *--p == ' ' ) {
2448 typedef struct acl_set_gather_t {
2454 acl_set_cb_gather( Operation *op, SlapReply *rs )
2456 acl_set_gather_t *p = (acl_set_gather_t *)op->o_callback->sc_private;
2458 if ( rs->sr_type == REP_SEARCH ) {
2459 BerValue bvals[ 2 ];
2460 BerVarray bvalsp = NULL;
2463 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
2464 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
2466 if ( desc == slap_schema.si_ad_entryDN ) {
2468 bvals[ 0 ] = rs->sr_entry->e_nname;
2469 BER_BVZERO( &bvals[ 1 ] );
2474 a = attr_find( rs->sr_entry->e_attrs, desc );
2478 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
2481 bvalsp = a->a_nvals;
2487 p->bvals = slap_set_join( p->cookie, p->bvals,
2488 ( '|' | SLAP_SET_RREF ), bvalsp );
2492 assert( rs->sr_type == REP_RESULT );
2499 acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2501 AclSetCookie *cp = (AclSetCookie *)cookie;
2503 LDAPURLDesc *ludp = NULL;
2504 Operation op2 = { 0 };
2505 SlapReply rs = {REP_RESULT};
2506 AttributeName anlist[ 2 ], *anlistp = NULL;
2508 slap_callback cb = { NULL, acl_set_cb_gather, NULL, NULL };
2509 acl_set_gather_t p = { 0 };
2510 const char *text = NULL;
2511 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2513 /* this routine needs to return the bervals instead of
2514 * plain strings, since syntax is not known. It should
2515 * also return the syntax or some "comparison cookie".
2517 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2518 return acl_set_gather2( cookie, name, desc );
2521 rc = ldap_url_parse( name->bv_val, &ludp );
2522 if ( rc != LDAP_URL_SUCCESS ) {
2523 rc = LDAP_PROTOCOL_ERROR;
2527 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2529 /* host part must be empty */
2530 /* extensions parts must be empty */
2531 rc = LDAP_PROTOCOL_ERROR;
2535 /* Grab the searchbase and see if an appropriate database can be found */
2536 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2537 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2538 &op2.o_req_ndn, cp->op->o_tmpmemctx );
2539 BER_BVZERO( &op2.o_req_dn );
2540 if ( rc != LDAP_SUCCESS ) {
2544 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2545 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2546 rc = LDAP_NO_SUCH_OBJECT;
2550 /* Grab the filter */
2551 if ( ludp->lud_filter ) {
2552 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2553 cp->op->o_tmpmemctx );
2556 op2.ors_filterstr = defaultFilter_bv;
2559 op2.ors_filter = str2filter_x( cp->op, op2.ors_filterstr.bv_val );
2560 if ( op2.ors_filter == NULL ) {
2561 rc = LDAP_PROTOCOL_ERROR;
2565 /* Grab the scope */
2566 op2.ors_scope = ludp->lud_scope;
2568 /* Grap the attributes */
2569 if ( ludp->lud_attrs ) {
2570 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2573 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2574 cp->op->o_tmpmemctx );
2576 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2577 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2578 anlistp[ nattrs ].an_desc = NULL;
2579 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2580 &anlistp[ nattrs ].an_desc, &text );
2581 if ( rc != LDAP_SUCCESS ) {
2590 anlistp[ nattrs ].an_name = desc->ad_cname;
2591 anlistp[ nattrs ].an_desc = desc;
2593 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2597 op2.o_hdr = cp->op->o_hdr;
2598 op2.o_tag = LDAP_REQ_SEARCH;
2599 op2.o_ndn = op2.o_bd->be_rootndn;
2600 op2.o_callback = &cb;
2601 op2.o_time = slap_get_time();
2602 op2.o_do_not_cache = 1;
2603 op2.o_is_auth_check = 0;
2604 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->op->o_tmpmemctx );
2605 op2.ors_slimit = SLAP_NO_LIMIT;
2606 op2.ors_tlimit = SLAP_NO_LIMIT;
2607 op2.ors_attrs = anlistp;
2608 op2.ors_attrsonly = 0;
2609 op2.o_private = cp->op->o_private;
2613 rc = op2.o_bd->be_search( &op2, &rs );
2619 if ( op2.ors_filter ) {
2620 filter_free_x( cp->op, op2.ors_filter );
2622 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2623 slap_sl_free( op2.o_req_ndn.bv_val, cp->op->o_tmpmemctx );
2625 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2626 slap_sl_free( op2.o_req_dn.bv_val, cp->op->o_tmpmemctx );
2629 ldap_free_urldesc( ludp );
2631 if ( anlistp && anlistp != anlist ) {
2632 slap_sl_free( anlistp, cp->op->o_tmpmemctx );
2639 acl_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2641 AclSetCookie *cp = (AclSetCookie *)cookie;
2642 BerVarray bvals = NULL;
2646 /* this routine needs to return the bervals instead of
2647 * plain strings, since syntax is not known. It should
2648 * also return the syntax or some "comparison cookie".
2650 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
2651 if ( rc == LDAP_SUCCESS ) {
2652 if ( desc == slap_schema.si_ad_entryDN ) {
2653 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2654 cp->op->o_tmpmemctx );
2656 BER_BVZERO( &bvals[ 1 ] );
2660 backend_attribute( cp->op,
2661 cp->e, &ndn, desc, &bvals, ACL_NONE );
2664 if ( !BER_BVISNULL( &ndn ) ) {
2665 slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
2674 struct berval *subj,
2679 struct berval set = BER_BVNULL;
2681 AclSetCookie cookie;
2683 if ( setref == 0 ) {
2684 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2687 struct berval subjdn, ndn = BER_BVNULL;
2688 struct berval setat;
2691 AttributeDescription *desc = NULL;
2693 /* format of string is "entry/setAttrName" */
2694 if ( acl_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2698 if ( acl_get_part( subj, 1, '/', &setat ) < 0 ) {
2699 setat = aci_bv[ ACI_BV_SET_ATTR ];
2703 * NOTE: dnNormalize honors the ber_len field
2704 * as the length of the dn to be normalized
2706 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2707 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2709 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2710 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2714 BER_BVZERO( &bvals[0] );
2715 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2717 bvals[0].bv_val = bvals[i-1].bv_val;
2718 BER_BVZERO( &bvals[i-1] );
2720 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2721 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2726 if ( !BER_BVISNULL( &set ) ) {
2729 rc = ( slap_set_filter( acl_set_gather, (SetCookie *)&cookie, &set,
2730 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2731 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2740 * dynamic ACL infrastructure
2742 static slap_dynacl_t *da_list = NULL;
2745 slap_dynacl_register( slap_dynacl_t *da )
2749 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2750 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2755 if ( tmp != NULL ) {
2759 if ( da->da_mask == NULL ) {
2763 da->da_private = NULL;
2764 da->da_next = da_list;
2770 static slap_dynacl_t *
2771 slap_dynacl_next( slap_dynacl_t *da )
2780 slap_dynacl_get( const char *name )
2784 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2785 if ( strcasecmp( da->da_name, name ) == 0 ) {
2792 #endif /* SLAP_DYNACL */
2800 #ifdef SLAPD_ACI_ENABLED
2801 rc = dynacl_aci_init();
2805 #endif /* SLAPD_ACI_ENABLED */
2807 #endif /* SLAP_DYNACL */
2818 regmatch_t *matches)
2826 bv->bv_val[0] = '\0';
2827 bv->bv_len--; /* leave space for lone $ */
2830 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2831 sp < pat->bv_val + pat->bv_len ; sp++ )
2833 /* did we previously see a $ */
2835 if ( flag == 1 && *sp == '$' ) {
2840 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2843 } else if ( *sp >= '0' && *sp <= '9' ) {
2851 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2852 if ( *sp >= '0' && *sp <= '9' ) {
2853 n = 10*n + ( *sp - '0' );
2857 if ( *sp != /*'{'*/ '}' ) {
2863 if ( n >= nmatch ) {
2869 i = matches[n].rm_so;
2870 l = matches[n].rm_eo;
2871 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2889 /* must have ended with a single $ */
2897 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2898 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2905 struct berval *pat, /* pattern to expand and match against */
2906 char *str, /* string to match against pattern */
2907 char *buf, /* buffer with $N expansion variables */
2908 int nmatch, /* size of the matches array */
2909 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2913 char newbuf[ACL_BUF_SIZE];
2917 bv.bv_len = sizeof( newbuf ) - 1;
2924 acl_string_expand( &bv, pat, buf, nmatch, matches );
2925 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2927 char error[ACL_BUF_SIZE];
2928 regerror( rc, &re, error, sizeof( error ) );
2930 Debug( LDAP_DEBUG_TRACE,
2931 "compile( \"%s\", \"%s\") failed %s\n",
2932 pat->bv_val, str, error );
2936 rc = regexec( &re, str, 0, NULL, 0 );
2939 Debug( LDAP_DEBUG_TRACE,
2940 "=> regex_matches: string: %s\n", str, 0, 0 );
2941 Debug( LDAP_DEBUG_TRACE,
2942 "=> regex_matches: rc: %d %s\n",
2943 rc, !rc ? "matches" : "no matches", 0 );