diff options
author | Stefan Metzmacher <metze@samba.org> | 2008-04-06 11:55:57 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2008-04-06 13:42:00 +0200 |
commit | cb4e77d991ae41ff112b14bb8043a896efedc72f (patch) | |
tree | cac809850672c52b855720c68c5fddbbd445a23c /source3 | |
parent | 7d0ebc1976652c8ef8cfc5b0151342f95079d5a2 (diff) | |
download | samba-cb4e77d991ae41ff112b14bb8043a896efedc72f.tar.gz samba-cb4e77d991ae41ff112b14bb8043a896efedc72f.tar.bz2 samba-cb4e77d991ae41ff112b14bb8043a896efedc72f.zip |
libwbclient: add wbcGetGroups()
metze
(This used to be commit 596d030b976102e7476a2460fce355914c4e8210)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/nsswitch/libwbclient/wbc_pwd.c | 60 | ||||
-rw-r--r-- | source3/nsswitch/libwbclient/wbclient.h | 4 |
2 files changed, 64 insertions, 0 deletions
diff --git a/source3/nsswitch/libwbclient/wbc_pwd.c b/source3/nsswitch/libwbclient/wbc_pwd.c index b7febcce0c..baee3c3781 100644 --- a/source3/nsswitch/libwbclient/wbc_pwd.c +++ b/source3/nsswitch/libwbclient/wbc_pwd.c @@ -374,3 +374,63 @@ wbcErr wbcGetgrent(struct group **grp) return WBC_ERR_NOT_IMPLEMENTED; } +/** @brief Return the unix group array belonging to the given user + * + * @param *account The given user name + * @param *num_groups Number of elements returned in the groups array + * @param **groups Pointer to resulting gid_t array. + * + * @return #wbcErr + **/ +wbcErr wbcGetGroups(const char *account, + uint32_t *num_groups, + gid_t **_groups) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct winbindd_request request; + struct winbindd_response response; + uint32_t i; + gid_t *groups = NULL; + + if (!account) { + wbc_status = WBC_ERR_INVALID_PARAM; + BAIL_ON_WBC_ERROR(wbc_status); + } + + /* Initialize request */ + + ZERO_STRUCT(request); + ZERO_STRUCT(response); + + /* Send request */ + + strncpy(request.data.username, account, sizeof(request.data.username)-1); + + wbc_status = wbcRequestResponse(WINBINDD_GETGROUPS, + &request, + &response); + BAIL_ON_WBC_ERROR(wbc_status); + + groups = talloc_array(NULL, gid_t, response.data.num_entries); + BAIL_ON_PTR_ERROR(groups, wbc_status); + + for (i = 0; i < response.data.num_entries; i++) { + groups[i] = ((gid_t *)response.extra_data.data)[i]; + } + + *num_groups = response.data.num_entries; + *_groups = groups; + groups = NULL; + + wbc_status = WBC_ERR_SUCCESS; + + done: + if (response.extra_data.data) { + free(response.extra_data.data); + } + if (groups) { + talloc_free(groups); + } + + return wbc_status; +} diff --git a/source3/nsswitch/libwbclient/wbclient.h b/source3/nsswitch/libwbclient/wbclient.h index 8590a30795..16b68c0802 100644 --- a/source3/nsswitch/libwbclient/wbclient.h +++ b/source3/nsswitch/libwbclient/wbclient.h @@ -370,6 +370,10 @@ wbcErr wbcEndgrent(void); wbcErr wbcGetgrent(struct group **grp); +wbcErr wbcGetGroups(const char *account, + uint32_t *num_groups, + gid_t **_groups); + /* * Lookup Domain information |