summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-03-21 10:18:54 +0100
committerStefan Metzmacher <metze@samba.org>2008-03-28 15:11:41 +0100
commitf58ca063bba86b74f1f4982694b5a7ead442becb (patch)
tree90b98412f1204616533f3832ef1ecffc6fff8f70
parent14b6e9d46bd6b7939acdf66f8c8bc043579d39a6 (diff)
downloadsamba-f58ca063bba86b74f1f4982694b5a7ead442becb.tar.gz
samba-f58ca063bba86b74f1f4982694b5a7ead442becb.tar.bz2
samba-f58ca063bba86b74f1f4982694b5a7ead442becb.zip
libwbclient: add wbcLookupUserSids()
metze (This used to be commit 38007a387a1f1b53877ef9ea518f83ecf026f4f3)
-rw-r--r--source3/nsswitch/libwbclient/wbc_sid.c82
-rw-r--r--source3/nsswitch/libwbclient/wbclient.h5
2 files changed, 87 insertions, 0 deletions
diff --git a/source3/nsswitch/libwbclient/wbc_sid.c b/source3/nsswitch/libwbclient/wbc_sid.c
index 0519d8bf9f..cd865b9bb5 100644
--- a/source3/nsswitch/libwbclient/wbc_sid.c
+++ b/source3/nsswitch/libwbclient/wbc_sid.c
@@ -423,3 +423,85 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
return wbc_status;
}
+
+/** @brief Get the groups a user belongs to
+ *
+ **/
+
+wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
+ bool domain_groups_only,
+ uint32_t *num_sids,
+ struct wbcDomainSid **_sids)
+{
+ uint32_t i;
+ const char *s;
+ struct winbindd_request request;
+ struct winbindd_response response;
+ char *sid_string = NULL;
+ struct wbcDomainSid *sids = NULL;
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ int cmd;
+
+ /* Initialise request */
+
+ ZERO_STRUCT(request);
+ ZERO_STRUCT(response);
+
+ if (!user_sid) {
+ wbc_status = WBC_ERR_INVALID_PARAM;
+ BAIL_ON_WBC_ERROR(wbc_status);
+ }
+
+ wbc_status = wbcSidToString(user_sid, &sid_string);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
+ wbcFreeMemory(sid_string);
+
+ if (domain_groups_only) {
+ cmd = WINBINDD_GETUSERDOMGROUPS;
+ } else {
+ cmd = WINBINDD_GETUSERSIDS;
+ }
+
+ wbc_status = wbcRequestResponse(cmd,
+ &request,
+ &response);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ if (response.data.num_entries &&
+ !response.extra_data.data) {
+ wbc_status = WBC_INVALID_RESPONSE;
+ BAIL_ON_WBC_ERROR(wbc_status);
+ }
+
+ sids = talloc_array(NULL, struct wbcDomainSid,
+ response.data.num_entries);
+ BAIL_ON_PTR_ERROR(sids, wbc_status);
+
+ s = (const char *)response.extra_data.data;
+ for (i = 0; i < response.data.num_entries; i++) {
+ char *n = strchr(s, '\n');
+ if (n) {
+ *n = '\0';
+ }
+ wbc_status = wbcStringToSid(s, &sids[i]);
+ BAIL_ON_WBC_ERROR(wbc_status);
+ s += strlen(s) + 1;
+ }
+
+ *num_sids = response.data.num_entries;
+ *_sids = sids;
+ sids = NULL;
+ wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+ if (response.extra_data.data) {
+ free(response.extra_data.data);
+ }
+ if (sids) {
+ talloc_free(sids);
+ }
+
+ return wbc_status;
+}
diff --git a/source3/nsswitch/libwbclient/wbclient.h b/source3/nsswitch/libwbclient/wbclient.h
index c01db9618d..4b6978080b 100644
--- a/source3/nsswitch/libwbclient/wbclient.h
+++ b/source3/nsswitch/libwbclient/wbclient.h
@@ -298,6 +298,11 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
const char ***names,
enum wbcSidType **types);
+wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
+ bool domain_groups_only,
+ uint32_t *num_sids,
+ struct wbcDomainSid **sids);
+
/*
* SID/uid/gid Mappings
*/