summaryrefslogtreecommitdiff
path: root/nsswitch
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-02-14 10:06:05 +0100
committerKai Blin <kai@samba.org>2010-02-11 23:56:33 +0100
commit861ef367c839d44b185ae3dd9191e849a5e33027 (patch)
tree2fa90fafd784107ba791360d735dea62b199a7e3 /nsswitch
parent99c0f569f9a62b63e1d26418a777302b03c3fc7f (diff)
downloadsamba-861ef367c839d44b185ae3dd9191e849a5e33027.tar.gz
samba-861ef367c839d44b185ae3dd9191e849a5e33027.tar.bz2
samba-861ef367c839d44b185ae3dd9191e849a5e33027.zip
libwbclient: Add wbcDomainInfo_send/recv calls
Diffstat (limited to 'nsswitch')
-rw-r--r--nsswitch/libwbclient/wbc_async.h8
-rw-r--r--nsswitch/libwbclient/wbc_util.c148
2 files changed, 155 insertions, 1 deletions
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h
index 8a48e6bd18..081764aeb9 100644
--- a/nsswitch/libwbclient/wbc_async.h
+++ b/nsswitch/libwbclient/wbc_async.h
@@ -127,4 +127,12 @@ wbcErr wbcDomainName_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
char **netbios_name);
+struct tevent_req *wbcDomainInfo_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const char *domain);
+wbcErr wbcDomainInfo_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct wbcDomainInfo **dinfo);
+
#endif /*_WBC_ASYNC_H_*/
diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c
index fcec32af8a..f36ab13070 100644
--- a/nsswitch/libwbclient/wbc_util.c
+++ b/nsswitch/libwbclient/wbc_util.c
@@ -577,8 +577,154 @@ done:
return wbc_status;
}
+struct wbc_domain_info_state {
+ struct winbindd_request req;
+ struct wbcDomainInfo *info;
+};
+
+static void wbcDomainInfo_done(struct tevent_req *subreq);
+
+/**
+ * @brief Request status of a given trusted domain
+ *
+ * @param mem_ctx talloc context to allocate memory from
+ * @param ev tevent context to use for async requests
+ * @param wb_ctx winbind context
+ * @param domain domain to request status from
+ *
+ * @return tevent_req on success, NULL on failure
+ */
+
+struct tevent_req *wbcDomainInfo_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const char *domain)
+{
+ struct tevent_req *req, *subreq;
+ struct wbc_domain_info_state *state;
+
+ if (!domain) {
+ return NULL;
+ }
+
+ req = tevent_req_create(mem_ctx, &state, struct wbc_domain_info_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ state->info = talloc(state, struct wbcDomainInfo);
+ if (tevent_req_nomem(state->info, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ ZERO_STRUCT(state->req);
+
+ strncpy(state->req.domain_name, domain,
+ sizeof(state->req.domain_name)-1);
+
+ state->req.cmd = WINBINDD_DOMAIN_INFO;
+
+ 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, wbcDomainInfo_done, req);
+ return req;
+}
+
+static void wbcDomainInfo_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wbc_domain_info_state *state = tevent_req_data(
+ req, struct wbc_domain_info_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->info->short_name = talloc_strdup(state->info,
+ resp->data.domain_info.name);
+ if (tevent_req_nomem(state->info->short_name, req)) {
+ return;
+ }
+
+ state->info->dns_name = talloc_strdup(state->info,
+ resp->data.domain_info.alt_name);
+ if (tevent_req_nomem(state->info->dns_name, req)) {
+ return;
+ }
+
+ wbc_status = wbcStringToSid(resp->data.domain_info.sid,
+ &state->info->sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return;
+ }
+
+ if (resp->data.domain_info.native_mode) {
+ state->info->domain_flags |= WBC_DOMINFO_DOMAIN_NATIVE;
+ }
+ if (resp->data.domain_info.active_directory) {
+ state->info->domain_flags |= WBC_DOMINFO_DOMAIN_AD;
+ }
+ if (resp->data.domain_info.primary) {
+ state->info->domain_flags |= WBC_DOMINFO_DOMAIN_PRIMARY;
+ }
+
+ TALLOC_FREE(resp);
+
+ tevent_req_done(req);
+}
+
+/**
+ * @brief Receive information about a trusted domain
+ *
+ * @param req tevent_req containing the request
+ * @param mem_ctx talloc context to allocate memory from
+ * @param *dinfo pointer to returned struct wbcDomainInfo
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcDomainInfo_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct wbcDomainInfo **dinfo)
+{
+ struct wbc_domain_info_state *state = tevent_req_data(
+ req, struct wbc_domain_info_state);
+ wbcErr wbc_status;
+
+ if (tevent_req_is_wbcerr(req, &wbc_status)) {
+ tevent_req_received(req);
+ return wbc_status;
+ }
+
+ if (dinfo == NULL) {
+ tevent_req_received(req);
+ return WBC_ERR_INVALID_PARAM;
+ }
+
+ *dinfo = talloc_steal(mem_ctx, state->info);
+
+ tevent_req_received(req);
+ return WBC_ERR_SUCCESS;
+}
+
+/** @brief Lookup the current status of a trusted domain, sync wrapper
+ *
+ * @param domain Domain to query
+ * @param *dinfo Pointer to returned struct wbcDomainInfo
+ *
+ * @return #wbcErr
+ */
-/* Lookup the current status of a trusted domain */
wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
{
struct winbindd_request request;