mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
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)
This commit is contained in:
parent
e669d0c53d
commit
c98c6aa561
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user