]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/acl.c
component cleanup
[openldap] / servers / slapd / acl.c
index 823efe7728e3a9bda2a2bf078c480e97a82b7755..d1142bbe2119daa74761fec27d1f3be0a76f3830 100644 (file)
@@ -72,7 +72,8 @@ static struct berval
        aci_bv_group_class      = BER_BVC(SLAPD_GROUP_CLASS),
        aci_bv_group_attr       = BER_BVC(SLAPD_GROUP_ATTR),
        aci_bv_role_class       = BER_BVC(SLAPD_ROLE_CLASS),
-       aci_bv_role_attr        = BER_BVC(SLAPD_ROLE_ATTR);
+       aci_bv_role_attr        = BER_BVC(SLAPD_ROLE_ATTR),
+       aci_bv_set_attr         = BER_BVC(SLAPD_ACI_SET_ATTR);
 
 
 static AccessControl * acl_get(
@@ -132,16 +133,21 @@ static int aci_match_set ( struct berval *subj, Operation *op,
  * returns:
  *             0       access denied
  *             1       access granted
+ *
+ * Notes:
+ * - can be legally called with op == NULL
+ * - can be legally called with op->o_bd == NULL
  */
 
 int
-access_allowed(
+access_allowed_mask(
        Operation               *op,
        Entry           *e,
        AttributeDescription    *desc,
        struct berval   *val,
        slap_access_t   access,
-       AccessControlState *state )
+       AccessControlState *state,
+       slap_mask_t *maskp )
 {
        int                             ret = 1;
        int                             count;
@@ -162,6 +168,7 @@ access_allowed(
        assert( e != NULL );
        assert( desc != NULL );
        assert( access > ACL_NONE );
+       if ( maskp ) ACL_INVALIDATE( *maskp );
 
        attr = desc->ad_cname.bv_val;
 
@@ -194,15 +201,9 @@ access_allowed(
                state->as_vd_ad=desc;
        }
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, ENTRY, 
-               "access_allowed: %s access to \"%s\" \"%s\" requested\n",
-               access2str( access ), e->e_dn, attr );
-#else
        Debug( LDAP_DEBUG_ACL,
                "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
            access2str( access ), e->e_dn, attr );
-#endif
 
        if ( op == NULL ) {
                /* no-op call */
@@ -213,7 +214,15 @@ access_allowed(
        if ( be == NULL ) {
                be = &backends[0];
                be_null = 1;
-               op->o_bd = be;
+#ifdef LDAP_DEVEL
+               /*
+                * FIXME: experimental; use first backend rules
+                * iff there is no global_acl (ITS#3100) */
+               if ( frontendDB->be_acl == NULL ) 
+#endif
+               {
+                       op->o_bd = be;
+               }
        }
        assert( be != NULL );
 
@@ -228,16 +237,14 @@ access_allowed(
 #endif /* LDAP_SLAPI */
 
        /* grant database root access */
-       if ( be != NULL && be_isroot( be, &op->o_ndn ) ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, INFO, 
-                       "access_allowed: conn %lu root access granted\n", 
-                       op->o_connid, 0, 0 );
-#else
+       if ( be != NULL && be_isroot( op ) ) {
                Debug( LDAP_DEBUG_ACL,
                    "<= root access granted\n",
                        0, 0, 0 );
-#endif
+               if ( maskp ) {
+                       mask = ACL_LVL_WRITE;
+               }
+
                goto done;
        }
 
@@ -250,53 +257,51 @@ access_allowed(
                && desc != slap_schema.si_ad_entry
                && desc != slap_schema.si_ad_children )
        {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "access_allowed: conn %lu NoUserMod Operational attribute: %s "
-                       "access granted\n", op->o_connid, attr , 0 );
-#else
                Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
                        " %s access granted\n",
                        attr, 0, 0 );
-#endif
                goto done;
        }
 
        /* use backend default access if no backend acls */
        if( be != NULL && be->be_acl == NULL ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "access_allowed: backend default %s access %s to \"%s\"\n",
-                   access2str( access ),
-                   be->be_dfltaccess >= access ? "granted" : "denied", 
-                       op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
-#else
                Debug( LDAP_DEBUG_ACL,
                        "=> access_allowed: backend default %s access %s to \"%s\"\n",
                        access2str( access ),
                        be->be_dfltaccess >= access ? "granted" : "denied",
                        op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
-#endif
                ret = be->be_dfltaccess >= access;
+
+               if ( maskp ) {
+                       int     i;
+
+                       mask = ACL_PRIV_LEVEL;
+                       for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
+                               mask |= ACL_ACCESS2PRIV( i );
+                       }
+               }
+
                goto done;
 
 #ifdef notdef
        /* be is always non-NULL */
        /* use global default access if no global acls */
-       } else if ( be == NULL && global_acl == NULL ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "access_allowed: global default %s access %s to \"%s\"\n",
-                   access2str( access ),
-                   global_default_access >= access ? "granted" : "denied", 
-                       op->o_dn.bv_val );
-#else
+       } else if ( be == NULL && frontendDB->be_acl == NULL ) {
                Debug( LDAP_DEBUG_ACL,
                        "=> access_allowed: global default %s access %s to \"%s\"\n",
                        access2str( access ),
-                       global_default_access >= access ? "granted" : "denied", op->o_dn.bv_val );
-#endif
-               ret = global_default_access >= access;
+                       frontendDB->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
+               ret = frontendDB->be_dfltaccess >= access;
+
+               if ( maskp ) {
+                       int     i;
+
+                       mask = ACL_PRIV_LEVEL;
+                       for ( i = ACL_NONE; i <= global_default_access; i++ ) {
+                               mask |= ACL_ACCESS2PRIV( i );
+                       }
+               }
+
                goto done;
 #endif
        }
@@ -329,25 +334,15 @@ access_allowed(
                int i;
 
                for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                               "access_allowed: match[%d]:  %d %d ",
-                           i, (int)matches[i].rm_so, (int)matches[i].rm_eo );
-#else
                        Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
                            (int)matches[i].rm_so, (int)matches[i].rm_eo );
-#endif
                        if( matches[i].rm_so <= matches[0].rm_eo ) {
                                int n;
                                for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
                                        Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
                                }
                        }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, ARGS, "\n" , 0, 0, 0 );
