summaryrefslogtreecommitdiff
path: root/source4/winbind/wb_async_helpers.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2005-10-15 19:18:05 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:44:48 -0500
commit42ececdfae15a34205638cc6e3ec53d6f3ac2148 (patch)
treeca9b6b82f861b11c3f0362e5bb863d7efa62f953 /source4/winbind/wb_async_helpers.c
parent9259f9ecc0ab6fa3faeb582796d59420e71fc069 (diff)
downloadsamba-42ececdfae15a34205638cc6e3ec53d6f3ac2148.tar.gz
samba-42ececdfae15a34205638cc6e3ec53d6f3ac2148.tar.bz2
samba-42ececdfae15a34205638cc6e3ec53d6f3ac2148.zip
r11093: Implement wb_queue_domain_send: If the domain is not yet initialized, do that
first. And if a request is being processed, queue it. This correctly survived 3 endless loops with wbinfo's doing different things while starting up smbd. The number of indirections starts to become a bit scary, but what can you do without a decent programming language that provides closures :-) One thing that we might consider is to auto-generate async rpc requests that return composite_context structs instead of rpc_requests. Otherwise I'd have to write a lot of wrappers like composite_netr_LogonSamLogon_send. The alternative would be to write two versions of wb_queue_domain_send which I would like to avoid. This is cluttered enough already. Volker (This used to be commit 66c1b674f9870de73cce0e611909caf9eff34baa)
Diffstat (limited to 'source4/winbind/wb_async_helpers.c')
-rw-r--r--source4/winbind/wb_async_helpers.c135
1 files changed, 78 insertions, 57 deletions
diff --git a/source4/winbind/wb_async_helpers.c b/source4/winbind/wb_async_helpers.c
index 0480304abe..146a957727 100644
--- a/source4/winbind/wb_async_helpers.c
+++ b/source4/winbind/wb_async_helpers.c
@@ -66,6 +66,7 @@ struct composite_context *wb_finddcs_send(const char *domain_name,
result = talloc_zero(NULL, struct composite_context);
if (result == NULL) goto failed;
result->state = COMPOSITE_STATE_IN_PROGRESS;
+ result->async.fn = NULL;
result->event_ctx = event_ctx;
state = talloc(result, struct finddcs_state);
@@ -197,6 +198,7 @@ struct composite_context *wb_get_schannel_creds_send(struct cli_credentials *wks
result = talloc_zero(NULL, struct composite_context);
if (result == NULL) goto failed;
result->state = COMPOSITE_STATE_IN_PROGRESS;
+ result->async.fn = NULL;
result->event_ctx = ev;
state = talloc(result, struct get_schannel_creds_state);
@@ -384,6 +386,7 @@ struct composite_context *wb_lsa_lookupnames_send(struct dcerpc_pipe *lsa_pipe,
result = talloc_zero(NULL, struct composite_context);
if (result == NULL) goto failed;
result->state = COMPOSITE_STATE_IN_PROGRESS;
+ result->async.fn = NULL;
result->event_ctx = lsa_pipe->conn->event_ctx;
state = talloc(result, struct lsa_lookupnames_state);
@@ -506,94 +509,68 @@ struct cmd_lookupname_state {
struct wb_sid_object *result;
};
-static void cmd_lookupname_recv_init(struct composite_context *ctx);
-static void cmd_lookupname_recv_sid(struct composite_context *ctx);
+static struct composite_context *lookupname_send_req(void *p);
+static NTSTATUS lookupname_recv_req(struct composite_context *ctx, void *p);
struct composite_context *wb_cmd_lookupname_send(struct wbsrv_call *call,
const char *name)
{
- struct composite_context *result, *ctx;
struct cmd_lookupname_state *state;
struct wbsrv_service *service = call->wbconn->listen_socket->service;
- result = talloc_zero(call, struct composite_context);
- if (result == NULL) goto failed;
- result->state = COMPOSITE_STATE_IN_PROGRESS;
- result->event_ctx = call->event_ctx;
-
- state = talloc(result, struct cmd_lookupname_state);
- if (state == NULL) goto failed;
- state->ctx = result;
- result->private_data = state;
-
+ state = talloc(NULL, struct cmd_lookupname_state);
+ state->domain = service->domains;
state->call = call;
state->name = talloc_strdup(state, name);
-
- state->domain = service->domains;
-
- if (state->domain->initialized) {
- ctx = wb_lsa_lookupnames_send(state->domain->lsa_pipe,
- state->domain->lsa_policy,
- 1, &state->name);
- if (ctx == NULL) goto failed;
- ctx->async.fn = cmd_lookupname_recv_sid;
- ctx->async.private_data = state;
- return result;
+ state->ctx = wb_queue_domain_send(state, state->domain,
+ call->event_ctx,
+ call->wbconn->conn->msg_ctx,
+ lookupname_send_req,
+ lookupname_recv_req,
+ state);
+ if (state->ctx == NULL) {
+ talloc_free(state);
+ return NULL;
}
-
- ctx = wb_init_domain_send(state->domain,
- result->event_ctx,
- call->wbconn->conn->msg_ctx);
- if (ctx == NULL) goto failed;
- ctx->async.fn = cmd_lookupname_recv_init;
- ctx->async.private_data = state;
- return result;
-
- failed:
- talloc_free(result);
- return NULL;
+ state->ctx->private_data = state;
+ return state->ctx;
}
-static void cmd_lookupname_recv_init(struct composite_context *ctx)
+static struct composite_context *lookupname_send_req(void *p)
{
struct cmd_lookupname_state *state =
- talloc_get_type(ctx->async.private_data,
- struct cmd_lookupname_state);
+ talloc_get_type(p, struct cmd_lookupname_state);
- state->ctx->status = wb_init_domain_recv(ctx);
- if (!composite_is_ok(state->ctx)) return;
-
- ctx = wb_lsa_lookupnames_send(state->domain->lsa_pipe,
- state->domain->lsa_policy,
- 1, &state->name);
- composite_continue(state->ctx, ctx, cmd_lookupname_recv_sid, state);
+ return wb_lsa_lookupnames_send(state->domain->lsa_pipe,
+ state->domain->lsa_policy,
+ 1, &state->name);
}
-static void cmd_lookupname_recv_sid(struct composite_context *ctx)
+static NTSTATUS lookupname_recv_req(struct composite_context *ctx, void *p)
{
struct cmd_lookupname_state *state =
- talloc_get_type(ctx->async.private_data,
- struct cmd_lookupname_state);
+ talloc_get_type(p, struct cmd_lookupname_state);
struct wb_sid_object **sids;
+ NTSTATUS status;
- state->ctx->status = wb_lsa_lookupnames_recv(ctx, state, &sids);
- if (!composite_is_ok(state->ctx)) return;
- state->result = sids[0];
- composite_done(state->ctx);
+ status = wb_lsa_lookupnames_recv(ctx, state, &sids);
+ if (NT_STATUS_IS_OK(status)) {
+ state->result = sids[0];
+ }
+ return status;
}
NTSTATUS wb_cmd_lookupname_recv(struct composite_context *c,
TALLOC_CTX *mem_ctx,
struct wb_sid_object **sid)
{
+ struct cmd_lookupname_state *state =
+ talloc_get_type(c->private_data, struct cmd_lookupname_state);
NTSTATUS status = composite_wait(c);
if (NT_STATUS_IS_OK(status)) {
- struct cmd_lookupname_state *state =
- talloc_get_type(c->private_data,
- struct cmd_lookupname_state);
*sid = talloc_steal(mem_ctx, state->result);
}
- talloc_free(c);
+ talloc_free(state);
return status;
}
@@ -622,6 +599,7 @@ struct composite_context *wb_cmd_checkmachacc_send(struct wbsrv_call *call)
result = talloc(call, struct composite_context);
if (result == NULL) goto failed;
result->state = COMPOSITE_STATE_IN_PROGRESS;
+ result->async.fn = NULL;
result->event_ctx = call->event_ctx;
state = talloc(result, struct cmd_checkmachacc_state);
@@ -669,3 +647,46 @@ NTSTATUS wb_cmd_checkmachacc(struct wbsrv_call *call)
struct composite_context *c = wb_cmd_checkmachacc_send(call);
return wb_cmd_checkmachacc_recv(c);
}
+
+static void composite_netr_LogonSamLogon_recv_rpc(struct rpc_request *req);
+
+struct composite_context *composite_netr_LogonSamLogon_send(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ struct netr_LogonSamLogon *r)
+{
+ struct composite_context *result;
+ struct rpc_request *req;
+
+ result = talloc(mem_ctx, struct composite_context);
+ if (result == NULL) goto failed;
+ result->state = COMPOSITE_STATE_IN_PROGRESS;
+ result->async.fn = NULL;
+ result->event_ctx = p->conn->event_ctx;
+
+ req = dcerpc_netr_LogonSamLogon_send(p, mem_ctx, r);
+ if (req == NULL) goto failed;
+ req->async.callback = composite_netr_LogonSamLogon_recv_rpc;
+ req->async.private = result;
+ return result;
+
+ failed:
+ talloc_free(result);
+ return NULL;
+}
+
+static void composite_netr_LogonSamLogon_recv_rpc(struct rpc_request *req)
+{
+ struct composite_context *ctx =
+ talloc_get_type(req->async.private, struct composite_context);
+
+ ctx->status = dcerpc_ndr_request_recv(req);
+ if (!composite_is_ok(ctx)) return;
+ composite_done(ctx);
+}
+
+NTSTATUS composite_netr_LogonSamLogon_recv(struct composite_context *ctx)
+{
+ NTSTATUS status = composite_wait(ctx);
+ talloc_free(ctx);
+ return status;
+}