diff options
-rw-r--r-- | source4/lib/socket/connect.c | 2 | ||||
-rw-r--r-- | source4/lib/socket/connect_multi.c | 2 | ||||
-rw-r--r-- | source4/libcli/composite/composite.c | 65 | ||||
-rw-r--r-- | source4/libcli/composite/composite.h | 2 | ||||
-rw-r--r-- | source4/libcli/ldap/ldap_client.c | 2 | ||||
-rw-r--r-- | source4/libcli/resolve/resolve.c | 2 | ||||
-rw-r--r-- | source4/libcli/smb2/connect.c | 2 | ||||
-rw-r--r-- | source4/libcli/smb2/session.c | 2 | ||||
-rw-r--r-- | source4/librpc/rpc/dcerpc.c | 4 | ||||
-rw-r--r-- | source4/librpc/rpc/dcerpc_auth.c | 6 | ||||
-rw-r--r-- | source4/torture/rpc/xplogin.c | 16 | ||||
-rw-r--r-- | source4/winbind/wb_async_helpers.c | 2 | ||||
-rw-r--r-- | source4/winbind/wb_sid2domain.c | 2 | ||||
-rw-r--r-- | source4/wrepl_server/wrepl_out_helpers.c | 6 |
14 files changed, 57 insertions, 58 deletions
diff --git a/source4/lib/socket/connect.c b/source4/lib/socket/connect.c index 1ab4892128d..116a8c67d86 100644 --- a/source4/lib/socket/connect.c +++ b/source4/lib/socket/connect.c @@ -138,7 +138,7 @@ struct composite_context *socket_connect_send(struct socket_context *sock, return result; failed: - composite_trigger_error(result); + composite_error(result, result->status); return result; } diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c index 3948c1e2a12..258560cec57 100644 --- a/source4/lib/socket/connect_multi.c +++ b/source4/lib/socket/connect_multi.c @@ -119,7 +119,7 @@ struct composite_context *socket_connect_multi_send(TALLOC_CTX *mem_ctx, return result; failed: - composite_trigger_error(result); + composite_error(result, result->status); return result; } diff --git a/source4/libcli/composite/composite.c b/source4/libcli/composite/composite.c index 3842ddfe9fb..c9cc20e9235 100644 --- a/source4/libcli/composite/composite.c +++ b/source4/libcli/composite/composite.c @@ -35,6 +35,8 @@ NTSTATUS composite_wait(struct composite_context *c) { if (c == NULL) return NT_STATUS_NO_MEMORY; + c->used_wait = True; + while (c->state < COMPOSITE_STATE_DONE) { if (event_loop_once(c->event_ctx) != 0) { return NT_STATUS_UNSUCCESSFUL; @@ -45,44 +47,10 @@ NTSTATUS composite_wait(struct composite_context *c) } -/* - callback from composite_trigger_done() and composite_trigger_error() -*/ -static void composite_trigger(struct event_context *ev, struct timed_event *te, - struct timeval t, void *ptr) -{ - struct composite_context *c = talloc_get_type(ptr, struct composite_context); - if (c->async.fn) { - c->async.fn(c); - } -} - - -/* - trigger an immediate 'done' event on a composite context - this is used when the composite code works out that the call - can be completed without waiting for any external event -*/ -void composite_trigger_done(struct composite_context *c) -{ - c->state = COMPOSITE_STATE_DONE; - /* a zero timeout means immediate */ - event_add_timed(c->event_ctx, c, timeval_zero(), composite_trigger, c); -} - -void composite_trigger_error(struct composite_context *c) -{ - c->state = COMPOSITE_STATE_ERROR; - /* a zero timeout means immediate */ - event_add_timed(c->event_ctx, c, timeval_zero(), composite_trigger, c); -} - - /* * Some composite helpers that are handy if you write larger composite * functions. */ - BOOL composite_is_ok(struct composite_context *ctx) { if (NT_STATUS_IS_OK(ctx->status)) { @@ -95,8 +63,34 @@ BOOL composite_is_ok(struct composite_context *ctx) return False; } +/* + callback from composite_done() and composite_error() + + this is used to allow for a composite function to complete without + going through any state transitions. When that happens the caller + has had no opportunity to fill in the async callback fields + (ctx->async.fn and ctx->async.private) which means the usual way of + dealing with composite functions doesn't work. To cope with this, + we trigger a timer event that will happen then the event loop is + re-entered. This gives the caller a chance to setup the callback, + and allows the caller to ignore the fact that the composite + function completed early +*/ +static void composite_trigger(struct event_context *ev, struct timed_event *te, + struct timeval t, void *ptr) +{ + struct composite_context *c = talloc_get_type(ptr, struct composite_context); + if (c->async.fn) { + c->async.fn(c); + } +} + + void composite_error(struct composite_context *ctx, NTSTATUS status) { + if (!ctx->used_wait && !ctx->async.fn) { + event_add_timed(ctx->event_ctx, ctx, timeval_zero(), composite_trigger, ctx); + } ctx->status = status; SMB_ASSERT(!composite_is_ok(ctx)); } @@ -112,6 +106,9 @@ BOOL composite_nomem(const void *p, struct composite_context *ctx) void composite_done(struct composite_context *ctx) { + if (!ctx->used_wait && !ctx->async.fn) { + event_add_timed(ctx->event_ctx, ctx, timeval_zero(), composite_trigger, ctx); + } ctx->state = COMPOSITE_STATE_DONE; if (ctx->async.fn != NULL) { ctx->async.fn(ctx); diff --git a/source4/libcli/composite/composite.h b/source4/libcli/composite/composite.h index 1e6e9f5dc85..26490f1c4a2 100644 --- a/source4/libcli/composite/composite.h +++ b/source4/libcli/composite/composite.h @@ -57,4 +57,6 @@ struct composite_context { void (*fn)(struct composite_context *); void *private_data; } async; + + BOOL used_wait; }; diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c index a5f647939fc..0a787bbf578 100644 --- a/source4/libcli/ldap/ldap_client.c +++ b/source4/libcli/ldap/ldap_client.c @@ -341,7 +341,7 @@ struct composite_context *ldap_connect_send(struct ldap_connection *conn, state->ctx->status = ldap_parse_basic_url(conn, url, &conn->host, &conn->port, &conn->ldaps); if (!NT_STATUS_IS_OK(state->ctx->status)) { - composite_trigger_error(state->ctx); + composite_error(state->ctx, state->ctx->status); return result; } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index db5aefeaeb0..bbed931eedf 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -153,7 +153,7 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ struct ipv4_addr ip = interpret_addr2(state->name.name); state->reply_addr = talloc_strdup(state, sys_inet_ntoa(ip)); if (!state->reply_addr) goto failed; - composite_trigger_done(c); + composite_done(c); return c; } diff --git a/source4/libcli/smb2/connect.c b/source4/libcli/smb2/connect.c index 7ed3f97bf3f..d15f370feba 100644 --- a/source4/libcli/smb2/connect.c +++ b/source4/libcli/smb2/connect.c @@ -201,7 +201,7 @@ struct composite_context *smb2_connect_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 07970747c49..208e2a94de4 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -253,7 +253,7 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c index aabc71a258f..d8fb3e4e6a3 100644 --- a/source4/librpc/rpc/dcerpc.c +++ b/source4/librpc/rpc/dcerpc.c @@ -722,7 +722,7 @@ struct composite_context *dcerpc_bind_send(struct dcerpc_pipe *p, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -1633,7 +1633,7 @@ struct composite_context *dcerpc_alter_context_send(struct dcerpc_pipe *p, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } diff --git a/source4/librpc/rpc/dcerpc_auth.c b/source4/librpc/rpc/dcerpc_auth.c index 1dbc3b8aef6..dcf33342127 100644 --- a/source4/librpc/rpc/dcerpc_auth.c +++ b/source4/librpc/rpc/dcerpc_auth.c @@ -47,7 +47,7 @@ struct composite_context *dcerpc_bind_auth_none_send(TALLOC_CTX *mem_ctx, if (!NT_STATUS_IS_OK(c->status)) { DEBUG(2,("Invalid uuid string in " "dcerpc_bind_auth_none_send\n")); - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -277,7 +277,7 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx, NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED); if (state->credentials.length == 0) { - composite_trigger_done(c); + composite_done(c); return c; } @@ -296,7 +296,7 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } diff --git a/source4/torture/rpc/xplogin.c b/source4/torture/rpc/xplogin.c index 055b857e8e8..cc91e510820 100644 --- a/source4/torture/rpc/xplogin.c +++ b/source4/torture/rpc/xplogin.c @@ -373,7 +373,7 @@ static struct composite_context *lsa_enumtrust_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -475,7 +475,7 @@ static struct composite_context *get_netlogon_schannel_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -655,7 +655,7 @@ static struct composite_context *lookupsids_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -898,7 +898,7 @@ static struct composite_context *get_samr_domain_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -1109,7 +1109,7 @@ static struct composite_context *domadmins_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -1420,7 +1420,7 @@ static struct composite_context *memberships_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -1550,7 +1550,7 @@ static struct composite_context *ntconfig_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } @@ -1689,7 +1689,7 @@ static struct composite_context *xp_login_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } diff --git a/source4/winbind/wb_async_helpers.c b/source4/winbind/wb_async_helpers.c index 8efd19f96b3..f6c61c8c363 100644 --- a/source4/winbind/wb_async_helpers.c +++ b/source4/winbind/wb_async_helpers.c @@ -230,7 +230,7 @@ struct composite_context *wb_get_schannel_creds_send(TALLOC_CTX *mem_ctx, return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } diff --git a/source4/winbind/wb_sid2domain.c b/source4/winbind/wb_sid2domain.c index 70f8f4c6263..2c19ef858f4 100644 --- a/source4/winbind/wb_sid2domain.c +++ b/source4/winbind/wb_sid2domain.c @@ -85,7 +85,7 @@ struct composite_context *wb_sid2domain_send(TALLOC_CTX *mem_ctx, state->domain = find_domain_from_sid(service, sid); if (state->domain != NULL) { result->status = NT_STATUS_OK; - composite_trigger_done(result); + composite_done(result); return result; } diff --git a/source4/wrepl_server/wrepl_out_helpers.c b/source4/wrepl_server/wrepl_out_helpers.c index 36d189a4d00..c7c6f55767c 100644 --- a/source4/wrepl_server/wrepl_out_helpers.c +++ b/source4/wrepl_server/wrepl_out_helpers.c @@ -156,12 +156,12 @@ static struct composite_context *wreplsrv_out_connect_send(struct wreplsrv_partn if (!wreplconn->sock->dead) { state->stage = WREPLSRV_OUT_CONNECT_STAGE_DONE; state->wreplconn= wreplconn; - composite_trigger_done(c); + composite_done(c); return c; } else if (!cached_connection) { state->stage = WREPLSRV_OUT_CONNECT_STAGE_DONE; state->wreplconn= NULL; - composite_trigger_done(c); + composite_done(c); return c; } else { talloc_free(wreplconn); @@ -328,7 +328,7 @@ struct composite_context *wreplsrv_pull_table_send(TALLOC_CTX *mem_ctx, struct w state->table_io.out.num_partners = io->in.num_owners; state->table_io.out.partners = io->in.owners; state->stage = WREPLSRV_PULL_TABLE_STAGE_DONE; - composite_trigger_done(c); + composite_done(c); return c; } |