libwbclient: Add wbcDomainName_send/recv call
authorKai Blin <kai@samba.org>
Fri, 13 Feb 2009 21:51:52 +0000 (22:51 +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

index daf1e6bd647ce9ca909e8bc52a6a4f9a5f5f375e..8a48e6bd188380cf659051a0ba582df6f54b0c01 100644 (file)
@@ -120,4 +120,11 @@ wbcErr wbcNetbiosName_recv(struct tevent_req *req,
                           TALLOC_CTX *mem_ctx,
                           char **netbios_name);
 
+struct tevent_req *wbcDomainName_send(TALLOC_CTX *mem_ctx,
+                                     struct tevent_context *ev,
+                                     struct wb_context *wb_ctx);
+wbcErr wbcDomainName_recv(struct tevent_req *req,
+                         TALLOC_CTX *mem_ctx,
+                         char **netbios_name);
+
 #endif /*_WBC_ASYNC_H_*/
index fca0b061af3090ba6f373bda145b4c610b366251..fcec32af8a8fc83e775bbe7baa02852449b5152d 100644 (file)
@@ -409,6 +409,100 @@ wbcErr wbcNetbiosName_recv(struct tevent_req *req,
        return WBC_ERR_SUCCESS;
 }
 
+struct wbc_domain_name_state {
+       struct winbindd_request req;
+       char *domain_name;
+};
+
+static void wbcDomainName_done(struct tevent_req *subreq);
+
+/**
+ * @brief Request the machine's domain name
+ *
+ * @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 *wbcDomainName_send(TALLOC_CTX *mem_ctx,
+                                     struct tevent_context *ev,
+                                     struct wb_context *wb_ctx)
+{
+       struct tevent_req *req, *subreq;
+       struct wbc_domain_name_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct wbc_domain_name_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       ZERO_STRUCT(state->req);
+       state->req.cmd = WINBINDD_DOMAIN_NAME;
+
+       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, wbcDomainName_done, req);
+       return req;
+}
+
+static void wbcDomainName_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_domain_name_state *state = tevent_req_data(
+                       req, struct wbc_domain_name_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_name = talloc_strdup(state, resp->data.domain_name);
+       if (tevent_req_nomem(state->domain_name, subreq)) {
+               return;
+       }
+       TALLOC_FREE(resp);
+
+       tevent_req_done(req);
+}
+
+/**
+ * @brief Receive the machine's domain name
+ *
+ * @param req          tevent_req containing the request
+ * @param mem_ctx      talloc context to allocate memory from
+ * @param domain_name  pointer to a string to hold the domain name
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcDomainName_recv(struct tevent_req *req,
+                         TALLOC_CTX *mem_ctx,
+                         char **domain_name)
+{
+       struct wbc_domain_name_state *state = tevent_req_data(
+                       req, struct wbc_domain_name_state);
+       wbcErr wbc_status;
+
+       if (tevent_req_is_wbcerr(req, &wbc_status)) {
+               tevent_req_received(req);
+               return wbc_status;
+       }
+
+       *domain_name = talloc_steal(mem_ctx, state->domain_name);
+
+       tevent_req_received(req);
+       return WBC_ERR_SUCCESS;
+}
+
 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;