summaryrefslogtreecommitdiff
path: root/source4/libcli/resolve/host.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-11-08 22:33:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:25:24 -0500
commitc71152180c6e65e1492e41e9c2ea61b37f4f8df1 (patch)
tree911ff880033b46b94a3d8671312cf8257dd10ea3 /source4/libcli/resolve/host.c
parent8845a00fa1bee118a24fe160eb7482465190461a (diff)
downloadsamba-c71152180c6e65e1492e41e9c2ea61b37f4f8df1.tar.gz
samba-c71152180c6e65e1492e41e9c2ea61b37f4f8df1.tar.bz2
samba-c71152180c6e65e1492e41e9c2ea61b37f4f8df1.zip
r19642: convert host.c to new composite api
metze (This used to be commit a5d36a6ddefb8c24e748b839391241da41e31440)
Diffstat (limited to 'source4/libcli/resolve/host.c')
-rw-r--r--source4/libcli/resolve/host.c61
1 files changed, 26 insertions, 35 deletions
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;
}
/*