Skip to content

Commit 90deacd

Browse files
Robyn Koschingzx2c4
authored andcommitted
wg-quick: pass on # comments to {Pre,Post}{Up,Down}
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 <[email protected]> [Jason: massage commit message, port to other platforms] Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 780182e commit 90deacd

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/wg-quick/darwin.bash

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ parse_options() {
6262
stripped="${line%%\#*}"
6363
key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
6464
value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
65+
unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
6566
[[ $key == "["* ]] && interface_section=0
6667
[[ $key == "[Interface]" ]] && interface_section=1
6768
if [[ $interface_section -eq 1 ]]; then
@@ -72,10 +73,10 @@ parse_options() {
7273
[[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
7374
done; continue ;;
7475
Table) TABLE="$value"; continue ;;
75-
PreUp) PRE_UP+=( "$value" ); continue ;;
76-
PreDown) PRE_DOWN+=( "$value" ); continue ;;
77-
PostUp) POST_UP+=( "$value" ); continue ;;
78-
PostDown) POST_DOWN+=( "$value" ); continue ;;
76+
PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
77+
PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
78+
PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
79+
PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
7980
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
8081
esac
8182
fi

src/wg-quick/freebsd.bash

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ parse_options() {
8080
stripped="${line%%\#*}"
8181
key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
8282
value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
83+
unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
8384
[[ $key == "["* ]] && interface_section=0
8485
[[ $key == "[Interface]" ]] && interface_section=1
8586
if [[ $interface_section -eq 1 ]]; then
@@ -90,10 +91,10 @@ parse_options() {
9091
[[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
9192
done; continue ;;
9293
Table) TABLE="$value"; continue ;;
93-
PreUp) PRE_UP+=( "$value" ); continue ;;
94-
PreDown) PRE_DOWN+=( "$value" ); continue ;;
95-
PostUp) POST_UP+=( "$value" ); continue ;;
96-
PostDown) POST_DOWN+=( "$value" ); continue ;;
94+
PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
95+
PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
96+
PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
97+
PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
9798
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
9899
esac
99100
fi

src/wg-quick/linux.bash

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ parse_options() {
5151
stripped="${line%%\#*}"
5252
key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
5353
value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
54+
unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
5455
[[ $key == "["* ]] && interface_section=0
5556
[[ $key == "[Interface]" ]] && interface_section=1
5657
if [[ $interface_section -eq 1 ]]; then
@@ -61,10 +62,10 @@ parse_options() {
6162
[[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
6263
done; continue ;;
6364
Table) TABLE="$value"; continue ;;
64-
PreUp) PRE_UP+=( "$value" ); continue ;;
65-
PreDown) PRE_DOWN+=( "$value" ); continue ;;
66-
PostUp) POST_UP+=( "$value" ); continue ;;
67-
PostDown) POST_DOWN+=( "$value" ); continue ;;
65+
PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
66+
PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
67+
PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
68+
PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
6869
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
6970
esac
7071
fi

src/wg-quick/openbsd.bash

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ parse_options() {
5252
stripped="${line%%\#*}"
5353
key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
5454
value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
55+
unstripped_value="${line#*=}"; unstripped_value="${unstripped_value##*([[:space:]])}"; unstripped_value="${unstripped_value%%*([[:space:]])}"
5556
[[ $key == "["* ]] && interface_section=0
5657
[[ $key == "[Interface]" ]] && interface_section=1
5758
if [[ $interface_section -eq 1 ]]; then
@@ -62,10 +63,10 @@ parse_options() {
6263
[[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
6364
done; continue ;;
6465
Table) TABLE="$value"; continue ;;
65-
PreUp) PRE_UP+=( "$value" ); continue ;;
66-
PreDown) PRE_DOWN+=( "$value" ); continue ;;
67-
PostUp) POST_UP+=( "$value" ); continue ;;
68-
PostDown) POST_DOWN+=( "$value" ); continue ;;
66+
PreUp) PRE_UP+=( "$unstripped_value" ); continue ;;
67+
PreDown) PRE_DOWN+=( "$unstripped_value" ); continue ;;
68+
PostUp) POST_UP+=( "$unstripped_value" ); continue ;;
69+
PostDown) POST_DOWN+=( "$unstripped_value" ); continue ;;
6970
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
7071
esac
7172
fi

0 commit comments

Comments
 (0)