Debian Codegraph @

src/launch/config.h

raw
1 #pragma once
2
3 /*
4 * D-Bus XML Config Parser
5 */
6
7 #include <c-list.h>
8 #include <c-stdaux.h>
9 #include <stdlib.h>
10
11 struct XML_ParserStruct;
12
13 typedef struct ConfigPath ConfigPath;
14 typedef struct ConfigNode ConfigNode;
15 typedef struct ConfigParser ConfigParser;
16 typedef struct ConfigRoot ConfigRoot;
17 typedef struct ConfigState ConfigState;
18 typedef struct Dirwatch Dirwatch;
19 typedef struct NSSCache NSSCache;
20
21 #define CONFIG_PARSER_BUFFER_MAX 4096
22
23 enum {
24 _CONFIG_E_SUCCESS,
25
26 CONFIG_E_INVALID,
27 };
28
29 enum {
30 CONFIG_NODE_NONE,
31
32 CONFIG_NODE_BUSCONFIG,
33 CONFIG_NODE_USER,
34 CONFIG_NODE_TYPE,
35 CONFIG_NODE_FORK,
36 CONFIG_NODE_SYSLOG,
37 CONFIG_NODE_KEEP_UMASK,
38 CONFIG_NODE_LISTEN,
39 CONFIG_NODE_PIDFILE,
40 CONFIG_NODE_INCLUDEDIR,
41 CONFIG_NODE_STANDARD_SESSION_SERVICEDIRS,
42 CONFIG_NODE_STANDARD_SYSTEM_SERVICEDIRS,
43 CONFIG_NODE_SERVICEDIR,
44 CONFIG_NODE_SERVICEHELPER,
45 CONFIG_NODE_AUTH,
46 CONFIG_NODE_INCLUDE,
47 CONFIG_NODE_POLICY,
48 CONFIG_NODE_LIMIT,
49 CONFIG_NODE_SELINUX,
50 CONFIG_NODE_APPARMOR,
51 CONFIG_NODE_ALLOW,
52 CONFIG_NODE_DENY,
53 CONFIG_NODE_ASSOCIATE,
54
55 _CONFIG_NODE_N,
56 };
57
58 enum {
59 CONFIG_POLICY_NONE,
60
61 CONFIG_POLICY_DEFAULT,
62 CONFIG_POLICY_GROUP,
63 CONFIG_POLICY_USER,
64 CONFIG_POLICY_AT_CONSOLE,
65 CONFIG_POLICY_NO_CONSOLE,
66 CONFIG_POLICY_MANDATORY,
67
68 _CONFIG_POLICY_N,
69 };
70
71 enum {
72 _CONFIG_LIMIT_INVALID = 0,
73
74 CONFIG_LIMIT_MAX_INCOMING_BYTES,
75 CONFIG_LIMIT_MAX_INCOMING_UNIX_FDS,
76 CONFIG_LIMIT_MAX_OUTGOING_BYTES,
77 CONFIG_LIMIT_MAX_OUTGOING_UNIX_FDS,
78 CONFIG_LIMIT_MAX_MESSAGE_SIZE,
79 CONFIG_LIMIT_MAX_MESSAGE_UNIX_FDS,
80 CONFIG_LIMIT_SERVICE_START_TIMEOUT,
81 CONFIG_LIMIT_AUTH_TIMEOUT,
82 CONFIG_LIMIT_PENDING_FD_TIMEOUT,
83 CONFIG_LIMIT_MAX_COMPLETED_CONNECTIONS,
84 CONFIG_LIMIT_MAX_INCOMPLETE_CONNECTIONS,
85 CONFIG_LIMIT_MAX_CONNECTIONS_PER_USER,
86 CONFIG_LIMIT_MAX_PENDING_SERVICE_STARTS,
87 CONFIG_LIMIT_MAX_NAMES_PER_CONNECTION,
88 CONFIG_LIMIT_MAX_MATCH_RULES_PER_CONNECTION,
89 CONFIG_LIMIT_MAX_REPLIES_PER_CONNECTION,
90 CONFIG_LIMIT_MAX_CONTAINERS_PER_USER,
91 CONFIG_LIMIT_MAX_CONTAINERS,
92 CONFIG_LIMIT_MAX_CONNECTIONS_PER_CONTAINER,
93 CONFIG_LIMIT_MAX_CONTAINER_METADATA_BYTES,
94 CONFIG_LIMIT_REPLY_TIMEOUT,
95 };
96
97 enum {
98 CONFIG_APPARMOR_ENABLED,
99 CONFIG_APPARMOR_DISABLED,
100 CONFIG_APPARMOR_REQUIRED,
101 };
102
103 struct ConfigPath {
104 unsigned long n_refs;
105 ConfigPath *parent;
106 bool is_dir;
107 char path[];
108 };
109
110 #define CONFIG_FILE_NULL(_x) { \
111 .n_refs = 1, \
112 }
113
114 struct ConfigNode {
115 CList root_link;
116 CList include_link;
117 ConfigNode *parent;
118 size_t n_children;
119
120 ConfigPath *path;
121 const char *file;
122 unsigned long lineno;
123
124 char *cdata;
125 size_t n_cdata;
126
127 unsigned int type;
128
129 union {
130 struct {
131 char *name;
132 } bustype;
133
134 struct {
135 uint32_t uid;
136 uint32_t gid;
137 bool valid : 1;
138 } user;
139
140 struct {
141 ConfigPath *dir;
142 } includedir;
143
144 struct {
145 ConfigPath *file;
146 bool ignore_missing : 1;
147 bool if_selinux_enabled : 1;
148 bool selinux_root_relative : 1;
149 } include;
150
151 struct {
152 char *path;
153 } servicedir;
154
155 struct {
156 unsigned int context;
157 uint32_t id;
158 } policy;
159
160 struct {
161 unsigned int name;
162 uint64_t value;
163 } limit;
164
165 struct {
166 unsigned int mode;
167 } apparmor;
168
169 struct {
170 char *send_interface;
171 char *send_member;
172 char *send_error;
173 char *send_destination;
174 char *send_path;
175 unsigned int send_type;
176 unsigned int send_broadcast;
177 char *recv_interface;
178 char *recv_member;
179 char *recv_error;
180 char *recv_sender;
181 char *recv_path;
182 unsigned int recv_type;
183 uint64_t min_fds;
184 uint64_t max_fds;
185 char *own;
186 char *own_prefix;
187 uint32_t uid;
188 uint32_t gid;
189 unsigned int send_requested_reply : 2;
190 unsigned int recv_requested_reply : 2;
191 unsigned int eavesdrop : 2;
192 bool user : 1;
193 bool group : 1;
194 bool log : 1;
195 } allow_deny;
196
197 struct {
198 char *own;
199 char *context;
200 } associate;
201 };
202 };
203
204 #define CONFIG_NODE_NULL(_x) { \
205 .root_link = C_LIST_INIT((_x).root_link), \
206 .include_link = C_LIST_INIT((_x).include_link), \
207 .file = "<unknown>", \
208 .type = CONFIG_NODE_NONE, \
209 }
210
211 struct ConfigRoot {
212 CList node_list;
213 CList include_list;
214 };
215
216 #define CONFIG_ROOT_NULL(_x) { \
217 .node_list = C_LIST_INIT((_x).node_list), \
218 .include_list = C_LIST_INIT((_x).include_list), \
219 }
220
221 struct ConfigParser {
222 struct XML_ParserStruct *xml;
223 unsigned long salt;
224
225 struct ConfigState {
226 NSSCache *nss;
227 Dirwatch *dirwatch;
228 ConfigPath *file;
229 ConfigRoot *root;
230 ConfigNode *current;
231 ConfigNode *last;
232 size_t n_depth;
233 size_t n_failed;
234 int error;
235 } state;
236 };
237
238 #define CONFIG_PARSER_NULL(_x) { \
239 .xml = NULL, \
240 }
241
242 /* files */
243
244 int config_path_new(ConfigPath **filep, ConfigPath *parent, const char *prefix, const char *path);
245 ConfigPath *config_path_ref(ConfigPath *file);
246 ConfigPath *config_path_unref(ConfigPath *file);
247
248 C_DEFINE_CLEANUP(ConfigPath *, config_path_unref);
249
250 /* nodes */
251
252 int config_node_new(ConfigNode **nodep, ConfigNode *parent, unsigned int type);
253 ConfigNode *config_node_free(ConfigNode *node);
254
255 C_DEFINE_CLEANUP(ConfigNode *, config_node_free);
256
257 /* roots */
258
259 int config_root_new(ConfigRoot **rootp);
260 ConfigRoot *config_root_free(ConfigRoot *root);
261
262 C_DEFINE_CLEANUP(ConfigRoot *, config_root_free);
263
264 /* parser */
265
266 void config_parser_init(ConfigParser *parser);
267 void config_parser_deinit(ConfigParser *parser);
268
269 int config_parser_read(ConfigParser *parser, ConfigRoot **rootp, const char *path, NSSCache *nss_cache, Dirwatch *dirwatch);
270
271 C_DEFINE_CLEANUP(ConfigParser *, config_parser_deinit);