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