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 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 )
126 char accessmaskbuf[ACCESSMASK_MAXLEN];
129 slap_control_t control;
131 regmatch_t matches[MAXREMATCHES];
134 assert( desc != NULL );
135 assert( access > ACL_NONE );
137 attr = desc->ad_cname.bv_val;
139 assert( attr != NULL );
141 if( state && state->as_recorded ) {
142 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
145 return state->as_result;
147 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
148 val != NULL && state->as_vd_acl == NULL )
150 return state->as_result;
155 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
156 "access_allowed: conn %lu %s access to \"%s\" \"%s\" requested\n",
157 conn ? conn->c_connid : -1, access2str( access ), e->e_dn, attr ));
159 Debug( LDAP_DEBUG_ACL,
160 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
161 access2str( access ), e->e_dn, attr );
169 if ( be == NULL ) be = &backends[0];
170 assert( be != NULL );
172 /* grant database root access */
173 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
175 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
176 "access_allowed: conn %lu root access granted\n",
179 Debug( LDAP_DEBUG_ACL,
180 "<= root access granted\n",
187 * no-user-modification operational attributes are ignored
188 * by ACL_WRITE checking as any found here are not provided
191 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
192 && desc != slap_schema.si_ad_entry
193 && desc != slap_schema.si_ad_children )
196 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
197 "access_allowed: conn %lu NoUserMod Operational attribute: %s access granted\n",
198 conn->c_connid, attr ));
200 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
201 " %s access granted\n",
207 /* use backend default access if no backend acls */
208 if( be != NULL && be->be_acl == NULL ) {
210 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
211 "access_allowed: conn %lu backend default %s access %s to \"%s\"\n",
212 conn->c_connid, access2str( access ),
213 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val ));
215 Debug( LDAP_DEBUG_ACL,
216 "=> access_allowed: backend default %s access %s to \"%s\"\n",
217 access2str( access ),
218 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
220 ret = be->be_dfltaccess >= access;
224 /* be is always non-NULL */
225 /* use global default access if no global acls */
226 } else if ( be == NULL && global_acl == NULL ) {
228 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
229 "access_allowed: conn %lu global default %s access %s to \"%s\"\n",
230 conn->c_connid, access2str( access ),
231 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val ));
233 Debug( LDAP_DEBUG_ACL,
234 "=> access_allowed: global default %s access %s to \"%s\"\n",
235 access2str( access ),
236 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
238 ret = global_default_access >= access;
246 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )) {
247 assert( state->as_vd_acl != NULL );
249 a = state->as_vd_acl;
250 mask = state->as_vd_acl_mask;
251 count = state->as_vd_acl_count;
252 AC_MEMCPY( matches, state->as_vd_acl_matches,
260 memset(matches, '\0', sizeof(matches));
263 while((a = acl_get( a, &count, be, op, e, desc,
264 MAXREMATCHES, matches )) != NULL)
268 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
270 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
271 "access_allowed: conn %lu match[%d]: %d %d ",
273 (int)matches[i].rm_so, (int)matches[i].rm_eo ));
275 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
276 (int)matches[i].rm_so, (int)matches[i].rm_eo );
278 if( matches[i].rm_so <= matches[0].rm_eo ) {
280 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
281 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
285 LDAP_LOG(( "acl", LDAP_LEVEL_ARGS, "\n" ));
287 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
292 control = acl_mask( a, &mask, be, conn, op,
293 e, desc, val, matches, count, state );
295 if ( control != ACL_BREAK ) {
299 memset(matches, '\0', sizeof(matches));
302 if ( ACL_IS_INVALID( mask ) ) {
304 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
305 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
306 conn->c_connid, e->e_dn, attr ));
308 Debug( LDAP_DEBUG_ACL,
309 "=> access_allowed: \"%s\" (%s) invalid!\n",
314 } else if ( control == ACL_BREAK ) {
316 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
317 "access_allowed: conn %lu no more rules\n",
320 Debug( LDAP_DEBUG_ACL,
321 "=> access_allowed: no more rules\n", 0, 0, 0);
328 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
329 "access_allowed: conn %lu %s access %s by %s\n",
331 access2str( access ),
332 ACL_GRANT( mask, access ) ? "granted" : "denied",
333 accessmask2str( mask, accessmaskbuf ) ));
335 Debug( LDAP_DEBUG_ACL,
336 "=> access_allowed: %s access %s by %s\n",
337 access2str( access ),
338 ACL_GRANT(mask, access) ? "granted" : "denied",
339 accessmask2str( mask, accessmaskbuf ) );
342 ret = ACL_GRANT(mask, access);
345 if( state != NULL ) {
346 state->as_recorded |= ACL_STATE_RECORDED;
347 state->as_result = ret;
353 * acl_get - return the acl applicable to entry e, attribute
354 * attr. the acl returned is suitable for use in subsequent calls to
355 * acl_access_allowed().
358 static AccessControl *
365 AttributeDescription *desc,
367 regmatch_t *matches )
373 assert( count != NULL );
374 assert( desc != NULL );
376 attr = desc->ad_cname.bv_val;
378 assert( attr != NULL );
393 dnlen = e->e_nname.bv_len;
395 for ( ; a != NULL; a = a->acl_next ) {
398 if (a->acl_dn_pat.bv_len != 0) {
399 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
401 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
402 "acl_get: dnpat [%d] %s nsub: %d\n",
403 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub ));
405 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
406 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
408 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
413 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
414 "acl_get: dn [%d] %s\n",
415 *count, a->acl_dn_pat.bv_val ));
417 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
418 *count, a->acl_dn_pat.bv_val, 0 );
420 patlen = a->acl_dn_pat.bv_len;
421 if ( dnlen < patlen )
424 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
425 /* base dn -- entire object DN must match */
426 if ( dnlen != patlen )
429 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
432 if ( dnlen <= patlen )
435 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
438 rdnlen = dn_rdnlen( NULL, &e->e_nname );
439 if ( rdnlen != dnlen - patlen - 1 )
442 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
443 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
446 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
447 if ( dnlen <= patlen )
449 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
453 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
458 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
459 "acl_get: [%d] matched\n",
462 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
467 if ( a->acl_filter != NULL ) {
468 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
469 if ( rc != LDAP_COMPARE_TRUE ) {
475 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
476 "acl_get: [%d] check attr %s\n",
479 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
482 if ( attr == NULL || a->acl_attrs == NULL ||
483 ad_inlist( desc, a->acl_attrs ) )
486 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
487 "acl_get: [%d] acl %s attr: %s\n",
488 *count, e->e_dn, attr ));
490 Debug( LDAP_DEBUG_ACL,
491 "<= acl_get: [%d] acl %s attr: %s\n",
492 *count, e->e_dn, attr );
496 matches[0].rm_so = matches[0].rm_eo = -1;
500 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
501 "acl_get: done.\n" ));
503 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
509 * Record value-dependent access control state
511 #define ACL_RECORD_VALUE_STATE do { \
512 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
513 state->as_recorded |= ACL_STATE_RECORDED_VD; \
514 state->as_vd_acl = a; \
515 AC_MEMCPY( state->as_vd_acl_matches, matches, \
516 sizeof( state->as_vd_acl_matches )) ; \
517 state->as_vd_acl_count = count; \
518 state->as_vd_access = b; \
519 state->as_vd_access_count = i; \
524 * acl_mask - modifies mask based upon the given acl and the
525 * requested access to entry e, attribute attr, value val. if val
526 * is null, access to the whole attribute is assumed (all values).
528 * returns 0 access NOT allowed
532 static slap_control_t
540 AttributeDescription *desc,
544 AccessControlState *state )
546 int i, odnlen, patlen;
549 char accessmaskbuf[ACCESSMASK_MAXLEN];
554 assert( mask != NULL );
555 assert( desc != NULL );
557 attr = desc->ad_cname.bv_val;
559 assert( attr != NULL );
562 LDAP_LOG(( "acl", LDAP_LEVEL_ENTRY,
563 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
564 conn->c_connid, e->e_dn, attr ));
566 LDAP_LOG(( "acl", LDAP_LEVEL_ARGS,
567 " to %s by \"%s\", (%s) \n",
568 val ? "value" : "all values",
569 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
570 accessmask2str( *mask, accessmaskbuf ) ));
572 Debug( LDAP_DEBUG_ACL,
573 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
576 Debug( LDAP_DEBUG_ACL,
577 "=> acl_mask: to %s by \"%s\", (%s) \n",
578 val ? "value" : "all values",
579 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
580 accessmask2str( *mask, accessmaskbuf ) );
583 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
584 && state->as_vd_acl == a )
586 b = state->as_vd_access;
587 i = state->as_vd_access_count;
594 for ( ; b != NULL; b = b->a_next, i++ ) {
595 slap_mask_t oldmask, modmask;
597 ACL_INVALIDATE( modmask );
599 /* AND <who> clauses */
600 if ( b->a_dn_pat.bv_len != 0 ) {
602 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
603 "acl_mask: conn %lu check a_dn_pat: %s\n",
604 conn->c_connid, b->a_dn_pat.bv_val ));
606 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
607 b->a_dn_pat.bv_val, 0, 0);
610 * if access applies to the entry itself, and the
611 * user is bound as somebody in the same namespace as
612 * the entry, OR the given dn matches the dn pattern
614 if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_anonymous ) == 0 ) {
615 if ( op->o_ndn.bv_len != 0 ) {
619 } else if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_users ) == 0 ) {
620 if ( op->o_ndn.bv_len == 0 ) {
624 } else if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_self ) == 0 ) {
625 if ( op->o_ndn.bv_len == 0 ) {
629 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
633 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
634 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
635 int ret = regex_matches( &b->a_dn_pat,
636 op->o_ndn.bv_val, e->e_ndn, matches );
647 if ( e->e_dn == NULL )
650 if ( b->a_dn_expand ) {
652 char buf[ACL_BUF_SIZE];
654 bv.bv_len = sizeof( buf ) - 1;
657 string_expand(&bv, &b->a_dn_pat,
659 if ( dnNormalize2(NULL, &bv, &pat) != LDAP_SUCCESS ) {
660 /* did not expand to a valid dn */
668 odnlen = op->o_ndn.bv_len;
669 if ( odnlen < patlen ) {
670 goto dn_match_cleanup;
674 if ( b->a_dn_style == ACL_STYLE_BASE ) {
675 /* base dn -- entire object DN must match */
676 if ( odnlen != patlen ) {
677 goto dn_match_cleanup;
680 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
683 if ( odnlen <= patlen ) {
684 goto dn_match_cleanup;
687 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
688 goto dn_match_cleanup;
691 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
692 if ( rdnlen != odnlen - patlen - 1 ) {
693 goto dn_match_cleanup;
696 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
697 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
698 goto dn_match_cleanup;
701 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
702 if ( odnlen <= patlen ) {
703 goto dn_match_cleanup;
706 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
707 goto dn_match_cleanup;
711 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
714 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
724 if ( b->a_sockurl_pat.bv_len ) {
726 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
727 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
728 conn->c_connid, b->a_sockurl_pat.bv_val ));
730 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
731 b->a_sockurl_pat.bv_val, 0, 0 );
734 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
735 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
736 if (!regex_matches( &b->a_sockurl_pat, conn->c_listener_url.bv_val,
737 e->e_ndn, matches ) )
742 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &conn->c_listener_url ) != 0 )
748 if ( b->a_domain_pat.bv_len ) {
750 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
751 "acl_mask: conn %lu check a_domain_pat: %s\n",
752 conn->c_connid, b->a_domain_pat.bv_val ));
754 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
755 b->a_domain_pat.bv_val, 0, 0 );
757 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
758 if ( b->a_domain_style == ACL_STYLE_REGEX) {
759 if (!regex_matches( &b->a_domain_pat, conn->c_peer_domain.bv_val,
760 e->e_ndn, matches ) )
765 char buf[ACL_BUF_SIZE];
767 struct berval cmp = conn->c_peer_domain;
768 struct berval pat = b->a_domain_pat;
770 if ( b->a_domain_expand ) {
773 bv.bv_len = sizeof(buf);
776 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
780 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
781 int offset = cmp.bv_len - pat.bv_len;
786 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
790 /* trim the domain */
791 cmp.bv_val = &cmp.bv_val[ offset ];
792 cmp.bv_len -= offset;
795 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
802 if ( b->a_peername_pat.bv_len ) {
804 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
805 "acl_mask: conn %lu check a_perrname_path: %s\n",
806 conn->c_connid, b->a_peername_pat.bv_val ));
808 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
809 b->a_peername_pat.bv_val, 0, 0 );
811 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
812 if ( b->a_peername_style == ACL_STYLE_REGEX) {
813 if (!regex_matches( &b->a_peername_pat, conn->c_peer_name.bv_val,
814 e->e_ndn, matches ) )
819 if ( ber_bvstrcasecmp( &b->a_peername_pat, &conn->c_peer_name ) != 0 )
825 if ( b->a_sockname_pat.bv_len ) {
827 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
828 "acl_mask: conn %lu check a_sockname_path: %s\n",
829 conn->c_connid, b->a_sockname_pat.bv_val ));
831 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
832 b->a_sockname_pat.bv_val, 0, 0 );
834 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
835 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
836 if (!regex_matches( &b->a_sockname_pat, conn->c_sock_name.bv_val,
837 e->e_ndn, matches ) )
842 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &conn->c_sock_name ) != 0 )
848 if ( b->a_dn_at != NULL ) {
853 const char *attr = b->a_dn_at->ad_cname.bv_val;
855 assert( attr != NULL );
857 if ( op->o_ndn.bv_len == 0 ) {
862 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
863 "acl_mask: conn %lu check a_dn_pat: %s\n",
864 conn->c_connid, attr ));
866 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
871 /* see if asker is listed in dnattr */
872 for( at = attrs_find( e->e_attrs, b->a_dn_at );
874 at = attrs_find( at->a_next, b->a_dn_at ) )
876 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
884 /* have a dnattr match. if this is a self clause then
885 * the target must also match the op dn.
887 if ( b->a_dn_self ) {
888 /* check if the target is an attribute. */
891 /* target is attribute, check if the attribute value
894 rc = value_match( &match, b->a_dn_at,
895 b->a_dn_at->ad_type->sat_equality, 0,
897 /* on match error or no match, fail the ACL clause */
898 if (rc != LDAP_SUCCESS || match != 0 )
902 /* no dnattr match, check if this is a self clause */
903 if ( ! b->a_dn_self )
906 ACL_RECORD_VALUE_STATE;
908 /* this is a self clause, check if the target is an
914 /* target is attribute, check if the attribute value
917 rc = value_match( &match, b->a_dn_at,
918 b->a_dn_at->ad_type->sat_equality, 0,
921 /* on match error or no match, fail the ACL clause */
922 if (rc != LDAP_SUCCESS || match != 0 )
927 if ( b->a_group_pat.bv_len ) {
928 char buf[ACL_BUF_SIZE];
930 struct berval ndn = { 0, NULL };
933 if ( op->o_ndn.bv_len == 0 ) {
937 bv.bv_len = sizeof(buf) - 1;
940 /* b->a_group is an unexpanded entry name, expanded it should be an
941 * entry with objectclass group* and we test to see if odn is one of
942 * the values in the attribute group
944 /* see if asker is listed in dnattr */
945 if ( b->a_group_style == ACL_STYLE_REGEX ) {
946 string_expand(&bv, &b->a_group_pat, e->e_ndn, matches);
947 if ( dnNormalize2(NULL, &bv, &ndn) != LDAP_SUCCESS ) {
948 /* did not expand to a valid dn */
956 rc = backend_group(be, conn, op, e, &bv, &op->o_ndn,
957 b->a_group_oc, b->a_group_at);
965 if ( b->a_set_pat.bv_len != 0 ) {
966 if (aci_match_set( &b->a_set_pat, be, e, conn, op, 0 ) == 0) {
971 if ( b->a_authz.sai_ssf ) {
973 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
974 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
975 conn->c_connid, b->a_authz.sai_ssf, op->o_ssf ));
977 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
978 b->a_authz.sai_ssf, op->o_ssf, 0 );
980 if ( b->a_authz.sai_ssf > op->o_ssf ) {
985 if ( b->a_authz.sai_transport_ssf ) {
987 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
988 "acl_mask: conn %lu check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
989 conn->c_connid, b->a_authz.sai_transport_ssf, op->o_transport_ssf ));
991 Debug( LDAP_DEBUG_ACL,
992 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
993 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
995 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1000 if ( b->a_authz.sai_tls_ssf ) {
1002 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
1003 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1004 conn->c_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf ));
1006 Debug( LDAP_DEBUG_ACL,
1007 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1008 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1010 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1015 if ( b->a_authz.sai_sasl_ssf ) {
1017 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
1018 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1019 conn->c_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf ));
1021 Debug( LDAP_DEBUG_ACL,
1022 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1023 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1025 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1030 #ifdef SLAPD_ACI_ENABLED
1031 if ( b->a_aci_at != NULL ) {
1033 slap_access_t grant, deny, tgrant, tdeny;
1035 /* this case works different from the others above.
1036 * since aci's themselves give permissions, we need
1037 * to first check b->a_access_mask, the ACL's access level.
1040 if ( e->e_nname.bv_len == 0 ) {
1041 /* no ACIs in the root DSE */
1045 /* first check if the right being requested
1046 * is allowed by the ACL clause.
1048 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1052 /* get the aci attribute */
1053 at = attr_find( e->e_attrs, b->a_aci_at );
1058 ACL_RECORD_VALUE_STATE;
1060 /* start out with nothing granted, nothing denied */
1064 /* the aci is an multi-valued attribute. The
1065 * rights are determined by OR'ing the individual
1066 * rights given by the acis.
1068 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1069 if (aci_mask( be, conn, op,
1070 e, desc, val, &at->a_vals[i],
1071 matches, &grant, &deny ) != 0)
1078 /* remove anything that the ACL clause does not allow */
1079 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1080 tdeny &= ACL_PRIV_MASK;
1082 /* see if we have anything to contribute */
1083 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1087 /* this could be improved by changing acl_mask so that it can deal with
1088 * by clauses that return grant/deny pairs. Right now, it does either
1089 * additive or subtractive rights, but not both at the same time. So,
1090 * we need to combine the grant/deny pair into a single rights mask in
1091 * a smart way: if either grant or deny is "empty", then we use the
1092 * opposite as is, otherwise we remove any denied rights from the grant
1093 * rights mask and construct an additive mask.
1095 if (ACL_IS_INVALID(tdeny)) {
1096 modmask = tgrant | ACL_PRIV_ADDITIVE;
1098 } else if (ACL_IS_INVALID(tgrant)) {
1099 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1102 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1108 modmask = b->a_access_mask;
1112 LDAP_LOG(( "acl", LDAP_LEVEL_RESULTS,
1113 "acl_mask: conn %lu [%d] applying %s (%s)\n",
1114 conn->c_connid, i, accessmask2str( modmask, accessmaskbuf),
1115 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1116 ? "break" : "stop" ));
1118 Debug( LDAP_DEBUG_ACL,
1119 "<= acl_mask: [%d] applying %s (%s)\n",
1120 i, accessmask2str( modmask, accessmaskbuf ),
1121 b->a_type == ACL_CONTINUE
1123 : b->a_type == ACL_BREAK
1130 if( ACL_IS_ADDITIVE(modmask) ) {
1132 ACL_PRIV_SET( *mask, modmask );
1135 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1137 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1138 /* substract privs */
1139 ACL_PRIV_CLR( *mask, modmask );
1142 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1150 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1151 "acl_mask: conn %lu [%d] mask: %s\n",
1152 conn->c_connid, i, accessmask2str( *mask, accessmaskbuf) ));
1154 Debug( LDAP_DEBUG_ACL,
1155 "<= acl_mask: [%d] mask: %s\n",
1156 i, accessmask2str(*mask, accessmaskbuf), 0 );
1159 if( b->a_type == ACL_CONTINUE ) {
1162 } else if ( b->a_type == ACL_BREAK ) {
1170 /* implicit "by * none" clause */
1174 LDAP_LOG(( "acl", LDAP_LEVEL_RESULTS,
1175 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1176 conn->c_connid, accessmask2str( *mask, accessmaskbuf) ));
1178 Debug( LDAP_DEBUG_ACL,
1179 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1180 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1186 * acl_check_modlist - check access control on the given entry to see if
1187 * it allows the given modifications by the user associated with op.
1188 * returns 1 if mods allowed ok
1189 * 0 mods not allowed
1198 Modifications *mlist
1203 assert( be != NULL );
1205 /* short circuit root database access */
1206 if ( be_isroot( be, &op->o_ndn ) ) {
1208 LDAP_LOG(( "acl", LDAP_LEVEL_DETAIL1,
1209 "acl_check_modlist: conn %lu access granted to root user\n",
1212 Debug( LDAP_DEBUG_ACL,
1213 "<= acl_access_allowed: granted to database root\n",
1219 /* use backend default access if no backend acls */
1220 if( be != NULL && be->be_acl == NULL ) {
1222 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1223 "acl_check_modlist: conn %lu backend default %s access %s to \"%s\"\n",
1224 conn->c_connid, access2str( ACL_WRITE ),
1225 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val ));
1227 Debug( LDAP_DEBUG_ACL,
1228 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1229 access2str( ACL_WRITE ),
1230 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1232 return be->be_dfltaccess >= ACL_WRITE;
1235 /* be is always non-NULL */
1236 /* use global default access if no global acls */
1237 } else if ( be == NULL && global_acl == NULL ) {
1239 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1240 "acl_check_modlist: conn %lu global default %s access %s to \"%s\"\n",
1241 conn->c_connid, access2str( ACL_WRITE ),
1242 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn ));
1244 Debug( LDAP_DEBUG_ACL,
1245 "=> access_allowed: global default %s access %s to \"%s\"\n",
1246 access2str( ACL_WRITE ),
1247 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1249 return global_default_access >= ACL_WRITE;
1253 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1254 static AccessControlState state_init = ACL_STATE_INIT;
1255 AccessControlState state;
1258 * no-user-modification operational attributes are ignored
1259 * by ACL_WRITE checking as any found here are not provided
1262 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1264 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1265 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1266 conn->c_connid, mlist->sml_desc->ad_cname.bv_val ));
1268 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1269 " modify access granted\n",
1270 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1277 switch ( mlist->sml_op ) {
1278 case LDAP_MOD_REPLACE:
1280 * We must check both permission to delete the whole
1281 * attribute and permission to add the specific attributes.
1282 * This prevents abuse from selfwriters.
1284 if ( ! access_allowed( be, conn, op, e,
1285 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1290 if ( mlist->sml_bvalues == NULL ) break;
1292 /* fall thru to check value to add */
1295 assert( mlist->sml_bvalues != NULL );
1297 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1298 if ( ! access_allowed( be, conn, op, e,
1299 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1306 case LDAP_MOD_DELETE:
1307 if ( mlist->sml_bvalues == NULL ) {
1308 if ( ! access_allowed( be, conn, op, e,
1309 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1315 for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
1316 if ( ! access_allowed( be, conn, op, e,
1317 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1324 case SLAP_MOD_SOFTADD:
1325 /* allow adding attribute via modrdn thru */
1339 struct berval *list,
1353 while (len >= 0 && --ix >= 0) {
1354 while (--len >= 0 && *p++ != sep) ;
1356 while (len >= 0 && *p == ' ') {
1367 while (--len >= 0 && *p != sep) {
1371 while (bv->bv_len > 0 && *--p == ' ')
1377 aci_set_gather (void *cookie, struct berval *name, struct berval *attr)
1379 AciSetCookie *cp = cookie;
1380 BerVarray bvals = NULL;
1383 /* this routine needs to return the bervals instead of
1384 * plain strings, since syntax is not known. It should
1385 * also return the syntax or some "comparison cookie".
1388 if (dnNormalize2(NULL, name, &ndn) == LDAP_SUCCESS) {
1390 AttributeDescription *desc = NULL;
1391 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1392 backend_attribute(cp->be, NULL, NULL,
1393 cp->e, &ndn, desc, &bvals);
1402 struct berval *subj,
1410 struct berval set = { 0, NULL };
1412 AciSetCookie cookie;
1415 ber_dupbv( &set, subj );
1417 struct berval subjdn, ndn = { 0, NULL };
1418 struct berval setat;
1421 AttributeDescription *desc = NULL;
1423 /* format of string is "entry/setAttrName" */
1424 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1428 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1429 setat.bv_val = SLAPD_ACI_SET_ATTR;
1430 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1433 if ( setat.bv_val != NULL ) {
1435 * NOTE: dnNormalize2 honors the ber_len field
1436 * as the length of the dn to be normalized
1438 if ( dnNormalize2(NULL, &subjdn, &ndn) == LDAP_SUCCESS
1439 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1441 backend_attribute(be, NULL, NULL, e,
1442 &ndn, desc, &bvals);
1443 if ( bvals != NULL ) {
1444 if ( bvals[0].bv_val != NULL ) {
1447 bvals[0].bv_val = NULL;
1448 for (i=1;bvals[i].bv_val;i++);
1449 bvals[0].bv_val = bvals[i-1].bv_val;
1450 bvals[i-1].bv_val = NULL;
1452 ber_bvarray_free(bvals);
1460 if (set.bv_val != NULL) {
1465 rc = (slap_set_filter(aci_set_gather, &cookie, &set,
1466 &op->o_ndn, &e->e_nname, NULL) > 0);
1467 ch_free(set.bv_val);
1472 #ifdef SLAPD_ACI_ENABLED
1474 aci_list_map_rights(
1475 struct berval *list )
1482 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1485 switch (*bv.bv_val) {
1487 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1490 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1491 * the right 's' to mean "set", but in the examples states
1492 * that the right 's' means "search". The latter definition
1495 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1498 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1501 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1504 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1505 * define any equivalent to the AUTH right, so I've just used
1508 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1520 struct berval *list,
1521 const struct berval *attr,
1522 struct berval *val )
1524 struct berval bv, left, right;
1527 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1528 if (aci_get_part(&bv, 0, '=', &left) < 0
1529 || aci_get_part(&bv, 1, '=', &right) < 0)
1531 if (ber_bvstrcasecmp(attr, &bv) == 0)
1533 } else if (val == NULL) {
1534 if (ber_bvstrcasecmp(attr, &left) == 0)
1537 if (ber_bvstrcasecmp(attr, &left) == 0) {
1538 /* this is experimental code that implements a
1539 * simple (prefix) match of the attribute value.
1540 * the ACI draft does not provide for aci's that
1541 * apply to specific values, but it would be
1542 * nice to have. If the <attr> part of an aci's
1543 * rights list is of the form <attr>=<value>,
1544 * that means the aci applies only to attrs with
1545 * the given value. Furthermore, if the attr is
1546 * of the form <attr>=<value>*, then <value> is
1547 * treated as a prefix, and the aci applies to
1548 * any value with that prefix.
1550 * Ideally, this would allow r.e. matches.
1552 if (aci_get_part(&right, 0, '*', &left) < 0
1553 || right.bv_len <= left.bv_len)
1555 if (ber_bvstrcasecmp(val, &right) == 0)
1557 } else if (val->bv_len >= left.bv_len) {
1558 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1567 static slap_access_t
1568 aci_list_get_attr_rights(
1569 struct berval *list,
1570 const struct berval *attr,
1571 struct berval *val )
1577 /* loop through each rights/attr pair, skip first part (action) */
1579 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1580 if (aci_list_has_attr(&bv, attr, val) == 0)
1582 if (aci_get_part(list, i, ';', &bv) < 0)
1584 mask |= aci_list_map_rights(&bv);
1590 aci_list_get_rights(
1591 struct berval *list,
1592 const struct berval *attr,
1594 slap_access_t *grant,
1595 slap_access_t *deny )
1597 struct berval perm, actn;
1598 slap_access_t *mask;
1601 if (attr == NULL || attr->bv_len == 0
1602 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1603 attr = &aci_bv_br_entry;
1609 /* loop through each permissions clause */
1610 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1611 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1613 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1615 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1622 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1623 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1630 struct berval *subj,
1631 struct berval *defgrpoc,
1632 struct berval *defgrpat,
1640 struct berval subjdn;
1641 struct berval grpoc;
1642 struct berval grpat;
1643 ObjectClass *grp_oc = NULL;
1644 AttributeDescription *grp_ad = NULL;
1648 /* format of string is "group/objectClassValue/groupAttrName" */
1649 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1653 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1657 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1661 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1662 if( rc != LDAP_SUCCESS ) {
1668 grp_oc = oc_bvfind( &grpoc );
1670 if (grp_oc != NULL && grp_ad != NULL ) {
1671 char buf[ACL_BUF_SIZE];
1672 struct berval bv, ndn;
1673 bv.bv_len = sizeof( buf );
1674 bv.bv_val = (char *)&buf;
1675 string_expand(&bv, &subjdn, e->e_ndn, matches);
1676 if ( dnNormalize2(NULL, &bv, &ndn) == LDAP_SUCCESS ) {
1677 rc = (backend_group(be, conn, op, e, &ndn, &op->o_ndn, grp_oc, grp_ad) == 0);
1692 AttributeDescription *desc,
1695 regmatch_t *matches,
1696 slap_access_t *grant,
1700 struct berval bv, perms, sdn;
1704 assert( desc->ad_cname.bv_val != NULL );
1706 /* parse an aci of the form:
1707 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1709 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1710 a full description of the format for this attribute.
1712 For now, this routine only supports scope=entry.
1715 /* check that the aci has all 5 components */
1716 if (aci_get_part(aci, 4, '#', NULL) < 0)
1719 /* check that the aci family is supported */
1720 if (aci_get_part(aci, 0, '#', &bv) < 0)
1723 /* check that the scope is "entry" */
1724 if (aci_get_part(aci, 1, '#', &bv) < 0
1725 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1730 /* get the list of permissions clauses, bail if empty */
1731 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1734 /* check if any permissions allow desired access */
1735 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1738 /* see if we have a DN match */
1739 if (aci_get_part(aci, 3, '#', &bv) < 0)
1742 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1745 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1748 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1749 if (!dn_match( &op->o_ndn, &ndn))
1756 if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1757 if (dn_match(&op->o_ndn, &e->e_nname))
1760 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1762 AttributeDescription *ad = NULL;
1765 rc = slap_bv2ad( &sdn, &ad, &text );
1767 if( rc != LDAP_SUCCESS ) {
1775 for(at = attrs_find( e->e_attrs, ad );
1777 at = attrs_find( at->a_next, ad ) )
1779 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1788 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1789 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, be, e, conn, op, matches))
1792 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1793 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, be, e, conn, op, matches))
1796 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1797 if (aci_match_set(&sdn, be, e, conn, op, 0))
1800 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1801 if (aci_match_set(&sdn, be, e, conn, op, 1))
1809 #endif /* SLAPD_ACI_ENABLED */
1816 regmatch_t *matches)
1824 bv->bv_val[0] = '\0';
1825 bv->bv_len--; /* leave space for lone $ */
1828 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1829 sp < pat->bv_val + pat->bv_len ; sp++) {
1830 /* did we previously see a $ */
1832 if ( flag == 1 && *sp == '$' ) {
1837 } else if ( flag == 1 && *sp == '{') {
1840 } else if ( *sp >= '0' && *sp <= '9' ) {
1848 for ( sp++; *sp != '\0' && *sp != /* { */ '}'; sp++ ) {
1849 if ( *sp >= '0' && *sp <= '9' ) {
1850 n = 10*n + ( *sp - '0' );
1854 if ( *sp != /* { */ '}' ) {
1859 if ( n >= MAXREMATCHES ) {
1864 i = matches[n].rm_so;
1865 l = matches[n].rm_eo;
1866 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1884 /* must have ended with a single $ */
1893 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1894 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val ));
1895 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL1,
1896 "string_expand: expanded = %s\n", bv->bv_val ));
1898 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1899 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1905 struct berval *pat, /* pattern to expand and match against */
1906 char *str, /* string to match against pattern */
1907 char *buf, /* buffer with $N expansion variables */
1908 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1916 bv.bv_len = sizeof(newbuf);
1919 if(str == NULL) str = "";
1921 string_expand(&bv, pat, buf, matches);
1922 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1924 regerror(rc, &re, error, sizeof(error));
1927 LDAP_LOG(( "aci", LDAP_LEVEL_ERR,
1928 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
1929 pat->bv_val, str, error ));
1931 Debug( LDAP_DEBUG_TRACE,
1932 "compile( \"%s\", \"%s\") failed %s\n",
1933 pat->bv_val, str, error );
1938 rc = regexec(&re, str, 0, NULL, 0);
1942 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL2,
1943 "regex_matches: string: %s\n", str ));
1944 LDAP_LOG(( "aci", LDAP_LEVEL_DETAIL2,
1945 "regex_matches: rc: %d %s\n",
1946 rc, rc ? "matches" : "no matches" ));
1948 Debug( LDAP_DEBUG_TRACE,
1949 "=> regex_matches: string: %s\n", str, 0, 0 );
1950 Debug( LDAP_DEBUG_TRACE,
1951 "=> regex_matches: rc: %d %s\n",
1952 rc, !rc ? "matches" : "no matches", 0 );