Commit 29c71168 authored by Havoc Pennington's avatar Havoc Pennington

2003-03-31 Havoc Pennington <hp@pobox.com>

	* dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket)
	(_dbus_transport_new_for_tcp_socket): these didn't need the "server"
	argument since they are always client side

	* dbus/dbus-server.c (dbus_server_get_address): new function

	* bus/main.c (main): take the configuration file as an argument.

	* test/data/valid-config-files/debug-allow-all.conf: new file to
	use with dispatch.c tests for example

	* bus/test-main.c (main): require test data dir

	* bus/bus.c (bus_context_new): change this to take a
	configuration file name as argument

	* doc/config-file.txt (Elements): add <servicedir>

	* bus/system.conf, bus/session.conf: new files

	* dbus/dbus-bus.c (dbus_bus_get): look for system bus on
	well-known socket if none set

	* configure.in: create system.conf and session.conf
parent bc86794f
2003-03-31 Havoc Pennington <hp@pobox.com>
* dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket)
(_dbus_transport_new_for_tcp_socket): these didn't need the "server"
argument since they are always client side
* dbus/dbus-server.c (dbus_server_get_address): new function
* bus/main.c (main): take the configuration file as an argument.
* test/data/valid-config-files/debug-allow-all.conf: new file to
use with dispatch.c tests for example
* bus/test-main.c (main): require test data dir
* bus/bus.c (bus_context_new): change this to take a
configuration file name as argument
* doc/config-file.txt (Elements): add <servicedir>
* bus/system.conf, bus/session.conf: new files
* dbus/dbus-bus.c (dbus_bus_get): look for system bus on
well-known socket if none set
* configure.in: create system.conf and session.conf
2003-03-30 Havoc Pennington <hp@pobox.com> 2003-03-30 Havoc Pennington <hp@pobox.com>
* bus/config-parser.c: hacking * bus/config-parser.c: hacking
......
...@@ -4,6 +4,12 @@ INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) \ ...@@ -4,6 +4,12 @@ INCLUDES=-I$(top_srcdir) $(DBUS_BUS_CFLAGS) \
EFENCE= EFENCE=
configdir=$(sysconfdir)/dbus-1
config_DATA= \
system.conf \
session.conf
bin_PROGRAMS=dbus-daemon-1 bin_PROGRAMS=dbus-daemon-1
if DBUS_USE_LIBXML if DBUS_USE_LIBXML
......
...@@ -323,10 +323,10 @@ load_directory (BusActivation *activation, ...@@ -323,10 +323,10 @@ load_directory (BusActivation *activation,
} }
BusActivation* BusActivation*
bus_activation_new (BusContext *context, bus_activation_new (BusContext *context,
const char *address, const DBusString *address,
const char **directories, const char **directories,
DBusError *error) DBusError *error)
{ {
int i; int i;
BusActivation *activation; BusActivation *activation;
...@@ -343,9 +343,7 @@ bus_activation_new (BusContext *context, ...@@ -343,9 +343,7 @@ bus_activation_new (BusContext *context,
activation->refcount = 1; activation->refcount = 1;
activation->context = context; activation->context = context;
/* FIXME: We should split up the server addresses. */ if (!_dbus_string_copy_data (address, &activation->server_address))
activation->server_address = _dbus_strdup (address);
if (activation->server_address == NULL)
{ {
BUS_SET_OOM (error); BUS_SET_OOM (error);
goto failed; goto failed;
......
...@@ -27,19 +27,20 @@ ...@@ -27,19 +27,20 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "bus.h" #include "bus.h"
BusActivation* bus_activation_new (BusContext *context, BusActivation* bus_activation_new (BusContext *context,
const char *address, const DBusString *address,
const char **paths, const char **paths,
DBusError *error); DBusError *error);
void bus_activation_ref (BusActivation *activation); void bus_activation_ref (BusActivation *activation);
void bus_activation_unref (BusActivation *activation); void bus_activation_unref (BusActivation *activation);
dbus_bool_t bus_activation_activate_service (BusActivation *activation, dbus_bool_t bus_activation_activate_service (BusActivation *activation,
DBusConnection *connection, DBusConnection *connection,
DBusMessage *activation_message, DBusMessage *activation_message,
const char *service_name, const char *service_name,
DBusError *error); DBusError *error);
dbus_bool_t bus_activation_service_created (BusActivation *activation, dbus_bool_t bus_activation_service_created (BusActivation *activation,
const char *service_name, const char *service_name,
DBusError *error); DBusError *error);
#endif /* BUS_ACTIVATION_H */ #endif /* BUS_ACTIVATION_H */
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "services.h" #include "services.h"
#include "utils.h" #include "utils.h"
#include "policy.h" #include "policy.h"
#include "config-parser.h"
#include <dbus/dbus-list.h> #include <dbus/dbus-list.h>
#include <dbus/dbus-hash.h> #include <dbus/dbus-hash.h>
#include <dbus/dbus-internals.h> #include <dbus/dbus-internals.h>
...@@ -36,7 +37,7 @@ struct BusContext ...@@ -36,7 +37,7 @@ struct BusContext
{ {
int refcount; int refcount;
char *address; char *address;
DBusServer *server; DBusList *servers;
BusConnections *connections; BusConnections *connections;
BusActivation *activation; BusActivation *activation;
BusRegistry *registry; BusRegistry *registry;
...@@ -51,24 +52,24 @@ server_watch_callback (DBusWatch *watch, ...@@ -51,24 +52,24 @@ server_watch_callback (DBusWatch *watch,
unsigned int condition, unsigned int condition,
void *data) void *data)
{ {
BusContext *context = data; DBusServer *server = data;
return dbus_server_handle_watch (context->server, watch, condition); return dbus_server_handle_watch (server, watch, condition);
} }
static dbus_bool_t static dbus_bool_t
add_server_watch (DBusWatch *watch, add_server_watch (DBusWatch *watch,
BusContext *context) void *data)
{ {
return bus_loop_add_watch (watch, server_watch_callback, context, return bus_loop_add_watch (watch, server_watch_callback, data,
NULL); NULL);
} }
static void static void
remove_server_watch (DBusWatch *watch, remove_server_watch (DBusWatch *watch,
BusContext *context) void *data)
{ {
bus_loop_remove_watch (watch, server_watch_callback, context); bus_loop_remove_watch (watch, server_watch_callback, data);
} }
...@@ -82,16 +83,16 @@ server_timeout_callback (DBusTimeout *timeout, ...@@ -82,16 +83,16 @@ server_timeout_callback (DBusTimeout *timeout,
static dbus_bool_t static dbus_bool_t
add_server_timeout (DBusTimeout *timeout, add_server_timeout (DBusTimeout *timeout,
BusContext *context) void *data)
{ {
return bus_loop_add_timeout (timeout, server_timeout_callback, context, NULL); return bus_loop_add_timeout (timeout, server_timeout_callback, data, NULL);
} }
static void static void
remove_server_timeout (DBusTimeout *timeout, remove_server_timeout (DBusTimeout *timeout,
BusContext *context) void *data)
{ {
bus_loop_remove_timeout (timeout, server_timeout_callback, context); bus_loop_remove_timeout (timeout, server_timeout_callback, data);
} }
static void static void
...@@ -137,37 +138,136 @@ free_rule_list_func (void *data) ...@@ -137,37 +138,136 @@ free_rule_list_func (void *data)
dbus_free (list); dbus_free (list);
} }
static dbus_bool_t
setup_server (BusContext *context,
DBusServer *server,
DBusError *error)
{
dbus_server_set_new_connection_function (server,
new_connection_callback,
context, NULL);
if (!dbus_server_set_watch_functions (server,
add_server_watch,
remove_server_watch,
NULL,
server,
NULL))
{
BUS_SET_OOM (error);
return FALSE;
}
if (!dbus_server_set_timeout_functions (server,
add_server_timeout,
remove_server_timeout,
NULL,
server, NULL))
{
BUS_SET_OOM (error);
return FALSE;
}
return TRUE;
}
BusContext* BusContext*
bus_context_new (const char *address, bus_context_new (const DBusString *config_file,
const char **service_dirs, DBusError *error)
DBusError *error)
{ {
BusContext *context; BusContext *context;
DBusList *link;
DBusList **addresses;
BusConfigParser *parser;
DBusString full_address;
const char *service_dirs[] = { NULL, NULL };
_DBUS_ASSERT_ERROR_IS_CLEAR (error); _DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!_dbus_string_init (&full_address, _DBUS_INT_MAX))
return NULL;
parser = NULL;
context = NULL;
parser = bus_config_load (config_file, error);
if (parser == NULL)
goto failed;
context = dbus_new0 (BusContext, 1); context = dbus_new0 (BusContext, 1);
if (context == NULL) if (context == NULL)
{ {
BUS_SET_OOM (error); BUS_SET_OOM (error);
return NULL; goto failed;
} }
context->refcount = 1; context->refcount = 1;
addresses = bus_config_parser_get_addresses (parser);
link = _dbus_list_get_first_link (addresses);
while (link != NULL)
{
DBusServer *server;
server = dbus_server_listen (link->data, error);
if (server == NULL)
goto failed;
else if (!setup_server (context, server, error))
goto failed;
context->address = _dbus_strdup (address); if (!_dbus_list_append (&context->servers, server))
if (context->address == NULL) {
BUS_SET_OOM (error);
goto failed;
}
link = _dbus_list_get_next_link (addresses, link);
}
/* We have to build the address backward, so that
* <listen> later in the config file have priority
*/
link = _dbus_list_get_last_link (&context->servers);
while (link != NULL)
{
char *addr;
addr = dbus_server_get_address (link->data);
if (addr == NULL)
{
BUS_SET_OOM (error);
goto failed;
}
if (_dbus_string_get_length (&full_address) > 0)
{
if (!_dbus_string_append (&full_address, ";"))
{
BUS_SET_OOM (error);
goto failed;
}
}
if (!_dbus_string_append (&full_address, addr))
{
BUS_SET_OOM (error);
goto failed;
}
dbus_free (addr);
link = _dbus_list_get_prev_link (&context->servers, link);
}
if (!_dbus_string_copy_data (&full_address, &context->address))
{ {
BUS_SET_OOM (error); BUS_SET_OOM (error);
goto failed; goto failed;
} }
context->server = dbus_server_listen (address, error); context->activation = bus_activation_new (context, &full_address,
if (context->server == NULL) service_dirs, error);
goto failed;
context->activation = bus_activation_new (context, address, service_dirs,
error);
if (context->activation == NULL) if (context->activation == NULL)
{ {
_DBUS_ASSERT_ERROR_IS_SET (error); _DBUS_ASSERT_ERROR_IS_SET (error);
...@@ -205,59 +305,58 @@ bus_context_new (const char *address, ...@@ -205,59 +305,58 @@ bus_context_new (const char *address,
BUS_SET_OOM (error); BUS_SET_OOM (error);
goto failed; goto failed;
} }
dbus_server_set_new_connection_function (context->server,
new_connection_callback,
context, NULL);
if (!dbus_server_set_watch_functions (context->server,
(DBusAddWatchFunction) add_server_watch,
(DBusRemoveWatchFunction) remove_server_watch,
NULL,
context,
NULL))
{
BUS_SET_OOM (error);
goto failed;
}
if (!dbus_server_set_timeout_functions (context->server, bus_config_parser_unref (parser);
(DBusAddTimeoutFunction) add_server_timeout, _dbus_string_free (&full_address);
(DBusRemoveTimeoutFunction) remove_server_timeout,
NULL,
context, NULL))
{
BUS_SET_OOM (error);
goto failed;
}
return context; return context;
failed: failed:
bus_context_unref (context); if (parser != NULL)
bus_config_parser_unref (parser);
if (context != NULL)
bus_context_unref (context);
_dbus_string_free (&full_address);
return NULL; return NULL;
} }
void static void
bus_context_shutdown (BusContext *context) shutdown_server (BusContext *context,
DBusServer *server)
{ {
if (context->server == NULL || if (server == NULL ||
!dbus_server_get_is_connected (context->server)) !dbus_server_get_is_connected (server))
return; return;
if (!dbus_server_set_watch_functions (context->server, if (!dbus_server_set_watch_functions (server,
NULL, NULL, NULL, NULL, NULL, NULL,
context, context,
NULL)) NULL))
_dbus_assert_not_reached ("setting watch functions to NULL failed"); _dbus_assert_not_reached ("setting watch functions to NULL failed");
if (!dbus_server_set_timeout_functions (context->server, if (!dbus_server_set_timeout_functions (server,
NULL, NULL, NULL, NULL, NULL, NULL,
context, context,
NULL)) NULL))
_dbus_assert_not_reached ("setting timeout functions to NULL failed"); _dbus_assert_not_reached ("setting timeout functions to NULL failed");
dbus_server_disconnect (context->server); dbus_server_disconnect (server);
}
void
bus_context_shutdown (BusContext *context)
{
DBusList *link;
link = _dbus_list_get_first_link (&context->servers);
while (link != NULL)
{
shutdown_server (context, link->data);
link = _dbus_list_get_next_link (&context->servers, link);
}
} }
void void
...@@ -275,6 +374,8 @@ bus_context_unref (BusContext *context) ...@@ -275,6 +374,8 @@ bus_context_unref (BusContext *context)
if (context->refcount == 0) if (context->refcount == 0)
{ {
DBusList *link;
_dbus_verbose ("Finalizing bus context %p\n", context); _dbus_verbose ("Finalizing bus context %p\n", context);
bus_context_shutdown (context); bus_context_shutdown (context);
...@@ -296,12 +397,15 @@ bus_context_unref (BusContext *context) ...@@ -296,12 +397,15 @@ bus_context_unref (BusContext *context)
bus_activation_unref (context->activation); bus_activation_unref (context->activation);
context->activation = NULL; context->activation = NULL;
} }
if (context->server) link = _dbus_list_get_first_link (&context->servers);
while (link != NULL)
{ {
dbus_server_unref (context->server); dbus_server_unref (link->data);
context->server = NULL;
link = _dbus_list_get_next_link (&context->servers, link);
} }
_dbus_list_clear (&context->servers);
if (context->rules_by_uid) if (context->rules_by_uid)
{ {
......
...@@ -38,19 +38,17 @@ typedef struct BusRegistry BusRegistry; ...@@ -38,19 +38,17 @@ typedef struct BusRegistry BusRegistry;
typedef struct BusService BusService; typedef struct BusService BusService;
typedef struct BusTransaction BusTransaction; typedef struct BusTransaction BusTransaction;
BusContext* bus_context_new (const char *address, BusContext* bus_context_new (const DBusString *config_file,
const char **service_dirs, DBusError *error);
DBusError *error); void bus_context_shutdown (BusContext *context);
void bus_context_shutdown (BusContext *context); void bus_context_ref (BusContext *context);
void bus_context_ref (BusContext *context); void bus_context_unref (BusContext *context);
void bus_context_unref (BusContext *context); BusRegistry* bus_context_get_registry (BusContext *context);
BusRegistry* bus_context_get_registry (BusContext *context); BusConnections* bus_context_get_connections (BusContext *context);
BusConnections* bus_context_get_connections (BusContext *context); BusActivation* bus_context_get_activation (BusContext *context);
BusActivation* bus_context_get_activation (BusContext *context); dbus_bool_t bus_context_allow_user (BusContext *context,
dbus_bool_t bus_context_allow_user (BusContext *context, unsigned long uid);
unsigned long uid); BusPolicy* bus_context_create_connection_policy (BusContext *context,
BusPolicy* bus_context_create_connection_policy (BusContext *context, DBusConnection *connection);
DBusConnection *connection);
#endif /* BUS_BUS_H */ #endif /* BUS_BUS_H */
...@@ -828,6 +828,13 @@ bus_config_parser_finished (BusConfigParser *parser, ...@@ -828,6 +828,13 @@ bus_config_parser_finished (BusConfigParser *parser,
return FALSE; return FALSE;
} }
if (parser->listen_on == NULL)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Configuration file needs one or more <listen> elements giving addresses");
return FALSE;
}
return TRUE; return TRUE;
} }
...@@ -838,6 +845,12 @@ bus_config_parser_get_user (BusConfigParser *parser) ...@@ -838,6 +845,12 @@ bus_config_parser_get_user (BusConfigParser *parser)
return parser->user; return parser->user;
} }
DBusList**
bus_config_parser_get_addresses (BusConfigParser *parser)
{
return &parser->listen_on;
}
#ifdef DBUS_BUILD_TESTS #ifdef DBUS_BUILD_TESTS
#include <stdio.h> #include <stdio.h>
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-string.h> #include <dbus/dbus-string.h>
#include <dbus/dbus-list.h>
/* Whatever XML library we're using just pushes data into this API */ /* Whatever XML library we're using just pushes data into this API */
...@@ -55,7 +56,7 @@ dbus_bool_t bus_config_parser_finished (BusConfigParser *parser, ...@@ -55,7 +56,7 @@ dbus_bool_t bus_config_parser_finished (BusConfigParser *parser,
/* Functions for extracting the parse results */ /* Functions for extracting the parse results */
const char* bus_config_parser_get_user (BusConfigParser *parser); const char* bus_config_parser_get_user (BusConfigParser *parser);