Commit eeb88949 authored by Havoc Pennington's avatar Havoc Pennington

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

	* bus/config-parser.c (bus_config_parser_unref): free
	list of mechanisms, bug discovered by test suite enhancements
	(putting system.conf and session.conf into suite)

	* test/Makefile.am, test/test-service.c: add placeholder for a
	test service that we'll activate as part of test suite. Doesn't
	do anything yet.

	* dbus/dbus-sysdeps.c (_dbus_setenv): support unsetenv by
	setting NULL value, and use system malloc not dbus_malloc()
	when we have unavoidable memleakage.

	* dbus/dbus-bus.c (dbus_bus_get): fix bug where bus type of 0
	didn't work, and support DBUS_BUS_ACTIVATION.

	* bus/activation.c (child_setup): pass our well-known bus type to
	the child

	* bus/config-parser.c: support <type> to specify well-known type

	* doc/dbus-specification.sgml: document the env variables to
	locate well-known buses and find service activator
parent 5364beac
2003-04-03 Havoc Pennington <hp@pobox.com>
* bus/config-parser.c (bus_config_parser_unref): free
list of mechanisms, bug discovered by test suite enhancements
(putting system.conf and session.conf into suite)
* test/Makefile.am, test/test-service.c: add placeholder for a
test service that we'll activate as part of test suite. Doesn't
do anything yet.
* dbus/dbus-sysdeps.c (_dbus_setenv): support unsetenv by
setting NULL value, and use system malloc not dbus_malloc()
when we have unavoidable memleakage.
* dbus/dbus-bus.c (dbus_bus_get): fix bug where bus type of 0
didn't work, and support DBUS_BUS_ACTIVATION.
* bus/activation.c (child_setup): pass our well-known bus type to
the child
* bus/config-parser.c: support <type> to specify well-known type
* doc/dbus-specification.sgml: document the env variables to
locate well-known buses and find service activator
2003-04-02 Havoc Pennington <hp@redhat.com> 2003-04-02 Havoc Pennington <hp@redhat.com>
* test/Makefile.am (all-local): add a rule to copy tests to * test/Makefile.am (all-local): add a rule to copy tests to
......
...@@ -404,12 +404,20 @@ static void ...@@ -404,12 +404,20 @@ static void
child_setup (void *data) child_setup (void *data)
{ {
BusActivation *activation = data; BusActivation *activation = data;
const char *type;
/* If no memory, we simply have the child exit, so it won't try /* If no memory, we simply have the child exit, so it won't try
* to connect to the wrong thing. * to connect to the wrong thing.
*/ */
if (!_dbus_setenv ("DBUS_ADDRESS", activation->server_address)) if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", activation->server_address))
_dbus_exit (1); _dbus_exit (1);
type = bus_context_get_type (activation->context);
if (type != NULL)
{
if (!_dbus_setenv ("DBUS_BUS_TYPE", type))
_dbus_exit (1);
}
} }
dbus_bool_t dbus_bool_t
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
struct BusContext struct BusContext
{ {
int refcount; int refcount;
char *type;
char *address; char *address;
DBusList *servers; DBusList *servers;
BusConnections *connections; BusConnections *connections;
...@@ -290,6 +291,9 @@ bus_context_new (const DBusString *config_file, ...@@ -290,6 +291,9 @@ bus_context_new (const DBusString *config_file,
if (!_dbus_change_identity (creds.uid, creds.gid, error)) if (!_dbus_change_identity (creds.uid, creds.gid, error))
goto failed; goto failed;
} }
/* note that type may be NULL */
context->type = _dbus_strdup (bus_config_parser_get_type (parser));
/* We have to build the address backward, so that /* We have to build the address backward, so that
* <listen> later in the config file have priority * <listen> later in the config file have priority
...@@ -496,12 +500,20 @@ bus_context_unref (BusContext *context) ...@@ -496,12 +500,20 @@ bus_context_unref (BusContext *context)
_dbus_hash_table_unref (context->rules_by_gid); _dbus_hash_table_unref (context->rules_by_gid);
context->rules_by_gid = NULL; context->rules_by_gid = NULL;
} }
dbus_free (context->type);
dbus_free (context->address); dbus_free (context->address);
dbus_free (context); dbus_free (context);
} }
} }
/* type may be NULL */
const char*
bus_context_get_type (BusContext *context)
{
return context->type;
}
BusRegistry* BusRegistry*
bus_context_get_registry (BusContext *context) bus_context_get_registry (BusContext *context)
{ {
......
...@@ -43,6 +43,7 @@ BusContext* bus_context_new (const DBusString *config_f ...@@ -43,6 +43,7 @@ BusContext* bus_context_new (const DBusString *config_f
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);
const char* bus_context_get_type (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);
......
...@@ -41,7 +41,8 @@ typedef enum ...@@ -41,7 +41,8 @@ typedef enum
ELEMENT_DENY, ELEMENT_DENY,
ELEMENT_FORK, ELEMENT_FORK,
ELEMENT_SERVICEDIR, ELEMENT_SERVICEDIR,
ELEMENT_INCLUDEDIR ELEMENT_INCLUDEDIR,
ELEMENT_TYPE
} ElementType; } ElementType;
typedef struct typedef struct
...@@ -57,11 +58,6 @@ typedef struct ...@@ -57,11 +58,6 @@ typedef struct
unsigned int ignore_missing : 1; unsigned int ignore_missing : 1;
} include; } include;
struct
{
char *mechanism;
} auth;
struct struct
{ {
char *context; char *context;
...@@ -89,6 +85,8 @@ struct BusConfigParser ...@@ -89,6 +85,8 @@ struct BusConfigParser
char *user; /**< user to run as */ char *user; /**< user to run as */
char *bus_type; /**< Message bus type */
DBusList *listen_on; /**< List of addresses to listen to */ DBusList *listen_on; /**< List of addresses to listen to */
DBusList *mechanisms; /**< Auth mechanisms */ DBusList *mechanisms; /**< Auth mechanisms */
...@@ -129,6 +127,8 @@ element_type_to_name (ElementType type) ...@@ -129,6 +127,8 @@ element_type_to_name (ElementType type)
return "servicedir"; return "servicedir";
case ELEMENT_INCLUDEDIR: case ELEMENT_INCLUDEDIR:
return "includedir"; return "includedir";
case ELEMENT_TYPE:
return "type";
} }
_dbus_assert_not_reached ("bad element type"); _dbus_assert_not_reached ("bad element type");
...@@ -213,6 +213,13 @@ merge_included (BusConfigParser *parser, ...@@ -213,6 +213,13 @@ merge_included (BusConfigParser *parser,
included->user = NULL; included->user = NULL;
} }
if (included->bus_type != NULL)
{
dbus_free (parser->bus_type);
parser->bus_type = included->bus_type;
included->bus_type = NULL;
}
if (included->fork) if (included->fork)
parser->fork = TRUE; parser->fork = TRUE;
...@@ -276,7 +283,8 @@ bus_config_parser_unref (BusConfigParser *parser) ...@@ -276,7 +283,8 @@ bus_config_parser_unref (BusConfigParser *parser)
pop_element (parser); pop_element (parser);
dbus_free (parser->user); dbus_free (parser->user);
dbus_free (parser->bus_type);
_dbus_list_foreach (&parser->listen_on, _dbus_list_foreach (&parser->listen_on,
(DBusForeachFunction) dbus_free, (DBusForeachFunction) dbus_free,
NULL); NULL);
...@@ -289,6 +297,12 @@ bus_config_parser_unref (BusConfigParser *parser) ...@@ -289,6 +297,12 @@ bus_config_parser_unref (BusConfigParser *parser)
_dbus_list_clear (&parser->service_dirs); _dbus_list_clear (&parser->service_dirs);
_dbus_list_foreach (&parser->mechanisms,
(DBusForeachFunction) dbus_free,
NULL);
_dbus_list_clear (&parser->mechanisms);
_dbus_string_free (&parser->basedir); _dbus_string_free (&parser->basedir);
dbus_free (parser); dbus_free (parser);
...@@ -451,7 +465,20 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -451,7 +465,20 @@ start_busconfig_child (BusConfigParser *parser,
if (push_element (parser, ELEMENT_USER) == NULL) if (push_element (parser, ELEMENT_USER) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE;
}
return TRUE;
}
else if (strcmp (element_name, "type") == 0)
{
if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
return FALSE;
if (push_element (parser, ELEMENT_TYPE) == NULL)
{
BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -464,7 +491,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -464,7 +491,7 @@ start_busconfig_child (BusConfigParser *parser,
if (push_element (parser, ELEMENT_FORK) == NULL) if (push_element (parser, ELEMENT_FORK) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -479,7 +506,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -479,7 +506,7 @@ start_busconfig_child (BusConfigParser *parser,
if (push_element (parser, ELEMENT_LISTEN) == NULL) if (push_element (parser, ELEMENT_LISTEN) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -492,7 +519,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -492,7 +519,7 @@ start_busconfig_child (BusConfigParser *parser,
if (push_element (parser, ELEMENT_AUTH) == NULL) if (push_element (parser, ELEMENT_AUTH) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -505,7 +532,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -505,7 +532,7 @@ start_busconfig_child (BusConfigParser *parser,
if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL) if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -518,7 +545,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -518,7 +545,7 @@ start_busconfig_child (BusConfigParser *parser,
if (push_element (parser, ELEMENT_SERVICEDIR) == NULL) if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -531,7 +558,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -531,7 +558,7 @@ start_busconfig_child (BusConfigParser *parser,
if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL) if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -570,7 +597,7 @@ start_busconfig_child (BusConfigParser *parser, ...@@ -570,7 +597,7 @@ start_busconfig_child (BusConfigParser *parser,
if ((e = push_element (parser, ELEMENT_POLICY)) == NULL) if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -608,7 +635,7 @@ start_policy_child (BusConfigParser *parser, ...@@ -608,7 +635,7 @@ start_policy_child (BusConfigParser *parser,
{ {
if (push_element (parser, ELEMENT_ALLOW) == NULL) if (push_element (parser, ELEMENT_ALLOW) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -618,7 +645,7 @@ start_policy_child (BusConfigParser *parser, ...@@ -618,7 +645,7 @@ start_policy_child (BusConfigParser *parser,
{ {
if (push_element (parser, ELEMENT_DENY) == NULL) if (push_element (parser, ELEMENT_DENY) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -657,7 +684,7 @@ bus_config_parser_start_element (BusConfigParser *parser, ...@@ -657,7 +684,7 @@ bus_config_parser_start_element (BusConfigParser *parser,
if (push_element (parser, ELEMENT_BUSCONFIG) == NULL) if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
{ {
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); BUS_SET_OOM (error);
return FALSE; return FALSE;
} }
...@@ -725,7 +752,8 @@ bus_config_parser_end_element (BusConfigParser *parser, ...@@ -725,7 +752,8 @@ bus_config_parser_end_element (BusConfigParser *parser,
* being paranoid about XML parsers * being paranoid about XML parsers
*/ */
dbus_set_error (error, DBUS_ERROR_FAILED, dbus_set_error (error, DBUS_ERROR_FAILED,
"XML element ended which was not the topmost element on the stack"); "XML element <%s> ended but topmost element on the stack was <%s>",
element_name, n);
return FALSE; return FALSE;
} }
...@@ -740,6 +768,7 @@ bus_config_parser_end_element (BusConfigParser *parser, ...@@ -740,6 +768,7 @@ bus_config_parser_end_element (BusConfigParser *parser,
case ELEMENT_INCLUDE: case ELEMENT_INCLUDE:
case ELEMENT_USER: case ELEMENT_USER:
case ELEMENT_TYPE:
case ELEMENT_LISTEN: case ELEMENT_LISTEN:
case ELEMENT_AUTH: case ELEMENT_AUTH:
case ELEMENT_SERVICEDIR: case ELEMENT_SERVICEDIR:
...@@ -1040,6 +1069,20 @@ bus_config_parser_content (BusConfigParser *parser, ...@@ -1040,6 +1069,20 @@ bus_config_parser_content (BusConfigParser *parser,
} }
break; break;
case ELEMENT_TYPE:
{
char *s;
e->had_content = TRUE;
if (!_dbus_string_copy_data (content, &s))
goto nomem;
dbus_free (parser->bus_type);
parser->bus_type = s;
}
break;
case ELEMENT_LISTEN: case ELEMENT_LISTEN:
{ {
char *s; char *s;
...@@ -1149,6 +1192,12 @@ bus_config_parser_get_user (BusConfigParser *parser) ...@@ -1149,6 +1192,12 @@ bus_config_parser_get_user (BusConfigParser *parser)
return parser->user; return parser->user;
} }
const char*
bus_config_parser_get_type (BusConfigParser *parser)
{
return parser->bus_type;
}
DBusList** DBusList**
bus_config_parser_get_addresses (BusConfigParser *parser) bus_config_parser_get_addresses (BusConfigParser *parser)
{ {
......
...@@ -56,6 +56,7 @@ dbus_bool_t bus_config_parser_finished (BusConfigParser *parser, ...@@ -56,6 +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);
const char* bus_config_parser_get_type (BusConfigParser *parser);
DBusList** bus_config_parser_get_addresses (BusConfigParser *parser); DBusList** bus_config_parser_get_addresses (BusConfigParser *parser);
DBusList** bus_config_parser_get_mechanisms (BusConfigParser *parser); DBusList** bus_config_parser_get_mechanisms (BusConfigParser *parser);
dbus_bool_t bus_config_parser_get_fork (BusConfigParser *parser); dbus_bool_t bus_config_parser_get_fork (BusConfigParser *parser);
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig> <busconfig>
<!-- Our well-known bus type, don't change this -->
<type>session</type>
<!-- FIXME - this is fairly complicated to fix. <!-- FIXME - this is fairly complicated to fix.
Propose the following: Propose the following:
- add "unix:tmpdir=/tmp" which means unix domain transport - add "unix:tmpdir=/tmp" which means unix domain transport
...@@ -18,6 +21,7 @@ ...@@ -18,6 +21,7 @@
reads the address from there and sets the env variable reads the address from there and sets the env variable
--> -->
<listen>unix:path=/tmp/foobar</listen> <listen>unix:path=/tmp/foobar</listen>
<policy context="default"> <policy context="default">
<!-- Allow everything --> <!-- Allow everything -->
<allow send="*"/> <allow send="*"/>
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig> <busconfig>
<!-- Our well-known bus type, do not change this -->
<type>system</type>
<!-- Run as special user --> <!-- Run as special user -->
<user>messagebus</user> <user>messagebus</user>
......
...@@ -139,7 +139,7 @@ AC_C_BIGENDIAN ...@@ -139,7 +139,7 @@ AC_C_BIGENDIAN
AC_CHECK_LIB(socket,socket) AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(nsl,gethostbyname) AC_CHECK_LIB(nsl,gethostbyname)
AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep poll setenv socketpair getgrouplist) AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep poll setenv unsetenv socketpair getgrouplist)
AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)]) AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "dbus-bus.h" #include "dbus-bus.h"
#include "dbus-protocol.h" #include "dbus-protocol.h"
#include "dbus-internals.h" #include "dbus-internals.h"
#include <string.h>
/** /**
* @defgroup DBusBus Message bus APIs * @defgroup DBusBus Message bus APIs
...@@ -61,11 +62,132 @@ static int bus_data_slot = -1; ...@@ -61,11 +62,132 @@ static int bus_data_slot = -1;
*/ */
static int bus_data_slot_refcount = 0; static int bus_data_slot_refcount = 0;
/** Number of bus types */
#define N_BUS_TYPES 3
static DBusConnection *bus_connections[N_BUS_TYPES];
static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL };
static DBusBusType activation_bus_type = DBUS_BUS_ACTIVATION;
static dbus_bool_t initialized = FALSE;
/** /**
* Lock for bus_data_slot and bus_data_slot_refcount * Lock for globals in this file
*/ */
_DBUS_DEFINE_GLOBAL_LOCK (bus); _DBUS_DEFINE_GLOBAL_LOCK (bus);
static void
addresses_shutdown_func (void *data)
{
int i;
i = 0;
while (i < N_BUS_TYPES)
{
if (bus_connections[i] != NULL)
_dbus_warn ("dbus_shutdown() called but connections were still live!");
dbus_free (bus_connection_addresses[i]);
bus_connection_addresses[i] = NULL;
++i;
}
activation_bus_type = DBUS_BUS_ACTIVATION;
}
static dbus_bool_t
get_from_env (char **connection_p,
const char *env_var)
{
const char *s;
_dbus_assert (*connection_p == NULL);
s = _dbus_getenv (env_var);
if (s == NULL || *s == '\0')
return TRUE; /* successfully didn't use the env var */
else
{
*connection_p = _dbus_strdup (s);
return *connection_p != NULL;
}
}
static dbus_bool_t
init_connections_unlocked (void)
{
if (!initialized)
{
const char *s;
bus_connections[0] = NULL;
bus_connections[1] = NULL;
bus_connections[2] = NULL;
/* Don't init these twice, we may run this code twice if
* init_connections_unlocked() fails midway through.
*/
if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
{
if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SYSTEM],
"DBUS_SYSTEM_BUS_ADDRESS"))
return FALSE;
if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
{
/* Use default system bus address if none set in environment */