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, op->o_tmpmemctx ) != 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,
903 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
904 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
906 &bv, op->o_tmpmemctx ) == 0 )
915 /* have a dnattr match. if this is a self clause then
916 * the target must also match the op dn.
918 if ( b->a_dn_self ) {
919 /* check if the target is an attribute. */
920 if ( val == NULL ) continue;
922 /* target is attribute, check if the attribute value
925 rc = value_match( &match, b->a_dn_at,
926 b->a_dn_at->ad_type->sat_equality, 0,
928 /* on match error or no match, fail the ACL clause */
929 if (rc != LDAP_SUCCESS || match != 0 )
933 /* no dnattr match, check if this is a self clause */
934 if ( ! b->a_dn_self )
937 ACL_RECORD_VALUE_STATE;
939 /* this is a self clause, check if the target is an
945 /* target is attribute, check if the attribute value
948 rc = value_match( &match, b->a_dn_at,
949 b->a_dn_at->ad_type->sat_equality, 0,
952 /* on match error or no match, fail the ACL clause */
953 if (rc != LDAP_SUCCESS || match != 0 )
958 if ( b->a_group_pat.bv_len ) {
960 struct berval ndn = { 0, NULL };
963 if ( op->o_ndn.bv_len == 0 ) {
967 /* b->a_group is an unexpanded entry name, expanded it should be an
968 * entry with objectclass group* and we test to see if odn is one of
969 * the values in the attribute group
971 /* see if asker is listed in dnattr */
972 if ( b->a_group_style == ACL_STYLE_REGEX ) {
973 char buf[ACL_BUF_SIZE];
974 bv.bv_len = sizeof(buf) - 1;
977 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
978 if ( dnNormalize2( NULL, &bv, &ndn, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
979 /* did not expand to a valid dn */
989 rc = backend_group( op, e, &bv, &op->o_ndn,
990 b->a_group_oc, b->a_group_at );
992 if ( ndn.bv_val ) free( ndn.bv_val );
999 if ( b->a_set_pat.bv_len != 0 ) {
1001 char buf[ACL_BUF_SIZE];
1002 if( b->a_set_style == ACL_STYLE_REGEX ){
1003 bv.bv_len = sizeof(buf) - 1;
1005 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1009 if (aci_match_set( &bv, op, e, 0 ) == 0) {
1014 if ( b->a_authz.sai_ssf ) {
1016 LDAP_LOG( ACL, DETAIL1,
1017 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1018 op->o_connid, b->a_authz.sai_ssf, op->o_ssf );
1020 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1021 b->a_authz.sai_ssf, op->o_ssf, 0 );
1023 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1028 if ( b->a_authz.sai_transport_ssf ) {
1030 LDAP_LOG( ACL, DETAIL1,
1031 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1033 op->o_connid, b->a_authz.sai_transport_ssf,
1034 op->o_transport_ssf );
1036 Debug( LDAP_DEBUG_ACL,
1037 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1038 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1040 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1045 if ( b->a_authz.sai_tls_ssf ) {
1047 LDAP_LOG( ACL, DETAIL1,
1048 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1050 op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1052 Debug( LDAP_DEBUG_ACL,
1053 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1054 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1056 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1061 if ( b->a_authz.sai_sasl_ssf ) {
1063 LDAP_LOG( ACL, DETAIL1,
1064 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1066 op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1068 Debug( LDAP_DEBUG_ACL,
1069 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1070 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1072 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1077 #ifdef SLAPD_ACI_ENABLED
1078 if ( b->a_aci_at != NULL ) {
1080 slap_access_t grant, deny, tgrant, tdeny;
1082 /* this case works different from the others above.
1083 * since aci's themselves give permissions, we need
1084 * to first check b->a_access_mask, the ACL's access level.
1087 if ( e->e_nname.bv_len == 0 ) {
1088 /* no ACIs in the root DSE */
1092 /* first check if the right being requested
1093 * is allowed by the ACL clause.
1095 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1099 /* get the aci attribute */
1100 at = attr_find( e->e_attrs, b->a_aci_at );
1105 ACL_RECORD_VALUE_STATE;
1107 /* start out with nothing granted, nothing denied */
1111 /* the aci is an multi-valued attribute. The
1112 * rights are determined by OR'ing the individual
1113 * rights given by the acis.
1115 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1119 matches, &grant, &deny ) != 0)
1126 /* remove anything that the ACL clause does not allow */
1127 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1128 tdeny &= ACL_PRIV_MASK;
1130 /* see if we have anything to contribute */
1131 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1135 /* this could be improved by changing acl_mask so that it can deal with
1136 * by clauses that return grant/deny pairs. Right now, it does either
1137 * additive or subtractive rights, but not both at the same time. So,
1138 * we need to combine the grant/deny pair into a single rights mask in
1139 * a smart way: if either grant or deny is "empty", then we use the
1140 * opposite as is, otherwise we remove any denied rights from the grant
1141 * rights mask and construct an additive mask.
1143 if (ACL_IS_INVALID(tdeny)) {
1144 modmask = tgrant | ACL_PRIV_ADDITIVE;
1146 } else if (ACL_IS_INVALID(tgrant)) {
1147 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1150 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1156 modmask = b->a_access_mask;
1160 LDAP_LOG( ACL, RESULTS,
1161 "acl_mask: [%d] applying %s (%s)\n",
1162 i, accessmask2str( modmask, accessmaskbuf),
1163 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1164 ? "break" : "stop" );
1166 Debug( LDAP_DEBUG_ACL,
1167 "<= acl_mask: [%d] applying %s (%s)\n",
1168 i, accessmask2str( modmask, accessmaskbuf ),
1169 b->a_type == ACL_CONTINUE
1171 : b->a_type == ACL_BREAK
1178 if( ACL_IS_ADDITIVE(modmask) ) {
1180 ACL_PRIV_SET( *mask, modmask );
1183 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1185 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1186 /* substract privs */
1187 ACL_PRIV_CLR( *mask, modmask );
1190 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1198 LDAP_LOG( ACL, DETAIL1,
1199 "acl_mask: conn %lu [%d] mask: %s\n",
1200 op->o_connid, i, accessmask2str( *mask, accessmaskbuf) );
1202 Debug( LDAP_DEBUG_ACL,
1203 "<= acl_mask: [%d] mask: %s\n",
1204 i, accessmask2str(*mask, accessmaskbuf), 0 );
1207 if( b->a_type == ACL_CONTINUE ) {
1210 } else if ( b->a_type == ACL_BREAK ) {
1218 /* implicit "by * none" clause */
1222 LDAP_LOG( ACL, RESULTS,
1223 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1224 op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1226 Debug( LDAP_DEBUG_ACL,
1227 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1228 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1234 * acl_check_modlist - check access control on the given entry to see if
1235 * it allows the given modifications by the user associated with op.
1236 * returns 1 if mods allowed ok
1237 * 0 mods not allowed
1244 Modifications *mlist
1248 AccessControlState state = ACL_STATE_INIT;
1250 assert( op->o_bd != NULL );
1252 /* short circuit root database access */
1253 if ( be_isroot( op->o_bd, &op->o_ndn ) ) {
1255 LDAP_LOG( ACL, DETAIL1,
1256 "acl_check_modlist: conn %lu access granted to root user\n",
1257 op->o_connid, 0, 0 );
1259 Debug( LDAP_DEBUG_ACL,
1260 "<= acl_access_allowed: granted to database root\n",
1266 /* use backend default access if no backend acls */
1267 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1269 LDAP_LOG( ACL, DETAIL1,
1270 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1271 access2str( ACL_WRITE ),
1272 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1275 Debug( LDAP_DEBUG_ACL,
1276 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1277 access2str( ACL_WRITE ),
1278 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1280 return op->o_bd->be_dfltaccess >= ACL_WRITE;
1283 /* op->o_bd is always non-NULL */
1284 /* use global default access if no global acls */
1285 } else if ( op->o_bd == NULL && global_acl == NULL ) {
1287 LDAP_LOG( ACL, DETAIL1,
1288 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1289 access2str( ACL_WRITE ),
1290 global_default_access >= ACL_WRITE ? "granted" : "denied",
1293 Debug( LDAP_DEBUG_ACL,
1294 "=> access_allowed: global default %s access %s to \"%s\"\n",
1295 access2str( ACL_WRITE ),
1296 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1298 return global_default_access >= ACL_WRITE;
1302 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1304 * no-user-modification operational attributes are ignored
1305 * by ACL_WRITE checking as any found here are not provided
1308 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1310 LDAP_LOG( ACL, DETAIL1,
1311 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1312 op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1314 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1315 " modify access granted\n",
1316 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1321 switch ( mlist->sml_op ) {
1322 case LDAP_MOD_REPLACE:
1324 * We must check both permission to delete the whole
1325 * attribute and permission to add the specific attributes.
1326 * This prevents abuse from selfwriters.
1328 if ( ! access_allowed( op, e,
1329 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1334 if ( mlist->sml_bvalues == NULL ) break;
1336 /* fall thru to check value to add */
1339 assert( mlist->sml_bvalues != NULL );
1341 for ( bv = mlist->sml_nvalues
1342 ? mlist->sml_nvalues : mlist->sml_values;
1343 bv->bv_val != NULL; bv++ )
1345 if ( ! access_allowed( op, e,
1346 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1353 case LDAP_MOD_DELETE:
1354 if ( mlist->sml_bvalues == NULL ) {
1355 if ( ! access_allowed( op, e,
1356 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1362 for ( bv = mlist->sml_nvalues
1363 ? mlist->sml_nvalues : mlist->sml_values;
1364 bv->bv_val != NULL; bv++ )
1366 if ( ! access_allowed( op, e,
1367 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1374 case SLAP_MOD_SOFTADD:
1375 /* allow adding attribute via modrdn thru */
1389 struct berval *list,
1403 while (len >= 0 && --ix >= 0) {
1404 while (--len >= 0 && *p++ != sep) ;
1406 while (len >= 0 && *p == ' ') {
1417 while (--len >= 0 && *p != sep) {
1421 while (bv->bv_len > 0 && *--p == ' ')
1427 aci_set_gather (void *cookie, struct berval *name, struct berval *attr)
1429 AciSetCookie *cp = cookie;
1430 BerVarray bvals = NULL;
1433 /* this routine needs to return the bervals instead of
1434 * plain strings, since syntax is not known. It should
1435 * also return the syntax or some "comparison cookie".
1438 if (dnNormalize2(NULL, name, &ndn, cp->op->o_tmpmemctx ) == LDAP_SUCCESS) {
1440 AttributeDescription *desc = NULL;
1441 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1442 backend_attribute(cp->op,
1443 cp->e, &ndn, desc, &bvals);
1452 struct berval *subj,
1458 struct berval set = { 0, NULL };
1460 AciSetCookie cookie;
1463 ber_dupbv( &set, subj );
1465 struct berval subjdn, ndn = { 0, NULL };
1466 struct berval setat;
1469 AttributeDescription *desc = NULL;
1471 /* format of string is "entry/setAttrName" */
1472 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1476 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1477 setat.bv_val = SLAPD_ACI_SET_ATTR;
1478 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1481 if ( setat.bv_val != NULL ) {
1483 * NOTE: dnNormalize2 honors the ber_len field
1484 * as the length of the dn to be normalized
1486 if ( dnNormalize2(NULL, &subjdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS
1487 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1489 backend_attribute(op, e,
1490 &ndn, desc, &bvals);
1491 if ( bvals != NULL ) {
1492 if ( bvals[0].bv_val != NULL ) {
1495 bvals[0].bv_val = NULL;
1496 for (i=1;bvals[i].bv_val;i++);
1497 bvals[0].bv_val = bvals[i-1].bv_val;
1498 bvals[i-1].bv_val = NULL;
1500 ber_bvarray_free(bvals);
1508 if (set.bv_val != NULL) {
1511 rc = (slap_set_filter(aci_set_gather, &cookie, &set,
1512 &op->o_ndn, &e->e_nname, NULL) > 0);
1513 ch_free(set.bv_val);
1518 #ifdef SLAPD_ACI_ENABLED
1520 aci_list_map_rights(
1521 struct berval *list )
1528 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1531 switch (*bv.bv_val) {
1533 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1536 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1537 * the right 's' to mean "set", but in the examples states
1538 * that the right 's' means "search". The latter definition
1541 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1544 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1547 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1550 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1551 * define any equivalent to the AUTH right, so I've just used
1554 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1566 struct berval *list,
1567 const struct berval *attr,
1568 struct berval *val )
1570 struct berval bv, left, right;
1573 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1574 if (aci_get_part(&bv, 0, '=', &left) < 0
1575 || aci_get_part(&bv, 1, '=', &right) < 0)
1577 if (ber_bvstrcasecmp(attr, &bv) == 0)
1579 } else if (val == NULL) {
1580 if (ber_bvstrcasecmp(attr, &left) == 0)
1583 if (ber_bvstrcasecmp(attr, &left) == 0) {
1584 /* this is experimental code that implements a
1585 * simple (prefix) match of the attribute value.
1586 * the ACI draft does not provide for aci's that
1587 * apply to specific values, but it would be
1588 * nice to have. If the <attr> part of an aci's
1589 * rights list is of the form <attr>=<value>,
1590 * that means the aci applies only to attrs with
1591 * the given value. Furthermore, if the attr is
1592 * of the form <attr>=<value>*, then <value> is
1593 * treated as a prefix, and the aci applies to
1594 * any value with that prefix.
1596 * Ideally, this would allow r.e. matches.
1598 if (aci_get_part(&right, 0, '*', &left) < 0
1599 || right.bv_len <= left.bv_len)
1601 if (ber_bvstrcasecmp(val, &right) == 0)
1603 } else if (val->bv_len >= left.bv_len) {
1604 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1613 static slap_access_t
1614 aci_list_get_attr_rights(
1615 struct berval *list,
1616 const struct berval *attr,
1617 struct berval *val )
1623 /* loop through each rights/attr pair, skip first part (action) */
1625 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1626 if (aci_list_has_attr(&bv, attr, val) == 0)
1628 if (aci_get_part(list, i, ';', &bv) < 0)
1630 mask |= aci_list_map_rights(&bv);
1636 aci_list_get_rights(
1637 struct berval *list,
1638 const struct berval *attr,
1640 slap_access_t *grant,
1641 slap_access_t *deny )
1643 struct berval perm, actn;
1644 slap_access_t *mask;
1647 if (attr == NULL || attr->bv_len == 0
1648 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1649 attr = &aci_bv_br_entry;
1655 /* loop through each permissions clause */
1656 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1657 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1659 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1661 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1668 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1669 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1676 struct berval *subj,
1677 struct berval *defgrpoc,
1678 struct berval *defgrpat,
1684 struct berval subjdn;
1685 struct berval grpoc;
1686 struct berval grpat;
1687 ObjectClass *grp_oc = NULL;
1688 AttributeDescription *grp_ad = NULL;
1692 /* format of string is "group/objectClassValue/groupAttrName" */
1693 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1697 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1701 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1705 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1706 if( rc != LDAP_SUCCESS ) {
1712 grp_oc = oc_bvfind( &grpoc );
1714 if (grp_oc != NULL && grp_ad != NULL ) {
1715 char buf[ACL_BUF_SIZE];
1716 struct berval bv, ndn;
1717 bv.bv_len = sizeof( buf ) - 1;
1718 bv.bv_val = (char *)&buf;
1719 string_expand(&bv, &subjdn, e->e_ndn, matches);
1720 if ( dnNormalize2(NULL, &bv, &ndn) == LDAP_SUCCESS ) {
1721 rc = (backend_group(op, e, &ndn, &op->o_ndn,
1722 grp_oc, grp_ad) == 0);
1735 AttributeDescription *desc,
1738 regmatch_t *matches,
1739 slap_access_t *grant,
1743 struct berval bv, perms, sdn;
1747 assert( desc->ad_cname.bv_val != NULL );
1749 /* parse an aci of the form:
1750 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1752 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1753 a full description of the format for this attribute.
1754 Differences: "this" in the draft is "self" here, and
1755 "self" and "public" is in the position of dnType.
1757 For now, this routine only supports scope=entry.
1760 /* check that the aci has all 5 components */
1761 if (aci_get_part(aci, 4, '#', NULL) < 0)
1764 /* check that the aci family is supported */
1765 if (aci_get_part(aci, 0, '#', &bv) < 0)
1768 /* check that the scope is "entry" */
1769 if (aci_get_part(aci, 1, '#', &bv) < 0
1770 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1775 /* get the list of permissions clauses, bail if empty */
1776 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1779 /* check if any permissions allow desired access */
1780 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1783 /* see if we have a DN match */
1784 if (aci_get_part(aci, 3, '#', &bv) < 0)
1787 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1790 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1793 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1794 if (dn_match( &op->o_ndn, &ndn))
1800 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1803 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1804 if (dn_match(&op->o_ndn, &e->e_nname))
1807 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1809 AttributeDescription *ad = NULL;
1812 rc = slap_bv2ad( &sdn, &ad, &text );
1814 if( rc != LDAP_SUCCESS ) {
1822 for(at = attrs_find( e->e_attrs, ad );
1824 at = attrs_find( at->a_next, ad ) )
1826 if (value_find_ex( ad,
1827 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1828 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1840 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1841 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, op, e, matches))
1844 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1845 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, op, e, matches))
1848 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1849 if (aci_match_set(&sdn, op, e, 0))
1852 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1853 if (aci_match_set(&sdn, op, e, 1))
1861 #endif /* SLAPD_ACI_ENABLED */
1868 regmatch_t *matches)
1876 bv->bv_val[0] = '\0';
1877 bv->bv_len--; /* leave space for lone $ */
1880 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1881 sp < pat->bv_val + pat->bv_len ; sp++ )
1883 /* did we previously see a $ */
1885 if ( flag == 1 && *sp == '$' ) {
1890 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
1893 } else if ( *sp >= '0' && *sp <= '9' ) {
1901 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
1902 if ( *sp >= '0' && *sp <= '9' ) {
1903 n = 10*n + ( *sp - '0' );
1907 if ( *sp != /*'{'*/ '}' ) {
1912 if ( n >= MAXREMATCHES ) {
1917 i = matches[n].rm_so;
1918 l = matches[n].rm_eo;
1919 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1937 /* must have ended with a single $ */
1946 LDAP_LOG( ACL, DETAIL1,
1947 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1948 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
1950 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1951 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1957 struct berval *pat, /* pattern to expand and match against */
1958 char *str, /* string to match against pattern */
1959 char *buf, /* buffer with $N expansion variables */
1960 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1964 char newbuf[ACL_BUF_SIZE];
1968 bv.bv_len = sizeof(newbuf) - 1;
1971 if(str == NULL) str = "";
1973 string_expand(&bv, pat, buf, matches);
1974 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1975 char error[ACL_BUF_SIZE];
1976 regerror(rc, &re, error, sizeof(error));
1980 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
1981 pat->bv_val, str, error );
1983 Debug( LDAP_DEBUG_TRACE,
1984 "compile( \"%s\", \"%s\") failed %s\n",
1985 pat->bv_val, str, error );
1990 rc = regexec(&re, str, 0, NULL, 0);
1994 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
1995 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
1996 rc, rc ? "matches" : "no matches", 0 );
1998 Debug( LDAP_DEBUG_TRACE,
1999 "=> regex_matches: string: %s\n", str, 0, 0 );
2000 Debug( LDAP_DEBUG_TRACE,
2001 "=> regex_matches: rc: %d %s\n",
2002 rc, !rc ? "matches" : "no matches", 0 );