#include "lib/cmdline/popt_common.h"
#include "system/dir.h"
#include "system/filesys.h"
-#include "ldb/include/ldb.h"
-#include "registry/registry.h"
#include "ntvfs/ntvfs.h"
#include "ntptr/ntptr.h"
#include "auth/gensec/gensec.h"
+#include "auth/gensec/schannel_state.h"
#include "smbd/process_model.h"
-#include "smbd/service.h"
#include "param/secrets.h"
#include "smbd/pidfile.h"
#include "param/param.h"
+#include "dsdb/samdb/samdb.h"
+#include "auth/session.h"
+#include "lib/messaging/irpc.h"
+#include "librpc/gen_ndr/ndr_irpc.h"
+#include "cluster/cluster.h"
/*
recursively delete a directory tree
kill(-getpgrp(), SIGTERM);
}
#endif
+ DEBUG(0,("Exiting pid %d on SIGTERM\n", (int)getpid()));
exit(0);
}
handle io on stdin
*/
static void server_stdin_handler(struct tevent_context *event_ctx, struct tevent_fd *fde,
- uint16_t flags, void *private)
+ uint16_t flags, void *private_data)
{
- const char *binary_name = (const char *)private;
+ const char *binary_name = (const char *)private_data;
uint8_t c;
if (read(0, &c, 1) == 0) {
DEBUG(0,("%s: EOF on stdin - terminating\n", binary_name));
#if HAVE_GETPGRP
if (getpgrp() == getpid()) {
+ DEBUG(0,("Sending SIGTERM from pid %d\n", (int)getpid()));
kill(-getpgrp(), SIGTERM);
}
#endif
*/
_NORETURN_ static void max_runtime_handler(struct tevent_context *ev,
struct tevent_timer *te,
- struct timeval t, void *private)
+ struct timeval t, void *private_data)
{
- const char *binary_name = (const char *)private;
+ const char *binary_name = (const char *)private_data;
DEBUG(0,("%s: maximum runtime exceeded - terminating\n", binary_name));
exit(0);
}
+/*
+ pre-open the key databases. This saves a lot of time in child
+ processes
+ */
+static void prime_ldb_databases(struct tevent_context *event_ctx)
+{
+ TALLOC_CTX *db_context;
+ db_context = talloc_new(event_ctx);
+
+ samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx));
+ privilege_connect(db_context, event_ctx, cmdline_lp_ctx);
+ schannel_db_connect(db_context, event_ctx, cmdline_lp_ctx);
+
+ /* we deliberately leave these open, which allows them to be
+ * re-used in ldb_wrap_connect() */
+}
+
+
+/*
+ called when a fatal condition occurs in a child task
+ */
+static NTSTATUS samba_terminate(struct irpc_message *msg,
+ struct samba_terminate *r)
+{
+ DEBUG(0,("samba_terminate: %s\n", r->in.reason));
+ exit(1);
+}
+
+/*
+ setup messaging for the top level samba (parent) task
+ */
+static NTSTATUS setup_parent_messaging(struct tevent_context *event_ctx,
+ struct loadparm_context *lp_ctx)
+{
+ struct messaging_context *msg;
+ NTSTATUS status;
+
+ msg = messaging_init(talloc_autofree_context(),
+ lp_messaging_path(event_ctx, lp_ctx),
+ cluster_id(0, SAMBA_PARENT_TASKID),
+ lp_iconv_convenience(lp_ctx),
+ event_ctx);
+ NT_STATUS_HAVE_NO_MEMORY(msg);
+
+ irpc_add_name(msg, "samba");
+
+ status = IRPC_REGISTER(msg, irpc, SAMBA_TERMINATE,
+ samba_terminate, NULL);
+
+ return status;
+}
+
+
+
/*
main server.
*/
extern NTSTATUS server_service_cldapd_init(void);
extern NTSTATUS server_service_smb_init(void);
extern NTSTATUS server_service_drepl_init(void);
+ extern NTSTATUS server_service_kcc_init(void);
extern NTSTATUS server_service_rpc_init(void);
extern NTSTATUS server_service_ntp_signd_init(void);
extern NTSTATUS server_service_samba3_smb_init(void);
if (opt_daemon) {
DEBUG(3,("Becoming a daemon.\n"));
- become_daemon(true);
+ become_daemon(true, false);
}
cleanup_tmp_files(cmdline_lp_ctx);
if (opt_interactive) {
/* terminate when stdin goes away */
- stdin_event_flags = EVENT_FD_READ;
+ stdin_event_flags = TEVENT_FD_READ;
} else {
/* stay alive forever */
stdin_event_flags = 0;
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
- event_add_fd(event_ctx, event_ctx, 0, stdin_event_flags,
- server_stdin_handler,
- discard_const(binary_name));
+ tevent_add_fd(event_ctx, event_ctx, 0, stdin_event_flags,
+ server_stdin_handler,
+ discard_const(binary_name));
if (max_runtime) {
- event_add_timed(event_ctx, event_ctx,
- timeval_current_ofs(max_runtime, 0),
- max_runtime_handler,
- discard_const(binary_name));
+ tevent_add_timer(event_ctx, event_ctx,
+ timeval_current_ofs(max_runtime, 0),
+ max_runtime_handler,
+ discard_const(binary_name));
+ }
+
+ prime_ldb_databases(event_ctx);
+
+ status = setup_parent_messaging(event_ctx, cmdline_lp_ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("Failed to setup parent messaging - %s\n", nt_errstr(status)));
+ return 1;
}
DEBUG(0,("%s: using '%s' process model\n", binary_name, model));
+
status = server_service_startup(event_ctx, cmdline_lp_ctx, model,
lp_server_services(cmdline_lp_ctx));
if (!NT_STATUS_IS_OK(status)) {
/* wait for events - this is where smbd sits for most of its
life */
- event_loop_wait(event_ctx);
+ tevent_loop_wait(event_ctx);
/* as everything hangs off this event context, freeing it
should initiate a clean shutdown of all services */
return 0;
}
- int main(int argc, const char *argv[])
+int main(int argc, const char *argv[])
{
- return binary_smbd_main("smbd", argc, argv);
+ return binary_smbd_main("samba", argc, argv);
}