[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Apr 12 18:02:02 MDT 2013


The branch, master has been updated
       via  41333f9 ntdb: remove --disable-ntdb.
       via  ed6a4e0 source4/cluster and source4/ntvfs: convert to dbwrap, add ntdb option.
       via  c5bd2ae Samba3-HOWTO: mention NTDB.
       via  b4b56ee schannel_store.tdb: make it schannel_store.ntdb if 'use ntdb'.
       via  00c9e83 libcli/auth: convert to dbwrap.
       via  b45e3f5 secrets: use lpcfg_private_db_path() convenience helper.
       via  ccfd929 lib/param: lpcfg_private_db_path()
       via  1cf46d2 source4/scripting/python/samba/samba3: handle ntdb files.
       via  5b15d10 autoconf: build in NTDB.
      from  7a4dd84 Remove dependency on detection of HAVE_DIRFD for use of fdopendir().

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


- Log -----------------------------------------------------------------
commit 41333f92d0c78e44a524f2248f5ae641ad59abf3
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:16 2013 +0930

    ntdb: remove --disable-ntdb.
    
    Remove DISABLE_NTDB option, and --disable-ntdb from waf build.  This just
    means that it will always get built: it isn't used by default yet.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Sat Apr 13 02:01:02 CEST 2013 on sn-devel-104

commit ed6a4e04e1f8a0ca952e37577bfdc9731d6ef93d
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:15 2013 +0930

    source4/cluster and source4/ntvfs: convert to dbwrap, add ntdb option.
    
    This makes the code use dbwrap_local_open(), so it can handle
    NTDB.
    
    brlock.tdb, notify.tdb and openfiles.tdb can now be brlock.ntdb,
    notify.ntdb and openfiles.ntdb, if 'use ntdb' is set.
    
    Cc: Andrew Bartlett <abartlet at samba.org>
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c5bd2ae338c0b67304ee253e3b5139b50cc1d0e5
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:14 2013 +0930

    Samba3-HOWTO: mention NTDB.
    
    Not sure if we're keeping this up-to-date, but try to document which
    databases can be NTDB now.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b4b56ee6ad990d99d9fd04591702167ca3b911ce
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:13 2013 +0930

    schannel_store.tdb: make it schannel_store.ntdb if 'use ntdb'.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 00c9e83d92ab1cc0635485386d28f445ea561ce3
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:12 2013 +0930

    libcli/auth: convert to dbwrap.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b45e3f557a00ba78f0d10b2253c99d5710de25c8
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:11 2013 +0930

    secrets: use lpcfg_private_db_path() convenience helper.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ccfd929d964ae111cfac33acaf6c3bcc039724c1
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:10 2013 +0930

    lib/param: lpcfg_private_db_path()
    
    This wrapper avoids testing lpcfg_use_ntdb() everywhere.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 1cf46d2e35c3c290a3d7d1c57d622a2abf2643e6
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:09 2013 +0930

    source4/scripting/python/samba/samba3: handle ntdb files.
    
    Upgrading old Samba 3 instances seems like a place where we don't have
    to read ntdb files, but Andrew Bartlett points out that you can run a
    Samba 4.0 and even a 4.1 'classic' domain and desire to migrate that
    to the AD DC.
    
    So make this upgrade code generic: if it finds an ntdb file, read
    that, otherwise read the tdb file.
    
    Cc: Jelmer Vernooij <jelmer at samba.org>
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5b15d107951d353eb4f055a62cf48a8226e8e6a6
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Thu Apr 11 17:12:08 2013 +0930

    autoconf: build in NTDB.
    
    I previously added -DDISABLE_NTDB to FLAGS, but lib/param/util.c
    doesn't seem to be compiled with that flag, so it's really not a good
    solution.
    
    So instead, compile in ntdb for the autoconf build.  This means:
    
    1) Add -DHAVE_CCAN to cflags.
    2) Remove pyntdb from autoconf objects (which is what tdb does)
    3) Remove -DDISABLE_NTDB
    4) Add ntdb utility objects
    5) Link in ntdb everywhere we link in tdb.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 auth/credentials/credentials_secrets.c     |    4 +-
 docs-xml/Samba3-HOWTO/TOSHARG-TDBFiles.xml |   59 ++++----
 lib/ccan/libccan.m4                        |    2 +-
 lib/dbwrap/dbwrap_local_open.c             |    8 -
 lib/ntdb/libntdb.m4                        |    2 +-
 lib/param/param.h                          |   15 ++
 lib/param/util.c                           |   25 +++
 libcli/auth/schannel_proto.h               |    4 +-
 libcli/auth/schannel_state_tdb.c           |   72 ++++-----
 libcli/auth/wscript_build                  |    2 +-
 python/samba/samba3/__init__.py            |   98 ++++++------
 python/samba/tests/samba3.py               |    4 +-
 source3/Makefile.in                        |  234 ++++++++++++++++------------
 source4/cluster/cluster.c                  |    4 +-
 source4/cluster/cluster.h                  |    2 +-
 source4/cluster/cluster_private.h          |    4 +-
 source4/cluster/local.c                    |   32 +++--
 source4/cluster/wscript_build              |    2 +-
 source4/ntvfs/common/brlock_tdb.c          |  136 ++++++++---------
 source4/ntvfs/common/notify.c              |   94 ++++++------
 source4/ntvfs/common/opendb_tdb.c          |   59 +++-----
 wscript                                    |   10 +-
 22 files changed, 458 insertions(+), 414 deletions(-)


