]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/tools.c
Changes from HEAD for beta
[openldap] / servers / slapd / back-bdb / tools.c
index 69aeea22aea59b9ae632faf1da58688638f50679..354589cc35b53012b21577b3574a3796256a7276 100644 (file)
@@ -104,6 +104,54 @@ ID bdb_tool_entry_next(
        return id;
 }
 
+ID bdb_tool_dn2id_get(
+       Backend *be,
+       struct berval *dn
+)
+{
+       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       DB *db = bdb->bi_dn2id->bdi_db;
+       int rc;
+       DBT     key, data;
+       ID      id;
+
+       DBTzero( &key );
+       key.size = dn->bv_len + 2;
+       key.data = ch_malloc( key.size );
+       ((char*)key.data)[0] = DN_BASE_PREFIX;
+       AC_MEMCPY( &((char*)key.data)[1], dn->bv_val, key.size - 1 );
+
+       DBTzero( &data );
+       data.data = &id;
+       data.ulen = sizeof(ID);
+       data.flags = DB_DBT_USERMEM;
+
+       rc = db->get( db, NULL, &key, &data, bdb->bi_db_opflags );
+
+    if( rc != 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG ( INDEX, ERR, "bdb_tool_dn2id_get: get failed %s (%d)\n",
+                               db_strerror(rc), rc, 0 );
+#else
+               Debug( LDAP_DEBUG_TRACE, "bdb_tool_dn2id_get: get failed: %s (%d)\n",
+                               db_strerror( rc ), rc, 0 );
+#endif
+               id = NOID;
+       }
+
+       ch_free( key.data );
+       return id;
+}
+
+int bdb_tool_id2entry_get(
+       Backend *be,
+       ID id,
+       Entry **e
+)
+{
+       return bdb_id2entry( be, NULL, id, e );
+}
+
 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
 {
        int rc;
@@ -173,10 +221,10 @@ static int bdb_tool_next_id(
                                db_strerror(rc), rc );
 #ifdef NEW_LOGGING
                LDAP_LOG ( TOOLS, ERR, 
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #endif
                        return rc;
                }
@@ -188,10 +236,10 @@ static int bdb_tool_next_id(
                                db_strerror(rc), rc );
 #ifdef NEW_LOGGING
                LDAP_LOG ( TOOLS, ERR, 
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #endif
                } else if ( hole ) {
                        if ( nholes == nhmax - 1 ) {
@@ -464,3 +512,134 @@ done:
 
        return rc;
 }
+
+ID bdb_tool_entry_modify(
+       BackendDB *be,
+       Entry *e,
+       struct berval *text )
+{
+       int rc;
+       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       DB_TXN *tid = NULL;
+       Operation op = {0};
+
+       assert( be != NULL );
+       assert( slapMode & SLAP_TOOL_MODE );
+
+       assert( text );
+       assert( text->bv_val );
+       assert( text->bv_val[0] == '\0' );      /* overconservative? */
+
+       assert ( e->e_id != NOID );
+       assert ( e->e_id != 0 );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG ( TOOLS, ARGS, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
+               (long) e->e_id, e->e_dn, 0 );
+#else
+       Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
+               (long) e->e_id, e->e_dn, 0 );
+#endif
+
+       rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid, 
+               bdb->bi_db_opflags );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                       "txn_begin failed: %s (%d)",
+                       db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+       LDAP_LOG ( TOOLS, ERR, "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n",
+                        text->bv_val, 0, 0 );
+#endif
+               return NOID;
+       }
+
+       op.o_bd = be;
+       op.o_tmpmemctx = NULL;
+       op.o_tmpmfuncs = &ch_mfuncs;
+
+       /* id2entry index */
+       rc = bdb_id2entry_update( be, tid, e );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                               "id2entry_add failed: %s (%d)",
+                               db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#endif
+               goto done;
+       }
+
+       rc = bdb_index_entry_del( &op, tid, e );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                               "index_entry_del failed: %s (%d)",
+                               db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#endif
+               goto done;
+       }
+
+       rc = bdb_index_entry_add( &op, tid, e );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                               "index_entry_add failed: %s (%d)",
+                               db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#endif
+               goto done;
+       }
+
+done:
+       if( rc == 0 ) {
+               rc = TXN_COMMIT( tid, 0 );
+               if( rc != 0 ) {
+                       snprintf( text->bv_val, text->bv_len,
+                                       "txn_commit failed: %s (%d)",
+                                       db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+                       LDAP_LOG ( TOOLS, ERR, 
+                               "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY,
+                               "=> bdb_tool_entry_put: %s\n",
+                               text->bv_val, 0, 0 );
+#endif
+                       e->e_id = NOID;
+               }
+
+       } else {
+               TXN_ABORT( tid );
+               snprintf( text->bv_val, text->bv_len,
+                       "txn_aborted! %s (%d)",
+                       db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n",
+                       text->bv_val, 0, 0 );
+#endif
+               e->e_id = NOID;
+       }
+
+       return e->e_id;
+}