2 Unix SMB/CIFS implementation.
4 Start MIT krb5kdc server within Samba AD
6 Copyright (c) 2014 Andreas Schneider <asn@samba.org>
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/>.
25 #include "system/filesys.h"
26 #include "lib/param/param.h"
27 #include "lib/util/samba_util.h"
28 #include "source4/smbd/service.h"
29 #include "source4/smbd/process_model.h"
30 #include "kdc/kdc-service-mit.h"
31 #include "dynconfig.h"
32 #include "libds/common/roles.h"
34 static void mitkdc_server_done(struct tevent_req *subreq);
37 * Startup a copy of the krb5kdc as a child daemon
39 void mitkdc_task_init(struct task_server *task)
41 struct tevent_req *subreq;
42 const char * const *kdc_cmd;
44 task_server_set_title(task, "task[mitkdc_parent]");
46 switch (lpcfg_server_role(task->lp_ctx)) {
48 task_server_terminate(task,
49 "The KDC is not required in standalone "
50 "server configuration, terminate!",
53 case ROLE_DOMAIN_MEMBER:
54 task_server_terminate(task,
55 "The KDC is not required in member "
56 "server configuration",
59 case ROLE_ACTIVE_DIRECTORY_DC:
60 /* Yes, we want to start the KDC */
64 /* start it as a child process */
65 kdc_cmd = lpcfg_mit_kdc_command(task->lp_ctx);
67 subreq = samba_runcmd_send(task,
70 1, /* stdout log level */
71 0, /* stderr log level */
73 "-n", /* Don't go into background */
75 "-w 2", /* Start two workers */
79 DEBUG(0, ("Failed to start MIT KDC as child daemon\n"));
81 task_server_terminate(task,
82 "Failed to startup mitkdc task",
87 tevent_req_set_callback(subreq, mitkdc_server_done, task);
89 DEBUG(5,("Started krb5kdc process\n"));
93 * This gets called the kdc exits.
95 static void mitkdc_server_done(struct tevent_req *subreq)
97 struct task_server *task =
98 tevent_req_callback_data(subreq,
103 ret = samba_runcmd_recv(subreq, &sys_errno);
105 DEBUG(0, ("The MIT KDC daemon died with exit status %d\n",
108 DEBUG(0,("The MIT KDC daemon exited normally\n"));
111 task_server_terminate(task, "mitkdc child process exited", true);
114 /* Called at MIT KRB5 startup - register ourselves as a server service */
115 NTSTATUS server_service_mitkdc_init(TALLOC_CTX *mem_ctx);
117 NTSTATUS server_service_mitkdc_init(TALLOC_CTX *mem_ctx)
119 return register_server_service("kdc", mitkdc_task_init);