s4-netlogon: implement dcesrv_netr_DsRAddressToSitenamesExW
[Samba/aatanasov.git] / source4 / smbd / service_task.c
blob5db899576450ac051822ea441ddd27d281ee39b1
1 /*
2 Unix SMB/CIFS implementation.
4 helper functions for task based servers (nbtd, winbind etc)
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "process_model.h"
24 #include "smbd/service.h"
25 #include "smbd/service_task.h"
26 #include "lib/messaging/irpc.h"
27 #include "param/param.h"
28 #include "librpc/gen_ndr/ndr_irpc.h"
31 terminate a task service
33 void task_server_terminate(struct task_server *task, const char *reason, bool fatal)
35 struct tevent_context *event_ctx = task->event_ctx;
36 const struct model_ops *model_ops = task->model_ops;
37 DEBUG(0,("task_server_terminate: [%s]\n", reason));
39 if (fatal) {
40 struct samba_terminate r;
41 struct server_id *sid;
43 sid = irpc_servers_byname(task->msg_ctx, task, "samba");
45 r.in.reason = reason;
46 IRPC_CALL(task->msg_ctx, sid[0],
47 irpc, SAMBA_TERMINATE,
48 &r, NULL);
51 model_ops->terminate(event_ctx, task->lp_ctx, reason);
53 /* don't free this above, it might contain the 'reason' being printed */
54 talloc_free(task);
57 /* used for the callback from the process model code */
58 struct task_state {
59 void (*task_init)(struct task_server *);
60 const struct model_ops *model_ops;
65 called by the process model code when the new task starts up. This then calls
66 the server specific startup code
68 static void task_server_callback(struct tevent_context *event_ctx,
69 struct loadparm_context *lp_ctx,
70 struct server_id server_id, void *private_data)
72 struct task_state *state = talloc_get_type(private_data, struct task_state);
73 struct task_server *task;
75 task = talloc(event_ctx, struct task_server);
76 if (task == NULL) return;
78 task->event_ctx = event_ctx;
79 task->model_ops = state->model_ops;
80 task->server_id = server_id;
81 task->lp_ctx = lp_ctx;
83 task->msg_ctx = messaging_init(task,
84 lp_messaging_path(task, task->lp_ctx),
85 task->server_id,
86 lp_iconv_convenience(task->lp_ctx),
87 task->event_ctx);
88 if (!task->msg_ctx) {
89 task_server_terminate(task, "messaging_init() failed", true);
90 return;
93 state->task_init(task);
97 startup a task based server
99 NTSTATUS task_server_startup(struct tevent_context *event_ctx,
100 struct loadparm_context *lp_ctx,
101 const char *service_name,
102 const struct model_ops *model_ops,
103 void (*task_init)(struct task_server *))
105 struct task_state *state;
107 state = talloc(event_ctx, struct task_state);
108 NT_STATUS_HAVE_NO_MEMORY(state);
110 state->task_init = task_init;
111 state->model_ops = model_ops;
113 model_ops->new_task(event_ctx, lp_ctx, service_name, task_server_callback, state);
115 return NT_STATUS_OK;
119 setup a task title
121 void task_server_set_title(struct task_server *task, const char *title)
123 task->model_ops->set_title(task->event_ctx, title);