From f512c908edc331ca6a87bb83a8ae06e630d2e040 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Sat, 18 Jul 2020 16:29:05 +0200 Subject: [PATCH] Do not leak wireless options into non-wireless device configurations on concurrent runs When configuring a wlan device *and* afterwards a non-wlan device within the same netcardconfig invocation, the wireless configuration is still around (via $IWOURLINE and its underlying writeiwline()). This causes the wireless options to be present even if not applicable, like for example (wlan0 was configured first, then eth0 afterwards): | allow-hotplug eth0 | iface wlan0 inet dhcp | wireless-mode Managed | wireless-essid SECRET | wpa-ssid SECRET | wpa-psk SECRET | | | iface eth0 inet static | address 10.42.42.1 | netmask 255.255.255.0 | network 10.42.42.0 | broadcast 10.42.42.255 | gateway 10.42.42.1 | dns-nameservers 10.42.42.1 | wireless-mode Managed | wireless-essid SECRET | wpa-ssid SECRET | wpa-psk SECRET This work was funded by Grml-Forensic. --- sbin/netcardconfig | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/sbin/netcardconfig b/sbin/netcardconfig index 675c44a..d9440e6 100755 --- a/sbin/netcardconfig +++ b/sbin/netcardconfig @@ -433,7 +433,11 @@ configiface() { $DIALOG --inputbox "$MESSAGEW20 $DEVICENAME $MESSAGEW21" 15 50 "$IWPRIV" 2>"$TMP" || bailout 1 read -r IWPRIV <"$TMP" ; rm -f "$TMP" - writeiwline + unset IWOURLINE + if [ "$iswireless" = "1" ] ; then + writeiwline + fi + fi # Setup wireless options? # Configure VLAN on this interface? @@ -459,7 +463,14 @@ configiface() { {if(!(found+lastblank)){print}} END{print "iface '"$DV"' inet dhcp";if("'"$PDV"'"!=""){print "\tvlan-raw-device '"$PDV"'"}}' \ /etc/network/interfaces >"$TMP" - echo -e "$IWOURLINE" >> "$TMP" + case "$DV" in + "$WLAN") + # write wireless configuration only when we are dealing with a wireless device, + # it might be set from a previous configuration run of a wireless device + # while the currently configured network device isn't a wireless device + echo -e "$IWOURLINE" >> "$TMP" + ;; + esac #echo -e "\n\n" >> $TMP cat "$TMP" >/etc/network/interfaces rm -f "$TMP" @@ -501,6 +512,17 @@ configiface() { fi if [ -w /etc/network/interfaces ]; then + case "$DV" in + "$WLAN") + ;; + *) + # ensure we don't leak the IWOURLINE into the + # following awk command line, if we are configuring + # a device without wireless capabilities + unset IWOURLINE + ;; + esac + awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}} {if(!found){print}} END{print "\niface '"$DV"' inet static\n\taddress '"$IP"'\n\tnetmask '"$NM"'\n\tnetwork '"${IP%.*}.0"'";if("'"$BC"'"!=""){print "\tbroadcast '"$BC"'"};if("'"$DG"'"!=""){print "\tgateway '"$DG"'"};if("'"$NS"'"!=""){print "\tdns-nameservers '"$NS"'"};if("'"$PDV"'"!=""){print "\tvlan-raw-device '"$PDV"'"};if("'"$IWOURLINE"'"!=""){print "'"$IWOURLINE"'"};print "\n"}' \ -- 2.1.4