diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-16 20:10:25 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-17 05:55:03 +0100 |
commit | a3b104108ebd06c2585d8bf4cbea1ed51c955c5e (patch) | |
tree | 18bdcdff754ce7973278dab5389c7f3b44ff39d4 /src/tools | |
parent | external-tests: update go version (diff) | |
download | wireguard-monolithic-historical-a3b104108ebd06c2585d8bf4cbea1ed51c955c5e.tar.xz wireguard-monolithic-historical-a3b104108ebd06c2585d8bf4cbea1ed51c955c5e.zip |
tools: allow in-line comments
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/config.c | 17 | ||||
-rwxr-xr-x | src/tools/wg-quick.bash | 7 | ||||
-rw-r--r-- | src/tools/wg.8 | 4 |
3 files changed, 17 insertions, 11 deletions
diff --git a/src/tools/config.c b/src/tools/config.c index 0407b36..93c39fa 100644 --- a/src/tools/config.c +++ b/src/tools/config.c @@ -417,25 +417,30 @@ error: bool config_read_line(struct config_ctx *ctx, const char *input) { - size_t len = strlen(input), cleaned_len = 0; - char *line = calloc(len + 1, sizeof(char)); + size_t len, cleaned_len = 0; + char *line, *comment; bool ret = true; + /* This is what strchrnull is for, but that isn't portable. */ + comment = strchr(input, COMMENT_CHAR); + if (comment) + len = comment - input; + else + len = strlen(input); + + line = calloc(len + 1, sizeof(char)); if (!line) { perror("calloc"); ret = false; goto out; } - if (!len) - goto out; + for (size_t i = 0; i < len; ++i) { if (!isspace(input[i])) line[cleaned_len++] = input[i]; } if (!cleaned_len) goto out; - if (line[0] == COMMENT_CHAR) - goto out; ret = process_line(ctx, line); out: free(line); diff --git a/src/tools/wg-quick.bash b/src/tools/wg-quick.bash index 80921bf..af72f7d 100755 --- a/src/tools/wg-quick.bash +++ b/src/tools/wg-quick.bash @@ -27,7 +27,7 @@ PROGRAM="${0##*/}" ARGS=( "$@" ) parse_options() { - local interface_section=0 line key value + local interface_section=0 line key value stripped CONFIG_FILE="$1" [[ $CONFIG_FILE =~ ^[a-zA-Z0-9_=+.-]{1,15}$ ]] && CONFIG_FILE="/etc/wireguard/$CONFIG_FILE.conf" [[ -e $CONFIG_FILE ]] || die "\`$CONFIG_FILE' does not exist" @@ -37,8 +37,9 @@ parse_options() { INTERFACE="${BASH_REMATCH[2]}" shopt -s nocasematch while read -r line || [[ -n $line ]]; do - key="${line%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}" - value="${line#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}" + stripped="${line%%\#*}" + key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}" + value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}" [[ $key == "["* ]] && interface_section=0 [[ $key == "[Interface]" ]] && interface_section=1 if [[ $interface_section -eq 1 ]]; then diff --git a/src/tools/wg.8 b/src/tools/wg.8 index 612fb4e..ebfb7f6 100644 --- a/src/tools/wg.8 +++ b/src/tools/wg.8 @@ -165,8 +165,8 @@ when unspecified, this option is off. Most users will not need this. Optional. .SH CONFIGURATION FILE FORMAT EXAMPLE This example may be used as a model for writing configuration files, following an -INI-like syntax. Lines that start with a '#' are considered comments and are thus -ignored. +INI-like syntax. Characters after and including a '#' are considered comments and +are thus ignored. [Interface] .br |