diff --git a/src/allocator_thread.c b/src/allocator_thread.c index 01aee47..5ed6b13 100644 --- a/src/allocator_thread.c +++ b/src/allocator_thread.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "allocator_thread.h" #include "shm.h" #include "debug.h" @@ -147,8 +148,8 @@ struct at_msghdr { static pthread_t allocator_thread; static pthread_attr_t allocator_thread_attr; -static int req_pipefd[2]; -static int resp_pipefd[2]; +int req_pipefd[2]; +int resp_pipefd[2]; static int wait_data(int readfd) { PFUNC(); @@ -158,7 +159,13 @@ static int wait_data(int readfd) { int ret; while((ret = select(readfd+1, &fds, NULL, NULL, NULL)) <= 0) { if(ret < 0) { - perror("select2"); + int e = errno; + if(e == EINTR) continue; +#ifdef __GLIBC__ + char emsg[1024]; + char* x = strerror_r(errno, emsg, sizeof emsg); + dprintf(2, "select2: %s\n", x); +#endif return 0; } } diff --git a/src/allocator_thread.h b/src/allocator_thread.h index be24529..cfa9866 100644 --- a/src/allocator_thread.h +++ b/src/allocator_thread.h @@ -6,6 +6,9 @@ #define MSG_LEN_MAX 256 +extern int req_pipefd[2]; +extern int resp_pipefd[2]; + void at_init(void); void at_close(void); size_t at_get_host_for_ip(ip_type ip, char* readbuf); diff --git a/src/core.h b/src/core.h index 1b8892f..d8a62c6 100644 --- a/src/core.h +++ b/src/core.h @@ -82,6 +82,7 @@ int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port void proxychains_write_log(char *str, ...); +typedef int (*close_t)(int); typedef int (*connect_t)(int, const struct sockaddr *, socklen_t); typedef struct hostent* (*gethostbyname_t)(const char *); typedef int (*freeaddrinfo_t)(struct addrinfo *); diff --git a/src/libproxychains.c b/src/libproxychains.c index 9c6c58c..8f687df 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -45,6 +45,7 @@ #define SOCKFAMILY(x) (satosin(x)->sin_family) #define MAX_CHAIN 512 +close_t true_close; connect_t true_connect; gethostbyname_t true_gethostbyname; getaddrinfo_t true_getaddrinfo; @@ -113,6 +114,7 @@ static void do_init(void) { SETUP_SYM(freeaddrinfo); SETUP_SYM(gethostbyaddr); SETUP_SYM(getnameinfo); + SETUP_SYM(close); init_l = 1; } @@ -282,6 +284,16 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ /******* HOOK FUNCTIONS *******/ +int close(int fd) { + /* prevent rude programs (like ssh) from closing our pipes */ + if(fd != req_pipefd[0] && fd != req_pipefd[1] && + fd != resp_pipefd[0] && fd != resp_pipefd[1]) { + return true_close(fd); + } + errno = EINTR; + return -1; +} + int connect(int sock, const struct sockaddr *addr, unsigned int len) { PFUNC(); int socktype = 0, flags = 0, ret = 0;