1 /* acl.c - routines to parse and check acl's */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
20 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
26 aci_bv_entry = BER_BVC("entry"),
27 aci_bv_br_entry = BER_BVC("[entry]"),
28 aci_bv_br_all = BER_BVC("[all]"),
29 aci_bv_access_id = BER_BVC("access-id"),
30 aci_bv_anonymous = BER_BVC("anonymous"),
31 aci_bv_public = BER_BVC("public"),
32 aci_bv_users = BER_BVC("users"),
33 aci_bv_self = BER_BVC("self"),
34 aci_bv_dnattr = BER_BVC("dnattr"),
35 aci_bv_group = BER_BVC("group"),
36 aci_bv_role = BER_BVC("role"),
37 aci_bv_set = BER_BVC("set"),
38 aci_bv_set_ref = BER_BVC("set-ref"),
39 aci_bv_grant = BER_BVC("grant"),
40 aci_bv_deny = BER_BVC("deny"),
42 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
43 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
44 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
45 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR);
48 static AccessControl * acl_get(
49 AccessControl *ac, int *count,
50 Operation *op, Entry *e,
51 AttributeDescription *desc,
52 int nmatches, regmatch_t *matches );
54 static slap_control_t acl_mask(
55 AccessControl *ac, slap_mask_t *mask,
56 Operation *op, Entry *e,
57 AttributeDescription *desc,
61 AccessControlState *state );
63 #ifdef SLAPD_ACI_ENABLED
65 Operation *op, Entry *e,
66 AttributeDescription *desc,
71 slap_access_t *deny );
74 static int regex_matches(
75 struct berval *pat, char *str, char *buf, regmatch_t *matches);
76 static void string_expand(
77 struct berval *newbuf, struct berval *pattern,
78 char *match, regmatch_t *matches);
80 typedef struct AciSetCookie {
85 SLAP_SET_GATHER aci_set_gather;
86 static int aci_match_set ( struct berval *subj, Operation *op,
87 Entry *e, int setref );
90 * access_allowed - check whether op->o_ndn is allowed the requested access
91 * to entry e, attribute attr, value val. if val is null, access to
92 * the whole attribute is assumed (all values).
94 * This routine loops through all access controls and calls
95 * acl_mask() on each applicable access control.
96 * The loop exits when a definitive answer is reached or
97 * or no more controls remain.
108 AttributeDescription *desc,
110 slap_access_t access,
111 AccessControlState *state )
115 AccessControl *a = NULL;
120 char accessmaskbuf[ACCESSMASK_MAXLEN];
123 slap_control_t control;
125 regmatch_t matches[MAXREMATCHES];
126 int st_same_attr = 0;
127 int st_initialized = 0;
128 static AccessControlState state_init = ACL_STATE_INIT;
131 assert( desc != NULL );
132 assert( access > ACL_NONE );
134 attr = desc->ad_cname.bv_val;
136 assert( attr != NULL );
138 if( op && op->o_is_auth_check &&
139 ( access == ACL_SEARCH || access == ACL_READ ))
144 if( state && state->as_recorded && state->as_vd_ad==desc) {
145 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
148 return state->as_result;
150 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
151 val != NULL && state->as_vd_acl == NULL )
153 return state->as_result;
159 state->as_vd_ad=desc;
163 LDAP_LOG( ACL, ENTRY,
164 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
165 access2str( access ), e->e_dn, attr );
167 Debug( LDAP_DEBUG_ACL,
168 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
169 access2str( access ), e->e_dn, attr );
183 assert( be != NULL );
185 /* grant database root access */
186 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
189 "access_allowed: conn %lu root access granted\n",
190 op->o_connid, 0, 0 );
192 Debug( LDAP_DEBUG_ACL,
193 "<= root access granted\n",
200 * no-user-modification operational attributes are ignored
201 * by ACL_WRITE checking as any found here are not provided
204 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
205 && desc != slap_schema.si_ad_entry
206 && desc != slap_schema.si_ad_children )
209 LDAP_LOG( ACL, DETAIL1,
210 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
211 "access granted\n", op->o_connid, attr , 0 );
213 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
214 " %s access granted\n",
220 /* use backend default access if no backend acls */
221 if( be != NULL && be->be_acl == NULL ) {
223 LDAP_LOG( ACL, DETAIL1,
224 "access_allowed: backend default %s access %s to \"%s\"\n",
225 access2str( access ),
226 be->be_dfltaccess >= access ? "granted" : "denied",
227 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
229 Debug( LDAP_DEBUG_ACL,
230 "=> access_allowed: backend default %s access %s to \"%s\"\n",
231 access2str( access ),
232 be->be_dfltaccess >= access ? "granted" : "denied",
233 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
235 ret = be->be_dfltaccess >= access;
239 /* be is always non-NULL */
240 /* use global default access if no global acls */
241 } else if ( be == NULL && global_acl == NULL ) {
243 LDAP_LOG( ACL, DETAIL1,
244 "access_allowed: global default %s access %s to \"%s\"\n",
245 access2str( access ),
246 global_default_access >= access ? "granted" : "denied",
249 Debug( LDAP_DEBUG_ACL,
250 "=> access_allowed: global default %s access %s to \"%s\"\n",
251 access2str( access ),
252 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
254 ret = global_default_access >= access;
263 assert( state->as_vd_acl != NULL );
265 a = state->as_vd_acl;
266 mask = state->as_vd_acl_mask;
267 count = state->as_vd_acl_count;
268 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
275 memset(matches, '\0', sizeof(matches));
278 while((a = acl_get( a, &count, op, e, desc,
279 MAXREMATCHES, matches )) != NULL)
283 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
285 LDAP_LOG( ACL, DETAIL1,
286 "access_allowed: match[%d]: %d %d ",
287 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
289 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
290 (int)matches[i].rm_so, (int)matches[i].rm_eo );
292 if( matches[i].rm_so <= matches[0].rm_eo ) {
294 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
295 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
299 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
301 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
306 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
307 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
308 ret = state->as_result;
310 } else if (!st_initialized) {
311 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
313 state->as_vd_ad=desc;
319 control = acl_mask( a, &mask, op,
320 e, desc, val, matches, count, state );
322 if ( control != ACL_BREAK ) {
326 memset(matches, '\0', sizeof(matches));
329 if ( ACL_IS_INVALID( mask ) ) {
331 LDAP_LOG( ACL, DETAIL1,
332 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
333 op->o_connid, e->e_dn, attr );
335 Debug( LDAP_DEBUG_ACL,
336 "=> access_allowed: \"%s\" (%s) invalid!\n",
341 } else if ( control == ACL_BREAK ) {
343 LDAP_LOG( ACL, DETAIL1,
344 "access_allowed: conn %lu no more rules\n", op->o_connid, 0,0 );
346 Debug( LDAP_DEBUG_ACL,
347 "=> access_allowed: no more rules\n", 0, 0, 0);
354 LDAP_LOG( ACL, ENTRY,
355 "access_allowed: %s access %s by %s\n",
356 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
357 accessmask2str( mask, accessmaskbuf ) );
359 Debug( LDAP_DEBUG_ACL,
360 "=> access_allowed: %s access %s by %s\n",
361 access2str( access ),
362 ACL_GRANT(mask, access) ? "granted" : "denied",
363 accessmask2str( mask, accessmaskbuf ) );
366 ret = ACL_GRANT(mask, access);
369 if( state != NULL ) {
370 /* If not value-dependent, save ACL in case of more attrs */
371 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) )
372 state->as_vi_acl = a;
373 state->as_recorded |= ACL_STATE_RECORDED;
374 state->as_result = ret;
376 if (be_null) op->o_bd = NULL;
381 * acl_get - return the acl applicable to entry e, attribute
382 * attr. the acl returned is suitable for use in subsequent calls to
383 * acl_access_allowed().
386 static AccessControl *
392 AttributeDescription *desc,
394 regmatch_t *matches )
400 assert( count != NULL );
401 assert( desc != NULL );
403 attr = desc->ad_cname.bv_val;
405 assert( attr != NULL );
408 if( op->o_bd == NULL ) {
411 a = op->o_bd->be_acl;
420 dnlen = e->e_nname.bv_len;
422 for ( ; a != NULL; a = a->acl_next ) {
425 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
426 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
428 LDAP_LOG( ACL, DETAIL1,
429 "acl_get: dnpat [%d] %s nsub: %d\n",
430 *count, a->acl_dn_pat.bv_val,
431 (int) a->acl_dn_re.re_nsub );
433 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
434 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
436 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
441 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
442 *count, a->acl_dn_pat.bv_val, 0 );
444 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
445 *count, a->acl_dn_pat.bv_val, 0 );
447 patlen = a->acl_dn_pat.bv_len;
448 if ( dnlen < patlen )
451 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
452 /* base dn -- entire object DN must match */
453 if ( dnlen != patlen )
456 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
459 if ( dnlen <= patlen )
462 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
465 rdnlen = dn_rdnlen( NULL, &e->e_nname );
466 if ( rdnlen != dnlen - patlen - 1 )
469 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
470 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
473 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
474 if ( dnlen <= patlen )
476 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
480 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
485 LDAP_LOG( ACL, DETAIL1,
486 "acl_get: [%d] matched\n", *count, 0, 0 );
488 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
493 if ( a->acl_filter != NULL ) {
494 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
495 if ( rc != LDAP_COMPARE_TRUE ) {
501 LDAP_LOG( ACL, DETAIL1,
502 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
504 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
507 if ( attr == NULL || a->acl_attrs == NULL ||
508 ad_inlist( desc, a->acl_attrs ) )
511 LDAP_LOG( ACL, DETAIL1,
512 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
514 Debug( LDAP_DEBUG_ACL,
515 "<= acl_get: [%d] acl %s attr: %s\n",
516 *count, e->e_dn, attr );
520 matches[0].rm_so = matches[0].rm_eo = -1;
524 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
526 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
532 * Record value-dependent access control state
534 #define ACL_RECORD_VALUE_STATE do { \
535 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
536 state->as_recorded |= ACL_STATE_RECORDED_VD; \
537 state->as_vd_acl = a; \
538 AC_MEMCPY( state->as_vd_acl_matches, matches, \
539 sizeof( state->as_vd_acl_matches )) ; \
540 state->as_vd_acl_count = count; \
541 state->as_vd_access = b; \
542 state->as_vd_access_count = i; \
547 * acl_mask - modifies mask based upon the given acl and the
548 * requested access to entry e, attribute attr, value val. if val
549 * is null, access to the whole attribute is assumed (all values).
551 * returns 0 access NOT allowed
555 static slap_control_t
561 AttributeDescription *desc,
565 AccessControlState *state )
567 int i, odnlen, patlen;
570 char accessmaskbuf[ACCESSMASK_MAXLEN];
575 assert( mask != NULL );
576 assert( desc != NULL );
578 attr = desc->ad_cname.bv_val;
580 assert( attr != NULL );
583 LDAP_LOG( ACL, ENTRY,
584 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
585 op->o_connid, e->e_dn, attr );
588 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
589 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
590 accessmask2str( *mask, accessmaskbuf ) );
592 Debug( LDAP_DEBUG_ACL,
593 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
596 Debug( LDAP_DEBUG_ACL,
597 "=> acl_mask: to %s by \"%s\", (%s) \n",
598 val ? "value" : "all values",
599 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
600 accessmask2str( *mask, accessmaskbuf ) );
603 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
604 && state->as_vd_acl == a )
606 b = state->as_vd_access;
607 i = state->as_vd_access_count;
614 for ( ; b != NULL; b = b->a_next, i++ ) {
615 slap_mask_t oldmask, modmask;
617 ACL_INVALIDATE( modmask );
619 /* AND <who> clauses */
620 if ( b->a_dn_pat.bv_len != 0 ) {
622 LDAP_LOG( ACL, DETAIL1,
623 "acl_mask: conn %lu check a_dn_pat: %s\n",
624 op->o_connid, b->a_dn_pat.bv_val ,0 );
626 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
627 b->a_dn_pat.bv_val, 0, 0);
630 * if access applies to the entry itself, and the
631 * user is bound as somebody in the same namespace as
632 * the entry, OR the given dn matches the dn pattern
634 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
635 if ( op->o_ndn.bv_len != 0 ) {
639 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
640 if ( op->o_ndn.bv_len == 0 ) {
644 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
645 if ( op->o_ndn.bv_len == 0 ) {
649 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
653 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
654 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
655 int ret = regex_matches( &b->a_dn_pat,
656 op->o_ndn.bv_val, e->e_ndn, matches );
667 if ( e->e_dn == NULL )
670 if ( b->a_dn_expand ) {
672 char buf[ACL_BUF_SIZE];
674 bv.bv_len = sizeof( buf ) - 1;
677 string_expand(&bv, &b->a_dn_pat,
679 if ( dnNormalize(0, NULL, NULL, &bv, &pat, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
680 /* did not expand to a valid dn */
688 odnlen = op->o_ndn.bv_len;
689 if ( odnlen < patlen ) {
690 goto dn_match_cleanup;
694 if ( b->a_dn_style == ACL_STYLE_BASE ) {
695 /* base dn -- entire object DN must match */
696 if ( odnlen != patlen ) {
697 goto dn_match_cleanup;
700 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
703 if ( odnlen <= patlen ) {
704 goto dn_match_cleanup;
707 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
708 goto dn_match_cleanup;
711 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
712 if ( rdnlen != odnlen - patlen - 1 ) {
713 goto dn_match_cleanup;
716 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
717 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
718 goto dn_match_cleanup;
721 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
722 if ( odnlen <= patlen ) {
723 goto dn_match_cleanup;
726 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
727 goto dn_match_cleanup;
731 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
734 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
744 if ( b->a_sockurl_pat.bv_len ) {
745 if ( ! op->o_conn->c_listener ) {
749 LDAP_LOG( ACL, DETAIL1,
750 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
751 op->o_connid, b->a_sockurl_pat.bv_val , 0 );
753 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
754 b->a_sockurl_pat.bv_val, 0, 0 );
757 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
758 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
759 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
760 e->e_ndn, matches ) )
765 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
771 if ( b->a_domain_pat.bv_len ) {
772 if ( !op->o_conn->c_peer_domain.bv_val ) {
776 LDAP_LOG( ACL, DETAIL1,
777 "acl_mask: conn %lu check a_domain_pat: %s\n",
778 op->o_connid, b->a_domain_pat.bv_val , 0 );
780 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
781 b->a_domain_pat.bv_val, 0, 0 );
783 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
784 if ( b->a_domain_style == ACL_STYLE_REGEX) {
785 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
786 e->e_ndn, matches ) )
791 char buf[ACL_BUF_SIZE];
793 struct berval cmp = op->o_conn->c_peer_domain;
794 struct berval pat = b->a_domain_pat;
796 if ( b->a_domain_expand ) {
799 bv.bv_len = sizeof(buf) - 1;
802 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
806 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
807 int offset = cmp.bv_len - pat.bv_len;
812 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
816 /* trim the domain */
817 cmp.bv_val = &cmp.bv_val[ offset ];
818 cmp.bv_len -= offset;
821 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
828 if ( b->a_peername_pat.bv_len ) {
829 if ( !op->o_conn->c_peer_name.bv_val ) {
833 LDAP_LOG( ACL, DETAIL1,
834 "acl_mask: conn %lu check a_peername_path: %s\n",
835 op->o_connid, b->a_peername_pat.bv_val , 0 );
837 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
838 b->a_peername_pat.bv_val, 0, 0 );
840 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
841 if ( b->a_peername_style == ACL_STYLE_REGEX) {
842 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
843 e->e_ndn, matches ) )
848 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 )
854 if ( b->a_sockname_pat.bv_len ) {
855 if ( !op->o_conn->c_sock_name.bv_val ) {
859 LDAP_LOG( ACL, DETAIL1,
860 "acl_mask: conn %lu check a_sockname_path: %s\n",
861 op->o_connid, b->a_sockname_pat.bv_val , 0 );
863 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
864 b->a_sockname_pat.bv_val, 0, 0 );
866 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
867 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
868 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
869 e->e_ndn, matches ) )
874 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 )
880 if ( b->a_dn_at != NULL ) {
885 const char *attr = b->a_dn_at->ad_cname.bv_val;
887 assert( attr != NULL );
889 if ( op->o_ndn.bv_len == 0 ) {
894 LDAP_LOG( ACL, DETAIL1,
895 "acl_mask: conn %lu check a_dn_pat: %s\n",
896 op->o_connid, attr , 0 );
898 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
903 /* see if asker is listed in dnattr */
904 for( at = attrs_find( e->e_attrs, b->a_dn_at );
906 at = attrs_find( at->a_next, b->a_dn_at ) )
908 if( value_find_ex( b->a_dn_at,
909 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
910 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
912 &bv, op->o_tmpmemctx ) == 0 )
921 /* have a dnattr match. if this is a self clause then
922 * the target must also match the op dn.
924 if ( b->a_dn_self ) {
925 /* check if the target is an attribute. */
926 if ( val == NULL ) continue;
928 /* target is attribute, check if the attribute value
931 rc = value_match( &match, b->a_dn_at,
932 b->a_dn_at->ad_type->sat_equality, 0,
934 /* on match error or no match, fail the ACL clause */
935 if (rc != LDAP_SUCCESS || match != 0 )
939 /* no dnattr match, check if this is a self clause */
940 if ( ! b->a_dn_self )
943 ACL_RECORD_VALUE_STATE;
945 /* this is a self clause, check if the target is an
951 /* target is attribute, check if the attribute value
954 rc = value_match( &match, b->a_dn_at,
955 b->a_dn_at->ad_type->sat_equality, 0,
958 /* on match error or no match, fail the ACL clause */
959 if (rc != LDAP_SUCCESS || match != 0 )
964 if ( b->a_group_pat.bv_len ) {
966 struct berval ndn = { 0, NULL };
969 if ( op->o_ndn.bv_len == 0 ) {
973 /* b->a_group is an unexpanded entry name, expanded it should be an
974 * entry with objectclass group* and we test to see if odn is one of
975 * the values in the attribute group
977 /* see if asker is listed in dnattr */
978 if ( b->a_group_style == ACL_STYLE_REGEX ) {
979 char buf[ACL_BUF_SIZE];
980 bv.bv_len = sizeof(buf) - 1;
983 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
984 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
985 /* did not expand to a valid dn */
995 rc = backend_group( op, e, &bv, &op->o_ndn,
996 b->a_group_oc, b->a_group_at );
998 if ( ndn.bv_val ) free( ndn.bv_val );
1005 if ( b->a_set_pat.bv_len != 0 ) {
1007 char buf[ACL_BUF_SIZE];
1008 if( b->a_set_style == ACL_STYLE_REGEX ){
1009 bv.bv_len = sizeof(buf) - 1;
1011 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1015 if (aci_match_set( &bv, op, e, 0 ) == 0) {
1020 if ( b->a_authz.sai_ssf ) {
1022 LDAP_LOG( ACL, DETAIL1,
1023 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1024 op->o_connid, b->a_authz.sai_ssf, op->o_ssf );
1026 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1027 b->a_authz.sai_ssf, op->o_ssf, 0 );
1029 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1034 if ( b->a_authz.sai_transport_ssf ) {
1036 LDAP_LOG( ACL, DETAIL1,
1037 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1039 op->o_connid, b->a_authz.sai_transport_ssf,
1040 op->o_transport_ssf );
1042 Debug( LDAP_DEBUG_ACL,
1043 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1044 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1046 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1051 if ( b->a_authz.sai_tls_ssf ) {
1053 LDAP_LOG( ACL, DETAIL1,
1054 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1056 op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1058 Debug( LDAP_DEBUG_ACL,
1059 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1060 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1062 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1067 if ( b->a_authz.sai_sasl_ssf ) {
1069 LDAP_LOG( ACL, DETAIL1,
1070 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1072 op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1074 Debug( LDAP_DEBUG_ACL,
1075 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1076 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1078 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1083 #ifdef SLAPD_ACI_ENABLED
1084 if ( b->a_aci_at != NULL ) {
1086 slap_access_t grant, deny, tgrant, tdeny;
1088 /* this case works different from the others above.
1089 * since aci's themselves give permissions, we need
1090 * to first check b->a_access_mask, the ACL's access level.
1093 if ( e->e_nname.bv_len == 0 ) {
1094 /* no ACIs in the root DSE */
1098 /* first check if the right being requested
1099 * is allowed by the ACL clause.
1101 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1105 /* get the aci attribute */
1106 at = attr_find( e->e_attrs, b->a_aci_at );
1111 ACL_RECORD_VALUE_STATE;
1113 /* start out with nothing granted, nothing denied */
1117 /* the aci is an multi-valued attribute. The
1118 * rights are determined by OR'ing the individual
1119 * rights given by the acis.
1121 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1125 matches, &grant, &deny ) != 0)
1132 /* remove anything that the ACL clause does not allow */
1133 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1134 tdeny &= ACL_PRIV_MASK;
1136 /* see if we have anything to contribute */
1137 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1141 /* this could be improved by changing acl_mask so that it can deal with
1142 * by clauses that return grant/deny pairs. Right now, it does either
1143 * additive or subtractive rights, but not both at the same time. So,
1144 * we need to combine the grant/deny pair into a single rights mask in
1145 * a smart way: if either grant or deny is "empty", then we use the
1146 * opposite as is, otherwise we remove any denied rights from the grant
1147 * rights mask and construct an additive mask.
1149 if (ACL_IS_INVALID(tdeny)) {
1150 modmask = tgrant | ACL_PRIV_ADDITIVE;
1152 } else if (ACL_IS_INVALID(tgrant)) {
1153 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1156 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1162 modmask = b->a_access_mask;
1166 LDAP_LOG( ACL, RESULTS,
1167 "acl_mask: [%d] applying %s (%s)\n",
1168 i, accessmask2str( modmask, accessmaskbuf),
1169 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1170 ? "break" : "stop" );
1172 Debug( LDAP_DEBUG_ACL,
1173 "<= acl_mask: [%d] applying %s (%s)\n",
1174 i, accessmask2str( modmask, accessmaskbuf ),
1175 b->a_type == ACL_CONTINUE
1177 : b->a_type == ACL_BREAK
1184 if( ACL_IS_ADDITIVE(modmask) ) {
1186 ACL_PRIV_SET( *mask, modmask );
1189 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1191 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1192 /* substract privs */
1193 ACL_PRIV_CLR( *mask, modmask );
1196 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1204 LDAP_LOG( ACL, DETAIL1,
1205 "acl_mask: conn %lu [%d] mask: %s\n",
1206 op->o_connid, i, accessmask2str( *mask, accessmaskbuf) );
1208 Debug( LDAP_DEBUG_ACL,
1209 "<= acl_mask: [%d] mask: %s\n",
1210 i, accessmask2str(*mask, accessmaskbuf), 0 );
1213 if( b->a_type == ACL_CONTINUE ) {
1216 } else if ( b->a_type == ACL_BREAK ) {
1224 /* implicit "by * none" clause */
1228 LDAP_LOG( ACL, RESULTS,
1229 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1230 op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1232 Debug( LDAP_DEBUG_ACL,
1233 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1234 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1240 * acl_check_modlist - check access control on the given entry to see if
1241 * it allows the given modifications by the user associated with op.
1242 * returns 1 if mods allowed ok
1243 * 0 mods not allowed
1250 Modifications *mlist
1254 AccessControlState state = ACL_STATE_INIT;
1256 assert( op->o_bd != NULL );
1258 /* short circuit root database access */
1259 if ( be_isroot( op->o_bd, &op->o_ndn ) ) {
1261 LDAP_LOG( ACL, DETAIL1,
1262 "acl_check_modlist: conn %lu access granted to root user\n",
1263 op->o_connid, 0, 0 );
1265 Debug( LDAP_DEBUG_ACL,
1266 "<= acl_access_allowed: granted to database root\n",
1272 /* use backend default access if no backend acls */
1273 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1275 LDAP_LOG( ACL, DETAIL1,
1276 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1277 access2str( ACL_WRITE ),
1278 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1281 Debug( LDAP_DEBUG_ACL,
1282 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1283 access2str( ACL_WRITE ),
1284 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1286 return op->o_bd->be_dfltaccess >= ACL_WRITE;
1289 /* op->o_bd is always non-NULL */
1290 /* use global default access if no global acls */
1291 } else if ( op->o_bd == NULL && global_acl == NULL ) {
1293 LDAP_LOG( ACL, DETAIL1,
1294 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1295 access2str( ACL_WRITE ),
1296 global_default_access >= ACL_WRITE ? "granted" : "denied",
1299 Debug( LDAP_DEBUG_ACL,
1300 "=> access_allowed: global default %s access %s to \"%s\"\n",
1301 access2str( ACL_WRITE ),
1302 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1304 return global_default_access >= ACL_WRITE;
1308 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1310 * no-user-modification operational attributes are ignored
1311 * by ACL_WRITE checking as any found here are not provided
1314 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1316 LDAP_LOG( ACL, DETAIL1,
1317 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1318 op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1320 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1321 " modify access granted\n",
1322 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1327 switch ( mlist->sml_op ) {
1328 case LDAP_MOD_REPLACE:
1330 * We must check both permission to delete the whole
1331 * attribute and permission to add the specific attributes.
1332 * This prevents abuse from selfwriters.
1334 if ( ! access_allowed( op, e,
1335 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1340 if ( mlist->sml_bvalues == NULL ) break;
1342 /* fall thru to check value to add */
1345 assert( mlist->sml_bvalues != NULL );
1347 for ( bv = mlist->sml_nvalues
1348 ? mlist->sml_nvalues : mlist->sml_values;
1349 bv->bv_val != NULL; bv++ )
1351 if ( ! access_allowed( op, e,
1352 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1359 case LDAP_MOD_DELETE:
1360 if ( mlist->sml_bvalues == NULL ) {
1361 if ( ! access_allowed( op, e,
1362 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1368 for ( bv = mlist->sml_nvalues
1369 ? mlist->sml_nvalues : mlist->sml_values;
1370 bv->bv_val != NULL; bv++ )
1372 if ( ! access_allowed( op, e,
1373 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1380 case SLAP_MOD_SOFTADD:
1381 /* allow adding attribute via modrdn thru */
1395 struct berval *list,
1409 while (len >= 0 && --ix >= 0) {
1410 while (--len >= 0 && *p++ != sep) ;
1412 while (len >= 0 && *p == ' ') {
1423 while (--len >= 0 && *p != sep) {
1427 while (bv->bv_len > 0 && *--p == ' ')
1433 aci_set_gather (SetCookie *cookie, struct berval *name, struct berval *attr)
1435 AciSetCookie *cp = (AciSetCookie *)cookie;
1436 BerVarray bvals = NULL;
1439 /* this routine needs to return the bervals instead of
1440 * plain strings, since syntax is not known. It should
1441 * also return the syntax or some "comparison cookie".
1444 if (dnNormalize(0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx) == LDAP_SUCCESS) {
1446 AttributeDescription *desc = NULL;
1447 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1448 backend_attribute(cp->op,
1449 cp->e, &ndn, desc, &bvals);
1451 sl_free(ndn.bv_val, cp->op->o_tmpmemctx);
1458 struct berval *subj,
1464 struct berval set = { 0, NULL };
1466 AciSetCookie cookie;
1469 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
1471 struct berval subjdn, ndn = { 0, NULL };
1472 struct berval setat;
1475 AttributeDescription *desc = NULL;
1477 /* format of string is "entry/setAttrName" */
1478 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1482 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1483 setat.bv_val = SLAPD_ACI_SET_ATTR;
1484 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1487 if ( setat.bv_val != NULL ) {
1489 * NOTE: dnNormalize honors the ber_len field
1490 * as the length of the dn to be normalized
1492 if ( dnNormalize(0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS
1493 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1495 backend_attribute(op, e,
1496 &ndn, desc, &bvals);
1497 if ( bvals != NULL ) {
1498 if ( bvals[0].bv_val != NULL ) {
1501 bvals[0].bv_val = NULL;
1502 for (i=1;bvals[i].bv_val;i++);
1503 bvals[0].bv_val = bvals[i-1].bv_val;
1504 bvals[i-1].bv_val = NULL;
1506 ber_bvarray_free_x(bvals, op->o_tmpmemctx);
1514 if (set.bv_val != NULL) {
1517 rc = (slap_set_filter(aci_set_gather, (SetCookie *)&cookie, &set,
1518 &op->o_ndn, &e->e_nname, NULL) > 0);
1519 sl_free(set.bv_val, op->o_tmpmemctx);
1524 #ifdef SLAPD_ACI_ENABLED
1526 aci_list_map_rights(
1527 struct berval *list )
1534 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1537 switch (*bv.bv_val) {
1539 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1542 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1543 * the right 's' to mean "set", but in the examples states
1544 * that the right 's' means "search". The latter definition
1547 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1550 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1553 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1556 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1557 * define any equivalent to the AUTH right, so I've just used
1560 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1572 struct berval *list,
1573 const struct berval *attr,
1574 struct berval *val )
1576 struct berval bv, left, right;
1579 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1580 if (aci_get_part(&bv, 0, '=', &left) < 0
1581 || aci_get_part(&bv, 1, '=', &right) < 0)
1583 if (ber_bvstrcasecmp(attr, &bv) == 0)
1585 } else if (val == NULL) {
1586 if (ber_bvstrcasecmp(attr, &left) == 0)
1589 if (ber_bvstrcasecmp(attr, &left) == 0) {
1590 /* this is experimental code that implements a
1591 * simple (prefix) match of the attribute value.
1592 * the ACI draft does not provide for aci's that
1593 * apply to specific values, but it would be
1594 * nice to have. If the <attr> part of an aci's
1595 * rights list is of the form <attr>=<value>,
1596 * that means the aci applies only to attrs with
1597 * the given value. Furthermore, if the attr is
1598 * of the form <attr>=<value>*, then <value> is
1599 * treated as a prefix, and the aci applies to
1600 * any value with that prefix.
1602 * Ideally, this would allow r.e. matches.
1604 if (aci_get_part(&right, 0, '*', &left) < 0
1605 || right.bv_len <= left.bv_len)
1607 if (ber_bvstrcasecmp(val, &right) == 0)
1609 } else if (val->bv_len >= left.bv_len) {
1610 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1619 static slap_access_t
1620 aci_list_get_attr_rights(
1621 struct berval *list,
1622 const struct berval *attr,
1623 struct berval *val )
1629 /* loop through each rights/attr pair, skip first part (action) */
1631 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1632 if (aci_list_has_attr(&bv, attr, val) == 0)
1634 if (aci_get_part(list, i, ';', &bv) < 0)
1636 mask |= aci_list_map_rights(&bv);
1642 aci_list_get_rights(
1643 struct berval *list,
1644 const struct berval *attr,
1646 slap_access_t *grant,
1647 slap_access_t *deny )
1649 struct berval perm, actn;
1650 slap_access_t *mask;
1653 if (attr == NULL || attr->bv_len == 0
1654 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1655 attr = &aci_bv_br_entry;
1661 /* loop through each permissions clause */
1662 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1663 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1665 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1667 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1674 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1675 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1682 struct berval *subj,
1683 struct berval *defgrpoc,
1684 struct berval *defgrpat,
1690 struct berval subjdn;
1691 struct berval grpoc;
1692 struct berval grpat;
1693 ObjectClass *grp_oc = NULL;
1694 AttributeDescription *grp_ad = NULL;
1698 /* format of string is "group/objectClassValue/groupAttrName" */
1699 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1703 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1707 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1711 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1712 if( rc != LDAP_SUCCESS ) {
1718 grp_oc = oc_bvfind( &grpoc );
1720 if (grp_oc != NULL && grp_ad != NULL ) {
1721 char buf[ACL_BUF_SIZE];
1722 struct berval bv, ndn;
1723 bv.bv_len = sizeof( buf ) - 1;
1724 bv.bv_val = (char *)&buf;
1725 string_expand(&bv, &subjdn, e->e_ndn, matches);
1726 if ( dnNormalize(0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1727 rc = (backend_group(op, e, &ndn, &op->o_ndn,
1728 grp_oc, grp_ad) == 0);
1741 AttributeDescription *desc,
1744 regmatch_t *matches,
1745 slap_access_t *grant,
1749 struct berval bv, perms, sdn;
1753 assert( desc->ad_cname.bv_val != NULL );
1755 /* parse an aci of the form:
1756 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1758 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1759 a full description of the format for this attribute.
1760 Differences: "this" in the draft is "self" here, and
1761 "self" and "public" is in the position of dnType.
1763 For now, this routine only supports scope=entry.
1766 /* check that the aci has all 5 components */
1767 if (aci_get_part(aci, 4, '#', NULL) < 0)
1770 /* check that the aci family is supported */
1771 if (aci_get_part(aci, 0, '#', &bv) < 0)
1774 /* check that the scope is "entry" */
1775 if (aci_get_part(aci, 1, '#', &bv) < 0
1776 || ber_bvstrcasecmp( &aci_bv_entry, &bv ) != 0)
1781 /* get the list of permissions clauses, bail if empty */
1782 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1785 /* check if any permissions allow desired access */
1786 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1789 /* see if we have a DN match */
1790 if (aci_get_part(aci, 3, '#', &bv) < 0)
1793 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1796 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1799 if ( dnNormalize(0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1800 if (dn_match( &op->o_ndn, &ndn))
1806 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1809 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1810 if (dn_match(&op->o_ndn, &e->e_nname))
1813 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1815 AttributeDescription *ad = NULL;
1818 rc = slap_bv2ad( &sdn, &ad, &text );
1820 if( rc != LDAP_SUCCESS ) {
1828 for(at = attrs_find( e->e_attrs, ad );
1830 at = attrs_find( at->a_next, ad ) )
1832 if (value_find_ex( ad,
1833 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1834 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1836 &bv, op->o_tmpmemctx) == 0 )
1846 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1847 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, op, e, matches))
1850 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1851 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, op, e, matches))
1854 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1855 if (aci_match_set(&sdn, op, e, 0))
1858 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1859 if (aci_match_set(&sdn, op, e, 1))
1867 #endif /* SLAPD_ACI_ENABLED */
1874 regmatch_t *matches)
1882 bv->bv_val[0] = '\0';
1883 bv->bv_len--; /* leave space for lone $ */
1886 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1887 sp < pat->bv_val + pat->bv_len ; sp++ )
1889 /* did we previously see a $ */
1891 if ( flag == 1 && *sp == '$' ) {
1896 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
1899 } else if ( *sp >= '0' && *sp <= '9' ) {
1907 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
1908 if ( *sp >= '0' && *sp <= '9' ) {
1909 n = 10*n + ( *sp - '0' );
1913 if ( *sp != /*'{'*/ '}' ) {
1918 if ( n >= MAXREMATCHES ) {
1923 i = matches[n].rm_so;
1924 l = matches[n].rm_eo;
1925 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
1943 /* must have ended with a single $ */
1952 LDAP_LOG( ACL, DETAIL1,
1953 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1954 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
1956 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
1957 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
1963 struct berval *pat, /* pattern to expand and match against */
1964 char *str, /* string to match against pattern */
1965 char *buf, /* buffer with $N expansion variables */
1966 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1970 char newbuf[ACL_BUF_SIZE];
1974 bv.bv_len = sizeof(newbuf) - 1;
1977 if(str == NULL) str = "";
1979 string_expand(&bv, pat, buf, matches);
1980 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1981 char error[ACL_BUF_SIZE];
1982 regerror(rc, &re, error, sizeof(error));
1986 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
1987 pat->bv_val, str, error );
1989 Debug( LDAP_DEBUG_TRACE,
1990 "compile( \"%s\", \"%s\") failed %s\n",
1991 pat->bv_val, str, error );
1996 rc = regexec(&re, str, 0, NULL, 0);
2000 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
2001 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
2002 rc, rc ? "matches" : "no matches", 0 );
2004 Debug( LDAP_DEBUG_TRACE,
2005 "=> regex_matches: string: %s\n", str, 0, 0 );
2006 Debug( LDAP_DEBUG_TRACE,
2007 "=> regex_matches: rc: %d %s\n",
2008 rc, !rc ? "matches" : "no matches", 0 );