mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-08-02 09:32:51 +02:00
fix: special handshake clean line
This commit is contained in:
parent
dbd48bde71
commit
bb9f1632cd
2 changed files with 38 additions and 21 deletions
56
src/config.c
56
src/config.c
|
@ -23,7 +23,7 @@
|
||||||
#define COMMENT_CHAR '#'
|
#define COMMENT_CHAR '#'
|
||||||
|
|
||||||
// Keys that should return empty string instead of NULL when not found
|
// Keys that should return empty string instead of NULL when not found
|
||||||
static const char *awg_optional_keys[] = {
|
static const char *awg_special_handshake_keys[] = {
|
||||||
"I1", "I2", "I3", "I4", "I5",
|
"I1", "I2", "I3", "I4", "I5",
|
||||||
"J1", "J2", "J3",
|
"J1", "J2", "J3",
|
||||||
NULL
|
NULL
|
||||||
|
@ -627,13 +627,6 @@ static bool process_line(struct config_ctx *ctx, const char *line)
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_ITIME;
|
ctx->device->flags |= WGDEVICE_HAS_ITIME;
|
||||||
} else {
|
} else {
|
||||||
// Check if this is an AWG optional key
|
|
||||||
if (strlen(line) == 3) {
|
|
||||||
for (int i = 0; awg_optional_keys[i] != NULL; i++) {
|
|
||||||
if (!strncasecmp(line, awg_optional_keys[i], 2))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (ctx->is_peer_section) {
|
} else if (ctx->is_peer_section) {
|
||||||
|
@ -677,9 +670,6 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
|
||||||
size_t len, cleaned_len = 0;
|
size_t len, cleaned_len = 0;
|
||||||
char *line, *comment;
|
char *line, *comment;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
bool found_equals = false;
|
|
||||||
bool found_value_start = false;
|
|
||||||
size_t value_end = 0;
|
|
||||||
|
|
||||||
/* This is what strchrnul is for, but that isn't portable. */
|
/* This is what strchrnul is for, but that isn't portable. */
|
||||||
comment = strchr(input, COMMENT_CHAR);
|
comment = strchr(input, COMMENT_CHAR);
|
||||||
|
@ -695,6 +685,40 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_awg_special_handshake_key = false;
|
||||||
|
for (size_t i = 0; awg_special_handshake_keys[i] != NULL; i++) {
|
||||||
|
if (!strncasecmp(input, awg_special_handshake_keys[i], 2)) {
|
||||||
|
is_awg_special_handshake_key = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_awg_special_handshake_key) {
|
||||||
|
cleaned_len = clean_special_handshake_line(input, len, line);
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
if (!char_is_space(input[i])) {
|
||||||
|
line[cleaned_len++] = input[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!cleaned_len)
|
||||||
|
goto out;
|
||||||
|
ret = process_line(ctx, line);
|
||||||
|
out:
|
||||||
|
free(line);
|
||||||
|
if (!ret)
|
||||||
|
free_wgdevice(ctx->device);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t clean_special_handshake_line(const char *input, size_t len, char *line)
|
||||||
|
{
|
||||||
|
size_t cleaned_len = 0, value_end = 0;
|
||||||
|
bool found_equals = false, found_value_start = false;
|
||||||
|
|
||||||
/* Remove preceding and trailing whitespaces before value
|
/* Remove preceding and trailing whitespaces before value
|
||||||
First pass: find the actual end of the value (trim trailing spaces) */
|
First pass: find the actual end of the value (trim trailing spaces) */
|
||||||
for (size_t i = len; i > 0; --i) {
|
for (size_t i = len; i > 0; --i) {
|
||||||
|
@ -725,15 +749,7 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
|
||||||
line[cleaned_len++] = input[i];
|
line[cleaned_len++] = input[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return cleaned_len;
|
||||||
if (!cleaned_len)
|
|
||||||
goto out;
|
|
||||||
ret = process_line(ctx, line);
|
|
||||||
out:
|
|
||||||
free(line);
|
|
||||||
if (!ret)
|
|
||||||
free_wgdevice(ctx->device);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool config_read_init(struct config_ctx *ctx, bool append)
|
bool config_read_init(struct config_ctx *ctx, bool append)
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct config_ctx {
|
||||||
bool is_peer_section, is_device_section;
|
bool is_peer_section, is_device_section;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
size_t clean_special_handshake_line(const char *input, size_t len, char *line);
|
||||||
struct wgdevice *config_read_cmd(const char *argv[], int argc);
|
struct wgdevice *config_read_cmd(const char *argv[], int argc);
|
||||||
bool config_read_init(struct config_ctx *ctx, bool append);
|
bool config_read_init(struct config_ctx *ctx, bool append);
|
||||||
bool config_read_line(struct config_ctx *ctx, const char *line);
|
bool config_read_line(struct config_ctx *ctx, const char *line);
|
||||||
|
|
Loading…
Add table
Reference in a new issue