Changeset truncated at 500 lines:

diff --git a/auth/credentials/credentials_secrets.c b/auth/credentials/credentials_secrets.c
index 730f047..27ee607 100644
--- a/auth/credentials/credentials_secrets.c
+++ b/auth/credentials/credentials_secrets.c
@@ -245,9 +245,7 @@ _PUBLIC_ NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cr
 	if (!tmp_ctx) {
 		return NT_STATUS_NO_MEMORY;
 	}
-	secrets_tdb = lpcfg_private_path(cred, lp_ctx,
-					 lpcfg_use_ntdb(lp_ctx) ?
-					 "secrets.ntdb" : "secrets.tdb");
+	secrets_tdb = lpcfg_private_db_path(cred, lp_ctx, "secrets");
 	if (!secrets_tdb) {
 		TALLOC_FREE(tmp_ctx);
 		return NT_STATUS_NO_MEMORY;
diff --git a/docs-xml/Samba3-HOWTO/TOSHARG-TDBFiles.xml b/docs-xml/Samba3-HOWTO/TOSHARG-TDBFiles.xml
index 9bda64d..19fe681 100644
--- a/docs-xml/Samba3-HOWTO/TOSHARG-TDBFiles.xml
+++ b/docs-xml/Samba3-HOWTO/TOSHARG-TDBFiles.xml
@@ -32,87 +32,92 @@
 	is at system shutdown (backup) and startup (restore from backup).
 	</para>
 
+<para>
+<indexterm><primary>NTDB</primary></indexterm>
+</para>
+	As of Samba 4.1, the NTDB format can be used if 'use ntdb' is set.  In this case, tdb files are automatically converted to ntdb files (with the .ntdb extension).  The old .tdb file is turned into a dangling symlink to 'This is now in an NTDB' to prevent it being accidentally used).  The table indicates what databases are currently available as NTDB files.
+
 <table frame="all" id="TOSH-TDB">
                 <title>Samba's Trivial Database Files</title>
                 <tgroup align="center" cols="2">
                 <thead>
-                <row><entry>File name</entry><entry>Preserve</entry><entry>Description</entry></row>
+                <row><entry>File name</entry><entry>Preserve</entry><entry>NTDB</entry><entry>Description</entry></row>
                 </thead>
 
                 <tbody>
