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 "lib/cmdline/cmdline.h"
25 #include "nmbd/nmbd.h"
28 #include "../lib/util/pidfile.h"
29 #include "util_cluster.h"
30 #include "lib/gencache.h"
31 #include "lib/global_contexts.h"
32 #include "source3/lib/substitute.h"
36 int global_nmb_port
= -1;
38 extern bool rescan_listen_set
;
39 extern bool global_in_nmbd
;
41 /* have we found LanMan clients yet? */
42 bool found_lm_clients
= False
;
44 /* what server type are we currently */
46 time_t StartupTime
= 0;
48 struct tevent_context
*nmbd_event_context(void)
50 return global_event_context();
53 /**************************************************************************** **
54 Handle a SIGTERM in band.
55 **************************************************************************** */
57 static void terminate(struct messaging_context
*msg
)
59 DBG_WARNING("Got SIGTERM: going down...\n");
61 /* Write out wins.dat file if samba is a WINS server */
62 wins_write_database(0,False
);
64 /* Remove all SELF registered names from WINS */
67 /* Announce all server entries as 0 time-to-live, 0 type. */
68 announce_my_servers_removed();
70 /* If there was an async dns child - kill it. */
71 kill_async_dns_child();
73 pidfile_unlink(lp_pid_directory(), "nmbd");
78 static void nmbd_sig_term_handler(struct tevent_context
*ev
,
79 struct tevent_signal
*se
,
85 struct messaging_context
*msg
= talloc_get_type_abort(
86 private_data
, struct messaging_context
);
92 handle stdin becoming readable when we are in --foreground mode
94 static void nmbd_stdin_handler(struct tevent_context
*ev
,
95 struct tevent_fd
*fde
,
100 if (read(0, &c
, 1) != 1) {
101 struct messaging_context
*msg
= talloc_get_type_abort(
102 private_data
, struct messaging_context
);
104 DBG_WARNING("EOF on stdin\n");
109 static bool nmbd_setup_sig_term_handler(struct messaging_context
*msg
)
111 struct tevent_signal
*se
;
113 se
= tevent_add_signal(nmbd_event_context(),
114 nmbd_event_context(),
116 nmbd_sig_term_handler
,
119 DBG_ERR("failed to setup SIGTERM handler\n");
126 static bool nmbd_setup_stdin_handler(struct messaging_context
*msg
, bool foreground
)
129 /* if we are running in the foreground then look for
130 EOF on stdin, and exit if it happens. This allows
131 us to die if the parent process dies
132 Only do this on a pipe or socket, no other device.
135 if (fstat(0, &st
) != 0) {
138 if (S_ISFIFO(st
.st_mode
) || S_ISSOCK(st
.st_mode
)) {
139 tevent_add_fd(nmbd_event_context(),
140 nmbd_event_context(),
151 static void msg_reload_nmbd_services(struct messaging_context
*msg
,
154 struct server_id server_id
,
157 static void nmbd_sig_hup_handler(struct tevent_context
*ev
,
158 struct tevent_signal
*se
,
164 struct messaging_context
*msg
= talloc_get_type_abort(
165 private_data
, struct messaging_context
);
167 DBG_WARNING("Got SIGHUP dumping debug info.\n");
168 msg_reload_nmbd_services(msg
, NULL
, MSG_SMB_CONF_UPDATED
,
169 messaging_server_id(msg
), NULL
);
172 static bool nmbd_setup_sig_hup_handler(struct messaging_context
*msg
)
174 struct tevent_signal
*se
;
176 se
= tevent_add_signal(nmbd_event_context(),
177 nmbd_event_context(),
179 nmbd_sig_hup_handler
,
182 DBG_ERR("failed to setup SIGHUP handler\n");
189 /**************************************************************************** **
190 Handle a SHUTDOWN message from smbcontrol.
191 **************************************************************************** */
193 static void nmbd_terminate(struct messaging_context
*msg
,
196 struct server_id server_id
,
202 /**************************************************************************** **
203 Expire old names from the namelist and server list.
204 **************************************************************************** */
206 static void expire_names_and_servers(time_t t
)
208 static time_t lastrun
= 0;
212 if ( t
< (lastrun
+ 5) )
217 * Expire any timed out names on all the broadcast
218 * subnets and those registered with the WINS server.
219 * (nmbd_namelistdb.c)
225 * Go through all the broadcast subnets and for each
226 * workgroup known on that subnet remove any expired
227 * server names. If a workgroup has an empty serverlist
228 * and has itself timed out then remove the workgroup.
229 * (nmbd_workgroupdb.c)
232 expire_workgroups_and_servers(t
);
235 /************************************************************************** **
236 Reload the list of network interfaces.
237 Doesn't return until a network interface is up.
238 ************************************************************************** */
240 static void reload_interfaces(time_t t
)
244 bool print_waiting_msg
= true;
245 struct subnet_record
*subrec
;
247 if (t
&& ((t
- lastt
) < NMBD_INTERFACES_RELOAD
)) {
253 if (!interfaces_changed()) {
259 /* the list of probed interfaces has changed, we may need to add/remove
263 /* find any interfaces that need adding */
264 for (n
=iface_count() - 1; n
>= 0; n
--) {
265 char str
[INET6_ADDRSTRLEN
];
266 const struct interface
*iface
= get_interface(n
);
267 struct in_addr ip
, nmask
;
270 DBG_WARNING("reload_interfaces: failed to get interface %d\n", n
);
274 /* Ensure we're only dealing with IPv4 here. */
275 if (iface
->ip
.ss_family
!= AF_INET
) {
276 DBG_NOTICE("reload_interfaces: "
277 "ignoring non IPv4 interface.\n");
281 ip
= ((const struct sockaddr_in
*)(const void *)&iface
->ip
)->sin_addr
;
282 nmask
= ((const struct sockaddr_in
*)(const void *)
283 &iface
->netmask
)->sin_addr
;
286 * We don't want to add a loopback interface, in case
287 * someone has added 127.0.0.1 for smbd, nmbd needs to
288 * ignore it here. JRA.
291 if (is_loopback_addr((const struct sockaddr
*)(const void *)&iface
->ip
)) {
292 DBG_NOTICE("reload_interfaces: Ignoring loopback "
294 print_sockaddr(str
, sizeof(str
), &iface
->ip
) );
298 for (subrec
=subnetlist
; subrec
; subrec
=subrec
->next
) {
299 if (ip_equal_v4(ip
, subrec
->myip
) &&
300 ip_equal_v4(nmask
, subrec
->mask_ip
)) {
306 /* it wasn't found! add it */
307 DBG_NOTICE("Found new interface %s\n",
309 sizeof(str
), &iface
->ip
) );
310 subrec
= make_normal_subnet(iface
);
312 register_my_workgroup_one_subnet(subrec
);
316 /* find any interfaces that need deleting */
317 for (subrec
=subnetlist
; subrec
; subrec
=subrec
->next
) {
318 for (n
=iface_count() - 1; n
>= 0; n
--) {
319 struct interface
*iface
= get_interface(n
);
320 struct in_addr ip
, nmask
;
324 /* Ensure we're only dealing with IPv4 here. */
325 if (iface
->ip
.ss_family
!= AF_INET
) {
326 DBG_NOTICE("reload_interfaces: "
327 "ignoring non IPv4 interface.\n");
330 ip
= ((struct sockaddr_in
*)(void *)
331 &iface
->ip
)->sin_addr
;
332 nmask
= ((struct sockaddr_in
*)(void *)
333 &iface
->netmask
)->sin_addr
;
334 if (ip_equal_v4(ip
, subrec
->myip
) &&
335 ip_equal_v4(nmask
, subrec
->mask_ip
)) {
340 /* oops, an interface has disappeared. This is
341 tricky, we don't dare actually free the
342 interface as it could be being used, so
343 instead we just wear the memory leak and
344 remove it from the list of interfaces without
346 DBG_NOTICE("Deleting dead interface %s\n",
347 inet_ntoa(subrec
->myip
));
348 close_subnet(subrec
);
352 rescan_listen_set
= True
;
354 /* We need to wait if there are no subnets... */
355 if (FIRST_SUBNET
== NULL
) {
356 void (*saved_handler
)(int);
358 if (print_waiting_msg
) {
359 DBG_WARNING("reload_interfaces: "
360 "No subnets to listen to. Waiting..\n");
361 print_waiting_msg
= false;
365 * Whilst we're waiting for an interface, allow SIGTERM to
368 saved_handler
= CatchSignal(SIGTERM
, SIG_DFL
);
370 /* We only count IPv4, non-loopback interfaces here. */
371 while (iface_count_v4_nl() == 0) {
372 usleep(NMBD_WAIT_INTERFACES_TIME_USEC
);
376 CatchSignal(SIGTERM
, saved_handler
);
379 * We got an interface, go back to blocking term.
386 /**************************************************************************** **
387 Reload the services file.
388 **************************************************************************** */
390 static bool reload_nmbd_services(bool test
)
392 const struct loadparm_substitution
*lp_sub
=
393 loadparm_s3_global_substitution();
396 set_remote_machine_name("nmbd", False
);
399 char *fname
= lp_next_configfile(talloc_tos(), lp_sub
);
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 DBG_NOTICE( "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);
438 nmbd_init_my_netbios_names();
441 static void msg_nmbd_send_packet(struct messaging_context
*msg
,
444 struct server_id src
,
447 struct packet_struct
*p
= (struct packet_struct
*)data
->data
;
448 struct subnet_record
*subrec
;
449 struct sockaddr_storage ss
;
450 const struct sockaddr_storage
*pss
;
451 const struct in_addr
*local_ip
;
453 DBG_DEBUG("Received send_packet from %u\n", (unsigned int)procid_to_pid(&src
));
455 if (data
->length
!= sizeof(struct packet_struct
)) {
456 DBG_WARNING("Discarding invalid packet length from %u\n",
457 (unsigned int)procid_to_pid(&src
));
461 if ((p
->packet_type
!= NMB_PACKET
) &&
462 (p
->packet_type
!= DGRAM_PACKET
)) {
463 DBG_WARNING("Discarding invalid packet type from %u: %d\n",
464 (unsigned int)procid_to_pid(&src
), p
->packet_type
);
468 in_addr_to_sockaddr_storage(&ss
, p
->ip
);
469 pss
= iface_ip((struct sockaddr
*)(void *)&ss
);
472 DBG_WARNING("Could not find ip for packet from %u\n",
473 (unsigned int)procid_to_pid(&src
));
477 local_ip
= &((const struct sockaddr_in
*)pss
)->sin_addr
;
478 subrec
= FIRST_SUBNET
;
481 p
->send_fd
= (p
->packet_type
== NMB_PACKET
) ?
482 subrec
->nmb_sock
: subrec
->dgram_sock
;
484 for (subrec
= FIRST_SUBNET
; subrec
!= NULL
;
485 subrec
= NEXT_SUBNET_EXCLUDING_UNICAST(subrec
)) {
486 if (ip_equal_v4(*local_ip
, subrec
->myip
)) {
487 p
->send_fd
= (p
->packet_type
== NMB_PACKET
) ?
488 subrec
->nmb_sock
: subrec
->dgram_sock
;
493 if (p
->packet_type
== DGRAM_PACKET
) {
495 p
->packet
.dgram
.header
.source_ip
.s_addr
= local_ip
->s_addr
;
496 p
->packet
.dgram
.header
.source_port
= 138;
502 /**************************************************************************** **
503 The main select loop.
504 **************************************************************************** */
506 static void process(struct messaging_context
*msg
)
511 time_t t
= time(NULL
);
512 TALLOC_CTX
*frame
= talloc_stackframe();
515 * Check all broadcast subnets to see if
516 * we need to run an election on any of them.
520 run_election
= check_elections();
523 * Read incoming UDP packets.
527 if (listen_for_packets(msg
, run_election
)) {
533 * Process all incoming packets
534 * read above. This calls the success and
535 * failure functions registered when response
536 * packets arrive, and also deals with request
537 * packets from other sources.
544 * Run any elections - initiate becoming
545 * a local master browser if we have won.
552 * Send out any broadcast announcements
553 * of our server names. This also announces
554 * the workgroup name if we are a local
556 * (nmbd_sendannounce.c)
559 announce_my_server_names(t
);
562 * Send out any LanMan broadcast announcements
563 * of our server names.
564 * (nmbd_sendannounce.c)
567 announce_my_lm_server_names(t
);
570 * If we are a local master browser, periodically
571 * announce ourselves to the domain master browser.
572 * This also deals with synchronising the domain master
573 * browser server lists with ourselves as a local
575 * (nmbd_sendannounce.c)
578 announce_myself_to_domain_master_browser(t
);
581 * Fulfill any remote announce requests.
582 * (nmbd_sendannounce.c)
588 * Fulfill any remote browse sync announce requests.
589 * (nmbd_sendannounce.c)
592 browse_sync_remote(t
);
595 * Scan the broadcast subnets, and WINS client
596 * namelists and refresh any that need refreshing.
603 * Scan the subnet namelists and server lists and
604 * expire those that have timed out.
608 expire_names_and_servers(t
);
611 * Write out a snapshot of our current browse list into
612 * the browse.dat file. This is used by smbd to service
613 * incoming NetServerEnum calls - used to synchronise
614 * browse lists over subnets.
615 * (nmbd_serverlistdb.c)
618 write_browse_list(t
, False
);
621 * If we are a domain master browser, we have a list of
622 * local master browsers we should synchronise browse
623 * lists with (these are added by an incoming local
624 * master browser announcement packet). Expire any of
625 * these that are no longer current, and pull the server
626 * lists from each of these known local master browsers.
627 * (nmbd_browsesync.c)
630 dmb_expire_and_sync_browser_lists(t
);
633 * Check that there is a local master browser for our
634 * workgroup for all our broadcast subnets. If one
635 * is not found, start an election (which we ourselves
636 * may or may not participate in, depending on the
637 * setting of the 'local master' parameter.
641 check_master_browser_exists(t
);
644 * If we are configured as a logon server, attempt to
645 * register the special NetBIOS names to become such
646 * (WORKGROUP<1c> name) on all broadcast subnets and
647 * with the WINS server (if used). If we are configured
648 * to become a domain master browser, attempt to register
649 * the special NetBIOS name (WORKGROUP<1b> name) to
651 * (nmbd_become_dmb.c)
657 * If we are a WINS server, do any timer dependent
658 * processing required.
659 * (nmbd_winsserver.c)
662 initiate_wins_processing(t
);
665 * If we are a domain master browser, attempt to contact the
666 * WINS server to get a list of all known WORKGROUPS/DOMAINS.
667 * This will only work to a Samba WINS server.
668 * (nmbd_browsesync.c)
671 if (lp_enhanced_browsing())
672 collect_all_workgroup_names_from_wins_server(t
);
675 * Go through the response record queue and time out or re-transmit
676 * and expired entries.
680 retransmit_or_expire_response_records(t
);
683 * check to see if any remote browse sync child processes have completed
686 sync_check_completion();
689 * regularly sync with any other DMBs we know about
692 if (lp_enhanced_browsing())
695 /* check for new network interfaces */
697 reload_interfaces(t
);
699 /* free up temp memory */
704 /**************************************************************************** **
705 Open the socket communication.
706 **************************************************************************** */
708 static bool open_sockets(bool isdaemon
, int port
)
710 struct sockaddr_storage ss
;
711 const char *sock_addr
= lp_nbt_client_socket_address();
714 * The sockets opened here will be used to receive broadcast
715 * packets *only*. Interface specific sockets are opened in
716 * make_subnet() in namedbsubnet.c. Thus we bind to the
717 * address "0.0.0.0". The parameter 'socket address' is
721 if (!interpret_string_addr(&ss
, sock_addr
,
722 AI_NUMERICHOST
|AI_PASSIVE
)) {
723 DBG_ERR("open_sockets: unable to get socket address "
724 "from string %s\n", sock_addr
);
727 if (ss
.ss_family
!= AF_INET
) {
728 DBG_ERR("open_sockets: unable to use IPv6 socket"
735 ClientNMB
= open_socket_in(SOCK_DGRAM
, &ss
, port
, true);
744 ClientDGRAM
= open_socket_in(SOCK_DGRAM
, &ss
, DGRAM_PORT
, true);
746 if (ClientDGRAM
< 0) {
747 if (ClientNMB
!= 0) {
753 /* we are never interested in SIGPIPE */
754 BlockSignals(True
,SIGPIPE
);
756 set_socket_options( ClientNMB
, "SO_BROADCAST" );
757 set_socket_options( ClientDGRAM
, "SO_BROADCAST" );
759 /* Ensure we're non-blocking. */
760 set_blocking( ClientNMB
, False
);
761 set_blocking( ClientDGRAM
, False
);
763 DBG_INFO( "open_sockets: Broadcast sockets opened.\n" );
767 /**************************************************************************** **
769 **************************************************************************** */
771 int main(int argc
, const char *argv
[])
773 struct samba_cmdline_daemon_cfg
*cmdline_daemon_cfg
= NULL
;
774 bool log_stdout
= false;
776 char *p_lmhosts
= NULL
;
778 struct messaging_context
*msg
;
779 struct poptOption long_options
[] = {
784 .argInfo
= POPT_ARG_STRING
,
787 .descrip
= "Load a netbios hosts file",
792 .argInfo
= POPT_ARG_INT
,
793 .arg
= &global_nmb_port
,
795 .descrip
= "Listen on the specified port",
802 const struct loadparm_substitution
*lp_sub
=
803 loadparm_s3_global_substitution();
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.
822 ok
= samba_cmdline_init(frame
,
823 SAMBA_CMDLINE_CONFIG_SERVER
,
824 true /* require_smbconf */);
826 DBG_ERR("Failed to init cmdline parser!\n");
831 cmdline_daemon_cfg
= samba_cmdline_get_daemon_cfg();
833 global_nmb_port
= NMB_PORT
;
835 pc
= samba_popt_get_context(getprogname(),
841 DBG_ERR("Failed to setup popt context!\n");
846 while ((opt
= poptGetNextOpt(pc
)) != -1) {
847 d_fprintf(stderr
, "\nInvalid options\n\n");
848 poptPrintUsage(pc
, stderr
, 0);
853 global_in_nmbd
= true;
855 StartupTime
= time(NULL
);
857 sys_srandom(time(NULL
) ^ getpid());
859 if (is_default_dyn_LOGFILEBASE()) {
861 if (asprintf(&lfile
, "%s/log.nmbd", get_dyn_LOGFILEBASE()) < 0) {
864 lp_set_logfile(lfile
);
868 dump_core_setup("nmbd", lp_logfile(talloc_tos(), lp_sub
));
870 /* POSIX demands that signals are inherited. If the invoking process has
871 * these signals masked, we will have problems, as we won't receive them. */
872 BlockSignals(False
, SIGHUP
);
873 BlockSignals(False
, SIGUSR1
);
874 BlockSignals(False
, SIGTERM
);
877 /* we are never interested in SIGFPE */
878 BlockSignals(True
,SIGFPE
);
881 /* We no longer use USR2... */
883 BlockSignals(True
, SIGUSR2
);
886 /* Ignore children - no zombies. */
889 log_stdout
= (debug_get_log_type() == DEBUG_STDOUT
);
890 if ( cmdline_daemon_cfg
->interactive
) {
894 if ( log_stdout
&& cmdline_daemon_cfg
->fork
) {
895 DBG_ERR("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n");
901 DBG_STARTUP_NOTICE("nmbd version %s started.\n"
902 COPYRIGHT_STARTUP_MESSAGE
"\n",
903 samba_version_string());
905 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
906 && !lp_parm_bool(-1, "server role check", "inhibit", false)) {
907 /* TODO: when we have a merged set of defaults for
908 * loadparm, we could possibly check if the internal
909 * nbt server is in the list, and allow a startup if disabled */
910 DBG_ERR("server role = 'active directory domain controller' not compatible with running nmbd standalone.\n"
911 "You should start 'samba' instead, and it will control starting the internal nbt server\n");
915 if (!cluster_probe_ok()) {
919 msg
= messaging_init(NULL
, global_event_context());
921 DBG_ERR("Failed to init messaging context!\n");
925 if ( !reload_nmbd_services(False
) )
928 if (!nmbd_init_my_netbios_names()) {
932 reload_nmbd_services( True
);
934 if (strequal(lp_workgroup(),"*")) {
935 DBG_ERR("ERROR: a workgroup name of * is no longer supported\n");
941 if (!cmdline_daemon_cfg
->daemon
&& !is_a_socket(0)) {
942 DBG_NOTICE("standard input is not a socket, assuming -D option\n");
943 cmdline_daemon_cfg
->daemon
= true;
946 if (cmdline_daemon_cfg
->daemon
&& !cmdline_daemon_cfg
->interactive
) {
947 DBG_NOTICE("Becoming a daemon.\n");
948 become_daemon(cmdline_daemon_cfg
->fork
,
949 cmdline_daemon_cfg
->no_process_group
,
951 } else if (!cmdline_daemon_cfg
->interactive
) {
952 daemon_status("nmbd", "Starting process...");
957 * If we're interactive we want to set our own process group for
960 if (cmdline_daemon_cfg
->interactive
&&
961 !cmdline_daemon_cfg
->no_process_group
)
963 setpgid( (pid_t
)0, (pid_t
)0 );
968 /* Setup the async dns. We do it here so it doesn't have all the other
969 stuff initialised and thus chewing memory and sockets */
970 if(lp_we_are_a_wins_server() && lp_wins_dns_proxy()) {
971 start_async_dns(msg
);
975 ok
= directory_create_or_exist(lp_lock_directory(), 0755);
977 exit_daemon("Failed to create directory for lock files, check 'lock directory'", errno
);
980 ok
= directory_create_or_exist(lp_pid_directory(), 0755);
982 exit_daemon("Failed to create directory for pid files, check 'pid directory'", errno
);
985 pidfile_create(lp_pid_directory(), "nmbd");
987 status
= reinit_after_fork(msg
, nmbd_event_context(), false);
989 if (!NT_STATUS_IS_OK(status
)) {
990 exit_daemon("reinit_after_fork() failed", map_errno_from_nt_status(status
));
994 * Do not initialize the parent-child-pipe before becoming
995 * a daemon: this is used to detect a died parent in the child
998 status
= init_before_fork();
999 if (!NT_STATUS_IS_OK(status
)) {
1000 exit_daemon(nt_errstr(status
), map_errno_from_nt_status(status
));
1003 if (!nmbd_setup_sig_term_handler(msg
))
1004 exit_daemon("NMBD failed to setup signal handler", EINVAL
);
1005 if (!nmbd_setup_stdin_handler(msg
, !cmdline_daemon_cfg
->fork
))
1006 exit_daemon("NMBD failed to setup stdin handler", EINVAL
);
1007 if (!nmbd_setup_sig_hup_handler(msg
))
1008 exit_daemon("NMBD failed to setup SIGHUP handler", EINVAL
);
1010 if (!messaging_parent_dgm_cleanup_init(msg
)) {
1014 messaging_register(msg
, NULL
, MSG_FORCE_ELECTION
,
1015 nmbd_message_election
);
1017 /* Until winsrepl is done. */
1018 messaging_register(msg
, NULL
, MSG_WINS_NEW_ENTRY
,
1019 nmbd_wins_new_entry
);
1021 messaging_register(msg
, NULL
, MSG_SHUTDOWN
,
1023 messaging_register(msg
, NULL
, MSG_SMB_CONF_UPDATED
,
1024 msg_reload_nmbd_services
);
1025 messaging_register(msg
, NULL
, MSG_SEND_PACKET
,
1026 msg_nmbd_send_packet
);
1030 DBG_NOTICE("Opening sockets %d\n", global_nmb_port
);
1032 if ( !open_sockets( cmdline_daemon_cfg
->daemon
, global_nmb_port
) ) {
1033 kill_async_dns_child();
1037 /* Determine all the IP addresses we have. */
1040 /* Create an nmbd subnet record for each of the above. */
1041 if( False
== create_subnets() ) {
1042 kill_async_dns_child();
1043 exit_daemon("NMBD failed when creating subnet lists", EACCES
);
1046 /* Load in any static local names. */
1048 set_dyn_LMHOSTSFILE(p_lmhosts
);
1050 load_lmhosts_file(get_dyn_LMHOSTSFILE());
1051 DBG_NOTICE("Loaded hosts file %s\n", get_dyn_LMHOSTSFILE());
1053 /* If we are acting as a WINS server, initialise data structures. */
1054 if( !initialise_wins() ) {
1055 kill_async_dns_child();
1056 exit_daemon( "NMBD failed when initialising WINS server.", EACCES
);
1060 * Register nmbd primary workgroup and nmbd names on all
1061 * the broadcast subnets, and on the WINS server (if specified).
1062 * Also initiate the startup of our primary workgroup (start
1063 * elections if we are setup as being able to be a local
1067 if( False
== register_my_workgroup_and_names() ) {
1068 kill_async_dns_child();
1069 exit_daemon( "NMBD failed when creating my workgroup.", EACCES
);
1072 if (!initialize_nmbd_proxy_logon()) {
1073 kill_async_dns_child();
1074 exit_daemon( "NMBD failed to setup nmbd_proxy_logon.", EACCES
);
1077 if (!nmbd_init_packet_server()) {
1078 kill_async_dns_child();
1079 exit_daemon( "NMBD failed to setup packet server.", EACCES
);
1082 if (!cmdline_daemon_cfg
->interactive
) {
1083 daemon_ready("nmbd");
1089 kill_async_dns_child();