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 if ( BER_BVISEMPTY( &op->o_ndn ) ) {
733 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
737 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
738 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
740 regmatch_t tmp_matches[2],
741 *tmp_matchesp = tmp_matches;
745 switch ( a->acl_dn_style ) {
746 case ACL_STYLE_REGEX:
747 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
748 tmp_matchesp = matches;
752 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
755 tmp_matches[0].rm_so = 0;
756 tmp_matches[0].rm_eo = e->e_nname.bv_len;
761 case ACL_STYLE_SUBTREE:
762 case ACL_STYLE_CHILDREN:
763 tmp_matches[0].rm_so = 0;
764 tmp_matches[0].rm_eo = e->e_nname.bv_len;
765 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
766 tmp_matches[1].rm_eo = e->e_nname.bv_len;
780 if ( !regex_matches( &b->a_dn_pat,
781 op->o_ndn.bv_val, e->e_ndn,
782 tmp_nmatch, tmp_matchesp ) )
792 if ( e->e_dn == NULL )
795 if ( b->a_dn_expand ) {
797 char buf[ACL_BUF_SIZE];
800 regmatch_t tmp_matches[2],
801 *tmp_matchesp = tmp_matches;
805 bv.bv_len = sizeof( buf ) - 1;
808 switch ( a->acl_dn_style ) {
809 case ACL_STYLE_REGEX:
810 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
811 tmp_matchesp = matches;
815 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
818 tmp_matches[0].rm_so = 0;
819 tmp_matches[0].rm_eo = e->e_nname.bv_len;
824 case ACL_STYLE_SUBTREE:
825 case ACL_STYLE_CHILDREN:
826 tmp_matches[0].rm_so = 0;
827 tmp_matches[0].rm_eo = e->e_nname.bv_len;
828 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
829 tmp_matches[1].rm_eo = e->e_nname.bv_len;
843 if ( string_expand( &bv, &b->a_dn_pat,
845 tmp_nmatch, tmp_matchesp ) )
850 if ( dnNormalize(0, NULL, NULL, &bv,
851 &pat, op->o_tmpmemctx )
854 /* did not expand to a valid dn */
863 odnlen = op->o_ndn.bv_len;
864 if ( odnlen < patlen ) {
865 goto dn_match_cleanup;
869 if ( b->a_dn_style == ACL_STYLE_BASE ) {
870 /* base dn -- entire object DN must match */
871 if ( odnlen != patlen ) {
872 goto dn_match_cleanup;
875 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
878 if ( odnlen <= patlen ) {
879 goto dn_match_cleanup;
882 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
883 goto dn_match_cleanup;
886 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
887 if ( rdnlen != odnlen - patlen - 1 ) {
888 goto dn_match_cleanup;
891 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
892 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
893 goto dn_match_cleanup;
896 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
897 if ( odnlen <= patlen ) {
898 goto dn_match_cleanup;
901 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
902 goto dn_match_cleanup;
906 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
909 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
910 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
919 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
920 if ( ! op->o_conn->c_listener ) {
923 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
924 b->a_sockurl_pat.bv_val, 0, 0 );
926 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
927 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
928 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
929 e->e_ndn, nmatch, matches ) )
934 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
936 char buf[ACL_BUF_SIZE];
938 bv.bv_len = sizeof( buf ) - 1;
940 if ( string_expand( &bv, &b->a_sockurl_pat,
941 e->e_ndn, nmatch, matches ) )
946 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
952 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
960 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
961 if ( !op->o_conn->c_peer_domain.bv_val ) {
964 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
965 b->a_domain_pat.bv_val, 0, 0 );
966 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
967 if ( b->a_domain_style == ACL_STYLE_REGEX) {
968 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
969 e->e_ndn, nmatch, matches ) )
974 char buf[ACL_BUF_SIZE];
976 struct berval cmp = op->o_conn->c_peer_domain;
977 struct berval pat = b->a_domain_pat;
979 if ( b->a_domain_expand ) {
982 bv.bv_len = sizeof(buf) - 1;
985 if ( string_expand(&bv, &b->a_domain_pat,
986 e->e_ndn, nmatch, matches) )
993 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
994 int offset = cmp.bv_len - pat.bv_len;
999 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1003 /* trim the domain */
1004 cmp.bv_val = &cmp.bv_val[ offset ];
1005 cmp.bv_len -= offset;
1008 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1015 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1016 if ( !op->o_conn->c_peer_name.bv_val ) {
1019 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1020 b->a_peername_pat.bv_val, 0, 0 );
1021 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1022 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1023 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1024 e->e_ndn, nmatch, matches ) )
1030 /* try exact match */
1031 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1032 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1036 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1038 char buf[ACL_BUF_SIZE];
1040 bv.bv_len = sizeof( buf ) - 1;
1042 if ( string_expand( &bv, &b->a_peername_pat,
1043 e->e_ndn, nmatch, matches ) )
1048 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1052 /* extract IP and try exact match */
1053 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1055 char buf[] = "255.255.255.255";
1058 int port_number = -1;
1060 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1061 aci_bv_ip_eq.bv_val, aci_bv_ip_eq.bv_len ) != 0 )
1064 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_ip_eq.bv_len;
1065 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_ip_eq.bv_len;
1067 port = strrchr( ip.bv_val, ':' );
1071 ip.bv_len = port - ip.bv_val;
1073 port_number = strtol( port, &next, 10 );
1074 if ( next[0] != '\0' )
1078 /* the port check can be anticipated here */
1079 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1082 /* address longer than expected? */
1083 if ( ip.bv_len >= sizeof(buf) )
1086 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1087 buf[ ip.bv_len ] = '\0';
1089 addr = inet_addr( buf );
1091 /* unable to convert? */
1092 if ( addr == (unsigned long)(-1) )
1095 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1098 #ifdef LDAP_PF_LOCAL
1099 /* extract path and try exact match */
1100 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1103 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1104 aci_bv_path_eq.bv_val, aci_bv_path_eq.bv_len ) != 0 )
1107 path.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_path_eq.bv_len;
1108 path.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_path_eq.bv_len;
1110 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1113 #endif /* LDAP_PF_LOCAL */
1115 /* exact match (very unlikely...) */
1116 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1123 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1124 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1127 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1128 b->a_sockname_pat.bv_val, 0, 0 );
1129 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1130 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1131 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1132 e->e_ndn, nmatch, matches ) )
1137 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1139 char buf[ACL_BUF_SIZE];
1141 bv.bv_len = sizeof( buf ) - 1;
1143 if ( string_expand( &bv, &b->a_sockname_pat,
1144 e->e_ndn, nmatch, matches ) )
1149 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1154 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1161 if ( b->a_dn_at != NULL ) {
1166 const char *attr = b->a_dn_at->ad_cname.bv_val;
1168 assert( attr != NULL );
1170 if ( op->o_ndn.bv_len == 0 ) {
1174 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
1178 /* see if asker is listed in dnattr */
1179 for( at = attrs_find( e->e_attrs, b->a_dn_at );
1181 at = attrs_find( at->a_next, b->a_dn_at ) )
1183 if( value_find_ex( b->a_dn_at,
1184 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1185 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1187 &bv, op->o_tmpmemctx ) == 0 )
1196 /* have a dnattr match. if this is a self clause then
1197 * the target must also match the op dn.
1199 if ( b->a_dn_self ) {
1200 /* check if the target is an attribute. */
1201 if ( val == NULL ) continue;
1203 /* target is attribute, check if the attribute value
1206 rc = value_match( &match, b->a_dn_at,
1207 b->a_dn_at->ad_type->sat_equality, 0,
1209 /* on match error or no match, fail the ACL clause */
1210 if (rc != LDAP_SUCCESS || match != 0 )
1214 /* no dnattr match, check if this is a self clause */
1215 if ( ! b->a_dn_self )
1218 ACL_RECORD_VALUE_STATE;
1220 /* this is a self clause, check if the target is an
1226 /* target is attribute, check if the attribute value
1229 rc = value_match( &match, b->a_dn_at,
1230 b->a_dn_at->ad_type->sat_equality, 0,
1233 /* on match error or no match, fail the ACL clause */
1234 if (rc != LDAP_SUCCESS || match != 0 )
1239 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1241 struct berval ndn = BER_BVNULL;
1244 if ( op->o_ndn.bv_len == 0 ) {
1248 /* b->a_group is an unexpanded entry name, expanded it should be an
1249 * entry with objectclass group* and we test to see if odn is one of
1250 * the values in the attribute group
1252 /* see if asker is listed in dnattr */
1253 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1254 char buf[ACL_BUF_SIZE];
1256 regmatch_t tmp_matches[2],
1257 *tmp_matchesp = tmp_matches;
1259 bv.bv_len = sizeof(buf) - 1;
1264 switch ( a->acl_dn_style ) {
1265 case ACL_STYLE_REGEX:
1266 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1267 tmp_matchesp = matches;
1268 tmp_nmatch = nmatch;
1272 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1273 case ACL_STYLE_BASE:
1274 tmp_matches[0].rm_so = 0;
1275 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1280 case ACL_STYLE_SUBTREE:
1281 case ACL_STYLE_CHILDREN:
1282 tmp_matches[0].rm_so = 0;
1283 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1284 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1285 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1299 if ( string_expand( &bv, &b->a_group_pat,
1301 tmp_nmatch, tmp_matchesp ) )
1306 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1307 op->o_tmpmemctx ) != LDAP_SUCCESS )
1309 /* did not expand to a valid dn */
1316 bv = b->a_group_pat;
1319 rc = backend_group( op, e, &bv, &op->o_ndn,
1320 b->a_group_oc, b->a_group_at );
1323 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1331 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1333 char buf[ACL_BUF_SIZE];
1335 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1337 regmatch_t tmp_matches[2],
1338 *tmp_matchesp = tmp_matches;
1341 bv.bv_len = sizeof( buf ) - 1;
1346 switch ( a->acl_dn_style ) {
1347 case ACL_STYLE_REGEX:
1348 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1349 tmp_matchesp = matches;
1350 tmp_nmatch = nmatch;
1354 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1355 case ACL_STYLE_BASE:
1356 tmp_matches[0].rm_so = 0;
1357 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1362 case ACL_STYLE_SUBTREE:
1363 case ACL_STYLE_CHILDREN:
1364 tmp_matches[0].rm_so = 0;
1365 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1366 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1367 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1381 if ( string_expand( &bv, &b->a_set_pat,
1383 tmp_nmatch, tmp_matchesp ) )
1392 if ( aci_match_set( &bv, op, e, 0 ) == 0 ) {
1397 if ( b->a_authz.sai_ssf ) {
1398 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1399 b->a_authz.sai_ssf, op->o_ssf, 0 );
1400 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1405 if ( b->a_authz.sai_transport_ssf ) {
1406 Debug( LDAP_DEBUG_ACL,
1407 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1408 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1409 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1414 if ( b->a_authz.sai_tls_ssf ) {
1415 Debug( LDAP_DEBUG_ACL,
1416 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1417 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1418 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1423 if ( b->a_authz.sai_sasl_ssf ) {
1424 Debug( LDAP_DEBUG_ACL,
1425 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1426 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1427 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1433 if ( b->a_dynacl ) {
1435 slap_access_t tgrant, tdeny;
1437 /* this case works different from the others above.
1438 * since aci's themselves give permissions, we need
1439 * to first check b->a_access_mask, the ACL's access level.
1441 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1442 /* no ACIs in the root DSE */
1446 /* first check if the right being requested
1447 * is allowed by the ACL clause.
1449 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1453 /* start out with nothing granted, nothing denied */
1457 for ( da = b->a_dynacl; da; da = da->da_next ) {
1458 slap_access_t grant, deny;
1460 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1466 /* remove anything that the ACL clause does not allow */
1467 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1468 tdeny &= ACL_PRIV_MASK;
1470 /* see if we have anything to contribute */
1471 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1475 /* this could be improved by changing acl_mask so that it can deal with
1476 * by clauses that return grant/deny pairs. Right now, it does either
1477 * additive or subtractive rights, but not both at the same time. So,
1478 * we need to combine the grant/deny pair into a single rights mask in
1479 * a smart way: if either grant or deny is "empty", then we use the
1480 * opposite as is, otherwise we remove any denied rights from the grant
1481 * rights mask and construct an additive mask.
1483 if (ACL_IS_INVALID(tdeny)) {
1484 modmask = tgrant | ACL_PRIV_ADDITIVE;
1486 } else if (ACL_IS_INVALID(tgrant)) {
1487 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1490 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1494 #else /* !SLAP_DYNACL */
1496 #ifdef SLAPD_ACI_ENABLED
1497 if ( b->a_aci_at != NULL ) {
1499 slap_access_t grant, deny, tgrant, tdeny;
1500 struct berval parent_ndn;
1501 BerVarray bvals = NULL;
1504 /* this case works different from the others above.
1505 * since aci's themselves give permissions, we need
1506 * to first check b->a_access_mask, the ACL's access level.
1509 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1510 /* no ACIs in the root DSE */
1514 /* first check if the right being requested
1515 * is allowed by the ACL clause.
1517 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1520 /* start out with nothing granted, nothing denied */
1524 /* get the aci attribute */
1525 at = attr_find( e->e_attrs, b->a_aci_at );
1528 /* FIXME: this breaks acl caching;
1529 * see also ACL_RECORD_VALUE_STATE below */
1530 ACL_RECORD_VALUE_STATE;
1532 /* the aci is an multi-valued attribute. The
1533 * rights are determined by OR'ing the individual
1534 * rights given by the acis.
1536 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
1541 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0)
1547 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1548 accessmask2str(tgrant, accessmaskbuf, 1),
1549 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
1552 /* If the entry level aci didn't contain anything valid for the
1553 * current operation, climb up the tree and evaluate the
1554 * acis with scope set to subtree
1556 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
1557 dnParent( &e->e_nname, &parent_ndn );
1558 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
1559 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1560 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
1568 for( i = 0; bvals[i].bv_val != NULL; i++){
1570 /* FIXME: this breaks acl caching;
1571 * see also ACL_RECORD_VALUE_STATE above */
1572 ACL_RECORD_VALUE_STATE;
1574 if (aci_mask(op, e, desc, val, &bvals[i],
1576 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
1580 /* evaluation stops as soon as either a "deny" or a
1581 * "grant" directive matches.
1583 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1587 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1588 accessmask2str(tgrant, accessmaskbuf, 1),
1589 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
1593 case LDAP_NO_SUCH_ATTRIBUTE:
1594 /* just go on if the aci-Attribute is not present in
1597 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1601 case LDAP_NO_SUCH_OBJECT:
1602 /* We have reached the base object */
1603 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1614 dnParent( &parent_ndn, &parent_ndn );
1619 /* remove anything that the ACL clause does not allow */
1620 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1621 tdeny &= ACL_PRIV_MASK;
1623 /* see if we have anything to contribute */
1624 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1628 /* this could be improved by changing acl_mask so that it can deal with
1629 * by clauses that return grant/deny pairs. Right now, it does either
1630 * additive or subtractive rights, but not both at the same time. So,
1631 * we need to combine the grant/deny pair into a single rights mask in
1632 * a smart way: if either grant or deny is "empty", then we use the
1633 * opposite as is, otherwise we remove any denied rights from the grant
1634 * rights mask and construct an additive mask.
1636 if (ACL_IS_INVALID(tdeny)) {
1637 modmask = tgrant | ACL_PRIV_ADDITIVE;
1639 } else if (ACL_IS_INVALID(tgrant)) {
1640 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1643 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1647 #endif /* SLAPD_ACI_ENABLED */
1648 #endif /* !SLAP_DYNACL */
1650 modmask = b->a_access_mask;
1653 Debug( LDAP_DEBUG_ACL,
1654 "<= acl_mask: [%d] applying %s (%s)\n",
1655 i, accessmask2str( modmask, accessmaskbuf, 1 ),
1656 b->a_type == ACL_CONTINUE
1658 : b->a_type == ACL_BREAK
1664 if( ACL_IS_ADDITIVE(modmask) ) {
1666 ACL_PRIV_SET( *mask, modmask );
1669 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1671 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1672 /* substract privs */
1673 ACL_PRIV_CLR( *mask, modmask );
1676 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1683 Debug( LDAP_DEBUG_ACL,
1684 "<= acl_mask: [%d] mask: %s\n",
1685 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
1687 if( b->a_type == ACL_CONTINUE ) {
1690 } else if ( b->a_type == ACL_BREAK ) {
1698 /* implicit "by * none" clause */
1701 Debug( LDAP_DEBUG_ACL,
1702 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1703 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
1708 * acl_check_modlist - check access control on the given entry to see if
1709 * it allows the given modifications by the user associated with op.
1710 * returns 1 if mods allowed ok
1711 * 0 mods not allowed
1718 Modifications *mlist
1722 AccessControlState state = ACL_STATE_INIT;
1725 int ret = 1; /* default is access allowed */
1729 be = LDAP_STAILQ_FIRST(&backendDB);
1733 assert( be != NULL );
1735 /* short circuit root database access */
1736 if ( be_isroot( op ) ) {
1737 Debug( LDAP_DEBUG_ACL,
1738 "<= acl_access_allowed: granted to database root\n",
1743 /* use backend default access if no backend acls */
1744 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1745 Debug( LDAP_DEBUG_ACL,
1746 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1747 access2str( ACL_WRITE ),
1748 op->o_bd->be_dfltaccess >= ACL_WRITE
1749 ? "granted" : "denied",
1751 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
1755 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1757 * no-user-modification operational attributes are ignored
1758 * by ACL_WRITE checking as any found here are not provided
1761 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1762 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1763 " modify access granted\n",
1764 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1768 switch ( mlist->sml_op ) {
1769 case LDAP_MOD_REPLACE:
1771 * We must check both permission to delete the whole
1772 * attribute and permission to add the specific attributes.
1773 * This prevents abuse from selfwriters.
1775 if ( ! access_allowed( op, e,
1776 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1782 if ( mlist->sml_values == NULL ) break;
1784 /* fall thru to check value to add */
1787 assert( mlist->sml_values != NULL );
1789 for ( bv = mlist->sml_nvalues
1790 ? mlist->sml_nvalues : mlist->sml_values;
1791 bv->bv_val != NULL; bv++ )
1793 if ( ! access_allowed( op, e,
1794 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1802 case LDAP_MOD_DELETE:
1803 if ( mlist->sml_values == NULL ) {
1804 if ( ! access_allowed( op, e,
1805 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1812 for ( bv = mlist->sml_nvalues
1813 ? mlist->sml_nvalues : mlist->sml_values;
1814 bv->bv_val != NULL; bv++ )
1816 if ( ! access_allowed( op, e,
1817 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1825 case SLAP_MOD_SOFTADD:
1826 /* allow adding attribute via modrdn thru */
1838 if (be_null) op->o_bd = NULL;
1844 struct berval *list,
1857 while ( len >= 0 && --ix >= 0 ) {
1858 while ( --len >= 0 && *p++ != sep )
1861 while ( len >= 0 && *p == ' ' ) {
1874 while ( --len >= 0 && *p != sep ) {
1878 while ( bv->bv_len > 0 && *--p == ' ' ) {
1885 typedef struct aci_set_gather_t {
1891 aci_set_cb_gather( Operation *op, SlapReply *rs )
1893 aci_set_gather_t *p = (aci_set_gather_t *)op->o_callback->sc_private;
1895 if ( rs->sr_type == REP_SEARCH ) {
1896 BerValue bvals[ 2 ];
1897 BerVarray bvalsp = NULL;
1900 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
1901 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
1903 if ( desc == slap_schema.si_ad_entryDN ) {
1905 bvals[ 0 ] = rs->sr_entry->e_nname;
1906 BER_BVZERO( &bvals[ 1 ] );
1911 a = attr_find( rs->sr_entry->e_attrs, desc );
1915 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
1918 bvalsp = a->a_nvals;
1924 p->bvals = slap_set_join( p->cookie, p->bvals,
1925 ( '|' | SLAP_SET_RREF ), bvalsp );
1929 assert( rs->sr_type == REP_RESULT );
1936 aci_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
1938 AciSetCookie *cp = (AciSetCookie *)cookie;
1940 LDAPURLDesc *ludp = NULL;
1941 Operation op2 = { 0 };
1942 SlapReply rs = {REP_RESULT};
1943 AttributeName anlist[ 2 ], *anlistp = NULL;
1945 slap_callback cb = { NULL, aci_set_cb_gather, NULL, NULL };
1946 aci_set_gather_t p = { 0 };
1947 const char *text = NULL;
1948 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
1950 /* this routine needs to return the bervals instead of
1951 * plain strings, since syntax is not known. It should
1952 * also return the syntax or some "comparison cookie".
1954 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
1955 return aci_set_gather2( cookie, name, desc );
1958 rc = ldap_url_parse( name->bv_val, &ludp );
1959 if ( rc != LDAP_URL_SUCCESS ) {
1960 rc = LDAP_PROTOCOL_ERROR;
1964 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
1966 /* host part must be empty */
1967 /* extensions parts must be empty */
1968 rc = LDAP_PROTOCOL_ERROR;
1972 /* Grab the searchbase and see if an appropriate database can be found */
1973 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
1974 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
1975 &op2.o_req_ndn, cp->op->o_tmpmemctx );
1976 BER_BVZERO( &op2.o_req_dn );
1977 if ( rc != LDAP_SUCCESS ) {
1981 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
1982 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
1983 rc = LDAP_NO_SUCH_OBJECT;
1987 /* Grab the filter */
1988 if ( ludp->lud_filter ) {
1989 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
1990 cp->op->o_tmpmemctx );
1993 op2.ors_filterstr = defaultFilter_bv;
1996 op2.ors_filter = str2filter_x( cp->op, op2.ors_filterstr.bv_val );
1997 if ( op2.ors_filter == NULL ) {
1998 rc = LDAP_PROTOCOL_ERROR;
2002 /* Grab the scope */
2003 op2.ors_scope = ludp->lud_scope;
2005 /* Grap the attributes */
2006 if ( ludp->lud_attrs ) {
2007 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2010 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2011 cp->op->o_tmpmemctx );
2013 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2014 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2015 anlistp[ nattrs ].an_desc = NULL;
2016 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2017 &anlistp[ nattrs ].an_desc, &text );
2018 if ( rc != LDAP_SUCCESS ) {
2027 anlistp[ nattrs ].an_name = desc->ad_cname;
2028 anlistp[ nattrs ].an_desc = desc;
2030 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2034 op2.o_hdr = cp->op->o_hdr;
2035 op2.o_tag = LDAP_REQ_SEARCH;
2036 op2.o_ndn = op2.o_bd->be_rootndn;
2037 op2.o_callback = &cb;
2038 op2.o_time = slap_get_time();
2039 op2.o_do_not_cache = 1;
2040 op2.o_is_auth_check = 0;
2041 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->op->o_tmpmemctx );
2042 op2.ors_slimit = SLAP_NO_LIMIT;
2043 op2.ors_tlimit = SLAP_NO_LIMIT;
2044 op2.ors_attrs = anlistp;
2045 op2.ors_attrsonly = 0;
2046 op2.o_private = cp->op->o_private;
2050 rc = op2.o_bd->be_search( &op2, &rs );
2056 if ( op2.ors_filter ) {
2057 filter_free_x( cp->op, op2.ors_filter );
2059 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2060 slap_sl_free( op2.o_req_ndn.bv_val, cp->op->o_tmpmemctx );
2062 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2063 slap_sl_free( op2.o_req_dn.bv_val, cp->op->o_tmpmemctx );
2066 ldap_free_urldesc( ludp );
2068 if ( anlistp && anlistp != anlist ) {
2069 slap_sl_free( anlistp, cp->op->o_tmpmemctx );
2076 aci_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2078 AciSetCookie *cp = (AciSetCookie *)cookie;
2079 BerVarray bvals = NULL;
2083 /* this routine needs to return the bervals instead of
2084 * plain strings, since syntax is not known. It should
2085 * also return the syntax or some "comparison cookie".
2087 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
2088 if ( rc == LDAP_SUCCESS ) {
2089 if ( desc == slap_schema.si_ad_entryDN ) {
2090 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2091 cp->op->o_tmpmemctx );
2093 BER_BVZERO( &bvals[ 1 ] );
2097 backend_attribute( cp->op,
2098 cp->e, &ndn, desc, &bvals, ACL_NONE );
2101 if ( !BER_BVISNULL( &ndn ) ) {
2102 slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
2111 struct berval *subj,
2117 struct berval set = BER_BVNULL;
2119 AciSetCookie cookie;
2121 if ( setref == 0 ) {
2122 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2125 struct berval subjdn, ndn = BER_BVNULL;
2126 struct berval setat;
2129 AttributeDescription *desc = NULL;
2131 /* format of string is "entry/setAttrName" */
2132 if ( aci_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2136 if ( aci_get_part( subj, 1, '/', &setat ) < 0 ) {
2137 setat = aci_bv_set_attr;
2141 * NOTE: dnNormalize honors the ber_len field
2142 * as the length of the dn to be normalized
2144 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2145 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2147 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2148 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2152 BER_BVZERO( &bvals[0] );
2153 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2155 bvals[0].bv_val = bvals[i-1].bv_val;
2156 BER_BVZERO( &bvals[i-1] );
2158 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2159 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2164 if ( !BER_BVISNULL( &set ) ) {
2167 rc = ( slap_set_filter( aci_set_gather, (SetCookie *)&cookie, &set,
2168 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2169 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2175 #ifdef SLAPD_ACI_ENABLED
2177 aci_list_map_rights(
2178 struct berval *list )
2185 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2188 switch (*bv.bv_val) {
2190 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2193 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
2194 * the right 's' to mean "set", but in the examples states
2195 * that the right 's' means "search". The latter definition
2198 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2201 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2204 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2207 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
2208 * define any equivalent to the AUTH right, so I've just used
2211 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2223 struct berval *list,
2224 const struct berval *attr,
2225 struct berval *val )
2227 struct berval bv, left, right;
2230 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2231 if (aci_get_part(&bv, 0, '=', &left) < 0
2232 || aci_get_part(&bv, 1, '=', &right) < 0)
2234 if (ber_bvstrcasecmp(attr, &bv) == 0)
2236 } else if (val == NULL) {
2237 if (ber_bvstrcasecmp(attr, &left) == 0)
2240 if (ber_bvstrcasecmp(attr, &left) == 0) {
2241 /* this is experimental code that implements a
2242 * simple (prefix) match of the attribute value.
2243 * the ACI draft does not provide for aci's that
2244 * apply to specific values, but it would be
2245 * nice to have. If the <attr> part of an aci's
2246 * rights list is of the form <attr>=<value>,
2247 * that means the aci applies only to attrs with
2248 * the given value. Furthermore, if the attr is
2249 * of the form <attr>=<value>*, then <value> is
2250 * treated as a prefix, and the aci applies to
2251 * any value with that prefix.
2253 * Ideally, this would allow r.e. matches.
2255 if (aci_get_part(&right, 0, '*', &left) < 0
2256 || right.bv_len <= left.bv_len)
2258 if (ber_bvstrcasecmp(val, &right) == 0)
2260 } else if (val->bv_len >= left.bv_len) {
2261 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
2270 static slap_access_t
2271 aci_list_get_attr_rights(
2272 struct berval *list,
2273 const struct berval *attr,
2274 struct berval *val )
2280 /* loop through each rights/attr pair, skip first part (action) */
2282 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
2283 if (aci_list_has_attr(&bv, attr, val) == 0)
2285 if (aci_get_part(list, i, ';', &bv) < 0)
2287 mask |= aci_list_map_rights(&bv);
2293 aci_list_get_rights(
2294 struct berval *list,
2295 const struct berval *attr,
2297 slap_access_t *grant,
2298 slap_access_t *deny )
2300 struct berval perm, actn;
2301 slap_access_t *mask;
2304 if (attr == NULL || attr->bv_len == 0
2305 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
2306 attr = &aci_bv_br_entry;
2312 /* loop through each permissions clause */
2313 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
2314 if (aci_get_part(&perm, 0, ';', &actn) < 0)
2316 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
2318 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
2325 *mask |= aci_list_get_attr_rights(&perm, attr, val);
2326 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
2333 struct berval *subj,
2334 struct berval *defgrpoc,
2335 struct berval *defgrpat,
2342 struct berval subjdn;
2343 struct berval grpoc;
2344 struct berval grpat;
2345 ObjectClass *grp_oc = NULL;
2346 AttributeDescription *grp_ad = NULL;
2350 /* format of string is "group/objectClassValue/groupAttrName" */
2351 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
2355 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
2359 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
2363 rc = slap_bv2ad( &grpat, &grp_ad, &text );
2364 if( rc != LDAP_SUCCESS ) {
2370 grp_oc = oc_bvfind( &grpoc );
2372 if (grp_oc != NULL && grp_ad != NULL ) {
2373 char buf[ACL_BUF_SIZE];
2374 struct berval bv, ndn;
2375 bv.bv_len = sizeof( buf ) - 1;
2376 bv.bv_val = (char *)&buf;
2377 if ( string_expand(&bv, &subjdn,
2378 e->e_ndn, nmatch, matches) )
2383 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
2384 rc = ( backend_group( op, e, &ndn, &op->o_ndn,
2385 grp_oc, grp_ad ) == 0 );
2386 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2398 AttributeDescription *desc,
2402 regmatch_t *matches,
2403 slap_access_t *grant,
2404 slap_access_t *deny,
2405 slap_aci_scope_t asserted_scope
2408 struct berval bv, scope, perms, type, sdn;
2412 assert( !BER_BVISNULL( &desc->ad_cname ) );
2414 /* parse an aci of the form:
2415 oid # scope # action;rights;attr;rights;attr
2416 $ action;rights;attr;rights;attr # type # subject
2418 [NOTE: the following comment is very outdated,
2419 as the draft version it refers to (Ando, 2004-11-20)].
2421 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
2422 a full description of the format for this attribute.
2423 Differences: "this" in the draft is "self" here, and
2424 "self" and "public" is in the position of type.
2426 <scope> = {entry|children|subtree}
2427 <type> = {public|users|access-id|subtree|onelevel|children|
2428 self|dnattr|group|role|set|set-ref}
2430 This routine now supports scope={ENTRY,CHILDREN}
2432 - ENTRY applies to "entry" and "subtree";
2433 - CHILDREN aplies to "children" and "subtree"
2436 /* check that the aci has all 5 components */
2437 if ( aci_get_part( aci, 4, '#', NULL ) < 0 ) {
2441 /* check that the aci family is supported */
2442 if ( aci_get_part( aci, 0, '#', &bv ) < 0 ) {
2446 /* check that the scope matches */
2447 if ( aci_get_part( aci, 1, '#', &scope ) < 0 ) {
2451 /* note: scope can be either ENTRY or CHILDREN;
2452 * they respectively match "entry" and "children" in bv
2453 * both match "subtree" */
2454 switch ( asserted_scope ) {
2455 case SLAP_ACI_SCOPE_ENTRY:
2456 if ( ber_bvstrcasecmp( &scope, &aci_bv_entry ) != 0
2457 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2463 case SLAP_ACI_SCOPE_CHILDREN:
2464 if ( ber_bvstrcasecmp( &scope, &aci_bv_children ) != 0
2465 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2475 /* get the list of permissions clauses, bail if empty */
2476 if ( aci_get_part( aci, 2, '#', &perms ) <= 0 ) {
2480 /* check if any permissions allow desired access */
2481 if ( aci_list_get_rights( &perms, &desc->ad_cname, val, grant, deny ) == 0 ) {
2485 /* see if we have a DN match */
2486 if ( aci_get_part( aci, 3, '#', &type ) < 0 ) {
2490 /* see if we have a public (i.e. anonymous) access */
2491 if ( ber_bvstrcasecmp( &aci_bv_public, &type ) == 0 ) {
2495 /* otherwise require an identity */
2496 if ( BER_BVISNULL( &op->o_ndn ) || BER_BVISEMPTY( &op->o_ndn ) ) {
2500 /* see if we have a users access */
2501 if ( ber_bvstrcasecmp( &aci_bv_users, &type ) == 0 ) {
2505 /* NOTE: this may fail if a DN contains a valid '#' (unescaped);
2506 * just grab all the berval up to its end (ITS#3303).
2507 * NOTE: the problem could be solved by providing the DN with
2508 * the embedded '#' encoded as hexpairs: "cn=Foo#Bar" would
2509 * become "cn=Foo\23Bar" and be safely used by aci_mask(). */
2511 if ( aci_get_part( aci, 4, '#', &sdn ) < 0 ) {
2515 sdn.bv_val = type.bv_val + type.bv_len + STRLENOF( "#" );
2516 sdn.bv_len = aci->bv_len - ( sdn.bv_val - aci->bv_val );
2518 if ( ber_bvstrcasecmp( &aci_bv_access_id, &type ) == 0 ) {
2521 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2522 if ( rc != LDAP_SUCCESS ) {
2526 if ( dn_match( &op->o_ndn, &ndn ) ) {
2529 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2533 } else if ( ber_bvstrcasecmp( &aci_bv_subtree, &type ) == 0 ) {
2536 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2537 if ( rc != LDAP_SUCCESS ) {
2541 if ( dnIsSuffix( &op->o_ndn, &ndn ) ) {
2544 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2548 } else if ( ber_bvstrcasecmp( &aci_bv_onelevel, &type ) == 0 ) {
2549 struct berval ndn, pndn;
2551 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2552 if ( rc != LDAP_SUCCESS ) {
2556 dnParent( &ndn, &pndn );
2558 if ( dn_match( &op->o_ndn, &pndn ) ) {
2561 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2565 } else if ( ber_bvstrcasecmp( &aci_bv_children, &type ) == 0 ) {
2568 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2569 if ( rc != LDAP_SUCCESS ) {
2573 if ( !dn_match( &op->o_ndn, &ndn )
2574 && dnIsSuffix( &op->o_ndn, &ndn ) )
2578 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2582 } else if ( ber_bvstrcasecmp( &aci_bv_self, &type ) == 0 ) {
2583 if ( dn_match( &op->o_ndn, &e->e_nname ) ) {
2587 } else if ( ber_bvstrcasecmp( &aci_bv_dnattr, &type ) == 0 ) {
2589 AttributeDescription *ad = NULL;
2592 rc = slap_bv2ad( &sdn, &ad, &text );
2594 if( rc != LDAP_SUCCESS ) {
2600 for ( at = attrs_find( e->e_attrs, ad );
2602 at = attrs_find( at->a_next, ad ) )
2604 if ( value_find_ex( ad,
2605 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
2606 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
2608 &op->o_ndn, op->o_tmpmemctx ) == 0 )
2617 } else if ( ber_bvstrcasecmp( &aci_bv_group, &type ) == 0 ) {
2618 if ( aci_group_member( &sdn, &aci_bv_group_class,
2619 &aci_bv_group_attr, op, e, nmatch, matches ) )
2624 } else if ( ber_bvstrcasecmp( &aci_bv_role, &type ) == 0 ) {
2625 if ( aci_group_member( &sdn, &aci_bv_role_class,
2626 &aci_bv_role_attr, op, e, nmatch, matches ) )
2631 } else if ( ber_bvstrcasecmp( &aci_bv_set, &type ) == 0 ) {
2632 if ( aci_match_set( &sdn, op, e, 0 ) ) {
2636 } else if ( ber_bvstrcasecmp( &aci_bv_set_ref, &type ) == 0 ) {
2637 if ( aci_match_set( &sdn, op, e, 1 ) ) {
2647 dynacl_aci_parse( const char *fname, int lineno, slap_style_t sty, const char *right, void **privp )
2649 AttributeDescription *ad = NULL;
2650 const char *text = NULL;
2652 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
2653 fprintf( stderr, "%s: line %d: "
2654 "inappropriate style \"%s\" in \"aci\" by clause\n",
2655 fname, lineno, sty );
2659 if ( right != NULL && *right != '\0' ) {
2660 if ( slap_str2ad( right, &ad, &text ) != LDAP_SUCCESS ) {
2662 "%s: line %d: aci \"%s\": %s\n",
2663 fname, lineno, right, text );
2668 ad = slap_schema.si_ad_aci;
2671 if ( !is_at_syntax( ad->ad_type, SLAPD_ACI_SYNTAX) ) {
2672 fprintf( stderr, "%s: line %d: "
2673 "aci \"%s\": inappropriate syntax: %s\n",
2674 fname, lineno, right,
2675 ad->ad_type->sat_syntax_oid );
2679 *privp = (void *)ad;
2685 dynacl_aci_unparse( void *priv, struct berval *bv )
2687 AttributeDescription *ad = ( AttributeDescription * )priv;
2692 bv->bv_val = ch_malloc( STRLENOF(" aci=") + ad->ad_cname.bv_len + 1 );
2693 ptr = lutil_strcopy( bv->bv_val, " aci=" );
2694 ptr = lutil_strcopy( ptr, ad->ad_cname.bv_val );
2695 bv->bv_len = ptr - bv->bv_val;
2706 AttributeDescription *desc,
2709 regmatch_t *matches,
2710 slap_access_t *grantp,
2711 slap_access_t *denyp )
2713 AttributeDescription *ad = ( AttributeDescription * )priv;
2715 slap_access_t tgrant, tdeny, grant, deny;
2717 char accessmaskbuf[ACCESSMASK_MAXLEN];
2718 char accessmaskbuf1[ACCESSMASK_MAXLEN];
2719 #endif /* LDAP_DEBUG */
2721 /* start out with nothing granted, nothing denied */
2725 /* get the aci attribute */
2726 at = attr_find( e->e_attrs, ad );
2730 /* the aci is an multi-valued attribute. The
2731 * rights are determined by OR'ing the individual
2732 * rights given by the acis.
2734 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2735 if ( aci_mask( op, e, desc, val, &at->a_nvals[i],
2736 nmatch, matches, &grant, &deny,
2737 SLAP_ACI_SCOPE_ENTRY ) != 0 )
2744 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2745 accessmask2str( tgrant, accessmaskbuf, 1 ),
2746 accessmask2str( tdeny, accessmaskbuf1, 1 ), 0 );
2749 /* If the entry level aci didn't contain anything valid for the
2750 * current operation, climb up the tree and evaluate the
2751 * acis with scope set to subtree
2753 if ( tgrant == ACL_PRIV_NONE && tdeny == ACL_PRIV_NONE ) {
2754 struct berval parent_ndn;
2757 /* to solve the chicken'n'egg problem of accessing
2758 * the OpenLDAPaci attribute, the direct access
2759 * to the entry's attribute is unchecked; however,
2760 * further accesses to OpenLDAPaci values in the
2761 * ancestors occur through backend_attribute(), i.e.
2762 * with the identity of the operation, requiring
2763 * further access checking. For uniformity, this
2764 * makes further requests occur as the rootdn, if
2765 * any, i.e. searching for the OpenLDAPaci attribute
2766 * is considered an internal search. If this is not
2767 * acceptable, then the same check needs be performed
2768 * when accessing the entry's attribute. */
2769 Operation op2 = *op;
2771 if ( !BER_BVISNULL( &op->o_bd->be_rootndn ) ) {
2772 op2.o_dn = op->o_bd->be_rootdn;
2773 op2.o_ndn = op->o_bd->be_rootndn;
2777 dnParent( &e->e_nname, &parent_ndn );
2778 while ( !BER_BVISEMPTY( &parent_ndn ) ){
2780 BerVarray bvals = NULL;
2783 Debug( LDAP_DEBUG_ACL, "checking ACI of \"%s\"\n", parent_ndn.bv_val, 0, 0 );
2784 ret = backend_attribute( &op2, NULL, &parent_ndn, ad, &bvals, ACL_AUTH );
2793 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++) {
2794 if ( aci_mask( op, e, desc, val,
2798 SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2802 /* evaluation stops as soon as either a "deny" or a
2803 * "grant" directive matches.
2805 if ( tgrant != ACL_PRIV_NONE || tdeny != ACL_PRIV_NONE ) {
2809 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2810 accessmask2str( tgrant, accessmaskbuf, 1 ),
2811 accessmask2str( tdeny, accessmaskbuf1, 1 ), 0 );
2815 case LDAP_NO_SUCH_ATTRIBUTE:
2816 /* just go on if the aci-Attribute is not present in
2819 Debug( LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0 );
2823 case LDAP_NO_SUCH_OBJECT:
2824 /* We have reached the base object */
2825 Debug( LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0 );
2837 dnParent( &parent_ndn, &parent_ndn );
2847 /* need to register this at some point */
2848 static slap_dynacl_t dynacl_aci = {
2858 #endif /* SLAP_DYNACL */
2860 #endif /* SLAPD_ACI_ENABLED */
2865 * dynamic ACL infrastructure
2867 static slap_dynacl_t *da_list = NULL;
2870 slap_dynacl_register( slap_dynacl_t *da )
2874 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2875 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2880 if ( tmp != NULL ) {
2884 if ( da->da_mask == NULL ) {
2888 da->da_private = NULL;
2889 da->da_next = da_list;
2895 static slap_dynacl_t *
2896 slap_dynacl_next( slap_dynacl_t *da )
2905 slap_dynacl_get( const char *name )
2909 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2910 if ( strcasecmp( da->da_name, name ) == 0 ) {
2917 #endif /* SLAP_DYNACL */
2924 slap_dynacl_t *known_dynacl[] = {
2925 #ifdef SLAPD_ACI_ENABLED
2927 #endif /* SLAPD_ACI_ENABLED */
2931 for ( i = 0; known_dynacl[ i ]; i++ ) {
2932 rc = slap_dynacl_register( known_dynacl[ i ] );
2937 #endif /* SLAP_DYNACL */
2948 regmatch_t *matches)
2956 bv->bv_val[0] = '\0';
2957 bv->bv_len--; /* leave space for lone $ */
2960 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2961 sp < pat->bv_val + pat->bv_len ; sp++ )
2963 /* did we previously see a $ */
2965 if ( flag == 1 && *sp == '$' ) {
2970 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2973 } else if ( *sp >= '0' && *sp <= '9' ) {
2981 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2982 if ( *sp >= '0' && *sp <= '9' ) {
2983 n = 10*n + ( *sp - '0' );
2987 if ( *sp != /*'{'*/ '}' ) {
2993 if ( n >= nmatch ) {
2999 i = matches[n].rm_so;
3000 l = matches[n].rm_eo;
3001 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
3019 /* must have ended with a single $ */
3027 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
3028 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
3035 struct berval *pat, /* pattern to expand and match against */
3036 char *str, /* string to match against pattern */
3037 char *buf, /* buffer with $N expansion variables */
3038 int nmatch, /* size of the matches array */
3039 regmatch_t *matches /* offsets in buffer for $N expansion variables */
3043 char newbuf[ACL_BUF_SIZE];
3047 bv.bv_len = sizeof( newbuf ) - 1;
3054 string_expand( &bv, pat, buf, nmatch, matches );
3055 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
3057 char error[ACL_BUF_SIZE];
3058 regerror( rc, &re, error, sizeof( error ) );
3060 Debug( LDAP_DEBUG_TRACE,
3061 "compile( \"%s\", \"%s\") failed %s\n",
3062 pat->bv_val, str, error );
3066 rc = regexec( &re, str, 0, NULL, 0 );
3069 Debug( LDAP_DEBUG_TRACE,
3070 "=> regex_matches: string: %s\n", str, 0, 0 );
3071 Debug( LDAP_DEBUG_TRACE,
3072 "=> regex_matches: rc: %d %s\n",
3073 rc, !rc ? "matches" : "no matches", 0 );