ran indent tool on the source code

now everythings finally correctly indented and future patches
will not be overshadowed by whitespace noise.
used the following settings
--braces-on-func-def-line
--braces-on-struct-decl-line
--braces-on-if-line
--dont-break-procedure-type
--leave-preprocessor-space
--continue-at-parentheses
-linux
-i8
-brace-indent1
--case-indentation8
--space-after-cast
--line-length120
--no-space-after-for
--no-space-after-if
--no-space-after-while
--leave-optional-blank-lines
--ignore-profile
--space-special-semicolon
--indent-label8
This commit is contained in:
rofl0r 2012-01-27 18:59:44 +01:00
parent 80817dbf6f
commit e32ef26fec
3 changed files with 634 additions and 685 deletions

File diff suppressed because it is too large Load Diff

View File

@ -57,12 +57,10 @@ localaddr_arg localnet_addr[MAX_LOCALNET];
size_t num_localnet_addr = 0;
unsigned int remote_dns_subnet = 224;
static inline void get_chain_data(proxy_data *pd, unsigned int *proxy_count,
chain_type *ct);
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
static void init_lib(void);
static void init_lib(void)
{
static void init_lib(void) {
#ifdef THREAD_SAFE
pthread_mutex_init(&internal_ips_lock, NULL);
#endif
@ -73,114 +71,96 @@ static void init_lib(void)
true_connect = (connect_t) dlsym(RTLD_NEXT, "connect");
if (!true_connect) {
if(!true_connect) {
fprintf(stderr, "Cannot load symbol 'connect' %s\n", dlerror());
exit(1);
} else {
#ifdef DEBUG
PDEBUG( "loaded symbol 'connect'"
" real addr %p wrapped addr %p\n",
true_connect, connect);
#endif
#ifdef DEBUG
PDEBUG("loaded symbol 'connect'" " real addr %p wrapped addr %p\n", true_connect, connect);
#endif
}
if(connect==true_connect) {
#ifdef DEBUG
if(connect == true_connect) {
#ifdef DEBUG
PDEBUG("circular reference detected, aborting!\n");
#endif
#endif
abort();
}
true_gethostbyname = (gethostbyname_t)
dlsym(RTLD_NEXT, "gethostbyname");
dlsym(RTLD_NEXT, "gethostbyname");
if (!true_gethostbyname) {
fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n",
dlerror());
if(!true_gethostbyname) {
fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n", dlerror());
exit(1);
} else {
#ifdef DEBUG
PDEBUG( "loaded symbol 'gethostbyname'"
" real addr %p wrapped addr %p\n",
true_gethostbyname, gethostbyname);
#endif
#ifdef DEBUG
PDEBUG("loaded symbol 'gethostbyname'"
" real addr %p wrapped addr %p\n", true_gethostbyname, gethostbyname);
#endif
}
true_getaddrinfo = (getaddrinfo_t)
dlsym(RTLD_NEXT, "getaddrinfo");
dlsym(RTLD_NEXT, "getaddrinfo");
if (!true_getaddrinfo) {
fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n",
dlerror());
if(!true_getaddrinfo) {
fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n", dlerror());
exit(1);
} else {
#ifdef DEBUG
PDEBUG( "loaded symbol 'getaddrinfo'"
" real addr %p wrapped addr %p\n",
true_getaddrinfo, getaddrinfo);
#endif
#ifdef DEBUG
PDEBUG("loaded symbol 'getaddrinfo'" " real addr %p wrapped addr %p\n", true_getaddrinfo, getaddrinfo);
#endif
}
true_freeaddrinfo = (freeaddrinfo_t)
dlsym(RTLD_NEXT, "freeaddrinfo");
dlsym(RTLD_NEXT, "freeaddrinfo");
if (!true_freeaddrinfo) {
fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n",
dlerror());
if(!true_freeaddrinfo) {
fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n", dlerror());
exit(1);
} else {
#ifdef DEBUG
PDEBUG( "loaded symbol 'freeaddrinfo'"
" real addr %p wrapped addr %p\n",
true_freeaddrinfo, freeaddrinfo);
#endif
#ifdef DEBUG
PDEBUG("loaded symbol 'freeaddrinfo'"
" real addr %p wrapped addr %p\n", true_freeaddrinfo, freeaddrinfo);
#endif
}
true_gethostbyaddr = (gethostbyaddr_t)
dlsym(RTLD_NEXT, "gethostbyaddr");
dlsym(RTLD_NEXT, "gethostbyaddr");
if (!true_gethostbyaddr) {
fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n",
dlerror());
if(!true_gethostbyaddr) {
fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n", dlerror());
exit(1);
} else {
#ifdef DEBUG
PDEBUG( "loaded symbol 'gethostbyaddr'"
" real addr %p wrapped addr %p\n",
true_gethostbyaddr, gethostbyaddr);
#endif
#ifdef DEBUG
PDEBUG("loaded symbol 'gethostbyaddr'"
" real addr %p wrapped addr %p\n", true_gethostbyaddr, gethostbyaddr);
#endif
}
true_getnameinfo = (getnameinfo_t)
dlsym(RTLD_NEXT, "getnameinfo");
dlsym(RTLD_NEXT, "getnameinfo");
if (!true_getnameinfo) {
fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n",
dlerror());
if(!true_getnameinfo) {
fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n", dlerror());
exit(1);
} else {
#ifdef DEBUG
PDEBUG( "loaded symbol 'getnameinfo'"
" real addr %p wrapped addr %p\n",
true_getnameinfo, getnameinfo);
#endif
#ifdef DEBUG
PDEBUG("loaded symbol 'getnameinfo'" " real addr %p wrapped addr %p\n", true_getnameinfo, getnameinfo);
#endif
}
init_l = 1;
}
static inline void get_chain_data(
proxy_data *pd,
unsigned int *proxy_count,
chain_type *ct)
{
int count=0,port_n=0,list=0;
char buff[1024],type[1024],host[1024],user[1024];
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
int count = 0, port_n = 0, list = 0;
char buff[1024], type[1024], host[1024], user[1024];
char *env;
char local_in_addr_port[32];
char local_in_addr[32], local_in_port[32], local_netmask[32];
FILE* file;
FILE *file;
if(proxychains_got_chain_data)
return;
return;
//Some defaults
tcp_read_time_out = 4*1000;
tcp_connect_time_out = 10*1000;
tcp_read_time_out = 4 * 1000;
tcp_connect_time_out = 10 * 1000;
*ct = DYNAMIC_TYPE;
/*
@ -189,119 +169,116 @@ static inline void get_chain_data(
*/
env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
snprintf(buff,256,"%s/.proxychains/proxychains.conf",getenv("HOME"));
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 || (!(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);
}
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
if(env && *env == '1') proxychains_quiet_mode = 1;
if(env && *env == '1')
proxychains_quiet_mode = 1;
while(fgets(buff,sizeof(buff),file)) {
if(buff[0] != '\n' && buff[strspn(buff," ")]!='#') {
while(fgets(buff, sizeof(buff), file)) {
if(buff[0] != '\n' && buff[strspn(buff, " ")] != '#') {
if(list) {
memset(&pd[count], 0, sizeof(proxy_data));
pd[count].ps = PLAY_STATE;
port_n = 0;
sscanf(buff,"%s %s %d %s %s", type, host, &port_n,
pd[count].user, pd[count].pass);
sscanf(buff, "%s %s %d %s %s", type, host, &port_n, pd[count].user, pd[count].pass);
pd[count].ip.as_int = (uint32_t) inet_addr(host);
pd[count].port = htons((unsigned short)port_n);
pd[count].port = htons((unsigned short) port_n);
if(!strcmp(type,"http")) {
if(!strcmp(type, "http")) {
pd[count].pt = HTTP_TYPE;
} else if(!strcmp(type,"socks4")) {
} else if(!strcmp(type, "socks4")) {
pd[count].pt = SOCKS4_TYPE;
} else if(!strcmp(type,"socks5")) {
} else if(!strcmp(type, "socks5")) {
pd[count].pt = SOCKS5_TYPE;
} else
continue;
if(pd[count].ip.as_int && port_n &&
pd[count].ip.as_int != (uint32_t) -1)
if(++count==MAX_CHAIN)
if(pd[count].ip.as_int && port_n && pd[count].ip.as_int != (uint32_t) - 1)
if(++count == MAX_CHAIN)
break;
} else {
if(strstr(buff,"[ProxyList]")) {
list=1;
} else {
if(strstr(buff, "[ProxyList]")) {
list = 1;
} else if(strstr(buff, "random_chain")) {
*ct=RANDOM_TYPE;
*ct = RANDOM_TYPE;
} else if(strstr(buff, "strict_chain")) {
*ct=STRICT_TYPE;
*ct = STRICT_TYPE;
} else if(strstr(buff, "dynamic_chain")) {
*ct=DYNAMIC_TYPE;
} else if(strstr(buff,"tcp_read_time_out")){
*ct = DYNAMIC_TYPE;
} else if(strstr(buff, "tcp_read_time_out")) {
sscanf(buff, "%s %d", user, &tcp_read_time_out);
} else if(strstr(buff,"tcp_connect_time_out")){
} else if(strstr(buff, "tcp_connect_time_out")) {
sscanf(buff, "%s %d", user, &tcp_connect_time_out);
} else if(strstr(buff,"remote_dns_subnet")){
} else if(strstr(buff, "remote_dns_subnet")) {
sscanf(buff, "%s %d", user, &remote_dns_subnet);
if(remote_dns_subnet >= 256) {
fprintf(stderr, "remote_dns_subnet: invalid value. requires a number between 0 and 255.\n");
fprintf(stderr,
"remote_dns_subnet: invalid value. requires a number between 0 and 255.\n");
exit(1);
}
} else if(strstr(buff, "localnet")) {
if (sscanf(buff, "%s %21[^/]/%15s", user,
local_in_addr_port, local_netmask) < 3) {
if(sscanf(buff, "%s %21[^/]/%15s", user, local_in_addr_port, local_netmask) < 3) {
fprintf(stderr, "localnet format error");
exit(1);
}
/* clean previously used buffer */
memset(local_in_port, 0,
sizeof(local_in_port) / sizeof(local_in_port[0]));
memset(local_in_port, 0, sizeof(local_in_port) / sizeof(local_in_port[0]));
if (sscanf(local_in_addr_port, "%15[^:]:%5s",
local_in_addr, local_in_port) < 2) {
PDEBUG("added localnet: netaddr=%s, port=%s\n",
local_in_addr, local_netmask);
if(sscanf(local_in_addr_port, "%15[^:]:%5s", local_in_addr, local_in_port) < 2) {
PDEBUG("added localnet: netaddr=%s, port=%s\n",
local_in_addr, local_netmask);
} else {
PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n",
local_in_addr, local_in_port, local_netmask);
PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n",
local_in_addr, local_in_port, local_netmask);
}
if (num_localnet_addr < MAX_LOCALNET)
{
if(num_localnet_addr < MAX_LOCALNET) {
int error;
error = inet_pton(AF_INET, local_in_addr, &localnet_addr[num_localnet_addr].in_addr);
if (error <= 0)
{
error =
inet_pton(AF_INET, local_in_addr,
&localnet_addr[num_localnet_addr].in_addr);
if(error <= 0) {
fprintf(stderr, "localnet address error\n");
exit(1);
}
error = inet_pton(AF_INET, local_netmask, &localnet_addr[num_localnet_addr].netmask);
if (error <= 0)
{
error =
inet_pton(AF_INET, local_netmask,
&localnet_addr[num_localnet_addr].netmask);
if(error <= 0) {
fprintf(stderr, "localnet netmask error\n");
exit(1);
}
if (local_in_port[0]) {
localnet_addr[num_localnet_addr].port = (short)atoi(local_in_port);
if(local_in_port[0]) {
localnet_addr[num_localnet_addr].port =
(short) atoi(local_in_port);
} else {
localnet_addr[num_localnet_addr].port = 0;
}
++num_localnet_addr;
}
else
{
} else {
fprintf(stderr, "# of localnet exceed %d.\n", MAX_LOCALNET);
}
} else if(strstr(buff,"chain_len")){
char *pc;int len;
pc=strchr(buff,'=');
len=atoi(++pc);
proxychains_max_chain=(len?len:1);
} else if(strstr(buff,"quiet_mode")){
proxychains_quiet_mode=1;
} else if(strstr(buff,"proxy_dns")){
proxychains_resolver=1;
} else if(strstr(buff, "chain_len")) {
char *pc;
int len;
pc = strchr(buff, '=');
len = atoi(++pc);
proxychains_max_chain = (len ? len : 1);
} else if(strstr(buff, "quiet_mode")) {
proxychains_quiet_mode = 1;
} else if(strstr(buff, "proxy_dns")) {
proxychains_resolver = 1;
}
}
}
@ -313,9 +290,8 @@ static inline void get_chain_data(
int connect (int sock, const struct sockaddr *addr, unsigned int len)
{
int socktype=0, flags=0, ret=0;
int connect(int sock, const struct sockaddr *addr, unsigned int len) {
int socktype = 0, flags = 0, ret = 0;
socklen_t optlen = 0;
ip_type dest_ip;
#ifdef DEBUG
@ -327,58 +303,52 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
if(!init_l)
init_lib();
optlen=sizeof(socktype);
getsockopt(sock,SOL_SOCKET,SO_TYPE,&socktype,&optlen);
if (! (SOCKFAMILY(*addr)==AF_INET && socktype==SOCK_STREAM))
return true_connect(sock,addr,len);
optlen = sizeof(socktype);
getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &optlen);
if(!(SOCKFAMILY(*addr) == AF_INET && socktype == SOCK_STREAM))
return true_connect(sock, addr, len);
p_addr_in = &((struct sockaddr_in *)addr)->sin_addr;
port = ntohs(((struct sockaddr_in *)addr)->sin_port);
p_addr_in = &((struct sockaddr_in *) addr)->sin_addr;
port = ntohs(((struct sockaddr_in *) addr)->sin_port);
#ifdef DEBUG
// PDEBUG("localnet: %s; ", inet_ntop(AF_INET,&in_addr_localnet, str, sizeof(str)));
// PDEBUG("netmask: %s; " , inet_ntop(AF_INET, &in_addr_netmask, str, sizeof(str)));
// PDEBUG("localnet: %s; ", inet_ntop(AF_INET,&in_addr_localnet, str, sizeof(str)));
// PDEBUG("netmask: %s; " , inet_ntop(AF_INET, &in_addr_netmask, str, sizeof(str)));
PDEBUG("target: %s\n", inet_ntop(AF_INET, p_addr_in, str, sizeof(str)));
PDEBUG("port: %d\n", port);
#endif
for (i = 0; i < num_localnet_addr; i++) {
if ((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr)
== (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr))
{
if (localnet_addr[i].port || localnet_addr[i].port == port) {
for(i = 0; i < num_localnet_addr; i++) {
if((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr)
== (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr)) {
if(localnet_addr[i].port || localnet_addr[i].port == port) {
PDEBUG("accessing localnet using true_connect\n");
return true_connect(sock,addr,len);
return true_connect(sock, addr, len);
}
}
}
flags = fcntl(sock, F_GETFL, 0);
if(flags & O_NONBLOCK)
fcntl(sock, F_SETFL, !O_NONBLOCK);
fcntl(sock, F_SETFL, !O_NONBLOCK);
dest_ip.as_int = SOCKADDR(*addr);
ret = connect_proxy_chain(
sock,
dest_ip,
SOCKPORT(*addr),
proxychains_pd,
proxychains_proxy_count,
proxychains_ct,
proxychains_max_chain );
ret = connect_proxy_chain(sock,
dest_ip,
SOCKPORT(*addr),
proxychains_pd, proxychains_proxy_count, proxychains_ct, proxychains_max_chain);
fcntl(sock, F_SETFL, flags);
if(ret != SUCCESS)
errno = ECONNREFUSED;
errno = ECONNREFUSED;
return ret;
}
struct hostent *gethostbyname(const char *name)
{
struct hostent *gethostbyname(const char *name) {
if(!init_l)
init_lib();
PDEBUG("gethostbyname: %s\n",name);
PDEBUG("gethostbyname: %s\n", name);
if(proxychains_resolver)
return proxy_gethostbyname(name);
@ -388,16 +358,13 @@ struct hostent *gethostbyname(const char *name)
return NULL;
}
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints,
struct addrinfo **res)
{
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
int ret = 0;
if(!init_l)
init_lib();
PDEBUG("getaddrinfo: %s %s\n",node ,service);
PDEBUG("getaddrinfo: %s %s\n", node, service);
if(proxychains_resolver)
ret = proxy_getaddrinfo(node, service, hints, res);
@ -407,12 +374,11 @@ int getaddrinfo(const char *node, const char *service,
return ret;
}
void freeaddrinfo(struct addrinfo *res)
{
void freeaddrinfo(struct addrinfo *res) {
if(!init_l)
init_lib();
PDEBUG("freeaddrinfo %p \n",res);
PDEBUG("freeaddrinfo %p \n", res);
if(!proxychains_resolver)
true_freeaddrinfo(res);
@ -422,18 +388,15 @@ void freeaddrinfo(struct addrinfo *res)
}
return;
}
// work around a buggy prototype in GLIBC. according to the bugtracker it has been fixed in git at 02 May 2011.
// 2.14 came out in June 2011 so that should be the first fixed version
#if defined(__GLIBC__) && (__GLIBC__ < 3) && (__GLIBC_MINOR__ < 14)
int getnameinfo (const struct sockaddr * sa,
socklen_t salen, char * host,
socklen_t hostlen, char * serv,
socklen_t servlen, unsigned int flags)
int getnameinfo(const struct sockaddr *sa,
socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags)
#else
int getnameinfo (const struct sockaddr * sa,
socklen_t salen, char * host,
socklen_t hostlen, char * serv,
socklen_t servlen, int flags)
int getnameinfo(const struct sockaddr *sa,
socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
#endif
{
int ret = 0;
@ -444,44 +407,44 @@ int getnameinfo (const struct sockaddr * sa,
PDEBUG("getnameinfo: %s %s\n", host, serv);
if(!proxychains_resolver) {
ret = true_getnameinfo(sa,salen,host,hostlen,
serv,servlen,flags);
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
} else {
if(hostlen)
strncpy(host, inet_ntoa(SOCKADDR_2(*sa)),hostlen);
strncpy(host, inet_ntoa(SOCKADDR_2(*sa)), hostlen);
if(servlen)
snprintf(serv, servlen,"%d",ntohs(SOCKPORT(*sa)));
snprintf(serv, servlen, "%d", ntohs(SOCKPORT(*sa)));
}
return ret;
}
// stolen from libulz (C) rofl0r
static void pc_stringfromipv4(unsigned char* ip_buf_4_bytes, char* outbuf_16_bytes) {
unsigned char* p;
char *o = outbuf_16_bytes;
unsigned char n;
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
n = *p;
if(*p >= 100) {
if(*p >= 200) *(o++) = '2';
else *(o++) = '1';
n %= 100;
}
if(*p >= 10) {
*(o++) = (n / 10) + '0';
n %= 10;
}
*(o++) = n + '0';
*(o++) = '.';
}
o[-1] = 0;
static void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
unsigned char *p;
char *o = outbuf_16_bytes;
unsigned char n;
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
n = *p;
if(*p >= 100) {
if(*p >= 200)
*(o++) = '2';
else
*(o++) = '1';
n %= 100;
}
if(*p >= 10) {
*(o++) = (n / 10) + '0';
n %= 10;
}
*(o++) = n + '0';
*(o++) = '.';
}
o[-1] = 0;
}
struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
{
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
static char buf[16];
static char ipv4[4];
static char* list[2];
static char *list[2];
static struct hostent he;
if(!init_l)
@ -490,11 +453,12 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
PDEBUG("TODO: proper gethostbyaddr hook\n");
if(!proxychains_resolver)
return true_gethostbyaddr(addr,len,type);
return true_gethostbyaddr(addr, len, type);
else {
PDEBUG("len %u\n", len);
if(len != 4) return NULL;
if(len != 4)
return NULL;
he.h_name = buf;
memcpy(ipv4, addr, 4);
list[0] = ipv4;
@ -503,9 +467,8 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
he.h_addrtype = AF_INET;
he.h_aliases = NULL;
he.h_length = 4;
pc_stringfromipv4((unsigned char*)addr, buf);
pc_stringfromipv4((unsigned char *) addr, buf);
return &he;
}
return NULL;
}

View File

@ -28,24 +28,24 @@
#include "common.h"
static int usage(char** argv) {
printf( "\nUsage:\t%s -q -f config_file program_name [arguments]\n"
"\t-q makes proxychains quiet - this overrides the config setting\n"
"\t-t allows to manually specify a configfile to use\n"
"\tfor example : proxychains telnet somehost.com\n"
"More help in README file\n\n", argv[0]);
static int usage(char **argv) {
printf("\nUsage:\t%s -q -f config_file program_name [arguments]\n"
"\t-q makes proxychains quiet - this overrides the config setting\n"
"\t-t allows to manually specify a configfile to use\n"
"\tfor example : proxychains telnet somehost.com\n" "More help in README file\n\n", argv[0]);
return EXIT_FAILURE;
}
int check_path(char* path) {
if(!path) return 0;
int check_path(char *path) {
if(!path)
return 0;
return access(path, R_OK) != -1;
}
static const char* dll_name = "libproxychains4.so";
static const char *dll_name = "libproxychains4.so";
static char own_dir[256];
static const char* dll_dirs[] = {
static const char *dll_dirs[] = {
".",
own_dir,
LIB_DIR,
@ -56,9 +56,10 @@ static const char* dll_dirs[] = {
NULL
};
static void set_own_dir(const char* argv0) {
static void set_own_dir(const char *argv0) {
size_t l = strlen(argv0);
while(l && argv0[l - 1] != '/') l--;
while(l && argv0[l - 1] != '/')
l--;
if(l == 0)
memcpy(own_dir, ".", 2);
else {
@ -76,7 +77,7 @@ int main(int argc, char *argv[]) {
int start_argv = 1;
int quiet = 0;
size_t i;
const char* prefix = NULL;
const char *prefix = NULL;
for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) {
if(start_argv < argc && argv[start_argv][0] == '-') {
@ -96,41 +97,48 @@ int main(int argc, char *argv[]) {
break;
}
if(start_argv >= argc) return usage(argv);
if(start_argv >= argc)
return usage(argv);
/* check if path of config file has not been passed via command line */
if(!path) {
// priority 1: env var PROXYCHAINS_CONF_FILE
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
if(check_path(path)) goto have;
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;
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;
if(check_path(path))
goto have;
// priority 4: /etc/proxychains.conf
path = "/etc/proxychains.conf";
if(check_path(path)) goto have;
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);
if(!quiet)
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1);
if(quiet) setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
if(quiet)
setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
// search DLL
@ -150,7 +158,8 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "couldnt locate %s\n", dll_name);
return EXIT_FAILURE;
}
if(!quiet) fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
if(!quiet)
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
snprintf(buf, sizeof(buf), "LD_PRELOAD=%s/%s", prefix, dll_name);