libwbclient: Implement wbcGidToSid_send/recv
authorKai Blin <kai@samba.org>
Thu, 2 Apr 2009 07:45:39 +0000 (09:45 +0200)
committerKai Blin <kai@samba.org>
Thu, 11 Feb 2010 22:56:34 +0000 (23:56 +0100)
nsswitch/libwbclient/wbc_async.h
nsswitch/libwbclient/wbc_idmap.c

index eb8798ebc6a75db707ebcf4b2d044082c8b6fa56..a1f2e2983147e3030cd2008332f131434038a9f1 100644 (file)
@@ -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,
index 03376782df2f2bdf4c98311a752e5efd68b18b0e..e1bb6f2d594aa45f44eb7fd2291ebce5dd68f7a3 100644 (file)
@@ -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)
 {