[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Fri Jul 13 02:03:04 UTC 2018


The branch, master has been updated
       via  f8d9751 python/samba/netcmd: Fix wrong exception referenced in code
       via  d96d85a python/samba/kcc: md5 needs to be passed bytes in py3
       via  1a9786f python/samba/tests: various py3 porting for ord/chr
       via  f59a20e s4/torure/drs/python: Fix incorrect use of unicode which doesn't exist in py3
       via  fee61c5 s4/torture/drs/python: xrange -> range for py2/py3 compat
       via  08c9ce4 s4/torture/drs/python: long is not used in py3
       via  409ad5c s4/torture/drs/python: use cmp_fn for cmp (for py2/py3 compat)
       via  77ee94c s4/torture/drs/python: use cmp_fn and key=cmp_to_key_fn for py2/py3
       via  0e930df python/samba: Add cmp_fn and cmp_to_key_fn functions for py2/py3
       via  06d3eac s4/torture/drs/python: py2/py3 port map / ord usage
       via  343dc31 s4/torture/drs: ndr_upack needs bytes in py3 (samba4.drs.repl_move)
       via  2a2c221 s4/dsdb/tests/python: base64.b64encode returns bytes
       via  883c3d8 s4/librpc/ndr: allow GUID to accept unicode also
       via  bbc5d31 python/samba/netcmd: Fix relative module import
       via  c46fd16 python/samba/netcmd: Protect variable that can be None
       via  352eee5 python/samba/netcmd: fix py2/py3 bytes usage for replace
       via  e915d18 s4/torture/drs/python: Py2/Py2 fix tab/space also incorrect unicode usage
       via  7b17020 lib/ldb: Implement a bytes derived object for attributes py2/py3
       via  337ae8c python/samba/tests: remove Py2 specific imports.
       via  7d43571 python/samba/emulate: Fix some more missed exception tuple assignments
       via  d5cd9af python/samba/tests: Py2/Py3 port for hexdump
       via  5b96e34 python/samba/tests: Py2/Py3 allow import of ndr_(un)pack to work
       via  9b16463 samdb: use int for get and set methods instead of digit str
      from  f3358f0 gpo: Specify samba module when importing from gpclass

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


- Log -----------------------------------------------------------------
commit f8d9751344c75f1f343b857db82f689847628adc
Author: Noel Power <noel.power at suse.com>
Date:   Wed Jun 27 12:01:18 2018 +0100

    python/samba/netcmd: Fix wrong exception referenced in code
    
    post commit: 52729d35495db638c84caa8cc6f5ffdf0b670353 wrong
    exception name was referenced.
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Fri Jul 13 04:01:59 CEST 2018 on sn-devel-144

commit d96d85a22be6da5b627ea6de212e99b8d08dca94
Author: Noel Power <noel.power at suse.com>
Date:   Tue Jun 19 11:22:50 2018 +0100

    python/samba/kcc: md5 needs to be passed bytes in py3
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Signed-off-by: Joe Guo <joeg at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 1a9786fe585d0354c20585768e8bd057a1473650
Author: Noel Power <noel.power at suse.com>
Date:   Mon Jun 18 18:02:01 2018 +0100

    python/samba/tests: various py3 porting for ord/chr
    
    various messages are lists of ints that need converting to str or bytes
    depending on py2/py3, others are str/bytes that need modification and
    are converted to lists or string char or ints for modificate (and then
    reconstructed as str/bytes again)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit f59a20eb3b20b12fbf128b93c2a7a768be89e656
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 16:26:28 2018 +0100

    s4/torure/drs/python: Fix incorrect use of unicode which doesn't exist in py3
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Signed-off-by: Joe Guo <joeg at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit fee61c57348d6964f61b27feef9d27b70889ed49
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 15:13:56 2018 +0100

    s4/torture/drs/python: xrange -> range for py2/py3 compat
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 08c9ce41e91c5e68aa116e5b5b2bae97353f2fbc
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 14:29:42 2018 +0100

    s4/torture/drs/python: long is not used in py3
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 409ad5c0f07445ea7d12466b56fbfbccfe71c2d1
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 13:06:13 2018 +0100

    s4/torture/drs/python: use cmp_fn for cmp (for py2/py3 compat)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 77ee94c3df1180da5cb6c7cc478bd814e1d02258
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 13:04:13 2018 +0100

    s4/torture/drs/python: use cmp_fn and key=cmp_to_key_fn for py2/py3
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 0e930dfb477b121b69351cc9a011dfb71bcd10c0
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 13:00:15 2018 +0100

    python/samba: Add cmp_fn and cmp_to_key_fn functions for py2/py3
    
    the cmp function and the cmp paramater (e.g. to sort functions)
    no longer exist in python3.
    
    cmp_fn is provides the missing functionality of the py2 cmp builtin
    function.
    
    cmp_to_key_fn allows the key paramater (e.g. for sort) to use the
    old py2 cmp function for sorting. Note: the cmp_to_key is present in
    since 2.7 (hence the inclusion of the source code for this function pre
    that version)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Signed-off-by: Joe Guo <joeg at catalyst.net.nz>

commit 06d3eac8a1f74b2954f6ca01a8ee3c33c23f1df5
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 10:58:13 2018 +0100

    s4/torture/drs/python: py2/py3 port map / ord usage
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 343dc311486a07be0830e15311c548d1ab53b7cf
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 15 10:18:30 2018 +0100

    s4/torture/drs: ndr_upack needs bytes in py3 (samba4.drs.repl_move)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 2a2c22136ba63eb994faa6b2eeda342dd5491d49
Author: Noel Power <noel.power at suse.com>
Date:   Thu May 31 16:13:28 2018 +0100

    s4/dsdb/tests/python: base64.b64encode returns bytes
    
    adjust to unicode for py2/py3 compat needed as part of changes
    to ensure samba4.ldap.password_settings will work with PY3
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Signed-off-by: Joe Guo <joeg at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 883c3d8d646135c182db3c6f4085edb052929bcf
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 18 17:15:44 2018 +0100

    s4/librpc/ndr: allow GUID to accept unicode also
    
    This needed since _GUID_string method change
    (in source4/torture/drs/python/drs_base.py) which makes use use
    a unicode guid at times now
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit bbc5d3147064e211df0619689945ea32468f5460
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 18 12:12:44 2018 +0100

    python/samba/netcmd: Fix relative module import
    
    Part of future changes needed to enable samba4.drs.replica_sync_rodc
    for PY3.
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit c46fd168fc1c0021e97f849088ac634c1b077f27
Author: Noel Power <noel.power at suse.com>
Date:   Thu May 17 15:25:29 2018 +0100

    python/samba/netcmd: Protect variable that can be None
    
    In py3 None variable cannot be compared with '>' '<' etc operators
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 352eee57ae0b3cd48ea8bab33d483812d57b8efd
Author: Noel Power <noel.power at suse.com>
Date:   Thu May 17 15:23:38 2018 +0100

    python/samba/netcmd: fix py2/py3 bytes usage for replace
    
    base64.b64encode returns bytes in py3 make sure associated replace
    uses 'b' for strings passed to replace
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit e915d18e559370ee661d24d9682f0ba8e138ace8
Author: Noel Power <noel.power at suse.com>
Date:   Tue May 15 15:32:35 2018 +0100

    s4/torture/drs/python: Py2/Py2 fix tab/space also incorrect unicode usage
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 7b170206b45e2c10af1591f3a8d6565a1ae3853c
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 11 13:48:29 2018 +0100

    lib/ldb: Implement a bytes derived object for attributes py2/py3
    
    ldb attributes are either bytes (py3) or str (py2)
    
    Some places in the code do str(res[0]['attribute'][0])
    which results in
       'result' (py2)
      b'result' (py3)
    
    or more commonly the attribute is used to construct a string e.g.
       "blah=" + res[0]['attribute'][0] + ",foo,bar=...."
    
    giving
       "blah=result,foo,bar=...." (py2)
    and very unhelpfully
       "blah=b'result',foo,bar=...." (py3)
    
    lots of code already constructs various strings for passing to other
    api using the above. To avoid many excessive
        res[0]['attribute'][0].decode('utf8')
    
    code like 'res[0]['attribute'][0]'
    
    will now return LdbBytes (a new object subclassing 'bytes') in py3
    instead of bytes. This object has a custom '__str__' method which
    attempts to return a string decoded to uft8. In Py2 this will behave as
    it did previously (this is the safer option at the moment)
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 337ae8cd586aeb43721f79485f6a35a68b6060f2
Author: Noel Power <noel.power at suse.com>
Date:   Thu May 10 13:14:22 2018 +0100

    python/samba/tests: remove Py2 specific imports.
    
    Remove some python2 specific import, probably this was due to
    previous unavailability for some c-modules in python3
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 7d435711692a7c6485bb13e626727400d01d21e3
Author: Noel Power <noel.power at suse.com>
Date:   Wed May 9 20:17:30 2018 +0100

    python/samba/emulate: Fix some more missed exception tuple assignments
    
    In python3 we need to change
    
        except LdbError as e:
    -        (status, _) = e
    to
        except LdbError as e:
    +        (status, _) = e.args
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit d5cd9af7b502f8cb3b0a6917bf5cc0a741bac454
Author: Noel Power <noel.power at suse.com>
Date:   Tue May 1 19:58:36 2018 +0100

    python/samba/tests: Py2/Py3 port for hexdump
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 5b96e349817eb28060b16095c907319c438cd670
Author: Noel Power <noel.power at suse.com>
Date:   Mon Apr 30 18:43:54 2018 +0100

    python/samba/tests: Py2/Py3 allow import of ndr_(un)pack to work
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 9b164637f03b5d19054d286f883b9ce3bc30d76d
Author: Joe Guo <joeg at catalyst.net.nz>
Date:   Thu Jul 12 16:57:43 2018 +1200

    samdb: use int for get and set methods instead of digit str
    
    This will make the API work in a nature way.
    
    Also, because of a defect in ldb API, code like `res[0]["maxPwdAge"][0]`
    will return bytes even in Python3, which will cause trouble. By casting
    the value to int, we avoid the str/bytes issue.
    
    Signed-off-by: Joe Guo <joeg at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

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

Summary of changes:
 lib/ldb/pyldb.c                                   | 45 +++++++++++++++++++++-
 python/samba/compat.py                            | 46 +++++++++++++++++++++++
 python/samba/emulate/traffic.py                   | 14 +++----
 python/samba/gp_sec_ext.py                        |  8 ++--
 python/samba/kcc/__init__.py                      |  4 +-
 python/samba/netcmd/domain.py                     | 29 ++++++++------
 python/samba/netcmd/drs.py                        |  2 +-
 python/samba/netcmd/user.py                       |  2 +-
 python/samba/samdb.py                             | 12 ++++--
 python/samba/tests/__init__.py                    | 28 ++++++++------
 python/samba/tests/dcerpc/raw_testcase.py         | 18 ++++-----
 python/samba/tests/dns_base.py                    | 28 ++++++++------
 python/samba/tests/net_join.py                    |  2 +-
 python/samba/tests/netlogonsvc.py                 |  2 +-
 python/samba/tests/ntlmdisabled.py                |  4 +-
 python/samba/tests/samba_tool/passwordsettings.py |  2 +-
 source4/dsdb/tests/python/password_settings.py    |  6 +--
 source4/librpc/ndr/py_misc.c                      |  2 +-
 source4/torture/drs/python/drs_base.py            | 24 ++++++------
 source4/torture/drs/python/getnc_exop.py          | 25 +++++++-----
 source4/torture/drs/python/repl_move.py           |  2 +-
 source4/torture/drs/python/repl_schema.py         |  2 +-
 22 files changed, 212 insertions(+), 95 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 110ec8e..66bc202 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -79,6 +79,7 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 						      PyObject *set_obj,
 						      unsigned int flags,
 						      const char *attr_name);
