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