From 926c0a6a330f3b0f643d6384a15e90d2999bce26 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 2 May 2012 12:57:27 +1000 Subject: s3-pypassdb: add wrapper for enum_group_memberships This will be used in samba3upgrade to try and get the group memberships by instead asking for the groups each user is in. This reverse lookup may be more reliable, as this is used at login time. Andrew Bartlett --- source3/passdb/py_passdb.c | 58 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/passdb/py_passdb.c b/source3/passdb/py_passdb.c index b7cc18c562..194a7d47a8 100644 --- a/source3/passdb/py_passdb.c +++ b/source3/passdb/py_passdb.c @@ -1922,6 +1922,60 @@ static PyObject *py_pdb_enum_group_members(pytalloc_Object *self, PyObject *args } +static PyObject *py_pdb_enum_group_memberships(pytalloc_Object *self, PyObject *args) +{ + NTSTATUS status; + struct pdb_methods *methods; + TALLOC_CTX *tframe; + int i; + + struct samu *sam_acct; + PyObject *py_sam_acct; + PyObject *py_sid_list; + struct dom_sid *user_group_sids = NULL; + gid_t *user_group_ids = NULL; + uint32_t num_groups = 0; + + if (!PyArg_ParseTuple(args, "O!:enum_group_memberships", &PySamu, &py_sam_acct)) { + return NULL; + } + + methods = pytalloc_get_ptr(self); + + if ((tframe = talloc_stackframe()) == NULL) { + PyErr_NoMemory(); + return NULL; + } + + sam_acct = pytalloc_get_ptr(py_sam_acct); + + status = methods->enum_group_memberships(methods, tframe, sam_acct, + &user_group_sids, &user_group_ids, &num_groups); + if (!NT_STATUS_IS_OK(status)) { + PyErr_Format(py_pdb_error, "Unable to enumerate group memberships, (%d,%s)", + NT_STATUS_V(status), + get_friendly_nt_error_msg(status)); + talloc_free(tframe); + return NULL; + } + + py_sid_list = PyList_New(0); + if (py_sid_list == NULL) { + PyErr_NoMemory(); + talloc_free(tframe); + return NULL; + } + + for(i=0; i List\n\n \ Return list of users (dom_sid object) in group." }, - /* enum_group_memberships */ + { "enum_group_memberships", (PyCFunction)py_pdb_enum_group_memberships, METH_VARARGS, + "enum_group_memberships(samu object) -> List\n\n \ + Return list of groups (dom_sid object) this user is part of." }, /* set_unix_primary_group */ { "add_groupmem", (PyCFunction)py_pdb_add_groupmem, METH_VARARGS, "add_groupmem(group_rid, member_rid) -> None\n\n \ -- cgit