[SCM] Samba Shared Repository - branch master updated

Michael Adam obnox at samba.org
Fri Jul 29 05:35:02 MDT 2011


The branch, master has been updated
       via  0b5c4a6 s3:dbwrap: move all .c and .h files of dbwrap to lib/dbwrap/
       via  d4c93ca s3-waf: replace the dbwrap_util library by a dbwrap library that contains the dbwrap core
       via  2414fc8 s3:dbwrap: move db_is_local() from dbwrap.c to dbwrap_open.c
       via  1abdd9b s3:dbwrap: move db_open() to a file dbwrap_open.c of its own.
       via  75c7320 s3:g_lock: explicitly include dbwrap.h
       via  ee3be0d s3:modules:nfs4_acls: fix the include of dbwrap.h to not include "include/"
       via  f72153e s3:dbwrap: explicitly include dbwrap.h in dbwrap_ctdb.c
      from  d004fd0 talloc: added test suite for talloc_free_children()

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 0b5c4a601a983aab06e4aba158cd9359babd1e71
Author: Michael Adam <obnox at samba.org>
Date:   Thu Jul 7 17:42:08 2011 +0200

    s3:dbwrap: move all .c and .h files of dbwrap to lib/dbwrap/
    
    Autobuild-User: Michael Adam <obnox at samba.org>
    Autobuild-Date: Fri Jul 29 13:34:22 CEST 2011 on sn-devel-104

commit d4c93ca721d0edd8780ce84e7cccd0e5a1ea4f37
Author: Michael Adam <obnox at samba.org>
Date:   Wed Jul 6 17:02:13 2011 +0200

    s3-waf: replace the dbwrap_util library by a dbwrap library that contains the dbwrap core

commit 2414fc88d85c8dcc22ddbb389255d6c36838cbad
Author: Michael Adam <obnox at samba.org>
Date:   Wed Jul 6 16:49:34 2011 +0200

    s3:dbwrap: move db_is_local() from dbwrap.c to dbwrap_open.c

commit 1abdd9b2bb09d072496db5207814aefefe403f60
Author: Michael Adam <obnox at samba.org>
Date:   Wed Jul 6 16:40:21 2011 +0200

    s3:dbwrap: move db_open() to a file dbwrap_open.c of its own.
    
    Also start new folder lib/dbwrap/ where dbwrap_open.c is stored and
    make the fallbacke implementation functoins non-static and create a
    dbwrap_private.h header file that contains their prototypes.

commit 75c7320497dc53d23bced5472faef7d9c31c1d9b
Author: Michael Adam <obnox at samba.org>
Date:   Wed Jul 6 16:09:17 2011 +0200

    s3:g_lock: explicitly include dbwrap.h

commit ee3be0defab27a7ab95144a6ee7fc6050e9e7265
Author: Michael Adam <obnox at samba.org>
Date:   Wed Jul 6 16:14:18 2011 +0200

    s3:modules:nfs4_acls: fix the include of dbwrap.h to not include "include/"

commit f72153ea83368cd7035b4a1003e35fedcb905ff6
Author: Michael Adam <obnox at samba.org>
Date:   Wed Jul 6 14:27:03 2011 +0200

    s3:dbwrap: explicitly include dbwrap.h in dbwrap_ctdb.c
    
    This used to come in via g_lock.h
    
    Pair-Programmed-With: Gregor Beck <gbeck at sernet.de>

-----------------------------------------------------------------------