-#else
                        Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
-#endif
                }
 
                if (state) {
@@ -372,41 +367,23 @@ vd_access:
        }
 
        if ( ACL_IS_INVALID( mask ) ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "access_allowed: conn %lu \"%s\" (%s) invalid!\n",
-                   op->o_connid, e->e_dn, attr );
-#else
                Debug( LDAP_DEBUG_ACL,
                        "=> access_allowed: \"%s\" (%s) invalid!\n",
                        e->e_dn, attr, 0 );
-#endif
                ACL_INIT(mask);
 
        } else if ( control == ACL_BREAK ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "access_allowed: conn %lu        no more rules\n", op->o_connid, 0,0 );
-#else
                Debug( LDAP_DEBUG_ACL,
                        "=> access_allowed: no more rules\n", 0, 0, 0);
-#endif
 
                goto done;
        }
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, ENTRY, 
-               "access_allowed: %s access %s by %s\n", 
-               access2str( access ), ACL_GRANT( mask, access ) ? "granted" : "denied",
-               accessmask2str( mask, accessmaskbuf ) );
-#else
        Debug( LDAP_DEBUG_ACL,
                "=> access_allowed: %s access %s by %s\n",
                access2str( access ),
                ACL_GRANT(mask, access) ? "granted" : "denied",
                accessmask2str( mask, accessmaskbuf ) );
-#endif
 
        ret = ACL_GRANT(mask, access);
 
@@ -420,6 +397,7 @@ done:
                state->as_recorded |= ACL_STATE_RECORDED;
        }
        if (be_null) op->o_bd = NULL;
+       if ( maskp ) *maskp = mask;
        return ret;
 }
 
