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/resolve.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 source4/libcli/resolve/resolve.c (limited to 'source4/libcli/resolve/resolve.c') 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 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/resolve.c | 113 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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; } /* -- 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/resolve.c | 51 +++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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/resolve.c') 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/resolve.c') 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 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/resolve.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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); } -- 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/resolve.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/resolve.c') 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 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/resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve/resolve.c') 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 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/resolve.c') 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/resolve.c') 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/resolve.c') 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/resolve.c') 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/resolve.c') 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: 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/resolve.c') 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/resolve.c') 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/resolve.c') 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 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/resolve.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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/resolve.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/resolve/resolve.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/resolve.c') 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/resolve.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/resolve.c') 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/resolve.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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; -- cgit From 4ac2be99588b48b0652a524bf12fb1aa9c3f5fbb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij 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/resolve.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/resolve.c') 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; -- 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/resolve.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/resolve.c') 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 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/resolve.c') 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 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/resolve.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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++; -- 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/resolve.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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" -- 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/resolve.c') 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve/resolve.c') 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); } -- 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/resolve.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/resolve/resolve.c') 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; -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve/resolve.c') 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); } -- 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/resolve.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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 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/resolve.c') 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 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/resolve.c | 110 ++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 37 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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; +} -- 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/resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve/resolve.c') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index f0d9c07874..ad2d58a64c 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -241,7 +241,7 @@ struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) 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); + resolve_context_add_bcast_method(ret, lp_ctx); } else if (!strcmp(methods[i], "host")) { resolve_context_add_host_method(ret); } else { -- cgit From 6a56c111d7a08e5add115edcdc81653cc19d3a4c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher 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/resolve.c') 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 ---------------------- 1 file changed, 22 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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; -} -- 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/resolve.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'source4/libcli/resolve/resolve.c') 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/resolve.c') 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