diff options
author | Kai Blin <kai@samba.org> | 2009-02-15 11:01:44 +0100 |
---|---|---|
committer | Kai Blin <kai@samba.org> | 2010-02-11 23:56:33 +0100 |
commit | 33bbe1cafda93d493509f5dabfdb0ed7bbe69a71 (patch) | |
tree | 73e8f52c82c4990c606eed005f214bad40ae90ce | |
parent | 861ef367c839d44b185ae3dd9191e849a5e33027 (diff) | |
download | samba-33bbe1cafda93d493509f5dabfdb0ed7bbe69a71.tar.gz samba-33bbe1cafda93d493509f5dabfdb0ed7bbe69a71.tar.bz2 samba-33bbe1cafda93d493509f5dabfdb0ed7bbe69a71.zip |
libwbclient: Add wbcInterfaceDetails_send/recv
-rw-r--r-- | nsswitch/libwbclient/wbc_async.h | 7 | ||||
-rw-r--r-- | nsswitch/libwbclient/wbc_util.c | 218 | ||||
-rw-r--r-- | nsswitch/libwbclient/wbclient.h | 11 |
3 files changed, 231 insertions, 5 deletions
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h index 081764aeb9..15115f2b7b 100644 --- a/nsswitch/libwbclient/wbc_async.h +++ b/nsswitch/libwbclient/wbc_async.h @@ -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, 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; diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h index 06f0713c86..718c9f6885 100644 --- a/nsswitch/libwbclient/wbclient.h +++ b/nsswitch/libwbclient/wbclient.h @@ -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; }; /* |