From 9c069faebf7febab64f8dd233a8d335f595448e3 Mon Sep 17 00:00:00 2001 From: David Mulder Date: Tue, 13 Feb 2018 08:35:12 -0700 Subject: [PATCH 01/41] python: Write py3 bin to correct args location Comands written like this were working: python /home/dmulder/code/samba/source4/scripting/bin/subunitrun Changed to: /usr/bin/python3 /home/dmulder/code/samba/source4/scripting/bin/subunitrun But commands with env args overwrite the wrong arg: CLIENT_IP=127.0.0.11 SOCKET_WRAPPER_DEFAULT_IFACE=11 python /home/dmulder/code/samba/source4/scripting/bin/subunitrun Changed to: /usr/bin/python3 SOCKET_WRAPPER_DEFAULT_IFACE=11 python /home/dmulder/code/samba/source4/scripting/bin/subunitrun And were further mangled in plantestsuite_loadlist() to: /usr/bin/python3 /home/dmulder/code/samba/source4/scripting/bin/subunitrun SOCKET_WRAPPER_DEFAULT_IFACE=11 python /home/dmulder/code/samba/source4/scripting/bin/subunitrun Signed-off-by: David Mulder --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 660a75fb927..0f32c6deed1 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -570,7 +570,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex name = module plantestsuite_loadlist(name, env, args) if py3_compatible and extra_python is not None: - args[0] = subunitrun3 + args[args.index(subunitrun)] = subunitrun3 plantestsuite_loadlist(name, env, args) From 48cfdff5337a202783f6ea9c61f65f114e4eac61 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:04:53 +0000 Subject: [PATCH 02/41] python3 port for policy module Signed-off-by: Noel Power --- source4/lib/policy/pypolicy.c | 22 ++++++++++++++++------ source4/lib/policy/wscript_build | 11 ++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/source4/lib/policy/pypolicy.c b/source4/lib/policy/pypolicy.c index 8a9aa47f1fd..dd44c0fcf16 100644 --- a/source4/lib/policy/pypolicy.c +++ b/source4/lib/policy/pypolicy.c @@ -19,6 +19,7 @@ #include #include "includes.h" +#include "python/py3compat.h" #include "policy.h" #include "libcli/util/pyerrors.h" @@ -51,7 +52,7 @@ static PyObject *py_get_gpo_flags(PyObject *self, PyObject *args) py_ret = PyList_New(0); for (i = 0; ret[i]; i++) { - PyObject *item = PyString_FromString(ret[i]); + PyObject *item = PyStr_FromString(ret[i]); if (item == NULL) { talloc_free(mem_ctx); Py_DECREF(py_ret); @@ -93,7 +94,7 @@ static PyObject *py_get_gplink_options(PyObject *self, PyObject *args) py_ret = PyList_New(0); for (i = 0; ret[i]; i++) { - PyObject *item = PyString_FromString(ret[i]); + PyObject *item = PyStr_FromString(ret[i]); if (item == NULL) { talloc_free(mem_ctx); Py_DECREF(py_ret); @@ -131,13 +132,21 @@ static PyMethodDef py_policy_methods[] = { { NULL } }; -void initpolicy(void) +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "policy", + .m_doc = "(Group) Policy manipulation", + .m_size = -1, + .m_methods = py_policy_methods, +}; + +MODULE_INIT_FUNC(policy) { - PyObject *m; + PyObject *m = NULL; - m = Py_InitModule3("policy", py_policy_methods, "(Group) Policy manipulation"); + m = PyModule_Create(&moduledef); if (!m) - return; + return m; PyModule_AddObject(m, "GPO_FLAG_USER_DISABLE", PyInt_FromLong(GPO_FLAG_USER_DISABLE)); @@ -147,4 +156,5 @@ void initpolicy(void) PyInt_FromLong(GPLINK_OPT_DISABLE )); PyModule_AddObject(m, "GPLINK_OPT_ENFORCE ", PyInt_FromLong(GPLINK_OPT_ENFORCE )); + return m; } diff --git a/source4/lib/policy/wscript_build b/source4/lib/policy/wscript_build index f7c59090b84..832d0f45cf6 100644 --- a/source4/lib/policy/wscript_build +++ b/source4/lib/policy/wscript_build @@ -10,8 +10,9 @@ bld.SAMBA_LIBRARY('samba-policy', enabled=bld.PYTHON_BUILD_IS_ENABLED() ) -bld.SAMBA_PYTHON('py_policy', - source='pypolicy.c', - public_deps='samba-policy pytalloc-util', - realname='samba/policy.so' - ) +for env in bld.gen_python_environments(): + bld.SAMBA_PYTHON('py_policy', + source='pypolicy.c', + public_deps='samba-policy pytalloc-util', + realname='samba/policy.so' + ) From dcb7c1155727de030c03dec137374d979ca0a94a Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 8 Mar 2018 11:28:16 +0000 Subject: [PATCH 03/41] samba test python: enable samba.tests.policy for py3 Signed-off-by: Noel Power --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index ccd184f60e1..c18cfbc9f79 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -144,7 +144,7 @@ planpythontestsuite("none", "samba.tests.upgradeprovision") planpythontestsuite("none", "samba.tests.xattr", py3_compatible=True) planpythontestsuite("none", "samba.tests.ntacls") -planpythontestsuite("none", "samba.tests.policy") +planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph") planpythontestsuite("none", "samba.tests.kcc.graph_utils") planpythontestsuite("none", "samba.tests.kcc.ldif_import_export") From 1850f84bc3686124d34cedeee1b0adc7ceccea66 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 21 Mar 2018 18:24:18 +0000 Subject: [PATCH 04/41] python selftest: split samba3 test into separate tests This patch splits the tests contained in samba3.py into separate tests s3idmapdb.py, s3param.py, s3passdb.py, s3registry.py, s3windb.py This allows test of associated python c-modules to be done independently. Signed-off-by: Noel Power --- python/samba/tests/s3idmapdb.py | 57 ++++++++++++++++++ python/samba/tests/s3param.py | 51 ++++++++++++++++ python/samba/tests/{samba3.py => s3passdb.py} | 84 +-------------------------- python/samba/tests/s3registry.py | 54 +++++++++++++++++ python/samba/tests/s3windb.py | 45 ++++++++++++++ selftest/tests.py | 6 +- 6 files changed, 213 insertions(+), 84 deletions(-) create mode 100644 python/samba/tests/s3idmapdb.py create mode 100644 python/samba/tests/s3param.py rename python/samba/tests/{samba3.py => s3passdb.py} (69%) create mode 100644 python/samba/tests/s3registry.py create mode 100644 python/samba/tests/s3windb.py diff --git a/python/samba/tests/s3idmapdb.py b/python/samba/tests/s3idmapdb.py new file mode 100644 index 00000000000..aa278404111 --- /dev/null +++ b/python/samba/tests/s3idmapdb.py @@ -0,0 +1,57 @@ +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2007 +# +# 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 . +# + +"""Tests for samba.samba3.""" + +from samba.samba3 import IdmapDatabase +from samba.tests import TestCase, TestCaseInTempDir +from samba.dcerpc.security import dom_sid +import os + +for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]: + DATADIR = os.path.join(os.path.dirname(__file__), p) + if os.path.exists(DATADIR): + break + +class IdmapDbTestCase(TestCase): + + def setUp(self): + super(IdmapDbTestCase, self).setUp() + self.idmapdb = IdmapDatabase(os.path.join(DATADIR, + "winbindd_idmap")) + + def test_user_hwm(self): + self.assertEquals(10000, self.idmapdb.get_user_hwm()) + + def test_group_hwm(self): + self.assertEquals(10002, self.idmapdb.get_group_hwm()) + + def test_uids(self): + self.assertEquals(1, len(list(self.idmapdb.uids()))) + + def test_gids(self): + self.assertEquals(3, len(list(self.idmapdb.gids()))) + + def test_get_user_sid(self): + self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534)) + + def test_get_group_sid(self): + self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001)) + + def tearDown(self): + self.idmapdb.close() + super(IdmapDbTestCase, self).tearDown() diff --git a/python/samba/tests/s3param.py b/python/samba/tests/s3param.py new file mode 100644 index 00000000000..7c70d335ed8 --- /dev/null +++ b/python/samba/tests/s3param.py @@ -0,0 +1,51 @@ +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2007 +# +# 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 . +# + +"""Tests for samba.samba3.param""" + +from samba.samba3 import param as s3param +from samba.tests import TestCase, TestCaseInTempDir +import os + + +for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]: + DATADIR = os.path.join(os.path.dirname(__file__), p) + if os.path.exists(DATADIR): + break + + +class ParamTestCase(TestCaseInTempDir): + + def setUp(self): + super(ParamTestCase, self).setUp() + os.system("cp -r %s %s" % (DATADIR, self.tempdir)) + datadir = os.path.join(self.tempdir, "samba3") + + self.lp = s3param.get_context() + self.lp.load(os.path.join(datadir, "smb.conf")) + + def tearDown(self): + self.lp = [] + os.system("rm -rf %s" % os.path.join(self.tempdir, "samba3")) + super(ParamTestCase, self).tearDown() + + def test_param(self): + self.assertEquals("BEDWYR", self.lp.get("netbios name")) + self.assertEquals("SAMBA", self.lp.get("workgroup")) + self.assertEquals("USER", self.lp.get("security")) + self.assertEquals("/mnt/cd1", self.lp.get("path", "cd1")) + diff --git a/python/samba/tests/samba3.py b/python/samba/tests/s3passdb.py similarity index 69% rename from python/samba/tests/samba3.py rename to python/samba/tests/s3passdb.py index 126e133f4c1..2f6bc74e869 100644 --- a/python/samba/tests/samba3.py +++ b/python/samba/tests/s3passdb.py @@ -15,13 +15,8 @@ # along with this program. If not, see . # -"""Tests for samba.samba3.""" +"""Tests for samba.s3passdb""" -from samba.samba3 import ( - Registry, - WinsDatabase, - IdmapDatabase, - ) from samba.samba3 import passdb from samba.samba3 import param as s3param from samba.tests import TestCase, TestCaseInTempDir @@ -35,31 +30,6 @@ break -class RegistryTestCase(TestCase): - - def setUp(self): - super(RegistryTestCase, self).setUp() - self.registry = Registry(os.path.join(DATADIR, "registry")) - - def tearDown(self): - self.registry.close() - super(RegistryTestCase, self).tearDown() - - def test_length(self): - self.assertEquals(28, len(self.registry)) - - def test_keys(self): - self.assertTrue("HKLM" in self.registry.keys()) - - def test_subkeys(self): - self.assertEquals(["SOFTWARE", "SYSTEM"], self.registry.subkeys("HKLM")) - - def test_values(self): - self.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'), - 'ErrorControl': (4L, '\x01\x00\x00\x00')}, - self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG")) - - class PassdbTestCase(TestCaseInTempDir): def setUp(self): @@ -82,11 +52,6 @@ def tearDown(self): os.system("rm -rf %s" % os.path.join(self.tempdir, "samba3")) super(PassdbTestCase, self).tearDown() - def test_param(self): - self.assertEquals("BEDWYR", self.lp.get("netbios name")) - self.assertEquals("SAMBA", self.lp.get("workgroup")) - self.assertEquals("USER", self.lp.get("security")) - def test_policy(self): policy = self.pdb.get_account_policy() self.assertEquals(0, policy['bad lockout attempt']) @@ -171,50 +136,3 @@ def test_alias_length(self): aliaslist = self.pdb.search_aliases() self.assertEquals(1, len(aliaslist)) self.assertEquals("Jelmers NT Group", aliaslist[0]['account_name']) - - -class WinsDatabaseTestCase(TestCase): - - def setUp(self): - super(WinsDatabaseTestCase, self).setUp() - self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat")) - - def test_length(self): - self.assertEquals(22, len(self.winsdb)) - - def test_first_entry(self): - self.assertEqual((1124185120, ["192.168.1.5"], 0x64), self.winsdb["ADMINISTRATOR#03"]) - - def tearDown(self): - self.winsdb.close() - super(WinsDatabaseTestCase, self).tearDown() - - -class IdmapDbTestCase(TestCase): - - def setUp(self): - super(IdmapDbTestCase, self).setUp() - self.idmapdb = IdmapDatabase(os.path.join(DATADIR, - "winbindd_idmap")) - - def test_user_hwm(self): - self.assertEquals(10000, self.idmapdb.get_user_hwm()) - - def test_group_hwm(self): - self.assertEquals(10002, self.idmapdb.get_group_hwm()) - - def test_uids(self): - self.assertEquals(1, len(list(self.idmapdb.uids()))) - - def test_gids(self): - self.assertEquals(3, len(list(self.idmapdb.gids()))) - - def test_get_user_sid(self): - self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534)) - - def test_get_group_sid(self): - self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001)) - - def tearDown(self): - self.idmapdb.close() - super(IdmapDbTestCase, self).tearDown() diff --git a/python/samba/tests/s3registry.py b/python/samba/tests/s3registry.py new file mode 100644 index 00000000000..43be412d51c --- /dev/null +++ b/python/samba/tests/s3registry.py @@ -0,0 +1,54 @@ +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2007 +# +# 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 . +# + +"""Tests for samba.samba3.""" + +from samba.samba3 import Registry +from samba.tests import TestCase, TestCaseInTempDir +from samba.dcerpc.security import dom_sid +import os + + +for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]: + DATADIR = os.path.join(os.path.dirname(__file__), p) + if os.path.exists(DATADIR): + break + + +class RegistryTestCase(TestCase): + + def setUp(self): + super(RegistryTestCase, self).setUp() + self.registry = Registry(os.path.join(DATADIR, "registry")) + + def tearDown(self): + self.registry.close() + super(RegistryTestCase, self).tearDown() + + def test_length(self): + self.assertEquals(28, len(self.registry)) + + def test_keys(self): + self.assertTrue("HKLM" in self.registry.keys()) + + def test_subkeys(self): + self.assertEquals(["SOFTWARE", "SYSTEM"], self.registry.subkeys("HKLM")) + + def test_values(self): + self.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'), + 'ErrorControl': (4L, '\x01\x00\x00\x00')}, + self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG")) diff --git a/python/samba/tests/s3windb.py b/python/samba/tests/s3windb.py new file mode 100644 index 00000000000..6fc5b09bf76 --- /dev/null +++ b/python/samba/tests/s3windb.py @@ -0,0 +1,45 @@ +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2007 +# +# 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 . +# + +"""Tests for samba.samba3.""" + +from samba.samba3 import WinsDatabase +from samba.tests import TestCase, TestCaseInTempDir +import os + + +for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]: + DATADIR = os.path.join(os.path.dirname(__file__), p) + if os.path.exists(DATADIR): + break + + +class WinsDatabaseTestCase(TestCase): + + def setUp(self): + super(WinsDatabaseTestCase, self).setUp() + self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat")) + + def test_length(self): + self.assertEquals(22, len(self.winsdb)) + + def test_first_entry(self): + self.assertEqual((1124185120, ["192.168.1.5"], 0x64), self.winsdb["ADMINISTRATOR#03"]) + + def tearDown(self): + self.winsdb.close() + super(WinsDatabaseTestCase, self).tearDown() diff --git a/selftest/tests.py b/selftest/tests.py index c18cfbc9f79..027a80e03f1 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -67,7 +67,6 @@ planpythontestsuite("none", "samba.tests.common") planpythontestsuite("none", "samba.tests.provision") planpythontestsuite("none", "samba.tests.password_quality") -planpythontestsuite("none", "samba.tests.samba3") planpythontestsuite("none", "samba.tests.strings") planpythontestsuite("none", "samba.tests.netcmd") planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc") @@ -76,6 +75,11 @@ planpythontestsuite("none", "samba.tests.hostconfig") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging", py3_compatible=True) +planpythontestsuite("none", "samba.tests.s3param") +planpythontestsuite("none", "samba.tests.s3passdb") +planpythontestsuite("none", "samba.tests.s3registry") +planpythontestsuite("none", "samba.tests.s3windb") +planpythontestsuite("none", "samba.tests.s3idmapdb") planpythontestsuite("none", "samba.tests.samba3sam") planpythontestsuite( "none", "wafsamba.tests.test_suite", From c539e343ba3f913d33f6cb2e8d210d7b21c30daf Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:39:58 +0000 Subject: [PATCH 05/41] python3 port for param module Signed-off-by: Noel Power --- source3/param/pyparam.c | 22 ++++++++++++++++------ source3/param/wscript_build | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source3/param/pyparam.c b/source3/param/pyparam.c index ddd17ca4b5f..4f80a0ef864 100644 --- a/source3/param/pyparam.c +++ b/source3/param/pyparam.c @@ -19,6 +19,7 @@ #include #include "includes.h" +#include "python/py3compat.h" #include "param/param.h" #include "param/loadparm.h" #include "lib/talloc/pytalloc.h" @@ -66,22 +67,31 @@ static PyMethodDef pyparam_methods[] = { { NULL } }; -void initparam(void) +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "param", + .m_doc = "Parsing and writing Samba3 configuration files.", + .m_size = -1, + .m_methods = pyparam_methods, +}; + +MODULE_INIT_FUNC(param) { - PyObject *m, *mod; + PyObject *m = NULL, *mod = NULL; - m = Py_InitModule3("param", pyparam_methods, "Parsing and writing Samba3 configuration files."); + m = PyModule_Create(&moduledef); if (m == NULL) - return; + return NULL; mod = PyImport_ImportModule("samba.param"); if (mod == NULL) { - return; + return NULL; } loadparm_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "LoadParm"); Py_DECREF(mod); if (loadparm_Type == NULL) { - return; + return NULL; } + return m; } diff --git a/source3/param/wscript_build b/source3/param/wscript_build index c60e917dba0..c9c42a35625 100644 --- a/source3/param/wscript_build +++ b/source3/param/wscript_build @@ -14,7 +14,8 @@ bld.SAMBA_GENERATOR('s3_param_proto_h', group='build_source', rule='${PYTHON} ${SRC[0].abspath(env)} --file ${SRC[1].abspath(env)} --output ${TGT} --mode=S3PROTO') -bld.SAMBA3_PYTHON('pys3param', +for env in bld.gen_python_environments(): + bld.SAMBA3_PYTHON('pys3param', source='pyparam.c', deps='smbconf', public_deps='samba-hostconfig pytalloc-util talloc', From 5bd0fbb2e8807fae82b702ab5bf798cab8d19423 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 12:50:48 +0000 Subject: [PATCH 06/41] python3 port for passdb module Signed-off-by: Noel Power --- source3/passdb/py_passdb.c | 226 ++++++++++++++++++++++--------------------- source3/passdb/wscript_build | 3 +- 2 files changed, 120 insertions(+), 109 deletions(-) diff --git a/source3/passdb/py_passdb.c b/source3/passdb/py_passdb.c index c49354c7765..bb0952fd1ea 100644 --- a/source3/passdb/py_passdb.c +++ b/source3/passdb/py_passdb.c @@ -20,6 +20,7 @@ #include #include #include "includes.h" +#include "python/py3compat.h" #include "lib/util/talloc_stack.h" #include "libcli/security/security.h" #include "librpc/gen_ndr/idmap.h" @@ -238,7 +239,7 @@ static PyObject *py_samu_get_username(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_username = PyString_FromString(username); + py_username = PyStr_FromString(username); talloc_free(frame); return py_username; } @@ -248,8 +249,8 @@ static int py_samu_set_username(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_username(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_username(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -269,7 +270,7 @@ static PyObject *py_samu_get_domain(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_domain = PyString_FromString(domain); + py_domain = PyStr_FromString(domain); talloc_free(frame); return py_domain; } @@ -279,8 +280,8 @@ static int py_samu_set_domain(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_domain(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_domain(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -300,7 +301,7 @@ static PyObject *py_samu_get_nt_username(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_nt_username = PyString_FromString(nt_username); + py_nt_username = PyStr_FromString(nt_username); talloc_free(frame); return py_nt_username; } @@ -310,8 +311,8 @@ static int py_samu_set_nt_username(PyObject *obj, PyObject *value, void *closure TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_nt_username(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_nt_username(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -331,7 +332,7 @@ static PyObject *py_samu_get_full_name(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_full_name = PyString_FromString(full_name); + py_full_name = PyStr_FromString(full_name); talloc_free(frame); return py_full_name; } @@ -341,8 +342,8 @@ static int py_samu_set_full_name(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_fullname(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_fullname(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -362,7 +363,7 @@ static PyObject *py_samu_get_home_dir(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_home_dir = PyString_FromString(home_dir); + py_home_dir = PyStr_FromString(home_dir); talloc_free(frame); return py_home_dir; } @@ -372,8 +373,8 @@ static int py_samu_set_home_dir(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_homedir(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_homedir(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -393,7 +394,7 @@ static PyObject *py_samu_get_dir_drive(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_dir_drive = PyString_FromString(dir_drive); + py_dir_drive = PyStr_FromString(dir_drive); talloc_free(frame); return py_dir_drive; } @@ -403,8 +404,8 @@ static int py_samu_set_dir_drive(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_dir_drive(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_dir_drive(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -424,7 +425,7 @@ static PyObject *py_samu_get_logon_script(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_logon_script = PyString_FromString(logon_script); + py_logon_script = PyStr_FromString(logon_script); talloc_free(frame); return py_logon_script; } @@ -434,8 +435,8 @@ static int py_samu_set_logon_script(PyObject *obj, PyObject *value, void *closur TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_logon_script(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_logon_script(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -455,7 +456,7 @@ static PyObject *py_samu_get_profile_path(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_profile_path = PyString_FromString(profile_path); + py_profile_path = PyStr_FromString(profile_path); talloc_free(frame); return py_profile_path; } @@ -465,8 +466,8 @@ static int py_samu_set_profile_path(PyObject *obj, PyObject *value, void *closur TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_profile_path(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_profile_path(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -486,7 +487,7 @@ static PyObject *py_samu_get_acct_desc(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_acct_desc = PyString_FromString(acct_desc); + py_acct_desc = PyStr_FromString(acct_desc); talloc_free(frame); return py_acct_desc; } @@ -496,8 +497,8 @@ static int py_samu_set_acct_desc(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_acct_desc(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_acct_desc(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -517,7 +518,7 @@ static PyObject *py_samu_get_workstations(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_workstations = PyString_FromString(workstations); + py_workstations = PyStr_FromString(workstations); talloc_free(frame); return py_workstations; } @@ -527,8 +528,8 @@ static int py_samu_set_workstations(PyObject *obj, PyObject *value, void *closur TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_workstations(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_workstations(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -548,7 +549,7 @@ static PyObject *py_samu_get_comment(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_comment = PyString_FromString(comment); + py_comment = PyStr_FromString(comment); talloc_free(frame); return py_comment; } @@ -558,8 +559,8 @@ static int py_samu_set_comment(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_comment(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_comment(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -579,7 +580,7 @@ static PyObject *py_samu_get_munged_dial(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_munged_dial = PyString_FromString(munged_dial); + py_munged_dial = PyStr_FromString(munged_dial); talloc_free(frame); return py_munged_dial; } @@ -589,8 +590,8 @@ static int py_samu_set_munged_dial(PyObject *obj, PyObject *value, void *closure TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_munged_dial(sam_acct, PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); + if (!pdb_set_munged_dial(sam_acct, PyStr_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -697,7 +698,7 @@ static PyObject *py_samu_get_lanman_passwd(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_lm_pw = PyString_FromStringAndSize(lm_pw, LM_HASH_LEN); + py_lm_pw = PyBytes_FromStringAndSize(lm_pw, LM_HASH_LEN); talloc_free(frame); return py_lm_pw; } @@ -707,8 +708,8 @@ static int py_samu_set_lanman_passwd(PyObject *obj, PyObject *value, void *closu TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); - if (!pdb_set_lanman_passwd(sam_acct, (uint8_t *)PyString_AsString(value), PDB_CHANGED)) { + PY_CHECK_TYPE(&PyBytes_Type, value, return -1;); + if (!pdb_set_lanman_passwd(sam_acct, (uint8_t *)PyBytes_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -728,7 +729,7 @@ static PyObject *py_samu_get_nt_passwd(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_nt_pw = PyString_FromStringAndSize(nt_pw, NT_HASH_LEN); + py_nt_pw = PyBytes_FromStringAndSize(nt_pw, NT_HASH_LEN); talloc_free(frame); return py_nt_pw; } @@ -738,7 +739,7 @@ static int py_samu_set_nt_passwd(PyObject *obj, PyObject *value, void *closure) TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - if (!pdb_set_nt_passwd(sam_acct, (uint8_t *)PyString_AsString(value), PDB_CHANGED)) { + if (!pdb_set_nt_passwd(sam_acct, (uint8_t *)PyBytes_AsString(value), PDB_CHANGED)) { talloc_free(frame); return -1; } @@ -759,7 +760,7 @@ static PyObject *py_samu_get_pw_history(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_nt_pw_his = PyString_FromStringAndSize(nt_pw_his, hist_len*PW_HISTORY_ENTRY_LEN); + py_nt_pw_his = PyBytes_FromStringAndSize(nt_pw_his, hist_len*PW_HISTORY_ENTRY_LEN); talloc_free(frame); return py_nt_pw_his; } @@ -772,7 +773,7 @@ static int py_samu_set_pw_history(PyObject *obj, PyObject *value, void *closure) Py_ssize_t len; uint32_t hist_len; - PyString_AsStringAndSize(value, &nt_pw_his, &len); + PyBytes_AsStringAndSize(value, &nt_pw_his, &len); hist_len = len / PW_HISTORY_ENTRY_LEN; if (!pdb_set_pw_history(sam_acct, (uint8_t *)nt_pw_his, hist_len, PDB_CHANGED)) { talloc_free(frame); @@ -794,7 +795,7 @@ static PyObject *py_samu_get_plaintext_passwd(PyObject *obj, void *closure) Py_RETURN_NONE; } - py_plaintext_pw = PyString_FromString(plaintext_pw); + py_plaintext_pw = PyStr_FromString(plaintext_pw); talloc_free(frame); return py_plaintext_pw; } @@ -804,7 +805,7 @@ static int py_samu_set_plaintext_passwd(PyObject *obj, PyObject *value, void *cl TALLOC_CTX *frame = talloc_stackframe(); struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj); - if (!pdb_set_plaintext_passwd(sam_acct, PyString_AsString(value))) { + if (!pdb_set_plaintext_passwd(sam_acct, PyStr_AsString(value))) { talloc_free(frame); return -1; } @@ -1211,7 +1212,7 @@ static PyObject *py_groupmap_get_nt_name(PyObject *obj, void *closure) py_nt_name = Py_None; Py_INCREF(py_nt_name); } else { - py_nt_name = PyString_FromString(group_map->nt_name); + py_nt_name = PyStr_FromString(group_map->nt_name); } talloc_free(frame); return py_nt_name; @@ -1222,11 +1223,11 @@ static int py_groupmap_set_nt_name(PyObject *obj, PyObject *value, void *closure TALLOC_CTX *frame = talloc_stackframe(); GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); if (value == Py_None) { fstrcpy(group_map->nt_name, NULL); } else { - fstrcpy(group_map->nt_name, PyString_AsString(value)); + fstrcpy(group_map->nt_name, PyStr_AsString(value)); } talloc_free(frame); return 0; @@ -1241,7 +1242,7 @@ static PyObject *py_groupmap_get_comment(PyObject *obj, void *closure) py_comment = Py_None; Py_INCREF(py_comment); } else { - py_comment = PyString_FromString(group_map->comment); + py_comment = PyStr_FromString(group_map->comment); } talloc_free(frame); return py_comment; @@ -1252,11 +1253,11 @@ static int py_groupmap_set_comment(PyObject *obj, PyObject *value, void *closure TALLOC_CTX *frame = talloc_stackframe(); GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj); - PY_CHECK_TYPE(&PyString_Type, value, return -1;); + PY_CHECK_TYPE(&PyStr_Type, value, return -1;); if (value == Py_None) { fstrcpy(group_map->comment, NULL); } else { - fstrcpy(group_map->comment, PyString_AsString(value)); + fstrcpy(group_map->comment, PyStr_AsString(value)); } talloc_free(frame); return 0; @@ -1355,9 +1356,9 @@ static PyObject *py_pdb_domain_info(PyObject *self, PyObject *args) return NULL; } - PyDict_SetItemString(py_domain_info, "name", PyString_FromString(domain_info->name)); - PyDict_SetItemString(py_domain_info, "dns_domain", PyString_FromString(domain_info->dns_domain)); - PyDict_SetItemString(py_domain_info, "dns_forest", PyString_FromString(domain_info->dns_forest)); + PyDict_SetItemString(py_domain_info, "name", PyStr_FromString(domain_info->name)); + PyDict_SetItemString(py_domain_info, "dns_domain", PyStr_FromString(domain_info->dns_domain)); + PyDict_SetItemString(py_domain_info, "dns_forest", PyStr_FromString(domain_info->dns_forest)); PyDict_SetItemString(py_domain_info, "dom_sid", pytalloc_steal(dom_sid_Type, sid)); PyDict_SetItemString(py_domain_info, "guid", pytalloc_steal(guid_Type, guid)); @@ -2227,9 +2228,9 @@ static PyObject *py_pdb_get_aliasinfo(PyObject *self, PyObject *args) } PyDict_SetItemString(py_alias_info, "acct_name", - PyString_FromString(alias_info->acct_name)); + PyStr_FromString(alias_info->acct_name)); PyDict_SetItemString(py_alias_info, "acct_desc", - PyString_FromString(alias_info->acct_desc)); + PyStr_FromString(alias_info->acct_desc)); PyDict_SetItemString(py_alias_info, "rid", PyInt_FromLong(alias_info->rid)); @@ -2257,13 +2258,13 @@ static PyObject *py_pdb_set_aliasinfo(PyObject *self, PyObject *args) alias_sid = pytalloc_get_ptr(py_alias_sid); - alias_info.acct_name = talloc_strdup(frame, PyString_AsString(PyDict_GetItemString(py_alias_info, "acct_name"))); + alias_info.acct_name = talloc_strdup(frame, PyStr_AsString(PyDict_GetItemString(py_alias_info, "acct_name"))); if (alias_info.acct_name == NULL) { PyErr_Format(py_pdb_error, "Unable to allocate memory"); talloc_free(frame); return NULL; } - alias_info.acct_desc = talloc_strdup(frame, PyString_AsString(PyDict_GetItemString(py_alias_info, "acct_desc"))); + alias_info.acct_desc = talloc_strdup(frame, PyStr_AsString(PyDict_GetItemString(py_alias_info, "acct_desc"))); if (alias_info.acct_desc == NULL) { PyErr_Format(py_pdb_error, "Unable to allocate memory"); talloc_free(frame); @@ -2523,9 +2524,9 @@ static PyObject *py_pdb_search_users(PyObject *self, PyObject *args) PyDict_SetItemString(py_dict, "idx", PyInt_FromLong(entry->idx)); PyDict_SetItemString(py_dict, "rid", PyInt_FromLong(entry->rid)); PyDict_SetItemString(py_dict, "acct_flags", PyInt_FromLong(entry->acct_flags)); - PyDict_SetItemString(py_dict, "account_name", PyString_FromString(entry->account_name)); - PyDict_SetItemString(py_dict, "fullname", PyString_FromString(entry->fullname)); - PyDict_SetItemString(py_dict, "description", PyString_FromString(entry->description)); + PyDict_SetItemString(py_dict, "account_name", PyStr_FromString(entry->account_name)); + PyDict_SetItemString(py_dict, "fullname", PyStr_FromString(entry->fullname)); + PyDict_SetItemString(py_dict, "description", PyStr_FromString(entry->description)); PyList_Append(py_userlist, py_dict); } } @@ -2581,9 +2582,9 @@ static PyObject *py_pdb_search_groups(PyObject *self, PyObject *unused) PyDict_SetItemString(py_dict, "idx", PyInt_FromLong(entry->idx)); PyDict_SetItemString(py_dict, "rid", PyInt_FromLong(entry->rid)); PyDict_SetItemString(py_dict, "acct_flags", PyInt_FromLong(entry->acct_flags)); - PyDict_SetItemString(py_dict, "account_name", PyString_FromString(entry->account_name)); - PyDict_SetItemString(py_dict, "fullname", PyString_FromString(entry->fullname)); - PyDict_SetItemString(py_dict, "description", PyString_FromString(entry->description)); + PyDict_SetItemString(py_dict, "account_name", PyStr_FromString(entry->account_name)); + PyDict_SetItemString(py_dict, "fullname", PyStr_FromString(entry->fullname)); + PyDict_SetItemString(py_dict, "description", PyStr_FromString(entry->description)); PyList_Append(py_grouplist, py_dict); } } @@ -2653,9 +2654,9 @@ static PyObject *py_pdb_search_aliases(PyObject *self, PyObject *args) PyDict_SetItemString(py_dict, "idx", PyInt_FromLong(entry->idx)); PyDict_SetItemString(py_dict, "rid", PyInt_FromLong(entry->rid)); PyDict_SetItemString(py_dict, "acct_flags", PyInt_FromLong(entry->acct_flags)); - PyDict_SetItemString(py_dict, "account_name", PyString_FromString(entry->account_name)); - PyDict_SetItemString(py_dict, "fullname", PyString_FromString(entry->fullname)); - PyDict_SetItemString(py_dict, "description", PyString_FromString(entry->description)); + PyDict_SetItemString(py_dict, "account_name", PyStr_FromString(entry->account_name)); + PyDict_SetItemString(py_dict, "fullname", PyStr_FromString(entry->fullname)); + PyDict_SetItemString(py_dict, "description", PyStr_FromString(entry->description)); PyList_Append(py_aliaslist, py_dict); } } @@ -2836,7 +2837,7 @@ static PyObject *py_pdb_get_trusteddom_pw(PyObject *self, PyObject *args) return NULL; } - PyDict_SetItemString(py_value, "pwd", PyString_FromString(pwd)); + PyDict_SetItemString(py_value, "pwd", PyStr_FromString(pwd)); PyDict_SetItemString(py_value, "sid", py_sid); PyDict_SetItemString(py_value, "last_set_tim", PyInt_FromLong(last_set_time)); @@ -2931,7 +2932,7 @@ static PyObject *py_pdb_enum_trusteddoms(PyObject *self, PyObject *unused) py_dict = PyDict_New(); if (py_dict) { PyDict_SetItemString(py_dict, "name", - PyString_FromString(domains[i]->name)); + PyStr_FromString(domains[i]->name)); PyDict_SetItemString(py_dict, "sid", pytalloc_steal(dom_sid_Type, &domains[i]->sid)); } @@ -2977,16 +2978,16 @@ static PyObject *py_pdb_get_trusted_domain(PyObject *self, PyObject *args) } PyDict_SetItemString(py_domain_info, "domain_name", - PyString_FromString(td->domain_name)); + PyStr_FromString(td->domain_name)); PyDict_SetItemString(py_domain_info, "netbios_name", - PyString_FromString(td->netbios_name)); + PyStr_FromString(td->netbios_name)); PyDict_SetItemString(py_domain_info, "security_identifier", pytalloc_steal(dom_sid_Type, &td->security_identifier)); PyDict_SetItemString(py_domain_info, "trust_auth_incoming", - PyString_FromStringAndSize((char *)td->trust_auth_incoming.data, + PyBytes_FromStringAndSize((const char *)td->trust_auth_incoming.data, td->trust_auth_incoming.length)); PyDict_SetItemString(py_domain_info, "trust_auth_outgoing", - PyString_FromStringAndSize((char *)td->trust_auth_outgoing.data, + PyBytes_FromStringAndSize((const char *)td->trust_auth_outgoing.data, td->trust_auth_outgoing.length)); PyDict_SetItemString(py_domain_info, "trust_direction", PyInt_FromLong(td->trust_direction)); @@ -2995,7 +2996,7 @@ static PyObject *py_pdb_get_trusted_domain(PyObject *self, PyObject *args) PyDict_SetItemString(py_domain_info, "trust_attributes", PyInt_FromLong(td->trust_attributes)); PyDict_SetItemString(py_domain_info, "trust_forest_trust_info", - PyString_FromStringAndSize((char *)td->trust_forest_trust_info.data, + PyBytes_FromStringAndSize((const char *)td->trust_forest_trust_info.data, td->trust_forest_trust_info.length)); talloc_free(frame); @@ -3039,16 +3040,16 @@ static PyObject *py_pdb_get_trusted_domain_by_sid(PyObject *self, PyObject *args } PyDict_SetItemString(py_domain_info, "domain_name", - PyString_FromString(td->domain_name)); + PyStr_FromString(td->domain_name)); PyDict_SetItemString(py_domain_info, "netbios_name", - PyString_FromString(td->netbios_name)); + PyStr_FromString(td->netbios_name)); PyDict_SetItemString(py_domain_info, "security_identifier", pytalloc_steal(dom_sid_Type, &td->security_identifier)); PyDict_SetItemString(py_domain_info, "trust_auth_incoming", - PyString_FromStringAndSize((char *)td->trust_auth_incoming.data, + PyBytes_FromStringAndSize((char *)td->trust_auth_incoming.data, td->trust_auth_incoming.length)); PyDict_SetItemString(py_domain_info, "trust_auth_outgoing", - PyString_FromStringAndSize((char *)td->trust_auth_outgoing.data, + PyBytes_FromStringAndSize((char *)td->trust_auth_outgoing.data, td->trust_auth_outgoing.length)); PyDict_SetItemString(py_domain_info, "trust_direction", PyInt_FromLong(td->trust_direction)); @@ -3057,7 +3058,7 @@ static PyObject *py_pdb_get_trusted_domain_by_sid(PyObject *self, PyObject *args PyDict_SetItemString(py_domain_info, "trust_attributes", PyInt_FromLong(td->trust_attributes)); PyDict_SetItemString(py_domain_info, "trust_forest_trust_info", - PyString_FromStringAndSize((char *)td->trust_forest_trust_info.data, + PyBytes_FromStringAndSize((char *)td->trust_forest_trust_info.data, td->trust_forest_trust_info.length)); talloc_free(frame); @@ -3082,20 +3083,20 @@ static PyObject *py_pdb_set_trusted_domain(PyObject *self, PyObject *args) } py_tmp = PyDict_GetItemString(py_td_info, "domain_name"); - td_info.domain_name = PyString_AsString(py_tmp); + td_info.domain_name = PyStr_AsString(py_tmp); py_tmp = PyDict_GetItemString(py_td_info, "netbios_name"); - td_info.netbios_name = PyString_AsString(py_tmp); + td_info.netbios_name = PyStr_AsString(py_tmp); py_tmp = PyDict_GetItemString(py_td_info, "security_identifier"); td_info.security_identifier = *pytalloc_get_type(py_tmp, struct dom_sid); py_tmp = PyDict_GetItemString(py_td_info, "trust_auth_incoming"); - PyString_AsStringAndSize(py_tmp, (char **)&td_info.trust_auth_incoming.data, &len); + PyBytes_AsStringAndSize(py_tmp, (char **)&td_info.trust_auth_incoming.data, &len); td_info.trust_auth_incoming.length = len; py_tmp = PyDict_GetItemString(py_td_info, "trust_auth_outgoing"); - PyString_AsStringAndSize(py_tmp, (char **)&td_info.trust_auth_outgoing.data, &len); + PyBytes_AsStringAndSize(py_tmp, (char **)&td_info.trust_auth_outgoing.data, &len); td_info.trust_auth_outgoing.length = len; py_tmp = PyDict_GetItemString(py_td_info, "trust_direction"); @@ -3108,7 +3109,7 @@ static PyObject *py_pdb_set_trusted_domain(PyObject *self, PyObject *args) td_info.trust_attributes = PyInt_AsLong(py_tmp); py_tmp = PyDict_GetItemString(py_td_info, "trust_forest_trust_info"); - PyString_AsStringAndSize(py_tmp, (char **)&td_info.trust_forest_trust_info.data, &len); + PyBytes_AsStringAndSize(py_tmp, (char **)&td_info.trust_forest_trust_info.data, &len); td_info.trust_forest_trust_info.length = len; methods = pytalloc_get_ptr(self); @@ -3196,16 +3197,16 @@ static PyObject *py_pdb_enum_trusted_domains(PyObject *self, PyObject *args) td = td_info[i]; PyDict_SetItemString(py_domain_info, "domain_name", - PyString_FromString(td->domain_name)); + PyStr_FromString(td->domain_name)); PyDict_SetItemString(py_domain_info, "netbios_name", - PyString_FromString(td->netbios_name)); + PyStr_FromString(td->netbios_name)); PyDict_SetItemString(py_domain_info, "security_identifier", pytalloc_steal(dom_sid_Type, &td->security_identifier)); PyDict_SetItemString(py_domain_info, "trust_auth_incoming", - PyString_FromStringAndSize((char *)td->trust_auth_incoming.data, + PyBytes_FromStringAndSize((const char *)td->trust_auth_incoming.data, td->trust_auth_incoming.length)); PyDict_SetItemString(py_domain_info, "trust_auth_outgoing", - PyString_FromStringAndSize((char *)td->trust_auth_outgoing.data, + PyBytes_FromStringAndSize((const char *)td->trust_auth_outgoing.data, td->trust_auth_outgoing.length)); PyDict_SetItemString(py_domain_info, "trust_direction", PyInt_FromLong(td->trust_direction)); @@ -3214,7 +3215,7 @@ static PyObject *py_pdb_enum_trusted_domains(PyObject *self, PyObject *args) PyDict_SetItemString(py_domain_info, "trust_attributes", PyInt_FromLong(td->trust_attributes)); PyDict_SetItemString(py_domain_info, "trust_forest_trust_info", - PyString_FromStringAndSize((char *)td->trust_forest_trust_info.data, + PyBytes_FromStringAndSize((const char *)td->trust_forest_trust_info.data, td->trust_forest_trust_info.length)); PyList_Append(py_td_info, py_domain_info); } @@ -3275,11 +3276,11 @@ static PyObject *py_pdb_get_secret(PyObject *self, PyObject *args) } PyDict_SetItemString(py_secret, "secret_current", - PyString_FromStringAndSize((char *)secret_current.data, secret_current.length)); + PyBytes_FromStringAndSize((const char*)secret_current.data, secret_current.length)); PyDict_SetItemString(py_secret, "secret_current_lastchange", PyLong_FromUnsignedLongLong(secret_current_lastchange)); PyDict_SetItemString(py_secret, "secret_old", - PyString_FromStringAndSize((char *)secret_old.data, secret_old.length)); + PyBytes_FromStringAndSize((const char*)secret_old.data, secret_old.length)); PyDict_SetItemString(py_secret, "secret_old_lastchange", PyLong_FromUnsignedLongLong(secret_old_lastchange)); PyDict_SetItemString(py_secret, "sd", py_sd); @@ -3310,15 +3311,15 @@ static PyObject *py_pdb_set_secret(PyObject *self, PyObject *args) py_secret_old = PyDict_GetItemString(py_secret, "secret_old"); py_sd = PyDict_GetItemString(py_secret, "sd"); - PY_CHECK_TYPE(&PyString_Type, py_secret_cur, return NULL;); - PY_CHECK_TYPE(&PyString_Type, py_secret_old, return NULL;); + PY_CHECK_TYPE(&PyBytes_Type, py_secret_cur, return NULL;); + PY_CHECK_TYPE(&PyBytes_Type, py_secret_old, return NULL;); PY_CHECK_TYPE(security_Type, py_sd, return NULL;); methods = pytalloc_get_ptr(self); - PyString_AsStringAndSize(py_secret_cur, (char **)&secret_current.data, &len); + PyBytes_AsStringAndSize(py_secret_cur, (char **)&secret_current.data, &len); secret_current.length = len; - PyString_AsStringAndSize(py_secret_old, (char **)&secret_old.data, &len); + PyBytes_AsStringAndSize(py_secret_old, (char **)&secret_old.data, &len); secret_current.length = len; sd = pytalloc_get_ptr(py_sd); @@ -3595,7 +3596,7 @@ static PyObject *py_passdb_backends(PyObject *self, PyObject *unused) } while(entry) { - PyList_Append(py_blist, PyString_FromString(entry->name)); + PyList_Append(py_blist, PyStr_FromString(entry->name)); entry = entry->next; } @@ -3704,31 +3705,39 @@ static PyMethodDef py_passdb_methods[] = { { NULL }, }; -void initpassdb(void) +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "passdb", + .m_doc = "SAMBA Password Database", + .m_size = -1, + .m_methods = py_passdb_methods, +}; + +MODULE_INIT_FUNC(passdb) { TALLOC_CTX *frame = talloc_stackframe(); - PyObject *m, *mod; + PyObject *m = NULL, *mod = NULL; char exception_name[] = "passdb.error"; if (pytalloc_BaseObject_PyType_Ready(&PyPDB) < 0) { talloc_free(frame); - return; + return NULL; } if (pytalloc_BaseObject_PyType_Ready(&PySamu) < 0) { talloc_free(frame); - return; + return NULL; } if (pytalloc_BaseObject_PyType_Ready(&PyGroupmap) < 0) { talloc_free(frame); - return; + return NULL; } - m = Py_InitModule3("passdb", py_passdb_methods, "SAMBA Password Database"); + m = PyModule_Create(&moduledef); if (m == NULL) { talloc_free(frame); - return; + return NULL; } /* Create new exception for passdb module */ @@ -3749,13 +3758,13 @@ void initpassdb(void) mod = PyImport_ImportModule("samba.dcerpc.security"); if (mod == NULL) { talloc_free(frame); - return; + return NULL; } dom_sid_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "dom_sid"); if (dom_sid_Type == NULL) { talloc_free(frame); - return; + return NULL; } /* Import security_descriptor type from dcerpc.security */ @@ -3763,21 +3772,22 @@ void initpassdb(void) Py_DECREF(mod); if (security_Type == NULL) { talloc_free(frame); - return; + return NULL; } /* Import GUID type from dcerpc.misc */ mod = PyImport_ImportModule("samba.dcerpc.misc"); if (mod == NULL) { talloc_free(frame); - return; + return NULL; } guid_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "GUID"); Py_DECREF(mod); if (guid_Type == NULL) { talloc_free(frame); - return; + return NULL; } talloc_free(frame); + return m; } diff --git a/source3/passdb/wscript_build b/source3/passdb/wscript_build index a1a7da3950b..0ae2c4def40 100644 --- a/source3/passdb/wscript_build +++ b/source3/passdb/wscript_build @@ -32,7 +32,8 @@ bld.SAMBA3_MODULE('pdb_samba_dsdb', internal_module=bld.SAMBA3_IS_STATIC_MODULE('pdb_samba_dsdb') and bld.AD_DC_BUILD_IS_ENABLED(), enabled=bld.SAMBA3_IS_ENABLED_MODULE('pdb_samba_dsdb') and bld.AD_DC_BUILD_IS_ENABLED()) -bld.SAMBA3_PYTHON('pypassdb', +for env in bld.gen_python_environments(): + bld.SAMBA3_PYTHON('pypassdb', source='py_passdb.c', deps='pdb', public_deps='samba-util tdb talloc pyrpc_util pytalloc-util', From 283f7c96787cac953f95a5634f431ec26f0e991e Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:21:12 +0000 Subject: [PATCH 07/41] python selftest: enable samba.tests.s3param to run with python3 Signed-off-by: Noel Power --- python/samba/samba3/__init__.py | 5 ++--- selftest/tests.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py index 8df01705497..ff28da49881 100644 --- a/python/samba/samba3/__init__.py +++ b/python/samba/samba3/__init__.py @@ -26,9 +26,8 @@ import struct import tdb -import passdb -import param as s3param - +import samba.samba3.passdb +from samba.samba3 import param as s3param def fetch_uint32(db, key): try: diff --git a/selftest/tests.py b/selftest/tests.py index 027a80e03f1..7b81900e521 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -75,7 +75,7 @@ planpythontestsuite("none", "samba.tests.hostconfig") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging", py3_compatible=True) -planpythontestsuite("none", "samba.tests.s3param") +planpythontestsuite("none", "samba.tests.s3param", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3passdb") planpythontestsuite("none", "samba.tests.s3registry") planpythontestsuite("none", "samba.tests.s3windb") From 04766a385ccfab8f8f1aebda464d4e861638731f Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:26:15 +0000 Subject: [PATCH 08/41] python selftest: enable samba.tests.s3passdb to run with python3 Signed-off-by: Noel Power --- python/samba/tests/s3passdb.py | 2 +- selftest/tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/s3passdb.py b/python/samba/tests/s3passdb.py index 2f6bc74e869..fe2ab088081 100644 --- a/python/samba/tests/s3passdb.py +++ b/python/samba/tests/s3passdb.py @@ -97,7 +97,7 @@ def test_getuser(self): self.assertEquals("", user.logon_script) self.assertEquals(0, user.logon_time) self.assertEquals("", user.munged_dial) - self.assertEquals('\x87\x8d\x80\x14`l\xda)gzD\xef\xa15?\xc7', user.nt_passwd) + self.assertEquals(b'\x87\x8d\x80\x14`l\xda)gzD\xef\xa15?\xc7', user.nt_passwd) self.assertEquals("", user.nt_username) self.assertEquals(1125418267, user.pass_can_change_time) self.assertEquals(1125418267, user.pass_last_set_time) diff --git a/selftest/tests.py b/selftest/tests.py index 7b81900e521..61419d3dd64 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -76,7 +76,7 @@ planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3param", py3_compatible=True) -planpythontestsuite("none", "samba.tests.s3passdb") +planpythontestsuite("none", "samba.tests.s3passdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3registry") planpythontestsuite("none", "samba.tests.s3windb") planpythontestsuite("none", "samba.tests.s3idmapdb") From bf26d41830750b090791298fedefe485befdaf80 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:35:11 +0000 Subject: [PATCH 09/41] python selftest: enabled samba.tests.s3registry to run with py3 Signed-off-by: Noel Power --- python/samba/samba3/__init__.py | 14 +++++++------- python/samba/tests/s3registry.py | 10 +++++----- selftest/tests.py | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py index ff28da49881..323953857d5 100644 --- a/python/samba/samba3/__init__.py +++ b/python/samba/samba3/__init__.py @@ -19,7 +19,7 @@ __docformat__ = "restructuredText" -REGISTRY_VALUE_PREFIX = "SAMBA_REGVAL" +REGISTRY_VALUE_PREFIX = b"SAMBA_REGVAL" REGISTRY_DB_VERSION = 1 import os @@ -79,7 +79,7 @@ def __len__(self): def keys(self): """Return list with all the keys.""" - return [k.rstrip("\x00") for k in self.db.iterkeys() if not k.startswith(REGISTRY_VALUE_PREFIX)] + return [k.rstrip(b"\x00") for k in self.db if not k.startswith(REGISTRY_VALUE_PREFIX)] def subkeys(self, key): """Retrieve the subkeys for the specified key. @@ -87,12 +87,12 @@ def subkeys(self, key): :param key: Key path. :return: list with key names """ - data = self.db.get("%s\x00" % key) + data = self.db.get(b"%s\x00" % key) if data is None: return [] (num, ) = struct.unpack(" Date: Thu, 22 Mar 2018 12:39:43 +0000 Subject: [PATCH 10/41] python selftest: enable samba.tests.s3windb to run with py3 Signed-off-by: Noel Power --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index eefc2c88c10..ea1e638f6f5 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -78,7 +78,7 @@ planpythontestsuite("none", "samba.tests.s3param", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3passdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3registry", py3_compatible=True) -planpythontestsuite("none", "samba.tests.s3windb") +planpythontestsuite("none", "samba.tests.s3windb", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3idmapdb") planpythontestsuite("none", "samba.tests.samba3sam") planpythontestsuite( From c6aeec54dccb4555df8f9cad43102ef49829d045 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:46:55 +0000 Subject: [PATCH 11/41] selftest python: get samba.tests.s3idmapdb to run with py3 Signed-off-by: Noel Power --- python/samba/samba3/__init__.py | 30 +++++++++++++++--------------- python/samba/tests/s3idmapdb.py | 4 ++-- selftest/tests.py | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py index 323953857d5..a0bb76f68c1 100644 --- a/python/samba/samba3/__init__.py +++ b/python/samba/samba3/__init__.py @@ -125,11 +125,11 @@ def values(self, key): # High water mark keys -IDMAP_HWM_GROUP = "GROUP HWM\0" -IDMAP_HWM_USER = "USER HWM\0" +IDMAP_HWM_GROUP = b"GROUP HWM\0" +IDMAP_HWM_USER = b"USER HWM\0" -IDMAP_GROUP_PREFIX = "GID " -IDMAP_USER_PREFIX = "UID " +IDMAP_GROUP_PREFIX = b"GID " +IDMAP_USER_PREFIX = b"UID " # idmap version determines auto-conversion IDMAP_VERSION_V2 = 2 @@ -138,27 +138,27 @@ class IdmapDatabase(DbDatabase): """Samba 3 ID map database reader.""" def _check_version(self): - assert fetch_int32(self.db, "IDMAP_VERSION\0") == IDMAP_VERSION_V2 + assert fetch_int32(self.db, b"IDMAP_VERSION\0") == IDMAP_VERSION_V2 def ids(self): """Retrieve a list of all ids in this database.""" for k in self.db.iterkeys(): if k.startswith(IDMAP_USER_PREFIX): - yield k.rstrip("\0").split(" ") + yield k.rstrip(b"\0").split(b" ") if k.startswith(IDMAP_GROUP_PREFIX): - yield k.rstrip("\0").split(" ") + yield k.rstrip(b"\0").split(b" ") def uids(self): """Retrieve a list of all uids in this database.""" - for k in self.db.iterkeys(): + for k in self.db: if k.startswith(IDMAP_USER_PREFIX): - yield int(k[len(IDMAP_USER_PREFIX):].rstrip("\0")) + yield int(k[len(IDMAP_USER_PREFIX):].rstrip(b"\0")) def gids(self): """Retrieve a list of all gids in this database.""" - for k in self.db.iterkeys(): + for k in self.db: if k.startswith(IDMAP_GROUP_PREFIX): - yield int(k[len(IDMAP_GROUP_PREFIX):].rstrip("\0")) + yield int(k[len(IDMAP_GROUP_PREFIX):].rstrip(b"\0")) def get_sid(self, xid, id_type): """Retrive SID associated with a particular id and type. @@ -177,16 +177,16 @@ def get_user_sid(self, uid): :param uid: UID to retrieve SID for. :return: A SID or None if no mapping was found. """ - data = self.db.get("%s%d\0" % (IDMAP_USER_PREFIX, uid)) + data = self.db.get(b"%s%d\0" % (IDMAP_USER_PREFIX, uid)) if data is None: return data - return data.rstrip("\0") + return data.rstrip(b"\0") def get_group_sid(self, gid): - data = self.db.get("%s%d\0" % (IDMAP_GROUP_PREFIX, gid)) + data = self.db.get(b"%s%d\0" % (IDMAP_GROUP_PREFIX, gid)) if data is None: return data - return data.rstrip("\0") + return data.rstrip(b"\0") def get_user_hwm(self): """Obtain the user high-water mark.""" diff --git a/python/samba/tests/s3idmapdb.py b/python/samba/tests/s3idmapdb.py index aa278404111..1f510f10bad 100644 --- a/python/samba/tests/s3idmapdb.py +++ b/python/samba/tests/s3idmapdb.py @@ -47,10 +47,10 @@ def test_gids(self): self.assertEquals(3, len(list(self.idmapdb.gids()))) def test_get_user_sid(self): - self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534)) + self.assertEquals(b"S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534)) def test_get_group_sid(self): - self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001)) + self.assertEquals(b"S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001)) def tearDown(self): self.idmapdb.close() diff --git a/selftest/tests.py b/selftest/tests.py index ea1e638f6f5..1dbbb0e5fc2 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -79,7 +79,7 @@ planpythontestsuite("none", "samba.tests.s3passdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3registry", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3windb", py3_compatible=True) -planpythontestsuite("none", "samba.tests.s3idmapdb") +planpythontestsuite("none", "samba.tests.s3idmapdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.samba3sam") planpythontestsuite( "none", "wafsamba.tests.test_suite", From 4dacdf231bb4bdbb81750978275c8f072bda5d4c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:34:15 +0000 Subject: [PATCH 12/41] python3 port for libsmb_samba_internal module Signed-off-by: Noel Power --- source3/libsmb/pylibsmb.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index d2167e917d6..311820c7d66 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -20,6 +20,7 @@ #include #include "includes.h" +#include "python/py3compat.h" #include "libsmb/libsmb.h" #include "libcli/security/security.h" #include "system/select.h" @@ -576,7 +577,7 @@ static void py_cli_state_dealloc(struct py_cli_state *self) cli_shutdown(self->cli); self->cli = NULL; } - self->ob_type->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *py_cli_create(struct py_cli_state *self, PyObject *args, @@ -875,7 +876,7 @@ static PyMethodDef py_cli_state_methods[] = { }; static PyTypeObject py_cli_state_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "libsmb_samba_internal.Conn", .tp_basicsize = sizeof(struct py_cli_state), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, @@ -891,18 +892,29 @@ static PyMethodDef py_libsmb_methods[] = { }; void initlibsmb_samba_internal(void); -void initlibsmb_samba_internal(void) + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "libsmb_samba_internal", + .m_doc = "libsmb wrapper", + .m_size = -1, + .m_methods = py_libsmb_methods, +}; + +MODULE_INIT_FUNC(libsmb_samba_internal) { - PyObject *m; + PyObject *m = NULL; talloc_stackframe(); - m = Py_InitModule3("libsmb_samba_internal", py_libsmb_methods, - "libsmb wrapper"); - + m = PyModule_Create(&moduledef); + if (m == NULL) { + return m; + } if (PyType_Ready(&py_cli_state_type) < 0) { - return; + return NULL; } Py_INCREF(&py_cli_state_type); PyModule_AddObject(m, "Conn", (PyObject *)&py_cli_state_type); + return m; } From eb8db75e1d2dc01450137cba9d1e84c0d0f61ece Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 8 Mar 2018 10:37:23 +0000 Subject: [PATCH 13/41] python samba test: enable samba.tests.libsmb_samba_internal for py3 Signed-off-by: Noel Power --- source3/wscript_build | 3 ++- source4/selftest/tests.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source3/wscript_build b/source3/wscript_build index ed9ed24fae2..254738e69ea 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -1302,7 +1302,8 @@ bld.SAMBA3_PYTHON('pysmbd', realname='samba/samba3/smbd.so' ) -bld.SAMBA3_PYTHON('pylibsmb', +for env in bld.gen_python_environments(): + bld.SAMBA3_PYTHON('pylibsmb', source='libsmb/pylibsmb.c', deps='smbclient samba-credentials pycredentials', realname='samba/samba3/libsmb_samba_internal.so' diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 0f32c6deed1..b882502be75 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -376,7 +376,7 @@ def plansmbtorture4testsuite(name, env, options, modname=None): #The dlz_bind9 tests needs to look at the DNS database plansmbtorture4testsuite(t, "chgdcpass:local", ["ncalrpc:$SERVER", '-U$USERNAME%$PASSWORD']) -planpythontestsuite("nt4_dc", "samba.tests.libsmb_samba_internal"); +planpythontestsuite("nt4_dc", "samba.tests.libsmb_samba_internal", py3_compatible=True); # Blackbox Tests: # tests that interact directly with the command-line tools rather than using From bc93af47fa295e69154e3d61923b369d942484d8 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:10:46 +0000 Subject: [PATCH 14/41] python3 port for smbd module Signed-off-by: Noel Power --- source3/smbd/pysmbd.c | 21 ++++++++++++++------- source3/wscript_build | 4 +++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index be30b866e20..daaf95cb665 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -25,6 +25,7 @@ #include #include "includes.h" +#include "python/py3compat.h" #include "smbd/smbd.h" #include "libcli/util/pyerrors.h" #include "librpc/rpc/pyrpc_util.h" @@ -739,13 +740,19 @@ static PyMethodDef py_smbd_methods[] = { }; void initsmbd(void); -void initsmbd(void) -{ - PyObject *m; - m = Py_InitModule3("smbd", py_smbd_methods, - "Python bindings for the smbd file server."); - if (m == NULL) - return; +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "smbd", + .m_doc = "Python bindings for the smbd file server.", + .m_size = -1, + .m_methods = py_smbd_methods, +}; + +MODULE_INIT_FUNC(smbd) +{ + PyObject *m = NULL; + m = PyModule_Create(&moduledef); + return m; } diff --git a/source3/wscript_build b/source3/wscript_build index 254738e69ea..f0eb23cc3f7 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -1296,7 +1296,9 @@ bld.SAMBA3_BINARY('vlp', ''', install=False) -bld.SAMBA3_PYTHON('pysmbd', + +for env in bld.gen_python_environments(): + bld.SAMBA3_PYTHON('pysmbd', source='smbd/pysmbd.c', deps='smbd_base pyrpc_util pytalloc-util', realname='samba/samba3/smbd.so' From 686daab52962abd5558b92cf46a80a039a6ba716 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 6 Mar 2018 15:03:13 +0000 Subject: [PATCH 15/41] s4/ntvfs/posix/python: python3 (get|set)xattr value should be bytes Signed-off-by: Noel Power --- source4/ntvfs/posix/python/pyposix_eadb.c | 4 ++-- source4/ntvfs/posix/python/pyxattr_native.c | 4 ++-- source4/ntvfs/posix/python/pyxattr_tdb.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source4/ntvfs/posix/python/pyposix_eadb.c b/source4/ntvfs/posix/python/pyposix_eadb.c index d43c7c47bb7..646498225b3 100644 --- a/source4/ntvfs/posix/python/pyposix_eadb.c +++ b/source4/ntvfs/posix/python/pyposix_eadb.c @@ -43,7 +43,7 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) TALLOC_CTX *mem_ctx; struct tdb_wrap *eadb; - if (!PyArg_ParseTuple(args, "ssss#", &tdbname, &filename, &attribute, + if (!PyArg_ParseTuple(args, "sss"PYARG_BYTES_LEN, &tdbname, &filename, &attribute, &blob.data, &blobsize)) return NULL; @@ -101,7 +101,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) talloc_free(mem_ctx); return NULL; } - ret = PyStr_FromStringAndSize((char *)blob.data, blob.length); + ret = Py_BuildValue(PYARG_BYTES_LEN, blob.data, blob.length); talloc_free(mem_ctx); return ret; } diff --git a/source4/ntvfs/posix/python/pyxattr_native.c b/source4/ntvfs/posix/python/pyxattr_native.c index c5e740fe577..168e53d8eb4 100644 --- a/source4/ntvfs/posix/python/pyxattr_native.c +++ b/source4/ntvfs/posix/python/pyxattr_native.c @@ -41,7 +41,7 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) Py_ssize_t blobsize; DATA_BLOB blob; - if (!PyArg_ParseTuple(args, "sss#", &filename, &attribute, &blob.data, + if (!PyArg_ParseTuple(args, "ss"PYARG_BYTES_LEN, &filename, &attribute, &blob.data, &blobsize)) return NULL; @@ -90,7 +90,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) talloc_free(mem_ctx); return NULL; } - ret = PyStr_FromStringAndSize(buf, len); + ret = Py_BuildValue(PYARG_BYTES_LEN, buf, len); talloc_free(mem_ctx); return ret; } diff --git a/source4/ntvfs/posix/python/pyxattr_tdb.c b/source4/ntvfs/posix/python/pyxattr_tdb.c index 05303b6aa00..8728054f943 100644 --- a/source4/ntvfs/posix/python/pyxattr_tdb.c +++ b/source4/ntvfs/posix/python/pyxattr_tdb.c @@ -50,7 +50,7 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) struct file_id id; struct stat sbuf; - if (!PyArg_ParseTuple(args, "ssss#", &tdbname, &filename, &attribute, + if (!PyArg_ParseTuple(args, "sss"PYARG_BYTES_LEN, &tdbname, &filename, &attribute, &blob.data, &blobsize)) return NULL; @@ -137,7 +137,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) talloc_free(mem_ctx); return NULL; } - ret_obj = PyStr_FromStringAndSize((char *)blob.data, xattr_size); + ret_obj = Py_BuildValue(PYARG_BYTES_LEN, blob.data, xattr_size); talloc_free(mem_ctx); return ret_obj; } From 287a306f8aa6d4e1d6cd21d6103a60d64f9b9879 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 6 Mar 2018 15:03:57 +0000 Subject: [PATCH 16/41] samba python tests: enable samba.tests.posixacl for python3 Signed-off-by: Noel Power --- source4/selftest/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index b882502be75..cb5bbff7c07 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -806,8 +806,8 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex ) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.upgradeprovisionneeddc") -planpythontestsuite("ad_dc:local", "samba.tests.posixacl") -planpythontestsuite("ad_dc_no_nss:local", "samba.tests.posixacl") +planpythontestsuite("ad_dc:local", "samba.tests.posixacl", py3_compatible=True) +planpythontestsuite("ad_dc_no_nss:local", "samba.tests.posixacl", py3_compatible=True) plantestsuite_loadlist("samba4.deletetest.python(ad_dc_ntvfs)", "ad_dc_ntvfs", [python, os.path.join(samba4srcdir, "dsdb/tests/python/deletetest.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '$LOADLIST', '$LISTOPT']) plantestsuite("samba4.blackbox.samba3dump", "none", [os.path.join(samba4srcdir, "selftest/test_samba3dump.sh")]) From f7c7e087d81a326261fe9e70430e414c44722fde Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 28 Mar 2018 10:33:12 +0100 Subject: [PATCH 17/41] samba python tests: enable samba.tests.ntacls for python3 Signed-off-by: Noel Power --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index 1dbbb0e5fc2..c3def9432ed 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -147,7 +147,7 @@ '$PREFIX_ABS/provision', configuration]) planpythontestsuite("none", "samba.tests.upgradeprovision") planpythontestsuite("none", "samba.tests.xattr", py3_compatible=True) -planpythontestsuite("none", "samba.tests.ntacls") +planpythontestsuite("none", "samba.tests.ntacls", py3_compatible=True) planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph") planpythontestsuite("none", "samba.tests.kcc.graph_utils") From e366f2104bae9119bc650c5ae50e3d411370eb48 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 10:56:20 +0000 Subject: [PATCH 18/41] python3 port for provision.c Signed-off-by: Noel Power --- source4/param/provision.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/source4/param/provision.c b/source4/param/provision.c index e1e5380ad24..4dab31f5c20 100644 --- a/source4/param/provision.c +++ b/source4/param/provision.c @@ -19,6 +19,7 @@ */ #include +#include "python/py3compat.h" #include #include #include "includes.h" @@ -32,7 +33,7 @@ static PyObject *provision_module(void) { - PyObject *name = PyString_FromString("samba.provision"); + PyObject *name = PyStr_FromString("samba.provision"); if (name == NULL) return NULL; return PyImport_Import(name); @@ -40,7 +41,7 @@ static PyObject *provision_module(void) static PyObject *schema_module(void) { - PyObject *name = PyString_FromString("samba.schema"); + PyObject *name = PyStr_FromString("samba.schema"); if (name == NULL) return NULL; return PyImport_Import(name); @@ -48,7 +49,7 @@ static PyObject *schema_module(void) static PyObject *ldb_module(void) { - PyObject *name = PyString_FromString("ldb"); + PyObject *name = PyStr_FromString("ldb"); if (name == NULL) return NULL; return PyImport_Import(name); @@ -123,46 +124,46 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, configfile = lpcfg_configfile(lp_ctx); if (configfile != NULL) { PyDict_SetItemString(parameters, "smbconf", - PyString_FromString(configfile)); + PyStr_FromString(configfile)); } PyDict_SetItemString(parameters, "rootdn", - PyString_FromString(settings->root_dn_str)); + PyStr_FromString(settings->root_dn_str)); if (settings->targetdir != NULL) PyDict_SetItemString(parameters, "targetdir", - PyString_FromString(settings->targetdir)); + PyStr_FromString(settings->targetdir)); PyDict_SetItemString(parameters, "hostname", - PyString_FromString(settings->netbios_name)); + PyStr_FromString(settings->netbios_name)); PyDict_SetItemString(parameters, "domain", - PyString_FromString(settings->domain)); + PyStr_FromString(settings->domain)); PyDict_SetItemString(parameters, "realm", - PyString_FromString(settings->realm)); + PyStr_FromString(settings->realm)); if (settings->root_dn_str) PyDict_SetItemString(parameters, "rootdn", - PyString_FromString(settings->root_dn_str)); + PyStr_FromString(settings->root_dn_str)); if (settings->domain_dn_str) PyDict_SetItemString(parameters, "domaindn", - PyString_FromString(settings->domain_dn_str)); + PyStr_FromString(settings->domain_dn_str)); if (settings->schema_dn_str) PyDict_SetItemString(parameters, "schemadn", - PyString_FromString(settings->schema_dn_str)); + PyStr_FromString(settings->schema_dn_str)); if (settings->config_dn_str) PyDict_SetItemString(parameters, "configdn", - PyString_FromString(settings->config_dn_str)); + PyStr_FromString(settings->config_dn_str)); if (settings->server_dn_str) PyDict_SetItemString(parameters, "serverdn", - PyString_FromString(settings->server_dn_str)); + PyStr_FromString(settings->server_dn_str)); if (settings->site_name) PyDict_SetItemString(parameters, "sitename", - PyString_FromString(settings->site_name)); + PyStr_FromString(settings->site_name)); PyDict_SetItemString(parameters, "machinepass", - PyString_FromString(settings->machine_password)); + PyStr_FromString(settings->machine_password)); PyDict_SetItemString(parameters, "debuglevel", PyInt_FromLong(DEBUGLEVEL)); @@ -179,7 +180,7 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, return NT_STATUS_UNSUCCESSFUL; } - result->domaindn = talloc_strdup(mem_ctx, PyString_AsString(PyObject_GetAttrString(py_result, "domaindn"))); + result->domaindn = talloc_strdup(mem_ctx, PyStr_AsString(PyObject_GetAttrString(py_result, "domaindn"))); /* FIXME paths */ py_lp_ctx = PyObject_GetAttrString(py_result, "lp"); @@ -279,15 +280,15 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context PyDict_SetItemString(parameters, "secretsdb", PyLdb_FromLdbContext(ldb)); PyDict_SetItemString(parameters, "domain", - PyString_FromString(settings->domain_name)); + PyStr_FromString(settings->domain_name)); if (settings->realm != NULL) { PyDict_SetItemString(parameters, "realm", - PyString_FromString(settings->realm)); + PyStr_FromString(settings->realm)); } PyDict_SetItemString(parameters, "machinepass", - PyString_FromString(settings->machine_password)); + PyStr_FromString(settings->machine_password)); PyDict_SetItemString(parameters, "netbiosname", - PyString_FromString(settings->netbios_name)); + PyStr_FromString(settings->netbios_name)); py_sid = py_dom_sid_FromSid(settings->domain_sid); if (py_sid == NULL) { @@ -371,12 +372,12 @@ struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, if (schema_dn) { PyDict_SetItemString(parameters, "schemadn", - PyString_FromString(schema_dn)); + PyStr_FromString(schema_dn)); } if (override_prefixmap) { PyDict_SetItemString(parameters, "override_prefixmap", - PyString_FromStringAndSize((const char *)override_prefixmap->data, + PyStr_FromStringAndSize((const char *)override_prefixmap->data, override_prefixmap->length)); } From b323551cf7571f63cb0a9aa546e0ec1626c88bd7 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Mar 2018 16:08:01 +0000 Subject: [PATCH 19/41] get make test TESTS=samba.tests.provision to work Signed-off-by: Noel Power --- python/samba/ms_schema.py | 14 +++++++------- python/samba/tests/provision.py | 2 +- selftest/tests.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/python/samba/ms_schema.py b/python/samba/ms_schema.py index 12a9909737f..889b7f5ef22 100644 --- a/python/samba/ms_schema.py +++ b/python/samba/ms_schema.py @@ -69,13 +69,13 @@ # ADTS: 3.1.1.2.2.2 oMObjectClassBER = { - '1.3.12.2.1011.28.0.702' : base64.b64encode('\x2B\x0C\x02\x87\x73\x1C\x00\x85\x3E'), - '1.2.840.113556.1.1.1.12': base64.b64encode('\x2A\x86\x48\x86\xF7\x14\x01\x01\x01\x0C'), - '2.6.6.1.2.5.11.29' : base64.b64encode('\x56\x06\x01\x02\x05\x0B\x1D'), - '1.2.840.113556.1.1.1.11': base64.b64encode('\x2A\x86\x48\x86\xF7\x14\x01\x01\x01\x0B'), - '1.3.12.2.1011.28.0.714' : base64.b64encode('\x2B\x0C\x02\x87\x73\x1C\x00\x85\x4A'), - '1.3.12.2.1011.28.0.732' : base64.b64encode('\x2B\x0C\x02\x87\x73\x1C\x00\x85\x5C'), - '1.2.840.113556.1.1.1.6' : base64.b64encode('\x2A\x86\x48\x86\xF7\x14\x01\x01\x01\x06') + '1.3.12.2.1011.28.0.702' : base64.b64encode(b'\x2B\x0C\x02\x87\x73\x1C\x00\x85\x3E').decode('utf8'), + '1.2.840.113556.1.1.1.12': base64.b64encode(b'\x2A\x86\x48\x86\xF7\x14\x01\x01\x01\x0C').decode('utf8'), + '2.6.6.1.2.5.11.29' : base64.b64encode(b'\x56\x06\x01\x02\x05\x0B\x1D').decode('utf8'), + '1.2.840.113556.1.1.1.11': base64.b64encode(b'\x2A\x86\x48\x86\xF7\x14\x01\x01\x01\x0B').decode('utf8'), + '1.3.12.2.1011.28.0.714' : base64.b64encode(b'\x2B\x0C\x02\x87\x73\x1C\x00\x85\x4A').decode('utf8'), + '1.3.12.2.1011.28.0.732' : base64.b64encode(b'\x2B\x0C\x02\x87\x73\x1C\x00\x85\x5C').decode('utf8'), + '1.2.840.113556.1.1.1.6' : base64.b64encode(b'\x2A\x86\x48\x86\xF7\x14\x01\x01\x01\x06').decode('utf8') } # separated by commas in docs, and must be broken up diff --git a/python/samba/tests/provision.py b/python/samba/tests/provision.py index bada14f5936..eb6deb5755f 100644 --- a/python/samba/tests/provision.py +++ b/python/samba/tests/provision.py @@ -66,7 +66,7 @@ def test_setup_secretsdb(self): ldb = setup_secretsdb(paths, None, None, lp=env_loadparm()) try: self.assertEquals("LSA Secrets", - ldb.searchone(basedn="CN=LSA Secrets", attribute="CN")) + ldb.searchone(basedn="CN=LSA Secrets", attribute="CN").decode('utf8')) finally: del ldb os.unlink(path) diff --git a/selftest/tests.py b/selftest/tests.py index c3def9432ed..d930373d8b1 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -65,7 +65,7 @@ planpythontestsuite("none", "samba.tests.upgrade") planpythontestsuite("none", "samba.tests.core", py3_compatible=True) planpythontestsuite("none", "samba.tests.common") -planpythontestsuite("none", "samba.tests.provision") +planpythontestsuite("none", "samba.tests.provision", py3_compatible=True) planpythontestsuite("none", "samba.tests.password_quality") planpythontestsuite("none", "samba.tests.strings") planpythontestsuite("none", "samba.tests.netcmd") From 17982fc1d2d7eb4dcf0e5669bed61e3c70f1fc24 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 28 Mar 2018 15:08:40 +1300 Subject: [PATCH 20/41] samba3: work around bytes formatting for Python 3.4 b'%s\x00' % key The above % formatting for bytes is only available since Python 3.5, however we need to support Python 3.4 so far. Work around this with `+`. Signed-off-by: Joe Guo --- python/samba/samba3/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py index a0bb76f68c1..f7927836c98 100644 --- a/python/samba/samba3/__init__.py +++ b/python/samba/samba3/__init__.py @@ -87,7 +87,7 @@ def subkeys(self, key): :param key: Key path. :return: list with key names """ - data = self.db.get(b"%s\x00" % key) + data = self.db.get(key + b"\x00") if data is None: return [] (num, ) = struct.unpack(" Date: Wed, 28 Mar 2018 15:53:50 +1300 Subject: [PATCH 21/41] wscript_build: fix c modeuls deps name for Python 3 In wscript_build, the lib name in deps list may have postfix for Python 3. Instead of hard coding the base name directly, need to load correct name for each Python version with `bld.pyembed_libname`. Signed-off-by: Joe Guo --- source3/param/wscript_build | 3 ++- source3/passdb/wscript_build | 4 +++- source3/wscript_build | 4 +++- source4/lib/policy/wscript_build | 12 +++++++----- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/source3/param/wscript_build b/source3/param/wscript_build index c9c42a35625..d999d0b89f2 100644 --- a/source3/param/wscript_build +++ b/source3/param/wscript_build @@ -15,10 +15,11 @@ bld.SAMBA_GENERATOR('s3_param_proto_h', rule='${PYTHON} ${SRC[0].abspath(env)} --file ${SRC[1].abspath(env)} --output ${TGT} --mode=S3PROTO') for env in bld.gen_python_environments(): + pytalloc_util = bld.pyembed_libname('pytalloc-util') bld.SAMBA3_PYTHON('pys3param', source='pyparam.c', deps='smbconf', - public_deps='samba-hostconfig pytalloc-util talloc', + public_deps=' '.join(['samba-hostconfig', pytalloc_util, 'talloc']), realname='samba/samba3/param.so') bld.SAMBA3_SUBSYSTEM('param_service', diff --git a/source3/passdb/wscript_build b/source3/passdb/wscript_build index 0ae2c4def40..2a35392f209 100644 --- a/source3/passdb/wscript_build +++ b/source3/passdb/wscript_build @@ -33,9 +33,11 @@ bld.SAMBA3_MODULE('pdb_samba_dsdb', enabled=bld.SAMBA3_IS_ENABLED_MODULE('pdb_samba_dsdb') and bld.AD_DC_BUILD_IS_ENABLED()) for env in bld.gen_python_environments(): + pyrpc_util = bld.pyembed_libname('pyrpc_util') + pytalloc_util = bld.pyembed_libname('pytalloc-util') bld.SAMBA3_PYTHON('pypassdb', source='py_passdb.c', deps='pdb', - public_deps='samba-util tdb talloc pyrpc_util pytalloc-util', + public_deps=' '.join(['samba-util', 'tdb', 'talloc', pyrpc_util, pytalloc_util]), realname='samba/samba3/passdb.so' ) diff --git a/source3/wscript_build b/source3/wscript_build index f0eb23cc3f7..717dd9e3676 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -1298,9 +1298,11 @@ bld.SAMBA3_BINARY('vlp', for env in bld.gen_python_environments(): + pyrpc_util = bld.pyembed_libname('pyrpc_util') + pytalloc_util = bld.pyembed_libname('pytalloc-util') bld.SAMBA3_PYTHON('pysmbd', source='smbd/pysmbd.c', - deps='smbd_base pyrpc_util pytalloc-util', + deps=' '.join(['smbd_base', pyrpc_util, pytalloc_util]), realname='samba/samba3/smbd.so' ) diff --git a/source4/lib/policy/wscript_build b/source4/lib/policy/wscript_build index 832d0f45cf6..2c5abb13154 100644 --- a/source4/lib/policy/wscript_build +++ b/source4/lib/policy/wscript_build @@ -11,8 +11,10 @@ bld.SAMBA_LIBRARY('samba-policy', ) for env in bld.gen_python_environments(): - bld.SAMBA_PYTHON('py_policy', - source='pypolicy.c', - public_deps='samba-policy pytalloc-util', - realname='samba/policy.so' - ) + pytalloc_util = bld.pyembed_libname('pytalloc-util') + bld.SAMBA_PYTHON( + 'py_policy', + source='pypolicy.c', + public_deps=' '.join(['samba-policy', pytalloc_util]), + realname='samba/policy.so' + ) From 0786dffd8dc145c69126222419e6414711a71196 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 5 Apr 2018 14:49:25 +1200 Subject: [PATCH 22/41] selftest: enable py3 for samba.tests.posixacl Fix bytes and str issue. Signed-off-by: Joe Guo --- python/samba/tests/posixacl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/tests/posixacl.py b/python/samba/tests/posixacl.py index ef4ed77f13e..74cabf1bb70 100644 --- a/python/samba/tests/posixacl.py +++ b/python/samba/tests/posixacl.py @@ -82,7 +82,7 @@ def test_setntacl_invalidate_getntacl(self): # This should invalidate the ACL, as we include the posix ACL in the hash (backend_obj, dbname) = checkset_backend(self.lp, None, None) backend_obj.wrap_setxattr(dbname, - self.tempf, "system.fake_access_acl", "") + self.tempf, "system.fake_access_acl", b"") #however, as this is direct DB access, we do not notice it facl = getntacl(self.lp, self.tempf, direct_db_access=True) @@ -96,7 +96,7 @@ def test_setntacl_invalidate_getntacl_smbd(self): # This should invalidate the ACL, as we include the posix ACL in the hash (backend_obj, dbname) = checkset_backend(self.lp, None, None) backend_obj.wrap_setxattr(dbname, - self.tempf, "system.fake_access_acl", "") + self.tempf, "system.fake_access_acl", b"") #the hash would break, and we return an ACL based only on the mode, except we set the ACL using the 'ntvfs' mode that doesn't include a hash facl = getntacl(self.lp, self.tempf) @@ -112,7 +112,7 @@ def test_setntacl_smbd_invalidate_getntacl_smbd(self): # This should invalidate the ACL, as we include the posix ACL in the hash (backend_obj, dbname) = checkset_backend(self.lp, None, None) backend_obj.wrap_setxattr(dbname, - self.tempf, "system.fake_access_acl", "") + self.tempf, "system.fake_access_acl", b"") #the hash will break, and we return an ACL based only on the mode facl = getntacl(self.lp, self.tempf, direct_db_access=False) From 6758af50d6d0ce5b21c15e46bf60949c1db03da3 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 5 Apr 2018 14:49:55 +1200 Subject: [PATCH 23/41] selftest: enable py3 for samba.tests.xattr Fix bytes and str issue. Signed-off-by: Joe Guo --- python/samba/tests/xattr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/tests/xattr.py b/python/samba/tests/xattr.py index b024175a8d6..8e6178bed75 100644 --- a/python/samba/tests/xattr.py +++ b/python/samba/tests/xattr.py @@ -58,7 +58,7 @@ def test_set_and_get_native(self): if not samba.xattr_native.is_xattr_supported(): raise SkipTest() tempf = self._tmpfilename() - reftxt = "this is a test" + reftxt = b"this is a test" open(tempf, 'w').write("empty") try: samba.xattr_native.wrap_setxattr(tempf, "user.unittests", reftxt) @@ -96,7 +96,7 @@ def test_set_tdb_not_open(self): def test_set_and_get_tdb(self): tempf = self._tmpfilename() eadb_path = self._eadbpath() - reftxt = "this is a test" + reftxt = b"this is a test" open(tempf, 'w').write("empty") try: samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests", @@ -124,7 +124,7 @@ def test_set_posix_eadb(self): def test_set_and_get_posix_eadb(self): tempf = self._tmpfilename() eadb_path = self._eadbpath() - reftxt = "this is a test" + reftxt = b"this is a test" open(tempf, 'w').write("empty") try: samba.posix_eadb.wrap_setxattr(eadb_path, tempf, "user.unittests", From d50b107fab6e8371a50e8f0ce701e0295f3b035e Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Fri, 23 Mar 2018 14:10:28 +1300 Subject: [PATCH 24/41] selftest: enable py3 for samba.tests.blackbox.check_output convert bytes to str for Python 3 `BlackboxTestCase.check_output` will return bytes since it uses `subprocess.communicate` underneath. Convert expected string result to bytes for comparing. Signed-off-by: Joe Guo --- python/samba/tests/blackbox/check_output.py | 4 +++- selftest/tests.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/blackbox/check_output.py b/python/samba/tests/blackbox/check_output.py index d7e41a838b4..8b3643d492d 100644 --- a/python/samba/tests/blackbox/check_output.py +++ b/python/samba/tests/blackbox/check_output.py @@ -100,6 +100,8 @@ def test_check_output_with_large_output(self): try: with TimeoutHelper(10): actual = self.check_output(cmdline) - self.assertEqual(actual, expected) + # check_output will return bytes + # convert expected to bytes for python 3 + self.assertEqual(actual, expected.encode('utf-8')) except TimeoutHelper.Timeout: self.fail(msg='Timeout!') diff --git a/selftest/tests.py b/selftest/tests.py index d930373d8b1..4cb6e23446c 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -52,7 +52,7 @@ else: planpythontestsuite("none", "subunit.tests.test_suite") planpythontestsuite("none", "samba.tests.blackbox.ndrdump") -planpythontestsuite("none", "samba.tests.blackbox.check_output") +planpythontestsuite("none", "samba.tests.blackbox.check_output", py3_compatible=True) planpythontestsuite("none", "api", name="ldb.python", extra_path=['lib/ldb/tests/python']) planpythontestsuite("none", "samba.tests.credentials", py3_compatible=True) planpythontestsuite("none", "samba.tests.registry", py3_compatible=True) From ae746aae0f586ca63d430efa45d6c0a20bac6153 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Tue, 3 Apr 2018 14:29:26 +1200 Subject: [PATCH 25/41] selftest: enable py3 for samba.tests.upgrade `os.tempname` is removed in Python 3. Use `tempfile` instead. Signed-off-by: Joe Guo --- python/samba/tests/__init__.py | 4 +++- selftest/tests.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index 935a0873303..bc8c185769b 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -19,6 +19,7 @@ """Samba Python tests.""" import os +import tempfile import ldb import samba from samba import param @@ -254,7 +255,8 @@ class LdbTestCase(TestCase): def setUp(self): super(LdbTestCase, self).setUp() - self.filename = os.tempnam() + self.tempfile = tempfile.NamedTemporaryFile(delete=False) + self.filename = self.tempfile.name self.ldb = samba.Ldb(self.filename) def set_modules(self, modules=[]): diff --git a/selftest/tests.py b/selftest/tests.py index 4cb6e23446c..55c3d0f59f4 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -62,7 +62,7 @@ planpythontestsuite("none", "samba.tests.dcerpc.misc", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.integer") planpythontestsuite("none", "samba.tests.param", py3_compatible=True) -planpythontestsuite("none", "samba.tests.upgrade") +planpythontestsuite("none", "samba.tests.upgrade", py3_compatible=True) planpythontestsuite("none", "samba.tests.core", py3_compatible=True) planpythontestsuite("none", "samba.tests.common") planpythontestsuite("none", "samba.tests.provision", py3_compatible=True) From 361dd46d07403ce8afc45675272235a083a5c34c Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Tue, 3 Apr 2018 14:47:41 +1200 Subject: [PATCH 26/41] selftest: enable py3 for samba.tests.password_quality No change needed. Signed-off-by: Joe Guo --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index 55c3d0f59f4..72838f734db 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -66,7 +66,7 @@ planpythontestsuite("none", "samba.tests.core", py3_compatible=True) planpythontestsuite("none", "samba.tests.common") planpythontestsuite("none", "samba.tests.provision", py3_compatible=True) -planpythontestsuite("none", "samba.tests.password_quality") +planpythontestsuite("none", "samba.tests.password_quality", py3_compatible=True) planpythontestsuite("none", "samba.tests.strings") planpythontestsuite("none", "samba.tests.netcmd") planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc") From 833e75656ef4d06ef1bf31d420254712b3eba919 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 22 Mar 2018 11:20:55 +1300 Subject: [PATCH 27/41] selftest: enable py3 for samba.tests.dcerpc.integer Remove L for long integer for Python 3. NOTE: There is still a known failure in this testsuite, but not in the scope of py3 porting. Signed-off-by: Joe Guo --- python/samba/tests/dcerpc/integer.py | 10 +++++----- selftest/knownfail | 2 +- selftest/tests.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/samba/tests/dcerpc/integer.py b/python/samba/tests/dcerpc/integer.py index ca5d571b7e8..37e2355bc25 100644 --- a/python/samba/tests/dcerpc/integer.py +++ b/python/samba/tests/dcerpc/integer.py @@ -25,7 +25,7 @@ class IntegerTests(samba.tests.TestCase): def test_uint32_into_hyper(self): s = server_id.server_id() s.unique_id = server_id.NONCLUSTER_VNN - self.assertEquals(s.unique_id, 0xFFFFFFFFL) + self.assertEquals(s.unique_id, 0xFFFFFFFF) def test_int_into_hyper(self): s = server_id.server_id() @@ -63,7 +63,7 @@ def assign(): def test_long_into_int32(self): s = srvsvc.NetRemoteTODInfo() - s.timezone = 5L + s.timezone = 5 self.assertEquals(s.timezone, 5) def test_larger_long_int_into_int32(self): @@ -171,12 +171,12 @@ def test_negative_int_into_int64(self): def test_larger_int_into_int64(self): s = samr.DomInfo1() s.max_password_age = server_id.NONCLUSTER_VNN - self.assertEquals(s.max_password_age, 0xFFFFFFFFL) + self.assertEquals(s.max_password_age, 0xFFFFFFFF) def test_larger_negative_int_into_int64(self): s = samr.DomInfo1() s.max_password_age = -2147483649 - self.assertEquals(s.max_password_age, -2147483649L) + self.assertEquals(s.max_password_age, -2147483649) def test_int_list_over_list(self): g = misc.GUID() @@ -185,7 +185,7 @@ def test_int_list_over_list(self): def test_long_int_list_over_uint8_list(self): g = misc.GUID() - g.node = [5L, 0, 5, 0, 7, 4] + g.node = [5, 0, 5, 0, 7, 4] self.assertEqual(g.node[0], 5) def test_negative_list_over_uint8_list(self): diff --git a/selftest/knownfail b/selftest/knownfail index a2aeed2690d..38ebf3a77f3 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -267,7 +267,7 @@ # This fails because our python bindings create python Lists, not a type # we can watch for set methods on. # -^samba.tests.dcerpc.integer.samba.tests.dcerpc.integer.IntegerTests.test_.*_into_uint8_list +^samba.tests.dcerpc.integer.*samba.tests.dcerpc.integer.IntegerTests.test_.*_into_uint8_list # # Samba sort takes a primative approach to unicode sort. These tests # match Windows 2012R2 behaviour. diff --git a/selftest/tests.py b/selftest/tests.py index 72838f734db..3ef24bca0c2 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -60,7 +60,7 @@ planpythontestsuite("none", "samba.tests.get_opt", py3_compatible=True) planpythontestsuite("none", "samba.tests.security", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.misc", py3_compatible=True) -planpythontestsuite("none", "samba.tests.dcerpc.integer") +planpythontestsuite("none", "samba.tests.dcerpc.integer", py3_compatible=True) planpythontestsuite("none", "samba.tests.param", py3_compatible=True) planpythontestsuite("none", "samba.tests.upgrade", py3_compatible=True) planpythontestsuite("none", "samba.tests.core", py3_compatible=True) From e18ab3c88f0aaf2462f7bf326a8deca823c80273 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Tue, 3 Apr 2018 15:11:48 +1200 Subject: [PATCH 28/41] selftest: enable py3 for samba.tests.dcerpc.rpc_talloc No changes needed. Signed-off-by: Joe Guo --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index 3ef24bca0c2..b3a774720e0 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -69,7 +69,7 @@ planpythontestsuite("none", "samba.tests.password_quality", py3_compatible=True) planpythontestsuite("none", "samba.tests.strings") planpythontestsuite("none", "samba.tests.netcmd") -planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc") +planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.array") planpythontestsuite("none", "samba.tests.dcerpc.string") planpythontestsuite("none", "samba.tests.hostconfig") From ddc7bae953b91e0149edfcaca947c3d804657517 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Tue, 3 Apr 2018 15:13:09 +1200 Subject: [PATCH 29/41] selftest: enable py3 for samba.tests.dcerpc.array No change needed. Signed-off-by: Joe Guo --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index b3a774720e0..a4173d7c9c1 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -70,7 +70,7 @@ planpythontestsuite("none", "samba.tests.strings") planpythontestsuite("none", "samba.tests.netcmd") planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc", py3_compatible=True) -planpythontestsuite("none", "samba.tests.dcerpc.array") +planpythontestsuite("none", "samba.tests.dcerpc.array", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.string") planpythontestsuite("none", "samba.tests.hostconfig") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging", From 92909bb6d720684fbae4bd8599c08b45feab9814 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Tue, 3 Apr 2018 15:15:12 +1200 Subject: [PATCH 30/41] selftest: enable py3 for samba.tests.dcerpc.string No change needed. Signed-off-by: Joe Guo --- selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest/tests.py b/selftest/tests.py index a4173d7c9c1..b17dfb6b90d 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -71,7 +71,7 @@ planpythontestsuite("none", "samba.tests.netcmd") planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.array", py3_compatible=True) -planpythontestsuite("none", "samba.tests.dcerpc.string") +planpythontestsuite("none", "samba.tests.dcerpc.string", py3_compatible=True) planpythontestsuite("none", "samba.tests.hostconfig") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging", py3_compatible=True) From 3e6e5288e7b55b4d79a9ea5b4753135ea74c7063 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Mon, 26 Mar 2018 17:07:33 +1300 Subject: [PATCH 31/41] selftest: enable py3 for samba.tests.common fix dsdb_Dn comparison for Python 3 In Python 3, the builtin `cmp` funtion was dropped. And the `__cmp__` magic method in object is no longer honored, which is replaced by 6 new methods: __eq__, __ne__, __lt__, __le__, __gt__, __ge__. This caused `tests.CommonTests` failed with `py3_compatiable=True`. Fixed by adding the above methods. Signed-off-by: Joe Guo --- python/samba/common.py | 27 +++++++++++++++++++++++++++ selftest/tests.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/python/samba/common.py b/python/samba/common.py index 1c410a4702d..66003993730 100644 --- a/python/samba/common.py +++ b/python/samba/common.py @@ -23,6 +23,14 @@ from samba.dcerpc import misc import binascii +from samba.compat import PY3 + + +if PY3: + # cmp() exists only in Python 2 + def cmp(a, b): + return (a > b) - (a < b) + def confirm(msg, forced=False, allow_all=False): """confirm an action with the user @@ -110,6 +118,25 @@ def __cmp__(self, other): v = cmp(dn1.binary, dn2.binary) return v + # In Python3, __cmp__ is replaced by these 6 methods + def __eq__(self, other): + return self.__cmp__(other) == 0 + + def __ne__(self, other): + return self.__cmp__(other) != 0 + + def __lt__(self, other): + return self.__cmp__(other) < 0 + + def __le__(self, other): + return self.__cmp__(other) <= 0 + + def __gt__(self, other): + return self.__cmp__(other) > 0 + + def __ge__(self, other): + return self.__cmp__(other) >= 0 + def get_binary_integer(self): '''return binary part of a dsdb_Dn as an integer, or None''' if self.prefix == '': diff --git a/selftest/tests.py b/selftest/tests.py index b17dfb6b90d..12d0a188cf5 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -64,7 +64,7 @@ planpythontestsuite("none", "samba.tests.param", py3_compatible=True) planpythontestsuite("none", "samba.tests.upgrade", py3_compatible=True) planpythontestsuite("none", "samba.tests.core", py3_compatible=True) -planpythontestsuite("none", "samba.tests.common") +planpythontestsuite("none", "samba.tests.common", py3_compatible=True) planpythontestsuite("none", "samba.tests.provision", py3_compatible=True) planpythontestsuite("none", "samba.tests.password_quality", py3_compatible=True) planpythontestsuite("none", "samba.tests.strings") From d391d41b3dbd31284475b102c2348bd17028ea4f Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Tue, 3 Apr 2018 15:24:28 +1200 Subject: [PATCH 32/41] selftest: enable py3 for samba.tests.hostconfig Fix relative import. Signed-off-by: Joe Guo --- python/samba/hostconfig.py | 4 ++-- selftest/tests.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/hostconfig.py b/python/samba/hostconfig.py index a66fbc23130..08fff4fdd4c 100644 --- a/python/samba/hostconfig.py +++ b/python/samba/hostconfig.py @@ -16,8 +16,8 @@ # """Local host configuration.""" - -from samdb import SamDB +from __future__ import absolute_import +from .samdb import SamDB class Hostconfig(object): """Aggregate object that contains all information about the configuration diff --git a/selftest/tests.py b/selftest/tests.py index 12d0a188cf5..34a6c502f40 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -72,7 +72,7 @@ planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.array", py3_compatible=True) planpythontestsuite("none", "samba.tests.dcerpc.string", py3_compatible=True) -planpythontestsuite("none", "samba.tests.hostconfig") +planpythontestsuite("none", "samba.tests.hostconfig", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3param", py3_compatible=True) From a4018ae6762b7d4de43ac0f617a53028c0f5fb33 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 10:44:31 +1200 Subject: [PATCH 33/41] selftest: enable py3 for samba.tests.samba3sam Fix bytes and string issues. Signed-off-by: Joe Guo --- python/samba/tests/samba3sam.py | 14 +++++++------- selftest/tests.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python/samba/tests/samba3sam.py b/python/samba/tests/samba3sam.py index 2fb4f13cfa6..8ede51c235b 100644 --- a/python/samba/tests/samba3sam.py +++ b/python/samba/tests/samba3sam.py @@ -130,7 +130,7 @@ def tearDown(self): def assertSidEquals(self, text, ndr_sid): sid_obj1 = samba.ndr.ndr_unpack(samba.dcerpc.security.dom_sid, - str(ndr_sid[0])) + ndr_sid[0]) sid_obj2 = samba.dcerpc.security.dom_sid(text) self.assertEquals(sid_obj1, sid_obj2) @@ -176,7 +176,7 @@ def test_mapped_containing_sid(self): self.assertSidEquals("S-1-5-21-4231626423-2410014848-2360679739-1052", msg[0]["objectSid"]) oc = set(msg[0]["objectClass"]) - self.assertEquals(oc, set(["group"])) + self.assertEquals(oc, set([b"group"])) def test_search_by_objclass(self): """Looking up by objectClass""" @@ -536,11 +536,11 @@ def test_map_search(self): self.assertEquals(str(res[0].dn), self.samba4.dn("cn=A")) self.assertTrue(not "dnsHostName" in res[0]) self.assertEquals(str(res[0]["lastLogon"]), "x") - self.assertEquals(str(res[0]["objectClass"][0]), "user") + self.assertEquals(res[0]["objectClass"][0], b"user") self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X")) self.assertEquals(str(res[1]["dnsHostName"]), "x") self.assertEquals(str(res[1]["lastLogon"]), "x") - self.assertEquals(str(res[1]["objectClass"][0]), "user") + self.assertEquals(res[1]["objectClass"][0], b"user") # Prove that the objectClass is actually used for the search res = self.ldb.search(expression="(|(objectClass=user)(badPwdCount=x))", @@ -550,15 +550,15 @@ def test_map_search(self): self.assertEquals(str(res[0].dn), self.samba4.dn("cn=A")) self.assertTrue(not "dnsHostName" in res[0]) self.assertEquals(str(res[0]["lastLogon"]), "x") - self.assertEquals(res[0]["objectClass"][0], "user") + self.assertEquals(res[0]["objectClass"][0], b"user") self.assertEquals(str(res[1].dn), self.samba4.dn("cn=B")) self.assertTrue(not "dnsHostName" in res[1]) self.assertEquals(str(res[1]["lastLogon"]), "y") - self.assertEquals(set(res[1]["objectClass"]), set(["top"])) + self.assertEquals(set(res[1]["objectClass"]), set([b"top"])) self.assertEquals(str(res[2].dn), self.samba4.dn("cn=X")) self.assertEquals(str(res[2]["dnsHostName"]), "x") self.assertEquals(str(res[2]["lastLogon"]), "x") - self.assertEquals(str(res[2]["objectClass"][0]), "user") + self.assertEquals(res[2]["objectClass"][0], b"user") # Testing search by parse tree diff --git a/selftest/tests.py b/selftest/tests.py index 34a6c502f40..d23861cb29b 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -80,7 +80,7 @@ planpythontestsuite("none", "samba.tests.s3registry", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3windb", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3idmapdb", py3_compatible=True) -planpythontestsuite("none", "samba.tests.samba3sam") +planpythontestsuite("none", "samba.tests.samba3sam", py3_compatible=True) planpythontestsuite( "none", "wafsamba.tests.test_suite", extra_path=[os.path.join(samba4srcdir, "..", "buildtools"), From 88192fd2830a6d2536416156acd766b5655340a3 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 11:19:48 +1200 Subject: [PATCH 34/41] selftest: enable py3 for samba.tests.upgradeprovision 1. `has_key` was removed from dict in Python 3, use `in` instead. 2. `cmp` was removed in Python 3, define it ourselves. Signed-off-by: Joe Guo --- python/samba/descriptor.py | 16 ++++++++-------- python/samba/upgradehelpers.py | 3 ++- selftest/tests.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/python/samba/descriptor.py b/python/samba/descriptor.py index cf797cc3e94..a9c5e1580f0 100644 --- a/python/samba/descriptor.py +++ b/python/samba/descriptor.py @@ -543,23 +543,23 @@ def get_diff_sds(refsd, cursd, domainsid, checkSacl = True): hash_cur = chunck_sddl(cursddl) hash_ref = chunck_sddl(refsddl) - if not hash_cur.has_key("owner"): + if "owner" not in hash_cur: txt = "\tNo owner in current SD" - elif hash_ref.has_key("owner") and hash_cur["owner"] != hash_ref["owner"]: + elif "owner" in hash_ref and hash_cur["owner"] != hash_ref["owner"]: txt = "\tOwner mismatch: %s (in ref) %s" \ "(in current)\n" % (hash_ref["owner"], hash_cur["owner"]) - if not hash_cur.has_key("group"): + if "group" not in hash_cur: txt = "%s\tNo group in current SD" % txt - elif hash_ref.has_key("group") and hash_cur["group"] != hash_ref["group"]: + elif "group" in hash_ref and hash_cur["group"] != hash_ref["group"]: txt = "%s\tGroup mismatch: %s (in ref) %s" \ "(in current)\n" % (txt, hash_ref["group"], hash_cur["group"]) - parts = [ "dacl" ] + parts = ["dacl"] if checkSacl: parts.append("sacl") for part in parts: - if hash_cur.has_key(part) and hash_ref.has_key(part): + if part in hash_cur and part in hash_ref: # both are present, check if they contain the same ACE h_cur = set() @@ -590,9 +590,9 @@ def get_diff_sds(refsd, cursd, domainsid, checkSacl = True): txt = "%s\t\t%s ACE is not present in the" \ " current\n" % (txt, item) - elif hash_cur.has_key(part) and not hash_ref.has_key(part): + elif part in hash_cur and part not in hash_ref: txt = "%s\tReference ACL hasn't a %s part\n" % (txt, part) - elif not hash_cur.has_key(part) and hash_ref.has_key(part): + elif part not in hash_cur and part in hash_ref: txt = "%s\tCurrent ACL hasn't a %s part\n" % (txt, part) return txt diff --git a/python/samba/upgradehelpers.py b/python/samba/upgradehelpers.py index a1ec804597c..e219602e0c7 100644 --- a/python/samba/upgradehelpers.py +++ b/python/samba/upgradehelpers.py @@ -282,6 +282,7 @@ def dn_sort(x, y): len1 = len(tab1)-1 len2 = len(tab2)-1 # Note: python range go up to upper limit but do not include it + cmp = lambda x, y: (x > y) - (x < y) # cmp is removed in py3 for i in range(0, minimum): ret = cmp(tab1[len1-i], tab2[len2-i]) if ret != 0: @@ -351,7 +352,7 @@ def update_secrets(newsecrets_ldb, secrets_ldb, messagefunc): hash[str(current[i]["dn"]).lower()] = current[i]["dn"] for k in hash_new.keys(): - if not hash.has_key(k): + if k not in hash: listMissing.append(hash_new[k]) else: listPresent.append(hash_new[k]) diff --git a/selftest/tests.py b/selftest/tests.py index d23861cb29b..b725bbc0361 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -145,7 +145,7 @@ ["PYTHON=%s" % python, os.path.join(bbdir, "functionalprep.sh"), '$PREFIX_ABS/provision', configuration]) -planpythontestsuite("none", "samba.tests.upgradeprovision") +planpythontestsuite("none", "samba.tests.upgradeprovision", py3_compatible=True) planpythontestsuite("none", "samba.tests.xattr", py3_compatible=True) planpythontestsuite("none", "samba.tests.ntacls", py3_compatible=True) planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) From 01f0506a2dee848344c5be0e982d4d2f31ca9100 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 11:29:41 +1200 Subject: [PATCH 35/41] selftest: enable py3 for samba.tests.kcc.graph In Python 3, range() will not return a list any more. So `range(7) * 4` will not work. Convert range to list to fix. Signed-off-by: Joe Guo --- python/samba/tests/kcc/graph.py | 6 +++--- selftest/tests.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/python/samba/tests/kcc/graph.py b/python/samba/tests/kcc/graph.py index dec861a9de5..31db853a40f 100644 --- a/python/samba/tests/kcc/graph.py +++ b/python/samba/tests/kcc/graph.py @@ -53,8 +53,8 @@ def test_total_schedule(self): ([0xff] * 84, 84 * 8), ([0xaa] * 84, 84 * 4), ([0x03, 0x33] * 42, 42 * 6), - (range(7) * 12, 12 * 9), - (range(4) * 21, 21 * 4)): + (list(range(7)) * 12, 12 * 9), + (list(range(4)) * 21, 21 * 4)): self.assertEquals(total_schedule(schedule), total) def test_convert_schedule_to_repltimes(self): @@ -63,7 +63,7 @@ def test_convert_schedule_to_repltimes(self): (None, [0x11] * 84), ([0x06] * 168, [0x66] * 84), ([0x03, 0xa] * 84, [0x3a] * 84), - (range(7) * 24, + (list(range(7)) * 24, [0x01, 0x23, 0x45, 0x60, 0x12, 0x34, 0x56] * 12)): schedule = ntdsconn_schedule(ntdsconn_times) self.assertEquals(convert_schedule_to_repltimes(schedule), diff --git a/selftest/tests.py b/selftest/tests.py index b725bbc0361..e508336bbcf 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -148,8 +148,8 @@ planpythontestsuite("none", "samba.tests.upgradeprovision", py3_compatible=True) planpythontestsuite("none", "samba.tests.xattr", py3_compatible=True) planpythontestsuite("none", "samba.tests.ntacls", py3_compatible=True) -planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) -planpythontestsuite("none", "samba.tests.kcc.graph") +planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) +planpythontestsuite("none", "samba.tests.kcc.graph", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph_utils") planpythontestsuite("none", "samba.tests.kcc.ldif_import_export") planpythontestsuite("none", "samba.tests.graph") From 427853cc2c8c91151da9907dd35aa4b9681afdec Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 13:07:38 +1200 Subject: [PATCH 36/41] selftest: enable py3 for samba.tests.kcc.graph_utils zip will not return a list in Python 3. Convert to list. Signed-off-by: Joe Guo --- python/samba/tests/kcc/graph_utils.py | 2 +- selftest/tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/kcc/graph_utils.py b/python/samba/tests/kcc/graph_utils.py index 2146fc9c7e1..b027838e78f 100644 --- a/python/samba/tests/kcc/graph_utils.py +++ b/python/samba/tests/kcc/graph_utils.py @@ -54,7 +54,7 @@ def setUp(self): vertices2 = tuple('ijk') edges = tuple(itertools.combinations(vertices, 2)) edges2 = tuple(itertools.combinations(vertices2, 2)) - line_edges = zip(vertices[1:], vertices[:-1]) + line_edges = list(zip(vertices[1:], vertices[:-1])) ring_edges = line_edges + [(vertices[0], vertices[-1])] tree = make_tree(vertices) diff --git a/selftest/tests.py b/selftest/tests.py index e508336bbcf..af0f7acb7ec 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -150,7 +150,7 @@ planpythontestsuite("none", "samba.tests.ntacls", py3_compatible=True) planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph", py3_compatible=True) -planpythontestsuite("none", "samba.tests.kcc.graph_utils") +planpythontestsuite("none", "samba.tests.kcc.graph_utils", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.ldif_import_export") planpythontestsuite("none", "samba.tests.graph") plantestsuite("wafsamba.duplicate_symbols", "none", [os.path.join(srcdir(), "buildtools/wafsamba/test_duplicate_symbol.sh")]) From 7d871c37750f7965be6d1f97e47b27bfee54b349 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 16:13:58 +1200 Subject: [PATCH 37/41] selftest: enable py3 for samba.tests.kcc.ldif_import_export Fixed a few py3 porting issues: 1. the `cmp` keyword arg was removed from `list.sort` and `sorted`, use the second keyword arg `key` for comparison. 2. explicitly implement `__hash__` for InternalEdge object, then it can be used as key in dict. 3. `str.translate(table, deletedchars)` changed to `str.translate(table)`, `deletedchars` was deleted. Use `replace` for deleting purpose. 4. dict.keys(), dict.values(), zip will not return list, convert to list explicitly. 5. data from ldb module are bytes, decode to unicode before usage. 6. divide(/) will return float in Python 3, use `//` to get integer. Signed-off-by: Joe Guo --- python/samba/common.py | 3 +++ python/samba/kcc/__init__.py | 16 ++-------------- python/samba/kcc/graph.py | 5 +++++ python/samba/kcc/graph_utils.py | 4 ++-- python/samba/kcc/kcc_utils.py | 17 +++++++---------- python/samba/tests/kcc/ldif_import_export.py | 4 ++-- selftest/tests.py | 2 +- 7 files changed, 22 insertions(+), 29 deletions(-) diff --git a/python/samba/common.py b/python/samba/common.py index 66003993730..66cce190f7f 100644 --- a/python/samba/common.py +++ b/python/samba/common.py @@ -77,6 +77,9 @@ class dsdb_Dn(object): def __init__(self, samdb, dnstring, syntax_oid=None): '''create a dsdb_Dn''' + if PY3: + if type(dnstring) == bytes: + dnstring = dnstring.decode('utf-8') if syntax_oid is None: # auto-detect based on string if dnstring.startswith("B:"): diff --git a/python/samba/kcc/__init__.py b/python/samba/kcc/__init__.py index f0046630fcf..8703d0cff19 100644 --- a/python/samba/kcc/__init__.py +++ b/python/samba/kcc/__init__.py @@ -46,18 +46,6 @@ from samba.kcc import debug -def sort_replica_by_dsa_guid(rep1, rep2): - """Helper to sort NCReplicas by their DSA guids - - The guids need to be sorted in their NDR form. - - :param rep1: An NC replica - :param rep2: Another replica - :return: -1, 0, or 1, indicating sort order. - """ - return cmp(ndr_pack(rep1.rep_dsa_guid), ndr_pack(rep2.rep_dsa_guid)) - - def sort_dsa_by_gc_and_guid(dsa1, dsa2): """Helper to sort DSAs by guid global catalog status @@ -286,7 +274,7 @@ def load_my_dsa(self): scope=ldb.SCOPE_BASE, attrs=["dsServiceName"]) dn = ldb.Dn(self.samdb, - service_name_res[0]["dsServiceName"][0]) + service_name_res[0]["dsServiceName"][0].decode()) res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, attrs=["objectGUID"]) @@ -2194,7 +2182,7 @@ def construct_intrasite_graph(self, site_local, dc_local, # on the local DC r_list.append(l_of_x) - r_list.sort(sort_replica_by_dsa_guid) + r_list.sort(key=lambda rep: ndr_pack(rep.rep_dsa_guid)) r_len = len(r_list) max_node_edges = self.intrasite_max_node_edges(r_len) diff --git a/python/samba/kcc/graph.py b/python/samba/kcc/graph.py index a0bff6997db..4920e2ee7ff 100644 --- a/python/samba/kcc/graph.py +++ b/python/samba/kcc/graph.py @@ -805,6 +805,11 @@ def __init__(self, v1, v2, redred, repl, eType, site_link): self.e_type = eType self.site_link = site_link + def __hash__(self): + return hash(tuple([ + self.v1, self.v2, self.red_red, self.repl_info, self.e_type, + self.site_link])) + def __eq__(self, other): return not self < other and not other < self diff --git a/python/samba/kcc/graph_utils.py b/python/samba/kcc/graph_utils.py index c564bee7a0a..086b6512201 100644 --- a/python/samba/kcc/graph_utils.py +++ b/python/samba/kcc/graph_utils.py @@ -32,7 +32,7 @@ def write_dot_file(basename, edge_list, vertices=None, label=None, s = dot_graph(vertices, edge_list, title=label, **kwargs) if label: # sanitise DN and guid labels - basename += '_' + label.translate(None, ', ') + basename += '_' + label.replace(', ', '') filename = os.path.join(dot_file_dir, "%s.dot" % basename) if debug is not None: @@ -235,7 +235,7 @@ def verify_graph_directed_double_ring(edges, vertices, edge_vertices): raise GraphError("wanted double directed ring, found a leaf node" "(%s)" % vertex) - for vertex in edge_map.keys(): + for vertex in list(edge_map.keys()): nset = edge_map[vertex] if not nset: continue diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py index a4870a3e7c8..953e73a154a 100644 --- a/python/samba/kcc/kcc_utils.py +++ b/python/samba/kcc/kcc_utils.py @@ -993,7 +993,7 @@ def load_connection(self, samdb): self.schedule = ndr_unpack(drsblobs.schedule, msg["schedule"][0]) if "whenCreated" in msg: - self.whenCreated = ldb.string_to_time(msg["whenCreated"][0]) + self.whenCreated = ldb.string_to_time(msg["whenCreated"][0].decode()) if "fromServer" in msg: dsdn = dsdb_Dn(samdb, msg["fromServer"][0]) @@ -1581,7 +1581,9 @@ def select_istg(self, samdb, mydsa, ro): # Which is a fancy way of saying "sort all the nTDSDSA objects # in the site by guid in ascending order". Place sorted list # in D_sort[] - D_sort = sorted(self.rw_dsa_table.values(), cmp=sort_dsa_by_guid) + D_sort = sorted( + self.rw_dsa_table.values(), + key=lambda dsa: ndr_pack(dsa.dsa_guid)) # double word number of 100 nanosecond intervals since 1600s @@ -1669,7 +1671,7 @@ def select_istg(self, samdb, mydsa, ro): # # Note: We don't want to divide by zero here so they must # have meant "f" instead of "o!interSiteTopologyFailover" - k_idx = (i_idx + ((self.nt_now - t_time) / f)) % len(D_sort) + k_idx = (i_idx + ((self.nt_now - t_time) // f)) % len(D_sort) # The local writable DC acts as an ISTG for its site if and # only if dk is the nTDSDSA object for the local DC. If the @@ -1917,10 +1919,10 @@ def load_transport(self, samdb): self.options = int(msg["options"][0]) if "transportAddressAttribute" in msg: - self.address_attr = str(msg["transportAddressAttribute"][0]) + self.address_attr = msg["transportAddressAttribute"][0].decode() if "name" in msg: - self.name = str(msg["name"][0]) + self.name = msg["name"][0].decode() if "bridgeheadServerListBL" in msg: for value in msg["bridgeheadServerListBL"]: @@ -2221,11 +2223,6 @@ def get_dsa_config_rep(dsa): dsa.dsa_dnstr) -def sort_dsa_by_guid(dsa1, dsa2): - "use ndr_pack for GUID comparison, as appears correct in some places""" - return cmp(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid)) - - def new_connection_schedule(): """Create a default schedule for an NTDSConnection or Sitelink. This is packed differently from the repltimes schedule used elsewhere diff --git a/python/samba/tests/kcc/ldif_import_export.py b/python/samba/tests/kcc/ldif_import_export.py index 6fb3ecd0c37..8c6c1f4ed96 100644 --- a/python/samba/tests/kcc/ldif_import_export.py +++ b/python/samba/tests/kcc/ldif_import_export.py @@ -104,7 +104,7 @@ def test_ldif_to_samdb(self): scope=ldb.SCOPE_BASE, attrs=["dsServiceName"]) dn = ldb.Dn(samdb, - service_name_res[0]["dsServiceName"][0]) + service_name_res[0]["dsServiceName"][0].decode()) self.assertEqual(dn, ldb.Dn(samdb, "CN=NTDS Settings," + dsa)) self.remove_files(dburl) @@ -128,7 +128,7 @@ def test_ldif_to_samdb_forced_local_dsa(self): scope=ldb.SCOPE_BASE, attrs=["dsServiceName"]) dn = ldb.Dn(samdb, - service_name_res[0]["dsServiceName"][0]) + service_name_res[0]["dsServiceName"][0].decode()) self.assertEqual(dn, ldb.Dn(samdb, "CN=NTDS Settings," + dsa)) self.remove_files(dburl) diff --git a/selftest/tests.py b/selftest/tests.py index af0f7acb7ec..8f9bee94a46 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -151,7 +151,7 @@ planpythontestsuite("none", "samba.tests.policy", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph_utils", py3_compatible=True) -planpythontestsuite("none", "samba.tests.kcc.ldif_import_export") +planpythontestsuite("none", "samba.tests.kcc.ldif_import_export", py3_compatible=True) planpythontestsuite("none", "samba.tests.graph") plantestsuite("wafsamba.duplicate_symbols", "none", [os.path.join(srcdir(), "buildtools/wafsamba/test_duplicate_symbol.sh")]) planpythontestsuite("none", "samba.tests.glue", py3_compatible=True) From 1ad428fb9038fcdb392a82050ac6b96538754786 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 17:03:19 +1200 Subject: [PATCH 38/41] selftest: enable py3 for samba.tests.graph 1. `iterkeys(), itervalues(), iteritems()` are removed from dict in Python 3. Use `keys(), values(), items()` instead, although inefficient in py2, but compatible. 2. `/` will return float in py3, use `//` keep consistent. 3. zip will not return list, convert to list explicitly. 4. `sorted` can not sort `None` with str in py3, use the `key` arg to fix. Signed-off-by: Joe Guo --- python/samba/graph.py | 8 ++++---- python/samba/tests/graph.py | 23 +++++++++++++---------- selftest/tests.py | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/python/samba/graph.py b/python/samba/graph.py index f626287800d..0cca240378c 100644 --- a/python/samba/graph.py +++ b/python/samba/graph.py @@ -463,11 +463,11 @@ def find_transitive_distance(vertices, edges): for i in range(inf): changed = False new_distances = {} - for v, d in distances.iteritems(): + for v, d in distances.items(): new_d = d.copy() new_distances[v] = new_d - for dest, cost in d.iteritems(): - for leaf, cost2 in distances[dest].iteritems(): + for dest, cost in d.items(): + for leaf, cost2 in distances[dest].items(): new_cost = cost + cost2 old_cost = d.get(leaf, inf) if new_cost < old_cost: @@ -497,7 +497,7 @@ def get_transitive_colourer(colours, n_vertices): n = 1 + int(n_vertices ** 0.5) def f(link): - return scale[min(link * m / n, m - 1)] + return scale[min(link * m // n, m - 1)] else: def f(link): diff --git a/python/samba/tests/graph.py b/python/samba/tests/graph.py index d1824bc3ef9..e42711fa14f 100644 --- a/python/samba/tests/graph.py +++ b/python/samba/tests/graph.py @@ -73,7 +73,7 @@ def assertEdges(self, lines, edges, directed): def test_basic_dot_files(self): vertices = tuple('abcdefgh') all_edges = tuple(itertools.combinations(vertices, 2)) - line_edges = zip(vertices[1:], vertices[:-1]) + line_edges = list(zip(vertices[1:], vertices[:-1])) ring_edges = line_edges + [(vertices[0], vertices[-1])] no_edges = [] # even join to even numbers, odd to odd @@ -101,6 +101,15 @@ def test_basic_dot_files(self): class DistanceTests(samba.tests.TestCase): + + def setUp(self): + super(DistanceTests, self).setUp() + # a sorted list of colour set names. + self.sorted_colour_sets = sorted( + graph.COLOUR_SETS, + # return '' for None, so it's sortable. + key=lambda name: name or '') + def test_simple_distance(self): edges = [('ant', 'bat'), ('cat', 'dog'), @@ -115,12 +124,10 @@ def test_simple_distance(self): ('cat', 'dog')] for utf8 in (True, False): - for colour in sorted(graph.COLOUR_SETS): + for colour in self.sorted_colour_sets: print('utf8 %s, colour %s' % (utf8, colour)) s = graph.distance_matrix(None, edges, utf8=utf8, colour=colour) - print(s) - print() def test_simple_distance2(self): edges = [('ant', 'bat'), @@ -129,12 +136,10 @@ def test_simple_distance2(self): ('ant', 'cat')] for utf8 in (True, False): - for colour in sorted(graph.COLOUR_SETS): + for colour in self.sorted_colour_sets: print('utf8 %s, colour %s' % (utf8, colour)) s = graph.distance_matrix(None, edges, utf8=utf8, colour=colour) - print(s) - print() def test_simple_distance3(self): edges = [('ant', 'bat'), @@ -144,9 +149,7 @@ def test_simple_distance3(self): ('dog', 'eel')] for utf8 in (True, False): - for colour in sorted(graph.COLOUR_SETS): + for colour in self.sorted_colour_sets: print('utf8 %s, colour %s' % (utf8, colour)) s = graph.distance_matrix(None, edges, utf8=utf8, colour=colour) - print(s) - print() diff --git a/selftest/tests.py b/selftest/tests.py index 8f9bee94a46..91f910c8fd6 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -152,7 +152,7 @@ planpythontestsuite("none", "samba.tests.kcc.graph", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.graph_utils", py3_compatible=True) planpythontestsuite("none", "samba.tests.kcc.ldif_import_export", py3_compatible=True) -planpythontestsuite("none", "samba.tests.graph") +planpythontestsuite("none", "samba.tests.graph", py3_compatible=True) plantestsuite("wafsamba.duplicate_symbols", "none", [os.path.join(srcdir(), "buildtools/wafsamba/test_duplicate_symbol.sh")]) planpythontestsuite("none", "samba.tests.glue", py3_compatible=True) planpythontestsuite("none", "samba.tests.tdb_util", py3_compatible=True) From 4ae6f4122c8180979b43c275b2e8298d81058526 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 5 Apr 2018 10:47:16 +1200 Subject: [PATCH 39/41] selftest: enable py3 for samba.tests.samdb_api Fix bytes and string. Signed-off-by: Joe Guo --- python/samba/tests/samdb_api.py | 20 ++++++++++---------- selftest/tests.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/python/samba/tests/samdb_api.py b/python/samba/tests/samdb_api.py index 259952031b5..c57da62410f 100644 --- a/python/samba/tests/samdb_api.py +++ b/python/samba/tests/samdb_api.py @@ -72,15 +72,15 @@ def test_dont_create_db_existing_non_tdb_file(self): # def test_create_db_existing_file_non_tdb_file(self): existing_name = self.tempdir + "/existing.db" - existing = open(existing_name, "w") - existing.write("This is not a tdb file!!!!!!") + existing = open(existing_name, "wb") + existing.write(b"This is not a tdb file!!!!!!") existing.close() SamDB(url="tdb://" + existing_name, flags=0) - existing = open(existing_name, "r") + existing = open(existing_name, "rb") contents = existing.readline() - self.assertEquals("TDB file\n", contents) + self.assertEquals(b"TDB file\n", contents) # # Attempt to open an existing tdb file as a tdb file. @@ -99,11 +99,11 @@ def test_dont_create_db_existing_tdb_file(self): }) cn = initial.searchone("cn", dn) - self.assertEquals("test_dont_create_db_existing_tdb_file", cn) + self.assertEquals(b"test_dont_create_db_existing_tdb_file", cn) second = SamDB(url="tdb://" + existing_name) cn = second.searchone("cn", dn) - self.assertEquals("test_dont_create_db_existing_tdb_file", cn) + self.assertEquals(b"test_dont_create_db_existing_tdb_file", cn) # # Attempt to open an existing tdb file as a tdb file. @@ -122,11 +122,11 @@ def test_create_db_existing_file_tdb_file(self): }) cn = initial.searchone("cn", dn) - self.assertEquals("test_dont_create_db_existing_tdb_file", cn) + self.assertEquals(b"test_dont_create_db_existing_tdb_file", cn) second = SamDB(url="tdb://" + existing_name, flags=0) cn = second.searchone("cn", dn) - self.assertEquals("test_dont_create_db_existing_tdb_file", cn) + self.assertEquals(b"test_dont_create_db_existing_tdb_file", cn) # Open a non existent TDB file. # Don't create new db is set, the default @@ -155,6 +155,6 @@ def test_dont_create_db_new_file(self): # def test_create_db_new_file(self): SamDB(url="tdb://" + self.tempdir + "/test.db", flags=0) - existing = open(self.tempdir + "/test.db", "r") + existing = open(self.tempdir + "/test.db", mode="rb") contents = existing.readline() - self.assertEquals("TDB file\n", contents) + self.assertEquals(b"TDB file\n", contents) diff --git a/selftest/tests.py b/selftest/tests.py index 91f910c8fd6..89ccad46e24 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -156,7 +156,7 @@ plantestsuite("wafsamba.duplicate_symbols", "none", [os.path.join(srcdir(), "buildtools/wafsamba/test_duplicate_symbol.sh")]) planpythontestsuite("none", "samba.tests.glue", py3_compatible=True) planpythontestsuite("none", "samba.tests.tdb_util", py3_compatible=True) -planpythontestsuite("none", "samba.tests.samdb_api") +planpythontestsuite("none", "samba.tests.samdb_api", py3_compatible=True) if with_pam: plantestsuite("samba.tests.pam_winbind(local)", "ad_member", From 71a5164cbb4739e92e17d68ef21eebdbe39441ba Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 5 Apr 2018 12:49:09 +1200 Subject: [PATCH 40/41] selftest: enable py3 for samba.tests.source Open files in text mode. Signed-off-by: Joe Guo --- python/samba/tests/source.py | 2 +- selftest/tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/source.py b/python/samba/tests/source.py index 3b18a91b5a2..831688c8978 100644 --- a/python/samba/tests/source.py +++ b/python/samba/tests/source.py @@ -60,7 +60,7 @@ def get_source_file_contents(): """Iterate over the contents of all python files.""" for fname in get_python_source_files(): try: - f = open(fname, 'rb') + f = open(fname, 'r') except IOError as e: if e.errno == errno.ENOENT: warnings.warn("source file %s broken link?" % fname) diff --git a/selftest/tests.py b/selftest/tests.py index 89ccad46e24..ac95d86ab6b 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -41,7 +41,7 @@ with_pam = ("WITH_PAM" in config_hash) pam_wrapper_so_path=config_hash["LIBPAM_WRAPPER_SO_PATH"] -planpythontestsuite("none", "samba.tests.source") +planpythontestsuite("none", "samba.tests.source", py3_compatible=True) if have_man_pages_support: planpythontestsuite("none", "samba.tests.docs") From 866b1d7c6ffa8760cf7d5ead666fc34d5495b632 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 5 Apr 2018 13:48:36 +1200 Subject: [PATCH 41/41] selftest: enable py3 for samba.tests.docs Popen methods will return bytes. Decode output to string before using. Signed-off-by: Joe Guo --- python/samba/tests/docs.py | 25 ++++++++++++++----------- selftest/tests.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/python/samba/tests/docs.py b/python/samba/tests/docs.py index 3d896d7c7d2..c94826fb16a 100644 --- a/python/samba/tests/docs.py +++ b/python/samba/tests/docs.py @@ -31,7 +31,7 @@ class TestCase(samba.tests.TestCaseInTempDir): def _format_message(self, parameters, message): parameters = list(parameters) - parameters = map(str, parameters) + parameters = list(map(str, parameters)) parameters.sort() return message + '\n\n %s' % ('\n '.join(parameters)) @@ -197,10 +197,11 @@ def _test_default(self, program): p = subprocess.Popen(program + ["-s", self.smbconf, "--section-name", section, "--parameter-name", param], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.topdir).communicate() - if p[0].upper().strip() != default.upper(): - if not (p[0].upper().strip() == "" and default == '""'): + result = p[0].upper().strip().decode() + if result != default.upper(): + if not (result == "" and default == '""'): doc_triple = "%s\n Expected: %s" % (param, default) - failset.add("%s\n Got: %s" % (doc_triple, p[0].upper().strip())) + failset.add("%s\n Got: %s" % (doc_triple, result)) if len(failset) > 0: self.fail(self._format_message(failset, @@ -227,10 +228,11 @@ def _set_defaults(self, program): "--section-name", section, "--parameter-name", param, "--option", "%s = %s" % (param, default)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.topdir).communicate() - if p[0].upper().strip() != default.upper(): - if not (p[0].upper().strip() == "" and default == '""'): + result = p[0].upper().strip().decode() + if result != default.upper(): + if not (result == "" and default == '""'): doc_triple = "%s\n Expected: %s" % (param, default) - failset.add("%s\n Got: %s" % (doc_triple, p[0].upper().strip())) + failset.add("%s\n Got: %s" % (doc_triple, result)) if len(failset) > 0: self.fail(self._format_message(failset, @@ -285,10 +287,11 @@ def _set_arbitrary(self, program, exceptions=None): "--section-name", section, "--parameter-name", param, "--option", "%s = %s" % (param, value_to_use)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.topdir).communicate() - if p[0].upper().strip() != value_to_use.upper(): + result = p[0].upper().strip().decode() + if result != value_to_use.upper(): # currently no way to distinguish command lists if param_type == 'list': - if ", ".join(p[0].upper().strip().split()) == value_to_use.upper(): + if ", ".join(result.split()) == value_to_use.upper(): continue # currently no way to identify octal @@ -320,7 +323,7 @@ def _set_arbitrary(self, program, exceptions=None): # testparm doesn't display a value if they are equivalent if (value_to_use.lower() != opposite_value.lower()): - for line in p[0].splitlines(): + for line in p[0].decode().splitlines(): if not line.strip().startswith(param): continue @@ -352,7 +355,7 @@ def _test_empty(self, program): stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.topdir).communicate() output = "" - for line in p[0].splitlines(): + for line in p[0].decode().splitlines(): if line.strip().startswith('#'): continue if line.strip().startswith("idmap config *"): diff --git a/selftest/tests.py b/selftest/tests.py index ac95d86ab6b..5c076b15974 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -43,7 +43,7 @@ planpythontestsuite("none", "samba.tests.source", py3_compatible=True) if have_man_pages_support: - planpythontestsuite("none", "samba.tests.docs") + planpythontestsuite("none", "samba.tests.docs", py3_compatible=True) try: import testscenarios