s3:dbwrap: add function dbwrap_wipe()
authorGregor Beck <gbeck@sernet.de>
Tue, 16 Aug 2011 12:39:19 +0000 (14:39 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 11 Oct 2011 13:33:20 +0000 (15:33 +0200)
Signed-off-by: Michael Adam <obnox@samba.org>
source3/include/dbwrap.h
source3/lib/dbwrap.c

index e3f2228f5033c270d4f6a41846f7cbbb1f480caf..e8493ed242bbbe9b73da7b0bc2d7f04c5dd53c33 100644 (file)
@@ -53,6 +53,7 @@ struct db_context {
                                          void *private_data),
                            void *private_data);
        int (*exists)(struct db_context *db,TDB_DATA key);
+       int (*wipe)(struct db_context *db);
        void *private_data;
        bool persistent;
 };
@@ -92,6 +93,7 @@ NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key,
                      TDB_DATA data, int flags);
 TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
                      TDB_DATA key);
+int dbwrap_wipe(struct db_context *db);
 bool dbwrap_exists(struct db_context *db, TDB_DATA key);
 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
 NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
index e1b3f26f4b92c3b3fe8266a692b2b63ac3ff247b..1b5748ee0412b82ff304db1f635c5c9ec788bd01 100644 (file)
@@ -62,6 +62,21 @@ static int dbwrap_fallback_exists(struct db_context *db, TDB_DATA key)
        }
 }
 
+static int delete_record(struct db_record *rec, void *data)
+{
+       NTSTATUS status = rec->delete_rec(rec);
+       return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
+
+/*
+ * Fall back using traverse and delete if no genuine wipe operation is provided
+ */
+static int dbwrap_fallback_wipe(struct db_context *db)
+{
+       NTSTATUS status = dbwrap_trans_traverse(db, &delete_record, NULL);
+       return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
+
 /*
  * Fall back using fetch if no genuine parse operation is provided
  */
@@ -173,6 +188,10 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
                result->parse_record = dbwrap_fallback_parse_record;
        }
 
+       if ((result != NULL) && (result->wipe == NULL)) {
+               result->wipe = dbwrap_fallback_wipe;
+       }
+
        return result;
 }
 
@@ -218,6 +237,10 @@ TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
        return result;
 }
 
+int dbwrap_wipe(struct db_context *db) {
+       return db->wipe(db);
+}
+
 bool dbwrap_exists(struct db_context *db, TDB_DATA key)
 {
        int result;