1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s4:winbind: convert wb_update_rodc_dns_send/recv to tevent_req

metze
This commit is contained in:
Stefan Metzmacher 2012-08-24 17:39:58 +02:00
parent 0ccdaa940a
commit d4aa8978cc
2 changed files with 125 additions and 81 deletions

View File

@ -79,7 +79,7 @@ struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state {
struct winbind_DsrUpdateReadOnlyServerDnsRecords *req; struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
}; };
static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx); static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct tevent_req *subreq);
static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *msg, static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *msg,
struct winbind_DsrUpdateReadOnlyServerDnsRecords *req) struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
@ -87,7 +87,7 @@ static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *m
struct wbsrv_service *service = talloc_get_type(msg->private_data, struct wbsrv_service *service = talloc_get_type(msg->private_data,
struct wbsrv_service); struct wbsrv_service);
struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s; struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s;
struct composite_context *ctx; struct tevent_req *subreq;
DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n")); DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n"));
@ -97,25 +97,30 @@ static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *m
s->msg = msg; s->msg = msg;
s->req = req; s->req = req;
ctx = wb_update_rodc_dns_send(msg, service, req); subreq = wb_update_rodc_dns_send(s,
NT_STATUS_HAVE_NO_MEMORY(ctx); service->task->event_ctx,
service, req);
NT_STATUS_HAVE_NO_MEMORY(subreq);
ctx->async.fn = wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback; tevent_req_set_callback(subreq,
ctx->async.private_data = s; wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback,
s);
msg->defer_reply = true; msg->defer_reply = true;
return NT_STATUS_OK; return NT_STATUS_OK;
} }
static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx) static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct tevent_req *subreq)
{ {
struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s = talloc_get_type(ctx->async.private_data, struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s =
struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state); tevent_req_callback_data(subreq,
struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
NTSTATUS status; NTSTATUS status;
DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback called\n")); DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback called\n"));
status = wb_update_rodc_dns_recv(ctx, s, s->req); status = wb_update_rodc_dns_recv(subreq, s, s->req);
TALLOC_FREE(subreq);
irpc_send_reply(s->msg, status); irpc_send_reply(s->msg, status);
} }

View File

