1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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>
50 BusConnections *connections;
51 BusActivation *activation;
52 BusRegistry *registry;
54 BusMatchmaker *matchmaker;
56 unsigned int fork : 1;
59 static dbus_int32_t server_data_slot = -1;
66 #define BUS_SERVER_DATA(server) (dbus_server_get_data ((server), server_data_slot))
69 server_get_context (DBusServer *server)
74 if (!dbus_server_allocate_data_slot (&server_data_slot))
77 bd = BUS_SERVER_DATA (server);
80 dbus_server_free_data_slot (&server_data_slot);
84 context = bd->context;
86 dbus_server_free_data_slot (&server_data_slot);
92 server_watch_callback (DBusWatch *watch,
93 unsigned int condition,
96 /* FIXME this can be done in dbus-mainloop.c
97 * if the code in activation.c for the babysitter
98 * watch handler is fixed.
101 return dbus_watch_handle (watch, condition);
105 add_server_watch (DBusWatch *watch,
108 DBusServer *server = data;
111 context = server_get_context (server);
113 return _dbus_loop_add_watch (context->loop,
114 watch, server_watch_callback, server,
119 remove_server_watch (DBusWatch *watch,
122 DBusServer *server = data;
125 context = server_get_context (server);
127 _dbus_loop_remove_watch (context->loop,
128 watch, server_watch_callback, server);
133 server_timeout_callback (DBusTimeout *timeout,
136 /* can return FALSE on OOM but we just let it fire again later */
137 dbus_timeout_handle (timeout);
141 add_server_timeout (DBusTimeout *timeout,
144 DBusServer *server = data;
147 context = server_get_context (server);
149 return _dbus_loop_add_timeout (context->loop,
150 timeout, server_timeout_callback, server, NULL);
154 remove_server_timeout (DBusTimeout *timeout,
157 DBusServer *server = data;
160 context = server_get_context (server);
162 _dbus_loop_remove_timeout (context->loop,
163 timeout, server_timeout_callback, server);
167 new_connection_callback (DBusServer *server,
168 DBusConnection *new_connection,
171 BusContext *context = data;
173 if (!bus_connections_setup_connection (context->connections, new_connection))
175 _dbus_verbose ("No memory to setup new connection\n");
177 /* if we don't do this, it will get unref'd without
178 * being disconnected... kind of strange really
179 * that we have to do this, people won't get it right
182 dbus_connection_close (new_connection);
185 dbus_connection_set_max_received_size (new_connection,
186 context->limits.max_incoming_bytes);
188 dbus_connection_set_max_message_size (new_connection,
189 context->limits.max_message_size);
191 /* on OOM, we won't have ref'd the connection so it will die. */
195 free_server_data (void *data)
197 BusServerData *bd = data;
203 setup_server (BusContext *context,
205 char **auth_mechanisms,
210 bd = dbus_new0 (BusServerData, 1);
211 if (!dbus_server_set_data (server,
213 bd, free_server_data))
220 bd->context = context;
222 if (!dbus_server_set_auth_mechanisms (server, (const char**) auth_mechanisms))
228 dbus_server_set_new_connection_function (server,
229 new_connection_callback,
232 if (!dbus_server_set_watch_functions (server,
243 if (!dbus_server_set_timeout_functions (server,
245 remove_server_timeout,
256 /* This code only gets executed the first time the
257 config files are parsed. It is not executed
258 when config files are reloaded.*/
260 process_config_first_time_only (BusContext *context,
261 BusConfigParser *parser,
265 DBusList **addresses;
266 const char *user, *pidfile, *servicehelper;
267 char **auth_mechanisms;
268 DBusList **auth_mechanisms_list;
272 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
275 auth_mechanisms = NULL;
277 /* Check for an existing pid file. Of course this is a race;
278 * we'd have to use fcntl() locks on the pid file to
279 * avoid that. But we want to check for the pid file
280 * before overwriting any existing sockets, etc.
282 pidfile = bus_config_parser_get_pidfile (parser);
288 _dbus_string_init_const (&u, pidfile);
290 if (_dbus_stat (&u, &stbuf, NULL))
292 dbus_set_error (error, DBUS_ERROR_FAILED,
293 "The pid file \"%s\" exists, if the message bus is not running, remove this file",
299 /* keep around the pid filename so we can delete it later */
300 context->pidfile = _dbus_strdup (pidfile);
302 /* we need to configure this so we can test the service helper */
303 servicehelper = bus_config_parser_get_servicehelper (parser);
304 if (servicehelper != NULL)
305 context->servicehelper = _dbus_strdup (servicehelper);
307 /* Build an array of auth mechanisms */
309 auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
310 len = _dbus_list_get_length (auth_mechanisms_list);
316 auth_mechanisms = dbus_new0 (char*, len + 1);
317 if (auth_mechanisms == NULL)
324 link = _dbus_list_get_first_link (auth_mechanisms_list);
327 auth_mechanisms[i] = _dbus_strdup (link->data);
328 if (auth_mechanisms[i] == NULL)
333 link = _dbus_list_get_next_link (auth_mechanisms_list, link);
338 auth_mechanisms = NULL;
341 /* Listen on our addresses */
343 addresses = bus_config_parser_get_addresses (parser);
345 link = _dbus_list_get_first_link (addresses);
350 server = dbus_server_listen (link->data, error);
353 _DBUS_ASSERT_ERROR_IS_SET (error);
356 else if (!setup_server (context, server, auth_mechanisms, error))
358 _DBUS_ASSERT_ERROR_IS_SET (error);
362 if (!_dbus_list_append (&context->servers, server))
368 link = _dbus_list_get_next_link (addresses, link);
371 /* note that type may be NULL */
372 context->type = _dbus_strdup (bus_config_parser_get_type (parser));
373 if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
379 user = bus_config_parser_get_user (parser);
382 context->user = _dbus_strdup (user);
383 if (context->user == NULL)
390 context->fork = bus_config_parser_get_fork (parser);
392 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
396 dbus_free_string_array (auth_mechanisms);
400 /* This code gets executed every time the config files
401 are parsed: both during BusContext construction
404 process_config_every_time (BusContext *context,
405 BusConfigParser *parser,
406 dbus_bool_t is_reload,
409 DBusString full_address;
412 BusActivation *new_activation;
417 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
422 if (!_dbus_string_init (&full_address))
428 /* get our limits and timeout lengths */
429 bus_config_parser_get_limits (parser, &context->limits);
431 context->policy = bus_config_parser_steal_policy (parser);
432 _dbus_assert (context->policy != NULL);
434 /* We have to build the address backward, so that
435 * <listen> later in the config file have priority
437 link = _dbus_list_get_last_link (&context->servers);
440 addr = dbus_server_get_address (link->data);
447 if (_dbus_string_get_length (&full_address) > 0)
449 if (!_dbus_string_append (&full_address, ";"))
456 if (!_dbus_string_append (&full_address, addr))
465 link = _dbus_list_get_prev_link (&context->servers, link);
469 dbus_free (context->address);
471 if (!_dbus_string_copy_data (&full_address, &context->address))
477 /* get the service directories */
478 dirs = bus_config_parser_get_service_dirs (parser);
480 /* Create activation subsystem */
481 new_activation = bus_activation_new (context, &full_address,
483 if (new_activation == NULL)
485 _DBUS_ASSERT_ERROR_IS_SET (error);
490 bus_activation_unref (context->activation);
492 context->activation = new_activation;
494 /* Drop existing conf-dir watches (if applicable) */
497 bus_drop_all_directory_watches ();
499 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
503 _dbus_string_free (&full_address);
512 process_config_postinit (BusContext *context,
513 BusConfigParser *parser,
516 DBusHashTable *service_context_table;
518 service_context_table = bus_config_parser_steal_service_context_table (parser);
519 if (!bus_registry_set_service_context_table (context->registry,
520 service_context_table))
526 _dbus_hash_table_unref (service_context_table);
528 /* Watch all conf directories */
529 _dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
530 (DBusForeachFunction) bus_watch_directory,
537 bus_context_new (const DBusString *config_file,
538 ForceForkSetting force_fork,
539 DBusPipe *print_addr_pipe,
540 DBusPipe *print_pid_pipe,
544 BusConfigParser *parser;
546 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
551 if (!dbus_server_allocate_data_slot (&server_data_slot))
557 context = dbus_new0 (BusContext, 1);
563 context->refcount = 1;
565 _dbus_generate_uuid (&context->uuid);
567 if (!_dbus_string_copy_data (config_file, &context->config_file))
573 context->loop = _dbus_loop_new ();
574 if (context->loop == NULL)
580 context->registry = bus_registry_new (context);
581 if (context->registry == NULL)
587 parser = bus_config_load (config_file, TRUE, NULL, error);
590 _DBUS_ASSERT_ERROR_IS_SET (error);
594 if (!process_config_first_time_only (context, parser, error))
596 _DBUS_ASSERT_ERROR_IS_SET (error);
599 if (!process_config_every_time (context, parser, FALSE, error))
601 _DBUS_ASSERT_ERROR_IS_SET (error);
605 /* we need another ref of the server data slot for the context
608 if (!dbus_server_allocate_data_slot (&server_data_slot))
609 _dbus_assert_not_reached ("second ref of server data slot failed");
611 /* Note that we don't know whether the print_addr_pipe is
612 * one of the sockets we're using to listen on, or some
613 * other random thing. But I think the answer is "don't do
616 if (print_addr_pipe != NULL && _dbus_pipe_is_valid (print_addr_pipe))
619 const char *a = bus_context_get_address (context);
622 _dbus_assert (a != NULL);
623 if (!_dbus_string_init (&addr))
629 if (!_dbus_string_append (&addr, a) ||
630 !_dbus_string_append (&addr, "\n"))
632 _dbus_string_free (&addr);
637 bytes = _dbus_string_get_length (&addr);
638 if (_dbus_pipe_write (print_addr_pipe, &addr, 0, bytes, error) != bytes)
640 /* pipe write returns an error on failure but not short write */
641 if (error != NULL && !dbus_error_is_set (error))
643 dbus_set_error (error, DBUS_ERROR_FAILED,
644 "Printing message bus address: did not write all bytes\n");
646 _dbus_string_free (&addr);
650 if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe))
651 _dbus_pipe_close (print_addr_pipe, NULL);
653 _dbus_string_free (&addr);
656 context->connections = bus_connections_new (context);
657 if (context->connections == NULL)
663 context->matchmaker = bus_matchmaker_new ();
664 if (context->matchmaker == NULL)
670 /* check user before we fork */
671 if (context->user != NULL)
673 if (!_dbus_verify_daemon_user (context->user))
675 dbus_set_error (error, DBUS_ERROR_FAILED,
676 "Could not get UID and GID for username \"%s\"",
682 /* Now become a daemon if appropriate */
683 if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
687 if (context->pidfile)
688 _dbus_string_init_const (&u, context->pidfile);
690 if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
694 _DBUS_ASSERT_ERROR_IS_SET (error);
700 /* Need to write PID file for ourselves, not for the child process */
701 if (context->pidfile != NULL)
705 _dbus_string_init_const (&u, context->pidfile);
707 if (!_dbus_write_pid_file (&u, _dbus_getpid (), error))
709 _DBUS_ASSERT_ERROR_IS_SET (error);
715 /* Write PID if requested */
716 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
721 if (!_dbus_string_init (&pid))
727 if (!_dbus_string_append_int (&pid, _dbus_getpid ()) ||
728 !_dbus_string_append (&pid, "\n"))
730 _dbus_string_free (&pid);
735 bytes = _dbus_string_get_length (&pid);
736 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
738 /* pipe_write sets error on failure but not short write */
739 if (error != NULL && !dbus_error_is_set (error))
741 dbus_set_error (error, DBUS_ERROR_FAILED,
742 "Printing message bus PID: did not write enough bytes\n");
744 _dbus_string_free (&pid);
748 if (!_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
749 _dbus_pipe_close (print_pid_pipe, NULL);
751 _dbus_string_free (&pid);
754 if (!process_config_postinit (context, parser, error))
756 _DBUS_ASSERT_ERROR_IS_SET (error);
762 bus_config_parser_unref (parser);
766 /* Here we change our credentials if required,
767 * as soon as we've set up our sockets and pidfile
769 if (context->user != NULL)
771 if (!_dbus_change_to_daemon_user (context->user, error))
773 _DBUS_ASSERT_ERROR_IS_SET (error);
778 if (!bus_selinux_full_init ())
780 _dbus_warn ("SELinux initialization failed\n");
783 dbus_server_free_data_slot (&server_data_slot);
789 bus_config_parser_unref (parser);
791 bus_context_unref (context);
793 if (server_data_slot >= 0)
794 dbus_server_free_data_slot (&server_data_slot);
800 bus_context_get_id (BusContext *context,
803 return _dbus_uuid_encode (&context->uuid, uuid);
807 bus_context_reload_config (BusContext *context,
810 BusConfigParser *parser;
811 DBusString config_file;
814 /* Flush the user database cache */
815 _dbus_flush_caches ();
818 _dbus_string_init_const (&config_file, context->config_file);
819 parser = bus_config_load (&config_file, TRUE, NULL, error);
822 _DBUS_ASSERT_ERROR_IS_SET (error);
826 if (!process_config_every_time (context, parser, TRUE, error))
828 _DBUS_ASSERT_ERROR_IS_SET (error);
831 if (!process_config_postinit (context, parser, error))
833 _DBUS_ASSERT_ERROR_IS_SET (error);
840 bus_config_parser_unref (parser);
845 shutdown_server (BusContext *context,
848 if (server == NULL ||
849 !dbus_server_get_is_connected (server))
852 if (!dbus_server_set_watch_functions (server,
856 _dbus_assert_not_reached ("setting watch functions to NULL failed");
858 if (!dbus_server_set_timeout_functions (server,
862 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
864 dbus_server_disconnect (server);
868 bus_context_shutdown (BusContext *context)
872 link = _dbus_list_get_first_link (&context->servers);
875 shutdown_server (context, link->data);
877 link = _dbus_list_get_next_link (&context->servers, link);
882 bus_context_ref (BusContext *context)
884 _dbus_assert (context->refcount > 0);
885 context->refcount += 1;
891 bus_context_unref (BusContext *context)
893 _dbus_assert (context->refcount > 0);
894 context->refcount -= 1;
896 if (context->refcount == 0)
900 _dbus_verbose ("Finalizing bus context %p\n", context);
902 bus_context_shutdown (context);
904 if (context->connections)
906 bus_connections_unref (context->connections);
907 context->connections = NULL;
910 if (context->registry)
912 bus_registry_unref (context->registry);
913 context->registry = NULL;
916 if (context->activation)
918 bus_activation_unref (context->activation);
919 context->activation = NULL;
922 link = _dbus_list_get_first_link (&context->servers);
925 dbus_server_unref (link->data);
927 link = _dbus_list_get_next_link (&context->servers, link);
929 _dbus_list_clear (&context->servers);
933 bus_policy_unref (context->policy);
934 context->policy = NULL;
939 _dbus_loop_unref (context->loop);
940 context->loop = NULL;
943 if (context->matchmaker)
945 bus_matchmaker_unref (context->matchmaker);
946 context->matchmaker = NULL;
949 dbus_free (context->config_file);
950 dbus_free (context->type);
951 dbus_free (context->address);
952 dbus_free (context->user);
953 dbus_free (context->servicehelper);
955 if (context->pidfile)
958 _dbus_string_init_const (&u, context->pidfile);
960 /* Deliberately ignore errors here, since there's not much
961 * we can do about it, and we're exiting anyways.
963 _dbus_delete_file (&u, NULL);
965 dbus_free (context->pidfile);
969 dbus_server_free_data_slot (&server_data_slot);
973 /* type may be NULL */
975 bus_context_get_type (BusContext *context)
977 return context->type;
981 bus_context_get_address (BusContext *context)
983 return context->address;
987 bus_context_get_servicehelper (BusContext *context)
989 return context->servicehelper;
993 bus_context_get_registry (BusContext *context)
995 return context->registry;
999 bus_context_get_connections (BusContext *context)
1001 return context->connections;
1005 bus_context_get_activation (BusContext *context)
1007 return context->activation;
1011 bus_context_get_matchmaker (BusContext *context)
1013 return context->matchmaker;
1017 bus_context_get_loop (BusContext *context)
1019 return context->loop;
1023 bus_context_allow_unix_user (BusContext *context,
1026 return bus_policy_allow_unix_user (context->policy,
1030 /* For now this is never actually called because the default
1031 * DBusConnection behavior of 'same user that owns the bus can connect'
1032 * is all it would do.
1035 bus_context_allow_windows_user (BusContext *context,
1036 const char *windows_sid)
1038 return bus_policy_allow_windows_user (context->policy,
1043 bus_context_get_policy (BusContext *context)
1045 return context->policy;
1049 bus_context_create_client_policy (BusContext *context,
1050 DBusConnection *connection,
1053 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1054 return bus_policy_create_client_policy (context->policy, connection,
1059 bus_context_get_activation_timeout (BusContext *context)
1062 return context->limits.activation_timeout;
1066 bus_context_get_auth_timeout (BusContext *context)
1068 return context->limits.auth_timeout;
1072 bus_context_get_max_completed_connections (BusContext *context)
1074 return context->limits.max_completed_connections;
1078 bus_context_get_max_incomplete_connections (BusContext *context)
1080 return context->limits.max_incomplete_connections;
1084 bus_context_get_max_connections_per_user (BusContext *context)
1086 return context->limits.max_connections_per_user;
1090 bus_context_get_max_pending_activations (BusContext *context)
1092 return context->limits.max_pending_activations;
1096 bus_context_get_max_services_per_connection (BusContext *context)
1098 return context->limits.max_services_per_connection;
1102 bus_context_get_max_match_rules_per_connection (BusContext *context)
1104 return context->limits.max_match_rules_per_connection;
1108 bus_context_get_max_replies_per_connection (BusContext *context)
1110 return context->limits.max_replies_per_connection;
1114 bus_context_get_reply_timeout (BusContext *context)
1116 return context->limits.reply_timeout;
1120 * addressed_recipient is the recipient specified in the message.
1122 * proposed_recipient is the recipient we're considering sending
1123 * to right this second, and may be an eavesdropper.
1125 * sender is the sender of the message.
1127 * NULL for proposed_recipient or sender definitely means the bus driver.
1129 * NULL for addressed_recipient may mean the bus driver, or may mean
1130 * no destination was specified in the message (e.g. a signal).
1133 bus_context_check_security_policy (BusContext *context,
1134 BusTransaction *transaction,
1135 DBusConnection *sender,
1136 DBusConnection *addressed_recipient,
1137 DBusConnection *proposed_recipient,
1138 DBusMessage *message,
1141 BusClientPolicy *sender_policy;
1142 BusClientPolicy *recipient_policy;
1144 dbus_bool_t requested_reply;
1146 type = dbus_message_get_type (message);
1148 /* dispatch.c was supposed to ensure these invariants */
1149 _dbus_assert (dbus_message_get_destination (message) != NULL ||
1150 type == DBUS_MESSAGE_TYPE_SIGNAL ||
1151 (sender == NULL && !bus_connection_is_active (proposed_recipient)));
1152 _dbus_assert (type == DBUS_MESSAGE_TYPE_SIGNAL ||
1153 addressed_recipient != NULL ||
1154 strcmp (dbus_message_get_destination (message), DBUS_SERVICE_DBUS) == 0);
1158 case DBUS_MESSAGE_TYPE_METHOD_CALL:
1159 case DBUS_MESSAGE_TYPE_SIGNAL:
1160 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1161 case DBUS_MESSAGE_TYPE_ERROR:
1165 _dbus_verbose ("security check disallowing message of unknown type %d\n",
1168 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1169 "Message bus will not accept messages of unknown type\n");
1174 requested_reply = FALSE;
1180 dest = dbus_message_get_destination (message);
1182 /* First verify the SELinux access controls. If allowed then
1183 * go on with the standard checks.
1185 if (!bus_selinux_allows_send (sender, proposed_recipient,
1186 dbus_message_type_to_string (dbus_message_get_type (message)),
1187 dbus_message_get_interface (message),
1188 dbus_message_get_member (message),
1189 dbus_message_get_error_name (message),
1190 dest ? dest : DBUS_SERVICE_DBUS, error))
1193 if (dbus_error_is_set (error) &&
1194 dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
1200 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1201 "An SELinux policy prevents this sender "
1202 "from sending this message to this recipient "
1203 "(rejected message had interface \"%s\" "
1204 "member \"%s\" error name \"%s\" destination \"%s\")",
1205 dbus_message_get_interface (message) ?
1206 dbus_message_get_interface (message) : "(unset)",
1207 dbus_message_get_member (message) ?
1208 dbus_message_get_member (message) : "(unset)",
1209 dbus_message_get_error_name (message) ?
1210 dbus_message_get_error_name (message) : "(unset)",
1211 dest ? dest : DBUS_SERVICE_DBUS);
1212 _dbus_verbose ("SELinux security check denying send to service\n");
1216 if (bus_connection_is_active (sender))
1218 sender_policy = bus_connection_get_policy (sender);
1219 _dbus_assert (sender_policy != NULL);
1221 /* Fill in requested_reply variable with TRUE if this is a
1222 * reply and the reply was pending.
1224 if (dbus_message_get_reply_serial (message) != 0)
1226 if (proposed_recipient != NULL /* not to the bus driver */ &&
1227 addressed_recipient == proposed_recipient /* not eavesdropping */)
1231 dbus_error_init (&error2);
1232 requested_reply = bus_connections_check_reply (bus_connection_get_connections (sender),
1234 sender, addressed_recipient, message,
1236 if (dbus_error_is_set (&error2))
1238 dbus_move_error (&error2, error);
1246 /* Policy for inactive connections is that they can only send
1247 * the hello message to the bus driver
1249 if (proposed_recipient == NULL &&
1250 dbus_message_is_method_call (message,
1251 DBUS_INTERFACE_DBUS,
1254 _dbus_verbose ("security check allowing %s message\n",
1260 _dbus_verbose ("security check disallowing non-%s message\n",
1263 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1264 "Client tried to send a message other than %s without being registered",
1273 sender_policy = NULL;
1275 /* If the sender is the bus driver, we assume any reply was a
1276 * requested reply as bus driver won't send bogus ones
1278 if (addressed_recipient == proposed_recipient /* not eavesdropping */ &&
1279 dbus_message_get_reply_serial (message) != 0)
1280 requested_reply = TRUE;
1283 _dbus_assert ((sender != NULL && sender_policy != NULL) ||
1284 (sender == NULL && sender_policy == NULL));
1286 if (proposed_recipient != NULL)
1288 /* only the bus driver can send to an inactive recipient (as it
1289 * owns no services, so other apps can't address it). Inactive
1290 * recipients can receive any message.
1292 if (bus_connection_is_active (proposed_recipient))
1294 recipient_policy = bus_connection_get_policy (proposed_recipient);
1295 _dbus_assert (recipient_policy != NULL);
1297 else if (sender == NULL)
1299 _dbus_verbose ("security check using NULL recipient policy for message from bus\n");
1300 recipient_policy = NULL;
1304 _dbus_assert_not_reached ("a message was somehow sent to an inactive recipient from a source other than the message bus\n");
1305 recipient_policy = NULL;
1309 recipient_policy = NULL;
1311 _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) ||
1312 (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) ||
1313 (proposed_recipient == NULL && recipient_policy == NULL));
1315 if (sender_policy &&
1316 !bus_client_policy_check_can_send (sender_policy,
1324 dest = dbus_message_get_destination (message);
1325 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1326 "A security policy in place prevents this sender "
1327 "from sending this message to this recipient, "
1328 "see message bus configuration file (rejected message "
1329 "had interface \"%s\" member \"%s\" error name \"%s\" destination \"%s\")",
1330 dbus_message_get_interface (message) ?
1331 dbus_message_get_interface (message) : "(unset)",
1332 dbus_message_get_member (message) ?
1333 dbus_message_get_member (message) : "(unset)",
1334 dbus_message_get_error_name (message) ?
1335 dbus_message_get_error_name (message) : "(unset)",
1336 dest ? dest : DBUS_SERVICE_DBUS);
1337 _dbus_verbose ("security policy disallowing message due to sender policy\n");
1341 if (recipient_policy &&
1342 !bus_client_policy_check_can_receive (recipient_policy,
1346 addressed_recipient, proposed_recipient,
1351 dest = dbus_message_get_destination (message);
1352 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1353 "A security policy in place prevents this recipient "
1354 "from receiving this message from this sender, "
1355 "see message bus configuration file (rejected message "
1356 "had interface \"%s\" member \"%s\" error name \"%s\" destination \"%s\" reply serial %u requested_reply=%d)",
1357 dbus_message_get_interface (message) ?
1358 dbus_message_get_interface (message) : "(unset)",
1359 dbus_message_get_member (message) ?
1360 dbus_message_get_member (message) : "(unset)",
1361 dbus_message_get_error_name (message) ?
1362 dbus_message_get_error_name (message) : "(unset)",
1363 dest ? dest : DBUS_SERVICE_DBUS,
1364 dbus_message_get_reply_serial (message),
1366 _dbus_verbose ("security policy disallowing message due to recipient policy\n");
1370 /* See if limits on size have been exceeded */
1371 if (proposed_recipient &&
1372 dbus_connection_get_outgoing_size (proposed_recipient) >
1373 context->limits.max_outgoing_bytes)
1377 dest = dbus_message_get_destination (message);
1378 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1379 "The destination service \"%s\" has a full message queue",
1380 dest ? dest : (proposed_recipient ?
1381 bus_connection_get_name (proposed_recipient) :
1382 DBUS_SERVICE_DBUS));
1383 _dbus_verbose ("security policy disallowing message due to full message queue\n");
1387 /* Record that we will allow a reply here in the future (don't
1388 * bother if the recipient is the bus or this is an eavesdropping
1389 * connection). Only the addressed recipient may reply.
1391 if (type == DBUS_MESSAGE_TYPE_METHOD_CALL &&
1393 addressed_recipient &&
1394 addressed_recipient == proposed_recipient && /* not eavesdropping */
1395 !bus_connections_expect_reply (bus_connection_get_connections (sender),
1397 sender, addressed_recipient,
1400 _dbus_verbose ("Failed to record reply expectation or problem with the message expecting a reply\n");
1404 _dbus_verbose ("security policy allowing message\n");