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

s3:rpc_server: Retrieve the dcesrv_endpoint from prefork listen data

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Samuel Cabrero 2019-02-27 20:21:44 +01:00 committed by Samuel Cabrero
parent 82020a3f62
commit 7fef249d7a
5 changed files with 91 additions and 135 deletions

View File

@ -44,7 +44,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
#define SPOOLSS_PIPE_NAME "spoolss"
#define DAEMON_NAME "spoolssd"
static struct server_id parent_id;
@ -287,6 +286,7 @@ static bool spoolss_child_init(struct tevent_context *ev_ctx,
struct spoolss_children_data {
struct tevent_context *ev_ctx;
struct messaging_context *msg_ctx;
struct dcesrv_context *dce_ctx;
struct pf_worker_data *pf;
int listen_fd_size;
struct pf_listen_fd *listen_fds;
@ -305,6 +305,9 @@ static int spoolss_children_main(struct tevent_context *ev_ctx,
struct spoolss_children_data *data;
bool ok;
int ret = 0;
struct dcesrv_context *dce_ctx = NULL;
dce_ctx = talloc_get_type_abort(private_data, struct dcesrv_context);
ok = spoolss_child_init(ev_ctx, child_id, pf);
if (!ok) {
@ -318,6 +321,7 @@ static int spoolss_children_main(struct tevent_context *ev_ctx,
data->pf = pf;
data->ev_ctx = ev_ctx;
data->msg_ctx = msg_ctx;
data->dce_ctx = dce_ctx;
data->listen_fd_size = listen_fd_size;
data->listen_fds = listen_fds;
@ -395,11 +399,13 @@ static void spoolss_handle_client(struct tevent_req *req)
int sd;
struct tsocket_address *srv_addr = NULL;
struct tsocket_address *cli_addr = NULL;
void *listen_fd_data = NULL;
struct dcesrv_endpoint *ep = NULL;
client = tevent_req_callback_data(req, struct spoolss_new_client);
data = client->data;
ret = prefork_listen_recv(req, data, &sd, NULL,
ret = prefork_listen_recv(req, data, &sd, &listen_fd_data,
&srv_addr, &cli_addr);
/* this will free the request too */
@ -410,6 +416,8 @@ static void spoolss_handle_client(struct tevent_req *req)
return;
}
ep = talloc_get_type_abort(listen_fd_data, struct dcesrv_endpoint);
/* Warn parent that our status changed */
messaging_send(data->msg_ctx, parent_id,
MSG_PREFORK_CHILD_EVENT, &ping);
@ -419,8 +427,8 @@ static void spoolss_handle_client(struct tevent_req *req)
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCACN_NP,
SPOOLSS_PIPE_NAME,
data->dce_ctx,
ep,
cli_addr,
srv_addr,
sd,
@ -776,7 +784,7 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx,
listen_fds_size, listen_fds,
pf_spoolss_cfg.min_children,
pf_spoolss_cfg.max_children,
&spoolss_children_main, NULL,
&spoolss_children_main, dce_ctx,
&spoolss_pool);
if (!ok) {
exit(1);

View File

@ -277,6 +277,7 @@ static bool lsasd_child_init(struct tevent_context *ev_ctx,
struct lsasd_children_data {
struct tevent_context *ev_ctx;
struct messaging_context *msg_ctx;
struct dcesrv_context *dce_ctx;
struct pf_worker_data *pf;
int listen_fd_size;
struct pf_listen_fd *listen_fds;
@ -295,6 +296,9 @@ static int lsasd_children_main(struct tevent_context *ev_ctx,
struct lsasd_children_data *data;
bool ok;
int ret = 0;
struct dcesrv_context *dce_ctx = NULL;
dce_ctx = talloc_get_type_abort(private_data, struct dcesrv_context);
ok = lsasd_child_init(ev_ctx, child_id, pf);
if (!ok) {
@ -308,6 +312,7 @@ static int lsasd_children_main(struct tevent_context *ev_ctx,
data->pf = pf;
data->ev_ctx = ev_ctx;
data->msg_ctx = msg_ctx;
data->dce_ctx = dce_ctx;
data->listen_fd_size = listen_fd_size;
data->listen_fds = listen_fds;
@ -388,6 +393,11 @@ static void lsasd_handle_client(struct tevent_req *req)
TALLOC_CTX *tmp_ctx;
struct tsocket_address *srv_addr;
struct tsocket_address *cli_addr;
void *listen_fd_data = NULL;
struct dcesrv_endpoint *ep = NULL;
enum dcerpc_transport_t transport;
dcerpc_ncacn_termination_fn term_fn = NULL;
void *term_fn_data = NULL;
client = tevent_req_callback_data(req, struct lsasd_new_client);
data = client->data;
@ -401,7 +411,7 @@ static void lsasd_handle_client(struct tevent_req *req)
rc = prefork_listen_recv(req,
tmp_ctx,
&sd,
NULL,
&listen_fd_data,
&srv_addr,
&cli_addr);
@ -413,69 +423,30 @@ static void lsasd_handle_client(struct tevent_req *req)
goto done;
}
ep = talloc_get_type_abort(listen_fd_data, struct dcesrv_endpoint);
transport = dcerpc_binding_get_transport(ep->ep_description);
if (transport == NCACN_NP) {
term_fn = lsasd_client_terminated;
term_fn_data = data;
}
/* Warn parent that our status changed */
messaging_send(data->msg_ctx, parent_id,
MSG_PREFORK_CHILD_EVENT, &ping);
DEBUG(2, ("LSASD preforked child %d got client connection!\n",
(int)(data->pf->pid)));
DBG_INFO("LSASD preforked child %d got client connection on '%s'\n",
(int)(data->pf->pid), dcerpc_binding_string(tmp_ctx,
ep->ep_description));
if (tsocket_address_is_inet(srv_addr, "ip")) {
DEBUG(3, ("Got a tcpip client connection from %s on interface %s\n",
tsocket_address_string(cli_addr, tmp_ctx),
tsocket_address_string(srv_addr, tmp_ctx)));
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCACN_IP_TCP,
"IP",
cli_addr,
srv_addr,
sd,
lsasd_client_terminated,
data);
} else if (tsocket_address_is_unix(srv_addr)) {
const char *p;
const char *b;
p = tsocket_address_unix_path(srv_addr, tmp_ctx);
if (p == NULL) {
talloc_free(tmp_ctx);
return;
}
b = strrchr(p, '/');
if (b != NULL) {
b++;
} else {
b = p;
}
if (strstr(p, "/np/")) {
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCACN_NP,
b,
NULL, /* remote client address */
NULL, /* local server address */
sd,
lsasd_client_terminated,
data);
} else {
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCALRPC,
b,
cli_addr,
srv_addr,
sd,
lsasd_client_terminated,
data);
}
} else {
DEBUG(0, ("ERROR: Unsupported socket!\n"));
}
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
data->dce_ctx,
ep,
cli_addr,
srv_addr,
sd,
term_fn,
term_fn_data);
done:
talloc_free(tmp_ctx);
@ -781,7 +752,7 @@ void start_lsasd(struct tevent_context *ev_ctx,
pf_lsasd_cfg.min_children,
pf_lsasd_cfg.max_children,
&lsasd_children_main,
NULL,
dce_ctx,
&lsasd_pool);
if (!ok) {
exit(1);

View File

@ -225,6 +225,7 @@ static bool mdssd_child_init(struct tevent_context *ev_ctx,
struct mdssd_children_data {
struct tevent_context *ev_ctx;
struct messaging_context *msg_ctx;
struct dcesrv_context *dce_ctx;
struct pf_worker_data *pf;
int listen_fd_size;
struct pf_listen_fd *listen_fds;
@ -243,6 +244,9 @@ static int mdssd_children_main(struct tevent_context *ev_ctx,
struct mdssd_children_data *data;
bool ok;
int ret = 0;
struct dcesrv_context *dce_ctx = NULL;
dce_ctx = talloc_get_type_abort(private_data, struct dcesrv_context);
ok = mdssd_child_init(ev_ctx, child_id, pf);
if (!ok) {
@ -256,6 +260,7 @@ static int mdssd_children_main(struct tevent_context *ev_ctx,
data->pf = pf;
data->ev_ctx = ev_ctx;
data->msg_ctx = msg_ctx;
data->dce_ctx = dce_ctx;
data->listen_fd_size = listen_fd_size;
data->listen_fds = listen_fds;
@ -336,6 +341,11 @@ static void mdssd_handle_client(struct tevent_req *req)
TALLOC_CTX *tmp_ctx;
struct tsocket_address *srv_addr;
struct tsocket_address *cli_addr;
void *listen_fd_data = NULL;
struct dcesrv_endpoint *ep = NULL;
enum dcerpc_transport_t transport;
dcerpc_ncacn_termination_fn term_fn = NULL;
void *term_fn_data = NULL;
client = tevent_req_callback_data(req, struct mdssd_new_client);
data = client->data;
@ -349,7 +359,7 @@ static void mdssd_handle_client(struct tevent_req *req)
rc = prefork_listen_recv(req,
tmp_ctx,
&sd,
NULL,
&listen_fd_data,
&srv_addr,
&cli_addr);
@ -361,68 +371,30 @@ static void mdssd_handle_client(struct tevent_req *req)
goto done;
}
ep = talloc_get_type_abort(listen_fd_data, struct dcesrv_endpoint);
transport = dcerpc_binding_get_transport(ep->ep_description);
if (transport == NCACN_NP) {
term_fn = mdssd_client_terminated;
term_fn_data = data;
}
/* Warn parent that our status changed */
messaging_send(data->msg_ctx, parent_id,
MSG_PREFORK_CHILD_EVENT, &ping);
DEBUG(2, ("mdssd preforked child %d got client connection!\n",
(int)(data->pf->pid)));
DBG_INFO("MDSSD preforked child %d got client connection on '%s'\n",
(int)(data->pf->pid), dcerpc_binding_string(tmp_ctx,
ep->ep_description));
if (tsocket_address_is_inet(srv_addr, "ip")) {
DEBUG(3, ("Got a tcpip client connection from %s on inteface %s\n",
tsocket_address_string(cli_addr, tmp_ctx),
tsocket_address_string(srv_addr, tmp_ctx)));
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCACN_IP_TCP,
"IP",
cli_addr,
srv_addr,
sd,
mdssd_client_terminated,
data);
} else if (tsocket_address_is_unix(srv_addr)) {
const char *p;
const char *b;
p = tsocket_address_unix_path(srv_addr, tmp_ctx);
if (p == NULL) {
talloc_free(tmp_ctx);
return;
}
b = strrchr(p, '/');
if (b != NULL) {
b++;
} else {
b = p;
}
if (strstr(p, "/np/")) {
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCACN_NP,
b,
NULL, /* remote client address */
NULL, /* local server address */
sd,
mdssd_client_terminated,
data);
} else {
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
NCALRPC,
b,
cli_addr,
srv_addr,
sd,
mdssd_client_terminated,
data);
}
} else {
DEBUG(0, ("ERROR: Unsupported socket!\n"));
}
dcerpc_ncacn_accept(data->ev_ctx,
data->msg_ctx,
data->dce_ctx,
ep,
cli_addr,
srv_addr,
sd,
term_fn,
term_fn_data);
done:
talloc_free(tmp_ctx);
@ -695,7 +667,7 @@ void start_mdssd(struct tevent_context *ev_ctx,
pf_mdssd_cfg.min_children,
pf_mdssd_cfg.max_children,
&mdssd_children_main,
NULL,
dce_ctx,
&mdssd_pool);
if (!ok) {
exit(1);

View File

@ -291,8 +291,8 @@ static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
dcerpc_ncacn_accept(state->ev_ctx,
state->msg_ctx,
NCACN_NP,
endpoint,
state->dce_ctx,
state->endpoint,
NULL, /* remote client address */
NULL, /* local server address */
sd,
@ -498,8 +498,8 @@ static void dcesrv_ncacn_ip_tcp_listener(struct tevent_context *ev,
dcerpc_ncacn_accept(state->ev_ctx,
state->msg_ctx,
NCACN_IP_TCP,
"IP",
state->dce_ctx,
state->endpoint,
cli_addr,
srv_addr,
s,
@ -719,8 +719,8 @@ static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
dcerpc_ncacn_accept(state->ev_ctx,
state->msg_ctx,
NCALRPC,
endpoint,
state->dce_ctx,
state->endpoint,
cli_addr, srv_addr, sd,
state->termination_fn,
state->termination_data);
@ -778,14 +778,19 @@ static void dcesrv_ncacn_accept_step2(struct dcerpc_ncacn_conn *ncacn_conn);
void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
enum dcerpc_transport_t transport,
const char *name,
struct dcesrv_context *dce_ctx,
struct dcesrv_endpoint *e,
struct tsocket_address *cli_addr,
struct tsocket_address *srv_addr,
int s,
dcerpc_ncacn_termination_fn termination_fn,
void *termination_data)
{
enum dcerpc_transport_t transport =
dcerpc_binding_get_transport(e->ep_description);
const char *endpoint =
dcerpc_binding_get_string_option(e->ep_description,
"endpoint");
struct dcerpc_ncacn_conn *ncacn_conn;
NTSTATUS status;
int rc;
@ -796,7 +801,7 @@ void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
ev_ctx,
msg_ctx,
transport,
name,
endpoint,
termination_fn,
termination_data,
&ncacn_conn);

View File

@ -106,8 +106,8 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
enum dcerpc_transport_t transport,
const char *name,
struct dcesrv_context *dce_ctx,
struct dcesrv_endpoint *e,
struct tsocket_address *cli_addr,
struct tsocket_address *srv_addr,
int s,