+static PyTypeObject PyLdbBytesType;
 
 #if PY_MAJOR_VERSION >= 3
 #define PyStr_Check PyUnicode_Check
@@ -89,6 +90,16 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 #define PyStr_AsUTF8 PyUnicode_AsUTF8
 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
 #define PyInt_FromLong PyLong_FromLong
+
+static PyObject *PyLdbBytes_FromStringAndSize(const char *msg, int size)
+{
+	PyObject* result = NULL;
+	PyObject* args = NULL;
+	args = Py_BuildValue("(y#)", msg, size);
+	result = PyLdbBytesType.tp_new(&PyLdbBytesType, args, NULL);
+	Py_DECREF(args);
+	return result;
+}
 #else
 #define PyStr_Check PyString_Check
 #define PyStr_FromString PyString_FromString
@@ -96,6 +107,7 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 #define PyStr_FromFormat PyString_FromFormat
 #define PyStr_FromFormatV PyString_FromFormatV
 #define PyStr_AsUTF8 PyString_AsString
+#define PyLdbBytes_FromStringAndSize PyString_FromStringAndSize
 
 const char *PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr);
 const char *
@@ -270,10 +282,34 @@ static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_
 			Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
 				      ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
 }
+static PyObject *py_ldb_bytes_str(PyBytesObject *self)
+{
+	char *msg = NULL;
+	Py_ssize_t size;
+	int result = 0;
+	if (!PyBytes_Check(self)) {
+		PyErr_Format(PyExc_TypeError,"Unexpected type");
+		return NULL;
+	}
+	result = PyBytes_AsStringAndSize((PyObject *)self, &msg, &size);
+	if (result != 0) {
+		PyErr_Format(PyExc_TypeError, "Failed to extract bytes");
+		return NULL;
+	}
+	return PyUnicode_FromStringAndSize(msg, size);
+}
+
+static PyTypeObject PyLdbBytesType = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	.tp_name = "ldb.bytes",
+	.tp_doc = "str/bytes (with custom str)",
+        .tp_str = (reprfunc)py_ldb_bytes_str,
+	.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+};
 
 static PyObject *PyObject_FromLdbValue(const struct ldb_val *val)
 {
-	return PyBytes_FromStringAndSize((const char *)val->data, val->length);
+	return PyLdbBytes_FromStringAndSize((const char *)val->data, val->length);
 }
 
 static PyObject *PyStr_FromLdbValue(const struct ldb_val *val)
