diff options
author | Rafal Szczesniak <mimir@samba.org> | 2006-07-09 12:54:56 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:09:57 -0500 |
commit | 861ec810488fc6c25fc7e6287ed27e82fe526fa0 (patch) | |
tree | dce1fcc5781e4372e0f7c4229ffe2580f84e6e81 /source4 | |
parent | ee898127583b1ac071e805a7019ad773234126d5 (diff) | |
download | samba-861ec810488fc6c25fc7e6287ed27e82fe526fa0.tar.gz samba-861ec810488fc6c25fc7e6287ed27e82fe526fa0.tar.bz2 samba-861ec810488fc6c25fc7e6287ed27e82fe526fa0.zip |
r16895: Add continue function and prevent from segfaulting (or unpredictable
behaviour) if composite context returned from _send function was NULL.
rafal
(This used to be commit d9fce228d006b702d76faebe4eb436327a7212d0)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/libnet/libnet_lookup.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/source4/libnet/libnet_lookup.c b/source4/libnet/libnet_lookup.c index 8356678d72..be669ca2e2 100644 --- a/source4/libnet/libnet_lookup.c +++ b/source4/libnet/libnet_lookup.c @@ -32,11 +32,14 @@ #include "libcli/finddcs.h" struct lookup_state { - struct composite_context *resolve_ctx; struct nbt_name hostname; + const char *address; }; +static void continue_name_resolved(struct composite_context *ctx); + + /** * Sends asynchronous Lookup request * @@ -48,20 +51,30 @@ struct composite_context *libnet_Lookup_send(struct libnet_context *ctx, { struct composite_context *c; struct lookup_state *s; + struct composite_context *cresolve_req; const char** methods; - if (!io) return NULL; - /* allocate context and state structures */ c = talloc_zero(NULL, struct composite_context); - if (c == NULL) goto failed; + if (c == NULL) return NULL; s = talloc_zero(c, struct lookup_state); - if (s == NULL) goto failed; + if (s == NULL) { + composite_error(c, NT_STATUS_NO_MEMORY); + return c; + } /* prepare event context */ c->event_ctx = event_context_find(c); - if (c->event_ctx == NULL) goto failed; + if (c->event_ctx == NULL) { + composite_error(c, NT_STATUS_NO_MEMORY); + return c; + } + + if (io == NULL || io->in.hostname == NULL) { + composite_error(c, NT_STATUS_INVALID_PARAMETER); + return c; + } /* parameters */ s->hostname.name = talloc_strdup(s, io->in.hostname); @@ -79,13 +92,25 @@ struct composite_context *libnet_Lookup_send(struct libnet_context *ctx, c->state = COMPOSITE_STATE_IN_PROGRESS; /* send resolve request */ - s->resolve_ctx = resolve_name_send(&s->hostname, c->event_ctx, methods); + cresolve_req = resolve_name_send(&s->hostname, c->event_ctx, methods); + + composite_continue(c, cresolve_req, continue_name_resolved, c); return c; +} -failed: - talloc_free(c); - return NULL; + +static void continue_name_resolved(struct composite_context *ctx) +{ + struct composite_context *c; + struct lookup_state *s; + + c = talloc_get_type(ctx->async.private_data, struct composite_context); + s = talloc_get_type(c->private_data, struct lookup_state); + + c->status = resolve_name_recv(ctx, s, &s->address); + + composite_done(c); } @@ -103,16 +128,16 @@ NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, { NTSTATUS status; struct lookup_state *s; - const char *address; - - s = talloc_get_type(c->private_data, struct lookup_state); - status = resolve_name_recv(s->resolve_ctx, mem_ctx, &address); + status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - io->out.address = str_list_make(mem_ctx, address, NULL); + s = talloc_get_type(c->private_data, struct lookup_state); + + io->out.address = str_list_make(mem_ctx, s->address, NULL); NT_STATUS_HAVE_NO_MEMORY(io->out.address); } + talloc_free(c); return status; } @@ -198,7 +223,7 @@ NTSTATUS libnet_LookupDCs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, } /** - * Synchronous version of LookupPdc + * Synchronous version of LookupDCs */ NTSTATUS libnet_LookupDCs(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_LookupDCs *io) |