@@ -456,7 +434,7 @@ acl_get(
 
        if( a == NULL ) {
                if( op->o_bd == NULL ) {
-                       a = global_acl;
+                       a = frontendDB->be_acl;
                } else {
                        a = op->o_bd->be_acl;
                }
@@ -476,26 +454,14 @@ acl_get(
 
                if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
                        if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
-#ifdef NEW_LOGGING
-                               LDAP_LOG( ACL, DETAIL1, 
-                                       "acl_get: dnpat [%d] %s nsub: %d\n",
-                                       *count, a->acl_dn_pat.bv_val, 
-                                       (int) a->acl_dn_re.re_nsub );
-#else
                                Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n", 
                                        *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
-#endif
                                if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
                                        continue;
 
                        } else {
-#ifdef NEW_LOGGING
-                               LDAP_LOG( ACL, DETAIL1, "acl_get: dn [%d] %s\n",
-                                          *count, a->acl_dn_pat.bv_val, 0 );
-#else
                                Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n", 
                                        *count, a->acl_dn_pat.bv_val, 0 );
-#endif
                                patlen = a->acl_dn_pat.bv_len;
                                if ( dnlen < patlen )
                                        continue;
@@ -506,16 +472,19 @@ acl_get(
                                                continue;
 
                                } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
-                                       int rdnlen = -1;
+                                       int     rdnlen = -1, sep = 0;
 
                                        if ( dnlen <= patlen )
                                                continue;
 
-                                       if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
-                                               continue;
+                                       if ( patlen > 0 ) {
+                                               if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
+                                                       continue;
+                                               sep = 1;
+                                       }
 
                                        rdnlen = dn_rdnlen( NULL, &e->e_nname );
-                                       if ( rdnlen != dnlen - patlen - 1 )
+                                       if ( rdnlen != dnlen - patlen - sep )
                                                continue;
 
                                } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
@@ -533,13 +502,8 @@ acl_get(
                                        continue;
                        }
 
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                               "acl_get: [%d] matched\n", *count, 0, 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
                                *count, 0, 0 );
-#endif
                }
 
                if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
@@ -563,29 +527,17 @@ acl_get(
                        }
 
                        if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
-#ifdef NEW_LOGGING
-                               LDAP_LOG( ACL, DETAIL1, 
-                                       "acl_get: valpat %s\n",
-                                       a->acl_attrval.bv_val, 0, 0 );
-#else
                                Debug( LDAP_DEBUG_ACL,
                                        "acl_get: valpat %s\n",
                                        a->acl_attrval.bv_val, 0, 0 );
-#endif
                                if (regexec(&a->acl_attrval_re, val->bv_val, 0, NULL, 0))
                                        continue;
                        } else {
                                int match = 0;
                                const char *text;
-#ifdef NEW_LOGGING
-                               LDAP_LOG( ACL, DETAIL1, 
-                                       "acl_get: val %s\n",
-                                       a->acl_attrval.bv_val, 0, 0 );
-#else
                                Debug( LDAP_DEBUG_ACL,
                                        "acl_get: val %s\n",
                                        a->acl_attrval.bv_val, 0, 0 );
-#endif
        
                                if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
                                        if (value_match( &match, desc,
@@ -642,21 +594,12 @@ acl_get(
                        }
                }
 
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "acl_get: [%d] attr %s\n", *count, attr ,0 );
-#else
                Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
                       *count, attr, 0);
-#endif
                return a;
        }
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, RESULTS, "acl_get: done.\n", 0, 0, 0 );
-#else
        Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
-#endif
        return( NULL );
 }
 
@@ -712,16 +655,6 @@ acl_mask(
 
        assert( attr != NULL );
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, ENTRY, 
-               "acl_mask: conn %lu  access to entry \"%s\", attr \"%s\" requested\n",
-               op->o_connid, e->e_dn, attr );
-
-       LDAP_LOG( ACL, ARGS, 
-               " to %s by \"%s\", (%s) \n", val ? "value" : "all values",
-               op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
-               accessmask2str( *mask, accessmaskbuf ) );
-#else
        Debug( LDAP_DEBUG_ACL,
                "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
                e->e_dn, attr, 0 );
@@ -731,7 +664,6 @@ acl_mask(
                val ? "value" : "all values",
                op->o_ndn.bv_val ?  op->o_ndn.bv_val : "",
                accessmask2str( *mask, accessmaskbuf ) );
