s3:dbwrap: move db_open() to a file dbwrap_open.c of its own.
authorMichael Adam <obnox@samba.org>
Wed, 6 Jul 2011 14:40:21 +0000 (16:40 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 29 Jul 2011 10:23:13 +0000 (12:23 +0200)
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.

33 files changed:
source3/Makefile.in
source3/groupdb/mapping_tdb.c
source3/include/dbwrap.h
source3/lib/conn_tdb.c
source3/lib/dbwrap.c
source3/lib/dbwrap/dbwrap_open.c [new file with mode: 0644]
source3/lib/dbwrap/dbwrap_open.h [new file with mode: 0644]
source3/lib/dbwrap/dbwrap_private.h [new file with mode: 0644]
source3/lib/g_lock.c
source3/lib/serverid.c
source3/lib/sessionid_tdb.c
source3/lib/sharesec.c
source3/locking/brlock.c
source3/locking/locking.c
source3/modules/nfs4_acls.c
source3/modules/vfs_acl_tdb.c
source3/modules/vfs_xattr_tdb.c
source3/passdb/account_pol.c
source3/passdb/pdb_tdb.c
source3/passdb/secrets.c
source3/printing/printer_list.c
source3/registry/reg_backend_db.c
source3/smbd/notify_internal.c
source3/torture/torture.c
source3/utils/dbwrap_tool.c
source3/utils/dbwrap_torture.c
source3/utils/net_idmap.c
source3/utils/net_idmap_check.c
source3/utils/status.c
source3/winbindd/idmap_autorid.c
source3/winbindd/idmap_tdb.c
source3/winbindd/idmap_tdb2.c
source3/wscript_build

index 51b0a7cb67db728bf28ea4df774e68a27fcb715e..ddcc8be3f929895b3699f3f16fa7200ab4997ff1 100644 (file)
@@ -260,7 +260,8 @@ 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.o lib/dbwrap/dbwrap_open.o \
+         lib/dbwrap_tdb.o \
          lib/dbwrap_ctdb.o \
          lib/g_lock.o \
          lib/dbwrap_rbt.o
index fc195cb348731853319ec8441d075cf6d240217a..cf038155ae287c30e00b0a733cfb6d9ee77d3cb4 100644 (file)
@@ -25,6 +25,7 @@
 #include "passdb.h"
 #include "groupdb/mapping.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "util_tdb.h"
 #include "../libcli/security/security.h"
 
index 303a5549381119c45da41ec5bfa4cc1fb29282f9..194692ca60d485ed6fe008dd48576d467cdf76e3 100644 (file)
@@ -58,11 +58,6 @@ struct db_context {
 
 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,
index 50f0d9fa1bb10a41c8632d1166a66c30134bcac7..669ddb2a3af9790d8be1ddec99508c04f10f205a 100644 (file)
@@ -21,6 +21,7 @@
 #include "system/filesys.h"
 #include "smbd/globals.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 
 static struct db_context *connections_db_ctx(bool rw)
 {
index 83fc40efacf14a40ce1b3cebfc43c2b26203e7bb..0774974ceddd5e21c78acf09330c8a0a905a17ad 100644 (file)
 
 #include "includes.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_private.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)
+int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+                         TDB_DATA key, TDB_DATA *data)
 {
        struct db_record *rec;
 
@@ -48,11 +51,11 @@ static int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
  * 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)
+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;
@@ -93,67 +96,3 @@ bool db_is_local(const char *name)
 #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_open.c b/source3/lib/dbwrap/dbwrap_open.c
new file mode 100644 (file)
index 0000000..d6b2f30
--- /dev/null
@@ -0,0 +1,92 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Database interface wrapper
+
+   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/>.
+*/
+
+#include "includes.h"
+#include "dbwrap.h"
+#include "dbwrap/dbwrap_private.h"
+#include "dbwrap/dbwrap_open.h"
+#include "util_tdb.h"
+#ifdef CLUSTER_SUPPORT
+#include "ctdb_private.h"
+#endif
+
+/**
+ * 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_open.h b/source3/lib/dbwrap/dbwrap_open.h
new file mode 100644 (file)
index 0000000..153e91a
--- /dev/null
@@ -0,0 +1,37 @@
+/* 
+   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_OPEN_H__
+#define __DBWRAP_OPEN_H__
+
+struct db_context;
+
+/**
+ * Convenience function that will determine whether to
+ * open a tdb database via the tdb backend or via the ctdb
+ * backend, based on lp_clustering() and a db-specific
+ * settings.
+ */
+struct db_context *db_open(TALLOC_CTX *mem_ctx,
+                          const char *name,
+                          int hash_size, int tdb_flags,
+                          int open_flags, mode_t mode);
+
+#endif /* __DBWRAP_OPEN_H__ */
diff --git a/source3/lib/dbwrap/dbwrap_private.h b/source3/lib/dbwrap/dbwrap_private.h
new file mode 100644 (file)
index 0000000..c8f3a10
--- /dev/null
@@ -0,0 +1,38 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Database interface wrapper around tdb - private header
+
+   Copyright (C) Volker Lendecke 2005-2007
+   Copyright (C) Gregor Beck 2011
+   Copyright (C) Michael Adam 2011
+
+   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_PRIVATE_H__
+#define __DBWRAP_PRIVATE_H__
+
+
+int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+                         TDB_DATA key, TDB_DATA *data);
+
+
+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);
+
+#endif /* __DBWRAP_PRIVATE_H__ */
+
index c4ac8e372bb46335eca37b84122d091dc588143b..3a983d5fb7ca28bfcdbd436a753be91d7be4891c 100644 (file)
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "g_lock.h"
 #include "util_tdb.h"
 #include "ctdbd_conn.h"
