[SCM] Samba Shared Repository - branch v4-9-test updated

Karolin Seeger kseeger at samba.org
Mon Jan 21 11:56:02 UTC 2019


The branch, v4-9-test has been updated
       via  76bcdecae23 ldb: Bump ldb version to 1.4.4
       via  8738db2afad lib/ldb: Use new PYARG_ES format for parseTuple
       via  869ae9a17b2 lib/ldb/tests/python: Add test to pass utf8 encoded bytes to ldb.Dn
       via  043e6e8b7d4 s4/libnet: use 'et' as format for ParseTuple with python2
       via  d253c470ae4 python: Add new compat PYARG_STR_UNI format
       via  38c459223d2 s3: lib: nmbname: Ensure we limit the NetBIOS name correctly. CID: 1433607
      from  0a3a26179f8 s3: net: Do not set NET_FLAGS_ANONYMOUS with -k

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-9-test


- Log -----------------------------------------------------------------
commit 76bcdecae236277f1510601aa35c207850c4e91e
Author: Noel Power <noel.power at suse.com>
Date:   Mon Jan 14 10:38:10 2019 +0000

    ldb: Bump ldb version to 1.4.4
    
    Python: Ensure ldb.Dn can doesn't rencoded str with py2 (bug 13616)
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    
    Autobuild-User(v4-9-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-9-test): Mon Jan 21 12:55:04 CET 2019 on sn-devel-144

commit 8738db2afadc449db26a79ccb6a6112fdbcac005
Author: Noel Power <noel.power at suse.com>
Date:   Mon Nov 12 16:06:10 2018 +0000

    lib/ldb: Use new PYARG_ES format for parseTuple
    
    While 'es' format works great for unicode (in python2) and
    str (in python3) The behaviour with str (in python2) is unexpected.
    In python2 the str type is (re-encoded) with the specified encoding.
    In python2 the 'et' type would be a better match, that ensures 'str'
    type is treated like it was with 's' (no reencoding) and unicode is
    encoded with the specified encoding. However in python3 'et' allows
    byte (or bytearray) params to be accepted (with no reencoding), we
    don't want this. This patch adds a new PYARG_STR_UNI format code which
    is a hybrid, in python2 it evaluates to 'et' and in python3 'es' and
    so gives the desired behaviour for each python version.
    
    Additionally remove the associated known fail.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    
    Autobuild-User(master): Douglas Bagnall <dbagnall at samba.org>
    Autobuild-Date(master): Sun Jan 13 03:53:00 CET 2019 on sn-devel-144
    
    (cherry picked from commit 8900e0b4cb05613df9cbeeb8b8253273b06b3c17)

commit 869ae9a17b2fb502714d68c73e95bd066d290a3d
Author: Noel Power <noel.power at suse.com>
Date:   Thu Jan 17 10:05:04 2019 +0000

    lib/ldb/tests/python: Add test to pass utf8 encoded bytes to ldb.Dn
    
    This test should demonstrate an error with the 'es' format in python
    where a 'str' byte-string is passed (containing utf8 encoded bytes)
    with some characters that cannot be decoded as ascii. The same
    code if run in python3 should generate an error (needs string not
    bytes)
    
    Also Add knownfail for ldb.Dn passed utf8 encoded byte string
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    (cherry picked from commit f8758b3b1f98476469501dd45a7c898950294e05)

commit 043e6e8b7d4a87253b01e0c37e4a17d358cc7b1e
Author: Noel Power <noel.power at suse.com>
Date:   Tue Dec 11 15:58:44 2018 +0000

    s4/libnet: use 'et' as format for ParseTuple with python2
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    (cherry picked from commit b6c8ef5fb70c65c04c8269ff95e661e219968767)

commit d253c470ae410436a5fbde817cb66cea92c1243c
Author: Noel Power <noel.power at suse.com>
Date:   Tue Dec 11 15:18:10 2018 +0000

    python: Add new compat PYARG_STR_UNI format
    
    In python2 PYARG_STR_UNI evaluates to et which allows str type
    (e.g bytes) pass through unencoded and accepts unicode objects
    encoded as utf8
    In python3 PYARG_STR_UNI evaluates to es which allows str type
    encoded as named/specified encoding
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    (cherry picked from commit 253af8b85450c2830a442084e98734ca338c1b2f)

