diff --git a/include/applet/adguard.h b/include/applet/adguard.h index c904eb3..060a152 100644 --- a/include/applet/adguard.h +++ b/include/applet/adguard.h @@ -1,5 +1,5 @@ -#ifndef _ADGUARD_H_ -#define _ADGUARD_H_ +#ifndef ADGUARD_H_ +#define ADGUARD_H_ #include #include "process.h" diff --git a/include/applet/dnsproxy.h b/include/applet/dnsproxy.h index 68eb67c..564d320 100644 --- a/include/applet/dnsproxy.h +++ b/include/applet/dnsproxy.h @@ -1,5 +1,5 @@ -#ifndef _DNSPROXY_H_ -#define _DNSPROXY_H_ +#ifndef DNSPROXY_H_ +#define DNSPROXY_H_ #include #include "process.h" diff --git a/include/applet/overture.h b/include/applet/overture.h index 476942a..beb8646 100644 --- a/include/applet/overture.h +++ b/include/applet/overture.h @@ -1,5 +1,5 @@ -#ifndef _OVERTURE_H_ -#define _OVERTURE_H_ +#ifndef OVERTURE_H_ +#define OVERTURE_H_ #include #include "process.h" diff --git a/include/common/constant.h b/include/common/constant.h index 16d6ace..bbcc630 100644 --- a/include/common/constant.h +++ b/include/common/constant.h @@ -1,5 +1,5 @@ -#ifndef _CONSTANT_H_ -#define _CONSTANT_H_ +#ifndef CONSTANT_H_ +#define CONSTANT_H_ #define VERSION "1.3.0-dev" diff --git a/include/common/json.h b/include/common/json.h index 45929ae..054c03c 100644 --- a/include/common/json.h +++ b/include/common/json.h @@ -1,5 +1,5 @@ -#ifndef _JSON_H_ -#define _JSON_H_ +#ifndef JSON_H_ +#define JSON_H_ #include #include "cJSON.h" diff --git a/include/common/structure.h b/include/common/structure.h index 403844c..ccc77ba 100644 --- a/include/common/structure.h +++ b/include/common/structure.h @@ -1,5 +1,5 @@ -#ifndef _STRUCTURE_H_ -#define _STRUCTURE_H_ +#ifndef STRUCTURE_H_ +#define STRUCTURE_H_ #include diff --git a/include/common/sundry.h b/include/common/sundry.h index 621470b..c10542d 100644 --- a/include/common/sundry.h +++ b/include/common/sundry.h @@ -1,5 +1,5 @@ -#ifndef _SUNDRY_H_ -#define _SUNDRY_H_ +#ifndef SUNDRY_H_ +#define SUNDRY_H_ #include diff --git a/include/common/system.h b/include/common/system.h index a6325bc..0404664 100644 --- a/include/common/system.h +++ b/include/common/system.h @@ -1,14 +1,14 @@ -#ifndef _SYSTEM_H_ -#define _SYSTEM_H_ +#ifndef SYSTEM_H_ +#define SYSTEM_H_ #include char* read_file(const char *file); +void remove_file(const char *file); int run_command(const char *command); void create_folder(const char *folder); uint8_t is_file_exist(const char *file); void save_file(const char *file, const char *content); void save_string_list(const char *file, char **string_list); - #endif diff --git a/include/flag.h b/include/flag.h deleted file mode 100644 index dc0cf2c..0000000 --- a/include/flag.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _EXIT_CODE_H_ -#define _EXIT_CODE_H_ - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#define EXIT_NORMAL 0 -#define EXIT_FILE_ERROR 1 -#define EXIT_FORK_ERROR 2 -#define EXIT_EXEC_ERROR 3 -#define EXIT_WAIT_ERROR 4 - -#endif diff --git a/include/loader/config.h b/include/loader/config.h index de1f2d0..b14e3e2 100644 --- a/include/loader/config.h +++ b/include/loader/config.h @@ -1,5 +1,5 @@ -#ifndef _CONFIG_H_ -#define _CONFIG_H_ +#ifndef CONFIG_H_ +#define CONFIG_H_ #include diff --git a/include/loader/loader.h b/include/loader/loader.h index 5b01f08..3f5f359 100644 --- a/include/loader/loader.h +++ b/include/loader/loader.h @@ -1,5 +1,5 @@ -#ifndef _LOADER_H_ -#define _LOADER_H_ +#ifndef LOADER_H_ +#define LOADER_H_ #include "adguard.h" #include "dnsproxy.h" diff --git a/include/loader/parser.h b/include/loader/parser.h index de25ad7..15a02de 100644 --- a/include/loader/parser.h +++ b/include/loader/parser.h @@ -1,5 +1,5 @@ -#ifndef _PARSER_H_ -#define _PARSER_H_ +#ifndef PARSER_H_ +#define PARSER_H_ #include "config.h" diff --git a/include/utils/logger.h b/include/utils/logger.h index 66c8b42..59ca40f 100644 --- a/include/utils/logger.h +++ b/include/utils/logger.h @@ -1,5 +1,5 @@ -#ifndef _LOGGER_H_ -#define _LOGGER_H_ +#ifndef LOGGER_H_ +#define LOGGER_H_ #define LOG_PREFIX "ClearDNS" diff --git a/include/utils/process.h b/include/utils/process.h index ce9d8c5..b4b5969 100644 --- a/include/utils/process.h +++ b/include/utils/process.h @@ -1,5 +1,5 @@ -#ifndef _PROCESS_H_ -#define _PROCESS_H_ +#ifndef PROCESS_H_ +#define PROCESS_H_ typedef struct { char *name; diff --git a/src/applet/adguard.c b/src/applet/adguard.c index 38470c6..3b7aeb6 100644 --- a/src/applet/adguard.c +++ b/src/applet/adguard.c @@ -1,4 +1,5 @@ #include +#include #include "json.h" #include "bcrypt.h" #include "logger.h" @@ -76,6 +77,12 @@ process* adguard_load(adguard *info, const char *dir) { // load adguard options if (!check_port(info->web_port)) { // invalid web port log_fatal("Invalid web port `%u`", info->web_port); } + if (!strcmp(info->username, "")) { // invalid username + log_fatal("Invalid AdGuardHome username"); + } + if (!strcmp(info->password, "")) { // invalid password + log_fatal("Invalid AdGuardHome password"); + } create_folder(dir); // ensure adguard work dir exist char *adguard_config_ret; diff --git a/src/cleardns.c b/src/cleardns.c index 1995dd9..0626768 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -42,15 +42,6 @@ int main(int argc, char *argv[]) { // ClearDNS server LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); -// if (is_file_exist("/tmp/test")) { -// log_info("File exist"); -// } - -// create_folder("/tmp/test"); -// run_command("exit 3"); - run_command("exit"); - - return 0; // char **temp = string_list_init(); // diff --git a/src/common/json.c b/src/common/json.c index a4cc53f..623958d 100644 --- a/src/common/json.c +++ b/src/common/json.c @@ -26,20 +26,17 @@ char* to_json(const char *file) { // convert JSON / TOML / YAML to json format ( } flag[8] = '\0'; - char *output_file = string_join("/tmp/tojson-", flag); + char *output_file = string_join("/tmp/to-json-", flag); char *to_json_cmd = (char *)malloc(strlen(file) + strlen(output_file) + 11); sprintf(to_json_cmd, "toJSON %s > %s", file, output_file); int to_json_ret = run_command(to_json_cmd); free(to_json_cmd); - char *remove_cmd = string_join("rm -f ", output_file); - run_command(remove_cmd); - free(remove_cmd); - if (to_json_ret) { // toJSON return non-zero code - free(output_file); - return NULL; // convert failed + char *json_content = NULL; + if (!to_json_ret) { // toJSON return zero code (convert fine) + json_content = read_file(output_file); } - char *json_content = read_file(output_file); + remove_file(output_file); free(output_file); return json_content; } diff --git a/src/common/system.c b/src/common/system.c index 9de03f0..aa318ef 100644 --- a/src/common/system.c +++ b/src/common/system.c @@ -15,6 +15,12 @@ int run_command(const char *command) { // running command with system shell return ret; } +void remove_file(const char *file) { + char *remove_cmd = string_join("rm -f ", file); + run_command(remove_cmd); + free(remove_cmd); +} + void create_folder(const char *folder) { // create folder if (!access(folder, 0)) { // target is file or folder struct stat buf; diff --git a/src/common_legacy.c b/src/common_legacy.c index ae9d59e..e27044e 100644 --- a/src/common_legacy.c +++ b/src/common_legacy.c @@ -2,7 +2,7 @@ #include #include #include "cJSON.h" -#include "flag.h" +#include "flag_legacy.h" char **adguard_command = NULL; char **overture_command = NULL; diff --git a/src/loader/loader.c b/src/loader/loader.c index c134c99..6d9a946 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -94,8 +94,8 @@ adguard* load_filter(cleardns_config *config) { adguard *filter = adguard_init(); filter->dns_port = config->port; filter->web_port = config->adguard.port; - filter->username = config->adguard.username; - filter->password = config->adguard.password; + filter->username = string_init(config->adguard.username); + filter->password = string_init(config->adguard.password); char *diverter_port = uint32_to_string(config->diverter.port); filter->upstream = string_join("127.0.0.1:", diverter_port); free(diverter_port); diff --git a/src/process_legacy.c b/src/process_legacy.c index c76c349..10757f3 100644 --- a/src/process_legacy.c +++ b/src/process_legacy.c @@ -7,7 +7,7 @@ #include #include #include "constant.h" -#include "flag.h" +#include "flag_legacy.h" int exiting = 0;