index 1a1141265a159d19e781252f2c635ed288a7e8f3..f2ba07ab34f7c4f2c58d3ef7d47ec6c63daf6ac9 100644 (file)
@@ -22,6 +22,7 @@
 #include "serverid.h"
 #include "util_tdb.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "lib/util/tdb_wrap.h"
 
 struct serverid_key {
index de3ccab26ae84003ccd15cee58841fff490b31c9..dc3f61c33b53843c127960b87b5254dda010949f 100644 (file)
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "session.h"
 #include "util_tdb.h"
 
index 11ccb42300c594f1474e29ed76a9a9f222522ee4..fa67567537ffc535c4c97f0d2ae31981e04a57ee 100644 (file)
@@ -22,6 +22,7 @@
 #include "../libcli/security/security.h"
 #include "../librpc/gen_ndr/ndr_security.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "util_tdb.h"
 
 /*******************************************************************
index a429768e69694680391cecfb57bf255f0a06f3ac..70147f4844d237017620beba5bd60a0248730a11 100644 (file)
@@ -29,6 +29,7 @@
 #include "locking/proto.h"
 #include "smbd/globals.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "serverid.h"
 #include "messages.h"
 
index 81e93a555a129d2d4f44fdb63c4f76e6a2493f44..0c5076f80621a4682d2689be3bcbfdbbf97c98d9 100644 (file)
@@ -40,6 +40,7 @@
 #include "locking/proto.h"
 #include "smbd/globals.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "serverid.h"
 #include "messages.h"
index 6739e78050637763dd9a69d683d74e523445913c..6f52bd1cd76c9e09dfb0317190ffec981474f5f2 100644 (file)
@@ -24,6 +24,7 @@
 #include "../libcli/security/dom_sid.h"
 #include "../libcli/security/security.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "system/filesys.h"
 #include "passdb/lookup_sid.h"
 #include "util_tdb.h"
index 0b03896dd90ae4ec307e04b6af3f589d5e44c950..abfe6ee32cfce4673867469d5b303cff07de85f1 100644 (file)
@@ -27,6 +27,7 @@
 #include "librpc/gen_ndr/ndr_xattr.h"
 #include "../lib/crypto/crypto.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "auth.h"
 #include "util_tdb.h"
 
index 40ccf06dd951e39943872e8a775b8579017b5baa..18d0be573e23bc75583ffaacc4b102a2d748a2f5 100644 (file)
@@ -24,6 +24,7 @@
 #include "librpc/gen_ndr/ndr_xattr.h"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "util_tdb.h"
 
 #undef DBGC_CLASS
index c4a39e408facf878b3e69de7d2eaa37abb6199c3..1179f5a335aabd5d379affebfbb516c78181b421 100644 (file)
@@ -23,6 +23,7 @@
 #include "system/filesys.h"
 #include "passdb.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "lib/privileges.h"
 
index 28461d0ac3d3d16ddcc5c7acd7a251dd1720c7be..1c40e24b28246a97e701142ef2a6028866597514 100644 (file)
@@ -26,6 +26,7 @@
 #include "system/filesys.h"
 #include "passdb.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "util_tdb.h"
 
index c9101ca0506fe37366d9f7eeb0894faed731323d..7ad79c14ece55f2a6c1c8f1bf0e3196d6875e272 100644 (file)
@@ -29,6 +29,7 @@
 #include "librpc/gen_ndr/ndr_secrets.h"
 #include "secrets.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "util_tdb.h"
 
index d28278d069b4d535950d42fc58274807a0edc886..0aaa730c8e52529ddd5caf11824e97899dc4e150 100644 (file)
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "util_tdb.h"
 #include "printer_list.h"
 
index e04374b917a99393412bbcd8f7c24f23546275f9..0d56cc61697c80bd8a59484614ed44e5fda5f5a8 100644 (file)
@@ -31,6 +31,7 @@
 #include "nt_printing.h"
 #include "util_tdb.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/secdesc.h"
 
 #undef DBGC_CLASS
index a0193a446790fd6efac1aa3bedd2887ade597a7b..b55dfe976fbfd4b04843f15c013a88c6e1741825 100644 (file)
@@ -27,6 +27,7 @@
 #include "system/filesys.h"
 #include "librpc/gen_ndr/ndr_notify.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "smbd/smbd.h"
 #include "messages.h"
 #include "lib/util/tdb_wrap.h"
index 2c309289fa9e34d570dd29de853453195e5ffdb8..cf0a5786b9dc60647bced2d8a24224cc847c4c90 100644 (file)
@@ -29,6 +29,7 @@
 #include "memcache.h"
 #include "nsswitch/winbind_client.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "talloc_dict.h"
 #include "async_smb.h"
 #include "libsmb/libsmb.h"
index 9061efd395879f27b0d237799989af8abb15fbe9..2210ab55971550579e931744ba1796bfcc58d835 100644 (file)
@@ -22,6 +22,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "messages.h"
 
 typedef enum { OP_FETCH, OP_STORE, OP_DELETE, OP_ERASE, OP_LISTKEYS } dbwrap_op;
index 21d5e8c8b63a760dbe7f48fd4b6e33d694e02235..5ce98f9c8c2df72d470c803b48636de9f9875079 100644 (file)
@@ -23,6 +23,7 @@
 #include "system/filesys.h"
 #include "popt_common.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "messages.h"
 
 #if 0
index 383035e906c1213afa7c58191463161d08da75f4..b1388d265dd851e01283eb082837b89440f603c0 100644 (file)
@@ -23,6 +23,7 @@
 #include "secrets.h"
 #include "idmap.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "net_idmap_check.h"
 #include "util_tdb.h"
index 3adc060a7c6620a66d5eacb4d83634171a6be9b8..76cd97916421f287fefc4e0917036463f7e8f841 100644 (file)
@@ -27,6 +27,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "net.h"
 #include "../libcli/security/dom_sid.h"
 #include "cbuf.h"
index 001c5fd011c1e4da886c6483a368e0c19bbcf44d..4bd18b6d0fc86ee0952919ea51839cf488f5506c 100644 (file)
@@ -34,6 +34,7 @@
 #include "system/filesys.h"
 #include "popt_common.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "session.h"
 #include "locking/proto.h"
index cddbff2d478b039af2c5056e30590a3a396d8693..c1a15803eb0faf049aae519885c6fb56c4eae754 100644 (file)
@@ -26,6 +26,7 @@
 #include "system/filesys.h"
 #include "winbindd.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "idmap.h"
 #include "../libcli/security/dom_sid.h"
 #include "util_tdb.h"
index d99d2f0e4e9328394292262a76552c706d386f97..6c326b4fdeab6250956cac2208be6354f495190b 100644 (file)
@@ -29,6 +29,7 @@
 #include "idmap.h"
 #include "idmap_rw.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
 #include "util_tdb.h"
 
index 112978bdc3e176d3731761a40684cecdb0570216..d7cbb8aef65fe05fd7f5bcefa1c51e5c0a52a5b6 100644 (file)
@@ -37,6 +37,7 @@
 #include "idmap.h"
 #include "idmap_rw.h"
 #include "dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/dom_sid.h"
 #include "util_tdb.h"
 
index 3fcd605f1930b4c9f175d8ba05a0c2156f744032..cdf64bebf9824ef85aff5588bf5f019c33823c29 100755 (executable)
@@ -14,7 +14,9 @@ bld.env.public_headers_skip = ['lib/ldb_compat.h']
 bld.env.public_headers_allow_broken = True
 
 TDB_LIB_SRC = '''
-          lib/dbwrap.c lib/dbwrap_tdb.c
+          lib/dbwrap.c
+         lib/dbwrap/dbwrap_open.c
+         lib/dbwrap_tdb.c
           lib/dbwrap_ctdb.c
           lib/g_lock.c'''