[SCM] Samba Shared Repository - branch master updated

Noel Power npower at samba.org
Mon Apr 30 16:26:02 UTC 2018


The branch, master has been updated
       via  268ad19 python/samba: Py2/Py3 compat change '/' to '//' to ensure int result
       via  141d908 python/samba: port some isinstance str checks (to cater for unicode)
       via  b54472f python: Bulk conversion callers of ldb.Dn second param
       via  13280d3 python/samba: bulk conversion of caller to dsdb_Dn 2nd param.
       via  cbd6786 python/samba: Add binary_type for p2/p3 testing.
       via  d331ddf Add aliases for StringIO.StringIO
       via  d2ee36e python/samba: Add some compatability PY2/PY3 functions
       via  ba5f00d s4/param: Additionally accept unicode as string param in Py2
       via  5c12935 s4/librpc: Additionally accept unicode as string param in Py2
       via  5055b54 s4/dsdb: Additionally accept unicode as string param in Py2
       via  3544f1b s4/auth: Additionally accept unicode as string param in Py2
       via  7020af4 libcli/nbt: Additionally accept unicode as string param in Py2
       via  702e85e lib/tevent: Additionally accept unicode as string param in Py2
       via  db8da07 lib/ldb: Additionally accept unicode as string param in Py2
       via  f477a75 samba-tool visualize: use correct DC in graph label
      from  a23d805 ctdb-tests: Fix a typo

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


- Log -----------------------------------------------------------------
commit 268ad19eee469ef7d703d5b9610683aca874fa9f
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 27 08:15:28 2018 +0100

    python/samba: Py2/Py3 compat change '/' to '//' to ensure int result
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    
    Autobuild-User(master): Noel Power <npower at samba.org>
    Autobuild-Date(master): Mon Apr 30 18:25:25 CEST 2018 on sn-devel-144

commit 141d9081f4715b6c0ef439f34ca3b79fbddac1dd
Author: Noel Power <noel.power at suse.com>
Date:   Thu Apr 26 10:38:57 2018 +0100

    python/samba: port some isinstance str checks (to cater for unicode)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit b54472f868dc491579b471db6c6660bb03ab51c3
Author: Noel Power <noel.power at suse.com>
Date:   Wed Apr 25 20:01:49 2018 +0100

    python: Bulk conversion callers of ldb.Dn second param
    
    Convert second param passed to ldb.Dn to be unicode so py2 & py3 code
    will work
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit 13280d3db9fdbbd87c6ed2faa69b24bc7660674d
Author: Noel Power <noel.power at suse.com>
Date:   Wed Apr 25 18:28:30 2018 +0100

    python/samba: bulk conversion of caller to dsdb_Dn 2nd param.
    
    Convert second param to dsdb_Dn to be unicode so py2 & py3 code
    will work
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit cbd6786c0471782024750b85b6f4fbf42977c81b
Author: Noel Power <noel.power at suse.com>
Date:   Tue Apr 24 16:28:41 2018 +0100

    python/samba: Add binary_type for p2/p3 testing.
    
    For helping test for binary types, binary_type evaluates to 'str'
    in py2, and 'bytes' in py3.
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit d331ddf47f7b0ee360a8c7a61e0b38d279ecbd48
Author: Noel Power <noel.power at suse.com>
Date:   Tue Apr 17 13:52:58 2018 +0100

    Add aliases for StringIO.StringIO
    
    cStringIO doesn't handle unicode, StringIO does. With py2/py3
    compatable code we can easily find ourselves getting passed
    unicode so we don't alias cStringIO
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit d2ee36e350108a226a3d3dc641a067c9eed4897d
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 11:19:10 2018 +0100

    python/samba: Add some compatability PY2/PY3 functions
    
    I hope these changes are a short term interim solution for the
    absence of the 'six' module/library. I also hope that soon this
    module can be removed and be replaced by usage of six.
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit ba5f00deb772b76719bfd06467a6b05edfeef061
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 17:34:40 2018 +0100

    s4/param: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit 5c129351cc6b6ebfec78747d8ab0709e45c196bb
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 17:34:19 2018 +0100

    s4/librpc: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit 5055b54d4a67d695e6c8f61098358a759cc49888
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 17:33:47 2018 +0100

    s4/dsdb: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit 3544f1b5d2713479dea2a7ce27da11c8d2b85a90
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 17:33:10 2018 +0100

    s4/auth: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit 7020af427ecb923015ba07ede45d4bb282db25e4
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 17:32:15 2018 +0100

    libcli/nbt: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit 702e85e48fc4972714c57683f4c7b1daf775bd5c