@@ -2990,7 +3026,7 @@ static PyObject *py_ldb_msg_element_find(PyLdbMessageElementObject *self, Py_ssi
 		PyErr_SetString(PyExc_IndexError, "Out of range");
 		return NULL;
 	}
-	return PyBytes_FromStringAndSize((char *)el->values[idx].data, el->values[idx].length);
+	return PyLdbBytes_FromStringAndSize((char *)el->values[idx].data, el->values[idx].length);
 }
 
 static PySequenceMethods py_ldb_msg_element_seq = {
@@ -4123,6 +4159,11 @@ static PyObject* module_init(void)
 {
 	PyObject *m;
 
+	PyLdbBytesType.tp_base = &PyBytes_Type;
+	if (PyType_Ready(&PyLdbBytesType) < 0) {
+		return NULL;
+	}
+
 	if (PyType_Ready(&PyLdbDn) < 0)
 		return NULL;
 
diff --git a/python/samba/compat.py b/python/samba/compat.py
index 042fc86..3fdeec8 100644
--- a/python/samba/compat.py
+++ b/python/samba/compat.py
@@ -22,9 +22,20 @@ import sys
 PY3 = sys.version_info[0] == 3
 
 if PY3:
+    def cmp_fn(x, y):
+        """
+        Replacement for built-in function cmp that was removed in Python 3
+
+        Compare the two objects x and y and return an integer according to
+        the outcome. The return value is negative if x < y, zero if x == y
+        and strictly positive if x > y.
+        """
+
+        return (x > y) - (x < y)
     # compat functions
     from  urllib.parse import quote as urllib_quote
     from urllib.request import urlopen as urllib_urlopen
+    from functools import cmp_to_key as cmp_to_key_fn
 
     # compat types
     integer_types = int,
@@ -36,6 +47,40 @@ if PY3:
     import io
     StringIO = io.StringIO
 else:
+
+    if sys.version_info < (2, 7):
+        def cmp_to_key_fn(mycmp):
+
+            """Convert a cmp= function into a key= function"""
+            class K(object):
+                __slots__ = ['obj']
+
+                def __init__(self, obj, *args):
+                    self.obj = obj
+
+                def __lt__(self, other):
+                    return mycmp(self.obj, other.obj) < 0
+
+                def __gt__(self, other):
+                    return mycmp(self.obj, other.obj) > 0
+
+                def __eq__(self, other):
+                    return mycmp(self.obj, other.obj) == 0
+
+                def __le__(self, other):
+                    return mycmp(self.obj, other.obj) <= 0
+
+                def __ge__(self, other):
+                    return mycmp(self.obj, other.obj) >= 0
+
+                def __ne__(self, other):
+                    return mycmp(self.obj, other.obj) != 0
+
+                def __hash__(self):
+                    raise TypeError('hash not implemented')
+            return K
+    else:
+        from functools import cmp_to_key as cmp_to_key_fn
     # compat functions
     from urllib import quote as urllib_quote
     from urllib import urlopen as urllib_urlopen
@@ -49,3 +94,4 @@ else:
     # alias
     import StringIO
     StringIO = StringIO.StringIO
+    cmp_fn = cmp
diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py
index dba2c3f..c96530b 100644
--- a/python/samba/emulate/traffic.py
+++ b/python/samba/emulate/traffic.py
@@ -1568,7 +1568,7 @@ def create_ou(ldb, instance_id):
         ldb.add({"dn":          ou.split(',', 1)[1],
                  "objectclass": "organizationalunit"})
     except LdbError as e:
-        (status, _) = e
+        (status, _) = e.args
         # ignore already exists
         if status != 68:
             raise
@@ -1576,7 +1576,7 @@ def create_ou(ldb, instance_id):
         ldb.add({"dn":          ou,
                  "objectclass": "organizationalunit"})
     except LdbError as e:
-        (status, _) = e
+        (status, _) = e.args
         # ignore already exists
         if status != 68:
             raise
@@ -1626,7 +1626,7 @@ def generate_traffic_accounts(ldb, instance_id, number, password):
             create_machine_account(ldb, instance_id, netbios_name, password)
             added += 1
         except LdbError as e:
-            (status, _) = e
+            (status, _) = e.args
             if status == 68:
                 break
             else:
@@ -1642,7 +1642,7 @@ def generate_traffic_accounts(ldb, instance_id, number, password):
             create_user_account(ldb, instance_id, username, password)
             added += 1
         except LdbError as e:
-            (status, _) = e
+            (status, _) = e.args
             if status == 68:
                 break
             else:
@@ -1728,7 +1728,7 @@ def generate_users(ldb, instance_id, number, password):
             create_user_account(ldb, instance_id, username, password)
             users += 1
         except LdbError as e:
-            (status, _) = e
+            (status, _) = e.args
             # Stop if entry exists
             if status == 68:
                 break
@@ -1752,7 +1752,7 @@ def generate_groups(ldb, instance_id, number):
             create_group(ldb, instance_id, name)
             groups += 1
         except LdbError as e:
-            (status, _) = e
+            (status, _) = e.args
             # Stop if entry exists
             if status == 68:
                 break
@@ -1767,7 +1767,7 @@ def clean_up_accounts(ldb, instance_id):
     try:
         ldb.delete(ou, ["tree_delete:1"])
     except LdbError as e:
-        (status, _) = e
+        (status, _) = e.args
         # ignore does not exist
         if status != 32:
             raise
diff --git a/python/samba/gp_sec_ext.py b/python/samba/gp_sec_ext.py
index 11fd1f5..6d245c4 100644
--- a/python/samba/gp_sec_ext.py
+++ b/python/samba/gp_sec_ext.py
@@ -57,14 +57,14 @@ class inf_to_ldb(gp_ext_setter):
         old_val = self.ldb.get_minPwdAge()
         self.logger.info('KDC Minimum Password age was changed from %s to %s' \
                          % (old_val, val))
-        self.gp_db.store(str(self), self.attribute, old_val)
+        self.gp_db.store(str(self), self.attribute, str(old_val))
         self.ldb.set_minPwdAge(val)
 
     def ch_maxPwdAge(self, val):
         old_val = self.ldb.get_maxPwdAge()
         self.logger.info('KDC Maximum Password age was changed from %s to %s' \
                          % (old_val, val))
-        self.gp_db.store(str(self), self.attribute, old_val)
+        self.gp_db.store(str(self), self.attribute, str(old_val))
         self.ldb.set_maxPwdAge(val)
 
     def ch_minPwdLength(self, val):
@@ -72,14 +72,14 @@ class inf_to_ldb(gp_ext_setter):
         self.logger.info(
             'KDC Minimum Password length was changed from %s to %s' \
              % (old_val, val))
-        self.gp_db.store(str(self), self.attribute, old_val)
+        self.gp_db.store(str(self), self.attribute, str(old_val))
         self.ldb.set_minPwdLength(val)
 
     def ch_pwdProperties(self, val):
         old_val = self.ldb.get_pwdProperties()
         self.logger.info('KDC Password Properties were changed from %s to %s' \
                          % (old_val, val))
-        self.gp_db.store(str(self), self.attribute, old_val)
+        self.gp_db.store(str(self), self.attribute, str(old_val))
         self.ldb.set_pwdProperties(val)
 
     def days2rel_nttime(self):
diff --git a/python/samba/kcc/__init__.py b/python/samba/kcc/__init__.py
index 1b22bf7..eace661 100644
--- a/python/samba/kcc/__init__.py
+++ b/python/samba/kcc/__init__.py
@@ -44,6 +44,7 @@ from samba.kcc.graph import Vertex
 
 from samba.kcc.debug import DEBUG, DEBUG_FN, logger
 from samba.kcc import debug
+from samba.compat import text_type
 
 
 def sort_dsa_by_gc_and_guid(dsa1, dsa2):
@@ -2586,7 +2587,8 @@ class KCC(object):
                 dot_colours = []
                 for link in self.sitelink_table.values():
                     from hashlib import md5
-                    colour = '#' + md5(link.dnstr).hexdigest()[:6]
+                    tmp_str = link.dnstr.encode('utf8')
+                    colour = '#' + md5(tmp_str).hexdigest()[:6]
                     for a, b in itertools.combinations(link.site_list, 2):
                         dot_edges.append((a[1], b[1]))
                         dot_colours.append(colour)
diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py
index 8624907..555462c 100644
--- a/python/samba/netcmd/domain.py
+++ b/python/samba/netcmd/domain.py
@@ -821,7 +821,10 @@ class cmd_domain_demote(Command):
                             controls=["search_options:1:2"])
 
         if len(res) != 0:
-            raise CommandError("Current DC is still the owner of %d role(s), use the role command to transfer roles to another DC" % len(res))
+            raise CommandError("Current DC is still the owner of %d role(s), "
+                               "use the role command to transfer roles to "
+                               "another DC" %
+                               len(res))
 
         self.errf.write("Using %s as partner server for the demotion\n" %
                         server)
@@ -1012,9 +1015,13 @@ class cmd_domain_demote(Command):
             remote_samdb.modify(msg)
             remote_samdb.rename(newdn, dc_dn)
             if werr == werror.WERR_DS_DRA_NO_REPLICA:
-                raise CommandError("The DC %s is not present on (already removed from) the remote server: " % server_dsa_dn, e)
+                raise CommandError("The DC %s is not present on (already "
+                                   "removed from) the remote server: %s" %
+                                   (server_dsa_dn, e3))
             else:
-                raise CommandError("Error while sending a removeDsServer of %s: " % server_dsa_dn, e)
+                raise CommandError("Error while sending a removeDsServer "
+                                   "of %s: %s" %
+                                   (server_dsa_dn, e3))
 
         remove_dc.remove_sysvol_references(remote_samdb, logger, dc_name)
 
@@ -1524,7 +1531,7 @@ class cmd_domain_passwordsettings_set(Command):
               ldb.FLAG_MOD_REPLACE, "lockOutObservationWindow")
             msgs.append("Duration to reset account lockout after changed!")
 
