]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/parse_config_file.c
tests: fix parse_config_file seccomp test
[mirror_lxc.git] / src / tests / parse_config_file.c
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 */
19
20 #include "config.h"
21
22 #include <lxc/lxccontainer.h>
23
24 #include <errno.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/types.h>
30 #include <sys/wait.h>
31 #include <unistd.h>
32 #include <libgen.h>
33
34 #include "conf.h"
35 #include "confile_utils.h"
36 #include "state.h"
37 #include "lxctest.h"
38 #include "utils.h"
39
40 static 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)
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
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
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
91 c->clear_config(c);
92 c->lxc_conf = NULL;
93
94 return 0;
95 }
96
97 static int set_and_clear_complete_netdev(struct lxc_container *c)
98 {
99 if (!c->set_config_item(c, "lxc.net.1.type", "veth")) {
100 lxc_error("%s\n", "lxc.net.1.type");
101 return -1;
102 }
103
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");
106 return -1;
107 }
108
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");
111 return -1;
112 }
113
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
124 if (!c->set_config_item(c, "lxc.net.1.ipv6.address",
125 "2003:db8:1:0:214:1234:fe0b:3596/64")) {
126 lxc_error("%s\n", "lxc.net.1.ipv6.address");
127 return -1;
128 }
129
130 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway",
131 "2003:db8:1:0::1")) {
132 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
133 return -1;
134 }
135
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
146 if (!c->set_config_item(c, "lxc.net.1.flags", "up")) {
147 lxc_error("%s\n", "lxc.net.1.flags");
148 return -1;
149 }
150
151 if (!c->set_config_item(c, "lxc.net.1.link", "br0")) {
152 lxc_error("%s\n", "lxc.net.1.link");
153 return -1;
154 }
155
156 if (!c->set_config_item(c, "lxc.net.1.veth.pair", "bla")) {
157 lxc_error("%s\n", "lxc.net.1.veth.pair");
158 return -1;
159 }
160
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
171 if (!c->set_config_item(c, "lxc.net.1.hwaddr",
172 "52:54:00:80:7a:5d")) {
173 lxc_error("%s\n", "lxc.net.1.hwaddr");
174 return -1;
175 }
176
177 if (!c->set_config_item(c, "lxc.net.1.mtu", "2000")) {
178 lxc_error("%s\n", "lxc.net.1.mtu");
179 return -1;
180 }
181
182 if (!c->clear_config_item(c, "lxc.net.1")) {
183 lxc_error("%s", "failed to clear \"lxc.net.1\"\n");
184 return -1;
185 }
186
187 c->clear_config(c);
188 c->lxc_conf = NULL;
189
190 return 0;
191 }
192
193 static 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
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
209 c->clear_config(c);
210 c->lxc_conf = NULL;
211
212 return 0;
213 }
214
215 int 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[] = {
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 " },
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
266 static 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
273 if (!c->set_config_item(c, "lxc.net.0.type", network_type)) {
274 lxc_error("%s\n", "lxc.net.0.type");
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
321 if (!c->clear_config_item(c, "lxc.net.0.type")) {
322 lxc_error("%s\n", "lxc.net.0.type");
323 return -1;
324 }
325
326 c->clear_config(c);
327 c->lxc_conf = NULL;
328
329 return 0;
330 }
331
332 int main(int argc, char *argv[])
333 {
334 int ret;
335 struct lxc_container *c;
336 int fd = -1, fret = EXIT_FAILURE;
337 char tmpf[] = "lxc-parse-config-file-XXXXXX";
338 char retval[4096] = {0};
339
340 fd = lxc_make_tmpfile(tmpf, false);
341 if (fd < 0) {
342 lxc_error("%s\n", "Could not create temporary file");
343 exit(fret);
344 }
345 close(fd);
346
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 }
352
353 if (set_get_compare_clear_save_load(c, "lxc.arch", "x86_64", tmpf,
354 true) < 0) {
355 lxc_error("%s\n", "lxc.arch");
356 goto non_test_error;
357 }
358
359 if (set_get_compare_clear_save_load(c, "lxc.pty.max", "1000", tmpf, true) < 0) {
360 lxc_error("%s\n", "lxc.pty.max");
361 goto non_test_error;
362 }
363
364 if (set_get_compare_clear_save_load(c, "lxc.tty.max", "4", tmpf, true) < 0) {
365 lxc_error("%s\n", "lxc.tty.max");
366 goto non_test_error;
367 }
368
369 if (set_get_compare_clear_save_load(c, "lxc.tty.dir", "not-dev", tmpf, true) < 0) {
370 lxc_error("%s\n", "lxc.tty.dir");
371 goto non_test_error;
372 }
373
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 {
381 lxc_error("%s\n", "lxc.apparmor.profile");
382 goto non_test_error;
383 }
384
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 {
392 lxc_error("%s\n", "lxc.apparmor.allow_incomplete");
393 goto non_test_error;
394 }
395
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 {
403 lxc_error("%s\n", "lxc.selinux.context");
404 goto non_test_error;
405 }
406
407 if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus",
408 "1-100", tmpf, false) < 0) {
409 lxc_error("%s\n", "lxc.cgroup.cpuset.cpus");
410 goto non_test_error;
411 }
412
413 if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) {
414 lxc_error("%s\n", "failed to set config item \"lxc.cgroup.cpuset.cpus\" to \"1-100\"");
415 return -1;
416 }
417
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\"");
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
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 */
436 if (set_get_compare_clear_save_load(c, "lxc.idmap", "u 0 100000 1000000000", NULL, false) < 0) {
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")) {
442 lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"u 1 100000 10000000\"");
443 return -1;
444 }
445
446 if (!c->set_config_item(c, "lxc.idmap", "g 1 100000 10000000")) {
447 lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"g 1 100000 10000000\"");
448 return -1;
449 }
450
451 if (!c->get_config_item(c, "lxc.idmap", retval, sizeof(retval))) {
452 lxc_error("%s\n", "failed to get config item \"lxc.idmap\"");
453 return -1;
454 }
455
456 c->clear_config(c);
457 c->lxc_conf = NULL;
458
459 if (set_get_compare_clear_save_load(c, "lxc.log.level", "DEBUG", tmpf, true) < 0) {
460 lxc_error("%s\n", "lxc.log.level");
461 goto non_test_error;
462 }
463
464 if (set_get_compare_clear_save_load(c, "lxc.log.file", "/some/path", tmpf, true) < 0) {
465 lxc_error("%s\n", "lxc.log.file");
466 goto non_test_error;
467 }
468
469 if (set_get_compare_clear_save_load(c, "lxc.mount.fstab", "/some/path", NULL, true) < 0) {
470 lxc_error("%s\n", "lxc.mount.fstab");
471 goto non_test_error;
472 }
473
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 */
478 if (set_get_compare_clear_save_load(c, "lxc.mount.auto", "proc:rw sys:rw cgroup-full:rw", tmpf, false) < 0) {
479 lxc_error("%s\n", "lxc.mount.auto");
480 goto non_test_error;
481 }
482
483 /* lxc.mount.entry
484 * Note that we cannot compare the values since the getter for
485 * lxc.mount.entry appends newlines.
486 */
487 if (set_get_compare_clear_save_load(c, "lxc.mount.entry", "/dev/dri dev/dri none bind,optional,create=dir", tmpf, false) < 0) {
488 lxc_error("%s\n", "lxc.mount.entry");
489 goto non_test_error;
490 }
491
492 if (set_get_compare_clear_save_load(c, "lxc.rootfs.path", "/some/path", tmpf, true) < 0) {
493 lxc_error("%s\n", "lxc.rootfs.path");
494 goto non_test_error;
495 }
496
497 if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path", tmpf, true) < 0) {
498 lxc_error("%s\n", "lxc.rootfs.mount");
499 goto non_test_error;
500 }
501
502 if (set_get_compare_clear_save_load(c, "lxc.rootfs.options", "ext4,discard", tmpf, true) < 0) {
503 lxc_error("%s\n", "lxc.rootfs.options");
504 goto non_test_error;
505 }
506
507 if (set_get_compare_clear_save_load(c, "lxc.uts.name", "the-shire", tmpf, true) < 0) {
508 lxc_error("%s\n", "lxc.uts.name");
509 goto non_test_error;
510 }
511
512 if (set_get_compare_clear_save_load(
513 c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) {
514 lxc_error("%s\n", "lxc.hook.pre-start");
515 goto non_test_error;
516 }
517
518 if (set_get_compare_clear_save_load(
519 c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) {
520 lxc_error("%s\n", "lxc.hook.pre-mount");
521 goto non_test_error;
522 }
523
524 if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount", tmpf, false) < 0) {
525 lxc_error("%s\n", "lxc.hook.mount");
526 goto non_test_error;
527 }
528
529 if (set_get_compare_clear_save_load(c, "lxc.hook.autodev", "/some/autodev", tmpf, false) < 0) {
530 lxc_error("%s\n", "lxc.hook.autodev");
531 goto non_test_error;
532 }
533
534 if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start", tmpf, false) < 0) {
535 lxc_error("%s\n", "lxc.hook.start");
536 goto non_test_error;
537 }
538
539 if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop", tmpf, false) < 0) {
540 lxc_error("%s\n", "lxc.hook.stop");
541 goto non_test_error;
542 }
543
544 if (set_get_compare_clear_save_load(c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) {
545 lxc_error("%s\n", "lxc.hook.post-stop");
546 goto non_test_error;
547 }
548
549 if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone", tmpf, false) < 0) {
550 lxc_error("%s\n", "lxc.hook.clone");
551 goto non_test_error;
552 }
553
554 if (set_get_compare_clear_save_load(c, "lxc.hook.destroy", "/some/destroy", tmpf, false) < 0) {
555 lxc_error("%s\n", "lxc.hook.destroy");
556 goto non_test_error;
557 }
558
559 if (set_get_compare_clear_save_load(c, "lxc.cap.drop", "sys_module mknod setuid net_raw", tmpf, false) < 0) {
560 lxc_error("%s\n", "lxc.cap.drop");
561 goto non_test_error;
562 }
563
564 if (set_get_compare_clear_save_load(c, "lxc.cap.keep", "sys_module mknod setuid net_raw", tmpf, false) < 0) {
565 lxc_error("%s\n", "lxc.cap.keep");
566 goto non_test_error;
567 }
568
569 if (set_get_compare_clear_save_load(c, "lxc.console.path", "none", tmpf, true) < 0) {
570 lxc_error("%s\n", "lxc.console.path");
571 goto non_test_error;
572 }
573
574 if (set_get_compare_clear_save_load(c, "lxc.console.logfile", "/some/logfile", tmpf, true) < 0) {
575 lxc_error("%s\n", "lxc.console.logfile");
576 goto non_test_error;
577 }
578
579 ret = set_get_compare_clear_save_load(c, "lxc.seccomp.profile", "/some/seccomp/file", tmpf, true);
580
581 #if HAVE_SECCOMP
582 if (ret < 0)
583 #else
584 if (ret == 0)
585 #endif
586 {
587 lxc_error("%s\n", "lxc.seccomp.profile");
588 goto non_test_error;
589 }
590
591 if (set_get_compare_clear_save_load(c, "lxc.autodev.tmpfs.size", "1", tmpf, true) < 0) {
592 lxc_error("%s\n", "lxc.autodev.tmpfs.size");
593 goto non_test_error;
594 }
595
596 if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
597 0) {
598 lxc_error("%s\n", "lxc.autodev");
599 goto non_test_error;
600 }
601
602 if (set_get_compare_clear_save_load(c, "lxc.signal.halt", "1", tmpf, true) < 0) {
603 lxc_error("%s\n", "lxc.signal.halt");
604 goto non_test_error;
605 }
606
607 if (set_get_compare_clear_save_load(c, "lxc.signal.reboot", "1", tmpf, true) < 0) {
608 lxc_error("%s\n", "lxc.signal.reboot");
609 goto non_test_error;
610 }
611
612 if (set_get_compare_clear_save_load(c, "lxc.signal.stop", "1", tmpf, true) < 0) {
613 lxc_error("%s\n", "lxc.signal.stop");
614 goto non_test_error;
615 }
616
617 if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf, true) < 0) {
618 lxc_error("%s\n", "lxc.start.auto");
619 goto non_test_error;
620 }
621
622 if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf, true) < 0) {
623 lxc_error("%s\n", "lxc.start.delay");
624 goto non_test_error;
625 }
626
627 if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf, true) < 0) {
628 lxc_error("%s\n", "lxc.start.order");
629 goto non_test_error;
630 }
631
632 if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf, true) < 0) {
633 lxc_error("%s\n", "lxc.log.syslog");
634 goto non_test_error;
635 }
636
637 if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf, true) < 0) {
638 lxc_error("%s\n", "lxc.monitor.unshare");
639 goto non_test_error;
640 }
641
642 if (set_get_compare_clear_save_load(c, "lxc.group", "some,container,groups", tmpf, false) < 0) {
643 lxc_error("%s\n", "lxc.group");
644 goto non_test_error;
645 }
646
647 if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR", tmpf, false) < 0) {
648 lxc_error("%s\n", "lxc.environment");
649 goto non_test_error;
650 }
651
652 if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash", tmpf, true) < 0) {
653 lxc_error("%s\n", "lxc.init.cmd");
654 goto non_test_error;
655 }
656
657 if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf, true) < 0) {
658 lxc_error("%s\n", "lxc.init.uid");
659 goto non_test_error;
660 }
661
662 if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf, true) < 0) {
663 lxc_error("%s\n", "lxc.init.gid");
664 goto non_test_error;
665 }
666
667 if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf, true) < 0) {
668 lxc_error("%s\n", "lxc.ephemeral");
669 goto non_test_error;
670 }
671
672 if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf, true) < 0) {
673 lxc_error("%s\n", "lxc.no_new_privs");
674 goto non_test_error;
675 }
676
677 if (set_get_compare_clear_save_load(c, "lxc.sysctl.net.core.somaxconn", "256", tmpf, true) < 0) {
678 lxc_error("%s\n", "lxc.sysctl.net.core.somaxconn");
679 goto non_test_error;
680 }
681
682 if (set_get_compare_clear_save_load(c, "lxc.proc.oom_score_adj", "10", tmpf, true) < 0) {
683 lxc_error("%s\n", "lxc.proc.oom_score_adj");
684 goto non_test_error;
685 }
686
687 if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536", tmpf, true) < 0) {
688 lxc_error("%s\n", "lxc.prlimit.nofile");
689 goto non_test_error;
690 }
691
692 if (test_idmap_parser() < 0) {
693 lxc_error("%s\n", "failed to test parser for \"lxc.id_map\"");
694 goto non_test_error;
695 }
696
697 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth", tmpf, true)) {
698 lxc_error("%s\n", "lxc.net.0.type");
699 goto non_test_error;
700 }
701
702 if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none", tmpf, true)) {
703 lxc_error("%s\n", "lxc.net.2.type");
704 goto non_test_error;
705 }
706
707 if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty", tmpf, true)) {
708 lxc_error("%s\n", "lxc.net.3.type");
709 goto non_test_error;
710 }
711
712 if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan", tmpf, true)) {
713 lxc_error("%s\n", "lxc.net.4.type");
714 goto non_test_error;
715 }
716
717 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan", tmpf, true)) {
718 lxc_error("%s\n", "lxc.net.0.type");
719 goto non_test_error;
720 }
721
722 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "ipvlan", tmpf, true)) {
723 lxc_error("%s\n", "lxc.net.0.type");
724 goto non_test_error;
725 }
726
727 if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys", tmpf, true)) {
728 lxc_error("%s\n", "lxc.net.1000.type");
729 goto non_test_error;
730 }
731
732 if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up", tmpf, true)) {
733 lxc_error("%s\n", "lxc.net.0.flags");
734 goto non_test_error;
735 }
736
737 if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0", tmpf, true)) {
738 lxc_error("%s\n", "lxc.net.0.name");
739 goto non_test_error;
740 }
741
742 if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla", tmpf, true)) {
743 lxc_error("%s\n", "lxc.net.0.link");
744 goto non_test_error;
745 }
746
747 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "private", tmpf, true, "macvlan")) {
748 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
749 goto non_test_error;
750 }
751
752 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true, "macvlan")) {
753 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
754 goto non_test_error;
755 }
756
757 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true, "macvlan")) {
758 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
759 goto non_test_error;
760 }
761
762 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l3", tmpf, true, "ipvlan")) {
763 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
764 goto non_test_error;
765 }
766
767 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l3s", tmpf, true, "ipvlan")) {
768 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
769 goto non_test_error;
770 }
771
772 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l2", tmpf, true, "ipvlan")) {
773 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
774 goto non_test_error;
775 }
776
777 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "bridge", tmpf, true, "ipvlan")) {
778 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
779 goto non_test_error;
780 }
781
782 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "private", tmpf, true, "ipvlan")) {
783 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
784 goto non_test_error;
785 }
786
787 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "vepa", tmpf, true, "ipvlan")) {
788 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
789 goto non_test_error;
790 }
791
792 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true, "veth")) {
793 lxc_error("%s\n", "lxc.net.0.veth.pair");
794 goto non_test_error;
795 }
796
797 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.ipv4.route", "192.0.2.1/32", tmpf, true, "veth")) {
798 lxc_error("%s\n", "lxc.net.0.veth.ipv4.route");
799 return -1;
800 }
801
802 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.ipv6.route", "2001:db8::1/128", tmpf, true, "veth")) {
803 lxc_error("%s\n", "lxc.net.0.veth.ipv6.route");
804 return -1;
805 }
806
807 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.vlan.id", "none", tmpf, false, "veth")) {
808 lxc_error("%s\n", "lxc.net.0.veth.vlan.id");
809 return -1;
810 }
811
812 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.vlan.id", "2", tmpf, true, "veth")) {
813 lxc_error("%s\n", "lxc.net.0.veth.vlan.id");
814 return -1;
815 }
816
817 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.vlan.tagged.id", "2", tmpf, true, "veth")) {
818 lxc_error("%s\n", "lxc.net.0.veth.vlan.tagged.id");
819 return -1;
820 }
821
822 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up", "/some/up/path", tmpf, true)) {
823 lxc_error("%s\n", "lxc.net.0.script.up");
824 goto non_test_error;
825 }
826
827 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down", "/some/down/path", tmpf, true)) {
828 lxc_error("%s\n", "lxc.net.0.script.down");
829 goto non_test_error;
830 }
831
832 if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr", "52:54:00:80:7a:5d", tmpf, true)) {
833 lxc_error("%s\n", "lxc.net.0.hwaddr");
834 goto non_test_error;
835 }
836
837 if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000", tmpf, true)) {
838 lxc_error("%s\n", "lxc.net.0.mtu");
839 goto non_test_error;
840 }
841
842 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id", "2", tmpf, true, "vlan")) {
843 lxc_error("%s\n", "lxc.net.0.vlan.id");
844 goto non_test_error;
845 }
846
847 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "10.0.2.2", tmpf, true)) {
848 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
849 goto non_test_error;
850 }
851
852 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "auto", tmpf, true)) {
853 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
854 goto non_test_error;
855 }
856
857 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "dev", tmpf, true)) {
858 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
859 goto non_test_error;
860 }
861
862 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "2003:db8:1::1", tmpf, true)) {
863 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
864 goto non_test_error;
865 }
866
867 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "auto", tmpf, true)) {
868 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
869 goto non_test_error;
870 }
871
872 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "dev", tmpf, true)) {
873 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
874 goto non_test_error;
875 }
876
877 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.address", "10.0.2.3/24", tmpf, true)) {
878 lxc_error("%s\n", "lxc.net.0.ipv4.address");
879 goto non_test_error;
880 }
881
882 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.address", "2003:db8:1:0:214:1234:fe0b:3596/64", tmpf, true)) {
883 lxc_error("%s\n", "lxc.net.0.ipv6.address");
884 goto non_test_error;
885 }
886
887 if (set_get_compare_clear_save_load(c, "lxc.cgroup.dir", "lxd", tmpf, true)) {
888 lxc_error("%s\n", "lxc.cgroup.dir");
889 goto non_test_error;
890 }
891
892 if (set_and_clear_complete_netdev(c) < 0) {
893 lxc_error("%s\n", "failed to clear whole network");
894 goto non_test_error;
895 }
896
897 if (set_invalid_netdev(c) < 0) {
898 lxc_error("%s\n", "failed to reject invalid configuration");
899 goto non_test_error;
900 }
901
902 ret = set_get_compare_clear_save_load(c, "lxc.hook.version", "1", tmpf, true);
903 if (ret < 0) {
904 lxc_error("%s\n", "lxc.hook.version");
905 goto non_test_error;
906 }
907
908 if (c->set_config_item(c, "lxc.hook.version", "2")) {
909 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.hook.version\" to \"2\"");
910 goto non_test_error;
911 }
912
913 if (!c->set_config_item(c, "lxc.monitor.signal.pdeath", "SIGKILL")) {
914 lxc_error("%s\n", "Failed to set to set invalid config item \"lxc.monitor.signal.pdeath\" to \"SIGKILL\"");
915 goto non_test_error;
916 }
917
918 if (set_get_compare_clear_save_load(c, "lxc.rootfs.managed", "1", tmpf, true) < 0) {
919 lxc_error("%s\n", "lxc.rootfs.managed");
920 goto non_test_error;
921 }
922
923 if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
924 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.notaconfigkey\" to \"invalid\"");
925 return -1;
926 }
927
928 if (c->set_config_item(c, "lxc.log.file=", "./")) {
929 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.log.file\" to \"./\"");
930 return -1;
931 }
932
933 if (c->set_config_item(c, "lxc.hook.versionasdfsadfsadf", "1")) {
934 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.hook.versionasdfsadfsadf\" to \"2\"");
935 goto non_test_error;
936 }
937
938 if (set_get_compare_clear_save_load(c, "lxc.sched.core", "1", tmpf, true) < 0) {
939 lxc_error("%s\n", "lxc.sched.core");
940 goto non_test_error;
941 }
942
943 fret = EXIT_SUCCESS;
944
945 non_test_error:
946 (void)unlink(tmpf);
947 (void)rmdir(dirname(c->configfile));
948 lxc_container_put(c);
949 exit(fret);
950 }