-                        <row><entry>account_policy.tdb</entry><entry>Y</entry>
+                        <row><entry>account_policy.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>NT account policy settings such as pw expiration, etc...</para></entry></row>
-                        <row><entry>brlock.tdb</entry><entry>N</entry>
+                        <row><entry>brlock.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Byte range locks.</para></entry></row>
-                        <row><entry>browse.dat</entry><entry>N</entry>
+                        <row><entry>browse.dat</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Browse lists - gets rebuilt automatically.</para></entry></row>
-                        <row><entry>connections.tdb</entry><entry>N</entry>
+                        <row><entry>connections.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Share connections. Used to enforce max connections, etc.</para></entry></row>
-                        <row><entry>gencache.tdb</entry><entry>N</entry>
+                        <row><entry>gencache.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Generic caching database.</para></entry></row>
-                        <row><entry>group_mapping.tdb</entry><entry>Y</entry>
+                        <row><entry>group_mapping.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Stores group mapping information. Not used when using LDAP backend.</para></entry></row>
-                        <row><entry>  lang_en.tdb</entry><entry>Y</entry>
+                        <row><entry>  lang_en.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Stores language encoding information.</para></entry></row>
-                        <row><entry>locking.tdb</entry><entry>N</entry>
+                        <row><entry>locking.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Stores share mode and oplock information.</para></entry></row>
-                        <row><entry>login_cache.tdb</entry><entry>N</entry>
+                        <row><entry>login_cache.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Keeps a log of bad pw attempts.</para></entry></row>
-                        <row><entry>messages.tdb</entry><entry>N</entry>
+                        <row><entry>messages.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Used to keep track of Samba internal messaging.</para></entry></row>
-                        <row><entry>netsamlogon_cache.tdb</entry><entry>Y</entry>
+                        <row><entry>netsamlogon_cache.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>
 					Cache of user net_info_3 struct from <emphasis>net_samlogon()</emphasis>
 					requests from domain member machines.
 				</para></entry></row>
-                        <row><entry>ntdrivers.tdb</entry><entry>Y</entry>
+                        <row><entry>ntdrivers.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Stores installed printer driver information.</para></entry></row>
-                        <row><entry>ntforms.tdb</entry><entry>Y</entry>
+                        <row><entry>ntforms.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Stores installed printer forms information.</para></entry></row>
-                        <row><entry>ntprinters.tdb</entry><entry>Y</entry>
+                        <row><entry>ntprinters.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Stores installed printers information.</para></entry></row>
-                        <row><entry>printing directory</entry><entry>Y</entry>
+                        <row><entry>printing directory</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Directory containing tdb per print queue of cached lpq output.</para></entry></row>
-                        <row><entry>registry.tdb</entry><entry>Y</entry>
+                        <row><entry>registry.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Windows registry skeleton (connect via regedit.exe).</para></entry></row>
-                        <row><entry>sessionid.tdb</entry><entry>N</entry>
+                        <row><entry>sessionid.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Session information to support <literal>utmp = yes</literal> capabilities.</para></entry></row>
-                        <row><entry>share_info.tdb</entry><entry>Y</entry>
+                        <row><entry>share_info.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Stores share-level ACL configuration settings.
 					Default ACL is <emphasis>Everyone - Full Control</emphasis>.
 				</para></entry></row>
-                        <row><entry>unexpected.tdb</entry><entry>N</entry>
+                        <row><entry>unexpected.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>
 					Unexpected packet queue needed to support windows clients that respond on a 
 					different port that the originating reques.
 				</para></entry></row>
-                        <row><entry>winbindd_cache.tdb</entry><entry>N</entry>
+                        <row><entry>winbindd_cache.tdb</entry><entry>N</entry><entry>N</entry>
 				<entry><para>Winbind's cache of user lists.</para></entry></row>
-                        <row><entry>winbindd_idmap.tdb</entry><entry>Y</entry>
+                        <row><entry>winbindd_idmap.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>Winbind's local IDMAP database.</para></entry></row>
-                        <row><entry>wins.dat</entry><entry>N</entry>
+                        <row><entry>wins.dat</entry><entry>N</entry><entry>N</entry>
 				<entry><para>
 				WINS database iused only when <parameter>wins support = yes</parameter>
 				has been set. This gets rebuilt or updated at every restart.
 				</para></entry></row>
-                        <row><entry>wins.tdb</entry><entry>Y</entry>
+                        <row><entry>wins.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>
 				The working permanent storage for all WINS data. This database is used only
 				when <parameter>wins support = yes</parameter> has been set in the &smb.conf; file.
 				Note: This retains all manually configured WINS entries. Manual setting can be done use the net utility.
 				</para></entry></row>
