Fixed delete on close bug. Added core dump code to winbindd.
[sfrench/samba-autobuild/.git] / source3 / nsswitch / winbindd.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4
5    Winbind daemon for ntdom nss module
6
7    Copyright (C) by Tim Potter 2000, 2001
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "winbindd.h"
25
26 extern pstring debugf;
27
28 /* List of all connected clients */
29
30 struct winbindd_cli_state *client_list;
31 static int num_clients;
32
33 /* Reload configuration */
34
35 static BOOL reload_services_file(BOOL test)
36 {
37         BOOL ret;
38
39         if (lp_loaded()) {
40                 pstring fname;
41
42                 pstrcpy(fname,lp_configfile());
43                 if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
44                         pstrcpy(dyn_CONFIGFILE,fname);
45                         test = False;
46                 }
47         }
48
49         reopen_logs();
50         ret = lp_load(dyn_CONFIGFILE,False,False,True);
51
52         reopen_logs();
53         load_interfaces();
54
55         return(ret);
56 }
57
58 #if DUMP_CORE
59
60 /**************************************************************************** **
61  Prepare to dump a core file - carefully!
62  **************************************************************************** */
63
64 static BOOL dump_core(void)
65 {
66         char *p;
67         pstring dname;
68         pstrcpy( dname, debugf );
69         if ((p=strrchr(dname,'/')))
70                 *p=0;
71         pstrcat( dname, "/corefiles" );
72         mkdir( dname, 0700 );
73         sys_chown( dname, getuid(), getgid() );
74         chmod( dname, 0700 );
75         if ( chdir(dname) )
76                 return( False );
77         umask( ~(0700) );
78  
79 #ifdef HAVE_GETRLIMIT
80 #ifdef RLIMIT_CORE
81         {
82                 struct rlimit rlp;
83                 getrlimit( RLIMIT_CORE, &rlp );
84                 rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur );
85                 setrlimit( RLIMIT_CORE, &rlp );
86                 getrlimit( RLIMIT_CORE, &rlp );
87                 DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) );
88         }
89 #endif
90 #endif
91  
92         DEBUG(0,("Dumping core in %s\n",dname));
93         abort();
94         return( True );
95 } /* dump_core */
96 #endif
97
98 /**************************************************************************** **
99  Handle a fault..
100  **************************************************************************** */
101
102 static void fault_quit(void)
103 {
104 #if DUMP_CORE
105         dump_core();
106 #endif
107 }
108
109 static void winbindd_status(void)
110 {
111         struct winbindd_cli_state *tmp;
112
113         DEBUG(0, ("winbindd status:\n"));
114
115         /* Print client state information */
116         
117         DEBUG(0, ("\t%d clients currently active\n", num_clients));
118         
119         if (DEBUGLEVEL >= 2 && num_clients) {
120                 DEBUG(2, ("\tclient list:\n"));
121                 for(tmp = client_list; tmp; tmp = tmp->next) {
122                         DEBUG(2, ("\t\tpid %d, sock %d, rbl %d, wbl %d\n",
123                                   tmp->pid, tmp->sock, tmp->read_buf_len, 
124                                   tmp->write_buf_len));
125                 }
126         }
127 }
128
129 /* Print winbindd status to log file */
130
131 static void print_winbindd_status(void)
132 {
133         winbindd_status();
134         winbindd_idmap_status();
135         winbindd_cache_status();
136         winbindd_cm_status();
137 }
138
139 /* Flush client cache */
140
141 static void flush_caches(void)
142 {
143         /* Clear cached user and group enumation info */
144         
145         winbindd_flush_cache();
146 }
147
148 /* Handle the signal by unlinking socket and exiting */
149
150 static void terminate(void)
151 {
152         pstring path;
153         
154         /* Remove socket file */
155         snprintf(path, sizeof(path), "%s/%s", 
156                  WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
157         unlink(path);
158         exit(0);
159 }
160
161 static BOOL do_sigterm;
162
163 static void termination_handler(int signum)
164 {
165         do_sigterm = True;
166 }
167
168 static BOOL do_sigusr1;
169
170 static void sigusr1_handler(int signum)
171 {
172         do_sigusr1 = True;
173 }
174
175 static BOOL do_sighup;
176
177 static void sighup_handler(int signum)
178 {
179         do_sighup = True;
180 }
181
182 /* Create winbindd socket */
183
184 static int create_sock(void)
185 {
186         struct sockaddr_un sunaddr;
187         struct stat st;
188         int sock;
189         mode_t old_umask;
190         pstring path;
191         
192         /* Create the socket directory or reuse the existing one */
193         
194         if (lstat(WINBINDD_SOCKET_DIR, &st) == -1) {
195                 
196                 if (errno == ENOENT) {
197                         
198                         /* Create directory */
199                         
200                         if (mkdir(WINBINDD_SOCKET_DIR, 0755) == -1) {
201                                 DEBUG(0, ("error creating socket directory "
202                                           "%s: %s\n", WINBINDD_SOCKET_DIR, 
203                                           strerror(errno)));
204                                 return -1;
205                         }
206                         
207                 } else {
208                         
209                         DEBUG(0, ("lstat failed on socket directory %s: %s\n",
210                                   WINBINDD_SOCKET_DIR, strerror(errno)));
211                         return -1;
212                 }
213                 
214         } else {
215                 
216                 /* Check ownership and permission on existing directory */
217                 
218                 if (!S_ISDIR(st.st_mode)) {
219                         DEBUG(0, ("socket directory %s isn't a directory\n",
220                                   WINBINDD_SOCKET_DIR));
221                         return -1;
222                 }
223                 
224                 if ((st.st_uid != sec_initial_uid()) || 
225                     ((st.st_mode & 0777) != 0755)) {
226                         DEBUG(0, ("invalid permissions on socket directory "
227                                   "%s\n", WINBINDD_SOCKET_DIR));
228                         return -1;
229                 }
230         }
231         
232         /* Create the socket file */
233         
234         old_umask = umask(0);
235         
236         sock = socket(AF_UNIX, SOCK_STREAM, 0);
237         
238         if (sock == -1) {
239                 perror("socket");
240                 return -1;
241         }
242         
243         snprintf(path, sizeof(path), "%s/%s", 
244                  WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
245         
246         unlink(path);
247         memset(&sunaddr, 0, sizeof(sunaddr));
248         sunaddr.sun_family = AF_UNIX;
249         safe_strcpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path)-1);
250         
251         if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1) {
252                 DEBUG(0, ("bind failed on winbind socket %s: %s\n",
253                           path,
254                           strerror(errno)));
255                 close(sock);
256                 return -1;
257         }
258         
259         if (listen(sock, 5) == -1) {
260                 DEBUG(0, ("listen failed on winbind socket %s: %s\n",
261                           path,
262                           strerror(errno)));
263                 close(sock);
264                 return -1;
265         }
266         
267         umask(old_umask);
268         
269         /* Success! */
270         
271         return sock;
272 }
273
274 struct dispatch_table {
275         enum winbindd_cmd cmd;
276         enum winbindd_result (*fn)(struct winbindd_cli_state *state);
277         char *winbindd_cmd_name;
278 };
279
280 static struct dispatch_table dispatch_table[] = {
281         
282         /* User functions */
283
284         { WINBINDD_GETPWNAM_FROM_USER, winbindd_getpwnam_from_user, "GETPWNAM_FROM_USER" },
285         { WINBINDD_GETPWNAM_FROM_UID, winbindd_getpwnam_from_uid, "GETPWNAM_FROM_UID" },
286
287         { WINBINDD_SETPWENT, winbindd_setpwent, "SETPWENT" },
288         { WINBINDD_ENDPWENT, winbindd_endpwent, "ENDPWENT" },
289         { WINBINDD_GETPWENT, winbindd_getpwent, "GETPWENT" },
290
291         { WINBINDD_GETGROUPS, winbindd_getgroups, "GETGROUPS" },
292
293         /* Group functions */
294
295         { WINBINDD_GETGRNAM_FROM_GROUP, winbindd_getgrnam_from_group, "GETGRNAM_FROM_GROUP" },
296         { WINBINDD_GETGRNAM_FROM_GID, winbindd_getgrnam_from_gid, "GETGRNAM_FROM_GID" },
297         { WINBINDD_SETGRENT, winbindd_setgrent, "SETGRENT" },
298         { WINBINDD_ENDGRENT, winbindd_endgrent, "ENDGRENT" },
299         { WINBINDD_GETGRENT, winbindd_getgrent, "GETGRENT" },
300
301         /* PAM auth functions */
302
303         { WINBINDD_PAM_AUTH, winbindd_pam_auth, "PAM_AUTH" },
304         { WINBINDD_PAM_AUTH_CRAP, winbindd_pam_auth_crap, "AUTH_CRAP" },
305         { WINBINDD_PAM_CHAUTHTOK, winbindd_pam_chauthtok, "CHAUTHTOK" },
306
307         /* Enumeration functions */
308
309         { WINBINDD_LIST_USERS, winbindd_list_users, "LIST_USERS" },
310         { WINBINDD_LIST_GROUPS, winbindd_list_groups, "LIST_GROUPS" },
311         { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains, "LIST_TRUSTDOM" },
312
313         /* SID related functions */
314
315         { WINBINDD_LOOKUPSID, winbindd_lookupsid, "LOOKUPSID" },
316         { WINBINDD_LOOKUPNAME, winbindd_lookupname, "LOOKUPNAME" },
317
318         /* Lookup related functions */
319
320         { WINBINDD_SID_TO_UID, winbindd_sid_to_uid, "SID_TO_UID" },
321         { WINBINDD_SID_TO_GID, winbindd_sid_to_gid, "SID_TO_GID" },
322         { WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
323         { WINBINDD_UID_TO_SID, winbindd_uid_to_sid, "UID_TO_SID" },
324
325         /* Miscellaneous */
326
327         { WINBINDD_CHECK_MACHACC, winbindd_check_machine_acct, "CHECK_MACHACC" },
328
329         /* End of list */
330
331         { WINBINDD_NUM_CMDS, NULL, "NONE" }
332 };
333
334 static void process_request(struct winbindd_cli_state *state)
335 {
336         struct dispatch_table *table = dispatch_table;
337
338         /* Free response data - we may be interrupted and receive another
339            command before being able to send this data off. */
340
341         SAFE_FREE(state->response.extra_data);  
342
343         ZERO_STRUCT(state->response);
344
345         state->response.result = WINBINDD_ERROR;
346         state->response.length = sizeof(struct winbindd_response);
347
348         /* Process command */
349
350         for (table = dispatch_table; table->fn; table++) {
351                 if (state->request.cmd == table->cmd) {
352                         DEBUG(10,("process_request: request fn %s\n", table->winbindd_cmd_name ));
353                         state->response.result = table->fn(state);
354                         break;
355                 }
356         }
357
358         if (!table->fn)
359                 DEBUG(10,("process_request: unknown request fn number %d\n", (int)state->request.cmd ));
360
361         /* In case extra data pointer is NULL */
362
363         if (!state->response.extra_data)
364                 state->response.length = sizeof(struct winbindd_response);
365 }
366
367 /* Process a new connection by adding it to the client connection list */
368
369 static void new_connection(int accept_sock)
370 {
371         struct sockaddr_un sunaddr;
372         struct winbindd_cli_state *state;
373         socklen_t len;
374         int sock;
375         
376         /* Accept connection */
377         
378         len = sizeof(sunaddr);
379
380         do {
381                 sock = accept(accept_sock, (struct sockaddr *)&sunaddr, &len);
382         } while (sock == -1 && errno == EINTR);
383
384         if (sock == -1)
385                 return;
386         
387         DEBUG(6,("accepted socket %d\n", sock));
388         
389         /* Create new connection structure */
390         
391         if ((state = (struct winbindd_cli_state *) 
392              malloc(sizeof(*state))) == NULL)
393                 return;
394         
395         ZERO_STRUCTP(state);
396         state->sock = sock;
397         
398         /* Add to connection list */
399         
400         DLIST_ADD(client_list, state);
401         num_clients++;
402 }
403
404 /* Remove a client connection from client connection list */
405
406 static void remove_client(struct winbindd_cli_state *state)
407 {
408         /* It's a dead client - hold a funeral */
409         
410         if (state != NULL) {
411                 
412                 /* Close socket */
413                 
414                 close(state->sock);
415                 
416                 /* Free any getent state */
417                 
418                 free_getent_state(state->getpwent_state);
419                 free_getent_state(state->getgrent_state);
420                 
421                 /* We may have some extra data that was not freed if the
422                    client was killed unexpectedly */
423
424                 SAFE_FREE(state->response.extra_data);
425                 
426                 /* Remove from list and free */
427                 
428                 DLIST_REMOVE(client_list, state);
429                 SAFE_FREE(state);
430                 num_clients--;
431         }
432 }
433
434 /* Process a complete received packet from a client */
435
436 static void process_packet(struct winbindd_cli_state *state)
437 {
438         /* Process request */
439         
440         state->pid = state->request.pid;
441         
442         process_request(state);
443
444         /* Update client state */
445         
446         state->read_buf_len = 0;
447         state->write_buf_len = sizeof(struct winbindd_response);
448 }
449
450 /* Read some data from a client connection */
451
452 static void client_read(struct winbindd_cli_state *state)
453 {
454         int n;
455     
456         /* Read data */
457
458         do {
459                 n = read(state->sock, state->read_buf_len + (char *)&state->request, 
460                                  sizeof(state->request) - state->read_buf_len);
461         } while (n == -1 && errno == EINTR);
462         
463         DEBUG(10,("client_read: read %d bytes. Need %d more for a full request.\n", n,
464                         sizeof(state->request) - n - state->read_buf_len ));
465
466         /* Read failed, kill client */
467         
468         if (n == -1 || n == 0) {
469                 DEBUG(5,("read failed on sock %d, pid %d: %s\n",
470                          state->sock, state->pid, 
471                          (n == -1) ? strerror(errno) : "EOF"));
472                 
473                 state->finished = True;
474                 return;
475         }
476         
477         /* Update client state */
478         
479         state->read_buf_len += n;
480 }
481
482 /* Write some data to a client connection */
483
484 static void client_write(struct winbindd_cli_state *state)
485 {
486         char *data;
487         int num_written;
488         
489         /* Write some data */
490         
491         if (!state->write_extra_data) {
492
493                 /* Write response structure */
494                 
495                 data = (char *)&state->response + sizeof(state->response) - 
496                         state->write_buf_len;
497
498         } else {
499
500                 /* Write extra data */
501                 
502                 data = (char *)state->response.extra_data + 
503                         state->response.length - 
504                         sizeof(struct winbindd_response) - 
505                         state->write_buf_len;
506         }
507         
508         do {
509                 num_written = write(state->sock, data, state->write_buf_len);
510         } while (num_written == -1 && errno == EINTR);
511         
512         DEBUG(10,("client_write: wrote %d bytes.\n", num_written ));
513
514         /* Write failed, kill cilent */
515         
516         if (num_written == -1 || num_written == 0) {
517                 
518                 DEBUG(3,("write failed on sock %d, pid %d: %s\n",
519                          state->sock, state->pid, 
520                          (num_written == -1) ? strerror(errno) : "EOF"));
521                 
522                 state->finished = True;
523
524                 SAFE_FREE(state->response.extra_data);
525
526                 return;
527         }
528         
529         /* Update client state */
530         
531         state->write_buf_len -= num_written;
532         
533         /* Have we written all data? */
534         
535         if (state->write_buf_len == 0) {
536                 
537                 /* Take care of extra data */
538                 
539                 if (state->write_extra_data) {
540
541                         SAFE_FREE(state->response.extra_data);
542
543                         state->write_extra_data = False;
544
545                         DEBUG(10,("client_write: client_write: complete response written.\n"));
546
547                 } else if (state->response.length > 
548                            sizeof(struct winbindd_response)) {
549                         
550                         /* Start writing extra data */
551
552                         state->write_buf_len = 
553                                 state->response.length -
554                                 sizeof(struct winbindd_response);
555                         
556                         DEBUG(10,("client_write: need to write %d extra data bytes.\n", (int)state->write_buf_len));
557
558                         state->write_extra_data = True;
559                 }
560         }
561 }
562
563 /* Process incoming clients on accept_sock.  We use a tricky non-blocking,
564    non-forking, non-threaded model which allows us to handle many
565    simultaneous connections while remaining impervious to many denial of
566    service attacks. */
567
568 static void process_loop(int accept_sock)
569 {
570         /* We'll be doing this a lot */
571
572         while (1) {
573                 struct winbindd_cli_state *state;
574                 fd_set r_fds, w_fds;
575                 int maxfd = accept_sock, selret;
576                 struct timeval timeout;
577
578                 /* Free up temporary memory */
579
580                 lp_talloc_free();
581
582                 /* Initialise fd lists for select() */
583
584                 FD_ZERO(&r_fds);
585                 FD_ZERO(&w_fds);
586                 FD_SET(accept_sock, &r_fds);
587
588                 timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
589                 timeout.tv_usec = 0;
590
591                 /* Set up client readers and writers */
592
593                 state = client_list;
594
595                 while (state) {
596
597                         /* Dispose of client connection if it is marked as 
598                            finished */ 
599
600                         if (state->finished) {
601                                 struct winbindd_cli_state *next = state->next;
602
603                                 remove_client(state);
604                                 state = next;
605                                 continue;
606                         }
607
608                         /* Select requires we know the highest fd used */
609
610                         if (state->sock > maxfd)
611                                 maxfd = state->sock;
612
613                         /* Add fd for reading */
614
615                         if (state->read_buf_len != sizeof(state->request))
616                                 FD_SET(state->sock, &r_fds);
617
618                         /* Add fd for writing */
619
620                         if (state->write_buf_len)
621                                 FD_SET(state->sock, &w_fds);
622
623                         state = state->next;
624                 }
625
626                 /* Call select */
627         
628                 selret = select(maxfd + 1, &r_fds, &w_fds, NULL, &timeout);
629
630                 if (selret == 0)
631                         continue;
632
633                 if ((selret == -1 && errno != EINTR) || selret == 0) {
634
635                         /* Select error, something is badly wrong */
636
637                         perror("select");
638                         exit(1);
639                 }
640
641                 /* Create a new connection if accept_sock readable */
642
643                 if (selret > 0) {
644
645                         if (FD_ISSET(accept_sock, &r_fds))
646                                 new_connection(accept_sock);
647             
648                         /* Process activity on client connections */
649             
650                         for (state = client_list; state; state = state->next) {
651                 
652                                 /* Data available for reading */
653                 
654                                 if (FD_ISSET(state->sock, &r_fds)) {
655                     
656                                         /* Read data */
657                     
658                                         client_read(state);
659
660 #if 0
661                                         /* JRA - currently there's no length field in the request... */
662                                         /* 
663                                          * If we have the start of a
664                                          * packet, then check the
665                                          * length field to make sure
666                                          * the client's not talking
667                                          * Mock Swedish.
668                                          */
669
670                                         if (state->read_buf_len >= sizeof(int)
671                                             && *(int *) state->buf != sizeof(state->request)) {
672
673                                                 struct winbindd_cli_state *rem_state = state;
674
675                                                 DEBUG(0,("process_loop: Invalid request size (%d) send, should be (%d)\n",
676                                                                 *(int *) rem_state->buf, sizeof(rem_state->request) ));
677
678                                                 state = state_next;
679                                                 remove_client(rem_state);
680                                                 continue;
681                                         }
682 #endif
683
684                                         /* A request packet might be 
685                                            complete */
686                     
687                                         if (state->read_buf_len == 
688                                             sizeof(state->request)) {
689                                                 process_packet(state);
690                                         }
691                                 }
692                 
693                                 /* Data available for writing */
694                 
695                                 if (FD_ISSET(state->sock, &w_fds))
696                                         client_write(state);
697                         }
698                 }
699
700                 /* Check signal handling things */
701
702                 if (do_sigterm)
703                         terminate();
704
705                 if (do_sighup) {
706
707                         /* Flush winbindd cache */
708
709                         flush_caches();
710                         reload_services_file(True);
711                         do_sighup = False;
712                 }
713
714                 if (do_sigusr1) {
715                         print_winbindd_status();
716                         do_sigusr1 = False;
717                 }
718         }
719 }
720
721 /* Main function */
722
723 struct winbindd_state server_state;   /* Server state information */
724
725 int main(int argc, char **argv)
726 {
727         extern pstring global_myname;
728         int accept_sock;
729         BOOL interactive = False;
730         int opt, new_debuglevel = -1;
731
732         /* glibc (?) likes to print "User defined signal 1" and exit if a
733                 SIGUSR1 is received before a handler is installed */
734
735         CatchSignal(SIGUSR1, SIG_IGN);
736
737         fault_setup((void (*)(void *))fault_quit );
738         snprintf(debugf, sizeof(debugf), "%s/log.winbindd", dyn_LOGFILEBASE);
739
740         /* Initialise for running in non-root mode */
741
742         sec_init();
743
744         /* Set environment variable so we don't recursively call ourselves.
745            This may also be useful interactively. */
746
747         SETENV(WINBINDD_DONT_ENV, "1", 1);
748
749         /* Initialise samba/rpc client stuff */
750
751         while ((opt = getopt(argc, argv, "id:s:")) != EOF) {
752                 switch (opt) {
753
754                 /* Don't become a daemon */
755
756                 case 'i':
757                         interactive = True;
758                         break;
759
760                         /* Run with specified debug level */
761
762                 case 'd':
763                         new_debuglevel = atoi(optarg);
764                         break;
765
766                         /* Load a different smb.conf file */
767
768                 case 's':
769                         pstrcpy(dyn_CONFIGFILE,optarg);
770                         break;
771
772                 default:
773                         printf("Unknown option %c\n", (char)opt);
774                         exit(1);
775                 }
776         }
777
778         snprintf(debugf, sizeof(debugf), "%s/log.winbindd", dyn_LOGFILEBASE);
779         setup_logging("winbindd", interactive);
780         reopen_logs();
781
782         if (!*global_myname) {
783                 char *p;
784
785                 fstrcpy(global_myname, myhostname());
786                 p = strchr(global_myname, '.');
787                 if (p)
788                         *p = 0;
789         }
790
791
792         DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
793         DEBUGADD( 1, ( "Copyright The Samba Team 2000-2001\n" ) );
794
795         if (!reload_services_file(False)) {
796                 DEBUG(0, ("error opening config file\n"));
797                 exit(1);
798         }
799
800         if (new_debuglevel != -1)
801                 DEBUGLEVEL = new_debuglevel;
802
803         if (!interactive)
804                 become_daemon();
805
806         load_interfaces();
807
808         secrets_init();
809
810         /* Get list of domains we look up requests for.  This includes the
811                 domain which we are a member of as well as any trusted
812                 domains. */ 
813
814         get_domain_info();
815
816         ZERO_STRUCT(server_state);
817
818         /* Winbind daemon initialisation */
819
820         if (!winbindd_param_init())
821                 return 1;
822
823         if (!winbindd_idmap_init())
824                 return 1;
825
826         winbindd_cache_init();
827
828         /* Unblock all signals we are interested in as they may have been
829            blocked by the parent process. */
830
831         BlockSignals(False, SIGINT);
832         BlockSignals(False, SIGQUIT);
833         BlockSignals(False, SIGTERM);
834         BlockSignals(False, SIGUSR1);
835         BlockSignals(False, SIGHUP);
836
837         /* Setup signal handlers */
838         
839         CatchSignal(SIGINT, termination_handler);      /* Exit on these sigs */
840         CatchSignal(SIGQUIT, termination_handler);
841         CatchSignal(SIGTERM, termination_handler);
842
843         CatchSignal(SIGPIPE, SIG_IGN);                 /* Ignore sigpipe */
844
845         CatchSignal(SIGUSR1, sigusr1_handler);         /* Debugging sigs */
846         CatchSignal(SIGHUP, sighup_handler);
847
848         /* Create UNIX domain socket */
849         
850         if ((accept_sock = create_sock()) == -1) {
851                 DEBUG(0, ("failed to create socket\n"));
852                 return 1;
853         }
854
855         /* Loop waiting for requests */
856
857         process_loop(accept_sock);
858
859         return 0;
860 }