Summary of changes:
 source3/Makefile.in                       |   10 +-
 source3/groupdb/mapping_tdb.c             |    3 +-
 source3/include/dbwrap.h                  |  145 ---
 source3/include/g_lock.h                  |    2 +-
 source3/lib/conn_tdb.c                    |    3 +-
 source3/lib/dbwrap.c                      |  159 ----
 source3/lib/dbwrap/dbwrap.c               |   66 ++
 source3/lib/dbwrap/dbwrap.h               |  138 +++
 source3/lib/dbwrap/dbwrap_ctdb.c          | 1440 +++++++++++++++++++++++++++++
 source3/lib/{ => dbwrap}/dbwrap_file.c    |    0
 source3/lib/dbwrap/dbwrap_open.c          |  119 +++
 source3/lib/dbwrap/dbwrap_open.h          |   43 +
 source3/lib/dbwrap/dbwrap_private.h       |   38 +
 source3/lib/dbwrap/dbwrap_rbt.c           |  420 +++++++++
 source3/lib/dbwrap/dbwrap_tdb.c           |  379 ++++++++
 source3/lib/{ => dbwrap}/dbwrap_util.c    |    0
 source3/lib/dbwrap_ctdb.c                 | 1439 ----------------------------
 source3/lib/dbwrap_rbt.c                  |  420 ---------
 source3/lib/dbwrap_tdb.c                  |  379 --------
 source3/lib/g_lock.c                      |    2 +
 source3/lib/messages.c                    |    2 +-
 source3/lib/privileges.c                  |    2 +-
 source3/lib/serverid.c                    |    3 +-
 source3/lib/sessionid_tdb.c               |    3 +-
 source3/lib/sharesec.c                    |    3 +-
 source3/lib/talloc_dict.c                 |    2 +-
 source3/libnet/libnet_dssync_passdb.c     |    2 +-
 source3/locking/brlock.c                  |    3 +-
 source3/locking/locking.c                 |    3 +-
 source3/locking/posix.c                   |    2 +-
 source3/modules/nfs4_acls.c               |    3 +-
 source3/modules/vfs_acl_tdb.c             |    3 +-
 source3/modules/vfs_xattr_tdb.c           |    3 +-
 source3/param/loadparm.c                  |    2 +-
 source3/passdb/account_pol.c              |    3 +-
 source3/passdb/machine_account_secrets.c  |    2 +-
 source3/passdb/machine_sid.c              |    2 +-
 source3/passdb/pdb_tdb.c                  |    3 +-
 source3/passdb/secrets.c                  |    3 +-
 source3/printing/printer_list.c           |    3 +-
 source3/registry/reg_backend_db.c         |    3 +-
 source3/registry/reg_objects.c            |    2 +-
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c |    2 +-
 source3/smbd/connection.c                 |    2 +-
 source3/smbd/notify_internal.c            |    3 +-
 source3/smbd/session.c                    |    2 +-
 source3/torture/torture.c                 |    3 +-
 source3/utils/dbwrap_tool.c               |    3 +-
 source3/utils/dbwrap_torture.c            |    3 +-
 source3/utils/net_idmap.c                 |    3 +-
 source3/utils/net_idmap_check.c           |    3 +-
 source3/utils/net_serverid.c              |    2 +-
 source3/utils/status.c                    |    3 +-
 source3/winbindd/idmap_autorid.c          |    3 +-
 source3/winbindd/idmap_tdb.c              |    3 +-
 source3/winbindd/idmap_tdb2.c             |    3 +-
 source3/wscript_build                     |   13 +-
 57 files changed, 2722 insertions(+), 2591 deletions(-)
 delete mode 100644 source3/include/dbwrap.h
 delete mode 100644 source3/lib/dbwrap.c
 create mode 100644 source3/lib/dbwrap/dbwrap.c
 create mode 100644 source3/lib/dbwrap/dbwrap.h
 create mode 100644 source3/lib/dbwrap/dbwrap_ctdb.c
 rename source3/lib/{ => dbwrap}/dbwrap_file.c (100%)
 create mode 100644 source3/lib/dbwrap/dbwrap_open.c
 create mode 100644 source3/lib/dbwrap/dbwrap_open.h
 create mode 100644 source3/lib/dbwrap/dbwrap_private.h
 create mode 100644 source3/lib/dbwrap/dbwrap_rbt.c
 create mode 100644 source3/lib/dbwrap/dbwrap_tdb.c
 rename source3/lib/{ => dbwrap}/dbwrap_util.c (100%)
 delete mode 100644 source3/lib/dbwrap_ctdb.c
 delete mode 100644 source3/lib/dbwrap_rbt.c
 delete mode 100644 source3/lib/dbwrap_tdb.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 51b0a7c..f0718ce 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -260,10 +260,12 @@ EXTRA_ALL_TARGETS = @EXTRA_ALL_TARGETS@
 
 TDB_LIB_OBJ = lib/util_tdb.o ../lib/util/util_tdb.o \
 	  ../lib/util/tdb_wrap.o \
-	  lib/dbwrap.o lib/dbwrap_tdb.o \
-	  lib/dbwrap_ctdb.o \
+	  lib/dbwrap/dbwrap.o \
+	  lib/dbwrap/dbwrap_open.o \
+	  lib/dbwrap/dbwrap_tdb.o \
+	  lib/dbwrap/dbwrap_ctdb.o \
 	  lib/g_lock.o \
