s4-server: make server sockets a child of the task context
authorAndrew Tridgell <tridge@samba.org>
Sun, 14 Nov 2010 23:12:22 +0000 (10:12 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sun, 14 Nov 2010 23:19:34 +0000 (10:19 +1100)
We previously allocated sockets as direct children of the event
context. That led to crashes if a service called
task_server_terminate(), as it left the socket open and handling
events for a dead protocol.

Making them a child of the task allows the task to terminate and take
all its sockets with it.

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

14 files changed:
source4/dns_server/dns_server.c
source4/ldap_server/ldap_server.c
source4/ntp_signd/ntp_signd.c
source4/rpc_server/dcerpc_server.c
source4/smb_server/service_smb.c
source4/smb_server/smb_samba3.c
source4/smb_server/smb_server.c
source4/smb_server/smb_server.h
source4/smbd/service_named_pipe.c
source4/smbd/service_stream.c
source4/torture/rpc/spoolss_notify.c
source4/web_server/web_server.c
source4/winbind/wb_server.c
source4/wrepl_server/wrepl_in_connection.c

index 8e37fc21d3d0b0d0daa7292f379d7171e396142b..fc343ba0580cfc0f49aa7ab781b3c7cc33112b98 100644 (file)
@@ -492,7 +492,8 @@ static NTSTATUS dns_add_socket(struct dns_server *dns,
                return status;
        }
 
-       status = stream_setup_socket(dns->task->event_ctx,
+       status = stream_setup_socket(dns->task,
+                                    dns->task->event_ctx,
                                     dns->task->lp_ctx,
                                     model_ops,
                                     &dns_tcp_stream_ops,
index eec505fdc5a7790ba2b5ff115ad3ce08b03e4aab..67fe18330f47456cc54fe91d9d4ef45399c7f48d 100644 (file)
@@ -797,10 +797,12 @@ static const struct stream_server_ops ldap_stream_priv_ops = {
 };
 
 #endif
+
+
 /*
   add a socket address to the list of events, one event per port
 */
-static NTSTATUS add_socket(struct tevent_context *event_context,
+static NTSTATUS add_socket(struct task_server *task,
                           struct loadparm_context *lp_ctx,
                           const struct model_ops *model_ops,
                           const char *address, struct ldapsrv_service *ldap_service)
@@ -809,7 +811,7 @@ static NTSTATUS add_socket(struct tevent_context *event_context,
        NTSTATUS status;
        struct ldb_context *ldb;
 
-       status = stream_setup_socket(event_context, lp_ctx,
+       status = stream_setup_socket(task, task->event_ctx, lp_ctx,
                                     model_ops, &ldap_stream_nonpriv_ops,
                                     "ipv4", address, &port, 
                                     lpcfg_socket_options(lp_ctx),
@@ -823,7 +825,7 @@ static NTSTATUS add_socket(struct tevent_context *event_context,
        if (tstream_tls_params_enabled(ldap_service->tls_params)) {
                /* add ldaps server */
                port = 636;
-               status = stream_setup_socket(event_context, lp_ctx,
+               status = stream_setup_socket(task, task->event_ctx, lp_ctx,
                                             model_ops,
                                             &ldap_stream_nonpriv_ops,
                                             "ipv4", address, &port, 
@@ -845,7 +847,7 @@ static NTSTATUS add_socket(struct tevent_context *event_context,
 
        if (samdb_is_gc(ldb)) {
                port = 3268;
-               status = stream_setup_socket(event_context, lp_ctx,
+               status = stream_setup_socket(task, task->event_ctx, lp_ctx,
                                             model_ops,
                                             &ldap_stream_nonpriv_ops,
                                             "ipv4", address, &port, 
@@ -941,11 +943,11 @@ static void ldapsrv_task_init(struct task_server *task)
                */
                for(i = 0; i < num_interfaces; i++) {
                        const char *address = iface_n_ip(ifaces, i);
-                       status = add_socket(task->event_ctx, task->lp_ctx, model_ops, address, ldap_service);
+                       status = add_socket(task, task->lp_ctx, model_ops, address, ldap_service);
                        if (!NT_STATUS_IS_OK(status)) goto failed;
                }
        } else {
-               status = add_socket(task->event_ctx, task->lp_ctx, model_ops,
+               status = add_socket(task, task->lp_ctx, model_ops,
                                    lpcfg_socket_address(task->lp_ctx), ldap_service);
                if (!NT_STATUS_IS_OK(status)) goto failed;
        }
@@ -955,7 +957,7 @@ static void ldapsrv_task_init(struct task_server *task)
                goto failed;
        }
 
-       status = stream_setup_socket(task->event_ctx, task->lp_ctx,
+       status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
                                     model_ops, &ldap_stream_nonpriv_ops,
                                     "unix", ldapi_path, NULL, 
                                     lpcfg_socket_options(task->lp_ctx),
@@ -986,7 +988,7 @@ static void ldapsrv_task_init(struct task_server *task)
                goto failed;
        }
 
-       status = stream_setup_socket(task->event_ctx, task->lp_ctx,
+       status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
                                     model_ops, &ldap_stream_priv_ops,
                                     "unix", ldapi_path, NULL,
                                     lpcfg_socket_options(task->lp_ctx),
index a0dd2d3065b8cd3ff682af82bfcb1d161b191070..71b9a9dbc2dbf74656f898b1154320f1ef9d7d3d 100644 (file)
@@ -528,7 +528,8 @@ static void ntp_signd_task_init(struct task_server *task)
 
        address = talloc_asprintf(ntp_signd, "%s/socket", lpcfg_ntp_signd_socket_directory(task->lp_ctx));
 
-       status = stream_setup_socket(ntp_signd->task->event_ctx, 
+       status = stream_setup_socket(ntp_signd->task,
+                                    ntp_signd->task->event_ctx,
                                     ntp_signd->task->lp_ctx,
                                     model_ops, 
                                     &ntp_signd_stream_ops, 
index 061d8e80b2b1d34312c8d4e5f3e25841f278c526..1371ad9b360821c152d538304fa458a0f046012c 100644 (file)
@@ -1538,7 +1538,7 @@ static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx,
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = stream_setup_socket(event_ctx, lp_ctx,
+       status = stream_setup_socket(dcesrv_sock, event_ctx, lp_ctx,
                                     model_ops, &dcesrv_stream_ops, 
                                     "unix", e->ep_description->endpoint, &port, 
                                     lpcfg_socket_options(lp_ctx),
@@ -1578,7 +1578,7 @@ static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx,
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = stream_setup_socket(event_ctx, lp_ctx,
+       status = stream_setup_socket(dcesrv_sock, event_ctx, lp_ctx,
                                     model_ops, &dcesrv_stream_ops, 
                                     "unix", full_path, &port, 
                                     lpcfg_socket_options(lp_ctx),
@@ -1610,7 +1610,7 @@ static NTSTATUS dcesrv_add_ep_np(struct dcesrv_context *dce_ctx,
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = tstream_setup_named_pipe(event_ctx, lp_ctx,
+       status = tstream_setup_named_pipe(dce_ctx, event_ctx, lp_ctx,
                                          model_ops, &dcesrv_stream_ops,
                                          e->ep_description->endpoint,
                                          dcesrv_sock);
@@ -1645,7 +1645,7 @@ static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = stream_setup_socket(event_ctx, dce_ctx->lp_ctx,
+       status = stream_setup_socket(dcesrv_sock, event_ctx, dce_ctx->lp_ctx,
                                     model_ops, &dcesrv_stream_ops, 
                                     "ipv4", address, &port, 
                                     lpcfg_socket_options(dce_ctx->lp_ctx),
index 54feccbe0536d5f0ef3ebc4900163a1819a0b85e..583360bbe790f7a105f2a91d57280f90287cb561 100644 (file)
@@ -58,12 +58,12 @@ static void smbsrv_task_init(struct task_server *task)
                */
                for(i = 0; i < num_interfaces; i++) {
                        const char *address = iface_n_ip(ifaces, i);
-                       status = smbsrv_add_socket(task->event_ctx, task->lp_ctx, task->model_ops, address);
+                       status = smbsrv_add_socket(task, task->event_ctx, task->lp_ctx, task->model_ops, address);
                        if (!NT_STATUS_IS_OK(status)) goto failed;
                }
        } else {
                /* Just bind to lpcfg_socket_address() (usually 0.0.0.0) */
-               status = smbsrv_add_socket(task->event_ctx, task->lp_ctx, task->model_ops,
+               status = smbsrv_add_socket(task, task->event_ctx, task->lp_ctx, task->model_ops,
                                           lpcfg_socket_address(task->lp_ctx));
                if (!NT_STATUS_IS_OK(status)) goto failed;
        }
index ee12480c39fb5ff12091da1f94d6bd250e3d5bcf..ed9027afac47e509a57dd8f75af327d49f52cb04 100644 (file)
@@ -86,7 +86,8 @@ static const struct stream_server_ops samba3_smb_stream_ops = {
 /*
   setup a listening socket on all the SMB ports for a particular address
 */
-static NTSTATUS samba3_add_socket(struct tevent_context *event_context,
+static NTSTATUS samba3_add_socket(struct task_server *task,
+                                 struct tevent_context *event_context,
                                  struct loadparm_context *lp_ctx,
                                  const struct model_ops *model_ops,
                                  const char *address)
@@ -98,7 +99,7 @@ static NTSTATUS samba3_add_socket(struct tevent_context *event_context,
        for (i=0;ports[i];i++) {
                uint16_t port = atoi(ports[i]);
                if (port == 0) continue;
-               status = stream_setup_socket(event_context, lp_ctx,
+               status = stream_setup_socket(task, event_context, lp_ctx,
                                             model_ops, &samba3_smb_stream_ops,
                                             "ip", address, &port,
                                             lpcfg_socket_options(lp_ctx),
@@ -142,14 +143,16 @@ static void samba3_smb_task_init(struct task_server *task)
                */
                for(i = 0; i < num_interfaces; i++) {
                        const char *address = iface_n_ip(ifaces, i);
-                       status = samba3_add_socket(task->event_ctx,
+                       status = samba3_add_socket(task,
+                                                  task->event_ctx,
                                                   task->lp_ctx,
                                                   model_ops, address);
                        if (!NT_STATUS_IS_OK(status)) goto failed;
                }
        } else {
                /* Just bind to lpcfg_socket_address() (usually 0.0.0.0) */
-               status = samba3_add_socket(task->event_ctx, task->lp_ctx,
+               status = samba3_add_socket(task,
+                                          task->event_ctx, task->lp_ctx,
                                           model_ops,
                                           lpcfg_socket_address(task->lp_ctx));
                if (!NT_STATUS_IS_OK(status)) goto failed;
index 8e54423706558bb27eaf10a68ae252f4ec214a55..d21e5fbdb072895e654775aeeea2813849f334fc 100644 (file)
@@ -175,10 +175,11 @@ static const struct stream_server_ops smb_stream_ops = {
 /*
   setup a listening socket on all the SMB ports for a particular address
 */
-_PUBLIC_ NTSTATUS smbsrv_add_socket(struct tevent_context *event_context,
+_PUBLIC_ NTSTATUS smbsrv_add_socket(TALLOC_CTX *mem_ctx,
+                                   struct tevent_context *event_context,
                                    struct loadparm_context *lp_ctx,
-                              const struct model_ops *model_ops,
-                              const char *address)
+                                   const struct model_ops *model_ops,
+                                   const char *address)
 {
        const char **ports = lpcfg_smb_ports(lp_ctx);
        int i;
@@ -187,7 +188,7 @@ _PUBLIC_ NTSTATUS smbsrv_add_socket(struct tevent_context *event_context,
        for (i=0;ports[i];i++) {
                uint16_t port = atoi(ports[i]);
                if (port == 0) continue;
-               status = stream_setup_socket(event_context, lp_ctx,
+               status = stream_setup_socket(mem_ctx, event_context, lp_ctx,
                                             model_ops, &smb_stream_ops, 
                                             "ipv4", address, &port, 
                                             lpcfg_socket_options(lp_ctx),
index 4399dc8c70fce24f9a6c48467be51e467f08ada2..6088853743bb941626bf5afc651e0fd33f799c1a 100644 (file)
@@ -395,10 +395,11 @@ struct smbsrv_connection {
 struct model_ops;
 struct loadparm_context;
 
-NTSTATUS smbsrv_add_socket(struct tevent_context *event_context,
+NTSTATUS smbsrv_add_socket(TALLOC_CTX *mem_ctx,
+                          struct tevent_context *event_context,
                           struct loadparm_context *lp_ctx,
-                              const struct model_ops *model_ops,
-                              const char *address);
+                          const struct model_ops *model_ops,
+                          const char *address);
 
 struct loadparm_context;
 
index f420e2bacbcb4f213ee32bf78d6273dbc302c207..25d37af8c4040dd120d4d0a3aba802502a835756 100644 (file)
@@ -289,7 +289,8 @@ static const struct stream_server_ops named_pipe_stream_ops = {
        .send_handler           = named_pipe_send,
 };
 
-NTSTATUS tstream_setup_named_pipe(struct tevent_context *event_context,
+NTSTATUS tstream_setup_named_pipe(TALLOC_CTX *mem_ctx,
+                                 struct tevent_context *event_context,
                                  struct loadparm_context *lp_ctx,
                                  const struct model_ops *model_ops,
                                  const struct stream_server_ops *stream_ops,
@@ -300,7 +301,7 @@ NTSTATUS tstream_setup_named_pipe(struct tevent_context *event_context,
        struct named_pipe_socket *pipe_sock;
        NTSTATUS status = NT_STATUS_NO_MEMORY;;
 
-       pipe_sock = talloc(event_context, struct named_pipe_socket);
+       pipe_sock = talloc(mem_ctx, struct named_pipe_socket);
        if (pipe_sock == NULL) {
                goto fail;
        }
@@ -338,7 +339,8 @@ NTSTATUS tstream_setup_named_pipe(struct tevent_context *event_context,
        pipe_sock->ops = stream_ops;
        pipe_sock->private_data = private_data;
 
-       status = stream_setup_socket(event_context,
+       status = stream_setup_socket(pipe_sock,
+                                    event_context,
                                     lp_ctx,
                                     model_ops,
                                     &named_pipe_stream_ops,
index 85efa34339bb9fd3a49900e602434999461080d8..916393253b877799649c967f0ebc2196a6fcb797 100644 (file)
@@ -255,7 +255,8 @@ static void stream_accept_handler(struct tevent_context *ev, struct tevent_fd *f
         a string for the port. Should leave allocating a port nr 
          to the socket implementation - JRV20070903
  */
-NTSTATUS stream_setup_socket(struct tevent_context *event_context,
+NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
+                            struct tevent_context *event_context,
                             struct loadparm_context *lp_ctx,
                             const struct model_ops *model_ops,
                             const struct stream_server_ops *stream_ops,
@@ -271,7 +272,7 @@ NTSTATUS stream_setup_socket(struct tevent_context *event_context,
        struct tevent_fd *fde;
        int i;
 
-       stream_socket = talloc_zero(event_context, struct stream_socket);
+       stream_socket = talloc_zero(mem_ctx, struct stream_socket);
        NT_STATUS_HAVE_NO_MEMORY(stream_socket);
 
        status = socket_create(family, SOCKET_TYPE_STREAM, &stream_socket->sock, 0);
index facfd3e52aab8bbc572937ad5f99d4e68d22dd15..a613e31a9ed1b5033e24e1989eaec5f20f2edea6 100644 (file)
@@ -464,7 +464,7 @@ static bool test_start_dcerpc_server(struct torture_context *tctx,
        torture_assert_ntstatus_ok(tctx, status,
                                   "unable to initialize process models");
 
-       status = smbsrv_add_socket(event_ctx, tctx->lp_ctx, process_model_startup("single"), address);
+       status = smbsrv_add_socket(tctx, event_ctx, tctx->lp_ctx, process_model_startup("single"), address);
        torture_assert_ntstatus_ok(tctx, status, "starting smb server");
 
        status = dcesrv_init_context(tctx, tctx->lp_ctx, endpoints, &dce_ctx);
index 97e65e5a475da7e658f4bb133e78866b47f38f8f..4cc2cb8d38f75414b241750be7341155e4e3b7f9 100644 (file)
@@ -320,7 +320,8 @@ static void websrv_task_init(struct task_server *task)
                num_interfaces = iface_count(ifaces);
                for(i = 0; i < num_interfaces; i++) {
                        const char *address = iface_n_ip(ifaces, i);
-                       status = stream_setup_socket(task->event_ctx, 
+                       status = stream_setup_socket(task,
+                                                    task->event_ctx,
                                                     task->lp_ctx, model_ops,
                                                     &web_stream_ops, 
                                                     "ipv4", address, 
@@ -331,7 +332,7 @@ static void websrv_task_init(struct task_server *task)
 
                talloc_free(ifaces);
        } else {
-               status = stream_setup_socket(task->event_ctx, task->lp_ctx,
+               status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
                                             model_ops, &web_stream_ops, 
                                             "ipv4", lpcfg_socket_address(task->lp_ctx),
                                             &port, lpcfg_socket_options(task->lp_ctx), task);
index 34d145d318ef098f5715e8b3f0c4eb7b1ab4eb4d..5390dab2f7f0e864877e695157c66384ffcac105 100644 (file)
@@ -299,7 +299,7 @@ static void winbind_task_init(struct task_server *task)
        if (!listen_socket->socket_path) goto nomem;
        listen_socket->service          = service;
        listen_socket->privileged       = false;
-       status = stream_setup_socket(task->event_ctx, task->lp_ctx, model_ops,
+       status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, model_ops,
                                     &wbsrv_ops, "unix",
                                     listen_socket->socket_path, &port,
                                     lpcfg_socket_options(task->lp_ctx),
@@ -316,7 +316,7 @@ static void winbind_task_init(struct task_server *task)
        if (!listen_socket->socket_path) goto nomem;
        listen_socket->service          = service;
        listen_socket->privileged       = true;
-       status = stream_setup_socket(task->event_ctx, task->lp_ctx, model_ops,
+       status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, model_ops,
                                     &wbsrv_ops, "unix",
                                     listen_socket->socket_path, &port,
                                     lpcfg_socket_options(task->lp_ctx),
index 632c9a9a5b2e604f33caea60d583e36bfdac11ba..3e2faa23e5f868c412c88f9292c8da513033b914 100644 (file)
@@ -451,7 +451,7 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar
                */
                for(i = 0; i < num_interfaces; i++) {
                        address = iface_n_ip(ifaces, i);
-                       status = stream_setup_socket(task->event_ctx, 
+                       status = stream_setup_socket(task, task->event_ctx,
                                                     task->lp_ctx, model_ops,
                                                     &wreplsrv_stream_ops,
                                                     "ipv4", address, &port, 
@@ -465,7 +465,7 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar
                }
        } else {
                address = lpcfg_socket_address(lp_ctx);
-               status = stream_setup_socket(task->event_ctx, task->lp_ctx,
+               status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
                                             model_ops, &wreplsrv_stream_ops,
                                             "ipv4", address, &port, lpcfg_socket_options(task->lp_ctx),
                                             service);