X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bus%2Fbus.c;h=e1d9c8ca0d6c7292d23280cd415348b96f889961;hb=7d9239c9c78cb6d0b9c282376fcf3cda1de23209;hp=19436f9a1bbd1d99ef4ca40767dceac93b1e4ab3;hpb=be07ce63621701f1ebebec23436c9e2b61d1d4ec;p=platform%2Fupstream%2Fdbus.git diff --git a/bus/bus.c b/bus/bus.c index 19436f9..e1d9c8c 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -2,6 +2,7 @@ /* bus.c message bus context object * * Copyright (C) 2003, 2004 Red Hat, Inc. + * Copyright (C) 2013 Samsung Electronics * * Licensed under the Academic Free License version 2.1 * @@ -23,6 +24,9 @@ #include #include "bus.h" + +#include + #include "activation.h" #include "connection.h" #include "services.h" @@ -36,6 +40,12 @@ #include #include #include + +#ifdef ENABLE_KDBUS_TRANSPORT +#include "kdbus-d.h" +#include +#endif + #ifdef DBUS_CYGWIN #include #endif @@ -64,6 +74,9 @@ struct BusContext unsigned int keep_umask : 1; unsigned int allow_anonymous : 1; unsigned int systemd_activation : 1; +#ifdef ENABLE_KDBUS_TRANSPORT + DBusConnection *myKdbusConnection; //todo maybe can be rafctored and removed +#endif }; static dbus_int32_t server_data_slot = -1; @@ -99,19 +112,6 @@ server_get_context (DBusServer *server) } static dbus_bool_t -server_watch_callback (DBusWatch *watch, - unsigned int condition, - void *data) -{ - /* FIXME this can be done in dbus-mainloop.c - * if the code in activation.c for the babysitter - * watch handler is fixed. - */ - - return dbus_watch_handle (watch, condition); -} - -static dbus_bool_t add_server_watch (DBusWatch *watch, void *data) { @@ -120,9 +120,7 @@ add_server_watch (DBusWatch *watch, context = server_get_context (server); - return _dbus_loop_add_watch (context->loop, - watch, server_watch_callback, server, - NULL); + return _dbus_loop_add_watch (context->loop, watch); } static void @@ -134,17 +132,19 @@ remove_server_watch (DBusWatch *watch, context = server_get_context (server); - _dbus_loop_remove_watch (context->loop, - watch, server_watch_callback, server); + _dbus_loop_remove_watch (context->loop, watch); } - static void -server_timeout_callback (DBusTimeout *timeout, - void *data) +toggle_server_watch (DBusWatch *watch, + void *data) { - /* can return FALSE on OOM but we just let it fire again later */ - dbus_timeout_handle (timeout); + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + _dbus_loop_toggle_watch (context->loop, watch); } static dbus_bool_t @@ -156,8 +156,7 @@ add_server_timeout (DBusTimeout *timeout, context = server_get_context (server); - return _dbus_loop_add_timeout (context->loop, - timeout, server_timeout_callback, server, NULL); + return _dbus_loop_add_timeout (context->loop, timeout); } static void @@ -169,8 +168,7 @@ remove_server_timeout (DBusTimeout *timeout, context = server_get_context (server); - _dbus_loop_remove_timeout (context->loop, - timeout, server_timeout_callback, server); + _dbus_loop_remove_timeout (context->loop, timeout); } static void @@ -251,7 +249,7 @@ setup_server (BusContext *context, if (!dbus_server_set_watch_functions (server, add_server_watch, remove_server_watch, - NULL, + toggle_server_watch, server, NULL)) { @@ -280,7 +278,7 @@ static dbus_bool_t process_config_first_time_only (BusContext *context, BusConfigParser *parser, const DBusString *address, - dbus_bool_t systemd_activation, + BusContextFlags flags, DBusError *error) { DBusString log_prefix; @@ -296,15 +294,24 @@ process_config_first_time_only (BusContext *context, retval = FALSE; auth_mechanisms = NULL; + pidfile = NULL; - context->systemd_activation = systemd_activation; + _dbus_init_system_log (TRUE); + + if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION) + context->systemd_activation = TRUE; + else + context->systemd_activation = FALSE; /* Check for an existing pid file. Of course this is a race; * we'd have to use fcntl() locks on the pid file to * avoid that. But we want to check for the pid file * before overwriting any existing sockets, etc. */ - pidfile = bus_config_parser_get_pidfile (parser); + + if (flags & BUS_CONTEXT_FLAG_WRITE_PID_FILE) + pidfile = bus_config_parser_get_pidfile (parser); + if (pidfile != NULL) { DBusString u; @@ -413,6 +420,7 @@ process_config_first_time_only (BusContext *context, if (auth_mechanisms[i] == NULL) goto oom; link = _dbus_list_get_next_link (auth_mechanisms_list, link); + i += 1; } } else @@ -424,22 +432,61 @@ process_config_first_time_only (BusContext *context, if (address) { - DBusServer *server; - - server = dbus_server_listen (_dbus_string_get_const_data(address), error); - if (server == NULL) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - goto failed; - } - else if (!setup_server (context, server, auth_mechanisms, error)) +#ifdef ENABLE_KDBUS_TRANSPORT + if(!strcmp(_dbus_string_get_const_data(address), "kdbus")) + { + DBusBusType type; + DBusServer* server; + char* bus_address; + + if(!strcmp (context->type, "system")) + type = DBUS_BUS_SYSTEM; + else if(!strcmp (context->type, "session")) + type = DBUS_BUS_SESSION; + else + type = DBUS_BUS_STARTER; + + bus_address = make_kdbus_bus(type, error); + if(bus_address == NULL) + goto failed; + + server = empty_server_init(bus_address); + if(server == NULL) + { + free(bus_address); + goto failed; + } + + if (!_dbus_list_append (&context->servers, server)) + { + free(bus_address); + goto oom; + } + + context->myKdbusConnection = daemon_as_client(type, bus_address, error); + if(context->myKdbusConnection == NULL) + goto failed; + } + else +#endif { - _DBUS_ASSERT_ERROR_IS_SET (error); - goto failed; - } - - if (!_dbus_list_append (&context->servers, server)) - goto oom; + DBusServer *server; + + server = dbus_server_listen (_dbus_string_get_const_data(address), error); + if (server == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + else if (!setup_server (context, server, auth_mechanisms, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (!_dbus_list_append (&context->servers, server)) + goto oom; + } } else { @@ -502,7 +549,6 @@ process_config_every_time (BusContext *context, DBusString full_address; DBusList *link; DBusList **dirs; - BusActivation *new_activation; char *addr; const char *servicehelper; char *s; @@ -702,17 +748,18 @@ process_config_postinit (BusContext *context, BusContext* bus_context_new (const DBusString *config_file, - ForceForkSetting force_fork, + BusContextFlags flags, DBusPipe *print_addr_pipe, DBusPipe *print_pid_pipe, const DBusString *address, - dbus_bool_t systemd_activation, DBusError *error) { - DBusString log_prefix; BusContext *context; BusConfigParser *parser; + _dbus_assert ((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 || + (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS) == 0); + _DBUS_ASSERT_ERROR_IS_CLEAR (error); context = NULL; @@ -732,6 +779,10 @@ bus_context_new (const DBusString *config_file, } context->refcount = 1; +#ifdef ENABLE_KDBUS_TRANSPORT + context->myKdbusConnection = NULL; +#endif + _dbus_generate_uuid (&context->uuid); if (!_dbus_string_copy_data (config_file, &context->config_file)) @@ -761,7 +812,7 @@ bus_context_new (const DBusString *config_file, goto failed; } - if (!process_config_first_time_only (context, parser, address, systemd_activation, error)) + if (!process_config_first_time_only (context, parser, address, flags, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); goto failed; @@ -856,7 +907,8 @@ bus_context_new (const DBusString *config_file, if (context->pidfile) _dbus_string_init_const (&u, context->pidfile); - if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS) + if (((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 && context->fork) || + (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS)) { _dbus_verbose ("Forking and becoming daemon\n"); @@ -928,6 +980,39 @@ bus_context_new (const DBusString *config_file, dbus_server_free_data_slot (&server_data_slot); +#ifdef ENABLE_KDBUS_TRANSPORT + if(context->myKdbusConnection) + { + DBusString unique_name; + + if(!bus_connections_setup_connection(context->connections, context->myKdbusConnection)) + { + _dbus_verbose ("Bus connections setup connection failed for myKdbusConnection!\n"); + dbus_connection_close (context->myKdbusConnection); + dbus_connection_unref (context->myKdbusConnection); + goto failed; + } + dbus_connection_set_route_peer_messages (context->myKdbusConnection, FALSE); + _dbus_string_init_const (&unique_name, ":1.1"); //dbus_bus_get_unique_name(context->myConnection)); this is without :1. + if(!bus_connection_complete (context->myKdbusConnection, &unique_name, error)) + { + _dbus_verbose ("Bus connection complete failed for myKdbusConnection!\n"); + goto failed; + } + + if(!register_daemon_name(context->myKdbusConnection)) + { + _dbus_verbose ("Registering org.freedesktop.DBus name for daemon failed!\n"); + goto failed; + } + if(!register_kdbus_starters(context->myKdbusConnection)) + { + _dbus_verbose ("Registering kdbus starters for dbus activatable names failed!\n"); + goto failed; + } + } +#endif + return context; failed: @@ -979,6 +1064,19 @@ bus_context_reload_config (BusContext *context, _DBUS_ASSERT_ERROR_IS_SET (error); goto failed; } + +#ifdef ENABLE_KDBUS_TRANSPORT + if(context->myKdbusConnection) + { + if(!update_kdbus_starters(context->myKdbusConnection)) + { + _dbus_verbose ("Update kdbus starters for dbus activatable names failed.\n"); + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + } +#endif + ret = TRUE; bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration"); @@ -1175,6 +1273,13 @@ bus_context_get_loop (BusContext *context) return context->loop; } +#ifdef ENABLE_KDBUS_TRANSPORT +DBusConnection* bus_context_get_myConnection(BusContext *context) +{ + return context->myKdbusConnection; +} +#endif + dbus_bool_t bus_context_allow_unix_user (BusContext *context, unsigned long uid) @@ -1272,6 +1377,13 @@ bus_context_get_reply_timeout (BusContext *context) return context->limits.reply_timeout; } +#ifdef ENABLE_KDBUS_TRANSPORT +dbus_bool_t bus_context_is_kdbus(BusContext* context) +{ + return context->myKdbusConnection != NULL; +} +#endif + void bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (3, 4); @@ -1281,7 +1393,14 @@ bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char va_list args; if (!context->syslog) - return; + { + /* we're not syslogging; just output to stderr */ + va_start (args, msg); + vfprintf (stderr, msg, args); + fprintf (stderr, "\n"); + va_end (args); + return; + } va_start (args, msg); @@ -1319,6 +1438,7 @@ nonnull (const char *maybe_null, */ static void complain_about_message (BusContext *context, + const char *error_name, const char *complaint, int matched_rules, DBusMessage *message, @@ -1333,7 +1453,7 @@ complain_about_message (BusContext *context, const char *sender_loginfo; const char *proposed_recipient_loginfo; - if (error == NULL && !(context->syslog && log)) + if (error == NULL && !log) return; if (sender != NULL) @@ -1352,7 +1472,7 @@ complain_about_message (BusContext *context, else proposed_recipient_loginfo = "bus"; - dbus_set_error (&stack_error, DBUS_ERROR_ACCESS_DENIED, + dbus_set_error (&stack_error, error_name, "%s, %d matched rules; type=\"%s\", sender=\"%s\" (%s) " "interface=\"%s\" member=\"%s\" error name=\"%s\" " "requested_reply=\"%d\" destination=\"%s\" (%s)", @@ -1406,9 +1526,6 @@ bus_context_check_security_policy (BusContext *context, dbus_bool_t log; int type; dbus_bool_t requested_reply; - const char *sender_name; - const char *sender_loginfo; - const char *proposed_recipient_loginfo; type = dbus_message_get_type (message); dest = dbus_message_get_destination (message); @@ -1457,7 +1574,7 @@ bus_context_check_security_policy (BusContext *context, { /* don't syslog this, just set the error: avc_has_perm should * have already written to either the audit log or syslog */ - complain_about_message (context, + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, "An SELinux policy prevents this sender from sending this " "message to this recipient", 0, message, sender, proposed_recipient, FALSE, FALSE, error); @@ -1574,10 +1691,8 @@ bus_context_check_security_policy (BusContext *context, proposed_recipient, message, &toggles, &log)) { - const char *msg = "Rejected send message, %d matched rules; " - "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))"; - - complain_about_message (context, "Rejected send message", toggles, + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "Rejected send message", toggles, message, sender, proposed_recipient, requested_reply, (addressed_recipient == proposed_recipient), error); _dbus_verbose ("security policy disallowing message due to sender policy\n"); @@ -1588,7 +1703,8 @@ bus_context_check_security_policy (BusContext *context, { /* We want to drop this message, and are only not doing so for backwards * compatibility. */ - complain_about_message (context, "Would reject message", toggles, + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "Would reject message", toggles, message, sender, proposed_recipient, requested_reply, TRUE, NULL); } @@ -1601,7 +1717,8 @@ bus_context_check_security_policy (BusContext *context, addressed_recipient, proposed_recipient, message, &toggles)) { - complain_about_message (context, "Rejected receive message", toggles, + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "Rejected receive message", toggles, message, sender, proposed_recipient, requested_reply, (addressed_recipient == proposed_recipient), NULL); _dbus_verbose ("security policy disallowing message due to recipient policy\n"); @@ -1613,11 +1730,10 @@ bus_context_check_security_policy (BusContext *context, ((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", - dest ? dest : (proposed_recipient ? - bus_connection_get_name (proposed_recipient) : - DBUS_SERVICE_DBUS)); + complain_about_message (context, DBUS_ERROR_LIMITS_EXCEEDED, + "Rejected: destination has a full message queue", + 0, message, sender, proposed_recipient, requested_reply, TRUE, + error); _dbus_verbose ("security policy disallowing message due to full message queue\n"); return FALSE; }