-        if max_pwd_age > 0 and min_pwd_age >= max_pwd_age:
+        if max_pwd_age and max_pwd_age > 0 and min_pwd_age >= max_pwd_age:
             raise CommandError("Maximum password age (%d) must be greater than minimum password age (%d)!" % (max_pwd_age, min_pwd_age))
 
         if len(m) == 0:
@@ -1715,7 +1722,7 @@ class DomainTrustCommand(Command):
         if runtime is None:
             return False
 
-        err32 = self._uint32(runtime[0])
+        err32 = self._uint32(runtime.args[0])
         if err32 == val:
             return True
 
@@ -1723,24 +1730,24 @@ class DomainTrustCommand(Command):
 
     class LocalRuntimeError(CommandError):
         def __init__(exception_self, self, runtime, message):
-            err32 = self._uint32(runtime[0])
-            errstr = runtime[1]
+            err32 = self._uint32(runtime.args[0])
+            errstr = runtime.args[1]
             msg = "LOCAL_DC[%s]: %s - ERROR(0x%08X) - %s" % (
                   self.local_server, message, err32, errstr)
             CommandError.__init__(exception_self, msg)
 
     class RemoteRuntimeError(CommandError):
         def __init__(exception_self, self, runtime, message):
-            err32 = self._uint32(runtime[0])
-            errstr = runtime[1]
+            err32 = self._uint32(runtime.args[0])
+            errstr = runtime.args[1]
             msg = "REMOTE_DC[%s]: %s - ERROR(0x%08X) - %s" % (
                   self.remote_server, message, err32, errstr)
             CommandError.__init__(exception_self, msg)
 
     class LocalLdbError(CommandError):
         def __init__(exception_self, self, ldb_error, message):
