Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst sysinst(8): Add initial support for connect...
details: https://anonhg.NetBSD.org/src/rev/1caba6b572ce
branches: trunk
changeset: 359571:1caba6b572ce
user: nia <nia%NetBSD.org@localhost>
date: Mon Jan 10 12:17:48 2022 +0000
description:
sysinst(8): Add initial support for connecting to Wi-Fi networks
by spawning wpa_supplicant.
Reviewed by martin.
diffstat:
usr.sbin/sysinst/msg.mi.de | 8 +-
usr.sbin/sysinst/msg.mi.en | 8 +-
usr.sbin/sysinst/msg.mi.es | 8 +-
usr.sbin/sysinst/msg.mi.fr | 8 +-
usr.sbin/sysinst/msg.mi.pl | 8 +-
usr.sbin/sysinst/net.c | 161 +++++++++++++++++++++++++++++++++-----------
6 files changed, 156 insertions(+), 45 deletions(-)
diffs (truncated from 326 to 300 lines):
diff -r b890038563b3 -r 1caba6b572ce usr.sbin/sysinst/msg.mi.de
--- a/usr.sbin/sysinst/msg.mi.de Mon Jan 10 10:02:30 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.de Mon Jan 10 12:17:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.de,v 1.34 2021/09/25 08:54:31 maya Exp $ */
+/* $NetBSD: msg.mi.de,v 1.35 2022/01/10 12:17:48 nia Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -641,6 +641,12 @@
message net_media
{Art der Netzwerkverbindung}
+message net_ssid
+{WLAN-SSID?}
+
+message net_passphrase
+{WLAN-Passwort?}
+
message netok
{Nachfolgend sehen Sie die aktuellen Netzwerkeinstellungen.
diff -r b890038563b3 -r 1caba6b572ce usr.sbin/sysinst/msg.mi.en
--- a/usr.sbin/sysinst/msg.mi.en Mon Jan 10 10:02:30 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.en Mon Jan 10 12:17:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.en,v 1.36 2021/09/25 08:54:31 maya Exp $ */
+/* $NetBSD: msg.mi.en,v 1.37 2022/01/10 12:17:48 nia Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -616,6 +616,12 @@
message net_media
{Network media type}
+message net_ssid
+{Wi-Fi SSID?}
+
+message net_passphrase
+{Wi-Fi passphrase?}
+
message netok
{The following are the values you entered.
diff -r b890038563b3 -r 1caba6b572ce usr.sbin/sysinst/msg.mi.es
--- a/usr.sbin/sysinst/msg.mi.es Mon Jan 10 10:02:30 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.es Mon Jan 10 12:17:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.es,v 1.30 2021/09/25 08:54:31 maya Exp $ */
+/* $NetBSD: msg.mi.es,v 1.31 2022/01/10 12:17:48 nia Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -632,6 +632,12 @@
message net_media
{Tipo de medio de la red}
+message net_ssid
+{Wi-Fi SSID?}
+
+message net_passphrase
+{Wi-Fi passphrase?}
+
message netok
{Ha introducido los siguientes valores.
diff -r b890038563b3 -r 1caba6b572ce usr.sbin/sysinst/msg.mi.fr
--- a/usr.sbin/sysinst/msg.mi.fr Mon Jan 10 10:02:30 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.fr Mon Jan 10 12:17:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.fr,v 1.35 2021/09/25 08:54:31 maya Exp $ */
+/* $NetBSD: msg.mi.fr,v 1.36 2022/01/10 12:17:48 nia Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -626,6 +626,12 @@
message net_media
{Type de réseau (média)}
+message net_ssid
+{Wi-Fi SSID?}
+
+message net_passphrase
+{Wi-Fi passphrase?}
+
message netok
{Vous avez spécifié les valeurs suivantes :
diff -r b890038563b3 -r 1caba6b572ce usr.sbin/sysinst/msg.mi.pl
--- a/usr.sbin/sysinst/msg.mi.pl Mon Jan 10 10:02:30 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.pl Mon Jan 10 12:17:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.pl,v 1.36 2021/09/25 08:54:31 maya Exp $ */
+/* $NetBSD: msg.mi.pl,v 1.37 2022/01/10 12:17:48 nia Exp $ */
/* Based on english version: */
/* NetBSD: msg.mi.pl,v 1.36 2004/04/17 18:55:35 atatat Exp */
@@ -611,6 +611,12 @@
message net_media
{Typ interfejsu sieciowego}
+message net_ssid
+{Wi-Fi SSID?}
+
+message net_passphrase
+{Wi-Fi passphrase?}
+
message netok
{Ponizej sa wartosci, ktore wprowadziles.
diff -r b890038563b3 -r 1caba6b572ce usr.sbin/sysinst/net.c
--- a/usr.sbin/sysinst/net.c Mon Jan 10 10:02:30 2022 +0000
+++ b/usr.sbin/sysinst/net.c Mon Jan 10 12:17:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: net.c,v 1.36 2021/01/31 22:45:46 rillig Exp $ */
+/* $NetBSD: net.c,v 1.37 2022/01/10 12:17:48 nia Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -79,6 +79,8 @@
char net_namesvr[STRSIZE];
static char net_defroute[STRSIZE];
static char net_media[STRSIZE];
+static char net_ssid[STRSIZE];
+static char net_passphrase[STRSIZE];
static char sl_flags[STRSIZE];
static int net_dhcpconf;
#define DHCPCONF_IPADDR 0x01
@@ -100,8 +102,11 @@
static void write_etc_hosts(FILE *f);
#define DHCPCD "/sbin/dhcpcd"
+#define WPA_SUPPLICANT "/usr/sbin/wpa_supplicant"
#include <signal.h>
+static int config_eth_medium(char *);
static int config_dhcp(char *);
+static int config_wlan(char *);
#ifdef INET6
static int is_v6kernel (void);
@@ -562,45 +567,8 @@
/* domain and host */
msg_display(MSG_netinfo);
- /* ethernet medium */
- for (;;) {
- msg_prompt_add(MSG_net_media, net_media, net_media,
- sizeof net_media);
-
- /*
- * ifconfig does not allow media specifiers on
- * IFM_MANUAL interfaces. Our UI gives no way
- * to set an option back
- * to null-string if it gets accidentally set.
- * Check for plausible alternatives.
- */
- if (strcmp(net_media, "<default>") == 0 ||
- strcmp(net_media, "default") == 0 ||
- strcmp(net_media, "<manual>") == 0 ||
- strcmp(net_media, "manual") == 0 ||
- strcmp(net_media, "<none>") == 0 ||
- strcmp(net_media, "none") == 0 ||
- strcmp(net_media, " ") == 0) {
- *net_media = '\0';
- }
-
- if (*net_media == '\0')
- break;
- /*
- * We must set the media type here - to give dhcp
- * a chance
- */
- if (run_program(0, "/sbin/ifconfig %s media %s",
- net_dev, net_media) == 0)
- break;
- /* Failed to set - output the supported values */
- if (collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -m %s |"
- "while IFS=; read line;"
- " do [ \"$line\" = \"${line#*media}\" ] || "
- "echo $line;"
- " done", net_dev ) > 0)
- msg_display(textbuf);
- free(textbuf);
+ if (!config_wlan(net_dev)) {
+ config_eth_medium(net_dev);
}
net_dhcpconf = 0;
@@ -1092,6 +1060,10 @@
if (net_namesvr[0] != '\0')
dup_file_into_target("/etc/resolv.conf");
+ /* Copy wpa_supplicant.conf to target. */
+ if (net_ssid[0] != '\0')
+ dup_file_into_target("/etc/wpa_supplicant.conf");
+
/*
* bring the interface up, it will be necessary for IPv6, and
* it won't make trouble with IPv4 case either
@@ -1149,6 +1121,11 @@
add_rc_conf("dhcpcd_flags=\"-qM %s\"\n", net_dev);
}
+ if (net_ssid[0] != '\0') {
+ add_rc_conf("wpa_supplicant=YES\n");
+ add_rc_conf("wpa_supplicant_flags=\"-B -s -i %s -D bsd -c /etc/wpa_supplicant.conf\"\n", net_dev);
+ }
+
if (ifconf)
fclose(ifconf);
@@ -1156,6 +1133,62 @@
}
int
+config_wlan(char *inter)
+{
+ FILE *wpa_conf = NULL;
+ char wpa_cmd[256];
+
+ if (!file_mode_match(WPA_SUPPLICANT, S_IFREG))
+ return 0;
+
+ msg_prompt_add(MSG_net_ssid, net_ssid, net_ssid,
+ sizeof net_ssid);
+ if (net_ssid[0] == '\0')
+ return 0;
+
+ msg_prompt_noecho(MSG_net_passphrase, net_passphrase, net_passphrase,
+ sizeof net_passphrase);
+
+ wpa_conf = fopen("/etc/wpa_supplicant.conf", "a");
+ if (wpa_conf == NULL)
+ return 0;
+
+ scripting_fprintf(NULL,
+ "cat <<EOF >>%s/etc/wpa_supplicant.conf\n",
+ target_prefix());
+ scripting_fprintf(wpa_conf, "\n#\n");
+ scripting_fprintf(wpa_conf, "# Added by NetBSD sysinst\n");
+ scripting_fprintf(wpa_conf, "#\n");
+ scripting_fprintf(wpa_conf, "network={\n");
+ scripting_fprintf(wpa_conf,
+ "\tssid=\"%s\"\n", net_ssid);
+ if (net_passphrase[0] != '\0') {
+ scripting_fprintf(wpa_conf, "\tpsk=\"%s\"\n",
+ net_passphrase);
+ } else {
+ scripting_fprintf(wpa_conf, "\tkey_mgmt=NONE\n");
+ }
+ scripting_fprintf(wpa_conf, "}\n");
+ (void)fclose(wpa_conf);
+ scripting_fprintf(NULL, "EOF\n");
+
+ if (run_program(RUN_DISPLAY | RUN_PROGRESS,
+ "/sbin/ifconfig %s up", inter) != 0)
+ return 0;
+
+ /*
+ * have to use system() here to avoid the server process dying
+ */
+ if (snprintf(wpa_cmd, sizeof(wpa_cmd),
+ WPA_SUPPLICANT
+ " -B -s -i %s -D bsd -c /etc/wpa_supplicant.conf", inter) < 0)
+ return 0;
+ (void)do_system(wpa_cmd);
+
+ return 1;
+}
+
+int
config_dhcp(char *inter)
{
int dhcpautoconf;
@@ -1176,3 +1209,51 @@
}
return 0;
}
+
+
+int
+config_eth_medium(char *inter)
+{
+ char *textbuf = NULL;
+
+ for (;;) {
+ msg_prompt_add(MSG_net_media, net_media, net_media,
+ sizeof net_media);
+
+ /*
+ * ifconfig does not allow media specifiers on
+ * IFM_MANUAL interfaces. Our UI gives no way
+ * to set an option back
+ * to null-string if it gets accidentally set.
+ * Check for plausible alternatives.
+ */
+ if (strcmp(net_media, "<default>") == 0 ||
+ strcmp(net_media, "default") == 0 ||
+ strcmp(net_media, "<manual>") == 0 ||
+ strcmp(net_media, "manual") == 0 ||
Home |
Main Index |
Thread Index |
Old Index