Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into registry
[kai/samba.git] / source4 / wrepl_server / wrepl_in_connection.c
index 5db2c883f94ff6eda08897444fb4ea9b3bea05fc..25227481b8820aa07ddf0ae459f168bcc35c6c60 100644 (file)
@@ -7,7 +7,7 @@
    
    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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -32,6 +31,7 @@
 #include "smbd/process_model.h"
 #include "system/network.h"
 #include "lib/socket/netif.h"
+#include "param/param.h"
 
 void wreplsrv_terminate_in_connection(struct wreplsrv_in_connection *wreplconn, const char *reason)
 {
@@ -55,6 +55,7 @@ static NTSTATUS wreplsrv_recv_request(void *private, DATA_BLOB blob)
        DATA_BLOB packet_out_blob;
        struct wrepl_wrap packet_out_wrap;
        NTSTATUS status;
+       enum ndr_err_code ndr_err;
 
        call = talloc_zero(wreplconn, struct wreplsrv_in_call);
        NT_STATUS_HAVE_NO_MEMORY(call);
@@ -64,9 +65,13 @@ static NTSTATUS wreplsrv_recv_request(void *private, DATA_BLOB blob)
        packet_in_blob.data = blob.data + 4;
        packet_in_blob.length = blob.length - 4;
 
-       status = ndr_pull_struct_blob(&packet_in_blob, call, &call->req_packet,
-                                     (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
-       NT_STATUS_NOT_OK_RETURN(status);
+       ndr_err = ndr_pull_struct_blob(&packet_in_blob, call, 
+                                      lp_iconv_convenience(wreplconn->service->task->lp_ctx),
+                                      &call->req_packet,
+                                      (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
 
        if (DEBUGLVL(10)) {
                DEBUG(10,("Received WINS-Replication packet of length %u\n", 
@@ -85,9 +90,13 @@ static NTSTATUS wreplsrv_recv_request(void *private, DATA_BLOB blob)
 
        /* and now encode the reply */
        packet_out_wrap.packet = call->rep_packet;
-       status = ndr_push_struct_blob(&packet_out_blob, call, &packet_out_wrap,
+       ndr_err = ndr_push_struct_blob(&packet_out_blob, call, 
+                                      lp_iconv_convenience(wreplconn->service->task->lp_ctx),
+                                      &packet_out_wrap,
                                      (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
-       NT_STATUS_NOT_OK_RETURN(status);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
 
        if (DEBUGLVL(10)) {
                DEBUG(10,("Sending WINS-Replication packet of length %d\n", (int)packet_out_blob.length));
@@ -221,7 +230,7 @@ NTSTATUS wreplsrv_in_connection_merge(struct wreplsrv_partner *partner,
        wrepl_in->service       = service;
        wrepl_in->partner       = partner;
 
-       status = stream_new_connection_merge(service->task->event_ctx, model_ops,
+       status = stream_new_connection_merge(service->task->event_ctx, service->task->lp_ctx, model_ops,
                                             sock, &wreplsrv_stream_ops, service->task->msg_ctx,
                                             wrepl_in, &conn);
        NT_STATUS_NOT_OK_RETURN(status);
@@ -253,7 +262,7 @@ NTSTATUS wreplsrv_in_connection_merge(struct wreplsrv_partner *partner,
 /*
   startup the wrepl port 42 server sockets
 */
-NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service)
+NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadparm_context *lp_ctx)
 {
        NTSTATUS status;
        struct task_server *task = service->task;
@@ -270,18 +279,27 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service)
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       if (lp_interfaces() && lp_bind_interfaces_only()) {
-               int num_interfaces = iface_count();
+       if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
+               int num_interfaces;
                int i;
+               struct interface *ifaces;
+
+               load_interfaces(task, 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(i);
-                       status = stream_setup_socket(task->event_ctx, model_ops, &wreplsrv_stream_ops,
-                                                    "ipv4", address, &port, service);
+                       address = iface_n_ip(ifaces, i);
+                       status = stream_setup_socket(task->event_ctx, 
+                                                    task->lp_ctx, model_ops, 
+                                                    &wreplsrv_stream_ops,
+                                                    "ipv4", address, &port, 
+                                                     lp_socket_options(task->lp_ctx), 
+                                                    service);
                        if (!NT_STATUS_IS_OK(status)) {
                                DEBUG(0,("stream_setup_socket(address=%s,port=%u) failed - %s\n",
                                         address, port, nt_errstr(status)));
@@ -289,9 +307,11 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service)
                        }
                }
        } else {
-               address = lp_socket_address();
-               status = stream_setup_socket(task->event_ctx, model_ops, &wreplsrv_stream_ops,
-                                            "ipv4", address, &port, service);
+               address = lp_socket_address(lp_ctx);
+               status = stream_setup_socket(task->event_ctx, task->lp_ctx, 
+                                            model_ops, &wreplsrv_stream_ops,
+                                            "ipv4", address, &port, lp_socket_options(task->lp_ctx), 
+                                            service);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0,("stream_setup_socket(address=%s,port=%u) failed - %s\n",
                                 address, port, nt_errstr(status)));