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,
54 int nmatches, regmatch_t *matches );
56 static slap_control_t acl_mask(
57 AccessControl *ac, slap_mask_t *mask,
58 Operation *op, Entry *e,
59 AttributeDescription *desc,
63 AccessControlState *state );
65 #ifdef SLAPD_ACI_ENABLED
67 Operation *op, Entry *e,
68 AttributeDescription *desc,
74 struct berval *scope);
77 static int regex_matches(
78 struct berval *pat, char *str, char *buf, regmatch_t *matches);
79 static void string_expand(
80 struct berval *newbuf, struct berval *pattern,
81 char *match, regmatch_t *matches);
83 typedef struct AciSetCookie {
88 SLAP_SET_GATHER aci_set_gather;
89 static int aci_match_set ( struct berval *subj, Operation *op,
90 Entry *e, int setref );
93 * access_allowed - check whether op->o_ndn is allowed the requested access
94 * to entry e, attribute attr, value val. if val is null, access to
95 * the whole attribute is assumed (all values).
97 * This routine loops through all access controls and calls
98 * acl_mask() on each applicable access control.
99 * The loop exits when a definitive answer is reached or
100 * or no more controls remain.
111 AttributeDescription *desc,
113 slap_access_t access,
114 AccessControlState *state )
118 AccessControl *a = NULL;
123 char accessmaskbuf[ACCESSMASK_MAXLEN];
126 slap_control_t control;
128 regmatch_t matches[MAXREMATCHES];
129 int st_same_attr = 0;
130 int st_initialized = 0;
131 static AccessControlState state_init = ACL_STATE_INIT;
134 assert( desc != NULL );
135 assert( access > ACL_NONE );
137 attr = desc->ad_cname.bv_val;
139 assert( attr != NULL );
141 if( op && op->o_is_auth_check &&
142 ( access == ACL_SEARCH || access == ACL_READ ))
147 if( state && state->as_recorded && state->as_vd_ad==desc) {
148 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
151 return state->as_result;
153 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
154 val != NULL && state->as_vd_acl == NULL )
156 return state->as_result;
162 state->as_vd_ad=desc;
166 LDAP_LOG( ACL, ENTRY,
167 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
168 access2str( access ), e->e_dn, attr );
170 Debug( LDAP_DEBUG_ACL,
171 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
172 access2str( access ), e->e_dn, attr );
182 !slapi_x_access_allowed( op, e, desc, val, access, state )) {
183 /* ACL plugin denied access */
186 #endif /* LDAP_SLAPI */
194 assert( be != NULL );
196 /* grant database root access */
197 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
200 "access_allowed: conn %lu root access granted\n",
201 op->o_connid, 0, 0 );
203 Debug( LDAP_DEBUG_ACL,
204 "<= root access granted\n",
211 * no-user-modification operational attributes are ignored
212 * by ACL_WRITE checking as any found here are not provided
215 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
216 && desc != slap_schema.si_ad_entry
217 && desc != slap_schema.si_ad_children )
220 LDAP_LOG( ACL, DETAIL1,
221 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
222 "access granted\n", op->o_connid, attr , 0 );
224 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
225 " %s access granted\n",
231 /* use backend default access if no backend acls */
232 if( be != NULL && be->be_acl == NULL ) {
234 LDAP_LOG( ACL, DETAIL1,
235 "access_allowed: backend default %s access %s to \"%s\"\n",
236 access2str( access ),
237 be->be_dfltaccess >= access ? "granted" : "denied",
238 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
240 Debug( LDAP_DEBUG_ACL,
241 "=> access_allowed: backend default %s access %s to \"%s\"\n",
242 access2str( access ),
243 be->be_dfltaccess >= access ? "granted" : "denied",
244 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
246 ret = be->be_dfltaccess >= access;
250 /* be is always non-NULL */
251 /* use global default access if no global acls */
252 } else if ( be == NULL && global_acl == NULL ) {
254 LDAP_LOG( ACL, DETAIL1,
255 "access_allowed: global default %s access %s to \"%s\"\n",
256 access2str( access ),
257 global_default_access >= access ? "granted" : "denied",
260 Debug( LDAP_DEBUG_ACL,
261 "=> access_allowed: global default %s access %s to \"%s\"\n",
262 access2str( access ),
263 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
265 ret = global_default_access >= access;
274 assert( state->as_vd_acl != NULL );
276 a = state->as_vd_acl;
277 mask = state->as_vd_acl_mask;
278 count = state->as_vd_acl_count;
279 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
283 if ( state ) state->as_vi_acl = NULL;
287 memset(matches, '\0', sizeof(matches));
290 while((a = acl_get( a, &count, op, e, desc, val,
291 MAXREMATCHES, matches )) != NULL)
295 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
297 LDAP_LOG( ACL, DETAIL1,
298 "access_allowed: match[%d]: %d %d ",
299 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
301 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
302 (int)matches[i].rm_so, (int)matches[i].rm_eo );
304 if( matches[i].rm_so <= matches[0].rm_eo ) {
306 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
307 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
311 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
313 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
318 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
319 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
320 ret = state->as_result;
322 } else if (!st_initialized) {
323 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
325 state->as_vd_ad=desc;
331 control = acl_mask( a, &mask, op,
332 e, desc, val, matches, count, state );
334 if ( control != ACL_BREAK ) {
338 memset(matches, '\0', sizeof(matches));
341 if ( ACL_IS_INVALID( mask ) ) {
343 LDAP_LOG( ACL, DETAIL1,
344 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
345 op->o_connid, e->e_dn, attr );
347 Debug( LDAP_DEBUG_ACL,
348 "=> access_allowed: \"%s\" (%s) invalid!\n",
353 } else if ( control == ACL_BREAK ) {
355 LDAP_LOG( ACL, DETAIL1,
356 "access_allowed: conn %lu no more rules\n", op->o_connid, 0,0 );
358 Debug( LDAP_DEBUG_ACL,
359 "=> access_allowed: no more rules\n", 0, 0, 0);
366 LDAP_LOG( ACL, ENTRY,
367 "access_allowed: %s access %s by %s\n",
368 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
369 accessmask2str( mask, accessmaskbuf ) );
371 Debug( LDAP_DEBUG_ACL,
372 "=> access_allowed: %s access %s by %s\n",
373 access2str( access ),
374 ACL_GRANT(mask, access) ? "granted" : "denied",
375 accessmask2str( mask, accessmaskbuf ) );
378 ret = ACL_GRANT(mask, access);
381 if( state != NULL ) {
382 /* If not value-dependent, save ACL in case of more attrs */
383 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) ) {
384 state->as_vi_acl = a;
385 state->as_result = ret;
387 state->as_recorded |= ACL_STATE_RECORDED;
389 if (be_null) op->o_bd = NULL;
394 * acl_get - return the acl applicable to entry e, attribute
395 * attr. the acl returned is suitable for use in subsequent calls to
396 * acl_access_allowed().
399 static AccessControl *
405 AttributeDescription *desc,
408 regmatch_t *matches )
414 assert( count != NULL );
415 assert( desc != NULL );
417 attr = desc->ad_cname.bv_val;
419 assert( attr != NULL );
422 if( op->o_bd == NULL ) {
425 a = op->o_bd->be_acl;
434 dnlen = e->e_nname.bv_len;
436 for ( ; a != NULL; a = a->acl_next ) {
439 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
440 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
442 LDAP_LOG( ACL, DETAIL1,
443 "acl_get: dnpat [%d] %s nsub: %d\n",
444 *count, a->acl_dn_pat.bv_val,
445 (int) a->acl_dn_re.re_nsub );
447 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
448 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
450 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
455 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
456 *count, a->acl_dn_pat.bv_val, 0 );
458 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
459 *count, a->acl_dn_pat.bv_val, 0 );
461 patlen = a->acl_dn_pat.bv_len;
462 if ( dnlen < patlen )
465 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
466 /* base dn -- entire object DN must match */
467 if ( dnlen != patlen )
470 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
473 if ( dnlen <= patlen )
476 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
479 rdnlen = dn_rdnlen( NULL, &e->e_nname );
480 if ( rdnlen != dnlen - patlen - 1 )
483 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
484 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
487 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
488 if ( dnlen <= patlen )
490 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
494 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
499 LDAP_LOG( ACL, DETAIL1,
500 "acl_get: [%d] matched\n", *count, 0, 0 );
502 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
507 if ( a->acl_filter != NULL ) {
508 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
509 if ( rc != LDAP_COMPARE_TRUE ) {
515 LDAP_LOG( ACL, DETAIL1,
516 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
518 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
521 if ( a->acl_attrs == NULL ||
522 ad_inlist( desc, a->acl_attrs ) )
525 LDAP_LOG( ACL, DETAIL1,
526 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
528 Debug( LDAP_DEBUG_ACL,
529 "<= acl_get: [%d] acl %s attr: %s\n",
530 *count, e->e_dn, attr );
534 matches[0].rm_so = matches[0].rm_eo = -1;
538 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
540 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
546 * Record value-dependent access control state
548 #define ACL_RECORD_VALUE_STATE do { \
549 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
550 state->as_recorded |= ACL_STATE_RECORDED_VD; \
551 state->as_vd_acl = a; \
552 AC_MEMCPY( state->as_vd_acl_matches, matches, \
553 sizeof( state->as_vd_acl_matches )) ; \
554 state->as_vd_acl_count = count; \
555 state->as_vd_access = b; \
556 state->as_vd_access_count = i; \
561 * acl_mask - modifies mask based upon the given acl and the
562 * requested access to entry e, attribute attr, value val. if val
563 * is null, access to the whole attribute is assumed (all values).
565 * returns 0 access NOT allowed
569 static slap_control_t
575 AttributeDescription *desc,
579 AccessControlState *state )
581 int i, odnlen, patlen;
584 char accessmaskbuf[ACCESSMASK_MAXLEN];
585 char accessmaskbuf1[ACCESSMASK_MAXLEN];
590 assert( mask != NULL );
591 assert( desc != NULL );
593 attr = desc->ad_cname.bv_val;
595 assert( attr != NULL );
598 LDAP_LOG( ACL, ENTRY,
599 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
600 op->o_connid, e->e_dn, attr );
603 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
604 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
605 accessmask2str( *mask, accessmaskbuf ) );
607 Debug( LDAP_DEBUG_ACL,
608 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
611 Debug( LDAP_DEBUG_ACL,
612 "=> acl_mask: to %s by \"%s\", (%s) \n",
613 val ? "value" : "all values",
614 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
615 accessmask2str( *mask, accessmaskbuf ) );
618 /* Is this ACL only for a specific value? */
619 if ( a->acl_attrval.bv_len ) {
620 if ( state && !state->as_vd_acl ) {
621 state->as_vd_acl = a;
622 state->as_vd_access = a->acl_access;
623 state->as_vd_access_count = 1;
628 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
630 LDAP_LOG( ACL, DETAIL1,
631 "acl_get: valpat %s\n",
632 a->acl_attrval.bv_val, 0, 0 );
634 Debug( LDAP_DEBUG_ACL,
635 "acl_get: valpat %s\n",
636 a->acl_attrval.bv_val, 0, 0 );
638 if (regexec(&a->acl_attrval_re, val->bv_val, 0, NULL, 0))
644 LDAP_LOG( ACL, DETAIL1,
646 a->acl_attrval.bv_val, 0, 0 );
648 Debug( LDAP_DEBUG_ACL,
650 a->acl_attrval.bv_val, 0, 0 );
652 if (value_match( &match, desc,
653 desc->ad_type->sat_equality, 0,
654 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
660 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
661 && state->as_vd_acl == a )
663 b = state->as_vd_access;
664 i = state->as_vd_access_count;
671 for ( ; b != NULL; b = b->a_next, i++ ) {
672 slap_mask_t oldmask, modmask;
674 ACL_INVALIDATE( modmask );
676 /* AND <who> clauses */
677 if ( b->a_dn_pat.bv_len != 0 ) {
679 LDAP_LOG( ACL, DETAIL1,
680 "acl_mask: conn %lu check a_dn_pat: %s\n",
681 op->o_connid, b->a_dn_pat.bv_val ,0 );
683 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
684 b->a_dn_pat.bv_val, 0, 0);
687 * if access applies to the entry itself, and the
688 * user is bound as somebody in the same namespace as
689 * the entry, OR the given dn matches the dn pattern
691 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
692 if ( op->o_ndn.bv_len != 0 ) {
696 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
697 if ( op->o_ndn.bv_len == 0 ) {
701 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
702 if ( op->o_ndn.bv_len == 0 ) {
706 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
710 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
711 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
712 int ret = regex_matches( &b->a_dn_pat,
713 op->o_ndn.bv_val, e->e_ndn, matches );
724 if ( e->e_dn == NULL )
727 if ( b->a_dn_expand ) {
729 char buf[ACL_BUF_SIZE];
731 bv.bv_len = sizeof( buf ) - 1;
734 string_expand(&bv, &b->a_dn_pat,
736 if ( dnNormalize(0, NULL, NULL, &bv, &pat, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
737 /* did not expand to a valid dn */
745 odnlen = op->o_ndn.bv_len;
746 if ( odnlen < patlen ) {
747 goto dn_match_cleanup;
751 if ( b->a_dn_style == ACL_STYLE_BASE ) {
752 /* base dn -- entire object DN must match */
753 if ( odnlen != patlen ) {
754 goto dn_match_cleanup;
757 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
760 if ( odnlen <= patlen ) {
761 goto dn_match_cleanup;
764 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
765 goto dn_match_cleanup;
768 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
769 if ( rdnlen != odnlen - patlen - 1 ) {
770 goto dn_match_cleanup;
773 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
774 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
775 goto dn_match_cleanup;
778 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
779 if ( odnlen <= patlen ) {
780 goto dn_match_cleanup;
783 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
784 goto dn_match_cleanup;
788 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
791 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
801 if ( b->a_sockurl_pat.bv_len ) {
802 if ( ! op->o_conn->c_listener ) {
806 LDAP_LOG( ACL, DETAIL1,
807 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
808 op->o_connid, b->a_sockurl_pat.bv_val , 0 );
810 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
811 b->a_sockurl_pat.bv_val, 0, 0 );
814 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
815 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
816 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
817 e->e_ndn, matches ) )
822 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
828 if ( b->a_domain_pat.bv_len ) {
829 if ( !op->o_conn->c_peer_domain.bv_val ) {
833 LDAP_LOG( ACL, DETAIL1,
834 "acl_mask: conn %lu check a_domain_pat: %s\n",
835 op->o_connid, b->a_domain_pat.bv_val , 0 );
837 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
838 b->a_domain_pat.bv_val, 0, 0 );
840 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
841 if ( b->a_domain_style == ACL_STYLE_REGEX) {
842 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
843 e->e_ndn, matches ) )
848 char buf[ACL_BUF_SIZE];
850 struct berval cmp = op->o_conn->c_peer_domain;
851 struct berval pat = b->a_domain_pat;
853 if ( b->a_domain_expand ) {
856 bv.bv_len = sizeof(buf) - 1;
859 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
863 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
864 int offset = cmp.bv_len - pat.bv_len;
869 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
873 /* trim the domain */
874 cmp.bv_val = &cmp.bv_val[ offset ];
875 cmp.bv_len -= offset;
878 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
885 if ( b->a_peername_pat.bv_len ) {
886 if ( !op->o_conn->c_peer_name.bv_val ) {
890 LDAP_LOG( ACL, DETAIL1,
891 "acl_mask: conn %lu check a_peername_path: %s\n",
892 op->o_connid, b->a_peername_pat.bv_val , 0 );
894 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
895 b->a_peername_pat.bv_val, 0, 0 );
897 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
898 if ( b->a_peername_style == ACL_STYLE_REGEX) {
899 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
900 e->e_ndn, matches ) )
905 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 )
911 if ( b->a_sockname_pat.bv_len ) {
912 if ( !op->o_conn->c_sock_name.bv_val ) {
916 LDAP_LOG( ACL, DETAIL1,
917 "acl_mask: conn %lu check a_sockname_path: %s\n",
918 op->o_connid, b->a_sockname_pat.bv_val , 0 );
920 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
921 b->a_sockname_pat.bv_val, 0, 0 );
923 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
924 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
925 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
926 e->e_ndn, matches ) )
931 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 )
937 if ( b->a_dn_at != NULL ) {
942 const char *attr = b->a_dn_at->ad_cname.bv_val;
944 assert( attr != NULL );
946 if ( op->o_ndn.bv_len == 0 ) {
951 LDAP_LOG( ACL, DETAIL1,
952 "acl_mask: conn %lu check a_dn_pat: %s\n",
953 op->o_connid, attr , 0 );
955 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
960 /* see if asker is listed in dnattr */
961 for( at = attrs_find( e->e_attrs, b->a_dn_at );
963 at = attrs_find( at->a_next, b->a_dn_at ) )
965 if( value_find_ex( b->a_dn_at,
966 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
967 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
969 &bv, op->o_tmpmemctx ) == 0 )
978 /* have a dnattr match. if this is a self clause then
979 * the target must also match the op dn.
981 if ( b->a_dn_self ) {
982 /* check if the target is an attribute. */
983 if ( val == NULL ) continue;
985 /* target is attribute, check if the attribute value
988 rc = value_match( &match, b->a_dn_at,
989 b->a_dn_at->ad_type->sat_equality, 0,
991 /* on match error or no match, fail the ACL clause */
992 if (rc != LDAP_SUCCESS || match != 0 )
996 /* no dnattr match, check if this is a self clause */
997 if ( ! b->a_dn_self )
1000 ACL_RECORD_VALUE_STATE;
1002 /* this is a self clause, check if the target is an
1008 /* target is attribute, check if the attribute value
1011 rc = value_match( &match, b->a_dn_at,
1012 b->a_dn_at->ad_type->sat_equality, 0,
1015 /* on match error or no match, fail the ACL clause */
1016 if (rc != LDAP_SUCCESS || match != 0 )
1021 if ( b->a_group_pat.bv_len ) {
1023 struct berval ndn = { 0, NULL };
1026 if ( op->o_ndn.bv_len == 0 ) {
1030 /* b->a_group is an unexpanded entry name, expanded it should be an
1031 * entry with objectclass group* and we test to see if odn is one of
1032 * the values in the attribute group
1034 /* see if asker is listed in dnattr */
1035 if ( b->a_group_style == ACL_STYLE_REGEX ) {
1036 char buf[ACL_BUF_SIZE];
1037 bv.bv_len = sizeof(buf) - 1;
1040 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
1041 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
1042 /* did not expand to a valid dn */
1049 bv = b->a_group_pat;
1052 rc = backend_group( op, e, &bv, &op->o_ndn,
1053 b->a_group_oc, b->a_group_at );
1055 if ( ndn.bv_val ) free( ndn.bv_val );
1062 if ( b->a_set_pat.bv_len != 0 ) {
1064 char buf[ACL_BUF_SIZE];
1065 if( b->a_set_style == ACL_STYLE_REGEX ){
1066 bv.bv_len = sizeof(buf) - 1;
1068 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1072 if (aci_match_set( &bv, op, e, 0 ) == 0) {
1077 if ( b->a_authz.sai_ssf ) {
1079 LDAP_LOG( ACL, DETAIL1,
1080 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1081 op->o_connid, b->a_authz.sai_ssf, op->o_ssf );
1083 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1084 b->a_authz.sai_ssf, op->o_ssf, 0 );
1086 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1091 if ( b->a_authz.sai_transport_ssf ) {
1093 LDAP_LOG( ACL, DETAIL1,
1094 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1096 op->o_connid, b->a_authz.sai_transport_ssf,
1097 op->o_transport_ssf );
1099 Debug( LDAP_DEBUG_ACL,
1100 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1101 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1103 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1108 if ( b->a_authz.sai_tls_ssf ) {
1110 LDAP_LOG( ACL, DETAIL1,
1111 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1113 op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1115 Debug( LDAP_DEBUG_ACL,
1116 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1117 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1119 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1124 if ( b->a_authz.sai_sasl_ssf ) {
1126 LDAP_LOG( ACL, DETAIL1,
1127 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1129 op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1131 Debug( LDAP_DEBUG_ACL,
1132 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1133 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1135 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1140 #ifdef SLAPD_ACI_ENABLED
1141 if ( b->a_aci_at != NULL ) {
1143 slap_access_t grant, deny, tgrant, tdeny;
1144 struct berval parent_ndn, old_parent_ndn;
1145 BerVarray bvals = NULL;
1148 /* this case works different from the others above.
1149 * since aci's themselves give permissions, we need
1150 * to first check b->a_access_mask, the ACL's access level.
1153 if ( e->e_nname.bv_len == 0 ) {
1154 /* no ACIs in the root DSE */
1158 /* first check if the right being requested
1159 * is allowed by the ACL clause.
1161 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1164 /* start out with nothing granted, nothing denied */
1168 /* get the aci attribute */
1169 at = attr_find( e->e_attrs, b->a_aci_at );
1171 ACL_RECORD_VALUE_STATE;
1172 /* the aci is an multi-valued attribute. The
1173 * rights are determined by OR'ing the individual
1174 * rights given by the acis.
1176 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1180 matches, &grant, &deny, &aci_bv_entry ) != 0)
1186 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1187 accessmask2str(tgrant,accessmaskbuf),
1188 accessmask2str(tdeny, accessmaskbuf1), 0);
1191 /* If the entry level aci didn't contain anything valid for the
1192 * current operation, climb up the tree and evaluate the
1193 * acis with scope set to subtree
1195 if( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ){
1196 dnParent(&(e->e_nname), &parent_ndn);
1197 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ){
1198 old_parent_ndn = parent_ndn;
1199 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1200 ret=backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals);
1204 for( i = 0; bvals[i].bv_val != NULL; i++){
1205 ACL_RECORD_VALUE_STATE;
1206 if (aci_mask(op, e, desc, val, &bvals[i], matches,
1207 &grant, &deny, &aci_bv_children) != 0) {
1210 /* evaluation stops as soon as either a "deny" or a
1211 * "grant" directive matches.
1213 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1217 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1218 accessmask2str(tgrant,accessmaskbuf),
1219 accessmask2str(tdeny, accessmaskbuf1), 0);
1224 case LDAP_NO_SUCH_ATTRIBUTE:
1225 /* just go on if the aci-Attribute is not present in
1228 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1231 case LDAP_NO_SUCH_OBJECT:
1232 /* We have reached the base object */
1233 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1243 dnParent(&old_parent_ndn, &parent_ndn);
1248 /* remove anything that the ACL clause does not allow */
1249 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1250 tdeny &= ACL_PRIV_MASK;
1252 /* see if we have anything to contribute */
1253 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1257 /* this could be improved by changing acl_mask so that it can deal with
1258 * by clauses that return grant/deny pairs. Right now, it does either
1259 * additive or subtractive rights, but not both at the same time. So,
1260 * we need to combine the grant/deny pair into a single rights mask in
1261 * a smart way: if either grant or deny is "empty", then we use the
1262 * opposite as is, otherwise we remove any denied rights from the grant
1263 * rights mask and construct an additive mask.
1265 if (ACL_IS_INVALID(tdeny)) {
1266 modmask = tgrant | ACL_PRIV_ADDITIVE;
1268 } else if (ACL_IS_INVALID(tgrant)) {
1269 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1272 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1278 modmask = b->a_access_mask;
1282 LDAP_LOG( ACL, RESULTS,
1283 "acl_mask: [%d] applying %s (%s)\n",
1284 i, accessmask2str( modmask, accessmaskbuf),
1285 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1286 ? "break" : "stop" );
1288 Debug( LDAP_DEBUG_ACL,
1289 "<= acl_mask: [%d] applying %s (%s)\n",
1290 i, accessmask2str( modmask, accessmaskbuf ),
1291 b->a_type == ACL_CONTINUE
1293 : b->a_type == ACL_BREAK
1300 if( ACL_IS_ADDITIVE(modmask) ) {
1302 ACL_PRIV_SET( *mask, modmask );
1305 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1307 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1308 /* substract privs */
1309 ACL_PRIV_CLR( *mask, modmask );
1312 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1320 LDAP_LOG( ACL, DETAIL1,
1321 "acl_mask: conn %lu [%d] mask: %s\n",
1322 op->o_connid, i, accessmask2str( *mask, accessmaskbuf) );
1324 Debug( LDAP_DEBUG_ACL,
1325 "<= acl_mask: [%d] mask: %s\n",
1326 i, accessmask2str(*mask, accessmaskbuf), 0 );
1329 if( b->a_type == ACL_CONTINUE ) {
1332 } else if ( b->a_type == ACL_BREAK ) {
1340 /* implicit "by * none" clause */
1344 LDAP_LOG( ACL, RESULTS,
1345 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1346 op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1348 Debug( LDAP_DEBUG_ACL,
1349 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1350 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1356 * acl_check_modlist - check access control on the given entry to see if
1357 * it allows the given modifications by the user associated with op.
1358 * returns 1 if mods allowed ok
1359 * 0 mods not allowed
1366 Modifications *mlist
1370 AccessControlState state = ACL_STATE_INIT;
1372 assert( op->o_bd != NULL );
1374 /* short circuit root database access */
1375 if ( be_isroot( op->o_bd, &op->o_ndn ) ) {
1377 LDAP_LOG( ACL, DETAIL1,
1378 "acl_check_modlist: conn %lu access granted to root user\n",
1379 op->o_connid, 0, 0 );
1381 Debug( LDAP_DEBUG_ACL,
1382 "<= acl_access_allowed: granted to database root\n",
1388 /* use backend default access if no backend acls */
1389 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1391 LDAP_LOG( ACL, DETAIL1,
1392 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1393 access2str( ACL_WRITE ),
1394 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1397 Debug( LDAP_DEBUG_ACL,
1398 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1399 access2str( ACL_WRITE ),
1400 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1402 return op->o_bd->be_dfltaccess >= ACL_WRITE;
1405 /* op->o_bd is always non-NULL */
1406 /* use global default access if no global acls */
1407 } else if ( op->o_bd == NULL && global_acl == NULL ) {
1409 LDAP_LOG( ACL, DETAIL1,
1410 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1411 access2str( ACL_WRITE ),
1412 global_default_access >= ACL_WRITE ? "granted" : "denied",
1415 Debug( LDAP_DEBUG_ACL,
1416 "=> access_allowed: global default %s access %s to \"%s\"\n",
1417 access2str( ACL_WRITE ),
1418 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1420 return global_default_access >= ACL_WRITE;
1424 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1426 * no-user-modification operational attributes are ignored
1427 * by ACL_WRITE checking as any found here are not provided
1430 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1432 LDAP_LOG( ACL, DETAIL1,
1433 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1434 op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1436 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1437 " modify access granted\n",
1438 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1443 switch ( mlist->sml_op ) {
1444 case LDAP_MOD_REPLACE:
1446 * We must check both permission to delete the whole
1447 * attribute and permission to add the specific attributes.
1448 * This prevents abuse from selfwriters.
1450 if ( ! access_allowed( op, e,
1451 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1456 if ( mlist->sml_bvalues == NULL ) break;
1458 /* fall thru to check value to add */
1461 assert( mlist->sml_bvalues != NULL );
1463 for ( bv = mlist->sml_nvalues
1464 ? mlist->sml_nvalues : mlist->sml_values;
1465 bv->bv_val != NULL; bv++ )
1467 if ( ! access_allowed( op, e,
1468 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1475 case LDAP_MOD_DELETE:
1476 if ( mlist->sml_bvalues == NULL ) {
1477 if ( ! access_allowed( op, e,
1478 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1484 for ( bv = mlist->sml_nvalues
1485 ? mlist->sml_nvalues : mlist->sml_values;
1486 bv->bv_val != NULL; bv++ )
1488 if ( ! access_allowed( op, e,
1489 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1496 case SLAP_MOD_SOFTADD:
1497 /* allow adding attribute via modrdn thru */
1511 struct berval *list,
1525 while (len >= 0 && --ix >= 0) {
1526 while (--len >= 0 && *p++ != sep) ;
1528 while (len >= 0 && *p == ' ') {
1539 while (--len >= 0 && *p != sep) {
1543 while (bv->bv_len > 0 && *--p == ' ')
1549 aci_set_gather (SetCookie *cookie, struct berval *name, struct berval *attr)
1551 AciSetCookie *cp = (AciSetCookie *)cookie;
1552 BerVarray bvals = NULL;
1555 /* this routine needs to return the bervals instead of
1556 * plain strings, since syntax is not known. It should
1557 * also return the syntax or some "comparison cookie".
1560 if (dnNormalize(0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx) == LDAP_SUCCESS) {
1562 AttributeDescription *desc = NULL;
1563 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1564 backend_attribute(cp->op,
1565 cp->e, &ndn, desc, &bvals);
1567 sl_free(ndn.bv_val, cp->op->o_tmpmemctx);
1574 struct berval *subj,
1580 struct berval set = { 0, NULL };
1582 AciSetCookie cookie;
1585 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
1587 struct berval subjdn, ndn = { 0, NULL };
1588 struct berval setat;
1591 AttributeDescription *desc = NULL;
1593 /* format of string is "entry/setAttrName" */
1594 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1598 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1599 setat.bv_val = SLAPD_ACI_SET_ATTR;
1600 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1603 if ( setat.bv_val != NULL ) {
1605 * NOTE: dnNormalize honors the ber_len field
1606 * as the length of the dn to be normalized
1608 if ( dnNormalize(0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS
1609 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1611 backend_attribute(op, e,
1612 &ndn, desc, &bvals);
1613 if ( bvals != NULL ) {
1614 if ( bvals[0].bv_val != NULL ) {
1617 bvals[0].bv_val = NULL;
1618 for (i=1;bvals[i].bv_val;i++);
1619 bvals[0].bv_val = bvals[i-1].bv_val;
1620 bvals[i-1].bv_val = NULL;
1622 ber_bvarray_free_x(bvals, op->o_tmpmemctx);
1630 if (set.bv_val != NULL) {
1633 rc = (slap_set_filter(aci_set_gather, (SetCookie *)&cookie, &set,
1634 &op->o_ndn, &e->e_nname, NULL) > 0);
1635 sl_free(set.bv_val, op->o_tmpmemctx);
1640 #ifdef SLAPD_ACI_ENABLED
1642 aci_list_map_rights(
1643 struct berval *list )
1650 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1653 switch (*bv.bv_val) {
1655 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1658 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1659 * the right 's' to mean "set", but in the examples states
1660 * that the right 's' means "search". The latter definition
1663 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1666 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1669 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1672 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1673 * define any equivalent to the AUTH right, so I've just used
1676 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1688 struct berval *list,
1689 const struct berval *attr,
1690 struct berval *val )
1692 struct berval bv, left, right;
1695 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1696 if (aci_get_part(&bv, 0, '=', &left) < 0
1697 || aci_get_part(&bv, 1, '=', &right) < 0)
1699 if (ber_bvstrcasecmp(attr, &bv) == 0)
1701 } else if (val == NULL) {
1702 if (ber_bvstrcasecmp(attr, &left) == 0)
1705 if (ber_bvstrcasecmp(attr, &left) == 0) {
1706 /* this is experimental code that implements a
1707 * simple (prefix) match of the attribute value.
1708 * the ACI draft does not provide for aci's that
1709 * apply to specific values, but it would be
1710 * nice to have. If the <attr> part of an aci's
1711 * rights list is of the form <attr>=<value>,
1712 * that means the aci applies only to attrs with
1713 * the given value. Furthermore, if the attr is
1714 * of the form <attr>=<value>*, then <value> is
1715 * treated as a prefix, and the aci applies to
1716 * any value with that prefix.
1718 * Ideally, this would allow r.e. matches.
1720 if (aci_get_part(&right, 0, '*', &left) < 0
1721 || right.bv_len <= left.bv_len)
1723 if (ber_bvstrcasecmp(val, &right) == 0)
1725 } else if (val->bv_len >= left.bv_len) {
1726 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1735 static slap_access_t
1736 aci_list_get_attr_rights(
1737 struct berval *list,
1738 const struct berval *attr,
1739 struct berval *val )
1745 /* loop through each rights/attr pair, skip first part (action) */
1747 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1748 if (aci_list_has_attr(&bv, attr, val) == 0)
1750 if (aci_get_part(list, i, ';', &bv) < 0)
1752 mask |= aci_list_map_rights(&bv);
1758 aci_list_get_rights(
1759 struct berval *list,
1760 const struct berval *attr,
1762 slap_access_t *grant,
1763 slap_access_t *deny )
1765 struct berval perm, actn;
1766 slap_access_t *mask;
1769 if (attr == NULL || attr->bv_len == 0
1770 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1771 attr = &aci_bv_br_entry;
1777 /* loop through each permissions clause */
1778 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1779 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1781 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1783 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1790 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1791 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1798 struct berval *subj,
1799 struct berval *defgrpoc,
1800 struct berval *defgrpat,
1806 struct berval subjdn;
1807 struct berval grpoc;
1808 struct berval grpat;
1809 ObjectClass *grp_oc = NULL;
1810 AttributeDescription *grp_ad = NULL;
1814 /* format of string is "group/objectClassValue/groupAttrName" */
1815 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1819 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1823 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1827 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1828 if( rc != LDAP_SUCCESS ) {
1834 grp_oc = oc_bvfind( &grpoc );
1836 if (grp_oc != NULL && grp_ad != NULL ) {
1837 char buf[ACL_BUF_SIZE];
1838 struct berval bv, ndn;
1839 bv.bv_len = sizeof( buf ) - 1;
1840 bv.bv_val = (char *)&buf;
1841 string_expand(&bv, &subjdn, e->e_ndn, matches);
1842 if ( dnNormalize(0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1843 rc = (backend_group(op, e, &ndn, &op->o_ndn,
1844 grp_oc, grp_ad) == 0);
1857 AttributeDescription *desc,
1860 regmatch_t *matches,
1861 slap_access_t *grant,
1862 slap_access_t *deny,
1863 struct berval *scope
1866 struct berval bv, perms, sdn;
1870 assert( desc->ad_cname.bv_val != NULL );
1872 /* parse an aci of the form:
1873 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1875 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1876 a full description of the format for this attribute.
1877 Differences: "this" in the draft is "self" here, and
1878 "self" and "public" is in the position of dnType.
1880 For now, this routine only supports scope=entry.
1882 /* check that the aci has all 5 components */
1883 if (aci_get_part(aci, 4, '#', NULL) < 0)
1886 /* check that the aci family is supported */
1887 if (aci_get_part(aci, 0, '#', &bv) < 0)
1890 /* check that the scope matches */
1891 if (aci_get_part(aci, 1, '#', &bv) < 0
1892 || ber_bvstrcasecmp( scope, &bv ) != 0)
1897 /* get the list of permissions clauses, bail if empty */
1898 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1901 /* check if any permissions allow desired access */
1902 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1905 /* see if we have a DN match */
1906 if (aci_get_part(aci, 3, '#', &bv) < 0)
1909 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1912 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1915 if ( dnNormalize(0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1916 if (dn_match( &op->o_ndn, &ndn))
1922 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1925 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1926 if (dn_match(&op->o_ndn, &e->e_nname))
1929 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1931 AttributeDescription *ad = NULL;
1934 rc = slap_bv2ad( &sdn, &ad, &text );
1936 if( rc != LDAP_SUCCESS ) {
1944 for(at = attrs_find( e->e_attrs, ad );
1946 at = attrs_find( at->a_next, ad ) )
1948 if (value_find_ex( ad,
1949 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1950 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1952 &bv, op->o_tmpmemctx) == 0 )
1962 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1963 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, op, e, matches))
1966 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1967 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, op, e, matches))
1970 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1971 if (aci_match_set(&sdn, op, e, 0))
1974 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1975 if (aci_match_set(&sdn, op, e, 1))
1983 #endif /* SLAPD_ACI_ENABLED */
1990 regmatch_t *matches)
1998 bv->bv_val[0] = '\0';
1999 bv->bv_len--; /* leave space for lone $ */
2002 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2003 sp < pat->bv_val + pat->bv_len ; sp++ )
2005 /* did we previously see a $ */
2007 if ( flag == 1 && *sp == '$' ) {
2012 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2015 } else if ( *sp >= '0' && *sp <= '9' ) {
2023 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2024 if ( *sp >= '0' && *sp <= '9' ) {
2025 n = 10*n + ( *sp - '0' );
2029 if ( *sp != /*'{'*/ '}' ) {
2034 if ( n >= MAXREMATCHES ) {
2039 i = matches[n].rm_so;
2040 l = matches[n].rm_eo;
2041 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2059 /* must have ended with a single $ */
2068 LDAP_LOG( ACL, DETAIL1,
2069 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2070 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
2072 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2073 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2079 struct berval *pat, /* pattern to expand and match against */
2080 char *str, /* string to match against pattern */
2081 char *buf, /* buffer with $N expansion variables */
2082 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2086 char newbuf[ACL_BUF_SIZE];
2090 bv.bv_len = sizeof(newbuf) - 1;
2093 if(str == NULL) str = "";
2095 string_expand(&bv, pat, buf, matches);
2096 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
2097 char error[ACL_BUF_SIZE];
2098 regerror(rc, &re, error, sizeof(error));
2102 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
2103 pat->bv_val, str, error );
2105 Debug( LDAP_DEBUG_TRACE,
2106 "compile( \"%s\", \"%s\") failed %s\n",
2107 pat->bv_val, str, error );
2112 rc = regexec(&re, str, 0, NULL, 0);
2116 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
2117 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
2118 rc, rc ? "matches" : "no matches", 0 );
2120 Debug( LDAP_DEBUG_TRACE,
2121 "=> regex_matches: string: %s\n", str, 0, 0 );
2122 Debug( LDAP_DEBUG_TRACE,
2123 "=> regex_matches: rc: %d %s\n",
2124 rc, !rc ? "matches" : "no matches", 0 );