1 From 4be15cc68a49b353f1f2f4f198b968098bee4d83 Mon Sep 17 00:00:00 2001
2 From: Alexander Bokovoy <ab@samba.org>
3 Date: Tue, 25 Mar 2014 12:53:04 +0200
4 Subject: [PATCH 1/5] add systemd integration
6 Add --with-systemd / --without-systemd options to check whether
7 libsystemd-daemon library is available and use it to report service
8 startup status to systemd for smbd/winbindd/nmbd and AD DC.
10 The problem it solves is correct reporting of the Samba services
11 at the point when they are ready to serve clients, important for
12 high availability software integration.
14 BUG: https://bugzilla.samba.org/show_bug.cgi?id=10517
16 Signed-off-by: Alexander Bokovoy <ab@samba.org>
17 Reviewed-by: Andreas Schneider <asn@samba.org>
19 (cherry picked from commit 54b5d9a7384ae27b2a26586ff909128427c05abe)
21 lib/util/become_daemon.c | 37 ++++++++++++++++++++++++++++++++++++-
22 lib/util/samba_util.h | 12 ++++++++++++
23 lib/util/wscript_build | 2 +-
24 packaging/systemd/nmb.service | 3 ++-
25 packaging/systemd/samba.service | 3 ++-
26 packaging/systemd/smb.service | 3 ++-
27 packaging/systemd/winbind.service | 3 ++-
28 source3/nmbd/nmbd.c | 4 ++++
29 source3/smbd/server.c | 4 ++++
30 source3/winbindd/winbindd.c | 5 +++++
31 source4/smbd/server.c | 4 ++++
32 wscript | 27 +++++++++++++++++++++++----
33 12 files changed, 97 insertions(+), 10 deletions(-)
35 diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c
36 index 2ca0478..35c8b32 100644
37 --- a/lib/util/become_daemon.c
38 +++ b/lib/util/become_daemon.c
41 #include "system/filesys.h"
42 #include "system/locale.h"
44 +#include <systemd/sd-daemon.h>
47 /*******************************************************************
48 Close the low 3 fd's and open dev/null in their place.
49 @@ -75,8 +78,13 @@ _PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too)
51 _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout)
59 + sd_notifyf(0, "READY=0\nSTATUS=Starting process...\nMAINPID=%lu", (unsigned long) newpid);
60 +#endif /* HAVE_SYSTEMD */
64 @@ -100,3 +108,30 @@ _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout
65 * never close stderr (but debug might dup it onto a log file) */
66 close_low_fds(do_fork, !log_stdout, false);
69 +_PUBLIC_ void exit_daemon(const char *msg, int error)
73 + msg = strerror(error);
76 + sd_notifyf(0, "STATUS=daemon failed to start: %s\n"
81 + DEBUG(0, ("STATUS=daemon failed to start: %s, error code %d\n", msg, error));
85 +_PUBLIC_ void daemon_ready(const char *daemon)
87 + if (daemon == NULL) {
91 + sd_notifyf(0, "READY=1\nSTATUS=%s: ready to serve connections...", daemon);
93 + DEBUG(0, ("STATUS=daemon '%s' finished starting up and ready to serve connections", daemon));
95 diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
96 index f52347e..2996710 100644
97 --- a/lib/util/samba_util.h
98 +++ b/lib/util/samba_util.h
99 @@ -842,6 +842,18 @@ _PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too);
100 _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout);
103 + Exit daemon and print error message to the log at level 0
104 + Optionally report failure to systemd if systemd integration is enabled
106 +_PUBLIC_ void exit_daemon(const char *msg, int error);
109 + Report that the daemon is ready to serve connections to the log at level 0
110 + Optionally report status to systemd if systemd integration is enabled
112 +_PUBLIC_ void daemon_ready(const char *daemon);
115 * @brief Get a password from the console.
117 * You should make sure that the buffer is an empty string!
118 diff --git a/lib/util/wscript_build b/lib/util/wscript_build
119 index 39a1613..5087116 100755
120 --- a/lib/util/wscript_build
121 +++ b/lib/util/wscript_build
122 @@ -10,7 +10,7 @@ bld.SAMBA_LIBRARY('samba-util',
123 server_id.c dprintf.c parmlist.c bitmap.c pidfile.c
124 tevent_debug.c util_process.c''',
126 - public_deps='talloc tevent execinfo uid_wrapper pthread LIBCRYPTO charset util_setid',
127 + public_deps='talloc tevent execinfo uid_wrapper pthread LIBCRYPTO charset util_setid systemd-daemon',
128 public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h samba_util.h string_wrappers.h',
129 header_path= [ ('dlinklist.h samba_util.h', '.'), ('*', 'util') ],
131 diff --git a/packaging/systemd/nmb.service b/packaging/systemd/nmb.service
132 index e5e81a1..3d71a7d 100644
133 --- a/packaging/systemd/nmb.service
134 +++ b/packaging/systemd/nmb.service
135 @@ -3,7 +3,8 @@ Description=Samba NMB Daemon
136 After=syslog.target network.target
142 PIDFile=/run/nmbd.pid
143 EnvironmentFile=-/etc/sysconfig/samba
144 ExecStart=/usr/sbin/nmbd $NMBDOPTIONS
145 diff --git a/packaging/systemd/samba.service b/packaging/systemd/samba.service
146 index e2878d1..824f89c 100644
147 --- a/packaging/systemd/samba.service
148 +++ b/packaging/systemd/samba.service
149 @@ -3,7 +3,8 @@ Description=Samba AD Daemon
150 After=syslog.target network.target
156 PIDFile=/run/samba.pid
158 EnvironmentFile=-/etc/sysconfig/samba
159 diff --git a/packaging/systemd/smb.service b/packaging/systemd/smb.service
160 index d0d945a..9810891 100644
161 --- a/packaging/systemd/smb.service
162 +++ b/packaging/systemd/smb.service
163 @@ -3,7 +3,8 @@ Description=Samba SMB Daemon
164 After=syslog.target network.target nmb.service winbind.service
170 PIDFile=/run/smbd.pid
172 EnvironmentFile=-/etc/sysconfig/samba
173 diff --git a/packaging/systemd/winbind.service b/packaging/systemd/winbind.service
174 index eff266f..f711a17 100644
175 --- a/packaging/systemd/winbind.service
176 +++ b/packaging/systemd/winbind.service
177 @@ -3,7 +3,8 @@ Description=Samba Winbind Daemon
178 After=syslog.target network.target nmb.service
184 PIDFile=/run/winbindd.pid
185 EnvironmentFile=-/etc/sysconfig/samba
186 ExecStart=/usr/sbin/winbindd "$WINBINDOPTIONS"
187 diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
188 index ec0e7d0..aced774 100644
189 --- a/source3/nmbd/nmbd.c
190 +++ b/source3/nmbd/nmbd.c
191 @@ -1088,6 +1088,10 @@ static bool open_sockets(bool isdaemon, int port)
195 + if (is_daemon && !opt_interactive) {
196 + daemon_ready("nmbd");
202 diff --git a/source3/smbd/server.c b/source3/smbd/server.c
203 index d3cd33e..b2a9d8f 100644
204 --- a/source3/smbd/server.c
205 +++ b/source3/smbd/server.c
206 @@ -1489,6 +1489,10 @@ extern void build_options(bool screen);
210 + if (is_daemon && !interactive) {
211 + daemon_ready("smbd");
214 /* only start other daemons if we are running as a daemon
215 * -- bad things will happen if smbd is launched via inetd
216 * and we fork a copy of ourselves here */
217 diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
218 index 50573ac..61c1dbc 100644
219 --- a/source3/winbindd/winbindd.c
220 +++ b/source3/winbindd/winbindd.c
221 @@ -1581,6 +1581,11 @@ int main(int argc, char **argv, char **envp)
226 + if (!interactive) {
227 + daemon_ready("winbindd");
230 /* Loop waiting for requests */
232 frame = talloc_stackframe();
233 diff --git a/source4/smbd/server.c b/source4/smbd/server.c
234 index 37aac62..3a23190 100644
235 --- a/source4/smbd/server.c
236 +++ b/source4/smbd/server.c
237 @@ -498,6 +498,10 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
242 + daemon_ready("samba");
245 /* wait for events - this is where smbd sits for most of its
247 tevent_loop_wait(event_ctx);
248 diff --git a/wscript b/wscript
249 index 83c82e3..2f02c6e 100644
252 @@ -64,8 +64,15 @@ def set_options(opt):
253 help=("Disable Position Independent Executable builds"),
254 action="store_false", dest='enable_pie')
256 - gr = opt.option_group('developer options')
257 + opt.add_option('--with-systemd',
258 + help=("Enable systemd integration"),
259 + action='store_true', dest='enable_systemd')
261 + opt.add_option('--without-systemd',
262 + help=("Disable systemd integration"),
263 + action='store_false', dest='enable_systemd')
265 + gr = opt.option_group('developer options')
267 opt.tool_options('python') # options for disabling pyc or pyo compilation
268 # enable options related to building python extensions
269 @@ -162,11 +169,8 @@ def configure(conf):
270 if not conf.CHECK_CODE('#include "tests/summary.c"',
271 define='SUMMARY_PASSES',
274 msg='Checking configure summary'):
275 raise Utils.WafError('configure summary failed')
277 - conf.SAMBA_CONFIG_H('include/config.h')
279 if Options.options.enable_pie != False:
280 if Options.options.enable_pie == True:
281 @@ -178,6 +182,21 @@ def configure(conf):
282 msg="Checking compiler for PIE support"):
283 conf.env['ENABLE_PIE'] = True
285 + if Options.options.enable_systemd != False:
286 + conf.check_cfg(package='libsystemd-daemon', args='--cflags --libs',
287 + msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")
288 + conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
289 + conf.CHECK_LIB('systemd-daemon', shlib=True)
291 + if conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H'):
292 + conf.DEFINE('HAVE_SYSTEMD', '1')
293 + conf.env['ENABLE_SYSTEMD'] = True
295 + conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
296 + conf.undefine('HAVE_SYSTEMD')
298 + conf.SAMBA_CONFIG_H('include/config.h')
301 '''build TAGS file using etags'''
307 From a6250f706655bd8fda81fe15ccc9441f7d4e1c84 Mon Sep 17 00:00:00 2001
308 From: Alexander Bokovoy <ab@samba.org>
309 Date: Wed, 26 Mar 2014 10:56:12 +0200
310 Subject: [PATCH 2/5] smbd: use exit_daemon() to support reporting to systemd
313 BUG: https://bugzilla.samba.org/show_bug.cgi?id=10517
315 Signed-off-by: Alexander Bokovoy <ab@samba.org>
316 Reviewed-by: Andreas Schneider <asn@samba.org>
318 source3/smbd/server.c | 44 +++++++++++++++++++-------------------------
319 1 file changed, 19 insertions(+), 25 deletions(-)
321 diff --git a/source3/smbd/server.c b/source3/smbd/server.c
322 index b2a9d8f..34c949d 100644
323 --- a/source3/smbd/server.c
324 +++ b/source3/smbd/server.c
325 @@ -1314,8 +1314,7 @@ extern void build_options(bool screen);
328 if (!NT_STATUS_IS_OK(status)) {
329 - DEBUG(0,("reinit_after_fork() failed\n"));
331 + exit_daemon("reinit_after_fork() failed", map_errno_from_nt_status(status));
335 @@ -1326,8 +1325,7 @@ extern void build_options(bool screen);
337 status = init_before_fork();
338 if (!NT_STATUS_IS_OK(status)) {
339 - DEBUG(0, ("init_before_fork failed: %s\n", nt_errstr(status)));
341 + exit_daemon(nt_errstr(status), map_errno_from_nt_status(status));
345 @@ -1360,7 +1358,7 @@ extern void build_options(bool screen);
346 /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
348 if (smbd_memcache() == NULL) {
350 + exit_daemon("no memcache available", EACCES);
353 memcache_set_global(smbd_memcache());
354 @@ -1372,69 +1370,65 @@ extern void build_options(bool screen);
357 if (!secrets_init()) {
358 - DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
360 + exit_daemon("smbd can not open secrets.tdb", EACCES);
363 if (lp_server_role() == ROLE_DOMAIN_BDC || lp_server_role() == ROLE_DOMAIN_PDC) {
364 struct loadparm_context *lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
365 if (!open_schannel_session_store(NULL, lp_ctx)) {
366 - DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n"));
368 + exit_daemon("ERROR: Samba cannot open schannel store for secured NETLOGON operations.", EACCES);
373 if(!get_global_sam_sid()) {
374 - DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
376 + exit_daemon("Samba cannot create a SAM SID", EACCES);
379 server_id = messaging_server_id(msg_ctx);
380 status = smbXsrv_version_global_init(&server_id);
381 if (!NT_STATUS_IS_OK(status)) {
383 + exit_daemon("Samba cannot init server context", EACCES);
386 status = smbXsrv_session_global_init();
387 if (!NT_STATUS_IS_OK(status)) {
389 + exit_daemon("Samba cannot init session context", EACCES);
392 status = smbXsrv_tcon_global_init();
393 if (!NT_STATUS_IS_OK(status)) {
395 + exit_daemon("Samba cannot init tcon context", EACCES);
400 + exit_daemon("Samba cannot init locking", EACCES);
402 if (!messaging_tdb_parent_init(ev_ctx)) {
404 + exit_daemon("Samba cannot init TDB messaging", EACCES);
407 if (!smbd_parent_notify_init(NULL, msg_ctx, ev_ctx)) {
409 + exit_daemon("Samba cannot init notification", EACCES);
412 if (!smbd_scavenger_init(NULL, msg_ctx, ev_ctx)) {
414 + exit_daemon("Samba cannot init scavenging", EACCES);
417 if (!serverid_parent_init(ev_ctx)) {
419 + exit_daemon("Samba cannot init server id", EACCES);
422 if (!W_ERROR_IS_OK(registry_init_full()))
424 + exit_daemon("Samba cannot init registry", EACCES);
426 /* Open the share_info.tdb here, so we don't have to open
427 after the fork on every single connection. This is a small
428 performance improvment and reduces the total number of system
430 if (!share_info_db_init()) {
431 - DEBUG(0,("ERROR: failed to load share info db.\n"));
433 + exit_daemon("ERROR: failed to load share info db.", EACCES);
436 status = init_system_session_info();
437 @@ -1455,7 +1449,7 @@ extern void build_options(bool screen);
439 status = smbXsrv_open_global_init();
440 if (!NT_STATUS_IS_OK(status)) {
442 + exit_daemon("Samba cannot init global open", map_errno_from_nt_status(status));
445 /* This MUST be done before start_epmd() because otherwise
446 @@ -1486,7 +1480,7 @@ extern void build_options(bool screen);
449 if (!dcesrv_ep_setup(ev_ctx, msg_ctx)) {
451 + exit_daemon("Samba cannot setup ep pipe", EACCES);
454 if (is_daemon && !interactive) {
455 @@ -1507,7 +1501,7 @@ extern void build_options(bool screen);
456 bool bgq = lp_parm_bool(-1, "smbd", "backgroundqueue", true);
458 if (!printing_subsystem_init(ev_ctx, msg_ctx, true, bgq)) {
460 + exit_daemon("Samba failed to init printing subsystem", EACCES);
463 } else if (!lp__disable_spoolss() &&
468 From 580933198c1da02ad668b32f68bfeac833d97980 Mon Sep 17 00:00:00 2001
469 From: Alexander Bokovoy <ab@samba.org>
470 Date: Wed, 26 Mar 2014 11:34:56 +0200
471 Subject: [PATCH 3/5] nmbd: use exit_daemon() to report status to systemd
473 BUG: https://bugzilla.samba.org/show_bug.cgi?id=10517
475 Signed-off-by: Alexander Bokovoy <ab@samba.org>
476 Reviewed-by: Andreas Schneider <asn@samba.org>
478 (cherry picked from commit a54e94559b5ebabbb8c5c938fdf159efceff39e6)
480 source3/nmbd/nmbd.c | 39 ++++++++++++++-------------------------
481 1 file changed, 14 insertions(+), 25 deletions(-)
483 diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
484 index aced774..dc2d4c7 100644
485 --- a/source3/nmbd/nmbd.c
486 +++ b/source3/nmbd/nmbd.c
487 @@ -966,16 +966,12 @@ static bool open_sockets(bool isdaemon, int port)
489 ok = directory_create_or_exist(lp_lockdir(), geteuid(), 0755);
491 - DEBUG(0, ("Failed to create directory %s for lock files - %s\n",
492 - lp_lockdir(), strerror(errno)));
494 + exit_daemon("Failed to create directory for lock files, check 'lock directory'", errno);
497 ok = directory_create_or_exist(lp_piddir(), geteuid(), 0755);
499 - DEBUG(0, ("Failed to create directory %s for pid files - %s\n",
500 - lp_piddir(), strerror(errno)));
502 + exit_daemon("Failed to create directory for pid files, check 'pid directory'", errno);
505 pidfile_create(lp_piddir(), "nmbd");
506 @@ -984,8 +980,7 @@ static bool open_sockets(bool isdaemon, int port)
509 if (!NT_STATUS_IS_OK(status)) {
510 - DEBUG(0,("reinit_after_fork() failed\n"));
512 + exit_daemon("reinit_after_fork() failed", map_errno_from_nt_status(status));
516 @@ -995,16 +990,15 @@ static bool open_sockets(bool isdaemon, int port)
518 status = init_before_fork();
519 if (!NT_STATUS_IS_OK(status)) {
520 - DEBUG(0, ("init_before_fork failed: %s\n", nt_errstr(status)));
522 + exit_daemon(nt_errstr(status), map_errno_from_nt_status(status));
525 if (!nmbd_setup_sig_term_handler(msg))
527 + exit_daemon("NMBD failed to setup signal handler", EINVAL);
528 if (!nmbd_setup_stdin_handler(msg, !Fork))
530 + exit_daemon("NMBD failed to setup stdin handler", EINVAL);
531 if (!nmbd_setup_sig_hup_handler(msg))
533 + exit_daemon("NMBD failed to setup SIGHUP handler", EINVAL);
535 /* get broadcast messages */
537 @@ -1012,8 +1006,7 @@ static bool open_sockets(bool isdaemon, int port)
541 - DEBUG(1, ("Could not register myself in serverid.tdb\n"));
543 + exit_daemon("Could not register NMBD process in serverid.tdb", EACCES);
546 messaging_register(msg, NULL, MSG_FORCE_ELECTION,
547 @@ -1044,9 +1037,8 @@ static bool open_sockets(bool isdaemon, int port)
549 /* Create an nmbd subnet record for each of the above. */
550 if( False == create_subnets() ) {
551 - DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));
552 kill_async_dns_child();
554 + exit_daemon("NMBD failed when creating subnet lists", EACCES);
557 /* Load in any static local names. */
558 @@ -1058,9 +1050,8 @@ static bool open_sockets(bool isdaemon, int port)
560 /* If we are acting as a WINS server, initialise data structures. */
561 if( !initialise_wins() ) {
562 - DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );
563 kill_async_dns_child();
565 + exit_daemon( "NMBD failed when initialising WINS server.", EACCES);
569 @@ -1072,21 +1063,19 @@ static bool open_sockets(bool isdaemon, int port)
572 if( False == register_my_workgroup_and_names() ) {
573 - DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));
574 kill_async_dns_child();
576 + exit_daemon( "NMBD failed when creating my workgroup.", EACCES);
579 if (!initialize_nmbd_proxy_logon()) {
580 - DEBUG(0,("ERROR: Failed setup nmbd_proxy_logon.\n"));
581 kill_async_dns_child();
583 + exit_daemon( "NMBD failed to setup nmbd_proxy_logon.", EACCES);
586 if (!nmbd_init_packet_server()) {
587 kill_async_dns_child();
590 + exit_daemon( "NMBD failed to setup packet server.", EACCES);
593 if (is_daemon && !opt_interactive) {
594 daemon_ready("nmbd");
599 From 1067bdd3e590d5ab880044456c667e3663d99c95 Mon Sep 17 00:00:00 2001
600 From: Alexander Bokovoy <ab@samba.org>
601 Date: Wed, 26 Mar 2014 11:45:21 +0200
602 Subject: [PATCH 4/5] winbindd: use exit_daemon() to pass startup status to
605 BUG: https://bugzilla.samba.org/show_bug.cgi?id=10517
607 Signed-off-by: Alexander Bokovoy <ab@samba.org>
608 Reviewed-by: Andreas Schneider <asn@samba.org>
609 (cherry picked from commit 91013315c9fa946bf85c85df0ccd40a803f3dc6f)
611 source3/winbindd/winbindd.c | 13 ++++---------
612 1 file changed, 4 insertions(+), 9 deletions(-)
614 diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
615 index 61c1dbc..68ffd7e 100644
616 --- a/source3/winbindd/winbindd.c
617 +++ b/source3/winbindd/winbindd.c
618 @@ -1543,8 +1543,7 @@ int main(int argc, char **argv, char **envp)
619 winbind_event_context(),
621 if (!NT_STATUS_IS_OK(status)) {
622 - DEBUG(0,("reinit_after_fork() failed\n"));
624 + exit_daemon("Winbindd reinit_after_fork() failed", map_errno_from_nt_status(status));
628 @@ -1554,17 +1553,14 @@ int main(int argc, char **argv, char **envp)
630 status = init_before_fork();
631 if (!NT_STATUS_IS_OK(status)) {
632 - DEBUG(0, ("init_before_fork failed: %s\n", nt_errstr(status)));
634 + exit_daemon(nt_errstr(status), map_errno_from_nt_status(status));
637 winbindd_register_handlers(winbind_messaging_context(), !Fork);
639 status = init_system_session_info();
640 if (!NT_STATUS_IS_OK(status)) {
641 - DEBUG(1, ("ERROR: failed to setup system user info: %s.\n",
642 - nt_errstr(status)));
644 + exit_daemon("Winbindd failed to setup system user info", map_errno_from_nt_status(status));
647 rpc_lsarpc_init(NULL);
648 @@ -1576,8 +1572,7 @@ int main(int argc, char **argv, char **envp)
649 /* setup listen sockets */
651 if (!winbindd_setup_listeners()) {
652 - DEBUG(0,("winbindd_setup_listeners() failed\n"));
654 + exit_daemon("Winbindd failed to setup listeners", EPIPE);
662 From 037b9fd66e777571e2c963945e41535371b4683e Mon Sep 17 00:00:00 2001
663 From: Alexander Bokovoy <ab@samba.org>
664 Date: Wed, 26 Mar 2014 12:30:30 +0200
665 Subject: [PATCH 5/5] ad-dc: use exit_daemon() to communicate status of startup
668 BUG: https://bugzilla.samba.org/show_bug.cgi?id=10517
670 Signed-off-by: Alexander Bokovoy <ab@samba.org>
671 Reviewed-by: Andreas Schneider <asn@samba.org>
672 (cherry picked from commit a343303cbcd5af303455843ebf202e2f30daf3a6)
674 source4/smbd/server.c | 19 +++++++------------
675 1 file changed, 7 insertions(+), 12 deletions(-)
677 diff --git a/source4/smbd/server.c b/source4/smbd/server.c
678 index 3a23190..d5d9d9c 100644
679 --- a/source4/smbd/server.c
680 +++ b/source4/smbd/server.c
681 @@ -398,15 +398,13 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
683 if (lpcfg_server_role(cmdline_lp_ctx) == ROLE_ACTIVE_DIRECTORY_DC) {
684 if (!open_schannel_session_store(talloc_autofree_context(), cmdline_lp_ctx)) {
685 - DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n"));
687 + exit_daemon("Samba cannot open schannel store for secured NETLOGON operations.", EACCES);
691 /* make sure we won't go through nss_winbind */
692 if (!winbind_off()) {
693 - DEBUG(0,("Failed to disable recusive winbindd calls. Exiting.\n"));
695 + exit_daemon("Samba failed to disable recusive winbindd calls.", EACCES);
698 gensec_init(); /* FIXME: */
699 @@ -431,8 +429,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
700 event_ctx = s4_event_context_init(talloc_autofree_context());
702 if (event_ctx == NULL) {
703 - DEBUG(0,("Initializing event context failed\n"));
705 + exit_daemon("Initializing event context failed", EACCES);
708 if (opt_interactive) {
709 @@ -449,7 +446,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
712 if (fstat(0, &st) != 0) {
714 + exit_daemon("Samba failed to set standard input handler", ENOTTY);
717 if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
718 @@ -478,15 +475,14 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
719 DEBUG(0, ("At this time the 'samba' binary should only be used for either:\n"));
720 DEBUGADD(0, ("'server role = active directory domain controller' or to access the ntvfs file server with 'server services = +smb' or the rpc proxy with 'dcerpc endpoint servers = remote'\n"));
721 DEBUGADD(0, ("You should start smbd/nmbd/winbindd instead for domain member and standalone file server tasks\n"));
723 + exit_daemon("Samba detected misconfigured 'server role' and exited. Check logs for details", EINVAL);
726 prime_ldb_databases(event_ctx);
728 status = setup_parent_messaging(event_ctx, cmdline_lp_ctx);
729 if (!NT_STATUS_IS_OK(status)) {
730 - DEBUG(0,("Failed to setup parent messaging - %s\n", nt_errstr(status)));
732 + exit_daemon("Samba failed to setup parent messaging", NT_STATUS_V(status));
735 DEBUG(0,("%s: using '%s' process model\n", binary_name, model));
736 @@ -494,8 +490,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
737 status = server_service_startup(event_ctx, cmdline_lp_ctx, model,
738 lpcfg_server_services(cmdline_lp_ctx));
739 if (!NT_STATUS_IS_OK(status)) {
740 - DEBUG(0,("Starting Services failed - %s\n", nt_errstr(status)));
742 + exit_daemon("Samba failed to start services", NT_STATUS_V(status));