[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Tue May 10 03:12:03 UTC 2016


The branch, master has been updated
       via  91f6439 tests/dcerpc: add tests for string allocation and deletion
       via  eab6796 selftest: Enable samba.tests.dcerpc.array test
       via  4c7a3fd tests/dcerpc/array.py: test deletion of arrays
       via  ed11ce8 Python pidl: avoid segfault with "del obj->attr"
       via  2ba83ae pytalloc: avoid double 0x0x in repr strings
       via  f6c7907 pidl: Correct string handling to use talloc and be in common
       via  9e2c1f7 join.py: Fetch the remote DC NTDS GUID early
       via  bcace46 selftest: Include a few more details in selftest and samba startup.
       via  9084dae repl_meta_data: Explain why time(NULL) is good enough here
       via  2f44f37 ldb: Fix error string when renaming to an DN that already exists
       via  891abcf source4/registry/local: avoid str_list_length() to check first element
       via  8a3c905 dsdb schema_query: reduce calls to str_list_length
       via  dfa9a5c dsdb/common/util: be careful about zero length string lists
       via  cc6ed8f dsdb/common/util: remove some unnecessary str_list_length()s
       via  6bb577f source4/param/pyparam.c: fix strange indentation
       via  4456f38 python/join.py: Avoid unchecked print in error path
       via  e822b31 dsdb: Improve debug messages in operational module
       via  d6cebed dsdb: Clarify rename handling as to which record is being renamed
       via  90cbf4f selftest: Wait 60 seconds for a RID alloc
       via  2855a30 selftest: Print a message when RID allocation fails
      from  58a8323 libcli/auth: let msrpc_parse() return talloc'ed empty strings

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


- Log -----------------------------------------------------------------
commit 91f6439929fc88cc1cdfc9572db300ce9f4df263
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed May 4 11:24:12 2016 +1200

    tests/dcerpc: add tests for string allocation and deletion
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Tue May 10 05:11:42 CEST 2016 on sn-devel-144

commit eab6796f5b9d2c3c44c182a832afa86de84466f4
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed May 4 11:21:47 2016 +1200

    selftest: Enable samba.tests.dcerpc.array test
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 4c7a3fd56796913794d2529d4ae8d10a95bbe93b
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed May 4 17:43:33 2016 +1200

    tests/dcerpc/array.py: test deletion of arrays
    
    We expect an AttributeError.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit ed11ce8f12d567a3e0edc1d24aab1784a171ac33
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed May 4 16:51:37 2016 +1200

    Python pidl: avoid segfault with "del obj->attr"
    
    Deleting an attribute in Python (using the "del" statement) is (at
    some stages along a winding path, for C objects) converted into
    setting the attribute to NULL. Not None, actual NULL. The way we
    handled this NULL was to dereference it. This changes the behaviour to
    raising an AttributeError, which is more or less what Python does in
    similar situations with builtin objects.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 2ba83ae49b34812ed165357e2bdcd1c4b627cad4
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed May 4 10:16:41 2016 +1200

    pytalloc: avoid double 0x0x in repr strings
    
    The %p format puts one in itself.
    
    Before: <drsblobs.repsFromTo2 talloc based object at 0x0x1b551e0>
    After:  <drsblobs.repsFromTo2 talloc based object at 0x1b551e0>
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit f6c79072ca50e05a68b73a80a0ebd635a9bac068
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Apr 21 21:44:56 2016 +1200

    pidl: Correct string handling to use talloc and be in common
    
    The previous string handling assumed the python variables referenced
    by PyString_AS_STRING had infinite life.  When they were re-used
    the C structure started to point at unexpected things.
    
    We now check correctly for Unicode in every case, and we always
    duplicate the string with talloc_strdup()
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 9e2c1f72e00cf63da777a515b95ed63139ef2d11
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sun Mar 27 17:29:35 2016 +1300

    join.py: Fetch the remote DC NTDS GUID early
    
    This avoids touching the LDAP connection after the long replicate cycle, as it may
    have timed out
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit bcace463b97b0a6737dded4a6d45996923ff0057
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu May 5 11:35:46 2016 +1200

    selftest: Include a few more details in selftest and samba startup.
    
    This helps us understand failure modes in selftest
    
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 9084dae5aaa343770614d6923e0c572bd0e26b8e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Feb 26 15:57:48 2016 +1300

    repl_meta_data: Explain why time(NULL) is good enough here
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 2f44f370d8eef19fd1e6fdd21b5ffac63fd4c49b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Mar 15 14:07:22 2016 +1300

    ldb: Fix error string when renaming to an DN that already exists
    
    We were printing the DN renamed from, not the DN being renamed to.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 891abcf78f50a6badc1cd6f9a6d408e4727ba61a
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri May 6 15:30:57 2016 +1200

    source4/registry/local: avoid str_list_length() to check first element
    
    We don't need to walk to the end of the list to find out if the first
    one is NULL.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 8a3c9056bd0a51dbaffe5ebb3299a2b490cbc650
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri May 6 15:30:15 2016 +1200

    dsdb schema_query: reduce calls to str_list_length
    
    We were calling str_list_length(new_attrs) three times when one is
    enough.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit dfa9a5c9286ba00f54dbffe7c3934618ed54aee9
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri May 6 15:25:54 2016 +1200

    dsdb/common/util: be careful about zero length string lists
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit cc6ed8f126d3832f2d569adcfa51716d3f96ecfa
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri May 6 15:22:35 2016 +1200

    dsdb/common/util: remove some unnecessary str_list_length()s
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 6bb577f254c49002dbe3cadf2491845a39172471
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Tue May 3 14:39:08 2016 +1200

    source4/param/pyparam.c: fix strange indentation
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 4456f38612c24effac88386e514791ceb734f878
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu May 5 09:39:58 2016 +1200

    python/join.py: Avoid unchecked print in error path
    
    In autobuild this print causes an IOError when stdout is dead,
    which hides the exception you care about and prevents the actual
    clean up.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit e822b312389a1a41e1a384f298cb667ffed41edd
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Mar 21 11:29:04 2016 +1300

    dsdb: Improve debug messages in operational module
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit d6cebedc017061e720b00f5da7f513b4d4c1ee33
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Mar 15 15:13:36 2016 +1300

    dsdb: Clarify rename handling as to which record is being renamed
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 90cbf4fb20c6de208e4392d3d663f2e232036160
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu May 5 22:21:11 2016 +1200

    selftest: Wait 60 seconds for a RID alloc
    
    This ensures we give it a reasonable enough chance to start up.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 2855a30ecce6fc2c0ccede0b6f053012c68687ef
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu May 5 19:34:41 2016 +1200

    selftest: Print a message when RID allocation fails
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

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

Summary of changes:
 lib/ldb/ldb_tdb/ldb_tdb.c                       |   2 +-
 lib/talloc/pytalloc.c                           |   2 +-
 pidl/lib/Parse/Pidl/Samba4/Python.pm            | 111 ++++++++++++--------
 python/samba/join.py                            |  10 +-
 python/samba/tests/dcerpc/array.py              |  38 ++++++-
 python/samba/tests/dcerpc/string.py             | 133 ++++++++++++++++++++++++
 selftest/target/Samba4.pm                       |  11 +-
 selftest/tests.py                               |   2 +
 source4/dsdb/common/util.c                      |   7 +-
 source4/dsdb/samdb/ldb_modules/operational.c    |   5 +-
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c |   8 +-
 source4/dsdb/schema/schema_query.c              |  13 +--
 source4/lib/registry/local.c                    |   2 +-
 source4/param/pyparam.c                         |   8 +-
 source4/smbd/server.c                           |  14 +--
 15 files changed, 292 insertions(+), 74 deletions(-)
 create mode 100644 python/samba/tests/dcerpc/string.py


Changeset truncated at 500 lines:

diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c
index 8d1fd36..6a91f05 100644
--- a/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -1054,7 +1054,7 @@ static int ltdb_rename(struct ltdb_context *ctx)
 			talloc_free(tdb_key.dptr);
 			ldb_asprintf_errstring(ldb_module_get_ctx(module),
 					       "Entry %s already exists",
-					       ldb_dn_get_linearized(msg->dn));
+					       ldb_dn_get_linearized(req->op.rename.newdn));
 			/* finding the new record already in the DB is an error */
 			talloc_free(msg);
 			return LDB_ERR_ENTRY_ALREADY_EXISTS;
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
index 74349da..2039528 100644
--- a/lib/talloc/pytalloc.c
+++ b/lib/talloc/pytalloc.c
@@ -166,7 +166,7 @@ static PyObject *pytalloc_base_default_repr(PyObject *obj)
 	pytalloc_BaseObject *talloc_obj = (pytalloc_BaseObject *)obj;
 	PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
 
