1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s3:rpc_server: Unify RPC client disconnect and termination functions

These functions are used by endpoint mapper to delete the endpoints
when a NCALRPC connection from an external daemon is lost and by
preforked childs to accept the next client as soon as the current
connection terminates. We can use the same function for both purposes.

Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
Samuel Cabrero 2019-02-18 20:28:05 +01:00 committed by Stefan Metzmacher
parent 5865cf4dd9
commit cdaf06abad
9 changed files with 22 additions and 42 deletions

View File

@ -368,7 +368,7 @@ static int spoolss_children_main(struct tevent_context *ev_ctx,
return ret;
}
static void spoolss_client_terminated(void *pvt)
static void spoolss_client_terminated(struct pipes_struct *p, void *pvt)
{
struct spoolss_children_data *data;
@ -455,7 +455,6 @@ static void spoolss_handle_client(struct tevent_req *req)
cli_addr,
srv_addr,
sd,
NULL, /* disconnect function */
spoolss_client_terminated,
data);
}

View File

@ -306,7 +306,7 @@ static bool is_privileged_pipe(struct auth_session_info *info) {
return true;
}
bool srv_epmapper_delete_endpoints(struct pipes_struct *p)
void srv_epmapper_delete_endpoints(struct pipes_struct *p, void *private_data)
{
struct epm_Delete r;
struct dcesrv_ep_entry_list *el = p->ep_entries;
@ -323,7 +323,8 @@ bool srv_epmapper_delete_endpoints(struct pipes_struct *p)
result = _epm_Delete(p, &r);
if (result != EPMAPPER_STATUS_OK) {
return false;
DBG_ERR("Failed to delete endpoint maps\n");
return;
}
DLIST_REMOVE(p->ep_entries, el);
@ -331,8 +332,6 @@ bool srv_epmapper_delete_endpoints(struct pipes_struct *p)
el = next;
}
return true;
}
void srv_epmapper_cleanup(void)

View File

@ -27,7 +27,11 @@
*/
void srv_epmapper_cleanup(void);
bool srv_epmapper_delete_endpoints(struct pipes_struct *p);
/**
* @brief Cleanup function used to delete endpoints when a ncalrpc connection
* from an external daemon is lost
*/
void srv_epmapper_delete_endpoints(struct pipes_struct *p, void *private_data);
#endif /*_SRV_EPMAPPER_H_ */

View File

@ -195,7 +195,8 @@ void start_epmd(struct tevent_context *ev_ctx,
status = dcesrv_setup_ncalrpc_socket(ev_ctx,
msg_ctx,
"EPMAPPER",
srv_epmapper_delete_endpoints);
srv_epmapper_delete_endpoints,
NULL);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Failed to open epmd ncalrpc pipe!\n"));
exit(1);

View File

@ -346,7 +346,7 @@ static int lsasd_children_main(struct tevent_context *ev_ctx,
return ret;
}
static void lsasd_client_terminated(void *pvt)
static void lsasd_client_terminated(struct pipes_struct *p, void *pvt)
{
struct lsasd_children_data *data;
@ -451,7 +451,6 @@ static void lsasd_handle_client(struct tevent_req *req)
cli_addr,
srv_addr,
sd,
NULL, /* disconnect function */
lsasd_client_terminated,
data);
} else if (tsocket_address_is_unix(srv_addr)) {
@ -479,7 +478,6 @@ static void lsasd_handle_client(struct tevent_req *req)
NULL, /* remote client address */
NULL, /* local server address */
sd,
NULL, /* disconnect function */
lsasd_client_terminated,
data);
@ -491,7 +489,6 @@ static void lsasd_handle_client(struct tevent_req *req)
cli_addr,
srv_addr,
sd,
NULL, /* disconnect function */
lsasd_client_terminated,
data);
}

View File

@ -286,7 +286,7 @@ static int mdssd_children_main(struct tevent_context *ev_ctx,
return ret;
}
static void mdssd_client_terminated(void *pvt)
static void mdssd_client_terminated(struct pipes_struct *p, void *pvt)
{
struct mdssd_children_data *data;
@ -391,7 +391,6 @@ static void mdssd_handle_client(struct tevent_req *req)
cli_addr,
srv_addr,
sd,
NULL, /* disconnect function */
mdssd_client_terminated,
data);
} else if (tsocket_address_is_unix(srv_addr)) {
@ -419,7 +418,6 @@ static void mdssd_handle_client(struct tevent_req *req)
NULL, /* remote client address */
NULL, /* local server address */
sd,
NULL, /* disconnect function */
mdssd_client_terminated,
data);
} else {
@ -430,7 +428,6 @@ static void mdssd_handle_client(struct tevent_req *req)
cli_addr,
srv_addr,
sd,
NULL, /* disconnect function */
mdssd_client_terminated,
data);
}

View File

@ -114,7 +114,6 @@ NTSTATUS make_internal_rpc_pipe_socketpair(
msg_ctx,
NCACN_NP,
pipe_name,
NULL, /* disconnect fn */
NULL, /* termination fn */
NULL, /* termination data */
&ncacn_conn);

View File