-                        <row><entry>secrets.tdb</entry><entry>Y</entry>
+                        <row><entry>secrets.tdb</entry><entry>Y</entry><entry>Y</entry>
 				<entry><para>
 				This tdb file stores internal settings such as the machine and the domain SID, secret passwords
 				that are used with LDAP, the machine secret token, etc. This is an essential file that is stored
 				in a secure area. Vendors locate this in various folders. Check <command>smbd -b</command> to
 				find its location on your system.
 				</para></entry></row>
-                        <row><entry>schannel_store.tdb</entry><entry>Y</entry>
+                        <row><entry>schannel_store.tdb</entry><entry>Y</entry><entry>Y</entry>
 				<entry><para>
 				This stores secure channel access token information used with SMB signing.
 				</para></entry></row>
-                        <row><entry>passdb.tdb</entry><entry>Y</entry>
+                        <row><entry>passdb.tdb</entry><entry>Y</entry><entry>N</entry>
 				<entry><para>
 				This stores the Samba SAM account information when using a tdbsam password backend.
 				</para></entry></row>
diff --git a/lib/ccan/libccan.m4 b/lib/ccan/libccan.m4
index cda1353..c573215 100644
--- a/lib/ccan/libccan.m4
+++ b/lib/ccan/libccan.m4
@@ -15,7 +15,7 @@ CCAN_OBJ="$ccandir/hash/hash.o $ccandir/htable/htable.o $ccandir/ilog/ilog.o $cc
 AC_SUBST(CCAN_OBJ)
 
 # Preferred method for including ccan modules is #include <ccan/module/...>.
-CCAN_CFLAGS="-I$ccandir/.."
+CCAN_CFLAGS="-I$ccandir/.. -DHAVE_CCAN"
 AC_SUBST(CCAN_CFLAGS)
 
 # All the configuration checks.  Regrettably, the __attribute__ checks will
diff --git a/lib/dbwrap/dbwrap_local_open.c b/lib/dbwrap/dbwrap_local_open.c
index c2eb7b7..56048af 100644
--- a/lib/dbwrap/dbwrap_local_open.c
+++ b/lib/dbwrap/dbwrap_local_open.c
@@ -23,14 +23,11 @@
 #include "dbwrap/dbwrap_tdb.h"
 #include "dbwrap/dbwrap_ntdb.h"
 #include "tdb.h"
-#ifndef DISABLE_NTDB
 #include "lib/util/util_ntdb.h"
-#endif
 #include "lib/param/param.h"
 #include "system/filesys.h"
 #include "ccan/str/str.h"
 
-#ifndef DISABLE_NTDB
 struct flag_map {
 	int tdb_flag;
 	int ntdb_flag;
@@ -157,7 +154,6 @@ static bool tdb_to_ntdb(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
 		  ntdbname, tdbbase, bakbase));
 	return true;
 }
-#endif /* !DISABLE_NTDB */
 
 struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
 				     struct loadparm_context *lp_ctx,
@@ -196,9 +192,6 @@ struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
 	}
 
 	if (name == ntdbname) {
-#ifdef DISABLE_NTDB
-		DEBUG(1, ("WARNING: no ntdb support to open '%s'\n", name));
-#else
 		int ntdb_flags = tdb_flags_to_ntdb_flags(tdb_flags);
 
 		/* For non-internal databases, we upgrade on demand. */
@@ -212,7 +205,6 @@ struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
 		}
 		db = db_open_ntdb(mem_ctx, lp_ctx, ntdbname, hash_size,
 				  ntdb_flags, open_flags, mode, lock_order);
