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_children = BER_BVC("children"),
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_public = BER_BVC("public"),
33 aci_bv_users = BER_BVC("users"),
34 aci_bv_self = BER_BVC("self"),
35 aci_bv_dnattr = BER_BVC("dnattr"),
36 aci_bv_group = BER_BVC("group"),
37 aci_bv_role = BER_BVC("role"),
38 aci_bv_set = BER_BVC("set"),
39 aci_bv_set_ref = BER_BVC("set-ref"),
40 aci_bv_grant = BER_BVC("grant"),
41 aci_bv_deny = BER_BVC("deny"),
43 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
44 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
45 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
46 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR);
49 static AccessControl * acl_get(
50 AccessControl *ac, int *count,
51 Operation *op, Entry *e,
52 AttributeDescription *desc,
53 int nmatches, regmatch_t *matches );
55 static slap_control_t acl_mask(
56 AccessControl *ac, slap_mask_t *mask,
57 Operation *op, Entry *e,
58 AttributeDescription *desc,
62 AccessControlState *state );
64 #ifdef SLAPD_ACI_ENABLED
66 Operation *op, Entry *e,
67 AttributeDescription *desc,
73 struct berval *scope);
76 static int regex_matches(
77 struct berval *pat, char *str, char *buf, regmatch_t *matches);
78 static void string_expand(
79 struct berval *newbuf, struct berval *pattern,
80 char *match, regmatch_t *matches);
82 typedef struct AciSetCookie {
87 SLAP_SET_GATHER aci_set_gather;
88 static int aci_match_set ( struct berval *subj, Operation *op,
89 Entry *e, int setref );
92 * access_allowed - check whether op->o_ndn is allowed the requested access
93 * to entry e, attribute attr, value val. if val is null, access to
94 * the whole attribute is assumed (all values).
96 * This routine loops through all access controls and calls
97 * acl_mask() on each applicable access control.
98 * The loop exits when a definitive answer is reached or
99 * or no more controls remain.
110 AttributeDescription *desc,
112 slap_access_t access,
113 AccessControlState *state )
117 AccessControl *a = NULL;
122 char accessmaskbuf[ACCESSMASK_MAXLEN];
125 slap_control_t control;
127 regmatch_t matches[MAXREMATCHES];
128 int st_same_attr = 0;
129 int st_initialized = 0;
130 static AccessControlState state_init = ACL_STATE_INIT;
133 assert( desc != NULL );
134 assert( access > ACL_NONE );
136 attr = desc->ad_cname.bv_val;
138 assert( attr != NULL );
140 if( op && op->o_is_auth_check &&
141 ( access == ACL_SEARCH || access == ACL_READ ))
146 if( state && state->as_recorded && state->as_vd_ad==desc) {
147 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
150 return state->as_result;
152 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
153 val != NULL && state->as_vd_acl == NULL )
155 return state->as_result;
161 state->as_vd_ad=desc;
165 LDAP_LOG( ACL, ENTRY,
166 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
167 access2str( access ), e->e_dn, attr );
169 Debug( LDAP_DEBUG_ACL,
170 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
171 access2str( access ), e->e_dn, attr );
180 ret = slapi_x_access_allowed( op, e, desc, val, access, state );
182 /* ACL plugin denied access */
185 #endif /* LDAP_SLAPI */
193 assert( be != NULL );
195 /* grant database root access */
196 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
199 "access_allowed: conn %lu root access granted\n",
200 op->o_connid, 0, 0 );
202 Debug( LDAP_DEBUG_ACL,
203 "<= root access granted\n",
210 * no-user-modification operational attributes are ignored
211 * by ACL_WRITE checking as any found here are not provided
214 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
215 && desc != slap_schema.si_ad_entry
216 && desc != slap_schema.si_ad_children )
219 LDAP_LOG( ACL, DETAIL1,
220 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
221 "access granted\n", op->o_connid, attr , 0 );
223 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
224 " %s access granted\n",
230 /* use backend default access if no backend acls */
231 if( be != NULL && be->be_acl == NULL ) {
233 LDAP_LOG( ACL, DETAIL1,
234 "access_allowed: backend default %s access %s to \"%s\"\n",
235 access2str( access ),
236 be->be_dfltaccess >= access ? "granted" : "denied",
237 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
239 Debug( LDAP_DEBUG_ACL,
240 "=> access_allowed: backend default %s access %s to \"%s\"\n",
241 access2str( access ),
242 be->be_dfltaccess >= access ? "granted" : "denied",
243 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
245 ret = be->be_dfltaccess >= access;
249 /* be is always non-NULL */
250 /* use global default access if no global acls */
251 } else if ( be == NULL && global_acl == NULL ) {
253 LDAP_LOG( ACL, DETAIL1,
254 "access_allowed: global default %s access %s to \"%s\"\n",
255 access2str( access ),
256 global_default_access >= access ? "granted" : "denied",
259 Debug( LDAP_DEBUG_ACL,
260 "=> access_allowed: global default %s access %s to \"%s\"\n",
261 access2str( access ),
262 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
264 ret = global_default_access >= access;
273 assert( state->as_vd_acl != NULL );
275 a = state->as_vd_acl;
276 mask = state->as_vd_acl_mask;
277 count = state->as_vd_acl_count;
278 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
282 if ( state ) state->as_vi_acl = NULL;
286 memset(matches, '\0', sizeof(matches));
289 while((a = acl_get( a, &count, op, e, desc,
290 MAXREMATCHES, matches )) != NULL)
294 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
296 LDAP_LOG( ACL, DETAIL1,
297 "access_allowed: match[%d]: %d %d ",
298 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
300 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
301 (int)matches[i].rm_so, (int)matches[i].rm_eo );
303 if( matches[i].rm_so <= matches[0].rm_eo ) {
305 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
306 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
310 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
312 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
317 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
318 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
319 ret = state->as_result;
321 } else if (!st_initialized) {
322 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
324 state->as_vd_ad=desc;
330 control = acl_mask( a, &mask, op,
331 e, desc, val, matches, count, state );
333 if ( control != ACL_BREAK ) {
337 memset(matches, '\0', sizeof(matches));
340 if ( ACL_IS_INVALID( mask ) ) {
342 LDAP_LOG( ACL, DETAIL1,
343 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
344 op->o_connid, e->e_dn, attr );
346 Debug( LDAP_DEBUG_ACL,
347 "=> access_allowed: \"%s\" (%s) invalid!\n",
352 } else if ( control == ACL_BREAK ) {
354 LDAP_LOG( ACL, DETAIL1,
355 "access_allowed: conn %lu no more rules\n", op->o_connid, 0,0 );
357 Debug( LDAP_DEBUG_ACL,
358 "=> access_allowed: no more rules\n", 0, 0, 0);
365 LDAP_LOG( ACL, ENTRY,
366 "access_allowed: %s access %s by %s\n",
367 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
368 accessmask2str( mask, accessmaskbuf ) );
370 Debug( LDAP_DEBUG_ACL,
371 "=> access_allowed: %s access %s by %s\n",
372 access2str( access ),
373 ACL_GRANT(mask, access) ? "granted" : "denied",
374 accessmask2str( mask, accessmaskbuf ) );
377 ret = ACL_GRANT(mask, access);
380 if( state != NULL ) {
381 /* If not value-dependent, save ACL in case of more attrs */
382 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) )
383 state->as_vi_acl = a;
384 state->as_recorded |= ACL_STATE_RECORDED;
385 state->as_result = ret;
387 if (be_null) op->o_bd = NULL;
392 * acl_get - return the acl applicable to entry e, attribute
393 * attr. the acl returned is suitable for use in subsequent calls to
394 * acl_access_allowed().
397 static AccessControl *
403 AttributeDescription *desc,
405 regmatch_t *matches )
411 assert( count != NULL );
412 assert( desc != NULL );
414 attr = desc->ad_cname.bv_val;
416 assert( attr != NULL );
419 if( op->o_bd == NULL ) {
422 a = op->o_bd->be_acl;
431 dnlen = e->e_nname.bv_len;
433 for ( ; a != NULL; a = a->acl_next ) {
436 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
437 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
439 LDAP_LOG( ACL, DETAIL1,
440 "acl_get: dnpat [%d] %s nsub: %d\n",
441 *count, a->acl_dn_pat.bv_val,
442 (int) a->acl_dn_re.re_nsub );
444 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
445 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
447 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
452 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
453 *count, a->acl_dn_pat.bv_val, 0 );
455 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
456 *count, a->acl_dn_pat.bv_val, 0 );
458 patlen = a->acl_dn_pat.bv_len;
459 if ( dnlen < patlen )
462 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
463 /* base dn -- entire object DN must match */
464 if ( dnlen != patlen )
467 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
470 if ( dnlen <= patlen )
473 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
476 rdnlen = dn_rdnlen( NULL, &e->e_nname );
477 if ( rdnlen != dnlen - patlen - 1 )
480 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
481 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
484 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
485 if ( dnlen <= patlen )
487 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
491 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
496 LDAP_LOG( ACL, DETAIL1,
497 "acl_get: [%d] matched\n", *count, 0, 0 );
499 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
504 if ( a->acl_filter != NULL ) {
505 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
506 if ( rc != LDAP_COMPARE_TRUE ) {
512 LDAP_LOG( ACL, DETAIL1,
513 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
515 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
518 if ( attr == NULL || a->acl_attrs == NULL ||
519 ad_inlist( desc, a->acl_attrs ) )
522 LDAP_LOG( ACL, DETAIL1,
523 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
525 Debug( LDAP_DEBUG_ACL,
526 "<= acl_get: [%d] acl %s attr: %s\n",
527 *count, e->e_dn, attr );
531 matches[0].rm_so = matches[0].rm_eo = -1;
535 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
537 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
543 * Record value-dependent access control state
545 #define ACL_RECORD_VALUE_STATE do { \
546 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
547 state->as_recorded |= ACL_STATE_RECORDED_VD; \
548 state->as_vd_acl = a; \
549 AC_MEMCPY( state->as_vd_acl_matches, matches, \
550 sizeof( state->as_vd_acl_matches )) ; \
551 state->as_vd_acl_count = count; \
552 state->as_vd_access = b; \
553 state->as_vd_access_count = i; \
558 * acl_mask - modifies mask based upon the given acl and the
559 * requested access to entry e, attribute attr, value val. if val
560 * is null, access to the whole attribute is assumed (all values).
562 * returns 0 access NOT allowed
566 static slap_control_t
572 AttributeDescription *desc,
576 AccessControlState *state )
578 int i, odnlen, patlen;
581 char accessmaskbuf[ACCESSMASK_MAXLEN];
582 char accessmaskbuf1[ACCESSMASK_MAXLEN];
587 assert( mask != NULL );
588 assert( desc != NULL );
590 attr = desc->ad_cname.bv_val;
592 assert( attr != NULL );
595 LDAP_LOG( ACL, ENTRY,
596 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
597 op->o_connid, e->e_dn, attr );
600 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
601 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
602 accessmask2str( *mask, accessmaskbuf ) );
604 Debug( LDAP_DEBUG_ACL,
605 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
608 Debug( LDAP_DEBUG_ACL,
609 "=> acl_mask: to %s by \"%s\", (%s) \n",
610 val ? "value" : "all values",
611 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
612 accessmask2str( *mask, accessmaskbuf ) );
615 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
616 && state->as_vd_acl == a )
618 b = state->as_vd_access;
619 i = state->as_vd_access_count;
626 for ( ; b != NULL; b = b->a_next, i++ ) {
627 slap_mask_t oldmask, modmask;
629 ACL_INVALIDATE( modmask );
631 /* AND <who> clauses */
632 if ( b->a_dn_pat.bv_len != 0 ) {
634 LDAP_LOG( ACL, DETAIL1,
635 "acl_mask: conn %lu check a_dn_pat: %s\n",
636 op->o_connid, b->a_dn_pat.bv_val ,0 );
638 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
639 b->a_dn_pat.bv_val, 0, 0);
642 * if access applies to the entry itself, and the
643 * user is bound as somebody in the same namespace as
644 * the entry, OR the given dn matches the dn pattern
646 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
647 if ( op->o_ndn.bv_len != 0 ) {
651 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
652 if ( op->o_ndn.bv_len == 0 ) {
656 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
657 if ( op->o_ndn.bv_len == 0 ) {
661 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
665 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
666 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
667 int ret = regex_matches( &b->a_dn_pat,
668 op->o_ndn.bv_val, e->e_ndn, matches );
679 if ( e->e_dn == NULL )
682 if ( b->a_dn_expand ) {
684 char buf[ACL_BUF_SIZE];
686 bv.bv_len = sizeof( buf ) - 1;
689 string_expand(&bv, &b->a_dn_pat,
691 if ( dnNormalize(0, NULL, NULL, &bv, &pat, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
692 /* did not expand to a valid dn */
700 odnlen = op->o_ndn.bv_len;
701 if ( odnlen < patlen ) {
702 goto dn_match_cleanup;
706 if ( b->a_dn_style == ACL_STYLE_BASE ) {
707 /* base dn -- entire object DN must match */
708 if ( odnlen != patlen ) {
709 goto dn_match_cleanup;
712 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
715 if ( odnlen <= patlen ) {
716 goto dn_match_cleanup;
719 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
720 goto dn_match_cleanup;
723 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
724 if ( rdnlen != odnlen - patlen - 1 ) {
725 goto dn_match_cleanup;
728 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
729 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
730 goto dn_match_cleanup;
733 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
734 if ( odnlen <= patlen ) {
735 goto dn_match_cleanup;
738 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
739 goto dn_match_cleanup;
743 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
746 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
756 if ( b->a_sockurl_pat.bv_len ) {
757 if ( ! op->o_conn->c_listener ) {
761 LDAP_LOG( ACL, DETAIL1,
762 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
763 op->o_connid, b->a_sockurl_pat.bv_val , 0 );
765 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
766 b->a_sockurl_pat.bv_val, 0, 0 );
769 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
770 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
771 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
772 e->e_ndn, matches ) )
777 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
783 if ( b->a_domain_pat.bv_len ) {
784 if ( !op->o_conn->c_peer_domain.bv_val ) {
788 LDAP_LOG( ACL, DETAIL1,
789 "acl_mask: conn %lu check a_domain_pat: %s\n",
790 op->o_connid, b->a_domain_pat.bv_val , 0 );
792 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
793 b->a_domain_pat.bv_val, 0, 0 );
795 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
796 if ( b->a_domain_style == ACL_STYLE_REGEX) {
797 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
798 e->e_ndn, matches ) )
803 char buf[ACL_BUF_SIZE];
805 struct berval cmp = op->o_conn->c_peer_domain;
806 struct berval pat = b->a_domain_pat;
808 if ( b->a_domain_expand ) {
811 bv.bv_len = sizeof(buf) - 1;
814 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
818 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
819 int offset = cmp.bv_len - pat.bv_len;
824 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
828 /* trim the domain */
829 cmp.bv_val = &cmp.bv_val[ offset ];
830 cmp.bv_len -= offset;
833 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
840 if ( b->a_peername_pat.bv_len ) {
841 if ( !op->o_conn->c_peer_name.bv_val ) {
845 LDAP_LOG( ACL, DETAIL1,
846 "acl_mask: conn %lu check a_peername_path: %s\n",
847 op->o_connid, b->a_peername_pat.bv_val , 0 );
849 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
850 b->a_peername_pat.bv_val, 0, 0 );
852 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
853 if ( b->a_peername_style == ACL_STYLE_REGEX) {
854 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
855 e->e_ndn, matches ) )
860 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 )
866 if ( b->a_sockname_pat.bv_len ) {
867 if ( !op->o_conn->c_sock_name.bv_val ) {
871 LDAP_LOG( ACL, DETAIL1,
872 "acl_mask: conn %lu check a_sockname_path: %s\n",
873 op->o_connid, b->a_sockname_pat.bv_val , 0 );
875 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
876 b->a_sockname_pat.bv_val, 0, 0 );
878 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
879 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
880 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
881 e->e_ndn, matches ) )
886 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 )
892 if ( b->a_dn_at != NULL ) {
897 const char *attr = b->a_dn_at->ad_cname.bv_val;
899 assert( attr != NULL );
901 if ( op->o_ndn.bv_len == 0 ) {
906 LDAP_LOG( ACL, DETAIL1,
907 "acl_mask: conn %lu check a_dn_pat: %s\n",
908 op->o_connid, attr , 0 );
910 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
915 /* see if asker is listed in dnattr */
916 for( at = attrs_find( e->e_attrs, b->a_dn_at );
918 at = attrs_find( at->a_next, b->a_dn_at ) )
920 if( value_find_ex( b->a_dn_at,
921 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
922 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
924 &bv, op->o_tmpmemctx ) == 0 )
933 /* have a dnattr match. if this is a self clause then
934 * the target must also match the op dn.
936 if ( b->a_dn_self ) {
937 /* check if the target is an attribute. */
938 if ( val == NULL ) continue;
940 /* target is attribute, check if the attribute value
943 rc = value_match( &match, b->a_dn_at,
944 b->a_dn_at->ad_type->sat_equality, 0,
946 /* on match error or no match, fail the ACL clause */
947 if (rc != LDAP_SUCCESS || match != 0 )
951 /* no dnattr match, check if this is a self clause */
952 if ( ! b->a_dn_self )
955 ACL_RECORD_VALUE_STATE;
957 /* this is a self clause, check if the target is an
963 /* target is attribute, check if the attribute value
966 rc = value_match( &match, b->a_dn_at,
967 b->a_dn_at->ad_type->sat_equality, 0,
970 /* on match error or no match, fail the ACL clause */
971 if (rc != LDAP_SUCCESS || match != 0 )
976 if ( b->a_group_pat.bv_len ) {
978 struct berval ndn = { 0, NULL };
981 if ( op->o_ndn.bv_len == 0 ) {
985 /* b->a_group is an unexpanded entry name, expanded it should be an
986 * entry with objectclass group* and we test to see if odn is one of
987 * the values in the attribute group
989 /* see if asker is listed in dnattr */
990 if ( b->a_group_style == ACL_STYLE_REGEX ) {
991 char buf[ACL_BUF_SIZE];
992 bv.bv_len = sizeof(buf) - 1;
995 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
996 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
997 /* did not expand to a valid dn */
1004 bv = b->a_group_pat;
1007 rc = backend_group( op, e, &bv, &op->o_ndn,
1008 b->a_group_oc, b->a_group_at );
1010 if ( ndn.bv_val ) free( ndn.bv_val );
1017 if ( b->a_set_pat.bv_len != 0 ) {
1019 char buf[ACL_BUF_SIZE];
1020 if( b->a_set_style == ACL_STYLE_REGEX ){
1021 bv.bv_len = sizeof(buf) - 1;
1023 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1027 if (aci_match_set( &bv, op, e, 0 ) == 0) {
1032 if ( b->a_authz.sai_ssf ) {
1034 LDAP_LOG( ACL, DETAIL1,
1035 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1036 op->o_connid, b->a_authz.sai_ssf, op->o_ssf );
1038 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1039 b->a_authz.sai_ssf, op->o_ssf, 0 );
1041 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1046 if ( b->a_authz.sai_transport_ssf ) {
1048 LDAP_LOG( ACL, DETAIL1,
1049 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1051 op->o_connid, b->a_authz.sai_transport_ssf,
1052 op->o_transport_ssf );
1054 Debug( LDAP_DEBUG_ACL,
1055 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1056 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1058 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1063 if ( b->a_authz.sai_tls_ssf ) {
1065 LDAP_LOG( ACL, DETAIL1,
1066 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1068 op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1070 Debug( LDAP_DEBUG_ACL,
1071 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1072 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1074 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1079 if ( b->a_authz.sai_sasl_ssf ) {
1081 LDAP_LOG( ACL, DETAIL1,
1082 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1084 op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1086 Debug( LDAP_DEBUG_ACL,
1087 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1088 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1090 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1095 #ifdef SLAPD_ACI_ENABLED
1096 if ( b->a_aci_at != NULL ) {
1098 slap_access_t grant, deny, tgrant, tdeny;
1099 struct berval parent_ndn, old_parent_ndn;
1100 BerVarray bvals = NULL;
1103 /* this case works different from the others above.
1104 * since aci's themselves give permissions, we need
1105 * to first check b->a_access_mask, the ACL's access level.
1108 if ( e->e_nname.bv_len == 0 ) {
1109 /* no ACIs in the root DSE */
1113 /* first check if the right being requested
1114 * is allowed by the ACL clause.
1116 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1119 /* start out with nothing granted, nothing denied */
1123 /* get the aci attribute */
1124 at = attr_find( e->e_attrs, b->a_aci_at );
1126 ACL_RECORD_VALUE_STATE;
1127 /* the aci is an multi-valued attribute. The
1128 * rights are determined by OR'ing the individual
1129 * rights given by the acis.
1131 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1135 matches, &grant, &deny, &aci_bv_entry ) != 0)
1141 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1142 accessmask2str(tgrant,accessmaskbuf),
1143 accessmask2str(tdeny, accessmaskbuf1), 0);
1146 /* If the entry level aci didn't contain anything valid for the
1147 * current operation, climb up the tree and evaluate the
1148 * acis with scope set to subtree
1150 if( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ){
1151 dnParent(&(e->e_nname), &parent_ndn);
1152 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ){
1153 old_parent_ndn = parent_ndn;
1154 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1155 ret=backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals);
1159 for( i = 0; bvals[i].bv_val != NULL; i++){
1160 ACL_RECORD_VALUE_STATE;
1161 if (aci_mask(op, e, desc, val, &bvals[i], matches,
1162 &grant, &deny, &aci_bv_children) != 0) {
1165 /* evaluation stops as soon as either a "deny" or a
1166 * "grant" directive matches.
1168 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1172 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1173 accessmask2str(tgrant,accessmaskbuf),
1174 accessmask2str(tdeny, accessmaskbuf1), 0);
1179 case LDAP_NO_SUCH_ATTRIBUTE:
1180 /* just go on if the aci-Attribute is not present in
1183 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1186 case LDAP_NO_SUCH_OBJECT:
1187 /* We have reached the base object */
1188 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1198 dnParent(&old_parent_ndn, &parent_ndn);
1203 /* remove anything that the ACL clause does not allow */
1204 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1205 tdeny &= ACL_PRIV_MASK;
1207 /* see if we have anything to contribute */
1208 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1212 /* this could be improved by changing acl_mask so that it can deal with
1213 * by clauses that return grant/deny pairs. Right now, it does either
1214 * additive or subtractive rights, but not both at the same time. So,
1215 * we need to combine the grant/deny pair into a single rights mask in
1216 * a smart way: if either grant or deny is "empty", then we use the
1217 * opposite as is, otherwise we remove any denied rights from the grant
1218 * rights mask and construct an additive mask.
1220 if (ACL_IS_INVALID(tdeny)) {
1221 modmask = tgrant | ACL_PRIV_ADDITIVE;
1223 } else if (ACL_IS_INVALID(tgrant)) {
1224 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1227 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1233 modmask = b->a_access_mask;
1237 LDAP_LOG( ACL, RESULTS,
1238 "acl_mask: [%d] applying %s (%s)\n",
1239 i, accessmask2str( modmask, accessmaskbuf),
1240 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1241 ? "break" : "stop" );
1243 Debug( LDAP_DEBUG_ACL,
1244 "<= acl_mask: [%d] applying %s (%s)\n",
1245 i, accessmask2str( modmask, accessmaskbuf ),
1246 b->a_type == ACL_CONTINUE
1248 : b->a_type == ACL_BREAK
1255 if( ACL_IS_ADDITIVE(modmask) ) {
1257 ACL_PRIV_SET( *mask, modmask );
1260 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1262 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1263 /* substract privs */
1264 ACL_PRIV_CLR( *mask, modmask );
1267 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1275 LDAP_LOG( ACL, DETAIL1,
1276 "acl_mask: conn %lu [%d] mask: %s\n",
1277 op->o_connid, i, accessmask2str( *mask, accessmaskbuf) );
1279 Debug( LDAP_DEBUG_ACL,
1280 "<= acl_mask: [%d] mask: %s\n",
1281 i, accessmask2str(*mask, accessmaskbuf), 0 );
1284 if( b->a_type == ACL_CONTINUE ) {
1287 } else if ( b->a_type == ACL_BREAK ) {
1295 /* implicit "by * none" clause */
1299 LDAP_LOG( ACL, RESULTS,
1300 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1301 op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1303 Debug( LDAP_DEBUG_ACL,
1304 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1305 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1311 * acl_check_modlist - check access control on the given entry to see if
1312 * it allows the given modifications by the user associated with op.
1313 * returns 1 if mods allowed ok
1314 * 0 mods not allowed
1321 Modifications *mlist
1325 AccessControlState state = ACL_STATE_INIT;
1327 assert( op->o_bd != NULL );
1329 /* short circuit root database access */
1330 if ( be_isroot( op->o_bd, &op->o_ndn ) ) {
1332 LDAP_LOG( ACL, DETAIL1,
1333 "acl_check_modlist: conn %lu access granted to root user\n",
1334 op->o_connid, 0, 0 );
1336 Debug( LDAP_DEBUG_ACL,
1337 "<= acl_access_allowed: granted to database root\n",
1343 /* use backend default access if no backend acls */
1344 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1346 LDAP_LOG( ACL, DETAIL1,
1347 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1348 access2str( ACL_WRITE ),
1349 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1352 Debug( LDAP_DEBUG_ACL,
1353 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1354 access2str( ACL_WRITE ),
1355 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1357 return op->o_bd->be_dfltaccess >= ACL_WRITE;
1360 /* op->o_bd is always non-NULL */
1361 /* use global default access if no global acls */
1362 } else if ( op->o_bd == NULL && global_acl == NULL ) {
1364 LDAP_LOG( ACL, DETAIL1,
1365 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1366 access2str( ACL_WRITE ),
1367 global_default_access >= ACL_WRITE ? "granted" : "denied",
1370 Debug( LDAP_DEBUG_ACL,
1371 "=> access_allowed: global default %s access %s to \"%s\"\n",
1372 access2str( ACL_WRITE ),
1373 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1375 return global_default_access >= ACL_WRITE;
1379 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1381 * no-user-modification operational attributes are ignored
1382 * by ACL_WRITE checking as any found here are not provided
1385 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1387 LDAP_LOG( ACL, DETAIL1,
1388 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1389 op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1391 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1392 " modify access granted\n",
1393 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1398 switch ( mlist->sml_op ) {
1399 case LDAP_MOD_REPLACE:
1401 * We must check both permission to delete the whole
1402 * attribute and permission to add the specific attributes.
1403 * This prevents abuse from selfwriters.
1405 if ( ! access_allowed( op, e,
1406 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1411 if ( mlist->sml_bvalues == NULL ) break;
1413 /* fall thru to check value to add */
1416 assert( mlist->sml_bvalues != NULL );
1418 for ( bv = mlist->sml_nvalues
1419 ? mlist->sml_nvalues : mlist->sml_values;
1420 bv->bv_val != NULL; bv++ )
1422 if ( ! access_allowed( op, e,
1423 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1430 case LDAP_MOD_DELETE:
1431 if ( mlist->sml_bvalues == NULL ) {
1432 if ( ! access_allowed( op, e,
1433 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1439 for ( bv = mlist->sml_nvalues
1440 ? mlist->sml_nvalues : mlist->sml_values;
1441 bv->bv_val != NULL; bv++ )
1443 if ( ! access_allowed( op, e,
1444 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1451 case SLAP_MOD_SOFTADD:
1452 /* allow adding attribute via modrdn thru */
1466 struct berval *list,
1480 while (len >= 0 && --ix >= 0) {
1481 while (--len >= 0 && *p++ != sep) ;
1483 while (len >= 0 && *p == ' ') {
1494 while (--len >= 0 && *p != sep) {
1498 while (bv->bv_len > 0 && *--p == ' ')
1504 aci_set_gather (SetCookie *cookie, struct berval *name, struct berval *attr)
1506 AciSetCookie *cp = (AciSetCookie *)cookie;
1507 BerVarray bvals = NULL;
1510 /* this routine needs to return the bervals instead of
1511 * plain strings, since syntax is not known. It should
1512 * also return the syntax or some "comparison cookie".
1515 if (dnNormalize(0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx) == LDAP_SUCCESS) {
1517 AttributeDescription *desc = NULL;
1518 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1519 backend_attribute(cp->op,
1520 cp->e, &ndn, desc, &bvals);
1522 sl_free(ndn.bv_val, cp->op->o_tmpmemctx);
1529 struct berval *subj,
1535 struct berval set = { 0, NULL };
1537 AciSetCookie cookie;
1540 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
1542 struct berval subjdn, ndn = { 0, NULL };
1543 struct berval setat;
1546 AttributeDescription *desc = NULL;
1548 /* format of string is "entry/setAttrName" */
1549 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1553 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1554 setat.bv_val = SLAPD_ACI_SET_ATTR;
1555 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1558 if ( setat.bv_val != NULL ) {
1560 * NOTE: dnNormalize honors the ber_len field
1561 * as the length of the dn to be normalized
1563 if ( dnNormalize(0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS
1564 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1566 backend_attribute(op, e,
1567 &ndn, desc, &bvals);
1568 if ( bvals != NULL ) {
1569 if ( bvals[0].bv_val != NULL ) {
1572 bvals[0].bv_val = NULL;
1573 for (i=1;bvals[i].bv_val;i++);
1574 bvals[0].bv_val = bvals[i-1].bv_val;
1575 bvals[i-1].bv_val = NULL;
1577 ber_bvarray_free_x(bvals, op->o_tmpmemctx);
1585 if (set.bv_val != NULL) {
1588 rc = (slap_set_filter(aci_set_gather, (SetCookie *)&cookie, &set,
1589 &op->o_ndn, &e->e_nname, NULL) > 0);
1590 sl_free(set.bv_val, op->o_tmpmemctx);
1595 #ifdef SLAPD_ACI_ENABLED
1597 aci_list_map_rights(
1598 struct berval *list )
1605 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1608 switch (*bv.bv_val) {
1610 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1613 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1614 * the right 's' to mean "set", but in the examples states
1615 * that the right 's' means "search". The latter definition
1618 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1621 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1624 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1627 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1628 * define any equivalent to the AUTH right, so I've just used
1631 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1643 struct berval *list,
1644 const struct berval *attr,
1645 struct berval *val )
1647 struct berval bv, left, right;
1650 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1651 if (aci_get_part(&bv, 0, '=', &left) < 0
1652 || aci_get_part(&bv, 1, '=', &right) < 0)
1654 if (ber_bvstrcasecmp(attr, &bv) == 0)
1656 } else if (val == NULL) {
1657 if (ber_bvstrcasecmp(attr, &left) == 0)
1660 if (ber_bvstrcasecmp(attr, &left) == 0) {
1661 /* this is experimental code that implements a
1662 * simple (prefix) match of the attribute value.
1663 * the ACI draft does not provide for aci's that
1664 * apply to specific values, but it would be
1665 * nice to have. If the <attr> part of an aci's
1666 * rights list is of the form <attr>=<value>,
1667 * that means the aci applies only to attrs with
1668 * the given value. Furthermore, if the attr is
1669 * of the form <attr>=<value>*, then <value> is
1670 * treated as a prefix, and the aci applies to
1671 * any value with that prefix.
1673 * Ideally, this would allow r.e. matches.
1675 if (aci_get_part(&right, 0, '*', &left) < 0
1676 || right.bv_len <= left.bv_len)
1678 if (ber_bvstrcasecmp(val, &right) == 0)
1680 } else if (val->bv_len >= left.bv_len) {
1681 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1690 static slap_access_t
1691 aci_list_get_attr_rights(
1692 struct berval *list,
1693 const struct berval *attr,
1694 struct berval *val )
1700 /* loop through each rights/attr pair, skip first part (action) */
1702 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1703 if (aci_list_has_attr(&bv, attr, val) == 0)
1705 if (aci_get_part(list, i, ';', &bv) < 0)
1707 mask |= aci_list_map_rights(&bv);
1713 aci_list_get_rights(
1714 struct berval *list,
1715 const struct berval *attr,
1717 slap_access_t *grant,
1718 slap_access_t *deny )
1720 struct berval perm, actn;
1721 slap_access_t *mask;
1724 if (attr == NULL || attr->bv_len == 0
1725 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1726 attr = &aci_bv_br_entry;
1732 /* loop through each permissions clause */
1733 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1734 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1736 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1738 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1745 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1746 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1753 struct berval *subj,
1754 struct berval *defgrpoc,
1755 struct berval *defgrpat,
1761 struct berval subjdn;
1762 struct berval grpoc;
1763 struct berval grpat;
1764 ObjectClass *grp_oc = NULL;
1765 AttributeDescription *grp_ad = NULL;
1769 /* format of string is "group/objectClassValue/groupAttrName" */
1770 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1774 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1778 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1782 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1783 if( rc != LDAP_SUCCESS ) {
1789 grp_oc = oc_bvfind( &grpoc );
1791 if (grp_oc != NULL && grp_ad != NULL ) {
1792 char buf[ACL_BUF_SIZE];
1793 struct berval bv, ndn;
1794 bv.bv_len = sizeof( buf ) - 1;
1795 bv.bv_val = (char *)&buf;
1796 string_expand(&bv, &subjdn, e->e_ndn, matches);
1797 if ( dnNormalize(0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1798 rc = (backend_group(op, e, &ndn, &op->o_ndn,
1799 grp_oc, grp_ad) == 0);
1812 AttributeDescription *desc,
1815 regmatch_t *matches,
1816 slap_access_t *grant,
1817 slap_access_t *deny,
1818 struct berval *scope
1821 struct berval bv, perms, sdn;
1825 assert( desc->ad_cname.bv_val != NULL );
1827 /* parse an aci of the form:
1828 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1830 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1831 a full description of the format for this attribute.
1832 Differences: "this" in the draft is "self" here, and
1833 "self" and "public" is in the position of dnType.
1835 For now, this routine only supports scope=entry.
1837 /* check that the aci has all 5 components */
1838 if (aci_get_part(aci, 4, '#', NULL) < 0)
1841 /* check that the aci family is supported */
1842 if (aci_get_part(aci, 0, '#', &bv) < 0)
1845 /* check that the scope matches */
1846 if (aci_get_part(aci, 1, '#', &bv) < 0
1847 || ber_bvstrcasecmp( scope, &bv ) != 0)
1852 /* get the list of permissions clauses, bail if empty */
1853 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1856 /* check if any permissions allow desired access */
1857 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1860 /* see if we have a DN match */
1861 if (aci_get_part(aci, 3, '#', &bv) < 0)
1864 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1867 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1870 if ( dnNormalize(0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1871 if (dn_match( &op->o_ndn, &ndn))
1877 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1880 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1881 if (dn_match(&op->o_ndn, &e->e_nname))
1884 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1886 AttributeDescription *ad = NULL;
1889 rc = slap_bv2ad( &sdn, &ad, &text );
1891 if( rc != LDAP_SUCCESS ) {
1899 for(at = attrs_find( e->e_attrs, ad );
1901 at = attrs_find( at->a_next, ad ) )
1903 if (value_find_ex( ad,
1904 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1905 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1907 &bv, op->o_tmpmemctx) == 0 )
1917 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1918 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, op, e, matches))
1921 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1922 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, op, e, matches))
1925 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1926 if (aci_match_set(&sdn, op, e, 0))
1929 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1930 if (aci_match_set(&sdn, op, e, 1))
1938 #endif /* SLAPD_ACI_ENABLED */
1945 regmatch_t *matches)
1953 bv->bv_val[0] = '\0';
1954 bv->bv_len--; /* leave space for lone $ */
1957 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
1958 sp < pat->bv_val + pat->bv_len ; sp++ )
1960 /* did we previously see a $ */
1962 if ( flag == 1 && *sp == '$' ) {
1967 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
1970 } else if ( *sp >= '0' && *sp <= '9' ) {
1978 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
1979 if ( *sp >= '0' && *sp <= '9' ) {
1980 n = 10*n + ( *sp - '0' );
1984 if ( *sp != /*'{'*/ '}' ) {
1989 if ( n >= MAXREMATCHES ) {
1994 i = matches[n].rm_so;
1995 l = matches[n].rm_eo;
1996 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2014 /* must have ended with a single $ */
2023 LDAP_LOG( ACL, DETAIL1,
2024 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2025 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
2027 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2028 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2034 struct berval *pat, /* pattern to expand and match against */
2035 char *str, /* string to match against pattern */
2036 char *buf, /* buffer with $N expansion variables */
2037 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2041 char newbuf[ACL_BUF_SIZE];
2045 bv.bv_len = sizeof(newbuf) - 1;
2048 if(str == NULL) str = "";
2050 string_expand(&bv, pat, buf, matches);
2051 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
2052 char error[ACL_BUF_SIZE];
2053 regerror(rc, &re, error, sizeof(error));
2057 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
2058 pat->bv_val, str, error );
2060 Debug( LDAP_DEBUG_TRACE,
2061 "compile( \"%s\", \"%s\") failed %s\n",
2062 pat->bv_val, str, error );
2067 rc = regexec(&re, str, 0, NULL, 0);
2071 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
2072 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
2073 rc, rc ? "matches" : "no matches", 0 );
2075 Debug( LDAP_DEBUG_TRACE,
2076 "=> regex_matches: string: %s\n", str, 0, 0 );
2077 Debug( LDAP_DEBUG_TRACE,
2078 "=> regex_matches: rc: %d %s\n",
2079 rc, !rc ? "matches" : "no matches", 0 );