-	return PyStr_FromFormat("<%s talloc based object at 0x%p>",
+	return PyStr_FromFormat("<%s talloc based object at %p>",
 				type->tp_name, talloc_obj->ptr);
 }
 
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 6488ac9..f43e4d6 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -960,6 +960,55 @@ sub assign($$$)
 	}
 }
 
+sub ConvertStringFromPythonData($$$$$)
+{
+	my ($self, $mem_ctx, $py_var, $target, $fail) = @_;
+
+	$self->pidl("{");
+	$self->indent;
+	$self->pidl("const char *test_str;");
+	$self->pidl("const char *talloc_str;");
+	$self->pidl("PyObject *unicode = NULL;");
+	$self->pidl("if (PyUnicode_Check($py_var)) {");
+	$self->indent;
+	# FIXME: Use Unix charset setting rather than utf-8
+	$self->pidl("unicode = PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\");");
+	$self->pidl("if (unicode == NULL) {");
+	$self->indent;
+	$self->pidl("PyErr_NoMemory();");
+	$self->pidl("$fail");
+	$self->deindent;
+	$self->pidl("}");
+
+	$self->pidl("test_str = PyString_AS_STRING(unicode);");
+	$self->deindent;
+	$self->pidl("} else if (PyString_Check($py_var)) {");
+	$self->indent;
+	$self->pidl("test_str = PyString_AS_STRING($py_var);");
+	$self->deindent;
+	$self->pidl("} else {");
+	$self->indent;
+	$self->pidl("PyErr_Format(PyExc_TypeError, \"Expected string or unicode object, got %s\", Py_TYPE($py_var)->tp_name);");
+	$self->pidl("$fail");
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("talloc_str = talloc_strdup($mem_ctx, test_str);");
+	$self->pidl("if (unicode != NULL) {");
+	$self->indent;
+	$self->pidl("Py_DECREF(unicode);");
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("if (talloc_str == NULL) {");
+	$self->indent;
+	$self->pidl("PyErr_NoMemory();");
+	$self->pidl("$fail");
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("$target = talloc_str;");
+	$self->deindent;
+	$self->pidl("}");
+}
+
 sub ConvertObjectFromPythonData($$$$$$;$)
 {
 	my ($self, $mem_ctx, $cvar, $ctype, $target, $fail, $location) = @_;
@@ -1114,33 +1163,17 @@ sub ConvertObjectFromPythonData($$$$$$;$)
 	}
 
 	if ($actual_ctype->{TYPE} eq "SCALAR" and
-		($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) {
-		$self->pidl("$target = talloc_strdup($mem_ctx, PyString_AS_STRING($cvar));");
-		return;
-	}
-
-	if ($actual_ctype->{TYPE} eq "SCALAR" and ($actual_ctype->{NAME} eq "dns_string" or $actual_ctype->{NAME} eq "dns_name")) {
-		$self->pidl("$target = talloc_strdup($mem_ctx, PyString_AS_STRING($cvar));");
-		return;
-	}
-
-	if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") {
-		$self->pidl("$target = PyString_AS_STRING($cvar);");
-		return;
-	}
-
-	if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv6address") {
-		$self->pidl("$target = PyString_AsString($cvar);");
-		return;
-	}
-
-	if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "dnsp_name") {
-		$self->pidl("$target = PyString_AS_STRING($cvar);");
-		return;
-	}
-
-	if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "dnsp_string") {
-		$self->pidl("$target = PyString_AS_STRING($cvar);");
+		($actual_ctype->{NAME} eq "string"
+		 or $actual_ctype->{NAME} eq "nbt_string"
+		 or $actual_ctype->{NAME} eq "nbt_name"
+		 or $actual_ctype->{NAME} eq "wrepl_nbt_name"
+		 or $actual_ctype->{NAME} eq "dns_string"
+		 or $actual_ctype->{NAME} eq "dnsp_string"
+		 or $actual_ctype->{NAME} eq "dns_name"
+		 or $actual_ctype->{NAME} eq "ipv4address"
+		 or $actual_ctype->{NAME} eq "ipv6address"
+		 or $actual_ctype->{NAME} eq "dnsp_name")) {
+	        $self->ConvertStringFromPythonData($mem_ctx, $cvar, $target, $fail);
 		return;
 	}
 
