+ /* close each backend database */
+ for( i = 0; i < nBackendDB; i++ ) {
+ BackendInfo *bi;
+
+ if ( backendDB[i].bd_info->bi_db_close ) {
+ backendDB[i].bd_info->bi_db_close(
+ &backendDB[i] );
+ }
+
+ if(rc != 0) {
+ Debug( LDAP_DEBUG_ANY,
+ "backend_close: bi_close %s failed!\n",
+ bi->bi_type, 0, 0 );
+ }
+ }
+
+ /* close each backend type */
+ for( i = 0; i < nBackendInfo; i++ ) {
+ if( backendInfo[i].bi_nDB == 0 ) {
+ /* no database of this type */
+ continue;
+ }
+
+ if( backendInfo[i].bi_close ) {
+ backendInfo[i].bi_close(
+ &backendInfo[i] );
+ }
+ }
+
+ return 0;
+}
+
+int backend_destroy(void)
+{
+ int i;
+
+ /* destroy each backend database */
+ for( i = 0; i < nBackendDB; i++ ) {
+ if ( backendDB[i].bd_info->bi_db_destroy ) {
+ backendDB[i].bd_info->bi_db_destroy(
+ &backendDB[i] );
+ }
+ }
+
+ /* destroy each backend type */
+ for( i = 0; i < nBackendInfo; i++ ) {
+ if( backendInfo[i].bi_destroy ) {
+ backendInfo[i].bi_destroy(
+ &backendInfo[i] );
+ }
+ }
+
+#ifdef SLAPD_MODULES
+ if (backendInfo != binfo) {
+ free(backendInfo);
+ }
+#endif /* SLAPD_MODULES */
+
+ nBackendInfo = 0;
+ backendInfo = NULL;
+
+ return 0;
+}
+
+BackendInfo* backend_info(char *type)
+{
+ int i;
+
+ /* search for the backend type */
+ for( i = 0; i < nBackendInfo; i++ ) {
+ if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
+ return &backendInfo[i];
+ }
+ }
+
+ return NULL;
+}
+
+
+BackendDB *
+backend_db_init(
+ char *type
+)
+{
+ Backend *be;
+ BackendInfo *bi = backend_info(type);
+ int rc = 0;
+
+ if( bi == NULL ) {