diff options
author | Colin Walters <walters@verbum.org> | 2010-03-16 16:04:15 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-03-16 16:11:14 -0400 |
commit | ebfa7c02fd67777684d39389e25346819836dcca (patch) | |
tree | 93c2b9876ce960cbf2fa27dad9fb017184b7610b /bus/bus.c | |
parent | acbc751e28446696fee92c236cfef176786409d5 (diff) | |
parent | ce34415302af586ea6ca9b0da4b21a7025041ef7 (diff) | |
download | dbus-ebfa7c02fd67777684d39389e25346819836dcca.tar.gz |
Merge branch 'dbus-1.2'
Conflicts:
bus/bus.c
configure.in
Diffstat (limited to 'bus/bus.c')
-rw-r--r-- | bus/bus.c | 168 |
1 files changed, 98 insertions, 70 deletions
@@ -33,6 +33,7 @@ #include "dir-watch.h" #include <dbus/dbus-list.h> #include <dbus/dbus-hash.h> +#include <dbus/dbus-credentials.h> #include <dbus/dbus-internals.h> struct BusContext @@ -45,6 +46,7 @@ struct BusContext char *address; char *pidfile; char *user; + char *log_prefix; DBusLoop *loop; DBusList *servers; BusConnections *connections; @@ -274,6 +276,7 @@ process_config_first_time_only (BusContext *context, BusConfigParser *parser, DBusError *error) { + DBusString log_prefix; DBusList *link; DBusList **addresses; const char *user, *pidfile; @@ -299,21 +302,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); @@ -323,21 +366,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); } } @@ -368,44 +405,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 @@ -609,6 +629,7 @@ bus_context_new (const DBusString *config_file, DBusPipe *print_pid_pipe, DBusError *error) { + DBusString log_prefix; BusContext *context; BusConfigParser *parser; @@ -793,9 +814,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); @@ -880,10 +901,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; @@ -993,8 +1014,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); @@ -1165,28 +1187,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); } @@ -1429,8 +1457,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)", @@ -1449,7 +1477,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, @@ -1493,8 +1521,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)", |