#include "../lib/util/tevent_unix.h"
struct prefork_pool {
-
int listen_fd_size;
- int *listen_fds;
+ struct pf_listen_fd *listen_fds;
prefork_main_fn_t *main_fn;
void *private_data;
bool prefork_create_pool(TALLOC_CTX *mem_ctx,
struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
- int listen_fd_size, int *listen_fds,
+ int listen_fd_size, struct pf_listen_fd *listen_fds,
int min_children, int max_children,
prefork_main_fn_t *main_fn, void *private_data,
struct prefork_pool **pf_pool)
return false;
}
pfp->listen_fd_size = listen_fd_size;
- pfp->listen_fds = talloc_array(pfp, int, listen_fd_size);
+ pfp->listen_fds = talloc_array(pfp, struct pf_listen_fd,
+ listen_fd_size);
if (!pfp->listen_fds) {
DEBUG(1, ("Out of memory!\n"));
return false;
for (i = 0; i < listen_fd_size; i++) {
pfp->listen_fds[i] = listen_fds[i];
/* force sockets in non-blocking mode */
- set_blocking(listen_fds[i], false);
+ set_blocking(listen_fds[i].fd, false);
}
pfp->main_fn = main_fn;
pfp->private_data = private_data;
struct pf_worker_data *pf;
int listen_fd_size;
- int *listen_fds;
+ struct pf_listen_fd *listen_fds;
- int accept_fd;
+ struct pf_listen_fd accept;
struct tsocket_address *srv_addr;
struct tsocket_address *cli_addr;
TALLOC_CTX *fde_ctx;
struct tevent_req *req;
int listen_fd;
+ void *listen_fd_data;
};
static void prefork_listen_accept_handler(struct tevent_context *ev,
struct tevent_context *ev,
struct pf_worker_data *pf,
int listen_fd_size,
- int *listen_fds)
+ struct pf_listen_fd *listen_fds)
{
struct tevent_req *req;
struct pf_listen_state *state;
state->pf = pf;
state->listen_fd_size = listen_fd_size;
state->listen_fds = listen_fds;
- state->accept_fd = -1;
+ state->accept.fd = -1;
+ state->accept.fd_data = NULL;
state->error = 0;
fde_ctx = talloc_new(state);
}
ctx->fde_ctx = fde_ctx;
ctx->req = req;
- ctx->listen_fd = state->listen_fds[i];
+ ctx->listen_fd = state->listen_fds[i].fd;
+ ctx->listen_fd_data = state->listen_fds[i].fd_data;
fde = tevent_add_fd(state->ev, fde_ctx,
ctx->listen_fd, TEVENT_FD_READ,
}
smb_set_close_on_exec(sd);
- state->accept_fd = sd;
+ state->accept.fd = sd;
+ state->accept.fd_data = ctx->listen_fd_data;
ret = tsocket_address_bsd_from_sockaddr(state,
(struct sockaddr *)(void *)&addr,
int prefork_listen_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx, int *fd,
+ void **fd_data,
struct tsocket_address **srv_addr,
struct tsocket_address **cli_addr)
{
}
if (ret) {
- if (state->accept_fd != -1) {
- close(state->accept_fd);
+ if (state->accept.fd != -1) {
+ close(state->accept.fd);
}
} else {
- *fd = state->accept_fd;
+ *fd = state->accept.fd;
+ if (fd_data != NULL) {
+ *fd_data = state->accept.fd_data;
+ }
*srv_addr = talloc_move(mem_ctx, &state->srv_addr);
*cli_addr = talloc_move(mem_ctx, &state->cli_addr);
state->pf->num_clients++;
PF_SRV_MSG_EXIT
};
+/**
+ * @brief This structure contains a socket listening for clients and a
+ * private pointer with any data associated to that particular
+ * socket.
+ */
+struct pf_listen_fd {
+ /* The socket to listen on */
+ int fd;
+
+ /* The socket associated data */
+ void *fd_data;
+};
+
/**
* @brief This structure is shared between the controlling parent and the
* the child. The parent can only write to the 'cmds' and
struct pf_worker_data *pf,
int child_id,
int listen_fd_size,
- int *listen_fds,
+ struct pf_listen_fd *pf_listen_fds,
void *private_data);
/**
bool prefork_create_pool(TALLOC_CTX *mem_ctx,
struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
- int listen_fd_size, int *listen_fds,
+ int listen_fd_size, struct pf_listen_fd *listen_fds,
int min_children, int max_children,
prefork_main_fn_t *main_fn, void *private_data,
struct prefork_pool **pf_pool);
struct tevent_context *ev,
struct pf_worker_data *pf,
int listen_fd_size,
- int *listen_fds);
+ struct pf_listen_fd *listen_fds);
/**
* @brief Returns the file descriptor after the new client connection has
* been accepted.
* @return The error in case the operation failed.
*/
int prefork_listen_recv(struct tevent_req *req,
- TALLOC_CTX *mem_ctx, int *fd,
+ TALLOC_CTX *mem_ctx, int *fd, void **fd_data,
struct tsocket_address **srv_addr,
struct tsocket_address **cli_addr);
struct messaging_context *msg_ctx;
struct pf_worker_data *pf;
int listen_fd_size;
- int *listen_fds;
+ struct pf_listen_fd *listen_fds;
};
static void spoolss_next_client(void *pvt);
struct pf_worker_data *pf,
int child_id,
int listen_fd_size,
- int *listen_fds,
+ struct pf_listen_fd *listen_fds,
void *private_data)
{
struct spoolss_children_data *data;
client = tevent_req_callback_data(req, struct spoolss_new_client);
data = client->data;
- ret = prefork_listen_recv(req, client, &sd,
+ ret = prefork_listen_recv(req, client, &sd, NULL,
&client->srv_addr, &client->cli_addr);
/* this will free the request too */
TALLOC_CTX *mem_ctx;
pid_t pid;
NTSTATUS status;
- int listen_fd;
+ struct pf_listen_fd listen_fds[1];
int ret;
bool ok;
/* the listening fd must be created before the children are actually
* forked out. */
- status = dcesrv_create_ncacn_np_socket(SPOOLSS_PIPE_NAME, &listen_fd);
+ status = dcesrv_create_ncacn_np_socket(SPOOLSS_PIPE_NAME,
+ &listen_fds[0].fd);
if (!NT_STATUS_IS_OK(status)) {
exit(1);
}
+ listen_fds[0].fd_data = NULL;
- ret = listen(listen_fd, pf_spoolss_cfg.max_allowed_clients);
+ ret = listen(listen_fds[0].fd, pf_spoolss_cfg.max_allowed_clients);
if (ret == -1) {
DEBUG(0, ("Failed to listen on spoolss pipe - %s\n",
strerror(errno)));
/* start children before any more initialization is done */
ok = prefork_create_pool(ev_ctx, /* mem_ctx */
ev_ctx, msg_ctx,
- 1, &listen_fd,
+ 1, listen_fds,
pf_spoolss_cfg.min_children,
pf_spoolss_cfg.max_children,
&spoolss_children_main, NULL,
struct messaging_context *msg_ctx;
struct pf_worker_data *pf;
int listen_fd_size;
- int *listen_fds;
+ struct pf_listen_fd *listen_fds;
};
static void lsasd_next_client(void *pvt);
struct pf_worker_data *pf,
int child_id,
int listen_fd_size,
- int *listen_fds,
+ struct pf_listen_fd *listen_fds,
void *private_data)
{
struct lsasd_children_data *data;
rc = prefork_listen_recv(req,
tmp_ctx,
&sd,
+ NULL,
&srv_addr,
&cli_addr);
static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
- int *listen_fd,
+ struct pf_listen_fd *listen_fd,
int *listen_fd_size)
{
struct dcerpc_binding_vector *v, *v_orig;
/* Start to listen on tcpip sockets */
for (i = 0; i < *listen_fd_size; i++) {
- rc = listen(listen_fd[i], pf_lsasd_cfg.max_allowed_clients);
+ rc = listen(listen_fd[i].fd, pf_lsasd_cfg.max_allowed_clients);
if (rc == -1) {
DEBUG(0, ("Failed to listen on tcpip socket - %s\n",
strerror(errno)));
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
status = dcesrv_create_ncacn_np_socket("lsass", &fd);
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
status = dcesrv_create_ncalrpc_socket("lsarpc", &fd);
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
fd = -1;
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
status = dcesrv_create_ncalrpc_socket("samr", &fd);
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
fd = -1;
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
status = dcesrv_create_ncalrpc_socket("netlogon", &fd);
strerror(errno)));
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
fd = -1;
struct messaging_context *msg_ctx)
{
NTSTATUS status;
- int listen_fd[LSASD_MAX_SOCKETS];
+ struct pf_listen_fd listen_fd[LSASD_MAX_SOCKETS];
int listen_fd_size = 0;
pid_t pid;
int rc;
struct messaging_context *msg_ctx;
struct pf_worker_data *pf;
int listen_fd_size;
- int *listen_fds;
+ struct pf_listen_fd *listen_fds;
};
static void mdssd_next_client(void *pvt);
struct pf_worker_data *pf,
int child_id,
int listen_fd_size,
- int *listen_fds,
+ struct pf_listen_fd *listen_fds,
void *private_data)
{
struct mdssd_children_data *data;
rc = prefork_listen_recv(req,
tmp_ctx,
&sd,
+ NULL,
&srv_addr,
&cli_addr);
static bool mdssd_create_sockets(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
- int *listen_fd,
+ struct pf_listen_fd *listen_fd,
int *listen_fd_size)
{
struct dcerpc_binding_vector *v, *v_orig;
if (rc == -1) {
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
status = dcesrv_create_ncalrpc_socket("mdssvc", &fd);
if (rc == -1) {
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
fd = -1;
struct messaging_context *msg_ctx)
{
NTSTATUS status;
- int listen_fd[MDSSD_MAX_SOCKETS];
+ struct pf_listen_fd listen_fd[MDSSD_MAX_SOCKETS];
int listen_fd_size = 0;
pid_t pid;
int rc;
#include "librpc/rpc/dcerpc_ep.h"
#include "rpc_server/rpc_server.h"
#include "rpc_server/rpc_sock_helper.h"
+#include "lib/server_prefork.h"
NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
const struct ndr_interface_table *iface,
struct dcerpc_binding_vector *bvec,
uint16_t port,
- int *listen_fd,
+ struct pf_listen_fd *listen_fd,
int *listen_fd_size)
{
uint32_t num_ifs = iface_count();
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
if (bvec != NULL) {
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
- listen_fd[*listen_fd_size] = fd;
+ listen_fd[*listen_fd_size].fd = fd;
+ listen_fd[*listen_fd_size].fd_data = NULL;
(*listen_fd_size)++;
if (bvec != NULL) {
#ifndef _RPC_SOCK_HELPER_H_
#define _RPC_SOCK_HELPER_H_
+struct pf_listen_fd;
+
NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
const struct ndr_interface_table *iface,
struct dcerpc_binding_vector *bvec,
uint16_t port,
- int *listen_fd,
+ struct pf_listen_fd *listen_fd,
int *listen_fd_size);
NTSTATUS dcesrv_setup_ncacn_ip_tcp_sockets(struct tevent_context *ev_ctx,