2003-04-24 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / bus / bus.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* bus.c  message bus context object
3  *
4  * Copyright (C) 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include "bus.h"
25 #include "activation.h"
26 #include "connection.h"
27 #include "services.h"
28 #include "utils.h"
29 #include "policy.h"
30 #include "config-parser.h"
31 #include <dbus/dbus-list.h>
32 #include <dbus/dbus-hash.h>
33 #include <dbus/dbus-internals.h>
34
35 struct BusContext
36 {
37   int refcount;
38   char *type;
39   char *address;
40   char *pidfile;
41   DBusLoop *loop;
42   DBusList *servers;
43   BusConnections *connections;
44   BusActivation *activation;
45   BusRegistry *registry;
46   BusPolicy *policy;
47   DBusUserDatabase *user_database;
48   long max_incoming_bytes;          /**< How many incoming messages for a connection */
49   long max_outgoing_bytes;          /**< How many outgoing bytes can be queued for a connection */
50   long max_message_size;            /**< Max size of a single message in bytes */
51   int activation_timeout;           /**< How long to wait for an activation to time out */
52   int auth_timeout;                 /**< How long to wait for an authentication to time out */
53   int max_completed_connections;    /**< Max number of authorized connections */
54   int max_incomplete_connections;   /**< Max number of incomplete connections */
55   int max_connections_per_user;     /**< Max number of connections auth'd as same user */
56 };
57
58 static int server_data_slot = -1;
59 static int server_data_slot_refcount = 0;
60
61 typedef struct
62 {
63   BusContext *context;
64 } BusServerData;
65
66 #define BUS_SERVER_DATA(server) (dbus_server_get_data ((server), server_data_slot))
67
68 static dbus_bool_t
69 server_data_slot_ref (void)
70 {
71   if (server_data_slot < 0)
72     {
73       server_data_slot = dbus_server_allocate_data_slot ();
74       
75       if (server_data_slot < 0)
76         return FALSE;
77
78       _dbus_assert (server_data_slot_refcount == 0);
79     }  
80
81   server_data_slot_refcount += 1;
82
83   return TRUE;
84 }
85
86 static void
87 server_data_slot_unref (void)
88 {
89   _dbus_assert (server_data_slot_refcount > 0);
90
91   server_data_slot_refcount -= 1;
92   
93   if (server_data_slot_refcount == 0)
94     {
95       dbus_server_free_data_slot (server_data_slot);
96       server_data_slot = -1;
97     }
98 }
99
100 static BusContext*
101 server_get_context (DBusServer *server)
102 {
103   BusContext *context;
104   BusServerData *bd;
105   
106   if (!server_data_slot_ref ())
107     return NULL;
108
109   bd = BUS_SERVER_DATA (server);
110   if (bd == NULL)
111     {
112       server_data_slot_unref ();
113       return NULL;
114     }
115
116   context = bd->context;
117
118   server_data_slot_unref ();
119
120   return context;
121 }
122
123 static dbus_bool_t
124 server_watch_callback (DBusWatch     *watch,
125                        unsigned int   condition,
126                        void          *data)
127 {
128   /* FIXME this can be done in dbus-mainloop.c
129    * if the code in activation.c for the babysitter
130    * watch handler is fixed.
131    */
132   
133   return dbus_watch_handle (watch, condition);
134 }
135
136 static dbus_bool_t
137 add_server_watch (DBusWatch  *watch,
138                   void       *data)
139 {
140   DBusServer *server = data;
141   BusContext *context;
142   
143   context = server_get_context (server);
144   
145   return _dbus_loop_add_watch (context->loop,
146                                watch, server_watch_callback, server,
147                                NULL);
148 }
149
150 static void
151 remove_server_watch (DBusWatch  *watch,
152                      void       *data)
153 {
154   DBusServer *server = data;
155   BusContext *context;
156   
157   context = server_get_context (server);
158   
159   _dbus_loop_remove_watch (context->loop,
160                            watch, server_watch_callback, server);
161 }
162
163
164 static void
165 server_timeout_callback (DBusTimeout   *timeout,
166                          void          *data)
167 {
168   /* can return FALSE on OOM but we just let it fire again later */
169   dbus_timeout_handle (timeout);
170 }
171
172 static dbus_bool_t
173 add_server_timeout (DBusTimeout *timeout,
174                     void        *data)
175 {
176   DBusServer *server = data;
177   BusContext *context;
178   
179   context = server_get_context (server);
180
181   return _dbus_loop_add_timeout (context->loop,
182                                  timeout, server_timeout_callback, server, NULL);
183 }
184
185 static void
186 remove_server_timeout (DBusTimeout *timeout,
187                        void        *data)
188 {
189   DBusServer *server = data;
190   BusContext *context;
191   
192   context = server_get_context (server);
193   
194   _dbus_loop_remove_timeout (context->loop,
195                              timeout, server_timeout_callback, server);
196 }
197
198 static void
199 new_connection_callback (DBusServer     *server,
200                          DBusConnection *new_connection,
201                          void           *data)
202 {
203   BusContext *context = data;
204   
205   if (!bus_connections_setup_connection (context->connections, new_connection))
206     {
207       _dbus_verbose ("No memory to setup new connection\n");
208
209       /* if we don't do this, it will get unref'd without
210        * being disconnected... kind of strange really
211        * that we have to do this, people won't get it right
212        * in general.
213        */
214       dbus_connection_disconnect (new_connection);
215     }
216
217   dbus_connection_set_max_received_size (new_connection,
218                                          context->max_incoming_bytes);
219
220   dbus_connection_set_max_message_size (new_connection,
221                                         context->max_message_size);
222   
223   /* on OOM, we won't have ref'd the connection so it will die. */
224 }
225
226 static void
227 free_server_data (void *data)
228 {
229   BusServerData *bd = data;  
230   
231   dbus_free (bd);
232 }
233
234 static dbus_bool_t
235 setup_server (BusContext *context,
236               DBusServer *server,
237               char      **auth_mechanisms,
238               DBusError  *error)
239 {
240   BusServerData *bd;
241
242   bd = dbus_new0 (BusServerData, 1);
243   if (!dbus_server_set_data (server,
244                              server_data_slot,
245                              bd, free_server_data))
246     {
247       dbus_free (bd);
248       BUS_SET_OOM (error);
249       return FALSE;
250     }
251
252   bd->context = context;
253   
254   if (!dbus_server_set_auth_mechanisms (server, (const char**) auth_mechanisms))
255     {
256       BUS_SET_OOM (error);
257       return FALSE;
258     }
259   
260   dbus_server_set_new_connection_function (server,
261                                            new_connection_callback,
262                                            context, NULL);
263   
264   if (!dbus_server_set_watch_functions (server,
265                                         add_server_watch,
266                                         remove_server_watch,
267                                         NULL,
268                                         server,
269                                         NULL))
270     {
271       BUS_SET_OOM (error);
272       return FALSE;
273     }
274
275   if (!dbus_server_set_timeout_functions (server,
276                                           add_server_timeout,
277                                           remove_server_timeout,
278                                           NULL,
279                                           server, NULL))
280     {
281       BUS_SET_OOM (error);
282       return FALSE;
283     }
284   
285   return TRUE;
286 }
287
288 BusContext*
289 bus_context_new (const DBusString *config_file,
290                  int               print_addr_fd,
291                  DBusError        *error)
292 {
293   BusContext *context;
294   DBusList *link;
295   DBusList **addresses;
296   BusConfigParser *parser;
297   DBusString full_address;
298   const char *user, *pidfile;
299   char **auth_mechanisms;
300   DBusList **auth_mechanisms_list;
301   int len;
302   
303   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
304
305   if (!_dbus_string_init (&full_address))
306     {
307       BUS_SET_OOM (error);
308       return NULL;
309     }
310
311   if (!server_data_slot_ref ())
312     {
313       BUS_SET_OOM (error);
314       _dbus_string_free (&full_address);
315       return NULL;
316     }
317   
318   parser = NULL;
319   context = NULL;
320   auth_mechanisms = NULL;
321   
322   parser = bus_config_load (config_file, error);
323   if (parser == NULL)
324     goto failed;
325
326   /* Check for an existing pid file. Of course this is a race;
327    * we'd have to use fcntl() locks on the pid file to
328    * avoid that. But we want to check for the pid file
329    * before overwriting any existing sockets, etc.
330    */
331   pidfile = bus_config_parser_get_pidfile (parser);
332   if (pidfile != NULL)
333     {
334       DBusString u;
335       DBusStat stbuf;
336       DBusError tmp_error;
337       
338       dbus_error_init (&tmp_error);
339       _dbus_string_init_const (&u, pidfile);
340       
341       if (_dbus_stat (&u, &stbuf, &tmp_error))
342         {
343           dbus_set_error (error, DBUS_ERROR_FAILED,
344                           "The pid file \"%s\" exists, if the message bus is not running, remove this file",
345                           pidfile);
346           dbus_error_free (&tmp_error);
347           goto failed;
348         }
349     }
350   
351   context = dbus_new0 (BusContext, 1);
352   if (context == NULL)
353     {
354       BUS_SET_OOM (error);
355       goto failed;
356     }
357   
358   context->refcount = 1;
359
360   /* we need another ref of the server data slot for the context
361    * to own
362    */
363   if (!server_data_slot_ref ())
364     _dbus_assert_not_reached ("second ref of server data slot failed");
365
366   /* Make up some numbers! woot! */
367   context->max_incoming_bytes = _DBUS_ONE_MEGABYTE * 63;  
368   context->max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 63;
369   context->max_message_size = _DBUS_ONE_MEGABYTE * 32;
370   
371 #ifdef DBUS_BUILD_TESTS
372   context->activation_timeout = 6000;  /* 6 seconds */
373 #else
374   context->activation_timeout = 15000; /* 15 seconds */
375 #endif
376
377   /* Making this long risks making a DOS attack easier, but too short
378    * and legitimate auth will fail.  If interactive auth (ask user for
379    * password) is allowed, then potentially it has to be quite long.
380    * Ultimately it needs to come from the configuration file.
381    */     
382   context->auth_timeout = 3000; /* 3 seconds */
383
384   context->max_incomplete_connections = 32;
385   context->max_connections_per_user = 128;
386
387   /* Note that max_completed_connections / max_connections_per_user
388    * is the number of users that would have to work together to
389    * DOS all the other users.
390    */
391   context->max_completed_connections = 1024;
392   
393   context->user_database = _dbus_user_database_new ();
394   if (context->user_database == NULL)
395     {
396       BUS_SET_OOM (error);
397       goto failed;
398     }
399   
400   context->loop = _dbus_loop_new ();
401   if (context->loop == NULL)
402     {
403       BUS_SET_OOM (error);
404       goto failed;
405     }
406   
407   /* Build an array of auth mechanisms */
408   
409   auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
410   len = _dbus_list_get_length (auth_mechanisms_list);
411
412   if (len > 0)
413     {
414       int i;
415
416       auth_mechanisms = dbus_new0 (char*, len + 1);
417       if (auth_mechanisms == NULL)
418         goto failed;
419       
420       i = 0;
421       link = _dbus_list_get_first_link (auth_mechanisms_list);
422       while (link != NULL)
423         {
424           auth_mechanisms[i] = _dbus_strdup (link->data);
425           if (auth_mechanisms[i] == NULL)
426             goto failed;
427           link = _dbus_list_get_next_link (auth_mechanisms_list, link);
428         }
429     }
430   else
431     {
432       auth_mechanisms = NULL;
433     }
434
435   /* Listen on our addresses */
436   
437   addresses = bus_config_parser_get_addresses (parser);  
438   
439   link = _dbus_list_get_first_link (addresses);
440   while (link != NULL)
441     {
442       DBusServer *server;
443       
444       server = dbus_server_listen (link->data, error);
445       if (server == NULL)
446         goto failed;
447       else if (!setup_server (context, server, auth_mechanisms, error))
448         goto failed;
449
450       if (!_dbus_list_append (&context->servers, server))
451         {
452           BUS_SET_OOM (error);
453           goto failed;
454         }          
455       
456       link = _dbus_list_get_next_link (addresses, link);
457     }
458
459   /* note that type may be NULL */
460   context->type = _dbus_strdup (bus_config_parser_get_type (parser));
461   
462   /* We have to build the address backward, so that
463    * <listen> later in the config file have priority
464    */
465   link = _dbus_list_get_last_link (&context->servers);
466   while (link != NULL)
467     {
468       char *addr;
469       
470       addr = dbus_server_get_address (link->data);
471       if (addr == NULL)
472         {
473           BUS_SET_OOM (error);
474           goto failed;
475         }
476
477       if (_dbus_string_get_length (&full_address) > 0)
478         {
479           if (!_dbus_string_append (&full_address, ";"))
480             {
481               BUS_SET_OOM (error);
482               goto failed;
483             }
484         }
485
486       if (!_dbus_string_append (&full_address, addr))
487         {
488           BUS_SET_OOM (error);
489           goto failed;
490         }
491
492       dbus_free (addr);
493
494       link = _dbus_list_get_prev_link (&context->servers, link);
495     }
496
497   if (!_dbus_string_copy_data (&full_address, &context->address))
498     {
499       BUS_SET_OOM (error);
500       goto failed;
501     }
502
503   /* Note that we don't know whether the print_addr_fd is
504    * one of the sockets we're using to listen on, or some
505    * other random thing. But I think the answer is "don't do
506    * that then"
507    */
508   if (print_addr_fd >= 0)
509     {
510       DBusString addr;
511       const char *a = bus_context_get_address (context);
512       int bytes;
513       
514       _dbus_assert (a != NULL);
515       if (!_dbus_string_init (&addr))
516         {
517           BUS_SET_OOM (error);
518           goto failed;
519         }
520       
521       if (!_dbus_string_append (&addr, a) ||
522           !_dbus_string_append (&addr, "\n"))
523         {
524           _dbus_string_free (&addr);
525           BUS_SET_OOM (error);
526           goto failed;
527         }
528
529       bytes = _dbus_string_get_length (&addr);
530       if (_dbus_write (print_addr_fd, &addr, 0, bytes) != bytes)
531         {
532           dbus_set_error (error, DBUS_ERROR_FAILED,
533                           "Printing message bus address: %s\n",
534                           _dbus_strerror (errno));
535           _dbus_string_free (&addr);
536           goto failed;
537         }
538
539       if (print_addr_fd > 2)
540         _dbus_close (print_addr_fd, NULL);
541
542       _dbus_string_free (&addr);
543     }
544   
545   /* Create activation subsystem */
546   
547   context->activation = bus_activation_new (context, &full_address,
548                                             bus_config_parser_get_service_dirs (parser),
549                                             error);
550   if (context->activation == NULL)
551     {
552       _DBUS_ASSERT_ERROR_IS_SET (error);
553       goto failed;
554     }
555
556   context->connections = bus_connections_new (context);
557   if (context->connections == NULL)
558     {
559       BUS_SET_OOM (error);
560       goto failed;
561     }
562
563   context->registry = bus_registry_new (context);
564   if (context->registry == NULL)
565     {
566       BUS_SET_OOM (error);
567       goto failed;
568     }
569
570   context->policy = bus_config_parser_steal_policy (parser);
571   _dbus_assert (context->policy != NULL);
572   
573   /* Now become a daemon if appropriate */
574   if (bus_config_parser_get_fork (parser))
575     {
576       DBusString u;
577
578       if (pidfile)
579         _dbus_string_init_const (&u, pidfile);
580       
581       if (!_dbus_become_daemon (pidfile ? &u : NULL, error))
582         goto failed;
583     }
584   else
585     {
586       /* Need to write PID file for ourselves, not for the child process */
587       if (pidfile != NULL)
588         {
589           DBusString u;
590
591           _dbus_string_init_const (&u, pidfile);
592           
593           if (!_dbus_write_pid_file (&u, _dbus_getpid (), error))
594             goto failed;
595         }
596     }
597
598   /* keep around the pid filename so we can delete it later */
599   context->pidfile = _dbus_strdup (pidfile);
600
601   /* Here we change our credentials if required,
602    * as soon as we've set up our sockets and pidfile
603    */
604   user = bus_config_parser_get_user (parser);
605   if (user != NULL)
606     {
607       DBusCredentials creds;
608       DBusString u;
609
610       _dbus_string_init_const (&u, user);
611
612       if (!_dbus_credentials_from_username (&u, &creds) ||
613           creds.uid < 0 ||
614           creds.gid < 0)
615         {
616           dbus_set_error (error, DBUS_ERROR_FAILED,
617                           "Could not get UID and GID for username \"%s\"",
618                           user);
619           goto failed;
620         }
621       
622       if (!_dbus_change_identity (creds.uid, creds.gid, error))
623         goto failed;
624     }
625   
626   bus_config_parser_unref (parser);
627   _dbus_string_free (&full_address);
628   dbus_free_string_array (auth_mechanisms);
629   server_data_slot_unref ();
630   
631   return context;
632   
633  failed:  
634   if (parser != NULL)
635     bus_config_parser_unref (parser);
636
637   if (context != NULL)
638     bus_context_unref (context);
639
640   _dbus_string_free (&full_address);
641   dbus_free_string_array (auth_mechanisms);
642
643   server_data_slot_unref ();
644   
645   return NULL;
646 }
647
648 static void
649 shutdown_server (BusContext *context,
650                  DBusServer *server)
651 {
652   if (server == NULL ||
653       !dbus_server_get_is_connected (server))
654     return;
655   
656   if (!dbus_server_set_watch_functions (server,
657                                         NULL, NULL, NULL,
658                                         context,
659                                         NULL))
660     _dbus_assert_not_reached ("setting watch functions to NULL failed");
661   
662   if (!dbus_server_set_timeout_functions (server,
663                                           NULL, NULL, NULL,
664                                           context,
665                                           NULL))
666     _dbus_assert_not_reached ("setting timeout functions to NULL failed");
667   
668   dbus_server_disconnect (server);
669 }
670
671 void
672 bus_context_shutdown (BusContext  *context)
673 {
674   DBusList *link;
675
676   link = _dbus_list_get_first_link (&context->servers);
677   while (link != NULL)
678     {
679       shutdown_server (context, link->data);
680
681       link = _dbus_list_get_next_link (&context->servers, link);
682     }
683 }
684
685 void
686 bus_context_ref (BusContext *context)
687 {
688   _dbus_assert (context->refcount > 0);
689   context->refcount += 1;
690 }
691
692 void
693 bus_context_unref (BusContext *context)
694 {
695   _dbus_assert (context->refcount > 0);
696   context->refcount -= 1;
697
698   if (context->refcount == 0)
699     {
700       DBusList *link;
701       
702       _dbus_verbose ("Finalizing bus context %p\n", context);
703       
704       bus_context_shutdown (context);
705
706       if (context->connections)
707         {
708           bus_connections_unref (context->connections);
709           context->connections = NULL;
710         }
711       
712       if (context->registry)
713         {
714           bus_registry_unref (context->registry);
715           context->registry = NULL;
716         }
717       
718       if (context->activation)
719         {
720           bus_activation_unref (context->activation);
721           context->activation = NULL;
722         }
723
724       link = _dbus_list_get_first_link (&context->servers);
725       while (link != NULL)
726         {
727           dbus_server_unref (link->data);
728           
729           link = _dbus_list_get_next_link (&context->servers, link);
730         }
731       _dbus_list_clear (&context->servers);
732
733       if (context->policy)
734         {
735           bus_policy_unref (context->policy);
736           context->policy = NULL;
737         }
738       
739       if (context->loop)
740         {
741           _dbus_loop_unref (context->loop);
742           context->loop = NULL;
743         }
744       
745       dbus_free (context->type);
746       dbus_free (context->address);
747
748       if (context->pidfile)
749         {
750           DBusString u;
751           _dbus_string_init_const (&u, context->pidfile);
752
753           /* Deliberately ignore errors here, since there's not much
754            * we can do about it, and we're exiting anyways.
755            */
756           _dbus_delete_file (&u, NULL);
757
758           dbus_free (context->pidfile); 
759         }
760
761       _dbus_user_database_unref (context->user_database);
762       
763       dbus_free (context);
764
765       server_data_slot_unref ();
766     }
767 }
768
769 /* type may be NULL */
770 const char*
771 bus_context_get_type (BusContext *context)
772 {
773   return context->type;
774 }
775
776 const char*
777 bus_context_get_address (BusContext *context)
778 {
779   return context->address;
780 }
781
782 BusRegistry*
783 bus_context_get_registry (BusContext  *context)
784 {
785   return context->registry;
786 }
787
788 BusConnections*
789 bus_context_get_connections (BusContext  *context)
790 {
791   return context->connections;
792 }
793
794 BusActivation*
795 bus_context_get_activation (BusContext  *context)
796 {
797   return context->activation;
798 }
799
800 DBusLoop*
801 bus_context_get_loop (BusContext *context)
802 {
803   return context->loop;
804 }
805
806 DBusUserDatabase*
807 bus_context_get_user_database (BusContext *context)
808 {
809   return context->user_database;
810 }
811
812 dbus_bool_t
813 bus_context_allow_user (BusContext   *context,
814                         unsigned long uid)
815 {
816   return bus_policy_allow_user (context->policy,
817                                 context->user_database,
818                                 uid);
819 }
820
821 BusClientPolicy*
822 bus_context_create_client_policy (BusContext      *context,
823                                   DBusConnection  *connection)
824 {
825   return bus_policy_create_client_policy (context->policy, connection);
826 }
827
828 int
829 bus_context_get_activation_timeout (BusContext *context)
830 {
831   
832   return context->activation_timeout;
833 }
834
835 int
836 bus_context_get_auth_timeout (BusContext *context)
837 {
838   return context->auth_timeout;
839 }
840
841 int
842 bus_context_get_max_completed_connections (BusContext *context)
843 {
844   return context->max_completed_connections;
845 }
846
847 int
848 bus_context_get_max_incomplete_connections (BusContext *context)
849 {
850   return context->max_incomplete_connections;
851 }
852
853 int
854 bus_context_get_max_connections_per_user (BusContext *context)
855 {
856   return context->max_connections_per_user;
857 }
858
859 dbus_bool_t
860 bus_context_check_security_policy (BusContext     *context,
861                                    DBusConnection *sender,
862                                    DBusConnection *recipient,
863                                    DBusMessage    *message,
864                                    DBusError      *error)
865 {
866   BusClientPolicy *sender_policy;
867   BusClientPolicy *recipient_policy;
868
869   /* NULL sender/receiver means the bus driver */
870   
871   if (sender != NULL)
872     {
873       _dbus_assert (dbus_connection_get_is_authenticated (sender));
874       sender_policy = bus_connection_get_policy (sender);
875     }
876   else
877     sender_policy = NULL;
878
879   if (recipient != NULL)
880     {
881       _dbus_assert (dbus_connection_get_is_authenticated (recipient));
882       recipient_policy = bus_connection_get_policy (recipient);
883     }
884   else
885     recipient_policy = NULL;
886
887   if (sender_policy &&
888       !bus_client_policy_check_can_send (sender_policy,
889                                          context->registry, recipient,
890                                          message))
891     {
892       const char *dest = dbus_message_get_destination (message);
893       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
894                       "A security policy in place prevents this sender "
895                       "from sending this message to this recipient, "
896                       "see message bus configuration file (rejected message "
897                       "had name \"%s\" destination \"%s\")",
898                       dbus_message_get_name (message),
899                       dest ? dest : DBUS_SERVICE_DBUS);
900       return FALSE;
901     }
902
903   if (recipient_policy &&
904       !bus_client_policy_check_can_receive (recipient_policy,
905                                             context->registry, sender,
906                                             message))
907     {
908       const char *dest = dbus_message_get_destination (message);
909       dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
910                       "A security policy in place prevents this recipient "
911                       "from receiving this message from this sender, "
912                       "see message bus configuration file (rejected message "
913                       "had name \"%s\" destination \"%s\")",
914                       dbus_message_get_name (message),
915                       dest ? dest : DBUS_SERVICE_DBUS);
916       return FALSE;
917     }
918
919   /* See if limits on size have been exceeded */
920   if (recipient &&
921       dbus_connection_get_outgoing_size (recipient) >
922       context->max_outgoing_bytes)
923     {
924       const char *dest = dbus_message_get_destination (message);
925       dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
926                       "The destination service \"%s\" has a full message queue",
927                       dest ? dest : DBUS_SERVICE_DBUS);
928       return FALSE;
929     }
930   
931   return TRUE;
932 }