]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/parse_config_file.c
tests: include config.h
[mirror_lxc.git] / src / tests / parse_config_file.c
CommitLineData
9c61a6d6
CB
1/* liblxcapi
2 *
3 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2017 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
e49c56d6
CB
19
20#include "config.h"
21
9c61a6d6
CB
22#include <lxc/lxccontainer.h>
23
8c582655 24#include <errno.h>
9c61a6d6
CB
25#include <signal.h>
26#include <stdio.h>
27#include <stdlib.h>
8c582655 28#include <string.h>
9c61a6d6
CB
29#include <sys/types.h>
30#include <sys/wait.h>
8c582655 31#include <unistd.h>
df24d436 32#include <libgen.h>
9c61a6d6 33
c3e3c21a 34#include "conf.h"
77803ee7 35#include "confile_utils.h"
9c61a6d6
CB
36#include "lxc/state.h"
37#include "lxctest.h"
dd5c5a5d 38#include "utils.h"
9c61a6d6 39
ae4ad10d
CB
40static int set_get_compare_clear_save_load(struct lxc_container *c,
41 const char *key, const char *value,
42 const char *config_file,
43 bool compare)
9c61a6d6
CB
44{
45 char retval[4096] = {0};
46 int ret;
47
48 if (!c->set_config_item(c, key, value)) {
49 lxc_error("failed to set config item \"%s\" to \"%s\"\n", key,
50 value);
51 return -1;
52 }
53
54 ret = c->get_config_item(c, key, retval, sizeof(retval));
55 if (ret < 0) {
56 lxc_error("failed to get config item \"%s\"\n", key);
57 return -1;
58 }
59
ae4ad10d
CB
60 if (compare) {
61 ret = strcmp(retval, value);
62 if (ret != 0) {
63 lxc_error(
64 "expected value \"%s\" and retrieved value \"%s\" "
65 "for config key \"%s\" do not match\n",
66 value, retval, key);
67 return -1;
68 }
69 }
70
9c61a6d6
CB
71 if (config_file) {
72 if (!c->save_config(c, config_file)) {
73 lxc_error("%s\n", "failed to save config file");
74 return -1;
75 }
76
77 c->clear_config(c);
78 c->lxc_conf = NULL;
79
80 if (!c->load_config(c, config_file)) {
81 lxc_error("%s\n", "failed to load config file");
82 return -1;
83 }
84 }
85
86 if (!c->clear_config_item(c, key)) {
87 lxc_error("failed to clear config item \"%s\"\n", key);
88 return -1;
89 }
90
8c582655
CB
91 c->clear_config(c);
92 c->lxc_conf = NULL;
9c61a6d6 93
8c582655
CB
94 return 0;
95}
9c61a6d6 96
8c582655
CB
97static int set_and_clear_complete_netdev(struct lxc_container *c)
98{
01aebbc3
CB
99 if (!c->set_config_item(c, "lxc.net.1.type", "veth")) {
100 lxc_error("%s\n", "lxc.net.1.type");
8c582655
CB
101 return -1;
102 }
103
9ff60df2
CB
104 if (!c->set_config_item(c, "lxc.net.1.ipv4.address", "10.0.2.3/24")) {
105 lxc_error("%s\n", "lxc.net.1.ipv4.address");
8c582655
CB
106 return -1;
107 }
108
9ff60df2
CB
109 if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "10.0.2.2")) {
110 lxc_error("%s\n", "lxc.net.1.ipv4.gateway");
8c582655
CB
111 return -1;
112 }
113
a2f9a670 114 if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "auto")) {
115 lxc_error("%s\n", "lxc.net.1.ipv4.gateway");
116 return -1;
117 }
118
119 if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "dev")) {
120 lxc_error("%s\n", "lxc.net.1.ipv4.gateway");
121 return -1;
122 }
123
2e44ae28 124 if (!c->set_config_item(c, "lxc.net.1.ipv6.address",
8c582655 125 "2003:db8:1:0:214:1234:fe0b:3596/64")) {
2e44ae28 126 lxc_error("%s\n", "lxc.net.1.ipv6.address");
8c582655
CB
127 return -1;
128 }
129
2e44ae28 130 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway",
8c582655 131 "2003:db8:1:0::1")) {
2e44ae28 132 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
8c582655
CB
133 return -1;
134 }
135
a2f9a670 136 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway", "auto")) {
137 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
138 return -1;
139 }
140
141 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway", "dev")) {
142 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
143 return -1;
144 }
145
01aebbc3
CB
146 if (!c->set_config_item(c, "lxc.net.1.flags", "up")) {
147 lxc_error("%s\n", "lxc.net.1.flags");
8c582655
CB
148 return -1;
149 }
150
01aebbc3
CB
151 if (!c->set_config_item(c, "lxc.net.1.link", "br0")) {
152 lxc_error("%s\n", "lxc.net.1.link");
8c582655
CB
153 return -1;
154 }
155
01aebbc3
CB
156 if (!c->set_config_item(c, "lxc.net.1.veth.pair", "bla")) {
157 lxc_error("%s\n", "lxc.net.1.veth.pair");
8c582655
CB
158 return -1;
159 }
160
d4a7da46 161 if (!c->set_config_item(c, "lxc.net.1.veth.ipv4.route", "192.0.2.1/32")) {
162 lxc_error("%s\n", "lxc.net.1.veth.ipv4.route");
163 return -1;
164 }
165
166 if (!c->set_config_item(c, "lxc.net.1.veth.ipv6.route", "2001:db8::1/128")) {
167 lxc_error("%s\n", "lxc.net.1.veth.ipv6.route");
168 return -1;
169 }
170
01aebbc3 171 if (!c->set_config_item(c, "lxc.net.1.hwaddr",
8c582655 172 "52:54:00:80:7a:5d")) {
01aebbc3 173 lxc_error("%s\n", "lxc.net.1.hwaddr");
8c582655
CB
174 return -1;
175 }
176
01aebbc3
CB
177 if (!c->set_config_item(c, "lxc.net.1.mtu", "2000")) {
178 lxc_error("%s\n", "lxc.net.1.mtu");
8c582655
CB
179 return -1;
180 }
181
01aebbc3
CB
182 if (!c->clear_config_item(c, "lxc.net.1")) {
183 lxc_error("%s", "failed to clear \"lxc.net.1\"\n");
8c582655 184 return -1;
9c61a6d6
CB
185 }
186
187 c->clear_config(c);
188 c->lxc_conf = NULL;
189
190 return 0;
191}
192
8bc6d539
FA
193static int set_invalid_netdev(struct lxc_container *c) {
194 if (c->set_config_item(c, "lxc.net.0.asdf", "veth")) {
195 lxc_error("%s\n", "lxc.net.0.asdf should be invalid");
196 return -1;
197 }
198
199 if (c->set_config_item(c, "lxc.net.2147483647.type", "veth")) {
200 lxc_error("%s\n", "lxc.net.2147483647.type should be invalid");
201 return -1;
202 }
203
24fa7df6
FA
204 if (c->set_config_item(c, "lxc.net.0.", "veth")) {
205 lxc_error("%s\n", "lxc.net.0. should be invalid");
206 return -1;
207 }
208
8bc6d539
FA
209 c->clear_config(c);
210 c->lxc_conf = NULL;
211
212 return 0;
213}
214
77803ee7
CB
215int test_idmap_parser(void)
216{
217 size_t i;
218 struct idmap_check {
219 bool is_valid;
220 const char *idmap;
221 };
222 static struct idmap_check idmaps[] = {
8c582655
CB
223 /* valid idmaps */
224 { true, "u 0 0 1" },
225 { true, "g 0 0 1" },
226 { true, "u 1 100001 999999999" },
227 { true, "g 1 100001 999999999" },
228 { true, "u 0 0 0" },
229 { true, "g 0 0 0" },
230 { true, "u 1000 165536 65536" },
231 { true, "g 999 999 1" },
232 { true, "u 0 5000 100000" },
233 { true, "g 577 789 5" },
234 { true, "u 65536 65536 1 " },
235 /* invalid idmaps */
236 { false, "1u 0 0 0" },
237 { false, "1g 0 0 0a" },
238 { false, "1 u 0 0 0" },
239 { false, "1g 0 0 0 1" },
240 { false, "1u a0 b0 c0 d1" },
241 { false, "1g 0 b0 0 d1" },
242 { false, "1u a0 0 c0 1" },
243 { false, "g -1 0 -10" },
244 { false, "a 1 0 10" },
245 { false, "u 1 1 0 10" },
246 { false, "g 1 0 10 z " },
77803ee7
CB
247 };
248
249 for (i = 0; i < sizeof(idmaps) / sizeof(struct idmap_check); i++) {
250 unsigned long hostid, nsid, range;
251 char type;
252 int ret;
253 ret = parse_idmaps(idmaps[i].idmap, &type, &nsid, &hostid,
254 &range);
255 if ((ret < 0 && idmaps[i].is_valid) ||
256 (ret == 0 && !idmaps[i].is_valid)) {
257 lxc_error("failed to parse idmap \"%s\"\n",
258 idmaps[i].idmap);
259 return -1;
260 }
261 }
262
263 return 0;
264}
265
8c582655
CB
266static int set_get_compare_clear_save_load_network(
267 struct lxc_container *c, const char *key, const char *value,
268 const char *config_file, bool compare, const char *network_type)
269{
270 char retval[4096] = {0};
271 int ret;
272
01aebbc3
CB
273 if (!c->set_config_item(c, "lxc.net.0.type", network_type)) {
274 lxc_error("%s\n", "lxc.net.0.type");
8c582655
CB
275 return -1;
276 }
277
278 if (!c->set_config_item(c, key, value)) {
279 lxc_error("failed to set config item \"%s\" to \"%s\"\n", key,
280 value);
281 return -1;
282 }
283
284 ret = c->get_config_item(c, key, retval, sizeof(retval));
285 if (ret < 0) {
286 lxc_error("failed to get config item \"%s\"\n", key);
287 return -1;
288 }
289
290 if (compare) {
291 ret = strcmp(retval, value);
292 if (ret != 0) {
293 lxc_error(
294 "expected value \"%s\" and retrieved value \"%s\" "
295 "for config key \"%s\" do not match\n",
296 value, retval, key);
297 return -1;
298 }
299 }
300
301 if (config_file) {
302 if (!c->save_config(c, config_file)) {
303 lxc_error("%s\n", "failed to save config file");
304 return -1;
305 }
306
307 c->clear_config(c);
308 c->lxc_conf = NULL;
309
310 if (!c->load_config(c, config_file)) {
311 lxc_error("%s\n", "failed to load config file");
312 return -1;
313 }
314 }
315
316 if (!c->clear_config_item(c, key)) {
317 lxc_error("failed to clear config item \"%s\"\n", key);
318 return -1;
319 }
320
01aebbc3
CB
321 if (!c->clear_config_item(c, "lxc.net.0.type")) {
322 lxc_error("%s\n", "lxc.net.0.type");
8c582655
CB
323 return -1;
324 }
325
326 c->clear_config(c);
327 c->lxc_conf = NULL;
328
329 return 0;
330}
331
9c61a6d6
CB
332int main(int argc, char *argv[])
333{
44ae0fb6 334 int ret;
9c61a6d6 335 struct lxc_container *c;
44ae0fb6 336 int fd = -1, fret = EXIT_FAILURE;
9c61a6d6
CB
337 char tmpf[] = "lxc-parse-config-file-XXXXXX";
338 char retval[4096] = {0};
339
dd5c5a5d 340 fd = lxc_make_tmpfile(tmpf, false);
9c61a6d6
CB
341 if (fd < 0) {
342 lxc_error("%s\n", "Could not create temporary file");
44ae0fb6 343 exit(fret);
9c61a6d6
CB
344 }
345 close(fd);
346
6cd5db20
LW
347 c = lxc_container_new(tmpf, NULL);
348 if (!c) {
349 lxc_error("%s\n", "Failed to create new container");
350 exit(EXIT_FAILURE);
351 }
8c582655 352
8c582655
CB
353 if (set_get_compare_clear_save_load(c, "lxc.arch", "x86_64", tmpf,
354 true) < 0) {
9c61a6d6
CB
355 lxc_error("%s\n", "lxc.arch");
356 goto non_test_error;
357 }
358
2a6d08c6 359 if (set_get_compare_clear_save_load(c, "lxc.pty.max", "1000", tmpf, true) < 0) {
6fba98b5 360 lxc_error("%s\n", "lxc.pty.max");
9c61a6d6
CB
361 goto non_test_error;
362 }
363
2a6d08c6 364 if (set_get_compare_clear_save_load(c, "lxc.tty.max", "4", tmpf, true) < 0) {
fe1c5887 365 lxc_error("%s\n", "lxc.tty.max");
9c61a6d6
CB
366 goto non_test_error;
367 }
368
2a6d08c6 369 if (set_get_compare_clear_save_load(c, "lxc.tty.dir", "not-dev", tmpf, true) < 0) {
42e53c29 370 lxc_error("%s\n", "lxc.tty.dir");
371 goto non_test_error;
372 }
373
b967f9e8
CB
374 ret = set_get_compare_clear_save_load(c, "lxc.apparmor.profile", "unconfined", tmpf, true);
375#if HAVE_APPARMOR
376 if (ret < 0)
377#else
378 if (ret == 0)
379#endif
380 {
953fe44f
CB
381 lxc_error("%s\n", "lxc.apparmor.profile");
382 goto non_test_error;
383 }
384
b967f9e8
CB
385 ret = set_get_compare_clear_save_load(c, "lxc.apparmor.allow_incomplete", "1", tmpf, true);
386#if HAVE_APPARMOR
387 if (ret < 0)
388#else
389 if (ret == 0)
390#endif
391 {
953fe44f
CB
392 lxc_error("%s\n", "lxc.apparmor.allow_incomplete");
393 goto non_test_error;
394 }
395
b967f9e8
CB
396 ret = set_get_compare_clear_save_load(c, "lxc.selinux.context", "system_u:system_r:lxc_t:s0:c22", tmpf, true);
397#if HAVE_SELINUX
398 if (ret < 0)
399#else
400 if (ret == 0)
401#endif
402 {
f30ab9fe 403 lxc_error("%s\n", "lxc.selinux.context");
953fe44f
CB
404 goto non_test_error;
405 }
406
8c582655
CB
407 if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus",
408 "1-100", tmpf, false) < 0) {
9c61a6d6
CB
409 lxc_error("%s\n", "lxc.cgroup.cpuset.cpus");
410 goto non_test_error;
411 }
412
9c61a6d6 413 if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) {
2a6d08c6 414 lxc_error("%s\n", "failed to set config item \"lxc.cgroup.cpuset.cpus\" to \"1-100\"");
9c61a6d6
CB
415 return -1;
416 }
417
2a6d08c6
CB
418 if (!c->set_config_item(c, "lxc.cgroup.memory.limit_in_bytes", "123456789")) {
419 lxc_error("%s\n", "failed to set config item \"lxc.cgroup.memory.limit_in_bytes\" to \"123456789\"");
9c61a6d6
CB
420 return -1;
421 }
422
423 if (!c->get_config_item(c, "lxc.cgroup", retval, sizeof(retval))) {
424 lxc_error("%s\n", "failed to get config item \"lxc.cgroup\"");
425 return -1;
426 }
427
428 c->clear_config(c);
429 c->lxc_conf = NULL;
430
bdcbb6b3
CB
431 /* lxc.idmap
432 * We can't really save the config here since save_config() wants to
433 * chown the container's directory but we haven't created an on-disk
434 * container. So let's test set-get-clear.
435 */
2a6d08c6 436 if (set_get_compare_clear_save_load(c, "lxc.idmap", "u 0 100000 1000000000", NULL, false) < 0) {
bdcbb6b3
CB
437 lxc_error("%s\n", "lxc.idmap");
438 goto non_test_error;
439 }
440
441 if (!c->set_config_item(c, "lxc.idmap", "u 1 100000 10000000")) {
2a6d08c6 442 lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"u 1 100000 10000000\"");
bdcbb6b3
CB
443 return -1;
444 }
445
446 if (!c->set_config_item(c, "lxc.idmap", "g 1 100000 10000000")) {
2a6d08c6 447 lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"g 1 100000 10000000\"");
bdcbb6b3
CB
448 return -1;
449 }
450
451 if (!c->get_config_item(c, "lxc.idmap", retval, sizeof(retval))) {
d6bec4ab 452 lxc_error("%s\n", "failed to get config item \"lxc.idmap\"");
bdcbb6b3
CB
453 return -1;
454 }
455
9c61a6d6
CB
456 c->clear_config(c);
457 c->lxc_conf = NULL;
458
2a6d08c6 459 if (set_get_compare_clear_save_load(c, "lxc.log.level", "DEBUG", tmpf, true) < 0) {
46cc906d 460 lxc_error("%s\n", "lxc.log.level");
461 goto non_test_error;
462 }
463
2a6d08c6 464 if (set_get_compare_clear_save_load(c, "lxc.log.file", "/some/path", tmpf, true) < 0) {
46cc906d 465 lxc_error("%s\n", "lxc.log.file");
466 goto non_test_error;
467 }
468
2a6d08c6 469 if (set_get_compare_clear_save_load(c, "lxc.mount.fstab", "/some/path", NULL, true) < 0) {
47148e96
CB
470 lxc_error("%s\n", "lxc.mount.fstab");
471 goto non_test_error;
472 }
473
ae4ad10d
CB
474 /* lxc.mount.auto
475 * Note that we cannot compare the values since the getter for
476 * lxc.mount.auto does not preserve ordering.
477 */
2a6d08c6 478 if (set_get_compare_clear_save_load(c, "lxc.mount.auto", "proc:rw sys:rw cgroup-full:rw", tmpf, false) < 0) {
9c61a6d6
CB
479 lxc_error("%s\n", "lxc.mount.auto");
480 goto non_test_error;
481 }
482
ae4ad10d
CB
483 /* lxc.mount.entry
484 * Note that we cannot compare the values since the getter for
485 * lxc.mount.entry appends newlines.
486 */
2a6d08c6 487 if (set_get_compare_clear_save_load(c, "lxc.mount.entry", "/dev/dri dev/dri none bind,optional,create=dir", tmpf, false) < 0) {
9c61a6d6
CB
488 lxc_error("%s\n", "lxc.mount.entry");
489 goto non_test_error;
490 }
491
2a6d08c6 492 if (set_get_compare_clear_save_load(c, "lxc.rootfs.path", "/some/path", tmpf, true) < 0) {
7a96a068
CB
493 lxc_error("%s\n", "lxc.rootfs.path");
494 goto non_test_error;
495 }
496
2a6d08c6 497 if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path", tmpf, true) < 0) {
9c61a6d6
CB
498 lxc_error("%s\n", "lxc.rootfs.mount");
499 goto non_test_error;
500 }
501
2a6d08c6 502 if (set_get_compare_clear_save_load(c, "lxc.rootfs.options", "ext4,discard", tmpf, true) < 0) {
9c61a6d6
CB
503 lxc_error("%s\n", "lxc.rootfs.options");
504 goto non_test_error;
505 }
506
2a6d08c6 507 if (set_get_compare_clear_save_load(c, "lxc.uts.name", "the-shire", tmpf, true) < 0) {
b67771bc 508 lxc_error("%s\n", "lxc.uts.name");
509 goto non_test_error;
510 }
511
8c582655
CB
512 if (set_get_compare_clear_save_load(
513 c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) {
9c61a6d6
CB
514 lxc_error("%s\n", "lxc.hook.pre-start");
515 goto non_test_error;
516 }
517
8c582655
CB
518 if (set_get_compare_clear_save_load(
519 c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) {
9c61a6d6
CB
520 lxc_error("%s\n", "lxc.hook.pre-mount");
521 goto non_test_error;
522 }
523
2a6d08c6 524 if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount", tmpf, false) < 0) {
9c61a6d6
CB
525 lxc_error("%s\n", "lxc.hook.mount");
526 goto non_test_error;
527 }
528
2a6d08c6 529 if (set_get_compare_clear_save_load(c, "lxc.hook.autodev", "/some/autodev", tmpf, false) < 0) {
9c61a6d6
CB
530 lxc_error("%s\n", "lxc.hook.autodev");
531 goto non_test_error;
532 }
533
2a6d08c6 534 if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start", tmpf, false) < 0) {
9c61a6d6
CB
535 lxc_error("%s\n", "lxc.hook.start");
536 goto non_test_error;
537 }
538
2a6d08c6 539 if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop", tmpf, false) < 0) {
9c61a6d6
CB
540 lxc_error("%s\n", "lxc.hook.stop");
541 goto non_test_error;
542 }
543
2a6d08c6 544 if (set_get_compare_clear_save_load(c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) {
9c61a6d6
CB
545 lxc_error("%s\n", "lxc.hook.post-stop");
546 goto non_test_error;
547 }
548
2a6d08c6 549 if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone", tmpf, false) < 0) {
9c61a6d6
CB
550 lxc_error("%s\n", "lxc.hook.clone");
551 goto non_test_error;
552 }
553
2a6d08c6 554 if (set_get_compare_clear_save_load(c, "lxc.hook.destroy", "/some/destroy", tmpf, false) < 0) {
9c61a6d6
CB
555 lxc_error("%s\n", "lxc.hook.destroy");
556 goto non_test_error;
557 }
558
2a6d08c6 559 if (set_get_compare_clear_save_load(c, "lxc.cap.drop", "sys_module mknod setuid net_raw", tmpf, false) < 0) {
9c61a6d6
CB
560 lxc_error("%s\n", "lxc.cap.drop");
561 goto non_test_error;
562 }
563
2a6d08c6 564 if (set_get_compare_clear_save_load(c, "lxc.cap.keep", "sys_module mknod setuid net_raw", tmpf, false) < 0) {
9c61a6d6
CB
565 lxc_error("%s\n", "lxc.cap.keep");
566 goto non_test_error;
567 }
568
2a6d08c6 569 if (set_get_compare_clear_save_load(c, "lxc.console.path", "none", tmpf, true) < 0) {
3aed4934
CB
570 lxc_error("%s\n", "lxc.console.path");
571 goto non_test_error;
572 }
573
2a6d08c6 574 if (set_get_compare_clear_save_load(c, "lxc.console.logfile", "/some/logfile", tmpf, true) < 0) {
9c61a6d6
CB
575 lxc_error("%s\n", "lxc.console.logfile");
576 goto non_test_error;
577 }
578
2a6d08c6 579 if (set_get_compare_clear_save_load(c, "lxc.seccomp.profile", "/some/seccomp/file", tmpf, true) < 0) {
0b427da0
CB
580 lxc_error("%s\n", "lxc.seccomp.profile");
581 goto non_test_error;
582 }
583
63012bdd
CK
584 if (set_get_compare_clear_save_load(c, "lxc.autodev.tmpfs.size", "1", tmpf, true) < 0) {
585 lxc_error("%s\n", "lxc.autodev.tmpfs.size");
586 goto non_test_error;
587 }
588
8c582655
CB
589 if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
590 0) {
9c61a6d6
CB
591 lxc_error("%s\n", "lxc.autodev");
592 goto non_test_error;
593 }
594
2a6d08c6 595 if (set_get_compare_clear_save_load(c, "lxc.signal.halt", "1", tmpf, true) < 0) {
55c84efc 596 lxc_error("%s\n", "lxc.signal.halt");
597 goto non_test_error;
598 }
599
2a6d08c6 600 if (set_get_compare_clear_save_load(c, "lxc.signal.reboot", "1", tmpf, true) < 0) {
55c84efc 601 lxc_error("%s\n", "lxc.signal.reboot");
602 goto non_test_error;
603 }
604
2a6d08c6 605 if (set_get_compare_clear_save_load(c, "lxc.signal.stop", "1", tmpf, true) < 0) {
55c84efc 606 lxc_error("%s\n", "lxc.signal.stop");
607 goto non_test_error;
608 }
609
2a6d08c6 610 if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf, true) < 0) {
9c61a6d6
CB
611 lxc_error("%s\n", "lxc.start.auto");
612 goto non_test_error;
613 }
614
2a6d08c6 615 if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf, true) < 0) {
9c61a6d6
CB
616 lxc_error("%s\n", "lxc.start.delay");
617 goto non_test_error;
618 }
619
2a6d08c6 620 if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf, true) < 0) {
9c61a6d6
CB
621 lxc_error("%s\n", "lxc.start.order");
622 goto non_test_error;
623 }
624
2a6d08c6 625 if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf, true) < 0) {
46cc906d 626 lxc_error("%s\n", "lxc.log.syslog");
9c61a6d6
CB
627 goto non_test_error;
628 }
629
2a6d08c6 630 if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf, true) < 0) {
9c61a6d6
CB
631 lxc_error("%s\n", "lxc.monitor.unshare");
632 goto non_test_error;
633 }
634
2a6d08c6 635 if (set_get_compare_clear_save_load(c, "lxc.group", "some,container,groups", tmpf, false) < 0) {
9c61a6d6
CB
636 lxc_error("%s\n", "lxc.group");
637 goto non_test_error;
638 }
639
2a6d08c6 640 if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR", tmpf, false) < 0) {
9c61a6d6
CB
641 lxc_error("%s\n", "lxc.environment");
642 goto non_test_error;
643 }
644
2a6d08c6 645 if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash", tmpf, true) < 0) {
9dcf7b4d 646 lxc_error("%s\n", "lxc.init.cmd");
647 goto non_test_error;
648 }
649
2a6d08c6 650 if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf, true) < 0) {
9dcf7b4d 651 lxc_error("%s\n", "lxc.init.uid");
652 goto non_test_error;
653 }
654
2a6d08c6 655 if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf, true) < 0) {
9dcf7b4d 656 lxc_error("%s\n", "lxc.init.gid");
657 goto non_test_error;
658 }
659
2a6d08c6 660 if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf, true) < 0) {
9c61a6d6
CB
661 lxc_error("%s\n", "lxc.ephemeral");
662 goto non_test_error;
663 }
664
2a6d08c6 665 if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf, true) < 0) {
9c61a6d6
CB
666 lxc_error("%s\n", "lxc.no_new_privs");
667 goto non_test_error;
668 }
669
2a6d08c6 670 if (set_get_compare_clear_save_load(c, "lxc.sysctl.net.core.somaxconn", "256", tmpf, true) < 0) {
7edd0540
L
671 lxc_error("%s\n", "lxc.sysctl.net.core.somaxconn");
672 goto non_test_error;
673 }
674
2a6d08c6 675 if (set_get_compare_clear_save_load(c, "lxc.proc.oom_score_adj", "10", tmpf, true) < 0) {
61d7a733
YT
676 lxc_error("%s\n", "lxc.proc.oom_score_adj");
677 goto non_test_error;
678 }
679
2a6d08c6 680 if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536", tmpf, true) < 0) {
240d4b74 681 lxc_error("%s\n", "lxc.prlimit.nofile");
682 goto non_test_error;
9c61a6d6
CB
683 }
684
77803ee7
CB
685 if (test_idmap_parser() < 0) {
686 lxc_error("%s\n", "failed to test parser for \"lxc.id_map\"");
687 goto non_test_error;
688 }
689
2a6d08c6 690 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth", tmpf, true)) {
01aebbc3 691 lxc_error("%s\n", "lxc.net.0.type");
8c582655
CB
692 goto non_test_error;
693 }
694
2a6d08c6 695 if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none", tmpf, true)) {
01aebbc3 696 lxc_error("%s\n", "lxc.net.2.type");
8c582655
CB
697 goto non_test_error;
698 }
699
2a6d08c6 700 if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty", tmpf, true)) {
01aebbc3 701 lxc_error("%s\n", "lxc.net.3.type");
8c582655
CB
702 goto non_test_error;
703 }
704
2a6d08c6 705 if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan", tmpf, true)) {
01aebbc3 706 lxc_error("%s\n", "lxc.net.4.type");
8c582655
CB
707 goto non_test_error;
708 }
709
2a6d08c6 710 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan", tmpf, true)) {
01aebbc3 711 lxc_error("%s\n", "lxc.net.0.type");
8c582655
CB
712 goto non_test_error;
713 }
714
c9f52382 715 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "ipvlan", tmpf, true)) {
716 lxc_error("%s\n", "lxc.net.0.type");
717 goto non_test_error;
718 }
719
2a6d08c6 720 if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys", tmpf, true)) {
01aebbc3 721 lxc_error("%s\n", "lxc.net.1000.type");
8c582655
CB
722 goto non_test_error;
723 }
724
2a6d08c6 725 if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up", tmpf, true)) {
01aebbc3 726 lxc_error("%s\n", "lxc.net.0.flags");
8c582655
CB
727 goto non_test_error;
728 }
729
2a6d08c6 730 if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0", tmpf, true)) {
01aebbc3 731 lxc_error("%s\n", "lxc.net.0.name");
8c582655
CB
732 goto non_test_error;
733 }
734
2a6d08c6 735 if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla", tmpf, true)) {
01aebbc3 736 lxc_error("%s\n", "lxc.net.0.link");
8c582655
CB
737 goto non_test_error;
738 }
739
2a6d08c6 740 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "private", tmpf, true, "macvlan")) {
01aebbc3 741 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
8c582655
CB
742 goto non_test_error;
743 }
744
2a6d08c6 745 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true, "macvlan")) {
01aebbc3 746 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
8c582655
CB
747 goto non_test_error;
748 }
749
2a6d08c6 750 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true, "macvlan")) {
01aebbc3 751 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
8c582655
CB
752 goto non_test_error;
753 }
754
c9f52382 755 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l3", tmpf, true, "ipvlan")) {
756 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
757 goto non_test_error;
758 }
759
760 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l3s", tmpf, true, "ipvlan")) {
761 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
762 goto non_test_error;
763 }
764
765 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l2", tmpf, true, "ipvlan")) {
766 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
767 goto non_test_error;
768 }
769
770 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "bridge", tmpf, true, "ipvlan")) {
771 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
772 goto non_test_error;
773 }
774
775 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "private", tmpf, true, "ipvlan")) {
776 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
777 goto non_test_error;
778 }
779
780 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "vepa", tmpf, true, "ipvlan")) {
781 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
782 goto non_test_error;
783 }
784
2a6d08c6 785 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true, "veth")) {
01aebbc3 786 lxc_error("%s\n", "lxc.net.0.veth.pair");
8c582655
CB
787 goto non_test_error;
788 }
789
d4a7da46 790 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.ipv4.route", "192.0.2.1/32", tmpf, true, "veth")) {
791 lxc_error("%s\n", "lxc.net.0.veth.ipv4.route");
792 return -1;
793 }
794
795 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.ipv6.route", "2001:db8::1/128", tmpf, true, "veth")) {
796 lxc_error("%s\n", "lxc.net.0.veth.ipv6.route");
797 return -1;
798 }
799
9262d646
TP
800 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.vlan.id", "none", tmpf, false, "veth")) {
801 lxc_error("%s\n", "lxc.net.0.veth.vlan.id");
802 return -1;
803 }
804
8abd9602
TP
805 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.vlan.id", "2", tmpf, true, "veth")) {
806 lxc_error("%s\n", "lxc.net.0.veth.vlan.id");
807 return -1;
808 }
809
5ca374db
TP
810 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.vlan.tagged.id", "2", tmpf, true, "veth")) {
811 lxc_error("%s\n", "lxc.net.0.veth.vlan.tagged.id");
812 return -1;
813 }
814
2a6d08c6 815 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up", "/some/up/path", tmpf, true)) {
01aebbc3 816 lxc_error("%s\n", "lxc.net.0.script.up");
8c582655
CB
817 goto non_test_error;
818 }
819
2a6d08c6 820 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down", "/some/down/path", tmpf, true)) {
01aebbc3 821 lxc_error("%s\n", "lxc.net.0.script.down");
8c582655
CB
822 goto non_test_error;
823 }
824
2a6d08c6 825 if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr", "52:54:00:80:7a:5d", tmpf, true)) {
01aebbc3 826 lxc_error("%s\n", "lxc.net.0.hwaddr");
8c582655
CB
827 goto non_test_error;
828 }
829
2a6d08c6 830 if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000", tmpf, true)) {
01aebbc3 831 lxc_error("%s\n", "lxc.net.0.mtu");
8c582655
CB
832 goto non_test_error;
833 }
834
2a6d08c6 835 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id", "2", tmpf, true, "vlan")) {
01aebbc3 836 lxc_error("%s\n", "lxc.net.0.vlan.id");
8c582655
CB
837 goto non_test_error;
838 }
839
2a6d08c6 840 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "10.0.2.2", tmpf, true)) {
01aebbc3 841 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
8c582655
CB
842 goto non_test_error;
843 }
844
a2f9a670 845 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "auto", tmpf, true)) {
846 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
847 goto non_test_error;
848 }
849
850 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "dev", tmpf, true)) {
851 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
852 goto non_test_error;
853 }
854
2a6d08c6 855 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "2003:db8:1::1", tmpf, true)) {
01aebbc3 856 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
8c582655
CB
857 goto non_test_error;
858 }
859
a2f9a670 860 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "auto", tmpf, true)) {
861 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
862 goto non_test_error;
863 }
864
865 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "dev", tmpf, true)) {
866 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
867 goto non_test_error;
868 }
869
2a6d08c6 870 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.address", "10.0.2.3/24", tmpf, true)) {
9ff60df2 871 lxc_error("%s\n", "lxc.net.0.ipv4.address");
8c582655
CB
872 goto non_test_error;
873 }
874
2a6d08c6 875 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.address", "2003:db8:1:0:214:1234:fe0b:3596/64", tmpf, true)) {
2e44ae28 876 lxc_error("%s\n", "lxc.net.0.ipv6.address");
8c582655
CB
877 goto non_test_error;
878 }
879
2a6d08c6 880 if (set_get_compare_clear_save_load(c, "lxc.cgroup.dir", "lxd", tmpf, true)) {
dae8c253
CB
881 lxc_error("%s\n", "lxc.cgroup.dir");
882 goto non_test_error;
883 }
884
8c582655
CB
885 if (set_and_clear_complete_netdev(c) < 0) {
886 lxc_error("%s\n", "failed to clear whole network");
887 goto non_test_error;
888 }
889
8bc6d539
FA
890 if (set_invalid_netdev(c) < 0) {
891 lxc_error("%s\n", "failed to reject invalid configuration");
892 goto non_test_error;
893 }
894
44ae0fb6
CB
895 ret = set_get_compare_clear_save_load(c, "lxc.hook.version", "1", tmpf, true);
896 if (ret < 0) {
897 lxc_error("%s\n", "lxc.hook.version");
898 goto non_test_error;
899 }
900
cea88c47
CB
901 if (c->set_config_item(c, "lxc.hook.version", "2")) {
902 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.hook.version\" to \"2\"");
44ae0fb6
CB
903 goto non_test_error;
904 }
905
cea88c47
CB
906 if (!c->set_config_item(c, "lxc.monitor.signal.pdeath", "SIGKILL")) {
907 lxc_error("%s\n", "Failed to set to set invalid config item \"lxc.monitor.signal.pdeath\" to \"SIGKILL\"");
e53cd6d8
CB
908 goto non_test_error;
909 }
910
6e0045bd
CB
911 if (set_get_compare_clear_save_load(c, "lxc.rootfs.managed", "1", tmpf, true) < 0) {
912 lxc_error("%s\n", "lxc.rootfs.managed");
913 goto non_test_error;
914 }
915
646e6c8b
CB
916 if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
917 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.notaconfigkey\" to \"invalid\"");
918 return -1;
919 }
920
2f6d3099
CB
921 if (c->set_config_item(c, "lxc.log.file=", "./")) {
922 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.log.file\" to \"./\"");
923 return -1;
924 }
925
2d676c00
CB
926 if (c->set_config_item(c, "lxc.hook.versionasdfsadfsadf", "1")) {
927 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.hook.versionasdfsadfsadf\" to \"2\"");
928 goto non_test_error;
929 }
930
09996a48
CB
931 if (set_get_compare_clear_save_load(c, "lxc.sched.core", "1", tmpf, true) < 0) {
932 lxc_error("%s\n", "lxc.sched.core");
933 goto non_test_error;
934 }
935
44ae0fb6
CB
936 fret = EXIT_SUCCESS;
937
9c61a6d6 938non_test_error:
8c582655 939 (void)unlink(tmpf);
df24d436 940 (void)rmdir(dirname(c->configfile));
9c61a6d6 941 lxc_container_put(c);
44ae0fb6 942 exit(fret);
9c61a6d6 943}