commit 38c459223d217bf8be6858bfc7066c9c9d3adbdd
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Nov 12 11:37:31 2018 -0800

    s3: lib: nmbname: Ensure we limit the NetBIOS name correctly. CID: 1433607
    
    Firstly, make the exit condition from the loop explicit (we must
    never write into byte n, where n >= sizeof(name->name).
    
    Secondly ensure exiting from the loop that n==MAX_NETBIOSNAME_LEN,
    as this is the sign of a correct NetBIOS name encoding (RFC1002)
    in order to properly read the NetBIOS name type (which is always
    encoded in byte 16 == name->name[15]).
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=11495
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    
    Autobuild-User(master): David Disseldorp <ddiss at samba.org>
    Autobuild-Date(master): Tue Nov 13 20:54:56 CET 2018 on sn-devel-144
    
    (cherry picked from commit 3634e20c7603103b0f2e00e5b61cc63f905d780d)

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

Summary of changes:
 lib/ldb/ABI/{ldb-1.3.0.sigs => ldb-1.4.4.sigs}     |  0
 ...yldb-util-1.1.10.sigs => pyldb-util-1.4.4.sigs} |  0
 ...-util-1.1.10.sigs => pyldb-util.py3-1.4.4.sigs} |  0
 lib/ldb/pyldb.c                                    |  7 ++++-
 lib/ldb/tests/python/api.py                        | 15 ++++++++++
 lib/ldb/wscript                                    |  2 +-
 python/py3compat.h                                 | 10 +++++++
 source3/libsmb/nmblib.c                            | 34 +++++++++++++---------
 source4/libnet/py_net.c                            |  3 +-
 9 files changed, 55 insertions(+), 16 deletions(-)
 copy lib/ldb/ABI/{ldb-1.3.0.sigs => ldb-1.4.4.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util-1.4.4.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util.py3-1.4.4.sigs} (100%)


Changeset truncated at 500 lines:

diff --git a/lib/ldb/ABI/ldb-1.3.0.sigs b/lib/ldb/ABI/ldb-1.4.4.sigs
similarity index 100%
copy from lib/ldb/ABI/ldb-1.3.0.sigs
copy to lib/ldb/ABI/ldb-1.4.4.sigs
diff --git a/lib/ldb/ABI/pyldb-util-1.1.10.sigs b/lib/ldb/ABI/pyldb-util-1.4.4.sigs
similarity index 100%
copy from lib/ldb/ABI/pyldb-util-1.1.10.sigs
copy to lib/ldb/ABI/pyldb-util-1.4.4.sigs
diff --git a/lib/ldb/ABI/pyldb-util-1.1.10.sigs b/lib/ldb/ABI/pyldb-util.py3-1.4.4.sigs
similarity index 100%
copy from lib/ldb/ABI/pyldb-util-1.1.10.sigs
copy to lib/ldb/ABI/pyldb-util.py3-1.4.4.sigs
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index a6290d9db09..e84cbbb184f 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -89,6 +89,9 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 #define PyStr_AsUTF8 PyUnicode_AsUTF8
 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
 #define PyInt_FromLong PyLong_FromLong
+
+#define PYARG_STR_UNI "es"
+
 #else
 #define PyStr_Check PyString_Check
 #define PyStr_FromString PyString_FromString
@@ -97,6 +100,8 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 #define PyStr_FromFormatV PyString_FromFormatV
 #define PyStr_AsUTF8 PyString_AsString
 
+#define PYARG_STR_UNI "et"
+
 const char *PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr);
 const char *
 PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr)