-#endif
 
 
        if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
@@ -752,14 +684,8 @@ acl_mask(
 
                /* AND <who> clauses */
                if ( b->a_dn_pat.bv_len != 0 ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                               "acl_mask: conn %lu  check a_dn_pat: %s\n",
-                               op->o_connid, b->a_dn_pat.bv_val ,0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
                                b->a_dn_pat.bv_val, 0, 0);
-#endif
                        /*
                         * if access applies to the entry itself, and the
                         * user is bound as somebody in the same namespace as
@@ -879,14 +805,8 @@ dn_match_cleanup:;
                        if ( ! op->o_conn->c_listener ) {
                                continue;
                        }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                                  "acl_mask: conn %lu  check a_sockurl_pat: %s\n",
-                                  op->o_connid, b->a_sockurl_pat.bv_val , 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
                                b->a_sockurl_pat.bv_val, 0, 0 );
-#endif
 
                        if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
                                if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
@@ -919,14 +839,8 @@ dn_match_cleanup:;
                        if ( !op->o_conn->c_peer_domain.bv_val ) {
                                continue;
                        }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                                  "acl_mask: conn %lu  check a_domain_pat: %s\n",
-                                  op->o_connid, b->a_domain_pat.bv_val , 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
                                b->a_domain_pat.bv_val, 0, 0 );
-#endif
                        if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
                                if ( b->a_domain_style == ACL_STYLE_REGEX) {
                                        if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
@@ -976,14 +890,8 @@ dn_match_cleanup:;
                        if ( !op->o_conn->c_peer_name.bv_val ) {
                                continue;
                        }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                                  "acl_mask: conn %lu  check a_peername_path: %s\n",
-                                  op->o_connid, b->a_peername_pat.bv_val , 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
                                b->a_peername_pat.bv_val, 0, 0 );
-#endif
                        if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
                                if ( b->a_peername_style == ACL_STYLE_REGEX ) {
                                        if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
@@ -1086,14 +994,8 @@ dn_match_cleanup:;
                        if ( !op->o_conn->c_sock_name.bv_val ) {
                                continue;
                        }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                                  "acl_mask: conn %lu  check a_sockname_path: %s\n",
-                                  op->o_connid, b->a_sockname_pat.bv_val , 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
                                b->a_sockname_pat.bv_val, 0, 0 );
-#endif
                        if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
                                if ( b->a_sockname_style == ACL_STYLE_REGEX) {
                                        if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
@@ -1134,14 +1036,8 @@ dn_match_cleanup:;
                                continue;
                        }
 
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                                  "acl_mask: conn %lu  check a_dn_pat: %s\n",
-                                  op->o_connid, attr , 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
                                attr, 0, 0);
-#endif
                        bv = op->o_ndn;
 
                        /* see if asker is listed in dnattr */
@@ -1207,7 +1103,7 @@ dn_match_cleanup:;
 
                if ( b->a_group_pat.bv_len ) {
                        struct berval bv;
-                       struct berval ndn = { 0, NULL };
+                       struct berval ndn = BER_BVNULL;
                        int rc;
 
                        if ( op->o_ndn.bv_len == 0 ) {
@@ -1262,63 +1158,35 @@ dn_match_cleanup:;
                }
 
                if ( b->a_authz.sai_ssf ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                               "acl_mask: conn %lu  check a_authz.sai_ssf: ACL %u > OP %u\n",
-                               op->o_connid, b->a_authz.sai_ssf, op->o_ssf  );
-#else
                        Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
                                b->a_authz.sai_ssf, op->o_ssf, 0 );
-#endif
                        if ( b->a_authz.sai_ssf >  op->o_ssf ) {
                                continue;
                        }
                }
 
                if ( b->a_authz.sai_transport_ssf ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                               "acl_mask: conn %lu  check a_authz.sai_transport_ssf: "
-                               "ACL %u > OP %u\n",
-                               op->o_connid, b->a_authz.sai_transport_ssf, 
-                               op->o_transport_ssf  );
-#else
                        Debug( LDAP_DEBUG_ACL,
                                "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
                                b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
-#endif
                        if ( b->a_authz.sai_transport_ssf >  op->o_transport_ssf ) {
                                continue;
                        }
                }
 
                if ( b->a_authz.sai_tls_ssf ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                               "acl_mask: conn %lu  check a_authz.sai_tls_ssf: ACL %u > "
-                               "OP %u\n",
-                               op->o_connid, b->a_authz.sai_tls_ssf, op->o_tls_ssf  );
-#else
                        Debug( LDAP_DEBUG_ACL,
                                "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
                                b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
-#endif
                        if ( b->a_authz.sai_tls_ssf >  op->o_tls_ssf ) {
                                continue;
                        }
                }
 
                if ( b->a_authz.sai_sasl_ssf ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                          "acl_mask: conn %lu check a_authz.sai_sasl_ssf: " 
-                          "ACL %u > OP %u\n",
-                               op->o_connid, b->a_authz.sai_sasl_ssf, op->o_sasl_ssf );
-#else
                        Debug( LDAP_DEBUG_ACL,
                                "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
                                b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
-#endif
                        if ( b->a_authz.sai_sasl_ssf >  op->o_sasl_ssf ) {
                                continue;
                        }
@@ -1355,12 +1223,16 @@ dn_match_cleanup:;
                        /* get the aci attribute */
                        at = attr_find( e->e_attrs, b->a_aci_at );
                        if ( at != NULL ) {
+#if 0
+                               /* FIXME: this breaks acl caching;
+                                * see also ACL_RECORD_VALUE_STATE below */
                                ACL_RECORD_VALUE_STATE;
+#endif
                                /* the aci is an multi-valued attribute.  The
                                * rights are determined by OR'ing the individual
                                * rights given by the acis.
                                */
-                               for ( i = 0; at->a_vals[i].bv_val != NULL; i++ ) {
+                               for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
                                        if (aci_mask( op,
                                                e, desc, val,
                                                &at->a_nvals[i],
@@ -1384,47 +1256,56 @@ dn_match_cleanup:;
                                while ( parent_ndn.bv_val != old_parent_ndn.bv_val ){
                                        old_parent_ndn = parent_ndn;
                                        Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
-                                       ret=backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals);
+                                       ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
                                        switch(ret){
-                                               case LDAP_SUCCESS :
-                                                       if(bvals){
-                                                               for( i = 0; bvals[i].bv_val != NULL; i++){
-                                                                       ACL_RECORD_VALUE_STATE;
-                                                                       if (aci_mask(op, e, desc, val, &bvals[i], matches,
-                                                                                       &grant, &deny, &aci_bv_children) != 0) {
-                                                                               tgrant |= grant;
-                                                                               tdeny |= deny;
-                                                                               /* evaluation stops as soon as either a "deny" or a 
-                                                                                * "grant" directive matches.
-                                                                                */
-                                                                               if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
-                                                                                       stop=1;
-                                                                               }
-                                                                       }
-                                                                       Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n", 
-                                                                               accessmask2str(tgrant,accessmaskbuf),
-                                                                               accessmask2str(tdeny, accessmaskbuf1), 0);
+                                       case LDAP_SUCCESS :
+                                               stop = 0;
+                                               if (!bvals){
+                                                       break;
+                                               }
+
+                                               for( i = 0; bvals[i].bv_val != NULL; i++){
+#if 0
+                                                       /* FIXME: this breaks acl caching;
+                                                        * see also ACL_RECORD_VALUE_STATE above */
+                                                       ACL_RECORD_VALUE_STATE;
+#endif
+                                                       if (aci_mask(op, e, desc, val, &bvals[i], matches,
+                                                                       &grant, &deny, &aci_bv_children) != 0) {
+                                                               tgrant |= grant;
+                                                               tdeny |= deny;
+                                                               /* evaluation stops as soon as either a "deny" or a 
+                                                                * "grant" directive matches.
+                                                                */
+                                                               if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
+                                                                       stop = 1;
                                                                }
                                                        }
-                                                       stop=0;
-                                                       break;
-                                               case LDAP_NO_SUCH_ATTRIBUTE:
-                                                       /* just go on if the aci-Attribute is not present in
-                                                        * the current entry 
-                                                        */
-                                                       Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
-                                                       stop=0;
-                                                       break;
-                                               case LDAP_NO_SUCH_OBJECT:
-                                                       /* We have reached the base object */
-                                                       Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
-                                                       stop=1;
-                                                       break;
-                                               default:
-                                                       stop=1;
-                                                       break;
+                                                       Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n", 
+                                                               accessmask2str(tgrant,accessmaskbuf),
+                                                               accessmask2str(tdeny, accessmaskbuf1), 0);
+                                               }
+                                               break;
+
+                                       case LDAP_NO_SUCH_ATTRIBUTE:
+                                               /* just go on if the aci-Attribute is not present in
+                                                * the current entry 
+                                                */
+                                               Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
+                                               stop = 0;
+                                               break;
+
+                                       case LDAP_NO_SUCH_OBJECT:
+                                               /* We have reached the base object */
+                                               Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
+                                               stop = 1;
+                                               break;
+
+                                       default:
+                                               stop = 1;
+                                               break;
                                        }
-                                       if(stop){
+                                       if (stop){
                                                break;
                                        }
                                        dnParent(&old_parent_ndn, &parent_ndn);
@@ -1465,13 +1346,6 @@ dn_match_cleanup:;
                        modmask = b->a_access_mask;
                }
 
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, RESULTS, 
-                          "acl_mask: [%d] applying %s (%s)\n",
-                          i, accessmask2str( modmask, accessmaskbuf),
-                          b->a_type == ACL_CONTINUE ? "continue" : b->a_type == ACL_BREAK
-                          ? "break" : "stop"  );
-#else
                Debug( LDAP_DEBUG_ACL,
                        "<= acl_mask: [%d] applying %s (%s)\n",
                        i, accessmask2str( modmask, accessmaskbuf ), 
@@ -1480,7 +1354,6 @@ dn_match_cleanup:;
                                : b->a_type == ACL_BREAK
                                        ? "break"
                                        : "stop" );
-#endif
                /* save old mask */
                oldmask = *mask;
 
@@ -1503,15 +1376,9 @@ dn_match_cleanup:;
                        *mask = modmask;
                }
 
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                          "acl_mask: conn %lu  [%d] mask: %s\n",
-                          op->o_connid, i, accessmask2str( *mask, accessmaskbuf)  );
-#else
                Debug( LDAP_DEBUG_ACL,
                        "<= acl_mask: [%d] mask: %s\n",
                        i, accessmask2str(*mask, accessmaskbuf), 0 );