Author: Noel Power <noel.power at suse.com>
Date:   Fri Apr 13 17:17:20 2018 +0100

    lib/tevent: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit db8da077ec5d2b23f2219dd8d667c85d38f56ca8
Author: Noel Power <noel.power at suse.com>
Date:   Thu Apr 12 14:46:59 2018 +0100

    lib/ldb: Additionally accept unicode as string param in Py2
    
    With the changes to make samba python code Py2/Py3 compatible there
    now are many instances where string content is decoded.
    Decoded string variables in Py2 are returned as the unicode type. Many
    Py2 c-module functions that take string arguments only check for the
    string type. However now it's quite possibe the content formally passed
    as a string argument is now passed as unicode after being decoded,
    such arguments are rejected and code can fail subtly. This only affects
    places where the type is directly checked e.g. via PyStr_Check etc.
    arguments that are parsed by ParseTuple* functions generally already
    accept both string and unicode (if 's', 'z', 's*' format specifiers
    are used)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

commit f477a7585b606a5f665636868da24da812f46da0
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Apr 20 10:52:31 2018 +1200

    samba-tool visualize: use correct DC in graph label
    
    We have been using a random DC (depending to hash order, which was not
    random enough on Python 2.7 to affect the tests).
    
    Reported-by: Noel Power <noel.power at suse.com>
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Noel Power <noel.power at suse.com>

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

