From 4f036497f1e8825d5ebe3a14c528ddf6cb1a4b22 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 2 Feb 2018 16:08:48 +0000 Subject: [PATCH] python3 port for dckeytab module Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- source4/libnet/py_net_dckeytab.c | 26 +++++++++++++++++++------- source4/libnet/wscript_build | 12 ++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/source4/libnet/py_net_dckeytab.c b/source4/libnet/py_net_dckeytab.c index efb92677055..cf43da71c60 100644 --- a/source4/libnet/py_net_dckeytab.c +++ b/source4/libnet/py_net_dckeytab.c @@ -22,6 +22,7 @@ #include #include "includes.h" +#include "python/py3compat.h" #include "py_net.h" #include "libnet_export_keytab.h" @@ -74,28 +75,37 @@ static PyMethodDef export_keytab_method_table[] = { * the global module table even if we don't really need that record. Thus, we initialize * dckeytab module but never use it. * */ -void initdckeytab(void) +void initdckeytab(void); +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "dckeytab", + .m_doc = "dckeytab", + .m_size = -1, + .m_methods = NULL +}; + +MODULE_INIT_FUNC(dckeytab) { - PyObject *m; + PyObject *m = NULL; PyObject *Net; PyObject *descr; int ret; - m = Py_InitModule3("dckeytab", NULL, NULL); + m = PyModule_Create(&moduledef); if (m == NULL) - return; + return m; m = PyImport_ImportModule("samba.net"); if (m == NULL) - return; + return m; Net = (PyObject *)PyObject_GetAttrString(m, "Net"); if (Net == NULL) - return; + return m; descr = PyDescr_NewMethod((PyTypeObject*)Net, &export_keytab_method_table[0]); if (descr == NULL) - return; + return m; ret = PyDict_SetItemString(((PyTypeObject*)Net)->tp_dict, export_keytab_method_table[0].ml_name, @@ -103,4 +113,6 @@ void initdckeytab(void) if (ret != -1) { Py_DECREF(descr); } + + return m; } diff --git a/source4/libnet/wscript_build b/source4/libnet/wscript_build index e192eb59404..df0a097e520 100644 --- a/source4/libnet/wscript_build +++ b/source4/libnet/wscript_build @@ -18,9 +18,9 @@ for env in bld.gen_python_environments(): realname='samba/net.so' ) -bld.SAMBA_PYTHON('python_dckeytab', - source='py_net_dckeytab.c libnet_export_keytab.c', - deps='pyrpc_util db-glue krb5 com_err', - realname='samba/dckeytab.so', - enabled=bld.CONFIG_SET('AD_DC_BUILD_IS_ENABLED') - ) + bld.SAMBA_PYTHON('python_dckeytab', + source='py_net_dckeytab.c libnet_export_keytab.c', + deps='pyrpc_util db-glue krb5 com_err', + realname='samba/dckeytab.so', + enabled=bld.CONFIG_SET('AD_DC_BUILD_IS_ENABLED') + )