summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authormartin <martin@NetBSD.org>2022-01-20 11:45:28 +0000
committermartin <martin@NetBSD.org>2022-01-20 11:45:28 +0000
commit9eb65dcff7d41492c8bcf2ed4d36e8dac5d06dd5 (patch)
tree6b8b62e048b1e8429c52a5b0be85c8714b507b84 /usr.sbin
parent7f386e5f834f3ab288ae8a6de050862009f56df9 (diff)
Pull up following revision(s) (requested by nia in ticket #1406):
usr.sbin/sysinst/net.c: revision 1.40 usr.sbin/sysinst/msg.mi.pl: revision 1.37 usr.sbin/sysinst/msg.mi.fr: revision 1.36 usr.sbin/sysinst/msg.mi.de: revision 1.35 usr.sbin/sysinst/msg.mi.en: revision 1.37 usr.sbin/sysinst/net.c: revision 1.37 usr.sbin/sysinst/net.c: revision 1.38 usr.sbin/sysinst/msg.mi.es: revision 1.31 usr.sbin/sysinst/net.c: revision 1.39 sysinst(8): Add initial support for connecting to Wi-Fi networks by spawning wpa_supplicant. Reviewed by martin. sysinst(8): Avoid asking Wi-Fi questions about non-Wi-Fi devices. sysinst(8): Add a "data" argument to do_ifreq that is set after the ifr struct is zeroed. This allows us to simplify the code by not having 2x socket creation code for checking whether interfaces are wireless. sysinst(8): use scan_ssid=1 so hidden wifi networks can be used
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/sysinst/msg.mi.de8
-rw-r--r--usr.sbin/sysinst/msg.mi.en8
-rw-r--r--usr.sbin/sysinst/msg.mi.es8
-rw-r--r--usr.sbin/sysinst/msg.mi.fr8
-rw-r--r--usr.sbin/sysinst/msg.mi.pl8
-rw-r--r--usr.sbin/sysinst/net.c178
6 files changed, 170 insertions, 48 deletions
diff --git a/usr.sbin/sysinst/msg.mi.de b/usr.sbin/sysinst/msg.mi.de
index 3445f7fd6f1..9e73eabb63d 100644
--- a/usr.sbin/sysinst/msg.mi.de
+++ b/usr.sbin/sysinst/msg.mi.de
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.de,v 1.13.2.9 2020/11/05 08:10:21 sborrill Exp $ */
+/* $NetBSD: msg.mi.de,v 1.13.2.10 2022/01/20 11:45:28 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -639,6 +639,12 @@ message net_defroute
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 --git a/usr.sbin/sysinst/msg.mi.en b/usr.sbin/sysinst/msg.mi.en
index 2cefb68618d..da1ae990fcd 100644
--- a/usr.sbin/sysinst/msg.mi.en
+++ b/usr.sbin/sysinst/msg.mi.en
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.en,v 1.19.2.10 2020/11/05 08:10:21 sborrill Exp $ */
+/* $NetBSD: msg.mi.en,v 1.19.2.11 2022/01/20 11:45:28 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -616,6 +616,12 @@ message net_defroute
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 --git a/usr.sbin/sysinst/msg.mi.es b/usr.sbin/sysinst/msg.mi.es
index de73a2b960c..ee62898d4f7 100644
--- a/usr.sbin/sysinst/msg.mi.es
+++ b/usr.sbin/sysinst/msg.mi.es
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.es,v 1.14.2.9 2020/11/05 08:10:21 sborrill Exp $ */
+/* $NetBSD: msg.mi.es,v 1.14.2.10 2022/01/20 11:45:28 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -632,6 +632,12 @@ message net_defroute
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 --git a/usr.sbin/sysinst/msg.mi.fr b/usr.sbin/sysinst/msg.mi.fr
index 29111199704..d6f9f22d8e1 100644
--- a/usr.sbin/sysinst/msg.mi.fr
+++ b/usr.sbin/sysinst/msg.mi.fr
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.fr,v 1.17.2.10 2020/11/05 08:10:21 sborrill Exp $ */
+/* $NetBSD: msg.mi.fr,v 1.17.2.11 2022/01/20 11:45:28 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -626,6 +626,12 @@ message net_defroute
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 --git a/usr.sbin/sysinst/msg.mi.pl b/usr.sbin/sysinst/msg.mi.pl
index 6d269cee999..18664167841 100644
--- a/usr.sbin/sysinst/msg.mi.pl
+++ b/usr.sbin/sysinst/msg.mi.pl
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.mi.pl,v 1.20.2.10 2020/11/05 08:10:21 sborrill Exp $ */
+/* $NetBSD: msg.mi.pl,v 1.20.2.11 2022/01/20 11:45:28 martin 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_defroute
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 --git a/usr.sbin/sysinst/net.c b/usr.sbin/sysinst/net.c
index 3411a57a12f..3206ec53aee 100644
--- a/usr.sbin/sysinst/net.c
+++ b/usr.sbin/sysinst/net.c
@@ -1,4 +1,4 @@
-/* $NetBSD: net.c,v 1.33.2.2 2020/01/28 10:17:58 msaitoh Exp $ */
+/* $NetBSD: net.c,v 1.33.2.3 2022/01/20 11:45:28 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -47,6 +47,7 @@
#include <net/if.h>
#include <net/if_media.h>
#include <netinet/in.h>
+#include <net80211/ieee80211_ioctl.h>
#include <err.h>
#include <stdio.h>
@@ -79,6 +80,8 @@ static char net_mask[SSTRSIZE];
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 +103,11 @@ static char *url_encode (char *dst, const char *src, const char *ep,
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);
@@ -269,7 +275,7 @@ get_ifconfig_info(struct net_desc *devs)
}
static int
-do_ifreq(struct ifreq *ifr, unsigned long cmd)
+do_ifreq(struct ifreq *ifr, unsigned long cmd, void *data)
{
int sock;
int rval;
@@ -279,6 +285,7 @@ do_ifreq(struct ifreq *ifr, unsigned long cmd)
return -1;
memset(ifr, 0, sizeof *ifr);
+ ifr->ifr_data = data;
strlcpy(ifr->ifr_name, net_dev, sizeof ifr->ifr_name);
rval = ioctl(sock, cmd, ifr);
close(sock);
@@ -315,10 +322,12 @@ get_ifinterface_info(void)
const char *media_opt;
const char *sep;
- if (do_ifreq(&ifr, SIOCGIFADDR) == 0 && sa_in->sin_addr.s_addr != 0)
+ if (do_ifreq(&ifr, SIOCGIFADDR, NULL) == 0 &&
+ sa_in->sin_addr.s_addr != 0)
strlcpy(net_ip, inet_ntoa(sa_in->sin_addr), sizeof net_ip);
- if (do_ifreq(&ifr, SIOCGIFNETMASK) == 0 && sa_in->sin_addr.s_addr != 0)
+ if (do_ifreq(&ifr, SIOCGIFNETMASK, NULL) == 0 &&
+ sa_in->sin_addr.s_addr != 0)
strlcpy(net_mask, inet_ntoa(sa_in->sin_addr), sizeof net_mask);
if (do_ifmreq(&ifmr, SIOCGIFMEDIA) == 0) {
@@ -562,45 +571,8 @@ again:
/* 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 +1064,10 @@ mnt_net_config(void)
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 +1125,11 @@ mnt_net_config(void)
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 +1137,69 @@ mnt_net_config(void)
}
int
+config_wlan(char *inter)
+{
+ FILE *wpa_conf = NULL;
+ char wpa_cmd[256];
+ struct ifreq ifr = {0};
+ struct ieee80211_nwid nwid = {0};
+
+ /* skip non-WLAN devices */
+ if (do_ifreq(&ifr, SIOCG80211NWID, &nwid) == -1)
+ return 0;
+
+ 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, "\tscan_ssid=1\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 +1220,51 @@ config_dhcp(char *inter)
}
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 ||
+ 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);
+ }
+ return 0;
+}