]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: allow in-line comments
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 16 Feb 2018 19:10:25 +0000 (20:10 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 17 Feb 2018 04:55:03 +0000 (05:55 +0100)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
contrib/reresolve-dns/reresolve-dns.sh
src/config.c
src/wg-quick.bash
src/wg.8

index 7f913ab65e2a26ce68c3a8aeb8e052ddd5d41215..5b9394b2100c37b607258a1473b54480dfa5e3ad 100755 (executable)
@@ -29,8 +29,9 @@ reset_peer_section() {
 
 reset_peer_section
 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 == "["* ]] && { process_peer; reset_peer_section; }
        [[ $key == "[Peer]" ]] && PEER_SECTION=1
        if [[ $PEER_SECTION -eq 1 ]]; then
index 0407b36405151ec8b0c2a39c9c9ec91a8582260f..93c39fa3bca6bb31e9e6314bd7f78d302862215e 100644 (file)
@@ -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);
index 80921bf07195141d481bd19a0dcb57186f32e792..af72f7d2d0125ab39184fcaecdfac7f8aa8031f2 100755 (executable)
@@ -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
index 612fb4e0a0553cf52ba21083a6bb7cbb3db3d08f..ebfb7f6f6f104bef621bf89d16355081713f3fde 100644 (file)
--- a/src/wg.8
+++ b/src/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