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-2005 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>
41 #include "slapi/slapi.h"
42 #endif /* LDAPI_SLAPI */
44 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
50 aci_bv_entry = BER_BVC("entry"),
51 aci_bv_children = BER_BVC("children"),
52 aci_bv_onelevel = BER_BVC("onelevel"),
53 aci_bv_subtree = BER_BVC("subtree"),
54 aci_bv_br_entry = BER_BVC("[entry]"),
55 aci_bv_br_all = BER_BVC("[all]"),
56 aci_bv_access_id = BER_BVC("access-id"),
57 aci_bv_anonymous = BER_BVC("anonymous"),
58 aci_bv_public = BER_BVC("public"),
59 aci_bv_users = BER_BVC("users"),
60 aci_bv_self = BER_BVC("self"),
61 aci_bv_dnattr = BER_BVC("dnattr"),
62 aci_bv_group = BER_BVC("group"),
63 aci_bv_role = BER_BVC("role"),
64 aci_bv_set = BER_BVC("set"),
65 aci_bv_set_ref = BER_BVC("set-ref"),
66 aci_bv_grant = BER_BVC("grant"),
67 aci_bv_deny = BER_BVC("deny"),
69 aci_bv_ip_eq = BER_BVC("IP="),
71 aci_bv_path_eq = BER_BVC("PATH="),
72 aci_bv_dirsep = BER_BVC(LDAP_DIRSEP),
73 #endif /* LDAP_PF_LOCAL */
75 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
76 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
77 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
78 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR),
79 aci_bv_set_attr = BER_BVC(SLAPD_ACI_SET_ATTR);
81 typedef enum slap_aci_scope_t {
82 SLAP_ACI_SCOPE_ENTRY = 0x1,
83 SLAP_ACI_SCOPE_CHILDREN = 0x2,
84 SLAP_ACI_SCOPE_SUBTREE = ( SLAP_ACI_SCOPE_ENTRY | SLAP_ACI_SCOPE_CHILDREN )
87 static AccessControl * acl_get(
88 AccessControl *ac, int *count,
89 Operation *op, Entry *e,
90 AttributeDescription *desc,
92 int nmatch, regmatch_t *matches,
93 AccessControlState *state );
95 static slap_control_t acl_mask(
96 AccessControl *ac, slap_mask_t *mask,
97 Operation *op, Entry *e,
98 AttributeDescription *desc,
103 AccessControlState *state );
105 #ifdef SLAPD_ACI_ENABLED
107 Operation *op, Entry *e,
108 AttributeDescription *desc,
113 slap_access_t *grant,
115 slap_aci_scope_t scope);
118 static int regex_matches(
119 struct berval *pat, char *str, char *buf,
120 int nmatch, regmatch_t *matches);
121 static int string_expand(
122 struct berval *newbuf, struct berval *pattern,
123 char *match, int nmatch, regmatch_t *matches);
125 typedef struct AciSetCookie {
130 SLAP_SET_GATHER aci_set_gather;
131 SLAP_SET_GATHER aci_set_gather2;
132 static int aci_match_set ( struct berval *subj, Operation *op,
133 Entry *e, int setref );
136 * access_allowed - check whether op->o_ndn is allowed the requested access
137 * to entry e, attribute attr, value val. if val is null, access to
138 * the whole attribute is assumed (all values).
140 * This routine loops through all access controls and calls
141 * acl_mask() on each applicable access control.
142 * The loop exits when a definitive answer is reached or
143 * or no more controls remain.
150 * - can be legally called with op == NULL
151 * - can be legally called with op->o_bd == NULL
158 AttributeDescription *desc,
160 slap_access_t access,
161 AccessControlState *state,
166 AccessControl *a = NULL;
171 char accessmaskbuf[ACCESSMASK_MAXLEN];
174 slap_control_t control;
176 regmatch_t matches[MAXREMATCHES];
177 int st_same_attr = 0;
178 static AccessControlState state_init = ACL_STATE_INIT;
181 assert( desc != NULL );
182 assert( access > ACL_NONE );
183 if ( maskp ) ACL_INVALIDATE( *maskp );
185 attr = desc->ad_cname.bv_val;
187 assert( attr != NULL );
189 if( op && op->o_is_auth_check &&
190 ( access == ACL_SEARCH || access == ACL_READ ))
196 if ( state->as_vd_ad==desc) {
197 if ( state->as_recorded ) {
198 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
201 return state->as_result;
202 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
203 val != NULL && state->as_vd_acl == NULL )
205 return state->as_result;
213 state->as_vd_ad=desc;
216 Debug( LDAP_DEBUG_ACL,
217 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
218 access2str( access ), e->e_dn, attr );
227 be = LDAP_STAILQ_FIRST(&backendDB);
231 * FIXME: experimental; use first backend rules
232 * iff there is no global_acl (ITS#3100) */
233 if ( frontendDB->be_acl == NULL )
239 assert( be != NULL );
242 if ( op->o_pb != NULL ) {
243 ret = slapi_int_access_allowed( op, e, desc, val, access, state );
245 /* ACL plugin denied access */
249 #endif /* LDAP_SLAPI */
251 /* grant database root access */
252 if ( /* be != NULL && */ be_isroot( op ) ) {
253 Debug( LDAP_DEBUG_ACL,
254 "<= root access granted\n",
257 mask = ACL_LVL_MANAGE;
264 * no-user-modification operational attributes are ignored
265 * by ACL_WRITE checking as any found here are not provided
268 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
269 && desc != slap_schema.si_ad_entry
270 && desc != slap_schema.si_ad_children )
272 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
273 " %s access granted\n",
278 /* use backend default access if no backend acls */
279 if( be != NULL && be->be_acl == NULL ) {
280 Debug( LDAP_DEBUG_ACL,
281 "=> access_allowed: backend default %s access %s to \"%s\"\n",
282 access2str( access ),
283 be->be_dfltaccess >= access ? "granted" : "denied",
284 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
285 ret = be->be_dfltaccess >= access;
290 mask = ACL_PRIV_LEVEL;
291 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
292 mask |= ACL_ACCESS2PRIV( i );
299 /* be is always non-NULL */
300 /* use global default access if no global acls */
301 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
302 Debug( LDAP_DEBUG_ACL,
303 "=> access_allowed: global default %s access %s to \"%s\"\n",
304 access2str( access ),
305 frontendDB->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
306 ret = frontendDB->be_dfltaccess >= access;
311 mask = ACL_PRIV_LEVEL;
312 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
313 mask |= ACL_ACCESS2PRIV( i );
325 assert( state->as_vd_acl != NULL );
327 a = state->as_vd_acl;
328 count = state->as_vd_acl_count;
329 if ( !ACL_IS_INVALID( state->as_vd_acl_mask )) {
330 mask = state->as_vd_acl_mask;
331 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
336 if ( state ) state->as_vi_acl = NULL;
340 memset(matches, '\0', sizeof(matches));
343 while((a = acl_get( a, &count, op, e, desc, val,
344 MAXREMATCHES, matches, state )) != NULL)
348 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
349 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
350 (int)matches[i].rm_so, (int)matches[i].rm_eo );
351 if( matches[i].rm_so <= matches[0].rm_eo ) {
353 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
354 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
357 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
361 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
362 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
363 ret = state->as_result;
366 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
371 control = acl_mask( a, &mask, op,
372 e, desc, val, MAXREMATCHES, matches, count, state );
374 if ( control != ACL_BREAK ) {
378 memset(matches, '\0', sizeof(matches));
381 if ( ACL_IS_INVALID( mask ) ) {
382 Debug( LDAP_DEBUG_ACL,
383 "=> access_allowed: \"%s\" (%s) invalid!\n",
387 } else if ( control == ACL_BREAK ) {
388 Debug( LDAP_DEBUG_ACL,
389 "=> access_allowed: no more rules\n", 0, 0, 0);
394 Debug( LDAP_DEBUG_ACL,
395 "=> access_allowed: %s access %s by %s\n",
396 access2str( access ),
397 ACL_GRANT(mask, access) ? "granted" : "denied",
398 accessmask2str( mask, accessmaskbuf, 1 ) );
400 ret = ACL_GRANT(mask, access);
403 if( state != NULL ) {
404 /* If not value-dependent, save ACL in case of more attrs */
405 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) ) {
406 state->as_vi_acl = a;
407 state->as_result = ret;
409 state->as_recorded |= ACL_STATE_RECORDED;
411 if (be_null) op->o_bd = NULL;
412 if ( maskp ) *maskp = mask;
418 * acl_get - return the acl applicable to entry e, attribute
419 * attr. the acl returned is suitable for use in subsequent calls to
420 * acl_access_allowed().
423 static AccessControl *
429 AttributeDescription *desc,
433 AccessControlState *state )
440 assert( count != NULL );
441 assert( desc != NULL );
443 attr = desc->ad_cname.bv_val;
445 assert( attr != NULL );
448 if( op->o_bd == NULL ) {
449 a = frontendDB->be_acl;
451 a = op->o_bd->be_acl;
462 dnlen = e->e_nname.bv_len;
464 for ( ; a != NULL; a = a->acl_next ) {
467 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
468 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
469 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
470 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
471 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
475 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
476 *count, a->acl_dn_pat.bv_val, 0 );
477 patlen = a->acl_dn_pat.bv_len;
478 if ( dnlen < patlen )
481 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
482 /* base dn -- entire object DN must match */
483 if ( dnlen != patlen )
486 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
487 int rdnlen = -1, sep = 0;
489 if ( dnlen <= patlen )
493 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
498 rdnlen = dn_rdnlen( NULL, &e->e_nname );
499 if ( rdnlen != dnlen - patlen - sep )
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 )
517 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
521 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
522 matches[0].rm_so = matches[0].rm_eo = -1;
526 /* Is this ACL only for a specific value? */
527 if ( a->acl_attrval.bv_len ) {
532 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
533 state->as_recorded |= ACL_STATE_RECORDED_VD;
534 state->as_vd_acl = prev;
535 state->as_vd_acl_count = *count;
536 state->as_vd_access = a->acl_access;
537 state->as_vd_access_count = 1;
538 ACL_INVALIDATE( state->as_vd_acl_mask );
541 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
542 Debug( LDAP_DEBUG_ACL,
543 "acl_get: valpat %s\n",
544 a->acl_attrval.bv_val, 0, 0 );
545 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
553 Debug( LDAP_DEBUG_ACL,
555 a->acl_attrval.bv_val, 0, 0 );
557 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
558 if (value_match( &match, desc,
559 desc->ad_type->sat_equality, 0,
560 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
567 patlen = a->acl_attrval.bv_len;
568 vdnlen = val->bv_len;
570 if ( vdnlen < patlen )
573 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
574 if ( vdnlen > patlen )
577 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
580 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
583 rdnlen = dn_rdnlen( NULL, val );
584 if ( rdnlen != vdnlen - patlen - 1 )
587 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
588 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
591 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
592 if ( vdnlen <= patlen )
595 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
599 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
605 if ( a->acl_filter != NULL ) {
606 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
607 if ( rc != LDAP_COMPARE_TRUE ) {
612 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
617 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
622 * Record value-dependent access control state
624 #define ACL_RECORD_VALUE_STATE do { \
625 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
626 state->as_recorded |= ACL_STATE_RECORDED_VD; \
627 state->as_vd_acl = a; \
628 AC_MEMCPY( state->as_vd_acl_matches, matches, \
629 sizeof( state->as_vd_acl_matches )) ; \
630 state->as_vd_acl_count = count; \
631 state->as_vd_access = b; \
632 state->as_vd_access_count = i; \
637 * acl_mask - modifies mask based upon the given acl and the
638 * requested access to entry e, attribute attr, value val. if val
639 * is null, access to the whole attribute is assumed (all values).
641 * returns 0 access NOT allowed
645 static slap_control_t
651 AttributeDescription *desc,
656 AccessControlState *state )
658 int i, odnlen, patlen;
661 char accessmaskbuf[ACCESSMASK_MAXLEN];
662 #if !defined( SLAP_DYNACL ) && defined( SLAPD_ACI_ENABLED )
663 char accessmaskbuf1[ACCESSMASK_MAXLEN];
664 #endif /* SLAPD_ACI_ENABLED */
669 assert( mask != NULL );
670 assert( desc != NULL );
672 attr = desc->ad_cname.bv_val;
674 assert( attr != NULL );
676 Debug( LDAP_DEBUG_ACL,
677 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
680 Debug( LDAP_DEBUG_ACL,
681 "=> acl_mask: to %s by \"%s\", (%s) \n",
682 val ? "value" : "all values",
683 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
684 accessmask2str( *mask, accessmaskbuf, 1) );
687 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
688 && state->as_vd_acl == a )
690 b = state->as_vd_access;
691 i = state->as_vd_access_count;
698 for ( ; b != NULL; b = b->a_next, i++ ) {
699 slap_mask_t oldmask, modmask;
701 ACL_INVALIDATE( modmask );
703 /* AND <who> clauses */
704 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
705 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
706 b->a_dn_pat.bv_val, 0, 0);
708 * if access applies to the entry itself, and the
709 * user is bound as somebody in the same namespace as
710 * the entry, OR the given dn matches the dn pattern
713 * NOTE: styles "anonymous", "users" and "self"
714 * have been moved to enum slap_style_t, whose
715 * value is set in a_dn_style; however, the string
716 * is maintaned in a_dn_pat.
718 if ( b->a_dn_style == ACL_STYLE_ANONYMOUS ) {
719 if ( !BER_BVISEMPTY( &op->o_ndn ) ) {
723 } else if ( b->a_dn_style == ACL_STYLE_USERS ) {
724 if ( BER_BVISEMPTY( &op->o_ndn ) ) {
728 } else if ( b->a_dn_style == ACL_STYLE_SELF ) {
729 struct berval ndn, selfndn;
732 if ( BER_BVISEMPTY( &op->o_ndn ) || BER_BVISNULL( &e->e_nname ) ) {
736 level = b->a_dn_self_level;
744 selfndn = e->e_nname;
747 for ( ; level > 0; level-- ) {
748 if ( BER_BVISEMPTY( &ndn ) ) {
751 dnParent( &ndn, &ndn );
754 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
759 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
760 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
762 regmatch_t tmp_matches[2],
763 *tmp_matchesp = tmp_matches;
767 switch ( a->acl_dn_style ) {
768 case ACL_STYLE_REGEX:
769 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
770 tmp_matchesp = matches;
774 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
777 tmp_matches[0].rm_so = 0;
778 tmp_matches[0].rm_eo = e->e_nname.bv_len;
783 case ACL_STYLE_SUBTREE:
784 case ACL_STYLE_CHILDREN:
785 tmp_matches[0].rm_so = 0;
786 tmp_matches[0].rm_eo = e->e_nname.bv_len;
787 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
788 tmp_matches[1].rm_eo = e->e_nname.bv_len;
802 if ( !regex_matches( &b->a_dn_pat,
803 op->o_ndn.bv_val, e->e_ndn,
804 tmp_nmatch, tmp_matchesp ) )
814 if ( e->e_dn == NULL )
817 if ( b->a_dn_expand ) {
819 char buf[ACL_BUF_SIZE];
822 regmatch_t tmp_matches[2],
823 *tmp_matchesp = tmp_matches;
827 bv.bv_len = sizeof( buf ) - 1;
830 switch ( a->acl_dn_style ) {
831 case ACL_STYLE_REGEX:
832 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
833 tmp_matchesp = matches;
837 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
840 tmp_matches[0].rm_so = 0;
841 tmp_matches[0].rm_eo = e->e_nname.bv_len;
846 case ACL_STYLE_SUBTREE:
847 case ACL_STYLE_CHILDREN:
848 tmp_matches[0].rm_so = 0;
849 tmp_matches[0].rm_eo = e->e_nname.bv_len;
850 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
851 tmp_matches[1].rm_eo = e->e_nname.bv_len;
865 if ( string_expand( &bv, &b->a_dn_pat,
867 tmp_nmatch, tmp_matchesp ) )
872 if ( dnNormalize(0, NULL, NULL, &bv,
873 &pat, op->o_tmpmemctx )
876 /* did not expand to a valid dn */
885 odnlen = op->o_ndn.bv_len;
886 if ( odnlen < patlen ) {
887 goto dn_match_cleanup;
891 if ( b->a_dn_style == ACL_STYLE_BASE ) {
892 /* base dn -- entire object DN must match */
893 if ( odnlen != patlen ) {
894 goto dn_match_cleanup;
897 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
900 if ( odnlen <= patlen ) {
901 goto dn_match_cleanup;
904 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
905 goto dn_match_cleanup;
908 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
909 if ( rdnlen != odnlen - patlen - 1 ) {
910 goto dn_match_cleanup;
913 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
914 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
915 goto dn_match_cleanup;
918 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
919 if ( odnlen <= patlen ) {
920 goto dn_match_cleanup;
923 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
924 goto dn_match_cleanup;
927 } else if ( b->a_dn_style == ACL_STYLE_LEVEL ) {
931 if ( odnlen <= patlen ) {
932 goto dn_match_cleanup;
935 if ( level > 0 && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) )
937 goto dn_match_cleanup;
940 level = b->a_dn_level;
942 for ( ; level > 0; level-- ) {
943 if ( BER_BVISEMPTY( &ndn ) ) {
944 goto dn_match_cleanup;
946 dnParent( &ndn, &ndn );
947 if ( ndn.bv_len < patlen ) {
948 goto dn_match_cleanup;
952 if ( ndn.bv_len != patlen ) {
953 goto dn_match_cleanup;
957 got_match = !strcmp( pat.bv_val, &op->o_ndn.bv_val[ odnlen - patlen ] );
960 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
961 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
970 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
971 if ( ! op->o_conn->c_listener ) {
974 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
975 b->a_sockurl_pat.bv_val, 0, 0 );
977 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
978 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
979 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
980 e->e_ndn, nmatch, matches ) )
985 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
987 char buf[ACL_BUF_SIZE];
989 bv.bv_len = sizeof( buf ) - 1;
991 if ( string_expand( &bv, &b->a_sockurl_pat,
992 e->e_ndn, nmatch, matches ) )
997 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1003 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1011 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1012 if ( !op->o_conn->c_peer_domain.bv_val ) {
1015 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1016 b->a_domain_pat.bv_val, 0, 0 );
1017 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1018 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1019 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1020 e->e_ndn, nmatch, matches ) )
1025 char buf[ACL_BUF_SIZE];
1027 struct berval cmp = op->o_conn->c_peer_domain;
1028 struct berval pat = b->a_domain_pat;
1030 if ( b->a_domain_expand ) {
1033 bv.bv_len = sizeof(buf) - 1;
1036 if ( string_expand(&bv, &b->a_domain_pat,
1037 e->e_ndn, nmatch, matches) )
1044 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1045 int offset = cmp.bv_len - pat.bv_len;
1050 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1054 /* trim the domain */
1055 cmp.bv_val = &cmp.bv_val[ offset ];
1056 cmp.bv_len -= offset;
1059 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1066 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1067 if ( !op->o_conn->c_peer_name.bv_val ) {
1070 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1071 b->a_peername_pat.bv_val, 0, 0 );
1072 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1073 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1074 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1075 e->e_ndn, nmatch, matches ) )
1081 /* try exact match */
1082 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1083 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1087 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1089 char buf[ACL_BUF_SIZE];
1091 bv.bv_len = sizeof( buf ) - 1;
1093 if ( string_expand( &bv, &b->a_peername_pat,
1094 e->e_ndn, nmatch, matches ) )
1099 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1103 /* extract IP and try exact match */
1104 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1106 char buf[] = "255.255.255.255";
1109 int port_number = -1;
1111 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1112 aci_bv_ip_eq.bv_val, aci_bv_ip_eq.bv_len ) != 0 )
1115 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_ip_eq.bv_len;
1116 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_ip_eq.bv_len;
1118 port = strrchr( ip.bv_val, ':' );
1122 ip.bv_len = port - ip.bv_val;
1124 port_number = strtol( port, &next, 10 );
1125 if ( next[0] != '\0' )
1129 /* the port check can be anticipated here */
1130 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1133 /* address longer than expected? */
1134 if ( ip.bv_len >= sizeof(buf) )
1137 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1138 buf[ ip.bv_len ] = '\0';
1140 addr = inet_addr( buf );
1142 /* unable to convert? */
1143 if ( addr == (unsigned long)(-1) )
1146 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1149 #ifdef LDAP_PF_LOCAL
1150 /* extract path and try exact match */
1151 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1154 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1155 aci_bv_path_eq.bv_val, aci_bv_path_eq.bv_len ) != 0 )
1158 path.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_path_eq.bv_len;
1159 path.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_path_eq.bv_len;
1161 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1164 #endif /* LDAP_PF_LOCAL */
1166 /* exact match (very unlikely...) */
1167 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1174 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1175 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1178 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1179 b->a_sockname_pat.bv_val, 0, 0 );
1180 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1181 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1182 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1183 e->e_ndn, nmatch, matches ) )
1188 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1190 char buf[ACL_BUF_SIZE];
1192 bv.bv_len = sizeof( buf ) - 1;
1194 if ( string_expand( &bv, &b->a_sockname_pat,
1195 e->e_ndn, nmatch, matches ) )
1200 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1205 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1212 if ( b->a_dn_at != NULL ) {
1217 const char *attr = b->a_dn_at->ad_cname.bv_val;
1219 assert( attr != NULL );
1221 if ( op->o_ndn.bv_len == 0 ) {
1225 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
1229 /* see if asker is listed in dnattr */
1230 for( at = attrs_find( e->e_attrs, b->a_dn_at );
1232 at = attrs_find( at->a_next, b->a_dn_at ) )
1234 if( value_find_ex( b->a_dn_at,
1235 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1236 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1238 &bv, op->o_tmpmemctx ) == 0 )
1247 /* have a dnattr match. if this is a self clause then
1248 * the target must also match the op dn.
1250 if ( b->a_dn_self ) {
1251 /* check if the target is an attribute. */
1252 if ( val == NULL ) continue;
1254 /* target is attribute, check if the attribute value
1257 rc = value_match( &match, b->a_dn_at,
1258 b->a_dn_at->ad_type->sat_equality, 0,
1260 /* on match error or no match, fail the ACL clause */
1261 if (rc != LDAP_SUCCESS || match != 0 )
1265 /* no dnattr match, check if this is a self clause */
1266 if ( ! b->a_dn_self )
1269 ACL_RECORD_VALUE_STATE;
1271 /* this is a self clause, check if the target is an
1277 /* target is attribute, check if the attribute value
1280 rc = value_match( &match, b->a_dn_at,
1281 b->a_dn_at->ad_type->sat_equality, 0,
1284 /* on match error or no match, fail the ACL clause */
1285 if (rc != LDAP_SUCCESS || match != 0 )
1290 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1292 struct berval ndn = BER_BVNULL;
1295 if ( op->o_ndn.bv_len == 0 ) {
1299 /* b->a_group is an unexpanded entry name, expanded it should be an
1300 * entry with objectclass group* and we test to see if odn is one of
1301 * the values in the attribute group
1303 /* see if asker is listed in dnattr */
1304 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1305 char buf[ACL_BUF_SIZE];
1307 regmatch_t tmp_matches[2],
1308 *tmp_matchesp = tmp_matches;
1310 bv.bv_len = sizeof(buf) - 1;
1315 switch ( a->acl_dn_style ) {
1316 case ACL_STYLE_REGEX:
1317 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1318 tmp_matchesp = matches;
1319 tmp_nmatch = nmatch;
1323 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1324 case ACL_STYLE_BASE:
1325 tmp_matches[0].rm_so = 0;
1326 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1331 case ACL_STYLE_SUBTREE:
1332 case ACL_STYLE_CHILDREN:
1333 tmp_matches[0].rm_so = 0;
1334 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1335 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1336 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1350 if ( string_expand( &bv, &b->a_group_pat,
1352 tmp_nmatch, tmp_matchesp ) )
1357 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1358 op->o_tmpmemctx ) != LDAP_SUCCESS )
1360 /* did not expand to a valid dn */
1367 bv = b->a_group_pat;
1370 rc = backend_group( op, e, &bv, &op->o_ndn,
1371 b->a_group_oc, b->a_group_at );
1374 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1382 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1384 char buf[ACL_BUF_SIZE];
1386 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1388 regmatch_t tmp_matches[2],
1389 *tmp_matchesp = tmp_matches;
1392 bv.bv_len = sizeof( buf ) - 1;
1397 switch ( a->acl_dn_style ) {
1398 case ACL_STYLE_REGEX:
1399 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1400 tmp_matchesp = matches;
1401 tmp_nmatch = nmatch;
1405 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1406 case ACL_STYLE_BASE:
1407 tmp_matches[0].rm_so = 0;
1408 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1413 case ACL_STYLE_SUBTREE:
1414 case ACL_STYLE_CHILDREN:
1415 tmp_matches[0].rm_so = 0;
1416 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1417 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1418 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1432 if ( string_expand( &bv, &b->a_set_pat,
1434 tmp_nmatch, tmp_matchesp ) )
1443 if ( aci_match_set( &bv, op, e, 0 ) == 0 ) {
1448 if ( b->a_authz.sai_ssf ) {
1449 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1450 b->a_authz.sai_ssf, op->o_ssf, 0 );
1451 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1456 if ( b->a_authz.sai_transport_ssf ) {
1457 Debug( LDAP_DEBUG_ACL,
1458 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1459 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1460 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1465 if ( b->a_authz.sai_tls_ssf ) {
1466 Debug( LDAP_DEBUG_ACL,
1467 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1468 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1469 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1474 if ( b->a_authz.sai_sasl_ssf ) {
1475 Debug( LDAP_DEBUG_ACL,
1476 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1477 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1478 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1484 if ( b->a_dynacl ) {
1486 slap_access_t tgrant, tdeny;
1488 /* this case works different from the others above.
1489 * since aci's themselves give permissions, we need
1490 * to first check b->a_access_mask, the ACL's access level.
1492 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1493 /* no ACIs in the root DSE */
1497 /* first check if the right being requested
1498 * is allowed by the ACL clause.
1500 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1504 /* start out with nothing granted, nothing denied */
1508 for ( da = b->a_dynacl; da; da = da->da_next ) {
1509 slap_access_t grant, deny;
1511 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1517 /* remove anything that the ACL clause does not allow */
1518 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1519 tdeny &= ACL_PRIV_MASK;
1521 /* see if we have anything to contribute */
1522 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1526 /* this could be improved by changing acl_mask so that it can deal with
1527 * by clauses that return grant/deny pairs. Right now, it does either
1528 * additive or subtractive rights, but not both at the same time. So,
1529 * we need to combine the grant/deny pair into a single rights mask in
1530 * a smart way: if either grant or deny is "empty", then we use the
1531 * opposite as is, otherwise we remove any denied rights from the grant
1532 * rights mask and construct an additive mask.
1534 if (ACL_IS_INVALID(tdeny)) {
1535 modmask = tgrant | ACL_PRIV_ADDITIVE;
1537 } else if (ACL_IS_INVALID(tgrant)) {
1538 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1541 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1545 #else /* !SLAP_DYNACL */
1547 #ifdef SLAPD_ACI_ENABLED
1548 if ( b->a_aci_at != NULL ) {
1550 slap_access_t grant, deny, tgrant, tdeny;
1551 struct berval parent_ndn;
1552 BerVarray bvals = NULL;
1555 /* this case works different from the others above.
1556 * since aci's themselves give permissions, we need
1557 * to first check b->a_access_mask, the ACL's access level.
1560 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1561 /* no ACIs in the root DSE */
1565 /* first check if the right being requested
1566 * is allowed by the ACL clause.
1568 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1571 /* start out with nothing granted, nothing denied */
1575 /* get the aci attribute */
1576 at = attr_find( e->e_attrs, b->a_aci_at );
1579 /* FIXME: this breaks acl caching;
1580 * see also ACL_RECORD_VALUE_STATE below */
1581 ACL_RECORD_VALUE_STATE;
1583 /* the aci is an multi-valued attribute. The
1584 * rights are determined by OR'ing the individual
1585 * rights given by the acis.
1587 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
1592 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0)
1598 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1599 accessmask2str(tgrant, accessmaskbuf, 1),
1600 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
1603 /* If the entry level aci didn't contain anything valid for the
1604 * current operation, climb up the tree and evaluate the
1605 * acis with scope set to subtree
1607 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
1608 dnParent( &e->e_nname, &parent_ndn );
1609 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
1610 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1611 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
1619 for( i = 0; bvals[i].bv_val != NULL; i++){
1621 /* FIXME: this breaks acl caching;
1622 * see also ACL_RECORD_VALUE_STATE above */
1623 ACL_RECORD_VALUE_STATE;
1625 if (aci_mask(op, e, desc, val, &bvals[i],
1627 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
1631 /* evaluation stops as soon as either a "deny" or a
1632 * "grant" directive matches.
1634 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1638 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1639 accessmask2str(tgrant, accessmaskbuf, 1),
1640 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
1644 case LDAP_NO_SUCH_ATTRIBUTE:
1645 /* just go on if the aci-Attribute is not present in
1648 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1652 case LDAP_NO_SUCH_OBJECT:
1653 /* We have reached the base object */
1654 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1665 dnParent( &parent_ndn, &parent_ndn );
1670 /* remove anything that the ACL clause does not allow */
1671 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1672 tdeny &= ACL_PRIV_MASK;
1674 /* see if we have anything to contribute */
1675 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1679 /* this could be improved by changing acl_mask so that it can deal with
1680 * by clauses that return grant/deny pairs. Right now, it does either
1681 * additive or subtractive rights, but not both at the same time. So,
1682 * we need to combine the grant/deny pair into a single rights mask in
1683 * a smart way: if either grant or deny is "empty", then we use the
1684 * opposite as is, otherwise we remove any denied rights from the grant
1685 * rights mask and construct an additive mask.
1687 if (ACL_IS_INVALID(tdeny)) {
1688 modmask = tgrant | ACL_PRIV_ADDITIVE;
1690 } else if (ACL_IS_INVALID(tgrant)) {
1691 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1694 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1698 #endif /* SLAPD_ACI_ENABLED */
1699 #endif /* !SLAP_DYNACL */
1701 modmask = b->a_access_mask;
1704 Debug( LDAP_DEBUG_ACL,
1705 "<= acl_mask: [%d] applying %s (%s)\n",
1706 i, accessmask2str( modmask, accessmaskbuf, 1 ),
1707 b->a_type == ACL_CONTINUE
1709 : b->a_type == ACL_BREAK
1715 if( ACL_IS_ADDITIVE(modmask) ) {
1717 ACL_PRIV_SET( *mask, modmask );
1720 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1722 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1723 /* substract privs */
1724 ACL_PRIV_CLR( *mask, modmask );
1727 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1734 Debug( LDAP_DEBUG_ACL,
1735 "<= acl_mask: [%d] mask: %s\n",
1736 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
1738 if( b->a_type == ACL_CONTINUE ) {
1741 } else if ( b->a_type == ACL_BREAK ) {
1749 /* implicit "by * none" clause */
1752 Debug( LDAP_DEBUG_ACL,
1753 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1754 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
1759 * acl_check_modlist - check access control on the given entry to see if
1760 * it allows the given modifications by the user associated with op.
1761 * returns 1 if mods allowed ok
1762 * 0 mods not allowed
1769 Modifications *mlist
1773 AccessControlState state = ACL_STATE_INIT;
1776 int ret = 1; /* default is access allowed */
1780 be = LDAP_STAILQ_FIRST(&backendDB);
1784 assert( be != NULL );
1786 /* short circuit root database access */
1787 if ( be_isroot( op ) ) {
1788 Debug( LDAP_DEBUG_ACL,
1789 "<= acl_access_allowed: granted to database root\n",
1794 /* use backend default access if no backend acls */
1795 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1796 Debug( LDAP_DEBUG_ACL,
1797 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1798 access2str( ACL_WRITE ),
1799 op->o_bd->be_dfltaccess >= ACL_WRITE
1800 ? "granted" : "denied",
1802 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
1806 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1808 * no-user-modification operational attributes are ignored
1809 * by ACL_WRITE checking as any found here are not provided
1812 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1813 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1814 " modify access granted\n",
1815 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1819 switch ( mlist->sml_op ) {
1820 case LDAP_MOD_REPLACE:
1822 * We must check both permission to delete the whole
1823 * attribute and permission to add the specific attributes.
1824 * This prevents abuse from selfwriters.
1826 if ( ! access_allowed( op, e,
1827 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1833 if ( mlist->sml_values == NULL ) break;
1835 /* fall thru to check value to add */
1838 assert( mlist->sml_values != NULL );
1840 for ( bv = mlist->sml_nvalues
1841 ? mlist->sml_nvalues : mlist->sml_values;
1842 bv->bv_val != NULL; bv++ )
1844 if ( ! access_allowed( op, e,
1845 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1853 case LDAP_MOD_DELETE:
1854 if ( mlist->sml_values == NULL ) {
1855 if ( ! access_allowed( op, e,
1856 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1863 for ( bv = mlist->sml_nvalues
1864 ? mlist->sml_nvalues : mlist->sml_values;
1865 bv->bv_val != NULL; bv++ )
1867 if ( ! access_allowed( op, e,
1868 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1876 case SLAP_MOD_SOFTADD:
1877 /* allow adding attribute via modrdn thru */
1889 if (be_null) op->o_bd = NULL;
1895 struct berval *list,
1908 while ( len >= 0 && --ix >= 0 ) {
1909 while ( --len >= 0 && *p++ != sep )
1912 while ( len >= 0 && *p == ' ' ) {
1925 while ( --len >= 0 && *p != sep ) {
1929 while ( bv->bv_len > 0 && *--p == ' ' ) {
1936 typedef struct aci_set_gather_t {
1942 aci_set_cb_gather( Operation *op, SlapReply *rs )
1944 aci_set_gather_t *p = (aci_set_gather_t *)op->o_callback->sc_private;
1946 if ( rs->sr_type == REP_SEARCH ) {
1947 BerValue bvals[ 2 ];
1948 BerVarray bvalsp = NULL;
1951 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
1952 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
1954 if ( desc == slap_schema.si_ad_entryDN ) {
1956 bvals[ 0 ] = rs->sr_entry->e_nname;
1957 BER_BVZERO( &bvals[ 1 ] );
1962 a = attr_find( rs->sr_entry->e_attrs, desc );
1966 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
1969 bvalsp = a->a_nvals;
1975 p->bvals = slap_set_join( p->cookie, p->bvals,
1976 ( '|' | SLAP_SET_RREF ), bvalsp );
1980 assert( rs->sr_type == REP_RESULT );
1987 aci_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
1989 AciSetCookie *cp = (AciSetCookie *)cookie;
1991 LDAPURLDesc *ludp = NULL;
1992 Operation op2 = { 0 };
1993 SlapReply rs = {REP_RESULT};
1994 AttributeName anlist[ 2 ], *anlistp = NULL;
1996 slap_callback cb = { NULL, aci_set_cb_gather, NULL, NULL };
1997 aci_set_gather_t p = { 0 };
1998 const char *text = NULL;
1999 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2001 /* this routine needs to return the bervals instead of
2002 * plain strings, since syntax is not known. It should
2003 * also return the syntax or some "comparison cookie".
2005 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2006 return aci_set_gather2( cookie, name, desc );
2009 rc = ldap_url_parse( name->bv_val, &ludp );
2010 if ( rc != LDAP_URL_SUCCESS ) {
2011 rc = LDAP_PROTOCOL_ERROR;
2015 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2017 /* host part must be empty */
2018 /* extensions parts must be empty */
2019 rc = LDAP_PROTOCOL_ERROR;
2023 /* Grab the searchbase and see if an appropriate database can be found */
2024 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2025 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2026 &op2.o_req_ndn, cp->op->o_tmpmemctx );
2027 BER_BVZERO( &op2.o_req_dn );
2028 if ( rc != LDAP_SUCCESS ) {
2032 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2033 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2034 rc = LDAP_NO_SUCH_OBJECT;
2038 /* Grab the filter */
2039 if ( ludp->lud_filter ) {
2040 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2041 cp->op->o_tmpmemctx );
2044 op2.ors_filterstr = defaultFilter_bv;
2047 op2.ors_filter = str2filter_x( cp->op, op2.ors_filterstr.bv_val );
2048 if ( op2.ors_filter == NULL ) {
2049 rc = LDAP_PROTOCOL_ERROR;
2053 /* Grab the scope */
2054 op2.ors_scope = ludp->lud_scope;
2056 /* Grap the attributes */
2057 if ( ludp->lud_attrs ) {
2058 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2061 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2062 cp->op->o_tmpmemctx );
2064 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2065 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2066 anlistp[ nattrs ].an_desc = NULL;
2067 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2068 &anlistp[ nattrs ].an_desc, &text );
2069 if ( rc != LDAP_SUCCESS ) {
2078 anlistp[ nattrs ].an_name = desc->ad_cname;
2079 anlistp[ nattrs ].an_desc = desc;
2081 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2085 op2.o_hdr = cp->op->o_hdr;
2086 op2.o_tag = LDAP_REQ_SEARCH;
2087 op2.o_ndn = op2.o_bd->be_rootndn;
2088 op2.o_callback = &cb;
2089 op2.o_time = slap_get_time();
2090 op2.o_do_not_cache = 1;
2091 op2.o_is_auth_check = 0;
2092 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->op->o_tmpmemctx );
2093 op2.ors_slimit = SLAP_NO_LIMIT;
2094 op2.ors_tlimit = SLAP_NO_LIMIT;
2095 op2.ors_attrs = anlistp;
2096 op2.ors_attrsonly = 0;
2097 op2.o_private = cp->op->o_private;
2101 rc = op2.o_bd->be_search( &op2, &rs );
2107 if ( op2.ors_filter ) {
2108 filter_free_x( cp->op, op2.ors_filter );
2110 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2111 slap_sl_free( op2.o_req_ndn.bv_val, cp->op->o_tmpmemctx );
2113 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2114 slap_sl_free( op2.o_req_dn.bv_val, cp->op->o_tmpmemctx );
2117 ldap_free_urldesc( ludp );
2119 if ( anlistp && anlistp != anlist ) {
2120 slap_sl_free( anlistp, cp->op->o_tmpmemctx );
2127 aci_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2129 AciSetCookie *cp = (AciSetCookie *)cookie;
2130 BerVarray bvals = NULL;
2134 /* this routine needs to return the bervals instead of
2135 * plain strings, since syntax is not known. It should
2136 * also return the syntax or some "comparison cookie".
2138 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
2139 if ( rc == LDAP_SUCCESS ) {
2140 if ( desc == slap_schema.si_ad_entryDN ) {
2141 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2142 cp->op->o_tmpmemctx );
2144 BER_BVZERO( &bvals[ 1 ] );
2148 backend_attribute( cp->op,
2149 cp->e, &ndn, desc, &bvals, ACL_NONE );
2152 if ( !BER_BVISNULL( &ndn ) ) {
2153 slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
2162 struct berval *subj,
2168 struct berval set = BER_BVNULL;
2170 AciSetCookie cookie;
2172 if ( setref == 0 ) {
2173 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2176 struct berval subjdn, ndn = BER_BVNULL;
2177 struct berval setat;
2180 AttributeDescription *desc = NULL;
2182 /* format of string is "entry/setAttrName" */
2183 if ( aci_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2187 if ( aci_get_part( subj, 1, '/', &setat ) < 0 ) {
2188 setat = aci_bv_set_attr;
2192 * NOTE: dnNormalize honors the ber_len field
2193 * as the length of the dn to be normalized
2195 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2196 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2198 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2199 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2203 BER_BVZERO( &bvals[0] );
2204 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2206 bvals[0].bv_val = bvals[i-1].bv_val;
2207 BER_BVZERO( &bvals[i-1] );
2209 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2210 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2215 if ( !BER_BVISNULL( &set ) ) {
2218 rc = ( slap_set_filter( aci_set_gather, (SetCookie *)&cookie, &set,
2219 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2220 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2226 #ifdef SLAPD_ACI_ENABLED
2228 aci_list_map_rights(
2229 struct berval *list )
2236 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2239 switch (*bv.bv_val) {
2241 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2244 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
2245 * the right 's' to mean "set", but in the examples states
2246 * that the right 's' means "search". The latter definition
2249 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2252 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2255 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2258 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
2259 * define any equivalent to the AUTH right, so I've just used
2262 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2274 struct berval *list,
2275 const struct berval *attr,
2276 struct berval *val )
2278 struct berval bv, left, right;
2281 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2282 if (aci_get_part(&bv, 0, '=', &left) < 0
2283 || aci_get_part(&bv, 1, '=', &right) < 0)
2285 if (ber_bvstrcasecmp(attr, &bv) == 0)
2287 } else if (val == NULL) {
2288 if (ber_bvstrcasecmp(attr, &left) == 0)
2291 if (ber_bvstrcasecmp(attr, &left) == 0) {
2292 /* this is experimental code that implements a
2293 * simple (prefix) match of the attribute value.
2294 * the ACI draft does not provide for aci's that
2295 * apply to specific values, but it would be
2296 * nice to have. If the <attr> part of an aci's
2297 * rights list is of the form <attr>=<value>,
2298 * that means the aci applies only to attrs with
2299 * the given value. Furthermore, if the attr is
2300 * of the form <attr>=<value>*, then <value> is
2301 * treated as a prefix, and the aci applies to
2302 * any value with that prefix.
2304 * Ideally, this would allow r.e. matches.
2306 if (aci_get_part(&right, 0, '*', &left) < 0
2307 || right.bv_len <= left.bv_len)
2309 if (ber_bvstrcasecmp(val, &right) == 0)
2311 } else if (val->bv_len >= left.bv_len) {
2312 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
2321 static slap_access_t
2322 aci_list_get_attr_rights(
2323 struct berval *list,
2324 const struct berval *attr,
2325 struct berval *val )
2331 /* loop through each rights/attr pair, skip first part (action) */
2333 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
2334 if (aci_list_has_attr(&bv, attr, val) == 0)
2336 if (aci_get_part(list, i, ';', &bv) < 0)
2338 mask |= aci_list_map_rights(&bv);
2344 aci_list_get_rights(
2345 struct berval *list,
2346 const struct berval *attr,
2348 slap_access_t *grant,
2349 slap_access_t *deny )
2351 struct berval perm, actn;
2352 slap_access_t *mask;
2355 if (attr == NULL || attr->bv_len == 0
2356 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
2357 attr = &aci_bv_br_entry;
2363 /* loop through each permissions clause */
2364 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
2365 if (aci_get_part(&perm, 0, ';', &actn) < 0)
2367 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
2369 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
2376 *mask |= aci_list_get_attr_rights(&perm, attr, val);
2377 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
2384 struct berval *subj,
2385 struct berval *defgrpoc,
2386 struct berval *defgrpat,
2393 struct berval subjdn;
2394 struct berval grpoc;
2395 struct berval grpat;
2396 ObjectClass *grp_oc = NULL;
2397 AttributeDescription *grp_ad = NULL;
2401 /* format of string is "group/objectClassValue/groupAttrName" */
2402 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
2406 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
2410 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
2414 rc = slap_bv2ad( &grpat, &grp_ad, &text );
2415 if( rc != LDAP_SUCCESS ) {
2421 grp_oc = oc_bvfind( &grpoc );
2423 if (grp_oc != NULL && grp_ad != NULL ) {
2424 char buf[ACL_BUF_SIZE];
2425 struct berval bv, ndn;
2426 bv.bv_len = sizeof( buf ) - 1;
2427 bv.bv_val = (char *)&buf;
2428 if ( string_expand(&bv, &subjdn,
2429 e->e_ndn, nmatch, matches) )
2434 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
2435 rc = ( backend_group( op, e, &ndn, &op->o_ndn,
2436 grp_oc, grp_ad ) == 0 );
2437 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2449 AttributeDescription *desc,
2453 regmatch_t *matches,
2454 slap_access_t *grant,
2455 slap_access_t *deny,
2456 slap_aci_scope_t asserted_scope
2459 struct berval bv, scope, perms, type, sdn;
2463 assert( !BER_BVISNULL( &desc->ad_cname ) );
2465 /* parse an aci of the form:
2466 oid # scope # action;rights;attr;rights;attr
2467 $ action;rights;attr;rights;attr # type # subject
2469 [NOTE: the following comment is very outdated,
2470 as the draft version it refers to (Ando, 2004-11-20)].
2472 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
2473 a full description of the format for this attribute.
2474 Differences: "this" in the draft is "self" here, and
2475 "self" and "public" is in the position of type.
2477 <scope> = {entry|children|subtree}
2478 <type> = {public|users|access-id|subtree|onelevel|children|
2479 self|dnattr|group|role|set|set-ref}
2481 This routine now supports scope={ENTRY,CHILDREN}
2483 - ENTRY applies to "entry" and "subtree";
2484 - CHILDREN aplies to "children" and "subtree"
2487 /* check that the aci has all 5 components */
2488 if ( aci_get_part( aci, 4, '#', NULL ) < 0 ) {
2492 /* check that the aci family is supported */
2493 if ( aci_get_part( aci, 0, '#', &bv ) < 0 ) {
2497 /* check that the scope matches */
2498 if ( aci_get_part( aci, 1, '#', &scope ) < 0 ) {
2502 /* note: scope can be either ENTRY or CHILDREN;
2503 * they respectively match "entry" and "children" in bv
2504 * both match "subtree" */
2505 switch ( asserted_scope ) {
2506 case SLAP_ACI_SCOPE_ENTRY:
2507 if ( ber_bvstrcasecmp( &scope, &aci_bv_entry ) != 0
2508 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2514 case SLAP_ACI_SCOPE_CHILDREN:
2515 if ( ber_bvstrcasecmp( &scope, &aci_bv_children ) != 0
2516 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2526 /* get the list of permissions clauses, bail if empty */
2527 if ( aci_get_part( aci, 2, '#', &perms ) <= 0 ) {
2531 /* check if any permissions allow desired access */
2532 if ( aci_list_get_rights( &perms, &desc->ad_cname, val, grant, deny ) == 0 ) {
2536 /* see if we have a DN match */
2537 if ( aci_get_part( aci, 3, '#', &type ) < 0 ) {
2541 /* see if we have a public (i.e. anonymous) access */
2542 if ( ber_bvstrcasecmp( &aci_bv_public, &type ) == 0 ) {
2546 /* otherwise require an identity */
2547 if ( BER_BVISNULL( &op->o_ndn ) || BER_BVISEMPTY( &op->o_ndn ) ) {
2551 /* see if we have a users access */
2552 if ( ber_bvstrcasecmp( &aci_bv_users, &type ) == 0 ) {
2556 /* NOTE: this may fail if a DN contains a valid '#' (unescaped);
2557 * just grab all the berval up to its end (ITS#3303).
2558 * NOTE: the problem could be solved by providing the DN with
2559 * the embedded '#' encoded as hexpairs: "cn=Foo#Bar" would
2560 * become "cn=Foo\23Bar" and be safely used by aci_mask(). */
2562 if ( aci_get_part( aci, 4, '#', &sdn ) < 0 ) {
2566 sdn.bv_val = type.bv_val + type.bv_len + STRLENOF( "#" );
2567 sdn.bv_len = aci->bv_len - ( sdn.bv_val - aci->bv_val );
2569 if ( ber_bvstrcasecmp( &aci_bv_access_id, &type ) == 0 ) {
2572 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2573 if ( rc != LDAP_SUCCESS ) {
2577 if ( dn_match( &op->o_ndn, &ndn ) ) {
2580 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2584 } else if ( ber_bvstrcasecmp( &aci_bv_subtree, &type ) == 0 ) {
2587 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2588 if ( rc != LDAP_SUCCESS ) {
2592 if ( dnIsSuffix( &op->o_ndn, &ndn ) ) {
2595 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2599 } else if ( ber_bvstrcasecmp( &aci_bv_onelevel, &type ) == 0 ) {
2600 struct berval ndn, pndn;
2602 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2603 if ( rc != LDAP_SUCCESS ) {
2607 dnParent( &ndn, &pndn );
2609 if ( dn_match( &op->o_ndn, &pndn ) ) {
2612 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2616 } else if ( ber_bvstrcasecmp( &aci_bv_children, &type ) == 0 ) {
2619 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2620 if ( rc != LDAP_SUCCESS ) {
2624 if ( !dn_match( &op->o_ndn, &ndn )
2625 && dnIsSuffix( &op->o_ndn, &ndn ) )
2629 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2633 } else if ( ber_bvstrcasecmp( &aci_bv_self, &type ) == 0 ) {
2634 if ( dn_match( &op->o_ndn, &e->e_nname ) ) {
2638 } else if ( ber_bvstrcasecmp( &aci_bv_dnattr, &type ) == 0 ) {
2640 AttributeDescription *ad = NULL;
2643 rc = slap_bv2ad( &sdn, &ad, &text );
2645 if( rc != LDAP_SUCCESS ) {
2651 for ( at = attrs_find( e->e_attrs, ad );
2653 at = attrs_find( at->a_next, ad ) )
2655 if ( value_find_ex( ad,
2656 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
2657 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
2659 &op->o_ndn, op->o_tmpmemctx ) == 0 )
2668 } else if ( ber_bvstrcasecmp( &aci_bv_group, &type ) == 0 ) {
2669 if ( aci_group_member( &sdn, &aci_bv_group_class,
2670 &aci_bv_group_attr, op, e, nmatch, matches ) )
2675 } else if ( ber_bvstrcasecmp( &aci_bv_role, &type ) == 0 ) {
2676 if ( aci_group_member( &sdn, &aci_bv_role_class,
2677 &aci_bv_role_attr, op, e, nmatch, matches ) )
2682 } else if ( ber_bvstrcasecmp( &aci_bv_set, &type ) == 0 ) {
2683 if ( aci_match_set( &sdn, op, e, 0 ) ) {
2687 } else if ( ber_bvstrcasecmp( &aci_bv_set_ref, &type ) == 0 ) {
2688 if ( aci_match_set( &sdn, op, e, 1 ) ) {
2698 dynacl_aci_parse( const char *fname, int lineno, slap_style_t sty, const char *right, void **privp )
2700 AttributeDescription *ad = NULL;
2701 const char *text = NULL;
2703 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
2704 fprintf( stderr, "%s: line %d: "
2705 "inappropriate style \"%s\" in \"aci\" by clause\n",
2706 fname, lineno, sty );
2710 if ( right != NULL && *right != '\0' ) {
2711 if ( slap_str2ad( right, &ad, &text ) != LDAP_SUCCESS ) {
2713 "%s: line %d: aci \"%s\": %s\n",
2714 fname, lineno, right, text );
2719 ad = slap_schema.si_ad_aci;
2722 if ( !is_at_syntax( ad->ad_type, SLAPD_ACI_SYNTAX) ) {
2723 fprintf( stderr, "%s: line %d: "
2724 "aci \"%s\": inappropriate syntax: %s\n",
2725 fname, lineno, right,
2726 ad->ad_type->sat_syntax_oid );
2730 *privp = (void *)ad;
2736 dynacl_aci_unparse( void *priv, struct berval *bv )
2738 AttributeDescription *ad = ( AttributeDescription * )priv;
2743 bv->bv_val = ch_malloc( STRLENOF(" aci=") + ad->ad_cname.bv_len + 1 );
2744 ptr = lutil_strcopy( bv->bv_val, " aci=" );
2745 ptr = lutil_strcopy( ptr, ad->ad_cname.bv_val );
2746 bv->bv_len = ptr - bv->bv_val;
2757 AttributeDescription *desc,
2760 regmatch_t *matches,
2761 slap_access_t *grantp,
2762 slap_access_t *denyp )
2764 AttributeDescription *ad = ( AttributeDescription * )priv;
2766 slap_access_t tgrant, tdeny, grant, deny;
2768 char accessmaskbuf[ACCESSMASK_MAXLEN];
2769 char accessmaskbuf1[ACCESSMASK_MAXLEN];
2770 #endif /* LDAP_DEBUG */
2772 /* start out with nothing granted, nothing denied */
2776 /* get the aci attribute */
2777 at = attr_find( e->e_attrs, ad );
2781 /* the aci is an multi-valued attribute. The
2782 * rights are determined by OR'ing the individual
2783 * rights given by the acis.
2785 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2786 if ( aci_mask( op, e, desc, val, &at->a_nvals[i],
2787 nmatch, matches, &grant, &deny,
2788 SLAP_ACI_SCOPE_ENTRY ) != 0 )
2795 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2796 accessmask2str( tgrant, accessmaskbuf, 1 ),
2797 accessmask2str( tdeny, accessmaskbuf1, 1 ), 0 );
2800 /* If the entry level aci didn't contain anything valid for the
2801 * current operation, climb up the tree and evaluate the
2802 * acis with scope set to subtree
2804 if ( tgrant == ACL_PRIV_NONE && tdeny == ACL_PRIV_NONE ) {
2805 struct berval parent_ndn;
2808 /* to solve the chicken'n'egg problem of accessing
2809 * the OpenLDAPaci attribute, the direct access
2810 * to the entry's attribute is unchecked; however,
2811 * further accesses to OpenLDAPaci values in the
2812 * ancestors occur through backend_attribute(), i.e.
2813 * with the identity of the operation, requiring
2814 * further access checking. For uniformity, this
2815 * makes further requests occur as the rootdn, if
2816 * any, i.e. searching for the OpenLDAPaci attribute
2817 * is considered an internal search. If this is not
2818 * acceptable, then the same check needs be performed
2819 * when accessing the entry's attribute. */
2820 Operation op2 = *op;
2822 if ( !BER_BVISNULL( &op->o_bd->be_rootndn ) ) {
2823 op2.o_dn = op->o_bd->be_rootdn;
2824 op2.o_ndn = op->o_bd->be_rootndn;
2828 dnParent( &e->e_nname, &parent_ndn );
2829 while ( !BER_BVISEMPTY( &parent_ndn ) ){
2831 BerVarray bvals = NULL;
2834 Debug( LDAP_DEBUG_ACL, "checking ACI of \"%s\"\n", parent_ndn.bv_val, 0, 0 );
2835 ret = backend_attribute( &op2, NULL, &parent_ndn, ad, &bvals, ACL_AUTH );
2844 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++) {
2845 if ( aci_mask( op, e, desc, val,
2849 SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2853 /* evaluation stops as soon as either a "deny" or a
2854 * "grant" directive matches.
2856 if ( tgrant != ACL_PRIV_NONE || tdeny != ACL_PRIV_NONE ) {
2860 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2861 accessmask2str( tgrant, accessmaskbuf, 1 ),
2862 accessmask2str( tdeny, accessmaskbuf1, 1 ), 0 );
2866 case LDAP_NO_SUCH_ATTRIBUTE:
2867 /* just go on if the aci-Attribute is not present in
2870 Debug( LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0 );
2874 case LDAP_NO_SUCH_OBJECT:
2875 /* We have reached the base object */
2876 Debug( LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0 );
2888 dnParent( &parent_ndn, &parent_ndn );
2898 /* need to register this at some point */
2899 static slap_dynacl_t dynacl_aci = {
2909 #endif /* SLAP_DYNACL */
2911 #endif /* SLAPD_ACI_ENABLED */
2916 * dynamic ACL infrastructure
2918 static slap_dynacl_t *da_list = NULL;
2921 slap_dynacl_register( slap_dynacl_t *da )
2925 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2926 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2931 if ( tmp != NULL ) {
2935 if ( da->da_mask == NULL ) {
2939 da->da_private = NULL;
2940 da->da_next = da_list;
2946 static slap_dynacl_t *
2947 slap_dynacl_next( slap_dynacl_t *da )
2956 slap_dynacl_get( const char *name )
2960 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2961 if ( strcasecmp( da->da_name, name ) == 0 ) {
2968 #endif /* SLAP_DYNACL */
2975 slap_dynacl_t *known_dynacl[] = {
2976 #ifdef SLAPD_ACI_ENABLED
2978 #endif /* SLAPD_ACI_ENABLED */
2982 for ( i = 0; known_dynacl[ i ]; i++ ) {
2983 rc = slap_dynacl_register( known_dynacl[ i ] );
2988 #endif /* SLAP_DYNACL */
2999 regmatch_t *matches)
3007 bv->bv_val[0] = '\0';
3008 bv->bv_len--; /* leave space for lone $ */
3011 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
3012 sp < pat->bv_val + pat->bv_len ; sp++ )
3014 /* did we previously see a $ */
3016 if ( flag == 1 && *sp == '$' ) {
3021 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
3024 } else if ( *sp >= '0' && *sp <= '9' ) {
3032 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
3033 if ( *sp >= '0' && *sp <= '9' ) {
3034 n = 10*n + ( *sp - '0' );
3038 if ( *sp != /*'{'*/ '}' ) {
3044 if ( n >= nmatch ) {
3050 i = matches[n].rm_so;
3051 l = matches[n].rm_eo;
3052 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
3070 /* must have ended with a single $ */
3078 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
3079 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
3086 struct berval *pat, /* pattern to expand and match against */
3087 char *str, /* string to match against pattern */
3088 char *buf, /* buffer with $N expansion variables */
3089 int nmatch, /* size of the matches array */
3090 regmatch_t *matches /* offsets in buffer for $N expansion variables */
3094 char newbuf[ACL_BUF_SIZE];
3098 bv.bv_len = sizeof( newbuf ) - 1;
3105 string_expand( &bv, pat, buf, nmatch, matches );
3106 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
3108 char error[ACL_BUF_SIZE];
3109 regerror( rc, &re, error, sizeof( error ) );
3111 Debug( LDAP_DEBUG_TRACE,
3112 "compile( \"%s\", \"%s\") failed %s\n",
3113 pat->bv_val, str, error );
3117 rc = regexec( &re, str, 0, NULL, 0 );
3120 Debug( LDAP_DEBUG_TRACE,
3121 "=> regex_matches: string: %s\n", str, 0, 0 );
3122 Debug( LDAP_DEBUG_TRACE,
3123 "=> regex_matches: rc: %d %s\n",
3124 rc, !rc ? "matches" : "no matches", 0 );