1 /* acl.c - routines to parse and check acl's */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
20 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
26 aci_bv_entry = BER_BVC("entry"),
27 aci_bv_br_entry = BER_BVC("[entry]"),
28 aci_bv_br_all = BER_BVC("[all]"),
29 aci_bv_access_id = BER_BVC("access-id"),
30 aci_bv_anonymous = BER_BVC("anonymous"),
31 aci_bv_public = BER_BVC("public"),
32 aci_bv_users = BER_BVC("users"),
33 aci_bv_self = BER_BVC("self"),
34 aci_bv_dnattr = BER_BVC("dnattr"),
35 aci_bv_group = BER_BVC("group"),
36 aci_bv_role = BER_BVC("role"),
37 aci_bv_set = BER_BVC("set"),
38 aci_bv_set_ref = BER_BVC("set-ref"),
39 aci_bv_grant = BER_BVC("grant"),
40 aci_bv_deny = BER_BVC("deny"),
42 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
43 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
44 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
45 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR);
48 static AccessControl * acl_get(
49 AccessControl *ac, int *count,
50 Operation *op, Entry *e,
51 AttributeDescription *desc,
52 int nmatches, regmatch_t *matches );
54 static slap_control_t acl_mask(
55 AccessControl *ac, slap_mask_t *mask,
56 Operation *op, Entry *e,
57 AttributeDescription *desc,
61 AccessControlState *state );
63 #ifdef SLAPD_ACI_ENABLED
65 Operation *op, Entry *e,
66 AttributeDescription *desc,
71 slap_access_t *deny );
74 static int regex_matches(
75 struct berval *pat, char *str, char *buf, regmatch_t *matches);
76 static void string_expand(
77 struct berval *newbuf, struct berval *pattern,
78 char *match, regmatch_t *matches);
80 typedef struct AciSetCookie {
85 SLAP_SET_GATHER aci_set_gather;
86 static int aci_match_set ( struct berval *subj, Operation *op,
87 Entry *e, int setref );
90 * access_allowed - check whether op->o_ndn is allowed the requested access
91 * to entry e, attribute attr, value val. if val is null, access to
92 * the whole attribute is assumed (all values).
94 * This routine loops through all access controls and calls
95 * acl_mask() on each applicable access control.
96 * The loop exits when a definitive answer is reached or
97 * or no more controls remain.
108 AttributeDescription *desc,
110 slap_access_t access,
111 AccessControlState *state )
115 AccessControl *a = NULL;
120 char accessmaskbuf[ACCESSMASK_MAXLEN];
123 slap_control_t control;
125 regmatch_t matches[MAXREMATCHES];
126 int st_same_attr = 0;
127 int st_initialized = 0;
128 static AccessControlState state_init = ACL_STATE_INIT;
131 assert( desc != NULL );
132 assert( access > ACL_NONE );
134 attr = desc->ad_cname.bv_val;
136 assert( attr != NULL );
138 if( op && op->o_is_auth_check && (access == ACL_SEARCH || access == ACL_READ)) {
141 if( state && state->as_recorded && state->as_vd_ad==desc) {
142 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
145 return state->as_result;
147 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
148 val != NULL && state->as_vd_acl == NULL )
150 return state->as_result;
154 state->as_vd_ad=desc;
158 LDAP_LOG( ACL, ENTRY,
159 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
160 access2str( access ), e->e_dn, attr );
162 Debug( LDAP_DEBUG_ACL,
163 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
164 access2str( access ), e->e_dn, attr );
178 assert( be != NULL );
180 /* grant database root access */
181 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
184 "access_allowed: conn %lu root access granted\n",
185 op->o_connid, 0, 0 );
187 Debug( LDAP_DEBUG_ACL,
188 "<= root access granted\n",
195 * no-user-modification operational attributes are ignored
196 * by ACL_WRITE checking as any found here are not provided
199 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
200 && desc != slap_schema.si_ad_entry
201 && desc != slap_schema.si_ad_children )
204 LDAP_LOG( ACL, DETAIL1,
205 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
206 "access granted\n", op->o_connid, attr , 0 );
208 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
209 " %s access granted\n",
215 /* use backend default access if no backend acls */
216 if( be != NULL && be->be_acl == NULL ) {
218 LDAP_LOG( ACL, DETAIL1,
219 "access_allowed: backend default %s access %s to \"%s\"\n",
220 access2str( access ),
221 be->be_dfltaccess >= access ? "granted" : "denied",
224 Debug( LDAP_DEBUG_ACL,
225 "=> access_allowed: backend default %s access %s to \"%s\"\n",
226 access2str( access ),
227 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
229 ret = be->be_dfltaccess >= access;
233 /* be is always non-NULL */
234 /* use global default access if no global acls */
235 } else if ( be == NULL && global_acl == NULL ) {
237 LDAP_LOG( ACL, DETAIL1,
238 "access_allowed: global default %s access %s to \"%s\"\n",
239 access2str( access ),
240 global_default_access >= access ? "granted" : "denied",
243 Debug( LDAP_DEBUG_ACL,
244 "=> access_allowed: global default %s access %s to \"%s\"\n",
245 access2str( access ),
246 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
248 ret = global_default_access >= access;
257 assert( state->as_vd_acl != NULL );
259 a = state->as_vd_acl;
260 mask = state->as_vd_acl_mask;
261 count = state->as_vd_acl_count;
262 AC_MEMCPY( matches, state->as_vd_acl_matches,
270 memset(matches, '\0', sizeof(matches));
273 while((a = acl_get( a, &count, op, e, desc,
274 MAXREMATCHES, matches )) != NULL)
278 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
280 LDAP_LOG( ACL, DETAIL1,
281 "access_allowed: match[%d]: %d %d ",
282 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
284 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
285 (int)matches[i].rm_so, (int)matches[i].rm_eo );
287 if( matches[i].rm_so <= matches[0].rm_eo ) {
289 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
290 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
294 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
296 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
301 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
302 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
303 return state->as_result;
304 } else if (!st_initialized) {
305 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
307 state->as_vd_ad=desc;
313 control = acl_mask( a, &mask, op,
314 e, desc, val, matches, count, state );
316 if ( control != ACL_BREAK ) {
320 memset(matches, '\0', sizeof(matches));
323 if ( ACL_IS_INVALID( mask ) ) {
325 LDAP_LOG( ACL, DETAIL1,
326 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
327 op->o_connid, e->e_dn, attr );
329 Debug( LDAP_DEBUG_ACL,
330 "=> access_allowed: \"%s\" (%s) invalid!\n",
335 } else if ( control == ACL_BREAK ) {
337 LDAP_LOG( ACL, DETAIL1,
338 "access_allowed: conn %lu no more rules\n", op->o_connid, 0,0 );
340 Debug( LDAP_DEBUG_ACL,
341 "=> access_allowed: no more rules\n", 0, 0, 0);
348 LDAP_LOG( ACL, ENTRY,
349 "access_allowed: %s access %s by %s\n",
350 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
351 accessmask2str( mask, accessmaskbuf ) );
353 Debug( LDAP_DEBUG_ACL,
354 "=> access_allowed: %s access %s by %s\n",
355 access2str( access ),
356 ACL_GRANT(mask, access) ? "granted" : "denied",
357 accessmask2str( mask, accessmaskbuf ) );
360 ret = ACL_GRANT(mask, access);
363 if( state != NULL ) {
364 /* If not value-dependent, save ACL in case of more attrs */
365 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) )
366 state->as_vi_acl = a;
367 state->as_recorded |= ACL_STATE_RECORDED;
368 state->as_result = ret;
370 if (be_null) op->o_bd = NULL;
375 * acl_get - return the acl applicable to entry e, attribute
376 * attr. the acl returned is suitable for use in subsequent calls to
377 * acl_access_allowed().
380 static AccessControl *
386 AttributeDescription *desc,
388 regmatch_t *matches )
394 assert( count != NULL );
395 assert( desc != NULL );
397 attr = desc->ad_cname.bv_val;
399 assert( attr != NULL );
402 if( op->o_bd == NULL ) {
405 a = op->o_bd->be_acl;
414 dnlen = e->e_nname.bv_len;
416 for ( ; a != NULL; a = a->acl_next ) {
419 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
420 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
422 LDAP_LOG( ACL, DETAIL1,
423 "acl_get: dnpat [%d] %s nsub: %d\n",
424 *count, a->acl_dn_pat.bv_val,
425 (int) a->acl_dn_re.re_nsub );
427 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
428 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
430 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
435 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
436 *count, a->acl_dn_pat.bv_val, 0 );
438 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
439 *count, a->acl_dn_pat.bv_val, 0 );
441 patlen = a->acl_dn_pat.bv_len;
442 if ( dnlen < patlen )
445 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
446 /* base dn -- entire object DN must match */
447 if ( dnlen != patlen )
450 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
453 if ( dnlen <= patlen )
456 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
459 rdnlen = dn_rdnlen( NULL, &e->e_nname );
460 if ( rdnlen != dnlen - patlen - 1 )
463 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
464 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
467 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
468 if ( dnlen <= patlen )
470 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
474 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
479 LDAP_LOG( ACL, DETAIL1,
480 "acl_get: [%d] matched\n", *count, 0, 0 );
482 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
487 if ( a->acl_filter != NULL ) {
488 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
489 if ( rc != LDAP_COMPARE_TRUE ) {
495 LDAP_LOG( ACL, DETAIL1,
496 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
498 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
501 if ( attr == NULL || a->acl_attrs == NULL ||
502 ad_inlist( desc, a->acl_attrs ) )
505 LDAP_LOG( ACL, DETAIL1,
506 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
508 Debug( LDAP_DEBUG_ACL,
509 "<= acl_get: [%d] acl %s attr: %s\n",
510 *count, e->e_dn, attr );
514 matches[0].rm_so = matches[0].rm_eo = -1;
518 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
520 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
526 * Record value-dependent access control state
528 #define ACL_RECORD_VALUE_STATE do { \
529 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
530 state->as_recorded |= ACL_STATE_RECORDED_VD; \
531 state->as_vd_acl = a; \
532 AC_MEMCPY( state->as_vd_acl_matches, matches, \
533 sizeof( state->as_vd_acl_matches )) ; \
534 state->as_vd_acl_count = count; \
535 state->as_vd_access = b; \
536 state->as_vd_access_count = i; \
541 * acl_mask - modifies mask based upon the given acl and the
542 * requested access to entry e, attribute attr, value val. if val
543 * is null, access to the whole attribute is assumed (all values).
545 * returns 0 access NOT allowed
549 static slap_control_t
555 AttributeDescription *desc,
559 AccessControlState *state )
561 int i, odnlen, patlen;
564 char accessmaskbuf[ACCESSMASK_MAXLEN];
569 assert( mask != NULL );
570 assert( desc != NULL );
572 attr = desc->ad_cname.bv_val;
574 assert( attr != NULL );
577 LDAP_LOG( ACL, ENTRY,
578 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
579 op->o_connid, e->e_dn, attr );
582 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
583 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
584 accessmask2str( *mask, accessmaskbuf ) );
586 Debug( LDAP_DEBUG_ACL,
587 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
590 Debug( LDAP_DEBUG_ACL,
591 "=> acl_mask: to %s by \"%s\", (%s) \n",
592 val ? "value" : "all values",
593 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
594 accessmask2str( *mask, accessmaskbuf ) );
597 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
598 && state->as_vd_acl == a )
600 b = state->as_vd_access;
601 i = state->as_vd_access_count;
608 for ( ; b != NULL; b = b->a_next, i++ ) {
609 slap_mask_t oldmask, modmask;
611 ACL_INVALIDATE( modmask );
613 /* AND <who> clauses */
614 if ( b->a_dn_pat.bv_len != 0 ) {
616 LDAP_LOG( ACL, DETAIL1,
617 "acl_mask: conn %lu check a_dn_pat: %s\n",
618 op->o_connid, b->a_dn_pat.bv_val ,0 );
620 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
621 b->a_dn_pat.bv_val, 0, 0);
624 * if access applies to the entry itself, and the
625 * user is bound as somebody in the same namespace as
626 * the entry, OR the given dn matches the dn pattern
628 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
629 if ( op->o_ndn.bv_len != 0 ) {
633 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
634 if ( op->o_ndn.bv_len == 0 ) {
638 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
639 if ( op->o_ndn.bv_len == 0 ) {
643 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
647 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
648 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
649 int ret = regex_matches( &b->a_dn_pat,
650 op->o_ndn.bv_val, e->e_ndn, matches );
661 if ( e->e_dn == NULL )
664 if ( b->a_dn_expand ) {
666 char buf[ACL_BUF_SIZE];
668 bv.bv_len = sizeof( buf ) - 1;
671 string_expand(&bv, &b->a_dn_pat,
673 if ( dnNormalize2(NULL, &bv, &pat) != LDAP_SUCCESS ) {
674 /* did not expand to a valid dn */
682 odnlen = op->o_ndn.bv_len;
683 if ( odnlen < patlen ) {
684 goto dn_match_cleanup;
688 if ( b->a_dn_style == ACL_STYLE_BASE ) {
689 /* base dn -- entire object DN must match */
690 if ( odnlen != patlen ) {
691 goto dn_match_cleanup;
694 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
697 if ( odnlen <= patlen ) {
698 goto dn_match_cleanup;
701 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
702 goto dn_match_cleanup;
705 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
706 if ( rdnlen != odnlen - patlen - 1 ) {
707 goto dn_match_cleanup;
710 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
711 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
712 goto dn_match_cleanup;
715 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
716 if ( odnlen <= patlen ) {
717 goto dn_match_cleanup;
720 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
721 goto dn_match_cleanup;
725 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
728 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
738 if ( b->a_sockurl_pat.bv_len ) {
739 if ( ! op->o_conn->c_listener ) {
743 LDAP_LOG( ACL, DETAIL1,
744 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
745 op->o_connid, b->a_sockurl_pat.bv_val , 0 );
747 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
748 b->a_sockurl_pat.bv_val, 0, 0 );
751 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
752 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
753 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
754 e->e_ndn, matches ) )
759 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
765 if ( b->a_domain_pat.bv_len ) {
766 if ( !op->o_conn->c_peer_domain.bv_val ) {
770 LDAP_LOG( ACL, DETAIL1,
771 "acl_mask: conn %lu check a_domain_pat: %s\n",
772 op->o_connid, b->a_domain_pat.bv_val , 0 );
774 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
775 b->a_domain_pat.bv_val, 0, 0 );
777 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
778 if ( b->a_domain_style == ACL_STYLE_REGEX) {
779 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
780 e->e_ndn, matches ) )
785 char buf[ACL_BUF_SIZE];
787 struct berval cmp = op->o_conn->c_peer_domain;
788 struct berval pat = b->a_domain_pat;
790 if ( b->a_domain_expand ) {
793 bv.bv_len = sizeof(buf) - 1;
796 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
800 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
801 int offset = cmp.bv_len - pat.bv_len;
806 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
810 /* trim the domain */
811 cmp.bv_val = &cmp.bv_val[ offset ];
812 cmp.bv_len -= offset;
815 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
822 if ( b->a_peername_pat.bv_len ) {
823 if ( !op->o_conn->c_peer_name.bv_val ) {
827 LDAP_LOG( ACL, DETAIL1,
828 "acl_mask: conn %lu check a_peername_path: %s\n",
829 op->o_connid, b->a_peername_pat.bv_val , 0 );
831 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
832 b->a_peername_pat.bv_val, 0, 0 );
834 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
835 if ( b->a_peername_style == ACL_STYLE_REGEX) {
836 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
837 e->e_ndn, matches ) )
842 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 )
848 if ( b->a_sockname_pat.bv_len ) {
849 if ( !op->o_conn->c_sock_name.bv_val ) {
853 LDAP_LOG( ACL, DETAIL1,
854 "acl_mask: conn %lu check a_sockname_path: %s\n",
855 op->o_connid, b->a_sockname_pat.bv_val , 0 );
857 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
858 b->a_sockname_pat.bv_val, 0, 0 );
860 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
861 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
862 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
863 e->e_ndn, matches ) )
868 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 )
874 if ( b->a_dn_at != NULL ) {
879 const char *attr = b->a_dn_at->ad_cname.bv_val;
881 assert( attr != NULL );
883 if ( op->o_ndn.bv_len == 0 ) {
888 LDAP_LOG( ACL, DETAIL1,
889 "acl_mask: conn %lu check a_dn_pat: %s\n",
890 op->o_connid, attr , 0 );
892 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
897 /* see if asker is listed in dnattr */
898 for( at = attrs_find( e->e_attrs, b->a_dn_at );
900 at = attrs_find( at->a_next, b->a_dn_at ) )
902 if( value_find_ex( b->a_dn_at,
904 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
905 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
908 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
920 /* have a dnattr match. if this is a self clause then
921 * the target must also match the op dn.
923 if ( b->a_dn_self ) {
924 /* check if the target is an attribute. */
925 if ( val == NULL ) continue;
927 /* target is attribute, check if the attribute value
930 rc = value_match( &match, b->a_dn_at,
931 b->a_dn_at->ad_type->sat_equality, 0,
933 /* on match error or no match, fail the ACL clause */
934 if (rc != LDAP_SUCCESS || match != 0 )
938 /* no dnattr match, check if this is a self clause */
939 if ( ! b->a_dn_self )
942 ACL_RECORD_VALUE_STATE;
944 /* this is a self clause, check if the target is an
950 /* target is attribute, check if the attribute value
953 rc = value_match( &match, b->a_dn_at,
954 b->a_dn_at->ad_type->sat_equality, 0,
957 /* on match error or no match, fail the ACL clause */
958 if (rc != LDAP_SUCCESS || match != 0 )
963 if ( b->a_group_pat.bv_len ) {
965 struct berval ndn = { 0, NULL };
968 if ( op->o_ndn.bv_len == 0 ) {
972 /* b->a_group is an unexpanded entry name, expanded it should be an
973 * entry with objectclass group* and we test to see if odn is one of
974 * the values in the attribute group
976 /* see if asker is listed in dnattr */
977 if ( b->a_group_style == ACL_STYLE_REGEX ) {
978 char buf[ACL_BUF_SIZE];
979 bv.bv_len = sizeof(buf) - 1;
982 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
983 if ( dnNormalize2( NULL, &bv, &ndn ) != LDAP_SUCCESS ) {
984 /* did not expand to a valid dn */
994 rc = backend_group( op, e, &bv, &op->o_ndn,
995 b->a_group_oc, b->a_group_at );
997 if ( ndn.bv_val ) free( ndn.bv_val );
1004 if ( b->a_set_pat.bv_len != 0 ) {
1006 char buf[ACL_BUF_SIZE];
1007 if( b->a_set_style == ACL_STYLE_REGEX ){
1008 bv.bv_len = sizeof(buf) - 1;
1010 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1014 if (aci_match_set( &bv, op, e, 0 ) == 0) {
1019 if ( b->a_authz.sai_ssf ) {
1021 LDAP_LOG( ACL, DETAIL1,
1022 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1023 op->o_connid, b->a_authz.sai_ssf, op->o_ssf );
1025 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1026 b->a_authz.sai_ssf, op->o_ssf, 0 );
1028 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1033 if ( b->a_authz.sai_transport_ssf ) {
1035 LDAP_LOG( ACL, DETAIL1,
1036 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1038 op->o_connid, b->a_authz.sai_transport_ssf,
1039 op->o_transport_ssf );
1041 Debug( LDAP_DEBUG_ACL,
1042 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1043 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1045 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1050 if ( b->a_authz.sai_tls_ssf ) {
1052 LDAP_LOG( ACL, DETAIL1,
1053 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1055 op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1057 Debug( LDAP_DEBUG_ACL,
1058 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1059 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1061 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1066 if ( b->a_authz.sai_sasl_ssf ) {
1068 LDAP_LOG( ACL, DETAIL1,
1069 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1071 op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1073 Debug( LDAP_DEBUG_ACL,
1074 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1075 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1077 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1082 #ifdef SLAPD_ACI_ENABLED
1083 if ( b->a_aci_at != NULL ) {
1085 slap_access_t grant, deny, tgrant, tdeny;
1087 /* this case works different from the others above.
1088 * since aci's themselves give permissions, we need
1089 * to first check b->a_access_mask, the ACL's access level.
1092 if ( e->e_nname.bv_len == 0 ) {
1093 /* no ACIs in the root DSE */
1097 /* first check if the right being requested
1098 * is allowed by the ACL clause.
1100 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1104 /* get the aci attribute */
1105 at = attr_find( e->e_attrs, b->a_aci_at );
1110 ACL_RECORD_VALUE_STATE;
1112 /* start out with nothing granted, nothing denied */
1116 /* the aci is an multi-valued attribute. The
1117 * rights are determined by OR'ing the individual
1118 * rights given by the acis.
1120 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1128 matches, &grant, &deny ) != 0)
1135 /* remove anything that the ACL clause does not allow */
1136 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1137 tdeny &= ACL_PRIV_MASK;
1139 /* see if we have anything to contribute */
1140 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1144 /* this could be improved by changing acl_mask so that it can deal with
1145 * by clauses that return grant/deny pairs. Right now, it does either
1146 * additive or subtractive rights, but not both at the same time. So,
1147 * we need to combine the grant/deny pair into a single rights mask in
1148 * a smart way: if either grant or deny is "empty", then we use the
1149 * opposite as is, otherwise we remove any denied rights from the grant
1150 * rights mask and construct an additive mask.
1152 if (ACL_IS_INVALID(tdeny)) {
1153 modmask = tgrant | ACL_PRIV_ADDITIVE;
1155 } else if (ACL_IS_INVALID(tgrant)) {
1156 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1159 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1165 modmask = b->a_access_mask;
1169 LDAP_LOG( ACL, RESULTS,
1170 "acl_mask: [%d] applying %s (%s)\n",
1171 i, accessmask2str( modmask, accessmaskbuf),
1172 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1173 ? "break" : "stop" );
1175 Debug( LDAP_DEBUG_ACL,
1176 "<= acl_mask: [%d] applying %s (%s)\n",
1177 i, accessmask2str( modmask, accessmaskbuf ),
1178 b->a_type == ACL_CONTINUE
1180 : b->a_type == ACL_BREAK
1187 if( ACL_IS_ADDITIVE(modmask) ) {
1189 ACL_PRIV_SET( *mask, modmask );
1192 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1194 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1195 /* substract privs */
1196 ACL_PRIV_CLR( *mask, modmask );
1199 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1207 LDAP_LOG( ACL, DETAIL1,
1208 "acl_mask: conn %lu [%d] mask: %s\n",
1209 op->o_connid, i, accessmask2str( *mask, accessmaskbuf) );
1211 Debug( LDAP_DEBUG_ACL,
1212 "<= acl_mask: [%d] mask: %s\n",
1213 i, accessmask2str(*mask, accessmaskbuf), 0 );
1216 if( b->a_type == ACL_CONTINUE ) {
1219 } else if ( b->a_type == ACL_BREAK ) {
1227 /* implicit "by * none" clause */
1231 LDAP_LOG( ACL, RESULTS,
1232 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1233 op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1235 Debug( LDAP_DEBUG_ACL,
1236 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1237 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1243 * acl_check_modlist - check access control on the given entry to see if
1244 * it allows the given modifications by the user associated with op.
1245 * returns 1 if mods allowed ok
1246 * 0 mods not allowed
1253 Modifications *mlist
1257 AccessControlState state = ACL_STATE_INIT;
1259 assert( op->o_bd != NULL );
1261 /* short circuit root database access */
1262 if ( be_isroot( op->o_bd, &op->o_ndn ) ) {
1264 LDAP_LOG( ACL, DETAIL1,
1265 "acl_check_modlist: conn %lu access granted to root user\n",
1266 op->o_connid, 0, 0 );
1268 Debug( LDAP_DEBUG_ACL,
1269 "<= acl_access_allowed: granted to database root\n",
1275 /* use backend default access if no backend acls */
1276 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1278 LDAP_LOG( ACL, DETAIL1,
1279 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1280 access2str( ACL_WRITE ),
1281 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1284 Debug( LDAP_DEBUG_ACL,
1285 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1286 access2str( ACL_WRITE ),
1287 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1289 return op->o_bd->be_dfltaccess >= ACL_WRITE;
1292 /* op->o_bd is always non-NULL */
1293 /* use global default access if no global acls */
1294 } else if ( op->o_bd == NULL && global_acl == NULL ) {
1296 LDAP_LOG( ACL, DETAIL1,
1297 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1298 access2str( ACL_WRITE ),
1299 global_default_access >= ACL_WRITE ? "granted" : "denied",
1302 Debug( LDAP_DEBUG_ACL,
1303 "=> access_allowed: global default %s access %s to \"%s\"\n",
1304 access2str( ACL_WRITE ),
1305 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1307 return global_default_access >= ACL_WRITE;
1311 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1313 * no-user-modification operational attributes are ignored
1314 * by ACL_WRITE checking as any found here are not provided
1317 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1319 LDAP_LOG( ACL, DETAIL1,
1320 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1321 op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1323 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1324 " modify access granted\n",
1325 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1330 switch ( mlist->sml_op ) {
1331 case LDAP_MOD_REPLACE:
1333 * We must check both permission to delete the whole
1334 * attribute and permission to add the specific attributes.
1335 * This prevents abuse from selfwriters.
1337 if ( ! access_allowed( op, e,
1338 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1343 if ( mlist->sml_bvalues == NULL ) break;
1345 /* fall thru to check value to add */
1348 assert( mlist->sml_bvalues != NULL );
1351 for ( bv = mlist->sml_nvalues
1352 ? mlist->sml_nvalues : mlist->sml_values;
1353 bv->bv_val != NULL; bv++ )
1355 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ )
1358 if ( ! access_allowed( op, e,
1359 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1366 case LDAP_MOD_DELETE:
1367 if ( mlist->sml_bvalues == NULL ) {
1368 if ( ! access_allowed( op, e,
1369 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1376 for ( bv = mlist->sml_nvalues
1377 ? mlist->sml_nvalues : mlist->sml_values;
1378 bv->bv_val != NULL; bv++ )
1380 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ )
1383 if ( ! access_allowed( op, e,
1384 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1391 case SLAP_MOD_SOFTADD:
1392 /* allow adding attribute via modrdn thru */
1406 struct berval *list,
1420 while (len >= 0 && --ix >= 0) {
1421 while (--len >= 0 && *p++ != sep) ;
1423 while (len >= 0 && *p == ' ') {
1434 while (--len >= 0 && *p != sep) {
1438 while (bv->bv_len > 0 && *--p == ' ')
1444 aci_set_gather (void *cookie, struct berval *name, struct berval *attr)
1446 AciSetCookie *cp = cookie;
1447 BerVarray bvals = NULL;
1450 /* this routine needs to return the bervals instead of
1451 * plain strings, since syntax is not known. It should
1452 * also return the syntax or some "comparison cookie".
1455 if (dnNormalize2(NULL, name, &ndn) == LDAP_SUCCESS) {
1457 AttributeDescription *desc = NULL;
1458 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1459 backend_attribute(cp->op,
1460 cp->e, &ndn, desc, &bvals);
1469 struct berval *subj,
1475 struct berval set = { 0, NULL };
1477 AciSetCookie cookie;
1480 ber_dupbv( &set, subj );
1482 struct berval subjdn, ndn = { 0, NULL };
1483 struct berval setat;
1486 AttributeDescription *desc = NULL;
1488 /* format of string is "entry/setAttrName" */
1489 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1493 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1494 setat.bv_val = SLAPD_ACI_SET_ATTR;
1495 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1498 if ( setat.bv_val != NULL ) {
1500 * NOTE: dnNormalize2 honors the ber_len field
1501 * as the length of the dn to be normalized
1503 if ( dnNormalize2(NULL, &subjdn, &ndn) == LDAP_SUCCESS
1504 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1506 backend_attribute(op, e,
1507 &ndn, desc, &bvals);
1508 if ( bvals != NULL ) {
1509 if ( bvals[0].bv_val != NULL ) {
1512 bvals[0].bv_val = NULL;
1513 for (i=1;bvals[i].bv_val;i++);
1514 bvals[0].bv_val = bvals[i-1].bv_val;
1515 bvals[i-1].bv_val = NULL;
1517 ber_bvarray_free(bvals);
1525 if (set.bv_val != NULL) {
1528 rc = (slap_set_filter(aci_set_gather, &cookie, &set,
1529 &op->o_ndn, &e->e_nname, NULL) > 0);
1530 ch_free(set.bv_val);
1535 #ifdef SLAPD_ACI_ENABLED
1537 aci_list_map_rights(
1538 struct berval *list )
1545 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1548 switch (*bv.bv_val) {
1550 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1553 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1554 * the right 's' to mean "set", but in the examples states
1555 * that the right 's' means "search". The latter definition
1558 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1561 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1564 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1567 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1568 * define any equivalent to the AUTH right, so I've just used
1571 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1583 struct berval *list,
1584 const struct berval *attr,
1585 struct berval *val )
1587 struct berval bv, left, right;
1590 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1591 if (aci_get_part(&bv, 0, '=', &left) < 0
1592 || aci_get_part(&bv, 1, '=', &right) < 0)
1594 if (ber_bvstrcasecmp(attr, &bv) == 0)
1596 } else if (val == NULL) {
1597 if (ber_bvstrcasecmp(attr, &left) == 0)
1600 if (ber_bvstrcasecmp(attr, &left) == 0) {
1601 /* this is experimental code that implements a
1602 * simple (prefix) match of the attribute value.
1603 * the ACI draft does not provide for aci's that
1604 * apply to specific values, but it would be
1605 * nice to have. If the <attr> part of an aci's
1606 * rights list is of the form <attr>=<value>,
1607 * that means the aci applies only to attrs with
1608 * the given value. Furthermore, if the attr is
1609 * of the form <attr>=<value>*, then <value> is
1610 * treated as a prefix, and the aci applies to
1611 * any value with that prefix.
1613 * Ideally, this would allow r.e. matches.
1615 if (aci_get_part(&right, 0, '*', &left) < 0
1616 || right.bv_len <= left.bv_len)
1618 if (ber_bvstrcasecmp(val, &right) == 0)
1620 } else if (val->bv_len >= left.bv_len) {
1621 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1630 static slap_access_t
1631 aci_list_get_attr_rights(
1632 struct berval *list,
1633 const struct berval *attr,
1634 struct berval *val )
1640 /* loop through each rights/attr pair, skip first part (action) */
1642 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1643 if (aci_list_has_attr(&bv, attr, val) == 0)
1645 if (aci_get_part(list, i, ';', &bv) < 0)
1647 mask |= aci_list_map_rights(&bv);
1653 aci_list_get_rights(
1654 struct berval *list,
1655 const struct berval *attr,
1657 slap_access_t *grant,
1658 slap_access_t *deny )
1660 struct berval perm, actn;
1661 slap_access_t *mask;
1664 if (attr == NULL || attr->bv_len == 0
1665 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1666 attr = &aci_bv_br_entry;
1672 /* loop through each permissions clause */
1673 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1674 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1676 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1678 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1685 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1686 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1693 struct berval *subj,
1694 struct berval *defgrpoc,
1695 struct berval *defgrpat,
1701 struct berval subjdn;
1702 struct berval grpoc;
1703 struct berval grpat;
1704 ObjectClass *grp_oc = NULL;
1705 AttributeDescription *grp_ad = NULL;
1709 /* format of string is "group/objectClassValue/groupAttrName" */
1710 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1714 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1718 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1722 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1723 if( rc != LDAP_SUCCESS ) {
1729 grp_oc = oc_bvfind( &grpoc );
1731 if (grp_oc != NULL && grp_ad != NULL ) {
1732 char buf[ACL_BUF_SIZE];
1733 struct berval bv, ndn;
1734 bv.bv_len = sizeof( buf ) - 1;
1735 bv.bv_val = (char *)&buf;
1736 string_expand(&bv, &subjdn, e->e_ndn, matches);
1737 if ( dnNormalize2(NULL, &bv, &ndn) == LDAP_SUCCESS ) {
1738 rc = (backend_group(op, e, &ndn, &op->o_ndn,
1739 grp_oc, grp_ad) == 0);
1752 AttributeDescription *desc,
1755 regmatch_t *matches,
1756 slap_access_t *grant,
1760 struct berval bv, perms, sdn;
1764 assert( desc->ad_cname.bv_val != NULL );
1766 /* parse an aci of the form:
1767 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1769 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1770 a full description of the format for this attribute.
1771 Differences: "this" in the draft is "self" here, and
1772 "self" and "public" is in the position of dnType.
1774 For now, this routine only supports scope=entry.
1777 /* check that the aci has all 5 components */
1778 if (aci_get_part(aci, 4, '#', NULL) < 0)
1781 /* check that the aci family is supported */
1782 if (aci_get_part(aci, 0, '#', &bv) < 0)
1785 /* check that the scope is "entry" */
1786 if (aci_get_part(aci, 1, '#', &bv) < 0
1787 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1792 /* get the list of permissions clauses, bail if empty */
1793 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1796 /* check if any permissions allow desired access */
1797 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1800 /* see if we have a DN match */
1801 if (aci_get_part(aci, 3, '#', &bv) < 0)
1804 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1807 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1810 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1811 if (dn_match( &op->o_ndn, &ndn))
1817 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1820 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1821 if (dn_match(&op->o_ndn, &e->e_nname))
1824 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1826 AttributeDescription *ad = NULL;
1829 rc = slap_bv2ad( &sdn, &ad, &text );
1831 if( rc != LDAP_SUCCESS ) {
1839 for(at = attrs_find( e->e_attrs, ad );
1841 at = attrs_find( at->a_next, ad ) )
1843 if (value_find_ex( ad,
1845 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1846 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1849 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1862 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1863 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, op, e, matches))
1866 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1867 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, op, e, matches))
1870 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1871 if (aci_match_set(&sdn, op, e, 0))
1874 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1875 if (aci_match_set(&sdn, op, e, 1))
1883 #endif /* SLAPD_ACI_ENABLED */
1890 regmatch_t *matches)
1898 bv->bv_val[0] = '\0';
1899 bv->bv_len--; /* leave space for lone $ */
1902 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1903 sp < pat->bv_val + pat->bv_len ; sp++ )
1905 /* did we previously see a $ */
1907 if ( flag == 1 && *sp == '$' ) {
1912 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
1915 } else if ( *sp >= '0' && *sp <= '9' ) {
1923 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
1924 if ( *sp >= '0' && *sp <= '9' ) {
1925 n = 10*n + ( *sp - '0' );
1929 if ( *sp != /*'{'*/ '}' ) {
1934 if ( n >= MAXREMATCHES ) {
1939 i = matches[n].rm_so;
1940 l = matches[n].rm_eo;
1941 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1959 /* must have ended with a single $ */
1968 LDAP_LOG( ACL, DETAIL1,
1969 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1970 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
1972 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1973 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1979 struct berval *pat, /* pattern to expand and match against */
1980 char *str, /* string to match against pattern */
1981 char *buf, /* buffer with $N expansion variables */
1982 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1986 char newbuf[ACL_BUF_SIZE];
1990 bv.bv_len = sizeof(newbuf) - 1;
1993 if(str == NULL) str = "";
1995 string_expand(&bv, pat, buf, matches);
1996 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1997 char error[ACL_BUF_SIZE];
1998 regerror(rc, &re, error, sizeof(error));
2002 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
2003 pat->bv_val, str, error );
2005 Debug( LDAP_DEBUG_TRACE,
2006 "compile( \"%s\", \"%s\") failed %s\n",
2007 pat->bv_val, str, error );
2012 rc = regexec(&re, str, 0, NULL, 0);
2016 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
2017 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
2018 rc, rc ? "matches" : "no matches", 0 );
2020 Debug( LDAP_DEBUG_TRACE,
2021 "=> regex_matches: string: %s\n", str, 0, 0 );
2022 Debug( LDAP_DEBUG_TRACE,
2023 "=> regex_matches: rc: %d %s\n",
2024 rc, !rc ? "matches" : "no matches", 0 );