s3:modules: call rpcgen only if vfs_nfs4acl_xattr is enabled
[Samba.git] / source4 / winbind / winbindd.c
blob7b6e3d9233399de33d5173944e824e13448b183c
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/samba/service.h"
29 #include "source4/samba/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 };
62 const char *config_file = "";
64 task_server_set_title(task, "task[winbindd_parent]");
66 winbindd_path = talloc_asprintf(task, "%s/winbindd", dyn_SBINDIR);
67 if (winbindd_path == NULL) {
68 return NT_STATUS_NO_MEMORY;
70 winbindd_cmd[0] = winbindd_path;
72 if (!is_default_dyn_CONFIGFILE()) {
73 config_file = talloc_asprintf(task,
74 "--configfile=%s",
75 get_dyn_CONFIGFILE());
76 if (config_file == NULL) {
77 return NT_STATUS_NO_MEMORY;
81 /* start it as a child process */
82 subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
83 winbindd_cmd,
84 "-D",
85 "--option=server role check:inhibit=yes",
86 "--foreground",
87 config_file,
88 debug_get_output_is_stdout()?"--debug-stdout":NULL,
89 NULL);
90 if (subreq == NULL) {
91 DEBUG(0, ("Failed to start winbindd as child daemon\n"));
92 task_server_terminate(task, "Failed to startup winbindd task", true);
93 return NT_STATUS_UNSUCCESSFUL;
96 tevent_req_set_callback(subreq, winbindd_done, task);
98 DEBUG(5,("Started winbindd as a child daemon\n"));
99 return NT_STATUS_OK;
102 /* called at winbindd startup - register ourselves as a server service */
103 NTSTATUS server_service_winbindd_init(TALLOC_CTX *);
105 NTSTATUS server_service_winbindd_init(TALLOC_CTX *ctx)
107 static const struct service_details details = {
108 .inhibit_fork_on_accept = true,
109 .inhibit_pre_fork = true,
110 .task_init = winbindd_task_init,
111 .post_fork = NULL
114 NTSTATUS status = register_server_service(ctx, "winbindd", &details);
115 if (!NT_STATUS_IS_OK(status)) {
116 return status;
118 return register_server_service(ctx, "winbind", &details);