]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/backend.c
ITS#7256 Add some necessary checks.
[openldap] / servers / slapd / backend.c
index de82ffa493b30186af82b9303d41d8175252f0cd..442cbf52034617fe03f5716c9a6c4a0af458746b 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2013 The OpenLDAP Foundation.
+ * Copyright 1998-2014 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -264,6 +264,9 @@ int backend_startup(Backend *be)
        }
 
        if(be != NULL) {
+               /* silent noop if disabled */
+               if ( SLAP_DBDISABLED( be ))
+                       return 0;
                if ( be->bd_info->bi_open ) {
                        rc = be->bd_info->bi_open( be->bd_info );
                        if ( rc != 0 ) {
@@ -315,6 +318,8 @@ int backend_startup(Backend *be)
        i = -1;
        LDAP_STAILQ_FOREACH(be, &backendDB, be_next) {
                i++;
+               if ( SLAP_DBDISABLED( be ))
+                       continue;
                if ( be->be_suffix == NULL ) {
                        Debug( LDAP_DEBUG_ANY,
                                "backend_startup: warning, database %d (%s) "
@@ -372,6 +377,8 @@ int backend_shutdown( Backend *be )
 
        /* close each backend database */
        LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( SLAP_DBDISABLED( be ))
+                       continue;
                if ( be->bd_info->bi_db_close ) {
                        be->bd_info->bi_db_close( be, NULL );
                }
@@ -666,7 +673,7 @@ select_backend(
        Backend         *be;
 
        LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
-               if ( be->be_nsuffix == NULL || SLAP_DBHIDDEN( be )) {
+               if ( be->be_nsuffix == NULL || SLAP_DBHIDDEN( be ) || SLAP_DBDISABLED( be )) {
                        continue;
                }
 
@@ -875,6 +882,69 @@ send_result:;
        return rc;
 }
 
+/* Inlined in proto-slap.h, sans assertions, when !(USE_RS_ASSERT) */
+int
+(slap_bi_op)(
+       BackendInfo *bi,
+       slap_operation_t which,
+       Operation *op,
+       SlapReply *rs )
+{
+       int rc;
+#ifndef slap_bi_op
+       void (*rsCheck)( const SlapReply *rs ) =
+               which < op_aux_operational ? rs_assert_ready : rs_assert_ok;
+#else
+#      define rsCheck(rs) ((void) 0)
+#endif
+       BI_op_func *fn;
+
+       assert( bi != NULL );
+       assert( (unsigned) which < (unsigned) op_last );
+
+       fn = (&bi->bi_op_bind)[ which ];
+
+       assert( op != NULL );
+       assert( rs != NULL );
+       assert( fn != 0 );
+       rsCheck( rs );
+
+       rc = fn( op, rs );
+
+#ifndef slap_bi_op
+       if ( rc != SLAP_CB_CONTINUE && rc != SLAP_CB_BYPASS ) {
+               int err = rs->sr_err;
+
+               if ( 0 )        /* TODO */
+               if ( err == LDAP_COMPARE_TRUE || err == LDAP_COMPARE_FALSE ) {
+                       assert( which == op_compare );
+                       assert( rc == LDAP_SUCCESS );
+               }
+
+               rsCheck = which < op_extended ? rs_assert_done : rs_assert_ok;
+               if ( which == op_aux_chk_referrals ) {
+                       if      ( rc == LDAP_SUCCESS  ) rsCheck = rs_assert_ready;
+                       else if ( rc == LDAP_REFERRAL ) rsCheck = rs_assert_done;
+               } else if ( which == op_bind ) {
+                       if      ( rc == LDAP_SUCCESS  ) rsCheck = rs_assert_ok;
+               }
+
+               /* TODO: Just what is the relation between rc and rs->sr_err? */
+               if ( rc != err &&
+                       (rc != LDAP_SUCCESS ||
+                        (err != LDAP_COMPARE_TRUE && err != LDAP_COMPARE_FALSE)) )
+               {
+                       rs->sr_err = rc;
+                       rsCheck( rs );
+                       rs->sr_err = err;
+               }
+       }
+       rsCheck( rs );
+#endif
+
+       return rc;
+}
+
 int
 be_entry_release_rw(
        Operation *op,