hook close() to prevent rude programs like ssh to close our pipes

those pipes are needed to talk with the dns-name allocator thread.

closes #9
This commit is contained in:
rofl0r
2013-01-21 01:54:45 +01:00
parent a8e8cced6d
commit 1da09e49e5
4 changed files with 26 additions and 3 deletions

View File

@ -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;