diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
commit | 4f5791ebd03eaec1c7da0865a383175b05102712 (patch) | |
tree | 8ce7b00f7a76baa386372422adebbe64510812d4 /source4/winbind/winbindd.c | |
parent | Initial commit. (diff) | |
download | samba-4f5791ebd03eaec1c7da0865a383175b05102712.tar.xz samba-4f5791ebd03eaec1c7da0865a383175b05102712.zip |
Adding upstream version 2:4.17.12+dfsg.upstream/2%4.17.12+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'source4/winbind/winbindd.c')
-rw-r--r-- | source4/winbind/winbindd.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/source4/winbind/winbindd.c b/source4/winbind/winbindd.c new file mode 100644 index 0000000..7b6e3d9 --- /dev/null +++ b/source4/winbind/winbindd.c @@ -0,0 +1,119 @@ +/* + Unix SMB/CIFS implementation. + + run s3 winbindd server within Samba4 + + Copyright (C) Andrew Tridgell 2011 + Copyright (C) Andrew Bartlett 2014 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "talloc.h" +#include "tevent.h" +#include "system/filesys.h" +#include "lib/param/param.h" +#include "source4/samba/service.h" +#include "source4/samba/process_model.h" +#include "dynconfig.h" +#include "nsswitch/winbind_client.h" + +/* + called if winbindd exits + */ +static void winbindd_done(struct tevent_req *subreq) +{ + struct task_server *task = + tevent_req_callback_data(subreq, + struct task_server); + int sys_errno; + int ret; + + ret = samba_runcmd_recv(subreq, &sys_errno); + if (ret != 0) { + DEBUG(0,("winbindd daemon died with exit status %d\n", sys_errno)); + } else { + DEBUG(0,("winbindd daemon exited normally\n")); + } + task_server_terminate(task, "winbindd child process exited", true); +} + + +/* + startup a copy of winbindd as a child daemon +*/ +static NTSTATUS winbindd_task_init(struct task_server *task) +{ + struct tevent_req *subreq; + const char *winbindd_path; + const char *winbindd_cmd[2] = { NULL, NULL }; + const char *config_file = ""; + + task_server_set_title(task, "task[winbindd_parent]"); + + winbindd_path = talloc_asprintf(task, "%s/winbindd", dyn_SBINDIR); + if (winbindd_path == NULL) { + return NT_STATUS_NO_MEMORY; + } + winbindd_cmd[0] = winbindd_path; + + if (!is_default_dyn_CONFIGFILE()) { + config_file = talloc_asprintf(task, + "--configfile=%s", + get_dyn_CONFIGFILE()); + if (config_file == NULL) { + return NT_STATUS_NO_MEMORY; + } + } + + /* start it as a child process */ + subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0, + winbindd_cmd, + "-D", + "--option=server role check:inhibit=yes", + "--foreground", + config_file, + debug_get_output_is_stdout()?"--debug-stdout":NULL, + NULL); + if (subreq == NULL) { + DEBUG(0, ("Failed to start winbindd as child daemon\n")); + task_server_terminate(task, "Failed to startup winbindd task", true); + return NT_STATUS_UNSUCCESSFUL; + } + + tevent_req_set_callback(subreq, winbindd_done, task); + + DEBUG(5,("Started winbindd as a child daemon\n")); + return NT_STATUS_OK; +} + +/* called at winbindd startup - register ourselves as a server service */ +NTSTATUS server_service_winbindd_init(TALLOC_CTX *); + +NTSTATUS server_service_winbindd_init(TALLOC_CTX *ctx) +{ + static const struct service_details details = { + .inhibit_fork_on_accept = true, + .inhibit_pre_fork = true, + .task_init = winbindd_task_init, + .post_fork = NULL + }; + + NTSTATUS status = register_server_service(ctx, "winbindd", &details); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + return register_server_service(ctx, "winbind", &details); +} |