wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
broadcast name resolution module
|
||||
|
||||
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/resolve/resolve.h"
|
||||
#include "system/network.h"
|
||||
#include "lib/socket/netif.h"
|
||||
|
||||
/*
|
||||
broadcast name resolution method - async send
|
||||
*/
|
||||
struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx,
|
||||
struct nbt_name *name)
|
||||
{
|
||||
int num_interfaces = iface_count();
|
||||
const char **address_list;
|
||||
struct composite_context *c;
|
||||
int i, count=0;
|
||||
|
||||
address_list = talloc_array(mem_ctx, const char *, num_interfaces+1);
|
||||
if (address_list == NULL) return NULL;
|
||||
|
||||
for (i=0;i<num_interfaces;i++) {
|
||||
const char *bcast = iface_n_bcast(i);
|
||||
if (bcast == NULL) continue;
|
||||
address_list[count] = talloc_strdup(address_list, bcast);
|
||||
if (address_list[count] == NULL) {
|
||||
talloc_free(address_list);
|
||||
return NULL;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
address_list[count] = NULL;
|
||||
|
||||
c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, True, False);
|
||||
talloc_free(address_list);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
broadcast name resolution method - recv side
|
||||
*/
|
||||
NTSTATUS resolve_name_bcast_recv(struct composite_context *c,
|
||||
TALLOC_CTX *mem_ctx, const char **reply_addr)
|
||||
{
|
||||
return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
broadcast name resolution method - sync call
|
||||
*/
|
||||
NTSTATUS resolve_name_bcast(struct nbt_name *name,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
const char **reply_addr)
|
||||
{
|
||||
struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, name);
|
||||
return resolve_name_bcast_recv(c, mem_ctx, reply_addr);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
async gethostbyname() name resolution module
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
this module uses a fork() per gethostbyname() call. At first that
|
||||
might seem crazy, but it is actually very fast, and solves many of
|
||||
the tricky problems of keeping a child hanging around in a library
|
||||
(like what happens when the parent forks). We use a talloc
|
||||
destructor to ensure that the child is cleaned up when we have
|
||||
finished with this name resolution.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "system/network.h"
|
||||
#include "system/filesys.h"
|
||||
#include "libcli/composite/composite.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
|
||||
struct host_state {
|
||||
struct nbt_name name;
|
||||
const char *reply_addr;
|
||||
pid_t child;
|
||||
int child_fd;
|
||||
struct fd_event *fde;
|
||||
struct event_context *event_ctx;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
kill off a wayward child if needed. This allows us to stop an async
|
||||
name resolution without leaving a potentially blocking call running
|
||||
in a child
|
||||
*/
|
||||
static int host_destructor(struct host_state *state)
|
||||
{
|
||||
close(state->child_fd);
|
||||
if (state->child != (pid_t)-1) {
|
||||
kill(state->child, SIGTERM);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
the blocking child
|
||||
*/
|
||||
static void run_child(struct composite_context *c, int fd)
|
||||
{
|
||||
struct host_state *state = talloc_get_type(c->private_data, struct host_state);
|
||||
struct ipv4_addr ip;
|
||||
const char *address;
|
||||
|
||||
/* this is the blocking call we are going to lots of trouble
|
||||
to avoid in the parent */
|
||||
ip = interpret_addr2(state->name.name);
|
||||
|
||||
address = sys_inet_ntoa(ip);
|
||||
if (address != NULL) {
|
||||
write(fd, address, strlen(address)+1);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
handle a read event on the pipe
|
||||
*/
|
||||
static void pipe_handler(struct event_context *ev, struct fd_event *fde,
|
||||
uint16_t flags, void *private_data)
|
||||
{
|
||||
struct composite_context *c = talloc_get_type(private_data, struct composite_context);
|
||||
struct host_state *state = talloc_get_type(c->private_data, struct host_state);
|
||||
char address[128];
|
||||
int ret;
|
||||
|
||||
/* if we get any event from the child then we know that we
|
||||
won't need to kill it off */
|
||||
state->child = (pid_t)-1;
|
||||
|
||||
/* yes, we don't care about EAGAIN or other niceities
|
||||
here. They just can't happen with this parent/child
|
||||
relationship, and even if they did then giving an error is
|
||||
the right thing to do */
|
||||
ret = read(state->child_fd, address, sizeof(address)-1);
|
||||
if (ret <= 0) {
|
||||
composite_error(c, NT_STATUS_BAD_NETWORK_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
/* enusre the address looks good */
|
||||
address[ret] = 0;
|
||||
if (strcmp(address, "0.0.0.0") == 0 ||
|
||||
inet_addr(address) == INADDR_NONE) {
|
||||
composite_error(c, NT_STATUS_BAD_NETWORK_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
state->reply_addr = talloc_strdup(state, address);
|
||||
if (composite_nomem(state->reply_addr, c)) return;
|
||||
|
||||
composite_done(c);
|
||||
}
|
||||
|
||||
/*
|
||||
gethostbyname name resolution method - async send
|
||||
*/
|
||||
struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx,
|
||||
struct nbt_name *name)
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct host_state *state;
|
||||
int fd[2] = { -1, -1 };
|
||||
int ret;
|
||||
|
||||
c = composite_create(mem_ctx, event_ctx);
|
||||
if (c == NULL) return NULL;
|
||||
|
||||
c->event_ctx = talloc_reference(c, event_ctx);
|
||||
if (composite_nomem(c->event_ctx, c)) return c;
|
||||
|
||||
state = talloc(c, struct host_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;
|
||||
|
||||
/* setup a pipe to chat to our child */
|
||||
ret = pipe(fd);
|
||||
if (ret == -1) {
|
||||
composite_error(c, map_nt_error_from_unix(errno));
|
||||
return c;
|
||||
}
|
||||
|
||||
state->child_fd = fd[0];
|
||||
state->event_ctx = c->event_ctx;
|
||||
|
||||
/* we need to put the child in our event context so
|
||||
we know when the gethostbyname() has finished */
|
||||
state->fde = event_add_fd(c->event_ctx, c, state->child_fd, EVENT_FD_READ,
|
||||
pipe_handler, c);
|
||||
if (composite_nomem(state->fde, c)) {
|
||||
close(fd[0]);
|
||||
close(fd[1]);
|
||||
return c;
|
||||
}
|
||||
|
||||
/* signal handling in posix really sucks - doing this in a library
|
||||
affects the whole app, but what else to do?? */
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
|
||||
state->child = fork();
|
||||
if (state->child == (pid_t)-1) {
|
||||
composite_error(c, map_nt_error_from_unix(errno));
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
if (state->child == 0) {
|
||||
close(fd[0]);
|
||||
run_child(c, fd[1]);
|
||||
_exit(0);
|
||||
}
|
||||
close(fd[1]);
|
||||
|
||||
/* cleanup wayward children */
|
||||
talloc_set_destructor(state, host_destructor);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
gethostbyname name resolution method - recv side
|
||||
*/
|
||||
NTSTATUS resolve_name_host_recv(struct composite_context *c,
|
||||
TALLOC_CTX *mem_ctx, const char **reply_addr)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
status = composite_wait(c);
|
||||
|
||||
if (NT_STATUS_IS_OK(status)) {
|
||||
struct host_state *state = talloc_get_type(c->private_data, struct host_state);
|
||||
*reply_addr = talloc_steal(mem_ctx, state->reply_addr);
|
||||
}
|
||||
|
||||
talloc_free(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
gethostbyname name resolution method - sync call
|
||||
*/
|
||||
NTSTATUS resolve_name_host(struct nbt_name *name,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
const char **reply_addr)
|
||||
{
|
||||
struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, name);
|
||||
return resolve_name_host_recv(c, mem_ctx, reply_addr);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
nbt list of addresses name resolution module
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
TODO: we should lower the timeout, and add retries for each name
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "libcli/composite/composite.h"
|
||||
#include "system/network.h"
|
||||
#include "lib/socket/netif.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
#include "libcli/nbt/libnbt.h"
|
||||
|
||||
struct nbtlist_state {
|
||||
struct nbt_name name;
|
||||
struct nbt_name_socket *nbtsock;
|
||||
int num_queries;
|
||||
struct nbt_name_request **queries;
|
||||
struct nbt_name_query *io_queries;
|
||||
const char *reply_addr;
|
||||
};
|
||||
|
||||
/*
|
||||
handle events during nbtlist name resolution
|
||||
*/
|
||||
static void nbtlist_handler(struct nbt_name_request *req)
|
||||
{
|
||||
struct composite_context *c = talloc_get_type(req->async.private,
|
||||
struct composite_context);
|
||||
struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state);
|
||||
struct nbt_name_query *q;
|
||||
int i;
|
||||
|
||||
for (i=0;i<state->num_queries;i++) {
|
||||
if (req == state->queries[i]) break;
|
||||
}
|
||||
|
||||
if (i == state->num_queries) {
|
||||
/* not for us?! */
|
||||
composite_error(c, NT_STATUS_INTERNAL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
q = &state->io_queries[i];
|
||||
|
||||
c->status = nbt_name_query_recv(req, state, q);
|
||||
|
||||
/* free the network resource directly */
|
||||
talloc_free(state->nbtsock);
|
||||
if (!composite_is_ok(c)) return;
|
||||
|
||||
if (state->io_queries[i].out.num_addrs < 1) {
|
||||
composite_error(c, NT_STATUS_UNEXPECTED_NETWORK_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
/* favor a local address if possible */
|
||||
state->reply_addr = NULL;
|
||||
for (i=0;i<q->out.num_addrs;i++) {
|
||||
if (iface_is_local(q->out.reply_addrs[i])) {
|
||||
state->reply_addr = talloc_steal(state,
|
||||
q->out.reply_addrs[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (state->reply_addr == NULL) {
|
||||
state->reply_addr = talloc_steal(state,
|
||||
q->out.reply_addrs[0]);
|
||||
}
|
||||
|
||||
composite_done(c);
|
||||
}
|
||||
|
||||
/*
|
||||
nbtlist name resolution method - async send
|
||||
*/
|
||||
struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx,
|
||||
struct nbt_name *name,
|
||||
const char **address_list,
|
||||
BOOL broadcast,
|
||||
BOOL wins_lookup)
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct nbtlist_state *state;
|
||||
int i;
|
||||
|
||||
c = composite_create(event_ctx, event_ctx);
|
||||
if (c == NULL) return NULL;
|
||||
|
||||
c->event_ctx = talloc_reference(c, event_ctx);
|
||||
if (composite_nomem(c->event_ctx, c)) return c;
|
||||
|
||||
state = talloc(c, struct nbtlist_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->name.name = strupper_talloc(state, state->name.name);
|
||||
if (composite_nomem(state->name.name, c)) return c;
|
||||
if (state->name.scope) {
|
||||
state->name.scope = strupper_talloc(state, state->name.scope);
|
||||
if (composite_nomem(state->name.scope, c)) return c;
|
||||
}
|
||||
|
||||
state->nbtsock = nbt_name_socket_init(state, event_ctx);
|
||||
if (composite_nomem(state->nbtsock, c)) return c;
|
||||
|
||||
/* count the address_list size */
|
||||
for (i=0;address_list[i];i++) /* noop */ ;
|
||||
|
||||
state->num_queries = i;
|
||||
state->io_queries = talloc_array(state, struct nbt_name_query, state->num_queries);
|
||||
if (composite_nomem(state->io_queries, c)) return c;
|
||||
|
||||
state->queries = talloc_array(state, struct nbt_name_request *, state->num_queries);
|
||||
if (composite_nomem(state->queries, c)) return c;
|
||||
|
||||
for (i=0;i<state->num_queries;i++) {
|
||||
state->io_queries[i].in.name = state->name;
|
||||
state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]);
|
||||
if (composite_nomem(state->io_queries[i].in.dest_addr, c)) return c;
|
||||
|
||||
state->io_queries[i].in.broadcast = broadcast;
|
||||
state->io_queries[i].in.wins_lookup = wins_lookup;
|
||||
state->io_queries[i].in.timeout = lp_parm_int(-1, "nbt", "timeout", 1);
|
||||
state->io_queries[i].in.retries = 2;
|
||||
|
||||
state->queries[i] = nbt_name_query_send(state->nbtsock, &state->io_queries[i]);
|
||||
if (composite_nomem(state->queries[i], c)) return c;
|
||||
|
||||
state->queries[i]->async.fn = nbtlist_handler;
|
||||
state->queries[i]->async.private = c;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
nbt list of addresses name resolution method - recv side
|
||||
*/
|
||||
NTSTATUS resolve_name_nbtlist_recv(struct composite_context *c,
|
||||
TALLOC_CTX *mem_ctx, const char **reply_addr)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
status = composite_wait(c);
|
||||
|
||||
if (NT_STATUS_IS_OK(status)) {
|
||||
struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state);
|
||||
*reply_addr = talloc_steal(mem_ctx, state->reply_addr);
|
||||
}
|
||||
|
||||
talloc_free(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
nbt list of addresses name resolution method - sync call
|
||||
*/
|
||||
NTSTATUS resolve_name_nbtlist(struct nbt_name *name,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
const char **address_list,
|
||||
BOOL broadcast, BOOL wins_lookup,
|
||||
const char **reply_addr)
|
||||
{
|
||||
struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list,
|
||||
broadcast, wins_lookup);
|
||||
return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
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 "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;
|
||||
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 }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
find a matching backend
|
||||
*/
|
||||
static const struct resolve_method *find_method(const char *name)
|
||||
{
|
||||
int i;
|
||||
if (name == NULL) return NULL;
|
||||
for (i=0;i<ARRAY_SIZE(resolve_methods);i++) {
|
||||
if (strcasecmp(name, resolve_methods[i].name) == 0) {
|
||||
return &resolve_methods[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
handle completion of one name resolve method
|
||||
*/
|
||||
static void resolve_handler(struct composite_context *creq)
|
||||
{
|
||||
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(creq, state, &state->reply_addr);
|
||||
|
||||
if (!NT_STATUS_IS_OK(c->status)) {
|
||||
state->methods++;
|
||||
state->creq = setup_next_method(c);
|
||||
if (state->creq != NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NT_STATUS_IS_OK(c->status)) {
|
||||
c->state = COMPOSITE_STATE_ERROR;
|
||||
} else {
|
||||
c->state = COMPOSITE_STATE_DONE;
|
||||
}
|
||||
if (c->async.fn) {
|
||||
c->async.fn(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct composite_context *setup_next_method(struct composite_context *c)
|
||||
{
|
||||
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) {
|
||||
creq = method->send_fn(c, c->event_ctx, &state->name);
|
||||
}
|
||||
if (creq == NULL && state->methods[0]) state->methods++;
|
||||
|
||||
} while (!creq && state->methods[0]);
|
||||
|
||||
if (creq) {
|
||||
creq->async.fn = resolve_handler;
|
||||
creq->async.private_data = c;
|
||||
}
|
||||
|
||||
return creq;
|
||||
}
|
||||
|
||||
/*
|
||||
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 *c;
|
||||
struct resolve_state *state;
|
||||
|
||||
c = composite_create(event_ctx, event_ctx);
|
||||
if (c == NULL) return NULL;
|
||||
|
||||
if (methods == 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);
|
||||
}
|
||||
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 (composite_nomem(state->reply_addr, c)) return c;
|
||||
composite_done(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
state->creq = setup_next_method(c);
|
||||
if (composite_nomem(state->creq, c)) return c;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
general name resolution method - recv side
|
||||
*/
|
||||
NTSTATUS resolve_name_recv(struct composite_context *c,
|
||||
TALLOC_CTX *mem_ctx, const char **reply_addr)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
status = composite_wait(c);
|
||||
|
||||
if (NT_STATUS_IS_OK(status)) {
|
||||
struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state);
|
||||
*reply_addr = talloc_steal(mem_ctx, state->reply_addr);
|
||||
}
|
||||
|
||||
talloc_free(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
general name resolution - sync call
|
||||
*/
|
||||
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());
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __RESOLVE_H__
|
||||
#define __RESOLVE_H__
|
||||
|
||||
#include "libcli/nbt/libnbt.h"
|
||||
#include "libcli/resolve/proto.h"
|
||||
|
||||
#endif /* __RESOLVE_H__ */
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
wins name resolution module
|
||||
|
||||
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/nbt/libnbt.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
|
||||
/*
|
||||
wins name resolution method - async send
|
||||
*/
|
||||
struct composite_context *resolve_name_wins_send(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx,
|
||||
struct nbt_name *name)
|
||||
{
|
||||
const char **address_list = lp_wins_server_list();
|
||||
if (address_list == NULL) return NULL;
|
||||
return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, False, True);
|
||||
}
|
||||
|
||||
/*
|
||||
wins name resolution method - recv side
|
||||
*/
|
||||
NTSTATUS resolve_name_wins_recv(struct composite_context *c,
|
||||
TALLOC_CTX *mem_ctx, const char **reply_addr)
|
||||
{
|
||||
return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
wins name resolution method - sync call
|
||||
*/
|
||||
NTSTATUS resolve_name_wins(struct nbt_name *name,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
const char **reply_addr)
|
||||
{
|
||||
struct composite_context *c = resolve_name_wins_send(mem_ctx, NULL, name);
|
||||
return resolve_name_wins_recv(c, mem_ctx, reply_addr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user