libwbclient: Add wbcInterfaceDetails_send/recv
authorKai Blin <kai@samba.org>
Sun, 15 Feb 2009 10:01:44 +0000 (11:01 +0100)
committerKai Blin <kai@samba.org>
Thu, 11 Feb 2010 22:56:33 +0000 (23:56 +0100)
nsswitch/libwbclient/wbc_async.h
nsswitch/libwbclient/wbc_util.c
nsswitch/libwbclient/wbclient.h

index 081764aeb9233406ae229f841fd62a79bb4546f7..15115f2b7b2c690ab2f06a00b11398434ccded16 100644 (file)
@@ -127,6 +127,13 @@ wbcErr wbcDomainName_recv(struct tevent_req *req,
                          TALLOC_CTX *mem_ctx,
                          char **netbios_name);
 
+struct tevent_req *wbcInterfaceDetails_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct wb_context *wb_ctx);
+wbcErr wbcInterfaceDetails_recv(struct tevent_req *req,
+                               TALLOC_CTX *mem_ctx,
+                               struct wbcInterfaceDetails **details);
+
 struct tevent_req *wbcDomainInfo_send(TALLOC_CTX *mem_ctx,
                                      struct tevent_context *ev,
                                      struct wb_context *wb_ctx,
index f36ab13070e30b3fc8f8eeec8e743dc96b984b34..57506f214b5825e343930af656af86d5947d9afd 100644 (file)
@@ -503,6 +503,224 @@ wbcErr wbcDomainName_recv(struct tevent_req *req,
        return WBC_ERR_SUCCESS;
 }
 
+struct wbc_interface_details_state {
+       struct tevent_context *ev;
+       struct wb_context *wb_ctx;
+       struct wbcDomainInfo *dinfo;
+       struct wbcInterfaceDetails *details;
+};
+
+static void wbcInterfaceDetails_version(struct tevent_req *subreq);
+static void wbcInterfaceDetails_info(struct tevent_req *subreq);
+static void wbcInterfaceDetails_netbios_name(struct tevent_req *subreq);
+static void wbcInterfaceDetails_domain_name(struct tevent_req *subreq);
+static void wbcInterfaceDetails_domain_info(struct tevent_req *subreq);
+
+/**
+ * @brief Request some useful details about the winbind service
+ *
+ * @param mem_ctx      talloc context to allocate memory from
+ * @param ev           tevent context to use for async requests
+ * @param wb_ctx       winbind context
+ *
+ * @return tevent_req on success, NULL on failure
+ */
+
+struct tevent_req *wbcInterfaceDetails_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct wb_context *wb_ctx)
+{
+       struct tevent_req *req, *subreq;
+       struct wbc_interface_details_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct wbc_interface_details_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       state->ev = ev;
+       state->wb_ctx = wb_ctx;
+       state->details = talloc(state, struct wbcInterfaceDetails);
+       if (tevent_req_nomem(state->details, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = wbcInterfaceVersion_send(state, ev, wb_ctx);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       tevent_req_set_callback(subreq, wbcInterfaceDetails_version, req);
+       return req;
+}
+
+static void wbcInterfaceDetails_version(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_interface_details_state *state = tevent_req_data(
+                       req, struct wbc_interface_details_state);
+       wbcErr wbc_status;
+
+
+       wbc_status  = wbcInterfaceVersion_recv(subreq,
+                                       &state->details->interface_version);
+       TALLOC_FREE(subreq);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               tevent_req_error(req, wbc_status);
+               return;
+       }
+
+       subreq = wbcInfo_send(state, state->ev, state->wb_ctx);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+
+       tevent_req_set_callback(subreq, wbcInterfaceDetails_info, req);
+}
+
+static void wbcInterfaceDetails_info(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_interface_details_state *state = tevent_req_data(
+                       req, struct wbc_interface_details_state);
+       wbcErr wbc_status;
+
+       wbc_status  = wbcInfo_recv(subreq, state->details,
+                                  &state->details->winbind_separator,
+                                  &state->details->winbind_version);
+       TALLOC_FREE(subreq);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               tevent_req_error(req, wbc_status);
+               return;
+       }
+
+       subreq = wbcNetbiosName_send(state, state->ev, state->wb_ctx);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+
+       tevent_req_set_callback(subreq, wbcInterfaceDetails_netbios_name, req);
+}
+
+static void wbcInterfaceDetails_netbios_name(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_interface_details_state *state = tevent_req_data(
+                       req, struct wbc_interface_details_state);
+       wbcErr wbc_status;
+
+       wbc_status  = wbcNetbiosName_recv(subreq, state->details,
+                                         &state->details->netbios_name);
+       TALLOC_FREE(subreq);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               tevent_req_error(req, wbc_status);
+               return;
+       }
+
+       subreq = wbcDomainName_send(state, state->ev, state->wb_ctx);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+
+       tevent_req_set_callback(subreq, wbcInterfaceDetails_domain_name, req);
+}
+
+static void wbcInterfaceDetails_domain_name(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_interface_details_state *state = tevent_req_data(
+                       req, struct wbc_interface_details_state);
+       wbcErr wbc_status;
+
+       wbc_status  = wbcDomainName_recv(subreq, state->details,
+                                        &state->details->netbios_domain);
+       TALLOC_FREE(subreq);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               tevent_req_error(req, wbc_status);
+               return;
+       }
+
+       subreq = wbcDomainInfo_send(state, state->ev, state->wb_ctx,
+                                   state->details->netbios_domain);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+
+       tevent_req_set_callback(subreq, wbcInterfaceDetails_domain_info, req);
+}
+
+static void wbcInterfaceDetails_domain_info(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_interface_details_state *state = tevent_req_data(
+                       req, struct wbc_interface_details_state);
+       struct wbcDomainInfo *domain;
+       wbcErr wbc_status;
+
+       wbc_status = wbcDomainInfo_recv(subreq, state, &domain);
+       TALLOC_FREE(subreq);
+       if (wbc_status == WBC_ERR_DOMAIN_NOT_FOUND) {
+               tevent_req_done(req);
+               return;
+       }
+
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               tevent_req_error(req, wbc_status);
+               return;
+       }
+       state->details->dns_domain = talloc_strdup(state->details,
+                                                  domain->dns_name);
+       if (tevent_req_nomem(state->details->dns_domain, req)) {
+               return;
+       }
+
+       TALLOC_FREE(domain);
+       tevent_req_done(req);
+}
+
+/**
+ * @brief Receive useful information about the winbind service
+ *
+ * @param req          tevent_req containing the request
+ * @param mem_ctx      talloc context to allocate memory from
+ * @param *details     pointer to hold the struct wbcInterfaceDetails
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcInterfaceDetails_recv(struct tevent_req *req,
+                               TALLOC_CTX *mem_ctx,
+                               struct wbcInterfaceDetails **details)
+{
+       struct wbc_interface_details_state *state = tevent_req_data(
+                       req, struct wbc_interface_details_state);
+       wbcErr wbc_status;
+
+       if (tevent_req_is_wbcerr(req, &wbc_status)) {
+               tevent_req_received(req);
+               return wbc_status;
+       }
+
+       *details = talloc_steal(mem_ctx, state->details);
+
+       tevent_req_received(req);
+       return WBC_ERR_SUCCESS;
+}
+
+/**
+ * @brief Query useful information about the winbind service
+ *
+ * @param *_details    pointer to hold the struct wbcInterfaceDetails
+ *
+ * @return #wbcErr
+ */
+
 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
index 06f0713c8604fc9f231c6f4812910199f98b0dde..718c9f6885c46a6332330b5b814fce988590bdb3 100644 (file)
@@ -65,9 +65,10 @@ const char *wbcErrorString(wbcErr error);
  *      Added wbcGetSidAliases()
  *  0.4: Added wbcSidTypeString()
  *  0.5: Added wbcChangeTrustCredentials()
+ *  0.6: Made struct wbcInterfaceDetails char* members non-const
  **/
 #define WBCLIENT_MAJOR_VERSION 0
-#define WBCLIENT_MINOR_VERSION 5
+#define WBCLIENT_MINOR_VERSION 6
 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
 struct wbcLibraryDetails {
        uint16_t major_version;
@@ -81,11 +82,11 @@ struct wbcLibraryDetails {
  **/
 struct wbcInterfaceDetails {
        uint32_t interface_version;
-       const char *winbind_version;
+       char *winbind_version;
        char winbind_separator;
-       const char *netbios_name;
-       const char *netbios_domain;
-       const char *dns_domain;
+       char *netbios_name;
+       char *netbios_domain;
+       char *dns_domain;
 };
 
 /*