]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/parse_config_file.c
confile: remove lxc.kmsg
[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 /* lxc.devttydir */
318 if (set_get_compare_clear_save_load(c, "lxc.devttydir", "not-dev", tmpf,
319 true) < 0) {
320 lxc_error("%s\n", "lxc.devttydir");
321 goto non_test_error;
322 }
323
324 /* REMOVE IN LXC 3.0
325 legacy security keys
326 */
327 if (set_get_compare_clear_save_load(c, "lxc.aa_profile", "unconfined",
328 tmpf, true) < 0) {
329 lxc_error("%s\n", "lxc.aa_profile");
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_allow_incomplete", "1",
337 tmpf, true) < 0) {
338 lxc_error("%s\n", "lxc.aa_allow_incomplete");
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.se_context", "system_u:system_r:lxc_t:s0:c22",
346 tmpf, true) < 0) {
347 lxc_error("%s\n", "lxc.apparmor.se_context");
348 goto non_test_error;
349 }
350
351 /* lxc.apparmor.profile */
352 if (set_get_compare_clear_save_load(c, "lxc.apparmor.profile", "unconfined",
353 tmpf, true) < 0) {
354 lxc_error("%s\n", "lxc.apparmor.profile");
355 goto non_test_error;
356 }
357
358 /* lxc.apparmor.allow_incomplete */
359 if (set_get_compare_clear_save_load(c, "lxc.apparmor.allow_incomplete", "1",
360 tmpf, true) < 0) {
361 lxc_error("%s\n", "lxc.apparmor.allow_incomplete");
362 goto non_test_error;
363 }
364
365 /* lxc.selinux.context */
366 if (set_get_compare_clear_save_load(c, "lxc.selinux.context", "system_u:system_r:lxc_t:s0:c22",
367 tmpf, true) < 0) {
368 lxc_error("%s\n", "lxc.apparmor.selinux.context");
369 goto non_test_error;
370 }
371
372 /* lxc.cgroup.cpuset.cpus */
373 if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus",
374 "1-100", tmpf, false) < 0) {
375 lxc_error("%s\n", "lxc.cgroup.cpuset.cpus");
376 goto non_test_error;
377 }
378
379 /* lxc.cgroup */
380 if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) {
381 lxc_error("%s\n", "failed to set config item "
382 "\"lxc.cgroup.cpuset.cpus\" to \"1-100\"");
383 return -1;
384 }
385
386 if (!c->set_config_item(c, "lxc.cgroup.memory.limit_in_bytes",
387 "123456789")) {
388 lxc_error(
389 "%s\n",
390 "failed to set config item "
391 "\"lxc.cgroup.memory.limit_in_bytes\" to \"123456789\"");
392 return -1;
393 }
394
395 if (!c->get_config_item(c, "lxc.cgroup", retval, sizeof(retval))) {
396 lxc_error("%s\n", "failed to get config item \"lxc.cgroup\"");
397 return -1;
398 }
399
400 c->clear_config(c);
401 c->lxc_conf = NULL;
402
403 /* lxc.id_map
404 * We can't really save the config here since save_config() wants to
405 * chown the container's directory but we haven't created an on-disk
406 * container. So let's test set-get-clear.
407 */
408 if (set_get_compare_clear_save_load(
409 c, "lxc.id_map", "u 0 100000 1000000000", NULL, false) < 0) {
410 lxc_error("%s\n", "lxc.id_map");
411 goto non_test_error;
412 }
413
414 if (!c->set_config_item(c, "lxc.id_map", "u 1 100000 10000000")) {
415 lxc_error("%s\n", "failed to set config item "
416 "\"lxc.id_map\" to \"u 1 100000 10000000\"");
417 return -1;
418 }
419
420 if (!c->set_config_item(c, "lxc.id_map", "g 1 100000 10000000")) {
421 lxc_error("%s\n", "failed to set config item "
422 "\"lxc.id_map\" to \"g 1 100000 10000000\"");
423 return -1;
424 }
425
426 if (!c->get_config_item(c, "lxc.id_map", retval, sizeof(retval))) {
427 lxc_error("%s\n", "failed to get config item \"lxc.cgroup\"");
428 return -1;
429 }
430
431 c->clear_config(c);
432 c->lxc_conf = NULL;
433
434 /* lxc.loglevel */
435 if (set_get_compare_clear_save_load(c, "lxc.loglevel", "DEBUG", tmpf,
436 true) < 0) {
437 lxc_error("%s\n", "lxc.loglevel");
438 goto non_test_error;
439 }
440
441 /* lxc.logfile */
442 if (set_get_compare_clear_save_load(c, "lxc.logfile", "/some/path",
443 tmpf, true) < 0) {
444 lxc_error("%s\n", "lxc.logfile");
445 goto non_test_error;
446 }
447
448 /* lxc.mount */
449 if (set_get_compare_clear_save_load(c, "lxc.mount", "/some/path", NULL,
450 true) < 0) {
451 lxc_error("%s\n", "lxc.mount");
452 goto non_test_error;
453 }
454
455 /* lxc.mount.auto
456 * Note that we cannot compare the values since the getter for
457 * lxc.mount.auto does not preserve ordering.
458 */
459 if (set_get_compare_clear_save_load(c, "lxc.mount.auto",
460 "proc:rw sys:rw cgroup-full:rw",
461 tmpf, false) < 0) {
462 lxc_error("%s\n", "lxc.mount.auto");
463 goto non_test_error;
464 }
465
466 /* lxc.mount.entry
467 * Note that we cannot compare the values since the getter for
468 * lxc.mount.entry appends newlines.
469 */
470 if (set_get_compare_clear_save_load(
471 c, "lxc.mount.entry",
472 "/dev/dri dev/dri none bind,optional,create=dir", tmpf,
473 false) < 0) {
474 lxc_error("%s\n", "lxc.mount.entry");
475 goto non_test_error;
476 }
477
478 /* lxc.rootfs */
479 if (set_get_compare_clear_save_load(c, "lxc.rootfs", "/some/path", tmpf,
480 true) < 0) {
481 lxc_error("%s\n", "lxc.rootfs");
482 goto non_test_error;
483 }
484
485 /* lxc.rootfs.mount */
486 if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path",
487 tmpf, true) < 0) {
488 lxc_error("%s\n", "lxc.rootfs.mount");
489 goto non_test_error;
490 }
491
492 /* lxc.rootfs.options */
493 if (set_get_compare_clear_save_load(c, "lxc.rootfs.options",
494 "ext4,discard", tmpf, true) < 0) {
495 lxc_error("%s\n", "lxc.rootfs.options");
496 goto non_test_error;
497 }
498
499 /* lxc.rootfs.backend */
500 if (set_get_compare_clear_save_load(c, "lxc.rootfs.backend", "btrfs",
501 tmpf, true) < 0) {
502 lxc_error("%s\n", "lxc.rootfs.backend");
503 goto non_test_error;
504 }
505
506 /* lxc.utsname */
507 if (set_get_compare_clear_save_load(c, "lxc.utsname", "the-shire", tmpf,
508 true) < 0) {
509 lxc_error("%s\n", "lxc.utsname");
510 goto non_test_error;
511 }
512
513 /* lxc.hook.pre-start */
514 if (set_get_compare_clear_save_load(
515 c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) {
516 lxc_error("%s\n", "lxc.hook.pre-start");
517 goto non_test_error;
518 }
519
520 /* lxc.hook.pre-mount */
521 if (set_get_compare_clear_save_load(
522 c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) {
523 lxc_error("%s\n", "lxc.hook.pre-mount");
524 goto non_test_error;
525 }
526
527 /* lxc.hook.mount */
528 if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount",
529 tmpf, false) < 0) {
530 lxc_error("%s\n", "lxc.hook.mount");
531 goto non_test_error;
532 }
533
534 /* lxc.hook.autodev */
535 if (set_get_compare_clear_save_load(c, "lxc.hook.autodev",
536 "/some/autodev", tmpf, false) < 0) {
537 lxc_error("%s\n", "lxc.hook.autodev");
538 goto non_test_error;
539 }
540
541 /* lxc.hook.start */
542 if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start",
543 tmpf, false) < 0) {
544 lxc_error("%s\n", "lxc.hook.start");
545 goto non_test_error;
546 }
547
548 /* lxc.hook.stop */
549 if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop",
550 tmpf, false) < 0) {
551 lxc_error("%s\n", "lxc.hook.stop");
552 goto non_test_error;
553 }
554
555 /* lxc.hook.post-stop */
556 if (set_get_compare_clear_save_load(
557 c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) {
558 lxc_error("%s\n", "lxc.hook.post-stop");
559 goto non_test_error;
560 }
561
562 /* lxc.hook.clone */
563 if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone",
564 tmpf, false) < 0) {
565 lxc_error("%s\n", "lxc.hook.clone");
566 goto non_test_error;
567 }
568
569 /* lxc.hook.destroy */
570 if (set_get_compare_clear_save_load(c, "lxc.hook.destroy",
571 "/some/destroy", tmpf, false) < 0) {
572 lxc_error("%s\n", "lxc.hook.destroy");
573 goto non_test_error;
574 }
575
576 /* lxc.cap.drop */
577 if (set_get_compare_clear_save_load(c, "lxc.cap.drop",
578 "sys_module mknod setuid net_raw",
579 tmpf, false) < 0) {
580 lxc_error("%s\n", "lxc.cap.drop");
581 goto non_test_error;
582 }
583
584 /* lxc.cap.keep */
585 if (set_get_compare_clear_save_load(c, "lxc.cap.keep",
586 "sys_module mknod setuid net_raw",
587 tmpf, false) < 0) {
588 lxc_error("%s\n", "lxc.cap.keep");
589 goto non_test_error;
590 }
591
592 /* lxc.console */
593 if (set_get_compare_clear_save_load(c, "lxc.console", "none", tmpf,
594 true) < 0) {
595 lxc_error("%s\n", "lxc.console");
596 goto non_test_error;
597 }
598
599 /* lxc.console.logfile */
600 if (set_get_compare_clear_save_load(c, "lxc.console.logfile",
601 "/some/logfile", tmpf, true) < 0) {
602 lxc_error("%s\n", "lxc.console.logfile");
603 goto non_test_error;
604 }
605
606 /* lxc.seccomp */
607 if (set_get_compare_clear_save_load(
608 c, "lxc.seccomp", "/some/seccomp/file", tmpf, true) < 0) {
609 lxc_error("%s\n", "lxc.seccomp");
610 goto non_test_error;
611 }
612
613 /* lxc.autodev */
614 if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
615 0) {
616 lxc_error("%s\n", "lxc.autodev");
617 goto non_test_error;
618 }
619
620 /* lxc.haltsignal */
621 if (set_get_compare_clear_save_load(c, "lxc.haltsignal", "1", tmpf,
622 true) < 0) {
623 lxc_error("%s\n", "lxc.haltsignal");
624 goto non_test_error;
625 }
626
627 /* lxc.rebootsignal */
628 if (set_get_compare_clear_save_load(c, "lxc.rebootsignal", "1", tmpf,
629 true) < 0) {
630 lxc_error("%s\n", "lxc.rebootsignal");
631 goto non_test_error;
632 }
633
634 /* lxc.stopsignal */
635 if (set_get_compare_clear_save_load(c, "lxc.stopsignal", "1", tmpf,
636 true) < 0) {
637 lxc_error("%s\n", "lxc.stopsignal");
638 goto non_test_error;
639 }
640
641 /* lxc.start.auto */
642 if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf,
643 true) < 0) {
644 lxc_error("%s\n", "lxc.start.auto");
645 goto non_test_error;
646 }
647
648 /* lxc.start.delay */
649 if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf,
650 true) < 0) {
651 lxc_error("%s\n", "lxc.start.delay");
652 goto non_test_error;
653 }
654
655 /* lxc.start.order */
656 if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf,
657 true) < 0) {
658 lxc_error("%s\n", "lxc.start.order");
659 goto non_test_error;
660 }
661
662 /* lxc.syslog */
663 if (set_get_compare_clear_save_load(c, "lxc.syslog", "local0", tmpf,
664 true) < 0) {
665 lxc_error("%s\n", "lxc.syslog");
666 goto non_test_error;
667 }
668
669 /* lxc.utsname */
670 if (set_get_compare_clear_save_load(c, "lxc.utsname", "get-schwifty",
671 tmpf, true) < 0) {
672 lxc_error("%s\n", "lxc.utsname");
673 goto non_test_error;
674 }
675
676 /* lxc.monitor.unshare */
677 if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf,
678 true) < 0) {
679 lxc_error("%s\n", "lxc.monitor.unshare");
680 goto non_test_error;
681 }
682
683 /* lxc.group */
684 if (set_get_compare_clear_save_load(
685 c, "lxc.group", "some,container,groups", tmpf, false) < 0) {
686 lxc_error("%s\n", "lxc.group");
687 goto non_test_error;
688 }
689
690 /* lxc.environment */
691 if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR",
692 tmpf, false) < 0) {
693 lxc_error("%s\n", "lxc.environment");
694 goto non_test_error;
695 }
696
697 /* lxc.init_cmd */
698 if (set_get_compare_clear_save_load(c, "lxc.init_cmd", "/bin/bash",
699 tmpf, true) < 0) {
700 lxc_error("%s\n", "lxc.init_cmd");
701 goto non_test_error;
702 }
703
704 /* lxc.init_uid */
705 if (set_get_compare_clear_save_load(c, "lxc.init_uid", "1000", tmpf,
706 true) < 0) {
707 lxc_error("%s\n", "lxc.init_uid");
708 goto non_test_error;
709 }
710
711 /* lxc.init_gid */
712 if (set_get_compare_clear_save_load(c, "lxc.init_gid", "1000", tmpf,
713 true) < 0) {
714 lxc_error("%s\n", "lxc.init_gid");
715 goto non_test_error;
716 }
717
718 /* lxc.ephemeral */
719 if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf,
720 true) < 0) {
721 lxc_error("%s\n", "lxc.ephemeral");
722 goto non_test_error;
723 }
724
725 /* lxc.no_new_privs */
726 if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf,
727 true) < 0) {
728 lxc_error("%s\n", "lxc.no_new_privs");
729 goto non_test_error;
730 }
731
732 /* lxc.limit.nofile */
733 if (set_get_compare_clear_save_load(c, "lxc.limit.nofile", "65536",
734 tmpf, true) < 0) {
735 lxc_error("%s\n", "lxc.limit.nofile");
736 goto non_test_error;
737 }
738
739 if (test_idmap_parser() < 0) {
740 lxc_error("%s\n", "failed to test parser for \"lxc.id_map\"");
741 goto non_test_error;
742 }
743
744 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth",
745 tmpf, true)) {
746 lxc_error("%s\n", "lxc.net.0.type");
747 goto non_test_error;
748 }
749
750 if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none",
751 tmpf, true)) {
752 lxc_error("%s\n", "lxc.net.2.type");
753 goto non_test_error;
754 }
755
756 if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty",
757 tmpf, true)) {
758 lxc_error("%s\n", "lxc.net.3.type");
759 goto non_test_error;
760 }
761
762 if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan",
763 tmpf, true)) {
764 lxc_error("%s\n", "lxc.net.4.type");
765 goto non_test_error;
766 }
767
768 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan",
769 tmpf, true)) {
770 lxc_error("%s\n", "lxc.net.0.type");
771 goto non_test_error;
772 }
773
774 if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys",
775 tmpf, true)) {
776 lxc_error("%s\n", "lxc.net.1000.type");
777 goto non_test_error;
778 }
779
780 if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up",
781 tmpf, true)) {
782 lxc_error("%s\n", "lxc.net.0.flags");
783 goto non_test_error;
784 }
785
786 if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0",
787 tmpf, true)) {
788 lxc_error("%s\n", "lxc.net.0.name");
789 goto non_test_error;
790 }
791
792 if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla",
793 tmpf, true)) {
794 lxc_error("%s\n", "lxc.net.0.link");
795 goto non_test_error;
796 }
797
798 if (set_get_compare_clear_save_load_network(
799 c, "lxc.net.0.macvlan.mode", "private", tmpf, true,
800 "macvlan")) {
801 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
802 goto non_test_error;
803 }
804
805 if (set_get_compare_clear_save_load_network(
806 c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true,
807 "macvlan")) {
808 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
809 goto non_test_error;
810 }
811
812 if (set_get_compare_clear_save_load_network(
813 c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true,
814 "macvlan")) {
815 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
816 goto non_test_error;
817 }
818
819 if (set_get_compare_clear_save_load_network(
820 c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true,
821 "veth")) {
822 lxc_error("%s\n", "lxc.net.0.veth.pair");
823 goto non_test_error;
824 }
825
826 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up",
827 "/some/up/path", tmpf, true)) {
828 lxc_error("%s\n", "lxc.net.0.script.up");
829 goto non_test_error;
830 }
831
832 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down",
833 "/some/down/path", tmpf, true)) {
834 lxc_error("%s\n", "lxc.net.0.script.down");
835 goto non_test_error;
836 }
837
838 if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr",
839 "52:54:00:80:7a:5d", tmpf, true)) {
840 lxc_error("%s\n", "lxc.net.0.hwaddr");
841 goto non_test_error;
842 }
843
844 if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000",
845 tmpf, true)) {
846 lxc_error("%s\n", "lxc.net.0.mtu");
847 goto non_test_error;
848 }
849
850 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id",
851 "2", tmpf, true, "vlan")) {
852 lxc_error("%s\n", "lxc.net.0.vlan.id");
853 goto non_test_error;
854 }
855
856 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway",
857 "10.0.2.2", 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",
863 "2003:db8:1::1", tmpf, true)) {
864 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
865 goto non_test_error;
866 }
867
868 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4",
869 "10.0.2.3/24", tmpf, true)) {
870 lxc_error("%s\n", "lxc.net.0.ipv4");
871 goto non_test_error;
872 }
873
874 if (set_get_compare_clear_save_load(
875 c, "lxc.net.0.ipv6", "2003:db8:1:0:214:1234:fe0b:3596/64",
876 tmpf, true)) {
877 lxc_error("%s\n", "lxc.net.0.ipv6");
878 goto non_test_error;
879 }
880
881 if (set_and_clear_complete_netdev(c) < 0) {
882 lxc_error("%s\n", "failed to clear whole network");
883 goto non_test_error;
884 }
885
886 ret = EXIT_SUCCESS;
887 non_test_error:
888 (void)unlink(tmpf);
889 c->destroy(c);
890 lxc_container_put(c);
891 exit(ret);
892 }