]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
rpc_server: Use dcesrv_open_ncacn_ip_tcp_sockets() in dcesrv_setup_ncacn_ip_tcp_sockets()
authorVolker Lendecke <vl@samba.org>
Thu, 31 Dec 2020 08:47:18 +0000 (09:47 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 11 Jan 2021 13:19:32 +0000 (13:19 +0000)
Avoid duplication of logic with "lp_interfaces_only()"

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@samba.org>
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h
source3/rpc_server/rpc_sock_helper.c

index 9e57bc345595ce77c6834fe8660de9819865b43d..e65d4a1b7c6e64c8c2abc232c111fbe59dad7313 100644 (file)
@@ -337,24 +337,15 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
                                          struct messaging_context *msg_ctx,
                                          struct dcesrv_context *dce_ctx,
                                          struct dcesrv_endpoint *e,
-                                         const struct sockaddr_storage *ifss,
+                                         int fd,
                                          dcerpc_ncacn_termination_fn term_fn,
                                          void *term_data)
 {
        struct dcerpc_ncacn_listen_state *state = NULL;
        struct tevent_fd *fde = NULL;
-       const char *endpoint = NULL;
-       uint16_t port = 0;
-       char port_str[6];
        int rc;
        NTSTATUS status;
 
-       endpoint = dcerpc_binding_get_string_option(e->ep_description,
-                                                   "endpoint");
-       if (endpoint != NULL) {
-               port = atoi(endpoint);
-       }
-
        /* Alloc in endpoint context. If the endpoint is freed (for example
         * when forked daemons reinit the dcesrv_context, the tevent_fd
         * listener will be stopped and the socket closed */
@@ -364,7 +355,7 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       state->fd = -1;
+       state->fd = fd;
        state->ev_ctx = ev_ctx;
        state->msg_ctx = msg_ctx;
        state->endpoint = e;
@@ -372,11 +363,6 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
        state->termination_fn = term_fn;
        state->termination_data = term_data;
 
-       status = dcesrv_create_ncacn_ip_tcp_socket(ifss, &port, &state->fd);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
        /* ready to listen */
        set_socket_options(state->fd, "SO_KEEPALIVE");
        set_socket_options(state->fd, lp_socket_options());
@@ -396,9 +382,6 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
                goto out;
        }
 
-       DBG_DEBUG("Opened socket fd %d for port %u\n",
-                 state->fd, port);
-
        errno = 0;
        fde = tevent_add_fd(state->ev_ctx,
                            state,
@@ -418,17 +401,6 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
 
        tevent_fd_set_auto_close(fde);
 
-       /* Set the port in the endpoint */
-       snprintf(port_str, sizeof(port_str), "%u", port);
-
-       status = dcerpc_binding_set_string_option(e->ep_description,
-                                                 "endpoint", port_str);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_ERR("Failed to set binding endpoint '%s': %s\n",
-                       port_str, nt_errstr(status));
-               goto out;
-       }
-
        return NT_STATUS_OK;
 
 out:
index 3d93da28cfbef953f9c7cc6fd0480d0eab4b225c..0ac5ae5b5dc52eb0d2d13af140cc7e528bb6392c 100644 (file)
@@ -91,7 +91,7 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
                                          struct messaging_context *msg_ctx,
                                          struct dcesrv_context *dce_ctx,
                                          struct dcesrv_endpoint *e,
-                                         const struct sockaddr_storage *ifss,
+                                         int fd,
                                          dcerpc_ncacn_termination_fn term_fn,
                                          void *term_data);
 
index d0c9bbe2eb5c556a1b61fe335db926959f2ca7d6..33ce8a616051b429dd74e379186eef28b79a066d 100644 (file)
@@ -194,71 +194,30 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_sockets(struct tevent_context *ev_ctx,
 {
        TALLOC_CTX *tmp_ctx;
        NTSTATUS status;
+       int *fds = NULL;
+       size_t i, num_fds = 0;
 
        tmp_ctx = talloc_stackframe();
        if (tmp_ctx == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (lp_interfaces() && lp_bind_interfaces_only()) {
-               uint32_t num_ifs = iface_count();
-               uint32_t i;
-
-               /*
-                * 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.
-                */
-
-               /* Now open a listen socket for each of the interfaces. */
-               for (i = 0; i < num_ifs; i++) {
-                       const struct sockaddr_storage *ifss =
-                                       iface_n_sockaddr_storage(i);
-
-                       status = dcesrv_setup_ncacn_ip_tcp_socket(ev_ctx,
-                                                                 msg_ctx,
-                                                                 dce_ctx,
-                                                                 e,
-                                                                 ifss,
-                                                                 t_fn,
-                                                                 t_data);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               goto done;
-                       }
-               }
-       } else {
-               const char *sock_addr;
-               const char *sock_ptr;
-               char *sock_tok;
-
-#ifdef HAVE_IPV6
-               sock_addr = "::,0.0.0.0";
-#else
-               sock_addr = "0.0.0.0";
-#endif
-
-               for (sock_ptr = sock_addr;
-                    next_token_talloc(talloc_tos(), &sock_ptr, &sock_tok, " \t,");
-                   ) {
-                       struct sockaddr_storage ss;
-
-                       /* open an incoming socket */
-                       if (!interpret_string_addr(&ss,
-                                                  sock_tok,
-                                                  AI_NUMERICHOST|AI_PASSIVE)) {
-                               continue;
-                       }
+       status = dcesrv_open_ncacn_ip_tcp_sockets(e, tmp_ctx, &num_fds, &fds);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
 
-                       status = dcesrv_setup_ncacn_ip_tcp_socket(ev_ctx,
-                                                                 msg_ctx,
-                                                                 dce_ctx,
-                                                                 e,
-                                                                 &ss,
-                                                                 t_fn,
-                                                                 t_data);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               goto done;
-                       }
+       for (i=0; i<num_fds; i++) {
+               status = dcesrv_setup_ncacn_ip_tcp_socket(
+                       ev_ctx,
+                       msg_ctx,
+                       dce_ctx,
+                       e,
+                       fds[i],
+                       t_fn,
+                       t_data);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto done;
                }
        }