-	  lib/dbwrap_rbt.o
+	  lib/dbwrap/dbwrap_rbt.o
 
 TDB_VALIDATE_OBJ = lib/tdb_validate.o
 
@@ -453,7 +455,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \
 	  ../lib/util/charset/util_unistr_w.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \
 	  lib/util.o lib/util_malloc.o lib/namearray.o lib/util_cmdline.o lib/util_names.o \
 	  lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
-	  lib/substitute.o lib/substitute_generic.o ../lib/util/substitute.o lib/dbwrap_util.o \
+	  lib/substitute.o lib/substitute_generic.o ../lib/util/substitute.o lib/dbwrap/dbwrap_util.o \
 	  lib/ms_fnmatch.o ../lib/util/ms_fnmatch.o lib/errmap_unix.o ../libcli/util/errmap_unix.o \
 	  lib/tallocmsg.o lib/dmallocmsg.o \
 	  libsmb/clisigning.o libsmb/smb_signing.o \
diff --git a/source3/groupdb/mapping_tdb.c b/source3/groupdb/mapping_tdb.c
index fc195cb..47f743d 100644
--- a/source3/groupdb/mapping_tdb.c
+++ b/source3/groupdb/mapping_tdb.c
@@ -24,7 +24,8 @@
 #include "system/filesys.h"
 #include "passdb.h"
 #include "groupdb/mapping.h"
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "util_tdb.h"
 #include "../libcli/security/security.h"
 
diff --git a/source3/include/dbwrap.h b/source3/include/dbwrap.h
deleted file mode 100644
index 303a554..0000000
--- a/source3/include/dbwrap.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   Database interface wrapper around tdb
-   Copyright (C) Volker Lendecke 2005-2007
-
-   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 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef __DBWRAP_H__
-#define __DBWRAP_H__
-
-#include "tdb_compat.h"
-
-struct db_record {
-	TDB_DATA key, value;
-	NTSTATUS (*store)(struct db_record *rec, TDB_DATA data, int flag);
-	NTSTATUS (*delete_rec)(struct db_record *rec);
-	void *private_data;
-};
-
-struct db_context {
-	struct db_record *(*fetch_locked)(struct db_context *db,
-					  TALLOC_CTX *mem_ctx,
-					  TDB_DATA key);
-	int (*fetch)(struct db_context *db, TALLOC_CTX *mem_ctx,
-		     TDB_DATA key, TDB_DATA *data);
-	int (*traverse)(struct db_context *db,
-			int (*f)(struct db_record *rec,
-				 void *private_data),
-			void *private_data);
-	int (*traverse_read)(struct db_context *db,
-			     int (*f)(struct db_record *rec,
-				      void *private_data),
-			     void *private_data);
-	int (*get_seqnum)(struct db_context *db);
-	int (*get_flags)(struct db_context *db);
-	int (*transaction_start)(struct db_context *db);
-	int (*transaction_commit)(struct db_context *db);
-	int (*transaction_cancel)(struct db_context *db);
-	int (*parse_record)(struct db_context *db, TDB_DATA key,
-			    int (*parser)(TDB_DATA key, TDB_DATA data,
-					  void *private_data),
-			    void *private_data);
-	void *private_data;
-	bool persistent;
-};
-
-bool db_is_local(const char *name);
-
-struct db_context *db_open(TALLOC_CTX *mem_ctx,
-			   const char *name,
-			   int hash_size, int tdb_flags,
-			   int open_flags, mode_t mode);
-
-struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx);
-
-struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
-			       const char *name,
-			       int hash_size, int tdb_flags,
-			       int open_flags, mode_t mode);
-
-struct messaging_context;
-
-#ifdef CLUSTER_SUPPORT
-struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
-				const char *name,
-				int hash_size, int tdb_flags,
-				int open_flags, mode_t mode);
-#endif
-
-struct db_context *db_open_file(TALLOC_CTX *mem_ctx,
-				struct messaging_context *msg_ctx,
-				const char *name,
-				int hash_size, int tdb_flags,
-				int open_flags, mode_t mode);
-
-
-NTSTATUS dbwrap_delete(struct db_context *db, TDB_DATA key);
-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);
-NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
-NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
-			       TDB_DATA data, int flags);
-TDB_DATA dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
-			       const char *key);
-
-/* The following definitions come from lib/dbwrap_util.c  */
-
-int32_t dbwrap_fetch_int32(struct db_context *db, const char *keystr);
-int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v);
-bool dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
-			 uint32_t *val);
-int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v);
-NTSTATUS dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
-				     uint32_t *oldval, uint32_t change_val);
-NTSTATUS dbwrap_trans_change_uint32_atomic(struct db_context *db,
-					   const char *keystr,
-					   uint32_t *oldval,
-					   uint32_t change_val);
-NTSTATUS dbwrap_change_int32_atomic(struct db_context *db, const char *keystr,
-				    int32_t *oldval, int32_t change_val);
-NTSTATUS dbwrap_trans_change_int32_atomic(struct db_context *db,
-					  const char *keystr,
-					  int32_t *oldval,
-					  int32_t change_val);
-NTSTATUS dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf,
-			    int flag);
-NTSTATUS dbwrap_trans_delete(struct db_context *db, TDB_DATA key);
-NTSTATUS dbwrap_trans_store_int32(struct db_context *db, const char *keystr,
-				  int32_t v);
-NTSTATUS dbwrap_trans_store_uint32(struct db_context *db, const char *keystr,
-				   uint32_t v);
-NTSTATUS dbwrap_trans_store_bystring(struct db_context *db, const char *key,
-				     TDB_DATA data, int flags);
-NTSTATUS dbwrap_trans_delete_bystring(struct db_context *db, const char *key);
-NTSTATUS dbwrap_trans_do(struct db_context *db,
-			 NTSTATUS (*action)(struct db_context *, void *),
-			 void *private_data);
-NTSTATUS dbwrap_trans_traverse(struct db_context *db,
-			       int (*f)(struct db_record*, void*),
-			       void *private_data);
-NTSTATUS dbwrap_traverse(struct db_context *db,
-			 int (*f)(struct db_record*, void*),
-			 void *private_data);
-
-NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key);
-NTSTATUS dbwrap_store_bystring_upper(struct db_context *db, const char *key,
-				     TDB_DATA data, int flags);
-TDB_DATA dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
-				     const char *key);
-
-#endif /* __DBWRAP_H__ */
diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 4092230..fc9a872 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -20,7 +20,7 @@
 #ifndef _G_LOCK_H_
 #define _G_LOCK_H_
 
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
 
 struct g_lock_ctx;
 
diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c
index 50f0d9f..f458480 100644
--- a/source3/lib/conn_tdb.c
+++ b/source3/lib/conn_tdb.c
@@ -20,7 +20,8 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "smbd/globals.h"
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 
 static struct db_context *connections_db_ctx(bool rw)
 {
diff --git a/source3/lib/dbwrap.c b/source3/lib/dbwrap.c
deleted file mode 100644
index 83fc40e..0000000
--- a/source3/lib/dbwrap.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   Database interface wrapper
-   Copyright (C) Jim McDonough <jmcd at us.ibm.com> 2006
-
-   Major code contributions from Aleksey Fedoseev (fedoseev at 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 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "dbwrap.h"
-#include "util_tdb.h"
-#ifdef CLUSTER_SUPPORT
-#include "ctdb_private.h"
-#endif
-/*
- * Fall back using fetch_locked if no genuine fetch operation is provided
- */
-
-static int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-				 TDB_DATA key, TDB_DATA *data)
-{
-	struct db_record *rec;
-
-	if (!(rec = db->fetch_locked(db, mem_ctx, key))) {
-		return -1;
-	}
-
-	data->dsize = rec->value.dsize;
-	data->dptr = talloc_move(mem_ctx, &rec->value.dptr);
-	TALLOC_FREE(rec);
-	return 0;
-}
-
-/*
- * Fall back using fetch if no genuine parse operation is provided
- */
-
-static int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key,
-					int (*parser)(TDB_DATA key,
-						      TDB_DATA data,
-						      void *private_data),
-					void *private_data)
-{
-	TDB_DATA data;
-	int res;
-
-	res = db->fetch(db, talloc_tos(), key, &data);
-	if (res != 0) {
-		return res;
-	}
-
-	res = parser(key, data, private_data);
-	TALLOC_FREE(data.dptr);
-	return res;
-}
-
-bool db_is_local(const char *name)
-{
-#ifdef CLUSTER_SUPPORT
-	const char *sockname = lp_ctdbd_socket();
-
-	if(!sockname || !*sockname) {
-		sockname = CTDB_PATH;
-	}
-
-	if (lp_clustering() && socket_exist(sockname)) {
-		const char *partname;
-		/* ctdb only wants the file part of the name */
-		partname = strrchr(name, '/');
-		if (partname) {
-			partname++;
-		} else {
-			partname = name;
-		}
-		/* allow ctdb for individual databases to be disabled */
-		if (lp_parm_bool(-1, "ctdb", partname, True)) {
-			return false;
-		}
-	}
-#endif
-	return true;
-}
-
-/**
- * open a database
- */
-struct db_context *db_open(TALLOC_CTX *mem_ctx,
-			   const char *name,
-			   int hash_size, int tdb_flags,
-			   int open_flags, mode_t mode)
-{
-	struct db_context *result = NULL;
-#ifdef CLUSTER_SUPPORT
-	const char *sockname = lp_ctdbd_socket();
-
-	if(!sockname || !*sockname) {
-		sockname = CTDB_PATH;
-	}
-
-	if (lp_clustering()) {
-		const char *partname;
-
-		if (!socket_exist(sockname)) {
-			DEBUG(1, ("ctdb socket does not exist - is ctdb not "
-				  "running?\n"));
-			return NULL;
-		}
-
-		/* ctdb only wants the file part of the name */
-		partname = strrchr(name, '/');
-		if (partname) {
-			partname++;
-		} else {
-			partname = name;
-		}
-		/* allow ctdb for individual databases to be disabled */
-		if (lp_parm_bool(-1, "ctdb", partname, True)) {
-			result = db_open_ctdb(mem_ctx, partname, hash_size,
-					      tdb_flags, open_flags, mode);
-			if (result == NULL) {
-				DEBUG(0,("failed to attach to ctdb %s\n",
-					 partname));
-				if (errno == 0) {
-					errno = EIO;
-				}
-				return NULL;
-			}
-		}
-	}
-
-#endif
-
-	if (result == NULL) {
-		result = db_open_tdb(mem_ctx, name, hash_size,
-				     tdb_flags, open_flags, mode);
-	}
-
-	if ((result != NULL) && (result->fetch == NULL)) {
-		result->fetch = dbwrap_fallback_fetch;
-	}
-	if ((result != NULL) && (result->parse_record == NULL)) {
-		result->parse_record = dbwrap_fallback_parse_record;
-	}
-
-	return result;
-}
diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c
new file mode 100644
index 0000000..6a6d4c6
--- /dev/null
+++ b/source3/lib/dbwrap/dbwrap.c
@@ -0,0 +1,66 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Database interface wrapper
+   Copyright (C) Jim McDonough <jmcd at us.ibm.com> 2006
+
+   Major code contributions from Aleksey Fedoseev (fedoseev at 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 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_private.h"
+
+/*
+ * Fall back using fetch_locked if no genuine fetch operation is provided
+ */
+
+int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			  TDB_DATA key, TDB_DATA *data)
+{
+	struct db_record *rec;
+
+	if (!(rec = db->fetch_locked(db, mem_ctx, key))) {
+		return -1;
+	}
+
+	data->dsize = rec->value.dsize;
+	data->dptr = talloc_move(mem_ctx, &rec->value.dptr);
+	TALLOC_FREE(rec);
+	return 0;
+}
+
+/*
+ * Fall back using fetch if no genuine parse operation is provided
+ */
+
+int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key,
+				 int (*parser)(TDB_DATA key,
+					       TDB_DATA data,
+					       void *private_data),
+				 void *private_data)
+{
+	TDB_DATA data;
+	int res;
+
+	res = db->fetch(db, talloc_tos(), key, &data);
+	if (res != 0) {
+		return res;
+	}
+
+	res = parser(key, data, private_data);
+	TALLOC_FREE(data.dptr);
+	return res;
+}
diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h
new file mode 100644
index 0000000..9084f87
--- /dev/null
+++ b/source3/lib/dbwrap/dbwrap.h
@@ -0,0 +1,138 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Database interface wrapper around tdb
+   Copyright (C) Volker Lendecke 2005-2007
+
+   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 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __DBWRAP_H__
+#define __DBWRAP_H__
+
+#include "tdb_compat.h"
+
+struct db_record {
+	TDB_DATA key, value;
+	NTSTATUS (*store)(struct db_record *rec, TDB_DATA data, int flag);
+	NTSTATUS (*delete_rec)(struct db_record *rec);
+	void *private_data;
+};
+
+struct db_context {
+	struct db_record *(*fetch_locked)(struct db_context *db,
+					  TALLOC_CTX *mem_ctx,
+					  TDB_DATA key);
+	int (*fetch)(struct db_context *db, TALLOC_CTX *mem_ctx,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list