1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

s4:winbind: convert wb_sid2domain to tevent_req internally

The public wrapper still uses composite_context, because I don't
have time to fix all the callers...

metze
This commit is contained in:
Stefan Metzmacher 2012-08-23 13:14:17 +02:00
parent 89a5a71654
commit d3756d8738

View File

@ -20,6 +20,8 @@
*/
#include "includes.h"
#include <tevent.h>
#include "../lib/util/tevent_ntstatus.h"
#include "libcli/composite/composite.h"
#include "winbind/wb_server.h"
#include "smbd/service_task.h"
@ -43,25 +45,214 @@ static struct wbsrv_domain *find_domain_from_sid(struct wbsrv_service *service,
return domain;
}
struct sid2domain_state {
struct composite_context *ctx;
struct wb_sid2domain_state {
struct wbsrv_service *service;
struct dom_sid *sid;
struct dom_sid sid;
struct wbsrv_domain *domain;
};
static void sid2domain_recv_dom_info(struct composite_context *ctx);
static void sid2domain_recv_name(struct composite_context *ctx);
static void sid2domain_recv_trusted_dom_info(struct composite_context *ctx);
static void sid2domain_recv_init(struct composite_context *ctx);
static void wb_sid2domain_recv_dom_info(struct composite_context *ctx);
static void wb_sid2domain_recv_name(struct composite_context *ctx);
static void wb_sid2domain_recv_trusted_dom_info(struct composite_context *ctx);
static void wb_sid2domain_recv_init(struct composite_context *ctx);
static struct tevent_req *_wb_sid2domain_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct wbsrv_service *service,
const struct dom_sid *sid)
{
struct tevent_req *req;
struct wb_sid2domain_state *state;
struct composite_context *ctx;
DEBUG(5, ("wb_sid2domain_send called\n"));
req = tevent_req_create(mem_ctx, &state,
struct wb_sid2domain_state);
if (req == NULL) {
return NULL;
}
state->service = service;
state->sid = *sid;
state->domain = find_domain_from_sid(service, sid);
if (state->domain != NULL) {
tevent_req_done(req);
return tevent_req_post(req, ev);
}
if (dom_sid_equal(service->primary_sid, sid) ||
dom_sid_in_domain(service->primary_sid, sid)) {
ctx = wb_get_dom_info_send(state, service,
lpcfg_workgroup(service->task->lp_ctx),
lpcfg_realm(service->task->lp_ctx),
service->primary_sid);
if (tevent_req_nomem(ctx, req)) {
return tevent_req_post(req, ev);
}
ctx->async.fn = wb_sid2domain_recv_dom_info;
ctx->async.private_data = req;
return req;
}
ctx = wb_cmd_lookupsid_send(state, service, &state->sid);
if (tevent_req_nomem(ctx, req)) {
return tevent_req_post(req, ev);
}
ctx->async.fn = wb_sid2domain_recv_name;
ctx->async.private_data = req;
return req;
}
static void wb_sid2domain_recv_dom_info(struct composite_context *ctx)
{
struct tevent_req *req =
talloc_get_type_abort(ctx->async.private_data,
struct tevent_req);
struct wb_sid2domain_state *state =
tevent_req_data(req,
struct wb_sid2domain_state);
struct wb_dom_info *info;
NTSTATUS status;
status = wb_get_dom_info_recv(ctx, state, &info);
if (tevent_req_nterror(req, status)) {
return;
}
ctx = wb_init_domain_send(state, state->service, info);
if (tevent_req_nomem(ctx, req)) {
return;
}
ctx->async.fn = wb_sid2domain_recv_init;
ctx->async.private_data = req;
}
static void wb_sid2domain_recv_name(struct composite_context *ctx)
{
struct tevent_req *req =
talloc_get_type_abort(ctx->async.private_data,
struct tevent_req);
struct wb_sid2domain_state *state =
tevent_req_data(req,
struct wb_sid2domain_state);
struct wb_sid_object *name;
NTSTATUS status;
status = wb_cmd_lookupsid_recv(ctx, state, &name);
if (tevent_req_nterror(req, status)) {
return;
}
if (name->type == SID_NAME_UNKNOWN) {
tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
return;
}
if (name->type != SID_NAME_DOMAIN) {
state->sid.num_auths -= 1;
}
ctx = wb_trusted_dom_info_send(state, state->service, name->domain,
&state->sid);
if (tevent_req_nomem(ctx, req)) {
return;
}
ctx->async.fn = wb_sid2domain_recv_trusted_dom_info;
ctx->async.private_data = req;
}
static void wb_sid2domain_recv_trusted_dom_info(struct composite_context *ctx)
{
struct tevent_req *req =
talloc_get_type_abort(ctx->async.private_data,
struct tevent_req);
struct wb_sid2domain_state *state =
tevent_req_data(req,
struct wb_sid2domain_state);
struct wb_dom_info *info;
NTSTATUS status;
status = wb_trusted_dom_info_recv(ctx, state, &info);
if (tevent_req_nterror(req, status)) {
return;
}
ctx = wb_init_domain_send(state, state->service, info);
if (tevent_req_nomem(ctx, req)) {
return;
}
ctx->async.fn = wb_sid2domain_recv_init;
ctx->async.private_data = req;
}
static void wb_sid2domain_recv_init(struct composite_context *ctx)
{
struct tevent_req *req =
talloc_get_type_abort(ctx->async.private_data,
struct tevent_req);
struct wb_sid2domain_state *state =
tevent_req_data(req,
struct wb_sid2domain_state);
struct wbsrv_domain *existing;
NTSTATUS status;
status = wb_init_domain_recv(ctx, state, &state->domain);
if (tevent_req_nterror(req, status)) {
DEBUG(10, ("Could not init domain\n"));
return;
}
existing = find_domain_from_sid(state->service, &state->sid);
if (existing != NULL) {
DEBUG(5, ("Initialized domain twice, dropping second one\n"));
talloc_free(state->domain);
state->domain = existing;
} else {
talloc_steal(state->service, state->domain);
DLIST_ADD(state->service->domains, state->domain);
}
tevent_req_done(req);
}
static NTSTATUS _wb_sid2domain_recv(struct tevent_req *req,
struct wbsrv_domain **result)
{
struct wb_sid2domain_state *state =
tevent_req_data(req,
struct wb_sid2domain_state);
NTSTATUS status;
if (tevent_req_is_nterror(req, &status)) {
tevent_req_received(req);
return status;
}
*result = state->domain;
tevent_req_received(req);
return NT_STATUS_OK;
}
struct sid2domain_state {
struct composite_context *ctx;
struct wbsrv_domain *domain;
};
static void sid2domain_recv_domain(struct tevent_req *subreq);
struct composite_context *wb_sid2domain_send(TALLOC_CTX *mem_ctx,
struct wbsrv_service *service,
const struct dom_sid *sid)
{
struct composite_context *result, *ctx;
struct composite_context *result;
struct sid2domain_state *state;
struct tevent_req *subreq;
DEBUG(5, ("wb_sid2domain_send called\n"));
result = composite_create(mem_ctx, service->task->event_ctx);
if (result == NULL) goto failed;
@ -71,32 +262,11 @@ struct composite_context *wb_sid2domain_send(TALLOC_CTX *mem_ctx,
state->ctx = result;
result->private_data = state;
state->service = service;
state->sid = dom_sid_dup(state, sid);
if (state->sid == NULL) goto failed;
state->domain = find_domain_from_sid(service, sid);
if (state->domain != NULL) {
result->status = NT_STATUS_OK;
composite_done(result);
return result;
}
if (dom_sid_equal(service->primary_sid, sid) ||
dom_sid_in_domain(service->primary_sid, sid)) {
ctx = wb_get_dom_info_send(state, service,
lpcfg_workgroup(service->task->lp_ctx),
lpcfg_realm(service->task->lp_ctx),
service->primary_sid);
if (ctx == NULL) goto failed;
ctx->async.fn = sid2domain_recv_dom_info;
ctx->async.private_data = state;
return result;
}
ctx = wb_cmd_lookupsid_send(state, service, state->sid);
if (ctx == NULL) goto failed;
composite_continue(result, ctx, sid2domain_recv_name, state);
subreq = _wb_sid2domain_send(state,
result->event_ctx,
service, sid);
if (subreq == NULL) goto failed;
tevent_req_set_callback(subreq, sid2domain_recv_domain, state);
return result;
@ -106,86 +276,16 @@ struct composite_context *wb_sid2domain_send(TALLOC_CTX *mem_ctx,
}
static void sid2domain_recv_dom_info(struct composite_context *ctx)
static void sid2domain_recv_domain(struct tevent_req *subreq)
{
struct sid2domain_state *state =
talloc_get_type(ctx->async.private_data,
tevent_req_callback_data(subreq,
struct sid2domain_state);
struct wb_dom_info *info;
state->ctx->status = wb_get_dom_info_recv(ctx, state, &info);
state->ctx->status = _wb_sid2domain_recv(subreq, &state->domain);
TALLOC_FREE(subreq);
if (!composite_is_ok(state->ctx)) return;
ctx = wb_init_domain_send(state, state->service, info);
composite_continue(state->ctx, ctx, sid2domain_recv_init, state);
}
static void sid2domain_recv_name(struct composite_context *ctx)
{
struct sid2domain_state *state =
talloc_get_type(ctx->async.private_data,
struct sid2domain_state);
struct wb_sid_object *name;
state->ctx->status = wb_cmd_lookupsid_recv(ctx, state, &name);
if (!composite_is_ok(state->ctx)) return;
if (name->type == SID_NAME_UNKNOWN) {
composite_error(state->ctx, NT_STATUS_NO_SUCH_DOMAIN);
return;
}
if (name->type != SID_NAME_DOMAIN) {
state->sid->num_auths -= 1;
}
ctx = wb_trusted_dom_info_send(state, state->service, name->domain,
state->sid);
composite_continue(state->ctx, ctx, sid2domain_recv_trusted_dom_info,
state);
}
static void sid2domain_recv_trusted_dom_info(struct composite_context *ctx)
{
struct sid2domain_state *state =
talloc_get_type(ctx->async.private_data,
struct sid2domain_state);
struct wb_dom_info *info;
state->ctx->status = wb_trusted_dom_info_recv(ctx, state, &info);
if (!composite_is_ok(state->ctx)) return;
ctx = wb_init_domain_send(state, state->service, info);
composite_continue(state->ctx, ctx, sid2domain_recv_init, state);
}
static void sid2domain_recv_init(struct composite_context *ctx)
{
struct sid2domain_state *state =
talloc_get_type(ctx->async.private_data,
struct sid2domain_state);
struct wbsrv_domain *existing;
state->ctx->status = wb_init_domain_recv(ctx, state,
&state->domain);
if (!composite_is_ok(state->ctx)) {
DEBUG(10, ("Could not init domain\n"));
return;
}
existing = find_domain_from_sid(state->service, state->sid);
if (existing != NULL) {
DEBUG(5, ("Initialized domain twice, dropping second one\n"));
talloc_free(state->domain);
state->domain = existing;
}
talloc_steal(state->service, state->domain);
DLIST_ADD(state->service->domains, state->domain);
composite_done(state->ctx);
}