From 6cfc45143f21cedb294d2886c95ae718499f02a1 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 7 Dec 2017 05:04:04 +0100 Subject: Check for files in both locations --- wg-quick.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/wg-quick.c b/wg-quick.c index d131885..08a5486 100644 --- a/wg-quick.c +++ b/wg-quick.c @@ -138,6 +138,7 @@ static char *vcmd_ret(struct command_buffer *c, const char *cmd_fmt, va_list arg exit(errno); } } + errno = 0; if (getline(&c->line, &c->len, c->stream) < 0) { if (errno) { perror("Error: getline"); @@ -427,7 +428,8 @@ static void cmd_usage(const char *program) "\n" " CONFIG_FILE is a configuration file, whose filename is the interface name\n" " followed by `.conf'. Otherwise, INTERFACE is an interface name, with\n" - " configuration found at /data/misc/wireguard/INTERFACE.conf. It is to be readable\n" + " configuration found at /data/misc/wireguard/INTERFACE.conf or\n" + " /data/data/com.wireguard.android/files/INTERFACE.conf. It is to be readable\n" " by wg(8)'s `setconf' sub-command, with the exception of the following additions\n" " to the [Interface] section, which are handled by %s:\n" "\n" @@ -520,13 +522,26 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char * perror("Error: asprintf"); exit(errno); } - } else + file = fopen(filename, "r"); + if (!file) { + free(filename); + if (asprintf(&filename, "/data/data/com.wireguard.android/files/%s.conf", arg) < 0) { + perror("Error: asprintf"); + exit(errno); + } + file = fopen(filename, "r"); + if (!file) { + fprintf(stderr, "Error: Unable to find configuration file for `%s' in either /data/misc/wireguard/ or /data/data/com.wireguard.android/files/\n", arg); + exit(errno); + } + } + } else { filename = xstrdup(arg); - - file = fopen(filename, "r"); - if (!file) { - fprintf(stderr, "Error: Unable to open configuration file `%s': %s\n", filename, strerror(errno)); - exit(errno); + file = fopen(filename, "r"); + if (!file) { + fprintf(stderr, "Error: Unable to find configuration file at `%s'\n", filename); + exit(errno); + } } if (regexec(®ex_conf, filename, ARRAY_SIZE(matches), matches, 0)) { -- cgit v1.2.3-59-g8ed1b