-            errval = ldb_error[0]
-            errstr = ldb_error[1]
+            errval = ldb_error.args[0]
+            errstr = ldb_error.args[1]
             msg = "LOCAL_DC[%s]: %s - ERROR(%d) - %s" % (
                   self.local_server, message, errval, errstr)
             CommandError.__init__(exception_self, msg)
diff --git a/python/samba/netcmd/drs.py b/python/samba/netcmd/drs.py
index b8793b7..6fb8c57 100644
--- a/python/samba/netcmd/drs.py
+++ b/python/samba/netcmd/drs.py
@@ -21,7 +21,7 @@
 import samba.getopt as options
 import ldb
 import logging
-import common
+from . import common
 import json
 
 from samba.auth import system_session
diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py
index f211b51..2131c68 100644
--- a/python/samba/netcmd/user.py
+++ b/python/samba/netcmd/user.py
@@ -119,7 +119,7 @@ def get_crypt_value(alg, utf8pw, rounds=0):
     # we can ignore the possible == at the end
     # of the base64 string
     # we just need to replace '+' by '.'
-    b64salt = base64.b64encode(salt)[0:16].replace('+', '.').decode('utf8')
+    b64salt = base64.b64encode(salt)[0:16].replace(b'+', b'.').decode('utf8')
     crypt_salt = ""
     if rounds != 0:
         crypt_salt = "$%s$rounds=%s$%s$" % (alg, rounds, b64salt)
