summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-08-28 02:37:14 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:51 -0500
commitc98c6aa5611f26ab591c50fcded1fc55e81a0d07 (patch)
tree599e3e9efc13a33535b50d40d9035c57a853dc19 /source4
parente669d0c53d843e664fc5b3d8f3ebcb170ceb8f37 (diff)
downloadsamba-c98c6aa5611f26ab591c50fcded1fc55e81a0d07.tar.gz
samba-c98c6aa5611f26ab591c50fcded1fc55e81a0d07.tar.bz2
samba-c98c6aa5611f26ab591c50fcded1fc55e81a0d07.zip
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)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/db_wrap.c8
-rw-r--r--source4/lib/events/events.c14
-rw-r--r--source4/lib/events/events.h2
-rw-r--r--source4/lib/socket/connect.c33
-rw-r--r--source4/libcli/raw/clisocket.c2
-rw-r--r--source4/libcli/resolve/resolve.c5
-rw-r--r--source4/scripting/ejs/smbcalls_nbt.c3
-rw-r--r--source4/scripting/ejs/smbcalls_rpc.c5
-rw-r--r--source4/torture/ldap/cldapbench.c2
-rw-r--r--source4/torture/nbt/dgram.c2
-rw-r--r--source4/torture/nbt/query.c2
-rw-r--r--source4/torture/nbt/register.c2
-rw-r--r--source4/torture/nbt/wins.c2
-rw-r--r--source4/torture/nbt/winsbench.c2
-rw-r--r--source4/torture/nbt/winsreplication.c2
15 files changed, 67 insertions, 19 deletions
diff --git a/source4/lib/db_wrap.c b/source4/lib/db_wrap.c
index 8698e9affd..77af27ff36 100644
--- a/source4/lib/db_wrap.c
+++ b/source4/lib/db_wrap.c
@@ -29,6 +29,7 @@
#include "includes.h"
#include "dlinklist.h"
+#include "lib/events/events.h"
#include "lib/tdb/include/tdb.h"
#include "lib/ldb/include/ldb.h"
#include "db_wrap.h"
@@ -76,12 +77,7 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
/* we want to use the existing event context if possible. This
relies on the fact that in smbd, everything is a child of
the main event_context */
- ev = talloc_find_parent_bytype(mem_ctx, struct event_context);
- if (ev) {
- ldb_set_opaque(ldb, "EventContext", ev);
- } else {
- DEBUG(5,("WARNING: event_context not found\n"));
- }
+ ev = event_context_find(ldb);
ret = ldb_register_samba_handlers(ldb);
if (ret == -1) {
diff --git a/source4/lib/events/events.c b/source4/lib/events/events.c
index 83b013f366..b6ba79430c 100644
--- a/source4/lib/events/events.c
+++ b/source4/lib/events/events.c
@@ -153,3 +153,17 @@ int event_loop_wait(struct event_context *ev)
{
return ev->ops->loop_wait(ev);
}
+
+/*
+ find an event context that is a parent of the given memory context,
+ or create a new event context as a child of the given context if
+ none is found
+*/
+struct event_context *event_context_find(TALLOC_CTX *mem_ctx)
+{
+ struct event_context *ev = talloc_find_parent_bytype(mem_ctx, struct event_context);
+ if (ev == NULL) {
+ ev = event_context_init(mem_ctx);
+ }
+ return ev;
+}
diff --git a/source4/lib/events/events.h b/source4/lib/events/events.h
index 794407204b..3570229715 100644
--- a/source4/lib/events/events.h
+++ b/source4/lib/events/events.h
@@ -49,6 +49,8 @@ int event_loop_wait(struct event_context *ev);
uint16_t event_get_fd_flags(struct fd_event *fde);
void event_set_fd_flags(struct fd_event *fde, uint16_t flags);
+struct event_context *event_context_find(TALLOC_CTX *mem_ctx);
+
/* bits for file descriptor event flags */
#define EVENT_FD_READ 1
#define EVENT_FD_WRITE 2
diff --git a/source4/lib/socket/connect.c b/source4/lib/socket/connect.c
index abe474720c..567c8f41d2 100644
--- a/source4/lib/socket/connect.c
+++ b/source4/lib/socket/connect.c
@@ -24,6 +24,29 @@
#include "includes.h"
#include "lib/socket/socket.h"
#include "lib/events/events.h"
+#include "librpc/gen_ndr/nbt.h"
+
+
+/*
+ async name resolution handler for socket_connect_ev, returnes either
+ an IP address or 'localhost' (which is specially recognised)
+*/
+static NTSTATUS connect_resolve(TALLOC_CTX *mem_ctx, const char *address,
+ struct event_context *ev, const char **ret_address)
+{
+ struct nbt_name name;
+
+ if (is_ipaddress(address) || strcasecmp("localhost", address) == 0) {
+ *ret_address = address;
+ return NT_STATUS_OK;
+ }
+
+ name.name = address;
+ name.scope = NULL;
+ name.type = NBT_NAME_CLIENT;
+
+ return resolve_name(&name, mem_ctx, ret_address, ev);
+}
/*
@@ -52,6 +75,16 @@ NTSTATUS socket_connect_ev(struct socket_context *sock,
TALLOC_CTX *tmp_ctx = talloc_new(sock);
NTSTATUS status;
+ /*
+ we resolve separately to ensure that the name resolutions happens
+ asynchronously
+ */
+ status = connect_resolve(tmp_ctx, server_address, ev, &server_address);
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(tmp_ctx);
+ return status;
+ }
+
set_blocking(socket_get_fd(sock), False);
status = socket_connect(sock, my_address, my_port,
diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c
index b325fa473e..90fb98603e 100644
--- a/source4/libcli/raw/clisocket.c
+++ b/source4/libcli/raw/clisocket.c
@@ -326,7 +326,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in
nbt_name.type = name_type;
nbt_name.scope = NULL;
- status = resolve_name(&nbt_name, sock, &address);
+ status = resolve_name(&nbt_name, sock, &address, sock->event.ctx);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
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);
}
diff --git a/source4/scripting/ejs/smbcalls_nbt.c b/source4/scripting/ejs/smbcalls_nbt.c
index c5722202f7..f72b4b46ac 100644
--- a/source4/scripting/ejs/smbcalls_nbt.c
+++ b/source4/scripting/ejs/smbcalls_nbt.c
@@ -24,6 +24,7 @@
#include "scripting/ejs/smbcalls.h"
#include "lib/appweb/ejs/ejs.h"
#include "librpc/gen_ndr/ndr_nbt.h"
+#include "lib/events/events.h"
/*
look up a netbios name
@@ -69,7 +70,7 @@ static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv)
result = 0;
- nt_status = resolve_name(&name, tmp_ctx, &reply_addr);
+ nt_status = resolve_name(&name, tmp_ctx, &reply_addr, event_context_find(tmp_ctx));
if (NT_STATUS_IS_OK(nt_status)) {
mprSetPropertyValue(argv[0], "value", mprString(reply_addr));
diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c
index 6da8cb351c..4163896e71 100644
--- a/source4/scripting/ejs/smbcalls_rpc.c
+++ b/source4/scripting/ejs/smbcalls_rpc.c
@@ -28,6 +28,7 @@
#include "lib/messaging/irpc.h"
#include "scripting/ejs/ejsrpc.h"
#include "dlinklist.h"
+#include "lib/events/events.h"
/*
state of a irpc 'connection'
@@ -69,7 +70,7 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv)
p->server_name = argv[0];
- ev = talloc_find_parent_bytype(mprMemCtx(), struct event_context);
+ ev = event_context_find(p);
/* create a messaging context, looping as we have no way to
allocate temporary server ids automatically */
@@ -150,7 +151,7 @@ static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv)
cli_credentials_set_anonymous(creds);
}
- ev = talloc_find_parent_bytype(mprMemCtx(), struct event_context);
+ ev = event_context_find(mprMemCtx());
status = dcerpc_pipe_connect(this, &p, binding,
iface->uuid, iface->if_version,
diff --git a/source4/torture/ldap/cldapbench.c b/source4/torture/ldap/cldapbench.c
index 0a021dacce..806bf9b558 100644
--- a/source4/torture/ldap/cldapbench.c
+++ b/source4/torture/ldap/cldapbench.c
@@ -111,7 +111,7 @@ BOOL torture_bench_cldap(void)
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c
index d5fa014ce1..cbebb7564d 100644
--- a/source4/torture/nbt/dgram.c
+++ b/source4/torture/nbt/dgram.c
@@ -294,7 +294,7 @@ BOOL torture_nbt_dgram(void)
name.scope = NULL;
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
diff --git a/source4/torture/nbt/query.c b/source4/torture/nbt/query.c
index 3764596f3f..f0522d52ae 100644
--- a/source4/torture/nbt/query.c
+++ b/source4/torture/nbt/query.c
@@ -113,7 +113,7 @@ BOOL torture_bench_nbt(void)
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
diff --git a/source4/torture/nbt/register.c b/source4/torture/nbt/register.c
index bca9fbeef4..b35808c844 100644
--- a/source4/torture/nbt/register.c
+++ b/source4/torture/nbt/register.c
@@ -163,7 +163,7 @@ BOOL torture_nbt_register(void)
make_nbt_name_server(&name, strupper_talloc(mem_ctx, lp_parm_string(-1, "torture", "host")));
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, NULL);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c
index b099f48476..852147786e 100644
--- a/source4/torture/nbt/wins.c
+++ b/source4/torture/nbt/wins.c
@@ -348,7 +348,7 @@ BOOL torture_nbt_wins(void)
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, NULL);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
diff --git a/source4/torture/nbt/winsbench.c b/source4/torture/nbt/winsbench.c
index 76763d3bf0..1bfc6f196c 100644
--- a/source4/torture/nbt/winsbench.c
+++ b/source4/torture/nbt/winsbench.c
@@ -279,7 +279,7 @@ BOOL torture_bench_wins(void)
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
diff --git a/source4/torture/nbt/winsreplication.c b/source4/torture/nbt/winsreplication.c
index 4e91deb84a..add34d4fa0 100644
--- a/source4/torture/nbt/winsreplication.c
+++ b/source4/torture/nbt/winsreplication.c
@@ -127,7 +127,7 @@ BOOL torture_nbt_winsreplication(void)
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address);
+ status = resolve_name(&name, mem_ctx, &address, NULL);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));