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 Backend *be, Operation *op,
52 AttributeDescription *desc,
53 int nmatches, regmatch_t *matches );
55 static slap_control_t acl_mask(
56 AccessControl *ac, slap_mask_t *mask,
57 Backend *be, Connection *conn, Operation *op,
59 AttributeDescription *desc,
63 AccessControlState *state );
65 #ifdef SLAPD_ACI_ENABLED
71 AttributeDescription *desc,
76 slap_access_t *deny );
79 static int regex_matches(
80 struct berval *pat, char *str, char *buf, regmatch_t *matches);
81 static void string_expand(
82 struct berval *newbuf, struct berval *pattern,
83 char *match, regmatch_t *matches);
85 typedef struct AciSetCookie {
92 SLAP_SET_GATHER aci_set_gather;
93 static int aci_match_set ( struct berval *subj, Backend *be,
94 Entry *e, Connection *conn, Operation *op, int setref );
97 * access_allowed - check whether op->o_ndn is allowed the requested access
98 * to entry e, attribute attr, value val. if val is null, access to
99 * the whole attribute is assumed (all values).
101 * This routine loops through all access controls and calls
102 * acl_mask() on each applicable access control.
103 * The loop exits when a definitive answer is reached or
104 * or no more controls remain.
117 AttributeDescription *desc,
119 slap_access_t access,
120 AccessControlState *state )
124 AccessControl *a = NULL;
127 char accessmaskbuf[ACCESSMASK_MAXLEN];
130 slap_control_t control;
132 regmatch_t matches[MAXREMATCHES];
133 int st_same_attr = 0;
134 int st_initialized = 0;
135 static AccessControlState state_init = ACL_STATE_INIT;
138 assert( desc != NULL );
139 assert( access > ACL_NONE );
141 attr = desc->ad_cname.bv_val;
143 assert( attr != NULL );
145 if( state && state->as_recorded && state->as_vd_ad==desc) {
146 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
149 return state->as_result;
151 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
152 val != NULL && state->as_vd_acl == NULL )
154 return state->as_result;
158 state->as_vd_ad=desc;
162 LDAP_LOG( ACL, ENTRY,
163 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
164 access2str( access ), e->e_dn, attr );
166 Debug( LDAP_DEBUG_ACL,
167 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
168 access2str( access ), e->e_dn, attr );
176 if ( be == NULL ) be = &backends[0];
177 assert( be != NULL );
179 /* grant database root access */
180 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
183 "access_allowed: conn %lu root access granted\n",
184 conn->c_connid, 0, 0 );
186 Debug( LDAP_DEBUG_ACL,
187 "<= root access granted\n",
194 * no-user-modification operational attributes are ignored
195 * by ACL_WRITE checking as any found here are not provided
198 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
199 && desc != slap_schema.si_ad_entry
200 && desc != slap_schema.si_ad_children )
203 LDAP_LOG( ACL, DETAIL1,
204 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
205 "access granted\n", conn->c_connid, attr , 0 );
207 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
208 " %s access granted\n",
214 /* use backend default access if no backend acls */
215 if( be != NULL && be->be_acl == NULL ) {
217 LDAP_LOG( ACL, DETAIL1,
218 "access_allowed: backend default %s access %s to \"%s\"\n",
219 access2str( access ),
220 be->be_dfltaccess >= access ? "granted" : "denied",
223 Debug( LDAP_DEBUG_ACL,
224 "=> access_allowed: backend default %s access %s to \"%s\"\n",
225 access2str( access ),
226 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
228 ret = be->be_dfltaccess >= access;
232 /* be is always non-NULL */
233 /* use global default access if no global acls */
234 } else if ( be == NULL && global_acl == NULL ) {
236 LDAP_LOG( ACL, DETAIL1,
237 "access_allowed: global default %s access %s to \"%s\"\n",
238 access2str( access ),
239 global_default_access >= access ? "granted" : "denied",
242 Debug( LDAP_DEBUG_ACL,
243 "=> access_allowed: global default %s access %s to \"%s\"\n",
244 access2str( access ),
245 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
247 ret = global_default_access >= access;
256 assert( state->as_vd_acl != NULL );
258 a = state->as_vd_acl;
259 mask = state->as_vd_acl_mask;
260 count = state->as_vd_acl_count;
261 AC_MEMCPY( matches, state->as_vd_acl_matches,
269 memset(matches, '\0', sizeof(matches));
272 while((a = acl_get( a, &count, be, op, e, desc,
273 MAXREMATCHES, matches )) != NULL)
277 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
279 LDAP_LOG( ACL, DETAIL1,
280 "access_allowed: match[%d]: %d %d ",
281 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
283 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
284 (int)matches[i].rm_so, (int)matches[i].rm_eo );
286 if( matches[i].rm_so <= matches[0].rm_eo ) {
288 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
289 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
293 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
295 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
300 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
301 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
302 return state->as_result;
303 } else if (!st_initialized) {
304 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
306 state->as_vd_ad=desc;
312 control = acl_mask( a, &mask, be, conn, op,
313 e, desc, val, matches, count, state );
315 if ( control != ACL_BREAK ) {
319 memset(matches, '\0', sizeof(matches));
322 if ( ACL_IS_INVALID( mask ) ) {
324 LDAP_LOG( ACL, DETAIL1,
325 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
326 conn->c_connid, e->e_dn, attr );
328 Debug( LDAP_DEBUG_ACL,
329 "=> access_allowed: \"%s\" (%s) invalid!\n",
334 } else if ( control == ACL_BREAK ) {
336 LDAP_LOG( ACL, DETAIL1,
337 "access_allowed: conn %lu no more rules\n", conn->c_connid, 0,0 );
339 Debug( LDAP_DEBUG_ACL,
340 "=> access_allowed: no more rules\n", 0, 0, 0);
347 LDAP_LOG( ACL, ENTRY,
348 "access_allowed: %s access %s by %s\n",
349 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
350 accessmask2str( mask, accessmaskbuf ) );
352 Debug( LDAP_DEBUG_ACL,
353 "=> access_allowed: %s access %s by %s\n",
354 access2str( access ),
355 ACL_GRANT(mask, access) ? "granted" : "denied",
356 accessmask2str( mask, accessmaskbuf ) );
359 ret = ACL_GRANT(mask, access);
362 if( state != NULL ) {
363 /* If not value-dependent, save ACL in case of more attrs */
364 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) )
365 state->as_vi_acl = a;
366 state->as_recorded |= ACL_STATE_RECORDED;
367 state->as_result = ret;
373 * acl_get - return the acl applicable to entry e, attribute
374 * attr. the acl returned is suitable for use in subsequent calls to
375 * acl_access_allowed().
378 static AccessControl *
385 AttributeDescription *desc,
387 regmatch_t *matches )
393 assert( count != NULL );
394 assert( desc != NULL );
396 attr = desc->ad_cname.bv_val;
398 assert( attr != NULL );
413 dnlen = e->e_nname.bv_len;
415 for ( ; a != NULL; a = a->acl_next ) {
418 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
419 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
421 LDAP_LOG( ACL, DETAIL1,
422 "acl_get: dnpat [%d] %s nsub: %d\n",
423 *count, a->acl_dn_pat.bv_val,
424 (int) a->acl_dn_re.re_nsub );
426 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
427 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
429 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
434 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
435 *count, a->acl_dn_pat.bv_val, 0 );
437 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
438 *count, a->acl_dn_pat.bv_val, 0 );
440 patlen = a->acl_dn_pat.bv_len;
441 if ( dnlen < patlen )
444 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
445 /* base dn -- entire object DN must match */
446 if ( dnlen != patlen )
449 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
452 if ( dnlen <= patlen )
455 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
458 rdnlen = dn_rdnlen( NULL, &e->e_nname );
459 if ( rdnlen != dnlen - patlen - 1 )
462 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
463 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
466 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
467 if ( dnlen <= patlen )
469 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
473 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
478 LDAP_LOG( ACL, DETAIL1,
479 "acl_get: [%d] matched\n", *count, 0, 0 );
481 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
486 if ( a->acl_filter != NULL ) {
487 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
488 if ( rc != LDAP_COMPARE_TRUE ) {
494 LDAP_LOG( ACL, DETAIL1,
495 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
497 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
500 if ( attr == NULL || a->acl_attrs == NULL ||
501 ad_inlist( desc, a->acl_attrs ) )
504 LDAP_LOG( ACL, DETAIL1,
505 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
507 Debug( LDAP_DEBUG_ACL,
508 "<= acl_get: [%d] acl %s attr: %s\n",
509 *count, e->e_dn, attr );
513 matches[0].rm_so = matches[0].rm_eo = -1;
517 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
519 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
525 * Record value-dependent access control state
527 #define ACL_RECORD_VALUE_STATE do { \
528 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
529 state->as_recorded |= ACL_STATE_RECORDED_VD; \
530 state->as_vd_acl = a; \
531 AC_MEMCPY( state->as_vd_acl_matches, matches, \
532 sizeof( state->as_vd_acl_matches )) ; \
533 state->as_vd_acl_count = count; \
534 state->as_vd_access = b; \
535 state->as_vd_access_count = i; \
540 * acl_mask - modifies mask based upon the given acl and the
541 * requested access to entry e, attribute attr, value val. if val
542 * is null, access to the whole attribute is assumed (all values).
544 * returns 0 access NOT allowed
548 static slap_control_t
556 AttributeDescription *desc,
560 AccessControlState *state )
562 int i, odnlen, patlen;
565 char accessmaskbuf[ACCESSMASK_MAXLEN];
570 assert( mask != NULL );
571 assert( desc != NULL );
573 attr = desc->ad_cname.bv_val;
575 assert( attr != NULL );
578 LDAP_LOG( ACL, ENTRY,
579 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
580 conn->c_connid, e->e_dn, attr );
583 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
584 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
585 accessmask2str( *mask, accessmaskbuf ) );
587 Debug( LDAP_DEBUG_ACL,
588 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
591 Debug( LDAP_DEBUG_ACL,
592 "=> acl_mask: to %s by \"%s\", (%s) \n",
593 val ? "value" : "all values",
594 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
595 accessmask2str( *mask, accessmaskbuf ) );
598 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
599 && state->as_vd_acl == a )
601 b = state->as_vd_access;
602 i = state->as_vd_access_count;
609 for ( ; b != NULL; b = b->a_next, i++ ) {
610 slap_mask_t oldmask, modmask;
612 ACL_INVALIDATE( modmask );
614 /* AND <who> clauses */
615 if ( b->a_dn_pat.bv_len != 0 ) {
617 LDAP_LOG( ACL, DETAIL1,
618 "acl_mask: conn %lu check a_dn_pat: %s\n",
619 conn->c_connid, b->a_dn_pat.bv_val ,0 );
621 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
622 b->a_dn_pat.bv_val, 0, 0);
625 * if access applies to the entry itself, and the
626 * user is bound as somebody in the same namespace as
627 * the entry, OR the given dn matches the dn pattern
629 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
630 if ( op->o_ndn.bv_len != 0 ) {
634 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
635 if ( op->o_ndn.bv_len == 0 ) {
639 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
640 if ( op->o_ndn.bv_len == 0 ) {
644 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
648 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
649 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
650 int ret = regex_matches( &b->a_dn_pat,
651 op->o_ndn.bv_val, e->e_ndn, matches );
662 if ( e->e_dn == NULL )
665 if ( b->a_dn_expand ) {
667 char buf[ACL_BUF_SIZE];
669 bv.bv_len = sizeof( buf ) - 1;
672 string_expand(&bv, &b->a_dn_pat,
674 if ( dnNormalize2(NULL, &bv, &pat) != LDAP_SUCCESS ) {
675 /* did not expand to a valid dn */
683 odnlen = op->o_ndn.bv_len;
684 if ( odnlen < patlen ) {
685 goto dn_match_cleanup;
689 if ( b->a_dn_style == ACL_STYLE_BASE ) {
690 /* base dn -- entire object DN must match */
691 if ( odnlen != patlen ) {
692 goto dn_match_cleanup;
695 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
698 if ( odnlen <= patlen ) {
699 goto dn_match_cleanup;
702 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
703 goto dn_match_cleanup;
706 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
707 if ( rdnlen != odnlen - patlen - 1 ) {
708 goto dn_match_cleanup;
711 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
712 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
713 goto dn_match_cleanup;
716 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
717 if ( odnlen <= patlen ) {
718 goto dn_match_cleanup;
721 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
722 goto dn_match_cleanup;
726 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
729 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
739 if ( b->a_sockurl_pat.bv_len ) {
741 LDAP_LOG( ACL, DETAIL1,
742 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
743 conn->c_connid, b->a_sockurl_pat.bv_val , 0 );
745 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
746 b->a_sockurl_pat.bv_val, 0, 0 );
749 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
750 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
751 if (!regex_matches( &b->a_sockurl_pat, conn->c_listener_url.bv_val,
752 e->e_ndn, matches ) )
757 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &conn->c_listener_url ) != 0 )
763 if ( b->a_domain_pat.bv_len ) {
765 LDAP_LOG( ACL, DETAIL1,
766 "acl_mask: conn %lu check a_domain_pat: %s\n",
767 conn->c_connid, b->a_domain_pat.bv_val , 0 );
769 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
770 b->a_domain_pat.bv_val, 0, 0 );
772 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
773 if ( b->a_domain_style == ACL_STYLE_REGEX) {
774 if (!regex_matches( &b->a_domain_pat, conn->c_peer_domain.bv_val,
775 e->e_ndn, matches ) )
780 char buf[ACL_BUF_SIZE];
782 struct berval cmp = conn->c_peer_domain;
783 struct berval pat = b->a_domain_pat;
785 if ( b->a_domain_expand ) {
788 bv.bv_len = sizeof(buf) - 1;
791 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
795 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
796 int offset = cmp.bv_len - pat.bv_len;
801 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
805 /* trim the domain */
806 cmp.bv_val = &cmp.bv_val[ offset ];
807 cmp.bv_len -= offset;
810 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
817 if ( b->a_peername_pat.bv_len ) {
819 LDAP_LOG( ACL, DETAIL1,
820 "acl_mask: conn %lu check a_perrname_path: %s\n",
821 conn->c_connid, b->a_peername_pat.bv_val , 0 );
823 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
824 b->a_peername_pat.bv_val, 0, 0 );
826 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
827 if ( b->a_peername_style == ACL_STYLE_REGEX) {
828 if (!regex_matches( &b->a_peername_pat, conn->c_peer_name.bv_val,
829 e->e_ndn, matches ) )
834 if ( ber_bvstrcasecmp( &b->a_peername_pat, &conn->c_peer_name ) != 0 )
840 if ( b->a_sockname_pat.bv_len ) {
842 LDAP_LOG( ACL, DETAIL1,
843 "acl_mask: conn %lu check a_sockname_path: %s\n",
844 conn->c_connid, b->a_sockname_pat.bv_val , 0 );
846 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
847 b->a_sockname_pat.bv_val, 0, 0 );
849 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
850 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
851 if (!regex_matches( &b->a_sockname_pat, conn->c_sock_name.bv_val,
852 e->e_ndn, matches ) )
857 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &conn->c_sock_name ) != 0 )
863 if ( b->a_dn_at != NULL ) {
868 const char *attr = b->a_dn_at->ad_cname.bv_val;
870 assert( attr != NULL );
872 if ( op->o_ndn.bv_len == 0 ) {
877 LDAP_LOG( ACL, DETAIL1,
878 "acl_mask: conn %lu check a_dn_pat: %s\n",
879 conn->c_connid, attr , 0 );
881 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
886 /* see if asker is listed in dnattr */
887 for( at = attrs_find( e->e_attrs, b->a_dn_at );
889 at = attrs_find( at->a_next, b->a_dn_at ) )
891 if( value_find_ex( b->a_dn_at,
892 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, at->a_vals, &bv )
902 /* have a dnattr match. if this is a self clause then
903 * the target must also match the op dn.
905 if ( b->a_dn_self ) {
906 /* check if the target is an attribute. */
907 if ( val == NULL ) continue;
909 /* target is attribute, check if the attribute value
912 rc = value_match( &match, b->a_dn_at,
913 b->a_dn_at->ad_type->sat_equality, 0,
915 /* on match error or no match, fail the ACL clause */
916 if (rc != LDAP_SUCCESS || match != 0 )
920 /* no dnattr match, check if this is a self clause */
921 if ( ! b->a_dn_self )
924 ACL_RECORD_VALUE_STATE;
926 /* this is a self clause, check if the target is an
932 /* target is attribute, check if the attribute value
935 rc = value_match( &match, b->a_dn_at,
936 b->a_dn_at->ad_type->sat_equality, 0,
939 /* on match error or no match, fail the ACL clause */
940 if (rc != LDAP_SUCCESS || match != 0 )
945 if ( b->a_group_pat.bv_len ) {
947 struct berval ndn = { 0, NULL };
950 if ( op->o_ndn.bv_len == 0 ) {
954 /* b->a_group is an unexpanded entry name, expanded it should be an
955 * entry with objectclass group* and we test to see if odn is one of
956 * the values in the attribute group
958 /* see if asker is listed in dnattr */
959 if ( b->a_group_style == ACL_STYLE_REGEX ) {
960 char buf[ACL_BUF_SIZE];
961 bv.bv_len = sizeof(buf) - 1;
964 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
965 if ( dnNormalize2( NULL, &bv, &ndn ) != LDAP_SUCCESS ) {
966 /* did not expand to a valid dn */
976 rc = backend_group( be, conn, op, e, &bv, &op->o_ndn,
977 b->a_group_oc, b->a_group_at );
979 if ( ndn.bv_val ) free( ndn.bv_val );
986 if ( b->a_set_pat.bv_len != 0 ) {
988 char buf[ACL_BUF_SIZE];
989 if( b->a_set_style == ACL_STYLE_REGEX ){
990 bv.bv_len = sizeof(buf) - 1;
992 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
996 if (aci_match_set( &bv, be, e, conn, op, 0 ) == 0) {
1001 if ( b->a_authz.sai_ssf ) {
1003 LDAP_LOG( ACL, DETAIL1,
1004 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1005 conn->c_connid, b->a_authz.sai_ssf, op->o_ssf );
1007 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1008 b->a_authz.sai_ssf, op->o_ssf, 0 );
1010 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1015 if ( b->a_authz.sai_transport_ssf ) {
1017 LDAP_LOG( ACL, DETAIL1,
1018 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1020 conn->c_connid, b->a_authz.sai_transport_ssf,
1021 op->o_transport_ssf );
1023 Debug( LDAP_DEBUG_ACL,
1024 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1025 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1027 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1032 if ( b->a_authz.sai_tls_ssf ) {
1034 LDAP_LOG( ACL, DETAIL1,
1035 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1037 conn->c_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1039 Debug( LDAP_DEBUG_ACL,
1040 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1041 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1043 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1048 if ( b->a_authz.sai_sasl_ssf ) {
1050 LDAP_LOG( ACL, DETAIL1,
1051 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1053 conn->c_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1055 Debug( LDAP_DEBUG_ACL,
1056 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1057 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1059 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1064 #ifdef SLAPD_ACI_ENABLED
1065 if ( b->a_aci_at != NULL ) {
1067 slap_access_t grant, deny, tgrant, tdeny;
1069 /* this case works different from the others above.
1070 * since aci's themselves give permissions, we need
1071 * to first check b->a_access_mask, the ACL's access level.
1074 if ( e->e_nname.bv_len == 0 ) {
1075 /* no ACIs in the root DSE */
1079 /* first check if the right being requested
1080 * is allowed by the ACL clause.
1082 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1086 /* get the aci attribute */
1087 at = attr_find( e->e_attrs, b->a_aci_at );
1092 ACL_RECORD_VALUE_STATE;
1094 /* start out with nothing granted, nothing denied */
1098 /* the aci is an multi-valued attribute. The
1099 * rights are determined by OR'ing the individual
1100 * rights given by the acis.
1102 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1103 if (aci_mask( be, conn, op,
1104 e, desc, val, &at->a_vals[i],
1105 matches, &grant, &deny ) != 0)
1112 /* remove anything that the ACL clause does not allow */
1113 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1114 tdeny &= ACL_PRIV_MASK;
1116 /* see if we have anything to contribute */
1117 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1121 /* this could be improved by changing acl_mask so that it can deal with
1122 * by clauses that return grant/deny pairs. Right now, it does either
1123 * additive or subtractive rights, but not both at the same time. So,
1124 * we need to combine the grant/deny pair into a single rights mask in
1125 * a smart way: if either grant or deny is "empty", then we use the
1126 * opposite as is, otherwise we remove any denied rights from the grant
1127 * rights mask and construct an additive mask.
1129 if (ACL_IS_INVALID(tdeny)) {
1130 modmask = tgrant | ACL_PRIV_ADDITIVE;
1132 } else if (ACL_IS_INVALID(tgrant)) {
1133 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1136 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1142 modmask = b->a_access_mask;
1146 LDAP_LOG( ACL, RESULTS,
1147 "acl_mask: [%d] applying %s (%s)\n",
1148 i, accessmask2str( modmask, accessmaskbuf),
1149 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1150 ? "break" : "stop" );
1152 Debug( LDAP_DEBUG_ACL,
1153 "<= acl_mask: [%d] applying %s (%s)\n",
1154 i, accessmask2str( modmask, accessmaskbuf ),
1155 b->a_type == ACL_CONTINUE
1157 : b->a_type == ACL_BREAK
1164 if( ACL_IS_ADDITIVE(modmask) ) {
1166 ACL_PRIV_SET( *mask, modmask );
1169 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1171 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1172 /* substract privs */
1173 ACL_PRIV_CLR( *mask, modmask );
1176 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1184 LDAP_LOG( ACL, DETAIL1,
1185 "acl_mask: conn %lu [%d] mask: %s\n",
1186 conn->c_connid, i, accessmask2str( *mask, accessmaskbuf) );
1188 Debug( LDAP_DEBUG_ACL,
1189 "<= acl_mask: [%d] mask: %s\n",
1190 i, accessmask2str(*mask, accessmaskbuf), 0 );
1193 if( b->a_type == ACL_CONTINUE ) {
1196 } else if ( b->a_type == ACL_BREAK ) {
1204 /* implicit "by * none" clause */
1208 LDAP_LOG( ACL, RESULTS,
1209 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1210 conn->c_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1212 Debug( LDAP_DEBUG_ACL,
1213 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1214 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1220 * acl_check_modlist - check access control on the given entry to see if
1221 * it allows the given modifications by the user associated with op.
1222 * returns 1 if mods allowed ok
1223 * 0 mods not allowed
1232 Modifications *mlist
1236 AccessControlState state = ACL_STATE_INIT;
1238 assert( be != NULL );
1240 /* short circuit root database access */
1241 if ( be_isroot( be, &op->o_ndn ) ) {
1243 LDAP_LOG( ACL, DETAIL1,
1244 "acl_check_modlist: conn %lu access granted to root user\n",
1245 conn->c_connid, 0, 0 );
1247 Debug( LDAP_DEBUG_ACL,
1248 "<= acl_access_allowed: granted to database root\n",
1254 /* use backend default access if no backend acls */
1255 if( be != NULL && be->be_acl == NULL ) {
1257 LDAP_LOG( ACL, DETAIL1,
1258 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1259 access2str( ACL_WRITE ),
1260 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1263 Debug( LDAP_DEBUG_ACL,
1264 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1265 access2str( ACL_WRITE ),
1266 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1268 return be->be_dfltaccess >= ACL_WRITE;
1271 /* be is always non-NULL */
1272 /* use global default access if no global acls */
1273 } else if ( be == NULL && global_acl == NULL ) {
1275 LDAP_LOG( ACL, DETAIL1,
1276 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1277 access2str( ACL_WRITE ),
1278 global_default_access >= ACL_WRITE ? "granted" : "denied",
1281 Debug( LDAP_DEBUG_ACL,
1282 "=> access_allowed: global default %s access %s to \"%s\"\n",
1283 access2str( ACL_WRITE ),
1284 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1286 return global_default_access >= ACL_WRITE;
1290 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1292 * no-user-modification operational attributes are ignored
1293 * by ACL_WRITE checking as any found here are not provided
1296 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1298 LDAP_LOG( ACL, DETAIL1,
1299 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1300 conn->c_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1302 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1303 " modify access granted\n",
1304 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1309 switch ( mlist->sml_op ) {
1310 case LDAP_MOD_REPLACE:
1312 * We must check both permission to delete the whole
1313 * attribute and permission to add the specific attributes.
1314 * This prevents abuse from selfwriters.
1316 if ( ! access_allowed( be, conn, op, e,
1317 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1322 if ( mlist->sml_bvalues == NULL ) break;
1324 /* fall thru to check value to add */
1327 assert( mlist->sml_bvalues != NULL );
1329 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1330 if ( ! access_allowed( be, conn, op, e,
1331 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1338 case LDAP_MOD_DELETE:
1339 if ( mlist->sml_bvalues == NULL ) {
1340 if ( ! access_allowed( be, conn, op, e,
1341 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1347 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1348 if ( ! access_allowed( be, conn, op, e,
1349 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1356 case SLAP_MOD_SOFTADD:
1357 /* allow adding attribute via modrdn thru */
1371 struct berval *list,
1385 while (len >= 0 && --ix >= 0) {
1386 while (--len >= 0 && *p++ != sep) ;
1388 while (len >= 0 && *p == ' ') {
1399 while (--len >= 0 && *p != sep) {
1403 while (bv->bv_len > 0 && *--p == ' ')
1409 aci_set_gather (void *cookie, struct berval *name, struct berval *attr)
1411 AciSetCookie *cp = cookie;
1412 BerVarray bvals = NULL;
1415 /* this routine needs to return the bervals instead of
1416 * plain strings, since syntax is not known. It should
1417 * also return the syntax or some "comparison cookie".
1420 if (dnNormalize2(NULL, name, &ndn) == LDAP_SUCCESS) {
1422 AttributeDescription *desc = NULL;
1423 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1424 backend_attribute(cp->be, NULL, cp->op,
1425 cp->e, &ndn, desc, &bvals);
1434 struct berval *subj,
1442 struct berval set = { 0, NULL };
1444 AciSetCookie cookie;
1447 ber_dupbv( &set, subj );
1449 struct berval subjdn, ndn = { 0, NULL };
1450 struct berval setat;
1453 AttributeDescription *desc = NULL;
1455 /* format of string is "entry/setAttrName" */
1456 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1460 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1461 setat.bv_val = SLAPD_ACI_SET_ATTR;
1462 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1465 if ( setat.bv_val != NULL ) {
1467 * NOTE: dnNormalize2 honors the ber_len field
1468 * as the length of the dn to be normalized
1470 if ( dnNormalize2(NULL, &subjdn, &ndn) == LDAP_SUCCESS
1471 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1473 backend_attribute(be, NULL, op, e,
1474 &ndn, desc, &bvals);
1475 if ( bvals != NULL ) {
1476 if ( bvals[0].bv_val != NULL ) {
1479 bvals[0].bv_val = NULL;
1480 for (i=1;bvals[i].bv_val;i++);
1481 bvals[0].bv_val = bvals[i-1].bv_val;
1482 bvals[i-1].bv_val = NULL;
1484 ber_bvarray_free(bvals);
1492 if (set.bv_val != NULL) {
1497 rc = (slap_set_filter(aci_set_gather, &cookie, &set,
1498 &op->o_ndn, &e->e_nname, NULL) > 0);
1499 ch_free(set.bv_val);
1504 #ifdef SLAPD_ACI_ENABLED
1506 aci_list_map_rights(
1507 struct berval *list )
1514 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1517 switch (*bv.bv_val) {
1519 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1522 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1523 * the right 's' to mean "set", but in the examples states
1524 * that the right 's' means "search". The latter definition
1527 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1530 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1533 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1536 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1537 * define any equivalent to the AUTH right, so I've just used
1540 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1552 struct berval *list,
1553 const struct berval *attr,
1554 struct berval *val )
1556 struct berval bv, left, right;
1559 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1560 if (aci_get_part(&bv, 0, '=', &left) < 0
1561 || aci_get_part(&bv, 1, '=', &right) < 0)
1563 if (ber_bvstrcasecmp(attr, &bv) == 0)
1565 } else if (val == NULL) {
1566 if (ber_bvstrcasecmp(attr, &left) == 0)
1569 if (ber_bvstrcasecmp(attr, &left) == 0) {
1570 /* this is experimental code that implements a
1571 * simple (prefix) match of the attribute value.
1572 * the ACI draft does not provide for aci's that
1573 * apply to specific values, but it would be
1574 * nice to have. If the <attr> part of an aci's
1575 * rights list is of the form <attr>=<value>,
1576 * that means the aci applies only to attrs with
1577 * the given value. Furthermore, if the attr is
1578 * of the form <attr>=<value>*, then <value> is
1579 * treated as a prefix, and the aci applies to
1580 * any value with that prefix.
1582 * Ideally, this would allow r.e. matches.
1584 if (aci_get_part(&right, 0, '*', &left) < 0
1585 || right.bv_len <= left.bv_len)
1587 if (ber_bvstrcasecmp(val, &right) == 0)
1589 } else if (val->bv_len >= left.bv_len) {
1590 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1599 static slap_access_t
1600 aci_list_get_attr_rights(
1601 struct berval *list,
1602 const struct berval *attr,
1603 struct berval *val )
1609 /* loop through each rights/attr pair, skip first part (action) */
1611 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1612 if (aci_list_has_attr(&bv, attr, val) == 0)
1614 if (aci_get_part(list, i, ';', &bv) < 0)
1616 mask |= aci_list_map_rights(&bv);
1622 aci_list_get_rights(
1623 struct berval *list,
1624 const struct berval *attr,
1626 slap_access_t *grant,
1627 slap_access_t *deny )
1629 struct berval perm, actn;
1630 slap_access_t *mask;
1633 if (attr == NULL || attr->bv_len == 0
1634 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1635 attr = &aci_bv_br_entry;
1641 /* loop through each permissions clause */
1642 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1643 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1645 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1647 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1654 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1655 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1662 struct berval *subj,
1663 struct berval *defgrpoc,
1664 struct berval *defgrpat,
1672 struct berval subjdn;
1673 struct berval grpoc;
1674 struct berval grpat;
1675 ObjectClass *grp_oc = NULL;
1676 AttributeDescription *grp_ad = NULL;
1680 /* format of string is "group/objectClassValue/groupAttrName" */
1681 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1685 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1689 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1693 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1694 if( rc != LDAP_SUCCESS ) {
1700 grp_oc = oc_bvfind( &grpoc );
1702 if (grp_oc != NULL && grp_ad != NULL ) {
1703 char buf[ACL_BUF_SIZE];
1704 struct berval bv, ndn;
1705 bv.bv_len = sizeof( buf ) - 1;
1706 bv.bv_val = (char *)&buf;
1707 string_expand(&bv, &subjdn, e->e_ndn, matches);
1708 if ( dnNormalize2(NULL, &bv, &ndn) == LDAP_SUCCESS ) {
1709 rc = (backend_group(be, conn, op, e, &ndn, &op->o_ndn,
1710 grp_oc, grp_ad) == 0);
1725 AttributeDescription *desc,
1728 regmatch_t *matches,
1729 slap_access_t *grant,
1733 struct berval bv, perms, sdn;
1737 assert( desc->ad_cname.bv_val != NULL );
1739 /* parse an aci of the form:
1740 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1742 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1743 a full description of the format for this attribute.
1744 Differences: "this" in the draft is "self" here, and
1745 "self" and "public" is in the position of dnType.
1747 For now, this routine only supports scope=entry.
1750 /* check that the aci has all 5 components */
1751 if (aci_get_part(aci, 4, '#', NULL) < 0)
1754 /* check that the aci family is supported */
1755 if (aci_get_part(aci, 0, '#', &bv) < 0)
1758 /* check that the scope is "entry" */
1759 if (aci_get_part(aci, 1, '#', &bv) < 0
1760 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1765 /* get the list of permissions clauses, bail if empty */
1766 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1769 /* check if any permissions allow desired access */
1770 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1773 /* see if we have a DN match */
1774 if (aci_get_part(aci, 3, '#', &bv) < 0)
1777 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1780 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1783 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1784 if (dn_match( &op->o_ndn, &ndn))
1790 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1793 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1794 if (dn_match(&op->o_ndn, &e->e_nname))
1797 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1799 AttributeDescription *ad = NULL;
1802 rc = slap_bv2ad( &sdn, &ad, &text );
1804 if( rc != LDAP_SUCCESS ) {
1812 for(at = attrs_find( e->e_attrs, ad );
1814 at = attrs_find( at->a_next, ad ) )
1816 if (value_find_ex( ad, SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, at->a_vals, &bv) == 0 ) {
1825 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1826 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, be, e, conn, op, matches))
1829 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1830 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, be, e, conn, op, matches))
1833 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1834 if (aci_match_set(&sdn, be, e, conn, op, 0))
1837 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1838 if (aci_match_set(&sdn, be, e, conn, op, 1))
1846 #endif /* SLAPD_ACI_ENABLED */
1853 regmatch_t *matches)
1861 bv->bv_val[0] = '\0';
1862 bv->bv_len--; /* leave space for lone $ */
1865 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1866 sp < pat->bv_val + pat->bv_len ; sp++ )
1868 /* did we previously see a $ */
1870 if ( flag == 1 && *sp == '$' ) {
1875 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
1878 } else if ( *sp >= '0' && *sp <= '9' ) {
1886 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
1887 if ( *sp >= '0' && *sp <= '9' ) {
1888 n = 10*n + ( *sp - '0' );
1892 if ( *sp != /*'{'*/ '}' ) {
1897 if ( n >= MAXREMATCHES ) {
1902 i = matches[n].rm_so;
1903 l = matches[n].rm_eo;
1904 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1922 /* must have ended with a single $ */
1931 LDAP_LOG( ACL, DETAIL1,
1932 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1933 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
1935 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1936 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1942 struct berval *pat, /* pattern to expand and match against */
1943 char *str, /* string to match against pattern */
1944 char *buf, /* buffer with $N expansion variables */
1945 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1949 char newbuf[ACL_BUF_SIZE];
1953 bv.bv_len = sizeof(newbuf) - 1;
1956 if(str == NULL) str = "";
1958 string_expand(&bv, pat, buf, matches);
1959 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1960 char error[ACL_BUF_SIZE];
1961 regerror(rc, &re, error, sizeof(error));
1965 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
1966 pat->bv_val, str, error );
1968 Debug( LDAP_DEBUG_TRACE,
1969 "compile( \"%s\", \"%s\") failed %s\n",
1970 pat->bv_val, str, error );
1975 rc = regexec(&re, str, 0, NULL, 0);
1979 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
1980 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
1981 rc, rc ? "matches" : "no matches", 0 );
1983 Debug( LDAP_DEBUG_TRACE,
1984 "=> regex_matches: string: %s\n", str, 0, 0 );
1985 Debug( LDAP_DEBUG_TRACE,
1986 "=> regex_matches: rc: %d %s\n",
1987 rc, !rc ? "matches" : "no matches", 0 );