]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/parse_config_file.c
confile: lxc.rootfs --> lxc.rootfs.path
[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 /* REMOVE IN LXC 3.0
507 legacy lxc.rootfs key
508 */
509 if (set_get_compare_clear_save_load(c, "lxc.rootfs", "/some/path", tmpf,
510 true) < 0) {
511 lxc_error("%s\n", "lxc.rootfs");
512 goto non_test_error;
513 }
514
515 /* lxc.rootfs.path */
516 if (set_get_compare_clear_save_load(c, "lxc.rootfs.path", "/some/path", tmpf,
517 true) < 0) {
518 lxc_error("%s\n", "lxc.rootfs.path");
519 goto non_test_error;
520 }
521
522 /* lxc.rootfs.mount */
523 if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path",
524 tmpf, true) < 0) {
525 lxc_error("%s\n", "lxc.rootfs.mount");
526 goto non_test_error;
527 }
528
529 /* lxc.rootfs.options */
530 if (set_get_compare_clear_save_load(c, "lxc.rootfs.options",
531 "ext4,discard", tmpf, true) < 0) {
532 lxc_error("%s\n", "lxc.rootfs.options");
533 goto non_test_error;
534 }
535
536 /* REMOVE IN LXC 3.0
537 legacy lxc.utsname key
538 */
539 if (set_get_compare_clear_save_load(c, "lxc.utsname", "the-shire", tmpf,
540 true) < 0) {
541 lxc_error("%s\n", "lxc.utsname");
542 goto non_test_error;
543 }
544
545 /* lxc.uts.name */
546 if (set_get_compare_clear_save_load(c, "lxc.uts.name", "the-shire", tmpf,
547 true) < 0) {
548 lxc_error("%s\n", "lxc.uts.name");
549 goto non_test_error;
550 }
551
552 /* lxc.hook.pre-start */
553 if (set_get_compare_clear_save_load(
554 c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) {
555 lxc_error("%s\n", "lxc.hook.pre-start");
556 goto non_test_error;
557 }
558
559 /* lxc.hook.pre-mount */
560 if (set_get_compare_clear_save_load(
561 c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) {
562 lxc_error("%s\n", "lxc.hook.pre-mount");
563 goto non_test_error;
564 }
565
566 /* lxc.hook.mount */
567 if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount",
568 tmpf, false) < 0) {
569 lxc_error("%s\n", "lxc.hook.mount");
570 goto non_test_error;
571 }
572
573 /* lxc.hook.autodev */
574 if (set_get_compare_clear_save_load(c, "lxc.hook.autodev",
575 "/some/autodev", tmpf, false) < 0) {
576 lxc_error("%s\n", "lxc.hook.autodev");
577 goto non_test_error;
578 }
579
580 /* lxc.hook.start */
581 if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start",
582 tmpf, false) < 0) {
583 lxc_error("%s\n", "lxc.hook.start");
584 goto non_test_error;
585 }
586
587 /* lxc.hook.stop */
588 if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop",
589 tmpf, false) < 0) {
590 lxc_error("%s\n", "lxc.hook.stop");
591 goto non_test_error;
592 }
593
594 /* lxc.hook.post-stop */
595 if (set_get_compare_clear_save_load(
596 c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) {
597 lxc_error("%s\n", "lxc.hook.post-stop");
598 goto non_test_error;
599 }
600
601 /* lxc.hook.clone */
602 if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone",
603 tmpf, false) < 0) {
604 lxc_error("%s\n", "lxc.hook.clone");
605 goto non_test_error;
606 }
607
608 /* lxc.hook.destroy */
609 if (set_get_compare_clear_save_load(c, "lxc.hook.destroy",
610 "/some/destroy", tmpf, false) < 0) {
611 lxc_error("%s\n", "lxc.hook.destroy");
612 goto non_test_error;
613 }
614
615 /* lxc.cap.drop */
616 if (set_get_compare_clear_save_load(c, "lxc.cap.drop",
617 "sys_module mknod setuid net_raw",
618 tmpf, false) < 0) {
619 lxc_error("%s\n", "lxc.cap.drop");
620 goto non_test_error;
621 }
622
623 /* lxc.cap.keep */
624 if (set_get_compare_clear_save_load(c, "lxc.cap.keep",
625 "sys_module mknod setuid net_raw",
626 tmpf, false) < 0) {
627 lxc_error("%s\n", "lxc.cap.keep");
628 goto non_test_error;
629 }
630
631 /* lxc.console */
632 if (set_get_compare_clear_save_load(c, "lxc.console", "none", tmpf,
633 true) < 0) {
634 lxc_error("%s\n", "lxc.console");
635 goto non_test_error;
636 }
637
638 /* lxc.console.logfile */
639 if (set_get_compare_clear_save_load(c, "lxc.console.logfile",
640 "/some/logfile", tmpf, true) < 0) {
641 lxc_error("%s\n", "lxc.console.logfile");
642 goto non_test_error;
643 }
644
645 /* lxc.seccomp */
646 if (set_get_compare_clear_save_load(
647 c, "lxc.seccomp", "/some/seccomp/file", tmpf, true) < 0) {
648 lxc_error("%s\n", "lxc.seccomp");
649 goto non_test_error;
650 }
651
652 /* lxc.autodev */
653 if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
654 0) {
655 lxc_error("%s\n", "lxc.autodev");
656 goto non_test_error;
657 }
658
659 /* REMOVE IN LXC 3.0
660 legacy lxc.haltsignal key
661 */
662 if (set_get_compare_clear_save_load(c, "lxc.haltsignal", "1", tmpf,
663 true) < 0) {
664 lxc_error("%s\n", "lxc.haltsignal");
665 goto non_test_error;
666 }
667
668 /* lxc.signal.halt */
669 if (set_get_compare_clear_save_load(c, "lxc.signal.halt", "1", tmpf,
670 true) < 0) {
671 lxc_error("%s\n", "lxc.signal.halt");
672 goto non_test_error;
673 }
674
675 /* REMOVE IN LXC 3.0
676 legacy lxc.rebootsignal key
677 */
678 if (set_get_compare_clear_save_load(c, "lxc.rebootsignal", "1", tmpf,
679 true) < 0) {
680 lxc_error("%s\n", "lxc.rebootsignal");
681 goto non_test_error;
682 }
683
684 /* lxc.signal.reboot */
685 if (set_get_compare_clear_save_load(c, "lxc.signal.reboot", "1", tmpf,
686 true) < 0) {
687 lxc_error("%s\n", "lxc.signal.reboot");
688 goto non_test_error;
689 }
690
691 /* REMOVE IN LXC 3.0
692 legacy lxc.stopsignal key
693 */
694 if (set_get_compare_clear_save_load(c, "lxc.stopsignal", "1", tmpf,
695 true) < 0) {
696 lxc_error("%s\n", "lxc.stopsignal");
697 goto non_test_error;
698 }
699
700 /* lxc.signal.stop */
701 if (set_get_compare_clear_save_load(c, "lxc.signal.stop", "1", tmpf,
702 true) < 0) {
703 lxc_error("%s\n", "lxc.signal.stop");
704 goto non_test_error;
705 }
706
707 /* lxc.start.auto */
708 if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf,
709 true) < 0) {
710 lxc_error("%s\n", "lxc.start.auto");
711 goto non_test_error;
712 }
713
714 /* lxc.start.delay */
715 if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf,
716 true) < 0) {
717 lxc_error("%s\n", "lxc.start.delay");
718 goto non_test_error;
719 }
720
721 /* lxc.start.order */
722 if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf,
723 true) < 0) {
724 lxc_error("%s\n", "lxc.start.order");
725 goto non_test_error;
726 }
727
728 /* lxc.log.syslog */
729 if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf,
730 true) < 0) {
731 lxc_error("%s\n", "lxc.log.syslog");
732 goto non_test_error;
733 }
734
735 /* lxc.utsname */
736 if (set_get_compare_clear_save_load(c, "lxc.utsname", "get-schwifty",
737 tmpf, true) < 0) {
738 lxc_error("%s\n", "lxc.utsname");
739 goto non_test_error;
740 }
741
742 /* lxc.monitor.unshare */
743 if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf,
744 true) < 0) {
745 lxc_error("%s\n", "lxc.monitor.unshare");
746 goto non_test_error;
747 }
748
749 /* lxc.group */
750 if (set_get_compare_clear_save_load(
751 c, "lxc.group", "some,container,groups", tmpf, false) < 0) {
752 lxc_error("%s\n", "lxc.group");
753 goto non_test_error;
754 }
755
756 /* lxc.environment */
757 if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR",
758 tmpf, false) < 0) {
759 lxc_error("%s\n", "lxc.environment");
760 goto non_test_error;
761 }
762
763 /* REMOVE IN LXC 3.0
764 legacy lxc.init_cmd key
765 */
766 if (set_get_compare_clear_save_load(c, "lxc.init_cmd", "/bin/bash",
767 tmpf, true) < 0) {
768 lxc_error("%s\n", "lxc.init_cmd");
769 goto non_test_error;
770 }
771
772 /* lxc.init.cmd */
773 if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash",
774 tmpf, true) < 0) {
775 lxc_error("%s\n", "lxc.init.cmd");
776 goto non_test_error;
777 }
778
779 /* REMOVE IN LXC 3.0
780 legacy lxc.init_uid key
781 */
782 if (set_get_compare_clear_save_load(c, "lxc.init_uid", "1000", tmpf,
783 true) < 0) {
784 lxc_error("%s\n", "lxc.init_uid");
785 goto non_test_error;
786 }
787
788 /* lxc.init.uid */
789 if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf,
790 true) < 0) {
791 lxc_error("%s\n", "lxc.init.uid");
792 goto non_test_error;
793 }
794
795 /* REMOVE IN LXC 3.0
796 legacy lxc.init_gid key
797 */
798 if (set_get_compare_clear_save_load(c, "lxc.init_gid", "1000", tmpf,
799 true) < 0) {
800 lxc_error("%s\n", "lxc.init_gid");
801 goto non_test_error;
802 }
803
804 /* lxc.init.gid */
805 if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf,
806 true) < 0) {
807 lxc_error("%s\n", "lxc.init.gid");
808 goto non_test_error;
809 }
810
811 /* lxc.ephemeral */
812 if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf,
813 true) < 0) {
814 lxc_error("%s\n", "lxc.ephemeral");
815 goto non_test_error;
816 }
817
818 /* lxc.no_new_privs */
819 if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf,
820 true) < 0) {
821 lxc_error("%s\n", "lxc.no_new_privs");
822 goto non_test_error;
823 }
824
825 /* REMOVE IN LXC 3.0
826 legacy lxc.limit.* key
827 */
828 if (set_get_compare_clear_save_load(c, "lxc.limit.nofile", "65536",
829 tmpf, true) < 0) {
830 lxc_error("%s\n", "lxc.limit.nofile");
831 goto non_test_error;
832 }
833
834 /* lxc.prlimit.nofile */
835 if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536",
836 tmpf, true) < 0) {
837 lxc_error("%s\n", "lxc.prlimit.nofile");
838 goto non_test_error;
839 }
840
841 if (test_idmap_parser() < 0) {
842 lxc_error("%s\n", "failed to test parser for \"lxc.id_map\"");
843 goto non_test_error;
844 }
845
846 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth",
847 tmpf, true)) {
848 lxc_error("%s\n", "lxc.net.0.type");
849 goto non_test_error;
850 }
851
852 if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none",
853 tmpf, true)) {
854 lxc_error("%s\n", "lxc.net.2.type");
855 goto non_test_error;
856 }
857
858 if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty",
859 tmpf, true)) {
860 lxc_error("%s\n", "lxc.net.3.type");
861 goto non_test_error;
862 }
863
864 if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan",
865 tmpf, true)) {
866 lxc_error("%s\n", "lxc.net.4.type");
867 goto non_test_error;
868 }
869
870 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan",
871 tmpf, true)) {
872 lxc_error("%s\n", "lxc.net.0.type");
873 goto non_test_error;
874 }
875
876 if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys",
877 tmpf, true)) {
878 lxc_error("%s\n", "lxc.net.1000.type");
879 goto non_test_error;
880 }
881
882 if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up",
883 tmpf, true)) {
884 lxc_error("%s\n", "lxc.net.0.flags");
885 goto non_test_error;
886 }
887
888 if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0",
889 tmpf, true)) {
890 lxc_error("%s\n", "lxc.net.0.name");
891 goto non_test_error;
892 }
893
894 if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla",
895 tmpf, true)) {
896 lxc_error("%s\n", "lxc.net.0.link");
897 goto non_test_error;
898 }
899
900 if (set_get_compare_clear_save_load_network(
901 c, "lxc.net.0.macvlan.mode", "private", tmpf, true,
902 "macvlan")) {
903 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
904 goto non_test_error;
905 }
906
907 if (set_get_compare_clear_save_load_network(
908 c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true,
909 "macvlan")) {
910 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
911 goto non_test_error;
912 }
913
914 if (set_get_compare_clear_save_load_network(
915 c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true,
916 "macvlan")) {
917 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
918 goto non_test_error;
919 }
920
921 if (set_get_compare_clear_save_load_network(
922 c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true,
923 "veth")) {
924 lxc_error("%s\n", "lxc.net.0.veth.pair");
925 goto non_test_error;
926 }
927
928 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up",
929 "/some/up/path", tmpf, true)) {
930 lxc_error("%s\n", "lxc.net.0.script.up");
931 goto non_test_error;
932 }
933
934 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down",
935 "/some/down/path", tmpf, true)) {
936 lxc_error("%s\n", "lxc.net.0.script.down");
937 goto non_test_error;
938 }
939
940 if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr",
941 "52:54:00:80:7a:5d", tmpf, true)) {
942 lxc_error("%s\n", "lxc.net.0.hwaddr");
943 goto non_test_error;
944 }
945
946 if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000",
947 tmpf, true)) {
948 lxc_error("%s\n", "lxc.net.0.mtu");
949 goto non_test_error;
950 }
951
952 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id",
953 "2", tmpf, true, "vlan")) {
954 lxc_error("%s\n", "lxc.net.0.vlan.id");
955 goto non_test_error;
956 }
957
958 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway",
959 "10.0.2.2", tmpf, true)) {
960 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
961 goto non_test_error;
962 }
963
964 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway",
965 "2003:db8:1::1", tmpf, true)) {
966 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
967 goto non_test_error;
968 }
969
970 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4",
971 "10.0.2.3/24", tmpf, true)) {
972 lxc_error("%s\n", "lxc.net.0.ipv4");
973 goto non_test_error;
974 }
975
976 if (set_get_compare_clear_save_load(
977 c, "lxc.net.0.ipv6", "2003:db8:1:0:214:1234:fe0b:3596/64",
978 tmpf, true)) {
979 lxc_error("%s\n", "lxc.net.0.ipv6");
980 goto non_test_error;
981 }
982
983 if (set_and_clear_complete_netdev(c) < 0) {
984 lxc_error("%s\n", "failed to clear whole network");
985 goto non_test_error;
986 }
987
988 ret = EXIT_SUCCESS;
989 non_test_error:
990 (void)unlink(tmpf);
991 c->destroy(c);
992 lxc_container_put(c);
993 exit(ret);
994 }