]> 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 78c655cc64cb8e3fdcdb7c06a48a0b112ac3dd3a..bde9f1a4606c779eb841158c193afcc3b3ebe8ea 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 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 );
                }
        }
 
@@ -261,8 +274,6 @@ int backend_startup(Backend *be)
                                return rc;
                        }
                }
-               /* append global access controls */
-               acl_append( &be->be_acl, frontendDB->be_acl, -1 );
 
                return backend_startup_one( be, &cr );
        }
@@ -310,8 +321,6 @@ int backend_startup(Backend *be)
                                "has no suffix\n",
                                i, be->bd_info->bi_type, 0 );
                }
-               /* append global access controls */
-               acl_append( &be->be_acl, frontendDB->be_acl, -1 );
 
                rc = backend_startup_one( be, &cr );
 
@@ -349,11 +358,13 @@ int backend_shutdown( Backend *be )
                }
 
                if ( be->bd_info->bi_db_close ) {
-                       be->bd_info->bi_db_close( be, NULL );
+                       rc = be->bd_info->bi_db_close( be, NULL );
+                       if ( rc ) return rc;
                }
 
                if( be->bd_info->bi_close ) {
-                       be->bd_info->bi_close( be->bd_info );
+                       rc = be->bd_info->bi_close( be->bd_info );
+                       if ( rc ) return rc;
                }
 
                return 0;
@@ -451,8 +462,11 @@ void backend_destroy_one( BackendDB *bd, int dynamic )
        if ( !BER_BVISNULL( &bd->be_rootpw ) ) {
                free( bd->be_rootpw.bv_val );
        }
-       acl_destroy( bd->be_acl, frontendDB->be_acl );
+       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 );
        }
@@ -460,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 );
        }
@@ -502,7 +518,8 @@ int backend_destroy(void)
                if ( !BER_BVISNULL( &bd->be_rootpw ) ) {
                        free( bd->be_rootpw.bv_val );
                }
-               acl_destroy( bd->be_acl, frontendDB->be_acl );
+               acl_destroy( bd->be_acl );
+               frontendDB = NULL;
        }
 
        return 0;
@@ -594,8 +611,7 @@ backend_db_init(
        be->be_requires = frontendDB->be_requires;
        be->be_ssf_set = frontendDB->be_ssf_set;
 
-       be->be_pcl_mutexp = &be->be_pcl_mutex;
-       ldap_pvt_thread_mutex_init( be->be_pcl_mutexp );
+       ldap_pvt_thread_mutex_init( &be->be_pcl_mutex );
 
        /* assign a default depth limit for alias deref */
        be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH; 
@@ -609,11 +625,15 @@ 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--;
                }
        } else {
+               if ( !bi->bi_nDB ) {
+                       backend_init_controls( bi );
+               }
                bi->bi_nDB++;
        }
        return( be );
@@ -745,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 ) ) );
 }
 
@@ -946,6 +966,14 @@ backend_check_controls(
 
                        case LDAP_COMPARE_FALSE:
                                if ( !op->o_bd->be_ctrls[cid] && (*ctrls)->ldctl_iscritical ) {
+#ifdef SLAP_CONTROL_X_WHATFAILED
+                                       if ( get_whatFailed( op ) ) {
+                                               char *oids[ 2 ];
+                                               oids[ 0 ] = (*ctrls)->ldctl_oid;
+                                               oids[ 1 ] = NULL;
+                                               slap_ctrl_whatFailed_add( op, rs, oids );
+                                       }
+#endif
                                        /* RFC 4511 allows unavailableCriticalExtension to be
                                         * returned when the server is unwilling to perform
                                         * an operation extended by a recognized critical
@@ -996,13 +1024,19 @@ backend_check_restrictions(
        slap_mask_t requires;
        slap_mask_t opflag;
        slap_mask_t exopflag = 0;
-       slap_ssf_set_t *ssf;
+       slap_ssf_set_t ssfs, *ssf;
        int updateop = 0;
        int starttls = 0;
        int session = 0;
 
+       restrictops = frontendDB->be_restrictops;
+       requires = frontendDB->be_requires;
+       ssfs = frontendDB->be_ssf_set;
+       ssf = &ssfs;
+
        if ( op->o_bd ) {
-               int     rc = SLAP_CB_CONTINUE;
+               slap_ssf_t *fssf, *bssf;
+               int     rc = SLAP_CB_CONTINUE, i;
 
                if ( op->o_bd->be_chk_controls ) {
                        rc = ( *op->o_bd->be_chk_controls )( op, rs );
@@ -1016,14 +1050,13 @@ backend_check_restrictions(
                        return rs->sr_err;
                }
 
-               restrictops = op->o_bd->be_restrictops;
-               requires = op->o_bd->be_requires;
-               ssf = &op->o_bd->be_ssf_set;
-
-       } else {
-               restrictops = frontendDB->be_restrictops;
-               requires = frontendDB->be_requires;
-               ssf = &frontendDB->be_ssf_set;
+               restrictops |= op->o_bd->be_restrictops;
+               requires |= op->o_bd->be_requires;
+               bssf = &op->o_bd->be_ssf_set.sss_ssf;
+               fssf = &ssfs.sss_ssf;
+               for ( i=0; i < (int)(sizeof(ssfs)/sizeof(slap_ssf_t)); i++ ) {
+                       if ( bssf[i] ) fssf[i] = bssf[i];
+               }
        }
 
        switch( op->o_tag ) {
@@ -1282,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 ) {
@@ -1496,7 +1530,7 @@ fe_acl_group(
                                                {
                                                        rc = 0;
                                                }
-                                               filter_free_x( op, filter );
+                                               filter_free_x( op, filter, 1 );
                                        }
 loopit:
                                        ldap_free_urldesc( ludp );
@@ -1642,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;
@@ -1655,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;
@@ -1761,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 );
@@ -1771,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 );
        }
@@ -1807,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;
@@ -1822,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 ) {
@@ -1937,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 );
+}