From d8cfca3a9bd2b6b6c562fd202377d95a98eb5472 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 May 2011 11:25:29 +0200 Subject: s3: only include tdb headers where needed. Guenther --- source3/lib/dbwrap_util.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/dbwrap_util.c') diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c index 35f8a14d0d4..365f0a06667 100644 --- a/source3/lib/dbwrap_util.c +++ b/source3/lib/dbwrap_util.c @@ -21,6 +21,7 @@ #include "includes.h" #include "dbwrap.h" +#include "util_tdb.h" int32_t dbwrap_fetch_int32(struct db_context *db, const char *keystr) { -- cgit From 019910034854dc1ed70ba09a14d419ed45903715 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 30 May 2011 17:27:23 +1000 Subject: s3-build Create dbwrap_util subsystem This contains the functions from dbwrap that don't require lp_ functions, and can therefore be put into a library (without dependency loops). Andrew Bartlett --- source3/lib/dbwrap_util.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'source3/lib/dbwrap_util.c') diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c index 365f0a06667..ce5ef527067 100644 --- a/source3/lib/dbwrap_util.c +++ b/source3/lib/dbwrap_util.c @@ -3,7 +3,10 @@ Utility functions for the dbwrap API Copyright (C) Volker Lendecke 2007 Copyright (C) Michael Adam 2009 - + Copyright (C) Jim McDonough 2006 + + Major code contributions from Aleksey Fedoseev (fedoseev@ru.ibm.com) + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -454,6 +457,66 @@ NTSTATUS dbwrap_traverse(struct db_context *db, +NTSTATUS dbwrap_delete(struct db_context *db, TDB_DATA key) +{ + struct db_record *rec; + NTSTATUS status; + + rec = db->fetch_locked(db, talloc_tos(), key); + if (rec == NULL) { + return NT_STATUS_NO_MEMORY; + } + status = rec->delete_rec(rec); + TALLOC_FREE(rec); + return status; +} + +NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key, + TDB_DATA data, int flags) +{ + struct db_record *rec; + NTSTATUS status; + + rec = db->fetch_locked(db, talloc_tos(), key); + if (rec == NULL) { + return NT_STATUS_NO_MEMORY; + } + + status = rec->store(rec, data, flags); + TALLOC_FREE(rec); + return status; +} + +TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, + TDB_DATA key) +{ + TDB_DATA result; + + if (db->fetch(db, mem_ctx, key, &result) == -1) { + return make_tdb_data(NULL, 0); + } + + return result; +} + +NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key) +{ + return dbwrap_delete(db, string_term_tdb_data(key)); +} + +NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key, + TDB_DATA data, int flags) +{ + return dbwrap_store(db, string_term_tdb_data(key), data, flags); +} + +TDB_DATA dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx, + const char *key) +{ + return dbwrap_fetch(db, mem_ctx, string_term_tdb_data(key)); +} + + NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key) { -- cgit From 5a7874e119acbc80410b2f2c1847371236c22a56 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_traverse/tdb_traverse_read: check returns for negative, not -1. TDB2 returns a negative error number on failure. This is compatible if we always check for < 0 instead of == -1. Also, there's no tdb_traverse_read in TDB2: we don't try to make traverse reliable any more, so there are no write locks anyway. Signed-off-by: Rusty Russell --- source3/lib/dbwrap_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/dbwrap_util.c') diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c index ce5ef527067..44a1b8827b6 100644 --- a/source3/lib/dbwrap_util.c +++ b/source3/lib/dbwrap_util.c @@ -433,7 +433,7 @@ static NTSTATUS dbwrap_trans_traverse_action(struct db_context* db, void* privat int ret = db->traverse(db, ctx->f, ctx->private_data); - return (ret == -1) ? NT_STATUS_INTERNAL_DB_CORRUPTION : NT_STATUS_OK; + return (ret < 0) ? NT_STATUS_INTERNAL_DB_CORRUPTION : NT_STATUS_OK; } NTSTATUS dbwrap_trans_traverse(struct db_context *db, @@ -452,7 +452,7 @@ NTSTATUS dbwrap_traverse(struct db_context *db, void *private_data) { int ret = db->traverse(db, f, private_data); - return (ret == -1) ? NT_STATUS_INTERNAL_DB_CORRUPTION : NT_STATUS_OK; + return (ret < 0) ? NT_STATUS_INTERNAL_DB_CORRUPTION : NT_STATUS_OK; } -- cgit From d925b327f4703cc141c0a7f3eec912dba8440880 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:33 +0930 Subject: tdb_compat: Higher level API fixes. My previous patches fixed up all direct TDB callers, but there are a few utility functions and the db_context functions which are still using the old -1 / 0 return codes. It's clearer to fix up all the callers of these too, so everywhere is consistent: non-zero means an error. Signed-off-by: Rusty Russell --- source3/lib/dbwrap_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/dbwrap_util.c') diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c index 44a1b8827b6..effcf40c6b3 100644 --- a/source3/lib/dbwrap_util.c +++ b/source3/lib/dbwrap_util.c @@ -492,7 +492,7 @@ TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, { TDB_DATA result; - if (db->fetch(db, mem_ctx, key, &result) == -1) { + if (db->fetch(db, mem_ctx, key, &result) != 0) { return make_tdb_data(NULL, 0); } -- cgit