summaryrefslogtreecommitdiff
path: root/nsswitch
diff options
context:
space:
mode:
Diffstat (limited to 'nsswitch')
-rw-r--r--nsswitch/libwbclient/wbc_async.h6
-rw-r--r--nsswitch/libwbclient/wbc_idmap.c111
2 files changed, 117 insertions, 0 deletions
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h
index eb8798ebc6..a1f2e29831 100644
--- a/nsswitch/libwbclient/wbc_async.h
+++ b/nsswitch/libwbclient/wbc_async.h
@@ -112,6 +112,12 @@ struct tevent_req *wbcSidToGid_send(TALLOC_CTX *mem_ctx,
const struct wbcDomainSid *sid);
wbcErr wbcSidToGid_recv(struct tevent_req *req, gid_t *pgid);
+struct tevent_req *wbcGidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ gid_t gid);
+wbcErr wbcGidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid);
+
/* Async functions from wbc_util.c */
struct tevent_req *wbcPing_send(TALLOC_CTX *mem_ctx,
diff --git a/nsswitch/libwbclient/wbc_idmap.c b/nsswitch/libwbclient/wbc_idmap.c
index 03376782df..e1bb6f2d59 100644
--- a/nsswitch/libwbclient/wbc_idmap.c
+++ b/nsswitch/libwbclient/wbc_idmap.c
@@ -477,6 +477,117 @@ wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
return WBC_ERR_NOT_IMPLEMENTED;
}
+struct wbc_gid_to_sid_state {
+ struct winbindd_request req;
+ struct wbcDomainSid *sid;
+};
+
+static void wbcGidToSid_done(struct tevent_req *subreq);
+
+/**
+ * @brief Request a Windows SID for an Unix Gid, allocating an SID if needed
+ *
+ * @param mem_ctx talloc context to allocate the request from
+ * @param ev tevent context to use for async operation
+ * @param wb_ctx winbind context to use
+ * @param gid gid to be resolved to a SID
+ *
+ * @return tevent_req on success, NULL on error
+ */
+
+struct tevent_req *wbcGidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ gid_t gid)
+{
+ struct tevent_req *req, *subreq;
+ struct wbc_gid_to_sid_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct wbc_gid_to_sid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ ZERO_STRUCT(state->req);
+
+ state->req.cmd = WINBINDD_GID_TO_SID;
+ state->req.data.gid = gid;
+
+ subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_req_set_callback(subreq, wbcGidToSid_done, req);
+ return req;
+}
+
+static void wbcGidToSid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wbc_gid_to_sid_state *state = tevent_req_data(
+ req, struct wbc_gid_to_sid_state);
+ struct winbindd_response *resp;
+ wbcErr wbc_status;
+
+ wbc_status = wb_trans_recv(subreq, state, &resp);
+ TALLOC_FREE(subreq);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return;
+ }
+
+ state->sid = talloc(state, struct wbcDomainSid);
+ if (state->sid == NULL) {
+ TALLOC_FREE(resp);
+ tevent_req_error(req, WBC_ERR_NO_MEMORY);
+ return;
+ }
+
+ wbc_status = wbcStringToSid(resp->data.sid.sid, state->sid);
+ TALLOC_FREE(resp);
+
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return;
+ }
+
+ tevent_req_done(req);
+}
+
+/**
+ * @brief Receive a Unix gid mapped to a Windows SID
+ *
+ * @param req tevent_req containing the request
+ * @param *psid pointer to hold the resolved SID
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcGidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid)
+{
+ struct wbc_gid_to_sid_state *state = tevent_req_data(
+ req, struct wbc_gid_to_sid_state);
+ wbcErr wbc_status;
+
+ if (psid == NULL) {
+ tevent_req_received(req);
+ return WBC_ERR_INVALID_PARAM;
+ }
+
+ if (tevent_req_is_wbcerr(req, &wbc_status)) {
+ tevent_req_received(req);
+ return wbc_status;
+ }
+
+ memcpy(psid, state->sid, sizeof(struct wbcDomainSid));
+
+ tevent_req_received(req);
+ return WBC_ERR_SUCCESS;
+}
+
+
/* Convert a Unix gid to a Windows SID, allocating a SID if needed */
wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
{