libwbclient: add wbcInterfaceVersion send/recv calls
authorKai Blin <kai@samba.org>
Wed, 11 Feb 2009 23:11:45 +0000 (00:11 +0100)
committerKai Blin <kai@samba.org>
Thu, 11 Feb 2010 22:56:32 +0000 (23:56 +0100)
nsswitch/libwbclient/wbc_async.h
nsswitch/libwbclient/wbc_util.c

index f3eab91633a7bad8b6fdde39e1920b923a1f2a26..e215fdd8e8d8165f1ee9c13ac4aa81dc1baf8385 100644 (file)
@@ -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_*/
index ddef8b644d334f281c4c2d96ebb3c484efacd58b..f72f4fc7493d4323f3273950a42fbb2b94280cd7 100644 (file)
@@ -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;