X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bus%2Fbus.c;h=81d69b569721b583e71e49f761989ae4ebc3e7a5;hb=dbecdeabb20e0ce11121819c63373f0afba57c58;hp=bfd398e6389cebecb88896585d441583aead87e9;hpb=8a9880ffd2b81df38bb0e3492bda7a9636ac0280;p=platform%2Fupstream%2Fdbus.git diff --git a/bus/bus.c b/bus/bus.c index bfd398e..81d69b5 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -21,6 +21,7 @@ * */ +#include #include "bus.h" #include "activation.h" #include "connection.h" @@ -33,6 +34,7 @@ #include "dir-watch.h" #include #include +#include #include struct BusContext @@ -45,6 +47,7 @@ struct BusContext char *address; char *pidfile; char *user; + char *log_prefix; DBusLoop *loop; DBusList *servers; BusConnections *connections; @@ -56,6 +59,7 @@ struct BusContext unsigned int fork : 1; unsigned int syslog : 1; unsigned int keep_umask : 1; + unsigned int allow_anonymous : 1; }; static dbus_int32_t server_data_slot = -1; @@ -189,7 +193,16 @@ new_connection_callback (DBusServer *server, dbus_connection_set_max_message_size (new_connection, context->limits.max_message_size); + + dbus_connection_set_max_received_unix_fds (new_connection, + context->limits.max_incoming_unix_fds); + + dbus_connection_set_max_message_unix_fds (new_connection, + context->limits.max_message_unix_fds); + dbus_connection_set_allow_anonymous (new_connection, + context->allow_anonymous); + /* on OOM, we won't have ref'd the connection so it will die. */ } @@ -264,6 +277,7 @@ process_config_first_time_only (BusContext *context, BusConfigParser *parser, DBusError *error) { + DBusString log_prefix; DBusList *link; DBusList **addresses; const char *user, *pidfile; @@ -289,21 +303,61 @@ process_config_first_time_only (BusContext *context, DBusStat stbuf; _dbus_string_init_const (&u, pidfile); - + if (_dbus_stat (&u, &stbuf, NULL)) - { - dbus_set_error (error, DBUS_ERROR_FAILED, - "The pid file \"%s\" exists, if the message bus is not running, remove this file", - pidfile); - goto failed; - } + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "The pid file \"%s\" exists, if the message bus is not running, remove this file", + pidfile); + goto failed; + } } - + /* keep around the pid filename so we can delete it later */ context->pidfile = _dbus_strdup (pidfile); + /* note that type may be NULL */ + context->type = _dbus_strdup (bus_config_parser_get_type (parser)); + if (bus_config_parser_get_type (parser) != NULL && context->type == NULL) + goto oom; + + user = bus_config_parser_get_user (parser); + if (user != NULL) + { + context->user = _dbus_strdup (user); + if (context->user == NULL) + goto oom; + } + + /* Set up the prefix for syslog messages */ + if (!_dbus_string_init (&log_prefix)) + goto oom; + if (context->type && !strcmp (context->type, "system")) + { + if (!_dbus_string_append (&log_prefix, "[system] ")) + goto oom; + } + else if (context->type && !strcmp (context->type, "session")) + { + DBusCredentials *credentials; + + credentials = _dbus_credentials_new_from_current_process (); + if (!credentials) + goto oom; + if (!_dbus_string_append (&log_prefix, "[session ")) + goto oom; + if (!_dbus_credentials_to_string_append (credentials, &log_prefix)) + goto oom; + if (!_dbus_string_append (&log_prefix, "] ")) + goto oom; + _dbus_credentials_unref (credentials); + } + if (!_dbus_string_steal_data (&log_prefix, &context->log_prefix)) + goto oom; + _dbus_string_free (&log_prefix); + /* Build an array of auth mechanisms */ - + auth_mechanisms_list = bus_config_parser_get_mechanisms (parser); len = _dbus_list_get_length (auth_mechanisms_list); @@ -313,21 +367,15 @@ process_config_first_time_only (BusContext *context, auth_mechanisms = dbus_new0 (char*, len + 1); if (auth_mechanisms == NULL) - { - BUS_SET_OOM (error); - goto failed; - } - + goto oom; + i = 0; link = _dbus_list_get_first_link (auth_mechanisms_list); while (link != NULL) { auth_mechanisms[i] = _dbus_strdup (link->data); if (auth_mechanisms[i] == NULL) - { - BUS_SET_OOM (error); - goto failed; - } + goto oom; link = _dbus_list_get_next_link (auth_mechanisms_list, link); } } @@ -358,43 +406,27 @@ process_config_first_time_only (BusContext *context, } if (!_dbus_list_append (&context->servers, server)) - { - BUS_SET_OOM (error); - goto failed; - } - - link = _dbus_list_get_next_link (addresses, link); - } - - /* note that type may be NULL */ - context->type = _dbus_strdup (bus_config_parser_get_type (parser)); - if (bus_config_parser_get_type (parser) != NULL && context->type == NULL) - { - BUS_SET_OOM (error); - goto failed; - } + goto oom; - user = bus_config_parser_get_user (parser); - if (user != NULL) - { - context->user = _dbus_strdup (user); - if (context->user == NULL) - { - BUS_SET_OOM (error); - goto failed; - } + link = _dbus_list_get_next_link (addresses, link); } context->fork = bus_config_parser_get_fork (parser); context->syslog = bus_config_parser_get_syslog (parser); context->keep_umask = bus_config_parser_get_keep_umask (parser); - + context->allow_anonymous = bus_config_parser_get_allow_anonymous (parser); + _DBUS_ASSERT_ERROR_IS_CLEAR (error); retval = TRUE; failed: dbus_free_string_array (auth_mechanisms); return retval; + + oom: + BUS_SET_OOM (error); + dbus_free_string_array (auth_mechanisms); + return FALSE; } /* This code gets executed every time the config files @@ -529,11 +561,39 @@ process_config_every_time (BusContext *context, } static dbus_bool_t +list_concat_new (DBusList **a, + DBusList **b, + DBusList **result) +{ + DBusList *link; + + *result = NULL; + + link = _dbus_list_get_first_link (a); + for (link = _dbus_list_get_first_link (a); link; link = _dbus_list_get_next_link (a, link)) + { + if (!_dbus_list_append (result, link->data)) + goto oom; + } + for (link = _dbus_list_get_first_link (b); link; link = _dbus_list_get_next_link (b, link)) + { + if (!_dbus_list_append (result, link->data)) + goto oom; + } + + return TRUE; +oom: + _dbus_list_clear (result); + return FALSE; +} + +static dbus_bool_t process_config_postinit (BusContext *context, BusConfigParser *parser, DBusError *error) { DBusHashTable *service_context_table; + DBusList *watched_dirs = NULL; service_context_table = bus_config_parser_steal_service_context_table (parser); if (!bus_registry_set_service_context_table (context->registry, @@ -545,16 +605,22 @@ process_config_postinit (BusContext *context, _dbus_hash_table_unref (service_context_table); - /* Watch all conf directories */ - bus_set_watched_dirs (context, bus_config_parser_get_conf_dirs (parser)); + /* We need to monitor both the configuration directories and directories + * containing .service files. + */ + if (!list_concat_new (bus_config_parser_get_conf_dirs (parser), + bus_config_parser_get_service_dirs (parser), + &watched_dirs)) + { + BUS_SET_OOM (error); + return FALSE; + } - return TRUE; -} + bus_set_watched_dirs (context, &watched_dirs); -static void -bus_shutdown_all_directory_watches (void *data) -{ - bus_set_watched_dirs ((BusContext *) data, NULL); + _dbus_list_clear (&watched_dirs); + + return TRUE; } BusContext* @@ -564,6 +630,7 @@ bus_context_new (const DBusString *config_file, DBusPipe *print_pid_pipe, DBusError *error) { + DBusString log_prefix; BusContext *context; BusConfigParser *parser; @@ -588,8 +655,6 @@ bus_context_new (const DBusString *config_file, _dbus_generate_uuid (&context->uuid); - _dbus_register_shutdown_func (bus_shutdown_all_directory_watches, context); - if (!_dbus_string_copy_data (config_file, &context->config_file)) { BUS_SET_OOM (error); @@ -750,9 +815,9 @@ bus_context_new (const DBusString *config_file, if (!bus_selinux_full_init ()) { - _dbus_warn ("SELinux initialization failed\n"); + bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but AVC initialization failed; check system log\n"); } - + if (!process_config_postinit (context, parser, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); @@ -837,10 +902,10 @@ bus_context_reload_config (BusContext *context, } ret = TRUE; - bus_context_log_info (context, "Reloaded configuration"); - failed: + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration"); + failed: if (!ret) - bus_context_log_info (context, "Unable to reload configuration: %s", error->message); + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to reload configuration: %s", error->message); if (parser != NULL) bus_config_parser_unref (parser); return ret; @@ -950,8 +1015,9 @@ bus_context_unref (BusContext *context) bus_matchmaker_unref (context->matchmaker); context->matchmaker = NULL; } - + dbus_free (context->config_file); + dbus_free (context->log_prefix); dbus_free (context->type); dbus_free (context->address); dbus_free (context->user); @@ -1122,28 +1188,34 @@ bus_context_get_reply_timeout (BusContext *context) } void -bus_context_log_info (BusContext *context, const char *msg, ...) +bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) { va_list args; - va_start (args, msg); - - if (context->syslog) - _dbus_log_info (msg, args); - - va_end (args); -} - -void -bus_context_log_security (BusContext *context, const char *msg, ...) -{ - va_list args; + if (!context->syslog) + return; va_start (args, msg); - - if (context->syslog) - _dbus_log_security (msg, args); + if (context->log_prefix) + { + DBusString full_msg; + + if (!_dbus_string_init (&full_msg)) + goto out; + if (!_dbus_string_append (&full_msg, context->log_prefix)) + goto oom_out; + if (!_dbus_string_append_printf_valist (&full_msg, msg, args)) + goto oom_out; + + _dbus_system_log (severity, "%s", full_msg); + oom_out: + _dbus_string_free (&full_msg); + } + else + _dbus_system_logv (severity, msg, args); + +out: va_end (args); } @@ -1386,8 +1458,8 @@ bus_context_check_security_policy (BusContext *context, dest ? dest : DBUS_SERVICE_DBUS, proposed_recipient_loginfo); /* Needs to be duplicated to avoid calling malloc and having to handle OOM */ - if (addressed_recipient == proposed_recipient) - bus_context_log_security (context, msg, + if (addressed_recipient == proposed_recipient) + bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg, toggles, dbus_message_type_to_string (dbus_message_get_type (message)), sender_name ? sender_name : "(unset)", @@ -1406,7 +1478,7 @@ bus_context_check_security_policy (BusContext *context, } if (log) - bus_context_log_security (context, + bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, "Would reject message, %d matched rules; " "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))", toggles, @@ -1450,8 +1522,8 @@ bus_context_check_security_policy (BusContext *context, dest ? dest : DBUS_SERVICE_DBUS, proposed_recipient_loginfo); /* Needs to be duplicated to avoid calling malloc and having to handle OOM */ - if (addressed_recipient == proposed_recipient) - bus_context_log_security (context, msg, + if (addressed_recipient == proposed_recipient) + bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg, toggles, dbus_message_type_to_string (dbus_message_get_type (message)), sender_name ? sender_name : "(unset)", @@ -1472,8 +1544,8 @@ bus_context_check_security_policy (BusContext *context, /* See if limits on size have been exceeded */ if (proposed_recipient && - dbus_connection_get_outgoing_size (proposed_recipient) > - context->limits.max_outgoing_bytes) + ((dbus_connection_get_outgoing_size (proposed_recipient) > context->limits.max_outgoing_bytes) || + (dbus_connection_get_outgoing_unix_fds (proposed_recipient) > context->limits.max_outgoing_unix_fds))) { dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, "The destination service \"%s\" has a full message queue",