summaryrefslogtreecommitdiff
path: root/nsswitch/libwbclient/wbc_idmap.c
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-04-02 09:45:39 +0200
committerKai Blin <kai@samba.org>2010-02-11 23:56:34 +0100
commit57886720bb1a0e93d8903a0fa677f3820fa3cb07 (patch)
tree5c23dfea0b3c8667c35b2911f5eebbea9e13de93 /nsswitch/libwbclient/wbc_idmap.c
parentada6e26d5e6bacaacbe9cdebdabe41c383e5f8c8 (diff)
downloadsamba-57886720bb1a0e93d8903a0fa677f3820fa3cb07.tar.gz
samba-57886720bb1a0e93d8903a0fa677f3820fa3cb07.tar.bz2
samba-57886720bb1a0e93d8903a0fa677f3820fa3cb07.zip
libwbclient: Implement wbcGidToSid_send/recv
Diffstat (limited to 'nsswitch/libwbclient/wbc_idmap.c')
-rw-r--r--nsswitch/libwbclient/wbc_idmap.c111
1 files changed, 111 insertions, 0 deletions
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)
{