From b9a1e9a6677613865474c3c66b443b1c9e54c408 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Jan 2005 00:52:54 +0000 Subject: r4916: added "host" name resolution using fork() per gethostbyname() comments welcome, but please think about the alternatives first :-) (This used to be commit 3d40b479907226be349137117e0d2bd718efa1a8) --- source4/libcli/resolve/host.c | 233 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 source4/libcli/resolve/host.c (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c new file mode 100644 index 0000000000..2cc0c1705f --- /dev/null +++ b/source4/libcli/resolve/host.c @@ -0,0 +1,233 @@ +/* + Unix SMB/CIFS implementation. + + async gethostbyname() name resolution module + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + this module uses a fork() per gethostbyname() call. At first that + might seem crazy, but it is actually very fast, and solves many of + the tricky problems of keeping a child hanging around in a library + (like what happens when the parent forks). We use a talloc + destructor to ensure that the child is cleaned up when we have + finished with this name resolution. +*/ + +#include "includes.h" +#include "events.h" +#include "system/network.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" + +struct host_state { + struct nbt_name name; + const char *reply_addr; + pid_t child; + int child_fd; + struct fd_event *fde; + struct event_context *event_ctx; +}; + + +/* + kill off a wayward child if needed. This allows us to stop an async + name resolution without leaving a potentially blocking call running + in a child +*/ +static int host_destructor(void *ptr) +{ + struct host_state *state = talloc_get_type(ptr, struct host_state); + close(state->child_fd); + if (state->child != (pid_t)-1) { + kill(state->child, SIGTERM); + } + if (state->fde) { + event_remove_fd(state->event_ctx, state->fde); + } + return 0; +} + +/* + the blocking child +*/ +static void run_child(struct smbcli_composite *c, int fd) +{ + struct host_state *state = talloc_get_type(c->private, struct host_state); + struct ipv4_addr ip; + const char *address; + + /* this is the blocking call we are going to lots of trouble + to avoid in the parent */ + ip = interpret_addr2(state->name.name); + + address = sys_inet_ntoa(ip); + if (address != NULL) { + write(fd, address, strlen(address)+1); + } +} + +/* + handle a read event on the pipe +*/ +static void pipe_handler(struct event_context *ev, struct fd_event *fde, + struct timeval t, uint16_t flags) +{ + struct smbcli_composite *c = talloc_get_type(fde->private, struct smbcli_composite); + struct host_state *state = talloc_get_type(c->private, struct host_state); + char address[128]; + int ret; + + /* if we get any event from the child then we know that we + won't need to kill it off */ + state->child = (pid_t)-1; + + /* yes, we don't care about EAGAIN or other niceities + here. They just can't happen with this parent/child + relationship, and even if they did then giving an error is + the right thing to do */ + ret = read(state->child_fd, address, sizeof(address)-1); + if (ret <= 0) goto failed; + + /* enusre the address looks good */ + address[ret] = 0; + if (strcmp(address, "0.0.0.0") == 0 || + sys_inet_addr(address) == INADDR_NONE) { + goto failed; + } + + state->reply_addr = talloc_strdup(state, address); + if (state->reply_addr == NULL) goto failed; + + c->status = NT_STATUS_OK; + c->state = SMBCLI_REQUEST_DONE; + if (c->async.fn) { + c->async.fn(c); + } + return; + +failed: + c->status = NT_STATUS_BAD_NETWORK_NAME; + c->state = SMBCLI_REQUEST_ERROR; + if (c->async.fn) { + c->async.fn(c); + } +} + +/* + gethostbyname name resolution method - async send + */ +struct smbcli_composite *resolve_name_host_send(struct nbt_name *name, + struct event_context *event_ctx) +{ + struct smbcli_composite *c; + struct host_state *state; + NTSTATUS status; + int fd[2] = { -1, -1 }; + struct fd_event fde; + int ret; + + c = talloc_zero(NULL, struct smbcli_composite); + if (c == NULL) goto failed; + + state = talloc(c, struct host_state); + if (state == NULL) goto failed; + + status = nbt_name_dup(state, name, &state->name); + if (!NT_STATUS_IS_OK(status)) goto failed; + + c->state = SMBCLI_REQUEST_SEND; + c->private = state; + c->event_ctx = talloc_reference(c, event_ctx); + + /* setup a pipe to chat to our child */ + ret = pipe(fd); + if (ret == -1) goto failed; + + state->child_fd = fd[0]; + state->event_ctx = c->event_ctx; + + /* we need to put the child in our event context so + we know when the gethostbyname() has finished */ + fde.fd = state->child_fd; + fde.flags = EVENT_FD_READ; + fde.handler = pipe_handler; + fde.private = c; + state->fde = event_add_fd(c->event_ctx, &fde); + if (state->fde == NULL) { + close(fd[0]); + close(fd[1]); + goto failed; + } + + /* signal handling in posix really sucks - doing this in a library + affects the whole app, but what else to do?? */ + signal(SIGCHLD, SIG_IGN); + + state->child = fork(); + if (state->child == (pid_t)-1) { + goto failed; + } + + if (state->child == 0) { + close(fd[0]); + run_child(c, fd[1]); + _exit(0); + } + close(fd[1]); + + /* cleanup wayward children */ + talloc_set_destructor(state, host_destructor); + + return c; + +failed: + talloc_free(c); + return NULL; +} + +/* + gethostbyname name resolution method - recv side +*/ +NTSTATUS resolve_name_host_recv(struct smbcli_composite *c, + TALLOC_CTX *mem_ctx, const char **reply_addr) +{ + NTSTATUS status; + + status = smb_composite_wait(c); + + if (NT_STATUS_IS_OK(status)) { + struct host_state *state = talloc_get_type(c->private, struct host_state); + *reply_addr = talloc_steal(mem_ctx, state->reply_addr); + } + + talloc_free(c); + return status; +} + +/* + gethostbyname name resolution method - sync call + */ +NTSTATUS resolve_name_host(struct nbt_name *name, + TALLOC_CTX *mem_ctx, + const char **reply_addr) +{ + struct smbcli_composite *c = resolve_name_host_send(name, NULL); + return resolve_name_host_recv(c, mem_ctx, reply_addr); +} + -- cgit From fd62df64188c0f992876c72fdda8a6da5dba3090 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 11:49:15 +0000 Subject: r4943: Smplified the events handling code a lot. The first source of complexity was that events didn't automatically cleanup themselves. This was because the events code was written before we had talloc destructors, so you needed to call event_remove_XX() to clean the event out of the event lists from every piece of code that used events. I have now added automatic event destructors, which in turn allowed me to simplify a lot of the calling code. The 2nd source of complexity was caused by the ref_count, which was needed to cope with event handlers destroying events while handling them, which meant the linked lists became invalid, so the ref_count ws used to mark events for later destruction. The new system is much simpler. I now have a ev->destruction_count, which is incremented in all event destructors. The event dispatch code checks for changes to this and handles it. (This used to be commit a3c7417cfeab429ffb22d5546b205818f531a7b4) --- source4/libcli/resolve/host.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 2cc0c1705f..b9aa1aa272 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -57,9 +57,6 @@ static int host_destructor(void *ptr) if (state->child != (pid_t)-1) { kill(state->child, SIGTERM); } - if (state->fde) { - event_remove_fd(state->event_ctx, state->fde); - } return 0; } @@ -174,6 +171,7 @@ struct smbcli_composite *resolve_name_host_send(struct nbt_name *name, close(fd[1]); goto failed; } + talloc_steal(state, state->fde); /* signal handling in posix really sucks - doing this in a library affects the whole app, but what else to do?? */ -- cgit From 6c14b0133dede38294a812be7f5f5bd5ec3d498b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 12:17:45 +0000 Subject: r4944: every event_add_*() caller was having to call talloc_steal() to take control of the event, so instead build that into the function. If you pass NULL as mem_ctx then it leaves it as a child of the events structure. (This used to be commit 7f981b9ed96f39027cbfd500f41e0c2be64cbb50) --- source4/libcli/resolve/host.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index b9aa1aa272..5b28a850fc 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -165,13 +165,12 @@ struct smbcli_composite *resolve_name_host_send(struct nbt_name *name, fde.flags = EVENT_FD_READ; fde.handler = pipe_handler; fde.private = c; - state->fde = event_add_fd(c->event_ctx, &fde); + state->fde = event_add_fd(c->event_ctx, &fde, state); if (state->fde == NULL) { close(fd[0]); close(fd[1]); goto failed; } - talloc_steal(state, state->fde); /* signal handling in posix really sucks - doing this in a library affects the whole app, but what else to do?? */ -- cgit From 9a70f446fc4abc2bd1278772810c0e8132f4bea4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Jan 2005 08:30:44 +0000 Subject: r5126: the composite code is no longer client specific or smb specific, so rename the core structure to composite_context and the wait routine to composite_wait() (suggestion from metze) (This used to be commit cf11d05e35179c2c3e51c5ab370cd0a3fb15f24a) --- source4/libcli/resolve/host.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 5b28a850fc..9bf278154d 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -63,7 +63,7 @@ static int host_destructor(void *ptr) /* the blocking child */ -static void run_child(struct smbcli_composite *c, int fd) +static void run_child(struct composite_context *c, int fd) { struct host_state *state = talloc_get_type(c->private, struct host_state); struct ipv4_addr ip; @@ -85,7 +85,7 @@ static void run_child(struct smbcli_composite *c, int fd) static void pipe_handler(struct event_context *ev, struct fd_event *fde, struct timeval t, uint16_t flags) { - struct smbcli_composite *c = talloc_get_type(fde->private, struct smbcli_composite); + struct composite_context *c = talloc_get_type(fde->private, struct composite_context); struct host_state *state = talloc_get_type(c->private, struct host_state); char address[128]; int ret; @@ -129,17 +129,17 @@ failed: /* gethostbyname name resolution method - async send */ -struct smbcli_composite *resolve_name_host_send(struct nbt_name *name, +struct composite_context *resolve_name_host_send(struct nbt_name *name, struct event_context *event_ctx) { - struct smbcli_composite *c; + struct composite_context *c; struct host_state *state; NTSTATUS status; int fd[2] = { -1, -1 }; struct fd_event fde; int ret; - c = talloc_zero(NULL, struct smbcli_composite); + c = talloc_zero(NULL, struct composite_context); if (c == NULL) goto failed; state = talloc(c, struct host_state); @@ -201,12 +201,12 @@ failed: /* gethostbyname name resolution method - recv side */ -NTSTATUS resolve_name_host_recv(struct smbcli_composite *c, +NTSTATUS resolve_name_host_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, const char **reply_addr) { NTSTATUS status; - status = smb_composite_wait(c); + status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { struct host_state *state = talloc_get_type(c->private, struct host_state); @@ -224,7 +224,7 @@ NTSTATUS resolve_name_host(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct smbcli_composite *c = resolve_name_host_send(name, NULL); + struct composite_context *c = resolve_name_host_send(name, NULL); return resolve_name_host_recv(c, mem_ctx, reply_addr); } -- cgit From 66170ef8b36b499aa5b44ef10c1bd362a50f2636 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 02:35:52 +0000 Subject: r5185: make all the events data structures private to events.c. This will make it possible to add optimisations to the events code such as keeping the next timed event in a sorted list, and using epoll for file descriptor events. I also removed the loop events code, as it wasn't being used anywhere, and changed timed events to always be one-shot (as adding a new timed event in the event handler is so easy to do if needed) (This used to be commit d7b4b6de51342a65bf46fce772d313f92f8d73d3) --- source4/libcli/resolve/host.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 9bf278154d..977c804a4a 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -83,9 +83,9 @@ static void run_child(struct composite_context *c, int fd) handle a read event on the pipe */ static void pipe_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags) + struct timeval t, uint16_t flags, void *private) { - struct composite_context *c = talloc_get_type(fde->private, struct composite_context); + struct composite_context *c = talloc_get_type(private, struct composite_context); struct host_state *state = talloc_get_type(c->private, struct host_state); char address[128]; int ret; @@ -136,7 +136,6 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, struct host_state *state; NTSTATUS status; int fd[2] = { -1, -1 }; - struct fd_event fde; int ret; c = talloc_zero(NULL, struct composite_context); @@ -161,11 +160,8 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, /* we need to put the child in our event context so we know when the gethostbyname() has finished */ - fde.fd = state->child_fd; - fde.flags = EVENT_FD_READ; - fde.handler = pipe_handler; - fde.private = c; - state->fde = event_add_fd(c->event_ctx, &fde, state); + state->fde = event_add_fd(c->event_ctx, state, state->child_fd, EVENT_FD_READ, + pipe_handler, c); if (state->fde == NULL) { close(fd[0]); close(fd[1]); -- cgit From 0798d54b4fc28be881e2c4012663b1461bc85ba7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 11:25:52 +0000 Subject: r5195: most events don't need the time of the event, so save a gettimeofday() call and just use timeval_current() when its actually needed (This used to be commit 236403cc4dc2924ed6a898acae0bb44cc1688dcc) --- source4/libcli/resolve/host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 977c804a4a..4df8f27534 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -83,7 +83,7 @@ static void run_child(struct composite_context *c, int fd) handle a read event on the pipe */ static void pipe_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags, void *private) + uint16_t flags, void *private) { struct composite_context *c = talloc_get_type(private, struct composite_context); struct host_state *state = talloc_get_type(c->private, struct host_state); @@ -160,7 +160,7 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, /* we need to put the child in our event context so we know when the gethostbyname() has finished */ - state->fde = event_add_fd(c->event_ctx, state, state->child_fd, EVENT_FD_READ, + state->fde = event_add_fd(c->event_ctx, c, state->child_fd, EVENT_FD_READ, pipe_handler, c); if (state->fde == NULL) { close(fd[0]); -- cgit From 131dc76d56df40b3511c47e54f15412a25b491f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 11:56:03 +0000 Subject: r5197: moved events code to lib/events/ (suggestion from metze) (This used to be commit 7f54c8a339f36aa43c9340be70ab7f0067593ef2) --- source4/libcli/resolve/host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 4df8f27534..cbf0f4614e 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -30,7 +30,7 @@ */ #include "includes.h" -#include "events.h" +#include "lib/events/events.h" #include "system/network.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -- cgit From e82aad1ce39a6b7a2e51b9e2cb494d74ec70e158 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 05:09:35 +0000 Subject: r5298: - got rid of pstring.h from includes.h. This at least makes it a bit less likely that anyone will use pstring for new code - got rid of winbind_client.h from includes.h. This one triggered a huge change, as winbind_client.h was including system/filesys.h and defining the old uint32 and uint16 types, as well as its own pstring and fstring. (This used to be commit 9db6c79e902ec538108d6b7d3324039aabe1704f) --- source4/libcli/resolve/host.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index cbf0f4614e..9f48f83ba4 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -32,6 +32,7 @@ #include "includes.h" #include "lib/events/events.h" #include "system/network.h" +#include "system/filesys.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -- cgit From f3b412fbd6dd94d64eb6a63d88baef2816891c29 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 Sep 2005 00:38:22 +0000 Subject: r10438: Move portability functions to lib/replace/; replace now simply ensures that a given set of (working) POSIX functions are available (without prefixes to their names, etc). See lib/replace/README for a list. Functions that behave different from their POSIX specification (such as sys_select, sys_read, etc) have kept the sys_ prefix. (This used to be commit 29919a71059b29fa27a49b1f5b84bb8881de65fc) --- source4/libcli/resolve/host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 9f48f83ba4..a5edfcbc8a 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -105,7 +105,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, /* enusre the address looks good */ address[ret] = 0; if (strcmp(address, "0.0.0.0") == 0 || - sys_inet_addr(address) == INADDR_NONE) { + inet_addr(address) == INADDR_NONE) { goto failed; } -- cgit From ab4d635b92b116b02b88843b4ec4f5b7517bab1a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 26 Sep 2005 11:47:55 +0000 Subject: r10504: - seperate implementation specific stuff, from the generic composite stuff. - don't use SMBCLI_REQUEST_* state's in the genreic composite stuff - move monitor_fn to libnet. NOTE: I have maybe found some bugs, in code that is dirrectly in DONE or ERROR state in the _send() function. I haven't fixed this bugs in this commit! We may need some composite_trigger_*() functions or so. And maybe some other generic helper functions... metze (This used to be commit 4527815a0a9b96e460f301cb1f0c0b3964c166fc) --- source4/libcli/resolve/host.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index a5edfcbc8a..13503b66b3 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -66,7 +66,7 @@ static int host_destructor(void *ptr) */ static void run_child(struct composite_context *c, int fd) { - struct host_state *state = talloc_get_type(c->private, struct host_state); + struct host_state *state = talloc_get_type(c->private_data, struct host_state); struct ipv4_addr ip; const char *address; @@ -84,10 +84,10 @@ static void run_child(struct composite_context *c, int fd) handle a read event on the pipe */ static void pipe_handler(struct event_context *ev, struct fd_event *fde, - uint16_t flags, void *private) + uint16_t flags, void *private_data) { - struct composite_context *c = talloc_get_type(private, struct composite_context); - struct host_state *state = talloc_get_type(c->private, struct host_state); + struct composite_context *c = talloc_get_type(private_data, struct composite_context); + struct host_state *state = talloc_get_type(c->private_data, struct host_state); char address[128]; int ret; @@ -113,7 +113,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, if (state->reply_addr == NULL) goto failed; c->status = NT_STATUS_OK; - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; if (c->async.fn) { c->async.fn(c); } @@ -121,7 +121,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, failed: c->status = NT_STATUS_BAD_NETWORK_NAME; - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; if (c->async.fn) { c->async.fn(c); } @@ -148,8 +148,8 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, status = nbt_name_dup(state, name, &state->name); if (!NT_STATUS_IS_OK(status)) goto failed; - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; c->event_ctx = talloc_reference(c, event_ctx); /* setup a pipe to chat to our child */ @@ -206,7 +206,7 @@ NTSTATUS resolve_name_host_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct host_state *state = talloc_get_type(c->private, struct host_state); + struct host_state *state = talloc_get_type(c->private_data, struct host_state); *reply_addr = talloc_steal(mem_ctx, state->reply_addr); } -- cgit From 2cd5ca7d25f12aa9198bf8c2deb6aea282f573ee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 28 Dec 2005 15:38:36 +0000 Subject: r12542: Move some more prototypes out to seperate headers (This used to be commit 0aca5fd5130d980d07398f3291d294202aefe3c2) --- source4/libcli/resolve/host.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 13503b66b3..f1925ca0d8 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -35,6 +35,7 @@ #include "system/filesys.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/nbt/libnbt.h" struct host_state { struct nbt_name name; -- cgit From d4de4c2d210d2e8c9b5aedf70695594809ad6a0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/libcli/resolve/host.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index f1925ca0d8..c283f0fda1 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -33,9 +33,7 @@ #include "lib/events/events.h" #include "system/network.h" #include "system/filesys.h" -#include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -#include "libcli/nbt/libnbt.h" struct host_state { struct nbt_name name; -- cgit From 8528016978b084213ef53d66e1b6e831b1a01acc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 16 Mar 2006 00:23:11 +0000 Subject: r14464: Don't include ndr_BASENAME.h files unless strictly required, instead try to include just the BASENAME.h files (containing only structs) (This used to be commit 3dd477ca5147f28a962b8437e2611a8222d706bd) --- source4/libcli/resolve/host.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index c283f0fda1..781ea957df 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -34,6 +34,7 @@ #include "system/network.h" #include "system/filesys.h" #include "libcli/composite/composite.h" +#include "librpc/gen_ndr/ndr_nbt.h" struct host_state { struct nbt_name name; -- cgit From 971d30bb201f5c3faff5f575d26882eb79f7955a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:34:11 +0000 Subject: r15854: more talloc_set_destructor() typesafe fixes (This used to be commit 61c6100617589ac6df4f527877241464cacbf8b3) --- source4/libcli/resolve/host.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 781ea957df..18188f7c1c 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -51,9 +51,8 @@ struct host_state { name resolution without leaving a potentially blocking call running in a child */ -static int host_destructor(void *ptr) +static int host_destructor(struct host_state *state) { - struct host_state *state = talloc_get_type(ptr, struct host_state); close(state->child_fd); if (state->child != (pid_t)-1) { kill(state->child, SIGTERM); -- cgit From c71152180c6e65e1492e41e9c2ea61b37f4f8df1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 8 Nov 2006 22:33:22 +0000 Subject: r19642: convert host.c to new composite api metze (This used to be commit a5d36a6ddefb8c24e748b839391241da41e31440) --- source4/libcli/resolve/host.c | 61 ++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 18188f7c1c..5f99a85268 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -99,31 +99,23 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, relationship, and even if they did then giving an error is the right thing to do */ ret = read(state->child_fd, address, sizeof(address)-1); - if (ret <= 0) goto failed; + if (ret <= 0) { + composite_error(c, NT_STATUS_BAD_NETWORK_NAME); + return; + } /* enusre the address looks good */ address[ret] = 0; if (strcmp(address, "0.0.0.0") == 0 || inet_addr(address) == INADDR_NONE) { - goto failed; + composite_error(c, NT_STATUS_BAD_NETWORK_NAME); + return; } state->reply_addr = talloc_strdup(state, address); - if (state->reply_addr == NULL) goto failed; - - c->status = NT_STATUS_OK; - c->state = COMPOSITE_STATE_DONE; - if (c->async.fn) { - c->async.fn(c); - } - return; + if (composite_nomem(state->reply_addr, c)) return; -failed: - c->status = NT_STATUS_BAD_NETWORK_NAME; - c->state = COMPOSITE_STATE_ERROR; - if (c->async.fn) { - c->async.fn(c); - } + composite_done(c); } /* @@ -134,26 +126,28 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, { struct composite_context *c; struct host_state *state; - NTSTATUS status; int fd[2] = { -1, -1 }; int ret; - c = talloc_zero(NULL, struct composite_context); - if (c == NULL) goto failed; - - state = talloc(c, struct host_state); - if (state == NULL) goto failed; + c = composite_create(event_ctx, event_ctx); + if (c == NULL) return NULL; - status = nbt_name_dup(state, name, &state->name); - if (!NT_STATUS_IS_OK(status)) goto failed; + c->event_ctx = talloc_reference(c, event_ctx); + if (composite_nomem(c->event_ctx, c)) return c; - c->state = COMPOSITE_STATE_IN_PROGRESS; + state = talloc(c, struct host_state); + if (composite_nomem(state, c)) return c; c->private_data = state; - c->event_ctx = talloc_reference(c, event_ctx); + + c->status = nbt_name_dup(state, name, &state->name); + if (!composite_is_ok(c)) return c; /* setup a pipe to chat to our child */ ret = pipe(fd); - if (ret == -1) goto failed; + if (ret == -1) { + composite_error(c, map_nt_error_from_unix(errno)); + return c; + } state->child_fd = fd[0]; state->event_ctx = c->event_ctx; @@ -162,10 +156,10 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, we know when the gethostbyname() has finished */ state->fde = event_add_fd(c->event_ctx, c, state->child_fd, EVENT_FD_READ, pipe_handler, c); - if (state->fde == NULL) { + if (composite_nomem(state->fde, c)) { close(fd[0]); close(fd[1]); - goto failed; + return c; } /* signal handling in posix really sucks - doing this in a library @@ -174,7 +168,8 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, state->child = fork(); if (state->child == (pid_t)-1) { - goto failed; + composite_error(c, map_nt_error_from_unix(errno)); + return c; } if (state->child == 0) { @@ -187,11 +182,7 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, /* cleanup wayward children */ talloc_set_destructor(state, host_destructor); - return c; - -failed: - talloc_free(c); - return NULL; + return c; } /* -- cgit From fe2a5a8abf3e1fb916e49700c5293eb91f9524ed Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 9 Nov 2006 01:11:45 +0000 Subject: r19645: don't pass NULL as mem_ctx... metze (This used to be commit 643a38bc30a0df1582035b8d264e0dbbc2d2e152) --- source4/libcli/resolve/host.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source4/libcli/resolve/host.c') 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); } -- cgit From c6b66db2b23f5a590152b3909da1193dc54d21ec Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 28 Feb 2007 17:26:25 +0000 Subject: r21594: give the same error in all resolve backends metze (This used to be commit 5534ba591deb362e30e40afff923af4b890ab7a9) --- source4/libcli/resolve/host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index f84a7dc808..43467cd274 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -101,7 +101,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, the right thing to do */ ret = read(state->child_fd, address, sizeof(address)-1); if (ret <= 0) { - composite_error(c, NT_STATUS_BAD_NETWORK_NAME); + composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND); return; } @@ -109,7 +109,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, address[ret] = 0; if (strcmp(address, "0.0.0.0") == 0 || inet_addr(address) == INADDR_NONE) { - composite_error(c, NT_STATUS_BAD_NETWORK_NAME); + composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND); return; } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/libcli/resolve/host.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 43467cd274..ec394309ef 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* -- cgit From b09047b78e981af8ade6a72d426bfcb0e742995b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 Oct 2007 20:24:37 +0200 Subject: r25624: Remove ipv4_addr hack. Only causes 4 extra includes of system/network.h because we stripped down includes. (This used to be commit 262c1c23a61f1f4fae13e0a61179fe98b682cecf) --- source4/libcli/resolve/host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index ec394309ef..e98bbc51b2 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -65,14 +65,14 @@ static int host_destructor(struct host_state *state) static void run_child(struct composite_context *c, int fd) { struct host_state *state = talloc_get_type(c->private_data, struct host_state); - struct ipv4_addr ip; + struct in_addr ip; const char *address; /* this is the blocking call we are going to lots of trouble to avoid in the parent */ ip = interpret_addr2(state->name.name); - address = sys_inet_ntoa(ip); + address = inet_ntoa(ip); if (address != NULL) { write(fd, address, strlen(address)+1); } -- cgit From 5f4842cf65ce64bfdf577cd549565da20ca818cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Dec 2007 18:41:19 +0100 Subject: r26376: Add context for libcli_resolve. (This used to be commit 459e1466a411d6f83b7372e248566e6e71c745fc) --- source4/libcli/resolve/host.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index e98bbc51b2..4b8f3f9553 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -34,6 +34,7 @@ #include "system/filesys.h" #include "libcli/composite/composite.h" #include "librpc/gen_ndr/ndr_nbt.h" +#include "libcli/resolve/resolve.h" struct host_state { struct nbt_name name; @@ -123,6 +124,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, */ struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + void *privdata, struct nbt_name *name) { struct composite_context *c; @@ -213,7 +215,12 @@ NTSTATUS resolve_name_host(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, name); + struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, NULL, name); return resolve_name_host_recv(c, mem_ctx, reply_addr); } +bool resolve_context_add_host_method(struct resolve_context *ctx) +{ + return resolve_context_add_method(ctx, resolve_name_host_send, resolve_name_host_recv, + NULL); +} -- cgit From 4e83011f72ba3df387512755a17760b42a7bf2f2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Apr 2008 17:58:23 -0400 Subject: Remove more event_context_init() uses from function calls within deep down the code. Make sure we pass around the event_context where we need it instead. All test but a few python ones fail. Jelmer promised to fix them. (This used to be commit 3045d391626fba169aa26be52174883e18d323e9) --- source4/libcli/resolve/host.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/resolve/host.c') diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index 4b8f3f9553..1a695432ee 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -135,7 +135,6 @@ struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx, c = composite_create(mem_ctx, event_ctx); if (c == NULL) return NULL; - c->event_ctx = talloc_reference(c, event_ctx); if (composite_nomem(c->event_ctx, c)) return c; state = talloc(c, struct host_state); -- cgit