From 2383787f199c51cdc202a3cef5822a9fe6b8774c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Jan 2005 11:18:56 +0000 Subject: r4891: - added a generic resolve_name() async interface in libcli/resolve/, which will eventually try all resolution methods setup in smb.conf - only resolution backend at the moment is bcast, which does a parallel broadcast to all configured network interfaces, and takes the first reply that comes in (this nicely demonstrates how to do parallel requests using the async APIs) - converted all the existing code to use the new resolve_name() api - removed all the old nmb code (yay!) (This used to be commit 239c310f255e43dd2d1c2433f666c9faaacbdce3) --- source4/libcli/resolve/bcast.c | 163 +++++++++++++++++++++++++++++++++++++++ source4/libcli/resolve/resolve.c | 51 ++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 source4/libcli/resolve/bcast.c create mode 100644 source4/libcli/resolve/resolve.c (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c new file mode 100644 index 0000000000..b2d37fbfbb --- /dev/null +++ b/source4/libcli/resolve/bcast.c @@ -0,0 +1,163 @@ +/* + Unix SMB/CIFS implementation. + + broadcast 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. +*/ + +#include "includes.h" +#include "system/network.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/nbt/libnbt.h" +#include "libcli/composite/composite.h" + +struct bcast_state { + struct nbt_name name; + struct nbt_name_socket *nbtsock; + int num_queries; + struct nbt_name_request **queries; + struct nbt_name_query *io_queries; + const char *reply_addr; +}; + +/* + handle events during broadcast name resolution +*/ +static void bcast_handler(struct nbt_name_request *req) +{ + struct smbcli_composite *c = talloc_get_type(req->async.private, + struct smbcli_composite); + struct bcast_state *state = talloc_get_type(c->private, struct bcast_state); + int i; + + for (i=0;inum_queries;i++) { + if (req == state->queries[i]) break; + } + if (i == state->num_queries) { + /* not for us?! */ + c->status = NT_STATUS_INTERNAL_ERROR; + c->state = SMBCLI_REQUEST_ERROR; + goto done; + } + + c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); + if (!NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_ERROR; + } else { + c->state = SMBCLI_REQUEST_DONE; + state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addr); + } + +done: + talloc_free(state->nbtsock); + if (c->async.fn) { + c->async.fn(c); + } +} + +/* + broadcast name resolution method - async send + */ +struct smbcli_composite *resolve_name_bcast_send(struct nbt_name *name, + struct event_context *event_ctx) +{ + struct smbcli_composite *c; + struct bcast_state *state; + int i; + NTSTATUS status; + + c = talloc_zero(NULL, struct smbcli_composite); + if (c == NULL) goto failed; + + state = talloc(c, struct bcast_state); + if (state == NULL) goto failed; + + status = nbt_name_dup(state, name, &state->name); + if (!NT_STATUS_IS_OK(status)) goto failed; + + state->nbtsock = nbt_name_socket_init(state, event_ctx); + if (state->nbtsock == NULL) goto failed; + + state->num_queries = iface_count(); + + state->io_queries = talloc_array(state, struct nbt_name_query, state->num_queries); + if (!state->io_queries) goto failed; + + state->queries = talloc_array(state, struct nbt_name_request *, state->num_queries); + if (!state->queries) goto failed; + + for (i=0;inum_queries;i++) { + struct ipv4_addr *ip = iface_n_bcast(i); + const char *addr = sys_inet_ntoa(*ip); + if (!addr) goto failed; + + state->io_queries[i].in.name = state->name; + state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, addr); + if (!state->io_queries[i].in.dest_addr) goto failed; + state->io_queries[i].in.broadcast = True; + state->io_queries[i].in.wins_lookup = False; + state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "bcastTimeout", 5); + + state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); + if (!state->queries[i]) goto failed; + + state->queries[i]->async.fn = bcast_handler; + state->queries[i]->async.private = c; + } + + c->state = SMBCLI_REQUEST_SEND; + c->private = state; + c->event_ctx = state->nbtsock->event_ctx; + + return c; + +failed: + talloc_free(c); + return NULL; +} + +/* + broadcast name resolution method - recv side + */ +NTSTATUS resolve_name_bcast_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 bcast_state *state = talloc_get_type(c->private, struct bcast_state); + *reply_addr = talloc_steal(mem_ctx, state->reply_addr); + } + + talloc_free(c); + return status; +} + +/* + broadcast name resolution method - sync call + */ +NTSTATUS resolve_name_bcast(struct nbt_name *name, + TALLOC_CTX *mem_ctx, + const char **reply_addr) +{ + struct smbcli_composite *c = resolve_name_bcast_send(name, NULL); + return resolve_name_bcast_recv(c, mem_ctx, reply_addr); +} + diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c new file mode 100644 index 0000000000..e83b11c95e --- /dev/null +++ b/source4/libcli/resolve/resolve.c @@ -0,0 +1,51 @@ +/* + Unix SMB/CIFS implementation. + + general name resolution interface + + 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. +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" + +/* + general name resolution - async send + */ +struct smbcli_composite *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx) +{ + return resolve_name_bcast_send(name, event_ctx); +} + +/* + general name resolution method - recv side + */ +NTSTATUS resolve_name_recv(struct smbcli_composite *c, + TALLOC_CTX *mem_ctx, const char **reply_addr) +{ + return resolve_name_bcast_recv(c, mem_ctx, reply_addr); +} + +/* + general name resolution - sync call + */ +NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) +{ + struct smbcli_composite *c = resolve_name_send(name, NULL); + return resolve_name_recv(c, mem_ctx, reply_addr); +} -- cgit From c0e21a4d3eaac92387c497f75b5957d0b8a4dc8a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Jan 2005 11:41:48 +0000 Subject: r4896: make sure the event context doesn't go away while waiting for event completion (This used to be commit c1063919c069b0b36dd3da6dc6853236629804e3) --- source4/libcli/resolve/bcast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index b2d37fbfbb..d424b5303a 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -122,7 +122,7 @@ struct smbcli_composite *resolve_name_bcast_send(struct nbt_name *name, c->state = SMBCLI_REQUEST_SEND; c->private = state; - c->event_ctx = state->nbtsock->event_ctx; + c->event_ctx = talloc_reference(c, state->nbtsock->event_ctx); return c; -- cgit From 6f0aef31cdfa9b486d1f2e0f097e071830f5600d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Jan 2005 13:13:24 +0000 Subject: r4898: - removed the unused wins_srv_*() code - expanded the generic async name resolver to try multiple methods - added wins resolutions to the list of methods tried - fixed up the random trn id generation to use the good random generator (This used to be commit 266fd2751c01808e5a18d4094032af50554ceb7a) --- source4/libcli/resolve/bcast.c | 116 ++++---------------------- source4/libcli/resolve/nbtlist.c | 170 +++++++++++++++++++++++++++++++++++++++ source4/libcli/resolve/resolve.c | 113 +++++++++++++++++++++++++- source4/libcli/resolve/wins.c | 58 +++++++++++++ 4 files changed, 354 insertions(+), 103 deletions(-) create mode 100644 source4/libcli/resolve/nbtlist.c create mode 100644 source4/libcli/resolve/wins.c (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index d424b5303a..9aefa32fae 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -23,112 +23,36 @@ #include "includes.h" #include "system/network.h" #include "libcli/raw/libcliraw.h" -#include "libcli/nbt/libnbt.h" #include "libcli/composite/composite.h" -struct bcast_state { - struct nbt_name name; - struct nbt_name_socket *nbtsock; - int num_queries; - struct nbt_name_request **queries; - struct nbt_name_query *io_queries; - const char *reply_addr; -}; - -/* - handle events during broadcast name resolution -*/ -static void bcast_handler(struct nbt_name_request *req) -{ - struct smbcli_composite *c = talloc_get_type(req->async.private, - struct smbcli_composite); - struct bcast_state *state = talloc_get_type(c->private, struct bcast_state); - int i; - - for (i=0;inum_queries;i++) { - if (req == state->queries[i]) break; - } - if (i == state->num_queries) { - /* not for us?! */ - c->status = NT_STATUS_INTERNAL_ERROR; - c->state = SMBCLI_REQUEST_ERROR; - goto done; - } - - c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); - if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; - } else { - c->state = SMBCLI_REQUEST_DONE; - state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addr); - } - -done: - talloc_free(state->nbtsock); - if (c->async.fn) { - c->async.fn(c); - } -} - /* broadcast name resolution method - async send */ struct smbcli_composite *resolve_name_bcast_send(struct nbt_name *name, struct event_context *event_ctx) { + int num_interfaces = iface_count(); + const char **address_list; struct smbcli_composite *c; - struct bcast_state *state; int i; - NTSTATUS status; - - c = talloc_zero(NULL, struct smbcli_composite); - if (c == NULL) goto failed; - state = talloc(c, struct bcast_state); - if (state == NULL) goto failed; + address_list = talloc_array(NULL, const char *, num_interfaces+1); + if (address_list == NULL) return NULL; - status = nbt_name_dup(state, name, &state->name); - if (!NT_STATUS_IS_OK(status)) goto failed; - - state->nbtsock = nbt_name_socket_init(state, event_ctx); - if (state->nbtsock == NULL) goto failed; - - state->num_queries = iface_count(); - - state->io_queries = talloc_array(state, struct nbt_name_query, state->num_queries); - if (!state->io_queries) goto failed; - - state->queries = talloc_array(state, struct nbt_name_request *, state->num_queries); - if (!state->queries) goto failed; - - for (i=0;inum_queries;i++) { + for (i=0;iio_queries[i].in.name = state->name; - state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, addr); - if (!state->io_queries[i].in.dest_addr) goto failed; - state->io_queries[i].in.broadcast = True; - state->io_queries[i].in.wins_lookup = False; - state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "bcastTimeout", 5); - - state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); - if (!state->queries[i]) goto failed; - - state->queries[i]->async.fn = bcast_handler; - state->queries[i]->async.private = c; + address_list[i] = talloc_strdup(address_list, sys_inet_ntoa(*ip)); + if (address_list[i] == NULL) { + talloc_free(address_list); + return NULL; + } } + address_list[i] = NULL; - c->state = SMBCLI_REQUEST_SEND; - c->private = state; - c->event_ctx = talloc_reference(c, state->nbtsock->event_ctx); - - return c; + c = resolve_name_nbtlist_send(name, event_ctx, address_list, True, False); + talloc_free(address_list); -failed: - talloc_free(c); - return NULL; + return c; } /* @@ -137,17 +61,7 @@ failed: NTSTATUS resolve_name_bcast_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 bcast_state *state = talloc_get_type(c->private, struct bcast_state); - *reply_addr = talloc_steal(mem_ctx, state->reply_addr); - } - - talloc_free(c); - return status; + return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); } /* diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c new file mode 100644 index 0000000000..036e983fd2 --- /dev/null +++ b/source4/libcli/resolve/nbtlist.c @@ -0,0 +1,170 @@ +/* + Unix SMB/CIFS implementation. + + nbt list of addresses 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. +*/ + +/* + TODO: we should lower the timeout, and add retries for each name +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/nbt/libnbt.h" +#include "libcli/composite/composite.h" + +struct nbtlist_state { + struct nbt_name name; + struct nbt_name_socket *nbtsock; + int num_queries; + struct nbt_name_request **queries; + struct nbt_name_query *io_queries; + const char *reply_addr; +}; + +/* + handle events during nbtlist name resolution +*/ +static void nbtlist_handler(struct nbt_name_request *req) +{ + struct smbcli_composite *c = talloc_get_type(req->async.private, + struct smbcli_composite); + struct nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); + int i; + + for (i=0;inum_queries;i++) { + if (req == state->queries[i]) break; + } + if (i == state->num_queries) { + /* not for us?! */ + c->status = NT_STATUS_INTERNAL_ERROR; + c->state = SMBCLI_REQUEST_ERROR; + goto done; + } + + c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); + if (!NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_ERROR; + } else { + c->state = SMBCLI_REQUEST_DONE; + state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addr); + } + +done: + talloc_free(state->nbtsock); + if (c->async.fn) { + c->async.fn(c); + } +} + +/* + nbtlist name resolution method - async send + */ +struct smbcli_composite *resolve_name_nbtlist_send(struct nbt_name *name, + struct event_context *event_ctx, + const char **address_list, + BOOL broadcast, + BOOL wins_lookup) +{ + struct smbcli_composite *c; + struct nbtlist_state *state; + int i; + NTSTATUS status; + + c = talloc_zero(NULL, struct smbcli_composite); + if (c == NULL) goto failed; + + state = talloc(c, struct nbtlist_state); + if (state == NULL) goto failed; + + status = nbt_name_dup(state, name, &state->name); + if (!NT_STATUS_IS_OK(status)) goto failed; + + state->nbtsock = nbt_name_socket_init(state, event_ctx); + if (state->nbtsock == NULL) goto failed; + + /* count the address_list size */ + for (i=0;address_list[i];i++) /* noop */ ; + + state->num_queries = i; + state->io_queries = talloc_array(state, struct nbt_name_query, state->num_queries); + if (!state->io_queries) goto failed; + + state->queries = talloc_array(state, struct nbt_name_request *, state->num_queries); + if (!state->queries) goto failed; + + for (i=0;inum_queries;i++) { + state->io_queries[i].in.name = state->name; + state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); + if (!state->io_queries[i].in.dest_addr) goto failed; + state->io_queries[i].in.broadcast = broadcast; + state->io_queries[i].in.wins_lookup = wins_lookup; + state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 3); + + state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); + if (!state->queries[i]) goto failed; + + state->queries[i]->async.fn = nbtlist_handler; + state->queries[i]->async.private = c; + } + + c->state = SMBCLI_REQUEST_SEND; + c->private = state; + c->event_ctx = talloc_reference(c, state->nbtsock->event_ctx); + + return c; + +failed: + talloc_free(c); + return NULL; +} + +/* + nbt list of addresses name resolution method - recv side + */ +NTSTATUS resolve_name_nbtlist_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 nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); + *reply_addr = talloc_steal(mem_ctx, state->reply_addr); + } + + talloc_free(c); + return status; +} + +/* + nbt list of addresses name resolution method - sync call + */ +NTSTATUS resolve_name_nbtlist(struct nbt_name *name, + TALLOC_CTX *mem_ctx, + const char **address_list, + BOOL broadcast, BOOL wins_lookup, + const char **reply_addr) +{ + struct smbcli_composite *c = resolve_name_nbtlist_send(name, NULL, 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 e83b11c95e..b36d6e8ee6 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -24,12 +24,111 @@ #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +struct resolve_state { + struct nbt_name name; + const char **methods; + struct smbcli_composite *req; + const char *reply_addr; +}; + +static struct smbcli_composite *setup_next_method(struct smbcli_composite *c); + +/* + handle completion of one name resolve method +*/ +static void resolve_handler(struct smbcli_composite *req) +{ + struct smbcli_composite *c = req->async.private; + struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + const char *method = state->methods[0]; + + if (strcasecmp(method, "bcast")) { + c->status = resolve_name_bcast_recv(req, state, &state->reply_addr); + } else if (strcasecmp(method, "wins")) { + c->status = resolve_name_wins_recv(req, state, &state->reply_addr); + } else { + c->status = NT_STATUS_INTERNAL_ERROR; + } + + if (!NT_STATUS_IS_OK(c->status)) { + state->methods++; + state->req = setup_next_method(c); + if (state->req != NULL) { + return; + } + } + + if (!NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_ERROR; + } else { + c->state = SMBCLI_REQUEST_DONE; + } + if (c->async.fn) { + c->async.fn(c); + } +} + + +static struct smbcli_composite *setup_next_method(struct smbcli_composite *c) +{ + struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + const char *method; + struct smbcli_composite *req = NULL; + + do { + method = state->methods[0]; + if (method == NULL) break; + if (strcasecmp(method, "bcast")) { + req = resolve_name_bcast_send(&state->name, c->event_ctx); + } else if (strcasecmp(method, "wins")) { + req = resolve_name_wins_send(&state->name, c->event_ctx); + } + if (req == NULL) state->methods++; + } while (!req && state->methods[0]); + + if (req) { + req->async.fn = resolve_handler; + req->async.private = c; + } + + return req; +} + /* general name resolution - async send */ struct smbcli_composite *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx) { - return resolve_name_bcast_send(name, event_ctx); + struct smbcli_composite *c; + struct resolve_state *state; + NTSTATUS status; + + c = talloc_zero(NULL, struct smbcli_composite); + if (c == NULL) goto failed; + + state = talloc(c, struct resolve_state); + if (state == NULL) goto failed; + + status = nbt_name_dup(state, name, &state->name); + if (!NT_STATUS_IS_OK(status)) goto failed; + + state->methods = lp_name_resolve_order(); + if (state->methods == NULL) { + return NULL; + } + + c->state = SMBCLI_REQUEST_SEND; + c->private = state; + c->event_ctx = talloc_reference(c, event_ctx); + + state->req = setup_next_method(c); + if (state->req == NULL) goto failed; + + return c; + +failed: + talloc_free(c); + return NULL; } /* @@ -38,7 +137,17 @@ struct smbcli_composite *resolve_name_send(struct nbt_name *name, struct event_c NTSTATUS resolve_name_recv(struct smbcli_composite *c, TALLOC_CTX *mem_ctx, const char **reply_addr) { - return resolve_name_bcast_recv(c, mem_ctx, reply_addr); + NTSTATUS status; + + status = smb_composite_wait(c); + + if (NT_STATUS_IS_OK(status)) { + struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + *reply_addr = talloc_steal(mem_ctx, state->reply_addr); + } + + talloc_free(c); + return status; } /* diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c new file mode 100644 index 0000000000..5a0e067832 --- /dev/null +++ b/source4/libcli/resolve/wins.c @@ -0,0 +1,58 @@ +/* + Unix SMB/CIFS implementation. + + wins 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. +*/ + +#include "includes.h" +#include "system/network.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" + +/* + wins name resolution method - async send + */ +struct smbcli_composite *resolve_name_wins_send(struct nbt_name *name, + struct event_context *event_ctx) +{ + 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); +} + +/* + wins name resolution method - recv side + */ +NTSTATUS resolve_name_wins_recv(struct smbcli_composite *c, + TALLOC_CTX *mem_ctx, const char **reply_addr) +{ + return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); +} + +/* + wins name resolution method - sync call + */ +NTSTATUS resolve_name_wins(struct nbt_name *name, + TALLOC_CTX *mem_ctx, + const char **reply_addr) +{ + struct smbcli_composite *c = resolve_name_wins_send(name, NULL); + return resolve_name_wins_recv(c, mem_ctx, reply_addr); +} + -- cgit 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 +++++++++++++++++++++++++++++++++++++++ source4/libcli/resolve/resolve.c | 51 ++++++--- 2 files changed, 268 insertions(+), 16 deletions(-) create mode 100644 source4/libcli/resolve/host.c (limited to 'source4/libcli/resolve') 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); +} + diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index b36d6e8ee6..013403fd9c 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -33,6 +33,33 @@ struct resolve_state { static struct smbcli_composite *setup_next_method(struct smbcli_composite *c); +/* pointers to the resolver backends */ +static const struct resolve_method { + const char *name; + struct smbcli_composite *(*send_fn)(struct nbt_name *, struct event_context *); + NTSTATUS (*recv_fn)(struct smbcli_composite *, TALLOC_CTX *, const char **); +} methods[] = { + { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, + { "wins", resolve_name_wins_send, resolve_name_wins_recv }, + { "host", resolve_name_host_send, resolve_name_host_recv } +}; + + +/* + find a matching backend +*/ +static const struct resolve_method *find_method(const char *name) +{ + int i; + if (name == NULL) return NULL; + for (i=0;iasync.private; struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); - const char *method = state->methods[0]; + const struct resolve_method *method = find_method(state->methods[0]); - if (strcasecmp(method, "bcast")) { - c->status = resolve_name_bcast_recv(req, state, &state->reply_addr); - } else if (strcasecmp(method, "wins")) { - c->status = resolve_name_wins_recv(req, state, &state->reply_addr); - } else { - c->status = NT_STATUS_INTERNAL_ERROR; - } + c->status = method->recv_fn(req, state, &state->reply_addr); if (!NT_STATUS_IS_OK(c->status)) { state->methods++; @@ -72,18 +93,16 @@ static void resolve_handler(struct smbcli_composite *req) static struct smbcli_composite *setup_next_method(struct smbcli_composite *c) { struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); - const char *method; struct smbcli_composite *req = NULL; do { - method = state->methods[0]; - if (method == NULL) break; - if (strcasecmp(method, "bcast")) { - req = resolve_name_bcast_send(&state->name, c->event_ctx); - } else if (strcasecmp(method, "wins")) { - req = resolve_name_wins_send(&state->name, c->event_ctx); + const struct resolve_method *method = find_method(state->methods[0]); + if (method) { + req = method->send_fn(&state->name, c->event_ctx); + if (req == NULL) { + state->methods++; + } } - if (req == NULL) state->methods++; } while (!req && state->methods[0]); if (req) { -- cgit From d069c368fbd900f9c6e22d7dccdd84c5202997a1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Jan 2005 01:37:48 +0000 Subject: r4919: if a caller doesn't provide an event context to the resolver library, then create one. This fixes a crash in the RAW-NEGNOWAIT test for 'host' resolution. (This used to be commit 3268d523cc381b9b3077f794bb53daf0865d139c) --- source4/libcli/resolve/resolve.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 013403fd9c..ef906d4ed0 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -138,7 +138,12 @@ struct smbcli_composite *resolve_name_send(struct nbt_name *name, struct event_c c->state = SMBCLI_REQUEST_SEND; c->private = state; - c->event_ctx = talloc_reference(c, event_ctx); + if (event_ctx == NULL) { + c->event_ctx = event_context_init(c); + if (c->event_ctx == NULL) goto failed; + } else { + c->event_ctx = talloc_reference(c, event_ctx); + } state->req = setup_next_method(c); if (state->req == NULL) goto failed; -- cgit From 5ffedbac3d06ef852508dde3924841a86b802295 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Jan 2005 02:08:30 +0000 Subject: r4922: fixed an infinite loop in the name resolve code when handling a method in smb.conf that isn't implemented in the library (This used to be commit dd5b43ed37b37feec4708f8f13033b42eb6a838c) --- source4/libcli/resolve/resolve.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index ef906d4ed0..054f10d529 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -99,10 +99,8 @@ static struct smbcli_composite *setup_next_method(struct smbcli_composite *c) const struct resolve_method *method = find_method(state->methods[0]); if (method) { req = method->send_fn(&state->name, c->event_ctx); - if (req == NULL) { - state->methods++; - } } + if (req == NULL) state->methods++; } while (!req && state->methods[0]); if (req) { -- 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') 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') 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 5269fb13a92850b5f22bf9f7640568d5946a43d5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Jan 2005 02:50:49 +0000 Subject: r5116: fixed build of the nbtlist code (This used to be commit 506e1e823cd3f652a793db9f4c43147d298b9b8b) --- source4/libcli/resolve/nbtlist.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 036e983fd2..08dc90c39d 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -62,8 +62,13 @@ static void nbtlist_handler(struct nbt_name_request *req) if (!NT_STATUS_IS_OK(c->status)) { c->state = SMBCLI_REQUEST_ERROR; } else { - c->state = SMBCLI_REQUEST_DONE; - state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addr); + if (state->io_queries[i].out.num_addrs < 1) { + c->state = SMBCLI_REQUEST_ERROR; + c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; + } else { + c->state = SMBCLI_REQUEST_DONE; + state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addrs[0]); + } } done: -- 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/bcast.c | 8 ++++---- source4/libcli/resolve/host.c | 16 ++++++++-------- source4/libcli/resolve/nbtlist.c | 16 ++++++++-------- source4/libcli/resolve/resolve.c | 28 ++++++++++++++-------------- source4/libcli/resolve/wins.c | 6 +++--- 5 files changed, 37 insertions(+), 37 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 9aefa32fae..5fb6e6dd5c 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -28,12 +28,12 @@ /* broadcast name resolution method - async send */ -struct smbcli_composite *resolve_name_bcast_send(struct nbt_name *name, +struct composite_context *resolve_name_bcast_send(struct nbt_name *name, struct event_context *event_ctx) { int num_interfaces = iface_count(); const char **address_list; - struct smbcli_composite *c; + struct composite_context *c; int i; address_list = talloc_array(NULL, const char *, num_interfaces+1); @@ -58,7 +58,7 @@ struct smbcli_composite *resolve_name_bcast_send(struct nbt_name *name, /* broadcast name resolution method - recv side */ -NTSTATUS resolve_name_bcast_recv(struct smbcli_composite *c, +NTSTATUS resolve_name_bcast_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, const char **reply_addr) { return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); @@ -71,7 +71,7 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct smbcli_composite *c = resolve_name_bcast_send(name, NULL); + struct composite_context *c = resolve_name_bcast_send(name, NULL); 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 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); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 08dc90c39d..5a9e31e09d 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -43,8 +43,8 @@ struct nbtlist_state { */ static void nbtlist_handler(struct nbt_name_request *req) { - struct smbcli_composite *c = talloc_get_type(req->async.private, - struct smbcli_composite); + struct composite_context *c = talloc_get_type(req->async.private, + struct composite_context); struct nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); int i; @@ -81,18 +81,18 @@ done: /* nbtlist name resolution method - async send */ -struct smbcli_composite *resolve_name_nbtlist_send(struct nbt_name *name, +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 smbcli_composite *c; + struct composite_context *c; struct nbtlist_state *state; int i; NTSTATUS status; - c = talloc_zero(NULL, struct smbcli_composite); + c = talloc_zero(NULL, struct composite_context); if (c == NULL) goto failed; state = talloc(c, struct nbtlist_state); @@ -143,12 +143,12 @@ failed: /* nbt list of addresses name resolution method - recv side */ -NTSTATUS resolve_name_nbtlist_recv(struct smbcli_composite *c, +NTSTATUS resolve_name_nbtlist_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 nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); @@ -168,7 +168,7 @@ NTSTATUS resolve_name_nbtlist(struct nbt_name *name, BOOL broadcast, BOOL wins_lookup, const char **reply_addr) { - struct smbcli_composite *c = resolve_name_nbtlist_send(name, NULL, address_list, + struct composite_context *c = resolve_name_nbtlist_send(name, NULL, 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 054f10d529..eb35a7cb99 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -27,17 +27,17 @@ struct resolve_state { struct nbt_name name; const char **methods; - struct smbcli_composite *req; + struct composite_context *req; const char *reply_addr; }; -static struct smbcli_composite *setup_next_method(struct smbcli_composite *c); +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 smbcli_composite *(*send_fn)(struct nbt_name *, struct event_context *); - NTSTATUS (*recv_fn)(struct smbcli_composite *, TALLOC_CTX *, const char **); + struct composite_context *(*send_fn)(struct nbt_name *, struct event_context *); + NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); } methods[] = { { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, { "wins", resolve_name_wins_send, resolve_name_wins_recv }, @@ -63,9 +63,9 @@ static const struct resolve_method *find_method(const char *name) /* handle completion of one name resolve method */ -static void resolve_handler(struct smbcli_composite *req) +static void resolve_handler(struct composite_context *req) { - struct smbcli_composite *c = req->async.private; + struct composite_context *c = req->async.private; struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); const struct resolve_method *method = find_method(state->methods[0]); @@ -90,10 +90,10 @@ static void resolve_handler(struct smbcli_composite *req) } -static struct smbcli_composite *setup_next_method(struct smbcli_composite *c) +static struct composite_context *setup_next_method(struct composite_context *c) { struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); - struct smbcli_composite *req = NULL; + struct composite_context *req = NULL; do { const struct resolve_method *method = find_method(state->methods[0]); @@ -114,13 +114,13 @@ static struct smbcli_composite *setup_next_method(struct smbcli_composite *c) /* general name resolution - async send */ -struct smbcli_composite *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx) +struct composite_context *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx) { - struct smbcli_composite *c; + struct composite_context *c; struct resolve_state *state; NTSTATUS status; - c = talloc_zero(NULL, struct smbcli_composite); + c = talloc_zero(NULL, struct composite_context); if (c == NULL) goto failed; state = talloc(c, struct resolve_state); @@ -156,12 +156,12 @@ failed: /* general name resolution method - recv side */ -NTSTATUS resolve_name_recv(struct smbcli_composite *c, +NTSTATUS resolve_name_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 resolve_state *state = talloc_get_type(c->private, struct resolve_state); @@ -177,6 +177,6 @@ NTSTATUS resolve_name_recv(struct smbcli_composite *c, */ NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct smbcli_composite *c = resolve_name_send(name, NULL); + struct composite_context *c = resolve_name_send(name, NULL); return resolve_name_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 5a0e067832..aa4ec0cea4 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -28,7 +28,7 @@ /* wins name resolution method - async send */ -struct smbcli_composite *resolve_name_wins_send(struct nbt_name *name, +struct composite_context *resolve_name_wins_send(struct nbt_name *name, struct event_context *event_ctx) { const char **address_list = lp_wins_server_list(); @@ -39,7 +39,7 @@ struct smbcli_composite *resolve_name_wins_send(struct nbt_name *name, /* wins name resolution method - recv side */ -NTSTATUS resolve_name_wins_recv(struct smbcli_composite *c, +NTSTATUS resolve_name_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, const char **reply_addr) { return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); @@ -52,7 +52,7 @@ NTSTATUS resolve_name_wins(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct smbcli_composite *c = resolve_name_wins_send(name, NULL); + struct composite_context *c = resolve_name_wins_send(name, NULL); return resolve_name_wins_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 ++++-------- source4/libcli/resolve/resolve.c | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'source4/libcli/resolve') 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]); diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index eb35a7cb99..e2e9462561 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -- 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') 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 +- source4/libcli/resolve/resolve.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') 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" diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index e2e9462561..7e3f78edb4 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -21,7 +21,7 @@ */ #include "includes.h" -#include "events.h" +#include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -- cgit From b9bb7f596de51496c18580863efbb8ac17c78970 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 03:22:47 +0000 Subject: r5294: - added a separate NBT-WINS test for WINS operations (register, refresh, release and query) - change the iface_n_*() functions to return a "const char *" instead of a "struct ipv4_addr" I think that in general we should move towards "const char *" for all IP addresses, as this makes IPv6 much easier, and is also easier to debug. Andrew, when you get a chance, could you fix some of the auth code to use strings for IPs ? - return a NTSTATUS error on bad name queries and node status instead of using rcode. This makes the calling code simpler. - added low level name release code in libcli/nbt/ - use a real IP in the register and wins nbt torture tests, as w2k3 WINS server silently rejects some operations that don't come from the IP being used (eg. it says "yes" to a release, but does not in fact release the name) (This used to be commit bb1ab11d8e0ea0bd9ae34aebeb565d36fe4b495f) --- source4/libcli/resolve/bcast.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 5fb6e6dd5c..c47bba38c5 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -40,8 +40,7 @@ struct composite_context *resolve_name_bcast_send(struct nbt_name *name, if (address_list == NULL) return NULL; for (i=0;i 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') 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 dd689afdc807b9ff057ee7e917e12b6597fe319c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Feb 2005 07:54:20 +0000 Subject: r5328: - allow case sensitive nbt name lookups - added --case-sensitive option to nmblookup - added case sensitivity tests to the NBT-WINS test (This used to be commit 80a95d5688e055b36727e5c043cb36322d719763) --- source4/libcli/resolve/nbtlist.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 5a9e31e09d..89e9a63748 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -101,6 +101,13 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, status = nbt_name_dup(state, name, &state->name); if (!NT_STATUS_IS_OK(status)) goto failed; + state->name.name = strupper_talloc(state, state->name.name); + if (state->name.name == NULL) goto failed; + if (state->name.scope) { + state->name.scope = strupper_talloc(state, state->name.scope); + if (state->name.scope == NULL) goto failed; + } + state->nbtsock = nbt_name_socket_init(state, event_ctx); if (state->nbtsock == NULL) goto failed; -- cgit From 7fc5f4a6f7bd7a0b5c66b019377ba4ad1bc110bb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 25 Feb 2005 04:59:46 +0000 Subject: r5550: Initialise retry count - valgrind was freaking out because this value was not set. (This used to be commit 328f37a3e8d10f97f361fb041be24f1ac88b6b0a) --- source4/libcli/resolve/nbtlist.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 89e9a63748..d5b01e06d9 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -129,6 +129,7 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, state->io_queries[i].in.wins_lookup = wins_lookup; state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 3); + state->io_queries[i].in.retries = 0; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); if (!state->queries[i]) goto failed; -- cgit From c9b766a9af70ac7e94f7ebf872fa5b9e21220d12 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 25 Feb 2005 05:25:17 +0000 Subject: r5551: Protect against falling off the end of the name resolve order list if a name is not found. (This used to be commit c23f767a9f5dd2dcae31bded540263b08876ecc2) --- source4/libcli/resolve/resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 7e3f78edb4..82268dc953 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -101,7 +101,7 @@ static struct composite_context *setup_next_method(struct composite_context *c) if (method) { req = method->send_fn(&state->name, c->event_ctx); } - if (req == NULL) state->methods++; + if (req == NULL && state->methods[0]) state->methods++; } while (!req && state->methods[0]); if (req) { -- cgit From 2b7fe67f4d02f861c9a4bfe823e648f0a995e613 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 22 May 2005 10:23:01 +0000 Subject: r6933: Add a couple of helper functions for creating nbt names. (This used to be commit b896daf11c3efb1b3ca939575da9dab82b395777) --- source4/libcli/resolve/resolve.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 82268dc953..a3bbd60920 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -181,3 +181,26 @@ NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **r struct composite_context *c = resolve_name_send(name, NULL); return resolve_name_recv(c, mem_ctx, reply_addr); } + +/* Initialise a struct nbt_name with a NULL scope */ + +void make_nbt_name(struct nbt_name *nbt, const char *name, int type) +{ + nbt->name = name; + nbt->scope = NULL; + nbt->type = type; +} + +/* Initialise a struct nbt_name with a NBT_NAME_CLIENT (0x00) name */ + +void make_nbt_name_client(struct nbt_name *nbt, const char *name) +{ + make_nbt_name(nbt, name, NBT_NAME_CLIENT); +} + +/* Initialise a struct nbt_name with a NBT_NAME_SERVER (0x20) name */ + +void make_nbt_name_server(struct nbt_name *nbt, const char *name) +{ + make_nbt_name(nbt, name, NBT_NAME_SERVER); +} -- cgit From b773ca709abf1468859110a849e193362d4a2641 Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Sat, 18 Jun 2005 22:32:14 +0000 Subject: r7735: Extend resolve_name function so that it's possible to pass resolve methods explicitly or NULL for defaults saved in smb.conf. rafal (This used to be commit 121cf5ec3e075a6e37df52caad9fbc8bf7d59339) --- source4/libcli/resolve/resolve.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index a3bbd60920..0b7c359ca1 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -39,10 +39,11 @@ static const struct resolve_method { const char *name; struct composite_context *(*send_fn)(struct nbt_name *, struct event_context *); NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); + } methods[] = { - { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, - { "wins", resolve_name_wins_send, resolve_name_wins_recv }, - { "host", resolve_name_host_send, resolve_name_host_recv } + { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, + { "wins", resolve_name_wins_send, resolve_name_wins_recv }, + { "host", resolve_name_host_send, resolve_name_host_recv } }; @@ -115,7 +116,8 @@ static struct composite_context *setup_next_method(struct composite_context *c) /* general name resolution - async send */ -struct composite_context *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx) +struct composite_context *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx, + const char **methods) { struct composite_context *c; struct resolve_state *state; @@ -130,9 +132,15 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ status = nbt_name_dup(state, name, &state->name); if (!NT_STATUS_IS_OK(status)) goto failed; - state->methods = lp_name_resolve_order(); - if (state->methods == NULL) { - return NULL; + /* use default methods from config file if not passed explicitly */ + if (methods == NULL) { + state->methods = lp_name_resolve_order(); + if (state->methods == NULL) { + return NULL; + } + + } else { + state->methods = methods; } c->state = SMBCLI_REQUEST_SEND; @@ -178,7 +186,7 @@ NTSTATUS resolve_name_recv(struct composite_context *c, */ NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_send(name, NULL); + struct composite_context *c = resolve_name_send(name, NULL, NULL); return resolve_name_recv(c, mem_ctx, reply_addr); } -- cgit From 338bc0f58aef55f4b5820b97b234d2507d1ea236 Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Tue, 21 Jun 2005 20:18:08 +0000 Subject: r7813: Make async request independent from config file routines. rafal (This used to be commit 84315cdf0d535ed0fe43bfc7cc4c83bc405c2cfb) --- source4/libcli/resolve/resolve.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 0b7c359ca1..b87f9abe89 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -132,16 +132,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ status = nbt_name_dup(state, name, &state->name); if (!NT_STATUS_IS_OK(status)) goto failed; - /* use default methods from config file if not passed explicitly */ - if (methods == NULL) { - state->methods = lp_name_resolve_order(); - if (state->methods == NULL) { - return NULL; - } - - } else { - state->methods = methods; - } + if (methods == NULL) goto failed; + state->methods = methods; c->state = SMBCLI_REQUEST_SEND; c->private = state; @@ -186,7 +178,7 @@ NTSTATUS resolve_name_recv(struct composite_context *c, */ NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_send(name, NULL, NULL); + struct composite_context *c = resolve_name_send(name, NULL, lp_name_resolve_order()); return resolve_name_recv(c, mem_ctx, reply_addr); } -- cgit From 21d6a163a30d2eac0e048c8ebc02cb48213ac543 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 24 Jun 2005 00:04:26 +0000 Subject: r7856: fixed warning of 'methods' shadowed variable (This used to be commit c435843c66a5dcc003d157374529c3c5ac733e36) --- source4/libcli/resolve/resolve.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index b87f9abe89..3607400155 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -40,7 +40,7 @@ static const struct resolve_method { struct composite_context *(*send_fn)(struct nbt_name *, struct event_context *); NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); -} methods[] = { +} resolve_methods[] = { { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, { "wins", resolve_name_wins_send, resolve_name_wins_recv }, { "host", resolve_name_host_send, resolve_name_host_recv } @@ -54,9 +54,9 @@ static const struct resolve_method *find_method(const char *name) { int i; if (name == NULL) return NULL; - for (i=0;i Date: Thu, 30 Jun 2005 01:26:52 +0000 Subject: r8002: favor addresses on our local interfaces in NBT name resolution if possible. This is needed because w2k3 will return bogus IPs in its name resolution replies when it has an unplugged network interface. (This used to be commit 2fafc230520fb5bbe9f763de94aaba87b56f5411) --- source4/libcli/resolve/nbtlist.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index d5b01e06d9..0026c6fceb 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -66,8 +66,21 @@ static void nbtlist_handler(struct nbt_name_request *req) c->state = SMBCLI_REQUEST_ERROR; c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; } else { + struct nbt_name_query *q = &state->io_queries[i]; c->state = SMBCLI_REQUEST_DONE; - state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addrs[0]); + /* favor a local address if possible */ + state->reply_addr = NULL; + for (i=0;iout.num_addrs;i++) { + if (iface_is_local(q->out.reply_addrs[i])) { + state->reply_addr = talloc_steal(state, + q->out.reply_addrs[i]); + break; + } + } + if (state->reply_addr == NULL) { + state->reply_addr = talloc_steal(state, + q->out.reply_addrs[0]); + } } } -- cgit From d9cfd55dbb969b08914fd306fb9d123e52ad6541 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jul 2005 04:21:10 +0000 Subject: r8628: add retries to the normal paths of nbt name resolution. UDP broadcasts are not 100% reliable :) (This used to be commit 0f8f1cd18e20ea4f3a06bb093b00b930cfd005b2) --- source4/libcli/resolve/nbtlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 0026c6fceb..7080c62e43 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -140,9 +140,9 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, if (!state->io_queries[i].in.dest_addr) goto failed; state->io_queries[i].in.broadcast = broadcast; state->io_queries[i].in.wins_lookup = wins_lookup; - state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 3); + state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 1); - state->io_queries[i].in.retries = 0; + state->io_queries[i].in.retries = 2; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); if (!state->queries[i]) goto failed; -- cgit From c98c6aa5611f26ab591c50fcded1fc55e81a0d07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 28 Aug 2005 02:37:14 +0000 Subject: r9702: r9680@blu: tridge | 2005-08-27 18:45:08 +1000 - fixed ncacn_ip_tcp to use the generic async name resolution methods, so NBT names now work (as requested several times by abartlet!) - changed resolve_name() to take an event_context, so it doesn't cause the whole process to block - cleaned up the talloc_find_parent_bytype() calls to go via a cleaner event_context_find() call (This used to be commit b3d491b210a8b889a25efcb273e70fefbd01b7f7) --- source4/libcli/resolve/resolve.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 3607400155..733eddf643 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -176,9 +176,10 @@ NTSTATUS resolve_name_recv(struct composite_context *c, /* general name resolution - sync call */ -NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) +NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, + struct event_context *ev) { - struct composite_context *c = resolve_name_send(name, NULL, lp_name_resolve_order()); + struct composite_context *c = resolve_name_send(name, ev, lp_name_resolve_order()); return resolve_name_recv(c, mem_ctx, reply_addr); } -- cgit From 45f760973d9b5c0663608e779eb337c0648e9313 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 13 Sep 2005 12:46:03 +0000 Subject: r10200: added a composite_trigger_done() call that allows a composite function to cause an event to happen immediately. This allows metzes patch for recognising IPs in resolve_name() to work, and also allows us to remove some of the other code where we currently do specific checks for is_ipaddress(). (This used to be commit 9cc000d868e1257ef6429f6f6f1f9d3c28ca330f) --- source4/libcli/resolve/resolve.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 733eddf643..d62890434b 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -144,6 +144,15 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ c->event_ctx = talloc_reference(c, event_ctx); } + if (is_ipaddress(state->name.name) || + strcasecmp(state->name.name, "localhost") == 0) { + 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); + return c; + } + state->req = setup_next_method(c); if (state->req == NULL) goto failed; -- cgit From e0febb258a29ac5deb034075219114337f468001 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 21 Sep 2005 16:35:15 +0000 Subject: r10395: While playing with winbind, I found a segfault because I had given resolve_name_send a stack-allocated method list. Duplicate it. Volker (This used to be commit 17dbbf965bcf038be7450781e28acb5e061eb295) --- source4/libcli/resolve/resolve.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index d62890434b..c21b29b57f 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -133,7 +133,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ if (!NT_STATUS_IS_OK(status)) goto failed; if (methods == NULL) goto failed; - state->methods = methods; + state->methods = str_list_copy(state, methods); + if (state->methods == NULL) goto failed; c->state = SMBCLI_REQUEST_SEND; c->private = state; -- 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') 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 ++++++++-------- source4/libcli/resolve/nbtlist.c | 20 ++++++++--------- source4/libcli/resolve/resolve.c | 46 ++++++++++++++++++++-------------------- 3 files changed, 42 insertions(+), 42 deletions(-) (limited to 'source4/libcli/resolve') 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); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 7080c62e43..4fb4ccbb20 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -44,8 +44,8 @@ struct nbtlist_state { static void nbtlist_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private, - struct composite_context); - struct nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); + struct composite_context); + struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state); int i; for (i=0;inum_queries;i++) { @@ -54,20 +54,20 @@ static void nbtlist_handler(struct nbt_name_request *req) if (i == state->num_queries) { /* not for us?! */ c->status = NT_STATUS_INTERNAL_ERROR; - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; goto done; - } + } c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } else { if (state->io_queries[i].out.num_addrs < 1) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; } else { struct nbt_name_query *q = &state->io_queries[i]; - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; /* favor a local address if possible */ state->reply_addr = NULL; for (i=0;iout.num_addrs;i++) { @@ -150,8 +150,8 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, state->queries[i]->async.private = c; } - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; c->event_ctx = talloc_reference(c, state->nbtsock->event_ctx); return c; @@ -172,7 +172,7 @@ NTSTATUS resolve_name_nbtlist_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); + struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state); *reply_addr = talloc_steal(mem_ctx, state->reply_addr); } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index c21b29b57f..c9e2fa503b 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -28,7 +28,7 @@ struct resolve_state { struct nbt_name name; const char **methods; - struct composite_context *req; + struct composite_context *creq; const char *reply_addr; }; @@ -65,26 +65,26 @@ static const struct resolve_method *find_method(const char *name) /* handle completion of one name resolve method */ -static void resolve_handler(struct composite_context *req) +static void resolve_handler(struct composite_context *creq) { - struct composite_context *c = req->async.private; - struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + struct composite_context *c = creq->async.private_data; + struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); const struct resolve_method *method = find_method(state->methods[0]); - c->status = method->recv_fn(req, state, &state->reply_addr); + c->status = method->recv_fn(creq, state, &state->reply_addr); if (!NT_STATUS_IS_OK(c->status)) { state->methods++; - state->req = setup_next_method(c); - if (state->req != NULL) { + state->creq = setup_next_method(c); + if (state->creq != NULL) { return; } } if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } else { - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; } if (c->async.fn) { c->async.fn(c); @@ -94,23 +94,23 @@ static void resolve_handler(struct composite_context *req) static struct composite_context *setup_next_method(struct composite_context *c) { - struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); - struct composite_context *req = NULL; + struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); + struct composite_context *creq = NULL; do { const struct resolve_method *method = find_method(state->methods[0]); if (method) { - req = method->send_fn(&state->name, c->event_ctx); + creq = method->send_fn(&state->name, c->event_ctx); } - if (req == NULL && state->methods[0]) state->methods++; - } while (!req && state->methods[0]); + if (creq == NULL && state->methods[0]) state->methods++; + } while (!creq && state->methods[0]); - if (req) { - req->async.fn = resolve_handler; - req->async.private = c; + if (creq) { + creq->async.fn = resolve_handler; + creq->async.private_data = c; } - return req; + return creq; } /* @@ -136,8 +136,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ state->methods = str_list_copy(state, methods); if (state->methods == NULL) goto failed; - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; if (event_ctx == NULL) { c->event_ctx = event_context_init(c); if (c->event_ctx == NULL) goto failed; @@ -154,8 +154,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ return c; } - state->req = setup_next_method(c); - if (state->req == NULL) goto failed; + state->creq = setup_next_method(c); + if (state->creq == NULL) goto failed; return c; @@ -175,7 +175,7 @@ NTSTATUS resolve_name_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); *reply_addr = talloc_steal(mem_ctx, state->reply_addr); } -- cgit From 9bc38ce65f1907230618b3edccafb1d33f753fe0 Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Thu, 29 Sep 2005 22:37:15 +0000 Subject: r10636: Formatting for better readability. rafal (This used to be commit ef29863d999089c47140bd37731c60659a200421) --- source4/libcli/resolve/nbtlist.c | 18 ++++++++++++------ source4/libcli/resolve/resolve.c | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 4fb4ccbb20..f8fe5df9a1 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -51,6 +51,7 @@ static void nbtlist_handler(struct nbt_name_request *req) for (i=0;inum_queries;i++) { if (req == state->queries[i]) break; } + if (i == state->num_queries) { /* not for us?! */ c->status = NT_STATUS_INTERNAL_ERROR; @@ -61,15 +62,18 @@ static void nbtlist_handler(struct nbt_name_request *req) c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); if (!NT_STATUS_IS_OK(c->status)) { c->state = COMPOSITE_STATE_ERROR; + } else { if (state->io_queries[i].out.num_addrs < 1) { c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; + } else { struct nbt_name_query *q = &state->io_queries[i]; c->state = COMPOSITE_STATE_DONE; /* favor a local address if possible */ state->reply_addr = NULL; + for (i=0;iout.num_addrs;i++) { if (iface_is_local(q->out.reply_addrs[i])) { state->reply_addr = talloc_steal(state, @@ -77,6 +81,7 @@ static void nbtlist_handler(struct nbt_name_request *req) break; } } + if (state->reply_addr == NULL) { state->reply_addr = talloc_steal(state, q->out.reply_addrs[0]); @@ -135,18 +140,19 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, if (!state->queries) goto failed; for (i=0;inum_queries;i++) { - state->io_queries[i].in.name = state->name; - state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); + state->io_queries[i].in.name = state->name; + state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); if (!state->io_queries[i].in.dest_addr) goto failed; - state->io_queries[i].in.broadcast = broadcast; + + state->io_queries[i].in.broadcast = broadcast; state->io_queries[i].in.wins_lookup = wins_lookup; - state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 1); + state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 1); + state->io_queries[i].in.retries = 2; - state->io_queries[i].in.retries = 2; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); if (!state->queries[i]) goto failed; - state->queries[i]->async.fn = nbtlist_handler; + state->queries[i]->async.fn = nbtlist_handler; state->queries[i]->async.private = c; } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index c9e2fa503b..db5aefeaeb 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -103,6 +103,7 @@ static struct composite_context *setup_next_method(struct composite_context *c) creq = method->send_fn(&state->name, c->event_ctx); } if (creq == NULL && state->methods[0]) state->methods++; + } while (!creq && state->methods[0]); if (creq) { @@ -138,9 +139,11 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ c->state = COMPOSITE_STATE_IN_PROGRESS; c->private_data = state; + if (event_ctx == NULL) { c->event_ctx = event_context_init(c); if (c->event_ctx == NULL) goto failed; + } else { c->event_ctx = talloc_reference(c, event_ctx); } -- cgit From 111a920fdb92ccef32f89b2f992bdd3051e5ac54 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 8 Dec 2005 01:13:45 +0000 Subject: r12116: got rid of composite_trigger_done() and composite_trigger_error(), and instead make the normal composite_done() and composite_error() functions automatically trigger a delayed callback if the caller has had no opportunity to setup a async callback this removes one of the common mistakes in writing a composite function (This used to be commit f9413ce792ded682e05134b66d433eeec293e6f1) --- source4/libcli/resolve/resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index db5aefeaeb..bbed931eed 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; } -- 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 + source4/libcli/resolve/resolve.c | 1 + 2 files changed, 2 insertions(+) (limited to 'source4/libcli/resolve') 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; diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index bbed931eed..dcbccc0c70 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -24,6 +24,7 @@ #include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/nbt/libnbt.h" struct resolve_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/bcast.c | 3 --- source4/libcli/resolve/host.c | 2 -- source4/libcli/resolve/nbtlist.c | 2 -- source4/libcli/resolve/resolve.c | 2 -- source4/libcli/resolve/wins.c | 3 --- 5 files changed, 12 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index c47bba38c5..c95fe945b1 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -21,9 +21,6 @@ */ #include "includes.h" -#include "system/network.h" -#include "libcli/raw/libcliraw.h" -#include "libcli/composite/composite.h" /* broadcast name resolution method - async send 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; diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index f8fe5df9a1..3af40c1b24 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -25,8 +25,6 @@ */ #include "includes.h" -#include "libcli/raw/libcliraw.h" -#include "libcli/nbt/libnbt.h" #include "libcli/composite/composite.h" struct nbtlist_state { diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index dcbccc0c70..d3d197e567 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -22,9 +22,7 @@ #include "includes.h" #include "lib/events/events.h" -#include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -#include "libcli/nbt/libnbt.h" struct resolve_state { struct nbt_name name; diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index aa4ec0cea4..b2e0ddae6f 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -21,9 +21,6 @@ */ #include "includes.h" -#include "system/network.h" -#include "libcli/raw/libcliraw.h" -#include "libcli/composite/composite.h" /* wins name resolution method - async send -- cgit From 048704a7e54573086e7913519d2b72577a34b135 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Feb 2006 04:18:11 +0000 Subject: r13505: allow servers to bind to non-broadcast interfaces. Servers now specifically ask for iface_n_bcast() and have to check if it returns NULL, in which case it is a non-broadcast interface (This used to be commit d004e250b6710251ea089ac242775481f13b5c2b) --- source4/libcli/resolve/bcast.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index c95fe945b1..f8ea6b2b3b 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -31,19 +31,22 @@ struct composite_context *resolve_name_bcast_send(struct nbt_name *name, int num_interfaces = iface_count(); const char **address_list; struct composite_context *c; - int i; + int i, count=0; address_list = talloc_array(NULL, const char *, num_interfaces+1); if (address_list == NULL) return NULL; for (i=0;i Date: Tue, 7 Mar 2006 11:07:23 +0000 Subject: r13924: Split more prototypes out of include/proto.h + initial work on header file dependencies (This used to be commit 122835876748a3eaf5e8d31ad1abddab9acb8781) --- source4/libcli/resolve/bcast.c | 3 +++ source4/libcli/resolve/nbtlist.c | 2 ++ source4/libcli/resolve/resolve.c | 1 + source4/libcli/resolve/wins.c | 1 + 4 files changed, 7 insertions(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index f8ea6b2b3b..1b58918ea7 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -21,6 +21,9 @@ */ #include "includes.h" +#include "libcli/resolve/resolve.h" +#include "system/network.h" +#include "netif/netif.h" /* broadcast name resolution method - async send diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 3af40c1b24..e8473966b4 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -26,6 +26,8 @@ #include "includes.h" #include "libcli/composite/composite.h" +#include "system/network.h" +#include "netif/netif.h" struct nbtlist_state { struct nbt_name name; diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index d3d197e567..c3fdf4bc25 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -23,6 +23,7 @@ #include "includes.h" #include "lib/events/events.h" #include "libcli/composite/composite.h" +#include "libcli/resolve/resolve.h" struct resolve_state { struct nbt_name name; diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index b2e0ddae6f..f11033ae4f 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "libcli/resolve/resolve.h" /* wins name resolution method - async send -- 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 + source4/libcli/resolve/nbtlist.c | 1 + source4/libcli/resolve/resolve.c | 1 + 3 files changed, 3 insertions(+) (limited to 'source4/libcli/resolve') 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; diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index e8473966b4..7188faba7b 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -28,6 +28,7 @@ #include "libcli/composite/composite.h" #include "system/network.h" #include "netif/netif.h" +#include "librpc/gen_ndr/ndr_nbt.h" struct nbtlist_state { struct nbt_name name; diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index c3fdf4bc25..8bacab8cd7 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -24,6 +24,7 @@ #include "lib/events/events.h" #include "libcli/composite/composite.h" #include "libcli/resolve/resolve.h" +#include "librpc/gen_ndr/ndr_nbt.h" struct resolve_state { struct nbt_name name; -- cgit From 35349a58df5b69446607fbd742a05f57f3515319 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 18 Mar 2006 15:42:57 +0000 Subject: r14542: Remove librpc, libndr and libnbt from includes.h (This used to be commit 51b4270513752d2eafbe77f9de598de16ef84a1f) --- source4/libcli/resolve/nbtlist.c | 1 + source4/libcli/resolve/resolve.h | 29 +++++++++++++++++++++++++++++ source4/libcli/resolve/wins.c | 1 + 3 files changed, 31 insertions(+) create mode 100644 source4/libcli/resolve/resolve.h (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 7188faba7b..a8ca2ced8b 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -29,6 +29,7 @@ #include "system/network.h" #include "netif/netif.h" #include "librpc/gen_ndr/ndr_nbt.h" +#include "libcli/nbt/libnbt.h" struct nbtlist_state { struct nbt_name name; diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h new file mode 100644 index 0000000000..ad479bab4b --- /dev/null +++ b/source4/libcli/resolve/resolve.h @@ -0,0 +1,29 @@ +/* + Unix SMB/CIFS implementation. + + general name resolution interface + + 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. +*/ + +#ifndef __RESOLVE_H__ +#define __RESOLVE_H__ + +#include "libcli/nbt/libnbt.h" +#include "libcli/resolve/proto.h" + +#endif /* __RESOLVE_H__ */ diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index f11033ae4f..6478710682 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "libcli/nbt/libnbt.h" #include "libcli/resolve/resolve.h" /* -- 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') 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 a2eca9174c7803732658a1e6f7e8ed873c4fb6fd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 17 Aug 2006 13:37:04 +0000 Subject: r17586: merge lib/netif into lib/socket and use -lnsl -lsocket on the configure check for the interfaces. should fix the build on some old sun boxes metze (This used to be commit f20e251bfd9f1eb7ce5c00739631b1625a2aa467) --- source4/libcli/resolve/bcast.c | 2 +- source4/libcli/resolve/nbtlist.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 1b58918ea7..8824ad395e 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -23,7 +23,7 @@ #include "includes.h" #include "libcli/resolve/resolve.h" #include "system/network.h" -#include "netif/netif.h" +#include "lib/socket/netif.h" /* broadcast name resolution method - async send diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index a8ca2ced8b..9d7035c26d 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -27,7 +27,7 @@ #include "includes.h" #include "libcli/composite/composite.h" #include "system/network.h" -#include "netif/netif.h" +#include "lib/socket/netif.h" #include "librpc/gen_ndr/ndr_nbt.h" #include "libcli/nbt/libnbt.h" -- cgit From d5314b9f3f8b27ea0f9efdf3fad27fd349a1adf3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 8 Nov 2006 21:18:24 +0000 Subject: r19638: convert resolve.c to the new composite api metze (This used to be commit 617f9c70c1b61e0fd4338048bbd94e7a4722ad9d) --- source4/libcli/resolve/resolve.c | 42 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 8bacab8cd7..532cf19bb4 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -123,49 +123,45 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ { struct composite_context *c; struct resolve_state *state; - NTSTATUS status; - - c = talloc_zero(NULL, struct composite_context); - if (c == NULL) goto failed; - - state = talloc(c, struct resolve_state); - if (state == NULL) goto failed; - - status = nbt_name_dup(state, name, &state->name); - if (!NT_STATUS_IS_OK(status)) goto failed; - if (methods == NULL) goto failed; - state->methods = str_list_copy(state, methods); - if (state->methods == NULL) goto failed; + c = composite_create(event_ctx, event_ctx); + if (c == NULL) return NULL; - c->state = COMPOSITE_STATE_IN_PROGRESS; - c->private_data = state; + if (methods == NULL) { + composite_error(c, NT_STATUS_INVALID_PARAMETER); + return c; + } if (event_ctx == NULL) { c->event_ctx = event_context_init(c); - if (c->event_ctx == NULL) goto failed; - } else { c->event_ctx = talloc_reference(c, event_ctx); } + if (composite_nomem(c->event_ctx, c)) return c; + + state = talloc(c, struct resolve_state); + if (composite_nomem(state, c)) return c; + c->private_data = state; + + c->status = nbt_name_dup(state, name, &state->name); + if (!composite_is_ok(c)) return c; + + state->methods = str_list_copy(state, methods); + if (composite_nomem(state->methods, c)) return c; if (is_ipaddress(state->name.name) || strcasecmp(state->name.name, "localhost") == 0) { 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; + if (composite_nomem(state->reply_addr, c)) return c; composite_done(c); return c; } state->creq = setup_next_method(c); - if (state->creq == NULL) goto failed; + if (composite_nomem(state->creq, c)) return c; return c; - -failed: - talloc_free(c); - return NULL; } /* -- cgit From 3bc459f813f24a96e273be893023a92a3fc2c2d6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 8 Nov 2006 21:20:45 +0000 Subject: r19639: convert nbtlist.c to new composite api metze (This used to be commit 800999733eb2f35486a62fb8fa9d179c8ca312fa) --- source4/libcli/resolve/nbtlist.c | 99 ++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 55 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 9d7035c26d..df76ec66a5 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -48,6 +48,7 @@ static void nbtlist_handler(struct nbt_name_request *req) struct composite_context *c = talloc_get_type(req->async.private, struct composite_context); struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state); + struct nbt_name_query *q; int i; for (i=0;inum_queries;i++) { @@ -56,46 +57,39 @@ static void nbtlist_handler(struct nbt_name_request *req) if (i == state->num_queries) { /* not for us?! */ - c->status = NT_STATUS_INTERNAL_ERROR; - c->state = COMPOSITE_STATE_ERROR; - goto done; + composite_error(c, NT_STATUS_INTERNAL_ERROR); + return; } - c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); - if (!NT_STATUS_IS_OK(c->status)) { - c->state = COMPOSITE_STATE_ERROR; - - } else { - if (state->io_queries[i].out.num_addrs < 1) { - c->state = COMPOSITE_STATE_ERROR; - c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; - - } else { - struct nbt_name_query *q = &state->io_queries[i]; - c->state = COMPOSITE_STATE_DONE; - /* favor a local address if possible */ - state->reply_addr = NULL; - - for (i=0;iout.num_addrs;i++) { - if (iface_is_local(q->out.reply_addrs[i])) { - state->reply_addr = talloc_steal(state, - q->out.reply_addrs[i]); - break; - } - } - - if (state->reply_addr == NULL) { - state->reply_addr = talloc_steal(state, - q->out.reply_addrs[0]); - } + q = &state->io_queries[i]; + + c->status = nbt_name_query_recv(req, state, q); + + /* free the network resource directly */ + talloc_free(state->nbtsock); + if (!composite_is_ok(c)) return; + + if (state->io_queries[i].out.num_addrs < 1) { + composite_error(c, NT_STATUS_UNEXPECTED_NETWORK_ERROR); + return; + } + + /* favor a local address if possible */ + state->reply_addr = NULL; + for (i=0;iout.num_addrs;i++) { + if (iface_is_local(q->out.reply_addrs[i])) { + state->reply_addr = talloc_steal(state, + q->out.reply_addrs[i]); + break; } } -done: - talloc_free(state->nbtsock); - if (c->async.fn) { - c->async.fn(c); + if (state->reply_addr == NULL) { + state->reply_addr = talloc_steal(state, + q->out.reply_addrs[0]); } + + composite_done(c); } /* @@ -110,41 +104,44 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, struct composite_context *c; struct nbtlist_state *state; int i; - NTSTATUS status; - c = talloc_zero(NULL, struct composite_context); - if (c == NULL) goto failed; + c = composite_create(event_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 nbtlist_state); - if (state == NULL) goto failed; + if (composite_nomem(state, c)) return c; + c->private_data = state; - status = nbt_name_dup(state, name, &state->name); - if (!NT_STATUS_IS_OK(status)) goto failed; + c->status = nbt_name_dup(state, name, &state->name); + if (!composite_is_ok(c)) return c; state->name.name = strupper_talloc(state, state->name.name); - if (state->name.name == NULL) goto failed; + if (composite_nomem(state->name.name, c)) return c; if (state->name.scope) { state->name.scope = strupper_talloc(state, state->name.scope); - if (state->name.scope == NULL) goto failed; + if (composite_nomem(state->name.scope, c)) return c; } state->nbtsock = nbt_name_socket_init(state, event_ctx); - if (state->nbtsock == NULL) goto failed; + if (composite_nomem(state->nbtsock, c)) return c; /* count the address_list size */ for (i=0;address_list[i];i++) /* noop */ ; state->num_queries = i; state->io_queries = talloc_array(state, struct nbt_name_query, state->num_queries); - if (!state->io_queries) goto failed; + if (composite_nomem(state->io_queries, c)) return c; state->queries = talloc_array(state, struct nbt_name_request *, state->num_queries); - if (!state->queries) goto failed; + if (composite_nomem(state->queries, c)) return c; for (i=0;inum_queries;i++) { state->io_queries[i].in.name = state->name; state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); - if (!state->io_queries[i].in.dest_addr) goto failed; + if (composite_nomem(state->io_queries[i].in.dest_addr, c)) return c; state->io_queries[i].in.broadcast = broadcast; state->io_queries[i].in.wins_lookup = wins_lookup; @@ -152,21 +149,13 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, state->io_queries[i].in.retries = 2; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); - if (!state->queries[i]) goto failed; + if (composite_nomem(state->queries[i], c)) return c; state->queries[i]->async.fn = nbtlist_handler; state->queries[i]->async.private = c; } - c->state = COMPOSITE_STATE_IN_PROGRESS; - c->private_data = state; - c->event_ctx = talloc_reference(c, state->nbtsock->event_ctx); - return c; - -failed: - talloc_free(c); - return NULL; } /* -- 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') 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/bcast.c | 11 ++++++----- source4/libcli/resolve/host.c | 13 ++++++++----- source4/libcli/resolve/nbtlist.c | 15 ++++++++------- source4/libcli/resolve/resolve.c | 4 ++-- source4/libcli/resolve/wins.c | 11 ++++++----- 5 files changed, 30 insertions(+), 24 deletions(-) (limited to 'source4/libcli/resolve') 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;ievent_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); } -- cgit From e31d922592b3bb037daff487f0b68c719e7584d4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 28 Feb 2007 17:25:29 +0000 Subject: r21593: give a more useful error, when we can't resolve a long name via broadcast of wins metze (This used to be commit 49591d699653e48f2e9540359e5b4ae97786511c) --- source4/libcli/resolve/nbtlist.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 58433d0a70..e8ea22a0dc 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -126,6 +126,15 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, if (composite_nomem(state->name.scope, c)) return c; } + /* + * we can't push long names on the wire, + * so bail out here to give a useful error message + */ + if (strlen(state->name.name) > 15) { + composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND); + return c; + } + state->nbtsock = nbt_name_socket_init(state, event_ctx); if (composite_nomem(state->nbtsock, c)) return c; -- 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') 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/bcast.c | 5 ++--- source4/libcli/resolve/host.c | 5 ++--- source4/libcli/resolve/nbtlist.c | 5 ++--- source4/libcli/resolve/resolve.c | 5 ++--- source4/libcli/resolve/resolve.h | 5 ++--- source4/libcli/resolve/wins.c | 5 ++--- 6 files changed, 12 insertions(+), 18 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index ba07670ced..f356dafdaa 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.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 . */ #include "includes.h" 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 . */ /* diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index e8ea22a0dc..ad331c872d 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.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 . */ /* diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 5e37fec42b..4df4de020c 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.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 . */ #include "includes.h" diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h index ad479bab4b..72db3839a2 100644 --- a/source4/libcli/resolve/resolve.h +++ b/source4/libcli/resolve/resolve.h @@ -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 . */ #ifndef __RESOLVE_H__ diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 62a3b81d0a..7af12075a1 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.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 . */ #include "includes.h" -- cgit From cd962355abad90a2161765a7be7d26e63572cab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:08:14 +0000 Subject: r25000: Fix some more C++ compatibility warnings. (This used to be commit 08bb1ef643ab906f1645cf6f32763dc73b1884e4) --- source4/libcli/resolve/resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 4df4de020c..63598fdd00 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -67,7 +67,7 @@ static const struct resolve_method *find_method(const char *name) */ static void resolve_handler(struct composite_context *creq) { - struct composite_context *c = creq->async.private_data; + struct composite_context *c = (struct composite_context *)creq->async.private_data; struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); const struct resolve_method *method = find_method(state->methods[0]); -- cgit From 959915a8cbea0c598ef1f29ce666329a521ef2f6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:35:18 +0000 Subject: r25001: Fix more C++ and other warnings, fix some of the indentation with ts=4 lines that I accidently added earlier. (This used to be commit 0bcb21ed740fcec0f48ad36bbc2deee2948e8fc7) --- source4/libcli/resolve/resolve.c | 3 ++- source4/libcli/resolve/wins.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 63598fdd00..ee9b8df148 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -188,7 +188,8 @@ NTSTATUS resolve_name_recv(struct composite_context *c, NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, struct event_context *ev) { - struct composite_context *c = resolve_name_send(name, ev, lp_name_resolve_order()); + struct composite_context *c = resolve_name_send(name, ev, + lp_name_resolve_order()); return resolve_name_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 7af12075a1..f7bfdc3405 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -26,9 +26,10 @@ /* wins name resolution method - async send */ -struct composite_context *resolve_name_wins_send(TALLOC_CTX *mem_ctx, - struct event_context *event_ctx, - struct nbt_name *name) +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; -- cgit From ffeee68e4b72dd94fee57366bd8d38b8c284c3d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 12:42:09 +0000 Subject: r25026: Move param/param.h out of includes.h (This used to be commit abe8349f9b4387961ff3665d8c589d61cd2edf31) --- source4/libcli/resolve/nbtlist.c | 1 + source4/libcli/resolve/resolve.c | 1 + source4/libcli/resolve/wins.c | 1 + 3 files changed, 3 insertions(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index ad331c872d..faa2962d5a 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -29,6 +29,7 @@ #include "lib/socket/netif.h" #include "librpc/gen_ndr/ndr_nbt.h" #include "libcli/nbt/libnbt.h" +#include "param/param.h" struct nbtlist_state { struct nbt_name name; diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index ee9b8df148..9315c0f354 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -24,6 +24,7 @@ #include "libcli/composite/composite.h" #include "libcli/resolve/resolve.h" #include "librpc/gen_ndr/ndr_nbt.h" +#include "param/param.h" struct resolve_state { struct nbt_name name; diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index f7bfdc3405..8c88950f53 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/nbt/libnbt.h" #include "libcli/resolve/resolve.h" +#include "param/param.h" /* wins name resolution method - async send -- cgit From 98b57d5eb61094a9c88e2f7d90d3e21b7e74e9d8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 16:46:30 +0000 Subject: r25035: Fix some more warnings, use service pointer rather than service number in more places. (This used to be commit df9cebcb97e20564359097148665bd519f31bc6f) --- source4/libcli/resolve/nbtlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index faa2962d5a..be4d01b79a 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -155,7 +155,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, state->io_queries[i].in.broadcast = broadcast; state->io_queries[i].in.wins_lookup = wins_lookup; - state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 1); + state->io_queries[i].in.timeout = lp_parm_int(NULL, "nbt", "timeout", 1); state->io_queries[i].in.retries = 2; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); -- cgit From 37d53832a4623653f706e77985a79d84bd7c6694 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 28 Sep 2007 01:17:46 +0000 Subject: r25398: Parse loadparm context to all lp_*() functions. (This used to be commit 3fcc960839c6e5ca4de2c3c042f12f369ac5f238) --- source4/libcli/resolve/resolve.c | 2 +- source4/libcli/resolve/wins.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 9315c0f354..02e1fbdc04 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -190,7 +190,7 @@ NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **r struct event_context *ev) { struct composite_context *c = resolve_name_send(name, ev, - lp_name_resolve_order()); + lp_name_resolve_order(global_loadparm)); return resolve_name_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 8c88950f53..05a2d4da31 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -32,7 +32,7 @@ struct composite_context *resolve_name_wins_send( struct event_context *event_ctx, struct nbt_name *name) { - const char **address_list = lp_wins_server_list(); + const char **address_list = lp_wins_server_list(global_loadparm); if (address_list == NULL) return NULL; return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, False, True); } -- cgit From 60a1046c5c5783799bd64fe18e03534670f83d82 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 29 Sep 2007 18:00:19 +0000 Subject: r25430: Add the loadparm context to all parametric options. (This used to be commit fd697d77c9fe67a00939a1f04b35c451316fff58) --- source4/libcli/resolve/nbtlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index be4d01b79a..9720434cb9 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -155,7 +155,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, state->io_queries[i].in.broadcast = broadcast; state->io_queries[i].in.wins_lookup = wins_lookup; - state->io_queries[i].in.timeout = lp_parm_int(NULL, "nbt", "timeout", 1); + state->io_queries[i].in.timeout = lp_parm_int(global_loadparm, NULL, "nbt", "timeout", 1); state->io_queries[i].in.retries = 2; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); -- cgit From 2151cde58014ea2e822c13d2f8a369b45dc19ca8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 22:28:14 +0000 Subject: r25554: Convert last instances of BOOL, True and False to the standard types. (This used to be commit 566aa14139510788548a874e9213d91317f83ca9) --- source4/libcli/resolve/bcast.c | 2 +- source4/libcli/resolve/nbtlist.c | 6 +++--- source4/libcli/resolve/wins.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index f356dafdaa..3193d70789 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -51,7 +51,7 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, } address_list[count] = NULL; - c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, True, False); + c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, true, false); talloc_free(address_list); return c; diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 9720434cb9..baf3874aa4 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -99,8 +99,8 @@ 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) + bool broadcast, + bool wins_lookup) { struct composite_context *c; struct nbtlist_state *state; @@ -193,7 +193,7 @@ NTSTATUS resolve_name_nbtlist_recv(struct composite_context *c, NTSTATUS resolve_name_nbtlist(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **address_list, - BOOL broadcast, BOOL wins_lookup, + bool broadcast, bool wins_lookup, const char **reply_addr) { struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list, diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 05a2d4da31..2cbcd5f483 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -34,7 +34,7 @@ struct composite_context *resolve_name_wins_send( { const char **address_list = lp_wins_server_list(global_loadparm); if (address_list == NULL) return NULL; - return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, False, True); + return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, false, true); } /* -- 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 ++-- source4/libcli/resolve/resolve.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') 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); } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 02e1fbdc04..24113db9f0 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -25,6 +25,7 @@ #include "libcli/resolve/resolve.h" #include "librpc/gen_ndr/ndr_nbt.h" #include "param/param.h" +#include "system/network.h" struct resolve_state { struct nbt_name name; @@ -151,8 +152,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ if (is_ipaddress(state->name.name) || strcasecmp(state->name.name, "localhost") == 0) { - struct ipv4_addr ip = interpret_addr2(state->name.name); - state->reply_addr = talloc_strdup(state, sys_inet_ntoa(ip)); + struct in_addr ip = interpret_addr2(state->name.name); + state->reply_addr = talloc_strdup(state, inet_ntoa(ip)); if (composite_nomem(state->reply_addr, c)) return c; composite_done(c); return c; -- cgit From 0bccc883921cd95fdc8c732df9730e32d97c2cca Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Nov 2007 00:07:17 +0100 Subject: r25903: Move more files out of torture/ (This used to be commit f734df3144cdd9ff280ee1cac2c3a7f972716f5d) --- source4/libcli/resolve/testsuite.c | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 source4/libcli/resolve/testsuite.c (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/testsuite.c b/source4/libcli/resolve/testsuite.c new file mode 100644 index 0000000000..b87b59b81a --- /dev/null +++ b/source4/libcli/resolve/testsuite.c @@ -0,0 +1,90 @@ +/* + Unix SMB/CIFS implementation. + + local test for async resolve code + + Copyright (C) Andrew Tridgell 2004 + + 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 3 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, see . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "libcli/resolve/resolve.h" +#include "torture/torture.h" +#include "system/network.h" + +static bool test_async_resolve(struct torture_context *tctx) +{ + struct nbt_name n; + struct event_context *ev; + int timelimit = torture_setting_int(tctx, "timelimit", 2); + const char *host = torture_setting_string(tctx, "host", NULL); + int count = 0; + struct timeval tv = timeval_current(); + TALLOC_CTX *mem_ctx = tctx; + + ev = tctx->ev; + + ZERO_STRUCT(n); + n.name = host; + + 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(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"); + count++; + } + + torture_comment(tctx, "async rate of %.1f resolves/sec\n", + count/timeval_elapsed(&tv)); + return true; +} + +/* + test resolution using sync method +*/ +static bool test_sync_resolve(struct torture_context *tctx) +{ + int timelimit = torture_setting_int(tctx, "timelimit", 2); + struct timeval tv = timeval_current(); + int count = 0; + const char *host = torture_setting_string(tctx, "host", NULL); + + torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n", + host, timelimit); + while (timeval_elapsed(&tv) < timelimit) { + inet_ntoa(interpret_addr2(host)); + count++; + } + + torture_comment(tctx, "sync rate of %.1f resolves/sec\n", + 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"); + + torture_suite_add_simple_test(suite, "async", test_async_resolve); + torture_suite_add_simple_test(suite, "sync", test_sync_resolve); + + return suite; +} -- cgit From 1fbdd6ef1dfb8704de0524fc6f5c33e1418858cd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 18:47:35 +0100 Subject: r26264: pass name resolve order explicitly, use torture context for settings in dssync tests. (This used to be commit c7eae1c7842f9ff8b70cce9e5d6f3ebbbe78e83b) --- source4/libcli/resolve/resolve.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 24113db9f0..0f8839a3b7 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -187,11 +187,9 @@ NTSTATUS resolve_name_recv(struct composite_context *c, /* general name resolution - sync call */ -NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, - struct event_context *ev) +NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, struct event_context *ev, const char **name_resolve_order) { - struct composite_context *c = resolve_name_send(name, ev, - lp_name_resolve_order(global_loadparm)); + struct composite_context *c = resolve_name_send(name, ev, name_resolve_order); return resolve_name_recv(c, mem_ctx, reply_addr); } -- cgit From b84be078c197f9752b53d68c882f4d1b44979b8e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 16:26:56 +0100 Subject: r26309: Move specification of port higher up the all stack. (This used to be commit 7de55cde7c7fe0141c05c8a38248667ebf3a9033) --- source4/libcli/resolve/nbtlist.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index baf3874aa4..13010eec3e 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -151,6 +151,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, for (i=0;inum_queries;i++) { state->io_queries[i].in.name = state->name; state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); + state->io_queries[i].in.dest_port = lp_nbt_port(global_loadparm); if (composite_nomem(state->io_queries[i].in.dest_addr, c)) return c; state->io_queries[i].in.broadcast = broadcast; -- cgit From c5bf20c5fe7eaa04cd11a7ce4f365aa6ffd7b124 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 23:57:22 +0100 Subject: r26325: Remove use of global_loadparm in netif. (This used to be commit e452cb28594f23add7c00247ed39e8323aea78a6) --- source4/libcli/resolve/bcast.c | 7 ++++--- source4/libcli/resolve/nbtlist.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 3193d70789..ad574e4c9e 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -23,15 +23,16 @@ #include "libcli/resolve/resolve.h" #include "system/network.h" #include "lib/socket/netif.h" +#include "param/param.h" -/* +/** broadcast name resolution method - async send */ 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(); + int num_interfaces = iface_count(global_loadparm); const char **address_list; struct composite_context *c; int i, count=0; @@ -40,7 +41,7 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, if (address_list == NULL) return NULL; for (i=0;ireply_addr = NULL; for (i=0;iout.num_addrs;i++) { - if (iface_is_local(q->out.reply_addrs[i])) { + if (iface_is_local(global_loadparm, q->out.reply_addrs[i])) { state->reply_addr = talloc_steal(state, q->out.reply_addrs[i]); break; -- 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/bcast.c | 8 ++- source4/libcli/resolve/host.c | 9 ++- source4/libcli/resolve/resolve.c | 110 ++++++++++++++++++++++++------------- source4/libcli/resolve/resolve.h | 2 + source4/libcli/resolve/testsuite.c | 2 +- source4/libcli/resolve/wins.c | 26 +++++++-- 6 files changed, 112 insertions(+), 45 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index ad574e4c9e..5a2c49c5ad 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -30,6 +30,7 @@ */ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + void *userdata, struct nbt_name *name) { int num_interfaces = iface_count(global_loadparm); @@ -74,7 +75,12 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, name); + struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, NULL, name); return resolve_name_bcast_recv(c, mem_ctx, reply_addr); } +bool resolve_context_add_bcast_method(struct resolve_context *ctx) +{ + return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, + NULL); +} 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); +} diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 0f8839a3b7..f0d9c07874 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -4,6 +4,7 @@ general name resolution interface Copyright (C) Andrew Tridgell 2005 + Copyright (C) Jelmer Vernooij 2007 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 @@ -26,57 +27,67 @@ #include "librpc/gen_ndr/ndr_nbt.h" #include "param/param.h" #include "system/network.h" +#include "util/dlinklist.h" struct resolve_state { + struct resolve_context *ctx; + struct resolve_method *method; struct nbt_name name; - const char **methods; struct composite_context *creq; const char *reply_addr; }; 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)(TALLOC_CTX *mem_ctx, struct event_context *, struct nbt_name *); - NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); -} resolve_methods[] = { - { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, - { "wins", resolve_name_wins_send, resolve_name_wins_recv }, - { "host", resolve_name_host_send, resolve_name_host_recv } +struct resolve_context { + struct resolve_method { + resolve_name_send_fn send_fn; + resolve_name_recv_fn recv_fn; + void *privdata; + struct resolve_method *prev, *next; + } *methods; }; +/** + * Initialize a resolve context + */ +struct resolve_context *resolve_context_init(TALLOC_CTX *mem_ctx) +{ + return talloc_zero(mem_ctx, struct resolve_context); +} -/* - find a matching backend -*/ -static const struct resolve_method *find_method(const char *name) +/** + * Add a resolve method + */ +bool resolve_context_add_method(struct resolve_context *ctx, resolve_name_send_fn send_fn, + resolve_name_recv_fn recv_fn, void *userdata) { - int i; - if (name == NULL) return NULL; - for (i=0;isend_fn = send_fn; + method->recv_fn = recv_fn; + method->privdata = userdata; + DLIST_ADD_END(ctx->methods, method, struct resolve_method *); + return true; } -/* +/** handle completion of one name resolve method */ static void resolve_handler(struct composite_context *creq) { struct composite_context *c = (struct composite_context *)creq->async.private_data; struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); - const struct resolve_method *method = find_method(state->methods[0]); + const struct resolve_method *method = state->method; c->status = method->recv_fn(creq, state, &state->reply_addr); if (!NT_STATUS_IS_OK(c->status)) { - state->methods++; + state->method = state->method->next; state->creq = setup_next_method(c); if (state->creq != NULL) { return; @@ -100,13 +111,12 @@ static struct composite_context *setup_next_method(struct composite_context *c) struct composite_context *creq = NULL; do { - const struct resolve_method *method = find_method(state->methods[0]); - if (method) { - creq = method->send_fn(c, c->event_ctx, &state->name); + if (state->method) { + creq = state->method->send_fn(c, c->event_ctx, state->method->privdata, &state->name); } - if (creq == NULL && state->methods[0]) state->methods++; + if (creq == NULL && state->method) state->method = state->method->next; - } while (!creq && state->methods[0]); + } while (!creq && state->method); if (creq) { creq->async.fn = resolve_handler; @@ -119,8 +129,9 @@ static struct composite_context *setup_next_method(struct composite_context *c) /* general name resolution - async send */ -struct composite_context *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx, - const char **methods) +struct composite_context *resolve_name_send(struct resolve_context *ctx, + struct nbt_name *name, + struct event_context *event_ctx) { struct composite_context *c; struct resolve_state *state; @@ -128,7 +139,7 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ c = composite_create(event_ctx, event_ctx); if (c == NULL) return NULL; - if (methods == NULL) { + if (ctx == NULL) { composite_error(c, NT_STATUS_INVALID_PARAMETER); return c; } @@ -147,8 +158,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ c->status = nbt_name_dup(state, name, &state->name); if (!composite_is_ok(c)) return c; - state->methods = str_list_copy(state, methods); - if (composite_nomem(state->methods, c)) return c; + state->ctx = talloc_reference(state, ctx); + if (composite_nomem(state->ctx, c)) return c; if (is_ipaddress(state->name.name) || strcasecmp(state->name.name, "localhost") == 0) { @@ -159,6 +170,7 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ return c; } + state->method = ctx->methods; state->creq = setup_next_method(c); if (composite_nomem(state->creq, c)) return c; @@ -187,9 +199,9 @@ NTSTATUS resolve_name_recv(struct composite_context *c, /* general name resolution - sync call */ -NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, struct event_context *ev, const char **name_resolve_order) +NTSTATUS resolve_name(struct resolve_context *ctx, struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, struct event_context *ev) { - struct composite_context *c = resolve_name_send(name, ev, name_resolve_order); + struct composite_context *c = resolve_name_send(ctx, name, ev); return resolve_name_recv(c, mem_ctx, reply_addr); } @@ -215,3 +227,27 @@ void make_nbt_name_server(struct nbt_name *nbt, const char *name) { make_nbt_name(nbt, name, NBT_NAME_SERVER); } + +struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) +{ + const char **methods = lp_name_resolve_order(lp_ctx); + int i; + struct resolve_context *ret = resolve_context_init(lp_ctx); + + if (ret == NULL) + return NULL; + + for (i = 0; methods != NULL && methods[i] != NULL; i++) { + if (!strcmp(methods[i], "wins")) { + resolve_context_add_wins_method(ret, lp_wins_server_list(lp_ctx)); + } else if (!strcmp(methods[i], "bcast")) { + resolve_context_add_bcast_method(ret); + } else if (!strcmp(methods[i], "host")) { + resolve_context_add_host_method(ret); + } else { + DEBUG(0, ("Unknown resolve method '%s'", methods[i])); + } + } + + return ret; +} diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h index 72db3839a2..73cb78c124 100644 --- a/source4/libcli/resolve/resolve.h +++ b/source4/libcli/resolve/resolve.h @@ -23,6 +23,8 @@ #define __RESOLVE_H__ #include "libcli/nbt/libnbt.h" +typedef struct composite_context *(*resolve_name_send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, void *privdata, struct nbt_name *); +typedef NTSTATUS (*resolve_name_recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); #include "libcli/resolve/proto.h" #endif /* __RESOLVE_H__ */ diff --git a/source4/libcli/resolve/testsuite.c b/source4/libcli/resolve/testsuite.c index b87b59b81a..73a8c841bb 100644 --- a/source4/libcli/resolve/testsuite.c +++ b/source4/libcli/resolve/testsuite.c @@ -44,7 +44,7 @@ static bool test_async_resolve(struct torture_context *tctx) host, timelimit); while (timeval_elapsed(&tv) < timelimit) { const char *s; - struct composite_context *c = resolve_name_host_send(mem_ctx, ev, &n); + struct composite_context *c = resolve_name_host_send(mem_ctx, ev, NULL, &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"); diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 2cbcd5f483..73b9413eb4 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -24,17 +24,22 @@ #include "libcli/resolve/resolve.h" #include "param/param.h" -/* +struct resolve_wins_data { + const char **address_list; +}; + +/** wins name resolution method - async send */ struct composite_context *resolve_name_wins_send( TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + void *userdata, struct nbt_name *name) { - const char **address_list = lp_wins_server_list(global_loadparm); - if (address_list == NULL) return NULL; - return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, false, true); + struct resolve_wins_data *wins_data = talloc_get_type(userdata, struct resolve_wins_data); + if (wins_data->address_list == NULL) return NULL; + return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, wins_data->address_list, false, true); } /* @@ -51,9 +56,20 @@ NTSTATUS resolve_name_wins_recv(struct composite_context *c, */ NTSTATUS resolve_name_wins(struct nbt_name *name, TALLOC_CTX *mem_ctx, + const char **address_list, const char **reply_addr) { - struct composite_context *c = resolve_name_wins_send(mem_ctx, NULL, name); + struct composite_context *c; + struct resolve_wins_data *wins_data = talloc(mem_ctx, struct resolve_wins_data); + wins_data->address_list = address_list; + c = resolve_name_wins_send(mem_ctx, NULL, wins_data, name); return resolve_name_wins_recv(c, mem_ctx, reply_addr); } +bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list) +{ + struct resolve_wins_data *wins_data = talloc(ctx, struct resolve_wins_data); + wins_data->address_list = str_list_copy(wins_data, address_list); + return resolve_context_add_method(ctx, resolve_name_wins_send, resolve_name_wins_recv, + wins_data); +} -- cgit From eede6b87e1dac018035bb68a675f80d6b25c20e3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Dec 2007 18:41:33 +0100 Subject: r26378: Remove use of global_loadparm. (This used to be commit 81333de5353ce70512a3ed1d4960c09aa78954c6) --- source4/libcli/resolve/bcast.c | 9 +++++---- source4/libcli/resolve/resolve.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 5a2c49c5ad..1733ca9d2e 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -33,7 +33,8 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, void *userdata, struct nbt_name *name) { - int num_interfaces = iface_count(global_loadparm); + struct loadparm_context *lp_ctx = userdata; + int num_interfaces = iface_count(lp_ctx); const char **address_list; struct composite_context *c; int i, count=0; @@ -42,7 +43,7 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, if (address_list == NULL) return NULL; for (i=0;i Date: Tue, 11 Dec 2007 09:01:56 +0100 Subject: r26391: samba4 doesn't support 'lmhosts' as resolve module metze (This used to be commit cdb64b41018928122898257f65d2573109b473cc) --- source4/libcli/resolve/resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index ad2d58a64c..fe36aa59ea 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -245,7 +245,7 @@ struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) } else if (!strcmp(methods[i], "host")) { resolve_context_add_host_method(ret); } else { - DEBUG(0, ("Unknown resolve method '%s'", methods[i])); + DEBUG(0, ("Unknown resolve method '%s'\n", methods[i])); } } -- cgit From 1ea47faa979ad2e4aa4cf1f4252aa33aef98dbd8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 11 Dec 2007 13:38:54 +0100 Subject: r26397: Fix circular dependency in samba-socket. (This used to be commit 801c8c766cb6a104751be8829593e0e123508134) --- source4/libcli/resolve/resolve.c | 22 ------------------ source4/libcli/resolve/resolve.h | 1 + source4/libcli/resolve/resolve_lp.c | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 source4/libcli/resolve/resolve_lp.c (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index fe36aa59ea..33ace09443 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -228,26 +228,4 @@ void make_nbt_name_server(struct nbt_name *nbt, const char *name) make_nbt_name(nbt, name, NBT_NAME_SERVER); } -struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) -{ - const char **methods = lp_name_resolve_order(lp_ctx); - int i; - struct resolve_context *ret = resolve_context_init(lp_ctx); - - if (ret == NULL) - return NULL; - - for (i = 0; methods != NULL && methods[i] != NULL; i++) { - if (!strcmp(methods[i], "wins")) { - resolve_context_add_wins_method(ret, lp_wins_server_list(lp_ctx)); - } else if (!strcmp(methods[i], "bcast")) { - resolve_context_add_bcast_method(ret, lp_ctx); - } else if (!strcmp(methods[i], "host")) { - resolve_context_add_host_method(ret); - } else { - DEBUG(0, ("Unknown resolve method '%s'\n", methods[i])); - } - } - return ret; -} diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h index 73cb78c124..9282074aa4 100644 --- a/source4/libcli/resolve/resolve.h +++ b/source4/libcli/resolve/resolve.h @@ -26,5 +26,6 @@ typedef struct composite_context *(*resolve_name_send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, void *privdata, struct nbt_name *); typedef NTSTATUS (*resolve_name_recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); #include "libcli/resolve/proto.h" +#include "libcli/resolve/lp_proto.h" #endif /* __RESOLVE_H__ */ diff --git a/source4/libcli/resolve/resolve_lp.c b/source4/libcli/resolve/resolve_lp.c new file mode 100644 index 0000000000..5a506dca8b --- /dev/null +++ b/source4/libcli/resolve/resolve_lp.c @@ -0,0 +1,46 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2007 + + 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 3 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, see . +*/ + +#include "includes.h" +#include "libcli/resolve/resolve.h" +#include "param/param.h" + +struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) +{ + const char **methods = lp_name_resolve_order(lp_ctx); + int i; + struct resolve_context *ret = resolve_context_init(lp_ctx); + + if (ret == NULL) + return NULL; + + for (i = 0; methods != NULL && methods[i] != NULL; i++) { + if (!strcmp(methods[i], "wins")) { + resolve_context_add_wins_method(ret, lp_wins_server_list(lp_ctx)); + } else if (!strcmp(methods[i], "bcast")) { + resolve_context_add_bcast_method(ret, lp_ctx); + } else if (!strcmp(methods[i], "host")) { + resolve_context_add_host_method(ret); + } else { + DEBUG(0, ("Unknown resolve method '%s'\n", methods[i])); + } + } + + return ret; +} -- cgit From 6f2252dace1629d7b5c5637b103caa28d2c89b07 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 11 Dec 2007 22:23:14 +0100 Subject: r26401: Don't cache interfaces context in libnetif. (This used to be commit 9f975417cc66bfd4589da38bfd23731dbe0e6153) --- source4/libcli/resolve/bcast.c | 15 ++++++++++----- source4/libcli/resolve/nbtlist.c | 4 +++- source4/libcli/resolve/resolve.h | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 1733ca9d2e..d1f3d65faf 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -33,17 +33,19 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, void *userdata, struct nbt_name *name) { - struct loadparm_context *lp_ctx = userdata; - int num_interfaces = iface_count(lp_ctx); + int num_interfaces; const char **address_list; struct composite_context *c; int i, count=0; + struct interface *ifaces = userdata; + + num_interfaces = iface_count(ifaces); address_list = talloc_array(mem_ctx, const char *, num_interfaces+1); if (address_list == NULL) return NULL; for (i=0;iprivate_data, struct nbtlist_state); struct nbt_name_query *q; + struct interface *ifaces; int i; for (i=0;inum_queries;i++) { @@ -75,9 +76,10 @@ static void nbtlist_handler(struct nbt_name_request *req) } /* favor a local address if possible */ + load_interfaces(lp_interfaces(global_loadparm), &ifaces); state->reply_addr = NULL; for (i=0;iout.num_addrs;i++) { - if (iface_is_local(global_loadparm, q->out.reply_addrs[i])) { + if (iface_is_local(ifaces, q->out.reply_addrs[i])) { state->reply_addr = talloc_steal(state, q->out.reply_addrs[i]); break; diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h index 9282074aa4..79b91dc836 100644 --- a/source4/libcli/resolve/resolve.h +++ b/source4/libcli/resolve/resolve.h @@ -26,6 +26,7 @@ typedef struct composite_context *(*resolve_name_send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, void *privdata, struct nbt_name *); typedef NTSTATUS (*resolve_name_recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); #include "libcli/resolve/proto.h" +struct interface; #include "libcli/resolve/lp_proto.h" #endif /* __RESOLVE_H__ */ -- cgit From 70f1f33af8e6e82506d0ee9ff6cc7e0923a7d0a1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 11 Dec 2007 22:23:20 +0100 Subject: r26402: Require a talloc context in libnetif. (This used to be commit a35e51871bbf1ab33fc316fa59e597b722769c50) --- source4/libcli/resolve/bcast.c | 2 +- source4/libcli/resolve/nbtlist.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index d1f3d65faf..1dd9328760 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -86,7 +86,7 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name, bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct loadparm_context *lp_ctx) { struct interface *ifaces; - load_interfaces(lp_interfaces(lp_ctx), &ifaces); + load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, ifaces); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 6c12fe706b..595743e693 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -76,7 +76,7 @@ static void nbtlist_handler(struct nbt_name_request *req) } /* favor a local address if possible */ - load_interfaces(lp_interfaces(global_loadparm), &ifaces); + load_interfaces(NULL, lp_interfaces(global_loadparm), &ifaces); state->reply_addr = NULL; for (i=0;iout.num_addrs;i++) { if (iface_is_local(ifaces, q->out.reply_addrs[i])) { @@ -85,6 +85,7 @@ static void nbtlist_handler(struct nbt_name_request *req) break; } } + talloc_free(ifaces); if (state->reply_addr == NULL) { state->reply_addr = talloc_steal(state, -- cgit From aa32619c5c910b9f5989f44de21621db5ef7c357 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 11:41:47 +0100 Subject: r26426: Remove uses of global_loadparm. (This used to be commit e1d177c8c1101965479f7ade2270490cd6fae4f2) --- source4/libcli/resolve/nbtlist.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 595743e693..21792a665a 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -38,6 +38,7 @@ struct nbtlist_state { struct nbt_name_request **queries; struct nbt_name_query *io_queries; const char *reply_addr; + struct interface *ifaces; }; /* @@ -49,7 +50,6 @@ static void nbtlist_handler(struct nbt_name_request *req) struct composite_context); struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state); struct nbt_name_query *q; - struct interface *ifaces; int i; for (i=0;inum_queries;i++) { @@ -76,16 +76,14 @@ static void nbtlist_handler(struct nbt_name_request *req) } /* favor a local address if possible */ - load_interfaces(NULL, lp_interfaces(global_loadparm), &ifaces); state->reply_addr = NULL; for (i=0;iout.num_addrs;i++) { - if (iface_is_local(ifaces, q->out.reply_addrs[i])) { + if (iface_is_local(state->ifaces, q->out.reply_addrs[i])) { state->reply_addr = talloc_steal(state, q->out.reply_addrs[i]); break; } } - talloc_free(ifaces); if (state->reply_addr == NULL) { state->reply_addr = talloc_steal(state, @@ -129,6 +127,8 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, if (composite_nomem(state->name.scope, c)) return c; } + load_interfaces(state, lp_interfaces(global_loadparm), &state->ifaces); + /* * we can't push long names on the wire, * so bail out here to give a useful error message @@ -200,7 +200,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(mem_ctx, NULL, name, address_list, + 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); } -- cgit From e8f46760e0134c45cd2b6b27aef60622c4bf58fa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:44 +0100 Subject: r26437: remove another use of global_loadparm. (This used to be commit 703f17bc0986775bf3fe489eb5c876937dabaa9d) --- source4/libcli/resolve/bcast.c | 35 +++++++++++++++++++++++++++-------- source4/libcli/resolve/nbtlist.c | 9 +++++++-- source4/libcli/resolve/resolve_lp.c | 4 ++-- source4/libcli/resolve/wins.c | 20 ++++++++++++++++++-- 4 files changed, 54 insertions(+), 14 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 1dd9328760..c8d4ab2df3 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -4,6 +4,7 @@ broadcast name resolution module Copyright (C) Andrew Tridgell 2005 + Copyright (C) Jelmer Vernooij 2007 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 @@ -25,6 +26,11 @@ #include "lib/socket/netif.h" #include "param/param.h" +struct resolve_bcast_data { + struct interface *ifaces; + uint16_t nbt_port; +}; + /** broadcast name resolution method - async send */ @@ -37,15 +43,15 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, const char **address_list; struct composite_context *c; int i, count=0; - struct interface *ifaces = userdata; + struct resolve_bcast_data *data = talloc_get_type(userdata, struct resolve_bcast_data); - num_interfaces = iface_count(ifaces); + num_interfaces = iface_count(data->ifaces); address_list = talloc_array(mem_ctx, const char *, num_interfaces+1); if (address_list == NULL) return NULL; for (i=0;iifaces, i); if (bcast == NULL) continue; address_list[count] = talloc_strdup(address_list, bcast); if (address_list[count] == NULL) { @@ -56,7 +62,7 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, } address_list[count] = NULL; - c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, true, false); + c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, data->ifaces, data->nbt_port, true, false); talloc_free(address_list); return c; @@ -77,16 +83,29 @@ NTSTATUS resolve_name_bcast_recv(struct composite_context *c, NTSTATUS resolve_name_bcast(struct nbt_name *name, TALLOC_CTX *mem_ctx, struct interface *ifaces, + uint16_t nbt_port, const char **reply_addr) { - struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, ifaces, name); + struct resolve_bcast_data *data = talloc(mem_ctx, struct resolve_bcast_data); + struct composite_context *c; + data->ifaces = talloc_reference(data, ifaces); + data->nbt_port = nbt_port; + + c = resolve_name_bcast_send(mem_ctx, NULL, data, name); return resolve_name_bcast_recv(c, mem_ctx, reply_addr); } -bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct loadparm_context *lp_ctx) +bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interface *ifaces, uint16_t nbt_port) +{ + struct resolve_bcast_data *data = talloc(ctx, struct resolve_bcast_data); + data->ifaces = ifaces; + data->nbt_port = nbt_port; + return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, data); +} + +bool resolve_context_add_bcast_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) { struct interface *ifaces; load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); - return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, - ifaces); + return resolve_context_add_bcast_method(ctx, ifaces, lp_nbt_port(lp_ctx)); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 21792a665a..e1452c09d2 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -100,6 +100,8 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, struct nbt_name *name, const char **address_list, + struct interface *ifaces, + uint16_t nbt_port, bool broadcast, bool wins_lookup) { @@ -127,7 +129,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, if (composite_nomem(state->name.scope, c)) return c; } - load_interfaces(state, lp_interfaces(global_loadparm), &state->ifaces); + state->ifaces = talloc_reference(state, ifaces); /* * we can't push long names on the wire, @@ -154,7 +156,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, for (i=0;inum_queries;i++) { state->io_queries[i].in.name = state->name; state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); - state->io_queries[i].in.dest_port = lp_nbt_port(global_loadparm); + state->io_queries[i].in.dest_port = nbt_port; if (composite_nomem(state->io_queries[i].in.dest_addr, c)) return c; state->io_queries[i].in.broadcast = broadcast; @@ -197,11 +199,14 @@ NTSTATUS resolve_name_nbtlist_recv(struct composite_context *c, NTSTATUS resolve_name_nbtlist(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **address_list, + struct interface *ifaces, + uint16_t nbt_port, bool broadcast, bool wins_lookup, const char **reply_addr) { struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list, + ifaces, nbt_port, broadcast, wins_lookup); return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/resolve_lp.c b/source4/libcli/resolve/resolve_lp.c index 5a506dca8b..b41e2b98d8 100644 --- a/source4/libcli/resolve/resolve_lp.c +++ b/source4/libcli/resolve/resolve_lp.c @@ -32,9 +32,9 @@ struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) for (i = 0; methods != NULL && methods[i] != NULL; i++) { if (!strcmp(methods[i], "wins")) { - resolve_context_add_wins_method(ret, lp_wins_server_list(lp_ctx)); + resolve_context_add_wins_method_lp(ret, lp_ctx); } else if (!strcmp(methods[i], "bcast")) { - resolve_context_add_bcast_method(ret, lp_ctx); + resolve_context_add_bcast_method_lp(ret, lp_ctx); } else if (!strcmp(methods[i], "host")) { resolve_context_add_host_method(ret); } else { diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 73b9413eb4..78624ad81a 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -23,9 +23,12 @@ #include "libcli/nbt/libnbt.h" #include "libcli/resolve/resolve.h" #include "param/param.h" +#include "lib/socket/netif.h" struct resolve_wins_data { const char **address_list; + struct interface *ifaces; + uint16_t nbt_port; }; /** @@ -39,7 +42,7 @@ struct composite_context *resolve_name_wins_send( { struct resolve_wins_data *wins_data = talloc_get_type(userdata, struct resolve_wins_data); if (wins_data->address_list == NULL) return NULL; - return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, wins_data->address_list, false, true); + return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, wins_data->address_list, wins_data->ifaces, wins_data->nbt_port, false, true); } /* @@ -57,19 +60,32 @@ NTSTATUS resolve_name_wins_recv(struct composite_context *c, NTSTATUS resolve_name_wins(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **address_list, + struct interface *ifaces, + uint16_t nbt_port, const char **reply_addr) { struct composite_context *c; struct resolve_wins_data *wins_data = talloc(mem_ctx, struct resolve_wins_data); wins_data->address_list = address_list; + wins_data->ifaces = ifaces; + wins_data->nbt_port = nbt_port; c = resolve_name_wins_send(mem_ctx, NULL, wins_data, name); return resolve_name_wins_recv(c, mem_ctx, reply_addr); } -bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list) +bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list, struct interface *ifaces, uint16_t nbt_port) { struct resolve_wins_data *wins_data = talloc(ctx, struct resolve_wins_data); wins_data->address_list = str_list_copy(wins_data, address_list); + wins_data->ifaces = talloc_reference(wins_data, ifaces); + wins_data->nbt_port = nbt_port; return resolve_context_add_method(ctx, resolve_name_wins_send, resolve_name_wins_recv, wins_data); } + +bool resolve_context_add_wins_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) +{ + struct interface *ifaces; + load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); + return resolve_context_add_wins_method(ctx, lp_wins_server_list(lp_ctx), ifaces, lp_nbt_port(lp_ctx)); +} -- cgit From c38c2765d1059b33f044a42c6555f3d10d339911 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 17:17:37 +0100 Subject: Remove yet more uses of global_loadparm. (This used to be commit e01c1e87c0fe9709df7eb5b863f7ce85564174cd) --- source4/libcli/resolve/bcast.c | 10 +++++++--- source4/libcli/resolve/nbtlist.c | 5 ++++- source4/libcli/resolve/wins.c | 10 +++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index c8d4ab2df3..2e2eb05397 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -29,6 +29,7 @@ struct resolve_bcast_data { struct interface *ifaces; uint16_t nbt_port; + int nbt_timeout; }; /** @@ -62,7 +63,7 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, } address_list[count] = NULL; - c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, data->ifaces, data->nbt_port, true, false); + c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, data->ifaces, data->nbt_port, data->nbt_timeout, true, false); talloc_free(address_list); return c; @@ -84,22 +85,25 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name, TALLOC_CTX *mem_ctx, struct interface *ifaces, uint16_t nbt_port, + int nbt_timeout, const char **reply_addr) { struct resolve_bcast_data *data = talloc(mem_ctx, struct resolve_bcast_data); struct composite_context *c; data->ifaces = talloc_reference(data, ifaces); data->nbt_port = nbt_port; + data->nbt_timeout = nbt_timeout; c = resolve_name_bcast_send(mem_ctx, NULL, data, name); return resolve_name_bcast_recv(c, mem_ctx, reply_addr); } -bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interface *ifaces, uint16_t nbt_port) +bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interface *ifaces, uint16_t nbt_port, int nbt_timeout) { struct resolve_bcast_data *data = talloc(ctx, struct resolve_bcast_data); data->ifaces = ifaces; data->nbt_port = nbt_port; + data->nbt_timeout = nbt_timeout; return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, data); } @@ -107,5 +111,5 @@ bool resolve_context_add_bcast_method_lp(struct resolve_context *ctx, struct loa { struct interface *ifaces; load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); - return resolve_context_add_bcast_method(ctx, ifaces, lp_nbt_port(lp_ctx)); + return resolve_context_add_bcast_method(ctx, ifaces, lp_nbt_port(lp_ctx), lp_parm_int(lp_ctx, NULL, "nbt", "timeout", 1)); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index e1452c09d2..34578e953a 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -102,6 +102,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, const char **address_list, struct interface *ifaces, uint16_t nbt_port, + int nbt_timeout, bool broadcast, bool wins_lookup) { @@ -161,7 +162,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, state->io_queries[i].in.broadcast = broadcast; state->io_queries[i].in.wins_lookup = wins_lookup; - state->io_queries[i].in.timeout = lp_parm_int(global_loadparm, NULL, "nbt", "timeout", 1); + state->io_queries[i].in.timeout = nbt_timeout; state->io_queries[i].in.retries = 2; state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]); @@ -201,12 +202,14 @@ NTSTATUS resolve_name_nbtlist(struct nbt_name *name, const char **address_list, struct interface *ifaces, uint16_t nbt_port, + int nbt_timeout, bool broadcast, bool wins_lookup, const char **reply_addr) { struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list, ifaces, nbt_port, + nbt_timeout, broadcast, wins_lookup); return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 78624ad81a..3ec180f332 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -29,6 +29,7 @@ struct resolve_wins_data { const char **address_list; struct interface *ifaces; uint16_t nbt_port; + int nbt_timeout; }; /** @@ -42,7 +43,7 @@ struct composite_context *resolve_name_wins_send( { struct resolve_wins_data *wins_data = talloc_get_type(userdata, struct resolve_wins_data); if (wins_data->address_list == NULL) return NULL; - return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, wins_data->address_list, wins_data->ifaces, wins_data->nbt_port, false, true); + return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, wins_data->address_list, wins_data->ifaces, wins_data->nbt_port, wins_data->nbt_timeout, false, true); } /* @@ -62,6 +63,7 @@ NTSTATUS resolve_name_wins(struct nbt_name *name, const char **address_list, struct interface *ifaces, uint16_t nbt_port, + int nbt_timeout, const char **reply_addr) { struct composite_context *c; @@ -69,16 +71,18 @@ NTSTATUS resolve_name_wins(struct nbt_name *name, wins_data->address_list = address_list; wins_data->ifaces = ifaces; wins_data->nbt_port = nbt_port; + wins_data->nbt_timeout = nbt_timeout; c = resolve_name_wins_send(mem_ctx, NULL, wins_data, name); return resolve_name_wins_recv(c, mem_ctx, reply_addr); } -bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list, struct interface *ifaces, uint16_t nbt_port) +bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list, struct interface *ifaces, uint16_t nbt_port, int nbt_timeout) { struct resolve_wins_data *wins_data = talloc(ctx, struct resolve_wins_data); wins_data->address_list = str_list_copy(wins_data, address_list); wins_data->ifaces = talloc_reference(wins_data, ifaces); wins_data->nbt_port = nbt_port; + wins_data->nbt_timeout = nbt_timeout; return resolve_context_add_method(ctx, resolve_name_wins_send, resolve_name_wins_recv, wins_data); } @@ -87,5 +91,5 @@ bool resolve_context_add_wins_method_lp(struct resolve_context *ctx, struct load { struct interface *ifaces; load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); - return resolve_context_add_wins_method(ctx, lp_wins_server_list(lp_ctx), ifaces, lp_nbt_port(lp_ctx)); + return resolve_context_add_wins_method(ctx, lp_wins_server_list(lp_ctx), ifaces, lp_nbt_port(lp_ctx), lp_parm_int(lp_ctx, NULL, "nbt", "timeout", 1)); } -- cgit From 10169a203019445e6d325a5c1559de3c73782237 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 17:54:24 +0100 Subject: Remove more global_loadparm instance.s (This used to be commit a1280252ce924df69d911e597b7f65d8038abef9) --- source4/libcli/resolve/nbtlist.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 34578e953a..887bdd7ecf 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -141,7 +141,8 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, return c; } - state->nbtsock = nbt_name_socket_init(state, event_ctx); + state->nbtsock = nbt_name_socket_init(state, event_ctx, + lp_iconv_convenience(global_loadparm)); if (composite_nomem(state->nbtsock, c)) return c; /* count the address_list size */ -- 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 - source4/libcli/resolve/nbtlist.c | 3 +-- source4/libcli/resolve/resolve.c | 13 ++++--------- 3 files changed, 5 insertions(+), 12 deletions(-) (limited to 'source4/libcli/resolve') 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); diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 887bdd7ecf..8f085c5404 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -110,10 +110,9 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, struct nbtlist_state *state; int i; - 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); if (composite_nomem(c->event_ctx, c)) return c; state = talloc(c, struct nbtlist_state); diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 33ace09443..aaf9ff1f8d 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -136,19 +136,14 @@ struct composite_context *resolve_name_send(struct resolve_context *ctx, struct composite_context *c; struct resolve_state *state; - c = composite_create(event_ctx, event_ctx); - if (c == NULL) return NULL; - - if (ctx == NULL) { + if (ctx == NULL || event_ctx == NULL) { composite_error(c, NT_STATUS_INVALID_PARAMETER); return c; } - if (event_ctx == NULL) { - c->event_ctx = event_context_init(c); - } else { - c->event_ctx = talloc_reference(c, event_ctx); - } + c = composite_create(ctx, event_ctx); + if (c == NULL) return NULL; + if (composite_nomem(c->event_ctx, c)) return c; state = talloc(c, struct resolve_state); -- cgit From 8113bb07a8eaee2bce1290bff1f06856bc7c76e6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 14 May 2008 19:49:38 +0200 Subject: Fix an uninitialized variable introduced by 3045d391 Simo, please check! Volker (This used to be commit 0c09d28acf42400d26cc27675e37226060de26d3) --- source4/libcli/resolve/resolve.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index aaf9ff1f8d..d89b50e430 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -137,8 +137,7 @@ struct composite_context *resolve_name_send(struct resolve_context *ctx, struct resolve_state *state; if (ctx == NULL || event_ctx == NULL) { - composite_error(c, NT_STATUS_INVALID_PARAMETER); - return c; + return NULL; } c = composite_create(ctx, event_ctx); -- cgit