summaryrefslogtreecommitdiff
path: root/nsswitch/libwbclient/wbc_util.c
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-02-15 11:01:44 +0100
committerKai Blin <kai@samba.org>2010-02-11 23:56:33 +0100
commit33bbe1cafda93d493509f5dabfdb0ed7bbe69a71 (patch)
tree73e8f52c82c4990c606eed005f214bad40ae90ce /nsswitch/libwbclient/wbc_util.c
parent861ef367c839d44b185ae3dd9191e849a5e33027 (diff)
downloadsamba-33bbe1cafda93d493509f5dabfdb0ed7bbe69a71.tar.gz
samba-33bbe1cafda93d493509f5dabfdb0ed7bbe69a71.tar.bz2
samba-33bbe1cafda93d493509f5dabfdb0ed7bbe69a71.zip
libwbclient: Add wbcInterfaceDetails_send/recv
Diffstat (limited to 'nsswitch/libwbclient/wbc_util.c')
-rw-r--r--nsswitch/libwbclient/wbc_util.c218
1 files changed, 218 insertions, 0 deletions
diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c
index f36ab13070..57506f214b 100644
--- a/nsswitch/libwbclient/wbc_util.c
+++ b/nsswitch/libwbclient/wbc_util.c
@@ -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;