Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src/usr.sbin/sysinst Pull up following revision(s) (requested...
details: https://anonhg.NetBSD.org/src/rev/98167efd7b7c
branches: netbsd-9
changeset: 359740:98167efd7b7c
user: martin <martin%NetBSD.org@localhost>
date: Thu Jan 20 11:45:28 2022 +0000
description:
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:
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 | 178 ++++++++++++++++++++++++++++++++++----------
6 files changed, 170 insertions(+), 48 deletions(-)
diffs (truncated from 373 to 300 lines):
diff -r 6dba987a8ad3 -r 98167efd7b7c usr.sbin/sysinst/msg.mi.de
--- a/usr.sbin/sysinst/msg.mi.de Thu Jan 20 11:42:22 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.de Thu Jan 20 11:45:28 2022 +0000
@@ -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_media
{Art der Netzwerkverbindung}
+message net_ssid
+{WLAN-SSID?}
+
+message net_passphrase
+{WLAN-Passwort?}
+
message netok
{Nachfolgend sehen Sie die aktuellen Netzwerkeinstellungen.
diff -r 6dba987a8ad3 -r 98167efd7b7c usr.sbin/sysinst/msg.mi.en
--- a/usr.sbin/sysinst/msg.mi.en Thu Jan 20 11:42:22 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.en Thu Jan 20 11:45:28 2022 +0000
@@ -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_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 6dba987a8ad3 -r 98167efd7b7c usr.sbin/sysinst/msg.mi.es
--- a/usr.sbin/sysinst/msg.mi.es Thu Jan 20 11:42:22 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.es Thu Jan 20 11:45:28 2022 +0000
@@ -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_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 6dba987a8ad3 -r 98167efd7b7c usr.sbin/sysinst/msg.mi.fr
--- a/usr.sbin/sysinst/msg.mi.fr Thu Jan 20 11:42:22 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.fr Thu Jan 20 11:45:28 2022 +0000
@@ -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_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 6dba987a8ad3 -r 98167efd7b7c usr.sbin/sysinst/msg.mi.pl
--- a/usr.sbin/sysinst/msg.mi.pl Thu Jan 20 11:42:22 2022 +0000
+++ b/usr.sbin/sysinst/msg.mi.pl Thu Jan 20 11:45:28 2022 +0000
@@ -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_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 6dba987a8ad3 -r 98167efd7b7c usr.sbin/sysinst/net.c
--- a/usr.sbin/sysinst/net.c Thu Jan 20 11:42:22 2022 +0000
+++ b/usr.sbin/sysinst/net.c Thu Jan 20 11:45:28 2022 +0000
@@ -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 @@
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 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 @@
}
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
}
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");
Home |
Main Index |
Thread Index |
Old Index