1 /* acl.c - routines to parse and check acl's */
4 * Copyright 1998-2002 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 */
27 aci_bv_entry = BER_BVC("entry"),
28 aci_bv_br_entry = BER_BVC("[entry]"),
29 aci_bv_br_all = BER_BVC("[all]"),
30 aci_bv_access_id = BER_BVC("access-id"),
31 aci_bv_anonymous = BER_BVC("anonymous"),
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 static AccessControl * acl_get(
43 AccessControl *ac, int *count,
44 Backend *be, Operation *op,
46 AttributeDescription *desc,
47 int nmatches, regmatch_t *matches );
49 static slap_control_t acl_mask(
50 AccessControl *ac, slap_mask_t *mask,
51 Backend *be, Connection *conn, Operation *op,
53 AttributeDescription *desc,
57 AccessControlState *state );
59 #ifdef SLAPD_ACI_ENABLED
65 AttributeDescription *desc,
70 slap_access_t *deny );
73 static int regex_matches(
74 struct berval *pat, char *str, char *buf, regmatch_t *matches);
75 static void string_expand(
76 struct berval *newbuf, struct berval *pattern,
77 char *match, regmatch_t *matches);
79 typedef struct AciSetCookie {
86 SLAP_SET_GATHER aci_set_gather;
87 static int aci_match_set ( struct berval *subj, Backend *be,
88 Entry *e, Connection *conn, Operation *op, int setref );
91 * access_allowed - check whether op->o_ndn is allowed the requested access
92 * to entry e, attribute attr, value val. if val is null, access to
93 * the whole attribute is assumed (all values).
95 * This routine loops through all access controls and calls
96 * acl_mask() on each applicable access control.
97 * The loop exits when a definitive answer is reached or
98 * or no more controls remain.
111 AttributeDescription *desc,
113 slap_access_t access,
114 AccessControlState *state )
120 char accessmaskbuf[ACCESSMASK_MAXLEN];
123 slap_control_t control;
125 regmatch_t matches[MAXREMATCHES];
128 assert( desc != NULL );
129 assert( access > ACL_NONE );
131 attr = desc->ad_cname.bv_val;
133 assert( attr != NULL );
135 if( state && state->as_recorded ) {
136 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
139 return state->as_result;
141 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
142 val != NULL && state->as_vd_acl == NULL )
144 return state->as_result;
149 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
150 "access_allowed: conn %lu %s access to \"%s\" \"%s\" requested\n",
151 conn ? conn->c_connid : -1, access2str( access ), e->e_dn, attr ));
153 Debug( LDAP_DEBUG_ACL,
154 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
155 access2str( access ), e->e_dn, attr );
163 if ( be == NULL ) be = &backends[0];
164 assert( be != NULL );
166 /* grant database root access */
167 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
169 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
170 "access_allowed: conn %lu root access granted\n",
173 Debug( LDAP_DEBUG_ACL,
174 "<= root access granted\n",
181 * no-user-modification operational attributes are ignored
182 * by ACL_WRITE checking as any found here are not provided
185 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
186 && desc != slap_schema.si_ad_entry
187 && desc != slap_schema.si_ad_children )
190 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
191 "access_allowed: conn %lu NoUserMod Operational attribute: %s access granted\n",
192 conn->c_connid, attr ));
194 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
195 " %s access granted\n",
201 /* use backend default access if no backend acls */
202 if( be != NULL && be->be_acl == NULL ) {
204 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
205 "access_allowed: conn %lu backend default %s access %s to \"%s\"\n",
206 conn->c_connid, access2str( access ),
207 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val ));
209 Debug( LDAP_DEBUG_ACL,
210 "=> access_allowed: backend default %s access %s to \"%s\"\n",
211 access2str( access ),
212 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
214 ret = be->be_dfltaccess >= access;
218 /* be is always non-NULL */
219 /* use global default access if no global acls */
220 } else if ( be == NULL && global_acl == NULL ) {
222 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
223 "access_allowed: conn %lu global default %s access %s to \"%s\"\n",
224 conn->c_connid, access2str( access ),
225 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val ));
227 Debug( LDAP_DEBUG_ACL,
228 "=> access_allowed: global default %s access %s to \"%s\"\n",
229 access2str( access ),
230 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
232 ret = global_default_access >= access;
240 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )) {
241 assert( state->as_vd_acl != NULL );
243 a = state->as_vd_acl;
244 mask = state->as_vd_acl_mask;
245 count = state->as_vd_acl_count;
246 AC_MEMCPY( matches, state->as_vd_acl_matches,
254 memset(matches, '\0', sizeof(matches));
257 while((a = acl_get( a, &count, be, op, e, desc,
258 MAXREMATCHES, matches )) != NULL)
262 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
264 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
265 "access_allowed: conn %lu match[%d]: %d %d ",
267 (int)matches[i].rm_so, (int)matches[i].rm_eo ));
269 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
270 (int)matches[i].rm_so, (int)matches[i].rm_eo );
272 if( matches[i].rm_so <= matches[0].rm_eo ) {
274 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
275 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
279 LDAP_LOG(( "acl", LDAP_LEVEL_ARGS, "\n" ));
281 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
286 control = acl_mask( a, &mask, be, conn, op,
287 e, desc, val, matches, count, state );
289 if ( control != ACL_BREAK ) {
293 memset(matches, '\0', sizeof(matches));
296 if ( ACL_IS_INVALID( mask ) ) {
298 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
299 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
300 conn->c_connid, e->e_dn, attr ));
302 Debug( LDAP_DEBUG_ACL,
303 "=> access_allowed: \"%s\" (%s) invalid!\n",
308 } else if ( control == ACL_BREAK ) {
310 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
311 "access_allowed: conn %lu no more rules\n",
314 Debug( LDAP_DEBUG_ACL,
315 "=> access_allowed: no more rules\n", 0, 0, 0);
322 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
323 "access_allowed: conn %lu %s access %s by %s\n",
325 access2str( access ),
326 ACL_GRANT( mask, access ) ? "granted" : "denied",
327 accessmask2str( mask, accessmaskbuf ) ));
329 Debug( LDAP_DEBUG_ACL,
330 "=> access_allowed: %s access %s by %s\n",
331 access2str( access ),
332 ACL_GRANT(mask, access) ? "granted" : "denied",
333 accessmask2str( mask, accessmaskbuf ) );
336 ret = ACL_GRANT(mask, access);
339 if( state != NULL ) {
340 state->as_recorded |= ACL_STATE_RECORDED;
341 state->as_result = ret;
347 * acl_get - return the acl applicable to entry e, attribute
348 * attr. the acl returned is suitable for use in subsequent calls to
349 * acl_access_allowed().
352 static AccessControl *
359 AttributeDescription *desc,
361 regmatch_t *matches )
367 assert( count != NULL );
368 assert( desc != NULL );
370 attr = desc->ad_cname.bv_val;
372 assert( attr != NULL );
387 dnlen = e->e_nname.bv_len;
389 for ( ; a != NULL; a = a->acl_next ) {
392 if (a->acl_dn_pat.bv_len != 0) {
393 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
395 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
396 "acl_get: dnpat [%d] %s nsub: %d\n",
397 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub ));
399 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
400 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
402 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
407 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
408 "acl_get: dn [%d] %s\n",
409 *count, a->acl_dn_pat.bv_val ));
411 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
412 *count, a->acl_dn_pat.bv_val, 0 );
414 patlen = a->acl_dn_pat.bv_len;
415 if ( dnlen < patlen )
418 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
419 /* base dn -- entire object DN must match */
420 if ( dnlen != patlen )
423 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
426 if ( dnlen <= patlen )
429 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
432 rdnlen = dn_rdnlen( NULL, &e->e_nname );
433 if ( rdnlen != dnlen - patlen - 1 )
436 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
437 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
440 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
441 if ( dnlen <= patlen )
443 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
447 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
452 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
453 "acl_get: [%d] matched\n",
456 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
461 if ( a->acl_filter != NULL ) {
462 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
463 if ( rc != LDAP_COMPARE_TRUE ) {
469 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
470 "acl_get: [%d] check attr %s\n",
473 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
476 if ( attr == NULL || a->acl_attrs == NULL ||
477 ad_inlist( desc, a->acl_attrs ) )
480 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
481 "acl_get: [%d] acl %s attr: %s\n",
482 *count, e->e_dn, attr ));
484 Debug( LDAP_DEBUG_ACL,
485 "<= acl_get: [%d] acl %s attr: %s\n",
486 *count, e->e_dn, attr );
490 matches[0].rm_so = matches[0].rm_eo = -1;
494 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
495 "acl_get: done.\n" ));
497 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
503 * Record value-dependent access control state
505 #define ACL_RECORD_VALUE_STATE do { \
506 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
507 state->as_recorded |= ACL_STATE_RECORDED_VD; \
508 state->as_vd_acl = a; \
509 AC_MEMCPY( state->as_vd_acl_matches, matches, \
510 sizeof( state->as_vd_acl_matches )) ; \
511 state->as_vd_acl_count = count; \
512 state->as_vd_access = b; \
513 state->as_vd_access_count = i; \
518 * acl_mask - modifies mask based upon the given acl and the
519 * requested access to entry e, attribute attr, value val. if val
520 * is null, access to the whole attribute is assumed (all values).
522 * returns 0 access NOT allowed
526 static slap_control_t
534 AttributeDescription *desc,
538 AccessControlState *state )
540 int i, odnlen, patlen;
543 char accessmaskbuf[ACCESSMASK_MAXLEN];
548 assert( mask != NULL );
549 assert( desc != NULL );
551 attr = desc->ad_cname.bv_val;
553 assert( attr != NULL );
556 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
557 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
558 conn->c_connid, e->e_dn, attr ));
560 LDAP_LOG(( "acl", LDAP_LEVEL_ARGS,
561 " to %s by \"%s\", (%s) \n",
562 val ? "value" : "all values",
563 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
564 accessmask2str( *mask, accessmaskbuf ) ));
566 Debug( LDAP_DEBUG_ACL,
567 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
570 Debug( LDAP_DEBUG_ACL,
571 "=> acl_mask: to %s by \"%s\", (%s) \n",
572 val ? "value" : "all values",
573 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
574 accessmask2str( *mask, accessmaskbuf ) );
577 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
578 && state->as_vd_acl == a )
580 b = state->as_vd_access;
581 i = state->as_vd_access_count;
588 for ( ; b != NULL; b = b->a_next, i++ ) {
589 slap_mask_t oldmask, modmask;
591 ACL_INVALIDATE( modmask );
593 /* AND <who> clauses */
594 if ( b->a_dn_pat.bv_len != 0 ) {
596 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
597 "acl_mask: conn %lu check a_dn_pat: %s\n",
598 conn->c_connid, b->a_dn_pat.bv_val ));
600 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
601 b->a_dn_pat.bv_val, 0, 0);
604 * if access applies to the entry itself, and the
605 * user is bound as somebody in the same namespace as
606 * the entry, OR the given dn matches the dn pattern
608 if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_anonymous ) == 0 ) {
609 if ( op->o_ndn.bv_len != 0 ) {
613 } else if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_users ) == 0 ) {
614 if ( op->o_ndn.bv_len == 0 ) {
618 } else if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_self ) == 0 ) {
619 if ( op->o_ndn.bv_len == 0 ) {
623 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
627 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
628 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
629 int ret = regex_matches( &b->a_dn_pat,
630 op->o_ndn.bv_val, e->e_ndn, matches );
641 if ( e->e_dn == NULL )
644 if ( b->a_dn_expand ) {
646 char buf[ACL_BUF_SIZE];
648 bv.bv_len = sizeof( buf ) - 1;
651 string_expand(&bv, &b->a_dn_pat,
653 if ( dnNormalize2(NULL, &bv, &pat) != LDAP_SUCCESS ) {
654 /* did not expand to a valid dn */
662 odnlen = op->o_ndn.bv_len;
663 if ( odnlen < patlen ) {
664 goto dn_match_cleanup;
668 if ( b->a_dn_style == ACL_STYLE_BASE ) {
669 /* base dn -- entire object DN must match */
670 if ( odnlen != patlen ) {
671 goto dn_match_cleanup;
674 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
677 if ( odnlen <= patlen ) {
678 goto dn_match_cleanup;
681 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
682 goto dn_match_cleanup;
685 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
686 if ( rdnlen != odnlen - patlen - 1 ) {
687 goto dn_match_cleanup;
690 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
691 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
692 goto dn_match_cleanup;
695 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
696 if ( odnlen <= patlen ) {
697 goto dn_match_cleanup;
700 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
701 goto dn_match_cleanup;
705 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
708 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
718 if ( b->a_sockurl_pat.bv_len ) {
720 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
721 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
722 conn->c_connid, b->a_sockurl_pat.bv_val ));
724 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
725 b->a_sockurl_pat.bv_val, 0, 0 );
728 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
729 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
730 if (!regex_matches( &b->a_sockurl_pat, conn->c_listener_url.bv_val,
731 e->e_ndn, matches ) )
736 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &conn->c_listener_url ) != 0 )
742 if ( b->a_domain_pat.bv_len ) {
744 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
745 "acl_mask: conn %lu check a_domain_pat: %s\n",
746 conn->c_connid, b->a_domain_pat.bv_val ));
748 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
749 b->a_domain_pat.bv_val, 0, 0 );
751 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
752 if ( b->a_domain_style == ACL_STYLE_REGEX) {
753 if (!regex_matches( &b->a_domain_pat, conn->c_peer_domain.bv_val,
754 e->e_ndn, matches ) )
759 char buf[ACL_BUF_SIZE];
761 struct berval cmp = conn->c_peer_domain;
762 struct berval pat = b->a_domain_pat;
764 if ( b->a_domain_expand ) {
767 bv.bv_len = sizeof(buf);
770 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
774 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
775 int offset = cmp.bv_len - pat.bv_len;
780 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
784 /* trim the domain */
785 cmp.bv_val = &cmp.bv_val[ offset ];
786 cmp.bv_len -= offset;
789 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
796 if ( b->a_peername_pat.bv_len ) {
798 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
799 "acl_mask: conn %lu check a_perrname_path: %s\n",
800 conn->c_connid, b->a_peername_pat.bv_val ));
802 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
803 b->a_peername_pat.bv_val, 0, 0 );
805 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
806 if ( b->a_peername_style == ACL_STYLE_REGEX) {
807 if (!regex_matches( &b->a_peername_pat, conn->c_peer_name.bv_val,
808 e->e_ndn, matches ) )
813 if ( ber_bvstrcasecmp( &b->a_peername_pat, &conn->c_peer_name ) != 0 )
819 if ( b->a_sockname_pat.bv_len ) {
821 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
822 "acl_mask: conn %lu check a_sockname_path: %s\n",
823 conn->c_connid, b->a_sockname_pat.bv_val ));
825 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
826 b->a_sockname_pat.bv_val, 0, 0 );
828 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
829 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
830 if (!regex_matches( &b->a_sockname_pat, conn->c_sock_name.bv_val,
831 e->e_ndn, matches ) )
836 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &conn->c_sock_name ) != 0 )
842 if ( b->a_dn_at != NULL ) {
847 const char *attr = b->a_dn_at->ad_cname.bv_val;
849 assert( attr != NULL );
851 if ( op->o_ndn.bv_len == 0 ) {
856 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
857 "acl_mask: conn %lu check a_dn_pat: %s\n",
858 conn->c_connid, attr ));
860 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
865 /* see if asker is listed in dnattr */
866 for( at = attrs_find( e->e_attrs, b->a_dn_at );
868 at = attrs_find( at->a_next, b->a_dn_at ) )
870 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
878 /* have a dnattr match. if this is a self clause then
879 * the target must also match the op dn.
881 if ( b->a_dn_self ) {
882 /* check if the target is an attribute. */
885 /* target is attribute, check if the attribute value
888 rc = value_match( &match, b->a_dn_at,
889 b->a_dn_at->ad_type->sat_equality, 0,
891 /* on match error or no match, fail the ACL clause */
892 if (rc != LDAP_SUCCESS || match != 0 )
896 /* no dnattr match, check if this is a self clause */
897 if ( ! b->a_dn_self )
900 ACL_RECORD_VALUE_STATE;
902 /* this is a self clause, check if the target is an
908 /* target is attribute, check if the attribute value
911 rc = value_match( &match, b->a_dn_at,
912 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 )
921 if ( b->a_group_pat.bv_len ) {
922 char buf[ACL_BUF_SIZE];
924 struct berval ndn = { 0, NULL };
927 if ( op->o_ndn.bv_len == 0 ) {
931 bv.bv_len = sizeof(buf) - 1;
934 /* b->a_group is an unexpanded entry name, expanded it should be an
935 * entry with objectclass group* and we test to see if odn is one of
936 * the values in the attribute group
938 /* see if asker is listed in dnattr */
939 if ( b->a_group_style == ACL_STYLE_REGEX ) {
940 string_expand(&bv, &b->a_group_pat, e->e_ndn, matches);
941 if ( dnNormalize2(NULL, &bv, &ndn) != LDAP_SUCCESS ) {
942 /* did not expand to a valid dn */
950 rc = backend_group(be, conn, op, e, &bv, &op->o_ndn,
951 b->a_group_oc, b->a_group_at);
959 if ( b->a_set_pat.bv_len != 0 ) {
960 if (aci_match_set( &b->a_set_pat, be, e, conn, op, 0 ) == 0) {
965 if ( b->a_authz.sai_ssf ) {
967 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
968 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
969 conn->c_connid, b->a_authz.sai_ssf, op->o_ssf ));
971 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
972 b->a_authz.sai_ssf, op->o_ssf, 0 );
974 if ( b->a_authz.sai_ssf > op->o_ssf ) {
979 if ( b->a_authz.sai_transport_ssf ) {
981 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
982 "acl_mask: conn %lu check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
983 conn->c_connid, b->a_authz.sai_transport_ssf, op->o_transport_ssf ));
985 Debug( LDAP_DEBUG_ACL,
986 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
987 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
989 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
994 if ( b->a_authz.sai_tls_ssf ) {
996 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
997 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
998 conn->c_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf ));
1000 Debug( LDAP_DEBUG_ACL,
1001 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1002 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1004 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1009 if ( b->a_authz.sai_sasl_ssf ) {
1011 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
1012 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1013 conn->c_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf ));
1015 Debug( LDAP_DEBUG_ACL,
1016 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1017 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1019 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1024 #ifdef SLAPD_ACI_ENABLED
1025 if ( b->a_aci_at != NULL ) {
1027 slap_access_t grant, deny, tgrant, tdeny;
1029 /* this case works different from the others above.
1030 * since aci's themselves give permissions, we need
1031 * to first check b->a_access_mask, the ACL's access level.
1034 if ( e->e_nname.bv_len == 0 ) {
1035 /* no ACIs in the root DSE */
1039 /* first check if the right being requested
1040 * is allowed by the ACL clause.
1042 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1046 /* get the aci attribute */
1047 at = attr_find( e->e_attrs, b->a_aci_at );
1052 ACL_RECORD_VALUE_STATE;
1054 /* start out with nothing granted, nothing denied */
1058 /* the aci is an multi-valued attribute. The
1059 * rights are determined by OR'ing the individual
1060 * rights given by the acis.
1062 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1063 if (aci_mask( be, conn, op,
1064 e, desc, val, &at->a_vals[i],
1065 matches, &grant, &deny ) != 0)
1072 /* remove anything that the ACL clause does not allow */
1073 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1074 tdeny &= ACL_PRIV_MASK;
1076 /* see if we have anything to contribute */
1077 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1081 /* this could be improved by changing acl_mask so that it can deal with
1082 * by clauses that return grant/deny pairs. Right now, it does either
1083 * additive or subtractive rights, but not both at the same time. So,
1084 * we need to combine the grant/deny pair into a single rights mask in
1085 * a smart way: if either grant or deny is "empty", then we use the
1086 * opposite as is, otherwise we remove any denied rights from the grant
1087 * rights mask and construct an additive mask.
1089 if (ACL_IS_INVALID(tdeny)) {
1090 modmask = tgrant | ACL_PRIV_ADDITIVE;
1092 } else if (ACL_IS_INVALID(tgrant)) {
1093 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1096 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1102 modmask = b->a_access_mask;
1106 LDAP_LOG(( "acl", LDAP_LEVEL_RESULTS,
1107 "acl_mask: conn %lu [%d] applying %s (%s)\n",
1108 conn->c_connid, i, accessmask2str( modmask, accessmaskbuf),
1109 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1110 ? "break" : "stop" ));
1112 Debug( LDAP_DEBUG_ACL,
1113 "<= acl_mask: [%d] applying %s (%s)\n",
1114 i, accessmask2str( modmask, accessmaskbuf ),
1115 b->a_type == ACL_CONTINUE
1117 : b->a_type == ACL_BREAK
1124 if( ACL_IS_ADDITIVE(modmask) ) {
1126 ACL_PRIV_SET( *mask, modmask );
1129 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1131 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1132 /* substract privs */
1133 ACL_PRIV_CLR( *mask, modmask );
1136 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1144 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1145 "acl_mask: conn %lu [%d] mask: %s\n",
1146 conn->c_connid, i, accessmask2str( *mask, accessmaskbuf) ));
1148 Debug( LDAP_DEBUG_ACL,
1149 "<= acl_mask: [%d] mask: %s\n",
1150 i, accessmask2str(*mask, accessmaskbuf), 0 );
1153 if( b->a_type == ACL_CONTINUE ) {
1156 } else if ( b->a_type == ACL_BREAK ) {
1164 /* implicit "by * none" clause */
1168 LDAP_LOG(( "acl", LDAP_LEVEL_RESULTS,
1169 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1170 conn->c_connid, accessmask2str( *mask, accessmaskbuf) ));
1172 Debug( LDAP_DEBUG_ACL,
1173 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1174 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1180 * acl_check_modlist - check access control on the given entry to see if
1181 * it allows the given modifications by the user associated with op.
1182 * returns 1 if mods allowed ok
1183 * 0 mods not allowed
1192 Modifications *mlist
1197 assert( be != NULL );
1199 /* short circuit root database access */
1200 if ( be_isroot( be, &op->o_ndn ) ) {
1202 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
1203 "acl_check_modlist: conn %lu access granted to root user\n",
1206 Debug( LDAP_DEBUG_ACL,
1207 "<= acl_access_allowed: granted to database root\n",
1213 /* use backend default access if no backend acls */
1214 if( be != NULL && be->be_acl == NULL ) {
1216 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1217 "acl_check_modlist: conn %lu backend default %s access %s to \"%s\"\n",
1218 conn->c_connid, access2str( ACL_WRITE ),
1219 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val ));
1221 Debug( LDAP_DEBUG_ACL,
1222 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1223 access2str( ACL_WRITE ),
1224 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1226 return be->be_dfltaccess >= ACL_WRITE;
1229 /* be is always non-NULL */
1230 /* use global default access if no global acls */
1231 } else if ( be == NULL && global_acl == NULL ) {
1233 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1234 "acl_check_modlist: conn %lu global default %s access %s to \"%s\"\n",
1235 conn->c_connid, access2str( ACL_WRITE ),
1236 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn ));
1238 Debug( LDAP_DEBUG_ACL,
1239 "=> access_allowed: global default %s access %s to \"%s\"\n",
1240 access2str( ACL_WRITE ),
1241 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1243 return global_default_access >= ACL_WRITE;
1247 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1248 static AccessControlState state_init = ACL_STATE_INIT;
1249 AccessControlState state;
1252 * no-user-modification operational attributes are ignored
1253 * by ACL_WRITE checking as any found here are not provided
1256 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1258 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1259 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1260 conn->c_connid, mlist->sml_desc->ad_cname.bv_val ));
1262 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1263 " modify access granted\n",
1264 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1271 switch ( mlist->sml_op ) {
1272 case LDAP_MOD_REPLACE:
1274 * We must check both permission to delete the whole
1275 * attribute and permission to add the specific attributes.
1276 * This prevents abuse from selfwriters.
1278 if ( ! access_allowed( be, conn, op, e,
1279 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1284 if ( mlist->sml_bvalues == NULL ) break;
1286 /* fall thru to check value to add */
1289 assert( mlist->sml_bvalues != NULL );
1291 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1292 if ( ! access_allowed( be, conn, op, e,
1293 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1300 case LDAP_MOD_DELETE:
1301 if ( mlist->sml_bvalues == NULL ) {
1302 if ( ! access_allowed( be, conn, op, e,
1303 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1309 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1310 if ( ! access_allowed( be, conn, op, e,
1311 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1318 case SLAP_MOD_SOFTADD:
1319 /* allow adding attribute via modrdn thru */
1331 #if 0 /* not used any more */
1333 aci_bvstrdup( struct berval *bv )
1337 s = (char *)ch_malloc(bv->bv_len + 1);
1339 AC_MEMCPY(s, bv->bv_val, bv->bv_len);
1348 struct berval *list,
1362 while (len >= 0 && --ix >= 0) {
1363 while (--len >= 0 && *p++ != sep) ;
1365 while (len >= 0 && *p == ' ') {
1376 while (--len >= 0 && *p != sep) {
1380 while (bv->bv_len > 0 && *--p == ' ')
1386 aci_set_gather (void *cookie, struct berval *name, struct berval *attr)
1388 AciSetCookie *cp = cookie;
1389 BerVarray bvals = NULL;
1392 /* this routine needs to return the bervals instead of
1393 * plain strings, since syntax is not known. It should
1394 * also return the syntax or some "comparison cookie".
1397 if (dnNormalize2(NULL, name, &ndn) == LDAP_SUCCESS) {
1399 AttributeDescription *desc = NULL;
1400 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1401 backend_attribute(cp->be, NULL, NULL,
1402 cp->e, &ndn, desc, &bvals);
1411 struct berval *subj,
1419 struct berval set = { 0, NULL };
1421 AciSetCookie cookie;
1424 ber_dupbv( &set, subj );
1426 struct berval subjdn, ndn = { 0, NULL };
1427 struct berval setat;
1430 AttributeDescription *desc = NULL;
1432 /* format of string is "entry/setAttrName" */
1433 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1437 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1438 setat.bv_val = SLAPD_ACI_SET_ATTR;
1439 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1442 if ( setat.bv_val != NULL ) {
1444 * NOTE: dnNormalize2 honors the ber_len field
1445 * as the length of the dn to be normalized
1447 if ( dnNormalize2(NULL, &subjdn, &ndn) == LDAP_SUCCESS
1448 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1450 backend_attribute(be, NULL, NULL, e,
1451 &ndn, desc, &bvals);
1452 if ( bvals != NULL ) {
1453 if ( bvals[0].bv_val != NULL ) {
1456 bvals[0].bv_val = NULL;
1457 for (i=1;bvals[i].bv_val;i++);
1458 bvals[0].bv_val = bvals[i-1].bv_val;
1459 bvals[i-1].bv_val = NULL;
1461 ber_bvarray_free(bvals);
1469 if (set.bv_val != NULL) {
1474 rc = (slap_set_filter(aci_set_gather, &cookie, &set,
1475 &op->o_ndn, &e->e_nname, NULL) > 0);
1476 ch_free(set.bv_val);
1481 #ifdef SLAPD_ACI_ENABLED
1483 aci_list_map_rights(
1484 struct berval *list )
1491 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1494 switch (*bv.bv_val) {
1496 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1499 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1500 * the right 's' to mean "set", but in the examples states
1501 * that the right 's' means "search". The latter definition
1504 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1507 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1510 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1513 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1514 * define any equivalent to the AUTH right, so I've just used
1517 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1529 struct berval *list,
1530 const struct berval *attr,
1531 struct berval *val )
1533 struct berval bv, left, right;
1536 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1537 if (aci_get_part(&bv, 0, '=', &left) < 0
1538 || aci_get_part(&bv, 1, '=', &right) < 0)
1540 if (ber_bvstrcasecmp(attr, &bv) == 0)
1542 } else if (val == NULL) {
1543 if (ber_bvstrcasecmp(attr, &left) == 0)
1546 if (ber_bvstrcasecmp(attr, &left) == 0) {
1547 /* this is experimental code that implements a
1548 * simple (prefix) match of the attribute value.
1549 * the ACI draft does not provide for aci's that
1550 * apply to specific values, but it would be
1551 * nice to have. If the <attr> part of an aci's
1552 * rights list is of the form <attr>=<value>,
1553 * that means the aci applies only to attrs with
1554 * the given value. Furthermore, if the attr is
1555 * of the form <attr>=<value>*, then <value> is
1556 * treated as a prefix, and the aci applies to
1557 * any value with that prefix.
1559 * Ideally, this would allow r.e. matches.
1561 if (aci_get_part(&right, 0, '*', &left) < 0
1562 || right.bv_len <= left.bv_len)
1564 if (ber_bvstrcasecmp(val, &right) == 0)
1566 } else if (val->bv_len >= left.bv_len) {
1567 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1576 static slap_access_t
1577 aci_list_get_attr_rights(
1578 struct berval *list,
1579 const struct berval *attr,
1580 struct berval *val )
1586 /* loop through each rights/attr pair, skip first part (action) */
1588 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1589 if (aci_list_has_attr(&bv, attr, val) == 0)
1591 if (aci_get_part(list, i, ';', &bv) < 0)
1593 mask |= aci_list_map_rights(&bv);
1599 aci_list_get_rights(
1600 struct berval *list,
1601 const struct berval *attr,
1603 slap_access_t *grant,
1604 slap_access_t *deny )
1606 struct berval perm, actn;
1607 slap_access_t *mask;
1610 if (attr == NULL || attr->bv_len == 0
1611 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1612 attr = &aci_bv_br_entry;
1618 /* loop through each permissions clause */
1619 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1620 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1622 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1624 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1631 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1632 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1639 struct berval *subj,
1640 struct berval *defgrpoc,
1641 struct berval *defgrpat,
1649 struct berval subjdn;
1650 struct berval grpoc;
1651 struct berval grpat;
1652 ObjectClass *grp_oc = NULL;
1653 AttributeDescription *grp_ad = NULL;
1657 /* format of string is "group/objectClassValue/groupAttrName" */
1658 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1662 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1666 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1670 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1671 if( rc != LDAP_SUCCESS ) {
1677 grp_oc = oc_bvfind( &grpoc );
1679 if (grp_oc != NULL && grp_ad != NULL ) {
1680 char buf[ACL_BUF_SIZE];
1681 struct berval bv = { sizeof(buf), buf }, ndn;
1682 string_expand(&bv, &subjdn, e->e_ndn, matches);
1683 if ( dnNormalize2(NULL, &bv, &ndn) == LDAP_SUCCESS ) {
1684 rc = (backend_group(be, conn, op, e, &ndn, &op->o_ndn, grp_oc, grp_ad) == 0);
1693 static struct berval GroupClass = {
1694 sizeof(SLAPD_GROUP_CLASS)-1, SLAPD_GROUP_CLASS };
1695 static struct berval GroupAttr = {
1696 sizeof(SLAPD_GROUP_ATTR)-1, SLAPD_GROUP_ATTR };
1697 static struct berval RoleClass = {
1698 sizeof(SLAPD_ROLE_CLASS)-1, SLAPD_ROLE_CLASS };
1699 static struct berval RoleAttr = {
1700 sizeof(SLAPD_ROLE_ATTR)-1, SLAPD_ROLE_ATTR };
1708 AttributeDescription *desc,
1711 regmatch_t *matches,
1712 slap_access_t *grant,
1716 struct berval bv, perms, sdn;
1720 assert( desc->ad_cname.bv_val != NULL );
1722 /* parse an aci of the form:
1723 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1725 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1726 a full description of the format for this attribute.
1728 For now, this routine only supports scope=entry.
1731 /* check that the aci has all 5 components */
1732 if (aci_get_part(aci, 4, '#', NULL) < 0)
1735 /* check that the aci family is supported */
1736 if (aci_get_part(aci, 0, '#', &bv) < 0)
1739 /* check that the scope is "entry" */
1740 if (aci_get_part(aci, 1, '#', &bv) < 0
1741 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1746 /* get the list of permissions clauses, bail if empty */
1747 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1750 /* check if any permissions allow desired access */
1751 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1754 /* see if we have a DN match */
1755 if (aci_get_part(aci, 3, '#', &bv) < 0)
1758 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1761 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1764 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1765 if (!dn_match( &op->o_ndn, &ndn))
1772 if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1773 if (dn_match(&op->o_ndn, &e->e_nname))
1776 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1778 AttributeDescription *ad = NULL;
1781 rc = slap_bv2ad( &sdn, &ad, &text );
1783 if( rc != LDAP_SUCCESS ) {
1791 for(at = attrs_find( e->e_attrs, ad );
1793 at = attrs_find( at->a_next, ad ) )
1795 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1804 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1805 if (aci_group_member(&sdn, &GroupClass, &GroupAttr, be, e, conn, op, matches))
1808 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1809 if (aci_group_member(&sdn, &RoleClass, &RoleAttr, be, e, conn, op, matches))
1812 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1813 if (aci_match_set(&sdn, be, e, conn, op, 0))
1816 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1817 if (aci_match_set(&sdn, be, e, conn, op, 1))
1825 #endif /* SLAPD_ACI_ENABLED */
1832 regmatch_t *matches)
1840 bv->bv_val[0] = '\0';
1841 bv->bv_len--; /* leave space for lone $ */
1844 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1845 sp < pat->bv_val + pat->bv_len ; sp++) {
1846 /* did we previously see a $ */
1848 if ( flag == 1 && *sp == '$' ) {
1853 } else if ( flag == 1 && *sp == '{') {
1856 } else if ( *sp >= '0' && *sp <= '9' ) {
1864 for ( sp++; *sp != '\0' && *sp != /* { */ '}'; sp++ ) {
1865 if ( *sp >= '0' && *sp <= '9' ) {
1866 n = 10*n + ( *sp - '0' );
1870 if ( *sp != /* { */ '}' ) {
1875 if ( n >= MAXREMATCHES ) {
1880 i = matches[n].rm_so;
1881 l = matches[n].rm_eo;
1882 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1900 /* must have ended with a single $ */
1909 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1910 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val ));
1911 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1912 "string_expand: expanded = %s\n", bv->bv_val ));
1914 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1915 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1921 struct berval *pat, /* pattern to expand and match against */
1922 char *str, /* string to match against pattern */
1923 char *buf, /* buffer with $N expansion variables */
1924 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1932 bv.bv_len = sizeof(newbuf);
1935 if(str == NULL) str = "";
1937 string_expand(&bv, pat, buf, matches);
1938 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1940 regerror(rc, &re, error, sizeof(error));
1943 LDAP_LOG(( "aci", LDAP_LEVEL_ERR,
1944 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
1945 pat->bv_val, str, error ));
1947 Debug( LDAP_DEBUG_TRACE,
1948 "compile( \"%s\", \"%s\") failed %s\n",
1949 pat->bv_val, str, error );
1954 rc = regexec(&re, str, 0, NULL, 0);
1958 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL2,
1959 "regex_matches: string: %s\n", str ));
1960 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL2,
1961 "regex_matches: rc: %d %s\n",
1962 rc, rc ? "matches" : "no matches" ));
1964 Debug( LDAP_DEBUG_TRACE,
1965 "=> regex_matches: string: %s\n", str, 0, 0 );
1966 Debug( LDAP_DEBUG_TRACE,
1967 "=> regex_matches: rc: %d %s\n",
1968 rc, !rc ? "matches" : "no matches", 0 );