mirror of
https://github.com/rofl0r/proxychains-ng
synced 2025-01-09 14:52:52 +08:00
put abort functionality into get_config_path to further reduce code duplication
This commit is contained in:
parent
fafeaf5936
commit
e5e87c8f22
12
src/common.c
12
src/common.c
@ -9,10 +9,15 @@ static int check_path(char *path) {
|
|||||||
return access(path, R_OK) != -1;
|
return access(path, R_OK) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_config_path(char* pbuf, size_t bufsize) {
|
char *get_config_path(char* default_path, char* pbuf, size_t bufsize) {
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
// top priority: user defined path
|
||||||
|
char *path = default_path;
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
// priority 1: env var PROXYCHAINS_CONF_FILE
|
// priority 1: env var PROXYCHAINS_CONF_FILE
|
||||||
char *path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||||
if(check_path(path))
|
if(check_path(path))
|
||||||
goto have;
|
goto have;
|
||||||
|
|
||||||
@ -40,6 +45,9 @@ char *get_config_path(char* pbuf, size_t bufsize) {
|
|||||||
if(check_path(path))
|
if(check_path(path))
|
||||||
goto have;
|
goto have;
|
||||||
|
|
||||||
|
perror("couldnt find configuration file");
|
||||||
|
exit(1);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
have:
|
have:
|
||||||
return path;
|
return path;
|
||||||
|
@ -5,4 +5,4 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
char *get_config_path(char* pbuf, size_t bufsize);
|
char *get_config_path(char* default_path, char* pbuf, size_t bufsize);
|
@ -151,16 +151,8 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
|||||||
tcp_connect_time_out = 10 * 1000;
|
tcp_connect_time_out = 10 * 1000;
|
||||||
*ct = DYNAMIC_TYPE;
|
*ct = DYNAMIC_TYPE;
|
||||||
|
|
||||||
/* Get path to configuration file from env.
|
env = get_config_path(getenv(PROXYCHAINS_CONF_FILE_ENV_VAR), buff, sizeof(buff));
|
||||||
* this file has priority if it's defined. */
|
file = fopen(env, "r");
|
||||||
|
|
||||||
env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
|
||||||
if(!env) env = get_config_path(buff, sizeof(buff));
|
|
||||||
if(env) file = fopen(env, "r");
|
|
||||||
if(!file) {
|
|
||||||
perror("Can't locate proxychains.conf");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
||||||
if(env && *env == '1')
|
if(env && *env == '1')
|
||||||
|
@ -95,11 +95,7 @@ int main(int argc, char *argv[]) {
|
|||||||
return usage(argv);
|
return usage(argv);
|
||||||
|
|
||||||
/* check if path of config file has not been passed via command line */
|
/* check if path of config file has not been passed via command line */
|
||||||
if(!path) path = get_config_path(pbuf, sizeof(pbuf));
|
path = get_config_path(path, pbuf, sizeof(pbuf));
|
||||||
if(!path) {
|
|
||||||
perror("couldnt find configuration file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!quiet)
|
if(!quiet)
|
||||||
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
||||||
|
Loading…
Reference in New Issue
Block a user