1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-23 09:57:40 +03:00

source4/smbd: Do not overstamp the process model with "single"

Instead, except in RPC which is a special SNOWFLAKE, we rely on the struct
service_details in the init function.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
This commit is contained in:
Gary Lockyer 2017-09-18 13:05:24 +12:00 committed by Andrew Bartlett
parent 62d7bf9e0a
commit 0840252670
8 changed files with 39 additions and 116 deletions

View File

@ -684,23 +684,14 @@ static NTSTATUS dns_add_socket(struct dns_server *dns,
setup our listening sockets on the configured network interfaces setup our listening sockets on the configured network interfaces
*/ */
static NTSTATUS dns_startup_interfaces(struct dns_server *dns, static NTSTATUS dns_startup_interfaces(struct dns_server *dns,
struct interface *ifaces) struct interface *ifaces,
const struct model_ops *model_ops)
{ {
const struct model_ops *model_ops;
int num_interfaces; int num_interfaces;
TALLOC_CTX *tmp_ctx = talloc_new(dns); TALLOC_CTX *tmp_ctx = talloc_new(dns);
NTSTATUS status; NTSTATUS status;
int i; int i;
/* within the dns task we want to be a single process, so
ask for the single process model ops and pass these to the
stream_setup_socket() call. */
model_ops = process_model_startup("single");
if (!model_ops) {
DEBUG(0,("Can't find 'single' process model_ops\n"));
return NT_STATUS_INTERNAL_ERROR;
}
if (ifaces != NULL) { if (ifaces != NULL) {
num_interfaces = iface_list_count(ifaces); num_interfaces = iface_list_count(ifaces);
@ -907,7 +898,7 @@ static void dns_task_init(struct task_server *task)
return; return;
} }
status = dns_startup_interfaces(dns, ifaces); status = dns_startup_interfaces(dns, ifaces, task->model_ops);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
task_server_terminate(task, "dns failed to setup interfaces", true); task_server_terminate(task, "dns failed to setup interfaces", true);
return; return;

View File

@ -241,34 +241,14 @@ static NTSTATUS echo_add_socket(struct echo_server *echo,
/* Set up the listening sockets */ /* Set up the listening sockets */
static NTSTATUS echo_startup_interfaces(struct echo_server *echo, static NTSTATUS echo_startup_interfaces(struct echo_server *echo,
struct loadparm_context *lp_ctx, struct loadparm_context *lp_ctx,
struct interface *ifaces) struct interface *ifaces,
const struct model_ops *model_ops)
{ {
const struct model_ops *model_ops;
int num_interfaces; int num_interfaces;
TALLOC_CTX *tmp_ctx = talloc_new(echo); TALLOC_CTX *tmp_ctx = talloc_new(echo);
NTSTATUS status; NTSTATUS status;
int i; int i;
/*
* Samba allows subtask to set their own process model.
* Available models currently are:
* - onefork (forks exactly one child process)
* - prefork (keep a couple of child processes around)
* - single (only run a single process)
* - standard (fork one subprocess per incoming connection)
* - thread (use threads instead of forks)
*
* For the echo server, the "single" process model works fine,
* you probably don't want to use the thread model unless you really
* know what you're doing.
*/
model_ops = process_model_startup("single");
if (model_ops == NULL) {
DEBUG(0, ("Can't find 'single' process model_ops\n"));
return NT_STATUS_INTERNAL_ERROR;
}
num_interfaces = iface_list_count(ifaces); num_interfaces = iface_list_count(ifaces);
for(i=0; i<num_interfaces; i++) { for(i=0; i<num_interfaces; i++) {
@ -327,7 +307,8 @@ static void echo_task_init(struct task_server *task)
echo->task = task; echo->task = task;
status = echo_startup_interfaces(echo, task->lp_ctx, ifaces); status = echo_startup_interfaces(echo, task->lp_ctx, ifaces,
task->model_ops);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
task_server_terminate(task, "echo: Failed to set up interfaces", task_server_terminate(task, "echo: Failed to set up interfaces",
true); true);

View File

@ -110,10 +110,11 @@ static kdc_code kdc_process(struct kdc_server *kdc,
/* /*
setup our listening sockets on the configured network interfaces setup our listening sockets on the configured network interfaces
*/ */
static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_context *lp_ctx, static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc,
struct interface *ifaces) struct loadparm_context *lp_ctx,
struct interface *ifaces,
const struct model_ops *model_ops)
{ {
const struct model_ops *model_ops;
int num_interfaces; int num_interfaces;
TALLOC_CTX *tmp_ctx = talloc_new(kdc); TALLOC_CTX *tmp_ctx = talloc_new(kdc);
NTSTATUS status; NTSTATUS status;
@ -122,15 +123,6 @@ static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_c
uint16_t kpasswd_port = lpcfg_kpasswd_port(lp_ctx); uint16_t kpasswd_port = lpcfg_kpasswd_port(lp_ctx);
bool done_wildcard = false; bool done_wildcard = false;
/* within the kdc task we want to be a single process, so
ask for the single process model ops and pass these to the
stream_setup_socket() call. */
model_ops = process_model_startup("single");
if (!model_ops) {
DEBUG(0,("Can't find 'single' process model_ops\n"));
return NT_STATUS_INTERNAL_ERROR;
}
num_interfaces = iface_list_count(ifaces); num_interfaces = iface_list_count(ifaces);
/* if we are allowing incoming packets from any address, then /* if we are allowing incoming packets from any address, then
@ -448,7 +440,8 @@ static void kdc_task_init(struct task_server *task)
kdc->private_data = kdc_config; kdc->private_data = kdc_config;
/* start listening on the configured network interfaces */ /* start listening on the configured network interfaces */
status = kdc_startup_interfaces(kdc, task->lp_ctx, ifaces); status = kdc_startup_interfaces(kdc, task->lp_ctx, ifaces,
task->model_ops);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
task_server_terminate(task, "kdc failed to setup interfaces", true); task_server_terminate(task, "kdc failed to setup interfaces", true);
return; return;

View File

@ -72,12 +72,6 @@ static NTSTATUS startup_kpasswd_server(TALLOC_CTX *mem_ctx,
return NT_STATUS_OK; return NT_STATUS_OK;
} }
model_ops = process_model_startup("single");
if (model_ops == NULL) {
DBG_ERR("Can't find 'single' process model_ops\n");
return NT_STATUS_INTERNAL_ERROR;
}
tmp_ctx = talloc_named_const(mem_ctx, 0, "kpasswd"); tmp_ctx = talloc_named_const(mem_ctx, 0, "kpasswd");
if (tmp_ctx == NULL) { if (tmp_ctx == NULL) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;

View File

@ -1112,7 +1112,6 @@ static void ldapsrv_task_init(struct task_server *task)
const char *dns_host_name; const char *dns_host_name;
struct ldapsrv_service *ldap_service; struct ldapsrv_service *ldap_service;
NTSTATUS status; NTSTATUS status;
const struct model_ops *model_ops;
switch (lpcfg_server_role(task->lp_ctx)) { switch (lpcfg_server_role(task->lp_ctx)) {
case ROLE_STANDALONE: case ROLE_STANDALONE:
@ -1130,13 +1129,6 @@ static void ldapsrv_task_init(struct task_server *task)
task_server_set_title(task, "task[ldapsrv]"); task_server_set_title(task, "task[ldapsrv]");
/*
* Here we used to run the ldap server as a single process,
* but we don't want transaction locks for one task in a write
* blocking all other reads, so we go multi-process.
*/
model_ops = task->model_ops;
ldap_service = talloc_zero(task, struct ldapsrv_service); ldap_service = talloc_zero(task, struct ldapsrv_service);
if (ldap_service == NULL) goto failed; if (ldap_service == NULL) goto failed;
@ -1180,7 +1172,8 @@ static void ldapsrv_task_init(struct task_server *task)
*/ */
for(i = 0; i < num_interfaces; i++) { for(i = 0; i < num_interfaces; i++) {
const char *address = iface_list_n_ip(ifaces, i); const char *address = iface_list_n_ip(ifaces, i);
status = add_socket(task, task->lp_ctx, model_ops, address, ldap_service); status = add_socket(task, task->lp_ctx, task->model_ops,
address, ldap_service);
if (!NT_STATUS_IS_OK(status)) goto failed; if (!NT_STATUS_IS_OK(status)) goto failed;
} }
} else { } else {
@ -1193,7 +1186,8 @@ static void ldapsrv_task_init(struct task_server *task)
goto failed; goto failed;
} }
for (i=0; wcard[i]; i++) { for (i=0; wcard[i]; i++) {
status = add_socket(task, task->lp_ctx, model_ops, wcard[i], ldap_service); status = add_socket(task, task->lp_ctx, task->model_ops,
wcard[i], ldap_service);
if (NT_STATUS_IS_OK(status)) { if (NT_STATUS_IS_OK(status)) {
num_binds++; num_binds++;
} }
@ -1210,7 +1204,7 @@ static void ldapsrv_task_init(struct task_server *task)
} }
status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
model_ops, &ldap_stream_nonpriv_ops, task->model_ops, &ldap_stream_nonpriv_ops,
"unix", ldapi_path, NULL, "unix", ldapi_path, NULL,
lpcfg_socket_options(task->lp_ctx), lpcfg_socket_options(task->lp_ctx),
ldap_service, task->process_context); ldap_service, task->process_context);
@ -1241,7 +1235,7 @@ static void ldapsrv_task_init(struct task_server *task)
} }
status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
model_ops, &ldap_stream_priv_ops, task->model_ops, &ldap_stream_priv_ops,
"unix", ldapi_path, NULL, "unix", ldapi_path, NULL,
lpcfg_socket_options(task->lp_ctx), lpcfg_socket_options(task->lp_ctx),
ldap_service, ldap_service,

View File

@ -494,8 +494,6 @@ static void ntp_signd_task_init(struct task_server *task)
struct ntp_signd_server *ntp_signd; struct ntp_signd_server *ntp_signd;
NTSTATUS status; NTSTATUS status;
const struct model_ops *model_ops;
const char *address; const char *address;
if (!directory_create_or_exist_strict(lpcfg_ntp_signd_socket_directory(task->lp_ctx), geteuid(), 0750)) { if (!directory_create_or_exist_strict(lpcfg_ntp_signd_socket_directory(task->lp_ctx), geteuid(), 0750)) {
@ -506,15 +504,6 @@ static void ntp_signd_task_init(struct task_server *task)
return; return;
} }
/* within the ntp_signd task we want to be a single process, so
ask for the single process model ops and pass these to the
stream_setup_socket() call. */
model_ops = process_model_startup("single");
if (!model_ops) {
DEBUG(0,("Can't find 'single' process model_ops\n"));
return;
}
task_server_set_title(task, "task[ntp_signd]"); task_server_set_title(task, "task[ntp_signd]");
ntp_signd = talloc(task, struct ntp_signd_server); ntp_signd = talloc(task, struct ntp_signd_server);
@ -537,7 +526,7 @@ static void ntp_signd_task_init(struct task_server *task)
status = stream_setup_socket(ntp_signd->task, status = stream_setup_socket(ntp_signd->task,
ntp_signd->task->event_ctx, ntp_signd->task->event_ctx,
ntp_signd->task->lp_ctx, ntp_signd->task->lp_ctx,
model_ops, task->model_ops,
&ntp_signd_stream_ops, &ntp_signd_stream_ops,
"unix", address, NULL, "unix", address, NULL,
lpcfg_socket_options(ntp_signd->task->lp_ctx), lpcfg_socket_options(ntp_signd->task->lp_ctx),

View File

@ -298,15 +298,10 @@ static void websrv_task_init(struct task_server *task)
{ {
NTSTATUS status; NTSTATUS status;
uint16_t port = lpcfg_web_port(task->lp_ctx); uint16_t port = lpcfg_web_port(task->lp_ctx);
const struct model_ops *model_ops;
struct web_server_data *wdata; struct web_server_data *wdata;
task_server_set_title(task, "task[websrv]"); task_server_set_title(task, "task[websrv]");
/* run the web server as a single process */
model_ops = process_model_startup("single");
if (!model_ops) goto failed;
/* startup the Python processor - unfortunately we can't do this /* startup the Python processor - unfortunately we can't do this
per connection as that wouldn't allow for session variables */ per connection as that wouldn't allow for session variables */
wdata = talloc_zero(task, struct web_server_data); wdata = talloc_zero(task, struct web_server_data);
@ -327,7 +322,8 @@ static void websrv_task_init(struct task_server *task)
const char *address = iface_list_n_ip(ifaces, i); const char *address = iface_list_n_ip(ifaces, i);
status = stream_setup_socket(task, status = stream_setup_socket(task,
task->event_ctx, task->event_ctx,
task->lp_ctx, model_ops, task->lp_ctx,
task->model_ops,
&web_stream_ops, &web_stream_ops,
"ip", address, "ip", address,
&port, &port,
@ -348,7 +344,8 @@ static void websrv_task_init(struct task_server *task)
} }
for (i=0; wcard[i]; i++) { for (i=0; wcard[i]; i++) {
status = stream_setup_socket(task, task->event_ctx, status = stream_setup_socket(task, task->event_ctx,
task->lp_ctx, model_ops, task->lp_ctx,
task->model_ops,
&web_stream_ops, &web_stream_ops,
"ip", wcard[i], "ip", wcard[i],
&port, lpcfg_socket_options(task->lp_ctx), &port, lpcfg_socket_options(task->lp_ctx),

View File

@ -352,20 +352,10 @@ NTSTATUS wreplsrv_in_connection_merge(struct wreplsrv_partner *partner,
{ {
struct wreplsrv_service *service = partner->service; struct wreplsrv_service *service = partner->service;
struct wreplsrv_in_connection *wrepl_in; struct wreplsrv_in_connection *wrepl_in;
const struct model_ops *model_ops;
struct stream_connection *conn; struct stream_connection *conn;
struct tevent_req *subreq; struct tevent_req *subreq;
NTSTATUS status; NTSTATUS status;
/* within the wrepl task we want to be a single process, so
ask for the single process model ops and pass these to the
stream_setup_socket() call. */
model_ops = process_model_startup("single");
if (!model_ops) {
DEBUG(0,("Can't find 'single' process model_ops"));
return NT_STATUS_INTERNAL_ERROR;
}
wrepl_in = talloc_zero(partner, struct wreplsrv_in_connection); wrepl_in = talloc_zero(partner, struct wreplsrv_in_connection);
NT_STATUS_HAVE_NO_MEMORY(wrepl_in); NT_STATUS_HAVE_NO_MEMORY(wrepl_in);
@ -376,7 +366,7 @@ NTSTATUS wreplsrv_in_connection_merge(struct wreplsrv_partner *partner,
status = stream_new_connection_merge(service->task->event_ctx, status = stream_new_connection_merge(service->task->event_ctx,
service->task->lp_ctx, service->task->lp_ctx,
model_ops, service->task->model_ops,
&wreplsrv_stream_ops, &wreplsrv_stream_ops,
service->task->msg_ctx, service->task->msg_ctx,
wrepl_in, wrepl_in,
@ -427,19 +417,9 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar
{ {
NTSTATUS status; NTSTATUS status;
struct task_server *task = service->task; struct task_server *task = service->task;
const struct model_ops *model_ops;
const char *address; const char *address;
uint16_t port = WINS_REPLICATION_PORT; uint16_t port = WINS_REPLICATION_PORT;
/* within the wrepl task we want to be a single process, so
ask for the single process model ops and pass these to the
stream_setup_socket() call. */
model_ops = process_model_startup("single");
if (!model_ops) {
DEBUG(0,("Can't find 'single' process model_ops"));
return NT_STATUS_INTERNAL_ERROR;
}
if (lpcfg_interfaces(lp_ctx) && lpcfg_bind_interfaces_only(lp_ctx)) { if (lpcfg_interfaces(lp_ctx) && lpcfg_bind_interfaces_only(lp_ctx)) {
int num_interfaces; int num_interfaces;
int i; int i;
@ -458,8 +438,10 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar
continue; continue;
} }
address = iface_list_n_ip(ifaces, i); address = iface_list_n_ip(ifaces, i);
status = stream_setup_socket(task, task->event_ctx, status = stream_setup_socket(
task->lp_ctx, model_ops, task, task->event_ctx,
task->lp_ctx,
task->model_ops,
&wreplsrv_stream_ops, &wreplsrv_stream_ops,
"ipv4", address, &port, "ipv4", address, &port,
lpcfg_socket_options(task->lp_ctx), lpcfg_socket_options(task->lp_ctx),
@ -472,9 +454,11 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar
} }
} else { } else {
address = "0.0.0.0"; address = "0.0.0.0";
status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, status = stream_setup_socket(task, task->event_ctx,
model_ops, &wreplsrv_stream_ops, task->lp_ctx, task->model_ops,
"ipv4", address, &port, lpcfg_socket_options(task->lp_ctx), &wreplsrv_stream_ops,
"ipv4", address, &port,
lpcfg_socket_options(task->lp_ctx),
service, task->process_context); service, task->process_context);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("stream_setup_socket(address=%s,port=%u) failed - %s\n", DEBUG(0,("stream_setup_socket(address=%s,port=%u) failed - %s\n",