1 /* acl.c - routines to parse and check acl's */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
32 #include <ac/socket.h>
33 #include <ac/string.h>
39 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
45 aci_bv_entry = BER_BVC("entry"),
46 aci_bv_children = BER_BVC("children"),
47 aci_bv_br_entry = BER_BVC("[entry]"),
48 aci_bv_br_all = BER_BVC("[all]"),
49 aci_bv_access_id = BER_BVC("access-id"),
50 aci_bv_anonymous = BER_BVC("anonymous"),
51 aci_bv_public = BER_BVC("public"),
52 aci_bv_users = BER_BVC("users"),
53 aci_bv_self = BER_BVC("self"),
54 aci_bv_dnattr = BER_BVC("dnattr"),
55 aci_bv_group = BER_BVC("group"),
56 aci_bv_role = BER_BVC("role"),
57 aci_bv_set = BER_BVC("set"),
58 aci_bv_set_ref = BER_BVC("set-ref"),
59 aci_bv_grant = BER_BVC("grant"),
60 aci_bv_deny = BER_BVC("deny"),
62 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
63 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
64 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
65 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR);
68 static AccessControl * acl_get(
69 AccessControl *ac, int *count,
70 Operation *op, Entry *e,
71 AttributeDescription *desc,
73 int nmatches, regmatch_t *matches );
75 static slap_control_t acl_mask(
76 AccessControl *ac, slap_mask_t *mask,
77 Operation *op, Entry *e,
78 AttributeDescription *desc,
82 AccessControlState *state );
84 #ifdef SLAPD_ACI_ENABLED
86 Operation *op, Entry *e,
87 AttributeDescription *desc,
93 struct berval *scope);
96 static int regex_matches(
97 struct berval *pat, char *str, char *buf, regmatch_t *matches);
98 static void string_expand(
99 struct berval *newbuf, struct berval *pattern,
100 char *match, regmatch_t *matches);
102 typedef struct AciSetCookie {
107 SLAP_SET_GATHER aci_set_gather;
108 static int aci_match_set ( struct berval *subj, Operation *op,
109 Entry *e, int setref );
112 * access_allowed - check whether op->o_ndn is allowed the requested access
113 * to entry e, attribute attr, value val. if val is null, access to
114 * the whole attribute is assumed (all values).
116 * This routine loops through all access controls and calls
117 * acl_mask() on each applicable access control.
118 * The loop exits when a definitive answer is reached or
119 * or no more controls remain.
130 AttributeDescription *desc,
132 slap_access_t access,
133 AccessControlState *state )
137 AccessControl *a = NULL;
142 char accessmaskbuf[ACCESSMASK_MAXLEN];
145 slap_control_t control;
147 regmatch_t matches[MAXREMATCHES];
148 int st_same_attr = 0;
149 int st_initialized = 0;
150 static AccessControlState state_init = ACL_STATE_INIT;
153 assert( desc != NULL );
154 assert( access > ACL_NONE );
156 attr = desc->ad_cname.bv_val;
158 assert( attr != NULL );
160 if( op && op->o_is_auth_check &&
161 ( access == ACL_SEARCH || access == ACL_READ ))
166 if( state && state->as_recorded && state->as_vd_ad==desc) {
167 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
170 return state->as_result;
172 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
173 val != NULL && state->as_vd_acl == NULL )
175 return state->as_result;
181 state->as_vd_ad=desc;
185 LDAP_LOG( ACL, ENTRY,
186 "access_allowed: %s access to \"%s\" \"%s\" requested\n",
187 access2str( access ), e->e_dn, attr );
189 Debug( LDAP_DEBUG_ACL,
190 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
191 access2str( access ), e->e_dn, attr );
201 !slapi_x_access_allowed( op, e, desc, val, access, state )) {
202 /* ACL plugin denied access */
205 #endif /* LDAP_SLAPI */
213 assert( be != NULL );
215 /* grant database root access */
216 if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
219 "access_allowed: conn %lu root access granted\n",
220 op->o_connid, 0, 0 );
222 Debug( LDAP_DEBUG_ACL,
223 "<= root access granted\n",
230 * no-user-modification operational attributes are ignored
231 * by ACL_WRITE checking as any found here are not provided
234 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
235 && desc != slap_schema.si_ad_entry
236 && desc != slap_schema.si_ad_children )
239 LDAP_LOG( ACL, DETAIL1,
240 "access_allowed: conn %lu NoUserMod Operational attribute: %s "
241 "access granted\n", op->o_connid, attr , 0 );
243 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
244 " %s access granted\n",
250 /* use backend default access if no backend acls */
251 if( be != NULL && be->be_acl == NULL ) {
253 LDAP_LOG( ACL, DETAIL1,
254 "access_allowed: backend default %s access %s to \"%s\"\n",
255 access2str( access ),
256 be->be_dfltaccess >= access ? "granted" : "denied",
257 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
259 Debug( LDAP_DEBUG_ACL,
260 "=> access_allowed: backend default %s access %s to \"%s\"\n",
261 access2str( access ),
262 be->be_dfltaccess >= access ? "granted" : "denied",
263 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
265 ret = be->be_dfltaccess >= access;
269 /* be is always non-NULL */
270 /* use global default access if no global acls */
271 } else if ( be == NULL && global_acl == NULL ) {
273 LDAP_LOG( ACL, DETAIL1,
274 "access_allowed: global default %s access %s to \"%s\"\n",
275 access2str( access ),
276 global_default_access >= access ? "granted" : "denied",
279 Debug( LDAP_DEBUG_ACL,
280 "=> access_allowed: global default %s access %s to \"%s\"\n",
281 access2str( access ),
282 global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
284 ret = global_default_access >= access;
293 assert( state->as_vd_acl != NULL );
295 a = state->as_vd_acl;
296 mask = state->as_vd_acl_mask;
297 count = state->as_vd_acl_count;
298 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
302 if ( state ) state->as_vi_acl = NULL;
306 memset(matches, '\0', sizeof(matches));
309 while((a = acl_get( a, &count, op, e, desc, val,
310 MAXREMATCHES, matches )) != NULL)
314 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
316 LDAP_LOG( ACL, DETAIL1,
317 "access_allowed: match[%d]: %d %d ",
318 i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
320 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
321 (int)matches[i].rm_so, (int)matches[i].rm_eo );
323 if( matches[i].rm_so <= matches[0].rm_eo ) {
325 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
326 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
330 LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
332 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
337 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
338 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
339 ret = state->as_result;
341 } else if (!st_initialized) {
342 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
344 state->as_vd_ad=desc;
350 control = acl_mask( a, &mask, op,
351 e, desc, val, matches, count, state );
353 if ( control != ACL_BREAK ) {
357 memset(matches, '\0', sizeof(matches));
360 if ( ACL_IS_INVALID( mask ) ) {
362 LDAP_LOG( ACL, DETAIL1,
363 "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
364 op->o_connid, e->e_dn, attr );
366 Debug( LDAP_DEBUG_ACL,
367 "=> access_allowed: \"%s\" (%s) invalid!\n",
372 } else if ( control == ACL_BREAK ) {
374 LDAP_LOG( ACL, DETAIL1,
375 "access_allowed: conn %lu no more rules\n", op->o_connid, 0,0 );
377 Debug( LDAP_DEBUG_ACL,
378 "=> access_allowed: no more rules\n", 0, 0, 0);
385 LDAP_LOG( ACL, ENTRY,
386 "access_allowed: %s access %s by %s\n",
387 access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
388 accessmask2str( mask, accessmaskbuf ) );
390 Debug( LDAP_DEBUG_ACL,
391 "=> access_allowed: %s access %s by %s\n",
392 access2str( access ),
393 ACL_GRANT(mask, access) ? "granted" : "denied",
394 accessmask2str( mask, accessmaskbuf ) );
397 ret = ACL_GRANT(mask, access);
400 if( state != NULL ) {
401 /* If not value-dependent, save ACL in case of more attrs */
402 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) ) {
403 state->as_vi_acl = a;
404 state->as_result = ret;
406 state->as_recorded |= ACL_STATE_RECORDED;
408 if (be_null) op->o_bd = NULL;
413 * acl_get - return the acl applicable to entry e, attribute
414 * attr. the acl returned is suitable for use in subsequent calls to
415 * acl_access_allowed().
418 static AccessControl *
424 AttributeDescription *desc,
427 regmatch_t *matches )
433 assert( count != NULL );
434 assert( desc != NULL );
436 attr = desc->ad_cname.bv_val;
438 assert( attr != NULL );
441 if( op->o_bd == NULL ) {
444 a = op->o_bd->be_acl;
453 dnlen = e->e_nname.bv_len;
455 for ( ; a != NULL; a = a->acl_next ) {
458 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
459 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
461 LDAP_LOG( ACL, DETAIL1,
462 "acl_get: dnpat [%d] %s nsub: %d\n",
463 *count, a->acl_dn_pat.bv_val,
464 (int) a->acl_dn_re.re_nsub );
466 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
467 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
469 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
474 LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
475 *count, a->acl_dn_pat.bv_val, 0 );
477 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
478 *count, a->acl_dn_pat.bv_val, 0 );
480 patlen = a->acl_dn_pat.bv_len;
481 if ( dnlen < patlen )
484 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
485 /* base dn -- entire object DN must match */
486 if ( dnlen != patlen )
489 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
492 if ( dnlen <= patlen )
495 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
498 rdnlen = dn_rdnlen( NULL, &e->e_nname );
499 if ( rdnlen != dnlen - patlen - 1 )
502 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
503 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
506 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
507 if ( dnlen <= patlen )
509 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
513 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
518 LDAP_LOG( ACL, DETAIL1,
519 "acl_get: [%d] matched\n", *count, 0, 0 );
521 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
526 if ( a->acl_filter != NULL ) {
527 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
528 if ( rc != LDAP_COMPARE_TRUE ) {
534 LDAP_LOG( ACL, DETAIL1,
535 "acl_get: [%d] check attr %s\n", *count, attr ,0 );
537 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
540 if ( a->acl_attrs == NULL ||
541 ad_inlist( desc, a->acl_attrs ) )
544 LDAP_LOG( ACL, DETAIL1,
545 "acl_get: [%d] acl %s attr: %s\n", *count, e->e_dn, attr );
547 Debug( LDAP_DEBUG_ACL,
548 "<= acl_get: [%d] acl %s attr: %s\n",
549 *count, e->e_dn, attr );
553 matches[0].rm_so = matches[0].rm_eo = -1;
557 LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
559 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
565 * Record value-dependent access control state
567 #define ACL_RECORD_VALUE_STATE do { \
568 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
569 state->as_recorded |= ACL_STATE_RECORDED_VD; \
570 state->as_vd_acl = a; \
571 AC_MEMCPY( state->as_vd_acl_matches, matches, \
572 sizeof( state->as_vd_acl_matches )) ; \
573 state->as_vd_acl_count = count; \
574 state->as_vd_access = b; \
575 state->as_vd_access_count = i; \
580 * acl_mask - modifies mask based upon the given acl and the
581 * requested access to entry e, attribute attr, value val. if val
582 * is null, access to the whole attribute is assumed (all values).
584 * returns 0 access NOT allowed
588 static slap_control_t
594 AttributeDescription *desc,
598 AccessControlState *state )
600 int i, odnlen, patlen;
603 char accessmaskbuf[ACCESSMASK_MAXLEN];
604 char accessmaskbuf1[ACCESSMASK_MAXLEN];
609 assert( mask != NULL );
610 assert( desc != NULL );
612 attr = desc->ad_cname.bv_val;
614 assert( attr != NULL );
617 LDAP_LOG( ACL, ENTRY,
618 "acl_mask: conn %lu access to entry \"%s\", attr \"%s\" requested\n",
619 op->o_connid, e->e_dn, attr );
622 " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
623 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
624 accessmask2str( *mask, accessmaskbuf ) );
626 Debug( LDAP_DEBUG_ACL,
627 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
630 Debug( LDAP_DEBUG_ACL,
631 "=> acl_mask: to %s by \"%s\", (%s) \n",
632 val ? "value" : "all values",
633 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
634 accessmask2str( *mask, accessmaskbuf ) );
637 /* Is this ACL only for a specific value? */
638 if ( a->acl_attrval.bv_len ) {
639 if ( state && !state->as_vd_acl ) {
640 state->as_vd_acl = a;
641 state->as_vd_access = a->acl_access;
642 state->as_vd_access_count = 1;
647 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
649 LDAP_LOG( ACL, DETAIL1,
650 "acl_get: valpat %s\n",
651 a->acl_attrval.bv_val, 0, 0 );
653 Debug( LDAP_DEBUG_ACL,
654 "acl_get: valpat %s\n",
655 a->acl_attrval.bv_val, 0, 0 );
657 if (regexec(&a->acl_attrval_re, val->bv_val, 0, NULL, 0))
663 LDAP_LOG( ACL, DETAIL1,
665 a->acl_attrval.bv_val, 0, 0 );
667 Debug( LDAP_DEBUG_ACL,
669 a->acl_attrval.bv_val, 0, 0 );
671 if (value_match( &match, desc,
672 desc->ad_type->sat_equality, 0,
673 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
679 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
680 && state->as_vd_acl == a )
682 b = state->as_vd_access;
683 i = state->as_vd_access_count;
690 for ( ; b != NULL; b = b->a_next, i++ ) {
691 slap_mask_t oldmask, modmask;
693 ACL_INVALIDATE( modmask );
695 /* AND <who> clauses */
696 if ( b->a_dn_pat.bv_len != 0 ) {
698 LDAP_LOG( ACL, DETAIL1,
699 "acl_mask: conn %lu check a_dn_pat: %s\n",
700 op->o_connid, b->a_dn_pat.bv_val ,0 );
702 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
703 b->a_dn_pat.bv_val, 0, 0);
706 * if access applies to the entry itself, and the
707 * user is bound as somebody in the same namespace as
708 * the entry, OR the given dn matches the dn pattern
710 if ( bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) ) {
711 if ( op->o_ndn.bv_len != 0 ) {
715 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_users ) ) {
716 if ( op->o_ndn.bv_len == 0 ) {
720 } else if ( bvmatch( &b->a_dn_pat, &aci_bv_self ) ) {
721 if ( op->o_ndn.bv_len == 0 ) {
725 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
729 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
730 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
731 int ret = regex_matches( &b->a_dn_pat,
732 op->o_ndn.bv_val, e->e_ndn, matches );
743 if ( e->e_dn == NULL )
746 if ( b->a_dn_expand ) {
748 char buf[ACL_BUF_SIZE];
750 bv.bv_len = sizeof( buf ) - 1;
753 string_expand(&bv, &b->a_dn_pat,
755 if ( dnNormalize(0, NULL, NULL, &bv, &pat, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
756 /* did not expand to a valid dn */
764 odnlen = op->o_ndn.bv_len;
765 if ( odnlen < patlen ) {
766 goto dn_match_cleanup;
770 if ( b->a_dn_style == ACL_STYLE_BASE ) {
771 /* base dn -- entire object DN must match */
772 if ( odnlen != patlen ) {
773 goto dn_match_cleanup;
776 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
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;
787 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
788 if ( rdnlen != odnlen - patlen - 1 ) {
789 goto dn_match_cleanup;
792 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
793 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
794 goto dn_match_cleanup;
797 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
798 if ( odnlen <= patlen ) {
799 goto dn_match_cleanup;
802 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
803 goto dn_match_cleanup;
807 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
810 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
820 if ( b->a_sockurl_pat.bv_len ) {
821 if ( ! op->o_conn->c_listener ) {
825 LDAP_LOG( ACL, DETAIL1,
826 "acl_mask: conn %lu check a_sockurl_pat: %s\n",
827 op->o_connid, b->a_sockurl_pat.bv_val , 0 );
829 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
830 b->a_sockurl_pat.bv_val, 0, 0 );
833 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
834 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
835 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
836 e->e_ndn, matches ) )
841 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
847 if ( b->a_domain_pat.bv_len ) {
848 if ( !op->o_conn->c_peer_domain.bv_val ) {
852 LDAP_LOG( ACL, DETAIL1,
853 "acl_mask: conn %lu check a_domain_pat: %s\n",
854 op->o_connid, b->a_domain_pat.bv_val , 0 );
856 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
857 b->a_domain_pat.bv_val, 0, 0 );
859 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
860 if ( b->a_domain_style == ACL_STYLE_REGEX) {
861 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
862 e->e_ndn, matches ) )
867 char buf[ACL_BUF_SIZE];
869 struct berval cmp = op->o_conn->c_peer_domain;
870 struct berval pat = b->a_domain_pat;
872 if ( b->a_domain_expand ) {
875 bv.bv_len = sizeof(buf) - 1;
878 string_expand(&bv, &b->a_domain_pat, e->e_ndn, matches);
882 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
883 int offset = cmp.bv_len - pat.bv_len;
888 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
892 /* trim the domain */
893 cmp.bv_val = &cmp.bv_val[ offset ];
894 cmp.bv_len -= offset;
897 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
904 if ( b->a_peername_pat.bv_len ) {
905 if ( !op->o_conn->c_peer_name.bv_val ) {
909 LDAP_LOG( ACL, DETAIL1,
910 "acl_mask: conn %lu check a_peername_path: %s\n",
911 op->o_connid, b->a_peername_pat.bv_val , 0 );
913 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
914 b->a_peername_pat.bv_val, 0, 0 );
916 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
917 if ( b->a_peername_style == ACL_STYLE_REGEX) {
918 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
919 e->e_ndn, matches ) )
924 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 )
930 if ( b->a_sockname_pat.bv_len ) {
931 if ( !op->o_conn->c_sock_name.bv_val ) {
935 LDAP_LOG( ACL, DETAIL1,
936 "acl_mask: conn %lu check a_sockname_path: %s\n",
937 op->o_connid, b->a_sockname_pat.bv_val , 0 );
939 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
940 b->a_sockname_pat.bv_val, 0, 0 );
942 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
943 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
944 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
945 e->e_ndn, matches ) )
950 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 )
956 if ( b->a_dn_at != NULL ) {
961 const char *attr = b->a_dn_at->ad_cname.bv_val;
963 assert( attr != NULL );
965 if ( op->o_ndn.bv_len == 0 ) {
970 LDAP_LOG( ACL, DETAIL1,
971 "acl_mask: conn %lu check a_dn_pat: %s\n",
972 op->o_connid, attr , 0 );
974 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
979 /* see if asker is listed in dnattr */
980 for( at = attrs_find( e->e_attrs, b->a_dn_at );
982 at = attrs_find( at->a_next, b->a_dn_at ) )
984 if( value_find_ex( b->a_dn_at,
985 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
986 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
988 &bv, op->o_tmpmemctx ) == 0 )
997 /* have a dnattr match. if this is a self clause then
998 * the target must also match the op dn.
1000 if ( b->a_dn_self ) {
1001 /* check if the target is an attribute. */
1002 if ( val == NULL ) continue;
1004 /* target is attribute, check if the attribute value
1007 rc = value_match( &match, b->a_dn_at,
1008 b->a_dn_at->ad_type->sat_equality, 0,
1010 /* on match error or no match, fail the ACL clause */
1011 if (rc != LDAP_SUCCESS || match != 0 )
1015 /* no dnattr match, check if this is a self clause */
1016 if ( ! b->a_dn_self )
1019 ACL_RECORD_VALUE_STATE;
1021 /* this is a self clause, check if the target is an
1027 /* target is attribute, check if the attribute value
1030 rc = value_match( &match, b->a_dn_at,
1031 b->a_dn_at->ad_type->sat_equality, 0,
1034 /* on match error or no match, fail the ACL clause */
1035 if (rc != LDAP_SUCCESS || match != 0 )
1040 if ( b->a_group_pat.bv_len ) {
1042 struct berval ndn = { 0, NULL };
1045 if ( op->o_ndn.bv_len == 0 ) {
1049 /* b->a_group is an unexpanded entry name, expanded it should be an
1050 * entry with objectclass group* and we test to see if odn is one of
1051 * the values in the attribute group
1053 /* see if asker is listed in dnattr */
1054 if ( b->a_group_style == ACL_STYLE_REGEX ) {
1055 char buf[ACL_BUF_SIZE];
1056 bv.bv_len = sizeof(buf) - 1;
1059 string_expand( &bv, &b->a_group_pat, e->e_ndn, matches );
1060 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) != LDAP_SUCCESS ) {
1061 /* did not expand to a valid dn */
1068 bv = b->a_group_pat;
1071 rc = backend_group( op, e, &bv, &op->o_ndn,
1072 b->a_group_oc, b->a_group_at );
1074 if ( ndn.bv_val ) free( ndn.bv_val );
1081 if ( b->a_set_pat.bv_len != 0 ) {
1083 char buf[ACL_BUF_SIZE];
1084 if( b->a_set_style == ACL_STYLE_REGEX ){
1085 bv.bv_len = sizeof(buf) - 1;
1087 string_expand( &bv, &b->a_set_pat, e->e_ndn, matches );
1091 if (aci_match_set( &bv, op, e, 0 ) == 0) {
1096 if ( b->a_authz.sai_ssf ) {
1098 LDAP_LOG( ACL, DETAIL1,
1099 "acl_mask: conn %lu check a_authz.sai_ssf: ACL %u > OP %u\n",
1100 op->o_connid, b->a_authz.sai_ssf, op->o_ssf );
1102 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1103 b->a_authz.sai_ssf, op->o_ssf, 0 );
1105 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1110 if ( b->a_authz.sai_transport_ssf ) {
1112 LDAP_LOG( ACL, DETAIL1,
1113 "acl_mask: conn %lu check a_authz.sai_transport_ssf: "
1115 op->o_connid, b->a_authz.sai_transport_ssf,
1116 op->o_transport_ssf );
1118 Debug( LDAP_DEBUG_ACL,
1119 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1120 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1122 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1127 if ( b->a_authz.sai_tls_ssf ) {
1129 LDAP_LOG( ACL, DETAIL1,
1130 "acl_mask: conn %lu check a_authz.sai_tls_ssf: ACL %u > "
1132 op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf );
1134 Debug( LDAP_DEBUG_ACL,
1135 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1136 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1138 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1143 if ( b->a_authz.sai_sasl_ssf ) {
1145 LDAP_LOG( ACL, DETAIL1,
1146 "acl_mask: conn %lu check a_authz.sai_sasl_ssf: "
1148 op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
1150 Debug( LDAP_DEBUG_ACL,
1151 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1152 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1154 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1159 #ifdef SLAPD_ACI_ENABLED
1160 if ( b->a_aci_at != NULL ) {
1162 slap_access_t grant, deny, tgrant, tdeny;
1163 struct berval parent_ndn, old_parent_ndn;
1164 BerVarray bvals = NULL;
1167 /* this case works different from the others above.
1168 * since aci's themselves give permissions, we need
1169 * to first check b->a_access_mask, the ACL's access level.
1172 if ( e->e_nname.bv_len == 0 ) {
1173 /* no ACIs in the root DSE */
1177 /* first check if the right being requested
1178 * is allowed by the ACL clause.
1180 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1183 /* start out with nothing granted, nothing denied */
1187 /* get the aci attribute */
1188 at = attr_find( e->e_attrs, b->a_aci_at );
1190 ACL_RECORD_VALUE_STATE;
1191 /* the aci is an multi-valued attribute. The
1192 * rights are determined by OR'ing the individual
1193 * rights given by the acis.
1195 for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
1199 matches, &grant, &deny, &aci_bv_entry ) != 0)
1205 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1206 accessmask2str(tgrant,accessmaskbuf),
1207 accessmask2str(tdeny, accessmaskbuf1), 0);
1210 /* If the entry level aci didn't contain anything valid for the
1211 * current operation, climb up the tree and evaluate the
1212 * acis with scope set to subtree
1214 if( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ){
1215 dnParent(&(e->e_nname), &parent_ndn);
1216 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ){
1217 old_parent_ndn = parent_ndn;
1218 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1219 ret=backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals);
1223 for( i = 0; bvals[i].bv_val != NULL; i++){
1224 ACL_RECORD_VALUE_STATE;
1225 if (aci_mask(op, e, desc, val, &bvals[i], matches,
1226 &grant, &deny, &aci_bv_children) != 0) {
1229 /* evaluation stops as soon as either a "deny" or a
1230 * "grant" directive matches.
1232 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1236 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1237 accessmask2str(tgrant,accessmaskbuf),
1238 accessmask2str(tdeny, accessmaskbuf1), 0);
1243 case LDAP_NO_SUCH_ATTRIBUTE:
1244 /* just go on if the aci-Attribute is not present in
1247 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1250 case LDAP_NO_SUCH_OBJECT:
1251 /* We have reached the base object */
1252 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1262 dnParent(&old_parent_ndn, &parent_ndn);
1267 /* remove anything that the ACL clause does not allow */
1268 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1269 tdeny &= ACL_PRIV_MASK;
1271 /* see if we have anything to contribute */
1272 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1276 /* this could be improved by changing acl_mask so that it can deal with
1277 * by clauses that return grant/deny pairs. Right now, it does either
1278 * additive or subtractive rights, but not both at the same time. So,
1279 * we need to combine the grant/deny pair into a single rights mask in
1280 * a smart way: if either grant or deny is "empty", then we use the
1281 * opposite as is, otherwise we remove any denied rights from the grant
1282 * rights mask and construct an additive mask.
1284 if (ACL_IS_INVALID(tdeny)) {
1285 modmask = tgrant | ACL_PRIV_ADDITIVE;
1287 } else if (ACL_IS_INVALID(tgrant)) {
1288 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1291 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1297 modmask = b->a_access_mask;
1301 LDAP_LOG( ACL, RESULTS,
1302 "acl_mask: [%d] applying %s (%s)\n",
1303 i, accessmask2str( modmask, accessmaskbuf),
1304 b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
1305 ? "break" : "stop" );
1307 Debug( LDAP_DEBUG_ACL,
1308 "<= acl_mask: [%d] applying %s (%s)\n",
1309 i, accessmask2str( modmask, accessmaskbuf ),
1310 b->a_type == ACL_CONTINUE
1312 : b->a_type == ACL_BREAK
1319 if( ACL_IS_ADDITIVE(modmask) ) {
1321 ACL_PRIV_SET( *mask, modmask );
1324 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1326 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1327 /* substract privs */
1328 ACL_PRIV_CLR( *mask, modmask );
1331 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1339 LDAP_LOG( ACL, DETAIL1,
1340 "acl_mask: conn %lu [%d] mask: %s\n",
1341 op->o_connid, i, accessmask2str( *mask, accessmaskbuf) );
1343 Debug( LDAP_DEBUG_ACL,
1344 "<= acl_mask: [%d] mask: %s\n",
1345 i, accessmask2str(*mask, accessmaskbuf), 0 );
1348 if( b->a_type == ACL_CONTINUE ) {
1351 } else if ( b->a_type == ACL_BREAK ) {
1359 /* implicit "by * none" clause */
1363 LDAP_LOG( ACL, RESULTS,
1364 "acl_mask: conn %lu no more <who> clauses, returning %d (stop)\n",
1365 op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
1367 Debug( LDAP_DEBUG_ACL,
1368 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1369 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1375 * acl_check_modlist - check access control on the given entry to see if
1376 * it allows the given modifications by the user associated with op.
1377 * returns 1 if mods allowed ok
1378 * 0 mods not allowed
1385 Modifications *mlist
1389 AccessControlState state = ACL_STATE_INIT;
1391 assert( op->o_bd != NULL );
1393 /* short circuit root database access */
1394 if ( be_isroot( op->o_bd, &op->o_ndn ) ) {
1396 LDAP_LOG( ACL, DETAIL1,
1397 "acl_check_modlist: conn %lu access granted to root user\n",
1398 op->o_connid, 0, 0 );
1400 Debug( LDAP_DEBUG_ACL,
1401 "<= acl_access_allowed: granted to database root\n",
1407 /* use backend default access if no backend acls */
1408 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1410 LDAP_LOG( ACL, DETAIL1,
1411 "acl_check_modlist: backend default %s access %s to \"%s\"\n",
1412 access2str( ACL_WRITE ),
1413 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied",
1416 Debug( LDAP_DEBUG_ACL,
1417 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1418 access2str( ACL_WRITE ),
1419 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1421 return op->o_bd->be_dfltaccess >= ACL_WRITE;
1424 /* op->o_bd is always non-NULL */
1425 /* use global default access if no global acls */
1426 } else if ( op->o_bd == NULL && global_acl == NULL ) {
1428 LDAP_LOG( ACL, DETAIL1,
1429 "acl_check_modlist: global default %s access %s to \"%s\"\n",
1430 access2str( ACL_WRITE ),
1431 global_default_access >= ACL_WRITE ? "granted" : "denied",
1434 Debug( LDAP_DEBUG_ACL,
1435 "=> access_allowed: global default %s access %s to \"%s\"\n",
1436 access2str( ACL_WRITE ),
1437 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
1439 return global_default_access >= ACL_WRITE;
1443 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1445 * no-user-modification operational attributes are ignored
1446 * by ACL_WRITE checking as any found here are not provided
1449 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1451 LDAP_LOG( ACL, DETAIL1,
1452 "acl_check_modlist: conn %lu no-user-mod %s: modify access granted\n",
1453 op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
1455 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1456 " modify access granted\n",
1457 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1462 switch ( mlist->sml_op ) {
1463 case LDAP_MOD_REPLACE:
1465 * We must check both permission to delete the whole
1466 * attribute and permission to add the specific attributes.
1467 * This prevents abuse from selfwriters.
1469 if ( ! access_allowed( op, e,
1470 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1475 if ( mlist->sml_bvalues == NULL ) break;
1477 /* fall thru to check value to add */
1480 assert( mlist->sml_bvalues != NULL );
1482 for ( bv = mlist->sml_nvalues
1483 ? mlist->sml_nvalues : mlist->sml_values;
1484 bv->bv_val != NULL; bv++ )
1486 if ( ! access_allowed( op, e,
1487 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1494 case LDAP_MOD_DELETE:
1495 if ( mlist->sml_bvalues == NULL ) {
1496 if ( ! access_allowed( op, e,
1497 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1503 for ( bv = mlist->sml_nvalues
1504 ? mlist->sml_nvalues : mlist->sml_values;
1505 bv->bv_val != NULL; bv++ )
1507 if ( ! access_allowed( op, e,
1508 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1515 case SLAP_MOD_SOFTADD:
1516 /* allow adding attribute via modrdn thru */
1530 struct berval *list,
1544 while (len >= 0 && --ix >= 0) {
1545 while (--len >= 0 && *p++ != sep) ;
1547 while (len >= 0 && *p == ' ') {
1558 while (--len >= 0 && *p != sep) {
1562 while (bv->bv_len > 0 && *--p == ' ')
1568 aci_set_gather (SetCookie *cookie, struct berval *name, struct berval *attr)
1570 AciSetCookie *cp = (AciSetCookie *)cookie;
1571 BerVarray bvals = NULL;
1574 /* this routine needs to return the bervals instead of
1575 * plain strings, since syntax is not known. It should
1576 * also return the syntax or some "comparison cookie".
1579 if (dnNormalize(0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx) == LDAP_SUCCESS) {
1581 AttributeDescription *desc = NULL;
1582 if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
1583 backend_attribute(cp->op,
1584 cp->e, &ndn, desc, &bvals);
1586 sl_free(ndn.bv_val, cp->op->o_tmpmemctx);
1593 struct berval *subj,
1599 struct berval set = { 0, NULL };
1601 AciSetCookie cookie;
1604 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
1606 struct berval subjdn, ndn = { 0, NULL };
1607 struct berval setat;
1610 AttributeDescription *desc = NULL;
1612 /* format of string is "entry/setAttrName" */
1613 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1617 if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
1618 setat.bv_val = SLAPD_ACI_SET_ATTR;
1619 setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
1622 if ( setat.bv_val != NULL ) {
1624 * NOTE: dnNormalize honors the ber_len field
1625 * as the length of the dn to be normalized
1627 if ( dnNormalize(0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS
1628 && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
1630 backend_attribute(op, e,
1631 &ndn, desc, &bvals);
1632 if ( bvals != NULL ) {
1633 if ( bvals[0].bv_val != NULL ) {
1636 bvals[0].bv_val = NULL;
1637 for (i=1;bvals[i].bv_val;i++);
1638 bvals[0].bv_val = bvals[i-1].bv_val;
1639 bvals[i-1].bv_val = NULL;
1641 ber_bvarray_free_x(bvals, op->o_tmpmemctx);
1649 if (set.bv_val != NULL) {
1652 rc = (slap_set_filter(aci_set_gather, (SetCookie *)&cookie, &set,
1653 &op->o_ndn, &e->e_nname, NULL) > 0);
1654 sl_free(set.bv_val, op->o_tmpmemctx);
1659 #ifdef SLAPD_ACI_ENABLED
1661 aci_list_map_rights(
1662 struct berval *list )
1669 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1672 switch (*bv.bv_val) {
1674 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1677 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
1678 * the right 's' to mean "set", but in the examples states
1679 * that the right 's' means "search". The latter definition
1682 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1685 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1688 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1691 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
1692 * define any equivalent to the AUTH right, so I've just used
1695 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1707 struct berval *list,
1708 const struct berval *attr,
1709 struct berval *val )
1711 struct berval bv, left, right;
1714 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
1715 if (aci_get_part(&bv, 0, '=', &left) < 0
1716 || aci_get_part(&bv, 1, '=', &right) < 0)
1718 if (ber_bvstrcasecmp(attr, &bv) == 0)
1720 } else if (val == NULL) {
1721 if (ber_bvstrcasecmp(attr, &left) == 0)
1724 if (ber_bvstrcasecmp(attr, &left) == 0) {
1725 /* this is experimental code that implements a
1726 * simple (prefix) match of the attribute value.
1727 * the ACI draft does not provide for aci's that
1728 * apply to specific values, but it would be
1729 * nice to have. If the <attr> part of an aci's
1730 * rights list is of the form <attr>=<value>,
1731 * that means the aci applies only to attrs with
1732 * the given value. Furthermore, if the attr is
1733 * of the form <attr>=<value>*, then <value> is
1734 * treated as a prefix, and the aci applies to
1735 * any value with that prefix.
1737 * Ideally, this would allow r.e. matches.
1739 if (aci_get_part(&right, 0, '*', &left) < 0
1740 || right.bv_len <= left.bv_len)
1742 if (ber_bvstrcasecmp(val, &right) == 0)
1744 } else if (val->bv_len >= left.bv_len) {
1745 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1754 static slap_access_t
1755 aci_list_get_attr_rights(
1756 struct berval *list,
1757 const struct berval *attr,
1758 struct berval *val )
1764 /* loop through each rights/attr pair, skip first part (action) */
1766 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1767 if (aci_list_has_attr(&bv, attr, val) == 0)
1769 if (aci_get_part(list, i, ';', &bv) < 0)
1771 mask |= aci_list_map_rights(&bv);
1777 aci_list_get_rights(
1778 struct berval *list,
1779 const struct berval *attr,
1781 slap_access_t *grant,
1782 slap_access_t *deny )
1784 struct berval perm, actn;
1785 slap_access_t *mask;
1788 if (attr == NULL || attr->bv_len == 0
1789 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
1790 attr = &aci_bv_br_entry;
1796 /* loop through each permissions clause */
1797 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1798 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1800 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
1802 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
1809 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1810 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
1817 struct berval *subj,
1818 struct berval *defgrpoc,
1819 struct berval *defgrpat,
1825 struct berval subjdn;
1826 struct berval grpoc;
1827 struct berval grpat;
1828 ObjectClass *grp_oc = NULL;
1829 AttributeDescription *grp_ad = NULL;
1833 /* format of string is "group/objectClassValue/groupAttrName" */
1834 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
1838 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
1842 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
1846 rc = slap_bv2ad( &grpat, &grp_ad, &text );
1847 if( rc != LDAP_SUCCESS ) {
1853 grp_oc = oc_bvfind( &grpoc );
1855 if (grp_oc != NULL && grp_ad != NULL ) {
1856 char buf[ACL_BUF_SIZE];
1857 struct berval bv, ndn;
1858 bv.bv_len = sizeof( buf ) - 1;
1859 bv.bv_val = (char *)&buf;
1860 string_expand(&bv, &subjdn, e->e_ndn, matches);
1861 if ( dnNormalize(0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1862 rc = (backend_group(op, e, &ndn, &op->o_ndn,
1863 grp_oc, grp_ad) == 0);
1876 AttributeDescription *desc,
1879 regmatch_t *matches,
1880 slap_access_t *grant,
1881 slap_access_t *deny,
1882 struct berval *scope
1885 struct berval bv, perms, sdn;
1889 assert( desc->ad_cname.bv_val != NULL );
1891 /* parse an aci of the form:
1892 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1894 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1895 a full description of the format for this attribute.
1896 Differences: "this" in the draft is "self" here, and
1897 "self" and "public" is in the position of dnType.
1899 For now, this routine only supports scope=entry.
1901 /* check that the aci has all 5 components */
1902 if (aci_get_part(aci, 4, '#', NULL) < 0)
1905 /* check that the aci family is supported */
1906 if (aci_get_part(aci, 0, '#', &bv) < 0)
1909 /* check that the scope matches */
1910 if (aci_get_part(aci, 1, '#', &bv) < 0
1911 || ber_bvstrcasecmp( scope, &bv ) != 0)
1916 /* get the list of permissions clauses, bail if empty */
1917 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1920 /* check if any permissions allow desired access */
1921 if (aci_list_get_rights(&perms, &desc->ad_cname, val, grant, deny) == 0)
1924 /* see if we have a DN match */
1925 if (aci_get_part(aci, 3, '#', &bv) < 0)
1928 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1931 if (ber_bvstrcasecmp( &aci_bv_access_id, &bv ) == 0) {
1934 if ( dnNormalize(0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS ) {
1935 if (dn_match( &op->o_ndn, &ndn))
1941 } else if (ber_bvstrcasecmp( &aci_bv_public, &bv ) == 0) {
1944 } else if (ber_bvstrcasecmp( &aci_bv_self, &bv ) == 0) {
1945 if (dn_match(&op->o_ndn, &e->e_nname))
1948 } else if (ber_bvstrcasecmp( &aci_bv_dnattr, &bv ) == 0) {
1950 AttributeDescription *ad = NULL;
1953 rc = slap_bv2ad( &sdn, &ad, &text );
1955 if( rc != LDAP_SUCCESS ) {
1963 for(at = attrs_find( e->e_attrs, ad );
1965 at = attrs_find( at->a_next, ad ) )
1967 if (value_find_ex( ad,
1968 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1969 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1971 &bv, op->o_tmpmemctx) == 0 )
1981 } else if (ber_bvstrcasecmp( &aci_bv_group, &bv ) == 0) {
1982 if (aci_group_member(&sdn, &aci_bv_group_class, &aci_bv_group_attr, op, e, matches))
1985 } else if (ber_bvstrcasecmp( &aci_bv_role, &bv ) == 0) {
1986 if (aci_group_member(&sdn, &aci_bv_role_class, &aci_bv_role_attr, op, e, matches))
1989 } else if (ber_bvstrcasecmp( &aci_bv_set, &bv ) == 0) {
1990 if (aci_match_set(&sdn, op, e, 0))
1993 } else if (ber_bvstrcasecmp( &aci_bv_set_ref, &bv ) == 0) {
1994 if (aci_match_set(&sdn, op, e, 1))
2002 #endif /* SLAPD_ACI_ENABLED */
2009 regmatch_t *matches)
2017 bv->bv_val[0] = '\0';
2018 bv->bv_len--; /* leave space for lone $ */
2021 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2022 sp < pat->bv_val + pat->bv_len ; sp++ )
2024 /* did we previously see a $ */
2026 if ( flag == 1 && *sp == '$' ) {
2031 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2034 } else if ( *sp >= '0' && *sp <= '9' ) {
2042 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2043 if ( *sp >= '0' && *sp <= '9' ) {
2044 n = 10*n + ( *sp - '0' );
2048 if ( *sp != /*'{'*/ '}' ) {
2053 if ( n >= MAXREMATCHES ) {
2058 i = matches[n].rm_so;
2059 l = matches[n].rm_eo;
2060 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2078 /* must have ended with a single $ */
2087 LDAP_LOG( ACL, DETAIL1,
2088 "string_expand: pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2089 LDAP_LOG( ACL, DETAIL1, "string_expand: expanded = %s\n", bv->bv_val, 0, 0 );
2091 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2092 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2098 struct berval *pat, /* pattern to expand and match against */
2099 char *str, /* string to match against pattern */
2100 char *buf, /* buffer with $N expansion variables */
2101 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2105 char newbuf[ACL_BUF_SIZE];
2109 bv.bv_len = sizeof(newbuf) - 1;
2112 if(str == NULL) str = "";
2114 string_expand(&bv, pat, buf, matches);
2115 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
2116 char error[ACL_BUF_SIZE];
2117 regerror(rc, &re, error, sizeof(error));
2121 "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
2122 pat->bv_val, str, error );
2124 Debug( LDAP_DEBUG_TRACE,
2125 "compile( \"%s\", \"%s\") failed %s\n",
2126 pat->bv_val, str, error );
2131 rc = regexec(&re, str, 0, NULL, 0);
2135 LDAP_LOG( ACL, DETAIL2, "regex_matches: string: %s\n", str, 0, 0 );
2136 LDAP_LOG( ACL, DETAIL2, "regex_matches: rc: %d %s\n",
2137 rc, rc ? "matches" : "no matches", 0 );
2139 Debug( LDAP_DEBUG_TRACE,
2140 "=> regex_matches: string: %s\n", str, 0, 0 );
2141 Debug( LDAP_DEBUG_TRACE,
2142 "=> regex_matches: rc: %d %s\n",
2143 rc, !rc ? "matches" : "no matches", 0 );