diff options
author | Tim Potter <tpot@samba.org> | 2002-05-06 04:53:44 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-05-06 04:53:44 +0000 |
commit | 202341dbce8f53ed71334cc8eb8a9ab0c1873b61 (patch) | |
tree | 17a9401f45749b7c63b1fe295cd42ada94085fe2 /source3/python/py_lsa.c | |
parent | 0a01e23e2be461fe3d4a8af7344c0a08ed091d96 (diff) | |
download | samba-202341dbce8f53ed71334cc8eb8a9ab0c1873b61.tar.gz samba-202341dbce8f53ed71334cc8eb8a9ab0c1873b61.tar.bz2 samba-202341dbce8f53ed71334cc8eb8a9ab0c1873b61.zip |
Allow lookup_sids() and lookup_names() to take either a list of strings or
just a single string.
(This used to be commit 775549b70e1d2770619c2fe1ed39418a8788dbfe)
Diffstat (limited to 'source3/python/py_lsa.c')
-rw-r--r-- | source3/python/py_lsa.c | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index fecbf535aa..82ae99c53e 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -133,19 +133,36 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args) DOM_SID *sids; uint32 *name_types; - if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &py_names)) + if (!PyArg_ParseTuple(args, "O", &py_names)) return NULL; - /* Convert dictionary to char ** array */ + if (!PyList_Check(py_names) && !PyString_Check(py_names)) { + PyErr_SetString(PyExc_TypeError, "must be list or string"); + return NULL; + } - num_names = PyList_Size(py_names); - names = (const char **)talloc( - hnd->mem_ctx, num_names * sizeof(char *)); + if (PyList_Check(py_names)) { - for (i = 0; i < num_names; i++) { - PyObject *obj = PyList_GetItem(py_names, i); + /* Convert list to char ** array */ + + num_names = PyList_Size(py_names); + names = (const char **)talloc( + hnd->mem_ctx, num_names * sizeof(char *)); + + for (i = 0; i < num_names; i++) { + PyObject *obj = PyList_GetItem(py_names, i); + + names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj)); + } + + } else { + + /* Just a single element */ - names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj)); + num_names = 1; + names = (const char **)talloc(hnd->mem_ctx, sizeof(char *)); + + names[0] = PyString_AsString(py_names); } ntstatus = cli_lsa_lookup_names(hnd->cli, hnd->mem_ctx, &hnd->pol, @@ -182,20 +199,37 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self; DOM_SID *sids; - if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &py_sids)) + if (!PyArg_ParseTuple(args, "O", &py_sids)) + return NULL; + + if (!PyList_Check(py_sids) && !PyString_Check(py_sids)) { + PyErr_SetString(PyExc_TypeError, "must be list or string"); return NULL; + } - /* Convert dictionary to char ** array */ + if (PyList_Check(py_sids)) { - num_sids = PyList_Size(py_sids); - sids = (DOM_SID *)talloc(hnd->mem_ctx, num_sids * sizeof(DOM_SID)); + /* Convert dictionary to char ** array */ + + num_sids = PyList_Size(py_sids); + sids = (DOM_SID *)talloc(hnd->mem_ctx, num_sids * sizeof(DOM_SID)); + + memset(sids, 0, num_sids * sizeof(DOM_SID)); + + for (i = 0; i < num_sids; i++) { + PyObject *obj = PyList_GetItem(py_sids, i); + + string_to_sid(&sids[i], PyString_AsString(obj)); + } - memset(sids, 0, num_sids * sizeof(DOM_SID)); + } else { - for (i = 0; i < num_sids; i++) { - PyObject *obj = PyList_GetItem(py_sids, i); + /* Just a single element */ + + num_sids = 1; + sids = (DOM_SID *)talloc(hnd->mem_ctx, sizeof(DOM_SID)); - string_to_sid(&sids[i], PyString_AsString(obj)); + string_to_sid(&sids[0], PyString_AsString(py_sids)); } ntstatus = cli_lsa_lookup_sids(hnd->cli, hnd->mem_ctx, &hnd->pol, |