diff options
-rw-r--r-- | source4/libcli/resolve/bcast.c | 11 | ||||
-rw-r--r-- | source4/libcli/resolve/host.c | 13 | ||||
-rw-r--r-- | source4/libcli/resolve/nbtlist.c | 15 | ||||
-rw-r--r-- | source4/libcli/resolve/resolve.c | 4 | ||||
-rw-r--r-- | source4/libcli/resolve/wins.c | 11 | ||||
-rw-r--r-- | source4/torture/local/resolve.c | 17 |
6 files changed, 38 insertions, 33 deletions
diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 8824ad395e..ba07670ced 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -28,15 +28,16 @@ /* broadcast name resolution method - async send */ -struct composite_context *resolve_name_bcast_send(struct nbt_name *name, - struct event_context *event_ctx) +struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, + struct event_context *event_ctx, + struct nbt_name *name) { int num_interfaces = iface_count(); const char **address_list; struct composite_context *c; int i, count=0; - address_list = talloc_array(NULL, const char *, num_interfaces+1); + address_list = talloc_array(mem_ctx, const char *, num_interfaces+1); if (address_list == NULL) return NULL; for (i=0;i<num_interfaces;i++) { @@ -51,7 +52,7 @@ struct composite_context *resolve_name_bcast_send(struct nbt_name *name, } address_list[count] = NULL; - c = resolve_name_nbtlist_send(name, event_ctx, address_list, True, False); + c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, True, False); talloc_free(address_list); return c; @@ -73,7 +74,7 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_bcast_send(name, NULL); + struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, name); return resolve_name_bcast_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 5f99a85268..f84a7dc808 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -77,6 +77,7 @@ static void run_child(struct composite_context *c, int fd) if (address != NULL) { write(fd, address, strlen(address)+1); } + close(fd); } /* @@ -121,15 +122,16 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, /* gethostbyname name resolution method - async send */ -struct composite_context *resolve_name_host_send(struct nbt_name *name, - struct event_context *event_ctx) +struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx, + struct event_context *event_ctx, + struct nbt_name *name) { struct composite_context *c; struct host_state *state; int fd[2] = { -1, -1 }; int ret; - c = composite_create(event_ctx, event_ctx); + c = composite_create(mem_ctx, event_ctx); if (c == NULL) return NULL; c->event_ctx = talloc_reference(c, event_ctx); @@ -172,6 +174,7 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, return c; } + if (state->child == 0) { close(fd[0]); run_child(c, fd[1]); @@ -189,7 +192,7 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, gethostbyname name resolution method - recv side */ NTSTATUS resolve_name_host_recv(struct composite_context *c, - TALLOC_CTX *mem_ctx, const char **reply_addr) + TALLOC_CTX *mem_ctx, const char **reply_addr) { NTSTATUS status; @@ -211,7 +214,7 @@ NTSTATUS resolve_name_host(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_host_send(name, NULL); + struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, name); return resolve_name_host_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index df76ec66a5..58433d0a70 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -95,11 +95,12 @@ static void nbtlist_handler(struct nbt_name_request *req) /* nbtlist name resolution method - async send */ -struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, - struct event_context *event_ctx, - const char **address_list, - BOOL broadcast, - BOOL wins_lookup) +struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, + struct event_context *event_ctx, + struct nbt_name *name, + const char **address_list, + BOOL broadcast, + BOOL wins_lookup) { struct composite_context *c; struct nbtlist_state *state; @@ -186,8 +187,8 @@ NTSTATUS resolve_name_nbtlist(struct nbt_name *name, BOOL broadcast, BOOL wins_lookup, const char **reply_addr) { - struct composite_context *c = resolve_name_nbtlist_send(name, NULL, address_list, - broadcast, wins_lookup); + struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list, + broadcast, wins_lookup); return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 532cf19bb4..5e37fec42b 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -38,7 +38,7 @@ static struct composite_context *setup_next_method(struct composite_context *c); /* pointers to the resolver backends */ static const struct resolve_method { const char *name; - struct composite_context *(*send_fn)(struct nbt_name *, struct event_context *); + struct composite_context *(*send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, struct nbt_name *); NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); } resolve_methods[] = { @@ -101,7 +101,7 @@ static struct composite_context *setup_next_method(struct composite_context *c) do { const struct resolve_method *method = find_method(state->methods[0]); if (method) { - creq = method->send_fn(&state->name, c->event_ctx); + creq = method->send_fn(c, c->event_ctx, &state->name); } if (creq == NULL && state->methods[0]) state->methods++; diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 6478710682..62a3b81d0a 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -27,19 +27,20 @@ /* wins name resolution method - async send */ -struct composite_context *resolve_name_wins_send(struct nbt_name *name, - struct event_context *event_ctx) +struct composite_context *resolve_name_wins_send(TALLOC_CTX *mem_ctx, + struct event_context *event_ctx, + struct nbt_name *name) { const char **address_list = lp_wins_server_list(); if (address_list == NULL) return NULL; - return resolve_name_nbtlist_send(name, event_ctx, address_list, False, True); + return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, False, True); } /* wins name resolution method - recv side */ NTSTATUS resolve_name_wins_recv(struct composite_context *c, - TALLOC_CTX *mem_ctx, const char **reply_addr) + TALLOC_CTX *mem_ctx, const char **reply_addr) { return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); } @@ -51,7 +52,7 @@ NTSTATUS resolve_name_wins(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_wins_send(name, NULL); + struct composite_context *c = resolve_name_wins_send(mem_ctx, NULL, name); return resolve_name_wins_recv(c, mem_ctx, reply_addr); } diff --git a/source4/torture/local/resolve.c b/source4/torture/local/resolve.c index 62aa600a3c..96da65a8c2 100644 --- a/source4/torture/local/resolve.c +++ b/source4/torture/local/resolve.c @@ -40,11 +40,11 @@ static bool test_async_resolve(struct torture_context *tctx) ZERO_STRUCT(n); n.name = host; - torture_comment(tctx, "Testing async resolve of localhost for %d seconds\n", - timelimit); + torture_comment(tctx, "Testing async resolve of '%s' for %d seconds\n", + host, timelimit); while (timeval_elapsed(&tv) < timelimit) { const char *s; - struct composite_context *c = resolve_name_host_send(&n, ev); + struct composite_context *c = resolve_name_host_send(mem_ctx, ev, &n); torture_assert(tctx, c != NULL, "resolve_name_host_send"); torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s), "async resolve failed"); @@ -52,7 +52,7 @@ static bool test_async_resolve(struct torture_context *tctx) } torture_comment(tctx, "async rate of %.1f resolves/sec\n", - count/timeval_elapsed(&tv)); + count/timeval_elapsed(&tv)); return true; } @@ -66,23 +66,22 @@ static bool test_sync_resolve(struct torture_context *tctx) int count = 0; const char *host = torture_setting_string(tctx, "host", NULL); - torture_comment(tctx, "Testing sync resolve of localhost for %d seconds\n", - timelimit); + torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n", + host, timelimit); while (timeval_elapsed(&tv) < timelimit) { sys_inet_ntoa(interpret_addr2(host)); count++; } torture_comment(tctx, "sync rate of %.1f resolves/sec\n", - count/timeval_elapsed(&tv)); + count/timeval_elapsed(&tv)); return true; } struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx) { - struct torture_suite *suite = torture_suite_create(mem_ctx, - "RESOLVE"); + struct torture_suite *suite = torture_suite_create(mem_ctx, "RESOLVE"); torture_suite_add_simple_test(suite, "async", test_async_resolve); torture_suite_add_simple_test(suite, "sync", test_sync_resolve); |