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>
40 #include "slapi/slapi.h"
41 #endif /* LDAPI_SLAPI */
43 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
49 aci_bv_entry = BER_BVC("entry"),
50 aci_bv_children = BER_BVC("children"),
51 aci_bv_onelevel = BER_BVC("onelevel"),
52 aci_bv_subtree = BER_BVC("subtree"),
53 aci_bv_br_entry = BER_BVC("[entry]"),
54 aci_bv_br_all = BER_BVC("[all]"),
55 aci_bv_access_id = BER_BVC("access-id"),
56 aci_bv_anonymous = BER_BVC("anonymous"),
57 aci_bv_public = BER_BVC("public"),
58 aci_bv_users = BER_BVC("users"),
59 aci_bv_self = BER_BVC("self"),
60 aci_bv_dnattr = BER_BVC("dnattr"),
61 aci_bv_group = BER_BVC("group"),
62 aci_bv_role = BER_BVC("role"),
63 aci_bv_set = BER_BVC("set"),
64 aci_bv_set_ref = BER_BVC("set-ref"),
65 aci_bv_grant = BER_BVC("grant"),
66 aci_bv_deny = BER_BVC("deny"),
68 aci_bv_ip_eq = BER_BVC("IP="),
70 aci_bv_path_eq = BER_BVC("PATH="),
71 aci_bv_dirsep = BER_BVC(LDAP_DIRSEP),
72 #endif /* LDAP_PF_LOCAL */
74 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
75 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
76 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
77 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR),
78 aci_bv_set_attr = BER_BVC(SLAPD_ACI_SET_ATTR);
80 typedef enum slap_aci_scope_t {
81 SLAP_ACI_SCOPE_ENTRY = 0x1,
82 SLAP_ACI_SCOPE_CHILDREN = 0x2,
83 SLAP_ACI_SCOPE_SUBTREE = ( SLAP_ACI_SCOPE_ENTRY | SLAP_ACI_SCOPE_CHILDREN )
86 static AccessControl * acl_get(
87 AccessControl *ac, int *count,
88 Operation *op, Entry *e,
89 AttributeDescription *desc,
91 int nmatch, regmatch_t *matches,
92 AccessControlState *state );
94 static slap_control_t acl_mask(
95 AccessControl *ac, slap_mask_t *mask,
96 Operation *op, Entry *e,
97 AttributeDescription *desc,
102 AccessControlState *state );
104 #ifdef SLAPD_ACI_ENABLED
106 Operation *op, Entry *e,
107 AttributeDescription *desc,
112 slap_access_t *grant,
114 slap_aci_scope_t scope);
117 static int regex_matches(
118 struct berval *pat, char *str, char *buf,
119 int nmatch, regmatch_t *matches);
120 static int string_expand(
121 struct berval *newbuf, struct berval *pattern,
122 char *match, int nmatch, regmatch_t *matches);
124 typedef struct AciSetCookie {
129 SLAP_SET_GATHER aci_set_gather;
130 SLAP_SET_GATHER aci_set_gather2;
131 static int aci_match_set ( struct berval *subj, Operation *op,
132 Entry *e, int setref );
135 * access_allowed - check whether op->o_ndn is allowed the requested access
136 * to entry e, attribute attr, value val. if val is null, access to
137 * the whole attribute is assumed (all values).
139 * This routine loops through all access controls and calls
140 * acl_mask() on each applicable access control.
141 * The loop exits when a definitive answer is reached or
142 * or no more controls remain.
149 * - can be legally called with op == NULL
150 * - can be legally called with op->o_bd == NULL
157 AttributeDescription *desc,
159 slap_access_t access,
160 AccessControlState *state,
165 AccessControl *a = NULL;
170 char accessmaskbuf[ACCESSMASK_MAXLEN];
173 slap_control_t control;
175 regmatch_t matches[MAXREMATCHES];
176 int st_same_attr = 0;
177 static AccessControlState state_init = ACL_STATE_INIT;
180 assert( desc != NULL );
181 assert( access > ACL_NONE );
182 if ( maskp ) ACL_INVALIDATE( *maskp );
184 attr = desc->ad_cname.bv_val;
186 assert( attr != NULL );
188 if( op && op->o_is_auth_check &&
189 ( access == ACL_SEARCH || access == ACL_READ ))
195 if ( state->as_vd_ad==desc) {
196 if ( state->as_recorded ) {
197 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
200 return state->as_result;
201 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
202 val != NULL && state->as_vd_acl == NULL )
204 return state->as_result;
212 state->as_vd_ad=desc;
215 Debug( LDAP_DEBUG_ACL,
216 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
217 access2str( access ), e->e_dn, attr );
230 * FIXME: experimental; use first backend rules
231 * iff there is no global_acl (ITS#3100) */
232 if ( frontendDB->be_acl == NULL )
238 assert( be != NULL );
241 if ( op->o_pb != NULL ) {
242 ret = slapi_int_access_allowed( op, e, desc, val, access, state );
244 /* ACL plugin denied access */
248 #endif /* LDAP_SLAPI */
250 /* grant database root access */
251 if ( be != NULL && be_isroot( op ) ) {
252 Debug( LDAP_DEBUG_ACL,
253 "<= root access granted\n",
256 mask = ACL_LVL_MANAGE;
263 * no-user-modification operational attributes are ignored
264 * by ACL_WRITE checking as any found here are not provided
267 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
268 && desc != slap_schema.si_ad_entry
269 && desc != slap_schema.si_ad_children )
271 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
272 " %s access granted\n",
277 /* use backend default access if no backend acls */
278 if( be != NULL && be->be_acl == NULL ) {
279 Debug( LDAP_DEBUG_ACL,
280 "=> access_allowed: backend default %s access %s to \"%s\"\n",
281 access2str( access ),
282 be->be_dfltaccess >= access ? "granted" : "denied",
283 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
284 ret = be->be_dfltaccess >= access;
289 mask = ACL_PRIV_LEVEL;
290 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
291 mask |= ACL_ACCESS2PRIV( i );
298 /* be is always non-NULL */
299 /* use global default access if no global acls */
300 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
301 Debug( LDAP_DEBUG_ACL,
302 "=> access_allowed: global default %s access %s to \"%s\"\n",
303 access2str( access ),
304 frontendDB->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
305 ret = frontendDB->be_dfltaccess >= access;
310 mask = ACL_PRIV_LEVEL;
311 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
312 mask |= ACL_ACCESS2PRIV( i );
324 assert( state->as_vd_acl != NULL );
326 a = state->as_vd_acl;
327 count = state->as_vd_acl_count;
328 if ( !ACL_IS_INVALID( state->as_vd_acl_mask )) {
329 mask = state->as_vd_acl_mask;
330 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
335 if ( state ) state->as_vi_acl = NULL;
339 memset(matches, '\0', sizeof(matches));
342 while((a = acl_get( a, &count, op, e, desc, val,
343 MAXREMATCHES, matches, state )) != NULL)
347 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
348 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
349 (int)matches[i].rm_so, (int)matches[i].rm_eo );
350 if( matches[i].rm_so <= matches[0].rm_eo ) {
352 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
353 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
356 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
360 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
361 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
362 ret = state->as_result;
365 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
370 control = acl_mask( a, &mask, op,
371 e, desc, val, MAXREMATCHES, matches, count, state );
373 if ( control != ACL_BREAK ) {
377 memset(matches, '\0', sizeof(matches));
380 if ( ACL_IS_INVALID( mask ) ) {
381 Debug( LDAP_DEBUG_ACL,
382 "=> access_allowed: \"%s\" (%s) invalid!\n",
386 } else if ( control == ACL_BREAK ) {
387 Debug( LDAP_DEBUG_ACL,
388 "=> access_allowed: no more rules\n", 0, 0, 0);
393 Debug( LDAP_DEBUG_ACL,
394 "=> access_allowed: %s access %s by %s\n",
395 access2str( access ),
396 ACL_GRANT(mask, access) ? "granted" : "denied",
397 accessmask2str( mask, accessmaskbuf ) );
399 ret = ACL_GRANT(mask, access);
402 if( state != NULL ) {
403 /* If not value-dependent, save ACL in case of more attrs */
404 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) ) {
405 state->as_vi_acl = a;
406 state->as_result = ret;
408 state->as_recorded |= ACL_STATE_RECORDED;
410 if (be_null) op->o_bd = NULL;
411 if ( maskp ) *maskp = mask;
417 * acl_get - return the acl applicable to entry e, attribute
418 * attr. the acl returned is suitable for use in subsequent calls to
419 * acl_access_allowed().
422 static AccessControl *
428 AttributeDescription *desc,
432 AccessControlState *state )
439 assert( count != NULL );
440 assert( desc != NULL );
442 attr = desc->ad_cname.bv_val;
444 assert( attr != NULL );
447 if( op->o_bd == NULL ) {
448 a = frontendDB->be_acl;
450 a = op->o_bd->be_acl;
461 dnlen = e->e_nname.bv_len;
463 for ( ; a != NULL; a = a->acl_next ) {
466 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
467 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
468 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
469 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
470 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
474 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
475 *count, a->acl_dn_pat.bv_val, 0 );
476 patlen = a->acl_dn_pat.bv_len;
477 if ( dnlen < patlen )
480 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
481 /* base dn -- entire object DN must match */
482 if ( dnlen != patlen )
485 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
486 int rdnlen = -1, sep = 0;
488 if ( dnlen <= patlen )
492 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
497 rdnlen = dn_rdnlen( NULL, &e->e_nname );
498 if ( rdnlen != dnlen - patlen - sep )
501 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
502 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
505 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
506 if ( dnlen <= patlen )
508 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
512 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
516 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
520 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
521 matches[0].rm_so = matches[0].rm_eo = -1;
525 /* Is this ACL only for a specific value? */
526 if ( a->acl_attrval.bv_len ) {
531 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
532 state->as_recorded |= ACL_STATE_RECORDED_VD;
533 state->as_vd_acl = prev;
534 state->as_vd_acl_count = *count;
535 state->as_vd_access = a->acl_access;
536 state->as_vd_access_count = 1;
537 ACL_INVALIDATE( state->as_vd_acl_mask );
540 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
541 Debug( LDAP_DEBUG_ACL,
542 "acl_get: valpat %s\n",
543 a->acl_attrval.bv_val, 0, 0 );
544 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
552 Debug( LDAP_DEBUG_ACL,
554 a->acl_attrval.bv_val, 0, 0 );
556 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
557 if (value_match( &match, desc,
558 desc->ad_type->sat_equality, 0,
559 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
566 patlen = a->acl_attrval.bv_len;
567 vdnlen = val->bv_len;
569 if ( vdnlen < patlen )
572 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
573 if ( vdnlen > patlen )
576 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
579 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
582 rdnlen = dn_rdnlen( NULL, val );
583 if ( rdnlen != vdnlen - patlen - 1 )
586 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
587 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
590 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
591 if ( vdnlen <= patlen )
594 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
598 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
604 if ( a->acl_filter != NULL ) {
605 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
606 if ( rc != LDAP_COMPARE_TRUE ) {
611 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
616 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
621 * Record value-dependent access control state
623 #define ACL_RECORD_VALUE_STATE do { \
624 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
625 state->as_recorded |= ACL_STATE_RECORDED_VD; \
626 state->as_vd_acl = a; \
627 AC_MEMCPY( state->as_vd_acl_matches, matches, \
628 sizeof( state->as_vd_acl_matches )) ; \
629 state->as_vd_acl_count = count; \
630 state->as_vd_access = b; \
631 state->as_vd_access_count = i; \
636 * acl_mask - modifies mask based upon the given acl and the
637 * requested access to entry e, attribute attr, value val. if val
638 * is null, access to the whole attribute is assumed (all values).
640 * returns 0 access NOT allowed
644 static slap_control_t
650 AttributeDescription *desc,
655 AccessControlState *state )
657 int i, odnlen, patlen;
660 char accessmaskbuf[ACCESSMASK_MAXLEN];
661 char accessmaskbuf1[ACCESSMASK_MAXLEN];
666 assert( mask != NULL );
667 assert( desc != NULL );
669 attr = desc->ad_cname.bv_val;
671 assert( attr != NULL );
673 Debug( LDAP_DEBUG_ACL,
674 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
677 Debug( LDAP_DEBUG_ACL,
678 "=> acl_mask: to %s by \"%s\", (%s) \n",
679 val ? "value" : "all values",
680 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
681 accessmask2str( *mask, accessmaskbuf ) );
684 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
685 && state->as_vd_acl == a )
687 b = state->as_vd_access;
688 i = state->as_vd_access_count;
695 for ( ; b != NULL; b = b->a_next, i++ ) {
696 slap_mask_t oldmask, modmask;
698 ACL_INVALIDATE( modmask );
700 /* AND <who> clauses */
701 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
702 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
703 b->a_dn_pat.bv_val, 0, 0);
705 * if access applies to the entry itself, and the
706 * user is bound as somebody in the same namespace as
707 * the entry, OR the given dn matches the dn pattern
710 * NOTE: styles "anonymous", "users" and "self"
711 * have been moved to enum slap_style_t, whose
712 * value is set in a_dn_style; however, the string
713 * is maintaned in a_dn_pat.
715 if ( b->a_dn_style == ACL_STYLE_ANONYMOUS ) {
716 if ( op->o_ndn.bv_len != 0 ) {
720 } else if ( b->a_dn_style == ACL_STYLE_USERS ) {
721 if ( op->o_ndn.bv_len == 0 ) {
725 } else if ( b->a_dn_style == ACL_STYLE_SELF ) {
726 if ( op->o_ndn.bv_len == 0 ) {
730 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
734 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
735 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
737 regmatch_t tmp_matches[2],
738 *tmp_matchesp = tmp_matches;
742 switch ( a->acl_dn_style ) {
743 case ACL_STYLE_REGEX:
744 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
745 tmp_matchesp = matches;
749 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
752 tmp_matches[0].rm_so = 0;
753 tmp_matches[0].rm_eo = e->e_nname.bv_len;
758 case ACL_STYLE_SUBTREE:
759 case ACL_STYLE_CHILDREN:
760 tmp_matches[0].rm_so = 0;
761 tmp_matches[0].rm_eo = e->e_nname.bv_len;
762 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
763 tmp_matches[1].rm_eo = e->e_nname.bv_len;
777 if ( !regex_matches( &b->a_dn_pat,
778 op->o_ndn.bv_val, e->e_ndn,
779 tmp_nmatch, tmp_matchesp ) )
789 if ( e->e_dn == NULL )
792 if ( b->a_dn_expand ) {
794 char buf[ACL_BUF_SIZE];
797 regmatch_t tmp_matches[2],
798 *tmp_matchesp = tmp_matches;
802 bv.bv_len = sizeof( buf ) - 1;
805 switch ( a->acl_dn_style ) {
806 case ACL_STYLE_REGEX:
807 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
808 tmp_matchesp = matches;
812 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
815 tmp_matches[0].rm_so = 0;
816 tmp_matches[0].rm_eo = e->e_nname.bv_len;
821 case ACL_STYLE_SUBTREE:
822 case ACL_STYLE_CHILDREN:
823 tmp_matches[0].rm_so = 0;
824 tmp_matches[0].rm_eo = e->e_nname.bv_len;
825 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
826 tmp_matches[1].rm_eo = e->e_nname.bv_len;
840 if ( string_expand( &bv, &b->a_dn_pat,
842 tmp_nmatch, tmp_matchesp ) )
847 if ( dnNormalize(0, NULL, NULL, &bv,
848 &pat, op->o_tmpmemctx )
851 /* did not expand to a valid dn */
860 odnlen = op->o_ndn.bv_len;
861 if ( odnlen < patlen ) {
862 goto dn_match_cleanup;
866 if ( b->a_dn_style == ACL_STYLE_BASE ) {
867 /* base dn -- entire object DN must match */
868 if ( odnlen != patlen ) {
869 goto dn_match_cleanup;
872 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
875 if ( odnlen <= patlen ) {
876 goto dn_match_cleanup;
879 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
880 goto dn_match_cleanup;
883 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
884 if ( rdnlen != odnlen - patlen - 1 ) {
885 goto dn_match_cleanup;
888 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
889 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
890 goto dn_match_cleanup;
893 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
894 if ( odnlen <= patlen ) {
895 goto dn_match_cleanup;
898 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
899 goto dn_match_cleanup;
903 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
906 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
907 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
916 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
917 if ( ! op->o_conn->c_listener ) {
920 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
921 b->a_sockurl_pat.bv_val, 0, 0 );
923 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
924 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
925 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
926 e->e_ndn, nmatch, matches ) )
931 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
933 char buf[ACL_BUF_SIZE];
935 bv.bv_len = sizeof( buf ) - 1;
937 if ( string_expand( &bv, &b->a_sockurl_pat,
938 e->e_ndn, nmatch, matches ) )
943 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
949 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
957 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
958 if ( !op->o_conn->c_peer_domain.bv_val ) {
961 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
962 b->a_domain_pat.bv_val, 0, 0 );
963 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
964 if ( b->a_domain_style == ACL_STYLE_REGEX) {
965 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
966 e->e_ndn, nmatch, matches ) )
971 char buf[ACL_BUF_SIZE];
973 struct berval cmp = op->o_conn->c_peer_domain;
974 struct berval pat = b->a_domain_pat;
976 if ( b->a_domain_expand ) {
979 bv.bv_len = sizeof(buf) - 1;
982 if ( string_expand(&bv, &b->a_domain_pat,
983 e->e_ndn, nmatch, matches) )
990 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
991 int offset = cmp.bv_len - pat.bv_len;
996 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1000 /* trim the domain */
1001 cmp.bv_val = &cmp.bv_val[ offset ];
1002 cmp.bv_len -= offset;
1005 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1012 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1013 if ( !op->o_conn->c_peer_name.bv_val ) {
1016 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1017 b->a_peername_pat.bv_val, 0, 0 );
1018 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1019 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1020 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1021 e->e_ndn, nmatch, matches ) )
1027 /* try exact match */
1028 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1029 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1033 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1035 char buf[ACL_BUF_SIZE];
1037 bv.bv_len = sizeof( buf ) - 1;
1039 if ( string_expand( &bv, &b->a_peername_pat,
1040 e->e_ndn, nmatch, matches ) )
1045 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1049 /* extract IP and try exact match */
1050 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1052 char buf[] = "255.255.255.255";
1055 int port_number = -1;
1057 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1058 aci_bv_ip_eq.bv_val, aci_bv_ip_eq.bv_len ) != 0 )
1061 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_ip_eq.bv_len;
1062 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_ip_eq.bv_len;
1064 port = strrchr( ip.bv_val, ':' );
1068 ip.bv_len = port - ip.bv_val;
1070 port_number = strtol( port, &next, 10 );
1071 if ( next[0] != '\0' )
1075 /* the port check can be anticipated here */
1076 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1079 /* address longer than expected? */
1080 if ( ip.bv_len >= sizeof(buf) )
1083 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1084 buf[ ip.bv_len ] = '\0';
1086 addr = inet_addr( buf );
1088 /* unable to convert? */
1089 if ( addr == (unsigned long)(-1) )
1092 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1095 #ifdef LDAP_PF_LOCAL
1096 /* extract path and try exact match */
1097 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1100 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1101 aci_bv_path_eq.bv_val, aci_bv_path_eq.bv_len ) != 0 )
1104 path.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_path_eq.bv_len;
1105 path.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_path_eq.bv_len;
1107 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1110 #endif /* LDAP_PF_LOCAL */
1112 /* exact match (very unlikely...) */
1113 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1120 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1121 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1124 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1125 b->a_sockname_pat.bv_val, 0, 0 );
1126 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1127 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1128 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1129 e->e_ndn, nmatch, matches ) )
1134 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1136 char buf[ACL_BUF_SIZE];
1138 bv.bv_len = sizeof( buf ) - 1;
1140 if ( string_expand( &bv, &b->a_sockname_pat,
1141 e->e_ndn, nmatch, matches ) )
1146 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1151 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1158 if ( b->a_dn_at != NULL ) {
1163 const char *attr = b->a_dn_at->ad_cname.bv_val;
1165 assert( attr != NULL );
1167 if ( op->o_ndn.bv_len == 0 ) {
1171 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
1175 /* see if asker is listed in dnattr */
1176 for( at = attrs_find( e->e_attrs, b->a_dn_at );
1178 at = attrs_find( at->a_next, b->a_dn_at ) )
1180 if( value_find_ex( b->a_dn_at,
1181 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1182 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1184 &bv, op->o_tmpmemctx ) == 0 )
1193 /* have a dnattr match. if this is a self clause then
1194 * the target must also match the op dn.
1196 if ( b->a_dn_self ) {
1197 /* check if the target is an attribute. */
1198 if ( val == NULL ) continue;
1200 /* target is attribute, check if the attribute value
1203 rc = value_match( &match, b->a_dn_at,
1204 b->a_dn_at->ad_type->sat_equality, 0,
1206 /* on match error or no match, fail the ACL clause */
1207 if (rc != LDAP_SUCCESS || match != 0 )
1211 /* no dnattr match, check if this is a self clause */
1212 if ( ! b->a_dn_self )
1215 ACL_RECORD_VALUE_STATE;
1217 /* this is a self clause, check if the target is an
1223 /* target is attribute, check if the attribute value
1226 rc = value_match( &match, b->a_dn_at,
1227 b->a_dn_at->ad_type->sat_equality, 0,
1230 /* on match error or no match, fail the ACL clause */
1231 if (rc != LDAP_SUCCESS || match != 0 )
1236 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1238 struct berval ndn = BER_BVNULL;
1241 if ( op->o_ndn.bv_len == 0 ) {
1245 /* b->a_group is an unexpanded entry name, expanded it should be an
1246 * entry with objectclass group* and we test to see if odn is one of
1247 * the values in the attribute group
1249 /* see if asker is listed in dnattr */
1250 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1251 char buf[ACL_BUF_SIZE];
1253 regmatch_t tmp_matches[2],
1254 *tmp_matchesp = tmp_matches;
1256 bv.bv_len = sizeof(buf) - 1;
1261 switch ( a->acl_dn_style ) {
1262 case ACL_STYLE_REGEX:
1263 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1264 tmp_matchesp = matches;
1265 tmp_nmatch = nmatch;
1269 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1270 case ACL_STYLE_BASE:
1271 tmp_matches[0].rm_so = 0;
1272 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1277 case ACL_STYLE_SUBTREE:
1278 case ACL_STYLE_CHILDREN:
1279 tmp_matches[0].rm_so = 0;
1280 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1281 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1282 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1296 if ( string_expand( &bv, &b->a_group_pat,
1298 tmp_nmatch, tmp_matchesp ) )
1303 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1304 op->o_tmpmemctx ) != LDAP_SUCCESS )
1306 /* did not expand to a valid dn */
1313 bv = b->a_group_pat;
1316 rc = backend_group( op, e, &bv, &op->o_ndn,
1317 b->a_group_oc, b->a_group_at );
1320 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1328 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1330 char buf[ACL_BUF_SIZE];
1332 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1334 regmatch_t tmp_matches[2],
1335 *tmp_matchesp = tmp_matches;
1338 bv.bv_len = sizeof( buf ) - 1;
1343 switch ( a->acl_dn_style ) {
1344 case ACL_STYLE_REGEX:
1345 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1346 tmp_matchesp = matches;
1347 tmp_nmatch = nmatch;
1351 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1352 case ACL_STYLE_BASE:
1353 tmp_matches[0].rm_so = 0;
1354 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1359 case ACL_STYLE_SUBTREE:
1360 case ACL_STYLE_CHILDREN:
1361 tmp_matches[0].rm_so = 0;
1362 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1363 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1364 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1378 if ( string_expand( &bv, &b->a_set_pat,
1380 tmp_nmatch, tmp_matchesp ) )
1389 if ( aci_match_set( &bv, op, e, 0 ) == 0 ) {
1394 if ( b->a_authz.sai_ssf ) {
1395 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1396 b->a_authz.sai_ssf, op->o_ssf, 0 );
1397 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1402 if ( b->a_authz.sai_transport_ssf ) {
1403 Debug( LDAP_DEBUG_ACL,
1404 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1405 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1406 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1411 if ( b->a_authz.sai_tls_ssf ) {
1412 Debug( LDAP_DEBUG_ACL,
1413 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1414 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1415 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1420 if ( b->a_authz.sai_sasl_ssf ) {
1421 Debug( LDAP_DEBUG_ACL,
1422 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1423 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1424 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1430 if ( b->a_dynacl ) {
1432 slap_access_t tgrant, tdeny;
1434 /* this case works different from the others above.
1435 * since aci's themselves give permissions, we need
1436 * to first check b->a_access_mask, the ACL's access level.
1438 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1439 /* no ACIs in the root DSE */
1443 /* first check if the right being requested
1444 * is allowed by the ACL clause.
1446 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1450 /* start out with nothing granted, nothing denied */
1454 for ( da = b->a_dynacl; da; da = da->da_next ) {
1455 slap_access_t grant, deny;
1457 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1463 /* remove anything that the ACL clause does not allow */
1464 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1465 tdeny &= ACL_PRIV_MASK;
1467 /* see if we have anything to contribute */
1468 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1472 /* this could be improved by changing acl_mask so that it can deal with
1473 * by clauses that return grant/deny pairs. Right now, it does either
1474 * additive or subtractive rights, but not both at the same time. So,
1475 * we need to combine the grant/deny pair into a single rights mask in
1476 * a smart way: if either grant or deny is "empty", then we use the
1477 * opposite as is, otherwise we remove any denied rights from the grant
1478 * rights mask and construct an additive mask.
1480 if (ACL_IS_INVALID(tdeny)) {
1481 modmask = tgrant | ACL_PRIV_ADDITIVE;
1483 } else if (ACL_IS_INVALID(tgrant)) {
1484 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1487 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1491 #else /* !SLAP_DYNACL */
1493 #ifdef SLAPD_ACI_ENABLED
1494 if ( b->a_aci_at != NULL ) {
1496 slap_access_t grant, deny, tgrant, tdeny;
1497 struct berval parent_ndn,
1498 old_parent_ndn = BER_BVNULL;
1499 BerVarray bvals = NULL;
1502 /* this case works different from the others above.
1503 * since aci's themselves give permissions, we need
1504 * to first check b->a_access_mask, the ACL's access level.
1507 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1508 /* no ACIs in the root DSE */
1512 /* first check if the right being requested
1513 * is allowed by the ACL clause.
1515 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1518 /* start out with nothing granted, nothing denied */
1522 /* get the aci attribute */
1523 at = attr_find( e->e_attrs, b->a_aci_at );
1526 /* FIXME: this breaks acl caching;
1527 * see also ACL_RECORD_VALUE_STATE below */
1528 ACL_RECORD_VALUE_STATE;
1530 /* the aci is an multi-valued attribute. The
1531 * rights are determined by OR'ing the individual
1532 * rights given by the acis.
1534 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
1539 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0)
1545 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1546 accessmask2str(tgrant,accessmaskbuf),
1547 accessmask2str(tdeny, accessmaskbuf1), 0);
1550 /* If the entry level aci didn't contain anything valid for the
1551 * current operation, climb up the tree and evaluate the
1552 * acis with scope set to subtree
1554 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
1555 dnParent(&(e->e_nname), &parent_ndn);
1556 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ) {
1557 old_parent_ndn = parent_ndn;
1558 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1559 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
1567 for( i = 0; bvals[i].bv_val != NULL; i++){
1569 /* FIXME: this breaks acl caching;
1570 * see also ACL_RECORD_VALUE_STATE above */
1571 ACL_RECORD_VALUE_STATE;
1573 if (aci_mask(op, e, desc, val, &bvals[i],
1575 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
1579 /* evaluation stops as soon as either a "deny" or a
1580 * "grant" directive matches.
1582 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1586 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1587 accessmask2str(tgrant,accessmaskbuf),
1588 accessmask2str(tdeny, accessmaskbuf1), 0);
1592 case LDAP_NO_SUCH_ATTRIBUTE:
1593 /* just go on if the aci-Attribute is not present in
1596 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1600 case LDAP_NO_SUCH_OBJECT:
1601 /* We have reached the base object */
1602 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1613 dnParent(&old_parent_ndn, &parent_ndn);
1618 /* remove anything that the ACL clause does not allow */
1619 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1620 tdeny &= ACL_PRIV_MASK;
1622 /* see if we have anything to contribute */
1623 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1627 /* this could be improved by changing acl_mask so that it can deal with
1628 * by clauses that return grant/deny pairs. Right now, it does either
1629 * additive or subtractive rights, but not both at the same time. So,
1630 * we need to combine the grant/deny pair into a single rights mask in
1631 * a smart way: if either grant or deny is "empty", then we use the
1632 * opposite as is, otherwise we remove any denied rights from the grant
1633 * rights mask and construct an additive mask.
1635 if (ACL_IS_INVALID(tdeny)) {
1636 modmask = tgrant | ACL_PRIV_ADDITIVE;
1638 } else if (ACL_IS_INVALID(tgrant)) {
1639 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1642 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1646 #endif /* SLAPD_ACI_ENABLED */
1647 #endif /* !SLAP_DYNACL */
1649 modmask = b->a_access_mask;
1652 Debug( LDAP_DEBUG_ACL,
1653 "<= acl_mask: [%d] applying %s (%s)\n",
1654 i, accessmask2str( modmask, accessmaskbuf ),
1655 b->a_type == ACL_CONTINUE
1657 : b->a_type == ACL_BREAK
1663 if( ACL_IS_ADDITIVE(modmask) ) {
1665 ACL_PRIV_SET( *mask, modmask );
1668 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1670 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1671 /* substract privs */
1672 ACL_PRIV_CLR( *mask, modmask );
1675 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1682 Debug( LDAP_DEBUG_ACL,
1683 "<= acl_mask: [%d] mask: %s\n",
1684 i, accessmask2str(*mask, accessmaskbuf), 0 );
1686 if( b->a_type == ACL_CONTINUE ) {
1689 } else if ( b->a_type == ACL_BREAK ) {
1697 /* implicit "by * none" clause */
1700 Debug( LDAP_DEBUG_ACL,
1701 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1702 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1707 * acl_check_modlist - check access control on the given entry to see if
1708 * it allows the given modifications by the user associated with op.
1709 * returns 1 if mods allowed ok
1710 * 0 mods not allowed
1717 Modifications *mlist
1721 AccessControlState state = ACL_STATE_INIT;
1724 int ret = 1; /* default is access allowed */
1732 assert( be != NULL );
1734 /* short circuit root database access */
1735 if ( be_isroot( op ) ) {
1736 Debug( LDAP_DEBUG_ACL,
1737 "<= acl_access_allowed: granted to database root\n",
1742 /* use backend default access if no backend acls */
1743 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1744 Debug( LDAP_DEBUG_ACL,
1745 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1746 access2str( ACL_WRITE ),
1747 op->o_bd->be_dfltaccess >= ACL_WRITE
1748 ? "granted" : "denied",
1750 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
1754 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1756 * no-user-modification operational attributes are ignored
1757 * by ACL_WRITE checking as any found here are not provided
1760 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1761 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1762 " modify access granted\n",
1763 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1767 switch ( mlist->sml_op ) {
1768 case LDAP_MOD_REPLACE:
1770 * We must check both permission to delete the whole
1771 * attribute and permission to add the specific attributes.
1772 * This prevents abuse from selfwriters.
1774 if ( ! access_allowed( op, e,
1775 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1781 if ( mlist->sml_values == NULL ) break;
1783 /* fall thru to check value to add */
1786 assert( mlist->sml_values != NULL );
1788 for ( bv = mlist->sml_nvalues
1789 ? mlist->sml_nvalues : mlist->sml_values;
1790 bv->bv_val != NULL; bv++ )
1792 if ( ! access_allowed( op, e,
1793 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1801 case LDAP_MOD_DELETE:
1802 if ( mlist->sml_values == NULL ) {
1803 if ( ! access_allowed( op, e,
1804 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1811 for ( bv = mlist->sml_nvalues
1812 ? mlist->sml_nvalues : mlist->sml_values;
1813 bv->bv_val != NULL; bv++ )
1815 if ( ! access_allowed( op, e,
1816 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1824 case SLAP_MOD_SOFTADD:
1825 /* allow adding attribute via modrdn thru */
1837 if (be_null) op->o_bd = NULL;
1843 struct berval *list,
1856 while ( len >= 0 && --ix >= 0 ) {
1857 while ( --len >= 0 && *p++ != sep )
1860 while ( len >= 0 && *p == ' ' ) {
1873 while ( --len >= 0 && *p != sep ) {
1877 while ( bv->bv_len > 0 && *--p == ' ' ) {
1884 typedef struct aci_set_gather_t {
1890 aci_set_cb_gather( Operation *op, SlapReply *rs )
1892 aci_set_gather_t *p = (aci_set_gather_t *)op->o_callback->sc_private;
1894 if ( rs->sr_type == REP_SEARCH ) {
1895 BerValue bvals[ 2 ];
1896 BerVarray bvalsp = NULL;
1899 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
1900 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
1902 if ( desc == slap_schema.si_ad_entryDN ) {
1904 bvals[ 0 ] = rs->sr_entry->e_nname;
1905 BER_BVZERO( &bvals[ 1 ] );
1910 a = attr_find( rs->sr_entry->e_attrs, desc );
1914 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
1917 bvalsp = a->a_nvals;
1923 p->bvals = slap_set_join( p->cookie, p->bvals,
1924 ( '|' | SLAP_SET_RREF ), bvalsp );
1928 assert( rs->sr_type == REP_RESULT );
1935 aci_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
1937 AciSetCookie *cp = (AciSetCookie *)cookie;
1939 LDAPURLDesc *ludp = NULL;
1940 Operation op2 = { 0 };
1941 SlapReply rs = {REP_RESULT};
1942 AttributeName anlist[ 2 ], *anlistp = NULL;
1944 slap_callback cb = { NULL, aci_set_cb_gather, NULL, NULL };
1945 aci_set_gather_t p = { 0 };
1946 const char *text = NULL;
1947 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
1949 /* this routine needs to return the bervals instead of
1950 * plain strings, since syntax is not known. It should
1951 * also return the syntax or some "comparison cookie".
1953 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
1954 return aci_set_gather2( cookie, name, desc );
1957 rc = ldap_url_parse( name->bv_val, &ludp );
1958 if ( rc != LDAP_URL_SUCCESS ) {
1959 rc = LDAP_PROTOCOL_ERROR;
1963 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
1965 /* host part must be empty */
1966 /* extensions parts must be empty */
1967 rc = LDAP_PROTOCOL_ERROR;
1971 /* Grab the searchbase and see if an appropriate database can be found */
1972 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
1973 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
1974 &op2.o_req_ndn, cp->op->o_tmpmemctx );
1975 BER_BVZERO( &op2.o_req_dn );
1976 if ( rc != LDAP_SUCCESS ) {
1980 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
1981 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
1982 rc = LDAP_NO_SUCH_OBJECT;
1986 /* Grab the filter */
1987 if ( ludp->lud_filter ) {
1988 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
1989 cp->op->o_tmpmemctx );
1992 op2.ors_filterstr = defaultFilter_bv;
1995 op2.ors_filter = str2filter_x( cp->op, op2.ors_filterstr.bv_val );
1996 if ( op2.ors_filter == NULL ) {
1997 rc = LDAP_PROTOCOL_ERROR;
2001 /* Grab the scope */
2002 op2.ors_scope = ludp->lud_scope;
2004 /* Grap the attributes */
2005 if ( ludp->lud_attrs ) {
2006 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2009 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2010 cp->op->o_tmpmemctx );
2012 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2013 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2014 anlistp[ nattrs ].an_desc = NULL;
2015 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2016 &anlistp[ nattrs ].an_desc, &text );
2017 if ( rc != LDAP_SUCCESS ) {
2026 anlistp[ nattrs ].an_name = desc->ad_cname;
2027 anlistp[ nattrs ].an_desc = desc;
2029 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2033 op2.o_hdr = cp->op->o_hdr;
2034 op2.o_tag = LDAP_REQ_SEARCH;
2035 op2.o_ndn = op2.o_bd->be_rootndn;
2036 op2.o_callback = &cb;
2037 op2.o_time = slap_get_time();
2038 op2.o_do_not_cache = 1;
2039 op2.o_is_auth_check = 0;
2040 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->op->o_tmpmemctx );
2041 op2.ors_slimit = SLAP_NO_LIMIT;
2042 op2.ors_tlimit = SLAP_NO_LIMIT;
2043 op2.ors_attrs = anlistp;
2044 op2.ors_attrsonly = 0;
2048 rc = op2.o_bd->be_search( &op2, &rs );
2054 if ( op2.ors_filter ) {
2055 filter_free_x( cp->op, op2.ors_filter );
2057 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2058 slap_sl_free( op2.o_req_ndn.bv_val, cp->op->o_tmpmemctx );
2060 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2061 slap_sl_free( op2.o_req_dn.bv_val, cp->op->o_tmpmemctx );
2064 ldap_free_urldesc( ludp );
2066 if ( anlistp && anlistp != anlist ) {
2067 slap_sl_free( anlistp, cp->op->o_tmpmemctx );
2074 aci_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2076 AciSetCookie *cp = (AciSetCookie *)cookie;
2077 BerVarray bvals = NULL;
2081 /* this routine needs to return the bervals instead of
2082 * plain strings, since syntax is not known. It should
2083 * also return the syntax or some "comparison cookie".
2085 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
2086 if ( rc == LDAP_SUCCESS ) {
2087 if ( desc == slap_schema.si_ad_entryDN ) {
2088 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2089 cp->op->o_tmpmemctx );
2091 BER_BVZERO( &bvals[ 1 ] );
2095 backend_attribute( cp->op,
2096 cp->e, &ndn, desc, &bvals, ACL_NONE );
2099 if ( !BER_BVISNULL( &ndn ) ) {
2100 slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
2109 struct berval *subj,
2115 struct berval set = BER_BVNULL;
2117 AciSetCookie cookie;
2119 if ( setref == 0 ) {
2120 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2123 struct berval subjdn, ndn = BER_BVNULL;
2124 struct berval setat;
2127 AttributeDescription *desc = NULL;
2129 /* format of string is "entry/setAttrName" */
2130 if ( aci_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2134 if ( aci_get_part( subj, 1, '/', &setat ) < 0 ) {
2135 setat = aci_bv_set_attr;
2139 * NOTE: dnNormalize honors the ber_len field
2140 * as the length of the dn to be normalized
2142 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2143 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2145 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2146 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2150 BER_BVZERO( &bvals[0] );
2151 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2153 bvals[0].bv_val = bvals[i-1].bv_val;
2154 BER_BVZERO( &bvals[i-1] );
2156 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2157 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2162 if ( !BER_BVISNULL( &set ) ) {
2165 rc = ( slap_set_filter( aci_set_gather, (SetCookie *)&cookie, &set,
2166 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2167 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2173 #ifdef SLAPD_ACI_ENABLED
2175 aci_list_map_rights(
2176 struct berval *list )
2183 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2186 switch (*bv.bv_val) {
2188 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2191 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
2192 * the right 's' to mean "set", but in the examples states
2193 * that the right 's' means "search". The latter definition
2196 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2199 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2202 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2205 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
2206 * define any equivalent to the AUTH right, so I've just used
2209 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2221 struct berval *list,
2222 const struct berval *attr,
2223 struct berval *val )
2225 struct berval bv, left, right;
2228 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2229 if (aci_get_part(&bv, 0, '=', &left) < 0
2230 || aci_get_part(&bv, 1, '=', &right) < 0)
2232 if (ber_bvstrcasecmp(attr, &bv) == 0)
2234 } else if (val == NULL) {
2235 if (ber_bvstrcasecmp(attr, &left) == 0)
2238 if (ber_bvstrcasecmp(attr, &left) == 0) {
2239 /* this is experimental code that implements a
2240 * simple (prefix) match of the attribute value.
2241 * the ACI draft does not provide for aci's that
2242 * apply to specific values, but it would be
2243 * nice to have. If the <attr> part of an aci's
2244 * rights list is of the form <attr>=<value>,
2245 * that means the aci applies only to attrs with
2246 * the given value. Furthermore, if the attr is
2247 * of the form <attr>=<value>*, then <value> is
2248 * treated as a prefix, and the aci applies to
2249 * any value with that prefix.
2251 * Ideally, this would allow r.e. matches.
2253 if (aci_get_part(&right, 0, '*', &left) < 0
2254 || right.bv_len <= left.bv_len)
2256 if (ber_bvstrcasecmp(val, &right) == 0)
2258 } else if (val->bv_len >= left.bv_len) {
2259 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
2268 static slap_access_t
2269 aci_list_get_attr_rights(
2270 struct berval *list,
2271 const struct berval *attr,
2272 struct berval *val )
2278 /* loop through each rights/attr pair, skip first part (action) */
2280 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
2281 if (aci_list_has_attr(&bv, attr, val) == 0)
2283 if (aci_get_part(list, i, ';', &bv) < 0)
2285 mask |= aci_list_map_rights(&bv);
2291 aci_list_get_rights(
2292 struct berval *list,
2293 const struct berval *attr,
2295 slap_access_t *grant,
2296 slap_access_t *deny )
2298 struct berval perm, actn;
2299 slap_access_t *mask;
2302 if (attr == NULL || attr->bv_len == 0
2303 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
2304 attr = &aci_bv_br_entry;
2310 /* loop through each permissions clause */
2311 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
2312 if (aci_get_part(&perm, 0, ';', &actn) < 0)
2314 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
2316 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
2323 *mask |= aci_list_get_attr_rights(&perm, attr, val);
2324 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
2331 struct berval *subj,
2332 struct berval *defgrpoc,
2333 struct berval *defgrpat,
2340 struct berval subjdn;
2341 struct berval grpoc;
2342 struct berval grpat;
2343 ObjectClass *grp_oc = NULL;
2344 AttributeDescription *grp_ad = NULL;
2348 /* format of string is "group/objectClassValue/groupAttrName" */
2349 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
2353 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
2357 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
2361 rc = slap_bv2ad( &grpat, &grp_ad, &text );
2362 if( rc != LDAP_SUCCESS ) {
2368 grp_oc = oc_bvfind( &grpoc );
2370 if (grp_oc != NULL && grp_ad != NULL ) {
2371 char buf[ACL_BUF_SIZE];
2372 struct berval bv, ndn;
2373 bv.bv_len = sizeof( buf ) - 1;
2374 bv.bv_val = (char *)&buf;
2375 if ( string_expand(&bv, &subjdn,
2376 e->e_ndn, nmatch, matches) )
2381 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
2382 rc = ( backend_group( op, e, &ndn, &op->o_ndn,
2383 grp_oc, grp_ad ) == 0 );
2384 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2396 AttributeDescription *desc,
2400 regmatch_t *matches,
2401 slap_access_t *grant,
2402 slap_access_t *deny,
2403 slap_aci_scope_t asserted_scope
2406 struct berval bv, scope, perms, type, sdn;
2410 assert( !BER_BVISNULL( &desc->ad_cname ) );
2412 /* parse an aci of the form:
2413 oid # scope # action;rights;attr;rights;attr
2414 $ action;rights;attr;rights;attr # type # subject
2416 [NOTE: the following comment is very outdated,
2417 as the draft version it refers to (Ando, 2004-11-20)].
2419 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
2420 a full description of the format for this attribute.
2421 Differences: "this" in the draft is "self" here, and
2422 "self" and "public" is in the position of type.
2424 <scope> = {entry|children|subtree}
2425 <type> = {public|users|access-id|subtree|onelevel|children|
2426 self|dnattr|group|role|set|set-ref}
2428 This routine now supports scope={ENTRY,CHILDREN}
2430 - ENTRY applies to "entry" and "subtree";
2431 - CHILDREN aplies to "children" and "subtree"
2434 /* check that the aci has all 5 components */
2435 if ( aci_get_part( aci, 4, '#', NULL ) < 0 ) {
2439 /* check that the aci family is supported */
2440 if ( aci_get_part( aci, 0, '#', &bv ) < 0 ) {
2444 /* check that the scope matches */
2445 if ( aci_get_part( aci, 1, '#', &scope ) < 0 ) {
2449 /* note: scope can be either ENTRY or CHILDREN;
2450 * they respectively match "entry" and "children" in bv
2451 * both match "subtree" */
2452 switch ( asserted_scope ) {
2453 case SLAP_ACI_SCOPE_ENTRY:
2454 if ( ber_bvstrcasecmp( &scope, &aci_bv_entry ) != 0
2455 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2461 case SLAP_ACI_SCOPE_CHILDREN:
2462 if ( ber_bvstrcasecmp( &scope, &aci_bv_children ) != 0
2463 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2473 /* get the list of permissions clauses, bail if empty */
2474 if ( aci_get_part( aci, 2, '#', &perms ) <= 0 ) {
2478 /* check if any permissions allow desired access */
2479 if ( aci_list_get_rights( &perms, &desc->ad_cname, val, grant, deny ) == 0 ) {
2483 /* see if we have a DN match */
2484 if ( aci_get_part( aci, 3, '#', &type ) < 0 ) {
2488 /* see if we have a public (i.e. anonymous) access */
2489 if ( ber_bvstrcasecmp( &aci_bv_public, &type ) == 0 ) {
2493 /* otherwise require an identity */
2494 if ( BER_BVISNULL( &op->o_ndn ) || BER_BVISEMPTY( &op->o_ndn ) ) {
2498 /* see if we have a users access */
2499 if ( ber_bvstrcasecmp( &aci_bv_users, &type ) == 0 ) {
2503 /* NOTE: this may fail if a DN contains a valid '#' (unescaped);
2504 * just grab all the berval up to its end (ITS#3303).
2505 * NOTE: the problem could be solved by providing the DN with
2506 * the embedded '#' encoded as hexpairs: "cn=Foo#Bar" would
2507 * become "cn=Foo\23Bar" and be safely used by aci_mask(). */
2509 if ( aci_get_part( aci, 4, '#', &sdn ) < 0 ) {
2513 sdn.bv_val = type.bv_val + type.bv_len + STRLENOF( "#" );
2514 sdn.bv_len = aci->bv_len - ( sdn.bv_val - aci->bv_val );
2516 if ( ber_bvstrcasecmp( &aci_bv_access_id, &type ) == 0 ) {
2519 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2520 if ( rc != LDAP_SUCCESS ) {
2524 if ( dn_match( &op->o_ndn, &ndn ) ) {
2527 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2531 } else if ( ber_bvstrcasecmp( &aci_bv_subtree, &type ) == 0 ) {
2534 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2535 if ( rc != LDAP_SUCCESS ) {
2539 if ( dnIsSuffix( &op->o_ndn, &ndn ) ) {
2542 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2546 } else if ( ber_bvstrcasecmp( &aci_bv_onelevel, &type ) == 0 ) {
2547 struct berval ndn, pndn;
2549 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2550 if ( rc != LDAP_SUCCESS ) {
2554 dnParent( &ndn, &pndn );
2556 if ( dn_match( &op->o_ndn, &pndn ) ) {
2559 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2563 } else if ( ber_bvstrcasecmp( &aci_bv_children, &type ) == 0 ) {
2566 rc = dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx );
2567 if ( rc != LDAP_SUCCESS ) {
2571 if ( !dn_match( &op->o_ndn, &ndn )
2572 && dnIsSuffix( &op->o_ndn, &ndn ) )
2576 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2580 } else if ( ber_bvstrcasecmp( &aci_bv_self, &type ) == 0 ) {
2581 if ( dn_match( &op->o_ndn, &e->e_nname ) ) {
2585 } else if ( ber_bvstrcasecmp( &aci_bv_dnattr, &type ) == 0 ) {
2587 AttributeDescription *ad = NULL;
2590 rc = slap_bv2ad( &sdn, &ad, &text );
2592 if( rc != LDAP_SUCCESS ) {
2598 for ( at = attrs_find( e->e_attrs, ad );
2600 at = attrs_find( at->a_next, ad ) )
2602 if ( value_find_ex( ad,
2603 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
2604 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
2606 &op->o_ndn, op->o_tmpmemctx ) == 0 )
2615 } else if ( ber_bvstrcasecmp( &aci_bv_group, &type ) == 0 ) {
2616 if ( aci_group_member( &sdn, &aci_bv_group_class,
2617 &aci_bv_group_attr, op, e, nmatch, matches ) )
2622 } else if ( ber_bvstrcasecmp( &aci_bv_role, &type ) == 0 ) {
2623 if ( aci_group_member( &sdn, &aci_bv_role_class,
2624 &aci_bv_role_attr, op, e, nmatch, matches ) )
2629 } else if ( ber_bvstrcasecmp( &aci_bv_set, &type ) == 0 ) {
2630 if ( aci_match_set( &sdn, op, e, 0 ) ) {
2634 } else if ( ber_bvstrcasecmp( &aci_bv_set_ref, &type ) == 0 ) {
2635 if ( aci_match_set( &sdn, op, e, 1 ) ) {
2645 dynacl_aci_parse( const char *fname, int lineno, slap_style_t sty, const char *right, void **privp )
2647 AttributeDescription *ad = NULL;
2648 const char *text = NULL;
2650 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
2651 fprintf( stderr, "%s: line %d: "
2652 "inappropriate style \"%s\" in \"aci\" by clause\n",
2653 fname, lineno, sty );
2657 if ( right != NULL && *right != '\0' ) {
2658 if ( slap_str2ad( right, &ad, &text ) != LDAP_SUCCESS ) {
2660 "%s: line %d: aci \"%s\": %s\n",
2661 fname, lineno, right, text );
2666 ad = slap_schema.si_ad_aci;
2669 if ( !is_at_syntax( ad->ad_type, SLAPD_ACI_SYNTAX) ) {
2670 fprintf( stderr, "%s: line %d: "
2671 "aci \"%s\": inappropriate syntax: %s\n",
2672 fname, lineno, right,
2673 ad->ad_type->sat_syntax_oid );
2677 *privp = (void *)ad;
2683 dynacl_aci_print( void *priv )
2685 AttributeDescription *ad = ( AttributeDescription * )priv;
2689 fprintf( stderr, " aci=%s", ad->ad_cname.bv_val );
2700 AttributeDescription *desc,
2703 regmatch_t *matches,
2704 slap_access_t *grantp,
2705 slap_access_t *denyp )
2707 AttributeDescription *ad = ( AttributeDescription * )priv;
2709 slap_access_t tgrant, tdeny, grant, deny;
2711 char accessmaskbuf[ACCESSMASK_MAXLEN];
2712 char accessmaskbuf1[ACCESSMASK_MAXLEN];
2713 #endif /* LDAP_DEBUG */
2715 /* start out with nothing granted, nothing denied */
2719 /* get the aci attribute */
2720 at = attr_find( e->e_attrs, ad );
2724 /* the aci is an multi-valued attribute. The
2725 * rights are determined by OR'ing the individual
2726 * rights given by the acis.
2728 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2729 if ( aci_mask( op, e, desc, val, &at->a_nvals[i],
2730 nmatch, matches, &grant, &deny,
2731 SLAP_ACI_SCOPE_ENTRY ) != 0 )
2738 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2739 accessmask2str( tgrant, accessmaskbuf ),
2740 accessmask2str( tdeny, accessmaskbuf1 ), 0 );
2743 /* If the entry level aci didn't contain anything valid for the
2744 * current operation, climb up the tree and evaluate the
2745 * acis with scope set to subtree
2747 if ( tgrant == ACL_PRIV_NONE && tdeny == ACL_PRIV_NONE ) {
2748 struct berval parent_ndn;
2749 struct berval old_parent_ndn = BER_BVNULL;
2752 /* to solve the chicken'n'egg problem of accessing
2753 * the OpenLDAPaci attribute, the direct access
2754 * to the entry's attribute is unchecked; however,
2755 * further accesses to OpenLDAPaci values in the
2756 * ancestors occur through backend_attribute(), i.e.
2757 * with the identity of the operation, requiring
2758 * further access checking. For uniformity, this
2759 * makes further requests occur as the rootdn, if
2760 * any, i.e. searching for the OpenLDAPaci attribute
2761 * is considered an internal search. If this is not
2762 * acceptable, then the same check needs be performed
2763 * when accessing the entry's attribute. */
2764 Operation op2 = *op;
2766 if ( !BER_BVISNULL( &op->o_bd->be_rootndn ) ) {
2767 op2.o_dn = op->o_bd->be_rootdn;
2768 op2.o_ndn = op->o_bd->be_rootndn;
2772 dnParent( &e->e_nname, &parent_ndn );
2773 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ){
2775 BerVarray bvals = NULL;
2778 old_parent_ndn = parent_ndn;
2779 Debug( LDAP_DEBUG_ACL, "checking ACI of \"%s\"\n", parent_ndn.bv_val, 0, 0 );
2780 ret = backend_attribute( &op2, NULL, &parent_ndn, ad, &bvals, ACL_AUTH );
2789 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++) {
2790 if ( aci_mask( op, e, desc, val,
2794 SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2798 /* evaluation stops as soon as either a "deny" or a
2799 * "grant" directive matches.
2801 if ( tgrant != ACL_PRIV_NONE || tdeny != ACL_PRIV_NONE ) {
2805 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2806 accessmask2str( tgrant, accessmaskbuf ),
2807 accessmask2str( tdeny, accessmaskbuf1 ), 0 );
2811 case LDAP_NO_SUCH_ATTRIBUTE:
2812 /* just go on if the aci-Attribute is not present in
2815 Debug( LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0 );
2819 case LDAP_NO_SUCH_OBJECT:
2820 /* We have reached the base object */
2821 Debug( LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0 );
2833 dnParent( &old_parent_ndn, &parent_ndn );
2843 /* need to register this at some point */
2844 static slap_dynacl_t dynacl_aci = {
2854 #endif /* SLAP_DYNACL */
2856 #endif /* SLAPD_ACI_ENABLED */
2861 * dynamic ACL infrastructure
2863 static slap_dynacl_t *da_list = NULL;
2866 slap_dynacl_register( slap_dynacl_t *da )
2870 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2871 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2876 if ( tmp != NULL ) {
2880 if ( da->da_mask == NULL ) {
2884 da->da_private = NULL;
2885 da->da_next = da_list;
2891 static slap_dynacl_t *
2892 slap_dynacl_next( slap_dynacl_t *da )
2901 slap_dynacl_get( const char *name )
2905 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2906 if ( strcasecmp( da->da_name, name ) == 0 ) {
2913 #endif /* SLAP_DYNACL */
2920 slap_dynacl_t *known_dynacl[] = {
2921 #ifdef SLAPD_ACI_ENABLED
2923 #endif /* SLAPD_ACI_ENABLED */
2927 for ( i = 0; known_dynacl[ i ]; i++ ) {
2928 rc = slap_dynacl_register( known_dynacl[ i ] );
2933 #endif /* SLAP_DYNACL */
2944 regmatch_t *matches)
2952 bv->bv_val[0] = '\0';
2953 bv->bv_len--; /* leave space for lone $ */
2956 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2957 sp < pat->bv_val + pat->bv_len ; sp++ )
2959 /* did we previously see a $ */
2961 if ( flag == 1 && *sp == '$' ) {
2966 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2969 } else if ( *sp >= '0' && *sp <= '9' ) {
2977 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2978 if ( *sp >= '0' && *sp <= '9' ) {
2979 n = 10*n + ( *sp - '0' );
2983 if ( *sp != /*'{'*/ '}' ) {
2989 if ( n >= nmatch ) {
2995 i = matches[n].rm_so;
2996 l = matches[n].rm_eo;
2997 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
3015 /* must have ended with a single $ */
3023 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
3024 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
3031 struct berval *pat, /* pattern to expand and match against */
3032 char *str, /* string to match against pattern */
3033 char *buf, /* buffer with $N expansion variables */
3034 int nmatch, /* size of the matches array */
3035 regmatch_t *matches /* offsets in buffer for $N expansion variables */
3039 char newbuf[ACL_BUF_SIZE];
3043 bv.bv_len = sizeof( newbuf ) - 1;
3050 string_expand( &bv, pat, buf, nmatch, matches );
3051 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
3053 char error[ACL_BUF_SIZE];
3054 regerror( rc, &re, error, sizeof( error ) );
3056 Debug( LDAP_DEBUG_TRACE,
3057 "compile( \"%s\", \"%s\") failed %s\n",
3058 pat->bv_val, str, error );
3062 rc = regexec( &re, str, 0, NULL, 0 );
3065 Debug( LDAP_DEBUG_TRACE,
3066 "=> regex_matches: string: %s\n", str, 0, 0 );
3067 Debug( LDAP_DEBUG_TRACE,
3068 "=> regex_matches: rc: %d %s\n",
3069 rc, !rc ? "matches" : "no matches", 0 );