2003-03-25 04:45:25 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* config-parser.c XML-library-agnostic configuration file parser
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 1.2
|
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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#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"
|
2003-03-26 03:58:11 +00:00
|
|
|
#include <dbus/dbus-list.h>
|
|
|
|
|
#include <dbus/dbus-internals.h>
|
2003-03-25 04:45:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
2003-03-31 04:01:00 +00:00
|
|
|
ELEMENT_NONE,
|
2003-03-25 04:45:25 +00:00
|
|
|
ELEMENT_BUSCONFIG,
|
|
|
|
|
ELEMENT_INCLUDE,
|
|
|
|
|
ELEMENT_USER,
|
|
|
|
|
ELEMENT_LISTEN,
|
|
|
|
|
ELEMENT_AUTH,
|
|
|
|
|
ELEMENT_POLICY,
|
2003-03-31 04:01:00 +00:00
|
|
|
ELEMENT_LIMIT,
|
|
|
|
|
ELEMENT_ALLOW,
|
2003-04-01 05:33:01 +00:00
|
|
|
ELEMENT_DENY,
|
2003-04-02 00:29:33 +00:00
|
|
|
ELEMENT_FORK,
|
2003-04-06 23:15:41 +00:00
|
|
|
ELEMENT_PIDFILE,
|
2003-04-02 00:29:33 +00:00
|
|
|
ELEMENT_SERVICEDIR,
|
2003-04-03 05:22:49 +00:00
|
|
|
ELEMENT_INCLUDEDIR,
|
|
|
|
|
ELEMENT_TYPE
|
2003-03-25 04:45:25 +00:00
|
|
|
} ElementType;
|
|
|
|
|
|
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,
|
|
|
|
|
POLICY_GROUP
|
|
|
|
|
} 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;
|
2003-03-25 04:45:25 +00:00
|
|
|
} include;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
2003-04-13 08:33:10 +00:00
|
|
|
PolicyType type;
|
|
|
|
|
unsigned long gid_or_uid;
|
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 */
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
DBusList *service_dirs; /**< Directories to look for services 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 */
|
|
|
|
|
|
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
|
|
|
|
2003-04-28 19:29:42 +00:00
|
|
|
unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
|
2003-03-25 04:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
static const char*
|
|
|
|
|
element_type_to_name (ElementType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ELEMENT_NONE:
|
|
|
|
|
return NULL;
|
|
|
|
|
case ELEMENT_BUSCONFIG:
|
|
|
|
|
return "busconfig";
|
|
|
|
|
case ELEMENT_INCLUDE:
|
|
|
|
|
return "include";
|
|
|
|
|
case ELEMENT_USER:
|
|
|
|
|
return "user";
|
|
|
|
|
case ELEMENT_LISTEN:
|
|
|
|
|
return "listen";
|
|
|
|
|
case ELEMENT_AUTH:
|
|
|
|
|
return "auth";
|
|
|
|
|
case ELEMENT_POLICY:
|
|
|
|
|
return "policy";
|
|
|
|
|
case ELEMENT_LIMIT:
|
|
|
|
|
return "limit";
|
|
|
|
|
case ELEMENT_ALLOW:
|
|
|
|
|
return "allow";
|
|
|
|
|
case ELEMENT_DENY:
|
|
|
|
|
return "deny";
|
2003-04-01 05:33:01 +00:00
|
|
|
case ELEMENT_FORK:
|
|
|
|
|
return "fork";
|
2003-04-06 23:15:41 +00:00
|
|
|
case ELEMENT_PIDFILE:
|
|
|
|
|
return "pidfile";
|
2003-04-02 00:29:33 +00:00
|
|
|
case ELEMENT_SERVICEDIR:
|
|
|
|
|
return "servicedir";
|
|
|
|
|
case ELEMENT_INCLUDEDIR:
|
|
|
|
|
return "includedir";
|
2003-04-03 05:22:49 +00:00
|
|
|
case ELEMENT_TYPE:
|
|
|
|
|
return "type";
|
2003-03-31 04:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert_not_reached ("bad element type");
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (included->pidfile != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (parser->pidfile);
|
|
|
|
|
parser->pidfile = included->pidfile;
|
|
|
|
|
included->pidfile = NULL;
|
|
|
|
|
}
|
2003-04-01 05:33:01 +00:00
|
|
|
|
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)))
|
|
|
|
|
_dbus_list_append_link (&parser->service_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
|
|
|
}
|
|
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
BusConfigParser*
|
2003-04-28 19:29:42 +00:00
|
|
|
bus_config_parser_new (const DBusString *basedir,
|
|
|
|
|
dbus_bool_t is_toplevel)
|
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) ||
|
|
|
|
|
!_dbus_string_copy (basedir, 0, &parser->basedir, 0))
|
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);
|
|
|
|
|
dbus_free (parser);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2003-04-24 22:30:38 +00:00
|
|
|
|
|
|
|
|
/* Make up some numbers! woot! */
|
|
|
|
|
parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 63;
|
|
|
|
|
parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 63;
|
|
|
|
|
parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
|
2003-04-27 06:25:42 +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-04-24 22:30:38 +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.
|
2003-04-27 06:25:42 +00:00
|
|
|
*/
|
2003-04-25 23:50:34 +00:00
|
|
|
parser->limits.auth_timeout = 30000; /* 30 seconds */
|
2003-04-24 22:30:38 +00:00
|
|
|
|
|
|
|
|
parser->limits.max_incomplete_connections = 32;
|
|
|
|
|
parser->limits.max_connections_per_user = 128;
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
|
|
|
|
parser->limits.max_completed_connections = 1024;
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
parser->limits.max_pending_activations = 256;
|
|
|
|
|
parser->limits.max_services_per_connection = 256;
|
2003-09-21 19:53:56 +00:00
|
|
|
|
|
|
|
|
parser->limits.max_match_rules_per_connection = 128;
|
2003-04-02 21:43:29 +00:00
|
|
|
|
2003-03-25 04:45:25 +00:00
|
|
|
parser->refcount = 1;
|
|
|
|
|
|
|
|
|
|
return parser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_config_parser_ref (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (parser->refcount > 0);
|
|
|
|
|
|
|
|
|
|
parser->refcount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
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,
|
|
|
|
|
(DBusForeachFunction) dbus_free,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_clear (&parser->service_dirs);
|
2003-04-02 21:43:29 +00:00
|
|
|
|
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);
|
2003-04-02 00:29:33 +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);
|
|
|
|
|
|
|
|
|
|
if (!retval)
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (element_name, "user") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "type") == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (push_element (parser, ELEMENT_TYPE) == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
2003-03-31 04:01:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "fork") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2003-04-06 23:15:41 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "pidfile") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "listen") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "auth") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 00:29:33 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "includedir") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "servicedir") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "include") == 0)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
const char *ignore_missing;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (!locate_attributes (parser, "include",
|
|
|
|
|
attribute_names,
|
|
|
|
|
attribute_values,
|
|
|
|
|
error,
|
|
|
|
|
"ignore_missing", &ignore_missing,
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "policy") == 0)
|
|
|
|
|
{
|
|
|
|
|
Element *e;
|
|
|
|
|
const char *context;
|
|
|
|
|
const char *user;
|
|
|
|
|
const char *group;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
if (((context && user) ||
|
|
|
|
|
(context && group)) ||
|
|
|
|
|
(user && group) ||
|
|
|
|
|
!(context || user || group))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"<policy> element must have exactly one of (context|user|group) attributes");
|
|
|
|
|
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
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
if (_dbus_get_user_id (&username,
|
|
|
|
|
&e->d.policy.gid_or_uid))
|
|
|
|
|
e->d.policy.type = POLICY_USER;
|
|
|
|
|
else
|
|
|
|
|
_dbus_warn ("Unknown username \"%s\" in message bus configuration file\n",
|
|
|
|
|
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
|
|
|
|
2003-04-13 08:33:10 +00:00
|
|
|
if (_dbus_get_group_id (&group_name,
|
|
|
|
|
&e->d.policy.gid_or_uid))
|
|
|
|
|
e->d.policy.type = POLICY_GROUP;
|
|
|
|
|
else
|
|
|
|
|
_dbus_warn ("Unknown group \"%s\" in message bus configuration file\n",
|
|
|
|
|
group);
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (element_name, "limit") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Element <%s> not allowed inside <%s> in configuration file",
|
|
|
|
|
element_name, "busconfig");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
static int
|
|
|
|
|
message_type_from_string (const char *type_str)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (type_str, "method_call") == 0)
|
|
|
|
|
return DBUS_MESSAGE_TYPE_METHOD_CALL;
|
|
|
|
|
if (strcmp (type_str, "method_return") == 0)
|
|
|
|
|
return DBUS_MESSAGE_TYPE_METHOD_RETURN;
|
|
|
|
|
else if (strcmp (type_str, "signal") == 0)
|
|
|
|
|
return DBUS_MESSAGE_TYPE_SIGNAL;
|
|
|
|
|
else if (strcmp (type_str, "error") == 0)
|
|
|
|
|
return DBUS_MESSAGE_TYPE_ERROR;
|
|
|
|
|
else
|
|
|
|
|
return DBUS_MESSAGE_TYPE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
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;
|
2003-04-13 08:33:10 +00:00
|
|
|
const char *own;
|
|
|
|
|
const char *user;
|
|
|
|
|
const char *group;
|
|
|
|
|
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,
|
2003-04-13 08:33:10 +00:00
|
|
|
"own", &own,
|
|
|
|
|
"user", &user,
|
|
|
|
|
"group", &group,
|
|
|
|
|
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 ||
|
|
|
|
|
receive_type || receive_path || eavesdrop ||
|
2003-08-18 15:27:33 +00:00
|
|
|
own || 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
|
|
|
|
|
*
|
2003-09-21 19:53:56 +00:00
|
|
|
* base send_ can combine with send_destination, send_path, send_type
|
|
|
|
|
* base receive_ with receive_sender, receive_path, receive_type, eavesdrop
|
2003-08-18 15:27:33 +00:00
|
|
|
*
|
|
|
|
|
* user, group, own 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
|
|
|
|
2003-08-18 15:27:33 +00:00
|
|
|
if (((send_interface && send_error) ||
|
|
|
|
|
(send_interface && receive_interface) ||
|
|
|
|
|
(send_interface && receive_member) ||
|
|
|
|
|
(send_interface && receive_error) ||
|
2003-09-21 19:53:56 +00:00
|
|
|
(send_interface && receive_sender) ||
|
|
|
|
|
(send_interface && eavesdrop) ||
|
2003-08-18 15:27:33 +00:00
|
|
|
(send_interface && own) ||
|
|
|
|
|
(send_interface && user) ||
|
|
|
|
|
(send_interface && group)) ||
|
|
|
|
|
|
|
|
|
|
((send_member && send_error) ||
|
|
|
|
|
(send_member && receive_interface) ||
|
|
|
|
|
(send_member && receive_member) ||
|
|
|
|
|
(send_member && receive_error) ||
|
2003-09-21 19:53:56 +00:00
|
|
|
(send_member && receive_sender) ||
|
|
|
|
|
(send_member && eavesdrop) ||
|
2003-08-18 15:27:33 +00:00
|
|
|
(send_member && own) ||
|
|
|
|
|
(send_member && user) ||
|
|
|
|
|
(send_member && group)) ||
|
|
|
|
|
|
|
|
|
|
((send_error && receive_interface) ||
|
|
|
|
|
(send_error && receive_member) ||
|
|
|
|
|
(send_error && receive_error) ||
|
2003-09-21 19:53:56 +00:00
|
|
|
(send_error && receive_sender) ||
|
|
|
|
|
(send_error && eavesdrop) ||
|
2003-08-18 15:27:33 +00:00
|
|
|
(send_error && own) ||
|
|
|
|
|
(send_error && user) ||
|
|
|
|
|
(send_error && group)) ||
|
|
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
((send_destination && receive_interface) ||
|
|
|
|
|
(send_destination && receive_member) ||
|
|
|
|
|
(send_destination && receive_error) ||
|
|
|
|
|
(send_destination && receive_sender) ||
|
|
|
|
|
(send_destination && eavesdrop) ||
|
|
|
|
|
(send_destination && own) ||
|
|
|
|
|
(send_destination && user) ||
|
|
|
|
|
(send_destination && group)) ||
|
2003-08-18 15:27:33 +00:00
|
|
|
|
2003-09-06 21:12:11 +00:00
|
|
|
((send_type && receive_interface) ||
|
|
|
|
|
(send_type && receive_member) ||
|
|
|
|
|
(send_type && receive_error) ||
|
2003-09-21 19:53:56 +00:00
|
|
|
(send_type && receive_sender) ||
|
|
|
|
|
(send_type && eavesdrop) ||
|
2003-09-06 21:12:11 +00:00
|
|
|
(send_type && own) ||
|
|
|
|
|
(send_type && user) ||
|
|
|
|
|
(send_type && group)) ||
|
|
|
|
|
|
|
|
|
|
((send_path && receive_interface) ||
|
|
|
|
|
(send_path && receive_member) ||
|
|
|
|
|
(send_path && receive_error) ||
|
2003-09-21 19:53:56 +00:00
|
|
|
(send_path && receive_sender) ||
|
|
|
|
|
(send_path && eavesdrop) ||
|
2003-09-06 21:12:11 +00:00
|
|
|
(send_path && own) ||
|
|
|
|
|
(send_path && user) ||
|
|
|
|
|
(send_path && group)) ||
|
|
|
|
|
|
2003-08-18 15:27:33 +00:00
|
|
|
((receive_interface && receive_error) ||
|
|
|
|
|
(receive_interface && own) ||
|
|
|
|
|
(receive_interface && user) ||
|
|
|
|
|
(receive_interface && group)) ||
|
|
|
|
|
|
|
|
|
|
((receive_member && receive_error) ||
|
|
|
|
|
(receive_member && own) ||
|
|
|
|
|
(receive_member && user) ||
|
|
|
|
|
(receive_member && group)) ||
|
2003-09-21 19:53:56 +00:00
|
|
|
|
2003-08-18 15:27:33 +00:00
|
|
|
((receive_error && own) ||
|
|
|
|
|
(receive_error && user) ||
|
|
|
|
|
(receive_error && group)) ||
|
|
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
((eavesdrop && own) ||
|
|
|
|
|
(eavesdrop && user) ||
|
|
|
|
|
(eavesdrop && group)) ||
|
|
|
|
|
|
2003-08-18 15:27:33 +00:00
|
|
|
((own && user) ||
|
|
|
|
|
(own && group)) ||
|
2003-04-13 08:33:10 +00:00
|
|
|
|
2003-08-18 15:27:33 +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 ||
|
2003-09-06 21:12:11 +00:00
|
|
|
send_path || send_type)
|
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)
|
|
|
|
|
{
|
|
|
|
|
message_type = message_type_from_string (send_type);
|
|
|
|
|
if (message_type == DBUS_MESSAGE_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Bad message type \"%s\"",
|
|
|
|
|
send_type);
|
|
|
|
|
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
|
|
|
|
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 ||
|
|
|
|
|
receive_path || receive_type || eavesdrop)
|
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)
|
|
|
|
|
{
|
|
|
|
|
message_type = message_type_from_string (receive_type);
|
|
|
|
|
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,
|
|
|
|
|
"Bad value \"%s\" for eavesdrop attribute, must be true or false",
|
|
|
|
|
eavesdrop);
|
|
|
|
|
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-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-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;
|
|
|
|
|
}
|
|
|
|
|
else if (own)
|
|
|
|
|
{
|
|
|
|
|
rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (IS_WILDCARD (own))
|
|
|
|
|
own = NULL;
|
|
|
|
|
|
|
|
|
|
rule->d.own.service_name = _dbus_strdup (own);
|
|
|
|
|
if (own && rule->d.own.service_name == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (_dbus_get_user_id (&username, &uid))
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
_dbus_warn ("Unknown username \"%s\" on element <%s>\n",
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (_dbus_get_user_id (&groupname, &gid))
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
_dbus_warn ("Unknown group \"%s\" on element <%s>\n",
|
|
|
|
|
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:
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_or_uid,
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_or_uid,
|
|
|
|
|
rule))
|
|
|
|
|
goto nomem;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "max_outgoing_bytes") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_outgoing_bytes = value;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "max_message_size") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
parser->limits.max_message_size = value;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "activation_timeout") == 0)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2003-04-25 23:50:34 +00:00
|
|
|
else if (strcmp (name, "max_pending_activations") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_pending_activations = value;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (name, "max_services_per_connection") == 0)
|
|
|
|
|
{
|
|
|
|
|
must_be_positive = TRUE;
|
|
|
|
|
must_be_int = TRUE;
|
|
|
|
|
parser->limits.max_services_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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = element_type_to_name (t);
|
|
|
|
|
_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:
|
|
|
|
|
_dbus_assert_not_reached ("element in stack has no type");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ELEMENT_INCLUDE:
|
|
|
|
|
case ELEMENT_USER:
|
2003-04-03 05:22:49 +00:00
|
|
|
case ELEMENT_TYPE:
|
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:
|
|
|
|
|
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",
|
|
|
|
|
element_type_to_name (e->type));
|
|
|
|
|
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:
|
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))
|
|
|
|
|
{
|
|
|
|
|
return _dbus_string_copy (filename, 0, full_path, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_string_copy (basedir, 0, full_path, 0))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (full_path, filename))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
DBusError tmp_error;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&tmp_error);
|
2003-04-28 19:29:42 +00:00
|
|
|
included = bus_config_load (filename, FALSE, &tmp_error);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus_config_parser_unref (included);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
include_dir (BusConfigParser *parser,
|
|
|
|
|
const DBusString *dirname,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
DBusString filename;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
DBusError tmp_error;
|
|
|
|
|
DBusDirIter *dir;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
goto failed;
|
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))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
_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:
|
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",
|
|
|
|
|
element_type_to_name (top_element_type (parser)));
|
|
|
|
|
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:
|
|
|
|
|
{
|
2003-04-02 21:43:29 +00:00
|
|
|
DBusString full_path;
|
|
|
|
|
|
2003-03-31 04:01:00 +00:00
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
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 (!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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
case ELEMENT_TYPE:
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
e->had_content = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_copy_data (content, &s))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
dbus_free (parser->bus_type);
|
|
|
|
|
parser->bus_type = s;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
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;
|
2003-04-02 21:43:29 +00:00
|
|
|
DBusString full_path;
|
2003-04-02 00:29:33 +00:00
|
|
|
|
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
|
|
|
|
2003-04-02 21:43:29 +00:00
|
|
|
if (!_dbus_list_append (&parser->service_dirs, s))
|
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
|
|
|
|
|
|
|
|
_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",
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 05:33:01 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_config_parser_get_fork (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->fork;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-06 23:15:41 +00:00
|
|
|
const char *
|
|
|
|
|
bus_config_parser_get_pidfile (BusConfigParser *parser)
|
|
|
|
|
{
|
|
|
|
|
return parser->pidfile;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
#ifdef DBUS_BUILD_TESTS
|
2003-03-26 07:16:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
VALID,
|
|
|
|
|
INVALID,
|
|
|
|
|
UNKNOWN
|
|
|
|
|
} Validity;
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
do_load (const DBusString *full_path,
|
|
|
|
|
Validity validity,
|
|
|
|
|
dbus_bool_t oom_possible)
|
|
|
|
|
{
|
|
|
|
|
BusConfigParser *parser;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-04-28 19:29:42 +00:00
|
|
|
parser = bus_config_load (full_path, TRUE, &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
|
|
|
{
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_warn ("Failed to load valid file but still had memory: %s\n",
|
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
_dbus_warn ("Accepted invalid file\n");
|
|
|
|
|
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;
|
|
|
|
|
} 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
|
|
|
|
2003-03-28 05:42:19 +00:00
|
|
|
return do_load (d->full_path, d->validity, TRUE);
|
2003-03-26 07:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
process_test_subdir (const DBusString *test_base_dir,
|
|
|
|
|
const char *subdir,
|
|
|
|
|
Validity validity)
|
|
|
|
|
{
|
|
|
|
|
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))
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_assert_not_reached ("didn't allocate test_directory\n");
|
|
|
|
|
|
|
|
|
|
_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))
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_assert_not_reached ("didn't allocate filename string\n");
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
dir = _dbus_directory_open (&test_directory, &error);
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_warn ("Could not open %s: %s\n",
|
|
|
|
|
_dbus_string_get_const_data (&test_directory),
|
2003-03-26 07:16:03 +00:00
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("Testing:\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));
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
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;
|
|
|
|
|
if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d))
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_assert_not_reached ("test failed");
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
_dbus_warn ("Could not get next file in %s: %s\n",
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
if (!process_test_subdir (test_data_dir, "valid-config-files", VALID))
|
|
|
|
|
return FALSE;
|
2003-03-31 04:01:00 +00:00
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* DBUS_BUILD_TESTS */
|
|
|
|
|
|