1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* bus.c message bus context object
4 * Copyright (C) 2003, 2004 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
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.
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.
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
25 #include "activation.h"
26 #include "connection.h"
30 #include "config-parser.h"
33 #include "dir-watch.h"
34 #include <dbus/dbus-list.h>
35 #include <dbus/dbus-hash.h>
36 #include <dbus/dbus-internals.h>
48 BusConnections *connections;
49 BusActivation *activation;
50 BusRegistry *registry;
52 BusMatchmaker *matchmaker;
53 DBusUserDatabase *user_database;
55 unsigned int fork : 1;
58 static dbus_int32_t server_data_slot = -1;
65 #define BUS_SERVER_DATA(server) (dbus_server_get_data ((server), server_data_slot))
68 server_get_context (DBusServer *server)
73 if (!dbus_server_allocate_data_slot (&server_data_slot))
76 bd = BUS_SERVER_DATA (server);
79 dbus_server_free_data_slot (&server_data_slot);
83 context = bd->context;
85 dbus_server_free_data_slot (&server_data_slot);
91 server_watch_callback (DBusWatch *watch,
92 unsigned int condition,
95 /* FIXME this can be done in dbus-mainloop.c
96 * if the code in activation.c for the babysitter
97 * watch handler is fixed.
100 return dbus_watch_handle (watch, condition);
104 add_server_watch (DBusWatch *watch,
107 DBusServer *server = data;
110 context = server_get_context (server);
112 return _dbus_loop_add_watch (context->loop,
113 watch, server_watch_callback, server,
118 remove_server_watch (DBusWatch *watch,
121 DBusServer *server = data;
124 context = server_get_context (server);
126 _dbus_loop_remove_watch (context->loop,
127 watch, server_watch_callback, server);
132 server_timeout_callback (DBusTimeout *timeout,
135 /* can return FALSE on OOM but we just let it fire again later */
136 dbus_timeout_handle (timeout);
140 add_server_timeout (DBusTimeout *timeout,
143 DBusServer *server = data;
146 context = server_get_context (server);
148 return _dbus_loop_add_timeout (context->loop,
149 timeout, server_timeout_callback, server, NULL);
153 remove_server_timeout (DBusTimeout *timeout,
156 DBusServer *server = data;
159 context = server_get_context (server);
161 _dbus_loop_remove_timeout (context->loop,
162 timeout, server_timeout_callback, server);
166 new_connection_callback (DBusServer *server,
167 DBusConnection *new_connection,
170 BusContext *context = data;
172 if (!bus_connections_setup_connection (context->connections, new_connection))
174 _dbus_verbose ("No memory to setup new connection\n");
176 /* if we don't do this, it will get unref'd without
177 * being disconnected... kind of strange really
178 * that we have to do this, people won't get it right
181 dbus_connection_close (new_connection);
184 dbus_connection_set_max_received_size (new_connection,
185 context->limits.max_incoming_bytes);
187 dbus_connection_set_max_message_size (new_connection,
188 context->limits.max_message_size);
190 /* on OOM, we won't have ref'd the connection so it will die. */
194 free_server_data (void *data)
196 BusServerData *bd = data;
202 setup_server (BusContext *context,
204 char **auth_mechanisms,
209 bd = dbus_new0 (BusServerData, 1);
210 if (!dbus_server_set_data (server,
212 bd, free_server_data))
219 bd->context = context;
221 if (!dbus_server_set_auth_mechanisms (server, (const char**) auth_mechanisms))
227 dbus_server_set_new_connection_function (server,
228 new_connection_callback,
231 if (!dbus_server_set_watch_functions (server,
242 if (!dbus_server_set_timeout_functions (server,
244 remove_server_timeout,
255 /* This code only gets executed the first time the
256 config files are parsed. It is not executed
257 when config files are reloaded.*/
259 process_config_first_time_only (BusContext *context,
260 BusConfigParser *parser,
264 DBusList **addresses;
265 const char *user, *pidfile;
266 char **auth_mechanisms;
267 DBusList **auth_mechanisms_list;
271 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
274 auth_mechanisms = NULL;
276 /* Check for an existing pid file. Of course this is a race;
277 * we'd have to use fcntl() locks on the pid file to
278 * avoid that. But we want to check for the pid file
279 * before overwriting any existing sockets, etc.
281 pidfile = bus_config_parser_get_pidfile (parser);
287 _dbus_string_init_const (&u, pidfile);
289 if (_dbus_stat (&u, &stbuf, NULL))
291 dbus_set_error (error, DBUS_ERROR_FAILED,
292 "The pid file \"%s\" exists, if the message bus is not running, remove this file",
298 /* keep around the pid filename so we can delete it later */
299 context->pidfile = _dbus_strdup (pidfile);
301 /* Build an array of auth mechanisms */
303 auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
304 len = _dbus_list_get_length (auth_mechanisms_list);
310 auth_mechanisms = dbus_new0 (char*, len + 1);
311 if (auth_mechanisms == NULL)
318 link = _dbus_list_get_first_link (auth_mechanisms_list);
321 auth_mechanisms[i] = _dbus_strdup (link->data);
322 if (auth_mechanisms[i] == NULL)
327 link = _dbus_list_get_next_link (auth_mechanisms_list, link);
332 auth_mechanisms = NULL;
335 /* Listen on our addresses */
337 addresses = bus_config_parser_get_addresses (parser);
339 link = _dbus_list_get_first_link (addresses);
344 server = dbus_server_listen (link->data, error);
347 _DBUS_ASSERT_ERROR_IS_SET (error);
350 else if (!setup_server (context, server, auth_mechanisms, error))
352 _DBUS_ASSERT_ERROR_IS_SET (error);
356 if (!_dbus_list_append (&context->servers, server))
362 link = _dbus_list_get_next_link (addresses, link);
365 /* note that type may be NULL */
366 context->type = _dbus_strdup (bus_config_parser_get_type (parser));
367 if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
373 user = bus_config_parser_get_user (parser);
376 context->user = _dbus_strdup (user);
377 if (context->user == NULL)
384 context->fork = bus_config_parser_get_fork (parser);
386 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
390 dbus_free_string_array (auth_mechanisms);
394 /* This code gets executed every time the config files
395 are parsed: both during BusContext construction
398 process_config_every_time (BusContext *context,
399 BusConfigParser *parser,
400 dbus_bool_t is_reload,
403 DBusString full_address;
408 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
412 if (!_dbus_string_init (&full_address))
418 /* get our limits and timeout lengths */
419 bus_config_parser_get_limits (parser, &context->limits);
421 context->policy = bus_config_parser_steal_policy (parser);
422 _dbus_assert (context->policy != NULL);
424 /* We have to build the address backward, so that
425 * <listen> later in the config file have priority
427 link = _dbus_list_get_last_link (&context->servers);
432 addr = dbus_server_get_address (link->data);
439 if (_dbus_string_get_length (&full_address) > 0)
441 if (!_dbus_string_append (&full_address, ";"))
448 if (!_dbus_string_append (&full_address, addr))
456 link = _dbus_list_get_prev_link (&context->servers, link);
460 dbus_free (context->address);
462 if (!_dbus_string_copy_data (&full_address, &context->address))
468 /* Create activation subsystem */
471 bus_activation_unref (context->activation);
473 context->activation = bus_activation_new (context, &full_address,
474 bus_config_parser_get_service_dirs (parser),
476 if (context->activation == NULL)
478 _DBUS_ASSERT_ERROR_IS_SET (error);
482 /* Drop existing conf-dir watches (if applicable) and watch all conf directories */
485 bus_drop_all_directory_watches ();
487 _dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
488 (DBusForeachFunction) bus_watch_directory,
491 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
495 _dbus_string_free (&full_address);
500 process_config_postinit (BusContext *context,
501 BusConfigParser *parser,
504 DBusHashTable *service_context_table;
506 service_context_table = bus_config_parser_steal_service_context_table (parser);
507 if (!bus_registry_set_service_context_table (context->registry,
508 service_context_table))
514 _dbus_hash_table_unref (service_context_table);
519 bus_context_new (const DBusString *config_file,
520 ForceForkSetting force_fork,
526 BusConfigParser *parser;
528 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
533 if (!dbus_server_allocate_data_slot (&server_data_slot))
539 context = dbus_new0 (BusContext, 1);
545 context->refcount = 1;
547 if (!_dbus_string_copy_data (config_file, &context->config_file))
553 context->loop = _dbus_loop_new ();
554 if (context->loop == NULL)
560 context->registry = bus_registry_new (context);
561 if (context->registry == NULL)
567 parser = bus_config_load (config_file, TRUE, NULL, error);
570 _DBUS_ASSERT_ERROR_IS_SET (error);
574 if (!process_config_first_time_only (context, parser, error))
576 _DBUS_ASSERT_ERROR_IS_SET (error);
579 if (!process_config_every_time (context, parser, FALSE, error))
581 _DBUS_ASSERT_ERROR_IS_SET (error);
585 /* we need another ref of the server data slot for the context
588 if (!dbus_server_allocate_data_slot (&server_data_slot))
589 _dbus_assert_not_reached ("second ref of server data slot failed");
591 context->user_database = _dbus_user_database_new ();
592 if (context->user_database == NULL)
598 /* Note that we don't know whether the print_addr_fd is
599 * one of the sockets we're using to listen on, or some
600 * other random thing. But I think the answer is "don't do
603 if (print_addr_fd >= 0)
606 const char *a = bus_context_get_address (context);
609 _dbus_assert (a != NULL);
610 if (!_dbus_string_init (&addr))
616 if (!_dbus_string_append (&addr, a) ||
617 !_dbus_string_append (&addr, "\n"))
619 _dbus_string_free (&addr);
624 bytes = _dbus_string_get_length (&addr);
625 if (_dbus_write (print_addr_fd, &addr, 0, bytes) != bytes)
627 dbus_set_error (error, DBUS_ERROR_FAILED,
628 "Printing message bus address: %s\n",
629 _dbus_strerror (errno));
630 _dbus_string_free (&addr);
634 if (print_addr_fd > 2)
635 _dbus_close (print_addr_fd, NULL);
637 _dbus_string_free (&addr);
640 context->connections = bus_connections_new (context);
641 if (context->connections == NULL)
647 context->matchmaker = bus_matchmaker_new ();
648 if (context->matchmaker == NULL)
654 /* Now become a daemon if appropriate */
655 if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
659 if (context->pidfile)
660 _dbus_string_init_const (&u, context->pidfile);
662 if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
666 _DBUS_ASSERT_ERROR_IS_SET (error);
672 /* Need to write PID file for ourselves, not for the child process */
673 if (context->pidfile != NULL)
677 _dbus_string_init_const (&u, context->pidfile);
679 if (!_dbus_write_pid_file (&u, _dbus_getpid (), error))
681 _DBUS_ASSERT_ERROR_IS_SET (error);
687 /* Write PID if requested */
688 if (print_pid_fd >= 0)
693 if (!_dbus_string_init (&pid))
699 if (!_dbus_string_append_int (&pid, _dbus_getpid ()) ||
700 !_dbus_string_append (&pid, "\n"))
702 _dbus_string_free (&pid);
707 bytes = _dbus_string_get_length (&pid);
708 if (_dbus_write (print_pid_fd, &pid, 0, bytes) != bytes)
710 dbus_set_error (error, DBUS_ERROR_FAILED,
711 "Printing message bus PID: %s\n",
712 _dbus_strerror (errno));
713 _dbus_string_free (&pid);
717 if (print_pid_fd > 2)
718 _dbus_close (print_pid_fd, NULL);
720 _dbus_string_free (&pid);
723 if (!bus_selinux_full_init ())
725 _dbus_warn ("SELinux initialization failed\n");
728 if (!process_config_postinit (context, parser, error))
730 _DBUS_ASSERT_ERROR_IS_SET (error);
735 bus_config_parser_unref (parser);
737 /* Here we change our credentials if required,
738 * as soon as we've set up our sockets and pidfile
740 if (context->user != NULL)
742 DBusCredentials creds;
745 _dbus_string_init_const (&u, context->user);
747 if (!_dbus_credentials_from_username (&u, &creds) ||
751 dbus_set_error (error, DBUS_ERROR_FAILED,
752 "Could not get UID and GID for username \"%s\"",
757 if (!_dbus_change_identity (creds.uid, creds.gid, error))
759 _DBUS_ASSERT_ERROR_IS_SET (error);
764 dbus_server_free_data_slot (&server_data_slot);
770 bus_config_parser_unref (parser);
772 bus_context_unref (context);
774 if (server_data_slot >= 0)
775 dbus_server_free_data_slot (&server_data_slot);
781 bus_context_reload_config (BusContext *context,
784 BusConfigParser *parser;
785 DBusString config_file;
789 _dbus_string_init_const (&config_file, context->config_file);
790 parser = bus_config_load (&config_file, TRUE, NULL, error);
793 _DBUS_ASSERT_ERROR_IS_SET (error);
797 if (!process_config_every_time (context, parser, TRUE, error))
799 _DBUS_ASSERT_ERROR_IS_SET (error);
802 if (!process_config_postinit (context, parser, error))
804 _DBUS_ASSERT_ERROR_IS_SET (error);
811 bus_config_parser_unref (parser);
816 shutdown_server (BusContext *context,
819 if (server == NULL ||
820 !dbus_server_get_is_connected (server))
823 if (!dbus_server_set_watch_functions (server,
827 _dbus_assert_not_reached ("setting watch functions to NULL failed");
829 if (!dbus_server_set_timeout_functions (server,
833 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
835 dbus_server_disconnect (server);
839 bus_context_shutdown (BusContext *context)
843 link = _dbus_list_get_first_link (&context->servers);
846 shutdown_server (context, link->data);
848 link = _dbus_list_get_next_link (&context->servers, link);
853 bus_context_ref (BusContext *context)
855 _dbus_assert (context->refcount > 0);
856 context->refcount += 1;
862 bus_context_unref (BusContext *context)
864 _dbus_assert (context->refcount > 0);
865 context->refcount -= 1;
867 if (context->refcount == 0)
871 _dbus_verbose ("Finalizing bus context %p\n", context);
873 bus_context_shutdown (context);
875 if (context->connections)
877 bus_connections_unref (context->connections);
878 context->connections = NULL;
881 if (context->registry)
883 bus_registry_unref (context->registry);
884 context->registry = NULL;
887 if (context->activation)
889 bus_activation_unref (context->activation);
890 context->activation = NULL;
893 link = _dbus_list_get_first_link (&context->servers);
896 dbus_server_unref (link->data);
898 link = _dbus_list_get_next_link (&context->servers, link);
900 _dbus_list_clear (&context->servers);
904 bus_policy_unref (context->policy);
905 context->policy = NULL;
910 _dbus_loop_unref (context->loop);
911 context->loop = NULL;
914 if (context->matchmaker)
916 bus_matchmaker_unref (context->matchmaker);
917 context->matchmaker = NULL;
920 dbus_free (context->config_file);
921 dbus_free (context->type);
922 dbus_free (context->address);
923 dbus_free (context->user);
925 if (context->pidfile)
928 _dbus_string_init_const (&u, context->pidfile);
930 /* Deliberately ignore errors here, since there's not much
931 * we can do about it, and we're exiting anyways.
933 _dbus_delete_file (&u, NULL);
935 dbus_free (context->pidfile);
938 if (context->user_database != NULL)
939 _dbus_user_database_unref (context->user_database);
943 dbus_server_free_data_slot (&server_data_slot);
947 /* type may be NULL */
949 bus_context_get_type (BusContext *context)
951 return context->type;
955 bus_context_get_address (BusContext *context)
957 return context->address;
961 bus_context_get_registry (BusContext *context)
963 return context->registry;
967 bus_context_get_connections (BusContext *context)
969 return context->connections;
973 bus_context_get_activation (BusContext *context)
975 return context->activation;
979 bus_context_get_matchmaker (BusContext *context)
981 return context->matchmaker;
985 bus_context_get_loop (BusContext *context)
987 return context->loop;
991 bus_context_get_user_database (BusContext *context)
993 return context->user_database;
997 bus_context_allow_user (BusContext *context,
1000 return bus_policy_allow_user (context->policy,
1001 context->user_database,
1006 bus_context_get_policy (BusContext *context)
1008 return context->policy;
1012 bus_context_create_client_policy (BusContext *context,
1013 DBusConnection *connection,
1016 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1017 return bus_policy_create_client_policy (context->policy, connection,
1022 bus_context_get_activation_timeout (BusContext *context)
1025 return context->limits.activation_timeout;
1029 bus_context_get_auth_timeout (BusContext *context)
1031 return context->limits.auth_timeout;
1035 bus_context_get_max_completed_connections (BusContext *context)
1037 return context->limits.max_completed_connections;
1041 bus_context_get_max_incomplete_connections (BusContext *context)
1043 return context->limits.max_incomplete_connections;
1047 bus_context_get_max_connections_per_user (BusContext *context)
1049 return context->limits.max_connections_per_user;
1053 bus_context_get_max_pending_activations (BusContext *context)
1055 return context->limits.max_pending_activations;
1059 bus_context_get_max_services_per_connection (BusContext *context)
1061 return context->limits.max_services_per_connection;
1065 bus_context_get_max_match_rules_per_connection (BusContext *context)
1067 return context->limits.max_match_rules_per_connection;
1071 bus_context_get_max_replies_per_connection (BusContext *context)
1073 return context->limits.max_replies_per_connection;
1077 bus_context_get_reply_timeout (BusContext *context)
1079 return context->limits.reply_timeout;
1083 * addressed_recipient is the recipient specified in the message.
1085 * proposed_recipient is the recipient we're considering sending
1086 * to right this second, and may be an eavesdropper.
1088 * sender is the sender of the message.
1090 * NULL for proposed_recipient or sender definitely means the bus driver.
1092 * NULL for addressed_recipient may mean the bus driver, or may mean
1093 * no destination was specified in the message (e.g. a signal).
1096 bus_context_check_security_policy (BusContext *context,
1097 BusTransaction *transaction,
1098 DBusConnection *sender,
1099 DBusConnection *addressed_recipient,
1100 DBusConnection *proposed_recipient,
1101 DBusMessage *message,
1104 BusClientPolicy *sender_policy;
1105 BusClientPolicy *recipient_policy;
1107 dbus_bool_t requested_reply;
1109 type = dbus_message_get_type (message);
1111 /* dispatch.c was supposed to ensure these invariants */
1112 _dbus_assert (dbus_message_get_destination (message) != NULL ||
1113 type == DBUS_MESSAGE_TYPE_SIGNAL ||
1114 (sender == NULL && !bus_connection_is_active (proposed_recipient)));
1115 _dbus_assert (type == DBUS_MESSAGE_TYPE_SIGNAL ||
1116 addressed_recipient != NULL ||
1117 strcmp (dbus_message_get_destination (message), DBUS_SERVICE_DBUS) == 0);
1121 case DBUS_MESSAGE_TYPE_METHOD_CALL:
1122 case DBUS_MESSAGE_TYPE_SIGNAL:
1123 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1124 case DBUS_MESSAGE_TYPE_ERROR:
1128 _dbus_verbose ("security check disallowing message of unknown type %d\n",
1131 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1132 "Message bus will not accept messages of unknown type\n");
1137 requested_reply = FALSE;
1143 dest = dbus_message_get_destination (message);
1145 /* First verify the SELinux access controls. If allowed then
1146 * go on with the standard checks.
1148 if (!bus_selinux_allows_send (sender, proposed_recipient,
1149 dbus_message_type_to_string (dbus_message_get_type (message)),
1150 dbus_message_get_interface (message),
1151 dbus_message_get_member (message),
1152 dbus_message_get_error_name (message),
1153 dest ? dest : DBUS_SERVICE_DBUS, error))
1156 if (dbus_error_is_set (error) &&
1157 dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
1163 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1164 "An SELinux policy prevents this sender "
1165 "from sending this message to this recipient "
1166 "(rejected message had interface \"%s\" "
1167 "member \"%s\" error name \"%s\" destination \"%s\")",
1168 dbus_message_get_interface (message) ?
1169 dbus_message_get_interface (message) : "(unset)",
1170 dbus_message_get_member (message) ?
1171 dbus_message_get_member (message) : "(unset)",
1172 dbus_message_get_error_name (message) ?
1173 dbus_message_get_error_name (message) : "(unset)",
1174 dest ? dest : DBUS_SERVICE_DBUS);
1175 _dbus_verbose ("SELinux security check denying send to service\n");
1179 if (bus_connection_is_active (sender))
1181 sender_policy = bus_connection_get_policy (sender);
1182 _dbus_assert (sender_policy != NULL);
1184 /* Fill in requested_reply variable with TRUE if this is a
1185 * reply and the reply was pending.
1187 if (dbus_message_get_reply_serial (message) != 0)
1189 if (proposed_recipient != NULL /* not to the bus driver */ &&
1190 addressed_recipient == proposed_recipient /* not eavesdropping */)
1194 dbus_error_init (&error2);
1195 requested_reply = bus_connections_check_reply (bus_connection_get_connections (sender),
1197 sender, addressed_recipient, message,
1199 if (dbus_error_is_set (&error2))
1201 dbus_move_error (&error2, error);
1209 /* Policy for inactive connections is that they can only send
1210 * the hello message to the bus driver
1212 if (proposed_recipient == NULL &&
1213 dbus_message_is_method_call (message,
1214 DBUS_INTERFACE_DBUS,
1217 _dbus_verbose ("security check allowing %s message\n",
1223 _dbus_verbose ("security check disallowing non-%s message\n",
1226 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1227 "Client tried to send a message other than %s without being registered",
1236 sender_policy = NULL;
1238 /* If the sender is the bus driver, we assume any reply was a
1239 * requested reply as bus driver won't send bogus ones
1241 if (addressed_recipient == proposed_recipient /* not eavesdropping */ &&
1242 dbus_message_get_reply_serial (message) != 0)
1243 requested_reply = TRUE;
1246 _dbus_assert ((sender != NULL && sender_policy != NULL) ||
1247 (sender == NULL && sender_policy == NULL));
1249 if (proposed_recipient != NULL)
1251 /* only the bus driver can send to an inactive recipient (as it
1252 * owns no services, so other apps can't address it). Inactive
1253 * recipients can receive any message.
1255 if (bus_connection_is_active (proposed_recipient))
1257 recipient_policy = bus_connection_get_policy (proposed_recipient);
1258 _dbus_assert (recipient_policy != NULL);
1260 else if (sender == NULL)
1262 _dbus_verbose ("security check using NULL recipient policy for message from bus\n");
1263 recipient_policy = NULL;
1267 _dbus_assert_not_reached ("a message was somehow sent to an inactive recipient from a source other than the message bus\n");
1268 recipient_policy = NULL;
1272 recipient_policy = NULL;
1274 _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) ||
1275 (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) ||
1276 (proposed_recipient == NULL && recipient_policy == NULL));
1278 if (sender_policy &&
1279 !bus_client_policy_check_can_send (sender_policy,
1287 dest = dbus_message_get_destination (message);
1288 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1289 "A security policy in place prevents this sender "
1290 "from sending this message to this recipient, "
1291 "see message bus configuration file (rejected message "
1292 "had interface \"%s\" member \"%s\" error name \"%s\" destination \"%s\")",
1293 dbus_message_get_interface (message) ?
1294 dbus_message_get_interface (message) : "(unset)",
1295 dbus_message_get_member (message) ?
1296 dbus_message_get_member (message) : "(unset)",
1297 dbus_message_get_error_name (message) ?
1298 dbus_message_get_error_name (message) : "(unset)",
1299 dest ? dest : DBUS_SERVICE_DBUS);
1300 _dbus_verbose ("security policy disallowing message due to sender policy\n");
1304 if (recipient_policy &&
1305 !bus_client_policy_check_can_receive (recipient_policy,
1309 addressed_recipient, proposed_recipient,
1314 dest = dbus_message_get_destination (message);
1315 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1316 "A security policy in place prevents this recipient "
1317 "from receiving this message from this sender, "
1318 "see message bus configuration file (rejected message "
1319 "had interface \"%s\" member \"%s\" error name \"%s\" destination \"%s\" reply serial %u requested_reply=%d)",
1320 dbus_message_get_interface (message) ?
1321 dbus_message_get_interface (message) : "(unset)",
1322 dbus_message_get_member (message) ?
1323 dbus_message_get_member (message) : "(unset)",
1324 dbus_message_get_error_name (message) ?
1325 dbus_message_get_error_name (message) : "(unset)",
1326 dest ? dest : DBUS_SERVICE_DBUS,
1327 dbus_message_get_reply_serial (message),
1329 _dbus_verbose ("security policy disallowing message due to recipient policy\n");
1333 /* See if limits on size have been exceeded */
1334 if (proposed_recipient &&
1335 dbus_connection_get_outgoing_size (proposed_recipient) >
1336 context->limits.max_outgoing_bytes)
1340 dest = dbus_message_get_destination (message);
1341 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1342 "The destination service \"%s\" has a full message queue",
1343 dest ? dest : (proposed_recipient ?
1344 bus_connection_get_name (proposed_recipient) :
1345 DBUS_SERVICE_DBUS));
1346 _dbus_verbose ("security policy disallowing message due to full message queue\n");
1350 if (type == DBUS_MESSAGE_TYPE_METHOD_CALL)
1352 /* Record that we will allow a reply here in the future (don't
1353 * bother if the recipient is the bus). Only the addressed recipient
1356 if (sender && addressed_recipient &&
1357 !bus_connections_expect_reply (bus_connection_get_connections (sender),
1359 sender, addressed_recipient,
1362 _dbus_verbose ("Failed to record reply expectation or problem with the message expecting a reply\n");
1367 _dbus_verbose ("security policy allowing message\n");