From 747e020a07391f7529036ce2e65d46724a56bb70 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 20 Mar 2002 06:27:41 +0000 Subject: Added enum domain users and enum domain groups. (This used to be commit ba0624d0c397d49b032f34727c910c0be7014813) --- source3/python/py_winbind.c | 99 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 22 deletions(-) (limited to 'source3/python/py_winbind.c') diff --git a/source3/python/py_winbind.c b/source3/python/py_winbind.c index 9e03132ab4..5b0d3306ec 100644 --- a/source3/python/py_winbind.c +++ b/source3/python/py_winbind.c @@ -35,28 +35,6 @@ NSS_STATUS winbindd_request(int req_type, struct winbindd_request *request, struct winbindd_response *response); -/* FIXME: grr this needs to be a fn in a library somewhere */ - -static BOOL parse_domain_user(const char *domuser, fstring domain, - fstring user) -{ - char *p = strchr(domuser,*lp_winbind_separator()); - - if (!(p || lp_winbind_use_default_domain())) - return False; - - if(!p && lp_winbind_use_default_domain()) { - fstrcpy(user, domuser); - fstrcpy(domain, lp_workgroup()); - } else { - fstrcpy(user, p+1); - fstrcpy(domain, domuser); - domain[PTR_DIFF(p, domuser)] = 0; - } - strupper(domain); - return True; -} - /* * Name <-> SID conversion */ @@ -134,6 +112,73 @@ static PyObject *winbind_sid_to_name(PyObject *self, PyObject *args) return result; } +/* + * Enumerate users/groups + */ + +/* Enumerate domain users */ + +static PyObject *winbind_enum_domain_users(PyObject *self, PyObject *args) +{ + struct winbindd_response response; + PyObject *result; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + ZERO_STRUCT(response); + + if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) + != NSS_STATUS_SUCCESS) { + PyErr_SetString(winbind_error, "lookup failed"); + return NULL; + } + + result = PyList_New(0); + + if (response.extra_data) { + char *extra_data = response.extra_data; + fstring name; + + while (next_token(&extra_data, name, ",", sizeof(fstring))) + PyList_Append(result, PyString_FromString(name)); + } + + return result; +} + +/* Enumerate domain groups */ + +static PyObject *winbind_enum_domain_groups(PyObject *self, PyObject *args) +{ + struct winbindd_request request; + struct winbindd_response response; + PyObject *result = NULL; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + ZERO_STRUCT(response); + + if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) + != NSS_STATUS_SUCCESS) { + PyErr_SetString(winbind_error, "lookup failed"); + return NULL; + } + + result = PyList_New(0); + + if (response.extra_data) { + char *extra_data = response.extra_data; + fstring name; + + while (next_token(&extra_data, name, ",", sizeof(fstring))) + PyList_Append(result, PyString_FromString(name)); + } + + return result; +} + /* * Method dispatch table */ @@ -148,6 +193,14 @@ static PyMethodDef winbind_methods[] = { { "sid_to_name", winbind_sid_to_name, METH_VARARGS, "Convert a sid to a name" }, + /* Enumerate users/groups */ + + { "enum_domain_users", winbind_enum_domain_users, METH_VARARGS, + "Enumerate domain users" }, + + { "enum_domain_groups", winbind_enum_domain_groups, METH_VARARGS, + "Enumerate domain groups" }, + { NULL } }; @@ -166,4 +219,6 @@ void initwinbind(void) winbind_error = PyErr_NewException("winbind.error", NULL, NULL); PyDict_SetItemString(dict, "error", winbind_error); + + py_samba_init(); } -- cgit