Consistently include <config.h> in all C source files and never in header files.
[platform/upstream/dbus.git] / bus / bus.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* bus.c  message bus context object
3  *
4  * Copyright (C) 2003, 2004 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <config.h>
25 #include "bus.h"
26 #include "activation.h"
27 #include "connection.h"
28 #include "services.h"
29 #include "utils.h"
30 #include "policy.h"
31 #include "config-parser.h"
32 #include "signals.h"
33 #include "selinux.h"
34 #include "dir-watch.h"
35 #include <dbus/dbus-list.h>
36 #include <dbus/dbus-hash.h>
37 #include <dbus/dbus-credentials.h>
38 #include <dbus/dbus-internals.h>
39
40 struct BusContext
41 {
42   int refcount;
43   DBusGUID uuid;
44   char *config_file;
45   char *type;
46   char *servicehelper;
47   char *address;
48   char *pidfile;
49   char *user;
50   char *log_prefix;
51   DBusLoop *loop;
52   DBusList *servers;
53   BusConnections *connections;
54   BusActivation *activation;
55   BusRegistry *registry;
56   BusPolicy *policy;
57   BusMatchmaker *matchmaker;
58   BusLimits limits;
59   unsigned int fork : 1;
60   unsigned int syslog : 1;
61   unsigned int keep_umask : 1;
62   unsigned int allow_anonymous : 1;
63 };
64
65 static dbus_int32_t server_data_slot = -1;
66
67 typedef struct
68 {
69   BusContext *context;
70 } BusServerData;
71
72 #define BUS_SERVER_DATA(server) (dbus_server_get_data ((server), server_data_slot))
73
74 static BusContext*
75 server_get_context (DBusServer *server)
76 {
77   BusContext *context;
78   BusServerData *bd;
79   
80   if (!dbus_server_allocate_data_slot (&server_data_slot))
81     return NULL;
82
83   bd = BUS_SERVER_DATA (server);
84   if (bd == NULL)
85     {
86       dbus_server_free_data_slot (&server_data_slot);
87       return NULL;
88     }
89
90   context = bd->context;
91
92   dbus_server_free_data_slot (&server_data_slot);
93
94   return context;
95 }
96
97 static dbus_bool_t
98 server_watch_callback (DBusWatch     *watch,
99                        unsigned int   condition,
100                        void          *data)
101 {
102   /* FIXME this can be done in dbus-mainloop.c
103    * if the code in activation.c for the babysitter
104    * watch handler is fixed.
105    */
106   
107   return dbus_watch_handle (watch, condition);
108 }
109
110 static dbus_bool_t
111 add_server_watch (DBusWatch  *watch,
112                   void       *data)
113 {
114   DBusServer *server = data;
115   BusContext *context;
116   
117   context = server_get_context (server);
118   
119   return _dbus_loop_add_watch (context->loop,
120                                watch, server_watch_callback, server,
121                                NULL);
122 }
123
124 static void
125 remove_server_watch (DBusWatch  *watch,
126                      void       *data)
127 {
128   DBusServer *server = data;
129   BusContext *context;
130   
131   context = server_get_context (server);
132   
133   _dbus_loop_remove_watch (context->loop,
134                            watch, server_watch_callback, server);
135 }
136
137
138 static void
139 server_timeout_callback (DBusTimeout   *timeout,
140                          void          *data)
141 {
142   /* can return FALSE on OOM but we just let it fire again later */
143   dbus_timeout_handle (timeout);
144 }
145
146 static dbus_bool_t
147 add_server_timeout (DBusTimeout *timeout,
148                     void        *data)
149 {
150   DBusServer *server = data;
151   BusContext *context;
152   
153   context = server_get_context (server);
154
155   return _dbus_loop_add_timeout (context->loop,
156                                  timeout, server_timeout_callback, server, NULL);
157 }
158
159 static void
160 remove_server_timeout (DBusTimeout *timeout,
161                        void        *data)
162 {
163   DBusServer *server = data;
164   BusContext *context;
165   
166   context = server_get_context (server);
167   
168   _dbus_loop_remove_timeout (context->loop,
169                              timeout, server_timeout_callback, server);
170 }
171
172 static void
173 new_connection_callback (DBusServer     *server,
174                          DBusConnection *new_connection,
175                          void           *data)
176 {
177   BusContext *context = data;
178   
179   if (!bus_connections_setup_connection (context->connections, new_connection))
180     {
181       _dbus_verbose ("No memory to setup new connection\n");
182
183       /* if we don't do this, it will get unref'd without
184        * being disconnected... kind of strange really
185        * that we have to do this, people won't get it right
186        * in general.
187        */
188       dbus_connection_close (new_connection);
189     }
190
191   dbus_connection_set_max_received_size (new_connection,
192                                          context->limits.max_incoming_bytes);
193
194   dbus_connection_set_max_message_size (new_connection,
195                                         context->limits.max_message_size);
196
197   dbus_connection_set_max_received_unix_fds (new_connection,
198                                          context->limits.max_incoming_unix_fds);
199
200   dbus_connection_set_max_message_unix_fds (new_connection,
201                                         context->limits.max_message_unix_fds);
202   
203   dbus_connection_set_allow_anonymous (new_connection,
204                                        context->allow_anonymous);
205
206   /* on OOM, we won't have ref'd the connection so it will die. */
207 }
208
209 static void
210 free_server_data (void *data)
211 {
212   BusServerData *bd = data;  
213   
214   dbus_free (bd);
215 }
216
217 static dbus_bool_t
218 setup_server (BusContext *context,
219               DBusServer *server,
220               char      **auth_mechanisms,
221               DBusError  *error)
222 {
223   BusServerData *bd;
224
225   bd = dbus_new0 (BusServerData, 1);
226   if (bd == NULL || !dbus_server_set_data (server,
227                                            server_data_slot,
228                                            bd, free_server_data))
229     {
230       dbus_free (bd);
231       BUS_SET_OOM (error);
232       return FALSE;
233     }
234
235   bd->context = context;
236   
237   if (!dbus_server_set_auth_mechanisms (server, (const char**) auth_mechanisms))
238     {
239       BUS_SET_OOM (error);
240       return FALSE;
241     }
242   
243   dbus_server_set_new_connection_function (server,
244                                            new_connection_callback,
245                                            context, NULL);
246   
247   if (!dbus_server_set_watch_functions (server,
248                                         add_server_watch,
249                                         remove_server_watch,
250                                         NULL,
251                                         server,
252                                         NULL))
253     {
254       BUS_SET_OOM (error);
255       return FALSE;
256     }
257
258   if (!dbus_server_set_timeout_functions (server,
259                                           add_server_timeout,
260                                           remove_server_timeout,
261                                           NULL,
262                                           server, NULL))
263     {
264       BUS_SET_OOM (error);
265       return FALSE;
266     }
267   
268   return TRUE;
269 }
270
271 /* This code only gets executed the first time the
272  * config files are parsed.  It is not executed
273  * when config files are reloaded.
274  */
275 static dbus_bool_t
276 process_config_first_time_only (BusContext      *context,
277                                 BusConfigParser *parser,
278                                 DBusError       *error)
279 {
280   DBusString log_prefix;
281   DBusList *link;
282   DBusList **addresses;
283   const char *user, *pidfile;
284   char **auth_mechanisms;
285   DBusList **auth_mechanisms_list;
286   int len;
287   dbus_bool_t retval;
288
289   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
290
291   retval = FALSE;
292   auth_mechanisms = NULL;
293
294   /* Check for an existing pid file. Of course this is a race;
295    * we'd have to use fcntl() locks on the pid file to
296    * avoid that. But we want to check for the pid file
297    * before overwriting any existing sockets, etc.
298    */
299   pidfile = bus_config_parser_get_pidfile (parser);
300   if (pidfile != NULL)
301     {
302       DBusString u;
303       DBusStat stbuf;
304       
305       _dbus_string_init_const (&u, pidfile);
306
307       if (_dbus_stat (&u, &stbuf, NULL))
308         {
309           dbus_set_error (error, DBUS_ERROR_FAILED,
310                                   "The pid file \"%s\" exists, if the message bus is not running, remove this file",
311                           pidfile);
312               goto failed;
313         }
314     }
315
316   /* keep around the pid filename so we can delete it later */
317   context->pidfile = _dbus_strdup (pidfile);
318
319   /* note that type may be NULL */
320   context->type = _dbus_strdup (bus_config_parser_get_type (parser));
321   if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
322     goto oom;
323
324   user = bus_config_parser_get_user (parser);
325   if (user != NULL)
326     {
327       context->user = _dbus_strdup (user);
328       if (context->user == NULL)
329         goto oom;
330     }
331
332   /* Set up the prefix for syslog messages */
333   if (!_dbus_string_init (&log_prefix))
334     goto oom;
335   if (context->type && !strcmp (context->type, "system"))
336     {
337       if (!_dbus_string_append (&log_prefix, "[system] "))
338         goto oom;
339     }
340   else if (context->type && !strcmp (context->type, "session"))
341     {
342       DBusCredentials *credentials;
343
344       credentials = _dbus_credentials_new_from_current_process ();
345       if (!credentials)
346         goto oom;
347       if (!_dbus_string_append (&log_prefix, "[session "))
348         goto oom;
349       if (!_dbus_credentials_to_string_append (credentials, &log_prefix))
350         goto oom;
351       if (!_dbus_string_append (&log_prefix, "] "))
352         goto oom;
353       _dbus_credentials_unref (credentials);
354     }
355   if (!_dbus_string_steal_data (&log_prefix, &context->log_prefix))
356     goto oom;
357   _dbus_string_free (&log_prefix);
358
359   /* Build an array of auth mechanisms */
360
361   auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
362   len = _dbus_list_get_length (auth_mechanisms_list);
363
364   if (len > 0)
365     {
366       int i;
367
368       auth_mechanisms = dbus_new0 (char*, len + 1);
369       if (auth_mechanisms == NULL)
370         goto oom;
371
372       i = 0;
373       link = _dbus_list_get_first_link (auth_mechanisms_list);
374       while (link != NULL)
375         {
376           auth_mechanisms[i] = _dbus_strdup (link->data);
377           if (auth_mechanisms[i] == NULL)
378             goto oom;
379           link = _dbus_list_get_next_link (auth_mechanisms_list, link);
380         }
381     }
382   else
383     {
384       auth_mechanisms = NULL;
385     }
386
387   /* Listen on our addresses */
388   
389   addresses = bus_config_parser_get_addresses (parser);  
390   
391   link = _dbus_list_get_first_link (addresses);
392   while (link != NULL)
393     {
394       DBusServer *server;
395       
396       server = dbus_server_listen (link->data, error);
397       if (server == NULL)
398         {
399           _DBUS_ASSERT_ERROR_IS_SET (error);
400           goto failed;
401         }
402       else if (!setup_server (context, server, auth_mechanisms, error))
403         {
404           _DBUS_ASSERT_ERROR_IS_SET (error);
405           goto failed;
406         }
407
408       if (!_dbus_list_append (&context->servers, server))
409         goto oom;
410
411       link = _dbus_list_get_next_link (addresses, link);
412     }
413
414   context->fork = bus_config_parser_get_fork (parser);
415   context->syslog = bus_config_parser_get_syslog (parser);
416   context->keep_umask = bus_config_parser_get_keep_umask (parser);
417   context->allow_anonymous = bus_config_parser_get_allow_anonymous (parser);
418
419   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
420   retval = TRUE;
421
422  failed:
423   dbus_free_string_array (auth_mechanisms);
424   return retval;
425
426  oom:
427   BUS_SET_OOM (error);
428   dbus_free_string_array (auth_mechanisms);
429   return FALSE;
430 }
431
432 /* This code gets executed every time the config files
433  * are parsed: both during BusContext construction
434  * and on reloads. This function is slightly screwy
435  * since it can do a "half reload" in out-of-memory
436  * situations. Realistically, unlikely to ever matter.
437  */
438 static dbus_bool_t
439 process_config_every_time (BusContext      *context,
440                            BusConfigParser *parser,
441                            dbus_bool_t      is_reload,
442                            DBusError       *error)
443 {
444   DBusString full_address;
445   DBusList *link;
446   DBusList **dirs;
447   BusActivation *new_activation;
448   char *addr;
449   const char *servicehelper;
450   char *s;
451   
452   dbus_bool_t retval;
453
454   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
455
456   addr = NULL;
457   retval = FALSE;
458
459   if (!_dbus_string_init (&full_address))
460     {
461       BUS_SET_OOM (error);
462       return FALSE;
463     }
464
465   /* get our limits and timeout lengths */
466   bus_config_parser_get_limits (parser, &context->limits);
467
468   if (context->policy)
469     bus_policy_unref (context->policy);
470   context->policy = bus_config_parser_steal_policy (parser);
471   _dbus_assert (context->policy != NULL);
472
473   /* We have to build the address backward, so that
474    * <listen> later in the config file have priority
475    */
476   link = _dbus_list_get_last_link (&context->servers);
477   while (link != NULL)
478     {
479       addr = dbus_server_get_address (link->data);
480       if (addr == NULL)
481         {
482           BUS_SET_OOM (error);
483           goto failed;
484         }
485
486       if (_dbus_string_get_length (&full_address) > 0)
487         {
488           if (!_dbus_string_append (&full_address, ";"))
489             {
490               BUS_SET_OOM (error);
491               goto failed;
492             }
493         }
494
495       if (!_dbus_string_append (&full_address, addr))
496         {
497           BUS_SET_OOM (error);
498           goto failed;
499         }
500
501       dbus_free (addr);
502       addr = NULL;
503
504       link = _dbus_list_get_prev_link (&context->servers, link);
505     }
506
507   if (is_reload)
508     dbus_free (context->address);
509
510   if (!_dbus_string_copy_data (&full_address, &context->address))
511     {
512       BUS_SET_OOM (error);
513       goto failed;
514     }
515
516   /* get the service directories */
517   dirs = bus_config_parser_get_service_dirs (parser);
518
519   /* and the service helper */
520   servicehelper = bus_config_parser_get_servicehelper (parser);
521
522   s = _dbus_strdup(servicehelper);
523   if (s == NULL && servicehelper != NULL)
524     {
525       BUS_SET_OOM (error);
526       goto failed;
527     }
528   else
529     {
530       dbus_free(context->servicehelper);
531       context->servicehelper = s;
532     }
533
534   /* Create activation subsystem */
535   if (context->activation)
536     {
537       if (!bus_activation_reload (context->activation, &full_address, dirs, error))
538         goto failed;
539     }
540   else
541     {
542       context->activation = bus_activation_new (context, &full_address, dirs, error);
543     }
544
545   if (context->activation == NULL)
546     {
547       _DBUS_ASSERT_ERROR_IS_SET (error);
548       goto failed;
549     }
550
551   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
552   retval = TRUE;
553
554  failed:
555   _dbus_string_free (&full_address);
556   
557   if (addr)
558     dbus_free (addr);
559
560   return retval;
561 }
562
563 static dbus_bool_t
564 list_concat_new (DBusList **a,
565                  DBusList **b,
566                  DBusList **result)
567 {
568   DBusList *link;
569
570   *result = NULL;
571
572   link = _dbus_list_get_first_link (a);
573   for (link = _dbus_list_get_first_link (a); link; link = _dbus_list_get_next_link (a, link))
574     {
575       if (!_dbus_list_append (result, link->data))
576         goto oom;
577     }
578   for (link = _dbus_list_get_first_link (b); link; link = _dbus_list_get_next_link (b, link))
579     {
580       if (!_dbus_list_append (result, link->data))
581         goto oom;
582     }
583
584   return TRUE;
585 oom:
586   _dbus_list_clear (result);
587   return FALSE;
588 }
589
590 static dbus_bool_t
591 process_config_postinit (BusContext      *context,
592                          BusConfigParser *parser,
593                          DBusError       *error)
594 {
595   DBusHashTable *service_context_table;
596   DBusList *watched_dirs = NULL;
597
598   service_context_table = bus_config_parser_steal_service_context_table (parser);
599   if (!bus_registry_set_service_context_table (context->registry,
600                                                service_context_table))
601     {
602       BUS_SET_OOM (error);
603       return FALSE;
604     }
605
606   _dbus_hash_table_unref (service_context_table);
607
608   /* We need to monitor both the configuration directories and directories
609    * containing .service files.
610    */
611   if (!list_concat_new (bus_config_parser_get_conf_dirs (parser),
612                         bus_config_parser_get_service_dirs (parser),
613                         &watched_dirs))
614     {
615       BUS_SET_OOM (error);
616       return FALSE;
617     }
618
619   bus_set_watched_dirs (context, &watched_dirs);
620
621   _dbus_list_clear (&watched_dirs);
622
623   return TRUE;
624 }
625
626 BusContext*
627 bus_context_new (const DBusString *config_file,
628                  ForceForkSetting  force_fork,
629                  DBusPipe         *print_addr_pipe,
630                  DBusPipe         *print_pid_pipe,
631                  DBusError        *error)
632 {
633   DBusString log_prefix;
634   BusContext *context;
635   BusConfigParser *parser;
636
637   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
638
639   context = NULL;
640   parser = NULL;
641
642   if (!dbus_server_allocate_data_slot (&server_data_slot))
643     {
644       BUS_SET_OOM (error);
645       return NULL;
646     }
647
648   context = dbus_new0 (BusContext, 1);
649   if (context == NULL)
650     {
651       BUS_SET_OOM (error);
652       goto failed;
653     }
654   context->refcount = 1;
655
656   _dbus_generate_uuid (&context->uuid);
657
658   if (!_dbus_string_copy_data (config_file, &context->config_file))
659     {
660       BUS_SET_OOM (error);
661       goto failed;
662     }
663
664   context->loop = _dbus_loop_new ();
665   if (context->loop == NULL)
666     {
667       BUS_SET_OOM (error);
668       goto failed;
669     }
670
671   context->registry = bus_registry_new (context);
672   if (context->registry == NULL)
673     {
674       BUS_SET_OOM (error);
675       goto failed;
676     }
677
678   parser = bus_config_load (config_file, TRUE, NULL, error);
679   if (parser == NULL)
680     {
681       _DBUS_ASSERT_ERROR_IS_SET (error);
682       goto failed;
683     }
684   
685   if (!process_config_first_time_only (context, parser, error))
686     {
687       _DBUS_ASSERT_ERROR_IS_SET (error);
688       goto failed;
689     }
690   if (!process_config_every_time (context, parser, FALSE, error))
691     {
692       _DBUS_ASSERT_ERROR_IS_SET (error);
693       goto failed;
694     }
695   
696   /* we need another ref of the server data slot for the context
697    * to own
698    */
699   if (!dbus_server_allocate_data_slot (&server_data_slot))
700     _dbus_assert_not_reached ("second ref of server data slot failed");
701
702   /* Note that we don't know whether the print_addr_pipe is
703    * one of the sockets we're using to listen on, or some
704    * other random thing. But I think the answer is "don't do
705    * that then"
706    */
707   if (print_addr_pipe != NULL && _dbus_pipe_is_valid (print_addr_pipe))
708     {
709       DBusString addr;
710       const char *a = bus_context_get_address (context);
711       int bytes;
712       
713       _dbus_assert (a != NULL);
714       if (!_dbus_string_init (&addr))
715         {
716           BUS_SET_OOM (error);
717           goto failed;
718         }
719       
720       if (!_dbus_string_append (&addr, a) ||
721           !_dbus_string_append (&addr, "\n"))
722         {
723           _dbus_string_free (&addr);
724           BUS_SET_OOM (error);
725           goto failed;
726         }
727
728       bytes = _dbus_string_get_length (&addr);
729       if (_dbus_pipe_write (print_addr_pipe, &addr, 0, bytes, error) != bytes)
730         {
731           /* pipe write returns an error on failure but not short write */
732           if (error != NULL && !dbus_error_is_set (error))
733             {
734               dbus_set_error (error, DBUS_ERROR_FAILED,
735                               "Printing message bus address: did not write all bytes\n");
736             }
737           _dbus_string_free (&addr);
738           goto failed;
739         }
740
741       if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe))
742         _dbus_pipe_close (print_addr_pipe, NULL);
743       
744       _dbus_string_free (&addr);
745     }
746   
747   context->connections = bus_connections_new (context);
748   if (context->connections == NULL)
749     {
750       BUS_SET_OOM (error);
751       goto failed;
752     }
753
754   context->matchmaker = bus_matchmaker_new ();
755   if (context->matchmaker == NULL)
756     {
757       BUS_SET_OOM (error);
758       goto failed;
759     }
760
761   /* check user before we fork */
762   if (context->user != NULL)
763     {
764       if (!_dbus_verify_daemon_user (context->user))
765         {
766           dbus_set_error (error, DBUS_ERROR_FAILED,
767                           "Could not get UID and GID for username \"%s\"",
768                           context->user);
769           goto failed;
770         }
771     }
772
773   /* Now become a daemon if appropriate and write out pid file in any case */
774   {
775     DBusString u;
776
777     if (context->pidfile)
778       _dbus_string_init_const (&u, context->pidfile);
779
780     if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
781       {
782         _dbus_verbose ("Forking and becoming daemon\n");
783         
784         if (!_dbus_become_daemon (context->pidfile ? &u : NULL, 
785                                   print_pid_pipe,
786                                   error,
787                                   context->keep_umask))
788           {
789             _DBUS_ASSERT_ERROR_IS_SET (error);
790             goto failed;
791           }
792       }
793     else
794       {
795         _dbus_verbose ("Fork not requested\n");
796         
797         /* Need to write PID file and to PID pipe for ourselves,
798          * not for the child process. This is a no-op if the pidfile
799          * is NULL and print_pid_pipe is NULL.
800          */
801         if (!_dbus_write_pid_to_file_and_pipe (context->pidfile ? &u : NULL,
802                                                print_pid_pipe,
803                                                _dbus_getpid (),
804                                                error))
805           {
806             _DBUS_ASSERT_ERROR_IS_SET (error);
807             goto failed;
808           }
809       }
810   }
811
812   if (print_pid_pipe && _dbus_pipe_is_valid (print_pid_pipe) &&
813       !_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
814     _dbus_pipe_close (print_pid_pipe, NULL);
815
816   if (!bus_selinux_full_init ())
817     {
818       bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but AVC initialization failed; check system log\n");
819     }
820
821   if (!process_config_postinit (context, parser, error))
822     {
823       _DBUS_ASSERT_ERROR_IS_SET (error);
824       goto failed;
825     }
826
827   if (parser != NULL)
828     {
829       bus_config_parser_unref (parser);
830       parser = NULL;
831     }
832   
833   /* Here we change our credentials if required,
834    * as soon as we've set up our sockets and pidfile
835    */
836   if (context->user != NULL)
837     {
838       if (!_dbus_change_to_daemon_user (context->user, error))
839         {
840           _DBUS_ASSERT_ERROR_IS_SET (error);
841           goto failed;
842         }
843
844 #ifdef HAVE_SELINUX
845       /* FIXME - why not just put this in full_init() below? */
846       bus_selinux_audit_init ();
847 #endif
848     }
849
850   dbus_server_free_data_slot (&server_data_slot);
851   
852   return context;
853   
854  failed:  
855   if (parser != NULL)
856     bus_config_parser_unref (parser);
857   if (context != NULL)
858     bus_context_unref (context);
859
860   if (server_data_slot >= 0)
861     dbus_server_free_data_slot (&server_data_slot);
862   
863   return NULL;
864 }
865
866 dbus_bool_t
867 bus_context_get_id (BusContext       *context,
868                     DBusString       *uuid)
869 {
870   return _dbus_uuid_encode (&context->uuid, uuid);
871 }
872
873 dbus_bool_t
874 bus_context_reload_config (BusContext *context,
875                            DBusError  *error)
876 {
877   BusConfigParser *parser;
878   DBusString config_file;
879   dbus_bool_t ret;
880
881   /* Flush the user database cache */
882   _dbus_flush_caches ();
883
884   ret = FALSE;
885   _dbus_string_init_const (&config_file, context->config_file);
886   parser = bus_config_load (&config_file, TRUE, NULL, error);
887   if (parser == NULL)
888     {
889       _DBUS_ASSERT_ERROR_IS_SET (error);
890       goto failed;
891     }
892   
893   if (!process_config_every_time (context, parser, TRUE, error))
894     {
895       _DBUS_ASSERT_ERROR_IS_SET (error);
896       goto failed;
897     }
898   if (!process_config_postinit (context, parser, error))
899     {
900       _DBUS_ASSERT_ERROR_IS_SET (error);
901       goto failed;
902     }
903   ret = TRUE;
904
905   bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration");
906  failed:
907   if (!ret)
908     bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to reload configuration: %s", error->message);
909   if (parser != NULL)
910     bus_config_parser_unref (parser);
911   return ret;
912 }
913
914 static void
915 shutdown_server (BusContext *context,
916                  DBusServer *server)
917 {
918   if (server == NULL ||
919       !dbus_server_get_is_connected (server))
920     return;
921   
922   if (!dbus_server_set_watch_functions (server,
923                                         NULL, NULL, NULL,
924                                         context,
925                                         NULL))
926     _dbus_assert_not_reached ("setting watch functions to NULL failed");
927   
928   if (!dbus_server_set_timeout_functions (server,
929                                           NULL, NULL, NULL,
930                                           context,
931                                           NULL))
932     _dbus_assert_not_reached ("setting timeout functions to NULL failed");
933   
934   dbus_server_disconnect (server);
935 }
936
937 void
938 bus_context_shutdown (BusContext  *context)
939 {
940   DBusList *link;
941
942   link = _dbus_list_get_first_link (&context->servers);
943   while (link != NULL)
944     {
945       shutdown_server (context, link->data);
946
947       link = _dbus_list_get_next_link (&context->servers, link);
948     }
949 }
950
951 BusContext *
952 bus_context_ref (BusContext *context)
953 {
954   _dbus_assert (context->refcount > 0);
955   context->refcount += 1;
956
957   return context;
958 }
959
960 void
961 bus_context_unref (BusContext *context)
962 {
963   _dbus_assert (context->refcount > 0);
964   context->refcount -= 1;
965
966   if (context->refcount == 0)
967     {
968       DBusList *link;
969       
970       _dbus_verbose ("Finalizing bus context %p\n", context);
971       
972       bus_context_shutdown (context);
973
974       if (context->connections)
975         {
976           bus_connections_unref (context->connections);
977           context->connections = NULL;
978         }
979       
980       if (context->registry)
981         {
982           bus_registry_unref (context->registry);
983           context->registry = NULL;
984         }
985       
986       if (context->activation)
987         {
988           bus_activation_unref (context->activation);
989           context->activation = NULL;
990         }
991
992       link = _dbus_list_get_first_link (&context->servers);
993       while (link != NULL)
994         {
995           dbus_server_unref (link->data);
996           
997           link = _dbus_list_get_next_link (&context->servers, link);
998         }
999       _dbus_list_clear (&context->servers);
1000
1001       if (context->policy)
1002         {
1003           bus_policy_unref (context->policy);
1004           context->policy = NULL;
1005         }
1006       
1007       if (context->loop)
1008         {
1009           _dbus_loop_unref (context->loop);
1010           context->loop = NULL;
1011         }
1012
1013       if (context->matchmaker)
1014         {
1015           bus_matchmaker_unref (context->matchmaker);
1016           context->matchmaker = NULL;
1017         }
1018
1019       dbus_free (context->config_file);
1020       dbus_free (context->log_prefix);
1021       dbus_free (context->type);
1022       dbus_free (context->address);
1023       dbus_free (context->user);
1024       dbus_free (context->servicehelper);
1025
1026       if (context->pidfile)
1027         {
1028           DBusString u;
1029           _dbus_string_init_const (&u, context->pidfile);
1030
1031           /* Deliberately ignore errors here, since there's not much
1032            * we can do about it, and we're exiting anyways.
1033            */
1034           _dbus_delete_file (&u, NULL);
1035
1036           dbus_free (context->pidfile); 
1037         }
1038       dbus_free (context);
1039
1040       dbus_server_free_data_slot (&server_data_slot);
1041     }
1042 }
1043
1044 /* type may be NULL */
1045 const char*
1046 bus_context_get_type (BusContext *context)
1047 {
1048   return context->type;
1049 }
1050
1051 const char*
1052 bus_context_get_address (BusContext *context)
1053 {
1054   return context->address;
1055 }
1056
1057 const char*
1058 bus_context_get_servicehelper (BusContext *context)
1059 {
1060   return context->servicehelper;
1061 }
1062
1063 BusRegistry*
1064 bus_context_get_registry (BusContext  *context)
1065 {
1066   return context->registry;
1067 }
1068
1069 BusConnections*
1070 bus_context_get_connections (BusContext  *context)
1071 {
1072   return context->connections;
1073 }
1074
1075 BusActivation*
1076 bus_context_get_activation (BusContext  *context)
1077 {
1078   return context->activation;
1079 }
1080
1081 BusMatchmaker*
1082 bus_context_get_matchmaker (BusContext  *context)
1083 {
1084   return context->matchmaker;
1085 }
1086
1087 DBusLoop*
1088 bus_context_get_loop (BusContext *context)
1089 {
1090   return context->loop;
1091 }
1092
1093 dbus_bool_t
1094 bus_context_allow_unix_user (BusContext   *context,
1095                              unsigned long uid)
1096 {
1097   return bus_policy_allow_unix_user (context->policy,
1098                                      uid);
1099 }
1100
1101 /* For now this is never actually called because the default
1102  * DBusConnection behavior of 'same user that owns the bus can connect'
1103  * is all it would do.
1104  */
1105 dbus_bool_t
1106 bus_context_allow_windows_user (BusContext       *context,
1107                                 const char       *windows_sid)
1108 {
1109   return bus_policy_allow_windows_user (context->policy,
1110                                         windows_sid);
1111 }
1112
1113 BusPolicy *
1114 bus_context_get_policy (BusContext *context)
1115 {
1116   return context->policy;
1117 }
1118
1119 BusClientPolicy*
1120 bus_context_create_client_policy (BusContext      *context,
1121                                   DBusConnection  *connection,
1122                                   DBusError       *error)
1123 {
1124   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1125   return bus_policy_create_client_policy (context->policy, connection,
1126                                           error);
1127 }
1128
1129 int
1130 bus_context_get_activation_timeout (BusContext *context)
1131 {
1132   
1133   return context->limits.activation_timeout;
1134 }
1135
1136 int
1137 bus_context_get_auth_timeout (BusContext *context)
1138 {
1139   return context->limits.auth_timeout;
1140 }
1141
1142 int
1143 bus_context_get_max_completed_connections (BusContext *context)
1144 {
1145   return context->limits.max_completed_connections;
1146 }
1147
1148 int
1149 bus_context_get_max_incomplete_connections (BusContext *context)
1150 {
1151   return context->limits.max_incomplete_connections;
1152 }
1153
1154 int
1155 bus_context_get_max_connections_per_user (BusContext *context)
1156 {
1157   return context->limits.max_connections_per_user;
1158 }
1159
1160 int
1161 bus_context_get_max_pending_activations (BusContext *context)
1162 {
1163   return context->limits.max_pending_activations;
1164 }
1165
1166 int
1167 bus_context_get_max_services_per_connection (BusContext *context)
1168 {
1169   return context->limits.max_services_per_connection;
1170 }
1171
1172 int
1173 bus_context_get_max_match_rules_per_connection (BusContext *context)
1174 {
1175   return context->limits.max_match_rules_per_connection;
1176 }
1177
1178 int
1179 bus_context_get_max_replies_per_connection (BusContext *context)
1180 {
1181   return context->limits.max_replies_per_connection;
1182 }
1183
1184 int
1185 bus_context_get_reply_timeout (BusContext *context)
1186 {
1187   return context->limits.reply_timeout;
1188 }
1189
1190 void
1191 bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
1192 {
1193   va_list args;
1194
1195   if (!context->syslog)
1196     return;
1197
1198   va_start (args, msg);
1199
1200   if (context->log_prefix)
1201     {
1202       DBusString full_msg;
1203
1204       if (!_dbus_string_init (&full_msg))
1205         goto out;
1206       if (!_dbus_string_append (&full_msg, context->log_prefix))
1207         goto oom_out;
1208       if (!_dbus_string_append_printf_valist (&full_msg, msg, args))
1209         goto oom_out;
1210
1211       _dbus_system_log (severity, "%s", full_msg);
1212     oom_out:
1213       _dbus_string_free (&full_msg);
1214     }
1215   else
1216     _dbus_system_logv (severity, msg, args);
1217
1218 out:
1219   va_end (args);
1220 }
1221
1222 /*
1223  * addressed_recipient is the recipient specified in the message.
1224  *
1225  * proposed_recipient is the recipient we're considering sending
1226  * to right this second, and may be an eavesdropper.
1227  *
1228  * sender is the sender of the message.
1229  *
1230  * NULL for proposed_recipient or sender definitely means the bus driver.
1231  *
1232  * NULL for addressed_recipient may mean the bus driver, or may mean
1233  * no destination was specified in the message (e.g. a signal).
1234  */
1235 dbus_bool_t
1236 bus_context_check_security_policy (BusContext     *context,
1237                                    BusTransaction *transaction,
1238                                    DBusConnection *sender,
1239                                    DBusConnection *addressed_recipient,
1240                                    DBusConnection *proposed_recipient,
1241                                    DBusMessage    *message,
1242                                    DBusError      *error)
1243 {
1244   const char *dest;
1245   BusClientPolicy *sender_policy;
1246   BusClientPolicy *recipient_policy;
1247   dbus_int32_t toggles;
1248   dbus_bool_t log;
1249   int type;
1250   dbus_bool_t requested_reply;
1251   const char *sender_name;
1252   const char *sender_loginfo;
1253   const char *proposed_recipient_loginfo;
1254   
1255   type = dbus_message_get_type (message);
1256   dest = dbus_message_get_destination (message);
1257   
1258   /* dispatch.c was supposed to ensure these invariants */
1259   _dbus_assert (dest != NULL ||
1260                 type == DBUS_MESSAGE_TYPE_SIGNAL ||
1261                 (sender == NULL && !bus_connection_is_active (proposed_recipient)));
1262   _dbus_assert (type == DBUS_MESSAGE_TYPE_SIGNAL ||
1263                 addressed_recipient != NULL ||
1264                 strcmp (dest, DBUS_SERVICE_DBUS) == 0);
1265
1266   /* Used in logging below */
1267   if (sender != NULL)
1268     {
1269       sender_name = bus_connection_get_name (sender);
1270       sender_loginfo = bus_connection_get_loginfo (sender);
1271     }
1272   else
1273     {
1274       sender_name = NULL;
1275       sender_loginfo = "(bus)";
1276     }
1277   
1278   if (proposed_recipient != NULL)
1279     proposed_recipient_loginfo = bus_connection_get_loginfo (proposed_recipient);
1280   else
1281     proposed_recipient_loginfo = "bus";
1282   
1283   switch (type)
1284     {
1285     case DBUS_MESSAGE_TYPE_METHOD_CALL:
1286     case DBUS_MESSAGE_TYPE_SIGNAL:
1287     case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1288     case DBUS_MESSAGE_TYPE_ERROR:
1289       break;
1290       
1291     default:
1292       _dbus_verbose ("security check disallowing message of unknown type %d\n",
1293                      type);
1294
1295       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1296                       "Message bus will not accept messages of unknown type\n");
1297               
1298       return FALSE;
1299     }
1300
1301   requested_reply = FALSE;
1302   
1303   if (sender != NULL)
1304     {
1305       /* First verify the SELinux access controls.  If allowed then
1306        * go on with the standard checks.
1307        */
1308       if (!bus_selinux_allows_send (sender, proposed_recipient,
1309                                     dbus_message_type_to_string (dbus_message_get_type (message)),
1310                                     dbus_message_get_interface (message),
1311                                     dbus_message_get_member (message),
1312                                     dbus_message_get_error_name (message),
1313                                     dest ? dest : DBUS_SERVICE_DBUS, error))
1314         {
1315           if (error != NULL && !dbus_error_is_set (error))
1316             {
1317               dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1318                               "An SELinux policy prevents this sender "
1319                               "from sending this message to this recipient "
1320                               "(rejected message had sender \"%s\" interface \"%s\" "
1321                               "member \"%s\" error name \"%s\" destination \"%s\")",
1322                               sender_name ? sender_name : "(unset)",
1323                               dbus_message_get_interface (message) ?
1324                               dbus_message_get_interface (message) : "(unset)",
1325                               dbus_message_get_member (message) ?
1326                               dbus_message_get_member (message) : "(unset)",
1327                               dbus_message_get_error_name (message) ?
1328                               dbus_message_get_error_name (message) : "(unset)",
1329                               dest ? dest : DBUS_SERVICE_DBUS);
1330               _dbus_verbose ("SELinux security check denying send to service\n");
1331             }
1332
1333           return FALSE;
1334         }
1335        
1336       if (bus_connection_is_active (sender))
1337         {
1338           sender_policy = bus_connection_get_policy (sender);
1339           _dbus_assert (sender_policy != NULL);
1340           
1341           /* Fill in requested_reply variable with TRUE if this is a
1342            * reply and the reply was pending.
1343            */
1344           if (dbus_message_get_reply_serial (message) != 0)
1345             {
1346               if (proposed_recipient != NULL /* not to the bus driver */ &&
1347                   addressed_recipient == proposed_recipient /* not eavesdropping */)
1348                 {
1349                   DBusError error2;                  
1350                   
1351                   dbus_error_init (&error2);
1352                   requested_reply = bus_connections_check_reply (bus_connection_get_connections (sender),
1353                                                                  transaction,
1354                                                                  sender, addressed_recipient, message,
1355                                                                  &error2);
1356                   if (dbus_error_is_set (&error2))
1357                     {
1358                       dbus_move_error (&error2, error);
1359                       return FALSE;
1360                     }
1361                 }
1362             }
1363         }
1364       else
1365         {
1366           /* Policy for inactive connections is that they can only send
1367            * the hello message to the bus driver
1368            */
1369           if (proposed_recipient == NULL &&
1370               dbus_message_is_method_call (message,
1371                                            DBUS_INTERFACE_DBUS,
1372                                            "Hello"))
1373             {
1374               _dbus_verbose ("security check allowing %s message\n",
1375                              "Hello");
1376               return TRUE;
1377             }
1378           else
1379             {
1380               _dbus_verbose ("security check disallowing non-%s message\n",
1381                              "Hello");
1382
1383               dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1384                               "Client tried to send a message other than %s without being registered",
1385                               "Hello");
1386               
1387               return FALSE;
1388             }
1389         }
1390     }
1391   else
1392     {
1393       sender_policy = NULL;
1394
1395       /* If the sender is the bus driver, we assume any reply was a
1396        * requested reply as bus driver won't send bogus ones
1397        */
1398       if (addressed_recipient == proposed_recipient /* not eavesdropping */ &&
1399           dbus_message_get_reply_serial (message) != 0)
1400         requested_reply = TRUE;
1401     }
1402
1403   _dbus_assert ((sender != NULL && sender_policy != NULL) ||
1404                 (sender == NULL && sender_policy == NULL));
1405   
1406   if (proposed_recipient != NULL)
1407     {
1408       /* only the bus driver can send to an inactive recipient (as it
1409        * owns no services, so other apps can't address it). Inactive
1410        * recipients can receive any message.
1411        */
1412       if (bus_connection_is_active (proposed_recipient))
1413         {
1414           recipient_policy = bus_connection_get_policy (proposed_recipient);
1415           _dbus_assert (recipient_policy != NULL);
1416         }
1417       else if (sender == NULL)
1418         {
1419           _dbus_verbose ("security check using NULL recipient policy for message from bus\n");
1420           recipient_policy = NULL;
1421         }
1422       else
1423         {
1424           _dbus_assert_not_reached ("a message was somehow sent to an inactive recipient from a source other than the message bus\n");
1425           recipient_policy = NULL;
1426         }
1427     }
1428   else
1429     recipient_policy = NULL;
1430   
1431   _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) ||
1432                 (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) ||
1433                 (proposed_recipient == NULL && recipient_policy == NULL));
1434   
1435   log = FALSE;
1436   if (sender_policy &&
1437       !bus_client_policy_check_can_send (sender_policy,
1438                                          context->registry,
1439                                          requested_reply,
1440                                          proposed_recipient,
1441                                          message, &toggles, &log))
1442     {
1443       const char *msg = "Rejected send message, %d matched rules; "
1444                         "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))";
1445
1446       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, msg,
1447                       toggles,
1448                       dbus_message_type_to_string (dbus_message_get_type (message)),
1449                       sender_name ? sender_name : "(unset)",
1450                       sender_loginfo,
1451                       dbus_message_get_interface (message) ?
1452                       dbus_message_get_interface (message) : "(unset)",
1453                       dbus_message_get_member (message) ?
1454                       dbus_message_get_member (message) : "(unset)",
1455                       dbus_message_get_error_name (message) ?
1456                       dbus_message_get_error_name (message) : "(unset)",
1457                       requested_reply,
1458                       dest ? dest : DBUS_SERVICE_DBUS,
1459                       proposed_recipient_loginfo);
1460       /* Needs to be duplicated to avoid calling malloc and having to handle OOM */
1461       if (addressed_recipient == proposed_recipient)
1462         bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
1463                                   toggles,
1464                                   dbus_message_type_to_string (dbus_message_get_type (message)),
1465                                   sender_name ? sender_name : "(unset)",
1466                                   sender_loginfo,
1467                                   dbus_message_get_interface (message) ?
1468                                   dbus_message_get_interface (message) : "(unset)",
1469                                   dbus_message_get_member (message) ?
1470                                   dbus_message_get_member (message) : "(unset)",
1471                                   dbus_message_get_error_name (message) ?
1472                                   dbus_message_get_error_name (message) : "(unset)",
1473                                   requested_reply,
1474                                   dest ? dest : DBUS_SERVICE_DBUS,
1475                                   proposed_recipient_loginfo);
1476       _dbus_verbose ("security policy disallowing message due to sender policy\n");
1477       return FALSE;
1478     }
1479
1480   if (log)
1481     bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY,
1482                               "Would reject message, %d matched rules; "
1483                               "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))",
1484                               toggles,
1485                               dbus_message_type_to_string (dbus_message_get_type (message)),
1486                               sender_name ? sender_name : "(unset)",
1487                               sender_loginfo,
1488                               dbus_message_get_interface (message) ?
1489                               dbus_message_get_interface (message) : "(unset)",
1490                               dbus_message_get_member (message) ?
1491                               dbus_message_get_member (message) : "(unset)",
1492                               dbus_message_get_error_name (message) ?
1493                               dbus_message_get_error_name (message) : "(unset)",
1494                               requested_reply,                               
1495                               dest ? dest : DBUS_SERVICE_DBUS,
1496                               proposed_recipient_loginfo);
1497
1498   if (recipient_policy &&
1499       !bus_client_policy_check_can_receive (recipient_policy,
1500                                             context->registry,
1501                                             requested_reply,
1502                                             sender,
1503                                             addressed_recipient, proposed_recipient,
1504                                             message, &toggles))
1505     {
1506       const char *msg = "Rejected receive message, %d matched rules; "
1507                         "type=\"%s\" sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" reply serial=%u requested_reply=%d destination=\"%s\" (%s))";
1508
1509       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, msg,
1510                       toggles,
1511                       dbus_message_type_to_string (dbus_message_get_type (message)),
1512                       sender_name ? sender_name : "(unset)",
1513                       sender_loginfo,
1514                       dbus_message_get_interface (message) ?
1515                       dbus_message_get_interface (message) : "(unset)",
1516                       dbus_message_get_member (message) ?
1517                       dbus_message_get_member (message) : "(unset)",
1518                       dbus_message_get_error_name (message) ?
1519                       dbus_message_get_error_name (message) : "(unset)",
1520                       dbus_message_get_reply_serial (message),
1521                       requested_reply,
1522                       dest ? dest : DBUS_SERVICE_DBUS,
1523                       proposed_recipient_loginfo);
1524       /* Needs to be duplicated to avoid calling malloc and having to handle OOM */
1525       if (addressed_recipient == proposed_recipient)
1526         bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
1527                                   toggles,
1528                                   dbus_message_type_to_string (dbus_message_get_type (message)),
1529                                   sender_name ? sender_name : "(unset)",
1530                                   sender_loginfo,
1531                                   dbus_message_get_interface (message) ?
1532                                   dbus_message_get_interface (message) : "(unset)",
1533                                   dbus_message_get_member (message) ?
1534                                   dbus_message_get_member (message) : "(unset)",
1535                                   dbus_message_get_error_name (message) ?
1536                                   dbus_message_get_error_name (message) : "(unset)",
1537                                   dbus_message_get_reply_serial (message),
1538                                   requested_reply,
1539                                   dest ? dest : DBUS_SERVICE_DBUS,
1540                                   proposed_recipient_loginfo);
1541       _dbus_verbose ("security policy disallowing message due to recipient policy\n");
1542       return FALSE;
1543     }
1544
1545   /* See if limits on size have been exceeded */
1546   if (proposed_recipient &&
1547       ((dbus_connection_get_outgoing_size (proposed_recipient) > context->limits.max_outgoing_bytes) ||
1548        (dbus_connection_get_outgoing_unix_fds (proposed_recipient) > context->limits.max_outgoing_unix_fds)))
1549     {
1550       dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1551                       "The destination service \"%s\" has a full message queue",
1552                       dest ? dest : (proposed_recipient ?
1553                                      bus_connection_get_name (proposed_recipient) : 
1554                                      DBUS_SERVICE_DBUS));
1555       _dbus_verbose ("security policy disallowing message due to full message queue\n");
1556       return FALSE;
1557     }
1558
1559   /* Record that we will allow a reply here in the future (don't
1560    * bother if the recipient is the bus or this is an eavesdropping
1561    * connection). Only the addressed recipient may reply.
1562    */
1563   if (type == DBUS_MESSAGE_TYPE_METHOD_CALL &&
1564       sender && 
1565       addressed_recipient &&
1566       addressed_recipient == proposed_recipient && /* not eavesdropping */
1567       !bus_connections_expect_reply (bus_connection_get_connections (sender),
1568                                      transaction,
1569                                      sender, addressed_recipient,
1570                                      message, error))
1571     {
1572       _dbus_verbose ("Failed to record reply expectation or problem with the message expecting a reply\n");
1573       return FALSE;
1574     }
1575   
1576   _dbus_verbose ("security policy allowing message\n");
1577   return TRUE;
1578 }