r15700: Make nmbd udp sockets non-blocking to prevent problem
[metze/samba/wip.git] / source3 / nmbd / nmbd.c
1 /*
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)
7    
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 2 of the License, or
11    (at your option) any later version.
12    
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.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21    
22 */
23
24 #include "includes.h"
25
26 int ClientNMB       = -1;
27 int ClientDGRAM     = -1;
28 int global_nmb_port = -1;
29
30 extern BOOL rescan_listen_set;
31 extern struct in_addr loopback_ip;
32 extern BOOL global_in_nmbd;
33
34 extern BOOL override_logfile;
35
36 /* are we running as a daemon ? */
37 static BOOL is_daemon;
38
39 /* fork or run in foreground ? */
40 static BOOL Fork = True;
41
42 /* log to standard output ? */
43 static BOOL log_stdout;
44
45 /* have we found LanMan clients yet? */
46 BOOL found_lm_clients = False;
47
48 /* what server type are we currently */
49
50 time_t StartupTime = 0;
51
52 /**************************************************************************** **
53  Handle a SIGTERM in band.
54  **************************************************************************** */
55
56 static void terminate(void)
57 {
58         DEBUG(0,("Got SIGTERM: going down...\n"));
59   
60         /* Write out wins.dat file if samba is a WINS server */
61         wins_write_database(0,False);
62   
63         /* Remove all SELF registered names from WINS */
64         release_wins_names();
65   
66         /* Announce all server entries as 0 time-to-live, 0 type. */
67         announce_my_servers_removed();
68
69         /* If there was an async dns child - kill it. */
70         kill_async_dns_child();
71
72         exit(0);
73 }
74
75 /**************************************************************************** **
76  Handle a SHUTDOWN message from smbcontrol.
77  **************************************************************************** */
78
79 static void nmbd_terminate(int msg_type, struct process_id src,
80                            void *buf, size_t len)
81 {
82         terminate();
83 }
84
85 /**************************************************************************** **
86  Catch a SIGTERM signal.
87  **************************************************************************** */
88
89 static SIG_ATOMIC_T got_sig_term;
90
91 static void sig_term(int sig)
92 {
93         got_sig_term = 1;
94         sys_select_signal(SIGTERM);
95 }
96
97 /**************************************************************************** **
98  Catch a SIGHUP signal.
99  **************************************************************************** */
100
101 static SIG_ATOMIC_T reload_after_sighup;
102
103 static void sig_hup(int sig)
104 {
105         reload_after_sighup = 1;
106         sys_select_signal(SIGHUP);
107 }
108
109 /**************************************************************************** **
110  Possibly continue after a fault.
111  **************************************************************************** */
112
113 static void fault_continue(void)
114 {
115 #if DUMP_CORE
116         dump_core();
117 #endif
118 }
119
120 /**************************************************************************** **
121  Expire old names from the namelist and server list.
122  **************************************************************************** */
123
124 static void expire_names_and_servers(time_t t)
125 {
126         static time_t lastrun = 0;
127   
128         if ( !lastrun )
129                 lastrun = t;
130         if ( t < (lastrun + 5) )
131                 return;
132         lastrun = t;
133
134         /*
135          * Expire any timed out names on all the broadcast
136          * subnets and those registered with the WINS server.
137          * (nmbd_namelistdb.c)
138          */
139
140         expire_names(t);
141
142         /*
143          * Go through all the broadcast subnets and for each
144          * workgroup known on that subnet remove any expired
145          * server names. If a workgroup has an empty serverlist
146          * and has itself timed out then remove the workgroup.
147          * (nmbd_workgroupdb.c)
148          */
149
150         expire_workgroups_and_servers(t);
151 }
152
153 /************************************************************************** **
154  Reload the list of network interfaces.
155  ************************************************************************** */
156
157 static BOOL reload_interfaces(time_t t)
158 {
159         static time_t lastt;
160         int n;
161         struct subnet_record *subrec;
162
163         if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return False;
164         lastt = t;
165
166         if (!interfaces_changed()) return False;
167
168         /* the list of probed interfaces has changed, we may need to add/remove
169            some subnets */
170         load_interfaces();
171
172         /* find any interfaces that need adding */
173         for (n=iface_count() - 1; n >= 0; n--) {
174                 struct interface *iface = get_interface(n);
175
176                 /*
177                  * We don't want to add a loopback interface, in case
178                  * someone has added 127.0.0.1 for smbd, nmbd needs to
179                  * ignore it here. JRA.
180                  */
181
182                 if (ip_equal(iface->ip, loopback_ip)) {
183                         DEBUG(2,("reload_interfaces: Ignoring loopback interface %s\n", inet_ntoa(iface->ip)));
184                         continue;
185                 }
186
187                 for (subrec=subnetlist; subrec; subrec=subrec->next) {
188                         if (ip_equal(iface->ip, subrec->myip) &&
189                             ip_equal(iface->nmask, subrec->mask_ip)) break;
190                 }
191
192                 if (!subrec) {
193                         /* it wasn't found! add it */
194                         DEBUG(2,("Found new interface %s\n", 
195                                  inet_ntoa(iface->ip)));
196                         subrec = make_normal_subnet(iface);
197                         if (subrec)
198                                 register_my_workgroup_one_subnet(subrec);
199                 }
200         }
201
202         /* find any interfaces that need deleting */
203         for (subrec=subnetlist; subrec; subrec=subrec->next) {
204                 for (n=iface_count() - 1; n >= 0; n--) {
205                         struct interface *iface = get_interface(n);
206                         if (ip_equal(iface->ip, subrec->myip) &&
207                             ip_equal(iface->nmask, subrec->mask_ip)) break;
208                 }
209                 if (n == -1) {
210                         /* oops, an interface has disapeared. This is
211                          tricky, we don't dare actually free the
212                          interface as it could be being used, so
213                          instead we just wear the memory leak and
214                          remove it from the list of interfaces without
215                          freeing it */
216                         DEBUG(2,("Deleting dead interface %s\n", 
217                                  inet_ntoa(subrec->myip)));
218                         close_subnet(subrec);
219                 }
220         }
221         
222         rescan_listen_set = True;
223
224         /* We need to shutdown if there are no subnets... */
225         if (FIRST_SUBNET == NULL) {
226                 DEBUG(0,("reload_interfaces: No subnets to listen to. Shutting down...\n"));
227                 return True;
228         }
229         return False;
230 }
231
232 /**************************************************************************** **
233  Reload the services file.
234  **************************************************************************** */
235
236 static BOOL reload_nmbd_services(BOOL test)
237 {
238         BOOL ret;
239
240         set_remote_machine_name("nmbd", False);
241
242         if ( lp_loaded() ) {
243                 pstring fname;
244                 pstrcpy( fname,lp_configfile());
245                 if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
246                         pstrcpy(dyn_CONFIGFILE,fname);
247                         test = False;
248                 }
249         }
250
251         if ( test && !lp_file_list_changed() )
252                 return(True);
253
254         ret = lp_load( dyn_CONFIGFILE, True , False, False, True);
255
256         /* perhaps the config filename is now set */
257         if ( !test ) {
258                 DEBUG( 3, ( "services not loaded\n" ) );
259                 reload_nmbd_services( True );
260         }
261
262         return(ret);
263 }
264
265 /**************************************************************************** **
266  * React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP
267  * We use buf here to return BOOL result to process() when reload_interfaces()
268  * detects that there are no subnets.
269  **************************************************************************** */
270
271 static void msg_reload_nmbd_services(int msg_type, struct process_id src,
272                                      void *buf, size_t len)
273 {
274         write_browse_list( 0, True );
275         dump_all_namelists();
276         reload_nmbd_services( True );
277         reopen_logs();
278         
279         if(buf) {
280                 /* We were called from process() */
281                 /* If reload_interfaces() returned True */
282                 /* we need to shutdown if there are no subnets... */
283                 /* pass this info back to process() */
284                 *((BOOL*)buf) = reload_interfaces(0);  
285         }
286 }
287
288 static void msg_nmbd_send_packet(int msg_type, struct process_id src,
289                                  void *buf, size_t len)
290 {
291         struct packet_struct *p = (struct packet_struct *)buf;
292         struct subnet_record *subrec;
293         struct in_addr *local_ip;
294
295         DEBUG(10, ("Received send_packet from %d\n", procid_to_pid(&src)));
296
297         if (len != sizeof(struct packet_struct)) {
298                 DEBUG(2, ("Discarding invalid packet length from %d\n",
299                           procid_to_pid(&src)));
300                 return;
301         }
302
303         if ((p->packet_type != NMB_PACKET) &&
304             (p->packet_type != DGRAM_PACKET)) {
305                 DEBUG(2, ("Discarding invalid packet type from %d: %d\n",
306                           procid_to_pid(&src), p->packet_type));
307                 return;
308         }
309
310         local_ip = iface_ip(p->ip);
311
312         if (local_ip == NULL) {
313                 DEBUG(2, ("Could not find ip for packet from %d\n",
314                           procid_to_pid(&src)));
315                 return;
316         }
317
318         subrec = FIRST_SUBNET;
319
320         p->fd = (p->packet_type == NMB_PACKET) ?
321                 subrec->nmb_sock : subrec->dgram_sock;
322
323         for (subrec = FIRST_SUBNET; subrec != NULL;
324              subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
325                 if (ip_equal(*local_ip, subrec->myip)) {
326                         p->fd = (p->packet_type == NMB_PACKET) ?
327                                 subrec->nmb_sock : subrec->dgram_sock;
328                         break;
329                 }
330         }
331
332         if (p->packet_type == DGRAM_PACKET) {
333                 p->port = 138;
334                 p->packet.dgram.header.source_ip.s_addr = local_ip->s_addr;
335                 p->packet.dgram.header.source_port = 138;
336         }
337
338         send_packet(p);
339 }
340
341 /**************************************************************************** **
342  The main select loop.
343  **************************************************************************** */
344
345 static void process(void)
346 {
347         BOOL run_election;
348         BOOL no_subnets;
349
350         while( True ) {
351                 time_t t = time(NULL);
352
353                 /* Check for internal messages */
354
355                 message_dispatch();
356
357                 /*
358                  * Check all broadcast subnets to see if
359                  * we need to run an election on any of them.
360                  * (nmbd_elections.c)
361                  */
362
363                 run_election = check_elections();
364
365                 /*
366                  * Read incoming UDP packets.
367                  * (nmbd_packets.c)
368                  */
369
370                 if(listen_for_packets(run_election))
371                         return;
372
373                 /*
374                  * Handle termination inband.
375                  */
376
377                 if (got_sig_term) {
378                         got_sig_term = 0;
379                         terminate();
380                 }
381
382                 /*
383                  * Process all incoming packets
384                  * read above. This calls the success and
385                  * failure functions registered when response
386                  * packets arrrive, and also deals with request
387                  * packets from other sources.
388                  * (nmbd_packets.c)
389                  */
390
391                 run_packet_queue();
392
393                 /*
394                  * Run any elections - initiate becoming
395                  * a local master browser if we have won.
396                  * (nmbd_elections.c)
397                  */
398
399                 run_elections(t);
400
401                 /*
402                  * Send out any broadcast announcements
403                  * of our server names. This also announces
404                  * the workgroup name if we are a local
405                  * master browser.
406                  * (nmbd_sendannounce.c)
407                  */
408
409                 announce_my_server_names(t);
410
411                 /*
412                  * Send out any LanMan broadcast announcements
413                  * of our server names.
414                  * (nmbd_sendannounce.c)
415                  */
416
417                 announce_my_lm_server_names(t);
418
419                 /*
420                  * If we are a local master browser, periodically
421                  * announce ourselves to the domain master browser.
422                  * This also deals with syncronising the domain master
423                  * browser server lists with ourselves as a local
424                  * master browser.
425                  * (nmbd_sendannounce.c)
426                  */
427
428                 announce_myself_to_domain_master_browser(t);
429
430                 /*
431                  * Fullfill any remote announce requests.
432                  * (nmbd_sendannounce.c)
433                  */
434
435                 announce_remote(t);
436
437                 /*
438                  * Fullfill any remote browse sync announce requests.
439                  * (nmbd_sendannounce.c)
440                  */
441
442                 browse_sync_remote(t);
443
444                 /*
445                  * Scan the broadcast subnets, and WINS client
446                  * namelists and refresh any that need refreshing.
447                  * (nmbd_mynames.c)
448                  */
449
450                 refresh_my_names(t);
451
452                 /*
453                  * Scan the subnet namelists and server lists and
454                  * expire thos that have timed out.
455                  * (nmbd.c)
456                  */
457
458                 expire_names_and_servers(t);
459
460                 /*
461                  * Write out a snapshot of our current browse list into
462                  * the browse.dat file. This is used by smbd to service
463                  * incoming NetServerEnum calls - used to synchronise
464                  * browse lists over subnets.
465                  * (nmbd_serverlistdb.c)
466                  */
467
468                 write_browse_list(t, False);
469
470                 /*
471                  * If we are a domain master browser, we have a list of
472                  * local master browsers we should synchronise browse
473                  * lists with (these are added by an incoming local
474                  * master browser announcement packet). Expire any of
475                  * these that are no longer current, and pull the server
476                  * lists from each of these known local master browsers.
477                  * (nmbd_browsesync.c)
478                  */
479
480                 dmb_expire_and_sync_browser_lists(t);
481
482                 /*
483                  * Check that there is a local master browser for our
484                  * workgroup for all our broadcast subnets. If one
485                  * is not found, start an election (which we ourselves
486                  * may or may not participate in, depending on the
487                  * setting of the 'local master' parameter.
488                  * (nmbd_elections.c)
489                  */
490
491                 check_master_browser_exists(t);
492
493                 /*
494                  * If we are configured as a logon server, attempt to
495                  * register the special NetBIOS names to become such
496                  * (WORKGROUP<1c> name) on all broadcast subnets and
497                  * with the WINS server (if used). If we are configured
498                  * to become a domain master browser, attempt to register
499                  * the special NetBIOS name (WORKGROUP<1b> name) to
500                  * become such.
501                  * (nmbd_become_dmb.c)
502                  */
503
504                 add_domain_names(t);
505
506                 /*
507                  * If we are a WINS server, do any timer dependent
508                  * processing required.
509                  * (nmbd_winsserver.c)
510                  */
511
512                 initiate_wins_processing(t);
513
514                 /*
515                  * If we are a domain master browser, attempt to contact the
516                  * WINS server to get a list of all known WORKGROUPS/DOMAINS.
517                  * This will only work to a Samba WINS server.
518                  * (nmbd_browsesync.c)
519                  */
520
521                 if (lp_enhanced_browsing())
522                         collect_all_workgroup_names_from_wins_server(t);
523
524                 /*
525                  * Go through the response record queue and time out or re-transmit
526                  * and expired entries.
527                  * (nmbd_packets.c)
528                  */
529
530                 retransmit_or_expire_response_records(t);
531
532                 /*
533                  * check to see if any remote browse sync child processes have completed
534                  */
535
536                 sync_check_completion();
537
538                 /*
539                  * regularly sync with any other DMBs we know about 
540                  */
541
542                 if (lp_enhanced_browsing())
543                         sync_all_dmbs(t);
544
545                 /*
546                  * clear the unexpected packet queue 
547                  */
548
549                 clear_unexpected(t);
550
551                 /*
552                  * Reload the services file if we got a sighup.
553                  */
554
555                 if(reload_after_sighup) {
556                         DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) );
557                         msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED,
558                                                  pid_to_procid(0), (void*) &no_subnets, 0);
559                         if(no_subnets)
560                                 return;
561                         reload_after_sighup = 0;
562                 }
563
564                 /* check for new network interfaces */
565
566                 if(reload_interfaces(t))
567                         return;
568
569                 /* free up temp memory */
570                         lp_TALLOC_FREE();
571         }
572 }
573
574 /**************************************************************************** **
575  Open the socket communication.
576  **************************************************************************** */
577
578 static BOOL open_sockets(BOOL isdaemon, int port)
579 {
580         /*
581          * The sockets opened here will be used to receive broadcast
582          * packets *only*. Interface specific sockets are opened in
583          * make_subnet() in namedbsubnet.c. Thus we bind to the
584          * address "0.0.0.0". The parameter 'socket address' is
585          * now deprecated.
586          */
587
588         if ( isdaemon )
589                 ClientNMB = open_socket_in(SOCK_DGRAM, port,
590                                            0, interpret_addr(lp_socket_address()),
591                                            True);
592         else
593                 ClientNMB = 0;
594   
595         ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT,
596                                            3, interpret_addr(lp_socket_address()),
597                                            True);
598
599         if ( ClientNMB == -1 )
600                 return( False );
601
602         /* we are never interested in SIGPIPE */
603         BlockSignals(True,SIGPIPE);
604
605         set_socket_options( ClientNMB,   "SO_BROADCAST" );
606         set_socket_options( ClientDGRAM, "SO_BROADCAST" );
607
608         /* Ensure we're non-blocking. */
609         set_blocking( ClientNMB, False);
610         set_blocking( ClientDGRAM, False);
611
612         DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) );
613         return( True );
614 }
615
616 /**************************************************************************** **
617  main program
618  **************************************************************************** */
619  int main(int argc, const char *argv[])
620 {
621         pstring logfile;
622         static BOOL opt_interactive;
623         poptContext pc;
624         static char *p_lmhosts = dyn_LMHOSTSFILE;
625         static BOOL no_process_group = False;
626         struct poptOption long_options[] = {
627         POPT_AUTOHELP
628         {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" },
629         {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" },
630         {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" },
631         {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
632         {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
633         {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"},
634         {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" },
635         POPT_COMMON_SAMBA
636         { NULL }
637         };
638
639         load_case_tables();
640
641         global_nmb_port = NMB_PORT;
642
643         pc = poptGetContext("nmbd", argc, argv, long_options, 0);
644         while (poptGetNextOpt(pc) != -1) {};
645         poptFreeContext(pc);
646
647         global_in_nmbd = True;
648         
649         StartupTime = time(NULL);
650         
651         sys_srandom(time(NULL) ^ sys_getpid());
652         
653         if (!override_logfile) {
654                 slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE);
655                 lp_set_logfile(logfile);
656         }
657         
658         fault_setup((void (*)(void *))fault_continue );
659         dump_core_setup("nmbd");
660         
661         /* POSIX demands that signals are inherited. If the invoking process has
662          * these signals masked, we will have problems, as we won't receive them. */
663         BlockSignals(False, SIGHUP);
664         BlockSignals(False, SIGUSR1);
665         BlockSignals(False, SIGTERM);
666         
667         CatchSignal( SIGHUP,  SIGNAL_CAST sig_hup );
668         CatchSignal( SIGTERM, SIGNAL_CAST sig_term );
669         
670 #if defined(SIGFPE)
671         /* we are never interested in SIGFPE */
672         BlockSignals(True,SIGFPE);
673 #endif
674
675         /* We no longer use USR2... */
676 #if defined(SIGUSR2)
677         BlockSignals(True, SIGUSR2);
678 #endif
679
680         if ( opt_interactive ) {
681                 Fork = False;
682                 log_stdout = True;
683         }
684
685         if ( log_stdout && Fork ) {
686                 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
687                 exit(1);
688         }
689
690         setup_logging( argv[0], log_stdout );
691
692         reopen_logs();
693
694         DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) );
695         DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) );
696
697         if ( !reload_nmbd_services(False) )
698                 return(-1);
699
700         if(!init_names())
701                 return -1;
702
703         reload_nmbd_services( True );
704
705         if (strequal(lp_workgroup(),"*")) {
706                 DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n"));
707                 exit(1);
708         }
709
710         set_samba_nb_type();
711
712         if (!is_daemon && !is_a_socket(0)) {
713                 DEBUG(0,("standard input is not a socket, assuming -D option\n"));
714                 is_daemon = True;
715         }
716   
717         if (is_daemon && !opt_interactive) {
718                 DEBUG( 2, ( "Becoming a daemon.\n" ) );
719                 become_daemon(Fork, no_process_group);
720         }
721
722 #if HAVE_SETPGID
723         /*
724          * If we're interactive we want to set our own process group for 
725          * signal management.
726          */
727         if (opt_interactive && !no_process_group)
728                 setpgid( (pid_t)0, (pid_t)0 );
729 #endif
730
731 #ifndef SYNC_DNS
732         /* Setup the async dns. We do it here so it doesn't have all the other
733                 stuff initialised and thus chewing memory and sockets */
734         if(lp_we_are_a_wins_server() && lp_dns_proxy()) {
735                 start_async_dns();
736         }
737 #endif
738
739         if (!directory_exist(lp_lockdir(), NULL)) {
740                 mkdir(lp_lockdir(), 0755);
741         }
742
743         pidfile_create("nmbd");
744         message_init();
745         message_register(MSG_FORCE_ELECTION, nmbd_message_election);
746 #if 0
747         /* Until winsrepl is done. */
748         message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry);
749 #endif
750         message_register(MSG_SHUTDOWN, nmbd_terminate);
751         message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services);
752         message_register(MSG_SEND_PACKET, msg_nmbd_send_packet);
753
754         TimeInit();
755
756         DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) );
757
758         if ( !open_sockets( is_daemon, global_nmb_port ) ) {
759                 kill_async_dns_child();
760                 return 1;
761         }
762
763         /* Determine all the IP addresses we have. */
764         load_interfaces();
765
766         /* Create an nmbd subnet record for each of the above. */
767         if( False == create_subnets() ) {
768                 DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));
769                 kill_async_dns_child();
770                 exit(1);
771         }
772
773         /* Load in any static local names. */ 
774         load_lmhosts_file(p_lmhosts);
775         DEBUG(3,("Loaded hosts file %s\n", p_lmhosts));
776
777         /* If we are acting as a WINS server, initialise data structures. */
778         if( !initialise_wins() ) {
779                 DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );
780                 kill_async_dns_child();
781                 exit(1);
782         }
783
784         /* 
785          * Register nmbd primary workgroup and nmbd names on all
786          * the broadcast subnets, and on the WINS server (if specified).
787          * Also initiate the startup of our primary workgroup (start
788          * elections if we are setup as being able to be a local
789          * master browser.
790          */
791
792         if( False == register_my_workgroup_and_names() ) {
793                 DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));
794                 kill_async_dns_child();
795                 exit(1);
796         }
797
798         /* We can only take signals in the select. */
799         BlockSignals( True, SIGTERM );
800
801         process();
802
803         if (dbf)
804                 x_fclose(dbf);
805         kill_async_dns_child();
806         return(0);
807 }