mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
python: Move PyList_AsStringList to common code so we can reuse
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15289 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
848fea1a01
commit
fd81759e2e
@ -71,3 +71,38 @@ error:
|
||||
Py_XDECREF(mod_sys);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list,
|
||||
const char *paramname)
|
||||
{
|
||||
const char **ret;
|
||||
Py_ssize_t i;
|
||||
if (!PyList_Check(list)) {
|
||||
PyErr_Format(PyExc_TypeError, "%s is not a list", paramname);
|
||||
return NULL;
|
||||
}
|
||||
ret = talloc_array(NULL, const char *, PyList_Size(list)+1);
|
||||
if (ret == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < PyList_Size(list); i++) {
|
||||
const char *value;
|
||||
Py_ssize_t size;
|
||||
PyObject *item = PyList_GetItem(list, i);
|
||||
if (!PyUnicode_Check(item)) {
|
||||
PyErr_Format(PyExc_TypeError, "%s should be strings", paramname);
|
||||
return NULL;
|
||||
}
|
||||
value = PyUnicode_AsUTF8AndSize(item, &size);
|
||||
if (value == NULL) {
|
||||
talloc_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret[i] = talloc_strndup(ret, value, size);
|
||||
}
|
||||
ret[i] = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,14 @@
|
||||
#ifndef __SAMBA_PYTHON_MODULES_H__
|
||||
#define __SAMBA_PYTHON_MODULES_H__
|
||||
|
||||
#include <talloc.h>
|
||||
|
||||
bool py_update_path(void);
|
||||
/* discard signature of 'func' in favour of 'target_sig' */
|
||||
#define PY_DISCARD_FUNC_SIG(target_sig, func) (target_sig)(void(*)(void))func
|
||||
|
||||
const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list,
|
||||
const char *paramname);
|
||||
|
||||
#endif /* __SAMBA_PYTHON_MODULES_H__ */
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <Python.h>
|
||||
#include "python/py3compat.h"
|
||||
#include "includes.h"
|
||||
#include "python/modules.h"
|
||||
#include "version.h"
|
||||
#include "param/pyparam.h"
|
||||
#include "lib/socket/netif.h"
|
||||
|
@ -350,40 +350,6 @@ static PyObject *py_session_info_set_unix(PyObject *module,
|
||||
}
|
||||
|
||||
|
||||
static const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list,
|
||||
const char *paramname)
|
||||
{
|
||||
const char **ret;
|
||||
Py_ssize_t i;
|
||||
if (!PyList_Check(list)) {
|
||||
PyErr_Format(PyExc_TypeError, "%s is not a list", paramname);
|
||||
return NULL;
|
||||
}
|
||||
ret = talloc_array(NULL, const char *, PyList_Size(list)+1);
|
||||
if (ret == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < PyList_Size(list); i++) {
|
||||
const char *value;
|
||||
Py_ssize_t size;
|
||||
PyObject *item = PyList_GetItem(list, i);
|
||||
if (!PyUnicode_Check(item)) {
|
||||
PyErr_Format(PyExc_TypeError, "%s should be strings", paramname);
|
||||
return NULL;
|
||||
}
|
||||
value = PyUnicode_AsUTF8AndSize(item, &size);
|
||||
if (value == NULL) {
|
||||
talloc_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret[i] = talloc_strndup(ret, value, size);
|
||||
}
|
||||
ret[i] = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *PyAuthContext_FromContext(struct auth4_context *auth_context)
|
||||
{
|
||||
return pytalloc_reference(&PyAuthContext, auth_context);
|
||||
|
@ -85,10 +85,12 @@ pytalloc_util = bld.pyembed_libname('pytalloc-util')
|
||||
pyparam_util = bld.pyembed_libname('pyparam_util')
|
||||
pyldb_util = bld.pyembed_libname('pyldb-util')
|
||||
pycredentials = 'pycredentials'
|
||||
libpython = bld.pyembed_libname('LIBPYTHON')
|
||||
|
||||
bld.SAMBA_PYTHON('pyauth',
|
||||
source='pyauth.c',
|
||||
public_deps='auth_system_session',
|
||||
deps='samdb %s %s %s %s auth4' % (pytalloc_util, pyparam_util, pyldb_util, pycredentials),
|
||||
deps=f'samdb {pytalloc_util} {pyparam_util} {pyldb_util} {pycredentials} {libpython} auth4',
|
||||
realname='samba/auth.so'
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user