summaryrefslogtreecommitdiff
path: root/source4/dsdb
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2018-01-30 18:53:38 +0100
committerAndrew Bartlett <abartlet@samba.org>2018-02-15 00:18:29 +0100
commitdce18a079e8c1e259bab4b4da57121d6ab4b7635 (patch)
tree29a8db193d2516bdc5fae635beb3471b079340b9 /source4/dsdb
parentbc7c6c15da0ba42cd7f4b3551d2ab33f349bae1b (diff)
downloadsamba-dce18a079e8c1e259bab4b4da57121d6ab4b7635.tar.gz
python: Port dsdb module to Python 3 compatible form.
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb')
-rw-r--r--source4/dsdb/pydsdb.c60
-rw-r--r--source4/dsdb/wscript_build20
2 files changed, 48 insertions, 32 deletions
diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index 8cf3ef5e4f6..d38d7095efa 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -18,6 +18,7 @@
*/
#include <Python.h>
+#include "python/py3compat.h"
#include "includes.h"
#include <ldb.h>
#include <pyldb.h>
@@ -32,7 +33,6 @@
#include "lib/util/dlinklist.h"
#include "dsdb/kcc/garbage_collect_tombstones.h"
-void initdsdb(void);
/* FIXME: These should be in a header file somewhere */
#define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
@@ -93,7 +93,7 @@ static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
return NULL;
}
- result = PyString_FromString(site);
+ result = PyStr_FromString(site);
talloc_free(mem_ctx);
return result;
}
@@ -119,7 +119,7 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
return NULL;
}
- ret = PyString_FromString(retstr);
+ ret = PyStr_FromString(retstr);
talloc_free(retstr);
return ret;
}
@@ -136,7 +136,7 @@ static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
PyErr_LDB_OR_RAISE(py_ldb, ldb);
- sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
+ sid = dom_sid_parse_talloc(NULL, PyStr_AsString(py_sid));
if (sid == NULL) {
PyErr_NoMemory();
return NULL;
@@ -209,7 +209,7 @@ static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
PyErr_NoMemory();
return NULL;
}
- ret = PyString_FromString(retstr);
+ ret = PyStr_FromString(retstr);
talloc_free(retstr);
return ret;
}
@@ -239,7 +239,7 @@ static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
PyErr_NoMemory();
return NULL;
}
- result = PyString_FromString(retstr);
+ result = PyStr_FromString(retstr);
talloc_free(retstr);
return result;
}
@@ -281,7 +281,7 @@ static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
return NULL;
}
- ret = PyString_FromString(oid);
+ ret = PyStr_FromString(oid);
talloc_free(mem_ctx);
@@ -436,7 +436,7 @@ static PyObject *py_dsdb_get_backlink_from_lDAPDisplayName(PyObject *self, PyObj
Py_RETURN_NONE;
}
- return PyString_FromString(target_attr->lDAPDisplayName);
+ return PyStr_FromString(target_attr->lDAPDisplayName);
}
@@ -466,7 +466,7 @@ static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *
return NULL;
}
- return PyString_FromString(a->lDAPDisplayName);
+ return PyStr_FromString(a->lDAPDisplayName);
}
@@ -499,7 +499,7 @@ static PyObject *py_dsdb_get_syntax_oid_from_lDAPDisplayName(PyObject *self, PyO
return NULL;
}
- return PyString_FromString(attribute->syntax->ldap_oid);
+ return PyStr_FromString(attribute->syntax->ldap_oid);
}
/*
@@ -518,6 +518,7 @@ static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
TALLOC_CTX *tmp_ctx;
WERROR werr;
Py_ssize_t i;
+ Py_ssize_t _size;
if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
return NULL;
@@ -579,13 +580,13 @@ static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
for (i = 0; i < el->num_values; i++) {
PyObject *item = PyList_GetItem(el_list, i);
- if (!PyString_Check(item)) {
+ if (!PyStr_Check(item)) {
PyErr_Format(PyExc_TypeError, "ldif_elements should be strings");
talloc_free(tmp_ctx);
return NULL;
}
- el->values[i].data = (uint8_t *)PyString_AsString(item);
- el->values[i].length = PyString_Size(item);
+ el->values[i].data = (uint8_t *)PyStr_AsUTF8AndSize(item, &_size);
+ el->values[i].length = _size;
}
}
@@ -624,6 +625,7 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
TALLOC_CTX *tmp_ctx;
WERROR werr;
Py_ssize_t i;
+ Py_ssize_t _size;
PyTypeObject *py_type = NULL;
PyObject *module = NULL;
@@ -686,13 +688,13 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
for (i = 0; i < el->num_values; i++) {
PyObject *item = PyList_GetItem(el_list, i);
- if (!PyString_Check(item)) {
+ if (!PyStr_Check(item)) {
PyErr_Format(PyExc_TypeError, "ldif_elements should be strings");
talloc_free(tmp_ctx);
return NULL;
}
- el->values[i].data = (uint8_t *)PyString_AsString(item);
- el->values[i].length = PyString_Size(item);
+ el->values[i].data = (uint8_t *)PyStr_AsUTF8AndSize(item, &_size);;
+ el->values[i].length = _size;
}
}
@@ -767,7 +769,7 @@ static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
return NULL;
PyErr_LDB_OR_RAISE(py_ldb, ldb);
- GUID_from_string(PyString_AsString(py_guid), &guid);
+ GUID_from_string(PyStr_AsString(py_guid), &guid);
if (GUID_all_zero(&guid)) {
PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id rejected due to all-zero invocation ID");
@@ -806,7 +808,7 @@ static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
PyErr_NoMemory();
return NULL;
}
- result = PyString_FromString(retstr);
+ result = PyStr_FromString(retstr);
talloc_free(retstr);
return result;
}
@@ -1200,7 +1202,7 @@ static PyObject *py_dsdb_garbage_collect_tombstones(PyObject *self, PyObject *ar
length = PyList_GET_SIZE(py_list_dn);
for (i = 0; i < length; i++) {
- char *part_str = PyString_AsString(PyList_GetItem(py_list_dn, i));
+ char *part_str = PyStr_AsString(PyList_GetItem(py_list_dn, i));
struct ldb_dn *p;
struct dsdb_ldb_dn_list_node *node;
@@ -1389,14 +1391,22 @@ static PyMethodDef py_dsdb_methods[] = {
{ NULL }
};
-void initdsdb(void)
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "dsdb",
+ .m_doc = "Python bindings for the directory service databases.",
+ .m_size = -1,
+ .m_methods = py_dsdb_methods,
+};
+
+MODULE_INIT_FUNC(dsdb)
{
PyObject *m;
- m = Py_InitModule3("dsdb", py_dsdb_methods,
- "Python bindings for the directory service databases.");
+ m = PyModule_Create(&moduledef);
+
if (m == NULL)
- return;
+ return NULL;
#define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyInt_FromLong(val))
@@ -1562,7 +1572,7 @@ void initdsdb(void)
ADD_DSDB_FLAG(GPO_INHERIT);
ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);
-#define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyString_FromString(val))
+#define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyStr_FromString(val))
ADD_DSDB_STRING(DSDB_SYNTAX_BINARY_DN);
ADD_DSDB_STRING(DSDB_SYNTAX_STRING_DN);
@@ -1586,4 +1596,6 @@ void initdsdb(void)
ADD_DSDB_STRING(DS_GUID_PROGRAM_DATA_CONTAINER);
ADD_DSDB_STRING(DS_GUID_SYSTEMS_CONTAINER);
ADD_DSDB_STRING(DS_GUID_USERS_CONTAINER);
+
+ return m;
}
diff --git a/source4/dsdb/wscript_build b/source4/dsdb/wscript_build
index 29c6f0e4a70..e1f1e61c55e 100644
--- a/source4/dsdb/wscript_build
+++ b/source4/dsdb/wscript_build
@@ -62,11 +62,15 @@ bld.SAMBA_MODULE('service_dns_update',
enabled=bld.AD_DC_BUILD_IS_ENABLED()
)
-bld.SAMBA_PYTHON('python_dsdb',
- source='pydsdb.c',
- # the dependency on dcerpc here is because gensec
- # depends on dcerpc but the waf circular dependency finder
- # removes it so we end up with unresolved symbols.
- deps='samdb pyldb-util dcerpc com_err pyrpc_util pyparam_util dsdb_garbage_collect_tombstones',
- realname='samba/dsdb.so'
- )
+for env in bld.gen_python_environments():
+ pyldb_util = bld.pyembed_libname('pyldb-util')
+ pyrpc_util = bld.pyembed_libname('pyrpc_util')
+ pyparam_util = bld.pyembed_libname('pyparam_util')
+ bld.SAMBA_PYTHON('python_dsdb',
+ source='pydsdb.c',
+ # the dependency on dcerpc here is because gensec
+ # depends on dcerpc but the waf circular dependency finder
+ # removes it so we end up with unresolved symbols.
+ deps='samdb %s dcerpc com_err %s %s dsdb_garbage_collect_tombstones' % (pyldb_util, pyrpc_util, pyparam_util),
+ realname='samba/dsdb.so'
+ )