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