[SCM] Samba Shared Repository - branch master updated
Andrew Bartlett
abartlet at samba.org
Fri Dec 20 09:02:02 UTC 2019
The branch, master has been updated
via b28d1dca86d librpc: Add test for ndr_string_length()
via f11e207e01c librpc: Fix string length checking in ndr_pull_charset_to_null()
via 0bd479140c1 upgradedns: ensure lmdb lock files linked
via f0cebbe4dd0 test upgradedns: ensure lmdb lock files linked
from 1cf2397226d selftest: don't use NTVFS fileserver in chgdcpass
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit b28d1dca86d33efac9d03b35c5c9804e02ddfb9a
Author: Andreas Schneider <asn at samba.org>
Date: Mon Dec 16 16:45:38 2019 +0100
librpc: Add test for ndr_string_length()
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
Autobuild-Date(master): Fri Dec 20 09:01:30 UTC 2019 on sn-devel-184
commit f11e207e01c52566c47e350ff240fe95392de0c3
Author: Andreas Schneider <asn at samba.org>
Date: Mon Dec 16 15:50:17 2019 +0100
librpc: Fix string length checking in ndr_pull_charset_to_null()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14219
Pair-Programmed-With: Guenther Deschner <gd at samba.org>
Signed-off-by: Guenther Deschner <gd at samba.org>
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 0bd479140c18ab79479ced4f25f366744c3afe18
Author: Gary Lockyer <gary at catalyst.net.nz>
Date: Thu Dec 19 16:31:46 2019 +1300
upgradedns: ensure lmdb lock files linked
Ensure that the '-lock' files for the dns partitions as well as the data
files are linked when running
samba_dnsupgrade --dns-backend=BIND9_DLZ
failure to create these links can cause corruption of the corresponding
data file.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14199
Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit f0cebbe4dd0317e2abfcbe252977383e6f37f3bd
Author: Gary Lockyer <gary at catalyst.net.nz>
Date: Thu Dec 19 16:31:24 2019 +1300
test upgradedns: ensure lmdb lock files linked
Add tests to check that the '-lock' files for the dns partitions as well as
the data files are linked when running
samba_dnsupgrade --dns-backend=BIND9_DLZ
failure to create these links can cause corruption of the corresponding
data file.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14199
Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
-----------------------------------------------------------------------
Summary of changes:
librpc/ndr/ndr_string.c | 49 ++++++++++++++++++-
librpc/tests/test_ndr_string.c | 37 +++++++++++++-
python/samba/provision/sambadns.py | 10 ++++
python/samba/tests/samba_upgradedns_lmdb.py | 75 +++++++++++++++++++++++++++++
source4/selftest/tests.py | 2 +
5 files changed, 170 insertions(+), 3 deletions(-)
create mode 100644 python/samba/tests/samba_upgradedns_lmdb.py
Changeset truncated at 500 lines:
diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c
index eb0af57a6ab..25f211b2ad3 100644
--- a/librpc/ndr/ndr_string.c
+++ b/librpc/ndr/ndr_string.c
@@ -560,6 +560,47 @@ _PUBLIC_ uint32_t ndr_string_length(const void *_var, uint32_t element_size)
return i+1;
}
+/**
+ * @brief Get the string length including the null terminator if available.
+ *
+ * This checks the string length based on the elements. The returned number
+ * includes the terminating null byte(s) if found.
+ *
+ * @param[in] _var The string the calculate the length for.
+ *
+ * @param[in] length The length of the buffer passed by _var.
+ *
+ * @param[in] element_size The element_size of a string char in bytes.
+ *
+ * @return The length of the strings or 0.
+ */
+static uint32_t ndr_string_n_length(const void *_var,
+ size_t length,
+ uint32_t element_size)
+{
+ size_t i = 0;
+ uint8_t zero[4] = {0,0,0,0};
+ const char *var = (const char *)_var;
+ int cmp;
+
+ if (element_size > 4) {
+ return 0;
+ }
+
+ for (i = 0; i < length; i++, var += element_size) {
+ cmp = memcmp(var, zero, element_size);
+ if (cmp == 0) {
+ break;
+ }
+ }
+
+ if (i == length) {
+ return length;
+ }
+
+ return i + 1;
+}
+
_PUBLIC_ enum ndr_err_code ndr_check_string_terminator(struct ndr_pull *ndr, uint32_t count, uint32_t element_size)
{
uint32_t i;
@@ -629,8 +670,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset_to_null(struct ndr_pull *ndr, int nd
NDR_PULL_NEED_BYTES(ndr, length*byte_mul);
- str_len = ndr_string_length(ndr->data+ndr->offset, byte_mul);
- str_len = MIN(str_len, length); /* overrun protection */
+ str_len = ndr_string_n_length(ndr->data+ndr->offset, length, byte_mul);
+ if (str_len == 0) {
+ return ndr_pull_error(ndr, NDR_ERR_LENGTH,
+ "Invalid length");
+ }
+
if (!convert_string_talloc(ndr->current_mem_ctx, chset, CH_UNIX,
ndr->data+ndr->offset, str_len*byte_mul,
discard_const_p(void *, var),
diff --git a/librpc/tests/test_ndr_string.c b/librpc/tests/test_ndr_string.c
index 6baa41bec31..b3b297c550c 100644
--- a/librpc/tests/test_ndr_string.c
+++ b/librpc/tests/test_ndr_string.c
@@ -127,12 +127,47 @@ static void test_pull_string_len_2_nul_term(void **state)
}
+static void test_ndr_string_n_length(void **state)
+{
+ char test_str1[5] = "Test";
+ char test_str2[5] = {0};
+ char test_str3[32] = "This is a test too";
+ uint8_t test_str_u16[64] = {
+ 0x5C, 0x00, 0x5C, 0x00, 0x4C, 0x00, 0x6F, 0x00,
+ 0x67, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x2D, 0x00,
+ 0x6D, 0x00, 0x75, 0x00, 0x63, 0x00, 0x5C, 0x00,
+ 0x6B, 0x00, 0x79, 0x00, 0x6F, 0x00, 0x63, 0x00,
+ 0x65, 0x00, 0x72, 0x00, 0x61, 0x00, 0x2D, 0x00,
+ 0x6D, 0x00, 0x75, 0x00, 0x63, 0x00, 0x2D, 0x00,
+ 0x6E, 0x00, 0x00, 0x00 };
+ size_t len;
+
+ len = ndr_string_n_length(test_str1, sizeof(test_str1), 1);
+ assert_int_equal(len, 5);
+
+ len = ndr_string_n_length(test_str1, sizeof(test_str1) - 1, 1);
+ assert_int_equal(len, 4);
+
+ len = ndr_string_n_length(test_str2, sizeof(test_str2), 1);
+ assert_int_equal(len, 1);
+
+ len = ndr_string_n_length(test_str3, sizeof(test_str3), 1);
+ assert_int_equal(len, 19);
+
+ len = ndr_string_n_length(test_str3, 0, 1);
+ assert_int_equal(len, 0);
+
+ len = ndr_string_n_length(test_str_u16, 32, 2);
+ assert_int_equal(len, 26);
+}
+
int main(int argc, const char **argv)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_pull_string_zero_len_nul_term),
cmocka_unit_test(test_pull_string_len_1_nul_term),
- cmocka_unit_test(test_pull_string_len_2_nul_term)
+ cmocka_unit_test(test_pull_string_len_2_nul_term),
+ cmocka_unit_test(test_ndr_string_n_length)
};
cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
diff --git a/python/samba/provision/sambadns.py b/python/samba/provision/sambadns.py
index e7273fc759e..ffdb2559979 100644
--- a/python/samba/provision/sambadns.py
+++ b/python/samba/provision/sambadns.py
@@ -850,9 +850,19 @@ def create_samdb_copy(samdb, logger, paths, names, domainsid, domainguid):
os.path.join(dns_samldb_dir, metadata_file))
os.link(os.path.join(private_dir, domainzone_file),
os.path.join(dns_dir, domainzone_file))
+ if backend_store == "mdb":
+ # If the file is an lmdb data file need to link the
+ # lock file as well
+ os.link(os.path.join(private_dir, domainzone_file + "-lock"),
+ os.path.join(dns_dir, domainzone_file + "-lock"))
if forestzone_file:
os.link(os.path.join(private_dir, forestzone_file),
os.path.join(dns_dir, forestzone_file))
+ if backend_store == "mdb":
+ # If the database file is an lmdb data file need to link the
+ # lock file as well
+ os.link(os.path.join(private_dir, forestzone_file + "-lock"),
+ os.path.join(dns_dir, forestzone_file + "-lock"))
except OSError:
logger.error(
"Failed to setup database for BIND, AD based DNS cannot be used")
diff --git a/python/samba/tests/samba_upgradedns_lmdb.py b/python/samba/tests/samba_upgradedns_lmdb.py
new file mode 100644
index 00000000000..048993152e2
--- /dev/null
+++ b/python/samba/tests/samba_upgradedns_lmdb.py
@@ -0,0 +1,75 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Catalyst IT Ltd. 2019
+#
+# 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/>.
+#
+
+from samba.tests.samba_tool.base import SambaToolCmdTest
+import os
+import shutil
+
+
+class UpgradeDnsLmdbTestCase(SambaToolCmdTest):
+ """
+ Tests for dns upgrade on a lmdb backend
+ """
+
+ def setUp(self):
+ super(UpgradeDnsLmdbTestCase, self).setUp()
+ self.tempsambadir = os.path.join(self.tempdir, "samba")
+ os.mkdir(self.tempsambadir)
+
+ # provision a domain
+ #
+ # returns the tuple (ret, stdout, stderr)
+ def provision(self):
+ command = (
+ "samba-tool "
+ "domain provision "
+ "--realm=foo.example.com "
+ "--domain=FOO "
+ "--targetdir=%s "
+ "--backend-store=mdb "
+ "--use-ntvfs " % self.tempsambadir)
+ return self.run_command(command)
+
+ # upgrade a domains dns to BIND9
+ #
+ # returns the tuple (ret, stdout, stderr)
+ def upgrade_dns(self):
+ command = (
+ "samba_upgradedns "
+ "--dns-backend=BIND9_DLZ "
+ "--configfile %s/etc/smb.conf" % self.tempsambadir)
+ return self.run_command(command)
+
+ def tearDown(self):
+ super(UpgradeDnsLmdbTestCase, self).tearDown()
+ shutil.rmtree(self.tempsambadir)
+
+ def test_lmdb_lock_files_linked_on_upgrade_to_bind9_dlz(self):
+ """
+ Ensure that links are created for the lock files as well as the
+ data files
+ """
+ self.provision()
+ self.upgrade_dns()
+ directory = ("%s/bind-dns/dns/sam.ldb.d" % self.tempsambadir)
+ for filename in os.listdir(directory):
+ if filename.endswith(".ldb") and "DNSZONES" in filename:
+ lock_file = ("%s/%s-lock" % (directory, filename))
+ self.assertTrue(
+ os.path.isfile(lock_file),
+ msg=("Lock file %s/%s-lock for %s, does not exist" %
+ (directory, filename, filename)))
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index 121ef2bd691..9b141f96aaf 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -710,6 +710,8 @@ planpythontestsuite("none", "samba.tests.samba_tool.help")
planpythontestsuite("ad_dc_default:local", "samba.tests.samba_tool.passwordsettings")
planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.dsacl")
+planpythontestsuite("none", "samba.tests.samba_upgradedns_lmdb")
+
# Run these against chgdcpass to share the runtime load
planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.sites")
planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.dnscmd")
--
Samba Shared Repository
More information about the samba-cvs
mailing list