-#endif
 	} else {
 		if (!streq(ntdbname, tdbname) && file_exist(ntdbname)) {
 			DEBUG(0, ("Refusing to open '%s' when '%s' exists\n",
diff --git a/lib/ntdb/libntdb.m4 b/lib/ntdb/libntdb.m4
index b713aba..847dc64 100644
--- a/lib/ntdb/libntdb.m4
+++ b/lib/ntdb/libntdb.m4
@@ -12,7 +12,7 @@ done
 if test x"$ntdbdir" = "x"; then
    AC_MSG_ERROR([cannot find ntdb source in $ntdbpaths])
 fi
-NTDB_OBJ="check.o free.o hash.o io.o lock.o ntdb.o open.o pyntdb.o summary.o transaction.o traverse.o"
+NTDB_OBJ="check.o free.o hash.o io.o lock.o ntdb.o open.o summary.o transaction.o traverse.o"
 AC_SUBST(NTDB_OBJ)
 AC_SUBST(LIBREPLACEOBJ)
 AC_SUBST(CCAN_OBJ)
diff --git a/lib/param/param.h b/lib/param/param.h
index 18d4b29..7e73dd0 100644
--- a/lib/param/param.h
+++ b/lib/param/param.h
@@ -284,6 +284,21 @@ char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
 			    const char *name);
 
 /**
+ * @brief Returns an absolute path to a NTDB or TDB file in the Samba
+ * private directory.
+ *
+ * @param name File to find, relative to PRIVATEDIR, without .(n)tdb extension.
+ * Only provide fixed-string names which are supposed to change with "use ntdb"
+ * option.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path, for
+ * use with dbwrap_local_open().
+ **/
+char *lpcfg_private_db_path(TALLOC_CTX *mem_ctx,
+			    struct loadparm_context *lp_ctx,
+			    const char *name);
+
+/**
   return a path in the smbd.tmp directory, where all temporary file
   for smbd go. If NULL is passed for name then return the directory 
   path itself
diff --git a/lib/param/util.c b/lib/param/util.c
index f488540..8c3badf 100644
--- a/lib/param/util.c
+++ b/lib/param/util.c
@@ -190,6 +190,31 @@ char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
 }
 
 /**
+ * @brief Returns an absolute path to a NTDB or TDB file in the Samba
+ * private directory.
+ *
+ * @param name File to find, relative to PRIVATEDIR, without .(n)tdb extension.
+ * Only provide fixed-string names which are supposed to change with "use ntdb"
+ * option.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path, for
+ * use with dbwrap_local_open().
+ **/
+char *lpcfg_private_db_path(TALLOC_CTX *mem_ctx,
+			    struct loadparm_context *lp_ctx,
+			    const char *name)
+{
+	const char *extension = ".tdb";
+
+	if (lpcfg_use_ntdb(lp_ctx)) {
+		extension = ".ntdb";
+	}
+
+	return talloc_asprintf(mem_ctx, "%s/%s%s",
+			       lpcfg_private_dir(lp_ctx), name, extension);
+}
+
+/**
   return a path in the smbd.tmp directory, where all temporary file
   for smbd go. If NULL is passed for name then return the directory 
   path itself
diff --git a/libcli/auth/schannel_proto.h b/libcli/auth/schannel_proto.h
index 7ee4c1c..0414218 100644
--- a/libcli/auth/schannel_proto.h
+++ b/libcli/auth/schannel_proto.h
@@ -25,8 +25,8 @@
 
 struct schannel_state;
 
-struct tdb_wrap *open_schannel_session_store(TALLOC_CTX *mem_ctx,
-					     struct loadparm_context *lp_ctx);
+struct db_context *open_schannel_session_store(TALLOC_CTX *mem_ctx,
+					       struct loadparm_context *lp_ctx);
 
 NTSTATUS netsec_incoming_packet(struct schannel_state *state,
 				bool do_unseal,
diff --git a/libcli/auth/schannel_state_tdb.c b/libcli/auth/schannel_state_tdb.c
index eecd00e..8f9c1f0 100644
--- a/libcli/auth/schannel_state_tdb.c
+++ b/libcli/auth/schannel_state_tdb.c
@@ -28,7 +28,7 @@
 #include "../lib/param/param.h"
 #include "../libcli/auth/schannel.h"
 #include "../librpc/gen_ndr/ndr_schannel.h"
-#include "lib/tdb_wrap/tdb_wrap.h"
+#include "lib/dbwrap/dbwrap.h"
 
 #define SECRETS_SCHANNEL_STATE "SECRETS/SCHANNEL"
 
@@ -37,19 +37,21 @@
  be called from parent processes to corectly handle TDB_CLEAR_IF_FIRST
 *******************************************************************************/
 
-struct tdb_wrap *open_schannel_session_store(TALLOC_CTX *mem_ctx,
-					     struct loadparm_context *lp_ctx)
+struct db_context *open_schannel_session_store(TALLOC_CTX *mem_ctx,
+					       struct loadparm_context *lp_ctx)
 {
-	struct tdb_wrap *tdb_sc = NULL;
-	char *fname = lpcfg_private_path(mem_ctx, lp_ctx, "schannel_store.tdb");
+	struct db_context *db_sc = NULL;
+	char *fname = lpcfg_private_db_path(mem_ctx, lp_ctx, "schannel_store");
 
 	if (!fname) {
 		return NULL;
 	}
 
-	tdb_sc = tdb_wrap_open(mem_ctx, fname, 0, TDB_CLEAR_IF_FIRST|TDB_NOSYNC, O_RDWR|O_CREAT, 0600, lp_ctx);
+	db_sc = dbwrap_local_open(mem_ctx, lp_ctx, fname, 0,
+				  TDB_CLEAR_IF_FIRST|TDB_NOSYNC, O_RDWR|O_CREAT,
+				  0600, 0);
 
-	if (!tdb_sc) {
+	if (!db_sc) {
 		DEBUG(0,("open_schannel_session_store: Failed to open %s - %s\n",
 			 fname, strerror(errno)));
 		TALLOC_FREE(fname);
@@ -58,23 +60,23 @@ struct tdb_wrap *open_schannel_session_store(TALLOC_CTX *mem_ctx,
 
 	TALLOC_FREE(fname);
 
-	return tdb_sc;
+	return db_sc;
 }
 
 /********************************************************************
  ********************************************************************/
 
 static
-NTSTATUS schannel_store_session_key_tdb(struct tdb_wrap *tdb_sc,
+NTSTATUS schannel_store_session_key_tdb(struct db_context *db_sc,
 					TALLOC_CTX *mem_ctx,
 					struct netlogon_creds_CredentialState *creds)
 {
 	enum ndr_err_code ndr_err;
 	DATA_BLOB blob;
 	TDB_DATA value;
-	int ret;
 	char *keystr;
 	char *name_upper;
+	NTSTATUS status;
 
 	name_upper = strupper_talloc(mem_ctx, creds->computer_name);
 	if (!name_upper) {
@@ -98,12 +100,12 @@ NTSTATUS schannel_store_session_key_tdb(struct tdb_wrap *tdb_sc,
 	value.dptr = blob.data;
 	value.dsize = blob.length;
 
-	ret = tdb_store_bystring(tdb_sc->tdb, keystr, value, TDB_REPLACE);
-	if (ret != TDB_SUCCESS) {
+	status = dbwrap_store_bystring(db_sc, keystr, value, TDB_REPLACE);
+	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0,("Unable to add %s to session key db - %s\n",
-			 keystr, tdb_errorstr(tdb_sc->tdb)));
+			 keystr, nt_errstr(status)));
 		talloc_free(keystr);
-		return NT_STATUS_INTERNAL_DB_CORRUPTION;
+		return status;
 	}
 
 	DEBUG(3,("schannel_store_session_key_tdb: stored schannel info with key %s\n",
@@ -122,7 +124,7 @@ NTSTATUS schannel_store_session_key_tdb(struct tdb_wrap *tdb_sc,
  ********************************************************************/
 
 static
-NTSTATUS schannel_fetch_session_key_tdb(struct tdb_wrap *tdb_sc,
+NTSTATUS schannel_fetch_session_key_tdb(struct db_context *db_sc,
 					TALLOC_CTX *mem_ctx,
 					const char *computer_name,
 					struct netlogon_creds_CredentialState **pcreds)
@@ -149,11 +151,10 @@ NTSTATUS schannel_fetch_session_key_tdb(struct tdb_wrap *tdb_sc,
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	value = tdb_fetch_bystring(tdb_sc->tdb, keystr);
-	if (!value.dptr) {
+	status = dbwrap_fetch_bystring(db_sc, keystr, keystr, &value);
+	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(10,("schannel_fetch_session_key_tdb: Failed to find entry with key %s\n",
 			keystr ));
-		status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 		goto done;
 	}
 
@@ -184,7 +185,6 @@ NTSTATUS schannel_fetch_session_key_tdb(struct tdb_wrap *tdb_sc,
  done:
 
 	talloc_free(keystr);
-	SAFE_FREE(value.dptr);
 
 	if (!NT_STATUS_IS_OK(status)) {
 		talloc_free(creds);
@@ -207,7 +207,7 @@ NTSTATUS schannel_get_creds_state(TALLOC_CTX *mem_ctx,
 				  struct netlogon_creds_CredentialState **_creds)
 {
 	TALLOC_CTX *tmpctx;
-	struct tdb_wrap *tdb_sc;
+	struct db_context *db_sc;
 	struct netlogon_creds_CredentialState *creds;
 	NTSTATUS status;
 
@@ -216,12 +216,12 @@ NTSTATUS schannel_get_creds_state(TALLOC_CTX *mem_ctx,
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	tdb_sc = open_schannel_session_store(tmpctx, lp_ctx);
-	if (!tdb_sc) {
+	db_sc = open_schannel_session_store(tmpctx, lp_ctx);
+	if (!db_sc) {
 		return NT_STATUS_ACCESS_DENIED;
 	}
 
-	status = schannel_fetch_session_key_tdb(tdb_sc, tmpctx, 
+	status = schannel_fetch_session_key_tdb(db_sc, tmpctx,
 						computer_name, &creds);
 	if (NT_STATUS_IS_OK(status)) {
 		*_creds = talloc_steal(mem_ctx, creds);
@@ -244,7 +244,7 @@ NTSTATUS schannel_save_creds_state(TALLOC_CTX *mem_ctx,
 				   struct netlogon_creds_CredentialState *creds)
 {
 	TALLOC_CTX *tmpctx;
-	struct tdb_wrap *tdb_sc;
+	struct db_context *db_sc;
 	NTSTATUS status;
 
 	tmpctx = talloc_named(mem_ctx, 0, "schannel_save_creds_state");
@@ -252,12 +252,12 @@ NTSTATUS schannel_save_creds_state(TALLOC_CTX *mem_ctx,
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	tdb_sc = open_schannel_session_store(tmpctx, lp_ctx);
-	if (!tdb_sc) {
+	db_sc = open_schannel_session_store(tmpctx, lp_ctx);
+	if (!db_sc) {
 		return NT_STATUS_ACCESS_DENIED;
 	}
 
-	status = schannel_store_session_key_tdb(tdb_sc, tmpctx, creds);
+	status = schannel_store_session_key_tdb(db_sc, tmpctx, creds);
 
 	talloc_free(tmpctx);
 	return status;
@@ -281,12 +281,13 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx,
 				    struct netlogon_creds_CredentialState **creds_out)
 {
 	TALLOC_CTX *tmpctx;
-	struct tdb_wrap *tdb_sc;
+	struct db_context *db_sc;
 	struct netlogon_creds_CredentialState *creds;
 	NTSTATUS status;
 	int ret;
 	char *name_upper = NULL;
 	char *keystr = NULL;
+	struct db_record *record;
 	TDB_DATA key;
 
 	if (creds_out != NULL) {
@@ -313,14 +314,14 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx,
 
 	key = string_term_tdb_data(keystr);
 
-	tdb_sc = open_schannel_session_store(tmpctx, lp_ctx);
-	if (!tdb_sc) {
+	db_sc = open_schannel_session_store(tmpctx, lp_ctx);
+	if (!db_sc) {
 		status = NT_STATUS_ACCESS_DENIED;
 		goto done;
 	}
 
-	ret = tdb_chainlock(tdb_sc->tdb, key);
-	if (ret != 0) {
+	record = dbwrap_fetch_locked(db_sc, tmpctx, key);
+	if (!record) {
 		status = NT_STATUS_INTERNAL_DB_CORRUPTION;
 		goto done;
 	}
@@ -329,10 +330,9 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx,
 	 * disconnects) we must update the database every time we
 	 * update the structure */
 
-	status = schannel_fetch_session_key_tdb(tdb_sc, tmpctx, 
+	status = schannel_fetch_session_key_tdb(db_sc, tmpctx,
 						computer_name, &creds);
 	if (!NT_STATUS_IS_OK(status)) {
-		tdb_chainunlock(tdb_sc->tdb, key);
 		goto done;
 	}
 
@@ -340,12 +340,10 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list