2 Unix SMB/CIFS implementation.
3 NBT netbios routines and daemon - version 2
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Jeremy Allison 1997-2002
6 Copyright (C) Jelmer Vernooij 2002,2003 (Conversion to popt)
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/>.
23 #include "system/filesys.h"
24 #include "popt_common.h"
25 #include "nmbd/nmbd.h"
28 #include "../lib/util/pidfile.h"
29 #include "util_cluster.h"
33 int global_nmb_port
= -1;
35 extern bool rescan_listen_set
;
36 extern bool global_in_nmbd
;
38 extern bool override_logfile
;
40 /* have we found LanMan clients yet? */
41 bool found_lm_clients
= False
;
43 /* what server type are we currently */
45 time_t StartupTime
= 0;
47 struct tevent_context
*nmbd_event_context(void)
49 return server_event_context();
52 /**************************************************************************** **
53 Handle a SIGTERM in band.
54 **************************************************************************** */
56 static void terminate(struct messaging_context
*msg
)
58 DEBUG(0,("Got SIGTERM: going down...\n"));
60 /* Write out wins.dat file if samba is a WINS server */
61 wins_write_database(0,False
);
63 /* Remove all SELF registered names from WINS */
66 /* Announce all server entries as 0 time-to-live, 0 type. */
67 announce_my_servers_removed();
69 /* If there was an async dns child - kill it. */
70 kill_async_dns_child();
73 serverid_deregister(messaging_server_id(msg
));
75 pidfile_unlink(lp_pid_directory(), "nmbd");
80 static void nmbd_sig_term_handler(struct tevent_context
*ev
,
81 struct tevent_signal
*se
,
87 struct messaging_context
*msg
= talloc_get_type_abort(
88 private_data
, struct messaging_context
);
94 handle stdin becoming readable when we are in --foreground mode
96 static void nmbd_stdin_handler(struct tevent_context
*ev
,
97 struct tevent_fd
*fde
,
102 if (read(0, &c
, 1) != 1) {
103 struct messaging_context
*msg
= talloc_get_type_abort(
104 private_data
, struct messaging_context
);
106 DEBUG(0,("EOF on stdin\n"));
111 static bool nmbd_setup_sig_term_handler(struct messaging_context
*msg
)
113 struct tevent_signal
*se
;
115 se
= tevent_add_signal(nmbd_event_context(),
116 nmbd_event_context(),
118 nmbd_sig_term_handler
,
121 DEBUG(0,("failed to setup SIGTERM handler"));
128 static bool nmbd_setup_stdin_handler(struct messaging_context
*msg
, bool foreground
)
131 /* if we are running in the foreground then look for
132 EOF on stdin, and exit if it happens. This allows
133 us to die if the parent process dies
134 Only do this on a pipe or socket, no other device.
137 if (fstat(0, &st
) != 0) {
140 if (S_ISFIFO(st
.st_mode
) || S_ISSOCK(st
.st_mode
)) {
141 tevent_add_fd(nmbd_event_context(),
142 nmbd_event_context(),
153 static void msg_reload_nmbd_services(struct messaging_context
*msg
,
156 struct server_id server_id
,
159 static void nmbd_sig_hup_handler(struct tevent_context
*ev
,
160 struct tevent_signal
*se
,
166 struct messaging_context
*msg
= talloc_get_type_abort(
167 private_data
, struct messaging_context
);
169 DEBUG(0,("Got SIGHUP dumping debug info.\n"));
170 msg_reload_nmbd_services(msg
, NULL
, MSG_SMB_CONF_UPDATED
,
171 messaging_server_id(msg
), NULL
);
174 static bool nmbd_setup_sig_hup_handler(struct messaging_context
*msg
)
176 struct tevent_signal
*se
;
178 se
= tevent_add_signal(nmbd_event_context(),
179 nmbd_event_context(),
181 nmbd_sig_hup_handler
,
184 DEBUG(0,("failed to setup SIGHUP handler"));
191 /**************************************************************************** **
192 Handle a SHUTDOWN message from smbcontrol.
193 **************************************************************************** */
195 static void nmbd_terminate(struct messaging_context
*msg
,
198 struct server_id server_id
,
204 /**************************************************************************** **
205 Expire old names from the namelist and server list.
206 **************************************************************************** */
208 static void expire_names_and_servers(time_t t
)
210 static time_t lastrun
= 0;
214 if ( t
< (lastrun
+ 5) )
219 * Expire any timed out names on all the broadcast
220 * subnets and those registered with the WINS server.
221 * (nmbd_namelistdb.c)
227 * Go through all the broadcast subnets and for each
228 * workgroup known on that subnet remove any expired
229 * server names. If a workgroup has an empty serverlist
230 * and has itself timed out then remove the workgroup.
231 * (nmbd_workgroupdb.c)
234 expire_workgroups_and_servers(t
);
237 /************************************************************************** **
238 Reload the list of network interfaces.
239 Doesn't return until a network interface is up.
240 ************************************************************************** */
242 static void reload_interfaces(time_t t
)
246 bool print_waiting_msg
= true;
247 struct subnet_record
*subrec
;
249 if (t
&& ((t
- lastt
) < NMBD_INTERFACES_RELOAD
)) {
255 if (!interfaces_changed()) {
261 /* the list of probed interfaces has changed, we may need to add/remove
265 /* find any interfaces that need adding */
266 for (n
=iface_count() - 1; n
>= 0; n
--) {
267 char str
[INET6_ADDRSTRLEN
];
268 const struct interface
*iface
= get_interface(n
);
269 struct in_addr ip
, nmask
;
272 DEBUG(2,("reload_interfaces: failed to get interface %d\n", n
));
276 /* Ensure we're only dealing with IPv4 here. */
277 if (iface
->ip
.ss_family
!= AF_INET
) {
278 DEBUG(2,("reload_interfaces: "
279 "ignoring non IPv4 interface.\n"));
283 ip
= ((const struct sockaddr_in
*)(const void *)&iface
->ip
)->sin_addr
;
284 nmask
= ((const struct sockaddr_in
*)(const void *)
285 &iface
->netmask
)->sin_addr
;
288 * We don't want to add a loopback interface, in case
289 * someone has added 127.0.0.1 for smbd, nmbd needs to
290 * ignore it here. JRA.
293 if (is_loopback_addr((const struct sockaddr
*)(const void *)&iface
->ip
)) {
294 DEBUG(2,("reload_interfaces: Ignoring loopback "
296 print_sockaddr(str
, sizeof(str
), &iface
->ip
) ));
300 for (subrec
=subnetlist
; subrec
; subrec
=subrec
->next
) {
301 if (ip_equal_v4(ip
, subrec
->myip
) &&
302 ip_equal_v4(nmask
, subrec
->mask_ip
)) {
308 /* it wasn't found! add it */
309 DEBUG(2,("Found new interface %s\n",
311 sizeof(str
), &iface
->ip
) ));
312 subrec
= make_normal_subnet(iface
);
314 register_my_workgroup_one_subnet(subrec
);
318 /* find any interfaces that need deleting */
319 for (subrec
=subnetlist
; subrec
; subrec
=subrec
->next
) {
320 for (n
=iface_count() - 1; n
>= 0; n
--) {
321 struct interface
*iface
= get_interface(n
);
322 struct in_addr ip
, nmask
;
326 /* Ensure we're only dealing with IPv4 here. */
327 if (iface
->ip
.ss_family
!= AF_INET
) {
328 DEBUG(2,("reload_interfaces: "
329 "ignoring non IPv4 interface.\n"));
332 ip
= ((struct sockaddr_in
*)(void *)
333 &iface
->ip
)->sin_addr
;
334 nmask
= ((struct sockaddr_in
*)(void *)
335 &iface
->netmask
)->sin_addr
;
336 if (ip_equal_v4(ip
, subrec
->myip
) &&
337 ip_equal_v4(nmask
, subrec
->mask_ip
)) {
342 /* oops, an interface has disapeared. This is
343 tricky, we don't dare actually free the
344 interface as it could be being used, so
345 instead we just wear the memory leak and
346 remove it from the list of interfaces without
348 DEBUG(2,("Deleting dead interface %s\n",
349 inet_ntoa(subrec
->myip
)));
350 close_subnet(subrec
);
354 rescan_listen_set
= True
;
356 /* We need to wait if there are no subnets... */
357 if (FIRST_SUBNET
== NULL
) {
358 void (*saved_handler
)(int);
360 if (print_waiting_msg
) {
361 DEBUG(0,("reload_interfaces: "
362 "No subnets to listen to. Waiting..\n"));
363 print_waiting_msg
= false;
367 * Whilst we're waiting for an interface, allow SIGTERM to
370 saved_handler
= CatchSignal(SIGTERM
, SIG_DFL
);
372 /* We only count IPv4, non-loopback interfaces here. */
373 while (iface_count_v4_nl() == 0) {
378 CatchSignal(SIGTERM
, saved_handler
);
381 * We got an interface, go back to blocking term.
388 /**************************************************************************** **
389 Reload the services file.
390 **************************************************************************** */
392 static bool reload_nmbd_services(bool test
)
396 set_remote_machine_name("nmbd", False
);
399 char *fname
= lp_next_configfile(talloc_tos());
400 if (file_exist(fname
) && !strcsequal(fname
,get_dyn_CONFIGFILE())) {
401 set_dyn_CONFIGFILE(fname
);
407 if ( test
&& !lp_file_list_changed() )
410 ret
= lp_load_global(get_dyn_CONFIGFILE());
412 /* perhaps the config filename is now set */
414 DEBUG( 3, ( "services not loaded\n" ) );
415 reload_nmbd_services( True
);
423 /**************************************************************************** **
424 * React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP
425 **************************************************************************** */
427 static void msg_reload_nmbd_services(struct messaging_context
*msg
,
430 struct server_id server_id
,
433 write_browse_list( 0, True
);
434 dump_all_namelists();
435 reload_nmbd_services( True
);
437 reload_interfaces(0);
440 static void msg_nmbd_send_packet(struct messaging_context
*msg
,
443 struct server_id src
,
446 struct packet_struct
*p
= (struct packet_struct
*)data
->data
;
447 struct subnet_record
*subrec
;
448 struct sockaddr_storage ss
;
449 const struct sockaddr_storage
*pss
;
450 const struct in_addr
*local_ip
;
452 DEBUG(10, ("Received send_packet from %u\n", (unsigned int)procid_to_pid(&src
)));
454 if (data
->length
!= sizeof(struct packet_struct
)) {
455 DEBUG(2, ("Discarding invalid packet length from %u\n",
456 (unsigned int)procid_to_pid(&src
)));
460 if ((p
->packet_type
!= NMB_PACKET
) &&
461 (p
->packet_type
!= DGRAM_PACKET
)) {
462 DEBUG(2, ("Discarding invalid packet type from %u: %d\n",
463 (unsigned int)procid_to_pid(&src
), p
->packet_type
));
467 in_addr_to_sockaddr_storage(&ss
, p
->ip
);
468 pss
= iface_ip((struct sockaddr
*)(void *)&ss
);
471 DEBUG(2, ("Could not find ip for packet from %u\n",
472 (unsigned int)procid_to_pid(&src
)));
476 local_ip
= &((const struct sockaddr_in
*)pss
)->sin_addr
;
477 subrec
= FIRST_SUBNET
;
480 p
->send_fd
= (p
->packet_type
== NMB_PACKET
) ?
481 subrec
->nmb_sock
: subrec
->dgram_sock
;
483 for (subrec
= FIRST_SUBNET
; subrec
!= NULL
;
484 subrec
= NEXT_SUBNET_EXCLUDING_UNICAST(subrec
)) {
485 if (ip_equal_v4(*local_ip
, subrec
->myip
)) {
486 p
->send_fd
= (p
->packet_type
== NMB_PACKET
) ?
487 subrec
->nmb_sock
: subrec
->dgram_sock
;
492 if (p
->packet_type
== DGRAM_PACKET
) {
494 p
->packet
.dgram
.header
.source_ip
.s_addr
= local_ip
->s_addr
;
495 p
->packet
.dgram
.header
.source_port
= 138;
501 /**************************************************************************** **
502 The main select loop.
503 **************************************************************************** */
505 static void process(struct messaging_context
*msg
)
510 time_t t
= time(NULL
);
511 TALLOC_CTX
*frame
= talloc_stackframe();
514 * Check all broadcast subnets to see if
515 * we need to run an election on any of them.
519 run_election
= check_elections();
522 * Read incoming UDP packets.
526 if (listen_for_packets(msg
, run_election
)) {
532 * Process all incoming packets
533 * read above. This calls the success and
534 * failure functions registered when response
535 * packets arrrive, and also deals with request
536 * packets from other sources.
543 * Run any elections - initiate becoming
544 * a local master browser if we have won.
551 * Send out any broadcast announcements
552 * of our server names. This also announces
553 * the workgroup name if we are a local
555 * (nmbd_sendannounce.c)
558 announce_my_server_names(t
);
561 * Send out any LanMan broadcast announcements
562 * of our server names.
563 * (nmbd_sendannounce.c)
566 announce_my_lm_server_names(t
);
569 * If we are a local master browser, periodically
570 * announce ourselves to the domain master browser.
571 * This also deals with syncronising the domain master
572 * browser server lists with ourselves as a local
574 * (nmbd_sendannounce.c)
577 announce_myself_to_domain_master_browser(t
);
580 * Fullfill any remote announce requests.
581 * (nmbd_sendannounce.c)
587 * Fullfill any remote browse sync announce requests.
588 * (nmbd_sendannounce.c)
591 browse_sync_remote(t
);
594 * Scan the broadcast subnets, and WINS client
595 * namelists and refresh any that need refreshing.
602 * Scan the subnet namelists and server lists and
603 * expire thos that have timed out.
607 expire_names_and_servers(t
);
610 * Write out a snapshot of our current browse list into
611 * the browse.dat file. This is used by smbd to service
612 * incoming NetServerEnum calls - used to synchronise
613 * browse lists over subnets.
614 * (nmbd_serverlistdb.c)
617 write_browse_list(t
, False
);
620 * If we are a domain master browser, we have a list of
621 * local master browsers we should synchronise browse
622 * lists with (these are added by an incoming local
623 * master browser announcement packet). Expire any of
624 * these that are no longer current, and pull the server
625 * lists from each of these known local master browsers.
626 * (nmbd_browsesync.c)
629 dmb_expire_and_sync_browser_lists(t
);
632 * Check that there is a local master browser for our
633 * workgroup for all our broadcast subnets. If one
634 * is not found, start an election (which we ourselves
635 * may or may not participate in, depending on the
636 * setting of the 'local master' parameter.
640 check_master_browser_exists(t
);
643 * If we are configured as a logon server, attempt to
644 * register the special NetBIOS names to become such
645 * (WORKGROUP<1c> name) on all broadcast subnets and
646 * with the WINS server (if used). If we are configured
647 * to become a domain master browser, attempt to register
648 * the special NetBIOS name (WORKGROUP<1b> name) to
650 * (nmbd_become_dmb.c)
656 * If we are a WINS server, do any timer dependent
657 * processing required.
658 * (nmbd_winsserver.c)
661 initiate_wins_processing(t
);
664 * If we are a domain master browser, attempt to contact the
665 * WINS server to get a list of all known WORKGROUPS/DOMAINS.
666 * This will only work to a Samba WINS server.
667 * (nmbd_browsesync.c)
670 if (lp_enhanced_browsing())
671 collect_all_workgroup_names_from_wins_server(t
);
674 * Go through the response record queue and time out or re-transmit
675 * and expired entries.
679 retransmit_or_expire_response_records(t
);
682 * check to see if any remote browse sync child processes have completed
685 sync_check_completion();
688 * regularly sync with any other DMBs we know about
691 if (lp_enhanced_browsing())
694 /* check for new network interfaces */
696 reload_interfaces(t
);
698 /* free up temp memory */
703 /**************************************************************************** **
704 Open the socket communication.
705 **************************************************************************** */
707 static bool open_sockets(bool isdaemon
, int port
)
709 struct sockaddr_storage ss
;
710 const char *sock_addr
= lp_nbt_client_socket_address();
713 * The sockets opened here will be used to receive broadcast
714 * packets *only*. Interface specific sockets are opened in
715 * make_subnet() in namedbsubnet.c. Thus we bind to the
716 * address "0.0.0.0". The parameter 'socket address' is
720 if (!interpret_string_addr(&ss
, sock_addr
,
721 AI_NUMERICHOST
|AI_PASSIVE
)) {
722 DEBUG(0,("open_sockets: unable to get socket address "
723 "from string %s", sock_addr
));
726 if (ss
.ss_family
!= AF_INET
) {
727 DEBUG(0,("open_sockets: unable to use IPv6 socket"
734 ClientNMB
= open_socket_in(SOCK_DGRAM
, port
,
741 if (ClientNMB
== -1) {
745 ClientDGRAM
= open_socket_in(SOCK_DGRAM
, DGRAM_PORT
,
749 if (ClientDGRAM
== -1) {
750 if (ClientNMB
!= 0) {
756 /* we are never interested in SIGPIPE */
757 BlockSignals(True
,SIGPIPE
);
759 set_socket_options( ClientNMB
, "SO_BROADCAST" );
760 set_socket_options( ClientDGRAM
, "SO_BROADCAST" );
762 /* Ensure we're non-blocking. */
763 set_blocking( ClientNMB
, False
);
764 set_blocking( ClientDGRAM
, False
);
766 DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) );
770 /**************************************************************************** **
772 **************************************************************************** */
774 int main(int argc
, const char *argv
[])
776 bool is_daemon
= false;
777 bool opt_interactive
= false;
779 bool no_process_group
= false;
780 bool log_stdout
= false;
782 char *p_lmhosts
= NULL
;
784 struct messaging_context
*msg
;
789 OPT_NO_PROCESS_GROUP
,
792 struct poptOption long_options
[] = {
794 {"daemon", 'D', POPT_ARG_NONE
, NULL
, OPT_DAEMON
, "Become a daemon(default)" },
795 {"interactive", 'i', POPT_ARG_NONE
, NULL
, OPT_INTERACTIVE
, "Run interactive (not a daemon)" },
796 {"foreground", 'F', POPT_ARG_NONE
, NULL
, OPT_FORK
, "Run daemon in foreground (for daemontools & etc)" },
797 {"no-process-group", 0, POPT_ARG_NONE
, NULL
, OPT_NO_PROCESS_GROUP
, "Don't create a new process group" },
798 {"log-stdout", 'S', POPT_ARG_NONE
, NULL
, OPT_LOG_STDOUT
, "Log to stdout" },
799 {"hosts", 'H', POPT_ARG_STRING
, &p_lmhosts
, 0, "Load a netbios hosts file"},
800 {"port", 'p', POPT_ARG_INT
, &global_nmb_port
, 0, "Listen on the specified port" },
809 * Do this before any other talloc operation
811 talloc_enable_null_tracking();
812 frame
= talloc_stackframe();
815 * We want total control over the permissions on created files,
816 * so set our umask to 0.
820 setup_logging(argv
[0], DEBUG_DEFAULT_STDOUT
);
824 global_nmb_port
= NMB_PORT
;
826 pc
= poptGetContext("nmbd", argc
, argv
, long_options
, 0);
827 while ((opt
= poptGetNextOpt(pc
)) != -1) {
832 case OPT_INTERACTIVE
:
833 opt_interactive
= true;
838 case OPT_NO_PROCESS_GROUP
:
839 no_process_group
= true;
845 d_fprintf(stderr
, "\nInvalid option %s: %s\n\n",
846 poptBadOption(pc
, 0), poptStrerror(opt
));
847 poptPrintUsage(pc
, stderr
, 0);
853 global_in_nmbd
= true;
855 StartupTime
= time(NULL
);
857 sys_srandom(time(NULL
) ^ getpid());
859 if (!override_logfile
) {
861 if (asprintf(&lfile
, "%s/log.nmbd", get_dyn_LOGFILEBASE()) < 0) {
864 lp_set_logfile(lfile
);
869 dump_core_setup("nmbd", lp_logfile(talloc_tos()));
871 /* POSIX demands that signals are inherited. If the invoking process has
872 * these signals masked, we will have problems, as we won't receive them. */
873 BlockSignals(False
, SIGHUP
);
874 BlockSignals(False
, SIGUSR1
);
875 BlockSignals(False
, SIGTERM
);
878 /* we are never interested in SIGFPE */
879 BlockSignals(True
,SIGFPE
);
882 /* We no longer use USR2... */
884 BlockSignals(True
, SIGUSR2
);
887 /* Ignore children - no zombies. */
890 if ( opt_interactive
) {
895 if ( log_stdout
&& Fork
) {
896 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
901 setup_logging(argv
[0], DEBUG_STDOUT
);
903 setup_logging( argv
[0], DEBUG_FILE
);
908 DEBUG(0,("nmbd version %s started.\n", samba_version_string()));
909 DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE
));
911 if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
912 DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE()));
918 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
919 && !lp_parm_bool(-1, "server role check", "inhibit", false)) {
920 /* TODO: when we have a merged set of defaults for
921 * loadparm, we could possibly check if the internal
922 * nbt server is in the list, and allow a startup if disabled */
923 DEBUG(0, ("server role = 'active directory domain controller' not compatible with running nmbd standalone. \n"));
924 DEBUGADD(0, ("You should start 'samba' instead, and it will control starting the internal nbt server\n"));
928 if (!cluster_probe_ok()) {
932 msg
= messaging_init(NULL
, server_event_context());
937 if ( !reload_nmbd_services(False
) )
943 reload_nmbd_services( True
);
945 if (strequal(lp_workgroup(),"*")) {
946 DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n"));
952 if (!is_daemon
&& !is_a_socket(0)) {
953 DEBUG(3, ("standard input is not a socket, assuming -D option\n"));
957 if (is_daemon
&& !opt_interactive
) {
958 DEBUG(3, ("Becoming a daemon.\n"));
959 become_daemon(Fork
, no_process_group
, log_stdout
);
964 * If we're interactive we want to set our own process group for
967 if (opt_interactive
&& !no_process_group
)
968 setpgid( (pid_t
)0, (pid_t
)0 );
972 /* Setup the async dns. We do it here so it doesn't have all the other
973 stuff initialised and thus chewing memory and sockets */
974 if(lp_we_are_a_wins_server() && lp_wins_dns_proxy()) {
975 start_async_dns(msg
);
979 ok
= directory_create_or_exist(lp_lock_directory(), 0755);
981 exit_daemon("Failed to create directory for lock files, check 'lock directory'", errno
);
984 ok
= directory_create_or_exist(lp_pid_directory(), 0755);
986 exit_daemon("Failed to create directory for pid files, check 'pid directory'", errno
);
989 pidfile_create(lp_pid_directory(), "nmbd");
991 status
= reinit_after_fork(msg
, nmbd_event_context(),
994 if (!NT_STATUS_IS_OK(status
)) {
995 exit_daemon("reinit_after_fork() failed", map_errno_from_nt_status(status
));
999 * Do not initialize the parent-child-pipe before becoming
1000 * a daemon: this is used to detect a died parent in the child
1003 status
= init_before_fork();
1004 if (!NT_STATUS_IS_OK(status
)) {
1005 exit_daemon(nt_errstr(status
), map_errno_from_nt_status(status
));
1008 if (!nmbd_setup_sig_term_handler(msg
))
1009 exit_daemon("NMBD failed to setup signal handler", EINVAL
);
1010 if (!nmbd_setup_stdin_handler(msg
, !Fork
))
1011 exit_daemon("NMBD failed to setup stdin handler", EINVAL
);
1012 if (!nmbd_setup_sig_hup_handler(msg
))
1013 exit_daemon("NMBD failed to setup SIGHUP handler", EINVAL
);
1015 if (!messaging_parent_dgm_cleanup_init(msg
)) {
1019 /* get broadcast messages */
1021 if (!serverid_register(messaging_server_id(msg
),
1025 exit_daemon("Could not register NMBD process in serverid.tdb", EACCES
);
1028 messaging_register(msg
, NULL
, MSG_FORCE_ELECTION
,
1029 nmbd_message_election
);
1031 /* Until winsrepl is done. */
1032 messaging_register(msg
, NULL
, MSG_WINS_NEW_ENTRY
,
1033 nmbd_wins_new_entry
);
1035 messaging_register(msg
, NULL
, MSG_SHUTDOWN
,
1037 messaging_register(msg
, NULL
, MSG_SMB_CONF_UPDATED
,
1038 msg_reload_nmbd_services
);
1039 messaging_register(msg
, NULL
, MSG_SEND_PACKET
,
1040 msg_nmbd_send_packet
);
1044 DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port
) );
1046 if ( !open_sockets( is_daemon
, global_nmb_port
) ) {
1047 kill_async_dns_child();
1051 /* Determine all the IP addresses we have. */
1054 /* Create an nmbd subnet record for each of the above. */
1055 if( False
== create_subnets() ) {
1056 kill_async_dns_child();
1057 exit_daemon("NMBD failed when creating subnet lists", EACCES
);
1060 /* Load in any static local names. */
1062 set_dyn_LMHOSTSFILE(p_lmhosts
);
1064 load_lmhosts_file(get_dyn_LMHOSTSFILE());
1065 DEBUG(3,("Loaded hosts file %s\n", get_dyn_LMHOSTSFILE()));
1067 /* If we are acting as a WINS server, initialise data structures. */
1068 if( !initialise_wins() ) {
1069 kill_async_dns_child();
1070 exit_daemon( "NMBD failed when initialising WINS server.", EACCES
);
1074 * Register nmbd primary workgroup and nmbd names on all
1075 * the broadcast subnets, and on the WINS server (if specified).
1076 * Also initiate the startup of our primary workgroup (start
1077 * elections if we are setup as being able to be a local
1081 if( False
== register_my_workgroup_and_names() ) {
1082 kill_async_dns_child();
1083 exit_daemon( "NMBD failed when creating my workgroup.", EACCES
);
1086 if (!initialize_nmbd_proxy_logon()) {
1087 kill_async_dns_child();
1088 exit_daemon( "NMBD failed to setup nmbd_proxy_logon.", EACCES
);
1091 if (!nmbd_init_packet_server()) {
1092 kill_async_dns_child();
1093 exit_daemon( "NMBD failed to setup packet server.", EACCES
);
1096 if (is_daemon
&& !opt_interactive
) {
1097 daemon_ready("nmbd");
1103 kill_async_dns_child();