@ -27,6 +27,8 @@
*/ */
#include "includes.h" #include "includes.h"
#include <tevent.h>
#include "../lib/util/tevent_ntstatus.h"
#include "libcli/composite/composite.h" #include "libcli/composite/composite.h"
#include "winbind/wb_server.h" #include "winbind/wb_server.h"
#include "smbd/service_task.h" #include "smbd/service_task.h"
@ -36,7 +38,7 @@
#include "librpc/gen_ndr/winbind.h" #include "librpc/gen_ndr/winbind.h"
struct wb_update_rodc_dns_state { struct wb_update_rodc_dns_state {
struct composite_context *ctx; struct tevent_context *ev;
struct winbind_DsrUpdateReadOnlyServerDnsRecords *req; struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
@ -47,62 +49,76 @@ struct wb_update_rodc_dns_state {
struct netr_DsrUpdateReadOnlyServerDnsRecords r; struct netr_DsrUpdateReadOnlyServerDnsRecords r;
}; };
static void wb_update_rodc_dns_recv_domain(struct composite_context *ctx); static void wb_update_rodc_dns_recv_domain(struct composite_context *csubreq);
static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq); static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq);
/* /*
Find the connection to the DC (or find an existing connection) Find the connection to the DC (or find an existing connection)
*/ */
struct composite_context *wb_update_rodc_dns_send(TALLOC_CTX *mem_ctx, struct tevent_req *wb_update_rodc_dns_send(TALLOC_CTX *mem_ctx,
struct wbsrv_service *service, struct tevent_context *ev,
struct winbind_DsrUpdateReadOnlyServerDnsRecords *req) struct wbsrv_service *service,
struct winbind_DsrUpdateReadOnlyServerDnsRecords *_req)
{ {
struct composite_context *c, *creq; struct tevent_req *req;
struct wb_update_rodc_dns_state *s; struct wb_update_rodc_dns_state *state;
struct composite_context *csubreq;
c = composite_create(mem_ctx, service->task->event_ctx); req = tevent_req_create(mem_ctx, &state,
if (!c) return NULL; struct wb_update_rodc_dns_state);
if (req == NULL) {
return NULL;
}
state->ev = ev;
state->req = _req;
s = talloc_zero(c, struct wb_update_rodc_dns_state); csubreq = wb_sid2domain_send(state, service, service->primary_sid);
if (composite_nomem(s, c)) return c; if (tevent_req_nomem(csubreq, req)) {
s->ctx = c; return tevent_req_post(req, ev);
s->req = req; }
csubreq->async.fn = wb_update_rodc_dns_recv_domain;
csubreq->async.private_data = req;
c->private_data = s; return req;
creq = wb_sid2domain_send(s, service, service->primary_sid);
composite_continue(c, creq, wb_update_rodc_dns_recv_domain, s);
return c;
} }
/* /*
Having finished making the connection to the DC Having finished making the connection to the DC
Send of a DsrUpdateReadOnlyServerDnsRecords request to authenticate a user. Send of a DsrUpdateReadOnlyServerDnsRecords request to authenticate a user.
*/ */
static void wb_update_rodc_dns_recv_domain(struct composite_context *creq) static void wb_update_rodc_dns_recv_domain(struct composite_context *csubreq)
{ {
struct wb_update_rodc_dns_state *s = talloc_get_type(creq->async.private_data, struct tevent_req *req =
struct wb_update_rodc_dns_state); talloc_get_type_abort(csubreq->async.private_data,
struct tevent_req);
struct wb_update_rodc_dns_state *state =
tevent_req_data(req,
struct wb_update_rodc_dns_state);
NTSTATUS status;
struct wbsrv_domain *domain; struct wbsrv_domain *domain;
struct tevent_req *subreq; struct tevent_req *subreq;
s->ctx->status = wb_sid2domain_recv(creq, &domain); status = wb_sid2domain_recv(csubreq, &domain);
if (!composite_is_ok(s->ctx)) return; if (tevent_req_nterror(req, status)) {
return;
}
s->creds_state = cli_credentials_get_netlogon_creds(domain->libnet_ctx->cred); state->creds_state = cli_credentials_get_netlogon_creds(domain->libnet_ctx->cred);
netlogon_creds_client_authenticator(s->creds_state, &s->auth1); netlogon_creds_client_authenticator(state->creds_state, &state->auth1);
s->r.in.server_name = talloc_asprintf(s, "\\\\%s", state->r.in.server_name = talloc_asprintf(state, "\\\\%s",
dcerpc_server_name(domain->netlogon_pipe)); dcerpc_server_name(domain->netlogon_pipe));
if (composite_nomem(s->r.in.server_name, s->ctx)) return; if (tevent_req_nomem(state->r.in.server_name, req)) {
return;
}
s->r.in.computer_name = cli_credentials_get_workstation(domain->libnet_ctx->cred); state->r.in.computer_name = cli_credentials_get_workstation(domain->libnet_ctx->cred);
s->r.in.credential = &s->auth1; state->r.in.credential = &state->auth1;
s->r.out.return_authenticator = &s->auth2; state->r.out.return_authenticator = &state->auth2;
s->r.in.site_name = s->req->in.site_name; state->r.in.site_name = state->req->in.site_name;
s->r.in.dns_ttl = s->req->in.dns_ttl; state->r.in.dns_ttl = state->req->in.dns_ttl;
s->r.in.dns_names = s->req->in.dns_names; state->r.in.dns_names = state->req->in.dns_names;
s->r.out.dns_names = s->req->in.dns_names; state->r.out.dns_names = state->req->in.dns_names;
/* /*
* use a new talloc context for the DsrUpdateReadOnlyServerDnsRecords call * use a new talloc context for the DsrUpdateReadOnlyServerDnsRecords call
@ -110,15 +126,19 @@ static void wb_update_rodc_dns_recv_domain(struct composite_context *creq)
* in the final _recv() function to give the caller all the content of * in the final _recv() function to give the caller all the content of
* the s->r.out.dns_names * the s->r.out.dns_names
*/ */
s->r_mem_ctx = talloc_new(s); state->r_mem_ctx = talloc_new(state);
if (composite_nomem(s->r_mem_ctx, s->ctx)) return; if (tevent_req_nomem(state->r_mem_ctx, req)) {
return;
}
subreq = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_send(s, subreq = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_send(state,
s->ctx->event_ctx, state->ev,
domain->netlogon_pipe->binding_handle, domain->netlogon_pipe->binding_handle,
&s->r); &state->r);
if (composite_nomem(subreq, s->ctx)) return; if (tevent_req_nomem(subreq, req)) {
tevent_req_set_callback(subreq, wb_update_rodc_dns_recv_response, s); return;
}
tevent_req_set_callback(subreq, wb_update_rodc_dns_recv_response, req);
} }
/* /*
@ -128,40 +148,59 @@ static void wb_update_rodc_dns_recv_domain(struct composite_context *creq)
*/ */
static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq) static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq)
{ {
struct wb_update_rodc_dns_state *s = tevent_req_callback_data(subreq, struct tevent_req *req =
struct wb_update_rodc_dns_state); tevent_req_callback_data(subreq,
struct tevent_req);
struct wb_update_rodc_dns_state *state =
tevent_req_data(req,
struct wb_update_rodc_dns_state);
NTSTATUS status;
bool ok;
s->ctx->status = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_recv(subreq, s->r_mem_ctx); status = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_recv(subreq,
state->r_mem_ctx);
TALLOC_FREE(subreq); TALLOC_FREE(subreq);
if (!composite_is_ok(s->ctx)) return; if (tevent_req_nterror(req, status)) {
s->ctx->status = s->r.out.result;
if (!composite_is_ok(s->ctx)) return;
if ((s->r.out.return_authenticator == NULL) ||
(!netlogon_creds_client_check(s->creds_state,
&s->r.out.return_authenticator->cred))) {
DEBUG(0, ("Credentials check failed!\n"));
composite_error(s->ctx, NT_STATUS_ACCESS_DENIED);
return; return;
} }
composite_done(s->ctx); if (tevent_req_nterror(req, state->r.out.result)) {
} return;
NTSTATUS wb_update_rodc_dns_recv(struct composite_context *c,
TALLOC_CTX *mem_ctx,
struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
{
struct wb_update_rodc_dns_state *s = talloc_get_type(c->private_data,
struct wb_update_rodc_dns_state);
NTSTATUS status = composite_wait(c);
if (NT_STATUS_IS_OK(status)) {
talloc_steal(mem_ctx, s->r_mem_ctx);
req->out.dns_names = s->r.out.dns_names;
} }
talloc_free(s); if (state->r.out.return_authenticator == NULL) {
return status; tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
ok = netlogon_creds_client_check(state->creds_state,
&state->r.out.return_authenticator->cred);
if (!ok) {
DEBUG(0, ("Credentials check failed!\n"));
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
tevent_req_done(req);
}
NTSTATUS wb_update_rodc_dns_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
struct winbind_DsrUpdateReadOnlyServerDnsRecords *_req)
{
struct wb_update_rodc_dns_state *state =
tevent_req_data(req,
struct wb_update_rodc_dns_state);
NTSTATUS status;
if (tevent_req_is_nterror(req, &status)) {
tevent_req_received(req);
return status;
}
talloc_steal(mem_ctx, state->r_mem_ctx);
_req->out.dns_names = state->r.out.dns_names;
tevent_req_received(req);
return NT_STATUS_OK;
} }