From 9333e1903e1ce193ded226f907f90ec5663a0460 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Mar 2011 18:31:38 +0100 Subject: [PATCH] s3: Use wbcSidsToUnixIds in create_local_token Signed-off-by: Jeremy Allison (cherry picked from commit b82f664ff25c69071aa9df8776c6dd1802cdfde5) --- source3/auth/auth_util.c | 26 ++++++++--- source3/passdb/lookup_sid.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ source3/passdb/lookup_sid.h | 3 ++ 3 files changed, 126 insertions(+), 6 deletions(-) diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index c84e3d3508f..cba7156026f 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -444,9 +444,11 @@ static NTSTATUS log_nt_token(struct security_token *token) NTSTATUS create_local_token(struct auth_serversupplied_info *server_info) { + struct security_token *t; NTSTATUS status; size_t i; struct dom_sid tmp_sid; + struct wbcUnixId *ids; /* * If winbind is not around, we can not make much use of the SIDs the @@ -481,18 +483,30 @@ NTSTATUS create_local_token(struct auth_serversupplied_info *server_info) server_info->utok.ngroups = 0; server_info->utok.groups = NULL; + t = server_info->security_token; + + ids = TALLOC_ARRAY(talloc_tos(), struct wbcUnixId, + t->num_sids); + if (ids == NULL) { + return NT_STATUS_NO_MEMORY; + } + + if (!sids_to_unix_ids(t->sids, t->num_sids, ids)) { + TALLOC_FREE(ids); + return NT_STATUS_NO_MEMORY; + } + /* Start at index 1, where the groups start. */ - for (i=1; isecurity_token->num_sids; i++) { - gid_t gid; - struct dom_sid *sid = &server_info->security_token->sids[i]; + for (i=1; inum_sids; i++) { - if (!sid_to_gid(sid, &gid)) { + if (ids[i].type != WBC_ID_TYPE_GID) { DEBUG(10, ("Could not convert SID %s to gid, " - "ignoring it\n", sid_string_dbg(sid))); + "ignoring it\n", + sid_string_dbg(&t->sids[i]))); continue; } - if (!add_gid_to_array_unique(server_info, gid, + if (!add_gid_to_array_unique(server_info, ids[i].id.gid, &server_info->utok.groups, &server_info->utok.ngroups)) { return NT_STATUS_NO_MEMORY; diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c index 677566187c8..5cf391f11c7 100644 --- a/source3/passdb/lookup_sid.c +++ b/source3/passdb/lookup_sid.c @@ -1395,6 +1395,109 @@ void gid_to_sid(struct dom_sid *psid, gid_t gid) return; } +bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids, + struct wbcUnixId *ids) +{ + struct wbcDomainSid *wbc_sids = NULL; + struct wbcUnixId *wbc_ids = NULL; + uint32_t i, num_not_cached; + wbcErr err; + bool ret = false; + + wbc_sids = TALLOC_ARRAY(talloc_tos(), struct wbcDomainSid, num_sids); + if (wbc_sids == NULL) { + return false; + } + + num_not_cached = 0; + + for (i=0; i