mirror of
				https://github.com/rofl0r/proxychains-ng.git
				synced 2025-11-04 00:56:03 +00:00 
			
		
		
		
	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:
		
							
								
								
									
										141
									
								
								src/core.c
									
									
									
									
									
								
							
							
						
						
									
										141
									
								
								src/core.c
									
									
									
									
									
								
							@@ -84,7 +84,8 @@ char* string_from_internal_ip(ip_type internalip) {
 | 
			
		||||
in_addr_t make_internal_ip(uint32_t index) {
 | 
			
		||||
	ip_type ret;
 | 
			
		||||
	index++;		// so we can start at .0.0.1
 | 
			
		||||
	if(index > 0xFFFFFF) return (in_addr_t) -1;
 | 
			
		||||
	if(index > 0xFFFFFF)
 | 
			
		||||
		return (in_addr_t) - 1;
 | 
			
		||||
	ret.octet[0] = remote_dns_subnet & 0xFF;
 | 
			
		||||
	ret.octet[1] = (index & 0xFF0000) >> 16;
 | 
			
		||||
	ret.octet[2] = (index & 0xFF00) >> 8;
 | 
			
		||||
@@ -94,8 +95,7 @@ in_addr_t make_internal_ip(uint32_t index) {
 | 
			
		||||
 | 
			
		||||
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 | 
			
		||||
 | 
			
		||||
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
 | 
			
		||||
{
 | 
			
		||||
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout) {
 | 
			
		||||
	int ret;
 | 
			
		||||
	int time_remain = timeout;
 | 
			
		||||
	int time_elapsed = 0;
 | 
			
		||||
@@ -120,13 +120,11 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void encode_base_64(char* src,char* dest,int max_len)
 | 
			
		||||
{
 | 
			
		||||
static void encode_base_64(char *src, char *dest, int max_len) {
 | 
			
		||||
	int n, l, i;
 | 
			
		||||
	l = strlen(src);
 | 
			
		||||
	max_len = (max_len - 1) / 4;
 | 
			
		||||
	for ( i=0;i<max_len;i++,src+=3,l-=3)
 | 
			
		||||
	{
 | 
			
		||||
	for(i = 0; i < max_len; i++, src += 3, l -= 3) {
 | 
			
		||||
		switch (l) {
 | 
			
		||||
			case 0:
 | 
			
		||||
				break;
 | 
			
		||||
@@ -151,15 +149,15 @@ static void encode_base_64(char* src,char* dest,int max_len)
 | 
			
		||||
				*dest++ = base64[(n >> 6) & 077];
 | 
			
		||||
				*dest++ = base64[n & 077];
 | 
			
		||||
		}
 | 
			
		||||
		if (l<3) break;
 | 
			
		||||
		if(l < 3)
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	*dest++ = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define LOG_BUFF 1024*20
 | 
			
		||||
 | 
			
		||||
int proxychains_write_log(char *str,...)
 | 
			
		||||
{
 | 
			
		||||
int proxychains_write_log(char *str, ...) {
 | 
			
		||||
	char buff[LOG_BUFF];
 | 
			
		||||
	va_list arglist;
 | 
			
		||||
	FILE *log_file;
 | 
			
		||||
@@ -174,8 +172,7 @@ int proxychains_write_log(char *str,...)
 | 
			
		||||
	return EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int write_n_bytes(int fd,char *buff,size_t size)
 | 
			
		||||
{
 | 
			
		||||
static int write_n_bytes(int fd, char *buff, size_t size) {
 | 
			
		||||
	int i = 0;
 | 
			
		||||
	size_t wrote = 0;
 | 
			
		||||
	for(;;) {
 | 
			
		||||
@@ -188,8 +185,7 @@ static int write_n_bytes(int fd,char *buff,size_t size)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int read_n_bytes(int fd,char *buff, size_t size)
 | 
			
		||||
{
 | 
			
		||||
static int read_n_bytes(int fd, char *buff, size_t size) {
 | 
			
		||||
	int ready;
 | 
			
		||||
	size_t i;
 | 
			
		||||
	struct pollfd pfd[1];
 | 
			
		||||
@@ -205,8 +201,7 @@ static int read_n_bytes(int fd,char *buff, size_t size)
 | 
			
		||||
	return (int) size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
 | 
			
		||||
{
 | 
			
		||||
static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
 | 
			
		||||
	int ret, value;
 | 
			
		||||
	socklen_t value_len;
 | 
			
		||||
	struct pollfd pfd[1];
 | 
			
		||||
@@ -216,7 +211,8 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
 | 
			
		||||
	fcntl(sock, F_SETFL, O_NONBLOCK);
 | 
			
		||||
	ret = true_connect(sock, addr, len);
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
	if(ret == -1) perror("true_connect");
 | 
			
		||||
	if(ret == -1)
 | 
			
		||||
		perror("true_connect");
 | 
			
		||||
	printf("\nconnect ret=%d\n", ret);
 | 
			
		||||
 | 
			
		||||
	fflush(stdout);
 | 
			
		||||
@@ -224,13 +220,15 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
 | 
			
		||||
	if(ret == -1 && errno == EINPROGRESS) {
 | 
			
		||||
		ret = poll_retry(pfd, 1, tcp_connect_time_out);
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
		printf("\npoll ret=%d\n",ret);fflush(stdout);
 | 
			
		||||
		printf("\npoll ret=%d\n", ret);
 | 
			
		||||
		fflush(stdout);
 | 
			
		||||
#endif
 | 
			
		||||
		if(ret == 1) {
 | 
			
		||||
			value_len = sizeof(socklen_t);
 | 
			
		||||
			getsockopt(sock, SOL_SOCKET, SO_ERROR, &value, &value_len);
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
			printf("\nvalue=%d\n",value);fflush(stdout);
 | 
			
		||||
			printf("\nvalue=%d\n", value);
 | 
			
		||||
			fflush(stdout);
 | 
			
		||||
#endif
 | 
			
		||||
			if(!value)
 | 
			
		||||
				ret = 0;
 | 
			
		||||
@@ -250,8 +248,7 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define INVALID_INDEX 0xFFFFFFFFU
 | 
			
		||||
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,char *user,char *pass)
 | 
			
		||||
{
 | 
			
		||||
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, char *user, char *pass) {
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
	PDEBUG("tunnel_to()\n");
 | 
			
		||||
#endif
 | 
			
		||||
@@ -264,9 +261,11 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
	// the hardcoded number 224 can now be changed using the config option remote_dns_subnet to i.e. 127
 | 
			
		||||
	if(ip.octet[0] == remote_dns_subnet) {
 | 
			
		||||
		dns_name = string_from_internal_ip(ip);
 | 
			
		||||
		if(!dns_name) goto err;
 | 
			
		||||
		if(!dns_name)
 | 
			
		||||
			goto err;
 | 
			
		||||
		dns_len = strlen(dns_name);
 | 
			
		||||
		if(!dns_len) goto err;
 | 
			
		||||
		if(!dns_len)
 | 
			
		||||
			goto err;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	size_t ulen = strlen(user);
 | 
			
		||||
@@ -286,10 +285,10 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
				if(!dns_len)
 | 
			
		||||
					dns_name = inet_ntoa(*(struct in_addr *) &ip.as_int);
 | 
			
		||||
 | 
			
		||||
			snprintf((char*)buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name, ntohs(port));
 | 
			
		||||
				snprintf((char *) buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name,
 | 
			
		||||
					 ntohs(port));
 | 
			
		||||
 | 
			
		||||
			if (user[0])
 | 
			
		||||
			{
 | 
			
		||||
				if(user[0]) {
 | 
			
		||||
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
 | 
			
		||||
					// 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator.
 | 
			
		||||
					char src[HTTP_AUTH_MAX];
 | 
			
		||||
@@ -304,8 +303,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
					strcat((char *) buff, "Proxy-Authorization: Basic ");
 | 
			
		||||
					strcat((char *) buff, dst);
 | 
			
		||||
					strcat((char *) buff, "\r\n\r\n");
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
				} else
 | 
			
		||||
					strcat((char *) buff, "\r\n");
 | 
			
		||||
 | 
			
		||||
				len = strlen((char *) buff);
 | 
			
		||||
@@ -322,17 +320,12 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
						goto err;
 | 
			
		||||
					if(len > 4 &&
 | 
			
		||||
					   buff[len - 1] == '\n' &&
 | 
			
		||||
					buff[len-2]=='\r'  &&
 | 
			
		||||
					buff[len-3]=='\n'  &&
 | 
			
		||||
					buff[len-4]=='\r'  )
 | 
			
		||||
					   buff[len - 2] == '\r' && buff[len - 3] == '\n' && buff[len - 4] == '\r')
 | 
			
		||||
						break;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// if not ok (200) or response greather than BUFF_SIZE return BLOCKED;
 | 
			
		||||
			if (len == BUFF_SIZE ||
 | 
			
		||||
				!( buff[9] =='2' &&
 | 
			
		||||
				buff[10]=='0' &&
 | 
			
		||||
				buff[11]=='0' ))
 | 
			
		||||
				if(len == BUFF_SIZE || !(buff[9] == '2' && buff[10] == '0' && buff[11] == '0'))
 | 
			
		||||
					return BLOCKED;
 | 
			
		||||
 | 
			
		||||
				return SUCCESS;
 | 
			
		||||
@@ -383,8 +376,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
					buff[3] = 2;	/// auth method -> username / password
 | 
			
		||||
					if(4 != write_n_bytes(sock, (char *) buff, 4))
 | 
			
		||||
						goto err;
 | 
			
		||||
       			}
 | 
			
		||||
            		else {
 | 
			
		||||
				} else {
 | 
			
		||||
					buff[0] = 5;	//version
 | 
			
		||||
					buff[1] = 1;	//nomber of methods
 | 
			
		||||
					buff[2] = 0;	// no auth method
 | 
			
		||||
@@ -405,7 +397,8 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
				if(buff[1] == 2) {
 | 
			
		||||
					// authentication
 | 
			
		||||
					char in[2];
 | 
			
		||||
				char out[515]; char* cur=out;
 | 
			
		||||
					char out[515];
 | 
			
		||||
					char *cur = out;
 | 
			
		||||
					int c;
 | 
			
		||||
					*cur++ = 1;	// version
 | 
			
		||||
					c = ulen & 0xFF;
 | 
			
		||||
@@ -461,9 +454,14 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
 | 
			
		||||
				switch (buff[3]) {
 | 
			
		||||
 | 
			
		||||
				case 1: len = 4;  break;
 | 
			
		||||
				case 4: len = 16; break;
 | 
			
		||||
				case 3: len = 0;
 | 
			
		||||
					case 1:
 | 
			
		||||
						len = 4;
 | 
			
		||||
						break;
 | 
			
		||||
					case 4:
 | 
			
		||||
						len = 16;
 | 
			
		||||
						break;
 | 
			
		||||
					case 3:
 | 
			
		||||
						len = 0;
 | 
			
		||||
						if(1 != read_n_bytes(sock, (char *) &len, 1))
 | 
			
		||||
							goto err;
 | 
			
		||||
						break;
 | 
			
		||||
@@ -488,8 +486,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
 | 
			
		||||
#define ST "Strict chain"
 | 
			
		||||
#define RT "Random chain"
 | 
			
		||||
 | 
			
		||||
static int start_chain(int *fd, proxy_data *pd, char* begin_mark)
 | 
			
		||||
{
 | 
			
		||||
static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
 | 
			
		||||
	struct sockaddr_in addr;
 | 
			
		||||
 | 
			
		||||
	*fd = socket(PF_INET, SOCK_STREAM, 0);
 | 
			
		||||
@@ -497,9 +494,7 @@ static int start_chain(int *fd, proxy_data *pd, char* begin_mark)
 | 
			
		||||
		goto error;
 | 
			
		||||
 | 
			
		||||
	proxychains_write_log(LOG_PREFIX "%s " TP " %s:%d ",
 | 
			
		||||
				begin_mark,
 | 
			
		||||
				inet_ntoa(*(struct in_addr*)&pd->ip),
 | 
			
		||||
				htons(pd->port));
 | 
			
		||||
			      begin_mark, inet_ntoa(*(struct in_addr *) &pd->ip), htons(pd->port));
 | 
			
		||||
	pd->ps = PLAY_STATE;
 | 
			
		||||
	memset(&addr, 0, sizeof(addr));
 | 
			
		||||
	addr.sin_family = AF_INET;
 | 
			
		||||
@@ -519,9 +514,7 @@ error:
 | 
			
		||||
	return SOCKET_ERROR;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static proxy_data * select_proxy(select_type how,
 | 
			
		||||
		proxy_data *pd, unsigned int proxy_count, unsigned int *offset)
 | 
			
		||||
{
 | 
			
		||||
static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) {
 | 
			
		||||
	unsigned int i = 0, k = 0;
 | 
			
		||||
	if(*offset >= proxy_count)
 | 
			
		||||
		return NULL;
 | 
			
		||||
@@ -530,8 +523,7 @@ static proxy_data * select_proxy(select_type how,
 | 
			
		||||
			srand(time(NULL));
 | 
			
		||||
			do {
 | 
			
		||||
				k++;
 | 
			
		||||
				i = 0 + (unsigned int) (proxy_count * 1.0 * rand()/
 | 
			
		||||
						(RAND_MAX + 1.0));
 | 
			
		||||
				i = 0 + (unsigned int) (proxy_count * 1.0 * rand() / (RAND_MAX + 1.0));
 | 
			
		||||
			} while(pd[i].ps != PLAY_STATE && k < proxy_count * 100);
 | 
			
		||||
			break;
 | 
			
		||||
		case FIFOLY:
 | 
			
		||||
@@ -550,16 +542,14 @@ static proxy_data * select_proxy(select_type how,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void release_all(proxy_data *pd, unsigned int proxy_count)
 | 
			
		||||
{
 | 
			
		||||
static void release_all(proxy_data * pd, unsigned int proxy_count) {
 | 
			
		||||
	unsigned int i;
 | 
			
		||||
	for(i = 0; i < proxy_count; i++)
 | 
			
		||||
		pd[i].ps = PLAY_STATE;
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void release_busy(proxy_data *pd, unsigned int proxy_count)
 | 
			
		||||
{
 | 
			
		||||
static void release_busy(proxy_data * pd, unsigned int proxy_count) {
 | 
			
		||||
	unsigned int i;
 | 
			
		||||
	for(i = 0; i < proxy_count; i++)
 | 
			
		||||
		if(pd[i].ps == BUSY_STATE)
 | 
			
		||||
@@ -567,8 +557,7 @@ static void release_busy(proxy_data *pd, unsigned int proxy_count)
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static unsigned int calc_alive(proxy_data *pd, unsigned int proxy_count)
 | 
			
		||||
{
 | 
			
		||||
static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
 | 
			
		||||
	unsigned int i;
 | 
			
		||||
	int alive_count = 0;
 | 
			
		||||
	release_busy(pd, proxy_count);
 | 
			
		||||
@@ -579,8 +568,7 @@ static unsigned int calc_alive(proxy_data *pd, unsigned int proxy_count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static int chain_step(int ns, proxy_data *pfrom, proxy_data *pto)
 | 
			
		||||
{
 | 
			
		||||
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
 | 
			
		||||
	int retcode = -1;
 | 
			
		||||
	char *hostname;
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
@@ -588,18 +576,15 @@ static int chain_step(int ns, proxy_data *pfrom, proxy_data *pto)
 | 
			
		||||
#endif
 | 
			
		||||
	if(pto->ip.octet[0] == remote_dns_subnet) {
 | 
			
		||||
		hostname = string_from_internal_ip(pto->ip);
 | 
			
		||||
		if(!hostname) goto usenumericip;
 | 
			
		||||
		if(!hostname)
 | 
			
		||||
			goto usenumericip;
 | 
			
		||||
	} else {
 | 
			
		||||
	usenumericip:
 | 
			
		||||
		hostname = inet_ntoa(*(struct in_addr *) &pto->ip);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	proxychains_write_log(TP" %s:%d ",
 | 
			
		||||
			hostname,
 | 
			
		||||
			htons(pto->port));
 | 
			
		||||
	retcode =
 | 
			
		||||
		tunnel_to(ns, pto->ip, pto->port, pfrom->pt, pfrom->user,
 | 
			
		||||
				pfrom->pass);
 | 
			
		||||
	proxychains_write_log(TP " %s:%d ", hostname, htons(pto->port));
 | 
			
		||||
	retcode = tunnel_to(ns, pto->ip, pto->port, pfrom->pt, pfrom->user, pfrom->pass);
 | 
			
		||||
	switch (retcode) {
 | 
			
		||||
		case SUCCESS:
 | 
			
		||||
			pto->ps = BUSY_STATE;
 | 
			
		||||
@@ -620,8 +605,7 @@ static int chain_step(int ns, proxy_data *pfrom, proxy_data *pto)
 | 
			
		||||
 | 
			
		||||
int connect_proxy_chain(int sock, ip_type target_ip,
 | 
			
		||||
			unsigned short target_port, proxy_data * pd,
 | 
			
		||||
		unsigned int proxy_count, chain_type ct, unsigned int max_chain )
 | 
			
		||||
{
 | 
			
		||||
			unsigned int proxy_count, chain_type ct, unsigned int max_chain) {
 | 
			
		||||
	proxy_data p4;
 | 
			
		||||
	proxy_data *p1, *p2, *p3;
 | 
			
		||||
	int ns = -1;
 | 
			
		||||
@@ -753,8 +737,7 @@ static in_addr_t resolved_addr;
 | 
			
		||||
static char *resolved_addr_p[2];
 | 
			
		||||
static char addr_name[1024 * 8];
 | 
			
		||||
static const ip_type local_host = { {127, 0, 0, 1} };
 | 
			
		||||
struct hostent* proxy_gethostbyname(const char *name)
 | 
			
		||||
{
 | 
			
		||||
struct hostent *proxy_gethostbyname(const char *name) {
 | 
			
		||||
	char buff[256];
 | 
			
		||||
	uint32_t i, hash;
 | 
			
		||||
	// yep, new_mem never gets freed. once you passed a fake ip to the client, you can't "retreat" it
 | 
			
		||||
@@ -802,7 +785,6 @@ struct hostent* proxy_gethostbyname(const char *name)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// grow list if needed.
 | 
			
		||||
	if(internal_ips.capa < internal_ips.counter + 1) {
 | 
			
		||||
		PDEBUG("realloc\n");
 | 
			
		||||
@@ -818,7 +800,8 @@ struct hostent* proxy_gethostbyname(const char *name)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	resolved_addr = make_internal_ip(internal_ips.counter);
 | 
			
		||||
	if(resolved_addr == (in_addr_t) -1) goto err_plus_unlock;
 | 
			
		||||
	if(resolved_addr == (in_addr_t) - 1)
 | 
			
		||||
		goto err_plus_unlock;
 | 
			
		||||
 | 
			
		||||
	l = strlen(name);
 | 
			
		||||
	new_mem = malloc(sizeof(string_hash_tuple) + l + 1);
 | 
			
		||||
@@ -854,10 +837,7 @@ err_plus_unlock:
 | 
			
		||||
#endif
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
int proxy_getaddrinfo(const char *node, const char *service,
 | 
			
		||||
		const struct addrinfo *hints,
 | 
			
		||||
		struct addrinfo **res)
 | 
			
		||||
{
 | 
			
		||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
 | 
			
		||||
	struct servent *se = NULL;
 | 
			
		||||
	struct hostent *hp = NULL;
 | 
			
		||||
	struct sockaddr *sockaddr_space = NULL;
 | 
			
		||||
@@ -872,13 +852,11 @@ int proxy_getaddrinfo(const char *node, const char *service,
 | 
			
		||||
		goto err2;
 | 
			
		||||
	memset(sockaddr_space, 0, sizeof(*sockaddr_space));
 | 
			
		||||
	memset(addrinfo_space, 0, sizeof(*addrinfo_space));
 | 
			
		||||
	if (node &&
 | 
			
		||||
	    !inet_aton(node,&((struct sockaddr_in*)sockaddr_space)->sin_addr)) {
 | 
			
		||||
	if(node && !inet_aton(node, &((struct sockaddr_in *) sockaddr_space)->sin_addr)) {
 | 
			
		||||
		hp = proxy_gethostbyname(node);
 | 
			
		||||
		if(hp)
 | 
			
		||||
			memcpy(&((struct sockaddr_in *) sockaddr_space)->sin_addr,
 | 
			
		||||
				*(hp->h_addr_list),
 | 
			
		||||
				sizeof(in_addr_t));
 | 
			
		||||
			       *(hp->h_addr_list), sizeof(in_addr_t));
 | 
			
		||||
		else
 | 
			
		||||
			goto err3;
 | 
			
		||||
	}
 | 
			
		||||
@@ -886,8 +864,7 @@ int proxy_getaddrinfo(const char *node, const char *service,
 | 
			
		||||
		se = getservbyname(service, NULL);
 | 
			
		||||
 | 
			
		||||
	if(!se) {
 | 
			
		||||
		((struct sockaddr_in*)sockaddr_space)->sin_port =
 | 
			
		||||
			htons(atoi(service?:"0"));
 | 
			
		||||
		((struct sockaddr_in *) sockaddr_space)->sin_port = htons(atoi(service ? : "0"));
 | 
			
		||||
	} else
 | 
			
		||||
		((struct sockaddr_in *) sockaddr_space)->sin_port = se->s_port;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -78,9 +76,7 @@ static void init_lib(void)
 | 
			
		||||
		exit(1);
 | 
			
		||||
	} else {
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
		PDEBUG( "loaded symbol 'connect'"
 | 
			
		||||
		" real addr %p  wrapped addr %p\n",
 | 
			
		||||
		true_connect, connect);
 | 
			
		||||
		PDEBUG("loaded symbol 'connect'" " real addr %p  wrapped addr %p\n", true_connect, connect);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
	if(connect == true_connect) {
 | 
			
		||||
@@ -94,80 +90,64 @@ static void init_lib(void)
 | 
			
		||||
	    dlsym(RTLD_NEXT, "gethostbyname");
 | 
			
		||||
 | 
			
		||||
	if(!true_gethostbyname) {
 | 
			
		||||
		fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n",
 | 
			
		||||
				dlerror());
 | 
			
		||||
		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);
 | 
			
		||||
		       " real addr %p  wrapped addr %p\n", true_gethostbyname, gethostbyname);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
	true_getaddrinfo = (getaddrinfo_t)
 | 
			
		||||
	    dlsym(RTLD_NEXT, "getaddrinfo");
 | 
			
		||||
 | 
			
		||||
	if(!true_getaddrinfo) {
 | 
			
		||||
		fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n",
 | 
			
		||||
				dlerror());
 | 
			
		||||
		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);
 | 
			
		||||
		PDEBUG("loaded symbol 'getaddrinfo'" " real addr %p  wrapped addr %p\n", true_getaddrinfo, getaddrinfo);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
	true_freeaddrinfo = (freeaddrinfo_t)
 | 
			
		||||
	    dlsym(RTLD_NEXT, "freeaddrinfo");
 | 
			
		||||
 | 
			
		||||
	if(!true_freeaddrinfo) {
 | 
			
		||||
		fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n",
 | 
			
		||||
				dlerror());
 | 
			
		||||
		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);
 | 
			
		||||
		       " real addr %p  wrapped addr %p\n", true_freeaddrinfo, freeaddrinfo);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
	true_gethostbyaddr = (gethostbyaddr_t)
 | 
			
		||||
	    dlsym(RTLD_NEXT, "gethostbyaddr");
 | 
			
		||||
 | 
			
		||||
	if(!true_gethostbyaddr) {
 | 
			
		||||
		fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n",
 | 
			
		||||
				dlerror());
 | 
			
		||||
		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);
 | 
			
		||||
		       " real addr %p  wrapped addr %p\n", true_gethostbyaddr, gethostbyaddr);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
	true_getnameinfo = (getnameinfo_t)
 | 
			
		||||
	    dlsym(RTLD_NEXT, "getnameinfo");
 | 
			
		||||
 | 
			
		||||
	if(!true_getnameinfo) {
 | 
			
		||||
		fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n",
 | 
			
		||||
				dlerror());
 | 
			
		||||
		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);
 | 
			
		||||
		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)
 | 
			
		||||
{
 | 
			
		||||
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;
 | 
			
		||||
@@ -194,14 +174,14 @@ static inline void get_chain_data(
 | 
			
		||||
	if(!env || (!(file = fopen(env, "r"))))
 | 
			
		||||
		if(!(file = fopen("./proxychains.conf", "r")))
 | 
			
		||||
			if(!(file = fopen(buff, "r")))
 | 
			
		||||
	if(!(file=fopen("/etc/proxychains.conf","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, " ")] != '#') {
 | 
			
		||||
@@ -211,8 +191,7 @@ static inline void get_chain_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);
 | 
			
		||||
@@ -226,8 +205,7 @@ static inline void get_chain_data(
 | 
			
		||||
				} else
 | 
			
		||||
					continue;
 | 
			
		||||
 | 
			
		||||
				if(pd[count].ip.as_int && port_n &&
 | 
			
		||||
				   pd[count].ip.as_int != (uint32_t) -1)
 | 
			
		||||
				if(pd[count].ip.as_int && port_n && pd[count].ip.as_int != (uint32_t) - 1)
 | 
			
		||||
					if(++count == MAX_CHAIN)
 | 
			
		||||
						break;
 | 
			
		||||
			} else {
 | 
			
		||||
@@ -246,55 +224,54 @@ static inline void get_chain_data(
 | 
			
		||||
				} 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) {
 | 
			
		||||
					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);
 | 
			
		||||
					}
 | 
			
		||||
					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);
 | 
			
		||||
							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;
 | 
			
		||||
					char *pc;
 | 
			
		||||
					int len;
 | 
			
		||||
					pc = strchr(buff, '=');
 | 
			
		||||
					len = atoi(++pc);
 | 
			
		||||
					proxychains_max_chain = (len ? len : 1);
 | 
			
		||||
@@ -313,8 +290,7 @@ static inline void get_chain_data(
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int connect (int sock, const struct sockaddr *addr, unsigned int len)
 | 
			
		||||
{
 | 
			
		||||
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;
 | 
			
		||||
@@ -343,8 +319,7 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
 | 
			
		||||
#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))
 | 
			
		||||
		{
 | 
			
		||||
		   == (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);
 | 
			
		||||
@@ -358,14 +333,10 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
 | 
			
		||||
 | 
			
		||||
	dest_ip.as_int = SOCKADDR(*addr);
 | 
			
		||||
 | 
			
		||||
	ret = connect_proxy_chain(
 | 
			
		||||
		sock,
 | 
			
		||||
	ret = connect_proxy_chain(sock,
 | 
			
		||||
				  dest_ip,
 | 
			
		||||
				  SOCKPORT(*addr),
 | 
			
		||||
		proxychains_pd,
 | 
			
		||||
		proxychains_proxy_count,
 | 
			
		||||
		proxychains_ct,
 | 
			
		||||
		proxychains_max_chain );
 | 
			
		||||
				  proxychains_pd, proxychains_proxy_count, proxychains_ct, proxychains_max_chain);
 | 
			
		||||
 | 
			
		||||
	fcntl(sock, F_SETFL, flags);
 | 
			
		||||
	if(ret != SUCCESS)
 | 
			
		||||
@@ -373,8 +344,7 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct hostent *gethostbyname(const char *name)
 | 
			
		||||
{
 | 
			
		||||
struct hostent *gethostbyname(const char *name) {
 | 
			
		||||
	if(!init_l)
 | 
			
		||||
		init_lib();
 | 
			
		||||
 | 
			
		||||
@@ -388,10 +358,7 @@ 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)
 | 
			
		||||
@@ -407,8 +374,7 @@ 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();
 | 
			
		||||
 | 
			
		||||
@@ -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)
 | 
			
		||||
		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)
 | 
			
		||||
		socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
 | 
			
		||||
#endif
 | 
			
		||||
{
 | 
			
		||||
	int ret = 0;
 | 
			
		||||
@@ -444,8 +407,7 @@ 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);
 | 
			
		||||
@@ -463,8 +425,10 @@ static void pc_stringfromipv4(unsigned char* ip_buf_4_bytes, char* outbuf_16_byt
 | 
			
		||||
	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';
 | 
			
		||||
			if(*p >= 200)
 | 
			
		||||
				*(o++) = '2';
 | 
			
		||||
			else
 | 
			
		||||
				*(o++) = '1';
 | 
			
		||||
			n %= 100;
 | 
			
		||||
		}
 | 
			
		||||
		if(*p >= 10) {
 | 
			
		||||
@@ -477,8 +441,7 @@ static void pc_stringfromipv4(unsigned char* ip_buf_4_bytes, char* outbuf_16_byt
 | 
			
		||||
	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];
 | 
			
		||||
@@ -494,7 +457,8 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int 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;
 | 
			
		||||
@@ -508,4 +472,3 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/main.c
									
									
									
									
									
								
							@@ -32,13 +32,13 @@ 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]);
 | 
			
		||||
	       "\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;
 | 
			
		||||
	if(!path)
 | 
			
		||||
		return 0;
 | 
			
		||||
	return access(path, R_OK) != -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +58,8 @@ static const char* dll_dirs[] = {
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user