ntdb: switch between secrets.tdb and secrets.ntdb depending on 'use ntdb'
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 20 Feb 2013 04:29:42 +0000 (14:59 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 20 Feb 2013 06:09:19 +0000 (07:09 +0100)
Since we open with dbwrap, it auto-converts old tdbs (which it will
rename to secrets.tdb.bak once it's done).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Rusty Russell <rusty@rustcorp.com.au>
Autobuild-Date(master): Wed Feb 20 07:09:19 CET 2013 on sn-devel-104

19 files changed:
auth/credentials/credentials_secrets.c
docs-xml/manpages/net.8.xml
docs-xml/manpages/smbpasswd.8.xml
docs-xml/manpages/vfs_smb_traffic_analyzer.8.xml
docs-xml/smbdotconf/domain/machinepasswordtimeout.xml
docs-xml/smbdotconf/ldap/ldapadmindn.xml
docs-xml/smbdotconf/security/kerberosmethod.xml
docs-xml/smbdotconf/security/privatedir.xml
examples/misc/adssearch.pl
lib/tdb/man/tdbbackup.8.xml
selftest/target/Samba3.pm
selftest/target/Samba4.pm
source3/include/secrets.h
source3/passdb/py_passdb.c
source3/passdb/secrets.c
source4/dsdb/samdb/ldb_modules/secrets_tdb_sync.c
source4/scripting/python/samba/tests/provision.py
source4/scripting/python/samba/tests/upgradeprovision.py
source4/scripting/python/samba/tests/upgradeprovisionneeddc.py

index a44fe1c8b8759384ce254cf7a747df8f7b1eb218..730f047672e3169b245163a928d1b21c72f04c7c 100644 (file)
@@ -245,7 +245,9 @@ _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, "secrets.tdb");
+       secrets_tdb = lpcfg_private_path(cred, lp_ctx,
+                                        lpcfg_use_ntdb(lp_ctx) ?
+                                        "secrets.ntdb" : "secrets.tdb");
        if (!secrets_tdb) {
                TALLOC_FREE(tmp_ctx);
                return NT_STATUS_NO_MEMORY;
index 3765af9be971cb961bfa1bf154c65ae7c241ae30..01044e104563bc4fe640ae596a7a5d88a56d304f 100644 (file)
@@ -1001,7 +1001,7 @@ local server.  You need to run this against the PDC, from a Samba machine joined
 <refsect2>
 <title>RPC GETSID</title>
 
-<para>Fetch domain SID and store it in the local <filename>secrets.tdb</filename>. </para>
+<para>Fetch domain SID and store it in the local <filename>secrets.tdb</filename> (or <filename>secrets.ntdb</filename>). </para>
 
 </refsect2>
 
index 376044ccafa5604052c6e77a7fd31438ef223375..88e7e8646092d45b636ac9be1fc32966a94c7350 100644 (file)
                has been compiled with LDAP support. The <parameter>-w</parameter> 
                switch is used to specify the password to be used with the 
                <smbconfoption name="ldap admin dn"/>.  Note that the password is stored in
-               the <filename>secrets.tdb</filename> and is keyed off 
+               the <filename>secrets.tdb</filename> (or <filename>secrets.ntdb</filename>) and is keyed off
                of the admin's DN.  This means that if the value of <parameter>ldap
                admin dn</parameter> ever changes, the password will need to be 
                manually updated as well.
                has been compiled with LDAP support. The <parameter>-W</parameter>
                switch is used to specify the password to be used with the
                <smbconfoption name="ldap admin dn"/>.  Note that the password is stored in
-               the <filename>secrets.tdb</filename> and is keyed off
+               the <filename>secrets.tdb</filename> (or <filename>secrets.ntdb</filename>) and is keyed off
                of the admin's DN.  This means that if the value of <parameter>ldap
                admin dn</parameter> ever changes, the password will need to be
                manually updated as well.
index 0d682c2b5be7d5877076f865eeab02bc902e8bd6..842856bf83844aa36d55bfc6bad8f9a66629ea8c 100644 (file)
        <itemizedlist>
                <listitem>
                <para>
-               The data from the module may be send encrypted, with a key stored in secrets.tdb. The
+               The data from the module may be send encrypted, with a key stored in secrets.tdb (or secrets.ntdb). The
                Receiver then has to use the same key. The module does AES block encryption over the
                data to send.
                </para>
index a8e312ba363f02ac7e247b48cb4fc5e65aff326d..4f55e81f0047d675cea65a7901294e035aa75b24 100644 (file)
@@ -9,7 +9,7 @@
        If a Samba server is a member of a Windows NT Domain (see the <smbconfoption
        name="security">domain</smbconfoption> parameter) then periodically a running smbd process will try and change
        the MACHINE ACCOUNT PASSWORD stored in the TDB called <filename moreinfo="none">private/secrets.tdb
-       </filename>.  This parameter specifies how often this password will be changed, in seconds. The default is one
+       </filename> (or <filename moreinfo="none">private/secrets.ntdb</filename>).  This parameter specifies how often this password will be changed, in seconds. The default is one
        week (expressed in seconds), the same as a Windows NT Domain member server.
        </para>
 
index 442d242679ddbfaa02fe1f2b3dc4085d02627eb3..b5fe0fbca07619673cf2ce42f378d90a91f6fda3 100644 (file)
@@ -8,7 +8,7 @@
         <para>
        The <smbconfoption name="ldap admin dn"/> defines the Distinguished  Name (DN) name used by Samba to contact
        the ldap server when retreiving  user account information. The <smbconfoption name="ldap admin dn"/> is used
-       in conjunction with the admin dn password stored in the <filename moreinfo="none">private/secrets.tdb</filename>
+       in conjunction with the admin dn password stored in the <filename moreinfo="none">private/secrets.tdb</filename> (or <filename moreinfo="none">private/secrets.ntdb</filename>)
        file.  See the <citerefentry><refentrytitle>smbpasswd</refentrytitle> <manvolnum>8</manvolnum></citerefentry>
        man page for more information on how  to accomplish this.
        </para>
index 3a11e06be96eae16033dd103a3f4de4e432cad1f..cc8a69bc7081903b208d9db2d5f1e81c5c2d6ea0 100644 (file)
@@ -8,7 +8,7 @@
 
        <para>Valid options are:</para>
        <itemizedlist>
-         <listitem><para>secrets only - use only the secrets.tdb for
+         <listitem><para>secrets only - use only the secrets.(n)tdb for
          ticket verification (default)</para></listitem>
 
          <listitem><para>system keytab - use only the system keytab
@@ -17,7 +17,7 @@
          <listitem><para>dedicated keytab - use a dedicated keytab
          for ticket verification</para></listitem>
 
-         <listitem><para>secrets and keytab - use the secrets.tdb
+         <listitem><para>secrets and keytab - use the secrets.(n)tdb
          first, then the system keytab</para></listitem>
        </itemizedlist>
 
index 46d4a8297cd813b90f717e07f1374c0d339b0069..2f4b5766de2441480b826ca51763ca5890be028f 100644 (file)
@@ -7,7 +7,7 @@
 <description>
     <para>This parameters defines the directory
     smbd will use for storing such files as <filename moreinfo="none">smbpasswd</filename>
-    and <filename moreinfo="none">secrets.tdb</filename>.
+    and <filename moreinfo="none">secrets.tdb</filename> (or <filename moreinfo="none">secrets.ntdb</filename>).
 </para>
 </description>
 
index 13a85bede985f948c5be677a34306288d354f284..02c4464abbad35126c0a93c9fc9713a911fe6c70 100755 (executable)
@@ -42,11 +42,13 @@ my $rebind_url;
 
 
 my $tdbdump    = "/usr/bin/tdbdump";
+my $ntdbdump   = "/usr/bin/ntdbdump";
 my $testparm   = "/usr/bin/testparm";
 my $net                = "/usr/bin/net";
 my $dig                = "/usr/bin/dig";
 my $nmblookup  = "/usr/bin/nmblookup";
 my $secrets_tdb = "/etc/samba/secrets.tdb";
+my $secrets_ntdb = "/etc/samba/secrets.ntdb";
 my $klist      = "/usr/bin/klist";
 my $kinit      = "/usr/bin/kinit";
 my $workgroup  = "";
@@ -723,13 +725,21 @@ sub get_machine_password {
        my $workgroup = shift || "";
        $workgroup = uc($workgroup);
 
-       my ($found, $tmp);
-       -x $tdbdump || die "tdbdump is not installed. cannot proceed autodetection\n";
-       -r $secrets_tdb || die "cannot read $secrets_tdb. cannot proceed autodetection\n";
+       my ($found, $tmp, $dbdump, $db);
+       if (-r $secrets_ntdb) {
+           -x $ntdbdump || die "ntdbdump is not installed. cannot proceed autodetection\n";
+           $dbdump = $ntdbdump;
+           $db = $secrets_ntdb;
+       } else {
+           -x $tdbdump || die "tdbdump is not installed. cannot proceed autodetection\n";
+           -r $secrets_tdb || die "cannot read $secrets_tdb. cannot proceed autodetection\n";
+           $dbdump = $tdbdump;
+           $db = $secrets_tdb;
+       }
 
        # get machine-password
        my $key = sprintf("SECRETS/MACHINE_PASSWORD/%s", $workgroup);
-       open(SECRETS,"$tdbdump $secrets_tdb |");
+       open(SECRETS,"$dbdump $db |");
        while(my $line = <SECRETS>) {
                chomp($line);
                if ($found) {
index 02936cf0d6bf0ff0635ed607215a287332ca02cc..c15cc14e2d17569e122eeb255c93f3586a46dd4f 100644 (file)
 
        <para>tdbbackup -v [-s suffix] *.tdb</para>
 
+       <para>
+       Note that Samba 4 can use .ntdb files instead, so you should
+       use <command>ntdbbackup</command> on those files.
+       </para>
+
        <para>
        Samba .tdb files are stored in various locations, be sure to run backup all
        .tdb file on the system. Important files includes:
index 8546bd28951983010e5dc873bf4e1bbc91268cac..c71419d4ba6d2c82331ace70b7868c9323a242d4 100755 (executable)
@@ -418,6 +418,9 @@ $ret->{USERNAME} = KTEST\\Administrator
        system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
        chmod 0600, "$prefix/private/secrets.tdb";
 
+#Make sure there's no old ntdb file.
+       system("rm -f $prefix/private/secrets.ntdb");
+
 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
 #
index 8ad62326cdad073ac0fec33a79f21edfba6d142c..e9e003704eaafb76e276f8fe685123489af348be 100644 (file)
@@ -1512,7 +1512,7 @@ sub provision_chgdcpass($$)
        
        # Remove secrets.tdb from this environment to test that we still start up
        # on systems without the new matching secrets.tdb records
-       unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb")) {
+       unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
                warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
                return undef;
        }
index 57a1be0c3eb944f23528ed3d1b3b2f75f5fe253c..1eeb24c1c9bcda6d146f62c2504c451d84e82c01 100644 (file)
@@ -82,7 +82,7 @@ struct afs_keyfile {
 
 /* The following definitions come from passdb/secrets.c  */
 
-bool secrets_init_path(const char *private_dir);
+bool secrets_init_path(const char *private_dir, bool use_ntdb);
 bool secrets_init(void);
 struct db_context *secrets_db_ctx(void);
 void secrets_shutdown(void);
index 69840617147555d9d98a79973e1266d44816ca38..3fd14cdc41181a6eebf2dbfbf2e734938a59e38f 100644 (file)
@@ -3638,7 +3638,7 @@ static PyObject *py_set_secrets_dir(PyObject *self, PyObject *args)
        }
 
        /* Initialize secrets database */
-       if (!secrets_init_path(private_dir)) {
+       if (!secrets_init_path(private_dir, lp_use_ntdb())) {
                PyErr_Format(py_pdb_error, "Cannot open secrets file database in '%s'",
                                private_dir);
                talloc_free(frame);
index 8f314a76cf574c504d47d1666fb858da7f63ca90..f97510db211d21d7ab8bc3a2dc686350c8311a5e 100644 (file)
@@ -55,7 +55,7 @@ static void get_rand_seed(void *userdata, int *new_seed)
 }
 
 /* open up the secrets database with specified private_dir path */
-bool secrets_init_path(const char *private_dir)
+bool secrets_init_path(const char *private_dir, bool use_ntdb)
 {
        char *fname = NULL;
        unsigned char dummy;
@@ -70,8 +70,8 @@ bool secrets_init_path(const char *private_dir)
        }
 
        frame = talloc_stackframe();
-       fname = talloc_asprintf(frame, "%s/secrets.tdb",
-                               private_dir);
+       fname = talloc_asprintf(frame, "%s/secrets.%s",
+                               private_dir, use_ntdb ? "ntdb" : "tdb");
        if (fname == NULL) {
                TALLOC_FREE(frame);
                return False;
@@ -105,7 +105,7 @@ bool secrets_init_path(const char *private_dir)
 /* open up the secrets database */
 bool secrets_init(void)
 {
-       return secrets_init_path(lp_private_dir());
+       return secrets_init_path(lp_private_dir(), lp_use_ntdb());
 }
 
 struct db_context *secrets_db_ctx(void)
index e90fc77068f0424e4882d1478fb2f2a0b251b22d..e3d8485c611b2962ad9c04bbde944f4466128775 100644 (file)
@@ -474,7 +474,8 @@ static int secrets_tdb_sync_init(struct ldb_module *module)
        struct ldb_context *ldb;
        struct secrets_tdb_sync_private *data;
        char *private_dir, *p;
-       const char *secrets_ldb;
+       const char *secrets_ldb, *secrets_ntdb;
+       bool use_ntdb;
 
        ldb = ldb_module_get_ctx(module);
 
@@ -498,11 +499,17 @@ static int secrets_tdb_sync_init(struct ldb_module *module)
        p = strrchr(private_dir, '/');
        if (p) {
                *p = '\0';
-               secrets_init_path(private_dir);
        } else {
-               secrets_init_path(".");
+               private_dir = talloc_strdup(data, ".");
        }
 
+       /* If there's an ntdb file, force code to load that. */
+       secrets_ntdb = talloc_asprintf(private_dir, "%s/secrets.ntdb",
+                                      private_dir);
+       use_ntdb = file_exist(secrets_ntdb);
+
+       secrets_init_path(private_dir, use_ntdb);
+
        TALLOC_FREE(private_dir);
 
        data->secrets_tdb = secrets_db_ctx();
index 992179124b2838e52754369c2c2f2e17d7f692eb..929e7074f75a59d3f001bbddd1eeb741c308cd03 100644 (file)
@@ -55,8 +55,9 @@ class ProvisionTestCase(samba.tests.TestCaseInTempDir):
 
     def test_setup_secretsdb(self):
         path = os.path.join(self.tempdir, "secrets.ldb")
-        secrets_tdb_path = os.path.join(self.tempdir, "secrets.tdb")
         paths = ProvisionPaths()
+        secrets_tdb_path = os.path.join(self.tempdir, "secrets.tdb")
+        secrets_ntdb_path = os.path.join(self.tempdir, "secrets.ntdb")
         paths.secrets = path
         paths.private_dir = os.path.dirname(path)
         paths.keytab = "no.keytab"
@@ -68,8 +69,10 @@ class ProvisionTestCase(samba.tests.TestCaseInTempDir):
         finally:
             del ldb
             os.unlink(path)
-            os.unlink(secrets_tdb_path)
-
+            if os.path.exists(secrets_tdb_path):
+                os.unlink(secrets_tdb_path)
+            if os.path.exists(secrets_ntdb_path):
+                os.unlink(secrets_ntdb_path)
 
 class FindNssTests(TestCase):
     """Test findnss() function."""
index c1c70c4a888add72be6ce5095c33c3a9156c42a3..93a6731c8307cf60038d880481faf94bcbd8e476 100644 (file)
@@ -126,7 +126,7 @@ class UpdateSecretsTests(samba.tests.TestCaseInTempDir):
         self.assertEquals(newmodules.msgs, refmodules.msgs)
 
     def tearDown(self):
-        for name in ["ref.ldb", "secrets.ldb", "secrets.tdb"]:
+        for name in ["ref.ldb", "secrets.ldb", "secrets.tdb", "secrets.tdb.bak", "secrets.ntdb"]:
             path = os.path.join(self.tempdir, name)
             if os.path.exists(path):
                 os.unlink(path)
index 1de123c71d1bb356688d577eba4542e7b9096bd5..a7cb298ed7fbff5fa6bf2e9ce73a53fb13bb28a6 100644 (file)
@@ -172,7 +172,7 @@ class UpgradeProvisionWithLdbTestCase(TestCaseInTempDir):
         self.assertTrue(re.match(".*upgrade to.*", str(oem2)))
 
     def tearDown(self):
-        for name in ["ref.ldb", "secrets.ldb", "secrets.tdb", "sam.ldb"]:
+        for name in ["ref.ldb", "secrets.ldb", "secrets.tdb", "secrets.tdb.bak", "secrets.ntdb", "sam.ldb"]:
             path = os.path.join(self.tempdir, name)
             if os.path.exists(path):
                 os.unlink(path)