summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-04-24 16:24:56 +0200
committerKai Blin <kai@samba.org>2010-02-11 23:56:34 +0100
commit749fb039719e60d82c496a2e1587bfa32d0360b8 (patch)
treebdfea1f54914b4dbf5b1b82ef17f6bc5eb12457b
parent57886720bb1a0e93d8903a0fa677f3820fa3cb07 (diff)
downloadsamba-749fb039719e60d82c496a2e1587bfa32d0360b8.tar.gz
samba-749fb039719e60d82c496a2e1587bfa32d0360b8.tar.bz2
samba-749fb039719e60d82c496a2e1587bfa32d0360b8.zip
libwbclient: Implement wbcLookupSid_send/recv
-rw-r--r--nsswitch/libwbclient/wbc_async.h11
-rw-r--r--nsswitch/libwbclient/wbc_sid.c129
2 files changed, 140 insertions, 0 deletions
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h
index a1f2e29831..21a45741b7 100644
--- a/nsswitch/libwbclient/wbc_async.h
+++ b/nsswitch/libwbclient/wbc_async.h
@@ -118,6 +118,17 @@ struct tevent_req *wbcGidToSid_send(TALLOC_CTX *mem_ctx,
gid_t gid);
wbcErr wbcGidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid);
+/* Async functions from wbc_sid.c */
+struct tevent_req *wbcLookupSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcDomainSid *sid);
+wbcErr wbcLookupSid_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ char **pdomain,
+ char **pname,
+ enum wbcSidType *pname_type);
+
/* Async functions from wbc_util.c */
struct tevent_req *wbcPing_send(TALLOC_CTX *mem_ctx,
diff --git a/nsswitch/libwbclient/wbc_sid.c b/nsswitch/libwbclient/wbc_sid.c
index 7aab04b86f..6069aa88d9 100644
--- a/nsswitch/libwbclient/wbc_sid.c
+++ b/nsswitch/libwbclient/wbc_sid.c
@@ -193,6 +193,135 @@ wbcErr wbcLookupName(const char *domain,
return wbc_status;
}
+struct wbc_lookup_sid_state {
+ struct winbindd_request req;
+ char *domain;
+ char *name;
+ enum wbcSidType name_type;
+};
+
+static void wbcLookupSid_done(struct tevent_req *subreq);
+
+/**
+ * @brief Request a conversion of a SID to a domain and name
+ *
+ * @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 *sid Pointer to the domain SID to be resolved
+ *
+ * @return tevent_req on success, NULL on error
+ **/
+
+struct tevent_req *wbcLookupSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcDomainSid *sid)
+{
+ struct tevent_req *req, *subreq;
+ struct wbc_lookup_sid_state *state;
+ char *sid_string;
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+
+ req = tevent_req_create(mem_ctx, &state, struct wbc_lookup_sid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ ZERO_STRUCT(state->req);
+
+ state->req.cmd = WINBINDD_LOOKUPSID;
+ wbc_status = wbcSidToString(sid, &sid_string);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return tevent_req_post(req, ev);
+ }
+ strncpy(state->req.data.sid, sid_string, sizeof(state->req.data.sid)-1);
+ wbcFreeMemory(sid_string);
+
+ 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, wbcLookupSid_done, req);
+ return req;
+}
+
+static void wbcLookupSid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wbc_lookup_sid_state *state = tevent_req_data(
+ req, struct wbc_lookup_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->domain = talloc_strdup(state, resp->data.name.dom_name);
+ if (tevent_req_nomem(state->domain, req)) {
+ return;
+ }
+
+ state->name = talloc_strdup(state, resp->data.name.name);
+ if (tevent_req_nomem(state->name, req)) {
+ return;
+ }
+
+ state->name_type = (enum wbcSidType)resp->data.name.type;
+
+ TALLOC_FREE(resp);
+
+ tevent_req_done(req);
+}
+
+/**
+ * @brief Receive a conversion a SID to a domain and name
+ *
+ * @param *mem_ctx, talloc context to move results to
+ * @param *pdomain Resolved Domain name (possibly "")
+ * @param *pname Resolved User or group name
+ * @param *pname_type Pointer to the resolved SID type
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcLookupSid_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ char **pdomain,
+ char **pname,
+ enum wbcSidType *pname_type)
+{
+ struct wbc_lookup_sid_state *state = tevent_req_data(
+ req, struct wbc_lookup_sid_state);
+ wbcErr wbc_status;
+
+ if (tevent_req_is_wbcerr(req, &wbc_status)) {
+ tevent_req_received(req);
+ return wbc_status;
+ }
+
+ if (pdomain != NULL) {
+ *pdomain = talloc_steal(mem_ctx, state->domain);
+ }
+
+ if (pname != NULL) {
+ *pname = talloc_steal(mem_ctx, state->name);
+ }
+
+ if (pname_type != NULL) {
+ *pname_type = state->name_type;
+ }
+
+ tevent_req_received(req);
+ return WBC_ERR_SUCCESS;
+}
+
/* Convert a SID to a domain and name */
wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
char **pdomain,