1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-30 17:49:30 +03:00

rpc_server: Consolidate transport-specific socket creation

We had the transport switch in two places, put them together into
dcesrv_create_binding_sockets(). This makes the transport-specific
socket creation functions static to rpc_sock_helper.c.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke
2021-01-16 22:40:37 +01:00
committed by Jeremy Allison
parent 125c605ea5
commit d4e46cae4c
3 changed files with 59 additions and 64 deletions

View File

@ -93,7 +93,6 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
int **pfds) int **pfds)
{ {
struct dcerpc_binding *b = e->ep_description; struct dcerpc_binding *b = e->ep_description;
enum dcerpc_transport_t transport = dcerpc_binding_get_transport(b);
char *binding = NULL; char *binding = NULL;
int *fds = NULL; int *fds = NULL;
size_t num_fds; size_t num_fds;
@ -106,33 +105,7 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
DBG_DEBUG("Creating endpoint '%s'\n", binding); DBG_DEBUG("Creating endpoint '%s'\n", binding);
TALLOC_FREE(binding); TALLOC_FREE(binding);
fds = talloc(mem_ctx, int); status = dcesrv_create_binding_sockets(b, mem_ctx, &num_fds, &fds);
if (fds == NULL) {
return NT_STATUS_NO_MEMORY;
}
num_fds = 1;
switch (transport) {
case NCALRPC:
status = dcesrv_create_ncalrpc_socket(b, fds);
break;
case NCACN_IP_TCP: {
TALLOC_FREE(fds);
status = dcesrv_create_ncacn_ip_tcp_sockets(
b, talloc_tos(), &num_fds, &fds);
break;
}
case NCACN_NP:
status = dcesrv_create_ncacn_np_socket(b, fds);
break;
default:
status = NT_STATUS_NOT_SUPPORTED;
break;
}
/* Build binding string again as the endpoint may have changed by /* Build binding string again as the endpoint may have changed by
* dcesrv_create_<transport>_socket functions */ * dcesrv_create_<transport>_socket functions */
@ -250,47 +223,27 @@ NTSTATUS dcesrv_setup_endpoint_sockets(struct tevent_context *ev_ctx,
void *term_data) void *term_data)
{ {
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
enum dcerpc_transport_t transport = struct dcerpc_binding *b = e->ep_description;
dcerpc_binding_get_transport(e->ep_description);
char *binding = NULL; char *binding = NULL;
NTSTATUS status = NT_STATUS_NO_MEMORY; NTSTATUS status = NT_STATUS_NO_MEMORY;
struct dcesrv_if_list *iface = NULL; struct dcesrv_if_list *iface = NULL;
int fd = -1; int *fds = NULL;
int *fds = &fd; size_t i, num_fds = 0;
size_t i, num_fds = 1;
struct dcerpc_ncacn_listen_state **listen_states = NULL; struct dcerpc_ncacn_listen_state **listen_states = NULL;
binding = dcerpc_binding_string(frame, e->ep_description); binding = dcerpc_binding_string(frame, b);
if (binding == NULL) { if (binding == NULL) {
goto fail; goto fail;
} }
DBG_DEBUG("Setting up endpoint '%s'\n", binding); DBG_DEBUG("Setting up endpoint '%s'\n", binding);
TALLOC_FREE(binding);
switch (transport) { status = dcesrv_create_binding_sockets(b, frame, &num_fds, &fds);
case NCALRPC:
status = dcesrv_create_ncalrpc_socket(e->ep_description, &fd);
break;
case NCACN_IP_TCP:
status = dcesrv_create_ncacn_ip_tcp_sockets(
e->ep_description, frame, &num_fds, &fds);
break;
case NCACN_NP:
status = dcesrv_create_ncacn_np_socket(
e->ep_description, &fd);
break;
default:
status = NT_STATUS_NOT_SUPPORTED;
break;
}
/* Build binding string again as the endpoint may have changed by /* Build binding string again as the endpoint may have changed by
* dcesrv_create_<transport>_socket functions */ * dcesrv_create_<transport>_socket functions */
TALLOC_FREE(binding); binding = dcerpc_binding_string(frame, b);
binding = dcerpc_binding_string(frame, e->ep_description);
if (binding == NULL) { if (binding == NULL) {
status = NT_STATUS_NO_MEMORY; status = NT_STATUS_NO_MEMORY;
goto fail; goto fail;

View File

@ -32,7 +32,8 @@
#undef DBGC_CLASS #undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV #define DBGC_CLASS DBGC_RPC_SRV
NTSTATUS dcesrv_create_ncacn_np_socket(struct dcerpc_binding *b, int *out_fd) static NTSTATUS dcesrv_create_ncacn_np_socket(
struct dcerpc_binding *b, int *out_fd)
{ {
char *np_dir = NULL; char *np_dir = NULL;
int fd = -1; int fd = -1;
@ -152,7 +153,7 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(
return NT_STATUS_OK; return NT_STATUS_OK;
} }
NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets( static NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
struct dcerpc_binding *b, struct dcerpc_binding *b,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
size_t *pnum_fds, size_t *pnum_fds,
@ -276,7 +277,8 @@ fail:
* Start listening on the ncalrpc socket * Start listening on the ncalrpc socket
********************************************************************/ ********************************************************************/
NTSTATUS dcesrv_create_ncalrpc_socket(struct dcerpc_binding *b, int *out_fd) static NTSTATUS dcesrv_create_ncalrpc_socket(
struct dcerpc_binding *b, int *out_fd)
{ {
int fd = -1; int fd = -1;
const char *endpoint = NULL; const char *endpoint = NULL;
@ -338,4 +340,48 @@ out:
return status; return status;
} }
NTSTATUS dcesrv_create_binding_sockets(
struct dcerpc_binding *b,
TALLOC_CTX *mem_ctx,
size_t *pnum_fds,
int **pfds)
{
enum dcerpc_transport_t transport = dcerpc_binding_get_transport(b);
size_t num_fds = 1;
int *fds = NULL;
NTSTATUS status;
if ((transport == NCALRPC) || (transport == NCACN_NP)) {
fds = talloc(mem_ctx, int);
if (fds == NULL) {
return NT_STATUS_NO_MEMORY;
}
}
switch(transport) {
case NCALRPC:
status = dcesrv_create_ncalrpc_socket(b, fds);
break;
case NCACN_NP:
status = dcesrv_create_ncacn_np_socket(b, fds);
break;
case NCACN_IP_TCP:
status = dcesrv_create_ncacn_ip_tcp_sockets(
b, talloc_tos(), &num_fds, &fds);
break;
default:
status = NT_STATUS_NOT_SUPPORTED;
break;
}
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(fds);
return status;
}
*pfds = fds;
*pnum_fds = num_fds;
return NT_STATUS_OK;
}
/* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */ /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */

View File

@ -25,15 +25,11 @@
#include "rpc_server.h" #include "rpc_server.h"
struct pf_listen_fd; NTSTATUS dcesrv_create_binding_sockets(
NTSTATUS dcesrv_create_ncacn_np_socket(struct dcerpc_binding *b, int *out_fd);
NTSTATUS dcesrv_create_ncalrpc_socket(struct dcerpc_binding *b, int *fd);
NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
struct dcerpc_binding *b, struct dcerpc_binding *b,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
size_t *pnum_fds, size_t *pnum_fds,
int **pfds); int **fds);
#endif /* _RPC_SOCK_HELPER_H_ */ #endif /* _RPC_SOCK_HELPER_H_ */