diff options
author | Andrew Bartlett <abartlet@samba.org> | 2012-05-02 12:57:27 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2012-05-03 08:09:09 +1000 |
commit | 926c0a6a330f3b0f643d6384a15e90d2999bce26 (patch) | |
tree | a3e5f0e57af70e7d8fa7bf469c07fe1a73301d50 /source3/passdb | |
parent | 0ef06dd0212c6504740a5e0333440a9be090c088 (diff) | |
download | samba-926c0a6a330f3b0f643d6384a15e90d2999bce26.tar.gz samba-926c0a6a330f3b0f643d6384a15e90d2999bce26.tar.bz2 samba-926c0a6a330f3b0f643d6384a15e90d2999bce26.zip |
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
Diffstat (limited to 'source3/passdb')
-rw-r--r-- | source3/passdb/py_passdb.c | 58 |
1 files changed, 57 insertions, 1 deletions
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<num_groups; i++) { + PyList_Append(py_sid_list, pytalloc_steal(dom_sid_Type, dom_sid_dup(NULL, &user_group_sids[i]))); + } + + talloc_free(tframe); + + return py_sid_list; +} + + static PyObject *py_pdb_add_groupmem(pytalloc_Object *self, PyObject *args) { NTSTATUS status; @@ -3410,7 +3464,9 @@ static PyMethodDef py_pdb_methods[] = { { "enum_group_members", (PyCFunction)py_pdb_enum_group_members, METH_VARARGS, "enum_group_members(group_sid) -> 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 \ |