winbind: Allow winbindd to be run from inside "samba"
authorAndrew Bartlett <abartlet@samba.org>
Fri, 28 Mar 2014 01:35:21 +0000 (14:35 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 29 Apr 2014 03:28:39 +0000 (05:28 +0200)
Change-Id: I6b90a9b62ba5821e0feedb23cd20642078ba0ca6
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Kamen Mazdrashki <kamenim@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Apr 29 05:28:39 CEST 2014 on sn-devel-104

source3/winbindd/winbindd.c
source4/winbind/winbindd.c [new file with mode: 0644]
source4/winbind/wscript_build

index 937f68db1cda4781cac483e0faec32423df49631..a1647c947fab0c4d396e4e9afc2a54965e10bfc2 100644 (file)
@@ -1460,7 +1460,8 @@ int main(int argc, const char **argv)
         */
        dump_core_setup("winbindd", lp_logfile(talloc_tos()));
 
-       if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC) {
+       if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
+           && !lp_parm_bool(-1, "server role check", "inhibit", false)) {
                DEBUG(0, ("server role = 'active directory domain controller' not compatible with running the winbindd binary. \n"));
                DEBUGADD(0, ("You should start 'samba' instead, and it will control starting the internal AD DC winbindd implementation, which is not the same as this one\n"));
                exit(1);
diff --git a/source4/winbind/winbindd.c b/source4/winbind/winbindd.c
new file mode 100644 (file)
index 0000000..f702739
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+   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/smbd/service.h"
+#include "source4/smbd/process_model.h"
+#include "file_server/file_server.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 void winbindd_task_init(struct task_server *task)
+{
+       struct tevent_req *subreq;
+       const char *winbindd_path;
+       const char *winbindd_cmd[2] = { NULL, NULL };
+
+       task_server_set_title(task, "task[winbindd_parent]");
+
+       winbindd_path = talloc_asprintf(task, "%s/winbindd", dyn_SBINDIR);
+       winbindd_cmd[0] = winbindd_path;
+
+       /* 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",
+                               debug_get_output_is_stdout()?"--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;
+       }
+
+       tevent_req_set_callback(subreq, winbindd_done, task);
+
+       DEBUG(5,("Started file server child winbindd\n"));
+}
+
+/* called at winbindd startup - register ourselves as a server service */
+NTSTATUS server_service_winbindd_init(void);
+
+NTSTATUS server_service_winbindd_init(void)
+{
+       return register_server_service("winbindd", winbindd_task_init);
+}
index 5ba9c2ae0f988b320e2b4190dc73d4ebe47e0f7a..e6710ceb2e3dcae69ec7d429cb54e9fa11817ef6 100644 (file)
@@ -10,6 +10,14 @@ bld.SAMBA_MODULE('service_winbind',
        internal_module=False,
        )
 
+bld.SAMBA_MODULE('service_winbindd',
+       source='winbindd.c',
+       subsystem='service',
+       init_function='server_service_winbindd_init',
+       deps='process_model UTIL_RUNCMD',
+       internal_module=False,
+       )
+
 
 bld.SAMBA_SUBSYSTEM('WB_HELPER',
        source='wb_async_helpers.c wb_utils.c',