diff --git a/python/samba/samdb.py b/python/samba/samdb.py
index 7184fcf..e0c29d8 100644
--- a/python/samba/samdb.py
+++ b/python/samba/samdb.py
@@ -917,6 +917,7 @@ schemaUpdateNow: 1
         return dn
 
     def set_minPwdAge(self, value):
+        value = str(value).encode('utf8')
         m = ldb.Message()
         m.dn = ldb.Dn(self, self.domain_dn())
         m["minPwdAge"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "minPwdAge")
@@ -929,9 +930,10 @@ schemaUpdateNow: 1
         elif not "minPwdAge" in res[0]:
             return None
         else:
-            return res[0]["minPwdAge"][0]
+            return int(res[0]["minPwdAge"][0])
 
     def set_maxPwdAge(self, value):
+        value = str(value).encode('utf8')
         m = ldb.Message()
         m.dn = ldb.Dn(self, self.domain_dn())
         m["maxPwdAge"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "maxPwdAge")
@@ -945,11 +947,12 @@ schemaUpdateNow: 1
         elif not "maxPwdAge" in res[0]:
             return None
         else:
-            return res[0]["maxPwdAge"][0]
+            return int(res[0]["maxPwdAge"][0])
 
 
 
     def set_minPwdLength(self, value):
