s4-dsdb-util: Utility function to process ldb_request in transaction
authorKamen Mazdrashki <kamen.mazdrashki@postpath.com>
Fri, 18 Dec 2009 16:11:48 +0000 (18:11 +0200)
committerAndrew Tridgell <tridge@samba.org>
Mon, 21 Dec 2009 12:44:47 +0000 (23:44 +1100)
This function is to be used later for manually crafted
ldb_requests from within dsdb layer

Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/dsdb/common/util.c

index b0f9ef0f35332d31d198e7f1fb074201d59bbed1..4f7ddde14cfbe60d37cdf823579d56902a6a1c6b 100644 (file)
@@ -996,6 +996,32 @@ int samdb_replace(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_m
        return ldb_modify(sam_ldb, msg);
 }
 
+/*
+ * Handle ldb_request in transaction
+ */
+static int dsdb_autotransaction_request(struct ldb_context *sam_ldb,
+                                struct ldb_request *req)
+{
+       int ret;
+
+       ret = ldb_transaction_start(sam_ldb);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       ret = ldb_request(sam_ldb, req);
+       if (ret == LDB_SUCCESS) {
+               ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+       }
+
+       if (ret == LDB_SUCCESS) {
+               return ldb_transaction_commit(sam_ldb);
+       }
+       ldb_transaction_cancel(sam_ldb);
+
+       return ret;
+}
+
 /*
   return a default security descriptor
 */