summaryrefslogtreecommitdiff
path: root/nsswitch/libwbclient
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-04-02 09:57:40 +0200
committerKai Blin <kai@samba.org>2010-02-11 23:56:34 +0100
commit446b4aa17c03993a0fa0c77bd7e8bdec938be991 (patch)
treed808966f3f5d437b3f4a528e4a88e46a277796ea /nsswitch/libwbclient
parent4ff1906357659a040aa90bcd51dd1974ec405001 (diff)
downloadsamba-446b4aa17c03993a0fa0c77bd7e8bdec938be991.tar.gz
samba-446b4aa17c03993a0fa0c77bd7e8bdec938be991.tar.bz2
samba-446b4aa17c03993a0fa0c77bd7e8bdec938be991.zip
libwbclient: Implement wbcUidToSid_send/recv
Diffstat (limited to 'nsswitch/libwbclient')
-rw-r--r--nsswitch/libwbclient/wbc_async.h6
-rw-r--r--nsswitch/libwbclient/wbc_idmap.c110
2 files changed, 116 insertions, 0 deletions
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h
index 6e90ad722c..043b303632 100644
--- a/nsswitch/libwbclient/wbc_async.h
+++ b/nsswitch/libwbclient/wbc_async.h
@@ -100,6 +100,12 @@ struct tevent_req *wbcSidToUid_send(TALLOC_CTX *mem_ctx,
const struct wbcDomainSid *sid);
wbcErr wbcSidToUid_recv(struct tevent_req *req, uid_t *puid);
+struct tevent_req *wbcUidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ uid_t uid);
+wbcErr wbcUidToSid_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 5283339ff3..353bd83665 100644
--- a/nsswitch/libwbclient/wbc_idmap.c
+++ b/nsswitch/libwbclient/wbc_idmap.c
@@ -171,6 +171,116 @@ wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
return WBC_ERR_NOT_IMPLEMENTED;
}
+struct wbc_uid_to_sid_state {
+ struct winbindd_request req;
+ struct wbcDomainSid *sid;
+};
+
+static void wbcUidToSid_done(struct tevent_req *subreq);
+
+/**
+ * @brief Request a Windows SID for an Unix uid, 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 uid uid to be resolved to a SID
+ *
+ * @return tevent_req on success, NULL on error
+ */
+
+struct tevent_req *wbcUidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ uid_t uid)
+{
+ struct tevent_req *req, *subreq;
+ struct wbc_uid_to_sid_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct wbc_uid_to_sid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ ZERO_STRUCT(state->req);
+
+ state->req.cmd = WINBINDD_UID_TO_SID;
+ state->req.data.uid = uid;
+
+ 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, wbcUidToSid_done, req);
+ return req;
+}
+
+static void wbcUidToSid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wbc_uid_to_sid_state *state = tevent_req_data(
+ req, struct wbc_uid_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 uid mapped to a Windows SID
+ *
+ * @param req tevent_req containing the request
+ * @param *psid pointer to hold the resolved SID
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcUidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid)
+{
+ struct wbc_uid_to_sid_state *state = tevent_req_data(
+ req, struct wbc_uid_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 uid to a Windows SID, allocating a SID if needed */
wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
{