Merge branch 'dbus-1.2'
[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, ...) _DBUS_GNUC_PRINTF (3, 4);
1192
1193 void
1194 bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
1195 {
1196   va_list args;
1197
1198   if (!context->syslog)
1199     return;
1200
1201   va_start (args, msg);
1202
1203   if (context->log_prefix)
1204     {
1205       DBusString full_msg;
1206
1207       if (!_dbus_string_init (&full_msg))
1208         goto out;
1209       if (!_dbus_string_append (&full_msg, context->log_prefix))
1210         goto oom_out;
1211       if (!_dbus_string_append_printf_valist (&full_msg, msg, args))
1212         goto oom_out;
1213
1214       _dbus_system_log (severity, "%s", _dbus_string_get_const_data (&full_msg));
1215     oom_out:
1216       _dbus_string_free (&full_msg);
1217     }
1218   else
1219     _dbus_system_logv (severity, msg, args);
1220
1221 out:
1222   va_end (args);
1223 }
1224
1225 /*
1226  * addressed_recipient is the recipient specified in the message.
1227  *
1228  * proposed_recipient is the recipient we're considering sending
1229  * to right this second, and may be an eavesdropper.
1230  *
1231  * sender is the sender of the message.
1232  *
1233  * NULL for proposed_recipient or sender definitely means the bus driver.
1234  *
1235  * NULL for addressed_recipient may mean the bus driver, or may mean
1236  * no destination was specified in the message (e.g. a signal).
1237  */
1238 dbus_bool_t
1239 bus_context_check_security_policy (BusContext     *context,
1240                                    BusTransaction *transaction,
1241                                    DBusConnection *sender,
1242                                    DBusConnection *addressed_recipient,
1243                                    DBusConnection *proposed_recipient,
1244                                    DBusMessage    *message,
1245                                    DBusError      *error)
1246 {
1247   const char *dest;
1248   BusClientPolicy *sender_policy;
1249   BusClientPolicy *recipient_policy;
1250   dbus_int32_t toggles;
1251   dbus_bool_t log;
1252   int type;
1253   dbus_bool_t requested_reply;
1254   const char *sender_name;
1255   const char *sender_loginfo;
1256   const char *proposed_recipient_loginfo;
1257   
1258   type = dbus_message_get_type (message);
1259   dest = dbus_message_get_destination (message);
1260   
1261   /* dispatch.c was supposed to ensure these invariants */
1262   _dbus_assert (dest != NULL ||
1263                 type == DBUS_MESSAGE_TYPE_SIGNAL ||
1264                 (sender == NULL && !bus_connection_is_active (proposed_recipient)));
1265   _dbus_assert (type == DBUS_MESSAGE_TYPE_SIGNAL ||
1266                 addressed_recipient != NULL ||
1267                 strcmp (dest, DBUS_SERVICE_DBUS) == 0);
1268
1269   /* Used in logging below */
1270   if (sender != NULL)
1271     {
1272       sender_name = bus_connection_get_name (sender);
1273       sender_loginfo = bus_connection_get_loginfo (sender);
1274     }
1275   else
1276     {
1277       sender_name = NULL;
1278       sender_loginfo = "(bus)";
1279     }
1280   
1281   if (proposed_recipient != NULL)
1282     proposed_recipient_loginfo = bus_connection_get_loginfo (proposed_recipient);
1283   else
1284     proposed_recipient_loginfo = "bus";
1285   
1286   switch (type)
1287     {
1288     case DBUS_MESSAGE_TYPE_METHOD_CALL:
1289     case DBUS_MESSAGE_TYPE_SIGNAL:
1290     case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1291     case DBUS_MESSAGE_TYPE_ERROR:
1292       break;
1293       
1294     default:
1295       _dbus_verbose ("security check disallowing message of unknown type %d\n",
1296                      type);
1297
1298       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1299                       "Message bus will not accept messages of unknown type\n");
1300               
1301       return FALSE;
1302     }
1303
1304   requested_reply = FALSE;
1305   
1306   if (sender != NULL)
1307     {
1308       /* First verify the SELinux access controls.  If allowed then
1309        * go on with the standard checks.
1310        */
1311       if (!bus_selinux_allows_send (sender, proposed_recipient,
1312                                     dbus_message_type_to_string (dbus_message_get_type (message)),
1313                                     dbus_message_get_interface (message),
1314                                     dbus_message_get_member (message),
1315                                     dbus_message_get_error_name (message),
1316                                     dest ? dest : DBUS_SERVICE_DBUS, error))
1317         {
1318           if (error != NULL && !dbus_error_is_set (error))
1319             {
1320               dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1321                               "An SELinux policy prevents this sender "
1322                               "from sending this message to this recipient "
1323                               "(rejected message had sender \"%s\" interface \"%s\" "
1324                               "member \"%s\" error name \"%s\" destination \"%s\")",
1325                               sender_name ? sender_name : "(unset)",
1326                               dbus_message_get_interface (message) ?
1327                               dbus_message_get_interface (message) : "(unset)",
1328                               dbus_message_get_member (message) ?
1329                               dbus_message_get_member (message) : "(unset)",
1330                               dbus_message_get_error_name (message) ?
1331                               dbus_message_get_error_name (message) : "(unset)",
1332                               dest ? dest : DBUS_SERVICE_DBUS);
1333               _dbus_verbose ("SELinux security check denying send to service\n");
1334             }
1335
1336           return FALSE;
1337         }
1338        
1339       if (bus_connection_is_active (sender))
1340         {
1341           sender_policy = bus_connection_get_policy (sender);
1342           _dbus_assert (sender_policy != NULL);
1343           
1344           /* Fill in requested_reply variable with TRUE if this is a
1345            * reply and the reply was pending.
1346            */
1347           if (dbus_message_get_reply_serial (message) != 0)
1348             {
1349               if (proposed_recipient != NULL /* not to the bus driver */ &&
1350                   addressed_recipient == proposed_recipient /* not eavesdropping */)
1351                 {
1352                   DBusError error2;                  
1353                   
1354                   dbus_error_init (&error2);
1355                   requested_reply = bus_connections_check_reply (bus_connection_get_connections (sender),
1356                                                                  transaction,
1357                                                                  sender, addressed_recipient, message,
1358                                                                  &error2);
1359                   if (dbus_error_is_set (&error2))
1360                     {
1361                       dbus_move_error (&error2, error);
1362                       return FALSE;
1363                     }
1364                 }
1365             }
1366         }
1367       else
1368         {
1369           /* Policy for inactive connections is that they can only send
1370            * the hello message to the bus driver
1371            */
1372           if (proposed_recipient == NULL &&
1373               dbus_message_is_method_call (message,
1374                                            DBUS_INTERFACE_DBUS,
1375                                            "Hello"))
1376             {
1377               _dbus_verbose ("security check allowing %s message\n",
1378                              "Hello");
1379               return TRUE;
1380             }
1381           else
1382             {
1383               _dbus_verbose ("security check disallowing non-%s message\n",
1384                              "Hello");
1385
1386               dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1387                               "Client tried to send a message other than %s without being registered",
1388                               "Hello");
1389               
1390               return FALSE;
1391             }
1392         }
1393     }
1394   else
1395     {
1396       sender_policy = NULL;
1397
1398       /* If the sender is the bus driver, we assume any reply was a
1399        * requested reply as bus driver won't send bogus ones
1400        */
1401       if (addressed_recipient == proposed_recipient /* not eavesdropping */ &&
1402           dbus_message_get_reply_serial (message) != 0)
1403         requested_reply = TRUE;
1404     }
1405
1406   _dbus_assert ((sender != NULL && sender_policy != NULL) ||
1407                 (sender == NULL && sender_policy == NULL));
1408   
1409   if (proposed_recipient != NULL)
1410     {
1411       /* only the bus driver can send to an inactive recipient (as it
1412        * owns no services, so other apps can't address it). Inactive
1413        * recipients can receive any message.
1414        */
1415       if (bus_connection_is_active (proposed_recipient))
1416         {
1417           recipient_policy = bus_connection_get_policy (proposed_recipient);
1418           _dbus_assert (recipient_policy != NULL);
1419         }
1420       else if (sender == NULL)
1421         {
1422           _dbus_verbose ("security check using NULL recipient policy for message from bus\n");
1423           recipient_policy = NULL;
1424         }
1425       else
1426         {
1427           _dbus_assert_not_reached ("a message was somehow sent to an inactive recipient from a source other than the message bus\n");
1428           recipient_policy = NULL;
1429         }
1430     }
1431   else
1432     recipient_policy = NULL;
1433   
1434   _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) ||
1435                 (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) ||
1436                 (proposed_recipient == NULL && recipient_policy == NULL));
1437   
1438   log = FALSE;
1439   if (sender_policy &&
1440       !bus_client_policy_check_can_send (sender_policy,
1441                                          context->registry,
1442                                          requested_reply,
1443                                          proposed_recipient,
1444                                          message, &toggles, &log))
1445     {
1446       const char *msg = "Rejected send message, %d matched rules; "
1447                         "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))";
1448
1449       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, msg,
1450                       toggles,
1451                       dbus_message_type_to_string (dbus_message_get_type (message)),
1452                       sender_name ? sender_name : "(unset)",
1453                       sender_loginfo,
1454                       dbus_message_get_interface (message) ?
1455                       dbus_message_get_interface (message) : "(unset)",
1456                       dbus_message_get_member (message) ?
1457                       dbus_message_get_member (message) : "(unset)",
1458                       dbus_message_get_error_name (message) ?
1459                       dbus_message_get_error_name (message) : "(unset)",
1460                       requested_reply,
1461                       dest ? dest : DBUS_SERVICE_DBUS,
1462                       proposed_recipient_loginfo);
1463       /* Needs to be duplicated to avoid calling malloc and having to handle OOM */
1464       if (addressed_recipient == proposed_recipient)
1465         bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
1466                                   toggles,
1467                                   dbus_message_type_to_string (dbus_message_get_type (message)),
1468                                   sender_name ? sender_name : "(unset)",
1469                                   sender_loginfo,
1470                                   dbus_message_get_interface (message) ?
1471                                   dbus_message_get_interface (message) : "(unset)",
1472                                   dbus_message_get_member (message) ?
1473                                   dbus_message_get_member (message) : "(unset)",
1474                                   dbus_message_get_error_name (message) ?
1475                                   dbus_message_get_error_name (message) : "(unset)",
1476                                   requested_reply,
1477                                   dest ? dest : DBUS_SERVICE_DBUS,
1478                                   proposed_recipient_loginfo);
1479       _dbus_verbose ("security policy disallowing message due to sender policy\n");
1480       return FALSE;
1481     }
1482
1483   if (log)
1484     bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY,
1485                               "Would reject message, %d matched rules; "
1486                               "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))",
1487                               toggles,
1488                               dbus_message_type_to_string (dbus_message_get_type (message)),
1489                               sender_name ? sender_name : "(unset)",
1490                               sender_loginfo,
1491                               dbus_message_get_interface (message) ?
1492                               dbus_message_get_interface (message) : "(unset)",
1493                               dbus_message_get_member (message) ?
1494                               dbus_message_get_member (message) : "(unset)",
1495                               dbus_message_get_error_name (message) ?
1496                               dbus_message_get_error_name (message) : "(unset)",
1497                               requested_reply,                               
1498                               dest ? dest : DBUS_SERVICE_DBUS,
1499                               proposed_recipient_loginfo);
1500
1501   if (recipient_policy &&
1502       !bus_client_policy_check_can_receive (recipient_policy,
1503                                             context->registry,
1504                                             requested_reply,
1505                                             sender,
1506                                             addressed_recipient, proposed_recipient,
1507                                             message, &toggles))
1508     {
1509       const char *msg = "Rejected receive message, %d matched rules; "
1510                         "type=\"%s\" sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" reply serial=%u requested_reply=%d destination=\"%s\" (%s))";
1511
1512       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, msg,
1513                       toggles,
1514                       dbus_message_type_to_string (dbus_message_get_type (message)),
1515                       sender_name ? sender_name : "(unset)",
1516                       sender_loginfo,
1517                       dbus_message_get_interface (message) ?
1518                       dbus_message_get_interface (message) : "(unset)",
1519                       dbus_message_get_member (message) ?
1520                       dbus_message_get_member (message) : "(unset)",
1521                       dbus_message_get_error_name (message) ?
1522                       dbus_message_get_error_name (message) : "(unset)",
1523                       dbus_message_get_reply_serial (message),
1524                       requested_reply,
1525                       dest ? dest : DBUS_SERVICE_DBUS,
1526                       proposed_recipient_loginfo);
1527       /* Needs to be duplicated to avoid calling malloc and having to handle OOM */
1528       if (addressed_recipient == proposed_recipient)
1529         bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
1530                                   toggles,
1531                                   dbus_message_type_to_string (dbus_message_get_type (message)),
1532                                   sender_name ? sender_name : "(unset)",
1533                                   sender_loginfo,
1534                                   dbus_message_get_interface (message) ?
1535                                   dbus_message_get_interface (message) : "(unset)",
1536                                   dbus_message_get_member (message) ?
1537                                   dbus_message_get_member (message) : "(unset)",
1538                                   dbus_message_get_error_name (message) ?
1539                                   dbus_message_get_error_name (message) : "(unset)",
1540                                   dbus_message_get_reply_serial (message),
1541                                   requested_reply,
1542                                   dest ? dest : DBUS_SERVICE_DBUS,
1543                                   proposed_recipient_loginfo);
1544       _dbus_verbose ("security policy disallowing message due to recipient policy\n");
1545       return FALSE;
1546     }
1547
1548   /* See if limits on size have been exceeded */
1549   if (proposed_recipient &&
1550       ((dbus_connection_get_outgoing_size (proposed_recipient) > context->limits.max_outgoing_bytes) ||
1551        (dbus_connection_get_outgoing_unix_fds (proposed_recipient) > context->limits.max_outgoing_unix_fds)))
1552     {
1553       dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1554                       "The destination service \"%s\" has a full message queue",
1555                       dest ? dest : (proposed_recipient ?
1556                                      bus_connection_get_name (proposed_recipient) : 
1557                                      DBUS_SERVICE_DBUS));
1558       _dbus_verbose ("security policy disallowing message due to full message queue\n");
1559       return FALSE;
1560     }
1561
1562   /* Record that we will allow a reply here in the future (don't
1563    * bother if the recipient is the bus or this is an eavesdropping
1564    * connection). Only the addressed recipient may reply.
1565    */
1566   if (type == DBUS_MESSAGE_TYPE_METHOD_CALL &&
1567       sender && 
1568       addressed_recipient &&
1569       addressed_recipient == proposed_recipient && /* not eavesdropping */
1570       !bus_connections_expect_reply (bus_connection_get_connections (sender),
1571                                      transaction,
1572                                      sender, addressed_recipient,
1573                                      message, error))
1574     {
1575       _dbus_verbose ("Failed to record reply expectation or problem with the message expecting a reply\n");
1576       return FALSE;
1577     }
1578   
1579   _dbus_verbose ("security policy allowing message\n");
1580   return TRUE;
1581 }