diff options
33 files changed, 218 insertions, 132 deletions
diff --git a/source4/cldap_server/cldap_server.c b/source4/cldap_server/cldap_server.c index d71e933b5f0..8f6c9410f8c 100644 --- a/source4/cldap_server/cldap_server.c +++ b/source4/cldap_server/cldap_server.c @@ -121,12 +121,15 @@ static NTSTATUS cldapd_add_socket(struct cldapd_server *cldapd, struct loadparm_ /* 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)) { @@ -136,7 +139,7 @@ static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct l 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); } @@ -154,8 +157,11 @@ static void cldapd_task_init(struct task_server *task) { 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; } @@ -188,7 +194,7 @@ static void cldapd_task_init(struct task_server *task) } /* 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; diff --git a/source4/cldap_server/netlogon.c b/source4/cldap_server/netlogon.c index d1f001e333d..1c2b51aed70 100644 --- a/source4/cldap_server/netlogon.c +++ b/source4/cldap_server/netlogon.c @@ -64,6 +64,7 @@ static NTSTATUS cldapd_netlogon_fill(struct cldapd_server *cldapd, 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); @@ -187,7 +188,8 @@ static NTSTATUS cldapd_netlogon_fill(struct cldapd_server *cldapd, 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); diff --git a/source4/heimdal_build/glue.c b/source4/heimdal_build/glue.c index df08cae57c5..809b63f418e 100644 --- a/source4/heimdal_build/glue.c +++ b/source4/heimdal_build/glue.c @@ -31,13 +31,17 @@ 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); diff --git a/source4/kdc/kdc.c b/source4/kdc/kdc.c index 18fc86b8e01..0301a4c2641 100644 --- a/source4/kdc/kdc.c +++ b/source4/kdc/kdc.c @@ -520,16 +520,18 @@ static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address, /* 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); @@ -558,6 +560,7 @@ static void kdc_task_init(struct task_server *task) struct kdc_server *kdc; NTSTATUS status; krb5_error_code ret; + struct interface *ifaces; switch (lp_server_role(task->lp_ctx)) { case ROLE_STANDALONE: @@ -571,7 +574,9 @@ static void kdc_task_init(struct task_server *task) 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; } @@ -641,7 +646,7 @@ static void kdc_task_init(struct task_server *task) 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; diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c index 99889f1f7fc..9d3fa0ada43 100644 --- a/source4/ldap_server/ldap_server.c +++ b/source4/ldap_server/ldap_server.c @@ -546,15 +546,19 @@ static void ldapsrv_task_init(struct task_server *task) 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; } diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 309ed80744f..d21923d972b 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -35,8 +35,6 @@ struct interface { const char *nmask_s; }; -static struct interface *local_interfaces; - #define ALLONES ((uint32_t)0xFFFFFFFF) /* address construction based on a patch from fred@datalync.com @@ -114,7 +112,8 @@ This handles the following different forms: **/ 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; @@ -128,7 +127,7 @@ static void interpret_interface(const char *token, 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; } } @@ -146,7 +145,7 @@ static void interpret_interface(const char *token, 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; } } @@ -171,7 +170,7 @@ static void interpret_interface(const char *token, 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; } } @@ -179,14 +178,14 @@ static void interpret_interface(const char *token, 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; @@ -194,9 +193,7 @@ static void load_interfaces(const char **interfaces) struct in_addr loopback_ip; int total_probed; - if (local_interfaces != NULL) { - return; - } + *local_interfaces = NULL; loopback_ip = interpret_addr2("127.0.0.1"); @@ -212,42 +209,30 @@ static void load_interfaces(const char **interfaces) 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; } @@ -255,13 +240,11 @@ int iface_count(struct loadparm_context *lp_ctx) /** 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) { @@ -273,13 +256,11 @@ const char *iface_n_ip(struct loadparm_context *lp_ctx, int n) /** 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) { @@ -291,13 +272,11 @@ const char *iface_n_bcast(struct loadparm_context *lp_ctx, int n) /** 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) { @@ -310,32 +289,28 @@ const char *iface_n_netmask(struct loadparm_context *lp_ctx, int n) 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; diff --git a/source4/lib/socket/netif.h b/source4/lib/socket/netif.h index 4855f4bd73b..417c6e074fd 100644 --- a/source4/lib/socket/netif.h +++ b/source4/lib/socket/netif.h @@ -27,6 +27,8 @@ struct iface_struct { struct in_addr netmask; }; +struct interface; + #define MAX_INTERFACES 128 #ifndef AUTOCONF_TEST diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c index edbe617aa0c..a99ae078b55 100644 --- a/source4/lib/socket/testsuite.c +++ b/source4/lib/socket/testsuite.c @@ -40,6 +40,9 @@ static bool test_udp(struct torture_context *tctx) 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"); @@ -50,7 +53,7 @@ static bool test_udp(struct torture_context *tctx) 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"); @@ -59,10 +62,10 @@ static bool test_udp(struct torture_context *tctx) 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); @@ -122,6 +125,7 @@ static bool test_tcp(struct torture_context *tctx) 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"); @@ -131,8 +135,9 @@ static bool test_tcp(struct torture_context *tctx) 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); @@ -142,7 +147,7 @@ static bool test_tcp(struct torture_context *tctx) 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); diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 1733ca9d2ed..d1f3d65faf4 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -33,17 +33,19 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, 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) { @@ -74,14 +76,17 @@ NTSTATUS resolve_name_bcast_recv(struct composite_context *c, */ 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); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index daa602f97c0..6c12fe706b4 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -49,6 +49,7 @@ static void nbtlist_handler(struct nbt_name_request *req) 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++) { @@ -75,9 +76,10 @@ static void nbtlist_handler(struct nbt_name_request *req) } /* 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; diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h index 9282074aa4d..79b91dc8365 100644 --- a/source4/libcli/resolve/resolve.h +++ b/source4/libcli/resolve/resolve.h @@ -26,6 +26,7 @@ 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__ */ diff --git a/source4/libcli/wrepl/winsrepl.c b/source4/libcli/wrepl/winsrepl.c index 92543be4876..15dc98f675c 100644 --- a/source4/libcli/wrepl/winsrepl.c +++ b/source4/libcli/wrepl/winsrepl.c @@ -333,7 +333,9 @@ struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket, 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, diff --git a/source4/nbt_server/interfaces.c b/source4/nbt_server/interfaces.c index 21ebada3c81..486acfbad53 100644 --- a/source4/nbt_server/interfaces.c +++ b/source4/nbt_server/interfaces.c @@ -216,9 +216,10 @@ static NTSTATUS nbtd_add_wins_socket(struct nbtd_server *nbtsrv) /* 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; @@ -232,7 +233,7 @@ NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_con 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))); @@ -250,15 +251,15 @@ NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_con } 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); diff --git a/source4/nbt_server/nbt_server.c b/source4/nbt_server/nbt_server.c index 22f46dec69b..14b8d2461c1 100644 --- a/source4/nbt_server/nbt_server.c +++ b/source4/nbt_server/nbt_server.c @@ -37,8 +37,11 @@ static void nbtd_task_init(struct task_server *task) { 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; } @@ -57,7 +60,7 @@ static void nbtd_task_init(struct task_server *task) 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; @@ -82,8 +85,6 @@ static void nbtd_task_init(struct task_server *task) nbtd_register_names(nbtsrv); irpc_add_name(task->msg_ctx, "nbt_server"); - - } diff --git a/source4/nbt_server/nbt_server.h b/source4/nbt_server/nbt_server.h index 506098b691a..688b6a7a7d9 100644 --- a/source4/nbt_server/nbt_server.h +++ b/source4/nbt_server/nbt_server.h @@ -88,4 +88,5 @@ struct nbtd_server { } \ } while (0) +struct interface; #include "nbt_server/nbt_server_proto.h" diff --git a/source4/nbt_server/wins/wins_dns_proxy.c b/source4/nbt_server/wins/wins_dns_proxy.c index 24bcf1f3d1c..3322ad55fd1 100644 --- a/source4/nbt_server/wins/wins_dns_proxy.c +++ b/source4/nbt_server/wins/wins_dns_proxy.c @@ -72,10 +72,7 @@ void nbtd_wins_dns_proxy_query(struct nbt_name_socket *nbtsock, 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; @@ -86,7 +83,11 @@ void nbtd_wins_dns_proxy_query(struct nbt_name_socket *nbtsock, 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; diff --git a/source4/nbt_server/wins/wins_ldb.c b/source4/nbt_server/wins/wins_ldb.c index 7caab34aaaa..6fef2180560 100644 --- a/source4/nbt_server/wins/wins_ldb.c +++ b/source4/nbt_server/wins/wins_ldb.c @@ -90,7 +90,9 @@ static int wins_ldb_init(struct ldb_module *ctx) 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"; } diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c index 428b1547317..7de5bba468d 100644 --- a/source4/nbt_server/wins/winsdb.c +++ b/source4/nbt_server/wins/winsdb.c @@ -1011,10 +1011,10 @@ failed: } 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; @@ -1033,11 +1033,6 @@ struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx, struct loadparm_contex 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; diff --git a/source4/nbt_server/wins/winsserver.c b/source4/nbt_server/wins/winsserver.c index 98262a2f847..e24ad853769 100644 --- a/source4/nbt_server/wins/winsserver.c +++ b/source4/nbt_server/wins/winsserver.c @@ -33,6 +33,7 @@ #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 @@ -958,6 +959,7 @@ void nbtd_winsserver_request(struct nbt_name_socket *nbtsock, 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; @@ -974,8 +976,16 @@ NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv) 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; } diff --git a/source4/rpc_server/service_rpc.c b/source4/rpc_server/service_rpc.c index 265cf0b8120..363d5971c9c 100644 --- a/source4/rpc_server/service_rpc.c +++ b/source4/rpc_server/service_rpc.c @@ -374,13 +374,16 @@ static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, 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); } diff --git a/source4/scripting/ejs/smbcalls_config.c b/source4/scripting/ejs/smbcalls_config.c index 88c153ead3a..07e0f479dae 100644 --- a/source4/scripting/ejs/smbcalls_config.c +++ b/source4/scripting/ejs/smbcalls_config.c @@ -199,9 +199,6 @@ static int ejs_lpReload(MprVarHandle eid, int argc, char **argv) const char *filename = lp_configfile(global_loadparm); ret = lp_load(global_loadparm, filename); - if (ret) { - unload_interfaces(); - } mpr_Return(eid, mprCreateBoolVar(ret)); return 0; } diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c index 86e0873e09d..cc1c3b4e325 100644 --- a/source4/scripting/ejs/smbcalls_sys.c +++ b/source4/scripting/ejs/smbcalls_sys.c @@ -32,10 +32,15 @@ */ 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; diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index c1581f88422..1dd022405a0 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -218,15 +218,20 @@ static void smbsrv_task_init(struct task_server *task) 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; } diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c index 37d445cac4f..d8903eedac3 100644 --- a/source4/torture/nbt/dgram.c +++ b/source4/torture/nbt/dgram.c @@ -77,6 +77,8 @@ static bool nbt_test_netlogon(struct torture_context *tctx) const char *address; struct nbt_name name; + + struct interface *ifaces; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; @@ -87,7 +89,8 @@ static bool nbt_test_netlogon(struct torture_context *tctx) 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, @@ -156,6 +159,8 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) const char *address; struct nbt_name name; + + struct interface *ifaces; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; @@ -166,7 +171,8 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) 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)); @@ -265,6 +271,8 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) 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; @@ -275,7 +283,8 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) 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)); diff --git a/source4/torture/nbt/register.c b/source4/torture/nbt/register.c index 2c37d9de501..090027be2ea 100644 --- a/source4/torture/nbt/register.c +++ b/source4/torture/nbt/register.c @@ -49,11 +49,14 @@ static bool nbt_register_own(struct torture_context *tctx) 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); @@ -115,11 +118,14 @@ static bool nbt_refresh_own(struct torture_context *tctx) 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); diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c index 2ba7f221c9b..0d895ddd0dd 100644 --- a/source4/torture/nbt/wins.c +++ b/source4/torture/nbt/wins.c @@ -54,8 +54,13 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address 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, diff --git a/source4/torture/nbt/winsbench.c b/source4/torture/nbt/winsbench.c index d49b50b9d3a..95241a1a122 100644 --- a/source4/torture/nbt/winsbench.c +++ b/source4/torture/nbt/winsbench.c @@ -234,6 +234,7 @@ static bool bench_wins(struct torture_context *tctx) 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; @@ -244,7 +245,8 @@ static bool bench_wins(struct torture_context *tctx) 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, diff --git a/source4/torture/nbt/winsreplication.c b/source4/torture/nbt/winsreplication.c index fc88d7fce13..b90daa98c46 100644 --- a/source4/torture/nbt/winsreplication.c +++ b/source4/torture/nbt/winsreplication.c @@ -547,6 +547,7 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( 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; @@ -612,12 +613,14 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( 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; } @@ -674,12 +677,12 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( 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; } diff --git a/source4/torture/rpc/spoolss_notify.c b/source4/torture/rpc/spoolss_notify.c index bdbdc6b0c69..48ddcb6a607 100644 --- a/source4/torture/rpc/spoolss_notify.c +++ b/source4/torture/rpc/spoolss_notify.c @@ -193,6 +193,7 @@ static bool test_RFFPCNEx(struct torture_context *tctx, struct policy_handle handle; const char *address; + struct interface *ifaces; ZERO_STRUCT(q); @@ -226,7 +227,8 @@ static bool test_RFFPCNEx(struct torture_context *tctx, 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"); diff --git a/source4/utils/nmblookup.c b/source4/utils/nmblookup.c index 1471dfb5b78..6c849fc0dbd 100644 --- a/source4/utils/nmblookup.c +++ b/source4/utils/nmblookup.c @@ -180,7 +180,8 @@ static NTSTATUS do_node_query(struct nbt_name_socket *nbtsock, } -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; @@ -242,9 +243,11 @@ static bool process_one(struct loadparm_context *lp_ctx, const char *name, int n 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); @@ -267,6 +270,7 @@ static bool process_one(struct loadparm_context *lp_ctx, const char *name, int n int main(int argc, const char *argv[]) { bool ret = true; + struct interface *ifaces; poptContext pc; int opt; enum { @@ -350,11 +354,13 @@ int main(int argc, const char *argv[]) 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); diff --git a/source4/web_server/web_server.c b/source4/web_server/web_server.c index a8fd9234aef..0fdb0bfb4ff 100644 --- a/source4/web_server/web_server.c +++ b/source4/web_server/web_server.c @@ -251,10 +251,15 @@ static void websrv_task_init(struct task_server *task) 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, diff --git a/source4/wrepl_server/wrepl_in_connection.c b/source4/wrepl_server/wrepl_in_connection.c index 089bdd5f3ee..74c524dc790 100644 --- a/source4/wrepl_server/wrepl_in_connection.c +++ b/source4/wrepl_server/wrepl_in_connection.c @@ -276,15 +276,20 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar } 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), diff --git a/source4/wrepl_server/wrepl_server.c b/source4/wrepl_server/wrepl_server.c index 7455c57d75f..c8ad80351e0 100644 --- a/source4/wrepl_server/wrepl_server.c +++ b/source4/wrepl_server/wrepl_server.c @@ -32,6 +32,7 @@ #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) @@ -74,7 +75,15 @@ failed: 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; } |