|
0 |
#include <arpa/inet.h>
|
|
1 |
#include <ctype.h>
|
|
2 |
#include <errno.h>
|
|
3 |
#include <netinet/in.h>
|
|
4 |
#include <stdio.h>
|
|
5 |
#include <string.h>
|
|
6 |
#include <sys/socket.h>
|
|
7 |
#include <sys/stat.h>
|
|
8 |
|
|
9 |
#ifdef WIRELESS
|
|
10 |
#include <iwlib.h>
|
|
11 |
#endif
|
|
12 |
|
|
13 |
#include <debian-installer.h>
|
0 | 14 |
|
1 | 15 |
#include "nm-conf.h"
|
2 | |
#include <sys/stat.h>
|
3 | |
#include <errno.h>
|
4 | 16 |
|
5 | 17 |
/* Linux provides a lightweight facility that can generate UUIDs for us. */
|
6 | 18 |
static void get_uuid(char* target)
|
|
17 | 29 |
|
18 | 30 |
/* Functions for printing informations in Network Manager format. */
|
19 | 31 |
|
20 | |
void nm_write_connection(FILE *config_file, nm_connection connection)
|
|
32 |
static void nm_write_connection(FILE *config_file, nm_connection connection)
|
21 | 33 |
{
|
22 | 34 |
fprintf(config_file, "\n%s\n", NM_SETTINGS_CONNECTION);
|
23 | 35 |
fprintf(config_file, "id=%s\n", connection.id);
|
|
27 | 39 |
}
|
28 | 40 |
|
29 | 41 |
#ifdef WIRELESS
|
30 | |
void nm_write_wireless_specific_options(FILE *config_file,
|
|
42 |
static void nm_write_wireless_specific_options(FILE *config_file,
|
31 | 43 |
struct nm_config_info *nmconf)
|
32 | 44 |
{
|
33 | 45 |
nm_wireless wireless = nmconf->wireless;
|
|
46 | 58 |
}
|
47 | 59 |
#endif
|
48 | 60 |
|
49 | |
void nm_write_wired_specific_options(FILE *config_file,
|
|
61 |
static void nm_write_wired_specific_options(FILE *config_file,
|
50 | 62 |
struct nm_config_info *nmconf)
|
51 | 63 |
{
|
52 | 64 |
nm_wired wired = nmconf->wired;
|
|
59 | 71 |
}
|
60 | 72 |
|
61 | 73 |
#ifdef WIRELESS
|
62 | |
void nm_write_wireless_security(FILE *config_file, nm_wireless_security
|
|
74 |
static void nm_write_wireless_security(FILE *config_file, nm_wireless_security
|
63 | 75 |
wireless_security)
|
64 | 76 |
{
|
65 | 77 |
fprintf(config_file, "\n%s\n", NM_SETTINGS_WIRELESS_SECURITY);
|
|
79 | 91 |
}
|
80 | 92 |
#endif
|
81 | 93 |
|
82 | |
void nm_write_static_ipvX(FILE *config_file, nm_ipvX ipvx)
|
|
94 |
static void nm_write_static_ipvX(FILE *config_file, nm_ipvX ipvx)
|
83 | 95 |
{
|
84 | 96 |
char buffer[NM_MAX_LEN_BUF], addr[NM_MAX_LEN_IPV4];
|
85 | 97 |
int i;
|
|
124 | 136 |
fprintf(config_file, "addresses1=%s\n", buffer);
|
125 | 137 |
}
|
126 | 138 |
|
127 | |
void nm_write_ipv4(FILE *config_file, nm_ipvX ipv4)
|
|
139 |
static void nm_write_ipv4(FILE *config_file, nm_ipvX ipv4)
|
128 | 140 |
{
|
129 | 141 |
fprintf(config_file, "\n%s\n", NM_SETTINGS_IPV4);
|
130 | 142 |
|
|
137 | 149 |
}
|
138 | 150 |
}
|
139 | 151 |
|
140 | |
void nm_write_ipv6(FILE *config_file, nm_ipvX ipv6)
|
|
152 |
static void nm_write_ipv6(FILE *config_file, nm_ipvX ipv6)
|
141 | 153 |
{
|
142 | 154 |
fprintf(config_file, "\n%s\n", NM_SETTINGS_IPV6);
|
143 | 155 |
|
|
152 | 164 |
else if (ipv6.method == IGNORE) {
|
153 | 165 |
fprintf(config_file, "method=%s\n", "ignore");
|
154 | 166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
/* Write info about how the network was configured to a specific file, in
|
|
170 |
* order to be used in the finish install script. */
|
|
171 |
static void nm_write_connection_type(struct nm_config_info nmconf)
|
|
172 |
{
|
|
173 |
FILE *f = fopen(NM_CONNECTION_FILE, "w");
|
|
174 |
|
|
175 |
if (nmconf.connection.type == WIFI) {
|
|
176 |
fprintf(f, "connection type: wireless\n");
|
|
177 |
}
|
|
178 |
else {
|
|
179 |
fprintf(f, "connection type: wired\n");
|
|
180 |
}
|
|
181 |
|
|
182 |
if (nmconf.connection.type == WIFI && nmconf.wireless.is_secured) {
|
|
183 |
fprintf(f, "security: secured\n");
|
|
184 |
}
|
|
185 |
else {
|
|
186 |
fprintf(f, "security: unsecured\n");
|
|
187 |
}
|
|
188 |
|
|
189 |
fclose(f);
|
155 | 190 |
}
|
156 | 191 |
|
157 | 192 |
/* Write Network Manager config file. */
|
|
210 | 245 |
nm_write_connection_type(nmconf);
|
211 | 246 |
}
|
212 | 247 |
|
213 | |
/* Write info about how the network was configured to a specific file, in
|
214 | |
* order to be used in the finish install script. */
|
215 | |
void nm_write_connection_type(struct nm_config_info nmconf)
|
216 | |
{
|
217 | |
FILE *f = fopen(NM_CONNECTION_FILE, "w");
|
218 | |
|
219 | |
if (nmconf.connection.type == WIFI) {
|
220 | |
fprintf(f, "connection type: wireless\n");
|
221 | |
}
|
222 | |
else {
|
223 | |
fprintf(f, "connection type: wired\n");
|
224 | |
}
|
225 | |
|
226 | |
if (nmconf.connection.type == WIFI && nmconf.wireless.is_secured) {
|
227 | |
fprintf(f, "security: secured\n");
|
228 | |
}
|
229 | |
else {
|
230 | |
fprintf(f, "security: unsecured\n");
|
231 | |
}
|
232 | |
|
233 | |
fclose(f);
|
234 | |
}
|
235 | |
|
236 | 248 |
/* Functions for extracting information from netcfg variables. */
|
237 | 249 |
|
238 | 250 |
/* Get info for the connection setting for wireless networks. */
|
239 | 251 |
|
240 | 252 |
#ifdef WIRELESS
|
241 | |
void nm_get_wireless_connection(struct netcfg_interface *niface, nm_connection *connection)
|
|
253 |
static void nm_get_wireless_connection(struct netcfg_interface *niface, nm_connection *connection)
|
242 | 254 |
{
|
243 | 255 |
/* Use the wireless network name for connection id. */
|
244 | 256 |
snprintf(connection->id, NM_MAX_LEN_ID, "%s", niface->essid);
|
|
251 | 263 |
#endif
|
252 | 264 |
|
253 | 265 |
/* Get info for the connection setting for wired networks. */
|
254 | |
void nm_get_wired_connection(nm_connection *connection)
|
|
266 |
static void nm_get_wired_connection(nm_connection *connection)
|
255 | 267 |
{
|
256 | 268 |
/* This is the first wired connection. */
|
257 | 269 |
snprintf(connection->id, NM_MAX_LEN_ID, NM_DEFAULT_WIRED_NAME);
|
|
263 | 275 |
}
|
264 | 276 |
|
265 | 277 |
/* Get MAC address from default file. */
|
266 | |
void nm_get_mac_address(char *interface, char *mac_addr)
|
|
278 |
static void nm_get_mac_address(char *interface, char *mac_addr)
|
267 | 279 |
{
|
268 | 280 |
char file_name[NM_MAX_LEN_PATH];
|
269 | 281 |
FILE *file;
|
|
287 | 299 |
}
|
288 | 300 |
|
289 | 301 |
#ifdef WIRELESS
|
290 | |
void nm_get_wireless_specific_options(struct netcfg_interface *niface, nm_wireless *wireless)
|
|
302 |
static void nm_get_wireless_specific_options(struct netcfg_interface *niface, nm_wireless *wireless)
|
291 | 303 |
{
|
292 | 304 |
strncpy(wireless->ssid, niface->essid, NM_MAX_LEN_SSID);
|
293 | 305 |
|
|
313 | 325 |
#endif
|
314 | 326 |
|
315 | 327 |
/* Only set MAC address, the others have good defaults in NM. */
|
316 | |
void nm_get_wired_specific_options(struct netcfg_interface *niface, nm_wired *wired)
|
|
328 |
static void nm_get_wired_specific_options(struct netcfg_interface *niface, nm_wired *wired)
|
317 | 329 |
{
|
318 | 330 |
nm_get_mac_address(niface->name, wired->mac_addr);
|
319 | 331 |
}
|
320 | 332 |
|
321 | 333 |
/* Security type for wireless networks. */
|
322 | 334 |
#ifdef WIRELESS
|
323 | |
void nm_get_wireless_security(struct netcfg_interface *niface, nm_wireless_security *wireless_security)
|
|
335 |
static void nm_get_wireless_security(struct netcfg_interface *niface, nm_wireless_security *wireless_security)
|
324 | 336 |
{
|
325 | 337 |
if (niface->wifi_security == REPLY_WPA) {
|
326 | 338 |
wireless_security->key_mgmt = WPA_PSK;
|
|
340 | 352 |
#endif
|
341 | 353 |
|
342 | 354 |
/* Save IPv4 settings. */
|
343 | |
void nm_get_ipv4(struct netcfg_interface *niface, nm_ipvX *ipv4)
|
|
355 |
static void nm_get_ipv4(struct netcfg_interface *niface, nm_ipvX *ipv4)
|
344 | 356 |
{
|
345 | 357 |
/* DHCP wasn't used and there is no IPv4 address saved => didn't use ipv4
|
346 | 358 |
* so won't use it in the future. */
|
|
373 | 385 |
}
|
374 | 386 |
|
375 | 387 |
/* For the moment, just set it to ignore. */
|
376 | |
void nm_get_ipv6(struct netcfg_interface *niface, nm_ipvX *ipv6)
|
|
388 |
static void nm_get_ipv6(struct netcfg_interface *niface, nm_ipvX *ipv6)
|
377 | 389 |
{
|
378 | 390 |
/* No IPv6 address, no dhcpv6, nor slaac, so wasn't used. */
|
379 | 391 |
if (niface->address_family != AF_INET6 && niface->dhcpv6 == 0 &&
|
|
410 | 422 |
/* Extract all configs for a wireless interface, from both global netcfg
|
411 | 423 |
* values and other resources. */
|
412 | 424 |
#ifdef WIRELESS
|
413 | |
void nm_get_wireless_config(struct netcfg_interface *niface, struct nm_config_info *nmconf)
|
|
425 |
static void nm_get_wireless_config(struct netcfg_interface *niface, struct nm_config_info *nmconf)
|
414 | 426 |
{
|
415 | 427 |
nm_get_wireless_connection(niface, &(nmconf->connection));
|
416 | 428 |
nm_get_wireless_specific_options(niface, &(nmconf->wireless));
|
|
425 | 437 |
#endif
|
426 | 438 |
|
427 | 439 |
/* Extract all configs for a wired interface. */
|
428 | |
void nm_get_wired_config(struct netcfg_interface *niface, struct nm_config_info *nmconf)
|
|
440 |
static void nm_get_wired_config(struct netcfg_interface *niface, struct nm_config_info *nmconf)
|
429 | 441 |
{
|
430 | 442 |
nm_get_wired_connection(&(nmconf->connection));
|
431 | 443 |
nm_get_wired_specific_options(niface, &(nmconf->wired));
|