From d00ce3242116c5b71eace56f4c2bff4a2d01c019 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:04:53 +0000 Subject: [PATCH 01/15] 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 7fea7b7823628264fcd151455e34ba50a4d590f3 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 8 Mar 2018 11:28:16 +0000 Subject: [PATCH 02/15] 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 7edf93a987acea08db448c488a555c762f7c39ff Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 21 Mar 2018 18:24:18 +0000 Subject: [PATCH 03/15] 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 | 5 ++ 6 files changed, 213 insertions(+), 83 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..dc3830b310c 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -76,6 +76,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 33357d35dbbb78af809bd56203bda0f5be70cb06 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:39:58 +0000 Subject: [PATCH 04/15] 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 b45fad833e547dbc3f0a12b329d82b136041e566 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 12:50:48 +0000 Subject: [PATCH 05/15] 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 0e99d98ccc82a0d8499298581b4f8ca74b00a3ce Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:21:12 +0000 Subject: [PATCH 06/15] 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 dc3830b310c..b3d538c18f5 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -76,7 +76,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 b189c5fc5de2204c95d3d488873b86b4f71687e8 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:26:15 +0000 Subject: [PATCH 07/15] 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 b3d538c18f5..bf61e44a095 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -77,7 +77,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 2a4967a87af76dcf91419101ddf1ae7558e74168 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:35:11 +0000 Subject: [PATCH 08/15] 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 09/15] 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 6e7c4b1fcee..aa1a19d32eb 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -79,7 +79,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 b5179ed3f8cc6222efd84c13ab13ff74a0378dd7 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 22 Mar 2018 12:46:55 +0000 Subject: [PATCH 10/15] 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 aa1a19d32eb..8579868ec05 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -80,7 +80,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 e8f12bd675f58defb7ecd15c519943304355552e Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:34:15 +0000 Subject: [PATCH 11/15] 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 48eff5a7a50a4cbd57675dd6c345509b1e8fbb02 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 8 Mar 2018 10:37:23 +0000 Subject: [PATCH 12/15] 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 700decd8b9d..83f9f2dfc3e 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -374,7 +374,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 98e1d03701f95c912b413d8e6883f656cf5132d2 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 11:10:46 +0000 Subject: [PATCH 13/15] 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 94812e388505f70e0650a3178b2fcf343101fc19 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Feb 2018 10:56:20 +0000 Subject: [PATCH 14/15] 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 c975ccef1a6589aea31ce7ba909cd86921511380 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 5 Mar 2018 16:08:01 +0000 Subject: [PATCH 15/15] 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 8579868ec05..e38584066cd 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.samba3") planpythontestsuite("none", "samba.tests.strings")