+        value = str(value).encode('utf8')
         m = ldb.Message()
         m.dn = ldb.Dn(self, self.domain_dn())
         m["minPwdLength"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "minPwdLength")
@@ -962,9 +965,10 @@ schemaUpdateNow: 1
         elif not "minPwdLength" in res[0]:
             return None
         else:
-            return res[0]["minPwdLength"][0]
+            return int(res[0]["minPwdLength"][0])
 
     def set_pwdProperties(self, value):
+        value = str(value).encode('utf8')
         m = ldb.Message()
         m.dn = ldb.Dn(self, self.domain_dn())
         m["pwdProperties"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "pwdProperties")
@@ -977,7 +981,7 @@ schemaUpdateNow: 1
         elif not "pwdProperties" in res[0]:
             return None
         else:
-            return res[0]["pwdProperties"][0]
+            return int(res[0]["pwdProperties"][0])
 
     def set_dsheuristics(self, dsheuristics):
         m = ldb.Message()
diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py
index 7061f8b..1d50710 100644
--- a/python/samba/tests/__init__.py
+++ b/python/samba/tests/__init__.py
@@ -36,13 +36,12 @@ import re
 import samba.auth
 import samba.dcerpc.base
 from samba.compat import PY3, text_type
+from samba.compat import string_types
 from random import randint
-if not PY3:
-    # Py2 only
-    from samba.samdb import SamDB
-    import samba.ndr
-    import samba.dcerpc.dcerpc
-    import samba.dcerpc.epmapper
+from samba.samdb import SamDB
+import samba.ndr
+import samba.dcerpc.dcerpc
+import samba.dcerpc.epmapper
 
 try:
     from unittest import SkipTest
@@ -50,7 +49,7 @@ except ImportError:
     class SkipTest(Exception):
         """Test skipped."""
 
-HEXDUMP_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
+HEXDUMP_FILTER=bytearray([x if ((len(repr(chr(x)))==3) and (x < 127)) else ord('.') for x in range(256)])
 
 class TestCase(unittest.TestCase):
     """A Samba test case."""
@@ -80,14 +79,21 @@ class TestCase(unittest.TestCase):
     def hexdump(self, src):
         N = 0
         result = ''
+        is_string = isinstance(src, string_types)
         while src:
             ll = src[:8]
             lr = src[8:16]
             src = src[16:]
-            hl = ' '.join(["%02X" % ord(x) for x in ll])


-- 
Samba Shared Repository



More information about the samba-cvs mailing list