{
DBusString unique_name;
- bus_connections_setup_connection(context->connections, context->myKdbusConnection);
+ 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_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 kdbus!\n");
- _dbus_string_free(&unique_name);
+ _dbus_verbose ("Bus connection complete failed for myKdbusConnection!\n");
goto failed;
}
- _dbus_string_free(&unique_name);
+ 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");
_dbus_string_init_const (&service_string, service_name);
service = bus_registry_lookup (registry, &service_string);
- if (service == NULL && dbus_message_get_auto_start (message))
+ if (dbus_message_get_auto_start (message) && (service == NULL || bus_service_get_is_kdbus_starter(service)))
{
BusActivation *activation;
/* We can't do the security policy check here, since the addressed
DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *error)
{
DBusConnection* connection;
- DBusString daemon_name;
dbus_bus_set_bus_connection_address(type, address);
if(connection == NULL)
return NULL;
- _dbus_string_init_const(&daemon_name, DBUS_SERVICE_DBUS);
- if(!kdbus_register_policy (&daemon_name, connection))
- goto failed;
-
- if(kdbus_request_name(connection, &daemon_name, 0, 0) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
- goto failed;
-
- if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "member='IdRemoved'"))
+ if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "member='IdRemoved'"))
{
dbus_set_error (error, _dbus_error_from_errno (errno), "Could not add match for id:1, %s", _dbus_strerror_from_errno ());
- return FALSE;
+ goto failed;
}
if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "member='NameChanged'"))
{
dbus_set_error (error, _dbus_error_from_errno (errno), "Could not add match for id:1, %s", _dbus_strerror_from_errno ());
- return FALSE;
+ goto failed;
}
if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "member='NameLost'"))
{
dbus_set_error (error, _dbus_error_from_errno (errno), "Could not add match for id:1, %s", _dbus_strerror_from_errno ());
- return FALSE;
+ goto failed;
}
if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "member='NameAcquired'"))
{
dbus_set_error (error, _dbus_error_from_errno (errno), "Could not add match for id:1, %s", _dbus_strerror_from_errno ());
- return FALSE;
+ goto failed;
}
if(dbus_error_is_set(error))
return connection;
}
+dbus_bool_t register_daemon_name(DBusConnection* connection)
+{
+ DBusString daemon_name;
+ dbus_bool_t retval = FALSE;
+ BusTransaction *transaction;
+
+ _dbus_string_init_const(&daemon_name, DBUS_SERVICE_DBUS);
+ if(!kdbus_register_policy (&daemon_name, connection))
+ return FALSE;
+
+ if(kdbus_request_name(connection, &daemon_name, 0, 0) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+ return FALSE;
+
+ transaction = bus_transaction_new (bus_connection_get_context(connection));
+ if (transaction == NULL)
+ {
+ kdbus_release_name(connection, &daemon_name, 0);
+ goto out;
+ }
+
+ if(!bus_registry_ensure (bus_connection_get_registry (connection), &daemon_name, connection, 0, transaction, NULL))
+ {
+ kdbus_release_name(connection, &daemon_name, 0);
+ goto out;
+ }
+
+ retval = TRUE;
+
+out:
+ bus_transaction_free(transaction);
+ return retval;
+}
+
dbus_bool_t kdbus_register_policy (const DBusString *service_name, DBusConnection* connection)
{
int fd;
if (!bus_activation_list_services (bus_connection_get_activation (connection), &services, &len))
return FALSE;
- _dbus_transport_get_socket_fd(dbus_connection_get_transport(connection), &fd);
+ _dbus_transport_get_socket_fd (dbus_connection_get_transport(connection), &fd);
_dbus_string_init(&name);
for(i=0; i<len; i++)
services_old = bus_connection_get_services_owned(connection);
link = _dbus_list_get_first_link(services_old);
+ link = _dbus_list_get_next_link (services_old, link); //skip org.freedesktop.DBus which is not starter
while (link != NULL)
{
char* make_kdbus_bus(DBusBusType type, DBusError *error);
DBusServer* empty_server_init(char* address);
DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *error);
+dbus_bool_t register_daemon_name(DBusConnection* connection);
dbus_bool_t kdbus_register_policy (const DBusString *service_name, DBusConnection* connection);
dbus_uint32_t kdbus_request_name(DBusConnection* connection, const DBusString *service_name, dbus_uint32_t flags, __u64 sender_id);
dbus_uint32_t kdbus_release_name(DBusConnection* connection, const DBusString *service_name, __u64 sender_id);
#include "bus.h"
#include "selinux.h"
#include "kdbus-d.h"
+#include "dbus/kdbus.h"
struct BusService
{
unsigned int allow_replacement : 1;
unsigned int do_not_queue : 1;
+ unsigned int is_kdbus_starter : 1;
};
struct BusRegistry
owner->do_not_queue =
(flags & DBUS_NAME_FLAG_DO_NOT_QUEUE) != FALSE;
+
+ owner->is_kdbus_starter =
+ (flags & KDBUS_NAME_STARTER) != FALSE;
}
static BusOwner *
dbus_bool_t retval;
BusService *service;
BusActivation *activation;
-
DBusString service_name_real;
const DBusString *service_name = &service_name_real;
char* name;
dbus_uint32_t flags;
__u64 sender_id;
+ dbus_bool_t rm_owner_daemon = FALSE;
if (!dbus_message_get_args (message, error,
DBUS_TYPE_STRING, &name,
if (service == NULL)
goto out;
+ rm_owner_daemon = TRUE;
if(!kdbus_register_policy(service_name, connection))
{
dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
{
DBusConnection* phantom;
const char* name;
+// DBusList *link;
name = dbus_message_get_sender(message);
phantom = bus_connections_find_conn_by_name(bus_connection_get_connections(connection), name);
goto failed2;
if (!bus_service_add_owner (service, phantom, flags, transaction, error))
goto failed2;
- if(*result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+ if((*result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) && rm_owner_daemon)
{
/* Here we are removing DBus daemon as an owner of the service,
* which is set by bus_registry_ensure.
if(_bus_service_find_owner_link (service, connection))
bus_service_remove_owner (service, connection, transaction, NULL);
}
+ /*if(bus_service_get_is_kdbus_starter(service))
+ {
+ if (!bus_service_swap_owner (service, bus_service_get_primary_owners_connection(service),
+ transaction, error))
+ goto failed2;
+ }*/
+ /* if((link = _bus_service_find_owner_link (service, connection))) //if daemon is a starter
+ {
+ _dbus_list_unlink (&service->owners, link);
+ _dbus_list_append_link (&service->owners, link); //it must be moved at the end of the queue
+ }*/
}
activation = bus_context_get_activation (registry->context);
}
dbus_bool_t
+bus_service_get_is_kdbus_starter (BusService *service)
+{
+ BusOwner *owner;
+ DBusList *link;
+
+ _dbus_assert (service->owners != NULL);
+
+ link = _dbus_list_get_first_link (&service->owners);
+ owner = (BusOwner *) link->data;
+
+ return owner->is_kdbus_starter;
+}
+
+dbus_bool_t
bus_service_has_owner (BusService *service,
DBusConnection *connection)
{
owner = (BusOwner *) link->data;
uname = bus_connection_get_name (owner->conn);
- if (!_dbus_list_append (return_list, (char *)uname))
- goto oom;
+ if(!owner->is_kdbus_starter)
+ if (!_dbus_list_append (return_list, (char *)uname))
+ goto oom;
link = _dbus_list_get_next_link (&service->owners, link);
}
DBusConnection *connection);
BusOwner* bus_service_get_primary_owner (BusService *service);
dbus_bool_t bus_service_get_allow_replacement (BusService *service);
+dbus_bool_t bus_service_get_is_kdbus_starter (BusService *service);
const char* bus_service_get_name (BusService *service);
dbus_bool_t bus_service_list_queued_owners (BusService *service,
DBusList **return_list,
message = _dbus_connection_get_message_to_send (transport->connection);
_dbus_assert (message != NULL);
-// if(dbus_message_get_sender(message) == NULL) //needed for daemon todo check if really needed
+ if(dbus_message_get_sender(message) == NULL) //needed for daemon to pass pending activation messages
{
dbus_message_unlock(message);
dbus_message_set_sender(message, socket_transport->sender);