@@ -1185,6 +1218,14 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
 		$pl = GetPrevLevel($e, $pl);
 	}
 
+        $self->pidl("if ($py_var == NULL) {");
+        $self->indent;
+        $self->pidl("PyErr_Format(PyExc_AttributeError, \"Cannot delete NDR object: " .
+                    mapTypeName($var_name) . "\");");
+        $self->pidl($fail);
+        $self->deindent;
+        $self->pidl("}");
+
 	if ($l->{TYPE} eq "POINTER") {
 		if ($l->{POINTER_TYPE} ne "ref") {
 			$self->pidl("if ($py_var == Py_None) {");
@@ -1218,21 +1259,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
 		}
 
 		if (is_charset_array($e, $l)) {
-			$self->pidl("if (PyUnicode_Check($py_var)) {");
-			$self->indent;
-			# FIXME: Use Unix charset setting rather than utf-8
-			$self->pidl($var_name . " = PyString_AS_STRING(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));");
-			$self->deindent;
-			$self->pidl("} else if (PyString_Check($py_var)) {");
-			$self->indent;
-			$self->pidl($var_name . " = PyString_AS_STRING($py_var);");
-			$self->deindent;
-			$self->pidl("} else {");
-			$self->indent;
-			$self->pidl("PyErr_Format(PyExc_TypeError, \"Expected string or unicode object, got %s\", Py_TYPE($py_var)->tp_name);");
-			$self->pidl("$fail");
-			$self->deindent;
-			$self->pidl("}");
+		        $self->ConvertStringFromPythonData($mem_ctx, $py_var, $var_name, $fail);
 		} else {
 			my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}";
 			$self->pidl("PY_CHECK_TYPE(&PyList_Type, $py_var, $fail);");
diff --git a/python/samba/join.py b/python/samba/join.py
index 6df337c..ebfd63e 100644
--- a/python/samba/join.py
+++ b/python/samba/join.py
@@ -117,6 +117,9 @@ class dc_join(object):
             ctx.acct_dn = None
             ctx.myname = ctx.server.split('.')[0]
             ctx.ntds_guid = None
+
+            # Save this early
+            ctx.remote_dc_ntds_guid = ctx.samdb.get_ntds_GUID()
         else:
             # work out the DNs of all the objects we will be adding
             ctx.myname = netbios_name
@@ -929,7 +932,7 @@ class dc_join(object):
 
         # We want to appear to be the server we just cloned
         if ctx.clone_only:
-            guid = ctx.samdb.get_ntds_GUID()
+            guid = ctx.remote_dc_ntds_guid
         else:
             guid = ctx.ntds_guid
 
@@ -1100,7 +1103,10 @@ class dc_join(object):
                 ctx.join_setup_trusts()
             ctx.join_finalise()
         except:
-            print "Join failed - cleaning up"
+            try:
+                print "Join failed - cleaning up"
+            except IOError:
+                pass
             if not ctx.clone_only:
                 ctx.cleanup_old_join()
             raise
diff --git a/python/samba/tests/dcerpc/array.py b/python/samba/tests/dcerpc/array.py
index 80c53c6..da3b7a5 100644
--- a/python/samba/tests/dcerpc/array.py
+++ b/python/samba/tests/dcerpc/array.py
@@ -32,8 +32,10 @@ class ArrayTests(samba.tests.TestCase):
 
     def tearDown(self):
         super(ArrayTests, self).tearDown()
-        self.assertEqual(talloc.total_blocks(), self.startup_blocks)
-        talloc.report_full()
+        gc.collect()
+        if talloc.total_blocks() != self.startup_blocks:
+            talloc.report_full()
+            self.fail("it appears we are leaking memory")
 
     def test_array_from_python(self):
         rmd = drsblobs.replPropertyMetaDataBlob()
@@ -169,3 +171,35 @@ class ArrayTests(samba.tests.TestCase):
 
         self.assertEqual(rmd.ctr.array[0].attid,
                          rmd_unpacked.ctr.array[0].attid)
+
+    def test_array_delete(self):
+        rmd = drsblobs.replPropertyMetaDataBlob()
+
+        rmd.version = 1
+        rmd.ctr = drsblobs.replPropertyMetaDataCtr1()
+        rmd.ctr.count = 3
+
+        rmd1 = drsblobs.replPropertyMetaData1()
+        rmd1.attid = 1
+        rmd1.version = 2
+
+        rmd2 = drsblobs.replPropertyMetaData1()
+        rmd2.attid = 2
+        rmd2.version = 2
+
+        rmd3 = drsblobs.replPropertyMetaData1()
+        rmd3.attid = 3
+        rmd3.version = 2
+
+        rmd.ctr.array = [rmd1, rmd2, rmd3]
+        try:
+            del rmd1.version
+            self.fail("succeeded in deleting rmd1.version")
+        except AttributeError, e:
+            pass
+
+        try:
+            del rmd.ctr.array
+            self.fail("succeeded in deleting rmd.ctr.array")
+        except AttributeError, e:
+            pass
diff --git a/python/samba/tests/dcerpc/string.py b/python/samba/tests/dcerpc/string.py
new file mode 100644
index 0000000..7ce3393
--- /dev/null
+++ b/python/samba/tests/dcerpc/string.py
@@ -0,0 +1,133 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Andrew Bartlett <abartlet at samba.org> 2016
+#
+# 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/>.
+#
+
+"""Tests for string and unicode handling in PIDL generated bindings
+samba.dcerpc.*"""
+
+from samba.dcerpc import drsblobs
+import samba.tests
+from samba.ndr import ndr_unpack, ndr_pack
+import talloc
+import gc
+
+
+class TestException(Exception):
+    pass
+
+
+class StringTests(samba.tests.TestCase):
+
+    def setUp(self):
+        super(StringTests, self).setUp()
+        talloc.enable_null_tracking()
+        self.startup_blocks = talloc.total_blocks()
+
+    def tearDown(self):
+        super(StringTests, self).tearDown()
+        gc.collect()
+        if talloc.total_blocks() != self.startup_blocks:
+            talloc.report_full()
+            self.fail("it appears we are leaking memory")
+
+    def test_string_from_python(self):
+        info = drsblobs.repsFromTo2OtherInfo()
+        info.dns_name1 = "hello.example.com"
+        info.dns_name2 = "goodbye.example.com"
+        gc.collect()
+        self.assertIsNotNone(info)
+        self.assertEqual(info.dns_name1, "hello.example.com")
+        self.assertEqual(info.dns_name2, "goodbye.example.com")
+
+        info.dns_name1 = ""
+        info.dns_name2 = "goodbye.example.com"
+
+        self.assertEqual(info.dns_name1, "")
+        self.assertEqual(info.dns_name2, "goodbye.example.com")
+
+        info.dns_name2 = None
+
+        self.assertEqual(info.dns_name1, "")
+        self.assertIsNone(info.dns_name2)
+
+    def test_string_with_exception(self):
+        try:
+            self.test_string_from_python()
+            raise TestException()
+        except TestException:
+            pass
+
+    def test_string_from_python_function(self):
+        def get_info():
+            info = drsblobs.repsFromTo2OtherInfo()
+            info.dns_name1 = "1.example.com"
+            info.dns_name2 = "2.example.com"
+            return info
+
+        info = get_info()
+        gc.collect()
+        self.assertIsNotNone(info)
+        self.assertEqual(info.dns_name1, "1.example.com")
+        self.assertEqual(info.dns_name2, "2.example.com")
+
+    def test_string_modify_in_place(self):
+        info = drsblobs.repsFromTo2OtherInfo()
+        info.dns_name1 = "1.example.com"
+        info.dns_name2 = "%s.example.com"
+        gc.collect()
+        self.assertIsNotNone(info)
+        self.assertEqual(info.dns_name1, "1.example.com")
+        self.assertEqual(info.dns_name2, "%s.example.com")
+        info.dns_name1 += ".co.nz"
+        info.dns_name2 %= 2
+        self.assertEqual(info.dns_name1, "1.example.com.co.nz")
+        self.assertEqual(info.dns_name2, "2.example.com")
+        del info
+
+
+    def test_string_delete(self):
+        gc.collect()
+        info = drsblobs.repsFromTo2OtherInfo()
+        info.dns_name1 = "1.example.com"
+        info.dns_name2 = "2.example.com"
+        info.dns_name1 = None
+        try:
+            del info.dns_name2
+        except AttributeError:
+            pass
+
+        self.assertIsNotNone(info)
+        self.assertIsNone(info.dns_name1)
+        self.assertIsNotNone(info.dns_name2)
+
+
+class StringTestsWithoutLeakCheck(samba.tests.TestCase):
+    """We know that the ndr unpacking test leaves stuff in the
+    autofree_context, and we don't want to worry about that. So for
+    this test we don't make meory leak assertions."""
+
+    def test_string_from_ndr(self):
+        info = drsblobs.repsFromTo2OtherInfo()
+        info.dns_name1 = "1.example.com"
+        info.dns_name2 = "2.example.com"
+        packed = ndr_pack(info)
+        gc.collect()
+
+        info_unpacked = ndr_unpack(drsblobs.repsFromTo2OtherInfo, packed)
+
+        self.assertIsNotNone(info_unpacked)
+        self.assertEqual(info_unpacked.dns_name1, "1.example.com")
+        self.assertEqual(info_unpacked.dns_name2, "2.example.com")
diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index 73843a7..6daa6b2 100755
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -91,7 +91,10 @@ sub check_or_start($$$)
 
 	my $env_ok = $self->check_env($env_vars);
 	if ($env_ok) {
-	    return $env_vars->{SAMBA_PID};
+		return $env_vars->{SAMBA_PID};
+	} elsif (defined($env_vars->{SAMBA_PID})) {
+		warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
+		return undef;
 	}
 
 	# use a pipe for stdin in the child processes. This allows
@@ -210,10 +213,12 @@ sub wait_for_start($$)
 	    my $count = 0;
 	    my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
 	    my $rid_set_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
+	    my $max_wait = 60;
 	    sleep(1);
 	    while (system("$ldbsearch -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$rid_set_dn\" rIDAllocationPool > /dev/null") != 0) {
 		$count++;
-		if ($count > 40) {
+		if ($count > $max_wait) {
+		    warn("Timed out ($max_wait sec) waiting for working LDAP and a RID Set to be allocated by $testenv_vars->{NETBIOSNAME} PID $testenv_vars->{SAMBA_PID}");
 		    $ret = -1;
 		    last;
 		}
@@ -1818,7 +1823,7 @@ sub teardown_env($$)
 sub getlog_env($$)
 {
 	my ($self, $envvars) = @_;
-	my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
+	my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
 	my $out = $title;
 
 	open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
diff --git a/selftest/tests.py b/selftest/tests.py
index 20eb63b..ccedb40 100644
--- a/selftest/tests.py
+++ b/selftest/tests.py
@@ -60,6 +60,8 @@ planpythontestsuite("none", "samba.tests.samba3")
 planpythontestsuite("none", "samba.tests.strings")
 planpythontestsuite("none", "samba.tests.netcmd")
 planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc")
+planpythontestsuite("none", "samba.tests.dcerpc.array")
+planpythontestsuite("none", "samba.tests.dcerpc.string")
 planpythontestsuite("none", "samba.tests.hostconfig")
 planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging")
 planpythontestsuite("none", "samba.tests.samba3sam")
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index d0a7f54..84d3c6b 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -3555,16 +3555,17 @@ const char *samdb_cn_to_lDAPDisplayName(TALLOC_CTX *mem_ctx, const char *cn)
 	size_t i;
 
 	tokens = str_list_make(mem_ctx, cn, " -_");
-	if (tokens == NULL)
+	if (tokens == NULL || tokens[0] == NULL) {
 		return NULL;
+	}
 
 	/* "tolower()" and "toupper()" should also work properly on 0x00 */
 	tokens[0][0] = tolower(tokens[0][0]);
-	for (i = 1; i < str_list_length((const char * const *)tokens); i++)
+	for (i = 1; tokens[i] != NULL; i++)
 		tokens[i][0] = toupper(tokens[i][0]);
 
 	ret = talloc_strdup(mem_ctx, tokens[0]);
-	for (i = 1; i < str_list_length((const char * const *)tokens); i++)
+	for (i = 1; tokens[i] != NULL; i++)
 		ret = talloc_asprintf_append_buffer(ret, "%s", tokens[i]);
 
 	talloc_free(tokens);
diff --git a/source4/dsdb/samdb/ldb_modules/operational.c b/source4/dsdb/samdb/ldb_modules/operational.c
index c5fd8e2..0dd420a 100644
--- a/source4/dsdb/samdb/ldb_modules/operational.c
+++ b/source4/dsdb/samdb/ldb_modules/operational.c
@@ -362,7 +362,8 @@ static int construct_parent_guid(struct ldb_module *module,
 	/* not NC, so the object should have a parent*/
 	if (ret == LDB_ERR_NO_SUCH_OBJECT) {
 		return ldb_error(ldb_module_get_ctx(module), LDB_ERR_OPERATIONS_ERROR, 
-				 talloc_asprintf(msg, "Parent dn for %s does not exist", 
+				 talloc_asprintf(msg, "Parent dn %s for %s does not exist",
+						 ldb_dn_get_linearized(parent_dn),
 						 ldb_dn_get_linearized(msg->dn)));
 	} else if (ret != LDB_SUCCESS) {
 		return ret;
@@ -1037,7 +1038,7 @@ static int operational_search_post_process(struct ldb_module *module,
 failed:
 	ldb_debug_set(ldb, LDB_DEBUG_WARNING,
 		      "operational_search_post_process failed for attribute '%s' - %s",
-		      attrs_from_user[a], ldb_errstring(ldb));
+		      list_replace[a].attr, ldb_errstring(ldb));
 	return -1;
 }
 
diff --git a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
index 6ba2caa..40bccac 100644
--- a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
+++ b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c


-- 
Samba Shared Repository



More information about the samba-cvs mailing list