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( op && op->o_is_auth_check && (access == ACL_SEARCH || access == ACL_READ)) {
148 if( state && state->as_recorded && state->as_vd_ad==desc) {
149 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
152 return state->as_result;
154 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
155 val != NULL && state->as_vd_acl == NULL )
157 return state->as_result;
161 state->as_vd_ad=desc;
165 LDAP_LOG( ACL, ENTRY,
166 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
167 access2str( access ), e->e_dn, attr );
169 Debug( LDAP_DEBUG_ACL,
170 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
171 access2str( access ), e->e_dn, attr );
179 if ( be == NULL ) be = &backends[0];
180 assert( be != NULL );
182 /* grant database root access */
183 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
186 "access_allowed: conn %lu root access granted\n",
187 conn->c_connid, 0, 0 );
189 Debug( LDAP_DEBUG_ACL,
190 "<= root access granted\n",
197 * no-user-modification operational attributes are ignored
198 * by ACL_WRITE checking as any found here are not provided
201 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
202 && desc != slap_schema.si_ad_entry
203 && desc != slap_schema.si_ad_children )
206 LDAP_LOG( ACL, DETAIL1,
207 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
208 "access granted\n", conn->c_connid, attr , 0 );
210 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
211 " %s access granted\n",
217 /* use backend default access if no backend acls */
218 if( be != NULL && be->be_acl == NULL ) {
220 LDAP_LOG( ACL, DETAIL1,
221 "access_allowed: backend default %s access %s to \"%s\"\n",
222 access2str( access ),
223 be->be_dfltaccess >= access ? "granted" : "denied",
226 Debug( LDAP_DEBUG_ACL,
227 "=> access_allowed: backend default %s access %s to \"%s\"\n",
228 access2str( access ),
229 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
231 ret = be->be_dfltaccess >= access;
235 /* be is always non-NULL */
236 /* use global default access if no global acls */
237 } else if ( be == NULL && global_acl == NULL ) {
239 LDAP_LOG( ACL, DETAIL1,
240 "access_allowed: global default %s access %s to \"%s\"\n",
241 access2str( access ),
242 global_default_access >= access ? "granted" : "denied",
245 Debug( LDAP_DEBUG_ACL,
246 "=> access_allowed: global default %s access %s to \"%s\"\n",
247 access2str( access ),
248 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
250 ret = global_default_access >= access;
259 assert( state->as_vd_acl != NULL );
261 a = state->as_vd_acl;
262 mask = state->as_vd_acl_mask;
263 count = state->as_vd_acl_count;
264 AC_MEMCPY( matches, state->as_vd_acl_matches,
272 memset(matches, '\0', sizeof(matches));
275 while((a = acl_get( a, &count, be, op, e, desc,
276 MAXREMATCHES, matches )) != NULL)
280 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
282 LDAP_LOG( ACL, DETAIL1,
283 "access_allowed: match[%d]: %d %d ",
284 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
286 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
287 (int)matches[i].rm_so, (int)matches[i].rm_eo );
289 if( matches[i].rm_so <= matches[0].rm_eo ) {
291 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
292 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
296 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
298 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
303 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
304 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
305 return state->as_result;
306 } else if (!st_initialized) {
307 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
309 state->as_vd_ad=desc;
315 control = acl_mask( a, &mask, be, conn, op,
316 e, desc, val, matches, count, state );
318 if ( control != ACL_BREAK ) {
322 memset(matches, '\0', sizeof(matches));
325 if ( ACL_IS_INVALID( mask ) ) {
327 LDAP_LOG( ACL, DETAIL1,
328 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
329 conn->c_connid, e->e_dn, attr );
331 Debug( LDAP_DEBUG_ACL,
332 "=> access_allowed: \"%s\" (%s) invalid!\n",
337 } else if ( control == ACL_BREAK ) {
339 LDAP_LOG( ACL, DETAIL1,
340 "access_allowed: conn %lu no more rules\n", conn->c_connid, 0,0 );
342 Debug( LDAP_DEBUG_ACL,
343 "=> access_allowed: no more rules\n", 0, 0, 0);
350 LDAP_LOG( ACL, ENTRY,
351 "access_allowed: %s access %s by %s\n",
352 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
353 accessmask2str( mask, accessmaskbuf ) );
355 Debug( LDAP_DEBUG_ACL,
356 "=> access_allowed: %s access %s by %s\n",
357 access2str( access ),
358 ACL_GRANT(mask, access) ? "granted" : "denied",
359 accessmask2str( mask, accessmaskbuf ) );
362 ret = ACL_GRANT(mask, access);
365 if( state != NULL ) {
366 /* If not value-dependent, save ACL in case of more attrs */
367 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) )
368 state->as_vi_acl = a;
369 state->as_recorded |= ACL_STATE_RECORDED;
370 state->as_result = ret;
376 * acl_get - return the acl applicable to entry e, attribute
377 * attr. the acl returned is suitable for use in subsequent calls to
378 * acl_access_allowed().
381 static AccessControl *
388 AttributeDescription *desc,
390 regmatch_t *matches )
396 assert( count != NULL );
397 assert( desc != NULL );
399 attr = desc->ad_cname.bv_val;
401 assert( attr != NULL );
416 dnlen = e->e_nname.bv_len;
418 for ( ; a != NULL; a = a->acl_next ) {
421 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
422 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
424 LDAP_LOG( ACL, DETAIL1,
425 "acl_get: dnpat [%d] %s nsub: %d\n",
426 *count, a->acl_dn_pat.bv_val,
427 (int) a->acl_dn_re.re_nsub );
429 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
430 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
432 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
437 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
438 *count, a->acl_dn_pat.bv_val, 0 );
440 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
441 *count, a->acl_dn_pat.bv_val, 0 );
443 patlen = a->acl_dn_pat.bv_len;
444 if ( dnlen < patlen )
447 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
448 /* base dn -- entire object DN must match */
449 if ( dnlen != patlen )
452 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
455 if ( dnlen <= patlen )
458 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
461 rdnlen = dn_rdnlen( NULL, &e->e_nname );
462 if ( rdnlen != dnlen - patlen - 1 )
465 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
466 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
469 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
470 if ( dnlen <= patlen )
472 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
476 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
481 LDAP_LOG( ACL, DETAIL1,
482 "acl_get: [%d] matched\n", *count, 0, 0 );
484 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
489 if ( a->acl_filter != NULL ) {
490 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
491 if ( rc != LDAP_COMPARE_TRUE ) {
497 LDAP_LOG( ACL, DETAIL1,
498 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
500 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
503 if ( attr == NULL || a->acl_attrs == NULL ||
504 ad_inlist( desc, a->acl_attrs ) )
507 LDAP_LOG( ACL, DETAIL1,
508 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
510 Debug( LDAP_DEBUG_ACL,
511 "<= acl_get: [%d] acl %s attr: %s\n",
512 *count, e->e_dn, attr );
516 matches[0].rm_so = matches[0].rm_eo = -1;
520 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
522 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
528 * Record value-dependent access control state
530 #define ACL_RECORD_VALUE_STATE do { \
531 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
532 state->as_recorded |= ACL_STATE_RECORDED_VD; \
533 state->as_vd_acl = a; \
534 AC_MEMCPY( state->as_vd_acl_matches, matches, \
535 sizeof( state->as_vd_acl_matches )) ; \
536 state->as_vd_acl_count = count; \
537 state->as_vd_access = b; \
538 state->as_vd_access_count = i; \
543 * acl_mask - modifies mask based upon the given acl and the
544 * requested access to entry e, attribute attr, value val. if val
545 * is null, access to the whole attribute is assumed (all values).
547 * returns 0 access NOT allowed
551 static slap_control_t
559 AttributeDescription *desc,
563 AccessControlState *state )
565 int i, odnlen, patlen;
568 char accessmaskbuf[ACCESSMASK_MAXLEN];
573 assert( mask != NULL );
574 assert( desc != NULL );
576 attr = desc->ad_cname.bv_val;
578 assert( attr != NULL );
581 LDAP_LOG( ACL, ENTRY,
582 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
583 conn->c_connid, e->e_dn, attr );
586 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
587 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
588 accessmask2str( *mask, accessmaskbuf ) );
590 Debug( LDAP_DEBUG_ACL,
591 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
594 Debug( LDAP_DEBUG_ACL,
595 "=> acl_mask: to %s by \"%s\", (%s) \n",
596 val ? "value" : "all values",
597 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
598 accessmask2str( *mask, accessmaskbuf ) );
601 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
602 && state->as_vd_acl == a )
604 b = state->as_vd_access;
605 i = state->as_vd_access_count;
612 for ( ; b != NULL; b = b->a_next, i++ ) {
613 slap_mask_t oldmask, modmask;
615 ACL_INVALIDATE( modmask );
617 /* AND <who> clauses */
618 if ( b->a_dn_pat.bv_len != 0 ) {
620 LDAP_LOG( ACL, DETAIL1,
621 "acl_mask: conn %lu check a_dn_pat: %s\n",
622 conn->c_connid, b->a_dn_pat.bv_val ,0 );
624 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
625 b->a_dn_pat.bv_val, 0, 0);
628 * if access applies to the entry itself, and the
629 * user is bound as somebody in the same namespace as
630 * the entry, OR the given dn matches the dn pattern
632 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
633 if ( op->o_ndn.bv_len != 0 ) {
637 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
638 if ( op->o_ndn.bv_len == 0 ) {
642 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
643 if ( op->o_ndn.bv_len == 0 ) {
647 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
651 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
652 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
653 int ret = regex_matches( &b->a_dn_pat,
654 op->o_ndn.bv_val, e->e_ndn, matches );
665 if ( e->e_dn == NULL )
668 if ( b->a_dn_expand ) {
670 char buf[ACL_BUF_SIZE];
672 bv.bv_len = sizeof( buf ) - 1;
675 string_expand(&bv, &b->a_dn_pat,
677 if ( dnNormalize2(NULL, &bv, &pat) != LDAP_SUCCESS ) {
678 /* did not expand to a valid dn */
686 odnlen = op->o_ndn.bv_len;
687 if ( odnlen < patlen ) {
688 goto dn_match_cleanup;
692 if ( b->a_dn_style == ACL_STYLE_BASE ) {
693 /* base dn -- entire object DN must match */
694 if ( odnlen != patlen ) {
695 goto dn_match_cleanup;
698 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
701 if ( odnlen <= patlen ) {
702 goto dn_match_cleanup;
705 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
706 goto dn_match_cleanup;
709 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
710 if ( rdnlen != odnlen - patlen - 1 ) {
711 goto dn_match_cleanup;
714 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
715 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
716 goto dn_match_cleanup;
719 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
720 if ( odnlen <= patlen ) {
721 goto dn_match_cleanup;
724 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
725 goto dn_match_cleanup;
729 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
732 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
742 if ( b->a_sockurl_pat.bv_len ) {
743 if ( ! conn->c_listener ) {
747 LDAP_LOG( ACL, DETAIL1,
748 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
749 conn->c_connid, b->a_sockurl_pat.bv_val , 0 );
751 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
752 b->a_sockurl_pat.bv_val, 0, 0 );
755 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
756 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
757 if (!regex_matches( &b->a_sockurl_pat, conn->c_listener_url.bv_val,
758 e->e_ndn, matches ) )
763 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &conn->c_listener_url ) != 0 )
769 if ( b->a_domain_pat.bv_len ) {
770 if ( !conn->c_peer_domain.bv_val ) {
774 LDAP_LOG( ACL, DETAIL1,
775 "acl_mask: conn %lu check a_domain_pat: %s\n",
776 conn->c_connid, b->a_domain_pat.bv_val , 0 );
778 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
779 b->a_domain_pat.bv_val, 0, 0 );
781 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
782 if ( b->a_domain_style == ACL_STYLE_REGEX) {
783 if (!regex_matches( &b->a_domain_pat, conn->c_peer_domain.bv_val,
784 e->e_ndn, matches ) )
789 char buf[ACL_BUF_SIZE];
791 struct berval cmp = conn->c_peer_domain;
792 struct berval pat = b->a_domain_pat;
794 if ( b->a_domain_expand ) {
797 bv.bv_len = sizeof(buf) - 1;
800 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
804 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
805 int offset = cmp.bv_len - pat.bv_len;
810 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
814 /* trim the domain */
815 cmp.bv_val = &cmp.bv_val[ offset ];
816 cmp.bv_len -= offset;
819 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
826 if ( b->a_peername_pat.bv_len ) {
827 if ( !conn->c_peer_name.bv_val ) {
831 LDAP_LOG( ACL, DETAIL1,
832 "acl_mask: conn %lu check a_peername_path: %s\n",
833 conn->c_connid, b->a_peername_pat.bv_val , 0 );
835 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
836 b->a_peername_pat.bv_val, 0, 0 );
838 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
839 if ( b->a_peername_style == ACL_STYLE_REGEX) {
840 if (!regex_matches( &b->a_peername_pat, conn->c_peer_name.bv_val,
841 e->e_ndn, matches ) )
846 if ( ber_bvstrcasecmp( &b->a_peername_pat, &conn->c_peer_name ) != 0 )
852 if ( b->a_sockname_pat.bv_len ) {
853 if ( !conn->c_sock_name.bv_val ) {
857 LDAP_LOG( ACL, DETAIL1,
858 "acl_mask: conn %lu check a_sockname_path: %s\n",
859 conn->c_connid, b->a_sockname_pat.bv_val , 0 );
861 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
862 b->a_sockname_pat.bv_val, 0, 0 );
864 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
865 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
866 if (!regex_matches( &b->a_sockname_pat, conn->c_sock_name.bv_val,
867 e->e_ndn, matches ) )
872 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &conn->c_sock_name ) != 0 )
878 if ( b->a_dn_at != NULL ) {
883 const char *attr = b->a_dn_at->ad_cname.bv_val;
885 assert( attr != NULL );
887 if ( op->o_ndn.bv_len == 0 ) {
892 LDAP_LOG( ACL, DETAIL1,
893 "acl_mask: conn %lu check a_dn_pat: %s\n",
894 conn->c_connid, attr , 0 );
896 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
901 /* see if asker is listed in dnattr */
902 for( at = attrs_find( e->e_attrs, b->a_dn_at );
904 at = attrs_find( at->a_next, b->a_dn_at ) )
906 if( value_find_ex( b->a_dn_at,
907 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
908 at->a_vals, &bv ) == 0 )
917 /* have a dnattr match. if this is a self clause then
918 * the target must also match the op dn.
920 if ( b->a_dn_self ) {
921 /* check if the target is an attribute. */
922 if ( val == NULL ) continue;
924 /* target is attribute, check if the attribute value
927 rc = value_match( &match, b->a_dn_at,
928 b->a_dn_at->ad_type->sat_equality, 0,
930 /* on match error or no match, fail the ACL clause */
931 if (rc != LDAP_SUCCESS || match != 0 )
935 /* no dnattr match, check if this is a self clause */
936 if ( ! b->a_dn_self )
939 ACL_RECORD_VALUE_STATE;
941 /* this is a self clause, check if the target is an
947 /* target is attribute, check if the attribute value
950 rc = value_match( &match, b->a_dn_at,
951 b->a_dn_at->ad_type->sat_equality, 0,
954 /* on match error or no match, fail the ACL clause */
955 if (rc != LDAP_SUCCESS || match != 0 )
960 if ( b->a_group_pat.bv_len ) {
962 struct berval ndn = { 0, NULL };
965 if ( op->o_ndn.bv_len == 0 ) {
969 /* b->a_group is an unexpanded entry name, expanded it should be an
970 * entry with objectclass group* and we test to see if odn is one of
971 * the values in the attribute group
973 /* see if asker is listed in dnattr */
974 if ( b->a_group_style == ACL_STYLE_REGEX ) {
975 char buf[ACL_BUF_SIZE];
976 bv.bv_len = sizeof(buf) - 1;
979 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
980 if ( dnNormalize2( NULL, &bv, &ndn ) != LDAP_SUCCESS ) {
981 /* did not expand to a valid dn */
991 rc = backend_group( be, conn, op, e, &bv, &op->o_ndn,
992 b->a_group_oc, b->a_group_at );
994 if ( ndn.bv_val ) free( ndn.bv_val );
1001 if ( b->a_set_pat.bv_len != 0 ) {
1003 char buf[ACL_BUF_SIZE];
1004 if( b->a_set_style == ACL_STYLE_REGEX ){
1005 bv.bv_len = sizeof(buf) - 1;
1007 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1011 if (aci_match_set( &bv, be, e, conn, op, 0 ) == 0) {
1016 if ( b->a_authz.sai_ssf ) {
1018 LDAP_LOG( ACL, DETAIL1,
1019 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1020 conn->c_connid, b->a_authz.sai_ssf, op->o_ssf );
1022 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1023 b->a_authz.sai_ssf, op->o_ssf, 0 );
1025 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1030 if ( b->a_authz.sai_transport_ssf ) {
1032 LDAP_LOG( ACL, DETAIL1,
1033 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1035 conn->c_connid, b->a_authz.sai_transport_ssf,
1036 op->o_transport_ssf );
1038 Debug( LDAP_DEBUG_ACL,
1039 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1040 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1042 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1047 if ( b->a_authz.sai_tls_ssf ) {
1049 LDAP_LOG( ACL, DETAIL1,
1050 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1052 conn->c_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1054 Debug( LDAP_DEBUG_ACL,
1055 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1056 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1058 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1063 if ( b->a_authz.sai_sasl_ssf ) {
1065 LDAP_LOG( ACL, DETAIL1,
1066 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1068 conn->c_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1070 Debug( LDAP_DEBUG_ACL,
1071 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1072 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1074 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1079 #ifdef SLAPD_ACI_ENABLED
1080 if ( b->a_aci_at != NULL ) {
1082 slap_access_t grant, deny, tgrant, tdeny;
1084 /* this case works different from the others above.
1085 * since aci's themselves give permissions, we need
1086 * to first check b->a_access_mask, the ACL's access level.
1089 if ( e->e_nname.bv_len == 0 ) {
1090 /* no ACIs in the root DSE */
1094 /* first check if the right being requested
1095 * is allowed by the ACL clause.
1097 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1101 /* get the aci attribute */
1102 at = attr_find( e->e_attrs, b->a_aci_at );
1107 ACL_RECORD_VALUE_STATE;
1109 /* start out with nothing granted, nothing denied */
1113 /* the aci is an multi-valued attribute. The
1114 * rights are determined by OR'ing the individual
1115 * rights given by the acis.
1117 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1118 if (aci_mask( be, conn, op,
1119 e, desc, val, &at->a_vals[i],
1120 matches, &grant, &deny ) != 0)
1127 /* remove anything that the ACL clause does not allow */
1128 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1129 tdeny &= ACL_PRIV_MASK;
1131 /* see if we have anything to contribute */
1132 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1136 /* this could be improved by changing acl_mask so that it can deal with
1137 * by clauses that return grant/deny pairs. Right now, it does either
1138 * additive or subtractive rights, but not both at the same time. So,
1139 * we need to combine the grant/deny pair into a single rights mask in
1140 * a smart way: if either grant or deny is "empty", then we use the
1141 * opposite as is, otherwise we remove any denied rights from the grant
1142 * rights mask and construct an additive mask.
1144 if (ACL_IS_INVALID(tdeny)) {
1145 modmask = tgrant | ACL_PRIV_ADDITIVE;
1147 } else if (ACL_IS_INVALID(tgrant)) {
1148 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1151 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1157 modmask = b->a_access_mask;
1161 LDAP_LOG( ACL, RESULTS,
1162 "acl_mask: [%d] applying %s (%s)\n",
1163 i, accessmask2str( modmask, accessmaskbuf),
1164 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1165 ? "break" : "stop" );
1167 Debug( LDAP_DEBUG_ACL,
1168 "<= acl_mask: [%d] applying %s (%s)\n",
1169 i, accessmask2str( modmask, accessmaskbuf ),
1170 b->a_type == ACL_CONTINUE
1172 : b->a_type == ACL_BREAK
1179 if( ACL_IS_ADDITIVE(modmask) ) {
1181 ACL_PRIV_SET( *mask, modmask );
1184 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1186 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1187 /* substract privs */
1188 ACL_PRIV_CLR( *mask, modmask );
1191 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1199 LDAP_LOG( ACL, DETAIL1,
1200 "acl_mask: conn %lu [%d] mask: %s\n",
1201 conn->c_connid, i, accessmask2str( *mask, accessmaskbuf) );
1203 Debug( LDAP_DEBUG_ACL,
1204 "<= acl_mask: [%d] mask: %s\n",
1205 i, accessmask2str(*mask, accessmaskbuf), 0 );
1208 if( b->a_type == ACL_CONTINUE ) {
1211 } else if ( b->a_type == ACL_BREAK ) {
1219 /* implicit "by * none" clause */
1223 LDAP_LOG( ACL, RESULTS,
1224 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1225 conn->c_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1227 Debug( LDAP_DEBUG_ACL,
1228 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1229 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1235 * acl_check_modlist - check access control on the given entry to see if
1236 * it allows the given modifications by the user associated with op.
1237 * returns 1 if mods allowed ok
1238 * 0 mods not allowed
1247 Modifications *mlist
1251 AccessControlState state = ACL_STATE_INIT;
1253 assert( be != NULL );
1255 /* short circuit root database access */
1256 if ( be_isroot( be, &op->o_ndn ) ) {
1258 LDAP_LOG( ACL, DETAIL1,
1259 "acl_check_modlist: conn %lu access granted to root user\n",
1260 conn->c_connid, 0, 0 );
1262 Debug( LDAP_DEBUG_ACL,
1263 "<= acl_access_allowed: granted to database root\n",
1269 /* use backend default access if no backend acls */
1270 if( be != NULL && be->be_acl == NULL ) {
1272 LDAP_LOG( ACL, DETAIL1,
1273 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1274 access2str( ACL_WRITE ),
1275 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1278 Debug( LDAP_DEBUG_ACL,
1279 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1280 access2str( ACL_WRITE ),
1281 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1283 return be->be_dfltaccess >= ACL_WRITE;
1286 /* be is always non-NULL */
1287 /* use global default access if no global acls */
1288 } else if ( be == NULL && global_acl == NULL ) {
1290 LDAP_LOG( ACL, DETAIL1,
1291 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1292 access2str( ACL_WRITE ),
1293 global_default_access >= ACL_WRITE ? "granted" : "denied",
1296 Debug( LDAP_DEBUG_ACL,
1297 "=> access_allowed: global default %s access %s to \"%s\"\n",
1298 access2str( ACL_WRITE ),
1299 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1301 return global_default_access >= ACL_WRITE;
1305 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1307 * no-user-modification operational attributes are ignored
1308 * by ACL_WRITE checking as any found here are not provided
1311 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1313 LDAP_LOG( ACL, DETAIL1,
1314 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1315 conn->c_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1317 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1318 " modify access granted\n",
1319 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1324 switch ( mlist->sml_op ) {
1325 case LDAP_MOD_REPLACE:
1327 * We must check both permission to delete the whole
1328 * attribute and permission to add the specific attributes.
1329 * This prevents abuse from selfwriters.
1331 if ( ! access_allowed( be, conn, op, e,
1332 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1337 if ( mlist->sml_bvalues == NULL ) break;
1339 /* fall thru to check value to add */
1342 assert( mlist->sml_bvalues != NULL );
1344 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1345 if ( ! access_allowed( be, conn, 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( be, conn, op, e,
1356 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1362 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1363 if ( ! access_allowed( be, conn, op, e,
1364 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1371 case SLAP_MOD_SOFTADD:
1372 /* allow adding attribute via modrdn thru */
1386 struct berval *list,
1400 while (len >= 0 && --ix >= 0) {
1401 while (--len >= 0 && *p++ != sep) ;
1403 while (len >= 0 && *p == ' ') {
1414 while (--len >= 0 && *p != sep) {
1418 while (bv->bv_len > 0 && *--p == ' ')
1424 aci_set_gather (void *cookie, struct berval *name, struct berval *attr)
1426 AciSetCookie *cp = cookie;
1427 BerVarray bvals = NULL;
1430 /* this routine needs to return the bervals instead of
1431 * plain strings, since syntax is not known. It should
1432 * also return the syntax or some "comparison cookie".
1435 if (dnNormalize2(NULL, name, &ndn) == LDAP_SUCCESS) {
1437 AttributeDescription *desc = NULL;
1438 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1439 backend_attribute(cp->be, NULL, cp->op,
1440 cp->e, &ndn, desc, &bvals);
1449 struct berval *subj,
1457 struct berval set = { 0, NULL };
1459 AciSetCookie cookie;
1462 ber_dupbv( &set, subj );
1464 struct berval subjdn, ndn = { 0, NULL };
1465 struct berval setat;
1468 AttributeDescription *desc = NULL;
1470 /* format of string is "entry/setAttrName" */
1471 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1475 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1476 setat.bv_val = SLAPD_ACI_SET_ATTR;
1477 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1480 if ( setat.bv_val != NULL ) {
1482 * NOTE: dnNormalize2 honors the ber_len field
1483 * as the length of the dn to be normalized
1485 if ( dnNormalize2(NULL, &subjdn, &ndn) == LDAP_SUCCESS
1486 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1488 backend_attribute(be, NULL, op, e,
1489 &ndn, desc, &bvals);
1490 if ( bvals != NULL ) {
1491 if ( bvals[0].bv_val != NULL ) {
1494 bvals[0].bv_val = NULL;
1495 for (i=1;bvals[i].bv_val;i++);
1496 bvals[0].bv_val = bvals[i-1].bv_val;
1497 bvals[i-1].bv_val = NULL;
1499 ber_bvarray_free(bvals);
1507 if (set.bv_val != NULL) {
1512 rc = (slap_set_filter(aci_set_gather, &cookie, &set,
1513 &op->o_ndn, &e->e_nname, NULL) > 0);
1514 ch_free(set.bv_val);
1519 #ifdef SLAPD_ACI_ENABLED
1521 aci_list_map_rights(
1522 struct berval *list )
1529 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1532 switch (*bv.bv_val) {
1534 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1537 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1538 * the right 's' to mean "set", but in the examples states
1539 * that the right 's' means "search". The latter definition
1542 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1545 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1548 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1551 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1552 * define any equivalent to the AUTH right, so I've just used
1555 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1567 struct berval *list,
1568 const struct berval *attr,
1569 struct berval *val )
1571 struct berval bv, left, right;
1574 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1575 if (aci_get_part(&bv, 0, '=', &left) < 0
1576 || aci_get_part(&bv, 1, '=', &right) < 0)
1578 if (ber_bvstrcasecmp(attr, &bv) == 0)
1580 } else if (val == NULL) {
1581 if (ber_bvstrcasecmp(attr, &left) == 0)
1584 if (ber_bvstrcasecmp(attr, &left) == 0) {
1585 /* this is experimental code that implements a
1586 * simple (prefix) match of the attribute value.
1587 * the ACI draft does not provide for aci's that
1588 * apply to specific values, but it would be
1589 * nice to have. If the <attr> part of an aci's
1590 * rights list is of the form <attr>=<value>,
1591 * that means the aci applies only to attrs with
1592 * the given value. Furthermore, if the attr is
1593 * of the form <attr>=<value>*, then <value> is
1594 * treated as a prefix, and the aci applies to
1595 * any value with that prefix.
1597 * Ideally, this would allow r.e. matches.
1599 if (aci_get_part(&right, 0, '*', &left) < 0
1600 || right.bv_len <= left.bv_len)
1602 if (ber_bvstrcasecmp(val, &right) == 0)
1604 } else if (val->bv_len >= left.bv_len) {
1605 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1614 static slap_access_t
1615 aci_list_get_attr_rights(
1616 struct berval *list,
1617 const struct berval *attr,
1618 struct berval *val )
1624 /* loop through each rights/attr pair, skip first part (action) */
1626 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1627 if (aci_list_has_attr(&bv, attr, val) == 0)
1629 if (aci_get_part(list, i, ';', &bv) < 0)
1631 mask |= aci_list_map_rights(&bv);
1637 aci_list_get_rights(
1638 struct berval *list,
1639 const struct berval *attr,
1641 slap_access_t *grant,
1642 slap_access_t *deny )
1644 struct berval perm, actn;
1645 slap_access_t *mask;
1648 if (attr == NULL || attr->bv_len == 0
1649 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1650 attr = &aci_bv_br_entry;
1656 /* loop through each permissions clause */
1657 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1658 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1660 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1662 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1669 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1670 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1677 struct berval *subj,
1678 struct berval *defgrpoc,
1679 struct berval *defgrpat,
1687 struct berval subjdn;
1688 struct berval grpoc;
1689 struct berval grpat;
1690 ObjectClass *grp_oc = NULL;
1691 AttributeDescription *grp_ad = NULL;
1695 /* format of string is "group/objectClassValue/groupAttrName" */
1696 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1700 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1704 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1708 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1709 if( rc != LDAP_SUCCESS ) {
1715 grp_oc = oc_bvfind( &grpoc );
1717 if (grp_oc != NULL && grp_ad != NULL ) {
1718 char buf[ACL_BUF_SIZE];
1719 struct berval bv, ndn;
1720 bv.bv_len = sizeof( buf ) - 1;
1721 bv.bv_val = (char *)&buf;
1722 string_expand(&bv, &subjdn, e->e_ndn, matches);
1723 if ( dnNormalize2(NULL, &bv, &ndn) == LDAP_SUCCESS ) {
1724 rc = (backend_group(be, conn, op, e, &ndn, &op->o_ndn,
1725 grp_oc, grp_ad) == 0);
1740 AttributeDescription *desc,
1743 regmatch_t *matches,
1744 slap_access_t *grant,
1748 struct berval bv, perms, sdn;
1752 assert( desc->ad_cname.bv_val != NULL );
1754 /* parse an aci of the form:
1755 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1757 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1758 a full description of the format for this attribute.
1759 Differences: "this" in the draft is "self" here, and
1760 "self" and "public" is in the position of dnType.
1762 For now, this routine only supports scope=entry.
1765 /* check that the aci has all 5 components */
1766 if (aci_get_part(aci, 4, '#', NULL) < 0)
1769 /* check that the aci family is supported */
1770 if (aci_get_part(aci, 0, '#', &bv) < 0)
1773 /* check that the scope is "entry" */
1774 if (aci_get_part(aci, 1, '#', &bv) < 0
1775 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1780 /* get the list of permissions clauses, bail if empty */
1781 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1784 /* check if any permissions allow desired access */
1785 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1788 /* see if we have a DN match */
1789 if (aci_get_part(aci, 3, '#', &bv) < 0)
1792 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1795 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1798 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1799 if (dn_match( &op->o_ndn, &ndn))
1805 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1808 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1809 if (dn_match(&op->o_ndn, &e->e_nname))
1812 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1814 AttributeDescription *ad = NULL;
1817 rc = slap_bv2ad( &sdn, &ad, &text );
1819 if( rc != LDAP_SUCCESS ) {
1827 for(at = attrs_find( e->e_attrs, ad );
1829 at = attrs_find( at->a_next, ad ) )
1831 if (value_find_ex( ad, SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, at->a_vals, &bv) == 0 ) {
1840 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1841 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, be, e, conn, op, 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, be, e, conn, op, matches))
1848 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1849 if (aci_match_set(&sdn, be, e, conn, op, 0))
1852 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1853 if (aci_match_set(&sdn, be, e, conn, op, 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 );