]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/backend.c
Merge remote-tracking branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / servers / slapd / backend.c
index 7e0dbce7d99f9a6648ecc5c486afdb40fd6ea947..bde9f1a4606c779eb841158c193afcc3b3ebe8ea 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2014 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -226,9 +226,22 @@ int backend_startup_one(Backend *be, ConfigReply *cr)
                        (void)backend_set_controls( be );
 
                } else {
+                       char *type = be->bd_info->bi_type;
+                       char *suffix = "(null)";
+
+                       if ( overlay_is_over( be ) ) {
+                               slap_overinfo   *oi = (slap_overinfo *)be->bd_info->bi_private;
+                               type = oi->oi_orig->bi_type;
+                       }
+
+                       if ( be->be_suffix != NULL && !BER_BVISNULL( &be->be_suffix[0] ) ) {
+                               suffix = be->be_suffix[0].bv_val;
+                       }
+
                        Debug( LDAP_DEBUG_ANY,
-                               "backend_startup_one: bi_db_open failed! (%d)\n",
-                               rc, 0, 0 );
+                               "backend_startup_one (type=%s, suffix=\"%s\"): "
+                               "bi_db_open failed! (%d)\n",
+                               type, suffix, rc );
                }
        }
 
@@ -451,6 +464,9 @@ void backend_destroy_one( BackendDB *bd, int dynamic )
        }
        acl_destroy( bd->be_acl );
        limits_destroy( bd->be_limits );
+       if ( bd->be_extra_anlist ) {
+               anlist_free( bd->be_extra_anlist, 1, NULL );
+       }
        if ( !BER_BVISNULL( &bd->be_update_ndn ) ) {
                ch_free( bd->be_update_ndn.bv_val );
        }
@@ -458,6 +474,8 @@ void backend_destroy_one( BackendDB *bd, int dynamic )
                ber_bvarray_free( bd->be_update_refs );
        }
 
+       ldap_pvt_thread_mutex_destroy( &bd->be_pcl_mutex );
+
        if ( dynamic ) {
                free( bd );
        }
@@ -607,6 +625,7 @@ backend_db_init(
                /* If we created and linked this be, remove it and free it */
                if ( !b0 ) {
                        LDAP_STAILQ_REMOVE(&backendDB, be, BackendDB, be_next);
+                       ldap_pvt_thread_mutex_destroy( &be->be_pcl_mutex );
                        ch_free( be );
                        be = NULL;
                        nbackends--;
@@ -746,10 +765,10 @@ be_slurp_update( Operation *op )
 int
 be_shadow_update( Operation *op )
 {
-       /* This assumes that all internal ops (connid == -1) on a syncrepl
+       /* This assumes that all internal ops (connid <= -1000) on a syncrepl
         * database are syncrepl operations.
         */
-       return (( SLAP_SYNC_SHADOW( op->o_bd ) && op->o_connid == -1 ) ||
+       return ( ( SLAP_SYNC_SHADOW( op->o_bd ) && SLAPD_SYNC_IS_SYNCCONN( op->o_connid ) ) ||
                ( SLAP_SHADOW( op->o_bd ) && be_isupdate_dn( op->o_bd, &op->o_ndn ) ) );
 }
 
@@ -1035,7 +1054,7 @@ backend_check_restrictions(
                requires |= op->o_bd->be_requires;
                bssf = &op->o_bd->be_ssf_set.sss_ssf;
                fssf = &ssfs.sss_ssf;
-               for ( i=0; i<sizeof(ssfs)/sizeof(slap_ssf_t); i++ ) {
+               for ( i=0; i < (int)(sizeof(ssfs)/sizeof(slap_ssf_t)); i++ ) {
                        if ( bssf[i] ) fssf[i] = bssf[i];
                }
        }
@@ -1296,7 +1315,8 @@ backend_check_restrictions(
        }
 
        if( ( restrictops & opflag )
-                       || ( exopflag && ( restrictops & exopflag ) ) ) {
+                       || ( exopflag && ( restrictops & exopflag ) )
+                       || (( restrictops & SLAP_RESTRICT_READONLY ) && updateop )) {
                if( ( restrictops & SLAP_RESTRICT_OP_MASK) == SLAP_RESTRICT_OP_READS ) {
                        rs->sr_text = "read operations restricted";
                } else if ( restrictops & exopflag ) {
@@ -1656,7 +1676,7 @@ fe_acl_attribute(
 
                a = attr_find( e->e_attrs, entry_at );
                if ( a == NULL ) {
-                       SlapReply       rs = { 0 };
+                       SlapReply       rs = { REP_SEARCH };
                        AttributeName   anlist[ 2 ];
 
                        anlist[ 0 ].an_name = entry_at->ad_cname;
@@ -1669,8 +1689,7 @@ fe_acl_attribute(
                         * to do no harm to entries */
                        rs.sr_entry = e;
                        rc = backend_operational( op, &rs );
-                       rs.sr_entry = NULL;
+
                        if ( rc == LDAP_SUCCESS ) {
                                if ( rs.sr_operational_attrs ) {
                                        freeattr = 1;
@@ -1775,9 +1794,9 @@ backend_access(
        slap_mask_t             *mask )
 {
        Entry           *e = NULL;
-       void            *o_priv = op->o_private, *e_priv = NULL;
+       void            *o_priv, *e_priv = NULL;
        int             rc = LDAP_INSUFFICIENT_ACCESS;
-       Backend         *be = op->o_bd;
+       Backend         *be;
 
        /* pedantic */
        assert( op != NULL );
@@ -1785,6 +1804,9 @@ backend_access(
        assert( edn != NULL );
        assert( access > ACL_NONE );
 
+       be = op->o_bd;
+       o_priv = op->o_private;
+
        if ( !op->o_bd ) {
                op->o_bd = select_backend( edn, 0 );
        }
@@ -1821,7 +1843,7 @@ backend_access(
                } else {
                        a = attr_find( e->e_attrs, entry_at );
                        if ( a == NULL ) {
-                               SlapReply       rs = { 0 };
+                               SlapReply       rs = { REP_SEARCH };
                                AttributeName   anlist[ 2 ];
 
                                anlist[ 0 ].an_name = entry_at->ad_cname;
@@ -1836,7 +1858,6 @@ backend_access(
                                 * to do no harm to entries */
                                rs.sr_entry = e;
                                rc = backend_operational( op, &rs );
-                               rs.sr_entry = NULL;
 
                                if ( rc == LDAP_SUCCESS ) {
                                        if ( rs.sr_operational_attrs ) {
@@ -1951,3 +1972,12 @@ int backend_operational( Operation *op, SlapReply *rs )
        return rc;
 }
 
+/* helper that calls the bi_tool_entry_first_x() variant with default args;
+ * use to initialize a backend's bi_tool_entry_first() when appropriate
+ */
+ID
+backend_tool_entry_first( BackendDB *be )
+{
+       return be->bd_info->bi_tool_entry_first_x( be,
+               NULL, LDAP_SCOPE_DEFAULT, NULL );
+}