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 */
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 )
127 char accessmaskbuf[ACCESSMASK_MAXLEN];
130 slap_control_t control;
132 regmatch_t matches[MAXREMATCHES];
135 assert( desc != NULL );
136 assert( access > ACL_NONE );
138 attr = desc->ad_cname.bv_val;
140 assert( attr != NULL );
142 if( state && state->as_recorded ) {
143 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
146 return state->as_result;
148 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
149 val != NULL && state->as_vd_acl == NULL )
151 return state->as_result;
156 LDAP_LOG( ACL, ENTRY,
157 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
158 access2str( access ), e->e_dn, attr );
160 Debug( LDAP_DEBUG_ACL,
161 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
162 access2str( access ), e->e_dn, attr );
170 if ( be == NULL ) be = &backends[0];
171 assert( be != NULL );
173 /* grant database root access */
174 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
177 "access_allowed: conn %lu root access granted\n",
178 conn->c_connid, 0, 0 );
180 Debug( LDAP_DEBUG_ACL,
181 "<= root access granted\n",
188 * no-user-modification operational attributes are ignored
189 * by ACL_WRITE checking as any found here are not provided
192 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
193 && desc != slap_schema.si_ad_entry
194 && desc != slap_schema.si_ad_children )
197 LDAP_LOG( ACL, DETAIL1,
198 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
199 "access granted\n", conn->c_connid, attr , 0 );
201 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
202 " %s access granted\n",
208 /* use backend default access if no backend acls */
209 if( be != NULL && be->be_acl == NULL ) {
211 LDAP_LOG( ACL, DETAIL1,
212 "access_allowed: backend default %s access %s to \"%s\"\n",
213 access2str( access ),
214 be->be_dfltaccess >= access ? "granted" : "denied",
217 Debug( LDAP_DEBUG_ACL,
218 "=> access_allowed: backend default %s access %s to \"%s\"\n",
219 access2str( access ),
220 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
222 ret = be->be_dfltaccess >= access;
226 /* be is always non-NULL */
227 /* use global default access if no global acls */
228 } else if ( be == NULL && global_acl == NULL ) {
230 LDAP_LOG( ACL, DETAIL1,
231 "access_allowed: global default %s access %s to \"%s\"\n",
232 access2str( access ),
233 global_default_access >= access ? "granted" : "denied",
236 Debug( LDAP_DEBUG_ACL,
237 "=> access_allowed: global default %s access %s to \"%s\"\n",
238 access2str( access ),
239 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
241 ret = global_default_access >= access;
249 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )) {
250 assert( state->as_vd_acl != NULL );
252 a = state->as_vd_acl;
253 mask = state->as_vd_acl_mask;
254 count = state->as_vd_acl_count;
255 AC_MEMCPY( matches, state->as_vd_acl_matches,
263 memset(matches, '\0', sizeof(matches));
266 while((a = acl_get( a, &count, be, op, e, desc,
267 MAXREMATCHES, matches )) != NULL)
271 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
273 LDAP_LOG( ACL, DETAIL1,
274 "access_allowed: match[%d]: %d %d ",
275 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
277 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
278 (int)matches[i].rm_so, (int)matches[i].rm_eo );
280 if( matches[i].rm_so <= matches[0].rm_eo ) {
282 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
283 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
287 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
289 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
294 control = acl_mask( a, &mask, be, conn, op,
295 e, desc, val, matches, count, state );
297 if ( control != ACL_BREAK ) {
301 memset(matches, '\0', sizeof(matches));
304 if ( ACL_IS_INVALID( mask ) ) {
306 LDAP_LOG( ACL, DETAIL1,
307 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
308 conn->c_connid, e->e_dn, attr );
310 Debug( LDAP_DEBUG_ACL,
311 "=> access_allowed: \"%s\" (%s) invalid!\n",
316 } else if ( control == ACL_BREAK ) {
318 LDAP_LOG( ACL, DETAIL1,
319 "access_allowed: conn %lu no more rules\n", conn->c_connid, 0,0 );
321 Debug( LDAP_DEBUG_ACL,
322 "=> access_allowed: no more rules\n", 0, 0, 0);
329 LDAP_LOG( ACL, ENTRY,
330 "access_allowed: %s access %s by %s\n",
331 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
332 accessmask2str( mask, accessmaskbuf ) );
334 Debug( LDAP_DEBUG_ACL,
335 "=> access_allowed: %s access %s by %s\n",
336 access2str( access ),
337 ACL_GRANT(mask, access) ? "granted" : "denied",
338 accessmask2str( mask, accessmaskbuf ) );
341 ret = ACL_GRANT(mask, access);
344 if( state != NULL ) {
345 state->as_recorded |= ACL_STATE_RECORDED;
346 state->as_result = ret;
352 * acl_get - return the acl applicable to entry e, attribute
353 * attr. the acl returned is suitable for use in subsequent calls to
354 * acl_access_allowed().
357 static AccessControl *
364 AttributeDescription *desc,
366 regmatch_t *matches )
372 assert( count != NULL );
373 assert( desc != NULL );
375 attr = desc->ad_cname.bv_val;
377 assert( attr != NULL );
392 dnlen = e->e_nname.bv_len;
394 for ( ; a != NULL; a = a->acl_next ) {
397 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
398 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
400 LDAP_LOG( ACL, DETAIL1,
401 "acl_get: dnpat [%d] %s nsub: %d\n",
402 *count, a->acl_dn_pat.bv_val,
403 (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, DETAIL1, "acl_get: dn [%d] %s\n",
414 *count, a->acl_dn_pat.bv_val, 0 );
416 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
417 *count, a->acl_dn_pat.bv_val, 0 );
419 patlen = a->acl_dn_pat.bv_len;
420 if ( dnlen < patlen )
423 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
424 /* base dn -- entire object DN must match */
425 if ( dnlen != patlen )
428 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
431 if ( dnlen <= patlen )
434 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
437 rdnlen = dn_rdnlen( NULL, &e->e_nname );
438 if ( rdnlen != dnlen - patlen - 1 )
441 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
442 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
445 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
446 if ( dnlen <= patlen )
448 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
452 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
457 LDAP_LOG( ACL, DETAIL1,
458 "acl_get: [%d] matched\n", *count, 0, 0 );
460 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
465 if ( a->acl_filter != NULL ) {
466 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
467 if ( rc != LDAP_COMPARE_TRUE ) {
473 LDAP_LOG( ACL, DETAIL1,
474 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
476 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
479 if ( attr == NULL || a->acl_attrs == NULL ||
480 ad_inlist( desc, a->acl_attrs ) )
483 LDAP_LOG( ACL, DETAIL1,
484 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
486 Debug( LDAP_DEBUG_ACL,
487 "<= acl_get: [%d] acl %s attr: %s\n",
488 *count, e->e_dn, attr );
492 matches[0].rm_so = matches[0].rm_eo = -1;
496 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
498 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
504 * Record value-dependent access control state
506 #define ACL_RECORD_VALUE_STATE do { \
507 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
508 state->as_recorded |= ACL_STATE_RECORDED_VD; \
509 state->as_vd_acl = a; \
510 AC_MEMCPY( state->as_vd_acl_matches, matches, \
511 sizeof( state->as_vd_acl_matches )) ; \
512 state->as_vd_acl_count = count; \
513 state->as_vd_access = b; \
514 state->as_vd_access_count = i; \
519 * acl_mask - modifies mask based upon the given acl and the
520 * requested access to entry e, attribute attr, value val. if val
521 * is null, access to the whole attribute is assumed (all values).
523 * returns 0 access NOT allowed
527 static slap_control_t
535 AttributeDescription *desc,
539 AccessControlState *state )
541 int i, odnlen, patlen;
544 char accessmaskbuf[ACCESSMASK_MAXLEN];
549 assert( mask != NULL );
550 assert( desc != NULL );
552 attr = desc->ad_cname.bv_val;
554 assert( attr != NULL );
557 LDAP_LOG( ACL, ENTRY,
558 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
559 conn->c_connid, e->e_dn, attr );
562 " to %s by \"%s\", (%s) \n", 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, DETAIL1,
597 "acl_mask: conn %lu check a_dn_pat: %s\n",
598 conn->c_connid, b->a_dn_pat.bv_val ,0 );
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 ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
609 if ( op->o_ndn.bv_len != 0 ) {
613 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
614 if ( op->o_ndn.bv_len == 0 ) {
618 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
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, DETAIL1,
721 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
722 conn->c_connid, b->a_sockurl_pat.bv_val , 0 );
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, DETAIL1,
745 "acl_mask: conn %lu check a_domain_pat: %s\n",
746 conn->c_connid, b->a_domain_pat.bv_val , 0 );
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) - 1;
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, DETAIL1,
799 "acl_mask: conn %lu check a_perrname_path: %s\n",
800 conn->c_connid, b->a_peername_pat.bv_val , 0 );
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, DETAIL1,
822 "acl_mask: conn %lu check a_sockname_path: %s\n",
823 conn->c_connid, b->a_sockname_pat.bv_val , 0 );
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, DETAIL1,
857 "acl_mask: conn %lu check a_dn_pat: %s\n",
858 conn->c_connid, attr , 0 );
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, 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, DETAIL1,
982 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
984 conn->c_connid, b->a_authz.sai_transport_ssf,
985 op->o_transport_ssf );
987 Debug( LDAP_DEBUG_ACL,
988 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
989 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
991 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
996 if ( b->a_authz.sai_tls_ssf ) {
998 LDAP_LOG( ACL, DETAIL1,
999 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1001 conn->c_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1003 Debug( LDAP_DEBUG_ACL,
1004 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1005 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1007 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1012 if ( b->a_authz.sai_sasl_ssf ) {
1014 LDAP_LOG( ACL, DETAIL1,
1015 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1017 conn->c_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1019 Debug( LDAP_DEBUG_ACL,
1020 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1021 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1023 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1028 #ifdef SLAPD_ACI_ENABLED
1029 if ( b->a_aci_at != NULL ) {
1031 slap_access_t grant, deny, tgrant, tdeny;
1033 /* this case works different from the others above.
1034 * since aci's themselves give permissions, we need
1035 * to first check b->a_access_mask, the ACL's access level.
1038 if ( e->e_nname.bv_len == 0 ) {
1039 /* no ACIs in the root DSE */
1043 /* first check if the right being requested
1044 * is allowed by the ACL clause.
1046 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1050 /* get the aci attribute */
1051 at = attr_find( e->e_attrs, b->a_aci_at );
1056 ACL_RECORD_VALUE_STATE;
1058 /* start out with nothing granted, nothing denied */
1062 /* the aci is an multi-valued attribute. The
1063 * rights are determined by OR'ing the individual
1064 * rights given by the acis.
1066 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1067 if (aci_mask( be, conn, op,
1068 e, desc, val, &at->a_vals[i],
1069 matches, &grant, &deny ) != 0)
1076 /* remove anything that the ACL clause does not allow */
1077 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1078 tdeny &= ACL_PRIV_MASK;
1080 /* see if we have anything to contribute */
1081 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1085 /* this could be improved by changing acl_mask so that it can deal with
1086 * by clauses that return grant/deny pairs. Right now, it does either
1087 * additive or subtractive rights, but not both at the same time. So,
1088 * we need to combine the grant/deny pair into a single rights mask in
1089 * a smart way: if either grant or deny is "empty", then we use the
1090 * opposite as is, otherwise we remove any denied rights from the grant
1091 * rights mask and construct an additive mask.
1093 if (ACL_IS_INVALID(tdeny)) {
1094 modmask = tgrant | ACL_PRIV_ADDITIVE;
1096 } else if (ACL_IS_INVALID(tgrant)) {
1097 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1100 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1106 modmask = b->a_access_mask;
1110 LDAP_LOG( ACL, RESULTS,
1111 "acl_mask: [%d] applying %s (%s)\n",
1112 i, accessmask2str( modmask, accessmaskbuf),
1113 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1114 ? "break" : "stop" );
1116 Debug( LDAP_DEBUG_ACL,
1117 "<= acl_mask: [%d] applying %s (%s)\n",
1118 i, accessmask2str( modmask, accessmaskbuf ),
1119 b->a_type == ACL_CONTINUE
1121 : b->a_type == ACL_BREAK
1128 if( ACL_IS_ADDITIVE(modmask) ) {
1130 ACL_PRIV_SET( *mask, modmask );
1133 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1135 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1136 /* substract privs */
1137 ACL_PRIV_CLR( *mask, modmask );
1140 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1148 LDAP_LOG( ACL, DETAIL1,
1149 "acl_mask: conn %lu [%d] mask: %s\n",
1150 conn->c_connid, i, accessmask2str( *mask, accessmaskbuf) );
1152 Debug( LDAP_DEBUG_ACL,
1153 "<= acl_mask: [%d] mask: %s\n",
1154 i, accessmask2str(*mask, accessmaskbuf), 0 );
1157 if( b->a_type == ACL_CONTINUE ) {
1160 } else if ( b->a_type == ACL_BREAK ) {
1168 /* implicit "by * none" clause */
1172 LDAP_LOG( ACL, RESULTS,
1173 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1174 conn->c_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1176 Debug( LDAP_DEBUG_ACL,
1177 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1178 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1184 * acl_check_modlist - check access control on the given entry to see if
1185 * it allows the given modifications by the user associated with op.
1186 * returns 1 if mods allowed ok
1187 * 0 mods not allowed
1196 Modifications *mlist
1201 assert( be != NULL );
1203 /* short circuit root database access */
1204 if ( be_isroot( be, &op->o_ndn ) ) {
1206 LDAP_LOG( ACL, DETAIL1,
1207 "acl_check_modlist: conn %lu access granted to root user\n",
1208 conn->c_connid, 0, 0 );
1210 Debug( LDAP_DEBUG_ACL,
1211 "<= acl_access_allowed: granted to database root\n",
1217 /* use backend default access if no backend acls */
1218 if( be != NULL && be->be_acl == NULL ) {
1220 LDAP_LOG( ACL, DETAIL1,
1221 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1222 access2str( ACL_WRITE ),
1223 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1226 Debug( LDAP_DEBUG_ACL,
1227 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1228 access2str( ACL_WRITE ),
1229 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1231 return be->be_dfltaccess >= ACL_WRITE;
1234 /* be is always non-NULL */
1235 /* use global default access if no global acls */
1236 } else if ( be == NULL && global_acl == NULL ) {
1238 LDAP_LOG( ACL, DETAIL1,
1239 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1240 access2str( ACL_WRITE ),
1241 global_default_access >= ACL_WRITE ? "granted" : "denied",
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( ACL, 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 , 0 );
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, cp->op,
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, op, 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 ) - 1;
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.
1711 Differences: "this" in the draft is "self" here, and
1712 "self" and "public" is in the position of dnType.
1714 For now, this routine only supports scope=entry.
1717 /* check that the aci has all 5 components */
1718 if (aci_get_part(aci, 4, '#', NULL) < 0)
1721 /* check that the aci family is supported */
1722 if (aci_get_part(aci, 0, '#', &bv) < 0)
1725 /* check that the scope is "entry" */
1726 if (aci_get_part(aci, 1, '#', &bv) < 0
1727 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1732 /* get the list of permissions clauses, bail if empty */
1733 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1736 /* check if any permissions allow desired access */
1737 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1740 /* see if we have a DN match */
1741 if (aci_get_part(aci, 3, '#', &bv) < 0)
1744 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1747 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1750 if ( dnNormalize2(NULL, &sdn, &ndn) == LDAP_SUCCESS ) {
1751 if (dn_match( &op->o_ndn, &ndn))
1757 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1760 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1761 if (dn_match(&op->o_ndn, &e->e_nname))
1764 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1766 AttributeDescription *ad = NULL;
1769 rc = slap_bv2ad( &sdn, &ad, &text );
1771 if( rc != LDAP_SUCCESS ) {
1779 for(at = attrs_find( e->e_attrs, ad );
1781 at = attrs_find( at->a_next, ad ) )
1783 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1792 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1793 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, be, e, conn, op, matches))
1796 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1797 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, be, e, conn, op, matches))
1800 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1801 if (aci_match_set(&sdn, be, e, conn, op, 0))
1804 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1805 if (aci_match_set(&sdn, be, e, conn, op, 1))
1813 #endif /* SLAPD_ACI_ENABLED */
1820 regmatch_t *matches)
1828 bv->bv_val[0] = '\0';
1829 bv->bv_len--; /* leave space for lone $ */
1832 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1833 sp < pat->bv_val + pat->bv_len ; sp++ )
1835 /* did we previously see a $ */
1837 if ( flag == 1 && *sp == '$' ) {
1842 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
1845 } else if ( *sp >= '0' && *sp <= '9' ) {
1853 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
1854 if ( *sp >= '0' && *sp <= '9' ) {
1855 n = 10*n + ( *sp - '0' );
1859 if ( *sp != /*'{'*/ '}' ) {
1864 if ( n >= MAXREMATCHES ) {
1869 i = matches[n].rm_so;
1870 l = matches[n].rm_eo;
1871 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1889 /* must have ended with a single $ */
1898 LDAP_LOG( ACL, DETAIL1,
1899 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1900 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
1902 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1903 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1909 struct berval *pat, /* pattern to expand and match against */
1910 char *str, /* string to match against pattern */
1911 char *buf, /* buffer with $N expansion variables */
1912 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1916 char newbuf[ACL_BUF_SIZE];
1920 bv.bv_len = sizeof(newbuf) - 1;
1923 if(str == NULL) str = "";
1925 string_expand(&bv, pat, buf, matches);
1926 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1927 char error[ACL_BUF_SIZE];
1928 regerror(rc, &re, error, sizeof(error));
1932 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
1933 pat->bv_val, str, error );
1935 Debug( LDAP_DEBUG_TRACE,
1936 "compile( \"%s\", \"%s\") failed %s\n",
1937 pat->bv_val, str, error );
1942 rc = regexec(&re, str, 0, NULL, 0);
1946 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
1947 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
1948 rc, rc ? "matches" : "no matches", 0 );
1950 Debug( LDAP_DEBUG_TRACE,
1951 "=> regex_matches: string: %s\n", str, 0, 0 );
1952 Debug( LDAP_DEBUG_TRACE,
1953 "=> regex_matches: rc: %d %s\n",
1954 rc, !rc ? "matches" : "no matches", 0 );