1ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project/* -*- mode: C; c-file-style: "gnu" -*- */
2ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project/* config-parser.c  XML-library-agnostic configuration file parser
3ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project *
4ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * Copyright (C) 2003, 2004 Red Hat, Inc.
5ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project *
6ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * Licensed under the Academic Free License version 2.1
7ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project *
8ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * This program is free software; you can redistribute it and/or modify
9ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * it under the terms of the GNU General Public License as published by
10ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * the Free Software Foundation; either version 2 of the License, or
11ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * (at your option) any later version.
12ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project *
13ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * This program is distributed in the hope that it will be useful,
14ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of
15ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * GNU General Public License for more details.
17ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project *
18ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * You should have received a copy of the GNU General Public License
19ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * along with this program; if not, write to the Free Software
20ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project *
22ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project */
23ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include "config-parser.h"
24ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include "test.h"
25ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include "utils.h"
26ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include "policy.h"
27ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include "selinux.h"
28ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include <dbus/dbus-list.h>
29ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include <dbus/dbus-internals.h>
30ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include <string.h>
31ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
32ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttypedef enum
33ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
34ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_NONE,
35ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_BUSCONFIG,
36ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_INCLUDE,
37ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_USER,
38ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_LISTEN,
39ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_AUTH,
40ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_POLICY,
41ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_LIMIT,
42ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_ALLOW,
43ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_DENY,
44ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_FORK,
45ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_PIDFILE,
46ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_SERVICEDIR,
47ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_INCLUDEDIR,
48ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_TYPE,
49ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_SELINUX,
50ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_ASSOCIATE,
51ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ELEMENT_STANDARD_SESSION_SERVICEDIRS
52ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project} ElementType;
53ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
54ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttypedef enum
55ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
56ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* we ignore policies for unknown groups/users */
57ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  POLICY_IGNORED,
58ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
59ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* non-ignored */
60ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  POLICY_DEFAULT,
61ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  POLICY_MANDATORY,
62ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  POLICY_USER,
63ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  POLICY_GROUP,
64ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  POLICY_CONSOLE
65ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project} PolicyType;
66ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
67ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttypedef struct
68ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
69ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ElementType type;
70ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
71ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  unsigned int had_content : 1;
72ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
73ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  union
74ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  {
75ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    struct
76ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
77ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      unsigned int ignore_missing : 1;
78ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      unsigned int if_selinux_enabled : 1;
79ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      unsigned int selinux_root_relative : 1;
80ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    } include;
81ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
82ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    struct
83ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
84ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      PolicyType type;
85ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      unsigned long gid_uid_or_at_console;
86ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    } policy;
87ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
88ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    struct
89ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
90ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      char *name;
91ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      long value;
92ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    } limit;
93ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
94ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  } d;
95ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
96ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project} Element;
97ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
98ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project/**
99ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project * Parser for bus configuration file.
100ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project */
101ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstruct BusConfigParser
102ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
103ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  int refcount;        /**< Reference count */
104ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
105ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString basedir;  /**< Directory we resolve paths relative to */
106ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
107ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *stack;     /**< stack of Element */
108ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
109ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *user;          /**< user to run as */
110ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
111ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *bus_type;          /**< Message bus type */
112ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
113ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *listen_on; /**< List of addresses to listen to */
114ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
115ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *mechanisms; /**< Auth mechanisms */
116ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
117ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *service_dirs; /**< Directories to look for services in */
118ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
119ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *conf_dirs;   /**< Directories to look for policy configuration in */
120ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
121ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusPolicy *policy;     /**< Security policy */
122ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
123ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusLimits limits;      /**< Limits */
124ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
125ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *pidfile;         /**< PID file */
126ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
127ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *included_files;  /**< Included files stack */
128ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
129ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */
130ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
131ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  unsigned int fork : 1; /**< TRUE to fork into daemon mode */
132ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
133ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
134ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project};
135ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
136ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic const char*
137ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectelement_type_to_name (ElementType type)
138ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
139ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  switch (type)
140ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
141ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_NONE:
142ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return NULL;
143ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_BUSCONFIG:
144ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "busconfig";
145ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDE:
146ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "include";
147ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_USER:
148ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "user";
149ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LISTEN:
150ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "listen";
151ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_AUTH:
152ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "auth";
153ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_POLICY:
154ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "policy";
155ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LIMIT:
156ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "limit";
157ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_ALLOW:
158ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "allow";
159ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_DENY:
160ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "deny";
161ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_FORK:
162ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "fork";
163ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_PIDFILE:
164ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "pidfile";
165ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
166ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "standard_session_servicedirs";
167ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_SERVICEDIR:
168ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "servicedir";
169ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDEDIR:
170ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "includedir";
171ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_TYPE:
172ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "type";
173ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_SELINUX:
174ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "selinux";
175ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_ASSOCIATE:
176ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return "associate";
177ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
178ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
179ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert_not_reached ("bad element type");
180ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
181ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return NULL;
182ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
183ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
184ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic Element*
185ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectpush_element (BusConfigParser *parser,
186ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              ElementType      type)
187ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
188ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Element *e;
189ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
190ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (type != ELEMENT_NONE);
191ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
192ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e = dbus_new0 (Element, 1);
193ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (e == NULL)
194ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return NULL;
195ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
196ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_list_append (&parser->stack, e))
197ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
198ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (e);
199ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return NULL;
200ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
201ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
202ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e->type = type;
203ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
204ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return e;
205ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
206ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
207ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic void
208ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectelement_free (Element *e)
209ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
210ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (e->type == ELEMENT_LIMIT)
211ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    dbus_free (e->d.limit.name);
212ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
213ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_free (e);
214ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
215ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
216ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic void
217ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectpop_element (BusConfigParser *parser)
218ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
219ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Element *e;
220ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
221ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e = _dbus_list_pop_last (&parser->stack);
222ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
223ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  element_free (e);
224ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
225ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
226ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic Element*
227ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectpeek_element (BusConfigParser *parser)
228ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
229ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Element *e;
230ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
231ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e = _dbus_list_get_last (&parser->stack);
232ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
233ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return e;
234ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
235ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
236ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic ElementType
237ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttop_element_type (BusConfigParser *parser)
238ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
239ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Element *e;
240ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
241ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e = _dbus_list_get_last (&parser->stack);
242ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
243ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (e)
244ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return e->type;
245ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
246ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return ELEMENT_NONE;
247ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
248ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
249ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
250ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectmerge_service_context_hash (DBusHashTable *dest,
251ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project			    DBusHashTable *from)
252ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
253ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusHashIter iter;
254ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *service_copy;
255ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *context_copy;
256ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
257ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  service_copy = NULL;
258ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  context_copy = NULL;
259ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
260ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_hash_iter_init (from, &iter);
261ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (_dbus_hash_iter_next (&iter))
262ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
263ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *service = _dbus_hash_iter_get_string_key (&iter);
264ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *context = _dbus_hash_iter_get_value (&iter);
265ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
266ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      service_copy = _dbus_strdup (service);
267ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (service_copy == NULL)
268ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto fail;
269ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      context_copy = _dbus_strdup (context);
270ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (context_copy == NULL)
271ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto fail;
272ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
273ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
274ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto fail;
275ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
276ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      service_copy = NULL;
277ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      context_copy = NULL;
278ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
279ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
280ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
281ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
282ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project fail:
283ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (service_copy)
284ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    dbus_free (service_copy);
285ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
286ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (context_copy)
287ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    dbus_free (context_copy);
288ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
289ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return FALSE;
290ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
291ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
292ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
293ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectservice_dirs_find_dir (DBusList **service_dirs,
294ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       const char *dir)
295ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
296ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *link;
297ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
298ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (dir != NULL);
299ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
300ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link))
301ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
302ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *link_dir;
303ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
304ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      link_dir = (const char *)link->data;
305ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (strcmp (dir, link_dir) == 0)
306ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return TRUE;
307ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
308ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
309ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return FALSE;
310ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
311ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
312ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
313ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectservice_dirs_append_unique_or_free (DBusList **service_dirs,
314ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                    char *dir)
315ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
316ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!service_dirs_find_dir (service_dirs, dir))
317ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return _dbus_list_append (service_dirs, dir);
318ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
319ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_free (dir);
320ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
321ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
322ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
323ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic void
324ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectservice_dirs_append_link_unique_or_free (DBusList **service_dirs,
325ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                         DBusList *dir_link)
326ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
327ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!service_dirs_find_dir (service_dirs, dir_link->data))
328ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
329ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_append_link (service_dirs, dir_link);
330ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
331ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
332ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
333ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (dir_link->data);
334ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_free_link (dir_link);
335ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
336ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
337ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
338ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
339ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectmerge_included (BusConfigParser *parser,
340ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                BusConfigParser *included,
341ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                DBusError       *error)
342ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
343ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *link;
344ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
345ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!bus_policy_merge (parser->policy,
346ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                         included->policy))
347ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
348ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      BUS_SET_OOM (error);
349ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
350ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
351ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
352ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!merge_service_context_hash (parser->service_context_table,
353ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project				   included->service_context_table))
354ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
355ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      BUS_SET_OOM (error);
356ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
357ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
358ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
359ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (included->user != NULL)
360ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
361ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser->user);
362ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->user = included->user;
363ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      included->user = NULL;
364ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
365ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
366ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (included->bus_type != NULL)
367ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
368ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser->bus_type);
369ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->bus_type = included->bus_type;
370ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      included->bus_type = NULL;
371ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
372ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
373ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (included->fork)
374ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    parser->fork = TRUE;
375ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
376ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (included->pidfile != NULL)
377ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
378ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser->pidfile);
379ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->pidfile = included->pidfile;
380ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      included->pidfile = NULL;
381ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
382ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
383ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while ((link = _dbus_list_pop_first_link (&included->listen_on)))
384ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_list_append_link (&parser->listen_on, link);
385ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
386ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while ((link = _dbus_list_pop_first_link (&included->mechanisms)))
387ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_list_append_link (&parser->mechanisms, link);
388ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
389ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
390ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
391ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
392ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
393ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_list_append_link (&parser->conf_dirs, link);
394ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
395ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
396ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
397ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
398ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
399ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectseen_include (BusConfigParser  *parser,
400ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	      const DBusString *file)
401ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
402ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *iter;
403ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
404ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  iter = parser->included_files;
405ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (iter != NULL)
406ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
407ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (! strcmp (_dbus_string_get_const_data (file), iter->data))
408ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return TRUE;
409ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
410ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      iter = _dbus_list_get_next_link (&parser->included_files, iter);
411ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
412ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
413ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return FALSE;
414ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
415ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
416ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectBusConfigParser*
417ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_new (const DBusString      *basedir,
418ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       dbus_bool_t            is_toplevel,
419ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       const BusConfigParser *parent)
420ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
421ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusConfigParser *parser;
422ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
423ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser = dbus_new0 (BusConfigParser, 1);
424ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (parser == NULL)
425ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return NULL;
426ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
427ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser->is_toplevel = !!is_toplevel;
428ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
429ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&parser->basedir))
430ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
431ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser);
432ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return NULL;
433ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
434ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
435ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (((parser->policy = bus_policy_new ()) == NULL) ||
436ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      !_dbus_string_copy (basedir, 0, &parser->basedir, 0) ||
437ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING,
438ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project							      dbus_free,
439ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project							      dbus_free)) == NULL))
440ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
441ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (parser->policy)
442ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        bus_policy_unref (parser->policy);
443ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
444ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_free (&parser->basedir);
445ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
446ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser);
447ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return NULL;
448ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
449ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
450ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (parent != NULL)
451ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
452ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Initialize the parser's limits from the parent. */
453ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits = parent->limits;
454ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
455ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Use the parent's list of included_files to avoid
456ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	 circular inclusions. */
457ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->included_files = parent->included_files;
458ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
459ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
460ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
461ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
462ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Make up some numbers! woot! */
463ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 63;
464ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 63;
465ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
466ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
467ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Making this long means the user has to wait longer for an error
468ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * message if something screws up, but making it too short means
469ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * they might see a false failure.
470ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       */
471ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.activation_timeout = 25000; /* 25 seconds */
472ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
473ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Making this long risks making a DOS attack easier, but too short
474ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * and legitimate auth will fail.  If interactive auth (ask user for
475ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * password) is allowed, then potentially it has to be quite long.
476ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       */
477ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.auth_timeout = 30000; /* 30 seconds */
478ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
479ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_incomplete_connections = 32;
480ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_connections_per_user = 128;
481ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
482ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Note that max_completed_connections / max_connections_per_user
483ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * is the number of users that would have to work together to
484ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * DOS all the other users.
485ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       */
486ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_completed_connections = 1024;
487ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
488ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_pending_activations = 256;
489ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_services_per_connection = 256;
490ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
491ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_match_rules_per_connection = 512;
492ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
493ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.reply_timeout = 5 * 60 * 1000; /* 5 minutes */
494ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_replies_per_connection = 32;
495ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
496ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
497ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser->refcount = 1;
498ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
499ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return parser;
500ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
501ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
502ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectBusConfigParser *
503ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_ref (BusConfigParser *parser)
504ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
505ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (parser->refcount > 0);
506ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
507ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser->refcount += 1;
508ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
509ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return parser;
510ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
511ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
512ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectvoid
513ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_unref (BusConfigParser *parser)
514ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
515ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (parser->refcount > 0);
516ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
517ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser->refcount -= 1;
518ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
519ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (parser->refcount == 0)
520ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
521ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      while (parser->stack != NULL)
522ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        pop_element (parser);
523ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
524ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser->user);
525ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser->bus_type);
526ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser->pidfile);
527ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
528ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_foreach (&parser->listen_on,
529ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          (DBusForeachFunction) dbus_free,
530ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          NULL);
531ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
532ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_clear (&parser->listen_on);
533ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
534ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_foreach (&parser->service_dirs,
535ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          (DBusForeachFunction) dbus_free,
536ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          NULL);
537ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
538ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_clear (&parser->service_dirs);
539ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
540ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_foreach (&parser->conf_dirs,
541ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          (DBusForeachFunction) dbus_free,
542ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          NULL);
543ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
544ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_clear (&parser->conf_dirs);
545ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
546ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_foreach (&parser->mechanisms,
547ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          (DBusForeachFunction) dbus_free,
548ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          NULL);
549ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
550ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_clear (&parser->mechanisms);
551ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
552ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_free (&parser->basedir);
553ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
554ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (parser->policy)
555ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        bus_policy_unref (parser->policy);
556ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
557ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (parser->service_context_table)
558ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_hash_table_unref (parser->service_context_table);
559ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
560ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (parser);
561ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
562ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
563ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
564ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
565ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_check_doctype (BusConfigParser   *parser,
566ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 const char        *doctype,
567ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 DBusError         *error)
568ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
569ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
570ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
571ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (strcmp (doctype, "busconfig") != 0)
572ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
573ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error,
574ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      DBUS_ERROR_FAILED,
575ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Configuration file has the wrong document type %s",
576ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      doctype);
577ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
578ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
579ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
580ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return TRUE;
581ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
582ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
583ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttypedef struct
584ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
585ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char  *name;
586ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char **retloc;
587ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project} LocateAttr;
588ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
589ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
590ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectlocate_attributes (BusConfigParser  *parser,
591ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   const char       *element_name,
592ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   const char      **attribute_names,
593ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   const char      **attribute_values,
594ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   DBusError        *error,
595ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   const char       *first_attribute_name,
596ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   const char      **first_attribute_retloc,
597ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                   ...)
598ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
599ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  va_list args;
600ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *name;
601ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char **retloc;
602ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  int n_attrs;
603ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#define MAX_ATTRS 24
604ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  LocateAttr attrs[MAX_ATTRS];
605ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t retval;
606ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  int i;
607ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
608ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (first_attribute_name != NULL);
609ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (first_attribute_retloc != NULL);
610ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
611ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = TRUE;
612ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
613ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  n_attrs = 1;
614ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  attrs[0].name = first_attribute_name;
615ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  attrs[0].retloc = first_attribute_retloc;
616ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  *first_attribute_retloc = NULL;
617ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
618ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  va_start (args, first_attribute_retloc);
619ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
620ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  name = va_arg (args, const char*);
621ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retloc = va_arg (args, const char**);
622ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
623ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (name != NULL)
624ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
625ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert (retloc != NULL);
626ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert (n_attrs < MAX_ATTRS);
627ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
628ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      attrs[n_attrs].name = name;
629ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      attrs[n_attrs].retloc = retloc;
630ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      n_attrs += 1;
631ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      *retloc = NULL;
632ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
633ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      name = va_arg (args, const char*);
634ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      retloc = va_arg (args, const char**);
635ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
636ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
637ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  va_end (args);
638ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
639ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!retval)
640ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return retval;
641ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
642ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  i = 0;
643ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (attribute_names[i])
644ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
645ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      int j;
646ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_bool_t found;
647ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
648ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      found = FALSE;
649ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      j = 0;
650ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      while (j < n_attrs)
651ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
652ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (strcmp (attrs[j].name, attribute_names[i]) == 0)
653ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
654ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              retloc = attrs[j].retloc;
655ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
656ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              if (*retloc != NULL)
657ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                {
658ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  dbus_set_error (error, DBUS_ERROR_FAILED,
659ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                  "Attribute \"%s\" repeated twice on the same <%s> element",
660ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                  attrs[j].name, element_name);
661ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  retval = FALSE;
662ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  goto out;
663ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                }
664ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
665ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              *retloc = attribute_values[i];
666ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              found = TRUE;
667ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
668ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
669ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          ++j;
670ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
671ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
672ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!found)
673ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
674ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
675ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "Attribute \"%s\" is invalid on <%s> element in this context",
676ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          attribute_names[i], element_name);
677ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          retval = FALSE;
678ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto out;
679ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
680ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
681ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ++i;
682ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
683ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
684ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project out:
685ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return retval;
686ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
687ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
688ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
689ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectcheck_no_attributes (BusConfigParser  *parser,
690ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     const char       *element_name,
691ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     const char      **attribute_names,
692ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     const char      **attribute_values,
693ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     DBusError        *error)
694ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
695ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (attribute_names[0] != NULL)
696ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
697ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
698ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Attribute \"%s\" is invalid on <%s> element in this context",
699ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      attribute_names[0], element_name);
700ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
701ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
702ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
703ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
704ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
705ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
706ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
707ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstart_busconfig_child (BusConfigParser   *parser,
708ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       const char        *element_name,
709ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       const char       **attribute_names,
710ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       const char       **attribute_values,
711ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       DBusError         *error)
712ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
713ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (strcmp (element_name, "user") == 0)
714ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
715ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
716ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
717ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
718ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_USER) == NULL)
719ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
720ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
721ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
722ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
723ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
724ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
725ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
726ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "type") == 0)
727ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
728ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
729ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
730ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
731ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_TYPE) == NULL)
732ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
733ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
734ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
735ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
736ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
737ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
738ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
739ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "fork") == 0)
740ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
741ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
742ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
743ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
744ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_FORK) == NULL)
745ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
746ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
747ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
748ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
749ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
750ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->fork = TRUE;
751ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
752ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
753ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
754ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "pidfile") == 0)
755ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
756ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
757ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
758ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
759ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_PIDFILE) == NULL)
760ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
761ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
762ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
763ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
764ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
765ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
766ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
767ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "listen") == 0)
768ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
769ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
770ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
771ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
772ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_LISTEN) == NULL)
773ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
774ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
775ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
776ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
777ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
778ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
779ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
780ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "auth") == 0)
781ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
782ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
783ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
784ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
785ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_AUTH) == NULL)
786ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
787ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
788ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
789ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
790ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
791ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
792ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
793ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "includedir") == 0)
794ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
795ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
796ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
797ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
798ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
799ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
800ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
801ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
802ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
803ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
804ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
805ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
806ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "standard_session_servicedirs") == 0)
807ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
808ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusList *link;
809ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusList *dirs;
810ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dirs = NULL;
811ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
812ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error))
813ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
814ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
815ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL)
816ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
817ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
818ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
819ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
820ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
821ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_get_standard_session_servicedirs (&dirs))
822ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
823ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
824ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
825ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
826ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
827ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        while ((link = _dbus_list_pop_first_link (&dirs)))
828ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
829ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
830ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
831ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
832ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "servicedir") == 0)
833ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
834ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
835ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
836ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
837ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
838ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
839ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
840ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
841ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
842ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
843ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
844ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
845ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "include") == 0)
846ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
847ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      Element *e;
848ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *if_selinux_enabled;
849ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *ignore_missing;
850ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *selinux_root_relative;
851ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
852ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
853ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
854ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
855ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
856ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
857ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
858ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      e->d.include.ignore_missing = FALSE;
859ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      e->d.include.if_selinux_enabled = FALSE;
860ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      e->d.include.selinux_root_relative = FALSE;
861ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
862ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!locate_attributes (parser, "include",
863ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_names,
864ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_values,
865ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              error,
866ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "ignore_missing", &ignore_missing,
867ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "if_selinux_enabled", &if_selinux_enabled,
868ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "selinux_root_relative", &selinux_root_relative,
869ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              NULL))
870ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
871ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
872ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (ignore_missing != NULL)
873ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
874ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (strcmp (ignore_missing, "yes") == 0)
875ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.include.ignore_missing = TRUE;
876ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else if (strcmp (ignore_missing, "no") == 0)
877ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.include.ignore_missing = FALSE;
878ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
879ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
880ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
881ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "ignore_missing attribute must have value \"yes\" or \"no\"");
882ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
883ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
884ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
885ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
886ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (if_selinux_enabled != NULL)
887ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
888ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (strcmp (if_selinux_enabled, "yes") == 0)
889ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.include.if_selinux_enabled = TRUE;
890ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else if (strcmp (if_selinux_enabled, "no") == 0)
891ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.include.if_selinux_enabled = FALSE;
892ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
893ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
894ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
895ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "if_selinux_enabled attribute must have value"
896ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              " \"yes\" or \"no\"");
897ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
898ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	    }
899ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
900ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
901ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (selinux_root_relative != NULL)
902ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
903ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (strcmp (selinux_root_relative, "yes") == 0)
904ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.include.selinux_root_relative = TRUE;
905ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else if (strcmp (selinux_root_relative, "no") == 0)
906ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.include.selinux_root_relative = FALSE;
907ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
908ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
909ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
910ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "selinux_root_relative attribute must have value"
911ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              " \"yes\" or \"no\"");
912ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
913ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	    }
914ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
915ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
916ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
917ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
918ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "policy") == 0)
919ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
920ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      Element *e;
921ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *context;
922ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *user;
923ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *group;
924ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *at_console;
925ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
926ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
927ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
928ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
929ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
930ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
931ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
932ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      e->d.policy.type = POLICY_IGNORED;
933ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
934ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!locate_attributes (parser, "policy",
935ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_names,
936ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_values,
937ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              error,
938ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "context", &context,
939ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "user", &user,
940ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "group", &group,
941ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "at_console", &at_console,
942ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              NULL))
943ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
944ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
945ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (((context && user) ||
946ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           (context && group) ||
947ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           (context && at_console)) ||
948ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           ((user && group) ||
949ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           (user && at_console)) ||
950ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           (group && at_console) ||
951ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          !(context || user || group || at_console))
952ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
953ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
954ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "<policy> element must have exactly one of (context|user|group|at_console) attributes");
955ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
956ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
957ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
958ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (context != NULL)
959ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
960ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (strcmp (context, "default") == 0)
961ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
962ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              e->d.policy.type = POLICY_DEFAULT;
963ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
964ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else if (strcmp (context, "mandatory") == 0)
965ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
966ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              e->d.policy.type = POLICY_MANDATORY;
967ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
968ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
969ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
970ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
971ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"",
972ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              context);
973ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
974ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
975ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
976ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else if (user != NULL)
977ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
978ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          DBusString username;
979ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_init_const (&username, user);
980ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
981ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (_dbus_get_user_id (&username,
982ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 &e->d.policy.gid_uid_or_at_console))
983ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.policy.type = POLICY_USER;
984ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
985ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n",
986ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                        user);
987ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
988ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else if (group != NULL)
989ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
990ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          DBusString group_name;
991ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_init_const (&group_name, group);
992ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
993ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (_dbus_get_group_id (&group_name,
994ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                  &e->d.policy.gid_uid_or_at_console))
995ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            e->d.policy.type = POLICY_GROUP;
996ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
997ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n",
998ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                        group);
999ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1000ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else if (at_console != NULL)
1001ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1002ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           dbus_bool_t t;
1003ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           t = (strcmp (at_console, "true") == 0);
1004ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           if (t || strcmp (at_console, "false") == 0)
1005ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project             {
1006ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project               e->d.policy.gid_uid_or_at_console = t;
1007ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project               e->d.policy.type = POLICY_CONSOLE;
1008ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project             }
1009ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           else
1010ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project             {
1011ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project               dbus_set_error (error, DBUS_ERROR_FAILED,
1012ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "Unknown value \"%s\" for at_console in message bus configuration file",
1013ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              at_console);
1014ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1015ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project               return FALSE;
1016ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project             }
1017ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1018ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
1019ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1020ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
1021ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1022ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1023ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1024ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1025ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "limit") == 0)
1026ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1027ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      Element *e;
1028ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *name;
1029ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1030ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL)
1031ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1032ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
1033ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1034ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1035ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1036ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!locate_attributes (parser, "limit",
1037ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_names,
1038ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_values,
1039ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              error,
1040ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "name", &name,
1041ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              NULL))
1042ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1043ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1044ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (name == NULL)
1045ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1046ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1047ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "<limit> element must have a \"name\" attribute");
1048ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1049ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1050ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1051ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      e->d.limit.name = _dbus_strdup (name);
1052ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (e->d.limit.name == NULL)
1053ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1054ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
1055ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1056ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1057ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1058ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1059ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1060ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "selinux") == 0)
1061ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1062ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error))
1063ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1064ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1065ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_SELINUX) == NULL)
1066ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1067ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
1068ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1069ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1070ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1071ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1072ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1073ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1074ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1075ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1076ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Element <%s> not allowed inside <%s> in configuration file",
1077ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name, "busconfig");
1078ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1079ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1080ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1081ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1082ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
1083ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectappend_rule_from_element (BusConfigParser   *parser,
1084ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          const char        *element_name,
1085ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          const char       **attribute_names,
1086ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          const char       **attribute_values,
1087ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          dbus_bool_t        allow,
1088ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          DBusError         *error)
1089ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1090ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_interface;
1091ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_member;
1092ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_error;
1093ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_destination;
1094ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_path;
1095ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_type;
1096ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_interface;
1097ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_member;
1098ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_error;
1099ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_sender;
1100ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_path;
1101ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_type;
1102ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *eavesdrop;
1103ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *send_requested_reply;
1104ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *receive_requested_reply;
1105ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *own;
1106ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *user;
1107ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *group;
1108ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1109ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusPolicyRule *rule;
1110ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1111ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!locate_attributes (parser, element_name,
1112ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          attribute_names,
1113ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          attribute_values,
1114ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          error,
1115ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_interface", &send_interface,
1116ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_member", &send_member,
1117ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_error", &send_error,
1118ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_destination", &send_destination,
1119ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_path", &send_path,
1120ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_type", &send_type,
1121ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_interface", &receive_interface,
1122ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_member", &receive_member,
1123ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_error", &receive_error,
1124ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_sender", &receive_sender,
1125ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_path", &receive_path,
1126ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_type", &receive_type,
1127ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "eavesdrop", &eavesdrop,
1128ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_requested_reply", &send_requested_reply,
1129ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_requested_reply", &receive_requested_reply,
1130ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "own", &own,
1131ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "user", &user,
1132ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "group", &group,
1133ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          NULL))
1134ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
1135ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1136ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!(send_interface || send_member || send_error || send_destination ||
1137ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_type || send_path ||
1138ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_interface || receive_member || receive_error || receive_sender ||
1139ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_type || receive_path || eavesdrop ||
1140ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_requested_reply || receive_requested_reply ||
1141ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        own || user || group))
1142ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1143ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1144ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Element <%s> must have one or more attributes",
1145ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name);
1146ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1147ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1148ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1149ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if ((send_member && (send_interface == NULL && send_path == NULL)) ||
1150ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      (receive_member && (receive_interface == NULL && receive_path == NULL)))
1151ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1152ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1153ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "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.",
1154ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name);
1155ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1156ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1157ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1158ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* Allowed combinations of elements are:
1159ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *
1160ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *   base, must be all send or all receive:
1161ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *     nothing
1162ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *     interface
1163ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *     interface + member
1164ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *     error
1165ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *
1166ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *   base send_ can combine with send_destination, send_path, send_type, send_requested_reply
1167ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *   base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop
1168ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *
1169ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *   user, group, own must occur alone
1170ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   *
1171ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   * Pretty sure the below stuff is broken, FIXME think about it more.
1172ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   */
1173ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1174ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (((send_interface && send_error) ||
1175ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && receive_interface) ||
1176ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && receive_member) ||
1177ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && receive_error) ||
1178ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && receive_sender) ||
1179ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && eavesdrop) ||
1180ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && receive_requested_reply) ||
1181ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && own) ||
1182ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && user) ||
1183ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_interface && group)) ||
1184ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1185ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((send_member && send_error) ||
1186ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && receive_interface) ||
1187ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && receive_member) ||
1188ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && receive_error) ||
1189ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && receive_sender) ||
1190ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && eavesdrop) ||
1191ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && receive_requested_reply) ||
1192ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && own) ||
1193ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && user) ||
1194ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_member && group)) ||
1195ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1196ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((send_error && receive_interface) ||
1197ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && receive_member) ||
1198ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && receive_error) ||
1199ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && receive_sender) ||
1200ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && eavesdrop) ||
1201ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && receive_requested_reply) ||
1202ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && own) ||
1203ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && user) ||
1204ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_error && group)) ||
1205ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1206ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((send_destination && receive_interface) ||
1207ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && receive_member) ||
1208ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && receive_error) ||
1209ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && receive_sender) ||
1210ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && eavesdrop) ||
1211ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && receive_requested_reply) ||
1212ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && own) ||
1213ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && user) ||
1214ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_destination && group)) ||
1215ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1216ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((send_type && receive_interface) ||
1217ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && receive_member) ||
1218ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && receive_error) ||
1219ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && receive_sender) ||
1220ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && eavesdrop) ||
1221ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && receive_requested_reply) ||
1222ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && own) ||
1223ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && user) ||
1224ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_type && group)) ||
1225ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1226ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((send_path && receive_interface) ||
1227ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && receive_member) ||
1228ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && receive_error) ||
1229ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && receive_sender) ||
1230ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && eavesdrop) ||
1231ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && receive_requested_reply) ||
1232ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && own) ||
1233ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && user) ||
1234ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_path && group)) ||
1235ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1236ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((send_requested_reply && receive_interface) ||
1237ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && receive_member) ||
1238ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && receive_error) ||
1239ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && receive_sender) ||
1240ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && eavesdrop) ||
1241ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && receive_requested_reply) ||
1242ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && own) ||
1243ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && user) ||
1244ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (send_requested_reply && group)) ||
1245ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1246ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((receive_interface && receive_error) ||
1247ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_interface && own) ||
1248ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_interface && user) ||
1249ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_interface && group)) ||
1250ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1251ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((receive_member && receive_error) ||
1252ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_member && own) ||
1253ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_member && user) ||
1254ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_member && group)) ||
1255ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1256ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((receive_error && own) ||
1257ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_error && user) ||
1258ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_error && group)) ||
1259ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1260ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((eavesdrop && own) ||
1261ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (eavesdrop && user) ||
1262ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (eavesdrop && group)) ||
1263ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1264ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((receive_requested_reply && own) ||
1265ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_requested_reply && user) ||
1266ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (receive_requested_reply && group)) ||
1267ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1268ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((own && user) ||
1269ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       (own && group)) ||
1270ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1271ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ((user && group)))
1272ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1273ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1274ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Invalid combination of attributes on element <%s>",
1275ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name);
1276ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1277ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1278ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1279ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  rule = NULL;
1280ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1281ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* In BusPolicyRule, NULL represents wildcard.
1282ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   * In the config file, '*' represents it.
1283ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   */
1284ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
1285ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1286ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (send_interface || send_member || send_error || send_destination ||
1287ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      send_path || send_type || send_requested_reply)
1288ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1289ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      int message_type;
1290ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1291ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (send_interface))
1292ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_interface = NULL;
1293ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (send_member))
1294ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_member = NULL;
1295ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (send_error))
1296ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_error = NULL;
1297ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (send_destination))
1298ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_destination = NULL;
1299ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (send_path))
1300ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_path = NULL;
1301ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (send_type))
1302ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        send_type = NULL;
1303ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1304ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      message_type = DBUS_MESSAGE_TYPE_INVALID;
1305ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_type != NULL)
1306ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1307ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          message_type = dbus_message_type_from_string (send_type);
1308ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1309ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1310ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
1311ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "Bad message type \"%s\"",
1312ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              send_type);
1313ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
1314ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1315ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1316ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1317ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_requested_reply &&
1318ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          !(strcmp (send_requested_reply, "true") == 0 ||
1319ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            strcmp (send_requested_reply, "false") == 0))
1320ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1321ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1322ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "Bad value \"%s\" for %s attribute, must be true or false",
1323ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "send_requested_reply", send_requested_reply);
1324ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1325ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1326ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1327ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow);
1328ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (rule == NULL)
1329ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1330ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1331ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_requested_reply)
1332ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0);
1333ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1334ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.send.message_type = message_type;
1335ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.send.path = _dbus_strdup (send_path);
1336ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.send.interface = _dbus_strdup (send_interface);
1337ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.send.member = _dbus_strdup (send_member);
1338ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.send.error = _dbus_strdup (send_error);
1339ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.send.destination = _dbus_strdup (send_destination);
1340ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_path && rule->d.send.path == NULL)
1341ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1342ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_interface && rule->d.send.interface == NULL)
1343ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1344ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_member && rule->d.send.member == NULL)
1345ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1346ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_error && rule->d.send.error == NULL)
1347ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1348ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (send_destination && rule->d.send.destination == NULL)
1349ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1350ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1351ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (receive_interface || receive_member || receive_error || receive_sender ||
1352ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           receive_path || receive_type || eavesdrop || receive_requested_reply)
1353ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1354ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      int message_type;
1355ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1356ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (receive_interface))
1357ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_interface = NULL;
1358ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (receive_member))
1359ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_member = NULL;
1360ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (receive_error))
1361ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_error = NULL;
1362ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (receive_sender))
1363ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_sender = NULL;
1364ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (receive_path))
1365ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_path = NULL;
1366ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (receive_type))
1367ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        receive_type = NULL;
1368ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1369ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      message_type = DBUS_MESSAGE_TYPE_INVALID;
1370ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_type != NULL)
1371ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1372ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          message_type = dbus_message_type_from_string (receive_type);
1373ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1374ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1375ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
1376ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "Bad message type \"%s\"",
1377ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              receive_type);
1378ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
1379ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1380ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1381ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1382ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1383ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (eavesdrop &&
1384ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          !(strcmp (eavesdrop, "true") == 0 ||
1385ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            strcmp (eavesdrop, "false") == 0))
1386ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1387ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1388ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "Bad value \"%s\" for %s attribute, must be true or false",
1389ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "eavesdrop", eavesdrop);
1390ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1391ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1392ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1393ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_requested_reply &&
1394ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          !(strcmp (receive_requested_reply, "true") == 0 ||
1395ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            strcmp (receive_requested_reply, "false") == 0))
1396ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1397ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1398ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "Bad value \"%s\" for %s attribute, must be true or false",
1399ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "receive_requested_reply", receive_requested_reply);
1400ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1401ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1402ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1403ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow);
1404ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (rule == NULL)
1405ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1406ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1407ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (eavesdrop)
1408ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1409ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1410ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_requested_reply)
1411ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        rule->d.receive.requested_reply = (strcmp (receive_requested_reply, "true") == 0);
1412ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1413ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.receive.message_type = message_type;
1414ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.receive.path = _dbus_strdup (receive_path);
1415ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.receive.interface = _dbus_strdup (receive_interface);
1416ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.receive.member = _dbus_strdup (receive_member);
1417ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.receive.error = _dbus_strdup (receive_error);
1418ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.receive.origin = _dbus_strdup (receive_sender);
1419ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1420ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_path && rule->d.receive.path == NULL)
1421ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1422ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_interface && rule->d.receive.interface == NULL)
1423ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1424ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_member && rule->d.receive.member == NULL)
1425ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1426ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_error && rule->d.receive.error == NULL)
1427ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1428ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (receive_sender && rule->d.receive.origin == NULL)
1429ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1430ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1431ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (own)
1432ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1433ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
1434ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (rule == NULL)
1435ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1436ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1437ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (own))
1438ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        own = NULL;
1439ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1440ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule->d.own.service_name = _dbus_strdup (own);
1441ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (own && rule->d.own.service_name == NULL)
1442ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto nomem;
1443ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1444ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (user)
1445ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1446ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (user))
1447ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1448ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1449ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (rule == NULL)
1450ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1451ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1452ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          rule->d.user.uid = DBUS_UID_UNSET;
1453ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1454ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
1455ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1456ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          DBusString username;
1457ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_uid_t uid;
1458ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1459ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_init_const (&username, user);
1460ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1461ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (_dbus_get_user_id (&username, &uid))
1462ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1463ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1464ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              if (rule == NULL)
1465ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                goto nomem;
1466ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1467ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              rule->d.user.uid = uid;
1468ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1469ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
1470ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1471ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              _dbus_warn ("Unknown username \"%s\" on element <%s>\n",
1472ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          user, element_name);
1473ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1474ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1475ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1476ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (group)
1477ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1478ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (IS_WILDCARD (group))
1479ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1480ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1481ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (rule == NULL)
1482ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1483ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1484ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          rule->d.group.gid = DBUS_GID_UNSET;
1485ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1486ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
1487ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1488ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          DBusString groupname;
1489ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_gid_t gid;
1490ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1491ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_init_const (&groupname, group);
1492ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1493ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (_dbus_get_user_id (&groupname, &gid))
1494ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1495ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1496ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              if (rule == NULL)
1497ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                goto nomem;
1498ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1499ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              rule->d.group.gid = gid;
1500ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1501ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          else
1502ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1503ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              _dbus_warn ("Unknown group \"%s\" on element <%s>\n",
1504ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          group, element_name);
1505ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1506ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1507ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1508ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1509ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>");
1510ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1511ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (rule != NULL)
1512ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1513ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      Element *pe;
1514ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1515ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      pe = peek_element (parser);
1516ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert (pe != NULL);
1517ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert (pe->type == ELEMENT_POLICY);
1518ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1519ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      switch (pe->d.policy.type)
1520ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1521ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        case POLICY_IGNORED:
1522ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          /* drop the rule on the floor */
1523ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          break;
1524ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1525ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        case POLICY_DEFAULT:
1526ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!bus_policy_append_default_rule (parser->policy, rule))
1527ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1528ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          break;
1529ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        case POLICY_MANDATORY:
1530ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!bus_policy_append_mandatory_rule (parser->policy, rule))
1531ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1532ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          break;
1533ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        case POLICY_USER:
1534ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1535ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1536ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
1537ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "<%s> rule cannot be per-user because it has bus-global semantics",
1538ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              element_name);
1539ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              goto failed;
1540ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1541ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1542ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1543ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                            rule))
1544ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1545ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          break;
1546ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        case POLICY_GROUP:
1547ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1548ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1549ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_set_error (error, DBUS_ERROR_FAILED,
1550ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "<%s> rule cannot be per-group because it has bus-global semantics",
1551ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              element_name);
1552ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              goto failed;
1553ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1554ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1555ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1556ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                             rule))
1557ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1558ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          break;
1559ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1560ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1561ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        case POLICY_CONSOLE:
1562ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1563ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                             rule))
1564ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
1565ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          break;
1566ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1567ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1568ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      bus_policy_rule_unref (rule);
1569ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      rule = NULL;
1570ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1571ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1572ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
1573ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1574ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project nomem:
1575ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BUS_SET_OOM (error);
1576ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project failed:
1577ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (rule)
1578ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    bus_policy_rule_unref (rule);
1579ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return FALSE;
1580ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1581ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1582ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
1583ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstart_policy_child (BusConfigParser   *parser,
1584ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                    const char        *element_name,
1585ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                    const char       **attribute_names,
1586ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                    const char       **attribute_values,
1587ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                    DBusError         *error)
1588ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1589ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (strcmp (element_name, "allow") == 0)
1590ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1591ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!append_rule_from_element (parser, element_name,
1592ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                     attribute_names, attribute_values,
1593ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                     TRUE, error))
1594ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1595ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1596ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_ALLOW) == NULL)
1597ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1598ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
1599ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1600ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1601ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1602ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1603ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1604ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (element_name, "deny") == 0)
1605ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1606ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!append_rule_from_element (parser, element_name,
1607ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                     attribute_names, attribute_values,
1608ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                     FALSE, error))
1609ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1610ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1611ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_DENY) == NULL)
1612ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1613ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
1614ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1615ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1616ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1617ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1618ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1619ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1620ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1621ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1622ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Element <%s> not allowed inside <%s> in configuration file",
1623ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name, "policy");
1624ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1625ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1626ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1627ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1628ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
1629ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstart_selinux_child (BusConfigParser   *parser,
1630ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     const char        *element_name,
1631ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     const char       **attribute_names,
1632ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     const char       **attribute_values,
1633ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     DBusError         *error)
1634ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1635ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *own_copy;
1636ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *context_copy;
1637ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1638ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  own_copy = NULL;
1639ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  context_copy = NULL;
1640ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1641ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (strcmp (element_name, "associate") == 0)
1642ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1643ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *own;
1644ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      const char *context;
1645ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1646ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!locate_attributes (parser, "associate",
1647ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_names,
1648ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              attribute_values,
1649ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              error,
1650ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "own", &own,
1651ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              "context", &context,
1652ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              NULL))
1653ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1654ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1655ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (push_element (parser, ELEMENT_ASSOCIATE) == NULL)
1656ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1657ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
1658ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1659ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1660ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1661ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (own == NULL || context == NULL)
1662ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1663ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1664ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "Element <associate> must have attributes own=\"<servicename>\" and context=\"<selinux context>\"");
1665ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1666ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1667ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1668ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      own_copy = _dbus_strdup (own);
1669ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (own_copy == NULL)
1670ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto oom;
1671ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      context_copy = _dbus_strdup (context);
1672ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (context_copy == NULL)
1673ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto oom;
1674ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1675ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_hash_table_insert_string (parser->service_context_table,
1676ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project					   own_copy, context_copy))
1677ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        goto oom;
1678ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1679ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1680ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1681ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1682ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1683ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1684ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Element <%s> not allowed inside <%s> in configuration file",
1685ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name, "selinux");
1686ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1687ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1688ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1689ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project oom:
1690ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (own_copy)
1691ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    dbus_free (own_copy);
1692ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1693ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (context_copy)
1694ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    dbus_free (context_copy);
1695ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1696ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BUS_SET_OOM (error);
1697ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return FALSE;
1698ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1699ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1700ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
1701ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_start_element (BusConfigParser   *parser,
1702ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 const char        *element_name,
1703ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 const char       **attribute_names,
1704ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 const char       **attribute_values,
1705ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 DBusError         *error)
1706ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1707ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ElementType t;
1708ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1709ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1710ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1711ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* printf ("START: %s\n", element_name); */
1712ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1713ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  t = top_element_type (parser);
1714ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1715ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (t == ELEMENT_NONE)
1716ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1717ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (strcmp (element_name, "busconfig") == 0)
1718ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1719ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error))
1720ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            return FALSE;
1721ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1722ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
1723ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
1724ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              BUS_SET_OOM (error);
1725ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              return FALSE;
1726ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
1727ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1728ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return TRUE;
1729ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1730ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
1731ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1732ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1733ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "Unknown element <%s> at root of configuration file",
1734ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          element_name);
1735ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1736ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1737ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1738ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (t == ELEMENT_BUSCONFIG)
1739ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1740ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return start_busconfig_child (parser, element_name,
1741ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                    attribute_names, attribute_values,
1742ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                    error);
1743ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1744ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (t == ELEMENT_POLICY)
1745ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1746ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return start_policy_child (parser, element_name,
1747ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 attribute_names, attribute_values,
1748ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                 error);
1749ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1750ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (t == ELEMENT_SELINUX)
1751ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1752ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return start_selinux_child (parser, element_name,
1753ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                  attribute_names, attribute_values,
1754ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                  error);
1755ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1756ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1757ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1758ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1759ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Element <%s> is not allowed in this context",
1760ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name);
1761ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1762ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1763ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1764ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1765ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
1766ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectset_limit (BusConfigParser *parser,
1767ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           const char      *name,
1768ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           long             value,
1769ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project           DBusError       *error)
1770ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1771ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t must_be_positive;
1772ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t must_be_int;
1773ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1774ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  must_be_int = FALSE;
1775ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  must_be_positive = FALSE;
1776ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1777ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (strcmp (name, "max_incoming_bytes") == 0)
1778ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1779ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1780ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_incoming_bytes = value;
1781ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1782ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_outgoing_bytes") == 0)
1783ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1784ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1785ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_outgoing_bytes = value;
1786ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1787ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_message_size") == 0)
1788ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1789ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1790ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_message_size = value;
1791ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1792ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "service_start_timeout") == 0)
1793ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1794ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1795ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1796ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.activation_timeout = value;
1797ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1798ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "auth_timeout") == 0)
1799ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1800ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1801ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1802ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.auth_timeout = value;
1803ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1804ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "reply_timeout") == 0)
1805ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1806ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1807ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1808ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.reply_timeout = value;
1809ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1810ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_completed_connections") == 0)
1811ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1812ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1813ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1814ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_completed_connections = value;
1815ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1816ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_incomplete_connections") == 0)
1817ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1818ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1819ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1820ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_incomplete_connections = value;
1821ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1822ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_connections_per_user") == 0)
1823ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1824ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1825ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1826ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_connections_per_user = value;
1827ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1828ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_pending_service_starts") == 0)
1829ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1830ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1831ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1832ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_pending_activations = value;
1833ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1834ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_names_per_connection") == 0)
1835ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1836ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1837ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1838ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_services_per_connection = value;
1839ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1840ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_match_rules_per_connection") == 0)
1841ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1842ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1843ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1844ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_match_rules_per_connection = value;
1845ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1846ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (strcmp (name, "max_replies_per_connection") == 0)
1847ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1848ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_positive = TRUE;
1849ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      must_be_int = TRUE;
1850ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits.max_replies_per_connection = value;
1851ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1852ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1853ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1854ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1855ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "There is no limit called \"%s\"\n",
1856ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      name);
1857ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1858ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1859ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1860ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (must_be_positive && value < 0)
1861ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1862ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1863ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "<limit name=\"%s\"> must be a positive number\n",
1864ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      name);
1865ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1866ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1867ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1868ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (must_be_int &&
1869ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      (value < _DBUS_INT_MIN || value > _DBUS_INT_MAX))
1870ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1871ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1872ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "<limit name=\"%s\"> value is too large\n",
1873ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      name);
1874ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1875ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1876ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1877ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
1878ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1879ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1880ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
1881ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_end_element (BusConfigParser   *parser,
1882ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                               const char        *element_name,
1883ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                               DBusError         *error)
1884ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1885ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ElementType t;
1886ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *n;
1887ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Element *e;
1888ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1889ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1890ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1891ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* printf ("END: %s\n", element_name); */
1892ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1893ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  t = top_element_type (parser);
1894ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1895ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (t == ELEMENT_NONE)
1896ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1897ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* should probably be an assertion failure but
1898ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * being paranoid about XML parsers
1899ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       */
1900ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1901ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "XML parser ended element with no element on the stack");
1902ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1903ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1904ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1905ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  n = element_type_to_name (t);
1906ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (n != NULL);
1907ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (strcmp (n, element_name) != 0)
1908ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1909ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* should probably be an assertion failure but
1910ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * being paranoid about XML parsers
1911ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       */
1912ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
1913ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "XML element <%s> ended but topmost element on the stack was <%s>",
1914ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_name, n);
1915ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
1916ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1917ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1918ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e = peek_element (parser);
1919ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (e != NULL);
1920ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1921ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  switch (e->type)
1922ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1923ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_NONE:
1924ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert_not_reached ("element in stack has no type");
1925ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
1926ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1927ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDE:
1928ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_USER:
1929ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_TYPE:
1930ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LISTEN:
1931ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_PIDFILE:
1932ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_AUTH:
1933ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_SERVICEDIR:
1934ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDEDIR:
1935ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LIMIT:
1936ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!e->had_content)
1937ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1938ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
1939ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "XML element <%s> was expected to have content inside it",
1940ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          element_type_to_name (e->type));
1941ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
1942ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1943ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1944ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (e->type == ELEMENT_LIMIT)
1945ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
1946ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!set_limit (parser, e->d.limit.name, e->d.limit.value,
1947ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          error))
1948ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            return FALSE;
1949ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
1950ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
1951ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1952ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_BUSCONFIG:
1953ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_POLICY:
1954ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_ALLOW:
1955ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_DENY:
1956ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_FORK:
1957ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_SELINUX:
1958ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_ASSOCIATE:
1959ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
1960ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
1961ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1962ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1963ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  pop_element (parser);
1964ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1965ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
1966ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1967ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1968ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
1969ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectall_whitespace (const DBusString *str)
1970ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1971ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  int i;
1972ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1973ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_skip_white (str, 0, &i);
1974ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1975ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return i == _dbus_string_get_length (str);
1976ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1977ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1978ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
1979ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectmake_full_path (const DBusString *basedir,
1980ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                const DBusString *filename,
1981ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                DBusString       *full_path)
1982ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
1983ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (_dbus_path_is_absolute (filename))
1984ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1985ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return _dbus_string_copy (filename, 0, full_path, 0);
1986ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1987ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
1988ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
1989ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_copy (basedir, 0, full_path, 0))
1990ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1991ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1992ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_concat_dir_and_file (full_path, filename))
1993ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return FALSE;
1994ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1995ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
1996ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
1997ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
1998ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
1999ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2000ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectinclude_file (BusConfigParser   *parser,
2001ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              const DBusString  *filename,
2002ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              dbus_bool_t        ignore_missing,
2003ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              DBusError         *error)
2004ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2005ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* FIXME good test case for this would load each config file in the
2006ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   * test suite both alone, and as an include, and check
2007ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   * that the result is the same
2008ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project   */
2009ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusConfigParser *included;
2010ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const char *filename_str;
2011ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusError tmp_error;
2012ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2013ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_error_init (&tmp_error);
2014ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2015ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  filename_str = _dbus_string_get_const_data (filename);
2016ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2017ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* Check to make sure this file hasn't already been included. */
2018ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (seen_include (parser, filename))
2019ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2020ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
2021ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		      "Circular inclusion of file '%s'",
2022ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		      filename_str);
2023ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2024ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2025ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2026ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (! _dbus_list_append (&parser->included_files, (void *) filename_str))
2027ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2028ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      BUS_SET_OOM (error);
2029ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2030ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2031ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2032ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* Since parser is passed in as the parent, included
2033ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     inherits parser's limits. */
2034ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  included = bus_config_load (filename, FALSE, parser, &tmp_error);
2035ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2036ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_list_pop_last (&parser->included_files);
2037ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2038ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (included == NULL)
2039ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2040ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
2041ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2042ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) &&
2043ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          ignore_missing)
2044ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2045ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_error_free (&tmp_error);
2046ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return TRUE;
2047ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2048ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
2049ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2050ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_move_error (&tmp_error, error);
2051ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
2052ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2053ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2054ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
2055ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2056ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
2057ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2058ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!merge_included (parser, included, error))
2059ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2060ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          bus_config_parser_unref (included);
2061ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
2062ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2063ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2064ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Copy included's limits back to parser. */
2065ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser->limits = included->limits;
2066ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2067ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      bus_config_parser_unref (included);
2068ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
2069ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2070ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2071ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2072ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2073ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectinclude_dir (BusConfigParser   *parser,
2074ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project             const DBusString  *dirname,
2075ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project             DBusError         *error)
2076ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2077ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString filename;
2078ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t retval;
2079ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusError tmp_error;
2080ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusDirIter *dir;
2081ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  char *s;
2082ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2083ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&filename))
2084ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2085ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      BUS_SET_OOM (error);
2086ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2087ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2088ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2089ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = FALSE;
2090ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2091ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = _dbus_directory_open (dirname, error);
2092ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2093ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir == NULL)
2094ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    goto failed;
2095ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2096ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_error_init (&tmp_error);
2097ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
2098ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2099ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusString full_path;
2100ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2101ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_init (&full_path))
2102ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2103ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
2104ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto failed;
2105ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2106ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2107ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_copy (dirname, 0, &full_path, 0))
2108ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2109ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
2110ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_free (&full_path);
2111ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto failed;
2112ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2113ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2114ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_concat_dir_and_file (&full_path, &filename))
2115ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2116ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          BUS_SET_OOM (error);
2117ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_free (&full_path);
2118ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto failed;
2119ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2120ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2121ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (_dbus_string_ends_with_c_str (&full_path, ".conf"))
2122ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2123ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          if (!include_file (parser, &full_path, TRUE, error))
2124ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            {
2125ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              _dbus_string_free (&full_path);
2126ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              goto failed;
2127ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            }
2128ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2129ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2130ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_free (&full_path);
2131ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2132ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2133ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dbus_error_is_set (&tmp_error))
2134ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2135ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_move_error (&tmp_error, error);
2136ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto failed;
2137ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2138ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2139ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2140ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_copy_data (dirname, &s))
2141ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2142ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      BUS_SET_OOM (error);
2143ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto failed;
2144ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2145ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2146ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_list_append (&parser->conf_dirs, s))
2147ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2148ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (s);
2149ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      BUS_SET_OOM (error);
2150ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto failed;
2151ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2152ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2153ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = TRUE;
2154ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2155ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project failed:
2156ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&filename);
2157ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2158ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir)
2159ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_directory_close (dir);
2160ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2161ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return retval;
2162ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2163ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2164ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
2165ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_content (BusConfigParser   *parser,
2166ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                           const DBusString  *content,
2167ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                           DBusError         *error)
2168ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2169ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Element *e;
2170ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2171ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2172ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2173ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#if 0
2174ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  {
2175ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    const char *c_str;
2176ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2177ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_string_get_const_data (content, &c_str);
2178ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2179ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str);
2180ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  }
2181ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#endif
2182ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2183ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  e = peek_element (parser);
2184ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (e == NULL)
2185ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2186ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
2187ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Text content outside of any XML element in configuration file");
2188ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2189ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2190ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (e->had_content)
2191ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2192ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert_not_reached ("Element had multiple content blocks");
2193ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2194ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2195ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2196ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  switch (top_element_type (parser))
2197ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2198ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_NONE:
2199ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_assert_not_reached ("element at top of stack has no type");
2200ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2201ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2202ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_BUSCONFIG:
2203ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_POLICY:
2204ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_ALLOW:
2205ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_DENY:
2206ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_FORK:
2207ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2208ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_SELINUX:
2209ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_ASSOCIATE:
2210ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (all_whitespace (content))
2211ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        return TRUE;
2212ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
2213ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2214ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_set_error (error, DBUS_ERROR_FAILED,
2215ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          "No text content expected inside XML element %s in configuration file",
2216ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          element_type_to_name (top_element_type (parser)));
2217ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
2218ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2219ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2220ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_PIDFILE:
2221ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2222ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        char *s;
2223ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2224ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2225ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2226ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_copy_data (content, &s))
2227ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2228ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2229ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        dbus_free (parser->pidfile);
2230ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        parser->pidfile = s;
2231ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2232ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2233ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2234ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDE:
2235ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2236ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        DBusString full_path, selinux_policy_root;
2237ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2238ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2239ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2240ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	if (e->d.include.if_selinux_enabled
2241ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	    && !bus_selinux_enabled ())
2242ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  break;
2243ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2244ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_init (&full_path))
2245ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2246ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2247ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (e->d.include.selinux_root_relative)
2248ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  {
2249ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            if (!bus_selinux_get_policy_root ())
2250ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	      {
2251ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		dbus_set_error (error, DBUS_ERROR_FAILED,
2252ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project				"Could not determine SELinux policy root for relative inclusion");
2253ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		_dbus_string_free (&full_path);
2254ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		return FALSE;
2255ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	      }
2256ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_init_const (&selinux_policy_root,
2257ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                     bus_selinux_get_policy_root ());
2258ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            if (!make_full_path (&selinux_policy_root, content, &full_path))
2259ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              {
2260ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                _dbus_string_free (&full_path);
2261ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                goto nomem;
2262ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              }
2263ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2264ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        else if (!make_full_path (&parser->basedir, content, &full_path))
2265ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2266ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2267ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2268ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2269ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2270ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!include_file (parser, &full_path,
2271ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                           e->d.include.ignore_missing, error))
2272ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2273ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2274ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            return FALSE;
2275ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2276ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2277ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_string_free (&full_path);
2278ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2279ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2280ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2281ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDEDIR:
2282ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2283ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        DBusString full_path;
2284ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2285ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2286ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2287ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_init (&full_path))
2288ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2289ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2290ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!make_full_path (&parser->basedir, content, &full_path))
2291ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2292ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2293ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2294ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2295ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2296ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!include_dir (parser, &full_path, error))
2297ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2298ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2299ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            return FALSE;
2300ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2301ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2302ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_string_free (&full_path);
2303ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2304ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2305ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2306ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_USER:
2307ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2308ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        char *s;
2309ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2310ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2311ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2312ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_copy_data (content, &s))
2313ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2314ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2315ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        dbus_free (parser->user);
2316ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        parser->user = s;
2317ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2318ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2319ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2320ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_TYPE:
2321ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2322ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        char *s;
2323ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2324ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2325ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2326ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_copy_data (content, &s))
2327ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2328ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2329ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        dbus_free (parser->bus_type);
2330ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        parser->bus_type = s;
2331ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2332ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2333ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2334ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LISTEN:
2335ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2336ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        char *s;
2337ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2338ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2339ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2340ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_copy_data (content, &s))
2341ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2342ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2343ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_list_append (&parser->listen_on,
2344ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                s))
2345ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2346ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            dbus_free (s);
2347ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2348ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2349ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2350ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2351ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2352ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_AUTH:
2353ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2354ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        char *s;
2355ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2356ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2357ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2358ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_copy_data (content, &s))
2359ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2360ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2361ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_list_append (&parser->mechanisms,
2362ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                                s))
2363ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2364ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            dbus_free (s);
2365ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2366ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2367ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2368ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2369ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2370ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_SERVICEDIR:
2371ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2372ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        char *s;
2373ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        DBusString full_path;
2374ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2375ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2376ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2377ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_init (&full_path))
2378ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto nomem;
2379ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2380ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!make_full_path (&parser->basedir, content, &full_path))
2381ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2382ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2383ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2384ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2385ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2386ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_copy_data (&full_path, &s))
2387ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2388ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2389ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2390ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2391ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2392ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!service_dirs_append_unique_or_free (&parser->service_dirs, s))
2393ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2394ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            _dbus_string_free (&full_path);
2395ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            dbus_free (s);
2396ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            goto nomem;
2397ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2398ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2399ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_string_free (&full_path);
2400ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2401ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2402ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2403ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LIMIT:
2404ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      {
2405ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        long val;
2406ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2407ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->had_content = TRUE;
2408ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2409ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        val = 0;
2410ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        if (!_dbus_string_parse_int (content, 0, &val, NULL))
2411ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          {
2412ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            dbus_set_error (error, DBUS_ERROR_FAILED,
2413ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                            "<limit name=\"%s\"> element has invalid value (could not parse as integer)",
2414ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                            e->d.limit.name);
2415ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project            return FALSE;
2416ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          }
2417ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2418ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        e->d.limit.value = val;
2419ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2420ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_verbose ("Loaded value %ld for limit %s\n",
2421ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       e->d.limit.value,
2422ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                       e->d.limit.name);
2423ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      }
2424ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2425ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2426ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2427ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2428ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
2429ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2430ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project nomem:
2431ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BUS_SET_OOM (error);
2432ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return FALSE;
2433ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2434ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2435ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
2436ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_finished (BusConfigParser   *parser,
2437ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                            DBusError         *error)
2438ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2439ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2440ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2441ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (parser->stack != NULL)
2442ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2443ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
2444ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Element <%s> was not closed in configuration file",
2445ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      element_type_to_name (top_element_type (parser)));
2446ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2447ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2448ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2449ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2450ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (parser->is_toplevel && parser->listen_on == NULL)
2451ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2452ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_set_error (error, DBUS_ERROR_FAILED,
2453ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      "Configuration file needs one or more <listen> elements giving addresses");
2454ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
2455ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2456ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2457ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
2458ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2459ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2460ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectconst char*
2461ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_user (BusConfigParser *parser)
2462ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2463ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return parser->user;
2464ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2465ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2466ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectconst char*
2467ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_type (BusConfigParser *parser)
2468ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2469ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return parser->bus_type;
2470ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2471ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2472ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectDBusList**
2473ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_addresses (BusConfigParser *parser)
2474ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2475ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return &parser->listen_on;
2476ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2477ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2478ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectDBusList**
2479ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_mechanisms (BusConfigParser *parser)
2480ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2481ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return &parser->mechanisms;
2482ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2483ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2484ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectDBusList**
2485ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_service_dirs (BusConfigParser *parser)
2486ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2487ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return &parser->service_dirs;
2488ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2489ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2490ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectDBusList**
2491ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_conf_dirs (BusConfigParser *parser)
2492ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2493ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return &parser->conf_dirs;
2494ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2495ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2496ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
2497ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_fork (BusConfigParser   *parser)
2498ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2499ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return parser->fork;
2500ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2501ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2502ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectconst char *
2503ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_pidfile (BusConfigParser   *parser)
2504ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2505ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return parser->pidfile;
2506ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2507ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2508ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectBusPolicy*
2509ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_steal_policy (BusConfigParser *parser)
2510ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2511ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusPolicy *policy;
2512ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2513ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */
2514ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2515ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  policy = parser->policy;
2516ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2517ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser->policy = NULL;
2518ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2519ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return policy;
2520ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2521ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2522ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project/* Overwrite any limits that were set in the configuration file */
2523ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectvoid
2524ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_get_limits (BusConfigParser *parser,
2525ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                              BusLimits       *limits)
2526ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2527ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  *limits = parser->limits;
2528ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2529ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2530ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source ProjectDBusHashTable*
2531ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_steal_service_context_table (BusConfigParser *parser)
2532ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2533ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusHashTable *table;
2534ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2535ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_assert (parser->service_context_table != NULL); /* can only steal once */
2536ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2537ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  table = parser->service_context_table;
2538ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2539ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser->service_context_table = NULL;
2540ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2541ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return table;
2542ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2543ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2544ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#ifdef DBUS_BUILD_TESTS
2545ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#include <stdio.h>
2546ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2547ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttypedef enum
2548ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2549ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  VALID,
2550ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  INVALID,
2551ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  UNKNOWN
2552ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project} Validity;
2553ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2554ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2555ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdo_load (const DBusString *full_path,
2556ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         Validity          validity,
2557ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         dbus_bool_t       oom_possible)
2558ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2559ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusConfigParser *parser;
2560ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusError error;
2561ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2562ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_error_init (&error);
2563ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2564ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser = bus_config_load (full_path, TRUE, NULL, &error);
2565ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (parser == NULL)
2566ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2567ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _DBUS_ASSERT_ERROR_IS_SET (&error);
2568ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2569ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (oom_possible &&
2570ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2571ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2572ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_verbose ("Failed to load valid file due to OOM\n");
2573ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_error_free (&error);
2574ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return TRUE;
2575ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2576ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else if (validity == VALID)
2577ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2578ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_warn ("Failed to load valid file but still had memory: %s\n",
2579ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      error.message);
2580ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2581ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_error_free (&error);
2582ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
2583ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2584ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
2585ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2586ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          dbus_error_free (&error);
2587ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return TRUE;
2588ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2589ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2590ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
2591ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2592ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _DBUS_ASSERT_ERROR_IS_CLEAR (&error);
2593ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2594ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      bus_config_parser_unref (parser);
2595ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2596ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (validity == INVALID)
2597ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2598ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_warn ("Accepted invalid file\n");
2599ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
2600ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2601ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2602ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
2603ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2604ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2605ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2606ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttypedef struct
2607ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2608ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  const DBusString *full_path;
2609ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  Validity          validity;
2610ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project} LoaderOomData;
2611ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2612ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2613ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectcheck_loader_oom_func (void *data)
2614ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2615ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  LoaderOomData *d = data;
2616ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2617ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return do_load (d->full_path, d->validity, TRUE);
2618ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2619ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2620ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2621ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectprocess_test_valid_subdir (const DBusString *test_base_dir,
2622ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                           const char       *subdir,
2623ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                           Validity          validity)
2624ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2625ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString test_directory;
2626ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString filename;
2627ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusDirIter *dir;
2628ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t retval;
2629ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusError error;
2630ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2631ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = FALSE;
2632ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = NULL;
2633ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2634ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&test_directory))
2635ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("didn't allocate test_directory\n");
2636ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2637ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_init_const (&filename, subdir);
2638ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2639ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_copy (test_base_dir, 0,
2640ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                          &test_directory, 0))
2641ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
2642ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2643ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_concat_dir_and_file (&test_directory, &filename))
2644ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't allocate full path");
2645ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2646ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&filename);
2647ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&filename))
2648ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("didn't allocate filename string\n");
2649ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2650ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_error_init (&error);
2651ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = _dbus_directory_open (&test_directory, &error);
2652ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir == NULL)
2653ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2654ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_warn ("Could not open %s: %s\n",
2655ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  _dbus_string_get_const_data (&test_directory),
2656ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  error.message);
2657ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_error_free (&error);
2658ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto failed;
2659ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2660ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2661ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (validity == VALID)
2662ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    printf ("Testing valid files:\n");
2663ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else if (validity == INVALID)
2664ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    printf ("Testing invalid files:\n");
2665ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
2666ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    printf ("Testing unknown files:\n");
2667ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2668ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project next:
2669ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (_dbus_directory_get_next_file (dir, &filename, &error))
2670ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2671ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusString full_path;
2672ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      LoaderOomData d;
2673ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2674ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_init (&full_path))
2675ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't init string");
2676ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2677ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
2678ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't copy dir to full_path");
2679ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2680ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_concat_dir_and_file (&full_path, &filename))
2681ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't concat file to dir");
2682ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2683ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2684ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2685ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_verbose ("Skipping non-.conf file %s\n",
2686ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                         _dbus_string_get_const_data (&filename));
2687ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_free (&full_path);
2688ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto next;
2689ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2690ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2691ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      printf ("    %s\n", _dbus_string_get_const_data (&filename));
2692ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2693ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_verbose (" expecting %s\n",
2694ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     validity == VALID ? "valid" :
2695ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                     (validity == INVALID ? "invalid" :
2696ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      (validity == UNKNOWN ? "unknown" : "???")));
2697ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2698ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      d.full_path = &full_path;
2699ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      d.validity = validity;
2700ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2701ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* FIXME hackaround for an expat problem, see
2702ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747
2703ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       * http://freedesktop.org/pipermail/dbus/2004-May/001153.html
2704ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project       */
2705ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */
2706ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!check_loader_oom_func (&d))
2707ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("test failed");
2708ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2709ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_free (&full_path);
2710ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2711ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2712ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dbus_error_is_set (&error))
2713ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2714ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_warn ("Could not get next file in %s: %s\n",
2715ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  _dbus_string_get_const_data (&test_directory),
2716ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  error.message);
2717ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_error_free (&error);
2718ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto failed;
2719ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2720ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2721ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = TRUE;
2722ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2723ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project failed:
2724ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2725ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir)
2726ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_directory_close (dir);
2727ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&test_directory);
2728ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&filename);
2729ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2730ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return retval;
2731ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2732ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2733ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2734ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbools_equal (dbus_bool_t a,
2735ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	     dbus_bool_t b)
2736ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2737ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return a ? b : !b;
2738ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2739ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2740ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2741ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstrings_equal_or_both_null (const char *a,
2742ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                            const char *b)
2743ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2744ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (a == NULL || b == NULL)
2745ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return a == b;
2746ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  else
2747ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return !strcmp (a, b);
2748ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2749ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2750ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2751ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectelements_equal (const Element *a,
2752ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		const Element *b)
2753ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2754ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (a->type != b->type)
2755ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2756ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2757ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!bools_equal (a->had_content, b->had_content))
2758ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2759ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2760ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  switch (a->type)
2761ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2762ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2763ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_INCLUDE:
2764ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!bools_equal (a->d.include.ignore_missing,
2765ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project			b->d.include.ignore_missing))
2766ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2767ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2768ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2769ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_POLICY:
2770ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (a->d.policy.type != b->d.policy.type)
2771ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2772ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console)
2773ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2774ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2775ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2776ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    case ELEMENT_LIMIT:
2777ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (strcmp (a->d.limit.name, b->d.limit.name))
2778ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2779ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (a->d.limit.value != b->d.limit.value)
2780ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2781ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2782ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2783ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    default:
2784ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* do nothing */
2785ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      break;
2786ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2787ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2788ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
2789ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2790ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2791ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2792ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2793ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectlists_of_elements_equal (DBusList *a,
2794ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project			 DBusList *b)
2795ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2796ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *ia;
2797ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *ib;
2798ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2799ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ia = a;
2800ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ib = b;
2801ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2802ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (ia != NULL && ib != NULL)
2803ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2804ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (elements_equal (ia->data, ib->data))
2805ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2806ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ia = _dbus_list_get_next_link (&a, ia);
2807ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ib = _dbus_list_get_next_link (&b, ib);
2808ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2809ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2810ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return ia == NULL && ib == NULL;
2811ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2812ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2813ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2814ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectlists_of_c_strings_equal (DBusList *a,
2815ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project			  DBusList *b)
2816ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2817ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *ia;
2818ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *ib;
2819ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2820ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ia = a;
2821ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  ib = b;
2822ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2823ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (ia != NULL && ib != NULL)
2824ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2825ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (strcmp (ia->data, ib->data))
2826ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	return FALSE;
2827ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ia = _dbus_list_get_next_link (&a, ia);
2828ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ib = _dbus_list_get_next_link (&b, ib);
2829ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2830ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2831ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return ia == NULL && ib == NULL;
2832ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2833ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2834ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2835ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectlimits_equal (const BusLimits *a,
2836ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	      const BusLimits *b)
2837ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2838ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return
2839ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    (a->max_incoming_bytes == b->max_incoming_bytes
2840ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_outgoing_bytes == b->max_outgoing_bytes
2841ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_message_size == b->max_message_size
2842ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->activation_timeout == b->activation_timeout
2843ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->auth_timeout == b->auth_timeout
2844ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_completed_connections == b->max_completed_connections
2845ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_incomplete_connections == b->max_incomplete_connections
2846ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_connections_per_user == b->max_connections_per_user
2847ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_pending_activations == b->max_pending_activations
2848ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_services_per_connection == b->max_services_per_connection
2849ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_match_rules_per_connection == b->max_match_rules_per_connection
2850ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->max_replies_per_connection == b->max_replies_per_connection
2851ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project     || a->reply_timeout == b->reply_timeout);
2852ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2853ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2854ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2855ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectconfig_parsers_equal (const BusConfigParser *a,
2856ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                      const BusConfigParser *b)
2857ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2858ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_equal (&a->basedir, &b->basedir))
2859ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2860ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2861ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!lists_of_elements_equal (a->stack, b->stack))
2862ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2863ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2864ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!strings_equal_or_both_null (a->user, b->user))
2865ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2866ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2867ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!lists_of_c_strings_equal (a->listen_on, b->listen_on))
2868ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2869ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2870ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms))
2871ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2872ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2873ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!lists_of_c_strings_equal (a->service_dirs, b->service_dirs))
2874ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2875ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2876ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* FIXME: compare policy */
2877ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2878ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* FIXME: compare service selinux ID table */
2879ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2880ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (! limits_equal (&a->limits, &b->limits))
2881ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2882ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2883ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!strings_equal_or_both_null (a->pidfile, b->pidfile))
2884ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2885ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2886ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (! bools_equal (a->fork, b->fork))
2887ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2888ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2889ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (! bools_equal (a->is_toplevel, b->is_toplevel))
2890ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
2891ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2892ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
2893ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2894ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2895ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2896ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectall_are_equiv (const DBusString *target_directory)
2897ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2898ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString filename;
2899ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusDirIter *dir;
2900ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusConfigParser *first_parser;
2901ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  BusConfigParser *parser;
2902ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusError error;
2903ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t equal;
2904ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t retval;
2905ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2906ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = NULL;
2907ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  first_parser = NULL;
2908ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  parser = NULL;
2909ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = FALSE;
2910ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2911ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&filename))
2912ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("didn't allocate filename string");
2913ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2914ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_error_init (&error);
2915ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = _dbus_directory_open (target_directory, &error);
2916ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir == NULL)
2917ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2918ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_warn ("Could not open %s: %s\n",
2919ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		  _dbus_string_get_const_data (target_directory),
2920ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		  error.message);
2921ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_error_free (&error);
2922ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto finished;
2923ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2924ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2925ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  printf ("Comparing equivalent files:\n");
2926ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2927ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project next:
2928ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (_dbus_directory_get_next_file (dir, &filename, &error))
2929ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
2930ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusString full_path;
2931ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2932ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_init (&full_path))
2933ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	_dbus_assert_not_reached ("couldn't init string");
2934ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2935ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_copy (target_directory, 0, &full_path, 0))
2936ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't copy dir to full_path");
2937ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2938ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_concat_dir_and_file (&full_path, &filename))
2939ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't concat file to dir");
2940ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2941ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2942ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
2943ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_verbose ("Skipping non-.conf file %s\n",
2944ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                         _dbus_string_get_const_data (&filename));
2945ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  _dbus_string_free (&full_path);
2946ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          goto next;
2947ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
2948ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2949ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      printf ("    %s\n", _dbus_string_get_const_data (&filename));
2950ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2951ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      parser = bus_config_load (&full_path, TRUE, NULL, &error);
2952ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2953ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (parser == NULL)
2954ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	{
2955ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  _dbus_warn ("Could not load file %s: %s\n",
2956ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		      _dbus_string_get_const_data (&full_path),
2957ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		      error.message);
2958ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_free (&full_path);
2959ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  dbus_error_free (&error);
2960ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  goto finished;
2961ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	}
2962ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else if (first_parser == NULL)
2963ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	{
2964ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_free (&full_path);
2965ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  first_parser = parser;
2966ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	}
2967ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      else
2968ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	{
2969ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          _dbus_string_free (&full_path);
2970ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  equal = config_parsers_equal (first_parser, parser);
2971ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  bus_config_parser_unref (parser);
2972ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	  if (! equal)
2973ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	    goto finished;
2974ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	}
2975ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
2976ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2977ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = TRUE;
2978ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2979ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project finished:
2980ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&filename);
2981ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (first_parser)
2982ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    bus_config_parser_unref (first_parser);
2983ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir)
2984ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_directory_close (dir);
2985ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2986ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return retval;
2987ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2988ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
2989ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
2990ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
2991ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectprocess_test_equiv_subdir (const DBusString *test_base_dir,
2992ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project			   const char       *subdir)
2993ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
2994ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString test_directory;
2995ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusString filename;
2996ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusDirIter *dir;
2997ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusError error;
2998ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t equal;
2999ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_bool_t retval;
3000ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3001ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = NULL;
3002ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = FALSE;
3003ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3004ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&test_directory))
3005ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("didn't allocate test_directory");
3006ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3007ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_init_const (&filename, subdir);
3008ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3009ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_copy (test_base_dir, 0,
3010ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project			  &test_directory, 0))
3011ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
3012ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3013ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_concat_dir_and_file (&test_directory, &filename))
3014ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't allocate full path");
3015ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3016ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&filename);
3017ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_string_init (&filename))
3018ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("didn't allocate filename string");
3019ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3020ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dbus_error_init (&error);
3021ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dir = _dbus_directory_open (&test_directory, &error);
3022ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir == NULL)
3023ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
3024ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_warn ("Could not open %s: %s\n",
3025ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		  _dbus_string_get_const_data (&test_directory),
3026ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project		  error.message);
3027ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_error_free (&error);
3028ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      goto finished;
3029ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
3030ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3031ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while (_dbus_directory_get_next_file (dir, &filename, &error))
3032ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
3033ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusString full_path;
3034ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3035ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      /* Skip CVS's magic directories! */
3036ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (_dbus_string_equal_c_str (&filename, "CVS"))
3037ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	continue;
3038ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3039ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_init (&full_path))
3040ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	_dbus_assert_not_reached ("couldn't init string");
3041ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3042ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
3043ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't copy dir to full_path");
3044ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3045ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_concat_dir_and_file (&full_path, &filename))
3046ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        _dbus_assert_not_reached ("couldn't concat file to dir");
3047ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3048ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      equal = all_are_equiv (&full_path);
3049ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_free (&full_path);
3050ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3051ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!equal)
3052ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project	goto finished;
3053ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
3054ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3055ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  retval = TRUE;
3056ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3057ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project finished:
3058ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&test_directory);
3059ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  _dbus_string_free (&filename);
3060ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (dir)
3061ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_directory_close (dir);
3062ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3063ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return retval;
3064ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3065ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
3066ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3067ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic const char *test_service_dir_matches[] =
3068ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
3069ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         "/testusr/testlocal/testshare/dbus-1/services",
3070ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         "/testusr/testshare/dbus-1/services",
3071ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         DBUS_DATADIR"/dbus-1/services",
3072ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         "/testhome/foo/.testlocal/testshare/dbus-1/services",
3073ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project         NULL
3074ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        };
3075ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3076ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectstatic dbus_bool_t
3077ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projecttest_default_session_servicedirs (void)
3078ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
3079ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *dirs;
3080ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  DBusList *link;
3081ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  int i;
3082ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3083ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  dirs = NULL;
3084ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3085ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  printf ("Testing retriving the default session service directories\n");
3086ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_get_standard_session_servicedirs (&dirs))
3087ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't get stardard dirs");
3088ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3089ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* make sure our defaults end with share/dbus-1/service */
3090ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while ((link = _dbus_list_pop_first_link (&dirs)))
3091ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
3092ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      DBusString path;
3093ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3094ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      printf ("    default service dir: %s\n", (char *)link->data);
3095ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_init_const (&path, (char *)link->data);
3096ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (!_dbus_string_ends_with_c_str (&path, "share/dbus-1/services"))
3097ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
3098ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          printf ("error with default session service directories\n");
3099ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
3100ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
3101ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3102ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (link->data);
3103ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_free_link (link);
3104ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
3105ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3106ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
3107ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
3108ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3109ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
3110ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
3111ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3112ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!_dbus_get_standard_session_servicedirs (&dirs))
3113ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    _dbus_assert_not_reached ("couldn't get stardard dirs");
3114ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3115ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  /* make sure we read and parse the env variable correctly */
3116ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  i = 0;
3117ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  while ((link = _dbus_list_pop_first_link (&dirs)))
3118ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
3119ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      printf ("    test service dir: %s\n", (char *)link->data);
3120ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (test_service_dir_matches[i] == NULL)
3121ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
3122ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          printf ("more directories parsed than in match set\n");
3123ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
3124ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
3125ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3126ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      if (strcmp (test_service_dir_matches[i],
3127ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  (char *)link->data) != 0)
3128ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        {
3129ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          printf ("%s directory does not match %s in the match set\n",
3130ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  (char *)link->data,
3131ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project                  test_service_dir_matches[i]);
3132ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project          return FALSE;
3133ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project        }
3134ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3135ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      ++i;
3136ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3137ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      dbus_free (link->data);
3138ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_list_free_link (link);
3139ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
3140ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3141ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (test_service_dir_matches[i] != NULL)
3142ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
3143ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      printf ("extra data %s in the match set was not matched\n",
3144ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project              test_service_dir_matches[i]);
3145ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3146ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return FALSE;
3147ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
3148ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3149ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
3150ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
3151ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3152ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectdbus_bool_t
3153ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Projectbus_config_parser_test (const DBusString *test_data_dir)
3154ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project{
3155ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (test_data_dir == NULL ||
3156ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      _dbus_string_get_length (test_data_dir) == 0)
3157ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    {
3158ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      printf ("No test data\n");
3159ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project      return TRUE;
3160ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    }
3161ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3162ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!test_default_session_servicedirs())
3163ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
3164ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3165ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
3166ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
3167ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3168ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
3169ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
3170ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3171ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
3172ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project    return FALSE;
3173ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3174ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project  return TRUE;
3175ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project}
3176ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3177ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project#endif /* DBUS_BUILD_TESTS */
3178ae35d9c7cda6a436e81c7be962963aa31596f645The Android Open Source Project
3179