]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: pass on # comments to {Pre,Post}{Up,Down}
authorRobyn Kosching <robyn@kosching.me>
Wed, 15 Jan 2025 11:33:50 +0000 (12:33 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 23 May 2025 18:43:30 +0000 (20:43 +0200)
Currently commands in {Pre,Post}{Up,Down} are stripped of everything
starting with the first #, even if the # is escaped or in a string. This
patch leaves comment interpretation to the shell, as it can presumably
already handle the difference between comments and escaped #.

Signed-off-by: Robyn Kosching <robyn@kosching.me>
[Jason: massage commit message, port to other platforms]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/wg-quick/darwin.bash
src/wg-quick/freebsd.bash
src/wg-quick/linux.bash
src/wg-quick/openbsd.bash

index c9381124c9379de92d8f17810b466253cddf2853..ed6aadaccf19fe634783a38aa4722be8782e2231 100755 (executable)
@@ -62,6 +62,7 @@ parse_options() {
                stripped="${line%%\#*}"
                key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
                value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+               unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
                [[ $key == "["* ]] && interface_section=0
                [[ $key == "[Interface]" ]] && interface_section=1
                if [[ $interface_section -eq 1 ]]; then
@@ -72,10 +73,10 @@ parse_options() {
                                [[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
                        done; continue ;;
                        Table) TABLE="$value"; continue ;;
-                       PreUp) PRE_UP+=( "$value" ); continue ;;
-                       PreDown) PRE_DOWN+=( "$value" ); continue ;;
-                       PostUp) POST_UP+=( "$value" ); continue ;;
-                       PostDown) POST_DOWN+=( "$value" ); continue ;;
+                       PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
+                       PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
+                       PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
+                       PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
                        SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
                        esac
                fi
index f72daf69c112cb0505fd4e10b8d184ca74b2442d..af5b174546fc59f9a6dbb90c8170e3bc0b25fe7f 100755 (executable)
@@ -80,6 +80,7 @@ parse_options() {
                stripped="${line%%\#*}"
                key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
                value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+               unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
                [[ $key == "["* ]] && interface_section=0
                [[ $key == "[Interface]" ]] && interface_section=1
                if [[ $interface_section -eq 1 ]]; then
@@ -90,10 +91,10 @@ parse_options() {
                                [[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
                        done; continue ;;
                        Table) TABLE="$value"; continue ;;
-                       PreUp) PRE_UP+=( "$value" ); continue ;;
-                       PreDown) PRE_DOWN+=( "$value" ); continue ;;
-                       PostUp) POST_UP+=( "$value" ); continue ;;
-                       PostDown) POST_DOWN+=( "$value" ); continue ;;
+                       PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
+                       PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
+                       PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
+                       PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
                        SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
                        esac
                fi
index acb015d567a02dccc36fd735465010b24482f90a..f56f6e4a53091d2ddc382379c71792ec93c884b3 100755 (executable)
@@ -51,6 +51,7 @@ parse_options() {
                stripped="${line%%\#*}"
                key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
                value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+               unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
                [[ $key == "["* ]] && interface_section=0
                [[ $key == "[Interface]" ]] && interface_section=1
                if [[ $interface_section -eq 1 ]]; then
@@ -61,10 +62,10 @@ parse_options() {
                                [[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
                        done; continue ;;
                        Table) TABLE="$value"; continue ;;
-                       PreUp) PRE_UP+=( "$value" ); continue ;;
-                       PreDown) PRE_DOWN+=( "$value" ); continue ;;
-                       PostUp) POST_UP+=( "$value" ); continue ;;
-                       PostDown) POST_DOWN+=( "$value" ); continue ;;
+                       PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
+                       PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
+                       PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
+                       PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
                        SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
                        esac
                fi
index b58ecf5cd7fa10c0f715e875ac1263e4e98c8af6..d12f70e1c222aa95c9de21ce2f7214cb6cf51532 100755 (executable)
@@ -52,6 +52,7 @@ parse_options() {
                stripped="${line%%\#*}"
                key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
                value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+               unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
                [[ $key == "["* ]] && interface_section=0
                [[ $key == "[Interface]" ]] && interface_section=1
                if [[ $interface_section -eq 1 ]]; then
@@ -62,10 +63,10 @@ parse_options() {
                                [[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
                        done; continue ;;
                        Table) TABLE="$value"; continue ;;
-                       PreUp) PRE_UP+=( "$value" ); continue ;;
-                       PreDown) PRE_DOWN+=( "$value" ); continue ;;
-                       PostUp) POST_UP+=( "$value" ); continue ;;
-                       PostDown) POST_DOWN+=( "$value" ); continue ;;
+                       PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
+                       PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
+                       PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
+                       PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
                        SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
                        esac
                fi