build: Remove build of replacetort
[Samba.git] / source4 / winbind / winbindd.c
blobe68ddfb68e1216a2b29198be70118c35c1075a2e
1 /*
2 Unix SMB/CIFS implementation.
4 run s3 winbindd server within Samba4
6 Copyright (C) Andrew Tridgell 2011
7 Copyright (C) Andrew Bartlett 2014
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "talloc.h"
25 #include "tevent.h"
26 #include "system/filesys.h"
27 #include "lib/param/param.h"
28 #include "source4/smbd/service.h"
29 #include "source4/smbd/process_model.h"
30 #include "dynconfig.h"
31 #include "nsswitch/winbind_client.h"
34 called if winbindd exits
36 static void winbindd_done(struct tevent_req *subreq)
38 struct task_server *task =
39 tevent_req_callback_data(subreq,
40 struct task_server);
41 int sys_errno;
42 int ret;
44 ret = samba_runcmd_recv(subreq, &sys_errno);
45 if (ret != 0) {
46 DEBUG(0,("winbindd daemon died with exit status %d\n", sys_errno));
47 } else {
48 DEBUG(0,("winbindd daemon exited normally\n"));
50 task_server_terminate(task, "winbindd child process exited", true);
55 startup a copy of winbindd as a child daemon
57 static NTSTATUS winbindd_task_init(struct task_server *task)
59 struct tevent_req *subreq;
60 const char *winbindd_path;
61 const char *winbindd_cmd[2] = { NULL, NULL };
63 task_server_set_title(task, "task[winbindd_parent]");
65 winbindd_path = talloc_asprintf(task, "%s/winbindd", dyn_SBINDIR);
66 winbindd_cmd[0] = winbindd_path;
68 /* start it as a child process */
69 subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
70 winbindd_cmd,
71 "-D",
72 "--option=server role check:inhibit=yes",
73 "--foreground",
74 debug_get_output_is_stdout()?"--stdout":NULL,
75 NULL);
76 if (subreq == NULL) {
77 DEBUG(0, ("Failed to start winbindd as child daemon\n"));
78 task_server_terminate(task, "Failed to startup winbindd task", true);
79 return NT_STATUS_UNSUCCESSFUL;
82 tevent_req_set_callback(subreq, winbindd_done, task);
84 DEBUG(5,("Started winbindd as a child daemon\n"));
85 return NT_STATUS_OK;
88 /* called at winbindd startup - register ourselves as a server service */
89 NTSTATUS server_service_winbindd_init(TALLOC_CTX *);
91 NTSTATUS server_service_winbindd_init(TALLOC_CTX *ctx)
93 static const struct service_details details = {
94 .inhibit_fork_on_accept = true,
95 .inhibit_pre_fork = true,
96 .task_init = winbindd_task_init,
97 .post_fork = NULL
100 NTSTATUS status = register_server_service(ctx, "winbindd", &details);
101 if (!NT_STATUS_IS_OK(status)) {
102 return status;
104 return register_server_service(ctx, "winbind", &details);