@ -91,7 +91,6 @@ struct dcerpc_ncacn_listen_state {
struct tevent_context *ev_ctx;
struct messaging_context *msg_ctx;
dcerpc_ncacn_disconnect_fn disconnect_fn;
dcerpc_ncacn_termination_fn termination_fn;
void *termination_data;
};
@ -253,7 +252,6 @@ static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
NULL, /* remote client address */
NULL, /* local server address */
sd,
state->disconnect_fn,
state->termination_fn,
state->termination_data);
}
@ -324,7 +322,6 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
state->fd = -1;
state->ep.port = *port;
state->disconnect_fn = NULL;
status = dcesrv_create_ncacn_ip_tcp_socket(ifss, &state->ep.port,
&state->fd);
@ -437,7 +434,6 @@ static void dcesrv_ncacn_ip_tcp_listener(struct tevent_context *ev,
cli_addr,
srv_addr,
s,
state->disconnect_fn,
state->termination_fn,
state->termination_data);
}
@ -489,7 +485,8 @@ out:
NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
const char *name,
dcerpc_ncacn_disconnect_fn fn)
dcerpc_ncacn_termination_fn term_fn,
void *termination_data)
{
struct dcerpc_ncacn_listen_state *state;
struct tevent_fd *fde;
@ -503,7 +500,8 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
}
state->fd = -1;
state->disconnect_fn = fn;
state->termination_fn = term_fn;
state->termination_data = termination_data;
if (name == NULL) {
name = "DEFAULT";
@ -621,22 +619,15 @@ static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
NCALRPC,
state->ep.name,
cli_addr, srv_addr, sd,
state->disconnect_fn,
state->termination_fn,
state->termination_data);
}
static int dcerpc_ncacn_conn_destructor(struct dcerpc_ncacn_conn *ncacn_conn)
{
if (ncacn_conn->disconnect_fn != NULL) {
bool ok = ncacn_conn->disconnect_fn(ncacn_conn->p);
if (!ok) {
DBG_WARNING("Failed to call disconnect function\n");
}
}
if (ncacn_conn->termination_fn != NULL) {
ncacn_conn->termination_fn(ncacn_conn->termination_data);
ncacn_conn->termination_fn(ncacn_conn->p,
ncacn_conn->termination_data);
}
return 0;
@ -647,7 +638,6 @@ NTSTATUS dcerpc_ncacn_conn_init(TALLOC_CTX *mem_ctx,
struct messaging_context *msg_ctx,
enum dcerpc_transport_t transport,
const char *name,
dcerpc_ncacn_disconnect_fn disconnect_fn,
dcerpc_ncacn_termination_fn term_fn,
void *termination_data,
struct dcerpc_ncacn_conn **out)
@ -664,7 +654,6 @@ NTSTATUS dcerpc_ncacn_conn_init(TALLOC_CTX *mem_ctx,
ncacn_conn->ev_ctx = ev_ctx;
ncacn_conn->msg_ctx = msg_ctx;
ncacn_conn->sock = -1;
ncacn_conn->disconnect_fn = disconnect_fn;
ncacn_conn->termination_fn = term_fn;
ncacn_conn->termination_data = termination_data;
if (name != NULL) {
@ -691,7 +680,6 @@ void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
struct tsocket_address *cli_addr,
struct tsocket_address *srv_addr,
int s,
dcerpc_ncacn_disconnect_fn disconnect_fn,
dcerpc_ncacn_termination_fn termination_fn,
void *termination_data)
{
@ -706,7 +694,6 @@ void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
msg_ctx,
transport,
name,
disconnect_fn,
termination_fn,
termination_data,
&ncacn_conn);

View File

@ -25,8 +25,7 @@
struct pipes_struct;
struct auth_session_info;
typedef bool (*dcerpc_ncacn_disconnect_fn)(struct pipes_struct *p);
typedef void (*dcerpc_ncacn_termination_fn)(void *private_data);
typedef void (*dcerpc_ncacn_termination_fn)(struct pipes_struct *, void *);
struct dcerpc_ncacn_conn {
enum dcerpc_transport_t transport;
@ -35,7 +34,6 @@ struct dcerpc_ncacn_conn {
int sock;
struct pipes_struct *p;
dcerpc_ncacn_disconnect_fn disconnect_fn;
dcerpc_ncacn_termination_fn termination_fn;
void *termination_data;
@ -60,7 +58,6 @@ NTSTATUS dcerpc_ncacn_conn_init(TALLOC_CTX *mem_ctx,
struct messaging_context *msg_ctx,
enum dcerpc_transport_t transport,
const char *name,
dcerpc_ncacn_disconnect_fn disconnect_fn,
dcerpc_ncacn_termination_fn term_fn,
void *termination_data,
struct dcerpc_ncacn_conn **out);
@ -94,7 +91,8 @@ NTSTATUS dcesrv_create_ncalrpc_socket(const char *name, int *out_fd);
NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
const char *name,
dcerpc_ncacn_disconnect_fn fn);
dcerpc_ncacn_termination_fn term_fn,
void *termination_data);
void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
@ -103,7 +101,6 @@ void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
struct tsocket_address *cli_addr,
struct tsocket_address *srv_addr,
int s,
dcerpc_ncacn_disconnect_fn disconnect_fn,
dcerpc_ncacn_termination_fn termination_fn,
void *termination_data);
void dcerpc_ncacn_packet_process(struct tevent_req *subreq);