diff options
-rw-r--r-- | nsswitch/libwbclient/wbc_async.h | 6 | ||||
-rw-r--r-- | nsswitch/libwbclient/wbc_util.c | 92 |
2 files changed, 98 insertions, 0 deletions
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h index f3eab91633..e215fdd8e8 100644 --- a/nsswitch/libwbclient/wbc_async.h +++ b/nsswitch/libwbclient/wbc_async.h @@ -99,5 +99,11 @@ struct tevent_req *wbcPing_send(TALLOC_CTX *mem_ctx, struct wb_context *wb_ctx); wbcErr wbcPing_recv(struct tevent_req *req); +struct tevent_req *wbcInterfaceVersion_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct wb_context *wb_ctx); +wbcErr wbcInterfaceVersion_recv(struct tevent_req *req, + uint32_t *interface_version); + #endif /*_WBC_ASYNC_H_*/ diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c index ddef8b644d..f72f4fc749 100644 --- a/nsswitch/libwbclient/wbc_util.c +++ b/nsswitch/libwbclient/wbc_util.c @@ -123,6 +123,98 @@ wbcErr wbcPing(void) return wbcRequestResponse(WINBINDD_PING, &request, &response); } +struct wbc_interface_version_state { + struct winbindd_request req; + uint32_t version; +}; + +static void wbcInterfaceVersion_done(struct tevent_req *subreq); + +/** + * @brief Request the interface version from winbind + * + * @param mem_ctx talloc context to allocate memory from + * @param ev tevent context to use for async requests + * @param wb_ctx winbind context + * + * @return tevevt_req on success, NULL on failure + */ + +struct tevent_req *wbcInterfaceVersion_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct wb_context *wb_ctx) +{ + struct tevent_req *req, *subreq; + struct wbc_interface_version_state *state; + + req = tevent_req_create(mem_ctx, &state, struct wbc_interface_version_state); + if (req == NULL) { + return NULL; + } + + ZERO_STRUCT(state->req); + state->req.cmd = WINBINDD_INTERFACE_VERSION; + + 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, wbcInterfaceVersion_done, req); + + return req; +} + +static void wbcInterfaceVersion_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wbc_interface_version_state *state = tevent_req_data( + req, struct wbc_interface_version_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->version = resp->data.interface_version; + TALLOC_FREE(resp); + + tevent_req_done(req); +} + +/** + * @brief Receive the winbind interface version + * + * @param req tevent_req containing the request + * @param interface_version pointer to uint32_t to hold the interface + * version + * + * @return #wbcErr + */ + +wbcErr wbcInterfaceVersion_recv(struct tevent_req *req, + uint32_t *interface_version) +{ + struct wbc_interface_version_state *state = tevent_req_data( + req, struct wbc_interface_version_state); + wbcErr wbc_status; + + if (tevent_req_is_wbcerr(req, &wbc_status)) { + tevent_req_received(req); + return wbc_status; + } + + *interface_version = state->version; + + tevent_req_received(req); + return WBC_ERR_SUCCESS; +} + + wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; |