/*
setup our listening sockets on the configured network interfaces
*/
-static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct loadparm_context *lp_ctx)
+static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct loadparm_context *lp_ctx,
+ struct interface *ifaces)
{
- int num_interfaces = iface_count(lp_ctx);
+ int num_interfaces;
TALLOC_CTX *tmp_ctx = talloc_new(cldapd);
NTSTATUS status;
+ num_interfaces = iface_count(ifaces);
+
/* if we are allowing incoming packets from any address, then
we need to bind to the wildcard address */
if (!lp_bind_interfaces_only(lp_ctx)) {
int i;
for (i=0; i<num_interfaces; i++) {
- const char *address = talloc_strdup(tmp_ctx, iface_n_ip(lp_ctx, i));
+ const char *address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i));
status = cldapd_add_socket(cldapd, lp_ctx, address);
NT_STATUS_NOT_OK_RETURN(status);
}
{
struct cldapd_server *cldapd;
NTSTATUS status;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
- if (iface_count(task->lp_ctx) == 0) {
+ if (iface_count(ifaces) == 0) {
task_server_terminate(task, "cldapd: no network interfaces configured");
return;
}
}
/* start listening on the configured network interfaces */
- status = cldapd_startup_interfaces(cldapd, task->lp_ctx);
+ status = cldapd_startup_interfaces(cldapd, task->lp_ctx, ifaces);
if (!NT_STATUS_IS_OK(status)) {
task_server_terminate(task, "cldapd failed to setup interfaces");
return;
const char *client_site;
const char *pdc_ip;
struct ldb_dn *partitions_basedn;
+ struct interface *ifaces;
partitions_basedn = samdb_partitions_dn(cldapd->samctx, mem_ctx);
lp_workgroup(lp_ctx));
server_site = "Default-First-Site-Name";
client_site = "Default-First-Site-Name";
- pdc_ip = iface_best_ip(lp_ctx, src_address);
+ load_interfaces(lp_interfaces(lp_ctx), &ifaces);
+ pdc_ip = iface_best_ip(ifaces, src_address);
ZERO_STRUCTP(netlogon);
krb5_error_code KRB5_LIB_FUNCTION krb5_get_all_client_addrs(krb5_context context, krb5_addresses *res)
{
int i;
- res->len = iface_count(global_loadparm);
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(global_loadparm), &ifaces);
+
+ res->len = iface_count(ifaces);
res->val = malloc_array_p(HostAddress, res->len);
if (res->val == NULL) {
return ENOMEM;
}
for (i=0;i<res->len;i++) {
- const char *ip = iface_n_ip(global_loadparm, i);
+ const char *ip = iface_n_ip(ifaces, i);
res->val[i].addr_type = AF_INET;
res->val[i].address.length = 4;
res->val[i].address.data = malloc(4);
/*
setup our listening sockets on the configured network interfaces
*/
-static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_context *lp_ctx)
+static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_context *lp_ctx,
+ struct interface *ifaces)
{
- int num_interfaces = iface_count(lp_ctx);
+ int num_interfaces;
TALLOC_CTX *tmp_ctx = talloc_new(kdc);
NTSTATUS status;
-
int i;
+
+ num_interfaces = iface_count(ifaces);
for (i=0; i<num_interfaces; i++) {
- const char *address = talloc_strdup(tmp_ctx, iface_n_ip(lp_ctx, i));
+ const char *address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i));
status = kdc_add_socket(kdc, address, lp_krb5_port(lp_ctx),
lp_kpasswd_port(lp_ctx));
NT_STATUS_NOT_OK_RETURN(status);
struct kdc_server *kdc;
NTSTATUS status;
krb5_error_code ret;
+ struct interface *ifaces;
switch (lp_server_role(task->lp_ctx)) {
case ROLE_STANDALONE:
break;
}
- if (iface_count(task->lp_ctx) == 0) {
+ load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
+
+ if (iface_count(ifaces) == 0) {
task_server_terminate(task, "kdc: no network interfaces configured");
return;
}
kdc_mem_ctx = kdc->smb_krb5_context;
/* start listening on the configured network interfaces */
- status = kdc_startup_interfaces(kdc, task->lp_ctx);
+ status = kdc_startup_interfaces(kdc, task->lp_ctx, ifaces);
if (!NT_STATUS_IS_OK(status)) {
task_server_terminate(task, "kdc failed to setup interfaces");
return;
if (ldap_service->tls_params == NULL) goto failed;
if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) {
- int num_interfaces = iface_count(task->lp_ctx);
+ struct interface *ifaces;
+ int num_interfaces;
int i;
+ load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
+ num_interfaces = iface_count(ifaces);
+
/* We have been given an interfaces line, and been
told to only bind to those interfaces. Create a
socket per interface and bind to only these.
*/
for(i = 0; i < num_interfaces; i++) {
- const char *address = iface_n_ip(task->lp_ctx, i);
+ const char *address = iface_n_ip(ifaces, i);
status = add_socket(task->event_ctx, task->lp_ctx, model_ops, address, ldap_service);
if (!NT_STATUS_IS_OK(status)) goto failed;
}
const char *nmask_s;
};
-static struct interface *local_interfaces;
-
#define ALLONES ((uint32_t)0xFFFFFFFF)
/*
address construction based on a patch from fred@datalync.com
**/
static void interpret_interface(const char *token,
struct iface_struct *probed_ifaces,
- int total_probed)
+ int total_probed,
+ struct interface **local_interfaces)
{
struct in_addr ip, nmask;
char *p;
if (gen_fnmatch(token, probed_ifaces[i].name) == 0) {
add_interface(probed_ifaces[i].ip,
probed_ifaces[i].netmask,
- &local_interfaces);
+ local_interfaces);
added = 1;
}
}
if (ip.s_addr == probed_ifaces[i].ip.s_addr) {
add_interface(probed_ifaces[i].ip,
probed_ifaces[i].netmask,
- &local_interfaces);
+ local_interfaces);
return;
}
}
for (i=0;i<total_probed;i++) {
if (same_net(ip, probed_ifaces[i].ip, nmask)) {
add_interface(probed_ifaces[i].ip, nmask,
- &local_interfaces);
+ local_interfaces);
return;
}
}
return;
}
- add_interface(ip, nmask, &local_interfaces);
+ add_interface(ip, nmask, local_interfaces);
}
/**
load the list of network interfaces
**/
-static void load_interfaces(const char **interfaces)
+void load_interfaces(const char **interfaces, struct interface **local_interfaces)
{
const char **ptr = interfaces;
int i;
struct in_addr loopback_ip;
int total_probed;
- if (local_interfaces != NULL) {
- return;
- }
+ *local_interfaces = NULL;
loopback_ip = interpret_addr2("127.0.0.1");
for (i=0;i<total_probed;i++) {
if (ifaces[i].ip.s_addr != loopback_ip.s_addr) {
add_interface(ifaces[i].ip,
- ifaces[i].netmask, &local_interfaces);
+ ifaces[i].netmask, local_interfaces);
}
}
}
while (ptr && *ptr) {
- interpret_interface(*ptr, ifaces, total_probed);
+ interpret_interface(*ptr, ifaces, total_probed, local_interfaces);
ptr++;
}
- if (!local_interfaces) {
+ if (!*local_interfaces) {
DEBUG(0,("WARNING: no network interfaces found\n"));
}
}
-
-/**
- unload the interfaces list, so it can be reloaded when needed
-*/
-void unload_interfaces(void)
-{
- talloc_free(local_interfaces);
- local_interfaces = NULL;
-}
-
/**
how many interfaces do we have
**/
-int iface_count(struct loadparm_context *lp_ctx)
+int iface_count(struct interface *ifaces)
{
int ret = 0;
struct interface *i;
- load_interfaces(lp_interfaces(lp_ctx));
-
- for (i=local_interfaces;i;i=i->next)
+ for (i=ifaces;i;i=i->next)
ret++;
return ret;
}
/**
return IP of the Nth interface
**/
-const char *iface_n_ip(struct loadparm_context *lp_ctx, int n)
+const char *iface_n_ip(struct interface *ifaces, int n)
{
struct interface *i;
- load_interfaces(lp_interfaces(lp_ctx));
-
- for (i=local_interfaces;i && n;i=i->next)
+ for (i=ifaces;i && n;i=i->next)
n--;
if (i) {
/**
return bcast of the Nth interface
**/
-const char *iface_n_bcast(struct loadparm_context *lp_ctx, int n)
+const char *iface_n_bcast(struct interface *ifaces, int n)
{
struct interface *i;
- load_interfaces(lp_interfaces(lp_ctx));
-
- for (i=local_interfaces;i && n;i=i->next)
+ for (i=ifaces;i && n;i=i->next)
n--;
if (i) {
/**
return netmask of the Nth interface
**/
-const char *iface_n_netmask(struct loadparm_context *lp_ctx, int n)
+const char *iface_n_netmask(struct interface *ifaces, int n)
{
struct interface *i;
- load_interfaces(lp_interfaces(lp_ctx));
-
- for (i=local_interfaces;i && n;i=i->next)
+ for (i=ifaces;i && n;i=i->next)
n--;
if (i) {
return the local IP address that best matches a destination IP, or
our first interface if none match
*/
-const char *iface_best_ip(struct loadparm_context *lp_ctx, const char *dest)
+const char *iface_best_ip(struct interface *ifaces, const char *dest)
{
struct interface *iface;
struct in_addr ip;
- load_interfaces(lp_interfaces(lp_ctx));
-
ip.s_addr = interpret_addr(dest);
- iface = iface_find(local_interfaces, ip, true);
+ iface = iface_find(ifaces, ip, true);
if (iface) {
return iface->ip_s;
}
- return iface_n_ip(lp_ctx, 0);
+ return iface_n_ip(ifaces, 0);
}
/**
return true if an IP is one one of our local networks
*/
-bool iface_is_local(struct loadparm_context *lp_ctx, const char *dest)
+bool iface_is_local(struct interface *ifaces, const char *dest)
{
struct in_addr ip;
- load_interfaces(lp_interfaces(lp_ctx));
-
ip.s_addr = interpret_addr(dest);
- if (iface_find(local_interfaces, ip, true)) {
+ if (iface_find(ifaces, ip, true)) {
return true;
}
return false;
struct in_addr netmask;
};
+struct interface;
+
#define MAX_INTERFACES 128
#ifndef AUTOCONF_TEST
DATA_BLOB blob, blob2;
size_t sent, nread;
TALLOC_CTX *mem_ctx = tctx;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
talloc_steal(mem_ctx, sock2);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
- iface_best_ip(tctx->lp_ctx, "127.0.0.1"), 0);
+ iface_best_ip(ifaces, "127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
srv_addr = socket_get_my_addr(sock1, mem_ctx);
torture_assert(tctx, srv_addr != NULL &&
- strcmp(srv_addr->addr, iface_best_ip(tctx->lp_ctx, "127.0.0.1")) == 0,
+ strcmp(srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1")) == 0,
talloc_asprintf(tctx,
"Expected server address of %s but got %s",
- iface_best_ip(tctx->lp_ctx, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
+ iface_best_ip(ifaces, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
torture_comment(tctx, "server port is %d\n", srv_addr->port);
size_t sent, nread;
TALLOC_CTX *mem_ctx = tctx;
struct event_context *ev = event_context_init(mem_ctx);
+ struct interface *ifaces;
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0);
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(mem_ctx, sock2);
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
- iface_best_ip(tctx->lp_ctx, "127.0.0.1"), 0);
+ iface_best_ip(ifaces, "127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
status = socket_listen(sock1, localhost, 0, 0);
torture_assert(tctx, srv_addr && srv_addr->addr,
"Unexpected socket_get_my_addr NULL\n");
- torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip(tctx->lp_ctx, "127.0.0.1"),
+ torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1"),
"Unexpected server address");
torture_comment(tctx, "server port is %d\n", srv_addr->port);
void *userdata,
struct nbt_name *name)
{
- struct loadparm_context *lp_ctx = userdata;
- int num_interfaces = iface_count(lp_ctx);
+ int num_interfaces;
const char **address_list;
struct composite_context *c;
int i, count=0;
+ struct interface *ifaces = userdata;
+
+ num_interfaces = iface_count(ifaces);
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(lp_ctx, i);
+ const char *bcast = iface_n_bcast(ifaces, i);
if (bcast == NULL) continue;
address_list[count] = talloc_strdup(address_list, bcast);
if (address_list[count] == NULL) {
*/
NTSTATUS resolve_name_bcast(struct nbt_name *name,
TALLOC_CTX *mem_ctx,
+ struct interface *ifaces,
const char **reply_addr)
{
- struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, NULL, name);
+ struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, ifaces, name);
return resolve_name_bcast_recv(c, mem_ctx, reply_addr);
}
bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct loadparm_context *lp_ctx)
{
+ struct interface *ifaces;
+ load_interfaces(lp_interfaces(lp_ctx), &ifaces);
return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv,
- lp_ctx);
+ ifaces);
}
struct composite_context);
struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state);
struct nbt_name_query *q;
+ struct interface *ifaces;
int i;
for (i=0;i<state->num_queries;i++) {
}
/* favor a local address if possible */
+ load_interfaces(lp_interfaces(global_loadparm), &ifaces);
state->reply_addr = NULL;
for (i=0;i<q->out.num_addrs;i++) {
- if (iface_is_local(global_loadparm, q->out.reply_addrs[i])) {
+ if (iface_is_local(ifaces, q->out.reply_addrs[i])) {
state->reply_addr = talloc_steal(state,
q->out.reply_addrs[i]);
break;
typedef struct composite_context *(*resolve_name_send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, void *privdata, struct nbt_name *);
typedef NTSTATUS (*resolve_name_recv_fn)(struct composite_context *, TALLOC_CTX *, const char **);
#include "libcli/resolve/proto.h"
+struct interface;
#include "libcli/resolve/lp_proto.h"
#endif /* __RESOLVE_H__ */
state->wrepl_socket = wrepl_socket;
if (!our_ip) {
- our_ip = iface_best_ip(global_loadparm, peer_ip);
+ struct interface *ifaces;
+ load_interfaces(lp_interfaces(global_loadparm), &ifaces);
+ our_ip = iface_best_ip(ifaces, peer_ip);
}
us = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
/*
setup our listening sockets on the configured network interfaces
*/
-NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_context *lp_ctx)
+NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_context *lp_ctx,
+ struct interface *ifaces)
{
- int num_interfaces = iface_count(lp_ctx);
+ int num_interfaces = iface_count(ifaces);
int i;
TALLOC_CTX *tmp_ctx = talloc_new(nbtsrv);
NTSTATUS status;
for non-WINS queries not made on a specific
interface */
if (num_interfaces > 0) {
- primary_address = iface_n_ip(lp_ctx, 0);
+ primary_address = iface_n_ip(ifaces, 0);
} else {
primary_address = inet_ntoa(interpret_addr2(
lp_netbios_name(lp_ctx)));
}
for (i=0; i<num_interfaces; i++) {
- const char *bcast = iface_n_bcast(lp_ctx, i);
+ const char *bcast = iface_n_bcast(ifaces, i);
const char *address, *netmask;
/* we can't assume every interface is broadcast capable */
if (bcast == NULL) continue;
- address = talloc_strdup(tmp_ctx, iface_n_ip(lp_ctx, i));
+ address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i));
bcast = talloc_strdup(tmp_ctx, bcast);
- netmask = talloc_strdup(tmp_ctx, iface_n_netmask(lp_ctx, i));
+ netmask = talloc_strdup(tmp_ctx, iface_n_netmask(ifaces, i));
status = nbtd_add_socket(nbtsrv, lp_ctx,
address, address, bcast, netmask);
{
struct nbtd_server *nbtsrv;
NTSTATUS status;
+ struct interface *ifaces;
- if (iface_count(task->lp_ctx) == 0) {
+ load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
+
+ if (iface_count(ifaces) == 0) {
task_server_terminate(task, "nbtd: no network interfaces configured");
return;
}
nbtsrv->wins_interface = NULL;
/* start listening on the configured network interfaces */
- status = nbtd_startup_interfaces(nbtsrv, task->lp_ctx);
+ status = nbtd_startup_interfaces(nbtsrv, task->lp_ctx, ifaces);
if (!NT_STATUS_IS_OK(status)) {
task_server_terminate(task, "nbtd failed to setup interfaces");
return;
nbtd_register_names(nbtsrv);
irpc_add_name(task->msg_ctx, "nbt_server");
-
-
}
} \
} while (0)
+struct interface;
#include "nbt_server/nbt_server_proto.h"
struct nbtd_interface);
struct wins_dns_proxy_state *s;
struct composite_context *creq;
- const char *methods[] = {
- "host",
- NULL
- };
+ struct resolve_context *resolve_ctx;
s = talloc(nbtsock, struct wins_dns_proxy_state);
if (!s) goto failed;
goto failed;
}
- creq = resolve_name_send(name, iface->nbtsrv->task->event_ctx, methods);
+ resolve_ctx = resolve_context_init(s);
+ if (resolve_ctx == NULL) goto failed;
+ resolve_context_add_host_method(resolve_ctx);
+
+ creq = resolve_name_send(resolve_ctx, name, iface->nbtsrv->task->event_ctx);
if (!creq) goto failed;
creq->async.fn = nbtd_wins_dns_proxy_handler;
owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
if (!owner) {
- owner = iface_n_ip(lp_ctx, 0);
+ struct interface *ifaces;
+ load_interfaces(lp_interfaces(lp_ctx), &ifaces);
+ owner = iface_n_ip(ifaces, 0);
if (!owner) {
owner = "0.0.0.0";
}
}
struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
+ const char *owner,
enum winsdb_handle_caller caller)
{
struct winsdb_handle *h = NULL;
- const char *owner;
unsigned int flags = 0;
bool ret;
int ldb_err;
h->caller = caller;
h->hook_script = lp_wins_hook(lp_ctx);
- owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
- if (!owner) {
- owner = iface_n_ip(lp_ctx, 0);
- }
-
h->local_owner = talloc_strdup(h, owner);
if (!h->local_owner) goto failed;
#include "lib/socket/netif.h"
#include "lib/ldb/include/ldb.h"
#include "param/param.h"
+#include "libcli/resolve/resolve.h"
/*
work out the ttl we will use given a client requested ttl
NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv)
{
uint32_t tmp;
+ const char *owner;
if (!lp_wins_support(nbtsrv->task->lp_ctx)) {
nbtsrv->winssrv = NULL;
tmp = lp_parm_int(nbtsrv->task->lp_ctx, NULL, "wreplsrv"," tombstone_timeout", 1*24*60*60);
nbtsrv->winssrv->config.tombstone_timeout = tmp;
+ owner = lp_parm_string(nbtsrv->task->lp_ctx, NULL, "winsdb", "local_owner");
+
+ if (owner == NULL) {
+ struct interface *ifaces;
+ load_interfaces(lp_interfaces(nbtsrv->task->lp_ctx), &ifaces);
+ owner = iface_n_ip(ifaces, 0);
+ }
+
nbtsrv->winssrv->wins_db = winsdb_connect(nbtsrv->winssrv, nbtsrv->task->lp_ctx,
- WINSDB_HANDLE_CALLER_NBTD);
+ owner, WINSDB_HANDLE_CALLER_NBTD);
if (!nbtsrv->winssrv->wins_db) {
return NT_STATUS_INTERNAL_DB_ERROR;
}
struct event_context *event_ctx, const struct model_ops *model_ops)
{
NTSTATUS status;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(lp_ctx), &ifaces);
/* Add TCP/IP sockets */
if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
- int num_interfaces = iface_count(lp_ctx);
+ int num_interfaces = iface_count(ifaces);
int i;
for(i = 0; i < num_interfaces; i++) {
- const char *address = iface_n_ip(lp_ctx, i);
+ const char *address = iface_n_ip(ifaces, i);
status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, address);
NT_STATUS_NOT_OK_RETURN(status);
}
const char *filename = lp_configfile(global_loadparm);
ret = lp_load(global_loadparm, filename);
- if (ret) {
- unload_interfaces();
- }
mpr_Return(eid, mprCreateBoolVar(ret));
return 0;
}
*/
static int ejs_sys_interfaces(MprVarHandle eid, int argc, struct MprVar **argv)
{
- int i, count = iface_count(global_loadparm);
+ int i, count;
struct MprVar ret = mprArray("interfaces");
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(global_loadparm), &ifaces);
+
+ count = iface_count(ifaces);
for (i=0;i<count;i++) {
- mprAddArray(&ret, i, mprString(iface_n_ip(global_loadparm, i)));
+ mprAddArray(&ret, i, mprString(iface_n_ip(ifaces, i)));
}
mpr_Return(eid, ret);
return 0;
task_server_set_title(task, "task[smbsrv]");
if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) {
- int num_interfaces = iface_count(task->lp_ctx);
+ int num_interfaces;
int i;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
+
+ num_interfaces = iface_count(ifaces);
/* We have been given an interfaces line, and been
told to only bind to those interfaces. Create a
socket per interface and bind to only these.
*/
for(i = 0; i < num_interfaces; i++) {
- const char *address = iface_n_ip(task->lp_ctx, i);
+ const char *address = iface_n_ip(ifaces, i);
status = smbsrv_add_socket(task->event_ctx, task->lp_ctx, task->model_ops, address);
if (!NT_STATUS_IS_OK(status)) goto failed;
}
const char *address;
struct nbt_name name;
+
+ struct interface *ifaces;
name.name = lp_workgroup(tctx->lp_ctx);
name.type = NBT_NAME_LOGON;
resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, event_context_find(tctx)),
talloc_asprintf(tctx, "Failed to resolve %s", name.name));
- myaddress = talloc_strdup(dgmsock, iface_best_ip(tctx->lp_ctx, address));
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+ myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address));
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
const char *address;
struct nbt_name name;
+
+ struct interface *ifaces;
name.name = lp_workgroup(tctx->lp_ctx);
name.type = NBT_NAME_LOGON;
resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, event_context_find(tctx)),
talloc_asprintf(tctx, "Failed to resolve %s", name.name));
- myaddress = talloc_strdup(dgmsock, iface_best_ip(tctx->lp_ctx, address));
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+ myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address));
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port(tctx->lp_ctx));
struct socket_address *socket_address;
const char *address;
struct nbt_name name;
+
+ struct interface *ifaces;
name.name = lp_workgroup(tctx->lp_ctx);
name.type = NBT_NAME_LOGON;
resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, event_context_find(tctx)),
talloc_asprintf(tctx, "Failed to resolve %s", name.name));
- myaddress = talloc_strdup(dgmsock, iface_best_ip(tctx->lp_ctx, address));
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+ myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address));
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port(tctx->lp_ctx));
struct nbt_name name;
const char *address;
const char *myaddress;
+ struct interface *ifaces;
if (!torture_nbt_get_name(tctx, &name, &address))
return false;
- myaddress = iface_best_ip(tctx->lp_ctx, address);
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+
+ myaddress = iface_best_ip(ifaces, address);
socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name,
myaddress, 0);
struct socket_address *socket_address;
struct nbt_name name;
const char *address;
+ struct interface *ifaces;
if (!torture_nbt_get_name(tctx, &name, &address))
return false;
- myaddress = iface_best_ip(tctx->lp_ctx, address);
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+
+ myaddress = iface_best_ip(ifaces, address);
socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name,
myaddress, 0);
struct nbt_name_release release;
NTSTATUS status;
struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
- const char *myaddress = talloc_strdup(tctx, iface_best_ip(tctx->lp_ctx, address));
+ const char *myaddress;
struct socket_address *socket_address;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+
+ myaddress = talloc_strdup(tctx, iface_best_ip(ifaces, address));
socket_address = socket_address_from_strings(tctx,
nbtsock->sock->backend_name,
struct socket_address *my_ip;
struct nbt_name name;
const char *address;
+ struct interface *ifaces;
if (!torture_nbt_get_name(tctx, &name, &address))
return false;
state->registered = talloc_zero_array(state, bool, state->num_names);
state->wins_server = address;
state->wins_port = lp_nbt_port(tctx->lp_ctx);
- state->my_ip = talloc_strdup(tctx, iface_best_ip(tctx->lp_ctx, address));
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+ state->my_ip = talloc_strdup(tctx, iface_best_ip(ifaces, address));
state->ttl = timelimit;
my_ip = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name,
struct socket_address *nbt_srv_addr;
NTSTATUS status;
uint32_t i;
+ struct interface *ifaces;
ctx = talloc_zero(tctx, struct test_wrepl_conflict_conn);
if (!ctx) return NULL;
ctx->nbtsock = nbt_name_socket_init(ctx, NULL);
if (!ctx->nbtsock) return NULL;
- ctx->myaddr = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_best_ip(tctx->lp_ctx, address), 0);
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+
+ ctx->myaddr = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_best_ip(ifaces, address), 0);
if (!ctx->myaddr) return NULL;
- for (i = 0; i < iface_count(tctx->lp_ctx); i++) {
- if (strcmp(ctx->myaddr->addr, iface_n_ip(tctx->lp_ctx, i)) == 0) continue;
- ctx->myaddr2 = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_n_ip(tctx->lp_ctx, i), 0);
+ for (i = 0; i < iface_count(ifaces); i++) {
+ if (strcmp(ctx->myaddr->addr, iface_n_ip(ifaces, i)) == 0) continue;
+ ctx->myaddr2 = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_n_ip(ifaces, i), 0);
if (!ctx->myaddr2) return NULL;
break;
}
ctx->addresses_best[0].owner = ctx->b.address;
ctx->addresses_best[0].ip = ctx->myaddr->addr;
- ctx->addresses_all_num = iface_count(tctx->lp_ctx);
+ ctx->addresses_all_num = iface_count(ifaces);
ctx->addresses_all = talloc_array(ctx, struct wrepl_ip, ctx->addresses_all_num);
if (!ctx->addresses_all) return NULL;
for (i=0; i < ctx->addresses_all_num; i++) {
ctx->addresses_all[i].owner = ctx->b.address;
- ctx->addresses_all[i].ip = talloc_strdup(ctx->addresses_all, iface_n_ip(tctx->lp_ctx, i));
+ ctx->addresses_all[i].ip = talloc_strdup(ctx->addresses_all, iface_n_ip(ifaces, i));
if (!ctx->addresses_all[i].ip) return NULL;
}
struct policy_handle handle;
const char *address;
+ struct interface *ifaces;
ZERO_STRUCT(q);
lp_set_cmdline(tctx->lp_ctx, "dcerpc endpoint servers", "spoolss");
- address = iface_n_ip(tctx->lp_ctx, 0);
+ load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+ address = iface_n_ip(ifaces, 0);
torture_comment(tctx, "Listening for callbacks on %s\n", address);
status = smbsrv_add_socket(p->conn->event_ctx, tctx->lp_ctx, &single_ops, address);
torture_assert_ntstatus_ok(tctx, status, "starting smb server");
}
-static bool process_one(struct loadparm_context *lp_ctx, const char *name, int nbt_port)
+static bool process_one(struct loadparm_context *lp_ctx,
+ struct interface *ifaces, const char *name, int nbt_port)
{
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
enum nbt_name_type node_type = NBT_NAME_CLIENT;
status = do_node_query(nbtsock, options.unicast_address,
nbt_port, node_name, node_type, false);
} else {
- int i, num_interfaces = iface_count(lp_ctx);
+ int i, num_interfaces;
+
+ num_interfaces = iface_count(ifaces);
for (i=0;i<num_interfaces;i++) {
- const char *bcast = iface_n_bcast(lp_ctx, i);
+ const char *bcast = iface_n_bcast(ifaces, i);
if (bcast == NULL) continue;
status = do_node_query(nbtsock, bcast, nbt_port,
node_name, node_type, true);
int main(int argc, const char *argv[])
{
bool ret = true;
+ struct interface *ifaces;
poptContext pc;
int opt;
enum {
poptPrintUsage(pc, stderr, 0);
exit(1);
}
+
+ load_interfaces(lp_interfaces(cmdline_lp_ctx), &ifaces);
while (poptPeekArg(pc)) {
const char *name = poptGetArg(pc);
- ret &= process_one(cmdline_lp_ctx, name, lp_nbt_port(cmdline_lp_ctx));
+ ret &= process_one(cmdline_lp_ctx, ifaces, name, lp_nbt_port(cmdline_lp_ctx));
}
poptFreeContext(pc);
if (!model_ops) goto failed;
if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) {
- int num_interfaces = iface_count(task->lp_ctx);
+ int num_interfaces;
int i;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(task->lp_ctx), &ifaces);
+
+ num_interfaces = iface_count(ifaces);
for(i = 0; i < num_interfaces; i++) {
- const char *address = iface_n_ip(task->lp_ctx, i);
+ const char *address = iface_n_ip(ifaces, i);
status = stream_setup_socket(task->event_ctx, model_ops,
&web_stream_ops,
"ipv4", address,
}
if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
- int num_interfaces = iface_count(lp_ctx);
+ int num_interfaces;
int i;
+ struct interface *ifaces;
+
+ load_interfaces(lp_interfaces(lp_ctx), &ifaces);
+
+ num_interfaces = iface_count(ifaces);
/* We have been given an interfaces line, and been
told to only bind to those interfaces. Create a
socket per interface and bind to only these.
*/
for(i = 0; i < num_interfaces; i++) {
- address = iface_n_ip(lp_ctx, i);
+ address = iface_n_ip(ifaces, i);
status = stream_setup_socket(task->event_ctx, model_ops, &wreplsrv_stream_ops,
"ipv4", address, &port,
lp_socket_options(task->lp_ctx),
#include "auth/auth.h"
#include "ldb_wrap.h"
#include "param/param.h"
+#include "lib/socket/netif.h"
static struct ldb_context *wins_config_db_connect(TALLOC_CTX *mem_ctx,
struct loadparm_context *lp_ctx)
static NTSTATUS wreplsrv_open_winsdb(struct wreplsrv_service *service,
struct loadparm_context *lp_ctx)
{
- service->wins_db = winsdb_connect(service, lp_ctx, WINSDB_HANDLE_CALLER_WREPL);
+ const char *owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
+
+ if (owner == NULL) {
+ struct interface *ifaces;
+ load_interfaces(lp_interfaces(lp_ctx), &ifaces);
+ owner = iface_n_ip(ifaces, 0);
+ }
+
+ service->wins_db = winsdb_connect(service, lp_ctx, owner, WINSDB_HANDLE_CALLER_WREPL);
if (!service->wins_db) {
return NT_STATUS_INTERNAL_DB_ERROR;
}