]> git.ozlabs.org Git - petitboot/blob - lib/pb-config/pb-config.c
discover/grub2: Fix handling of positional parameters
[petitboot] / lib / pb-config / pb-config.c
1
2 #include <string.h>
3
4 #include <log/log.h>
5 #include <types/types.h>
6 #include <talloc/talloc.h>
7
8 #include "pb-config.h"
9
10 static struct interface_config *config_copy_interface(struct config *ctx,
11                 struct interface_config *src)
12 {
13         struct interface_config *dest = talloc(ctx, struct interface_config);
14
15         memcpy(dest->hwaddr, src->hwaddr, sizeof(src->hwaddr));
16         dest->ignore = src->ignore;
17
18         if (dest->ignore)
19                 return dest;
20
21         dest->method = src->method;
22
23         switch (src->method) {
24         case CONFIG_METHOD_DHCP:
25                 break;
26         case CONFIG_METHOD_STATIC:
27                 dest->static_config.address =
28                         talloc_strdup(dest, src->static_config.address);
29                 dest->static_config.gateway =
30                         talloc_strdup(dest, src->static_config.gateway);
31                 break;
32         }
33
34         return dest;
35 }
36
37 struct config *config_copy(void *ctx, const struct config *src)
38 {
39         struct config *dest;
40         unsigned int i;
41
42         dest = talloc(ctx, struct config);
43         dest->autoboot_enabled = src->autoboot_enabled;
44         dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
45         dest->safe_mode = src->safe_mode;
46
47         dest->network.n_interfaces = src->network.n_interfaces;
48         dest->network.interfaces = talloc_array(dest, struct interface_config *,
49                                         dest->network.n_interfaces);
50         dest->network.n_dns_servers = src->network.n_dns_servers;
51         dest->network.dns_servers = talloc_array(dest, const char *,
52                                         dest->network.n_dns_servers);
53
54         for (i = 0; i < src->network.n_interfaces; i++)
55                 dest->network.interfaces[i] = config_copy_interface(dest,
56                                 src->network.interfaces[i]);
57
58         for (i = 0; i < src->network.n_dns_servers; i++)
59                 dest->network.dns_servers[i] = talloc_strdup(dest,
60                                 src->network.dns_servers[i]);
61
62         dest->n_autoboot_opts = src->n_autoboot_opts;
63         dest->autoboot_opts = talloc_array(dest, struct autoboot_option,
64                                         dest->n_autoboot_opts);
65
66         for (i = 0; i < src->n_autoboot_opts; i++) {
67                 dest->autoboot_opts[i].boot_type =
68                         src->autoboot_opts[i].boot_type;
69                 if (src->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
70                         dest->autoboot_opts[i].type =
71                                 src->autoboot_opts[i].type;
72                 else
73                         dest->autoboot_opts[i].uuid =
74                                 talloc_strdup(dest, src->autoboot_opts[i].uuid);
75         }
76
77         dest->ipmi_bootdev = src->ipmi_bootdev;
78         dest->ipmi_bootdev_persistent = src->ipmi_bootdev_persistent;
79
80         dest->allow_writes = src->allow_writes;
81
82         if (src->lang && strlen(src->lang))
83                 dest->lang = talloc_strdup(dest, src->lang);
84         else
85                 dest->lang = NULL;
86
87         return dest;
88 }