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