@@ -865,7 +870,7 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa
 	PyLdbDnObject *py_ret = NULL;
 	const char * const kwnames[] = { "ldb", "dn", NULL };
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oes",
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O"PYARG_STR_UNI,
 					 discard_const_p(char *, kwnames),
 					 &py_ldb, "utf8", &str))
 		goto out;
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
index 0a883961c00..7f530724ed1 100755
--- a/lib/ldb/tests/python/api.py
+++ b/lib/ldb/tests/python/api.py
@@ -141,6 +141,21 @@ class SimpleLdb(LdbBaseTest):
         l = ldb.Ldb(self.url(), flags=self.flags())
         dn = ldb.Dn(l, (b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc').decode('utf8'))
 
+    def test_utf8_encoded_ldb_Dn(self):
+        l = ldb.Ldb(self.url(), flags=self.flags())
+        dn_encoded_utf8 = b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc'
+        try:
+            dn = ldb.Dn(l, dn_encoded_utf8)
+        except UnicodeDecodeError as e:
+                raise
+        except TypeError as te:
+            if PY3:
+               p3errors = ["argument 2 must be str, not bytes",
+                           "Can't convert 'bytes' object to str implicitly"]
+               self.assertIn(str(te), p3errors)
+            else:
+               raise
+
     def test_search_attrs(self):
         l = ldb.Ldb(self.url(), flags=self.flags())
         self.assertEqual(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0)
diff --git a/lib/ldb/wscript b/lib/ldb/wscript
index f6c34b21d89..028a213cce9 100644
--- a/lib/ldb/wscript
+++ b/lib/ldb/wscript
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 APPNAME = 'ldb'
-VERSION = '1.4.3'
+VERSION = '1.4.4'
 
 blddir = 'bin'
 
diff --git a/python/py3compat.h b/python/py3compat.h
index 5fa57f323d5..89b7552c791 100644
--- a/python/py3compat.h
+++ b/python/py3compat.h
@@ -118,6 +118,7 @@
 /* PyArg_ParseTuple/Py_BuildValue argument */
 
 #define PYARG_BYTES_LEN "y#"
+#define PYARG_STR_UNI "es"
 
 #else
 
@@ -179,6 +180,15 @@
 /* PyArg_ParseTuple/Py_BuildValue argument */
 
 #define PYARG_BYTES_LEN "s#"
+/*
+ * We want a format that will ensure unicode is encoded using the
+ * specified encoding 'utf8' (to obtain the char* array)
+ * In python3 we use "es" but in python2 the specifiying 'es' will
+ * result in the any incomming 'str' type being decoded first to ascii
+ * then encoded to the specified 'utf8' encoding. In order to avoid that
+ * we use format 'et' in python2 instead.
+ */
+#define PYARG_STR_UNI "et"
 
 /* Module init */
 
diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index ef6177e5209..727939575a7 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -207,25 +207,33 @@ static int parse_nmb_name(char *inbuf,int ofs,int length, struct nmb_name *name)
 		unsigned char c1,c2;
 		c1 = ubuf[offset++]-'A';
 		c2 = ubuf[offset++]-'A';
-		if ((c1 & 0xF0) || (c2 & 0xF0) || (n > sizeof(name->name)-1))
+		if ((c1 & 0xF0) || (c2 & 0xF0)) {
 			return(0);
+		}
+		if (n >= sizeof(name->name)) {
+			return 0;
+		}
 		name->name[n++] = (c1<<4) | c2;
 		m -= 2;
 	}
-	name->name[n] = 0;
-
-	if (n==MAX_NETBIOSNAME_LEN) {
-		/* parse out the name type, its always
-		 * in the 16th byte of the name */
-		name->name_type = ((unsigned char)name->name[15]) & 0xff;
-
-		/* remove trailing spaces */
-		name->name[15] = 0;
-		n = 14;
-		while (n && name->name[n]==' ')
-			name->name[n--] = 0;
+	/*
+	 * RFC1002: For a valid NetBIOS name, exiting from the above,
+	 * n *must* be MAX_NETBIOSNAME_LEN (16).
+	 */
+	if (n != MAX_NETBIOSNAME_LEN) {
+		return 0;
 	}
 
+	/* parse out the name type, its always
+	 * in the 16th byte of the name */
+	name->name_type = ((unsigned char)name->name[15]) & 0xff;
+
+	/* remove trailing spaces */
+	name->name[15] = 0;
+	n = 14;
+	while (n && name->name[n]==' ')
+		name->name[n--] = 0;
+
 	/* now the domain parts (if any) */
 	n = 0;
 	while (ubuf[offset]) {
diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c
index 65060d53091..b50f7abfb96 100644
--- a/source4/libnet/py_net.c
+++ b/source4/libnet/py_net.c
@@ -161,7 +161,8 @@ static PyObject *py_net_change_password(py_net_Object *self, PyObject *args, PyO
 	const char *newpass = NULL;
 	const char *oldpass = NULL;
 	ZERO_STRUCT(r);
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "es|esss:change_password",
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, PYARG_STR_UNI
+					 "|"PYARG_STR_UNI"ss:change_password",
 					 discard_const_p(char *, kwnames),
 					 "utf8",
 					 &newpass,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list