From patchwork Sat Jun 23 11:25:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 655 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id A096450064E3 for ; Sat, 23 Jun 2018 11:25:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on apollo X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,T_DKIMWL_WL_HIGH=-0.01 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-BL-Results: [127.0.0.11] [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Sat, 23 Jun 2018 11:25:55 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 6A9DAB54E02F1; Sat, 23 Jun 2018 11:25:49 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Sat, 23 Jun 2018 11:25:49 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 30B962CD79; Sat, 23 Jun 2018 11:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1529753149; bh=YPFTSFEfGlilT1HPCKC8JrjKg1CsB5hFQ8rEGObClR4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=Qg9VGo+gwXvI8JoKaOv6J09N0BAXymDHMm7E+LaR4MTpl+642HOVh00zL5Eg7PzhX /xFWdP/al3FS15sXHh+g8Z/d3mhRQsffgUHE0FQOjuiATBVH9ozwfcv+aVZOxJx20x vN6O5StOoGkFTFEg3u4rMdOA10mt1Rj091+tLjHyLkHdgYfeDkkJyQXpEXMinGYpmw yaxxepApSKGVmPh+6N0uVlWqIF00FPIeoX3xRZ+NPzKtfC/wbdoLolyY6PLYQE2/54 NrW/pjrAnI4soOBJRXCxhg7dSSyWVtO1HXqgUbo6FoMtWSD9jNvYERwI9qHeQEFBoW /Z+oBtFzLocsthhE8j2R6I4M9GWngdzIdCsLOZh44u3B4CcddNAvF0g0mU03IuDprP EJO2VqFsDvLFfHn/MY/SV2hcfrL7Cj8R5sAIdFXE6uiWJggA+ms7n1Q+AHFNd7dfBN HFsNXrKniUGxM3og0YAPgJ9uFYEF408YyAevJGeC7c+5BkmJzRmV6yCUVS0yPx82et YnjwGRbeOzrdo1B0JED/ySjJUo7fBIx6JY4hoQ/ovbnG2AQfrR8xM+BkrnEG6o+x2E Ir+CiK2OepbApeREoigxQxCkhNTquJnV76f4REdEfdYeD5kY+PZpwelExup439h6SQ w/2GoaK+bWYz8/Tb7LHnM930= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id D608D2C50A for ; Sat, 23 Jun 2018 11:25:47 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Sat, 23 Jun 2018 11:25:47 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 11B8CB54E02F0 for ; Sat, 23 Jun 2018 11:25:42 +0000 (UTC) Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Sat, 23 Jun 2018 11:25:41 +0000 (UTC) Received: by mail-ed1-x542.google.com with SMTP id j25-v6so2657260edr.4 for ; Sat, 23 Jun 2018 04:25:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=YBwt/ltWktQIPmgHKUpA+7Jp8d8RiQ2YtbG7aTwaSu4=; b=TCmFp6ccM6OLAiav1DgUrVBHaKIDR2S0xC4N8MZ8W2JwQX7Aw/Kfysr6KWUPLl/U0C l6UqkhtB5rYVPb/5/V630CRtWXa0wiSP9HnFCXnpTMePrQHV7x8AhvYhjacF+8B90OQA ysPLBzUNjkb+bL045UGAym0etGkElzVkNiZM6+fVvALtJ9n0tnpDo9528ydnztJgseyu 9msCWsVvtHgcKdjxIkRXsuXcQFYrLj6m7TRFuW3Y25N9mThlCQHHorVFCar6N46zLyq7 LBAm8aVmLvZPtrVoFGwcPwVp2PuPB+qFm34BLeSdBPSwgQQvU9TgdL+OXBLc6jmCUahV 7k5w== X-Gm-Message-State: APt69E0RVVEr6eVRE86HN1rMWSZywh04ni094qsu3UItTdC+cYpOp5fv jdHVXBs896X5ftk/MwVtzmyBjQ== X-Google-Smtp-Source: ADUXVKKlEdyMATguozIfK7FV+oli07KJ11yWjF1eqjZq2YMpWCPltX1tECC7VuArwq1cJXTmEAxNDg== X-Received: by 2002:a50:8ce3:: with SMTP id r32-v6mr4283786edr.113.1529753141309; Sat, 23 Jun 2018 04:25:41 -0700 (PDT) Received: from Mindship-03 (ip5653397a.direct-adsl.nl. [86.83.57.122]) by smtp.gmail.com with ESMTPSA id w17-v6sm192559edr.30.2018.06.23.04.25.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Jun 2018 04:25:40 -0700 (PDT) Date: Sat, 23 Jun 2018 13:25:36 +0200 To: arch-projects@archlinux.org Message-ID: <20180623112535.GA2331@Mindship-03> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.0 (2018-05-17) Subject: [arch-projects] [netctl] [PATCH] wifi-menu: Support UTF-8 encoded SSIDs (FS#45384) X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jouke Witteveen via arch-projects Reply-To: Arch Linux projects development discussion Cc: Jouke Witteveen Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" Strictly speaking, we should check with the SSIDEncoding value sent out by the station, as specified in the 2012 version of 802.11 (page 566), but wpa_supplicant does not (yet) expose this information and stations may not set the field to UTF-8 and still encode their SSID accordingly. We therefore assume SSIDs to be UTF-8 encoded (the only real alternative is treating SSIDs as raw byte string) in wifi-menu. Note that wifi-menu is only provided as a convenience and many/most use cases involve writing profile files manually. When the current character map is not set to UTF-8 , wifi-menu will only use ASCII characters in its screen output. This can be forced using for example `LC_CTYPE=C wifi-menu`. Reviewed-by: Emil Velikov --- src/wifi-menu | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/wifi-menu b/src/wifi-menu index 42c4c53..525830f 100755 --- a/src/wifi-menu +++ b/src/wifi-menu @@ -20,6 +20,11 @@ Arguments: END } +# Undo printf escaping in $1 +printf_decode() { + printf -- "${1//%/%%}" +} + # Prepare $1 for use in a special quoting context quote_safe() { if [[ "$1" = \"* ]]; then @@ -38,6 +43,9 @@ init_profiles() { unset Interface ESSID source "$PROFILE_DIR/$profile" > /dev/null if [[ "$Interface" = "$1" && -n "$ESSID" ]]; then + if [[ "$ESSID" = \"\"*\" ]]; then + ESSID=${ESSID:2:-1} + fi printf "%s" "$ESSID" if [[ "$Description" =~ "Automatically generated" ]]; then return 2 @@ -62,14 +70,19 @@ init_profiles() { # Build ENTRIES as an argument list for dialog based on scan results in $1 init_entries() { - local i=0 sep=$'\t' flags signal ssid + local i=0 sep=$'\t' decoded flags signal ssid while IFS=$'\t' read -r signal flags ssid; do + decoded=$(printf_decode "$ssid") ENTRIES[i++]="--" # the SSID might look like an option to dialog - ENTRIES[i++]=$ssid - if is_yes "${CONNECTED:-no}" && [[ "$ssid" = "$CONNECTION" ]]; then + if [[ "$CHARMAP" = "UTF-8" ]]; then + ENTRIES[i++]=$decoded + else + ENTRIES[i++]=$ssid + fi + if is_yes "${CONNECTED:-no}" && [[ "$decoded" = "$CONNECTION" ]]; then ENTRIES[i]="*" # Currently connected - elif in_array "$ssid" "${ESSIDS[@]}"; then - if in_array "$(ssid_to_profile "$ssid")" "${GENERATED[@]}"; then + elif in_array "$decoded" "${ESSIDS[@]}"; then + if in_array "$(ssid_to_profile "$decoded")" "${GENERATED[@]}"; then ENTRIES[i]="." # Automatically generated else ENTRIES[i]=":" # Handmade @@ -115,11 +128,14 @@ Do you want to overwrite it?" # Create a profile for ssid $1 create_profile() { - local box flags key msg security - PROFILE="$INTERFACE-${1//\//_}" + local box flags key msg security signal ssid + PROFILE=$(iconv -c -f UTF-8 -t //TRANSLIT <<< "$1") + PROFILE="$INTERFACE-${PROFILE//[?\/]/_}" [[ -e "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu" confirm_profile || return $? - flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2) + while IFS=$'\t' read -r signal flags ssid; do + [[ "$(printf_decode "$ssid")" != "$1" ]] || break + done < "$NETWORKS" if [[ "$flags" =~ WPA|WEP ]]; then security=${BASH_REMATCH[0],,} else @@ -221,6 +237,8 @@ ensure_root "$(basename "$0")" if ! type dialog &> /dev/null; then exit_error "Please install 'dialog' to use wifi-menu" fi +CHARMAP=$(locale charmap) +cd / # We do not want to spawn anything that can block unmounting INTERFACE=$1 if [[ -z "$INTERFACE" ]]; then @@ -237,7 +255,6 @@ elif ! is_interface "$INTERFACE"; then fi load_interface_config "$INTERFACE" -cd / # We do not want to spawn anything that can block unmounting if [[ "$RFKill" && "$(rf_status "$INTERFACE" "$RFKill")" ]]; then if ! rf_enable "$INTERFACE" "$RFKill"; then exit_error "Could not unblock transmission on interface '$INTERFACE'" @@ -247,7 +264,7 @@ fi echo -n "Scanning for networks... " if CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 "^ssid="); then - CONNECTION=${CONNECTION#ssid=} + CONNECTION=$(printf_decode "${CONNECTION#ssid=}") CONNECTED=yes fi NETWORKS=$(wpa_supplicant_scan "$INTERFACE" 3,4,5) @@ -270,6 +287,9 @@ Flags description: CHOICE=$(dialog --menu "$MSG" 24 50 12 "${ENTRIES[@]}" --stdout) RETURN=$? if (( RETURN == 0 )); then + if [[ "$CHARMAP" != "UTF-8" ]]; then + CHOICE=$(printf_decode "$CHOICE") + fi connect_to_ssid "$CHOICE" RETURN=$? fi