[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Jan 14 14:36:01 UTC 2021


The branch, master has been updated
       via  9bb5b326210 rpc_server: Remove protocol-specific dcerpc_setup_ routines
       via  8004fb4a5bf rpc_server: Use dcesrv_setup_ncacn_listener() in dcesrv_setup_endpoint_sockets()
       via  94f48f34f16 rpc_server: Add dcesrv_setup_ncacn_listener()
       via  6482bee22fe rpc_server: Move setting ip-based socket options
       via  50dada72ad9 rpc_server: Direct pointer initialization in dcesrv_ncacn_np_accept_done()
       via  cc9ade9b0a5 lib: Initialize variables in prefork_listen_accept_handler()
       via  834f9e152e5 lib: Fix typos
       via  33f7aac8719 rpc_server: Make dcerpc_ncacn_accept() take tsocket_address **
       via  51f5631bbb3 tsocket: Fix a few typos
       via  a21867bc48b rpc_server: Remove unused make_server_pipes_struct()
       via  562e48655cc rpc_server: Use make_base_pipes_struct() in make_internal_rpc_pipe_socketpair()
       via  8488b16f568 rpc_server: Use make_base_pipes_struct() in dcesrv_ncacn_accept_step2()
       via  dcc8f37af14 rpc_server: Simplify find_policy_by_hnd_internal()
       via  acca9ec4b60 vfs_fruit: Fix CID 1471764 Dereference null return value
       via  8d5fb1ad14d vfs_fruit: Fix CID 1471760 Dereference null return value
       via  5ef25729bd9 tdb: Fix CID 1471761 String not null terminated
      from  da052dde8a9 s3:smbd: simplify the error handling in create_file_unixpath()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 9bb5b3262102c99bf5bb881135739feffacd7108
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 17:53:57 2021 +0100

    rpc_server: Remove protocol-specific dcerpc_setup_ routines
    
    These are all just stream sockets, being taken care of by
    dcesrv_setup_ncacn_listener()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Thu Jan 14 14:35:58 UTC 2021 on sn-devel-184

commit 8004fb4a5bfa00d3199c11e8aadeb9691c0484e8
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 17:36:44 2021 +0100

    rpc_server: Use dcesrv_setup_ncacn_listener() in dcesrv_setup_endpoint_sockets()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 94f48f34f167c3665b9945cc9c9d499df64fab31
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 16:48:25 2021 +0100

    rpc_server: Add dcesrv_setup_ncacn_listener()
    
    This is supposed to replace the protocol-specific dcerpc_setup_*
    functions. They are all very similar except the way to create the
    socket file descriptor. By handing out the anonymous structure
    "listen_state" for an error path the listener tevent_fd structs can be
    cancelled individually or handed over to other talloc parents.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 6482bee22fe421266ea493d18367aa2a0444ef76
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 17:03:42 2021 +0100

    rpc_server: Move setting ip-based socket options
    
    All ncacn_ip_tcp listener sockets are created via
    dcesrv_create_ncacn_ip_tcp_socket(). Moving setting the socket options
    out of dcesrv_setup_ncacn_ip_tcp_socket() to remove a special case for
    TCP from the dcesrv_setup_* family of routines.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 50dada72ad97cffef25011a57fa6cc5bce80c5d4
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 16:57:59 2021 +0100

    rpc_server: Direct pointer initialization in dcesrv_ncacn_np_accept_done()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit cc9ade9b0a5a52cb468976b51dffbfad73ef5118
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jan 11 15:36:11 2021 +0100

    lib: Initialize variables in prefork_listen_accept_handler()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 834f9e152e5f81bd8d128bd627fce3b83d3ebb0b
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jan 11 15:23:41 2021 +0100

    lib: Fix typos
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 33f7aac8719a5de9a3dc01cda70b190c1a824a53
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 09:26:24 2021 +0100

    rpc_server: Make dcerpc_ncacn_accept() take tsocket_address **
    
    dcerpc_ncacn_accept() talloc_move's the addresses away from the
    caller's talloc hierarchy. Don't leave pointers around in the caller.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 51f5631bbb3801d320127ea4a90403cb074c0095
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 09:25:45 2021 +0100

    tsocket: Fix a few typos
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit a21867bc48b6a78d8bfa040e850a6b59b2af7860
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jan 11 21:37:08 2021 +0100

    rpc_server: Remove unused make_server_pipes_struct()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 562e48655ccc583fdb7c90ae509b092abc634a4d
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jan 11 21:35:26 2021 +0100

    rpc_server: Use make_base_pipes_struct() in make_internal_rpc_pipe_socketpair()
    
    make_server_pipes_struct() is just a simple wrapper.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 8488b16f568f3b4c778f186cea1b9044947319ed
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jan 11 21:32:52 2021 +0100

    rpc_server: Use make_base_pipes_struct() in dcesrv_ncacn_accept_step2()
    
    make_server_pipes_struct() is just a simple wrapper.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit dcc8f37af148df11ebc848013933967da45b0698
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jan 11 21:25:40 2021 +0100

    rpc_server: Simplify find_policy_by_hnd_internal()
    
    Best viewed with "git show -b". Use the typical pattern of an early
    error return.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit acca9ec4b606173c85809bbc0894011c0e29bab0
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 11:24:38 2021 +0100

    vfs_fruit: Fix CID 1471764 Dereference null return value
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 8d5fb1ad14dfda2722243378a5afa8af5d743b2a
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 11:22:57 2021 +0100

    vfs_fruit: Fix CID 1471760 Dereference null return value
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

commit 5ef25729bd9e6dc455d158c0016b2bd6191e8d51
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 12 11:19:54 2021 +0100

    tdb: Fix CID 1471761 String not null terminated
    
    This is a false positive (in is length 3 initialized to 0), but this
    patch does not hurt
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Samuel Cabrero <scabrero at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/tdb/tools/tdbrestore.c             |   2 +-
 lib/tsocket/tsocket_guide.txt          |   6 +-
 source3/lib/server_prefork.c           |   6 +-
 source3/lib/server_prefork.h           |   6 +-
 source3/modules/vfs_fruit.c            |   6 +-
 source3/printing/spoolssd.c            |   4 +-
 source3/rpc_server/lsasd.c             |   4 +-
 source3/rpc_server/mdssd.c             |   4 +-
 source3/rpc_server/rpc_handles.c       |  27 +-
 source3/rpc_server/rpc_ncacn_np.c      |  20 +-
 source3/rpc_server/rpc_server.c        | 523 +++++++--------------------------
 source3/rpc_server/rpc_server.h        |  44 +--
 source3/rpc_server/rpc_service_setup.c | 111 ++++---
 source3/rpc_server/rpc_sock_helper.c   |  43 ---
 source3/rpc_server/rpc_sock_helper.h   |   7 -
 15 files changed, 239 insertions(+), 574 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tdb/tools/tdbrestore.c b/lib/tdb/tools/tdbrestore.c
index 3312cf74d83..1435758b580 100644
--- a/lib/tdb/tools/tdbrestore.c
+++ b/lib/tdb/tools/tdbrestore.c
@@ -89,7 +89,7 @@ static int read_data(FILE *f, TDB_DATA *d, size_t size) {
 			}
 			ok = hex_byte(in, &d->dptr[i]);
 			if (!ok) {
-				fprintf(stderr, "Invalid hex: %s\n", in);
+				fprintf(stderr, "Invalid hex: .2%s\n", in);
 				return -1;
 			}
 		} else {
diff --git a/lib/tsocket/tsocket_guide.txt b/lib/tsocket/tsocket_guide.txt
index 9a96b0432bd..afd0bd37dbc 100644
--- a/lib/tsocket/tsocket_guide.txt
+++ b/lib/tsocket/tsocket_guide.txt
@@ -3,7 +3,7 @@ Basic design of the tsocket abstraction
 =======================================
 
 The tsocket abstraction is split into two
-different kinds of communitation interfaces.
+different kinds of communication interfaces.
 
 There is the "tstream_context" interface which abstracts
 the communication through a bidirectional
@@ -30,12 +30,12 @@ Constructors are described in later sections of this document.
 A function to get the string representation of an endpoint for debugging is
 available but callers SHOULD NOT try to parse this string. To get more
 details, callers should use getter methods of the specific tsocket_address
-implemention.
+implementation.
 
   char *tsocket_address_string(const struct tsocket_address *addr,
       TALLOC_CTX *mem_ctx);
 
-A function to create a copy of the tsocket_address is also avilable.
+A function to create a copy of the tsocket_address is also available.
 This is useful before doing modifications to a socket
 via additional methods of the specific tsocket_address implementation.
 
diff --git a/source3/lib/server_prefork.c b/source3/lib/server_prefork.c
index 344bff0efa2..2fb13c90fee 100644
--- a/source3/lib/server_prefork.c
+++ b/source3/lib/server_prefork.c
@@ -587,8 +587,8 @@ static void prefork_listen_accept_handler(struct tevent_context *ev,
 	struct tevent_req *req = ctx->req;
 	struct pf_listen_state *state = tevent_req_data(
 		ctx->req, struct pf_listen_state);
-	struct sockaddr_storage addr;
-	socklen_t addrlen;
+	struct sockaddr_storage addr = { .ss_family = 0 };
+	socklen_t addrlen = sizeof(addr);
 	int soerr = 0;
 	socklen_t solen = sizeof(soerr);
 	int sd = -1;
@@ -616,8 +616,6 @@ static void prefork_listen_accept_handler(struct tevent_context *ev,
 		goto done;
 	}
 
-	ZERO_STRUCT(addr);
-	addrlen = sizeof(addr);
 	sd = accept(ctx->listen_fd, (struct sockaddr *)&addr, &addrlen);
 	if (sd == -1) {
 		state->error = errno;
diff --git a/source3/lib/server_prefork.h b/source3/lib/server_prefork.h
index 179bbc0dff0..106ffdb3729 100644
--- a/source3/lib/server_prefork.h
+++ b/source3/lib/server_prefork.h
@@ -127,7 +127,7 @@ typedef void (prefork_sigchld_fn_t)(struct tevent_context *ev_ctx,
 * @return True if it was successful, False otherwise.
 *
 * NOTE: each listen_fd is forced to non-blocking mode once handed over.
-* You should not toush listen_fds once you hand the to the prefork library.
+* You should not touch listen_fds once you hand them to the prefork library.
 */
 bool prefork_create_pool(TALLOC_CTX *mem_ctx,
 			 struct tevent_context *ev_ctx,
@@ -227,7 +227,7 @@ void prefork_increase_allowed_clients(struct prefork_pool *pfp, int max);
 void prefork_decrease_allowed_clients(struct prefork_pool *pfp);
 
 /**
-* @brief Reset the maximum allowd clients per child to 1.
+* @brief Reset the maximum allowed clients per child to 1.
 *	 Does not reduce the number of clients actually beeing served by
 *	 any given child, but prevents children from overcommitting from
 *	 now on.
@@ -271,7 +271,7 @@ void prefork_set_sigchld_callback(struct prefork_pool *pfp,
 
 /**
 * @brief Try to listen and accept on one of the listening sockets.
-*	 Asynchronusly tries to grab the lock and perform an accept.
+*	 Asynchronously tries to grab the lock and perform an accept.
 *	 Will automatically update the 'status' of the child and handle
 *	 all the locking/unlocking/timingout as necessary.
 *	 Changes behavior depending on whether the child already has other
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index ecacaf5fc41..b25aebfa9ac 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -1668,6 +1668,10 @@ static int fruit_close_meta(vfs_handle_struct *handle,
 	SMB_VFS_HANDLE_GET_DATA(handle, config,
 				struct fruit_config_data, return -1);
 
+	if (fio == NULL) {
+		return -1;
+	}
+
 	switch (config->meta) {
 	case FRUIT_META_STREAM:
 		if (fio->fake_fd) {
@@ -2132,7 +2136,7 @@ static ssize_t fruit_pread_meta_stream(vfs_handle_struct *handle,
 	ssize_t nread;
 	int ret;
 
-	if (fio->fake_fd) {
+	if ((fio == NULL) || fio->fake_fd) {
 		return -1;
 	}
 
diff --git a/source3/printing/spoolssd.c b/source3/printing/spoolssd.c
index 8aef363fa91..67cd20684fd 100644
--- a/source3/printing/spoolssd.c
+++ b/source3/printing/spoolssd.c
@@ -430,8 +430,8 @@ static void spoolss_handle_client(struct tevent_req *req)
 			    data->msg_ctx,
 			    data->dce_ctx,
 			    ep,
-			    cli_addr,
-			    srv_addr,
+			    &cli_addr,
+			    &srv_addr,
 			    sd,
 			    spoolss_client_terminated,
 			    data);
diff --git a/source3/rpc_server/lsasd.c b/source3/rpc_server/lsasd.c
index a5cc1dad17d..93317688ce8 100644
--- a/source3/rpc_server/lsasd.c
+++ b/source3/rpc_server/lsasd.c
@@ -439,8 +439,8 @@ static void lsasd_handle_client(struct tevent_req *req)
 			    data->msg_ctx,
 			    data->dce_ctx,
 			    ep,
-			    cli_addr,
-			    srv_addr,
+			    &cli_addr,
+			    &srv_addr,
 			    sd,
 			    term_fn,
 			    term_fn_data);
diff --git a/source3/rpc_server/mdssd.c b/source3/rpc_server/mdssd.c
index 0c44b010aae..aec5c082b0b 100644
--- a/source3/rpc_server/mdssd.c
+++ b/source3/rpc_server/mdssd.c
@@ -389,8 +389,8 @@ static void mdssd_handle_client(struct tevent_req *req)
 			    data->msg_ctx,
 			    data->dce_ctx,
 			    ep,
-			    cli_addr,
-			    srv_addr,
+			    &cli_addr,
+			    &srv_addr,
 			    sd,
 			    term_fn,
 			    term_fn_data);
diff --git a/source3/rpc_server/rpc_handles.c b/source3/rpc_server/rpc_handles.c
index d897e0caabe..45968746440 100644
--- a/source3/rpc_server/rpc_handles.c
+++ b/source3/rpc_server/rpc_handles.c
@@ -153,22 +153,23 @@ static struct dcesrv_handle *find_policy_by_hnd_internal(
 	 * pipes_struct if the handle type does not match
 	 */
 	h = dcesrv_handle_lookup(p->dce_call, hnd, DCESRV_HANDLE_ANY);
-	if (h != NULL) {
-		if (handle_type != DCESRV_HANDLE_ANY &&
-			h->wire_handle.handle_type != handle_type) {
-			/* Just return NULL, do not set a fault
-			 * state in pipes_struct */
-			return NULL;
-		}
-		if (data_p) {
-			*data_p = h->data;
-		}
-		return h;
+	if (h == NULL) {
+		p->fault_state = DCERPC_FAULT_CONTEXT_MISMATCH;
+		return NULL;
+	}
+
+	if (handle_type != DCESRV_HANDLE_ANY &&
+	    h->wire_handle.handle_type != handle_type) {
+		/* Just return NULL, do not set a fault
+		 * state in pipes_struct */
+		return NULL;
 	}
 
-	p->fault_state = DCERPC_FAULT_CONTEXT_MISMATCH;
+	if (data_p) {
+		*data_p = h->data;
+	}
 
-	return NULL;
+	return h;
 }
 
 /****************************************************************************
diff --git a/source3/rpc_server/rpc_ncacn_np.c b/source3/rpc_server/rpc_ncacn_np.c
index d80c62e75d7..9ba271c2479 100644
--- a/source3/rpc_server/rpc_ncacn_np.c
+++ b/source3/rpc_server/rpc_ncacn_np.c
@@ -99,7 +99,6 @@ NTSTATUS make_internal_rpc_pipe_socketpair(
 	struct dcesrv_connection *dcesrv_conn = NULL;
 	struct npa_state *npa;
 	NTSTATUS status;
-	int error;
 	int rc;
 	enum dcerpc_transport_t transport = dcerpc_binding_get_transport(
 			endpoint->ep_description);
@@ -176,16 +175,15 @@ NTSTATUS make_internal_rpc_pipe_socketpair(
 		goto out;
 	}
 
-	rc = make_server_pipes_struct(ncacn_conn,
-				      ncacn_conn->msg_ctx,
-				      pipe_name,
-				      transport,
-				      ncacn_conn->remote_client_addr,
-				      ncacn_conn->local_server_addr,
-				      &ncacn_conn->p,
-				      &error);
-	if (rc == -1) {
-		status = map_nt_error_from_unix(error);
+	rc = make_base_pipes_struct(ncacn_conn,
+				    ncacn_conn->msg_ctx,
+				    pipe_name,
+				    transport,
+				    ncacn_conn->remote_client_addr,
+				    ncacn_conn->local_server_addr,
+				    &ncacn_conn->p);
+	if (rc != 0) {
+		status = map_nt_error_from_unix(rc);
 		goto out;
 	}
 
diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c
index e65d4a1b7c6..20b727b64df 100644
--- a/source3/rpc_server/rpc_server.c
+++ b/source3/rpc_server/rpc_server.c
@@ -38,32 +38,6 @@
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
 
-/* Creates a pipes_struct and initializes it with the information
- * sent from the client */
-int make_server_pipes_struct(TALLOC_CTX *mem_ctx,
-			     struct messaging_context *msg_ctx,
-			     const char *pipe_name,
-			     enum dcerpc_transport_t transport,
-			     const struct tsocket_address *remote_address,
-			     const struct tsocket_address *local_address,
-			     struct pipes_struct **_p,
-			     int *perrno)
-{
-	struct pipes_struct *p;
-	int ret;
-
-	ret = make_base_pipes_struct(mem_ctx, msg_ctx, pipe_name,
-				     transport,
-				     remote_address, local_address, &p);
-	if (ret) {
-		*perrno = ret;
-		return -1;
-	}
-
-	*_p = p;
-	return 0;
-}
-
 /* Start listening on the appropriate unix socket and setup all is needed to
  * dispatch requests to the pipes rpc implementation */
 
@@ -78,11 +52,6 @@ struct dcerpc_ncacn_listen_state {
 	void *termination_data;
 };
 
-static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
-				     struct tevent_fd *fde,
-				     uint16_t flags,
-				     void *private_data);
-
 NTSTATUS dcesrv_create_ncacn_np_socket(struct dcesrv_endpoint *e, int *out_fd)
 {
 	char *np_dir = NULL;
@@ -158,142 +127,10 @@ out:
 	return status;
 }
 
-NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
-				      struct messaging_context *msg_ctx,
-				      struct dcesrv_context *dce_ctx,
-				      struct dcesrv_endpoint *e,
-				      dcerpc_ncacn_termination_fn term_fn,
-				      void *term_data)
-{
-	struct dcerpc_ncacn_listen_state *state;
-	struct tevent_fd *fde;
-	int rc;
-	NTSTATUS status;
-	const char *endpoint = NULL;
-
-	endpoint = dcerpc_binding_get_string_option(e->ep_description,
-						    "endpoint");
-	if (endpoint == NULL) {
-		DBG_ERR("Endpoint mandatory for named pipes\n");
-		return NT_STATUS_INVALID_PARAMETER;
-	}
-
-	/* 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 */
-	state = talloc_zero(e, struct dcerpc_ncacn_listen_state);
-	if (state == NULL) {
-		DBG_ERR("Out of memory\n");
-		return NT_STATUS_NO_MEMORY;
-	}
-	state->fd = -1;
-	state->ev_ctx = ev_ctx;
-	state->msg_ctx = msg_ctx;
-	state->endpoint = e;
-	state->dce_ctx = dce_ctx;
-	state->termination_fn = term_fn;
-	state->termination_data = term_data;
-
-	status = dcesrv_create_ncacn_np_socket(e, &state->fd);
-	if (!NT_STATUS_IS_OK(status)) {
-		goto out;
-	}
-
-	rc = listen(state->fd, 5);
-	if (rc < 0) {
-		status = map_nt_error_from_unix_common(errno);
-		DBG_ERR("Failed to listen on ncacn_np socket %s: %s\n",
-			endpoint, strerror(errno));
-		goto out;
-	}
-
-	DBG_DEBUG("Opened pipe socket fd %d for %s\n",
-		  state->fd, endpoint);
-
-	errno = 0;
-	fde = tevent_add_fd(ev_ctx,
-			    state, state->fd, TEVENT_FD_READ,
-			    dcesrv_ncacn_np_listener, state);
-	if (fde == NULL) {
-		if (errno == 0) {
-			errno = ENOMEM;
-		}
-		status = map_nt_error_from_unix_common(errno);
-		DBG_ERR("Failed to add event handler for ncacn_np: %s\n",
-			strerror(errno));
-		goto out;
-	}
-
-	tevent_fd_set_auto_close(fde);
-
-	return NT_STATUS_OK;
-
-out:
-	if (state->fd != -1) {
-		close(state->fd);
-	}
-	TALLOC_FREE(state);
-	return status;
-}
-
-static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
-				     struct tevent_fd *fde,
-				     uint16_t flags,
-				     void *private_data)
-{
-	struct dcerpc_ncacn_listen_state *state =
-			talloc_get_type_abort(private_data,
-					      struct dcerpc_ncacn_listen_state);
-	struct samba_sockaddr addr = {
-		.sa_socklen = sizeof(struct sockaddr_un),
-	};
-	int sd = -1;
-	const char *endpoint = NULL;
-
-	/* TODO: should we have a limit to the number of clients ? */
-
-	sd = accept(state->fd, &addr.u.sa, &addr.sa_socklen);
-
-	if (sd == -1) {
-		if (errno != EINTR) {
-			DEBUG(6, ("Failed to get a valid socket [%s]\n",
-				  strerror(errno)));
-		}
-		return;
-	}
-	smb_set_close_on_exec(sd);
-
-	endpoint = dcerpc_binding_get_string_option(
-			state->endpoint->ep_description, "endpoint");
-	if (endpoint == NULL) {
-		DBG_ERR("Failed to get endpoint from binding description\n");
-		close(sd);
-		return;
-	}
-
-	DBG_DEBUG("Accepted ncacn_np socket %s (fd: %d)\n",
-		   addr.u.un.sun_path, sd);
-
-	dcerpc_ncacn_accept(state->ev_ctx,
-			    state->msg_ctx,
-			    state->dce_ctx,
-			    state->endpoint,
-			    NULL, /* remote client address */
-			    NULL, /* local server address */
-			    sd,
-			    state->termination_fn,
-			    state->termination_data);
-}
-
 /********************************************************************
  * Start listening on the tcp/ip socket
  ********************************************************************/
 
-static void dcesrv_ncacn_ip_tcp_listener(struct tevent_context *ev,
-					 struct tevent_fd *fde,
-					 uint16_t flags,
-					 void *private_data);
-
 NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(const struct sockaddr_storage *ifss,
 					   uint16_t *port,
 					   int *out_fd)
@@ -326,157 +163,21 @@ NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(const struct sockaddr_storage *ifss,
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	DBG_DEBUG("Opened ncacn_ip_tcp socket fd %d for port %u\n", fd, *port);
-
-	*out_fd = fd;
-
-	return NT_STATUS_OK;
-}
-
-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,
-					  int fd,
-					  dcerpc_ncacn_termination_fn term_fn,
-					  void *term_data)
-{
-	struct dcerpc_ncacn_listen_state *state = NULL;
-	struct tevent_fd *fde = NULL;
-	int rc;
-	NTSTATUS status;
-
-	/* 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 */
-	state = talloc_zero(e, struct dcerpc_ncacn_listen_state);
-	if (state == NULL) {
-		DBG_ERR("Out of memory\n");
-		return NT_STATUS_NO_MEMORY;
-	}
-
-	state->fd = fd;
-	state->ev_ctx = ev_ctx;
-	state->msg_ctx = msg_ctx;
-	state->endpoint = e;
-	state->dce_ctx = dce_ctx;
-	state->termination_fn = term_fn;
-	state->termination_data = term_data;
-
 	/* ready to listen */
-	set_socket_options(state->fd, "SO_KEEPALIVE");
-	set_socket_options(state->fd, lp_socket_options());
-
-	/* Set server socket to non-blocking for the accept. */
-	rc = set_blocking(state->fd, false);
-	if (rc < 0) {
-		status = map_nt_error_from_unix_common(errno);
-		goto out;
-	}
-
-	rc = listen(state->fd, SMBD_LISTEN_BACKLOG);
-	if (rc == -1) {
-		status = map_nt_error_from_unix_common(errno);
-		DBG_ERR("Failed to listen on ncacn_ip_tcp socket: %s\n",
-			strerror(errno));
-		goto out;
-	}
+	set_socket_options(fd, "SO_KEEPALIVE");
+	set_socket_options(fd, lp_socket_options());
 
-	errno = 0;
-	fde = tevent_add_fd(state->ev_ctx,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list