Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/haad/proxychains.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2012-07-09 01:32:50 +0400
committerrofl0r <retnyg@gmx.net>2012-07-09 01:32:50 +0400
commitfba5f5694c1da1ff21039a4992ce3adda427f0fb (patch)
treef6a03b09656540fd76e502a471c3d1ed83e8a802 /src
parent1a02b9f82f37c4ff62e7eb56dbf153e4fff48d37 (diff)
use config file lookup routine from a common place
Diffstat (limited to 'src')
-rw-r--r--src/common.c46
-rw-r--r--src/common.h4
-rw-r--r--src/libproxychains.c25
-rw-r--r--src/main.c39
4 files changed, 62 insertions, 52 deletions
diff --git a/src/common.c b/src/common.c
new file mode 100644
index 0000000..8c4b993
--- /dev/null
+++ b/src/common.c
@@ -0,0 +1,46 @@
+#include "common.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+static int check_path(char *path) {
+ if(!path)
+ return 0;
+ return access(path, R_OK) != -1;
+}
+
+char *get_config_path(char* pbuf, size_t bufsize) {
+ char buf[512];
+ // priority 1: env var PROXYCHAINS_CONF_FILE
+ char *path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
+ if(check_path(path))
+ goto have;
+
+ // priority 2; proxychains conf in actual dir
+ path = getcwd(buf, sizeof(buf));
+ snprintf(pbuf, bufsize, "%s/%s", path, PROXYCHAINS_CONF_FILE);
+ path = pbuf;
+ if(check_path(path))
+ goto have;
+
+ // priority 3; $HOME/.proxychains/proxychains.conf
+ path = getenv("HOME");
+ snprintf(pbuf, bufsize, "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
+ path = pbuf;
+ if(check_path(path))
+ goto have;
+
+ // priority 4: $SYSCONFDIR/proxychains.conf
+ path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
+ if(check_path(path))
+ goto have;
+
+ // priority 5: /etc/proxychains.conf
+ path = "/etc/" PROXYCHAINS_CONF_FILE;
+ if(check_path(path))
+ goto have;
+
+ return NULL;
+ have:
+ return path;
+}
diff --git a/src/common.h b/src/common.h
index ecfc33c..f4fd841 100644
--- a/src/common.h
+++ b/src/common.h
@@ -2,3 +2,7 @@
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
#define LOG_PREFIX "[proxychains] "
+
+#include <stddef.h>
+
+char *get_config_path(char* pbuf, size_t bufsize); \ No newline at end of file
diff --git a/src/libproxychains.c b/src/libproxychains.c
index 16b6e3d..c690b16 100644
--- a/src/libproxychains.c
+++ b/src/libproxychains.c
@@ -141,7 +141,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
char *env;
char local_in_addr_port[32];
char local_in_addr[32], local_in_port[32], local_netmask[32];
- FILE *file;
+ FILE *file = NULL;
if(proxychains_got_chain_data)
return;
@@ -151,21 +151,16 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
tcp_connect_time_out = 10 * 1000;
*ct = DYNAMIC_TYPE;
- /*
- * Get path to configuration file from env this file has priority
- * if it's defined.
- */
+ /* Get path to configuration file from env.
+ * this file has priority if it's defined. */
+
env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
-
- snprintf(buff, 256, "%s/.proxychains/proxychains.conf", getenv("HOME"));
-
- if(!env || (!(file = fopen(env, "r"))))
- if(!(file = fopen("./proxychains.conf", "r")))
- if(!(file = fopen(buff, "r")))
- if(!(file = fopen("/etc/proxychains.conf", "r"))) {
- perror("Can't locate proxychains.conf");
- exit(1);
- }
+ 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);
if(env && *env == '1')
diff --git a/src/main.c b/src/main.c
index 7e3b8f0..6a21c37 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,12 +36,6 @@ static int usage(char **argv) {
return EXIT_FAILURE;
}
-int check_path(char *path) {
- if(!path)
- return 0;
- return access(path, R_OK) != -1;
-}
-
static const char *dll_name = DLL_NAME;
static char own_dir[256];
@@ -101,41 +95,12 @@ int main(int argc, char *argv[]) {
return usage(argv);
/* check if path of config file has not been passed via command line */
+ if(!path) path = get_config_path(pbuf, sizeof(pbuf));
if(!path) {
- // priority 1: env var PROXYCHAINS_CONF_FILE
- path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
- if(check_path(path))
- goto have;
-
- // priority 2; proxychains conf in actual dir
- path = getcwd(buf, sizeof(buf));
- snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE);
- path = pbuf;
- if(check_path(path))
- goto have;
-
- // priority 3; $HOME/.proxychains/proxychains.conf
- path = getenv("HOME");
- snprintf(pbuf, sizeof(pbuf), "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
- path = pbuf;
- if(check_path(path))
- goto have;
-
- // priority 4: $SYSCONFDIR/proxychains.conf
- path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
- if(check_path(path))
- goto have;
-
- // priority 5: /etc/proxychains.conf
- path = "/etc/" PROXYCHAINS_CONF_FILE;
- if(check_path(path))
- goto have;
perror("couldnt find configuration file");
return 1;
}
-
- have:
-
+
if(!quiet)
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);