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.
261 process_config_first_time_only (BusContext *context,
262 BusConfigParser *parser,
266 DBusList **addresses;
267 const char *user, *pidfile;
268 char **auth_mechanisms;
269 DBusList **auth_mechanisms_list;
273 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
276 auth_mechanisms = NULL;
278 /* Check for an existing pid file. Of course this is a race;
279 * we'd have to use fcntl() locks on the pid file to
280 * avoid that. But we want to check for the pid file
281 * before overwriting any existing sockets, etc.
283 pidfile = bus_config_parser_get_pidfile (parser);
289 _dbus_string_init_const (&u, pidfile);
291 if (_dbus_stat (&u, &stbuf, NULL))
293 dbus_set_error (error, DBUS_ERROR_FAILED,
294 "The pid file \"%s\" exists, if the message bus is not running, remove this file",
300 /* keep around the pid filename so we can delete it later */
301 context->pidfile = _dbus_strdup (pidfile);
303 /* Build an array of auth mechanisms */
305 auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
306 len = _dbus_list_get_length (auth_mechanisms_list);
312 auth_mechanisms = dbus_new0 (char*, len + 1);
313 if (auth_mechanisms == NULL)
320 link = _dbus_list_get_first_link (auth_mechanisms_list);
323 auth_mechanisms[i] = _dbus_strdup (link->data);
324 if (auth_mechanisms[i] == NULL)
329 link = _dbus_list_get_next_link (auth_mechanisms_list, link);
334 auth_mechanisms = NULL;
337 /* Listen on our addresses */
339 addresses = bus_config_parser_get_addresses (parser);
341 link = _dbus_list_get_first_link (addresses);
346 server = dbus_server_listen (link->data, error);
349 _DBUS_ASSERT_ERROR_IS_SET (error);
352 else if (!setup_server (context, server, auth_mechanisms, error))
354 _DBUS_ASSERT_ERROR_IS_SET (error);
358 if (!_dbus_list_append (&context->servers, server))
364 link = _dbus_list_get_next_link (addresses, link);
367 /* note that type may be NULL */
368 context->type = _dbus_strdup (bus_config_parser_get_type (parser));
369 if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
375 user = bus_config_parser_get_user (parser);
378 context->user = _dbus_strdup (user);
379 if (context->user == NULL)
386 context->fork = bus_config_parser_get_fork (parser);
388 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
392 dbus_free_string_array (auth_mechanisms);
396 /* This code gets executed every time the config files
397 * are parsed: both during BusContext construction
398 * and on reloads. This function is slightly screwy
399 * since it can do a "half reload" in out-of-memory
400 * situations. Realistically, unlikely to ever matter.
403 process_config_every_time (BusContext *context,
404 BusConfigParser *parser,
405 dbus_bool_t is_reload,
408 DBusString full_address;
411 BusActivation *new_activation;
413 const char *servicehelper;
418 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
423 if (!_dbus_string_init (&full_address))
429 /* get our limits and timeout lengths */
430 bus_config_parser_get_limits (parser, &context->limits);
432 context->policy = bus_config_parser_steal_policy (parser);
433 _dbus_assert (context->policy != NULL);
435 /* We have to build the address backward, so that
436 * <listen> later in the config file have priority
438 link = _dbus_list_get_last_link (&context->servers);
441 addr = dbus_server_get_address (link->data);
448 if (_dbus_string_get_length (&full_address) > 0)
450 if (!_dbus_string_append (&full_address, ";"))
457 if (!_dbus_string_append (&full_address, addr))
466 link = _dbus_list_get_prev_link (&context->servers, link);
470 dbus_free (context->address);
472 if (!_dbus_string_copy_data (&full_address, &context->address))
478 /* get the service directories */
479 dirs = bus_config_parser_get_service_dirs (parser);
481 /* and the service helper */
482 servicehelper = bus_config_parser_get_servicehelper (parser);
484 s = _dbus_strdup(servicehelper);
485 if (s == NULL && servicehelper != NULL)
492 dbus_free(context->servicehelper);
493 context->servicehelper = s;
496 /* Create activation subsystem */
497 new_activation = bus_activation_new (context, &full_address,
499 if (new_activation == NULL)
501 _DBUS_ASSERT_ERROR_IS_SET (error);
506 bus_activation_unref (context->activation);
508 context->activation = new_activation;
510 /* Drop existing conf-dir watches (if applicable) */
513 bus_drop_all_directory_watches ();
515 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
519 _dbus_string_free (&full_address);
528 process_config_postinit (BusContext *context,
529 BusConfigParser *parser,
532 DBusHashTable *service_context_table;
534 service_context_table = bus_config_parser_steal_service_context_table (parser);
535 if (!bus_registry_set_service_context_table (context->registry,
536 service_context_table))
542 _dbus_hash_table_unref (service_context_table);
544 /* Watch all conf directories */
545 _dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
546 (DBusForeachFunction) bus_watch_directory,
553 bus_context_new (const DBusString *config_file,
554 ForceForkSetting force_fork,
555 DBusPipe *print_addr_pipe,
556 DBusPipe *print_pid_pipe,
560 BusConfigParser *parser;
562 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
567 if (!dbus_server_allocate_data_slot (&server_data_slot))
573 context = dbus_new0 (BusContext, 1);
579 context->refcount = 1;
581 _dbus_generate_uuid (&context->uuid);
583 if (!_dbus_string_copy_data (config_file, &context->config_file))
589 context->loop = _dbus_loop_new ();
590 if (context->loop == NULL)
596 context->registry = bus_registry_new (context);
597 if (context->registry == NULL)
603 parser = bus_config_load (config_file, TRUE, NULL, error);
606 _DBUS_ASSERT_ERROR_IS_SET (error);
610 if (!process_config_first_time_only (context, parser, error))
612 _DBUS_ASSERT_ERROR_IS_SET (error);
615 if (!process_config_every_time (context, parser, FALSE, error))
617 _DBUS_ASSERT_ERROR_IS_SET (error);
621 /* we need another ref of the server data slot for the context
624 if (!dbus_server_allocate_data_slot (&server_data_slot))
625 _dbus_assert_not_reached ("second ref of server data slot failed");
627 /* Note that we don't know whether the print_addr_pipe is
628 * one of the sockets we're using to listen on, or some
629 * other random thing. But I think the answer is "don't do
632 if (print_addr_pipe != NULL && _dbus_pipe_is_valid (print_addr_pipe))
635 const char *a = bus_context_get_address (context);
638 _dbus_assert (a != NULL);
639 if (!_dbus_string_init (&addr))
645 if (!_dbus_string_append (&addr, a) ||
646 !_dbus_string_append (&addr, "\n"))
648 _dbus_string_free (&addr);
653 bytes = _dbus_string_get_length (&addr);
654 if (_dbus_pipe_write (print_addr_pipe, &addr, 0, bytes, error) != bytes)
656 /* pipe write returns an error on failure but not short write */
657 if (error != NULL && !dbus_error_is_set (error))
659 dbus_set_error (error, DBUS_ERROR_FAILED,
660 "Printing message bus address: did not write all bytes\n");
662 _dbus_string_free (&addr);
666 if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe))
667 _dbus_pipe_close (print_addr_pipe, NULL);
669 _dbus_string_free (&addr);
672 context->connections = bus_connections_new (context);
673 if (context->connections == NULL)
679 context->matchmaker = bus_matchmaker_new ();
680 if (context->matchmaker == NULL)
686 /* check user before we fork */
687 if (context->user != NULL)
689 if (!_dbus_verify_daemon_user (context->user))
691 dbus_set_error (error, DBUS_ERROR_FAILED,
692 "Could not get UID and GID for username \"%s\"",
698 /* Now become a daemon if appropriate and write out pid file in any case */
702 if (context->pidfile)
703 _dbus_string_init_const (&u, context->pidfile);
705 if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
707 _dbus_verbose ("Forking and becoming daemon\n");
709 if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
713 _DBUS_ASSERT_ERROR_IS_SET (error);
719 _dbus_verbose ("Fork not requested\n");
721 /* Need to write PID file and to PID pipe for ourselves,
722 * not for the child process. This is a no-op if the pidfile
723 * is NULL and print_pid_pipe is NULL.
725 if (!_dbus_write_pid_to_file_and_pipe (context->pidfile ? &u : NULL,
730 _DBUS_ASSERT_ERROR_IS_SET (error);
736 if (print_pid_pipe && _dbus_pipe_is_valid (print_pid_pipe) &&
737 !_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
738 _dbus_pipe_close (print_pid_pipe, NULL);
740 if (!process_config_postinit (context, parser, error))
742 _DBUS_ASSERT_ERROR_IS_SET (error);
748 bus_config_parser_unref (parser);
752 /* Here we change our credentials if required,
753 * as soon as we've set up our sockets and pidfile
755 if (context->user != NULL)
757 if (!_dbus_change_to_daemon_user (context->user, error))
759 _DBUS_ASSERT_ERROR_IS_SET (error);
766 if (!bus_selinux_full_init ())
768 _dbus_warn ("SELinux initialization failed\n");
771 dbus_server_free_data_slot (&server_data_slot);
777 bus_config_parser_unref (parser);
779 bus_context_unref (context);
781 if (server_data_slot >= 0)
782 dbus_server_free_data_slot (&server_data_slot);
788 bus_context_get_id (BusContext *context,
791 return _dbus_uuid_encode (&context->uuid, uuid);
795 bus_context_reload_config (BusContext *context,
798 BusConfigParser *parser;
799 DBusString config_file;
802 /* Flush the user database cache */
803 _dbus_flush_caches ();
806 _dbus_string_init_const (&config_file, context->config_file);
807 parser = bus_config_load (&config_file, TRUE, NULL, error);
810 _DBUS_ASSERT_ERROR_IS_SET (error);
814 if (!process_config_every_time (context, parser, TRUE, error))
816 _DBUS_ASSERT_ERROR_IS_SET (error);
819 if (!process_config_postinit (context, parser, error))
821 _DBUS_ASSERT_ERROR_IS_SET (error);
828 bus_config_parser_unref (parser);
833 shutdown_server (BusContext *context,
836 if (server == NULL ||
837 !dbus_server_get_is_connected (server))
840 if (!dbus_server_set_watch_functions (server,
844 _dbus_assert_not_reached ("setting watch functions to NULL failed");
846 if (!dbus_server_set_timeout_functions (server,
850 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
852 dbus_server_disconnect (server);
856 bus_context_shutdown (BusContext *context)
860 link = _dbus_list_get_first_link (&context->servers);
863 shutdown_server (context, link->data);
865 link = _dbus_list_get_next_link (&context->servers, link);
870 bus_context_ref (BusContext *context)
872 _dbus_assert (context->refcount > 0);
873 context->refcount += 1;
879 bus_context_unref (BusContext *context)
881 _dbus_assert (context->refcount > 0);
882 context->refcount -= 1;
884 if (context->refcount == 0)
888 _dbus_verbose ("Finalizing bus context %p\n", context);
890 bus_context_shutdown (context);
892 if (context->connections)
894 bus_connections_unref (context->connections);
895 context->connections = NULL;
898 if (context->registry)
900 bus_registry_unref (context->registry);
901 context->registry = NULL;
904 if (context->activation)
906 bus_activation_unref (context->activation);
907 context->activation = NULL;
910 link = _dbus_list_get_first_link (&context->servers);
913 dbus_server_unref (link->data);
915 link = _dbus_list_get_next_link (&context->servers, link);
917 _dbus_list_clear (&context->servers);
921 bus_policy_unref (context->policy);
922 context->policy = NULL;
927 _dbus_loop_unref (context->loop);
928 context->loop = NULL;
931 if (context->matchmaker)
933 bus_matchmaker_unref (context->matchmaker);
934 context->matchmaker = NULL;
937 dbus_free (context->config_file);
938 dbus_free (context->type);
939 dbus_free (context->address);
940 dbus_free (context->user);
941 dbus_free (context->servicehelper);
943 if (context->pidfile)
946 _dbus_string_init_const (&u, context->pidfile);
948 /* Deliberately ignore errors here, since there's not much
949 * we can do about it, and we're exiting anyways.
951 _dbus_delete_file (&u, NULL);
953 dbus_free (context->pidfile);
957 dbus_server_free_data_slot (&server_data_slot);
961 /* type may be NULL */
963 bus_context_get_type (BusContext *context)
965 return context->type;
969 bus_context_get_address (BusContext *context)
971 return context->address;
975 bus_context_get_servicehelper (BusContext *context)
977 return context->servicehelper;
981 bus_context_get_registry (BusContext *context)
983 return context->registry;
987 bus_context_get_connections (BusContext *context)
989 return context->connections;
993 bus_context_get_activation (BusContext *context)
995 return context->activation;
999 bus_context_get_matchmaker (BusContext *context)
1001 return context->matchmaker;
1005 bus_context_get_loop (BusContext *context)
1007 return context->loop;
1011 bus_context_allow_unix_user (BusContext *context,
1014 return bus_policy_allow_unix_user (context->policy,
1018 /* For now this is never actually called because the default
1019 * DBusConnection behavior of 'same user that owns the bus can connect'
1020 * is all it would do.
1023 bus_context_allow_windows_user (BusContext *context,
1024 const char *windows_sid)
1026 return bus_policy_allow_windows_user (context->policy,
1031 bus_context_get_policy (BusContext *context)
1033 return context->policy;
1037 bus_context_create_client_policy (BusContext *context,
1038 DBusConnection *connection,
1041 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1042 return bus_policy_create_client_policy (context->policy, connection,
1047 bus_context_get_activation_timeout (BusContext *context)
1050 return context->limits.activation_timeout;
1054 bus_context_get_auth_timeout (BusContext *context)
1056 return context->limits.auth_timeout;
1060 bus_context_get_max_completed_connections (BusContext *context)
1062 return context->limits.max_completed_connections;
1066 bus_context_get_max_incomplete_connections (BusContext *context)
1068 return context->limits.max_incomplete_connections;
1072 bus_context_get_max_connections_per_user (BusContext *context)
1074 return context->limits.max_connections_per_user;
1078 bus_context_get_max_pending_activations (BusContext *context)
1080 return context->limits.max_pending_activations;
1084 bus_context_get_max_services_per_connection (BusContext *context)
1086 return context->limits.max_services_per_connection;
1090 bus_context_get_max_match_rules_per_connection (BusContext *context)
1092 return context->limits.max_match_rules_per_connection;
1096 bus_context_get_max_replies_per_connection (BusContext *context)
1098 return context->limits.max_replies_per_connection;
1102 bus_context_get_reply_timeout (BusContext *context)
1104 return context->limits.reply_timeout;
1108 * addressed_recipient is the recipient specified in the message.
1110 * proposed_recipient is the recipient we're considering sending
1111 * to right this second, and may be an eavesdropper.
1113 * sender is the sender of the message.
1115 * NULL for proposed_recipient or sender definitely means the bus driver.
1117 * NULL for addressed_recipient may mean the bus driver, or may mean
1118 * no destination was specified in the message (e.g. a signal).
1121 bus_context_check_security_policy (BusContext *context,
1122 BusTransaction *transaction,
1123 DBusConnection *sender,
1124 DBusConnection *addressed_recipient,
1125 DBusConnection *proposed_recipient,
1126 DBusMessage *message,
1129 BusClientPolicy *sender_policy;
1130 BusClientPolicy *recipient_policy;
1132 dbus_bool_t requested_reply;
1134 type = dbus_message_get_type (message);
1136 /* dispatch.c was supposed to ensure these invariants */
1137 _dbus_assert (dbus_message_get_destination (message) != NULL ||
1138 type == DBUS_MESSAGE_TYPE_SIGNAL ||
1139 (sender == NULL && !bus_connection_is_active (proposed_recipient)));
1140 _dbus_assert (type == DBUS_MESSAGE_TYPE_SIGNAL ||
1141 addressed_recipient != NULL ||
1142 strcmp (dbus_message_get_destination (message), DBUS_SERVICE_DBUS) == 0);
1146 case DBUS_MESSAGE_TYPE_METHOD_CALL:
1147 case DBUS_MESSAGE_TYPE_SIGNAL:
1148 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1149 case DBUS_MESSAGE_TYPE_ERROR:
1153 _dbus_verbose ("security check disallowing message of unknown type %d\n",
1156 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1157 "Message bus will not accept messages of unknown type\n");
1162 requested_reply = FALSE;
1168 dest = dbus_message_get_destination (message);
1170 /* First verify the SELinux access controls. If allowed then
1171 * go on with the standard checks.
1173 if (!bus_selinux_allows_send (sender, proposed_recipient,
1174 dbus_message_type_to_string (dbus_message_get_type (message)),
1175 dbus_message_get_interface (message),
1176 dbus_message_get_member (message),
1177 dbus_message_get_error_name (message),
1178 dest ? dest : DBUS_SERVICE_DBUS, error))
1181 if (dbus_error_is_set (error) &&
1182 dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
1188 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1189 "An SELinux policy prevents this sender "
1190 "from sending this message to this recipient "
1191 "(rejected message had interface \"%s\" "
1192 "member \"%s\" error name \"%s\" destination \"%s\")",
1193 dbus_message_get_interface (message) ?
1194 dbus_message_get_interface (message) : "(unset)",
1195 dbus_message_get_member (message) ?
1196 dbus_message_get_member (message) : "(unset)",
1197 dbus_message_get_error_name (message) ?
1198 dbus_message_get_error_name (message) : "(unset)",
1199 dest ? dest : DBUS_SERVICE_DBUS);
1200 _dbus_verbose ("SELinux security check denying send to service\n");
1204 if (bus_connection_is_active (sender))
1206 sender_policy = bus_connection_get_policy (sender);
1207 _dbus_assert (sender_policy != NULL);
1209 /* Fill in requested_reply variable with TRUE if this is a
1210 * reply and the reply was pending.
1212 if (dbus_message_get_reply_serial (message) != 0)
1214 if (proposed_recipient != NULL /* not to the bus driver */ &&
1215 addressed_recipient == proposed_recipient /* not eavesdropping */)
1219 dbus_error_init (&error2);
1220 requested_reply = bus_connections_check_reply (bus_connection_get_connections (sender),
1222 sender, addressed_recipient, message,
1224 if (dbus_error_is_set (&error2))
1226 dbus_move_error (&error2, error);
1234 /* Policy for inactive connections is that they can only send
1235 * the hello message to the bus driver
1237 if (proposed_recipient == NULL &&
1238 dbus_message_is_method_call (message,
1239 DBUS_INTERFACE_DBUS,
1242 _dbus_verbose ("security check allowing %s message\n",
1248 _dbus_verbose ("security check disallowing non-%s message\n",
1251 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1252 "Client tried to send a message other than %s without being registered",
1261 sender_policy = NULL;
1263 /* If the sender is the bus driver, we assume any reply was a
1264 * requested reply as bus driver won't send bogus ones
1266 if (addressed_recipient == proposed_recipient /* not eavesdropping */ &&
1267 dbus_message_get_reply_serial (message) != 0)
1268 requested_reply = TRUE;
1271 _dbus_assert ((sender != NULL && sender_policy != NULL) ||
1272 (sender == NULL && sender_policy == NULL));
1274 if (proposed_recipient != NULL)
1276 /* only the bus driver can send to an inactive recipient (as it
1277 * owns no services, so other apps can't address it). Inactive
1278 * recipients can receive any message.
1280 if (bus_connection_is_active (proposed_recipient))
1282 recipient_policy = bus_connection_get_policy (proposed_recipient);
1283 _dbus_assert (recipient_policy != NULL);
1285 else if (sender == NULL)
1287 _dbus_verbose ("security check using NULL recipient policy for message from bus\n");
1288 recipient_policy = NULL;
1292 _dbus_assert_not_reached ("a message was somehow sent to an inactive recipient from a source other than the message bus\n");
1293 recipient_policy = NULL;
1297 recipient_policy = NULL;
1299 _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) ||
1300 (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) ||
1301 (proposed_recipient == NULL && recipient_policy == NULL));
1303 if (sender_policy &&
1304 !bus_client_policy_check_can_send (sender_policy,
1312 dest = dbus_message_get_destination (message);
1313 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1314 "A security policy in place prevents this sender "
1315 "from sending this message to this recipient, "
1316 "see message bus configuration file (rejected message "
1317 "had interface \"%s\" member \"%s\" error name \"%s\" destination \"%s\")",
1318 dbus_message_get_interface (message) ?
1319 dbus_message_get_interface (message) : "(unset)",
1320 dbus_message_get_member (message) ?
1321 dbus_message_get_member (message) : "(unset)",
1322 dbus_message_get_error_name (message) ?
1323 dbus_message_get_error_name (message) : "(unset)",
1324 dest ? dest : DBUS_SERVICE_DBUS);
1325 _dbus_verbose ("security policy disallowing message due to sender policy\n");
1329 if (recipient_policy &&
1330 !bus_client_policy_check_can_receive (recipient_policy,
1334 addressed_recipient, proposed_recipient,
1339 dest = dbus_message_get_destination (message);
1340 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1341 "A security policy in place prevents this recipient "
1342 "from receiving this message from this sender, "
1343 "see message bus configuration file (rejected message "
1344 "had interface \"%s\" member \"%s\" error name \"%s\" destination \"%s\" reply serial %u requested_reply=%d)",
1345 dbus_message_get_interface (message) ?
1346 dbus_message_get_interface (message) : "(unset)",
1347 dbus_message_get_member (message) ?
1348 dbus_message_get_member (message) : "(unset)",
1349 dbus_message_get_error_name (message) ?
1350 dbus_message_get_error_name (message) : "(unset)",
1351 dest ? dest : DBUS_SERVICE_DBUS,
1352 dbus_message_get_reply_serial (message),
1354 _dbus_verbose ("security policy disallowing message due to recipient policy\n");
1358 /* See if limits on size have been exceeded */
1359 if (proposed_recipient &&
1360 dbus_connection_get_outgoing_size (proposed_recipient) >
1361 context->limits.max_outgoing_bytes)
1365 dest = dbus_message_get_destination (message);
1366 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1367 "The destination service \"%s\" has a full message queue",
1368 dest ? dest : (proposed_recipient ?
1369 bus_connection_get_name (proposed_recipient) :
1370 DBUS_SERVICE_DBUS));
1371 _dbus_verbose ("security policy disallowing message due to full message queue\n");
1375 /* Record that we will allow a reply here in the future (don't
1376 * bother if the recipient is the bus or this is an eavesdropping
1377 * connection). Only the addressed recipient may reply.
1379 if (type == DBUS_MESSAGE_TYPE_METHOD_CALL &&
1381 addressed_recipient &&
1382 addressed_recipient == proposed_recipient && /* not eavesdropping */
1383 !bus_connections_expect_reply (bus_connection_get_connections (sender),
1385 sender, addressed_recipient,
1388 _dbus_verbose ("Failed to record reply expectation or problem with the message expecting a reply\n");
1392 _dbus_verbose ("security policy allowing message\n");