r9702: r9680@blu: tridge | 2005-08-27 18:45:08 +1000
authorAndrew Tridgell <tridge@samba.org>
Sun, 28 Aug 2005 02:37:14 +0000 (02:37 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:34:51 +0000 (13:34 -0500)
 - 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

15 files changed:
source/lib/db_wrap.c
source/lib/events/events.c
source/lib/events/events.h
source/lib/socket/connect.c
source/libcli/raw/clisocket.c
source/libcli/resolve/resolve.c
source/scripting/ejs/smbcalls_nbt.c
source/scripting/ejs/smbcalls_rpc.c
source/torture/ldap/cldapbench.c
source/torture/nbt/dgram.c
source/torture/nbt/query.c
source/torture/nbt/register.c
source/torture/nbt/wins.c
source/torture/nbt/winsbench.c
source/torture/nbt/winsreplication.c

index 8698e9affdd5b1c7de3f519ac11b157c3721fe95..77af27ff36eada95f383d52da2dfd0389de0ab94 100644 (file)
@@ -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) {
index 83b013f366327e71f14ddc0fcb6a993c44bd7cb3..b6ba79430c633438692f088f2e953912dc5ed758 100644 (file)
@@ -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;
+}
index 794407204b131ac91dfcc5ef2fc5ae65eecaaee4..3570229715e856bfab79b8446ee544eef660a417 100644 (file)
@@ -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
index abe474720cbac4bf8a4797a1044a46a4fe5d086f..567c8f41d287127e6c856294634d571b419b572e 100644 (file)
 #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, 
index b325fa473e9b82ab87429f8647150bc8d1ef44ec..90fb98603e8b98e9b30130a20f3e97aafb16587e 100644 (file)
@@ -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;
        }
index 3607400155841201b1d78a887784972e8768ec6d..733eddf643f149b1aa4435ed515c4f896bcc0c8b 100644 (file)
@@ -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);
 }
 
index c5722202f7c58140f129c605b938aee570cad903..f72b4b46ac2dfb2f3887e323d29da1b977625ea9 100644 (file)
@@ -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));
index 6da8cb351c24554fe79fc39a1eb22ead2223f830..4163896e71a1b570870b7d4d62acec1537a60673 100644 (file)
@@ -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, 
index 0a021dacceed380c3162c86dd09834dc88c13633..806bf9b558cd8996e3de4d1546671e3f34cc62a4 100644 (file)
@@ -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));
index d5fa014ce1bb218b461c58cc842fd8e5234e587f..cbebb7564d01bad63f9f4f81b40318285b2bc2b7 100644 (file)
@@ -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));
index 3764596f3f16559192c89d745c2c59c9fdbeff33..f0522d52ae043d93a304cbd04b86efaef4f587ae 100644 (file)
@@ -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));
index bca9fbeef446caceacb73f23a41348efde772010..b35808c8440e0741b9118672df042f5385396e68 100644 (file)
@@ -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));
index b099f48476c4821bc6be868e9bea912bf77f24ad..852147786edcc2870071f26aa1722329dd2a79f0 100644 (file)
@@ -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));
index 76763d3bf0f6a79a056685c29a2a3460549112b6..1bfc6f196cf4d11bb13592cacaf53e49e9fdab57 100644 (file)
@@ -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));
index 4e91deb84a775509dbcf9d3e71a1ac0d2e69544e..add34d4fa0c819781159b0d222c217d898bec775 100644 (file)
@@ -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));