-#endif
 
                if( b->a_type == ACL_CONTINUE ) {
                        continue;
@@ -1527,15 +1394,9 @@ dn_match_cleanup:;
        /* implicit "by * none" clause */
        ACL_INIT(*mask);
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, RESULTS, 
-                  "acl_mask: conn %lu  no more <who> clauses, returning %d (stop)\n",
-                  op->o_connid, accessmask2str( *mask, accessmaskbuf) , 0 );
-#else
        Debug( LDAP_DEBUG_ACL,
                "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
                accessmask2str(*mask, accessmaskbuf), 0, 0 );
-#endif
        return ACL_STOP;
 }
 
@@ -1543,7 +1404,7 @@ dn_match_cleanup:;
  * acl_check_modlist - check access control on the given entry to see if
  * it allows the given modifications by the user associated with op.
  * returns     1       if mods allowed ok
- *                     0       mods not allowed
+ *             0       mods not allowed
  */
 
 int
@@ -1568,33 +1429,19 @@ acl_check_modlist(
        assert( be != NULL );
 
        /* short circuit root database access */
-       if ( be_isroot_dn( op ) ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                          "acl_check_modlist: conn %lu  access granted to root user\n",
-                          op->o_connid, 0, 0 );
-#else
+       if ( be_isroot( op ) ) {
                Debug( LDAP_DEBUG_ACL,
                        "<= acl_access_allowed: granted to database root\n",
                    0, 0, 0 );
-#endif
                goto done;
        }
 
        /* use backend default access if no backend acls */
        if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, DETAIL1, 
-                       "acl_check_modlist: backend default %s access %s to \"%s\"\n",
-                       access2str( ACL_WRITE ),
-                       op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", 
-                       op->o_dn.bv_val  );
-#else
                Debug( LDAP_DEBUG_ACL,
                        "=> access_allowed: backend default %s access %s to \"%s\"\n",
                        access2str( ACL_WRITE ),
                        op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
-#endif
                ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
                goto done;
        }
