2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2003-03-25 04:45:25 +00:00
|
|
|
/* config-parser.c XML-library-agnostic configuration file parser
|
|
|
|
|
*
|
2004-05-29 04:17:17 +00:00
|
|
|
* Copyright (C) 2003, 2004 Red Hat, Inc.
|
2003-03-25 04:45:25 +00:00
|
|
|
*
|
2004-08-10 03:07:01 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
2003-03-31 04:01:00 +00:00
|
|
|
*
|
2003-03-25 04:45:25 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2003-03-31 04:01:00 +00:00
|
|
|
*
|
2003-03-25 04:45:25 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-03-25 04:45:25 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2010-03-19 12:36:49 +01:00
|
|
|
|
|
|
|
|
#include <config.h>
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
#include "config-parser-common.h"
|
2003-03-25 04:45:25 +00:00
|
|
|
#include "config-parser.h"
|
2003-03-26 03:58:11 +00:00
|
|
|
#include "test.h"
|
2003-04-02 21:43:29 +00:00
|
|
|
#include "utils.h"
|
2003-04-12 18:32:11 +00:00
|
|
|
#include "policy.h"
|
2004-07-30 05:59:34 +00:00
|
|
|
#include "selinux.h"
|
2014-02-10 19:02:04 -06:00
|
|
|
#include "apparmor.h"
|
2003-03-26 03:58:11 +00:00
|
|
|
#include <dbus/dbus-list.h>
|
|
|
|
|
#include <dbus/dbus-internals.h>
|
2013-06-05 19:58:22 +01:00
|
|
|
#include <dbus/dbus-misc.h>
|
2010-12-29 12:31:42 +01:00
|
|
|
#include <dbus/dbus-sysdeps.h>
|
2003-03-25 04:45:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
/* we ignore policies for unknown groups/users */
|
|
|
|
|
POLICY_IGNORED,
|
|
|
|
|
|
|
|
|
|
/* non-ignored */
|
|
|
|
|
POLICY_DEFAULT,
|
|
|
|
|
POLICY_MANDATORY,
|
|
|
|
|
POLICY_USER,
|
2004-08-25 22:11:49 +00:00
|
|
|
POLICY_GROUP,
|
|
|
|
|
POLICY_CONSOLE
|
2003-04-13 08:33:10 +00:00
|
|
|
} PolicyType;
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
ElementType type;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
unsigned int had_content : 1;
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
unsigned int ignore_missing : 1;
|
2004-10-18 04:04:12 +00:00
|
|
|
unsigned int if_selinux_enabled : 1;
|
2004-08-23 16:09:54 +00:00
|
|
|
unsigned int selinux_root_relative : 1;
|
2003-03-25 04:45:25 +00:00
|
|
|
} include;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
PolicyType type;
|
2004-08-25 22:11:49 +00:00
|
|
|
unsigned long gid_uid_or_at_console;
|
2003-03-25 04:45:25 +00:00
|
|
|
} policy;
|
|
|
|
|
|
2003-04-24 22:30:38 +00:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
long value;
|
|
|
|
|
} limit;
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
} d;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
} Element;
|
|
|
|
|
|
2003-09-07 23:04:54 +00:00
|
|
|
/**
|
|
|
|
|
* Parser for bus configuration file.
|
|
|
|
|
*/
|
2003-03-25 04:45:25 +00:00
|
|
|
struct BusConfigParser
|
|
|
|
|
{
|
2003-09-07 23:04:54 +00:00
|
|
|
int refcount; /**< Reference count */
|
2003-03-25 04:45:25 +00:00
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
DBusString basedir; /**< Directory we resolve paths relative to */
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
DBusList *stack; /**< stack of Element */
|
2003-03-26 03:58:11 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
char *user; /**< user to run as */
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
char *servicehelper; /**< location of the setuid helper */
|
|
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
char *bus_type; /**< Message bus type */
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
DBusList *listen_on; /**< List of addresses to listen to */
|
2003-04-01 05:33:01 +00:00
|
|
|
|
|
|
|
|
DBusList *mechanisms; /**< Auth mechanisms */
|
2003-04-02 00:29:33 +00:00
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
DBusList *service_dirs; /**< BusConfigServiceDirs to look for session services in */
|
2003-04-12 18:32:11 +00:00
|
|
|
|
2005-06-15 02:31:38 +00:00
|
|
|
DBusList *conf_dirs; /**< Directories to look for policy configuration in */
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
BusPolicy *policy; /**< Security policy */
|
2003-04-24 22:30:38 +00:00
|
|
|
|
|
|
|
|
BusLimits limits; /**< Limits */
|
2003-04-28 19:29:42 +00:00
|
|
|
|
|
|
|
|
char *pidfile; /**< PID file */
|
|
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
DBusList *included_files; /**< Included files stack */
|
|
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
unsigned int fork : 1; /**< TRUE to fork into daemon mode */
|
2003-04-06 23:15:41 +00:00
|
|
|
|
2008-12-10 14:17:02 -05:00
|
|
|
unsigned int syslog : 1; /**< TRUE to enable syslog */
|
2008-11-10 08:55:27 -05:00
|
|
|
unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */
|
2008-12-10 14:17:02 -05:00
|
|
|
|
2003-04-28 19:29:42 +00:00
|
|
|
unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
|
2008-11-12 08:51:00 -05:00
|
|
|
|
|
|
|
|
unsigned int allow_anonymous : 1; /**< TRUE to allow anonymous connections */
|
2003-03-25 04:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
static Element*
|
|
|
|
|
push_element (BusConfigParser *parser,
|
|
|
|
|
ElementType type)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
_dbus_assert (type != ELEMENT_NONE);
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
e = dbus_new0 (Element, 1);
|
|
|
|
|
if (e == NULL)
|
|
|
|
|
return NULL;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_list_append (&parser->stack, e))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (e);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
e->type = type;
|
|
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
static void
|
|
|
|
|
element_free (Element *e)
|
|
|
|
|
{
|
2003-04-24 22:30:38 +00:00
|
|
|
if (e->type == ELEMENT_LIMIT)
|
|
|
|
|
dbus_free (e->d.limit.name);
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
dbus_free (e);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
static void
|
|
|
|
|
pop_element (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
|
|
|
|
|
e = _dbus_list_pop_last (&parser->stack);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
element_free (e);
|
|
|
|
|
}
|
2003-03-26 03:58:11 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
static Element*
|
|
|
|
|
peek_element (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
|
|
|
|
|
e = _dbus_list_get_last (&parser->stack);
|
|
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ElementType
|
|
|
|
|
top_element_type (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
|
|
|
|
|
e = _dbus_list_get_last (&parser->stack);
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
return e->type;
|
|
|
|
|
else
|
|
|
|
|
return ELEMENT_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
merge_service_context_hash (DBusHashTable *dest,
|
|
|
|
|
DBusHashTable *from)
|
|
|
|
|
{
|
|
|
|
|
DBusHashIter iter;
|
2006-08-08 23:29:03 +00:00
|
|
|
char *service_copy;
|
|
|
|
|
char *context_copy;
|
|
|
|
|
|
|
|
|
|
service_copy = NULL;
|
|
|
|
|
context_copy = NULL;
|
|
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
_dbus_hash_iter_init (from, &iter);
|
|
|
|
|
while (_dbus_hash_iter_next (&iter))
|
|
|
|
|
{
|
|
|
|
|
const char *service = _dbus_hash_iter_get_string_key (&iter);
|
|
|
|
|
const char *context = _dbus_hash_iter_get_value (&iter);
|
|
|
|
|
|
|
|
|
|
service_copy = _dbus_strdup (service);
|
|
|
|
|
if (service_copy == NULL)
|
2006-08-08 23:29:03 +00:00
|
|
|
goto fail;
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
context_copy = _dbus_strdup (context);
|
|
|
|
|
if (context_copy == NULL)
|
2006-08-08 23:29:03 +00:00
|
|
|
goto fail;
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
|
2006-08-08 23:29:03 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
service_copy = NULL;
|
|
|
|
|
context_copy = NULL;
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2006-08-08 23:29:03 +00:00
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
if (service_copy)
|
|
|
|
|
dbus_free (service_copy);
|
|
|
|
|
|
|
|
|
|
if (context_copy)
|
|
|
|
|
dbus_free (context_copy);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
/*
|
|
|
|
|
* Create a new BusConfigServiceDir. Takes ownership of path if #TRUE is returned.
|
|
|
|
|
*
|
|
|
|
|
* @returns #FALSE on OOM
|
|
|
|
|
*/
|
|
|
|
|
static BusConfigServiceDir *
|
|
|
|
|
bus_config_service_dir_new_take (char *path,
|
|
|
|
|
BusServiceDirFlags flags)
|
|
|
|
|
{
|
|
|
|
|
BusConfigServiceDir *self = dbus_new0 (BusConfigServiceDir, 1);
|
|
|
|
|
|
|
|
|
|
if (self == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
self->path = path; /* take ownership */
|
|
|
|
|
self->flags = flags;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_config_service_dir_free (BusConfigServiceDir *self)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (self->path);
|
|
|
|
|
dbus_free (self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BusConfigServiceDir *
|
2006-10-27 18:30:22 +00:00
|
|
|
service_dirs_find_dir (DBusList **service_dirs,
|
|
|
|
|
const char *dir)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (dir != NULL);
|
|
|
|
|
|
2006-11-02 23:56:48 +00:00
|
|
|
for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link))
|
2006-10-27 18:30:22 +00:00
|
|
|
{
|
2017-02-17 15:03:02 +00:00
|
|
|
BusConfigServiceDir *link_dir = link->data;
|
|
|
|
|
|
|
|
|
|
if (strcmp (dir, link_dir->path) == 0)
|
|
|
|
|
return link_dir;
|
2006-10-27 18:30:22 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
return NULL;
|
2006-10-27 18:30:22 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
static void
|
2006-10-27 18:30:22 +00:00
|
|
|
service_dirs_append_link_unique_or_free (DBusList **service_dirs,
|
|
|
|
|
DBusList *dir_link)
|
|
|
|
|
{
|
2017-02-17 15:03:02 +00:00
|
|
|
BusConfigServiceDir *dir = dir_link->data;
|
|
|
|
|
BusConfigServiceDir *already = service_dirs_find_dir (service_dirs,
|
|
|
|
|
dir->path);
|
|
|
|
|
|
|
|
|
|
if (already == NULL)
|
2006-10-27 18:30:22 +00:00
|
|
|
{
|
|
|
|
|
_dbus_list_append_link (service_dirs, dir_link);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-17 15:03:02 +00:00
|
|
|
/* BusServiceDirFlags are chosen such that the compatible thing to do
|
|
|
|
|
* is to "and" the flags. For example, if a directory is explicitly
|
|
|
|
|
* added as a <servicedir> (which is watched with inotify) and is also
|
|
|
|
|
* the transient service directory (which should not be watched),
|
|
|
|
|
* the compatible thing to do is to watch it. */
|
|
|
|
|
already->flags &= dir->flags;
|
|
|
|
|
bus_config_service_dir_free (dir_link->data);
|
2006-10-27 18:30:22 +00:00
|
|
|
_dbus_list_free_link (dir_link);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
/*
|
|
|
|
|
* Consume links from dirs (a list of paths), converting them into links in
|
|
|
|
|
* service_dirs (a list of unique BusServiceDir).
|
|
|
|
|
*
|
|
|
|
|
* On success, return TRUE. dirs will be empty, and every original entry in
|
|
|
|
|
* dirs will have a corresponding service_dirs entry.
|
|
|
|
|
*
|
|
|
|
|
* On OOM, return FALSE. Each original entry of dirs has either been
|
|
|
|
|
* appended to service_dirs or left in dirs.
|
|
|
|
|
*/
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
service_dirs_absorb_string_list (DBusList **service_dirs,
|
|
|
|
|
DBusList **dirs,
|
|
|
|
|
BusServiceDirFlags flags)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (service_dirs != NULL);
|
|
|
|
|
_dbus_assert (dirs != NULL);
|
|
|
|
|
|
|
|
|
|
while ((link = _dbus_list_pop_first_link (dirs)))
|
|
|
|
|
{
|
|
|
|
|
char *path = link->data;
|
|
|
|
|
BusConfigServiceDir *dir = bus_config_service_dir_new_take (path, flags);
|
|
|
|
|
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* OOM - roll back (this does not need to allocate memory) */
|
|
|
|
|
_dbus_list_prepend_link (service_dirs, link);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ownership of path has been taken by dir */
|
|
|
|
|
link->data = dir;
|
|
|
|
|
service_dirs_append_link_unique_or_free (service_dirs, link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert (*dirs == NULL);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
merge_included (BusConfigParser *parser,
|
|
|
|
|
BusConfigParser *included,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
2003-05-17 17:53:17 +00:00
|
|
|
if (!bus_policy_merge (parser->policy,
|
|
|
|
|
included->policy))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
if (!merge_service_context_hash (parser->service_context_table,
|
|
|
|
|
included->service_context_table))
|
2004-07-30 05:59:34 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-05-17 17:53:17 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
if (included->user != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (parser->user);
|
|
|
|
|
parser->user = included->user;
|
|
|
|
|
included->user = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
if (included->bus_type != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (parser->bus_type);
|
|
|
|
|
parser->bus_type = included->bus_type;
|
|
|
|
|
included->bus_type = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
if (included->fork)
|
|
|
|
|
parser->fork = TRUE;
|
2003-04-06 23:15:41 +00:00
|
|
|
|
2008-11-10 08:55:27 -05:00
|
|
|
if (included->keep_umask)
|
|
|
|
|
parser->keep_umask = TRUE;
|
|
|
|
|
|
2014-01-09 16:15:31 -06:00
|
|
|
if (included->allow_anonymous)
|
|
|
|
|
parser->allow_anonymous = TRUE;
|
|
|
|
|
|
2003-04-06 23:15:41 +00:00
|
|
|
if (included->pidfile != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (parser->pidfile);
|
|
|
|
|
parser->pidfile = included->pidfile;
|
|
|
|
|
included->pidfile = NULL;
|
|
|
|
|
}
|
2012-06-29 13:40:37 +01:00
|
|
|
|
|
|
|
|
if (included->servicehelper != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (parser->servicehelper);
|
|
|
|
|
parser->servicehelper = included->servicehelper;
|
|
|
|
|
included->servicehelper = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
while ((link = _dbus_list_pop_first_link (&included->listen_on)))
|
|
|
|
|
_dbus_list_append_link (&parser->listen_on, link);
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
while ((link = _dbus_list_pop_first_link (&included->mechanisms)))
|
|
|
|
|
_dbus_list_append_link (&parser->mechanisms, link);
|
2003-04-02 00:29:33 +00:00
|
|
|
|
|
|
|
|
while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
|
2006-10-27 18:30:22 +00:00
|
|
|
service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
|
2005-06-15 02:31:38 +00:00
|
|
|
|
|
|
|
|
while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
|
|
|
|
|
_dbus_list_append_link (&parser->conf_dirs, link);
|
2003-04-01 05:33:01 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
return TRUE;
|
2003-03-26 03:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
seen_include (BusConfigParser *parser,
|
|
|
|
|
const DBusString *file)
|
|
|
|
|
{
|
|
|
|
|
DBusList *iter;
|
|
|
|
|
|
|
|
|
|
iter = parser->included_files;
|
|
|
|
|
while (iter != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (! strcmp (_dbus_string_get_const_data (file), iter->data))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
iter = _dbus_list_get_next_link (&parser->included_files, iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
BusConfigParser*
|
2004-04-09 19:50:29 +00:00
|
|
|
bus_config_parser_new (const DBusString *basedir,
|
|
|
|
|
dbus_bool_t is_toplevel,
|
|
|
|
|
const BusConfigParser *parent)
|
2003-03-25 04:45:25 +00:00
|
|
|
{
|
|
|
|
|
BusConfigParser *parser;
|
|
|
|
|
|
|
|
|
|
parser = dbus_new0 (BusConfigParser, 1);
|
|
|
|
|
if (parser == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2003-04-28 19:29:42 +00:00
|
|
|
parser->is_toplevel = !!is_toplevel;
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
if (!_dbus_string_init (&parser->basedir))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (parser);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
if (((parser->policy = bus_policy_new ()) == NULL) ||
|
2004-07-30 05:59:34 +00:00
|
|
|
!_dbus_string_copy (basedir, 0, &parser->basedir, 0) ||
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING,
|
|
|
|
|
dbus_free,
|
|
|
|
|
dbus_free)) == NULL))
|
2003-04-02 21:43:29 +00:00
|
|
|
{
|
2003-04-13 00:10:53 +00:00
|
|
|
if (parser->policy)
|
|
|
|
|
bus_policy_unref (parser->policy);
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
_dbus_string_free (&parser->basedir);
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
dbus_free (parser);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
if (parent != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Initialize the parser's limits from the parent. */
|
|
|
|
|
parser->limits = parent->limits;
|
2004-04-13 01:37:57 +00:00
|
|
|
|
|
|
|
|
/* Use the parent's list of included_files to avoid
|
|
|
|
|
circular inclusions. */
|
|
|
|
|
parser->included_files = parent->included_files;
|
2004-04-09 19:50:29 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-09-21 19:53:56 +00:00
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
/* Make up some numbers! woot! */
|
2007-01-26 16:10:26 +00:00
|
|
|
parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 127;
|
|
|
|
|
parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 127;
|
2004-04-09 19:50:29 +00:00
|
|
|
parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
|
2009-05-20 01:33:17 +02:00
|
|
|
|
|
|
|
|
/* We set relatively conservative values here since due to the
|
|
|
|
|
way SCM_RIGHTS works we need to preallocate an array for the
|
|
|
|
|
maximum number of file descriptors we can receive. Picking a
|
|
|
|
|
high value here thus translates directly to more memory
|
|
|
|
|
allocation. */
|
2013-02-20 15:23:42 -06:00
|
|
|
parser->limits.max_incoming_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
|
|
|
|
|
parser->limits.max_outgoing_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
|
|
|
|
|
parser->limits.max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
|
2004-04-09 19:50:29 +00:00
|
|
|
|
|
|
|
|
/* Making this long means the user has to wait longer for an error
|
|
|
|
|
* message if something screws up, but making it too short means
|
|
|
|
|
* they might see a false failure.
|
|
|
|
|
*/
|
|
|
|
|
parser->limits.activation_timeout = 25000; /* 25 seconds */
|
2003-10-14 05:16:56 +00:00
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
/* Making this long risks making a DOS attack easier, but too short
|
|
|
|
|
* and legitimate auth will fail. If interactive auth (ask user for
|
|
|
|
|
* password) is allowed, then potentially it has to be quite long.
|
|
|
|
|
*/
|
2014-11-18 17:34:11 +00:00
|
|
|
parser->limits.auth_timeout = 30000; /* 30 seconds */
|
2014-07-21 17:34:08 +01:00
|
|
|
|
|
|
|
|
/* Do not allow a fd to stay forever in dbus-daemon
|
|
|
|
|
* https://bugs.freedesktop.org/show_bug.cgi?id=80559
|
|
|
|
|
*/
|
|
|
|
|
parser->limits.pending_fd_timeout = 150000; /* 2.5 minutes */
|
2004-04-09 19:50:29 +00:00
|
|
|
|
2007-01-26 16:10:26 +00:00
|
|
|
parser->limits.max_incomplete_connections = 64;
|
|
|
|
|
parser->limits.max_connections_per_user = 256;
|
2004-04-09 19:50:29 +00:00
|
|
|
|
|
|
|
|
/* Note that max_completed_connections / max_connections_per_user
|
|
|
|
|
* is the number of users that would have to work together to
|
|
|
|
|
* DOS all the other users.
|
|
|
|
|
*/
|
2007-01-26 16:10:26 +00:00
|
|
|
parser->limits.max_completed_connections = 2048;
|
2004-04-09 19:50:29 +00:00
|
|
|
|
2007-01-26 16:10:26 +00:00
|
|
|
parser->limits.max_pending_activations = 512;
|
|
|
|
|
parser->limits.max_services_per_connection = 512;
|
2007-06-19 17:23:55 +00:00
|
|
|
|
|
|
|
|
/* For this one, keep in mind that it isn't only the memory used
|
|
|
|
|
* by the match rules, but slowdown from linearly walking a big
|
|
|
|
|
* list of them. A client adding more than this is almost
|
|
|
|
|
* certainly a bad idea for that reason, and should change to a
|
|
|
|
|
* smaller number of wider-net match rules - getting every last
|
|
|
|
|
* message to the bus is probably better than having a thousand
|
|
|
|
|
* match rules.
|
|
|
|
|
*/
|
2005-04-14 15:10:22 +00:00
|
|
|
parser->limits.max_match_rules_per_connection = 512;
|
2004-04-09 19:50:29 +00:00
|
|
|
|
2009-05-11 22:43:09 +01:00
|
|
|
parser->limits.reply_timeout = -1; /* never */
|
2007-01-26 16:10:26 +00:00
|
|
|
|
|
|
|
|
/* this is effectively a limit on message queue size for messages
|
|
|
|
|
* that require a reply
|
|
|
|
|
*/
|
2014-07-10 15:08:06 +01:00
|
|
|
parser->limits.max_replies_per_connection = 128;
|
2004-04-09 19:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
parser->refcount = 1;
|
2004-04-09 19:50:29 +00:00
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
return parser;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-27 01:25:50 +00:00
|
|
|
BusConfigParser *
|
2003-03-25 04:45:25 +00:00
|
|
|
bus_config_parser_ref (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (parser->refcount > 0);
|
|
|
|
|
|
|
|
|
|
parser->refcount += 1;
|
2003-11-27 01:25:50 +00:00
|
|
|
|
|
|
|
|
return parser;
|
2003-03-25 04:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_config_parser_unref (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (parser->refcount > 0);
|
|
|
|
|
|
|
|
|
|
parser->refcount -= 1;
|
|
|
|
|
|
|
|
|
|
if (parser->refcount == 0)
|
|
|
|
|
{
|
2003-03-26 03:58:11 +00:00
|
|
|
while (parser->stack != NULL)
|
|
|
|
|
pop_element (parser);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
dbus_free (parser->user);
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
dbus_free (parser->servicehelper);
|
2003-04-03 05:22:49 +00:00
|
|
|
dbus_free (parser->bus_type);
|
2003-04-06 23:15:41 +00:00
|
|
|
dbus_free (parser->pidfile);
|
2003-04-03 05:22:49 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
_dbus_list_foreach (&parser->listen_on,
|
|
|
|
|
(DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_clear (&parser->listen_on);
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
_dbus_list_foreach (&parser->service_dirs,
|
2017-02-17 15:03:02 +00:00
|
|
|
(DBusForeachFunction) bus_config_service_dir_free,
|
2003-04-02 00:29:33 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_clear (&parser->service_dirs);
|
2003-04-02 21:43:29 +00:00
|
|
|
|
2005-06-15 02:31:38 +00:00
|
|
|
_dbus_list_foreach (&parser->conf_dirs,
|
|
|
|
|
(DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_clear (&parser->conf_dirs);
|
|
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
_dbus_list_foreach (&parser->mechanisms,
|
|
|
|
|
(DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_clear (&parser->mechanisms);
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
_dbus_string_free (&parser->basedir);
|
2003-04-12 18:32:11 +00:00
|
|
|
|
|
|
|
|
if (parser->policy)
|
|
|
|
|
bus_policy_unref (parser->policy);
|
2004-04-13 01:37:57 +00:00
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
if (parser->service_context_table)
|
|
|
|
|
_dbus_hash_table_unref (parser->service_context_table);
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
dbus_free (parser);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_check_doctype (BusConfigParser *parser,
|
|
|
|
|
const char *doctype,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
if (strcmp (doctype, "busconfig") != 0)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error,
|
|
|
|
|
DBUS_ERROR_FAILED,
|
2003-03-31 04:01:00 +00:00
|
|
|
"Configuration file has the wrong document type %s",
|
2003-03-25 04:45:25 +00:00
|
|
|
doctype);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
const char **retloc;
|
|
|
|
|
} LocateAttr;
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
locate_attributes (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
DBusError *error,
|
|
|
|
|
const char *first_attribute_name,
|
|
|
|
|
const char **first_attribute_retloc,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
const char *name;
|
|
|
|
|
const char **retloc;
|
|
|
|
|
int n_attrs;
|
|
|
|
|
#define MAX_ATTRS 24
|
|
|
|
|
LocateAttr attrs[MAX_ATTRS];
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (first_attribute_name != NULL);
|
|
|
|
|
_dbus_assert (first_attribute_retloc != NULL);
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
n_attrs = 1;
|
|
|
|
|
attrs[0].name = first_attribute_name;
|
|
|
|
|
attrs[0].retloc = first_attribute_retloc;
|
|
|
|
|
*first_attribute_retloc = NULL;
|
|
|
|
|
|
|
|
|
|
va_start (args, first_attribute_retloc);
|
|
|
|
|
|
|
|
|
|
name = va_arg (args, const char*);
|
|
|
|
|
retloc = va_arg (args, const char**);
|
|
|
|
|
|
|
|
|
|
while (name != NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (retloc != NULL);
|
|
|
|
|
_dbus_assert (n_attrs < MAX_ATTRS);
|
|
|
|
|
|
|
|
|
|
attrs[n_attrs].name = name;
|
|
|
|
|
attrs[n_attrs].retloc = retloc;
|
|
|
|
|
n_attrs += 1;
|
|
|
|
|
*retloc = NULL;
|
|
|
|
|
|
|
|
|
|
name = va_arg (args, const char*);
|
|
|
|
|
retloc = va_arg (args, const char**);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (attribute_names[i])
|
|
|
|
|
{
|
|
|
|
|
int j;
|
|
|
|
|
dbus_bool_t found;
|
|
|
|
|
|
|
|
|
|
found = FALSE;
|
|
|
|
|
j = 0;
|
|
|
|
|
while (j < n_attrs)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (attrs[j].name, attribute_names[i]) == 0)
|
|
|
|
|
{
|
|
|
|
|
retloc = attrs[j].retloc;
|
|
|
|
|
|
|
|
|
|
if (*retloc != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Attribute \"%s\" repeated twice on the same <%s> element",
|
|
|
|
|
attrs[j].name, element_name);
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*retloc = attribute_values[i];
|
|
|
|
|
found = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Attribute \"%s\" is invalid on <%s> element in this context",
|
|
|
|
|
attribute_names[i], element_name);
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
check_no_attributes (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
if (attribute_names[0] != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Attribute \"%s\" is invalid on <%s> element in this context",
|
|
|
|
|
attribute_names[0], element_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
start_busconfig_child (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
ElementType element_type;
|
|
|
|
|
|
|
|
|
|
element_type = bus_config_parser_element_name_to_type (element_name);
|
|
|
|
|
|
|
|
|
|
if (element_type == ELEMENT_USER)
|
2003-03-31 04:01:00 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_USER) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2011-03-07 11:43:23 +01:00
|
|
|
else if (element_type == ELEMENT_CONFIGTYPE)
|
2003-04-03 05:22:49 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-03-07 11:43:23 +01:00
|
|
|
if (push_element (parser, ELEMENT_CONFIGTYPE) == NULL)
|
2003-04-03 05:22:49 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_FORK)
|
2003-04-01 05:33:01 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_FORK) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-04-01 05:33:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parser->fork = TRUE;
|
|
|
|
|
|
2008-11-10 08:55:27 -05:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2008-12-10 14:17:02 -05:00
|
|
|
else if (element_type == ELEMENT_SYSLOG)
|
2008-11-10 08:55:27 -05:00
|
|
|
{
|
2008-12-10 14:17:02 -05:00
|
|
|
if (!check_no_attributes (parser, "syslog", attribute_names, attribute_values, error))
|
2008-11-10 08:55:27 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
2008-12-10 14:17:02 -05:00
|
|
|
if (push_element (parser, ELEMENT_SYSLOG) == NULL)
|
2008-11-10 08:55:27 -05:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2008-11-10 08:55:27 -05:00
|
|
|
|
2008-12-10 14:17:02 -05:00
|
|
|
parser->syslog = TRUE;
|
2008-11-10 08:55:27 -05:00
|
|
|
|
2008-12-10 14:17:02 -05:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2008-11-10 08:55:27 -05:00
|
|
|
else if (element_type == ELEMENT_KEEP_UMASK)
|
2008-12-10 14:17:02 -05:00
|
|
|
{
|
2008-11-10 08:55:27 -05:00
|
|
|
if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error))
|
2008-12-10 14:17:02 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
2008-11-10 08:55:27 -05:00
|
|
|
if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL)
|
2008-12-10 14:17:02 -05:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-10 08:55:27 -05:00
|
|
|
parser->keep_umask = TRUE;
|
2008-12-10 14:17:02 -05:00
|
|
|
|
2003-04-06 23:15:41 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_PIDFILE)
|
2003-04-06 23:15:41 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_PIDFILE) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_LISTEN)
|
2003-03-31 04:01:00 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_LISTEN) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_AUTH)
|
2003-04-01 05:33:01 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_AUTH) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-04-01 05:33:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_SERVICEHELPER)
|
|
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "servicehelper", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_SERVICEHELPER) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (element_type == ELEMENT_INCLUDEDIR)
|
2003-04-02 00:29:33 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-04-02 00:29:33 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-01 23:30:46 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_STANDARD_SESSION_SERVICEDIRS)
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
2017-02-13 20:58:51 +00:00
|
|
|
DBusError local_error = DBUS_ERROR_INIT;
|
|
|
|
|
DBusList *dirs = NULL;
|
2006-11-02 23:56:48 +00:00
|
|
|
|
2006-11-01 23:30:46 +00:00
|
|
|
if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
if (_dbus_set_up_transient_session_servicedirs (&dirs, &local_error))
|
|
|
|
|
{
|
|
|
|
|
if (!service_dirs_absorb_string_list (&parser->service_dirs, &dirs,
|
|
|
|
|
BUS_SERVICE_DIR_FLAGS_NO_WATCH |
|
|
|
|
|
BUS_SERVICE_DIR_FLAGS_STRICT_NAMING))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_list_foreach (&dirs, (DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
_dbus_list_clear (&dirs);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Failing to set these up isn't fatal */
|
|
|
|
|
_dbus_warn ("Unable to set up transient service directory: %s",
|
|
|
|
|
local_error.message);
|
|
|
|
|
dbus_error_free (&local_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert (dirs == NULL);
|
|
|
|
|
|
2006-11-02 23:56:48 +00:00
|
|
|
if (!_dbus_get_standard_session_servicedirs (&dirs))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
/* We have traditionally watched the standard session service
|
|
|
|
|
* directories with inotify, and allowed service files whose names do not
|
|
|
|
|
* match the bus name */
|
|
|
|
|
if (!service_dirs_absorb_string_list (&parser->service_dirs, &dirs,
|
|
|
|
|
BUS_SERVICE_DIR_FLAGS_NONE))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_list_foreach (&dirs, (DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
_dbus_list_clear (&dirs);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2006-11-02 23:56:48 +00:00
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
_dbus_assert (dirs == NULL);
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_STANDARD_SYSTEM_SERVICEDIRS)
|
|
|
|
|
{
|
|
|
|
|
DBusList *dirs;
|
|
|
|
|
dirs = NULL;
|
|
|
|
|
|
|
|
|
|
if (!check_no_attributes (parser, "standard_system_servicedirs", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_get_standard_system_servicedirs (&dirs))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
/* We have traditionally watched the standard system service
|
|
|
|
|
* directories with inotify, and allowed service files whose names do not
|
|
|
|
|
* match the bus name (the servicehelper won't successfully activate
|
|
|
|
|
* them, but we do still parse them) */
|
|
|
|
|
if (!service_dirs_absorb_string_list (&parser->service_dirs, &dirs,
|
|
|
|
|
BUS_SERVICE_DIR_FLAGS_NONE))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_list_foreach (&dirs, (DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
_dbus_list_clear (&dirs);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2008-11-12 08:51:00 -05:00
|
|
|
else if (element_type == ELEMENT_ALLOW_ANONYMOUS)
|
|
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "allow_anonymous", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_ALLOW_ANONYMOUS) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parser->allow_anonymous = TRUE;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_SERVICEDIR)
|
2003-04-02 00:29:33 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-04-02 00:29:33 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_INCLUDE)
|
2003-03-31 04:01:00 +00:00
|
|
|
{
|
|
|
|
|
Element *e;
|
2004-10-18 04:04:12 +00:00
|
|
|
const char *if_selinux_enabled;
|
2003-03-31 04:01:00 +00:00
|
|
|
const char *ignore_missing;
|
2004-08-23 16:09:54 +00:00
|
|
|
const char *selinux_root_relative;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e->d.include.ignore_missing = FALSE;
|
2004-10-18 04:04:12 +00:00
|
|
|
e->d.include.if_selinux_enabled = FALSE;
|
2004-08-23 16:09:54 +00:00
|
|
|
e->d.include.selinux_root_relative = FALSE;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
if (!locate_attributes (parser, "include",
|
|
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
|
|
|
|
"ignore_missing", &ignore_missing,
|
2004-10-18 04:04:12 +00:00
|
|
|
"if_selinux_enabled", &if_selinux_enabled,
|
2004-08-23 16:09:54 +00:00
|
|
|
"selinux_root_relative", &selinux_root_relative,
|
2003-03-31 04:01:00 +00:00
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (ignore_missing != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (ignore_missing, "yes") == 0)
|
|
|
|
|
e->d.include.ignore_missing = TRUE;
|
|
|
|
|
else if (strcmp (ignore_missing, "no") == 0)
|
|
|
|
|
e->d.include.ignore_missing = FALSE;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"ignore_missing attribute must have value \"yes\" or \"no\"");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-18 04:04:12 +00:00
|
|
|
|
|
|
|
|
if (if_selinux_enabled != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (if_selinux_enabled, "yes") == 0)
|
|
|
|
|
e->d.include.if_selinux_enabled = TRUE;
|
|
|
|
|
else if (strcmp (if_selinux_enabled, "no") == 0)
|
|
|
|
|
e->d.include.if_selinux_enabled = FALSE;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"if_selinux_enabled attribute must have value"
|
|
|
|
|
" \"yes\" or \"no\"");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-23 16:09:54 +00:00
|
|
|
|
|
|
|
|
if (selinux_root_relative != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (selinux_root_relative, "yes") == 0)
|
|
|
|
|
e->d.include.selinux_root_relative = TRUE;
|
|
|
|
|
else if (strcmp (selinux_root_relative, "no") == 0)
|
|
|
|
|
e->d.include.selinux_root_relative = FALSE;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"selinux_root_relative attribute must have value"
|
|
|
|
|
" \"yes\" or \"no\"");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_POLICY)
|
2003-03-31 04:01:00 +00:00
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
const char *context;
|
|
|
|
|
const char *user;
|
|
|
|
|
const char *group;
|
2004-08-25 22:11:49 +00:00
|
|
|
const char *at_console;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
e->d.policy.type = POLICY_IGNORED;
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
if (!locate_attributes (parser, "policy",
|
2003-03-31 04:01:00 +00:00
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
|
|
|
|
"context", &context,
|
|
|
|
|
"user", &user,
|
|
|
|
|
"group", &group,
|
2004-08-25 22:11:49 +00:00
|
|
|
"at_console", &at_console,
|
2003-03-31 04:01:00 +00:00
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
if (((context && user) ||
|
2004-08-25 22:11:49 +00:00
|
|
|
(context && group) ||
|
|
|
|
|
(context && at_console)) ||
|
|
|
|
|
((user && group) ||
|
|
|
|
|
(user && at_console)) ||
|
|
|
|
|
(group && at_console) ||
|
|
|
|
|
!(context || user || group || at_console))
|
2003-04-12 18:32:11 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
2004-08-25 22:11:49 +00:00
|
|
|
"<policy> element must have exactly one of (context|user|group|at_console) attributes");
|
2003-04-12 18:32:11 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (context, "default") == 0)
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
e->d.policy.type = POLICY_DEFAULT;
|
2003-04-12 18:32:11 +00:00
|
|
|
}
|
|
|
|
|
else if (strcmp (context, "mandatory") == 0)
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
e->d.policy.type = POLICY_MANDATORY;
|
2003-04-12 18:32:11 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"",
|
|
|
|
|
context);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (user != NULL)
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
DBusString username;
|
|
|
|
|
_dbus_string_init_const (&username, user);
|
2003-04-12 18:32:11 +00:00
|
|
|
|
2007-06-09 23:41:33 +00:00
|
|
|
if (_dbus_parse_unix_user_from_config (&username,
|
|
|
|
|
&e->d.policy.gid_uid_or_at_console))
|
2003-04-13 08:33:10 +00:00
|
|
|
e->d.policy.type = POLICY_USER;
|
|
|
|
|
else
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Unknown username \"%s\" in message bus configuration file",
|
2003-04-13 08:33:10 +00:00
|
|
|
user);
|
2003-04-12 18:32:11 +00:00
|
|
|
}
|
|
|
|
|
else if (group != NULL)
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
DBusString group_name;
|
|
|
|
|
_dbus_string_init_const (&group_name, group);
|
2003-04-12 18:32:11 +00:00
|
|
|
|
2007-06-09 23:41:33 +00:00
|
|
|
if (_dbus_parse_unix_group_from_config (&group_name,
|
|
|
|
|
&e->d.policy.gid_uid_or_at_console))
|
2003-04-13 08:33:10 +00:00
|
|
|
e->d.policy.type = POLICY_GROUP;
|
|
|
|
|
else
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Unknown group \"%s\" in message bus configuration file",
|
2003-04-13 08:33:10 +00:00
|
|
|
group);
|
2003-04-12 18:32:11 +00:00
|
|
|
}
|
2004-08-25 22:11:49 +00:00
|
|
|
else if (at_console != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t t;
|
|
|
|
|
t = (strcmp (at_console, "true") == 0);
|
|
|
|
|
if (t || strcmp (at_console, "false") == 0)
|
|
|
|
|
{
|
|
|
|
|
e->d.policy.gid_uid_or_at_console = t;
|
|
|
|
|
e->d.policy.type = POLICY_CONSOLE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Unknown value \"%s\" for at_console in message bus configuration file",
|
|
|
|
|
at_console);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-12 18:32:11 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-04-24 22:30:38 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_LIMIT)
|
2003-04-24 22:30:38 +00:00
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!locate_attributes (parser, "limit",
|
|
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
|
|
|
|
"name", &name,
|
|
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<limit> element must have a \"name\" attribute");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e->d.limit.name = _dbus_strdup (name);
|
|
|
|
|
if (e->d.limit.name == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-30 05:59:34 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
else if (element_type == ELEMENT_SELINUX)
|
2004-07-30 05:59:34 +00:00
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_SELINUX) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2014-02-10 19:02:04 -06:00
|
|
|
else if (element_type == ELEMENT_APPARMOR)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
const char *mode;
|
|
|
|
|
|
|
|
|
|
if ((e = push_element (parser, ELEMENT_APPARMOR)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!locate_attributes (parser, "apparmor",
|
|
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
|
|
|
|
"mode", &mode,
|
|
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return bus_apparmor_set_mode_from_config (mode, error);
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> not allowed inside <%s> in configuration file",
|
|
|
|
|
element_name, "busconfig");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
append_rule_from_element (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
dbus_bool_t allow,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2008-12-16 11:57:27 -05:00
|
|
|
const char *log;
|
2003-08-18 15:27:33 +00:00
|
|
|
const char *send_interface;
|
|
|
|
|
const char *send_member;
|
|
|
|
|
const char *send_error;
|
2003-09-21 19:53:56 +00:00
|
|
|
const char *send_destination;
|
2003-09-06 21:12:11 +00:00
|
|
|
const char *send_path;
|
|
|
|
|
const char *send_type;
|
2003-08-18 15:27:33 +00:00
|
|
|
const char *receive_interface;
|
|
|
|
|
const char *receive_member;
|
|
|
|
|
const char *receive_error;
|
2003-09-21 19:53:56 +00:00
|
|
|
const char *receive_sender;
|
2003-09-06 21:12:11 +00:00
|
|
|
const char *receive_path;
|
|
|
|
|
const char *receive_type;
|
2003-09-21 19:53:56 +00:00
|
|
|
const char *eavesdrop;
|
2004-05-29 04:17:17 +00:00
|
|
|
const char *send_requested_reply;
|
|
|
|
|
const char *receive_requested_reply;
|
2003-04-13 08:33:10 +00:00
|
|
|
const char *own;
|
2012-03-04 14:36:56 +00:00
|
|
|
const char *own_prefix;
|
2003-04-13 08:33:10 +00:00
|
|
|
const char *user;
|
|
|
|
|
const char *group;
|
2004-08-25 22:11:49 +00:00
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
BusPolicyRule *rule;
|
|
|
|
|
|
|
|
|
|
if (!locate_attributes (parser, element_name,
|
|
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
2003-08-18 15:27:33 +00:00
|
|
|
"send_interface", &send_interface,
|
|
|
|
|
"send_member", &send_member,
|
|
|
|
|
"send_error", &send_error,
|
2003-09-21 19:53:56 +00:00
|
|
|
"send_destination", &send_destination,
|
2003-09-06 21:12:11 +00:00
|
|
|
"send_path", &send_path,
|
|
|
|
|
"send_type", &send_type,
|
2003-08-18 15:27:33 +00:00
|
|
|
"receive_interface", &receive_interface,
|
|
|
|
|
"receive_member", &receive_member,
|
|
|
|
|
"receive_error", &receive_error,
|
2003-09-21 19:53:56 +00:00
|
|
|
"receive_sender", &receive_sender,
|
2003-09-06 21:12:11 +00:00
|
|
|
"receive_path", &receive_path,
|
|
|
|
|
"receive_type", &receive_type,
|
2003-09-21 19:53:56 +00:00
|
|
|
"eavesdrop", &eavesdrop,
|
2004-05-29 04:17:17 +00:00
|
|
|
"send_requested_reply", &send_requested_reply,
|
|
|
|
|
"receive_requested_reply", &receive_requested_reply,
|
2003-04-13 08:33:10 +00:00
|
|
|
"own", &own,
|
2012-03-04 14:36:56 +00:00
|
|
|
"own_prefix", &own_prefix,
|
2003-04-13 08:33:10 +00:00
|
|
|
"user", &user,
|
|
|
|
|
"group", &group,
|
2008-12-16 11:57:27 -05:00
|
|
|
"log", &log,
|
2003-04-13 08:33:10 +00:00
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
if (!(send_interface || send_member || send_error || send_destination ||
|
2003-09-06 21:12:11 +00:00
|
|
|
send_type || send_path ||
|
2003-09-21 19:53:56 +00:00
|
|
|
receive_interface || receive_member || receive_error || receive_sender ||
|
2004-05-29 04:17:17 +00:00
|
|
|
receive_type || receive_path || eavesdrop ||
|
|
|
|
|
send_requested_reply || receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix || user || group))
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> must have one or more attributes",
|
|
|
|
|
element_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
if ((send_member && (send_interface == NULL && send_path == NULL)) ||
|
|
|
|
|
(receive_member && (receive_interface == NULL && receive_path == NULL)))
|
2003-08-18 15:27:33 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
2003-09-06 21:12:11 +00:00
|
|
|
"On element <%s>, if you specify a member you must specify an interface or a path. Keep in mind that not all messages have an interface field.",
|
2003-08-18 15:27:33 +00:00
|
|
|
element_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allowed combinations of elements are:
|
|
|
|
|
*
|
|
|
|
|
* base, must be all send or all receive:
|
2003-09-06 21:12:11 +00:00
|
|
|
* nothing
|
2003-08-18 15:27:33 +00:00
|
|
|
* interface
|
|
|
|
|
* interface + member
|
|
|
|
|
* error
|
|
|
|
|
*
|
2004-05-29 04:17:17 +00:00
|
|
|
* base send_ can combine with send_destination, send_path, send_type, send_requested_reply
|
|
|
|
|
* base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop
|
2003-08-18 15:27:33 +00:00
|
|
|
*
|
2012-03-04 14:36:56 +00:00
|
|
|
* user, group, own, own_prefix must occur alone
|
2003-09-21 19:53:56 +00:00
|
|
|
*
|
|
|
|
|
* Pretty sure the below stuff is broken, FIXME think about it more.
|
2003-08-18 15:27:33 +00:00
|
|
|
*/
|
2003-04-13 08:33:10 +00:00
|
|
|
|
2011-03-14 11:45:04 +00:00
|
|
|
if ((send_interface && (send_error ||
|
|
|
|
|
receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(send_member && (send_error ||
|
|
|
|
|
receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(send_error && (receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(send_destination && (receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(send_type && (receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(send_path && (receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(send_requested_reply && (receive_interface ||
|
|
|
|
|
receive_member ||
|
|
|
|
|
receive_error ||
|
|
|
|
|
receive_sender ||
|
|
|
|
|
receive_requested_reply ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(receive_interface && (receive_error ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
|
|
|
|
(receive_member && (receive_error ||
|
2012-03-04 14:36:56 +00:00
|
|
|
own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
2012-03-04 14:36:56 +00:00
|
|
|
(receive_error && (own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
2012-03-04 14:36:56 +00:00
|
|
|
(eavesdrop && (own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
2012-03-04 14:36:56 +00:00
|
|
|
(receive_requested_reply && (own || own_prefix ||
|
2011-03-14 11:45:04 +00:00
|
|
|
user ||
|
|
|
|
|
group)) ||
|
|
|
|
|
|
2012-03-04 14:36:56 +00:00
|
|
|
(own && (own_prefix || user || group)) ||
|
|
|
|
|
|
|
|
|
|
(own_prefix && (own || user || group)) ||
|
2011-03-14 11:45:04 +00:00
|
|
|
|
|
|
|
|
(user && group))
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
2003-09-21 19:53:56 +00:00
|
|
|
"Invalid combination of attributes on element <%s>",
|
2003-04-13 08:33:10 +00:00
|
|
|
element_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-09-06 21:12:11 +00:00
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
rule = NULL;
|
|
|
|
|
|
|
|
|
|
/* In BusPolicyRule, NULL represents wildcard.
|
|
|
|
|
* In the config file, '*' represents it.
|
|
|
|
|
*/
|
|
|
|
|
#define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
|
|
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
if (send_interface || send_member || send_error || send_destination ||
|
2004-05-29 04:17:17 +00:00
|
|
|
send_path || send_type || send_requested_reply)
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
2003-09-06 21:12:11 +00:00
|
|
|
int message_type;
|
2003-04-13 08:33:10 +00:00
|
|
|
|
2003-08-18 15:27:33 +00:00
|
|
|
if (IS_WILDCARD (send_interface))
|
|
|
|
|
send_interface = NULL;
|
|
|
|
|
if (IS_WILDCARD (send_member))
|
|
|
|
|
send_member = NULL;
|
|
|
|
|
if (IS_WILDCARD (send_error))
|
|
|
|
|
send_error = NULL;
|
2003-09-21 19:53:56 +00:00
|
|
|
if (IS_WILDCARD (send_destination))
|
|
|
|
|
send_destination = NULL;
|
2003-09-06 21:12:11 +00:00
|
|
|
if (IS_WILDCARD (send_path))
|
|
|
|
|
send_path = NULL;
|
|
|
|
|
if (IS_WILDCARD (send_type))
|
|
|
|
|
send_type = NULL;
|
|
|
|
|
|
|
|
|
|
message_type = DBUS_MESSAGE_TYPE_INVALID;
|
|
|
|
|
if (send_type != NULL)
|
|
|
|
|
{
|
2003-10-10 02:42:21 +00:00
|
|
|
message_type = dbus_message_type_from_string (send_type);
|
2003-09-06 21:12:11 +00:00
|
|
|
if (message_type == DBUS_MESSAGE_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Bad message type \"%s\"",
|
|
|
|
|
send_type);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-05-29 04:17:17 +00:00
|
|
|
|
2007-03-15 13:27:01 +00:00
|
|
|
if (eavesdrop &&
|
|
|
|
|
!(strcmp (eavesdrop, "true") == 0 ||
|
|
|
|
|
strcmp (eavesdrop, "false") == 0))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Bad value \"%s\" for %s attribute, must be true or false",
|
|
|
|
|
"eavesdrop", eavesdrop);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-29 04:17:17 +00:00
|
|
|
if (send_requested_reply &&
|
|
|
|
|
!(strcmp (send_requested_reply, "true") == 0 ||
|
|
|
|
|
strcmp (send_requested_reply, "false") == 0))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Bad value \"%s\" for %s attribute, must be true or false",
|
|
|
|
|
"send_requested_reply", send_requested_reply);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-08-18 15:27:33 +00:00
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
2003-09-21 19:53:56 +00:00
|
|
|
|
2007-03-15 13:27:01 +00:00
|
|
|
if (eavesdrop)
|
|
|
|
|
rule->d.send.eavesdrop = (strcmp (eavesdrop, "true") == 0);
|
|
|
|
|
|
2008-12-16 11:57:27 -05:00
|
|
|
if (log)
|
|
|
|
|
rule->d.send.log = (strcmp (log, "true") == 0);
|
|
|
|
|
|
2004-05-29 04:17:17 +00:00
|
|
|
if (send_requested_reply)
|
|
|
|
|
rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0);
|
2007-03-15 13:27:01 +00:00
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
rule->d.send.message_type = message_type;
|
|
|
|
|
rule->d.send.path = _dbus_strdup (send_path);
|
2003-08-18 15:27:33 +00:00
|
|
|
rule->d.send.interface = _dbus_strdup (send_interface);
|
|
|
|
|
rule->d.send.member = _dbus_strdup (send_member);
|
|
|
|
|
rule->d.send.error = _dbus_strdup (send_error);
|
2003-09-21 19:53:56 +00:00
|
|
|
rule->d.send.destination = _dbus_strdup (send_destination);
|
2003-09-06 21:12:11 +00:00
|
|
|
if (send_path && rule->d.send.path == NULL)
|
|
|
|
|
goto nomem;
|
2003-08-18 15:27:33 +00:00
|
|
|
if (send_interface && rule->d.send.interface == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
if (send_member && rule->d.send.member == NULL)
|
2003-04-13 08:33:10 +00:00
|
|
|
goto nomem;
|
2003-08-18 15:27:33 +00:00
|
|
|
if (send_error && rule->d.send.error == NULL)
|
|
|
|
|
goto nomem;
|
2003-09-21 19:53:56 +00:00
|
|
|
if (send_destination && rule->d.send.destination == NULL)
|
2003-04-13 08:33:10 +00:00
|
|
|
goto nomem;
|
|
|
|
|
}
|
2003-09-21 19:53:56 +00:00
|
|
|
else if (receive_interface || receive_member || receive_error || receive_sender ||
|
2004-05-29 04:17:17 +00:00
|
|
|
receive_path || receive_type || eavesdrop || receive_requested_reply)
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
2003-09-06 21:12:11 +00:00
|
|
|
int message_type;
|
2003-04-13 08:33:10 +00:00
|
|
|
|
2003-08-18 15:27:33 +00:00
|
|
|
if (IS_WILDCARD (receive_interface))
|
|
|
|
|
receive_interface = NULL;
|
|
|
|
|
if (IS_WILDCARD (receive_member))
|
|
|
|
|
receive_member = NULL;
|
|
|
|
|
if (IS_WILDCARD (receive_error))
|
|
|
|
|
receive_error = NULL;
|
2003-09-21 19:53:56 +00:00
|
|
|
if (IS_WILDCARD (receive_sender))
|
|
|
|
|
receive_sender = NULL;
|
2003-09-06 21:12:11 +00:00
|
|
|
if (IS_WILDCARD (receive_path))
|
|
|
|
|
receive_path = NULL;
|
|
|
|
|
if (IS_WILDCARD (receive_type))
|
|
|
|
|
receive_type = NULL;
|
|
|
|
|
|
|
|
|
|
message_type = DBUS_MESSAGE_TYPE_INVALID;
|
|
|
|
|
if (receive_type != NULL)
|
|
|
|
|
{
|
2003-10-10 02:42:21 +00:00
|
|
|
message_type = dbus_message_type_from_string (receive_type);
|
2003-09-06 21:12:11 +00:00
|
|
|
if (message_type == DBUS_MESSAGE_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Bad message type \"%s\"",
|
|
|
|
|
receive_type);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-21 19:53:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if (eavesdrop &&
|
|
|
|
|
!(strcmp (eavesdrop, "true") == 0 ||
|
|
|
|
|
strcmp (eavesdrop, "false") == 0))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
2003-10-14 22:16:03 +00:00
|
|
|
"Bad value \"%s\" for %s attribute, must be true or false",
|
|
|
|
|
"eavesdrop", eavesdrop);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-29 04:17:17 +00:00
|
|
|
if (receive_requested_reply &&
|
|
|
|
|
!(strcmp (receive_requested_reply, "true") == 0 ||
|
|
|
|
|
strcmp (receive_requested_reply, "false") == 0))
|
2003-10-14 22:16:03 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Bad value \"%s\" for %s attribute, must be true or false",
|
2004-05-29 04:17:17 +00:00
|
|
|
"receive_requested_reply", receive_requested_reply);
|
2003-09-21 19:53:56 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-09-06 21:12:11 +00:00
|
|
|
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
2003-08-18 15:27:33 +00:00
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
if (eavesdrop)
|
|
|
|
|
rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0);
|
2003-10-14 22:16:03 +00:00
|
|
|
|
2004-05-29 04:17:17 +00:00
|
|
|
if (receive_requested_reply)
|
|
|
|
|
rule->d.receive.requested_reply = (strcmp (receive_requested_reply, "true") == 0);
|
2003-09-21 19:53:56 +00:00
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
rule->d.receive.message_type = message_type;
|
|
|
|
|
rule->d.receive.path = _dbus_strdup (receive_path);
|
2003-08-18 15:27:33 +00:00
|
|
|
rule->d.receive.interface = _dbus_strdup (receive_interface);
|
|
|
|
|
rule->d.receive.member = _dbus_strdup (receive_member);
|
|
|
|
|
rule->d.receive.error = _dbus_strdup (receive_error);
|
2003-09-21 19:53:56 +00:00
|
|
|
rule->d.receive.origin = _dbus_strdup (receive_sender);
|
2003-10-14 22:16:03 +00:00
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
if (receive_path && rule->d.receive.path == NULL)
|
|
|
|
|
goto nomem;
|
2003-08-18 15:27:33 +00:00
|
|
|
if (receive_interface && rule->d.receive.interface == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
if (receive_member && rule->d.receive.member == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
if (receive_error && rule->d.receive.error == NULL)
|
2003-04-13 08:33:10 +00:00
|
|
|
goto nomem;
|
2003-09-21 19:53:56 +00:00
|
|
|
if (receive_sender && rule->d.receive.origin == NULL)
|
2003-04-13 08:33:10 +00:00
|
|
|
goto nomem;
|
|
|
|
|
}
|
2012-03-04 14:36:56 +00:00
|
|
|
else if (own || own_prefix)
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2012-03-04 14:36:56 +00:00
|
|
|
if (own)
|
|
|
|
|
{
|
|
|
|
|
if (IS_WILDCARD (own))
|
|
|
|
|
own = NULL;
|
2003-04-13 08:33:10 +00:00
|
|
|
|
2012-03-04 14:36:56 +00:00
|
|
|
rule->d.own.prefix = 0;
|
|
|
|
|
rule->d.own.service_name = _dbus_strdup (own);
|
|
|
|
|
if (own && rule->d.own.service_name == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rule->d.own.prefix = 1;
|
|
|
|
|
rule->d.own.service_name = _dbus_strdup (own_prefix);
|
|
|
|
|
if (rule->d.own.service_name == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
2003-04-13 08:33:10 +00:00
|
|
|
}
|
|
|
|
|
else if (user)
|
|
|
|
|
{
|
|
|
|
|
if (IS_WILDCARD (user))
|
|
|
|
|
{
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
rule->d.user.uid = DBUS_UID_UNSET;
|
2003-04-13 08:33:10 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DBusString username;
|
|
|
|
|
dbus_uid_t uid;
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&username, user);
|
|
|
|
|
|
2007-06-09 23:41:33 +00:00
|
|
|
if (_dbus_parse_unix_user_from_config (&username, &uid))
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
2003-04-14 02:29:21 +00:00
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
rule->d.user.uid = uid;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Unknown username \"%s\" on element <%s>",
|
2003-04-13 08:33:10 +00:00
|
|
|
user, element_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (group)
|
|
|
|
|
{
|
|
|
|
|
if (IS_WILDCARD (group))
|
|
|
|
|
{
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
rule->d.group.gid = DBUS_GID_UNSET;
|
2003-04-13 08:33:10 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DBusString groupname;
|
|
|
|
|
dbus_gid_t gid;
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&groupname, group);
|
|
|
|
|
|
2007-06-09 23:41:33 +00:00
|
|
|
if (_dbus_parse_unix_group_from_config (&groupname, &gid))
|
2003-04-13 08:33:10 +00:00
|
|
|
{
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
2003-04-14 02:29:21 +00:00
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
rule->d.group.gid = gid;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Unknown group \"%s\" on element <%s>",
|
2003-04-13 08:33:10 +00:00
|
|
|
group, element_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>");
|
|
|
|
|
|
|
|
|
|
if (rule != NULL)
|
|
|
|
|
{
|
|
|
|
|
Element *pe;
|
|
|
|
|
|
|
|
|
|
pe = peek_element (parser);
|
|
|
|
|
_dbus_assert (pe != NULL);
|
|
|
|
|
_dbus_assert (pe->type == ELEMENT_POLICY);
|
|
|
|
|
|
|
|
|
|
switch (pe->d.policy.type)
|
|
|
|
|
{
|
|
|
|
|
case POLICY_IGNORED:
|
2017-01-17 20:58:06 +00:00
|
|
|
default:
|
2003-04-13 08:33:10 +00:00
|
|
|
/* drop the rule on the floor */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case POLICY_DEFAULT:
|
|
|
|
|
if (!bus_policy_append_default_rule (parser->policy, rule))
|
|
|
|
|
goto nomem;
|
|
|
|
|
break;
|
|
|
|
|
case POLICY_MANDATORY:
|
|
|
|
|
if (!bus_policy_append_mandatory_rule (parser->policy, rule))
|
|
|
|
|
goto nomem;
|
|
|
|
|
break;
|
|
|
|
|
case POLICY_USER:
|
|
|
|
|
if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<%s> rule cannot be per-user because it has bus-global semantics",
|
|
|
|
|
element_name);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-25 22:11:49 +00:00
|
|
|
if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
|
2003-04-13 08:33:10 +00:00
|
|
|
rule))
|
|
|
|
|
goto nomem;
|
|
|
|
|
break;
|
|
|
|
|
case POLICY_GROUP:
|
|
|
|
|
if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<%s> rule cannot be per-group because it has bus-global semantics",
|
|
|
|
|
element_name);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-25 22:11:49 +00:00
|
|
|
if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
|
|
|
|
|
rule))
|
|
|
|
|
goto nomem;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case POLICY_CONSOLE:
|
|
|
|
|
if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
|
2007-06-09 23:41:33 +00:00
|
|
|
rule))
|
2003-04-13 08:33:10 +00:00
|
|
|
goto nomem;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-25 22:11:49 +00:00
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
bus_policy_rule_unref (rule);
|
|
|
|
|
rule = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
failed:
|
|
|
|
|
if (rule)
|
|
|
|
|
bus_policy_rule_unref (rule);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
start_policy_child (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (element_name, "allow") == 0)
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
if (!append_rule_from_element (parser, element_name,
|
|
|
|
|
attribute_names, attribute_values,
|
|
|
|
|
TRUE, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
if (push_element (parser, ELEMENT_ALLOW) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "deny") == 0)
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
if (!append_rule_from_element (parser, element_name,
|
|
|
|
|
attribute_names, attribute_values,
|
|
|
|
|
FALSE, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
if (push_element (parser, ELEMENT_DENY) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> not allowed inside <%s> in configuration file",
|
|
|
|
|
element_name, "policy");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-30 05:59:34 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
start_selinux_child (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2006-08-08 23:29:03 +00:00
|
|
|
char *own_copy;
|
|
|
|
|
char *context_copy;
|
|
|
|
|
|
|
|
|
|
own_copy = NULL;
|
|
|
|
|
context_copy = NULL;
|
|
|
|
|
|
2004-07-30 05:59:34 +00:00
|
|
|
if (strcmp (element_name, "associate") == 0)
|
|
|
|
|
{
|
|
|
|
|
const char *own;
|
|
|
|
|
const char *context;
|
|
|
|
|
|
|
|
|
|
if (!locate_attributes (parser, "associate",
|
|
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
|
|
|
|
"own", &own,
|
|
|
|
|
"context", &context,
|
|
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_ASSOCIATE) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (own == NULL || context == NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <associate> must have attributes own=\"<servicename>\" and context=\"<selinux context>\"");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
own_copy = _dbus_strdup (own);
|
|
|
|
|
if (own_copy == NULL)
|
2006-08-08 23:29:03 +00:00
|
|
|
goto oom;
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
context_copy = _dbus_strdup (context);
|
|
|
|
|
if (context_copy == NULL)
|
2006-08-08 23:29:03 +00:00
|
|
|
goto oom;
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (parser->service_context_table,
|
|
|
|
|
own_copy, context_copy))
|
2006-08-08 23:29:03 +00:00
|
|
|
goto oom;
|
|
|
|
|
|
2004-07-30 05:59:34 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> not allowed inside <%s> in configuration file",
|
|
|
|
|
element_name, "selinux");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2006-08-08 23:29:03 +00:00
|
|
|
|
|
|
|
|
oom:
|
|
|
|
|
if (own_copy)
|
|
|
|
|
dbus_free (own_copy);
|
|
|
|
|
|
|
|
|
|
if (context_copy)
|
|
|
|
|
dbus_free (context_copy);
|
|
|
|
|
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
2004-07-30 05:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_start_element (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
ElementType t;
|
2003-03-25 04:45:25 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
|
|
|
|
/* printf ("START: %s\n", element_name); */
|
|
|
|
|
|
|
|
|
|
t = top_element_type (parser);
|
|
|
|
|
|
|
|
|
|
if (t == ELEMENT_NONE)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (element_name, "busconfig") == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
|
|
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Unknown element <%s> at root of configuration file",
|
|
|
|
|
element_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (t == ELEMENT_BUSCONFIG)
|
|
|
|
|
{
|
|
|
|
|
return start_busconfig_child (parser, element_name,
|
|
|
|
|
attribute_names, attribute_values,
|
|
|
|
|
error);
|
|
|
|
|
}
|
|
|
|
|
else if (t == ELEMENT_POLICY)
|
|
|
|
|
{
|
|
|
|
|
return start_policy_child (parser, element_name,
|
|
|
|
|
attribute_names, attribute_values,
|
|
|
|
|
error);
|
|
|
|
|
}
|
2004-07-30 05:59:34 +00:00
|
|
|
else if (t == ELEMENT_SELINUX)
|
|
|
|
|
{
|
|
|
|
|
return start_selinux_child (parser, element_name,
|
|
|
|
|
attribute_names, attribute_values,
|
|
|
|
|
error);
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> is not allowed in this context",
|
|
|
|
|
element_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-25 04:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-24 22:30:38 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
set_limit (BusConfigParser *parser,
|
|
|
|
|
const char *name,
|
|
|
|
|
long value,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t must_be_positive;
|
|
|
|
|
dbus_bool_t must_be_int;
|
|
|
|
|
|
|
|
|
|
must_be_int = FALSE;
|
|
|
|
|
must_be_positive = FALSE;
|
|
|
|
|
|
|
|
|
|
if (strcmp (name, "max_incoming_bytes") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_incoming_bytes = value;
|
|
|
|
|
}
|
2009-05-20 01:33:17 +02:00
|
|
|
else if (strcmp (name, "max_incoming_unix_fds") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_incoming_unix_fds = value;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
else if (strcmp (name, "max_outgoing_bytes") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_outgoing_bytes = value;
|
|
|
|
|
}
|
2009-05-20 01:33:17 +02:00
|
|
|
else if (strcmp (name, "max_outgoing_unix_fds") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_outgoing_unix_fds = value;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
else if (strcmp (name, "max_message_size") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_message_size = value;
|
|
|
|
|
}
|
2009-05-20 01:33:17 +02:00
|
|
|
else if (strcmp (name, "max_message_unix_fds") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_message_unix_fds = value;
|
|
|
|
|
}
|
2005-01-18 20:42:15 +00:00
|
|
|
else if (strcmp (name, "service_start_timeout") == 0)
|
2003-04-24 22:30:38 +00:00
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.activation_timeout = value;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "auth_timeout") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.auth_timeout = value;
|
|
|
|
|
}
|
2014-07-21 17:34:08 +01:00
|
|
|
else if (strcmp (name, "pending_fd_timeout") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.pending_fd_timeout = value;
|
|
|
|
|
}
|
2003-10-14 05:16:56 +00:00
|
|
|
else if (strcmp (name, "reply_timeout") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.reply_timeout = value;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
else if (strcmp (name, "max_completed_connections") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_completed_connections = value;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "max_incomplete_connections") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_incomplete_connections = value;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "max_connections_per_user") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_connections_per_user = value;
|
|
|
|
|
}
|
2005-01-18 20:42:15 +00:00
|
|
|
else if (strcmp (name, "max_pending_service_starts") == 0)
|
2003-04-25 23:50:34 +00:00
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_pending_activations = value;
|
|
|
|
|
}
|
2005-01-18 20:42:15 +00:00
|
|
|
else if (strcmp (name, "max_names_per_connection") == 0)
|
2003-04-25 23:50:34 +00:00
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_services_per_connection = value;
|
|
|
|
|
}
|
2004-08-25 08:03:12 +00:00
|
|
|
else if (strcmp (name, "max_match_rules_per_connection") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_match_rules_per_connection = value;
|
|
|
|
|
}
|
2003-10-14 05:16:56 +00:00
|
|
|
else if (strcmp (name, "max_replies_per_connection") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_replies_per_connection = value;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"There is no limit called \"%s\"\n",
|
|
|
|
|
name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (must_be_positive && value < 0)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<limit name=\"%s\"> must be a positive number\n",
|
|
|
|
|
name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (must_be_int &&
|
|
|
|
|
(value < _DBUS_INT_MIN || value > _DBUS_INT_MAX))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<limit name=\"%s\"> value is too large\n",
|
|
|
|
|
name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_end_element (BusConfigParser *parser,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
ElementType t;
|
|
|
|
|
const char *n;
|
|
|
|
|
Element *e;
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-25 04:45:25 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
/* printf ("END: %s\n", element_name); */
|
|
|
|
|
|
|
|
|
|
t = top_element_type (parser);
|
|
|
|
|
|
|
|
|
|
if (t == ELEMENT_NONE)
|
|
|
|
|
{
|
|
|
|
|
/* should probably be an assertion failure but
|
|
|
|
|
* being paranoid about XML parsers
|
|
|
|
|
*/
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"XML parser ended element with no element on the stack");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
n = bus_config_parser_element_type_to_name (t);
|
2003-03-31 04:01:00 +00:00
|
|
|
_dbus_assert (n != NULL);
|
|
|
|
|
if (strcmp (n, element_name) != 0)
|
|
|
|
|
{
|
|
|
|
|
/* should probably be an assertion failure but
|
|
|
|
|
* being paranoid about XML parsers
|
|
|
|
|
*/
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
2003-04-03 05:22:49 +00:00
|
|
|
"XML element <%s> ended but topmost element on the stack was <%s>",
|
|
|
|
|
element_name, n);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e = peek_element (parser);
|
|
|
|
|
_dbus_assert (e != NULL);
|
|
|
|
|
|
|
|
|
|
switch (e->type)
|
|
|
|
|
{
|
|
|
|
|
case ELEMENT_NONE:
|
2017-01-17 20:59:57 +00:00
|
|
|
default:
|
2003-03-31 04:01:00 +00:00
|
|
|
_dbus_assert_not_reached ("element in stack has no type");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_INCLUDE:
|
|
|
|
|
case ELEMENT_USER:
|
2011-03-07 11:43:23 +01:00
|
|
|
case ELEMENT_CONFIGTYPE:
|
2003-03-31 04:01:00 +00:00
|
|
|
case ELEMENT_LISTEN:
|
2003-04-06 23:15:41 +00:00
|
|
|
case ELEMENT_PIDFILE:
|
2003-03-31 04:01:00 +00:00
|
|
|
case ELEMENT_AUTH:
|
2003-04-02 00:29:33 +00:00
|
|
|
case ELEMENT_SERVICEDIR:
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
case ELEMENT_SERVICEHELPER:
|
2003-04-02 00:29:33 +00:00
|
|
|
case ELEMENT_INCLUDEDIR:
|
2003-04-24 22:30:38 +00:00
|
|
|
case ELEMENT_LIMIT:
|
2003-03-31 04:01:00 +00:00
|
|
|
if (!e->had_content)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"XML element <%s> was expected to have content inside it",
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
bus_config_parser_element_type_to_name (e->type));
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
|
|
|
|
|
if (e->type == ELEMENT_LIMIT)
|
|
|
|
|
{
|
|
|
|
|
if (!set_limit (parser, e->d.limit.name, e->d.limit.value,
|
|
|
|
|
error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_BUSCONFIG:
|
|
|
|
|
case ELEMENT_POLICY:
|
|
|
|
|
case ELEMENT_ALLOW:
|
|
|
|
|
case ELEMENT_DENY:
|
2003-04-01 05:33:01 +00:00
|
|
|
case ELEMENT_FORK:
|
2008-12-10 14:17:02 -05:00
|
|
|
case ELEMENT_SYSLOG:
|
2008-11-10 08:55:27 -05:00
|
|
|
case ELEMENT_KEEP_UMASK:
|
2004-07-30 05:59:34 +00:00
|
|
|
case ELEMENT_SELINUX:
|
|
|
|
|
case ELEMENT_ASSOCIATE:
|
2006-11-01 23:30:46 +00:00
|
|
|
case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
|
2008-11-12 08:51:00 -05:00
|
|
|
case ELEMENT_ALLOW_ANONYMOUS:
|
2014-02-10 19:02:04 -06:00
|
|
|
case ELEMENT_APPARMOR:
|
2003-03-31 04:01:00 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pop_element (parser);
|
|
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
return TRUE;
|
2003-03-25 04:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
all_whitespace (const DBusString *str)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
_dbus_string_skip_white (str, 0, &i);
|
|
|
|
|
|
|
|
|
|
return i == _dbus_string_get_length (str);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
make_full_path (const DBusString *basedir,
|
|
|
|
|
const DBusString *filename,
|
|
|
|
|
DBusString *full_path)
|
|
|
|
|
{
|
|
|
|
|
if (_dbus_path_is_absolute (filename))
|
|
|
|
|
{
|
2015-10-01 13:05:02 +01:00
|
|
|
if (!_dbus_string_copy (filename, 0, full_path, 0))
|
|
|
|
|
return FALSE;
|
2003-04-02 21:43:29 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_string_copy (basedir, 0, full_path, 0))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (full_path, filename))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2015-10-01 13:05:02 +01:00
|
|
|
|
|
|
|
|
if (!_dbus_replace_install_prefix (full_path))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2003-04-02 21:43:29 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
include_file (BusConfigParser *parser,
|
|
|
|
|
const DBusString *filename,
|
|
|
|
|
dbus_bool_t ignore_missing,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME good test case for this would load each config file in the
|
|
|
|
|
* test suite both alone, and as an include, and check
|
|
|
|
|
* that the result is the same
|
|
|
|
|
*/
|
|
|
|
|
BusConfigParser *included;
|
2004-04-13 01:37:57 +00:00
|
|
|
const char *filename_str;
|
2003-04-02 00:29:33 +00:00
|
|
|
DBusError tmp_error;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&tmp_error);
|
2004-04-09 19:50:29 +00:00
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
filename_str = _dbus_string_get_const_data (filename);
|
|
|
|
|
|
|
|
|
|
/* Check to make sure this file hasn't already been included. */
|
|
|
|
|
if (seen_include (parser, filename))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Circular inclusion of file '%s'",
|
|
|
|
|
filename_str);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! _dbus_list_append (&parser->included_files, (void *) filename_str))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
/* Since parser is passed in as the parent, included
|
|
|
|
|
inherits parser's limits. */
|
|
|
|
|
included = bus_config_load (filename, FALSE, parser, &tmp_error);
|
|
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
_dbus_list_pop_last (&parser->included_files);
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
if (included == NULL)
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) &&
|
|
|
|
|
ignore_missing)
|
|
|
|
|
{
|
|
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
|
|
|
|
|
|
|
|
|
|
if (!merge_included (parser, included, error))
|
|
|
|
|
{
|
|
|
|
|
bus_config_parser_unref (included);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
/* Copy included's limits back to parser. */
|
|
|
|
|
parser->limits = included->limits;
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
bus_config_parser_unref (included);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
servicehelper_path (BusConfigParser *parser,
|
|
|
|
|
const DBusString *filename,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
const char *filename_str;
|
|
|
|
|
char *servicehelper;
|
|
|
|
|
|
2007-07-24 22:11:00 +00:00
|
|
|
filename_str = _dbus_string_get_const_data (filename);
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
|
|
|
|
|
/* copy to avoid overwriting with NULL on OOM */
|
|
|
|
|
servicehelper = _dbus_strdup (filename_str);
|
|
|
|
|
|
|
|
|
|
/* check for OOM */
|
|
|
|
|
if (servicehelper == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* save the latest servicehelper only if not OOM */
|
|
|
|
|
dbus_free (parser->servicehelper);
|
|
|
|
|
parser->servicehelper = servicehelper;
|
|
|
|
|
|
2007-07-24 22:11:00 +00:00
|
|
|
/* We don't check whether the helper exists; instead we
|
|
|
|
|
* would just fail to ever activate anything if it doesn't.
|
|
|
|
|
* This allows an admin to fix the problem if it doesn't exist.
|
|
|
|
|
* It also allows the parser test suite to successfully parse
|
|
|
|
|
* test cases without installing the helper. ;-)
|
|
|
|
|
*/
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
include_dir (BusConfigParser *parser,
|
|
|
|
|
const DBusString *dirname,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
DBusString filename;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
DBusError tmp_error;
|
|
|
|
|
DBusDirIter *dir;
|
2005-06-15 02:31:38 +00:00
|
|
|
char *s;
|
2003-04-02 00:29:33 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&filename))
|
|
|
|
|
{
|
2003-04-02 21:43:29 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-04-02 00:29:33 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
|
|
|
|
dir = _dbus_directory_open (dirname, error);
|
|
|
|
|
|
|
|
|
|
if (dir == NULL)
|
2015-02-25 14:10:47 +00:00
|
|
|
{
|
|
|
|
|
if (dbus_error_has_name (error, DBUS_ERROR_FILE_NOT_FOUND))
|
|
|
|
|
{
|
|
|
|
|
dbus_error_free (error);
|
|
|
|
|
goto success;
|
|
|
|
|
}
|
2015-04-14 23:48:23 +02:00
|
|
|
else
|
|
|
|
|
goto failed;
|
2015-02-25 14:10:47 +00:00
|
|
|
}
|
2003-04-02 21:43:29 +00:00
|
|
|
|
|
|
|
|
dbus_error_init (&tmp_error);
|
2003-04-02 00:29:33 +00:00
|
|
|
while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
|
|
|
|
|
{
|
2003-04-02 21:43:29 +00:00
|
|
|
DBusString full_path;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (dirname, 0, &full_path, 0))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &filename))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_dbus_string_ends_with_c_str (&full_path, ".conf"))
|
2003-04-02 00:29:33 +00:00
|
|
|
{
|
2003-04-02 21:43:29 +00:00
|
|
|
if (!include_file (parser, &full_path, TRUE, error))
|
|
|
|
|
{
|
2011-01-31 18:06:09 +00:00
|
|
|
if (dbus_error_is_set (error))
|
|
|
|
|
{
|
2016-08-12 17:59:45 +01:00
|
|
|
/* We use both syslog and stderr here, because this is
|
2011-01-31 18:06:09 +00:00
|
|
|
* the configuration parser, so we don't yet know whether
|
2016-08-12 17:59:45 +01:00
|
|
|
* this bus is going to want to write to syslog! Err on
|
|
|
|
|
* the side of making sure the message gets to the sysadmin
|
|
|
|
|
* somehow. */
|
|
|
|
|
_dbus_init_system_log ("dbus-daemon",
|
|
|
|
|
DBUS_LOG_FLAGS_STDERR | DBUS_LOG_FLAGS_SYSTEM_LOG);
|
2016-07-20 08:55:14 +01:00
|
|
|
_dbus_log (DBUS_SYSTEM_LOG_INFO,
|
2016-07-20 08:55:55 +01:00
|
|
|
"Encountered error '%s' while parsing '%s'",
|
2016-07-20 08:55:14 +01:00
|
|
|
error->message,
|
|
|
|
|
_dbus_string_get_const_data (&full_path));
|
2011-01-31 18:06:09 +00:00
|
|
|
dbus_error_free (error);
|
|
|
|
|
}
|
2003-04-02 21:43:29 +00:00
|
|
|
}
|
2003-04-02 00:29:33 +00:00
|
|
|
}
|
2003-04-02 21:43:29 +00:00
|
|
|
|
|
|
|
|
_dbus_string_free (&full_path);
|
2003-04-02 00:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set (&tmp_error))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2005-06-15 02:31:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (dirname, &s))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_list_append (&parser->conf_dirs, s))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (s);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-25 14:10:47 +00:00
|
|
|
success:
|
2003-04-02 00:29:33 +00:00
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
|
|
|
|
|
if (dir)
|
|
|
|
|
_dbus_directory_close (dir);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_content (BusConfigParser *parser,
|
|
|
|
|
const DBusString *content,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
Element *e;
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
#if 0
|
|
|
|
|
{
|
|
|
|
|
const char *c_str;
|
|
|
|
|
|
|
|
|
|
_dbus_string_get_const_data (content, &c_str);
|
|
|
|
|
|
|
|
|
|
printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
e = peek_element (parser);
|
|
|
|
|
if (e == NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Text content outside of any XML element in configuration file");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else if (e->had_content)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert_not_reached ("Element had multiple content blocks");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (top_element_type (parser))
|
|
|
|
|
{
|
|
|
|
|
case ELEMENT_NONE:
|
2017-01-17 20:59:57 +00:00
|
|
|
default:
|
2003-03-31 04:01:00 +00:00
|
|
|
_dbus_assert_not_reached ("element at top of stack has no type");
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_BUSCONFIG:
|
|
|
|
|
case ELEMENT_POLICY:
|
|
|
|
|
case ELEMENT_ALLOW:
|
|
|
|
|
case ELEMENT_DENY:
|
2003-04-01 05:33:01 +00:00
|
|
|
case ELEMENT_FORK:
|
2008-12-10 14:17:02 -05:00
|
|
|
case ELEMENT_SYSLOG:
|
2008-11-10 08:55:27 -05:00
|
|
|
case ELEMENT_KEEP_UMASK:
|
2006-11-02 23:56:48 +00:00
|
|
|
case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
|
2008-11-12 08:51:00 -05:00
|
|
|
case ELEMENT_ALLOW_ANONYMOUS:
|
2004-07-30 05:59:34 +00:00
|
|
|
case ELEMENT_SELINUX:
|
|
|
|
|
case ELEMENT_ASSOCIATE:
|
2014-02-10 19:02:04 -06:00
|
|
|
case ELEMENT_APPARMOR:
|
2003-03-31 04:01:00 +00:00
|
|
|
if (all_whitespace (content))
|
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"No text content expected inside XML element %s in configuration file",
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
bus_config_parser_element_type_to_name (top_element_type (parser)));
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-06 23:15:41 +00:00
|
|
|
case ELEMENT_PIDFILE:
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (content, &s))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
dbus_free (parser->pidfile);
|
|
|
|
|
parser->pidfile = s;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
case ELEMENT_INCLUDE:
|
|
|
|
|
{
|
2004-08-23 16:09:54 +00:00
|
|
|
DBusString full_path, selinux_policy_root;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
2004-10-18 04:04:12 +00:00
|
|
|
if (e->d.include.if_selinux_enabled
|
|
|
|
|
&& !bus_selinux_enabled ())
|
|
|
|
|
break;
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
goto nomem;
|
2004-08-23 16:09:54 +00:00
|
|
|
|
|
|
|
|
if (e->d.include.selinux_root_relative)
|
|
|
|
|
{
|
|
|
|
|
if (!bus_selinux_get_policy_root ())
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Could not determine SELinux policy root for relative inclusion");
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
_dbus_string_init_const (&selinux_policy_root,
|
|
|
|
|
bus_selinux_get_policy_root ());
|
|
|
|
|
if (!make_full_path (&selinux_policy_root, content, &full_path))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!make_full_path (&parser->basedir, content, &full_path))
|
2003-04-02 21:43:29 +00:00
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
2004-08-23 16:09:54 +00:00
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
if (!include_file (parser, &full_path,
|
2003-04-02 00:29:33 +00:00
|
|
|
e->d.include.ignore_missing, error))
|
2003-04-02 21:43:29 +00:00
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&full_path);
|
2003-03-31 04:01:00 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
case ELEMENT_SERVICEHELPER:
|
|
|
|
|
{
|
|
|
|
|
DBusString full_path;
|
|
|
|
|
|
|
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!make_full_path (&parser->basedir, content, &full_path))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!servicehelper_path (parser, &full_path, error))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
case ELEMENT_INCLUDEDIR:
|
|
|
|
|
{
|
2003-04-02 21:43:29 +00:00
|
|
|
DBusString full_path;
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
e->had_content = TRUE;
|
2003-04-02 21:43:29 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
goto nomem;
|
2003-04-02 00:29:33 +00:00
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
if (!make_full_path (&parser->basedir, content, &full_path))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!include_dir (parser, &full_path, error))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&full_path);
|
2003-04-02 00:29:33 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
case ELEMENT_USER:
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (content, &s))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
dbus_free (parser->user);
|
|
|
|
|
parser->user = s;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2011-03-07 11:43:23 +01:00
|
|
|
case ELEMENT_CONFIGTYPE:
|
2003-04-03 05:22:49 +00:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
case ELEMENT_LISTEN:
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (content, &s))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_list_append (&parser->listen_on,
|
|
|
|
|
s))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (s);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_AUTH:
|
|
|
|
|
{
|
2003-04-01 05:33:01 +00:00
|
|
|
char *s;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
e->had_content = TRUE;
|
2003-04-01 05:33:01 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (content, &s))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_list_append (&parser->mechanisms,
|
|
|
|
|
s))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (s);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2003-04-02 00:29:33 +00:00
|
|
|
|
|
|
|
|
case ELEMENT_SERVICEDIR:
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
2017-02-17 15:03:02 +00:00
|
|
|
BusConfigServiceDir *dir;
|
2003-04-02 21:43:29 +00:00
|
|
|
DBusString full_path;
|
2017-02-13 19:31:39 +00:00
|
|
|
DBusList *link;
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
2003-04-02 00:29:33 +00:00
|
|
|
goto nomem;
|
2003-04-02 21:43:29 +00:00
|
|
|
|
|
|
|
|
if (!make_full_path (&parser->basedir, content, &full_path))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (&full_path, &s))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
2003-04-02 00:29:33 +00:00
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
/* <servicedir/> has traditionally implied that we watch the
|
|
|
|
|
* directory with inotify, and allow service files whose names do not
|
|
|
|
|
* match the bus name */
|
|
|
|
|
dir = bus_config_service_dir_new_take (s, BUS_SERVICE_DIR_FLAGS_NONE);
|
2017-02-13 19:31:39 +00:00
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
if (dir == NULL)
|
2003-04-02 00:29:33 +00:00
|
|
|
{
|
2003-04-02 21:43:29 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2003-04-02 00:29:33 +00:00
|
|
|
dbus_free (s);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
2003-04-02 21:43:29 +00:00
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
link = _dbus_list_alloc_link (dir);
|
|
|
|
|
|
|
|
|
|
if (link == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
bus_config_service_dir_free (dir);
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 19:31:39 +00:00
|
|
|
/* cannot fail */
|
|
|
|
|
service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
|
2003-04-02 21:43:29 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2003-04-02 00:29:33 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2003-04-24 22:30:38 +00:00
|
|
|
|
|
|
|
|
case ELEMENT_LIMIT:
|
|
|
|
|
{
|
|
|
|
|
long val;
|
|
|
|
|
|
|
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
|
if (!_dbus_string_parse_int (content, 0, &val, NULL))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<limit name=\"%s\"> element has invalid value (could not parse as integer)",
|
|
|
|
|
e->d.limit.name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e->d.limit.value = val;
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Loaded value %ld for limit %s\n",
|
|
|
|
|
e->d.limit.value,
|
|
|
|
|
e->d.limit.name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-03-31 04:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-26 07:16:03 +00:00
|
|
|
return TRUE;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
nomem:
|
2003-04-02 21:43:29 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
2003-03-26 03:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_finished (BusConfigParser *parser,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
|
|
|
|
if (parser->stack != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> was not closed in configuration file",
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
bus_config_parser_element_type_to_name (top_element_type (parser)));
|
2003-03-26 03:58:11 +00:00
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-31 08:19:50 +00:00
|
|
|
|
2003-04-28 19:29:42 +00:00
|
|
|
if (parser->is_toplevel && parser->listen_on == NULL)
|
2003-03-31 08:19:50 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Configuration file needs one or more <listen> elements giving addresses");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
return TRUE;
|
2003-03-26 03:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
|
bus_config_parser_get_user (BusConfigParser *parser)
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
return parser->user;
|
2003-03-25 04:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
const char*
|
|
|
|
|
bus_config_parser_get_type (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->bus_type;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 08:19:50 +00:00
|
|
|
DBusList**
|
|
|
|
|
bus_config_parser_get_addresses (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return &parser->listen_on;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
DBusList**
|
|
|
|
|
bus_config_parser_get_mechanisms (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return &parser->mechanisms;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
DBusList**
|
|
|
|
|
bus_config_parser_get_service_dirs (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return &parser->service_dirs;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-15 02:31:38 +00:00
|
|
|
DBusList**
|
|
|
|
|
bus_config_parser_get_conf_dirs (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return &parser->conf_dirs;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_get_fork (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->fork;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-10 08:55:27 -05:00
|
|
|
dbus_bool_t
|
2008-12-10 14:17:02 -05:00
|
|
|
bus_config_parser_get_syslog (BusConfigParser *parser)
|
2008-11-10 08:55:27 -05:00
|
|
|
{
|
2008-12-10 14:17:02 -05:00
|
|
|
return parser->syslog;
|
2008-11-10 08:55:27 -05:00
|
|
|
}
|
|
|
|
|
|
2008-12-10 14:17:02 -05:00
|
|
|
dbus_bool_t
|
2008-11-10 08:55:27 -05:00
|
|
|
bus_config_parser_get_keep_umask (BusConfigParser *parser)
|
2008-12-10 14:17:02 -05:00
|
|
|
{
|
2008-11-10 08:55:27 -05:00
|
|
|
return parser->keep_umask;
|
2008-12-10 14:17:02 -05:00
|
|
|
}
|
|
|
|
|
|
2008-11-12 08:51:00 -05:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_get_allow_anonymous (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->allow_anonymous;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-06 23:15:41 +00:00
|
|
|
const char *
|
|
|
|
|
bus_config_parser_get_pidfile (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->pidfile;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
const char *
|
|
|
|
|
bus_config_parser_get_servicehelper (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->servicehelper;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
BusPolicy*
|
|
|
|
|
bus_config_parser_steal_policy (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
BusPolicy *policy;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */
|
|
|
|
|
|
|
|
|
|
policy = parser->policy;
|
|
|
|
|
|
|
|
|
|
parser->policy = NULL;
|
|
|
|
|
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-24 22:30:38 +00:00
|
|
|
/* Overwrite any limits that were set in the configuration file */
|
|
|
|
|
void
|
|
|
|
|
bus_config_parser_get_limits (BusConfigParser *parser,
|
|
|
|
|
BusLimits *limits)
|
|
|
|
|
{
|
|
|
|
|
*limits = parser->limits;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-30 05:59:34 +00:00
|
|
|
DBusHashTable*
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
bus_config_parser_steal_service_context_table (BusConfigParser *parser)
|
2004-07-30 05:59:34 +00:00
|
|
|
{
|
|
|
|
|
DBusHashTable *table;
|
|
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
_dbus_assert (parser->service_context_table != NULL); /* can only steal once */
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
table = parser->service_context_table;
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2004-11-07 Colin Walters <walters@verbum.org>
* bus/bus.c (load_config): Break into three
separate functions: process_config_first_time_only,
process_config_every_time, and process_config_postinit.
(process_config_every_time): Move call of
bus_registry_set_service_context_table into
process_config_postinit.
(process_config_postinit): New function, does
any processing that needs to happen late
in initialization (and also on reload).
(bus_context_new): Instead of calling load_config,
open config parser here and call process_config_first_time_only
and process_config_every_time directly. Later, after
we have forked but before changing UID,
invoke bus_selinux_full_init, and then call
process_config_postinit.
(bus_context_reload_config): As in bus_context_new,
load parse file inside here, and call process_config_every_time
and process_config_postinit.
* bus/services.h, bus/services.c
(bus_registry_set_service_context_table): Rename
from bus_registry_set_sid_table. Take string hash from config
parser, and convert them here into SIDs.
* bus/config-parser.c (struct BusConfigParser): Have
config parser only store a mapping of service->context
string.
(merge_service_context_hash): New function.
(merge_included): Merge context string hashes instead
of using bus_selinux_id_table_union.
(bus_config_parser_new): Don't use bus_selinux_id_table_new;
simply create a new string hash.
(bus_config_parser_unref): Unref it.
(start_selinux_child): Simply insert strings into hash,
don't call bus_selinux_id_table_copy_over.
* bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union)
(bus_selinux_id_table_copy_over): Delete.
2004-11-07 17:05:19 +00:00
|
|
|
parser->service_context_table = NULL;
|
2004-07-30 05:59:34 +00:00
|
|
|
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 14:13:05 +00:00
|
|
|
/*
|
|
|
|
|
* Return a list of the directories that should be watched with inotify,
|
|
|
|
|
* as strings. The list might be empty and is in arbitrary order.
|
|
|
|
|
*
|
|
|
|
|
* The list must be empty on entry. On success, the links are owned by the
|
|
|
|
|
* caller and must be freed, but the data in each link remains owned by
|
|
|
|
|
* the BusConfigParser and must not be freed: in GObject-Introspection
|
|
|
|
|
* notation, it is (transfer container).
|
|
|
|
|
*/
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_get_watched_dirs (BusConfigParser *parser,
|
|
|
|
|
DBusList **watched_dirs)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (*watched_dirs == NULL);
|
|
|
|
|
|
|
|
|
|
for (link = _dbus_list_get_first_link (&parser->conf_dirs);
|
|
|
|
|
link != NULL;
|
|
|
|
|
link = _dbus_list_get_next_link (&parser->conf_dirs, link))
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_list_append (watched_dirs, link->data))
|
|
|
|
|
goto oom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (link = _dbus_list_get_first_link (&parser->service_dirs);
|
|
|
|
|
link != NULL;
|
|
|
|
|
link = _dbus_list_get_next_link (&parser->service_dirs, link))
|
|
|
|
|
{
|
2017-02-17 15:03:02 +00:00
|
|
|
BusConfigServiceDir *dir = link->data;
|
|
|
|
|
|
|
|
|
|
if (dir->flags & BUS_SERVICE_DIR_FLAGS_NO_WATCH)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_list_append (watched_dirs, dir->path))
|
2017-02-15 14:13:05 +00:00
|
|
|
goto oom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
oom:
|
|
|
|
|
_dbus_list_clear (watched_dirs);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 16:24:37 +08:00
|
|
|
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
2003-03-26 07:16:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
VALID,
|
|
|
|
|
INVALID,
|
|
|
|
|
UNKNOWN
|
|
|
|
|
} Validity;
|
|
|
|
|
|
2012-03-21 19:05:42 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
do_check_own_rules (BusPolicy *policy)
|
|
|
|
|
{
|
|
|
|
|
const struct {
|
Be more const-correct
As a general design principle, strings that we aren't going to modify
should usually be const. When compiling with -Wwrite-strings, quoted
string constants are of type "const char *", causing compiler warnings
when they are assigned to char * variables.
Unfortunately, we need to add casts in a few places:
* _dbus_list_append(), _dbus_test_oom_handling() and similar generic
"user-data" APIs take a void *, not a const void *, so we have
to cast
* For historical reasons the execve() family of functions take a
(char * const *), i.e. a constant pointer to an array of mutable
strings, so again we have to cast
* _dbus_spawn_async_with_babysitter similarly takes a char **,
although we can make it a little more const-correct by making it
take (char * const *) like execve() does
This also incorporates a subsequent patch by Thomas Zimmermann to
put various string constants in static storage, which is a little
more efficient.
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
2016-10-07 17:41:01 +01:00
|
|
|
const char *name;
|
2012-03-21 19:05:42 +00:00
|
|
|
dbus_bool_t allowed;
|
|
|
|
|
} checks[] = {
|
|
|
|
|
{"org.freedesktop", FALSE},
|
|
|
|
|
{"org.freedesktop.ManySystem", FALSE},
|
|
|
|
|
{"org.freedesktop.ManySystems", TRUE},
|
|
|
|
|
{"org.freedesktop.ManySystems.foo", TRUE},
|
|
|
|
|
{"org.freedesktop.ManySystems.foo.bar", TRUE},
|
|
|
|
|
{"org.freedesktop.ManySystems2", FALSE},
|
|
|
|
|
{"org.freedesktop.ManySystems2.foo", FALSE},
|
|
|
|
|
{"org.freedesktop.ManySystems2.foo.bar", FALSE},
|
|
|
|
|
{NULL, FALSE}
|
|
|
|
|
};
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
while (checks[i].name)
|
|
|
|
|
{
|
|
|
|
|
DBusString service_name;
|
|
|
|
|
dbus_bool_t ret;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&service_name))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't init string");
|
|
|
|
|
if (!_dbus_string_append (&service_name, checks[i].name))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't append string");
|
|
|
|
|
|
|
|
|
|
ret = bus_policy_check_can_own (policy, &service_name);
|
|
|
|
|
printf (" Check name %s: %s\n", checks[i].name,
|
|
|
|
|
ret ? "allowed" : "not allowed");
|
|
|
|
|
if (checks[i].allowed && !ret)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Cannot own %s", checks[i].name);
|
2012-03-21 19:05:42 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (!checks[i].allowed && ret)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Can own %s", checks[i].name);
|
2012-03-21 19:05:42 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
_dbus_string_free (&service_name);
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
do_load (const DBusString *full_path,
|
|
|
|
|
Validity validity,
|
2012-03-21 19:05:42 +00:00
|
|
|
dbus_bool_t oom_possible,
|
|
|
|
|
dbus_bool_t check_own_rules)
|
2003-03-26 07:16:03 +00:00
|
|
|
{
|
|
|
|
|
BusConfigParser *parser;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
parser = bus_config_load (full_path, TRUE, NULL, &error);
|
2003-03-26 07:16:03 +00:00
|
|
|
if (parser == NULL)
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (&error);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
if (oom_possible &&
|
|
|
|
|
dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to load valid file due to OOM\n");
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (validity == VALID)
|
2003-03-31 04:01:00 +00:00
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Failed to load valid file but still had memory: %s",
|
2003-03-26 07:16:03 +00:00
|
|
|
error.message);
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (&error);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2012-03-21 19:05:42 +00:00
|
|
|
if (check_own_rules && do_check_own_rules (parser->policy) == FALSE)
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
bus_config_parser_unref (parser);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
if (validity == INVALID)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Accepted invalid file");
|
2003-03-26 07:16:03 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-28 05:42:19 +00:00
|
|
|
typedef struct
|
2003-03-26 07:16:03 +00:00
|
|
|
{
|
2003-03-28 05:42:19 +00:00
|
|
|
const DBusString *full_path;
|
|
|
|
|
Validity validity;
|
2012-03-21 19:05:42 +00:00
|
|
|
dbus_bool_t check_own_rules;
|
2003-03-28 05:42:19 +00:00
|
|
|
} LoaderOomData;
|
2003-03-26 07:16:03 +00:00
|
|
|
|
2003-03-28 05:42:19 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
check_loader_oom_func (void *data)
|
|
|
|
|
{
|
|
|
|
|
LoaderOomData *d = data;
|
2003-03-26 07:16:03 +00:00
|
|
|
|
2012-03-21 19:05:42 +00:00
|
|
|
return do_load (d->full_path, d->validity, TRUE, d->check_own_rules);
|
2003-03-26 07:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
2004-04-09 19:50:29 +00:00
|
|
|
process_test_valid_subdir (const DBusString *test_base_dir,
|
|
|
|
|
const char *subdir,
|
|
|
|
|
Validity validity)
|
2003-03-26 07:16:03 +00:00
|
|
|
{
|
|
|
|
|
DBusString test_directory;
|
|
|
|
|
DBusString filename;
|
|
|
|
|
DBusDirIter *dir;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
dir = NULL;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_init (&test_directory))
|
2016-07-21 10:59:50 +01:00
|
|
|
_dbus_assert_not_reached ("didn't allocate test_directory");
|
2003-03-26 07:16:03 +00:00
|
|
|
|
|
|
|
|
_dbus_string_init_const (&filename, subdir);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
if (!_dbus_string_copy (test_base_dir, 0,
|
|
|
|
|
&test_directory, 0))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
|
2003-03-31 04:01:00 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&test_directory, &filename))
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_assert_not_reached ("couldn't allocate full path");
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&filename);
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_init (&filename))
|
2016-07-21 10:59:50 +01:00
|
|
|
_dbus_assert_not_reached ("didn't allocate filename string");
|
2003-03-26 07:16:03 +00:00
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
dir = _dbus_directory_open (&test_directory, &error);
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not open %s: %s",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&test_directory),
|
2003-03-26 07:16:03 +00:00
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
if (validity == VALID)
|
|
|
|
|
printf ("Testing valid files:\n");
|
|
|
|
|
else if (validity == INVALID)
|
|
|
|
|
printf ("Testing invalid files:\n");
|
|
|
|
|
else
|
|
|
|
|
printf ("Testing unknown files:\n");
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
next:
|
|
|
|
|
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
|
|
|
|
{
|
|
|
|
|
DBusString full_path;
|
2003-03-28 05:42:19 +00:00
|
|
|
LoaderOomData d;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_init (&full_path))
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_assert_not_reached ("couldn't init string");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't copy dir to full_path");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &filename))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't concat file to dir");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Skipping non-.conf file %s\n",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&filename));
|
2004-04-09 19:50:29 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2003-03-26 07:16:03 +00:00
|
|
|
goto next;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
printf (" %s\n", _dbus_string_get_const_data (&filename));
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_verbose (" expecting %s\n",
|
|
|
|
|
validity == VALID ? "valid" :
|
|
|
|
|
(validity == INVALID ? "invalid" :
|
|
|
|
|
(validity == UNKNOWN ? "unknown" : "???")));
|
|
|
|
|
|
2003-03-28 05:42:19 +00:00
|
|
|
d.full_path = &full_path;
|
|
|
|
|
d.validity = validity;
|
2012-03-21 19:05:42 +00:00
|
|
|
d.check_own_rules = _dbus_string_ends_with_c_str (&full_path,
|
|
|
|
|
"check-own-rules.conf");
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2004-05-29 04:17:17 +00:00
|
|
|
/* FIXME hackaround for an expat problem, see
|
|
|
|
|
* https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747
|
|
|
|
|
* http://freedesktop.org/pipermail/dbus/2004-May/001153.html
|
|
|
|
|
*/
|
|
|
|
|
/* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */
|
|
|
|
|
if (!check_loader_oom_func (&d))
|
|
|
|
|
_dbus_assert_not_reached ("test failed");
|
|
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not get next file in %s: %s",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&test_directory),
|
|
|
|
|
error.message);
|
2003-03-26 07:16:03 +00:00
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
retval = TRUE;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
failed:
|
|
|
|
|
|
|
|
|
|
if (dir)
|
|
|
|
|
_dbus_directory_close (dir);
|
|
|
|
|
_dbus_string_free (&test_directory);
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
2003-03-26 03:58:11 +00:00
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
bools_equal (dbus_bool_t a,
|
|
|
|
|
dbus_bool_t b)
|
|
|
|
|
{
|
|
|
|
|
return a ? b : !b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
strings_equal_or_both_null (const char *a,
|
|
|
|
|
const char *b)
|
|
|
|
|
{
|
|
|
|
|
if (a == NULL || b == NULL)
|
|
|
|
|
return a == b;
|
|
|
|
|
else
|
|
|
|
|
return !strcmp (a, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
elements_equal (const Element *a,
|
|
|
|
|
const Element *b)
|
|
|
|
|
{
|
|
|
|
|
if (a->type != b->type)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!bools_equal (a->had_content, b->had_content))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
switch (a->type)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case ELEMENT_INCLUDE:
|
|
|
|
|
if (!bools_equal (a->d.include.ignore_missing,
|
|
|
|
|
b->d.include.ignore_missing))
|
|
|
|
|
return FALSE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_POLICY:
|
|
|
|
|
if (a->d.policy.type != b->d.policy.type)
|
|
|
|
|
return FALSE;
|
2004-08-25 22:11:49 +00:00
|
|
|
if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console)
|
2004-04-09 19:50:29 +00:00
|
|
|
return FALSE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_LIMIT:
|
|
|
|
|
if (strcmp (a->d.limit.name, b->d.limit.name))
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (a->d.limit.value != b->d.limit.value)
|
|
|
|
|
return FALSE;
|
|
|
|
|
break;
|
|
|
|
|
|
2017-01-17 21:07:00 +00:00
|
|
|
case ELEMENT_NONE:
|
|
|
|
|
case ELEMENT_BUSCONFIG:
|
|
|
|
|
case ELEMENT_USER:
|
|
|
|
|
case ELEMENT_LISTEN:
|
|
|
|
|
case ELEMENT_AUTH:
|
|
|
|
|
case ELEMENT_ALLOW:
|
|
|
|
|
case ELEMENT_DENY:
|
|
|
|
|
case ELEMENT_FORK:
|
|
|
|
|
case ELEMENT_PIDFILE:
|
|
|
|
|
case ELEMENT_SERVICEDIR:
|
|
|
|
|
case ELEMENT_SERVICEHELPER:
|
|
|
|
|
case ELEMENT_INCLUDEDIR:
|
|
|
|
|
case ELEMENT_CONFIGTYPE:
|
|
|
|
|
case ELEMENT_SELINUX:
|
|
|
|
|
case ELEMENT_ASSOCIATE:
|
|
|
|
|
case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
|
|
|
|
|
case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
|
|
|
|
|
case ELEMENT_KEEP_UMASK:
|
|
|
|
|
case ELEMENT_SYSLOG:
|
|
|
|
|
case ELEMENT_ALLOW_ANONYMOUS:
|
|
|
|
|
case ELEMENT_APPARMOR:
|
2004-04-09 19:50:29 +00:00
|
|
|
default:
|
2017-01-17 21:07:00 +00:00
|
|
|
/* do nothing: nothing in the Element struct for these types */
|
2004-04-09 19:50:29 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
lists_of_elements_equal (DBusList *a,
|
|
|
|
|
DBusList *b)
|
|
|
|
|
{
|
|
|
|
|
DBusList *ia;
|
|
|
|
|
DBusList *ib;
|
|
|
|
|
|
|
|
|
|
ia = a;
|
|
|
|
|
ib = b;
|
|
|
|
|
|
|
|
|
|
while (ia != NULL && ib != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (elements_equal (ia->data, ib->data))
|
|
|
|
|
return FALSE;
|
|
|
|
|
ia = _dbus_list_get_next_link (&a, ia);
|
|
|
|
|
ib = _dbus_list_get_next_link (&b, ib);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ia == NULL && ib == NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
lists_of_c_strings_equal (DBusList *a,
|
|
|
|
|
DBusList *b)
|
|
|
|
|
{
|
|
|
|
|
DBusList *ia;
|
|
|
|
|
DBusList *ib;
|
|
|
|
|
|
|
|
|
|
ia = a;
|
|
|
|
|
ib = b;
|
|
|
|
|
|
|
|
|
|
while (ia != NULL && ib != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (ia->data, ib->data))
|
|
|
|
|
return FALSE;
|
|
|
|
|
ia = _dbus_list_get_next_link (&a, ia);
|
|
|
|
|
ib = _dbus_list_get_next_link (&b, ib);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ia == NULL && ib == NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
lists_of_service_dirs_equal (DBusList *a,
|
|
|
|
|
DBusList *b)
|
|
|
|
|
{
|
|
|
|
|
DBusList *ia;
|
|
|
|
|
DBusList *ib;
|
|
|
|
|
|
|
|
|
|
ia = a;
|
|
|
|
|
ib = b;
|
|
|
|
|
|
|
|
|
|
while (ia != NULL && ib != NULL)
|
|
|
|
|
{
|
|
|
|
|
BusConfigServiceDir *da = ia->data;
|
|
|
|
|
BusConfigServiceDir *db = ib->data;
|
|
|
|
|
|
|
|
|
|
if (strcmp (da->path, db->path))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (da->flags != db->flags)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
ia = _dbus_list_get_next_link (&a, ia);
|
|
|
|
|
ib = _dbus_list_get_next_link (&b, ib);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ia == NULL && ib == NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
limits_equal (const BusLimits *a,
|
|
|
|
|
const BusLimits *b)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
(a->max_incoming_bytes == b->max_incoming_bytes
|
2009-05-20 01:33:17 +02:00
|
|
|
|| a->max_incoming_unix_fds == b->max_incoming_unix_fds
|
2004-04-09 19:50:29 +00:00
|
|
|
|| a->max_outgoing_bytes == b->max_outgoing_bytes
|
2009-05-20 01:33:17 +02:00
|
|
|
|| a->max_outgoing_unix_fds == b->max_outgoing_unix_fds
|
2004-04-09 19:50:29 +00:00
|
|
|
|| a->max_message_size == b->max_message_size
|
2009-05-20 01:33:17 +02:00
|
|
|
|| a->max_message_unix_fds == b->max_message_unix_fds
|
2004-04-09 19:50:29 +00:00
|
|
|
|| a->activation_timeout == b->activation_timeout
|
|
|
|
|
|| a->auth_timeout == b->auth_timeout
|
2014-07-21 17:34:08 +01:00
|
|
|
|| a->pending_fd_timeout == b->pending_fd_timeout
|
2004-04-09 19:50:29 +00:00
|
|
|
|| a->max_completed_connections == b->max_completed_connections
|
|
|
|
|
|| a->max_incomplete_connections == b->max_incomplete_connections
|
|
|
|
|
|| a->max_connections_per_user == b->max_connections_per_user
|
|
|
|
|
|| a->max_pending_activations == b->max_pending_activations
|
|
|
|
|
|| a->max_services_per_connection == b->max_services_per_connection
|
|
|
|
|
|| a->max_match_rules_per_connection == b->max_match_rules_per_connection
|
|
|
|
|
|| a->max_replies_per_connection == b->max_replies_per_connection
|
|
|
|
|
|| a->reply_timeout == b->reply_timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
config_parsers_equal (const BusConfigParser *a,
|
|
|
|
|
const BusConfigParser *b)
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_string_equal (&a->basedir, &b->basedir))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!lists_of_elements_equal (a->stack, b->stack))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!strings_equal_or_both_null (a->user, b->user))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!lists_of_c_strings_equal (a->listen_on, b->listen_on))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
if (!lists_of_service_dirs_equal (a->service_dirs, b->service_dirs))
|
2004-04-09 19:50:29 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* FIXME: compare policy */
|
|
|
|
|
|
2004-07-30 05:59:34 +00:00
|
|
|
/* FIXME: compare service selinux ID table */
|
|
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
if (! limits_equal (&a->limits, &b->limits))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!strings_equal_or_both_null (a->pidfile, b->pidfile))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (! bools_equal (a->fork, b->fork))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2008-11-10 08:55:27 -05:00
|
|
|
if (! bools_equal (a->keep_umask, b->keep_umask))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
if (! bools_equal (a->is_toplevel, b->is_toplevel))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
all_are_equiv (const DBusString *target_directory)
|
|
|
|
|
{
|
|
|
|
|
DBusString filename;
|
|
|
|
|
DBusDirIter *dir;
|
|
|
|
|
BusConfigParser *first_parser;
|
|
|
|
|
BusConfigParser *parser;
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_bool_t equal;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
|
|
|
|
|
dir = NULL;
|
|
|
|
|
first_parser = NULL;
|
|
|
|
|
parser = NULL;
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&filename))
|
|
|
|
|
_dbus_assert_not_reached ("didn't allocate filename string");
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
dir = _dbus_directory_open (target_directory, &error);
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not open %s: %s",
|
2004-04-09 19:50:29 +00:00
|
|
|
_dbus_string_get_const_data (target_directory),
|
|
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto finished;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
printf ("Comparing equivalent files:\n");
|
2004-04-09 19:50:29 +00:00
|
|
|
|
|
|
|
|
next:
|
|
|
|
|
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
|
|
|
|
{
|
|
|
|
|
DBusString full_path;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't init string");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (target_directory, 0, &full_path, 0))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't copy dir to full_path");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &filename))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't concat file to dir");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Skipping non-.conf file %s\n",
|
|
|
|
|
_dbus_string_get_const_data (&filename));
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf (" %s\n", _dbus_string_get_const_data (&filename));
|
|
|
|
|
|
|
|
|
|
parser = bus_config_load (&full_path, TRUE, NULL, &error);
|
|
|
|
|
|
|
|
|
|
if (parser == NULL)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not load file %s: %s",
|
2004-04-09 19:50:29 +00:00
|
|
|
_dbus_string_get_const_data (&full_path),
|
|
|
|
|
error.message);
|
2005-01-18 20:42:15 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2004-04-09 19:50:29 +00:00
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto finished;
|
|
|
|
|
}
|
|
|
|
|
else if (first_parser == NULL)
|
|
|
|
|
{
|
2005-01-18 20:42:15 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2004-04-09 19:50:29 +00:00
|
|
|
first_parser = parser;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-01-18 20:42:15 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2004-04-09 19:50:29 +00:00
|
|
|
equal = config_parsers_equal (first_parser, parser);
|
|
|
|
|
bus_config_parser_unref (parser);
|
|
|
|
|
if (! equal)
|
|
|
|
|
goto finished;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
finished:
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
if (first_parser)
|
|
|
|
|
bus_config_parser_unref (first_parser);
|
|
|
|
|
if (dir)
|
|
|
|
|
_dbus_directory_close (dir);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
process_test_equiv_subdir (const DBusString *test_base_dir,
|
|
|
|
|
const char *subdir)
|
|
|
|
|
{
|
|
|
|
|
DBusString test_directory;
|
|
|
|
|
DBusString filename;
|
|
|
|
|
DBusDirIter *dir;
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_bool_t equal;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
|
|
|
|
|
dir = NULL;
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&test_directory))
|
|
|
|
|
_dbus_assert_not_reached ("didn't allocate test_directory");
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&filename, subdir);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (test_base_dir, 0,
|
|
|
|
|
&test_directory, 0))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&test_directory, &filename))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't allocate full path");
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
if (!_dbus_string_init (&filename))
|
|
|
|
|
_dbus_assert_not_reached ("didn't allocate filename string");
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
dir = _dbus_directory_open (&test_directory, &error);
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not open %s: %s",
|
2004-04-09 19:50:29 +00:00
|
|
|
_dbus_string_get_const_data (&test_directory),
|
|
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto finished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
|
|
|
|
{
|
|
|
|
|
DBusString full_path;
|
|
|
|
|
|
|
|
|
|
/* Skip CVS's magic directories! */
|
|
|
|
|
if (_dbus_string_equal_c_str (&filename, "CVS"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't init string");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't copy dir to full_path");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &filename))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't concat file to dir");
|
|
|
|
|
|
|
|
|
|
equal = all_are_equiv (&full_path);
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
|
|
|
|
|
if (!equal)
|
|
|
|
|
goto finished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
finished:
|
|
|
|
|
_dbus_string_free (&test_directory);
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
if (dir)
|
|
|
|
|
_dbus_directory_close (dir);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
|
|
}
|
2006-11-01 23:30:46 +00:00
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
static const char *test_session_service_dir_matches[] =
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
2010-12-29 12:31:42 +01:00
|
|
|
/* will be filled in test_default_session_servicedirs() */
|
2009-12-01 11:17:17 +01:00
|
|
|
#ifdef DBUS_WIN
|
2017-02-17 17:15:34 +00:00
|
|
|
NULL, /* install root-based */
|
|
|
|
|
NULL, /* CommonProgramFiles-based */
|
|
|
|
|
#else
|
2017-02-13 20:58:51 +00:00
|
|
|
NULL, /* XDG_RUNTIME_DIR-based */
|
2017-02-17 17:15:34 +00:00
|
|
|
NULL, /* XDG_DATA_HOME-based */
|
|
|
|
|
NULL, /* XDG_DATA_DIRS-based */
|
|
|
|
|
NULL, /* XDG_DATA_DIRS-based */
|
|
|
|
|
DBUS_DATADIR "/dbus-1/services",
|
2007-05-24 08:07:28 +00:00
|
|
|
#endif
|
2006-11-01 23:30:46 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
2017-02-17 18:12:54 +00:00
|
|
|
test_default_session_servicedirs (const DBusString *test_base_dir)
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
2017-02-17 18:12:54 +00:00
|
|
|
BusConfigParser *parser = NULL;
|
|
|
|
|
DBusError error = DBUS_ERROR_INIT;
|
|
|
|
|
DBusList **dirs;
|
2017-02-15 14:13:05 +00:00
|
|
|
DBusList *watched_dirs = NULL;
|
2006-11-01 23:30:46 +00:00
|
|
|
DBusList *link;
|
2017-02-17 18:12:54 +00:00
|
|
|
DBusString tmp;
|
|
|
|
|
DBusString full_path;
|
2007-05-17 11:47:48 +00:00
|
|
|
DBusString progs;
|
2015-11-02 14:24:51 +00:00
|
|
|
DBusString install_root_based;
|
2017-02-13 20:58:51 +00:00
|
|
|
DBusString runtime_dir_based;
|
2017-02-17 17:15:34 +00:00
|
|
|
DBusString data_home_based;
|
|
|
|
|
DBusString data_dirs_based;
|
|
|
|
|
DBusString data_dirs_based2;
|
2006-11-01 23:30:46 +00:00
|
|
|
int i;
|
2015-09-30 16:35:49 +01:00
|
|
|
dbus_bool_t ret = FALSE;
|
2010-12-29 12:31:42 +01:00
|
|
|
#ifdef DBUS_WIN
|
2011-07-14 18:46:38 +01:00
|
|
|
const char *common_progs;
|
2017-02-17 17:15:34 +00:00
|
|
|
#else
|
|
|
|
|
const char *dbus_test_builddir;
|
|
|
|
|
const char *xdg_data_home;
|
2017-02-13 20:58:51 +00:00
|
|
|
const char *xdg_runtime_dir;
|
2015-11-02 14:15:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
2017-02-17 17:15:34 +00:00
|
|
|
/* On each platform we don't actually use all of these, but it's easier to
|
|
|
|
|
* handle the deallocation if we always allocate them, whether needed or
|
|
|
|
|
* not */
|
2017-02-17 18:12:54 +00:00
|
|
|
if (!_dbus_string_init (&full_path) ||
|
|
|
|
|
!_dbus_string_init (&progs) ||
|
2017-02-17 17:15:34 +00:00
|
|
|
!_dbus_string_init (&install_root_based) ||
|
2017-02-13 20:58:51 +00:00
|
|
|
!_dbus_string_init (&runtime_dir_based) ||
|
2017-02-17 17:15:34 +00:00
|
|
|
!_dbus_string_init (&data_home_based) ||
|
|
|
|
|
!_dbus_string_init (&data_dirs_based) ||
|
|
|
|
|
!_dbus_string_init (&data_dirs_based2))
|
2015-11-02 14:24:51 +00:00
|
|
|
_dbus_assert_not_reached ("OOM allocating strings");
|
2011-07-14 18:46:38 +01:00
|
|
|
|
2017-02-17 18:12:54 +00:00
|
|
|
if (!_dbus_string_copy (test_base_dir, 0,
|
|
|
|
|
&full_path, 0))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't copy test_base_dir to full_path");
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&tmp, "valid-config-files");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &tmp))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't allocate full path");
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&tmp, "standard-session-dirs.conf");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &tmp))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't allocate full path");
|
|
|
|
|
|
2015-11-02 14:15:14 +00:00
|
|
|
#ifdef DBUS_WIN
|
2015-11-02 14:24:51 +00:00
|
|
|
if (!_dbus_string_append (&install_root_based, DBUS_DATADIR) ||
|
2015-11-06 12:12:55 +01:00
|
|
|
!_dbus_string_append (&install_root_based, "/dbus-1/services") ||
|
2015-10-02 16:51:59 +01:00
|
|
|
!_dbus_replace_install_prefix (&install_root_based))
|
2015-11-02 14:24:51 +00:00
|
|
|
goto out;
|
2015-09-30 16:35:49 +01:00
|
|
|
|
2015-10-02 16:51:59 +01:00
|
|
|
_dbus_assert (_dbus_path_is_absolute (&install_root_based));
|
2015-09-30 16:35:49 +01:00
|
|
|
|
2015-11-02 14:24:51 +00:00
|
|
|
test_session_service_dir_matches[0] = _dbus_string_get_const_data (
|
|
|
|
|
&install_root_based);
|
2015-09-30 16:35:49 +01:00
|
|
|
|
2011-07-14 18:46:38 +01:00
|
|
|
common_progs = _dbus_getenv ("CommonProgramFiles");
|
|
|
|
|
|
2007-05-17 11:47:48 +00:00
|
|
|
if (common_progs)
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_string_append (&progs, common_progs))
|
2015-09-30 16:35:49 +01:00
|
|
|
goto out;
|
2007-05-17 11:47:48 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&progs, "/dbus-1/services"))
|
2015-09-30 16:35:49 +01:00
|
|
|
goto out;
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
|
2007-05-17 11:47:48 +00:00
|
|
|
}
|
2017-02-17 17:15:34 +00:00
|
|
|
#else
|
|
|
|
|
dbus_test_builddir = _dbus_getenv ("DBUS_TEST_BUILDDIR");
|
|
|
|
|
xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
|
2017-02-13 20:58:51 +00:00
|
|
|
xdg_runtime_dir = _dbus_getenv ("XDG_RUNTIME_DIR");
|
2006-11-01 23:30:46 +00:00
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
if (dbus_test_builddir == NULL || xdg_data_home == NULL ||
|
|
|
|
|
xdg_runtime_dir == NULL)
|
2017-02-17 17:15:34 +00:00
|
|
|
{
|
|
|
|
|
printf ("Not testing default session service directories because a "
|
|
|
|
|
"build-time testing environment variable is not set: "
|
|
|
|
|
"see AM_TESTS_ENVIRONMENT in tests/Makefile.am\n");
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2006-11-01 23:30:46 +00:00
|
|
|
|
2017-02-17 17:15:34 +00:00
|
|
|
if (!_dbus_string_append (&data_dirs_based, dbus_test_builddir) ||
|
|
|
|
|
!_dbus_string_append (&data_dirs_based, "/XDG_DATA_DIRS/dbus-1/services") ||
|
|
|
|
|
!_dbus_string_append (&data_dirs_based2, dbus_test_builddir) ||
|
|
|
|
|
!_dbus_string_append (&data_dirs_based2, "/XDG_DATA_DIRS2/dbus-1/services") ||
|
2017-02-13 20:58:51 +00:00
|
|
|
!_dbus_string_append (&runtime_dir_based, xdg_runtime_dir) ||
|
2017-02-17 17:15:34 +00:00
|
|
|
!_dbus_string_append (&data_home_based, xdg_data_home) ||
|
|
|
|
|
!_dbus_string_append (&data_home_based, "/dbus-1/services"))
|
|
|
|
|
_dbus_assert_not_reached ("out of memory");
|
2006-11-01 23:30:46 +00:00
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
if (!_dbus_ensure_directory (&runtime_dir_based, NULL))
|
|
|
|
|
_dbus_assert_not_reached ("Unable to create fake XDG_RUNTIME_DIR");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&runtime_dir_based, "/dbus-1/services"))
|
|
|
|
|
_dbus_assert_not_reached ("out of memory");
|
|
|
|
|
|
2017-02-17 17:15:34 +00:00
|
|
|
/* Sanity check: the Makefile sets this up. We assume that if this is
|
|
|
|
|
* right, the XDG_DATA_DIRS will be too. */
|
|
|
|
|
if (!_dbus_string_starts_with_c_str (&data_home_based, dbus_test_builddir))
|
|
|
|
|
_dbus_assert_not_reached ("$XDG_DATA_HOME should start with $DBUS_TEST_BUILDDIR");
|
|
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
if (!_dbus_string_starts_with_c_str (&runtime_dir_based, dbus_test_builddir))
|
|
|
|
|
_dbus_assert_not_reached ("$XDG_RUNTIME_DIR should start with $DBUS_TEST_BUILDDIR");
|
|
|
|
|
|
2017-02-17 17:15:34 +00:00
|
|
|
test_session_service_dir_matches[0] = _dbus_string_get_const_data (
|
2017-02-13 20:58:51 +00:00
|
|
|
&runtime_dir_based);
|
2017-02-17 17:15:34 +00:00
|
|
|
test_session_service_dir_matches[1] = _dbus_string_get_const_data (
|
2017-02-13 20:58:51 +00:00
|
|
|
&data_home_based);
|
2017-02-17 17:15:34 +00:00
|
|
|
test_session_service_dir_matches[2] = _dbus_string_get_const_data (
|
2017-02-13 20:58:51 +00:00
|
|
|
&data_dirs_based);
|
|
|
|
|
test_session_service_dir_matches[3] = _dbus_string_get_const_data (
|
2017-02-17 17:15:34 +00:00
|
|
|
&data_dirs_based2);
|
2007-05-17 11:47:48 +00:00
|
|
|
#endif
|
2017-02-17 17:15:34 +00:00
|
|
|
|
2017-02-17 18:12:54 +00:00
|
|
|
parser = bus_config_load (&full_path, TRUE, NULL, &error);
|
2017-02-17 17:15:34 +00:00
|
|
|
|
2017-02-17 18:12:54 +00:00
|
|
|
if (parser == NULL)
|
|
|
|
|
_dbus_assert_not_reached (error.message);
|
2006-11-01 23:30:46 +00:00
|
|
|
|
2017-02-17 18:12:54 +00:00
|
|
|
dirs = bus_config_parser_get_service_dirs (parser);
|
|
|
|
|
|
|
|
|
|
for (link = _dbus_list_get_first_link (dirs), i = 0;
|
|
|
|
|
link != NULL;
|
|
|
|
|
link = _dbus_list_get_next_link (dirs, link), i++)
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
2017-02-17 15:03:02 +00:00
|
|
|
BusConfigServiceDir *dir = link->data;
|
2017-02-13 20:58:51 +00:00
|
|
|
BusServiceDirFlags expected = BUS_SERVICE_DIR_FLAGS_NONE;
|
2017-02-17 15:03:02 +00:00
|
|
|
|
|
|
|
|
printf (" test service dir: '%s'\n", dir->path);
|
2015-10-30 06:14:44 +01:00
|
|
|
printf (" current standard service dir: '%s'\n", test_session_service_dir_matches[i]);
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
if (test_session_service_dir_matches[i] == NULL)
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
|
|
|
|
printf ("more directories parsed than in match set\n");
|
2015-09-30 16:35:49 +01:00
|
|
|
goto out;
|
2006-11-01 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:03:02 +00:00
|
|
|
if (strcmp (test_session_service_dir_matches[i], dir->path) != 0)
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
2015-10-30 06:14:44 +01:00
|
|
|
printf ("'%s' directory does not match '%s' in the match set\n",
|
2017-02-17 15:03:02 +00:00
|
|
|
dir->path, test_session_service_dir_matches[i]);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
#ifndef DBUS_WIN
|
|
|
|
|
/* On Unix we expect the first directory in the search path to be
|
|
|
|
|
* in the XDG_RUNTIME_DIR, and we expect it to have special flags */
|
|
|
|
|
if (i == 0)
|
|
|
|
|
expected = (BUS_SERVICE_DIR_FLAGS_NO_WATCH |
|
|
|
|
|
BUS_SERVICE_DIR_FLAGS_STRICT_NAMING);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (dir->flags != expected)
|
2017-02-17 15:03:02 +00:00
|
|
|
{
|
|
|
|
|
printf ("'%s' directory has flags 0x%x, should be 0x%x\n",
|
2017-02-13 20:58:51 +00:00
|
|
|
dir->path, dir->flags, expected);
|
2015-09-30 16:35:49 +01:00
|
|
|
goto out;
|
2006-11-01 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
if (test_session_service_dir_matches[i] != NULL)
|
2006-11-01 23:30:46 +00:00
|
|
|
{
|
|
|
|
|
printf ("extra data %s in the match set was not matched\n",
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
test_session_service_dir_matches[i]);
|
2015-09-30 16:35:49 +01:00
|
|
|
goto out;
|
2006-11-01 23:30:46 +00:00
|
|
|
}
|
2015-09-30 16:35:49 +01:00
|
|
|
|
2017-02-15 14:13:05 +00:00
|
|
|
if (!bus_config_parser_get_watched_dirs (parser, &watched_dirs))
|
|
|
|
|
_dbus_assert_not_reached ("out of memory");
|
|
|
|
|
|
2017-02-13 20:58:51 +00:00
|
|
|
#ifdef DBUS_WIN
|
|
|
|
|
/* We expect all directories to be watched (not that it matters on Windows,
|
|
|
|
|
* because we don't know how) */
|
|
|
|
|
i = 0;
|
|
|
|
|
#else
|
|
|
|
|
/* We expect all directories except the first to be watched, because
|
|
|
|
|
* the first one is transient */
|
|
|
|
|
i = 1;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for (link = _dbus_list_get_first_link (&watched_dirs);
|
2017-02-15 14:13:05 +00:00
|
|
|
link != NULL;
|
|
|
|
|
link = _dbus_list_get_next_link (&watched_dirs, link), i++)
|
|
|
|
|
{
|
|
|
|
|
printf (" watched service dir: '%s'\n", (const char *) link->data);
|
|
|
|
|
printf (" current standard service dir: '%s'\n",
|
|
|
|
|
test_session_service_dir_matches[i]);
|
|
|
|
|
|
|
|
|
|
if (test_session_service_dir_matches[i] == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf ("more directories parsed than in match set\n");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp (test_session_service_dir_matches[i],
|
|
|
|
|
(const char *) link->data) != 0)
|
|
|
|
|
{
|
|
|
|
|
printf ("'%s' directory does not match '%s' in the match set\n",
|
|
|
|
|
(const char *) link->data,
|
|
|
|
|
test_session_service_dir_matches[i]);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (test_session_service_dir_matches[i] != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf ("extra data %s in the match set was not matched\n",
|
|
|
|
|
test_session_service_dir_matches[i]);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-30 16:35:49 +01:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
2017-02-17 18:12:54 +00:00
|
|
|
if (parser != NULL)
|
|
|
|
|
bus_config_parser_unref (parser);
|
|
|
|
|
|
2017-02-15 14:13:05 +00:00
|
|
|
_dbus_list_clear (&watched_dirs);
|
2017-02-17 18:12:54 +00:00
|
|
|
_dbus_string_free (&full_path);
|
2015-09-30 16:35:49 +01:00
|
|
|
_dbus_string_free (&install_root_based);
|
2007-05-17 11:47:48 +00:00
|
|
|
_dbus_string_free (&progs);
|
2017-02-13 20:58:51 +00:00
|
|
|
_dbus_string_free (&runtime_dir_based);
|
2017-02-17 17:15:34 +00:00
|
|
|
_dbus_string_free (&data_home_based);
|
|
|
|
|
_dbus_string_free (&data_dirs_based);
|
|
|
|
|
_dbus_string_free (&data_dirs_based2);
|
2015-09-30 16:35:49 +01:00
|
|
|
return ret;
|
2006-11-01 23:30:46 +00:00
|
|
|
}
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
|
2016-08-19 11:23:54 +02:00
|
|
|
#ifndef DBUS_WIN
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
static const char *test_system_service_dir_matches[] =
|
|
|
|
|
{
|
2012-02-08 16:11:35 +00:00
|
|
|
"/usr/local/share/dbus-1/system-services",
|
|
|
|
|
"/usr/share/dbus-1/system-services",
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
DBUS_DATADIR"/dbus-1/system-services",
|
2011-03-11 03:03:03 +01:00
|
|
|
"/lib/dbus-1/system-services",
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
test_default_system_servicedirs (void)
|
|
|
|
|
{
|
|
|
|
|
DBusList *dirs;
|
|
|
|
|
DBusList *link;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
dirs = NULL;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_get_standard_system_servicedirs (&dirs))
|
|
|
|
|
_dbus_assert_not_reached ("couldn't get stardard dirs");
|
|
|
|
|
|
|
|
|
|
/* make sure we read and parse the env variable correctly */
|
|
|
|
|
i = 0;
|
|
|
|
|
while ((link = _dbus_list_pop_first_link (&dirs)))
|
|
|
|
|
{
|
|
|
|
|
printf (" test service dir: %s\n", (char *)link->data);
|
|
|
|
|
if (test_system_service_dir_matches[i] == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf ("more directories parsed than in match set\n");
|
|
|
|
|
dbus_free (link->data);
|
|
|
|
|
_dbus_list_free_link (link);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp (test_system_service_dir_matches[i],
|
|
|
|
|
(char *)link->data) != 0)
|
|
|
|
|
{
|
|
|
|
|
printf ("%s directory does not match %s in the match set\n",
|
|
|
|
|
(char *)link->data,
|
|
|
|
|
test_system_service_dir_matches[i]);
|
|
|
|
|
dbus_free (link->data);
|
|
|
|
|
_dbus_list_free_link (link);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
|
|
|
|
|
dbus_free (link->data);
|
|
|
|
|
_dbus_list_free_link (link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (test_system_service_dir_matches[i] != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf ("extra data %s in the match set was not matched\n",
|
|
|
|
|
test_system_service_dir_matches[i]);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2016-08-19 11:23:54 +02:00
|
|
|
#endif
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_test (const DBusString *test_data_dir)
|
|
|
|
|
{
|
2003-03-26 07:16:03 +00:00
|
|
|
if (test_data_dir == NULL ||
|
|
|
|
|
_dbus_string_get_length (test_data_dir) == 0)
|
|
|
|
|
{
|
|
|
|
|
printf ("No test data\n");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2017-02-17 18:12:54 +00:00
|
|
|
if (!test_default_session_servicedirs (test_data_dir))
|
2006-11-01 23:30:46 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
2009-12-01 11:17:17 +01:00
|
|
|
#ifdef DBUS_WIN
|
|
|
|
|
printf("default system service dir skipped\n");
|
|
|
|
|
#else
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
if (!test_default_system_servicedirs())
|
|
|
|
|
return FALSE;
|
2009-12-01 11:17:17 +01:00
|
|
|
#endif
|
2007-07-24 Richard Hughes <richard@hughsie.com>
* bus/Makefile.am:
* bus/config-parser.c: (bus_config_parser_unref),
(start_busconfig_child), (bus_config_parser_end_element),
(servicehelper_path), (bus_config_parser_content),
(bus_config_parser_finished),
(bus_config_parser_get_servicehelper),
(test_default_session_servicedirs),
(test_default_system_servicedirs), (bus_config_parser_test):
* bus/config-parser.h:
Make the config-parser code use the common config code.
Also add the session and systemdirs stuff, and make the config parser
aware of the servicehelper field.
2007-07-24 11:58:08 +00:00
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2015-11-03 00:23:56 +01:00
|
|
|
#ifndef DBUS_WIN
|
|
|
|
|
if (!process_test_valid_subdir (test_data_dir, "valid-config-files-system", VALID))
|
|
|
|
|
return FALSE;
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-04-13 01:37:57 +00:00
|
|
|
if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2004-04-09 19:50:29 +00:00
|
|
|
if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
|
2003-03-26 07:16:03 +00:00
|
|
|
return FALSE;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 16:24:37 +08:00
|
|
|
#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
|
2003-03-26 03:58:11 +00:00
|
|
|
|