Summary of changes:
 lib/ldb/pyldb.c                              | 10 +++++-----
 lib/ldb/pyldb_util.c                         |  2 +-
 lib/tevent/pytevent.c                        |  2 +-
 libcli/nbt/pynbt.c                           |  6 +++---
 python/samba/__init__.py                     |  5 +++--
 python/samba/compat.py                       | 22 ++++++++++++++++++++++
 python/samba/dbchecker.py                    | 24 ++++++++++++------------
 python/samba/descriptor.py                   |  4 ++--
 python/samba/graph.py                        |  5 +++--
 python/samba/join.py                         |  4 ++--
 python/samba/kcc/__init__.py                 |  2 +-
 python/samba/kcc/kcc_utils.py                | 12 ++++++------
 python/samba/kcc/ldif_import_export.py       |  2 +-
 python/samba/ms_schema.py                    |  7 ++++---
 python/samba/netcmd/domain.py                |  3 ++-
 python/samba/netcmd/fsmo.py                  |  6 +++---
 python/samba/netcmd/visualize.py             |  6 +++---
 python/samba/provision/__init__.py           |  6 +++---
 python/samba/remove_dc.py                    |  4 ++--
 python/samba/tests/kcc/ldif_import_export.py |  4 ++--
 python/samba/tests/samba_tool/visualize.py   | 15 ++++++++++-----
 python/samba/upgradehelpers.py               |  3 ++-
 source4/auth/pyauth.c                        |  2 +-
 source4/dsdb/pydsdb.c                        |  2 +-
 source4/dsdb/tests/python/rodc_rwdc.py       |  6 +++---
 source4/dsdb/tests/python/token_group.py     |  4 ++--
 source4/librpc/rpc/pyrpc.c                   | 14 +++++++++-----
 source4/param/pyparam.c                      |  2 +-
 source4/param/pyparam_util.c                 |  2 +-
 source4/torture/drs/python/getnc_exop.py     |  4 ++--
 source4/torture/drs/python/repl_rodc.py      |  2 +-
 source4/torture/drs/python/ridalloc_exop.py  | 23 +++++++++++------------
 32 files changed, 125 insertions(+), 90 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 67ecafb..110ec8e 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -1078,7 +1078,7 @@ static const char **PyList_AsStrList(TALLOC_CTX *mem_ctx, PyObject *list,
 		const char *str = NULL;
 		Py_ssize_t size;
 		PyObject *item = PyList_GetItem(list, i);
-		if (!PyStr_Check(item)) {
+		if (!(PyStr_Check(item) || PyUnicode_Check(item))) {
 			PyErr_Format(PyExc_TypeError, "%s should be strings", paramname);
 			talloc_free(ret);
 			return NULL;
@@ -2861,7 +2861,7 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 
 	me->name = talloc_strdup(me, attr_name);
 	me->flags = flags;
-	if (PyBytes_Check(set_obj) || PyStr_Check(set_obj)) {
+	if (PyBytes_Check(set_obj) || PyUnicode_Check(set_obj)) {
 		me->num_values = 1;
 		me->values = talloc_array(me, struct ldb_val, me->num_values);
 		if (PyBytes_Check(set_obj)) {
@@ -2897,7 +2897,7 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 					return NULL;
 				}
 				msg = _msg;
-			} else if (PyStr_Check(obj)) {
+			} else if (PyUnicode_Check(obj)) {
 				msg = PyStr_AsUTF8AndSize(obj, &size);
 				if (msg == NULL) {
 					talloc_free(me);
@@ -3069,7 +3069,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
 
 	if (py_elements != NULL) {
 		Py_ssize_t i;
-		if (PyBytes_Check(py_elements) || PyStr_Check(py_elements)) {
+		if (PyBytes_Check(py_elements) || PyUnicode_Check(py_elements)) {
 			char *_msg = NULL;
 			el->num_values = 1;
 			el->values = talloc_array(el, struct ldb_val, 1);
@@ -3110,7 +3110,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
 					char *_msg = NULL;
 					result = PyBytes_AsStringAndSize(item, &_msg, &size);
 					msg = _msg;
-				} else if (PyStr_Check(item)) {
+				} else if (PyUnicode_Check(item)) {
 					msg = PyStr_AsUTF8AndSize(item, &size);
 					result = (msg == NULL) ? -1 : 0;
 				} else {
diff --git a/lib/ldb/pyldb_util.c b/lib/ldb/pyldb_util.c
index 3bda1db..46ee403 100644
--- a/lib/ldb/pyldb_util.c
+++ b/lib/ldb/pyldb_util.c
@@ -70,7 +70,7 @@ bool pyldb_Object_AsDn(TALLOC_CTX *mem_ctx, PyObject *object,
 	struct ldb_dn *odn;
 	PyTypeObject *PyLdb_Dn_Type;
 
-	if (ldb_ctx != NULL && PyStr_Check(object)) {
+	if (ldb_ctx != NULL && (PyStr_Check(object) || PyUnicode_Check(object))) {
 		odn = ldb_dn_new(mem_ctx, ldb_ctx, PyStr_AsUTF8(object));
 		*dn = odn;
 		return true;
diff --git a/lib/tevent/pytevent.c b/lib/tevent/pytevent.c
index 10d8a22..369ec6e 100644
--- a/lib/tevent/pytevent.c
+++ b/lib/tevent/pytevent.c
@@ -188,7 +188,7 @@ static PyObject *py_register_backend(PyObject *self, PyObject *args)
 		return NULL;
 	}
 
-	if (!PyStr_Check(name)) {
+	if (!(PyStr_Check(name) || PyUnicode_Check(name))) {
 		PyErr_SetNone(PyExc_TypeError);
 		Py_DECREF(name);
 		return NULL;
diff --git a/libcli/nbt/pynbt.c b/libcli/nbt/pynbt.c
index 254c98a..032561a 100644
--- a/libcli/nbt/pynbt.c
+++ b/libcli/nbt/pynbt.c
@@ -57,7 +57,7 @@ static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *
 
 static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
 {
-	if (PyStr_Check(obj)) {
+	if (PyStr_Check(obj) || PyUnicode_Check(obj)) {
 		*dest_addr = PyStr_AsString(obj);
 		*dest_port = NBT_NAME_SERVICE_PORT;
 		return true;
@@ -69,7 +69,7 @@ static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, u
 			return false;
 		}
 
-		if (!PyStr_Check(PyTuple_GetItem(obj, 0))) {
+		if (!(PyStr_Check(PyTuple_GetItem(obj, 0)) || PyUnicode_Check(PyTuple_GetItem(obj, 0)))) {
 			PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string");
 			return false;
 		}
@@ -111,7 +111,7 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
 		}
 	}
 
-	if (PyStr_Check(obj)) {
+	if (PyStr_Check(obj) || PyUnicode_Check(obj)) {
 		/* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
 		name->name = PyStr_AsString(obj);
 		name->scope = NULL;
diff --git a/python/samba/__init__.py b/python/samba/__init__.py
index f62f5e3..20c7db2 100644
--- a/python/samba/__init__.py
+++ b/python/samba/__init__.py
@@ -29,6 +29,7 @@ import ldb
 import samba.param
 from samba import _glue
 from samba._ldb import Ldb as _Ldb
+from samba.compat import string_types
 
 
 def source_tree_topdir():
@@ -249,8 +250,8 @@ def substitute_var(text, values):
     """
 
     for (name, value) in values.items():
-        assert isinstance(name, str), "%r is not a string" % name
-        assert isinstance(value, str), "Value %r for %s is not a string" % (value, name)
+        assert isinstance(name, string_types), "%r is not a string" % name
+        assert isinstance(value, string_types), "Value %r for %s is not a string" % (value, name)
         text = text.replace("${%s}" % name, value)
 
     return text
diff --git a/python/samba/compat.py b/python/samba/compat.py
index 667a1a4..042fc86 100644
--- a/python/samba/compat.py
+++ b/python/samba/compat.py
@@ -22,8 +22,30 @@ import sys
 PY3 = sys.version_info[0] == 3
 
 if PY3:
+    # compat functions
+    from  urllib.parse import quote as urllib_quote
+    from urllib.request import urlopen as urllib_urlopen
+
+    # compat types
     integer_types = int,
+    string_types = str
     text_type = str
+    binary_type = bytes
+
+    # alias
+    import io
+    StringIO = io.StringIO
 else:
+    # compat functions
+    from urllib import quote as urllib_quote
+    from urllib import urlopen as urllib_urlopen
+
+    # compat types
     integer_types = (int, long)
+    string_types = basestring
     text_type = unicode
+    binary_type = str
+
+    # alias
+    import StringIO
+    StringIO = StringIO.StringIO
diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py
index fb968a5..9d72fc6 100644
--- a/python/samba/dbchecker.py
+++ b/python/samba/dbchecker.py
@@ -144,11 +144,11 @@ class dbcheck(object):
 
         for nc in self.ncs:
             try:
-                dn = self.samdb.get_wellknown_dn(ldb.Dn(self.samdb, nc),
+                dn = self.samdb.get_wellknown_dn(ldb.Dn(self.samdb, nc.decode('utf8')),
                                                  dsdb.DS_GUID_DELETED_OBJECTS_CONTAINER)
                 self.deleted_objects_containers.append(dn)
             except KeyError:
-                self.ncs_lacking_deleted_containers.append(ldb.Dn(self.samdb, nc))
+                self.ncs_lacking_deleted_containers.append(ldb.Dn(self.samdb, nc.decode('utf8')))
 
         domaindns_zone = 'DC=DomainDnsZones,%s' % self.samdb.get_default_basedn()
         forestdns_zone = 'DC=ForestDnsZones,%s' % self.samdb.get_root_basedn()
@@ -178,13 +178,13 @@ class dbcheck(object):
         res = self.samdb.search(base=ldb.Dn(self.samdb, self.samdb.get_serverName()),
                                 scope=ldb.SCOPE_BASE, attrs=["serverReference"])
         # 2. Get server reference
-        self.server_ref_dn = ldb.Dn(self.samdb, res[0]['serverReference'][0])
+        self.server_ref_dn = ldb.Dn(self.samdb, res[0]['serverReference'][0].decode('utf8'))
 
         # 3. Get RID Set
         res = self.samdb.search(base=self.server_ref_dn,
                                 scope=ldb.SCOPE_BASE, attrs=['rIDSetReferences'])
         if "rIDSetReferences" in res[0]:
-            self.rid_set_dn = ldb.Dn(self.samdb, res[0]['rIDSetReferences'][0])
+            self.rid_set_dn = ldb.Dn(self.samdb, res[0]['rIDSetReferences'][0].decode('utf8'))
         else:
             self.rid_set_dn = None
 
@@ -286,7 +286,7 @@ class dbcheck(object):
             listwko = []
             proposed_objectguid = None
             for o in wko:
-                dsdb_dn = dsdb_Dn(self.samdb, o, dsdb.DSDB_SYNTAX_BINARY_DN)
+                dsdb_dn = dsdb_Dn(self.samdb, o.decode('utf8'), dsdb.DSDB_SYNTAX_BINARY_DN)
                 if self.is_deleted_objects_dn(dsdb_dn):
                     self.report("wellKnownObjects had duplicate Deleted Objects value %s" % o)
                     # We really want to put this back in the same spot
@@ -917,7 +917,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
                                 controls=["show_deleted:0", "extended_dn:0", "reveal_internals:0"])
         syntax_oid = self.samdb_schema.get_syntax_oid_from_lDAPDisplayName(attrname)
         for val in res[0][attrname]:
-            dsdb_dn = dsdb_Dn(self.samdb, val, syntax_oid)
+            dsdb_dn = dsdb_Dn(self.samdb, val.decode('utf8'), syntax_oid)
             guid2 = dsdb_dn.dn.get_extended_component("GUID")
             if guid == guid2:
                 return dsdb_dn
@@ -943,7 +943,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
             self.duplicate_link_cache[duplicate_cache_key] = False
 
         for val in obj[forward_attr]:
-            dsdb_dn = dsdb_Dn(self.samdb, val, forward_syntax)
+            dsdb_dn = dsdb_Dn(self.samdb, val.decode('utf8'), forward_syntax)
 
             # all DNs should have a GUID component
             guid = dsdb_dn.dn.get_extended_component("GUID")
@@ -1178,7 +1178,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
             obj[attrname] = ldb.MessageElement(vals, 0, attrname)
 
         for val in obj[attrname]:
-            dsdb_dn = dsdb_Dn(self.samdb, val, syntax_oid)
+            dsdb_dn = dsdb_Dn(self.samdb, val.decode('utf8'), syntax_oid)
 
             # all DNs should have a GUID component
             guid = dsdb_dn.dn.get_extended_component("GUID")
@@ -1312,7 +1312,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
             match_count = 0
             if reverse_link_name in res[0]:
                 for v in res[0][reverse_link_name]:
-                    v_dn = dsdb_Dn(self.samdb, v)
+                    v_dn = dsdb_Dn(self.samdb, v.decode('utf8'))
                     v_guid = v_dn.dn.get_extended_component("GUID")
                     v_blob = v_dn.dn.get_extended_component("RMD_FLAGS")
                     v_rmd_flags = 0
@@ -1329,7 +1329,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
                         # Forward binary multi-valued linked attribute
                         forward_count = 0
                         for w in obj[attrname]:
-                            w_guid = dsdb_Dn(self.samdb, w).dn.get_extended_component("GUID")
+                            w_guid = dsdb_Dn(self.samdb, w.decode('utf8')).dn.get_extended_component("GUID")
                             if w_guid == guid:
                                 forward_count += 1
 
@@ -1337,7 +1337,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
                             continue
             expected_count = 0
             for v in obj[attrname]:
-                v_dn = dsdb_Dn(self.samdb, v)
+                v_dn = dsdb_Dn(self.samdb, v.decode('utf8'))
                 v_guid = v_dn.dn.get_extended_component("GUID")
                 v_blob = v_dn.dn.get_extended_component("RMD_FLAGS")
                 v_rmd_flags = 0
@@ -2483,7 +2483,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
             error_count += 1
             if not self.confirm('Change dsServiceName to GUID form?'):
                 return error_count
-            res = self.samdb.search(base=ldb.Dn(self.samdb, obj['dsServiceName'][0]),
+            res = self.samdb.search(base=ldb.Dn(self.samdb, obj['dsServiceName'][0].decode('utf8')),
                                     scope=ldb.SCOPE_BASE, attrs=['objectGUID'])
             guid_str = str(ndr_unpack(misc.GUID, res[0]['objectGUID'][0]))
             m = ldb.Message()
diff --git a/python/samba/descriptor.py b/python/samba/descriptor.py
index a9c5e15..1e56e53 100644
--- a/python/samba/descriptor.py
+++ b/python/samba/descriptor.py
@@ -415,7 +415,7 @@ def get_wellknown_sds(samdb):
     for nc in current[0]["namingContexts"]:
 
         dnsforestdn = ldb.Dn(samdb, "DC=ForestDnsZones,%s" % (str(samdb.get_root_basedn())))
-        if ldb.Dn(samdb, nc) == dnsforestdn:
+        if ldb.Dn(samdb, nc.decode('utf8')) == dnsforestdn:
             c = (ldb.Dn(samdb, "%s" % str(dnsforestdn)), get_dns_partition_descriptor)
             subcontainers.append(c)
             c = (ldb.Dn(samdb, "CN=Infrastructure,%s" % str(dnsforestdn)),
@@ -430,7 +430,7 @@ def get_wellknown_sds(samdb):
             continue
 
         dnsdomaindn = ldb.Dn(samdb, "DC=DomainDnsZones,%s" % (str(samdb.domain_dn())))
-        if ldb.Dn(samdb, nc) == dnsdomaindn:
+        if ldb.Dn(samdb, nc.decode('utf8')) == dnsdomaindn:
             c = (ldb.Dn(samdb, "%s" % str(dnsdomaindn)), get_dns_partition_descriptor)
             subcontainers.append(c)
             c = (ldb.Dn(samdb, "CN=Infrastructure,%s" % str(dnsdomaindn)),
diff --git a/python/samba/graph.py b/python/samba/graph.py
index 6cdd2ef..7dfc190 100644
--- a/python/samba/graph.py
+++ b/python/samba/graph.py
@@ -19,6 +19,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from __future__ import print_function
+from __future__ import division
 from samba import colour
 import sys
 
@@ -39,8 +40,8 @@ def reformat_graph_label(s):
             if '-' in p[2:20]:
                 q, p = p.split('-', 1)
             else:
-                n = len(p) / 12
-                b = len(p) / n
+                n = len(p) // 12
+                b = len(p) // n
                 q, p = p[:b], p[b:]
             pieces.append(q + '-')
         if p:
diff --git a/python/samba/join.py b/python/samba/join.py
index b5cab7e..b35eb78 100644
--- a/python/samba/join.py
+++ b/python/samba/join.py
@@ -388,7 +388,7 @@ class dc_join(object):
         if not 'fSMORoleOwner' in res[0]:
             raise DCJoinException("Can't find naming master on partition DN %s in %s" % (ctx.partition_dn, ctx.samdb.url))
         try:
-            master_guid = str(misc.GUID(ldb.Dn(ctx.samdb, res[0]['fSMORoleOwner'][0]).get_extended_component('GUID')))
+            master_guid = str(misc.GUID(ldb.Dn(ctx.samdb, res[0]['fSMORoleOwner'][0].decode('utf8')).get_extended_component('GUID')))
         except KeyError:
             raise DCJoinException("Can't find GUID in naming master on partition DN %s" % res[0]['fSMORoleOwner'][0])
 
@@ -880,7 +880,7 @@ class dc_join(object):
             raise DCJoinException("Can't find naming context on partition DN %s in %s" % (ctx.partition_dn, ctx.samdb.url))
 
         try:
-            ctx.names.domainguid = str(misc.GUID(ldb.Dn(ctx.samdb, res[0]['ncName'][0]).get_extended_component('GUID')))
+            ctx.names.domainguid = str(misc.GUID(ldb.Dn(ctx.samdb, res[0]['ncName'][0].decode('utf8')).get_extended_component('GUID')))
         except KeyError:
             raise DCJoinException("Can't find GUID in naming master on partition DN %s" % res[0]['ncName'][0])
 
diff --git a/python/samba/kcc/__init__.py b/python/samba/kcc/__init__.py
index 1a962bb..be1c4d8 100644
--- a/python/samba/kcc/__init__.py
+++ b/python/samba/kcc/__init__.py
@@ -274,7 +274,7 @@ class KCC(object):
                                                      scope=ldb.SCOPE_BASE,
                                                      attrs=["dsServiceName"])
                 dn = ldb.Dn(self.samdb,
-                            service_name_res[0]["dsServiceName"][0])
+                            service_name_res[0]["dsServiceName"][0].decode('utf8'))
 
                 res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE,
                                         attrs=["objectGUID"])
diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py
index 2118570..23fbd40 100644
--- a/python/samba/kcc/kcc_utils.py
+++ b/python/samba/kcc/kcc_utils.py
@@ -739,7 +739,7 @@ class DirectoryServiceAgent(object):
                 for value in res[0][k]:
                     # Turn dn into a dsdb_Dn so we can use
                     # its methods to parse a binary DN
-                    dsdn = dsdb_Dn(samdb, value)
+                    dsdn = dsdb_Dn(samdb, value.decode('utf8'))
                     flags = dsdn.get_binary_integer()
                     dnstr = str(dsdn.dn)
 
@@ -986,7 +986,7 @@ class NTDSConnection(object):
                            "for (%s)" % (self.dnstr))
 
         if "transportType" in msg:
-            dsdn = dsdb_Dn(samdb, msg["transportType"][0])
+            dsdn = dsdb_Dn(samdb, msg["transportType"][0].decode('utf8'))
             self.load_connection_transport(samdb, str(dsdn.dn))
 
         if "schedule" in msg:
@@ -996,7 +996,7 @@ class NTDSConnection(object):
             self.whenCreated = ldb.string_to_time(msg["whenCreated"][0])
 
         if "fromServer" in msg:
-            dsdn = dsdb_Dn(samdb, msg["fromServer"][0])
+            dsdn = dsdb_Dn(samdb, msg["fromServer"][0].decode('utf8'))
             self.from_dnstr = str(dsdn.dn)
             assert self.from_dnstr is not None
 
@@ -1363,7 +1363,7 @@ class Partition(NamingContext):
                 continue
 
             for value in msg[k]:
-                dsdn = dsdb_Dn(samdb, value)
+                dsdn = dsdb_Dn(samdb, value.decode('utf8'))
                 dnstr = str(dsdn.dn)
 
                 if k == "nCName":
@@ -1926,7 +1926,7 @@ class Transport(object):
 
         if "bridgeheadServerListBL" in msg:
             for value in msg["bridgeheadServerListBL"]:
-                dsdn = dsdb_Dn(samdb, value)
+                dsdn = dsdb_Dn(samdb, value.decode('utf8'))
                 dnstr = str(dsdn.dn)
                 if dnstr not in self.bridgehead_list:
                     self.bridgehead_list.append(dnstr)
@@ -2188,7 +2188,7 @@ class SiteLink(object):
 
         if "siteList" in msg:
             for value in msg["siteList"]:
-                dsdn = dsdb_Dn(samdb, value)
+                dsdn = dsdb_Dn(samdb, value.decode('utf8'))
                 guid = misc.GUID(dsdn.dn.get_extended_component('GUID'))
                 if guid not in self.site_list:
                     self.site_list.append(guid)
diff --git a/python/samba/kcc/ldif_import_export.py b/python/samba/kcc/ldif_import_export.py
index aab39ee..86453f1 100644
--- a/python/samba/kcc/ldif_import_export.py
+++ b/python/samba/kcc/ldif_import_export.py
@@ -233,7 +233,7 @@ def samdb_to_ldif_file(samdb, dburl, lp, creds, ldif_file):
                         for value in msg[k]:
                             # Some of these have binary DNs so
                             # use dsdb_Dn to split out relevent parts
-                            dsdn = dsdb_Dn(samdb, value)
+                            dsdn = dsdb_Dn(samdb, value.decode('utf8'))
                             dnstr = str(dsdn.dn)
                             if dnstr not in nclist:
                                 nclist.append(dnstr)
diff --git a/python/samba/ms_schema.py b/python/samba/ms_schema.py
index 889b7f5..de6e4b2 100644
--- a/python/samba/ms_schema.py
+++ b/python/samba/ms_schema.py
@@ -21,6 +21,7 @@ from __future__ import print_function
 import re
 import base64
 import uuid
+from samba.compat import string_types
 
 bitFields = {}
 
@@ -172,7 +173,7 @@ def fix_dn(dn):
 
 def __convert_bitfield(key, value):
     """Evaluate the OR expression in 'value'"""
-    assert(isinstance(value, str))
+    assert(isinstance(value, string_types))
 
     value = value.replace("\n ", "")
     value = value.replace(" ", "")
@@ -194,7 +195,7 @@ def __write_ldif_one(entry):
     out = []
 
     for l in entry:
-        if isinstance(l[1], str):
+        if isinstance(l[1], string_types):
             vl = [l[1]]
         else:
             vl = l[1]
@@ -247,7 +248,7 @@ def __transform_entry(entry, objectClass):
                 l[1] = oMObjectClassBER[l[1].strip()]
                 l[2] = True
 
-        if isinstance(l[1], str):
+        if isinstance(l[1], string_types):
             l[1] = fix_dn(l[1])
 
         if key == 'dn':
diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py
index d2dd06a..1e242de 100644
--- a/python/samba/netcmd/domain.py
+++ b/python/samba/netcmd/domain.py
@@ -23,6 +23,7 @@
 #
 
 from __future__ import print_function
+from __future__ import division
 import samba.getopt as options
 import ldb
 import string
@@ -2331,7 +2332,7 @@ class cmd_domain_trust_create(DomainTrustCommand):
             # 512 bytes and a 2 bytes confounder is required.
             #
             def random_trust_secret(length):
-                pw = samba.generate_random_machine_password(length/2, length/2)
+                pw = samba.generate_random_machine_password(length//2, length//2)
                 return string_to_byte_array(pw.encode('utf-16-le'))
 
             if local_trust_info.trust_direction & lsa.LSA_TRUST_DIRECTION_INBOUND:
diff --git a/python/samba/netcmd/fsmo.py b/python/samba/netcmd/fsmo.py
index 41e4559..91de5da 100644
--- a/python/samba/netcmd/fsmo.py
+++ b/python/samba/netcmd/fsmo.py
@@ -47,7 +47,7 @@ def get_fsmo_roleowner(samdb, roledn, role):
         raise
 
     if 'fSMORoleOwner' in res[0]:
-        master_owner = (ldb.Dn(samdb, res[0]["fSMORoleOwner"][0]))
+        master_owner = (ldb.Dn(samdb, res[0]["fSMORoleOwner"][0].decode('utf8')))
     else:
         master_owner = None
 
@@ -72,9 +72,9 @@ def transfer_dns_role(outf, sambaopts, credopts, role, samdb):
     if 'fSMORoleOwner' in res[0]:
         try:
             master_guid = str(misc.GUID(ldb.Dn(samdb,
-                              res[0]['fSMORoleOwner'][0])
+                              res[0]['fSMORoleOwner'][0].decode('utf8'))


-- 
Samba Shared Repository



More information about the samba-cvs mailing list