diff options
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/db_wrap.c | 8 | ||||
-rw-r--r-- | source4/lib/events/events.c | 14 | ||||
-rw-r--r-- | source4/lib/events/events.h | 2 | ||||
-rw-r--r-- | source4/lib/socket/connect.c | 33 |
4 files changed, 51 insertions, 6 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, |