@@ -1606,15 +1453,9 @@ acl_check_modlist(
                 * by the user
                 */
                if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( ACL, DETAIL1, 
-                                  "acl_check_modlist: conn %lu  no-user-mod %s: modify access granted\n",
-                                  op->o_connid, mlist->sml_desc->ad_cname.bv_val , 0 );
-#else
                        Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
                                " modify access granted\n",
                                mlist->sml_desc->ad_cname.bv_val, 0, 0 );
-#endif
                        continue;
                }
 
@@ -1632,12 +1473,12 @@ acl_check_modlist(
                                goto done;
                        }
 
-                       if ( mlist->sml_bvalues == NULL ) break;
+                       if ( mlist->sml_values == NULL ) break;
 
                        /* fall thru to check value to add */
 
                case LDAP_MOD_ADD:
-                       assert( mlist->sml_bvalues != NULL );
+                       assert( mlist->sml_values != NULL );
 
                        for ( bv = mlist->sml_nvalues
                                        ? mlist->sml_nvalues : mlist->sml_values;
@@ -1653,7 +1494,7 @@ acl_check_modlist(
                        break;
 
                case LDAP_MOD_DELETE:
-                       if ( mlist->sml_bvalues == NULL ) {
+                       if ( mlist->sml_values == NULL ) {
                                if ( ! access_allowed( op, e,
                                        mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
                                {
@@ -1703,8 +1544,7 @@ aci_get_part(
        char *p;
 
        if (bv) {
-               bv->bv_len = 0;
-               bv->bv_val = NULL;
+               BER_BVZERO( bv );
        }
        len = list->bv_len;
        p = list->bv_val;
@@ -1748,9 +1588,9 @@ aci_set_gather (SetCookie *cookie, struct berval *name, struct berval *attr)
                AttributeDescription *desc = NULL;
                if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
                        backend_attribute(cp->op,
-                               cp->e, &ndn, desc, &bvals);
+                               cp->e, &ndn, desc, &bvals, ACL_NONE);
                }
-               sl_free(ndn.bv_val, cp->op->o_tmpmemctx);
+               slap_sl_free(ndn.bv_val, cp->op->o_tmpmemctx);
        }
        return(bvals);
 }
@@ -1763,63 +1603,60 @@ aci_match_set (
        int setref
 )
 {
-       struct berval set = { 0, NULL };
-       int rc = 0;
-       AciSetCookie cookie;
+       struct berval   set = BER_BVNULL;
+       int             rc = 0;
+       AciSetCookie    cookie;
 
        if (setref == 0) {
                ber_dupbv_x( &set, subj, op->o_tmpmemctx );
        } else {
-               struct berval subjdn, ndn = { 0, NULL };
-               struct berval setat;
-               BerVarray bvals;
-               const char *text;
-               AttributeDescription *desc = NULL;
+               struct berval           subjdn, ndn = BER_BVNULL;
+               struct berval           setat;
+               BerVarray               bvals;
+               const char              *text;
+               AttributeDescription    *desc = NULL;
 
                /* format of string is "entry/setAttrName" */
-               if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
+               if ( aci_get_part( subj, 0, '/', &subjdn ) < 0 ) {
                        return(0);
                }
 
-               if ( aci_get_part(subj, 1, '/', &setat) < 0 ) {
-                       setat.bv_val = SLAPD_ACI_SET_ATTR;
-                       setat.bv_len = sizeof(SLAPD_ACI_SET_ATTR)-1;
+               if ( aci_get_part( subj, 1, '/', &setat ) < 0 ) {
+                       setat = aci_bv_set_attr;
                }
 
-               if ( setat.bv_val != NULL ) {
-                       /*
-                        * NOTE: dnNormalize honors the ber_len field
-                        * as the length of the dn to be normalized
-                        */
-                       if ( dnNormalize(0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx) == LDAP_SUCCESS
-                               && slap_bv2ad(&setat, &desc, &text) == LDAP_SUCCESS )
+               /*
+                * NOTE: dnNormalize honors the ber_len field
+                * as the length of the dn to be normalized
+                */
+               if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
+                       if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
                        {
-                               backend_attribute(op, e,
-                                       &ndn, desc, &bvals);
-                               if ( bvals != NULL ) {
-                                       if ( bvals[0].bv_val != NULL ) {
-                                               int i;
-                                               set = bvals[0];
-                                               bvals[0].bv_val = NULL;
-                                               for (i=1;bvals[i].bv_val;i++);
-                                               bvals[0].bv_val = bvals[i-1].bv_val;
-                                               bvals[i-1].bv_val = NULL;
-                                       }
-                                       ber_bvarray_free_x(bvals, op->o_tmpmemctx);
+                               backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
+                               if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
+                                       int     i;
+
+                                       set = bvals[0];
+                                       BER_BVZERO( &bvals[0] );
+                                       for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
+                                               /* count */ ;
+                                       bvals[0].bv_val = bvals[i-1].bv_val;
+                                       BER_BVZERO( &bvals[i-1] );
                                }
+                               ber_bvarray_free_x( bvals, op->o_tmpmemctx );
+                               slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
                        }
-                       if (ndn.bv_val)
-                               free(ndn.bv_val);
                }
        }
 
-       if (set.bv_val != NULL) {
+       if ( !BER_BVISNULL( &set ) ) {
                cookie.op = op;
                cookie.e = e;
-               rc = (slap_set_filter(aci_set_gather, (SetCookie *)&cookie, &set,
-                       &op->o_ndn, &e->e_nname, NULL) > 0);
-               sl_free(set.bv_val, op->o_tmpmemctx);
+               rc = ( slap_set_filter( aci_set_gather, (SetCookie *)&cookie, &set,
+                       &op->o_ndn, &e->e_nname, NULL ) > 0 );
+               slap_sl_free( set.bv_val, op->o_tmpmemctx );
        }
+
        return(rc);
 }
 
@@ -2250,14 +2087,8 @@ string_expand(
        *dp = '\0';
        bv->bv_len = size;
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, DETAIL1, 
-          "string_expand:  pattern = %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
-       LDAP_LOG( ACL, DETAIL1, "string_expand:  expanded = %s\n", bv->bv_val, 0, 0 );
-#else
        Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern:  %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
        Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
-#endif
 }
 
 static int
@@ -2283,32 +2114,20 @@ regex_matches(
                char error[ACL_BUF_SIZE];
                regerror(rc, &re, error, sizeof(error));
 
-#ifdef NEW_LOGGING
-               LDAP_LOG( ACL, ERR, 
-                          "regex_matches: compile( \"%s\", \"%s\") failed %s\n",
-                          pat->bv_val, str, error  );
-#else
                Debug( LDAP_DEBUG_TRACE,
                    "compile( \"%s\", \"%s\") failed %s\n",
                        pat->bv_val, str, error );
-#endif
                return( 0 );
        }
 
        rc = regexec(&re, str, 0, NULL, 0);
        regfree( &re );
 
-#ifdef NEW_LOGGING
-       LDAP_LOG( ACL, DETAIL2, "regex_matches: string:   %s\n", str, 0, 0 );
-       LDAP_LOG( ACL, DETAIL2, "regex_matches: rc:     %d  %s\n",
-                  rc, rc ? "matches" : "no matches", 0  );
-#else
        Debug( LDAP_DEBUG_TRACE,
            "=> regex_matches: string:   %s\n", str, 0, 0 );
        Debug( LDAP_DEBUG_TRACE,
            "=> regex_matches: rc: %d %s\n",
                rc, !rc ? "matches" : "no matches", 0 );
-#endif
        return( !rc );
 }