From 9db88313c7e5161f8bd9a309765ff909e3b198de Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Sun, 31 Jan 2016 23:22:45 +0300 Subject: [PATCH 01/20] minor documentation correction --- doc/html/howtor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/html/howtor.html b/doc/html/howtor.html index 8aa200c..0d2268c 100644 --- a/doc/html/howtor.html +++ b/doc/html/howtor.html @@ -783,7 +783,7 @@ ... deny * * 127.0.0.2 добавляет статическую запись в кэш. Статические записи так же влияют на разрешение через dnspr если не указана опция -s. Начиная с версии 0.8 для dnspr могут быть сконфигурированы родительские прокси.
-
IPv6 поддерживается с версии 0.8. Обратите внимание, что в некоторых видах прокси (например SOCKSv4)
IPv6 не поддерживает на уровне протокола. В SOCKSv5 есть поддержка IPv6 с помощью отдельного вида
From 3cc979658319e8ba263efeada33f02f81399eb32 Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Fri, 5 Feb 2016 01:52:45 +0300
Subject: [PATCH 02/20] Support for 'extip' and 'smtp' parent types added
---
src/auth.c | 11 ++++++-----
src/common.c | 10 ++++++----
src/conf.c | 3 ++-
src/proxymain.c | 4 ++--
src/structures.h | 3 ++-
5 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/auth.c b/src/auth.c
index 7e8263b..55bde6a 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -241,7 +241,10 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
r2 = (myrand(param, sizeof(struct clientparam))%1000);
}
if(!connected){
- if(SAISNULL(&cur->addr) && !*SAPORT(&cur->addr)){
+ if(cur->type == R_EXTIP){
+ memcpy(¶m->sinsl, &cur->addr, sizeof(cur->addr));
+ }
+ else if(SAISNULL(&cur->addr) && !*SAPORT(&cur->addr)){
if(cur->extuser){
if(param->extusername)
myfree(param->extusername);
@@ -266,11 +269,9 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
case R_ICQ:
param->redirectfunc = icqprchild;
break;
-/*
- case R_MSN:
- param->redirectfunc = msnprchild;
+ case R_SMTP:
+ param->redirectfunc = smtppchild;
break;
-*/
default:
param->redirectfunc = proxychild;
}
diff --git a/src/common.c b/src/common.c
index 6cb3d50..509dd6a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -674,12 +674,14 @@ int doconnect(struct clientparam * param){
}
#endif
+ if(SAISNULL(¶m->sinsl)){
#ifndef NOIPV6
- if(*SAFAMILY(¶m->sinsr) == AF_INET6) memcpy(¶m->sinsl, ¶m->srv->extsa6, sizeof(param->srv->extsa6));
- else
+ if(*SAFAMILY(¶m->sinsr) == AF_INET6) memcpy(¶m->sinsl, ¶m->srv->extsa6, sizeof(param->srv->extsa6));
+ else
#endif
- memcpy(¶m->sinsl, ¶m->srv->extsa, sizeof(param->srv->extsa));
- *SAPORT(¶m->sinsl) = 0;
+ memcpy(¶m->sinsl, ¶m->srv->extsa, sizeof(param->srv->extsa));
+ *SAPORT(¶m->sinsl) = 0;
+ }
if(so._bind(param->remsock, (struct sockaddr*)¶m->sinsl, SASIZE(¶m->sinsl))==-1) {
return 12;
}
diff --git a/src/conf.c b/src/conf.c
index b050723..ec73767 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -705,7 +705,8 @@ static int h_parent(int argc, unsigned char **argv){
else if(!strcmp((char *)argv[2], "ftp"))chains->type = R_FTP;
else if(!strcmp((char *)argv[2], "admin"))chains->type = R_ADMIN;
else if(!strcmp((char *)argv[2], "icq"))chains->type = R_ICQ;
- else if(!strcmp((char *)argv[2], "msn"))chains->type = R_MSN;
+ else if(!strcmp((char *)argv[2], "extip"))chains->type = R_EXTIP;
+ else if(!strcmp((char *)argv[2], "smtp"))chains->type = R_SMTP;
else {
fprintf(stderr, "Chaining error: bad chain type (%s)\n", argv[2]);
return(4);
diff --git a/src/proxymain.c b/src/proxymain.c
index 9bb367e..080bb88 100644
--- a/src/proxymain.c
+++ b/src/proxymain.c
@@ -751,9 +751,9 @@ void srvinit2(struct srvparam * srv, struct clientparam *param){
memcpy(¶m->sincr, &srv->intsa, sizeof(param->sincr));
memcpy(¶m->sincl, &srv->intsa, sizeof(param->sincl));
#ifndef NOIPV6
- memcpy(¶m->sinsr, (srv->family == 6 || srv->family == 64)? (void *)&srv->extsa6: (void *)&srv->extsa, sizeof(param->sinsl));
+ memcpy(¶m->sinsr, (srv->family == 6 || srv->family == 64)? (void *)&srv->extsa6: (void *)&srv->extsa, sizeof(param->sinsr));
#else
- memcpy(¶m->sinsr, &srv->extsa, sizeof(param->sinsl));
+ memcpy(¶m->sinsr, &srv->extsa, sizeof(param->sinsr));
#endif
}
diff --git a/src/structures.h b/src/structures.h
index c6219c2..b3f34c3 100644
--- a/src/structures.h
+++ b/src/structures.h
@@ -217,6 +217,7 @@ typedef enum {
R_SOCKS5,
R_HTTP,
R_POP3,
+ R_SMTP,
R_FTP,
R_CONNECTP,
R_SOCKS4P,
@@ -225,7 +226,7 @@ typedef enum {
R_SOCKS5B,
R_ADMIN,
R_ICQ,
- R_MSN
+ R_EXTIP
} REDIRTYPE;
struct chain {
From 13a7d6be11fcc60dd5c4b29c51a7c194d3d3ca1e Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Fri, 5 Feb 2016 18:31:17 +0300
Subject: [PATCH 03/20] Replace memcpy with assignment where appropriate
---
src/3proxy.c | 2 +-
src/auth.c | 33 +++++++++++++++++----------------
src/common.c | 4 ++--
src/conf.c | 3 ++-
src/dnspr.c | 2 +-
src/ftp.c | 2 +-
src/proxymain.c | 28 +++++++++++++++-------------
src/socks.c | 12 ++++++------
8 files changed, 45 insertions(+), 41 deletions(-)
diff --git a/src/3proxy.c b/src/3proxy.c
index 30a1320..4a5eb70 100644
--- a/src/3proxy.c
+++ b/src/3proxy.c
@@ -139,7 +139,7 @@ int timechanged (time_t oldtime, time_t newtime, ROTATION lt){
struct tm tmold;
struct tm *tm;
tm = localtime(&oldtime);
- memcpy(&tmold, tm, sizeof(tmold));
+ tmold = *tm;
tm = localtime(&newtime);
switch(lt){
case MINUTELY:
diff --git a/src/auth.c b/src/auth.c
index 55bde6a..97f2673 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -242,7 +242,7 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
}
if(!connected){
if(cur->type == R_EXTIP){
- memcpy(¶m->sinsl, &cur->addr, sizeof(cur->addr));
+ param->sinsl = cur->addr;
}
else if(SAISNULL(&cur->addr) && !*SAPORT(&cur->addr)){
if(cur->extuser){
@@ -280,12 +280,12 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
}
else if(!*SAPORT(&cur->addr) && !SAISNULL(&cur->addr)) {
unsigned short port = *SAPORT(¶m->sinsr);
- memcpy(¶m->sinsr, &cur->addr, SASIZE(&cur->addr));
+ param->sinsr = cur->addr;
*SAPORT(¶m->sinsr) = port;
}
else if(SAISNULL(&cur->addr) && *SAPORT(&cur->addr)) *SAPORT(¶m->sinsr) = *SAPORT(&cur->addr);
else {
- memcpy(¶m->sinsr, &cur->addr, SASIZE(&cur->addr));
+ param->sinsr = cur->addr;
}
if((res = alwaysauth(param))){
@@ -609,7 +609,7 @@ int checkACL(struct clientparam * param){
if(param->redirected && acentry->chains && SAISNULL(&acentry->chains->addr) && !*SAPORT(&acentry->chains->addr)) {
continue;
}
- memcpy(&dup, acentry, sizeof(struct ace));
+ dup = *acentry;
return handleredirect(param, &dup);
}
return acentry->action;
@@ -700,7 +700,7 @@ int doauth(struct clientparam * param){
ac->password = mystrdup(param->password);
myfree(tmp);
}
- memcpy(&ac->sa, ¶m->sincr, SASIZE(¶m->sincr));
+ ac->sa = param->sincr;
break;
}
}
@@ -709,7 +709,7 @@ int doauth(struct clientparam * param){
if(ac){
ac->expires = conf.time + conf.authcachetime;
ac->username = mystrdup(param->username);
- memcpy(&ac->sa, ¶m->sincr, SASIZE(¶m->sincr));
+ ac->sa = param->sincr;
ac->password = NULL;
if((conf.authcachetype&4) && param->password) ac->password = mystrdup(param->password);
}
@@ -1038,17 +1038,18 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
unsigned ttl;
#ifndef NOIPV6
struct sockaddr_in6 addr;
+ struct sockaddr_in6 *sinsr, *sinsl;
#else
struct sockaddr_in addr;
+ struct sockaddr_in *sinsr, *sinsl;
#endif
- struct sockaddr *sinsr, *sinsl;
int usetcp = 0;
unsigned short serial = 1;
buf = b+2;
- sinsl = (param && !makeauth)? (struct sockaddr *)¶m->sinsl : (struct sockaddr *)&addr;
- sinsr = (param && !makeauth)? (struct sockaddr *)¶m->sinsr : (struct sockaddr *)&addr;
+ sinsl = (param && !makeauth)? ¶m->sinsl : &addr;
+ sinsr = (param && !makeauth)? ¶m->sinsr : &addr;
memset(sinsl, 0, sizeof(addr));
memset(sinsr, 0, sizeof(addr));
@@ -1062,19 +1063,19 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
*SAFAMILY(sinsl) = *SAFAMILY(&nservers[i].addr);
}
if((sock=so._socket(SASOCK(sinsl), usetcp?SOCK_STREAM:SOCK_DGRAM, usetcp?IPPROTO_TCP:IPPROTO_UDP)) == INVALID_SOCKET) break;
- if(so._bind(sock,sinsl,SASIZE(sinsl))){
+ if(so._bind(sock,(struct sockaddr *)sinsl,SASIZE(sinsl))){
so._shutdown(sock, SHUT_RDWR);
so._closesocket(sock);
break;
}
if(makeauth && !SAISNULL(&authnserver.addr)){
- memcpy(sinsr, &authnserver.addr, sizeof(authnserver.addr));
+ *sinsr = authnserver.addr;
}
else {
- memcpy(sinsr, &nservers[i].addr, sizeof(nservers[i].addr));
+ *sinsr = nservers[i].addr;
}
if(usetcp){
- if(so._connect(sock,sinsr,SASIZE(sinsr))) {
+ if(so._connect(sock,(struct sockaddr *)sinsr,SASIZE(sinsr))) {
so._shutdown(sock, SHUT_RDWR);
so._closesocket(sock);
break;
@@ -1110,13 +1111,13 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
len+=2;
}
- if(socksendto(sock, sinsr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
+ if(socksendto(sock, (struct sockaddr *)sinsr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
so._shutdown(sock, SHUT_RDWR);
so._closesocket(sock);
continue;
}
if(param) param->statscli64 += len;
- len = sockrecvfrom(sock, sinsr, buf, 4096, conf.timeouts[DNS_TO]*1000);
+ len = sockrecvfrom(sock, (struct sockaddr *)sinsr, buf, 4096, conf.timeouts[DNS_TO]*1000);
so._shutdown(sock, SHUT_RDWR);
so._closesocket(sock);
if(len <= 13) {
@@ -1128,7 +1129,7 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
us = ntohs(*(unsigned short*)buf);
len-=2;
buf+=2;
- if(us > 4096 || us < len || (us > len && sockrecvfrom(sock, sinsr, buf+len, us-len, conf.timeouts[DNS_TO]*1000) != us-len)) {
+ if(us > 4096 || us < len || (us > len && sockrecvfrom(sock, (struct sockaddr *)sinsr, buf+len, us-len, conf.timeouts[DNS_TO]*1000) != us-len)) {
continue;
}
}
diff --git a/src/common.c b/src/common.c
index 509dd6a..55aef52 100644
--- a/src/common.c
+++ b/src/common.c
@@ -676,10 +676,10 @@ int doconnect(struct clientparam * param){
if(SAISNULL(¶m->sinsl)){
#ifndef NOIPV6
- if(*SAFAMILY(¶m->sinsr) == AF_INET6) memcpy(¶m->sinsl, ¶m->srv->extsa6, sizeof(param->srv->extsa6));
+ if(*SAFAMILY(¶m->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6;
else
#endif
- memcpy(¶m->sinsl, ¶m->srv->extsa, sizeof(param->srv->extsa));
+ param->sinsl = param->srv->extsa;
*SAPORT(¶m->sinsl) = 0;
}
if(so._bind(param->remsock, (struct sockaddr*)¶m->sinsl, SASIZE(¶m->sinsl))==-1) {
diff --git a/src/conf.c b/src/conf.c
index ec73767..7ef51bf 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -274,7 +274,8 @@ static int h_external(int argc, unsigned char ** argv){
memset(&sa6, 0, sizeof(sa6));
res = getip46(46, argv[1], (struct sockaddr *)&sa6);
if(!res) return 1;
- memcpy((*SAFAMILY(&sa6)==AF_INET)?(void *)&conf.extsa:(void *)&conf.extsa6, &sa6, sizeof(sa6));
+ if (*SAFAMILY(&sa6)==AF_INET) conf.extsa = sa6;
+ else conf.extsa6 = sa6;
#else
res = getip46(46, argv[1], (struct sockaddr *)&conf.extsa);
if(!res) return 1;
diff --git a/src/dnspr.c b/src/dnspr.c
index 3e4137e..45d4355 100644
--- a/src/dnspr.c
+++ b/src/dnspr.c
@@ -138,7 +138,7 @@ void * dnsprchild(struct clientparam* param) {
if(so._bind(param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
RETURN(819);
}
- memcpy(¶m->sinsr, &nservers[0].addr, sizeof(param->sinsr));
+ param->sinsr = nservers[0].addr;
if(nservers[0].usetcp) {
if(so._connect(param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr))) RETURN(830);
buf-=2;
diff --git a/src/ftp.c b/src/ftp.c
index 734fa93..b776115 100644
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -189,7 +189,7 @@ SOCKET ftpdata(struct clientparam *param){
if(sscanf(sb+1, "%lu,%lu,%lu,%lu,%hu,%hu", &b1, &b2, &b3, &b4, &b5, &b6)!=6) return INVALID_SOCKET;
rem = param->remsock;
param->remsock = INVALID_SOCKET;
- memcpy(¶m->req,¶m->sinsr,sizeof(param->req));
+ param->req = param->sinsr;
*SAPORT(¶m->req) = *SAPORT(¶m->sinsr) = htons((unsigned short)((b5<<8)^b6));
i = param->operation;
param->operation = FTP_DATA;
diff --git a/src/proxymain.c b/src/proxymain.c
index 080bb88..dfb073d 100644
--- a/src/proxymain.c
+++ b/src/proxymain.c
@@ -26,7 +26,7 @@ void * threadfunc (void *p) {
continue;
}
#ifndef WITHMAIN
- memcpy(¶m->req, ¶m->sinsr, size);
+ param->req = param->sinsr;
if(param->srv->acl) param->res = checkACL(param);
if(param->res){
param->srv->logfunc(param, "Connect back ACL failed");
@@ -240,7 +240,10 @@ int MODULEMAINFUNC (int argc, char** argv){
struct sockaddr_in6 sa6;
memset(&sa6, 0, sizeof(sa6));
error = !getip46(46, argv[i]+2, (struct sockaddr *)&sa6);
- if(!error) memcpy((*SAFAMILY(&sa6)==AF_INET)?(void *)&srv.extsa:(void *)&srv.extsa6, &sa6, sizeof(sa6));
+ if(!error) {
+ if (*SAFAMILY(&sa6)==AF_INET) srv.extsa = sa6;
+ else srv.extsa6 = sa6;
+ }
#else
error = !getip46(46, argv[i]+2, (struct sockaddr *)&srv.extsa);
#endif
@@ -386,7 +389,7 @@ int MODULEMAINFUNC (int argc, char** argv){
if(! (newparam = myalloc (sizeof(defparam)))){
return 2;
};
- memcpy(newparam, &defparam, sizeof(defparam));
+ *newparam = defparam;
return((*srv.pf)((void *)newparam)? 1:0);
}
@@ -621,7 +624,7 @@ int MODULEMAINFUNC (int argc, char** argv){
usleep(SLEEPTIME);
continue;
};
- memcpy(newparam, &defparam, sizeof(defparam));
+ *newparam = defparam;
if(defparam.hostname)newparam->hostname=strdup(defparam.hostname);
clearstat(newparam);
if(!isudp) newparam->clisock = new_sock;
@@ -721,10 +724,10 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
param->remsock = param->clisock = param->ctrlsock = param->ctrlsocksrv = INVALID_SOCKET;
*SAFAMILY(¶m->req) = *SAFAMILY(¶m->sinsl) = *SAFAMILY(¶m->sinsr) = *SAFAMILY(¶m->sincr) = *SAFAMILY(¶m->sincl) = AF_INET;
pthread_mutex_init(&srv->counter_mutex, NULL);
- memcpy(&srv->intsa, &conf.intsa, sizeof(srv->intsa));
- memcpy(&srv->extsa, &conf.extsa, sizeof(srv->extsa));
+ srv->intsa = conf.intsa;
+ srv->extsa = conf.extsa;
#ifndef NOIPV6
- memcpy(&srv->extsa6, &conf.extsa6, sizeof(srv->extsa6));
+ srv->extsa6 = conf.extsa6;
#endif
}
@@ -748,13 +751,12 @@ void srvinit2(struct srvparam * srv, struct clientparam *param){
*SAFAMILY(¶m->sinsl) = AF_INET;
*SAFAMILY(¶m->sinsr) = AF_INET;
*SAFAMILY(¶m->req) = AF_INET;
- memcpy(¶m->sincr, &srv->intsa, sizeof(param->sincr));
- memcpy(¶m->sincl, &srv->intsa, sizeof(param->sincl));
+ param->sincr = param->sincl = srv->intsa;
#ifndef NOIPV6
- memcpy(¶m->sinsr, (srv->family == 6 || srv->family == 64)? (void *)&srv->extsa6: (void *)&srv->extsa, sizeof(param->sinsr));
-#else
- memcpy(¶m->sinsr, &srv->extsa, sizeof(param->sinsr));
+ if (srv->family == 6 || srv->family == 64) param->sinsr = srv->extsa6;
+ else
#endif
+ param->sinsr = srv->extsa;
}
void srvfree(struct srvparam * srv){
@@ -911,7 +913,7 @@ void copyfilter (struct filter *filter, struct srvparam *srv){
if(!filter->filter_open || !(data = (*filter->filter_open)(filter->data, srv))) continue;
- memcpy(srv->filter + srv->nfilters, filter, sizeof(struct filter));
+ srv->filter[srv->nfilters] = *filter;
srv->filter[srv->nfilters].data = data;
if(srv->nfilters>0)srv->filter[srv->nfilters - 1].next = srv->filter + srv->nfilters;
srv->nfilters++;
diff --git a/src/socks.c b/src/socks.c
index 6e2b7d8..b9c6b2b 100644
--- a/src/socks.c
+++ b/src/socks.c
@@ -133,7 +133,7 @@ void * sockschild(struct clientparam* param) {
}
buf[i] = 0;
if(!getip46(param->srv->family, buf, (struct sockaddr *) ¶m->req)) RETURN(100);
- memcpy(¶m->sinsr, ¶m->req, sizeof(param->req));
+ param->sinsr = param->req;
break;
default:
RETURN(997);
@@ -159,7 +159,7 @@ void * sockschild(struct clientparam* param) {
if(param->hostname)myfree(param->hostname);
param->hostname = (unsigned char *)mystrdup((char *)buf);
if(!getip46(param->srv->family, buf, (struct sockaddr *) ¶m->req)) RETURN(100);
- memcpy(¶m->sinsr, ¶m->req, sizeof(¶m->req));
+ param->sinsr = param->req;
}
}
@@ -173,9 +173,9 @@ void * sockschild(struct clientparam* param) {
case 3:
#ifndef NOIPV6
- memcpy(¶m->sinsl, *SAFAMILY(¶m->req)==AF_INET6? (struct sockaddr *)¶m->srv->extsa6:(struct sockaddr *)¶m->srv->extsa, SASIZE(¶m->req));
+ param->sinsl = *SAFAMILY(¶m->req)==AF_INET6? param->srv->extsa6 : param->srv->extsa;
#else
- memcpy(¶m->sinsl, ¶m->srv->extsa, SASIZE(¶m->req));
+ param->sinsl = param->srv->extsa;
#endif
if ((param->remsock=so._socket(SASOCK(¶m->req), command == 2? SOCK_STREAM:SOCK_DGRAM, command == 2?IPPROTO_TCP:IPPROTO_UDP)) == INVALID_SOCKET) {RETURN (11);}
param->operation = command == 2?BIND:UDPASSOC;
@@ -218,7 +218,7 @@ fflush(stderr);
param->ctrlsock = param->clisock;
param->clisock = so._socket(SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP);
if(param->clisock == INVALID_SOCKET) {RETURN(11);}
- memcpy(&sin, ¶m->sincl, sizeof(&sin));
+ sin = param->sincl;
*SAPORT(&sin) = 0;
if(so._bind(param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
#if SOCKSTRACE > 0
@@ -328,7 +328,7 @@ fflush(stderr);
param->res = sockmap(param, conf.timeouts[CONNECTION_S]);
break;
case 3:
- memcpy(¶m->sinsr, ¶m->req, sizeof(param->sinsr));
+ param->sinsr = param->req;
myfree(buf);
if(!(buf = myalloc(LARGEBUFSIZE))) {RETURN(21);}
From 6713530fda9721b52cc42c668886338613fb9d4d Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Fri, 5 Feb 2016 19:04:16 +0300
Subject: [PATCH 04/20] log_mutex init moved to proxymain
---
src/3proxy.c | 3 ---
src/common.c | 10 ----------
src/dighosts.c | 1 +
src/proxy.h | 1 -
src/proxymain.c | 6 ++++++
5 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/src/3proxy.c b/src/3proxy.c
index 4a5eb70..f5b7f07 100644
--- a/src/3proxy.c
+++ b/src/3proxy.c
@@ -510,9 +510,6 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
return 1;
}
- pthread_mutex_init(&log_mutex, NULL);
- logmutexinit = 1;
-
pthread_mutex_init(&config_mutex, NULL);
pthread_mutex_init(&bandlim_mutex, NULL);
pthread_mutex_init(&hash_mutex, NULL);
diff --git a/src/common.c b/src/common.c
index 55aef52..1244ec6 100644
--- a/src/common.c
+++ b/src/common.c
@@ -601,17 +601,11 @@ void lognone(struct clientparam * param, const unsigned char *s) {
if(param->trafcountfunc)(*param->trafcountfunc)(param);
clearstat(param);
}
-pthread_mutex_t log_mutex;
-int logmutexinit = 0;
unsigned char tmpbuf[8192];
void logstdout(struct clientparam * param, const unsigned char *s) {
FILE *log;
- if(!logmutexinit){
- pthread_mutex_init(&log_mutex, NULL);
- logmutexinit = 1;
- }
pthread_mutex_lock(&log_mutex);
log = param->srv->stdlog?param->srv->stdlog:conf.stdlog?conf.stdlog:stdout;
dobuf(param, tmpbuf, s, NULL);
@@ -624,10 +618,6 @@ void logstdout(struct clientparam * param, const unsigned char *s) {
#ifndef _WIN32
void logsyslog(struct clientparam * param, const unsigned char *s) {
- if(!logmutexinit){
- pthread_mutex_init(&log_mutex, NULL);
- logmutexinit = 1;
- }
pthread_mutex_lock(&log_mutex);
dobuf(param, tmpbuf, s, NULL);
if(!param->nolog)syslog(LOG_INFO, "%s", tmpbuf);
diff --git a/src/dighosts.c b/src/dighosts.c
index 2d25989..2df5150 100644
--- a/src/dighosts.c
+++ b/src/dighosts.c
@@ -6,6 +6,7 @@
*/
#include "proxy.h"
+pthread_mutex_t log_mutex;
int sockgetchar(SOCKET sock, int timeosec, int timeousec){
diff --git a/src/proxy.h b/src/proxy.h
index f92960a..2cb0eca 100644
--- a/src/proxy.h
+++ b/src/proxy.h
@@ -316,7 +316,6 @@ extern pthread_mutex_t hash_mutex;
extern pthread_mutex_t tc_mutex;
extern pthread_mutex_t pwl_mutex;
extern pthread_mutex_t log_mutex;
-extern int logmutexinit;
extern struct datatype datatypes[64];
diff --git a/src/proxymain.c b/src/proxymain.c
index dfb073d..25b3223 100644
--- a/src/proxymain.c
+++ b/src/proxymain.c
@@ -8,6 +8,8 @@
#include "proxy.h"
+pthread_mutex_t log_mutex;
+int logmutexinit = 0;
#define param ((struct clientparam *) p)
#ifdef _WIN32
@@ -179,6 +181,10 @@ int MODULEMAINFUNC (int argc, char** argv){
#endif
#endif
+ if(!logmutexinit){
+ pthread_mutex_init(&log_mutex, NULL);
+ logmutexinit = 1;
+ }
srvinit(&srv, &defparam);
srv.pf = childdef.pf;
From 3680f2d3b170188eb5bd7f4267afe2196c9c0c68 Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Mon, 8 Feb 2016 14:39:29 +0300
Subject: [PATCH 05/20] Do not negotiate handshake for extip redirection
---
src/auth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/auth.c b/src/auth.c
index 97f2673..d42d5c5 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -243,6 +243,8 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
if(!connected){
if(cur->type == R_EXTIP){
param->sinsl = cur->addr;
+ if(cur->next)continue;
+ return 0;
}
else if(SAISNULL(&cur->addr) && !*SAPORT(&cur->addr)){
if(cur->extuser){
From 5fc1d81e5c317a06d6953736c9736be304e542b9 Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Thu, 11 Feb 2016 16:16:44 +0300
Subject: [PATCH 06/20] add stack size configuration
'stacksize' command and -S configuration option added
---
src/common.c | 4 ++--
src/conf.c | 13 ++++++++++---
src/proxy.h | 2 --
src/proxymain.c | 18 ++++++++++++------
src/structures.h | 8 +++++---
5 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/src/common.c b/src/common.c
index 1244ec6..9ae590a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -58,7 +58,7 @@ struct extparam conf = {
NULL, NULL,
NULL,
NULL,
- 0, -1, 0, 0, 0, 0, 0, 500, 0, 0, 0,
+ 8192, 0, -1, 0, 0, 0, 0, 0, 500, 0, 0, 0,
6, 600,
1048576,
NULL, NULL,
@@ -84,7 +84,7 @@ struct extparam conf = {
NULL,
(time_t)0, (time_t)0,
0,0,
- '@'
+ '@',
};
int numservers=0;
diff --git a/src/conf.c b/src/conf.c
index 7ef51bf..68318a3 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -32,6 +32,7 @@ struct proxydef childdef = {NULL, 0, 0, S_NOSERVICE, ""};
#ifndef _WIN32
char *chrootp = NULL;
+static pthread_attr_t pa;
#endif
char * curconf = NULL;
@@ -142,14 +143,14 @@ int start_proxy_thread(struct child * chp){
conf.threadinit = 1;
#ifdef _WIN32
#ifndef _WINCE
- h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384, startsrv, (void *) chp, (DWORD)0, &thread);
+ h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, startsrv, (void *) chp, (DWORD)0, &thread);
#else
- h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 16384, startsrv, (void *) chp, (DWORD)0, &thread);
+ h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, startsrv, (void *) chp, (DWORD)0, &thread);
#endif
if(h)CloseHandle(h);
#else
pthread_attr_init(&pa);
- pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + 16384);
+ pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (16384+conf.stacksize));
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
pthread_create(&thread, &pa, startsrv, (void *)chp);
#endif
@@ -334,6 +335,11 @@ static int h_log(int argc, unsigned char ** argv){
return 0;
}
+static int h_stacksize(int argc, unsigned char **argv){
+ conf.stacksize = atoi((char *)argv[1]);
+ return 0;
+}
+
static int h_service(int argc, unsigned char **argv){
return 0;
}
@@ -1392,6 +1398,7 @@ struct commands commandhandlers[]={
{commandhandlers+55, "msnpr", h_proxy, 4, 0},
{commandhandlers+56, "delimchar",h_delimchar, 2, 2},
{commandhandlers+57, "authnserver", h_authnserver, 2, 2},
+ {commandhandlers+58, "stacksize", h_stacksize, 2, 2},
{specificcommands, "", h_noop, 1, 0}
};
diff --git a/src/proxy.h b/src/proxy.h
index 2cb0eca..3ae14c2 100644
--- a/src/proxy.h
+++ b/src/proxy.h
@@ -122,8 +122,6 @@
#ifdef _WIN32
#define strcasecmp stricmp
#define strncasecmp strnicmp
-#else
-extern pthread_attr_t pa;
#endif
#ifndef SOCKET_ERROR
diff --git a/src/proxymain.c b/src/proxymain.c
index 25b3223..d99580f 100644
--- a/src/proxymain.c
+++ b/src/proxymain.c
@@ -126,7 +126,8 @@ int MODULEMAINFUNC (int argc, char** argv){
" -fFORMAT logging format (see documentation)\n"
" -l log to stderr\n"
" -lFILENAME log to FILENAME\n"
- " -bBUFSIZE size of network buffer (default 4096 for TCP, 16384 for UDP)\n"
+ " -b(BUFSIZE) size of network buffer (default 4096 for TCP, 16384 for UDP)\n"
+ " -S(STACKSIZE) value to add to default client thread stack size\n"
" -t be silent (do not log service start/stop)\n"
" -iIP ip address or internal interface (clients are expected to connect)\n"
" -eIP ip address or external interface (outgoing connection will have this)\n"
@@ -140,6 +141,7 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifdef _WIN32
unsigned long ul = 1;
#else
+ pthread_attr_t pa;
#ifdef STDMAIN
int inetd = 0;
#endif
@@ -175,9 +177,6 @@ int MODULEMAINFUNC (int argc, char** argv){
#else
signal(SIGPIPE, SIG_IGN);
- pthread_attr_init(&pa);
- pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + 8192);
- pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
#endif
#endif
@@ -304,6 +303,9 @@ int MODULEMAINFUNC (int argc, char** argv){
case 'T':
srv.transparent = 1;
break;
+ case 'S':
+ srv.stacksize = atoi(argv[i]+2);
+ break;
case 's':
case 'a':
srv.singlepacket = 1 + atoi(argv[i]+2);
@@ -399,6 +401,9 @@ int MODULEMAINFUNC (int argc, char** argv){
return((*srv.pf)((void *)newparam)? 1:0);
}
+ pthread_attr_init(&pa);
+ pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (8192 + srv.stacksize));
+ pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
#endif
@@ -651,9 +656,9 @@ int MODULEMAINFUNC (int argc, char** argv){
}
#ifdef _WIN32
#ifndef _WINCE
- h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, (unsigned)16384, threadfunc, (void *) newparam, 0, &thread);
+ h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, (unsigned)(16384 + srv.stacksize), threadfunc, (void *) newparam, 0, &thread);
#else
- h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, (unsigned)16384, threadfunc, (void *) newparam, 0, &thread);
+ h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, (unsigned)(16384 + srv.stacksize), threadfunc, (void *) newparam, 0, &thread);
#endif
srv.childcount++;
if (h) {
@@ -715,6 +720,7 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
srv->authfunc = conf.authfunc;
srv->usentlm = 0;
srv->maxchild = conf.maxchild;
+ srv->stacksize = conf.stacksize;
srv->time_start = time(NULL);
if(conf.logtarget){
if(srv->logtarget) myfree(srv->logtarget);
diff --git a/src/structures.h b/src/structures.h
index b3f34c3..202a5b3 100644
--- a/src/structures.h
+++ b/src/structures.h
@@ -372,6 +372,7 @@ struct srvparam {
int transparent;
int nfilters, nreqfilters, nhdrfilterscli, nhdrfilterssrv, npredatfilters, ndatfilterscli, ndatfilterssrv;
int family;
+ int stacksize;
unsigned bufsize;
unsigned logdumpsrv, logdumpcli;
#ifndef NOIPV6
@@ -422,6 +423,9 @@ struct clientparam {
REDIRTYPE redirtype;
+ uint64_t waitclient64,
+ waitserver64;
+
int redirected,
operation,
nfilters, nreqfilters, nhdrfilterscli, nhdrfilterssrv, npredatfilters, ndatfilterscli, ndatfilterssrv,
@@ -429,8 +433,6 @@ struct clientparam {
int res,
status;
- uint64_t waitclient64,
- waitserver64;
int pwtype,
threadid,
weight,
@@ -491,7 +493,7 @@ struct extparam {
struct bandlim * bandlimiter, *bandlimiterout;
struct trafcount * trafcounter;
struct srvparam *services;
- int threadinit, counterd, haveerror, rotate, paused, archiverc,
+ int stacksize, threadinit, counterd, haveerror, rotate, paused, archiverc,
demon, maxchild, singlepacket, needreload, timetoexit;
int authcachetype, authcachetime;
int filtermaxsize;
From f70a8c0019ed96ba3b10da20ffc0a34b7ee9db73 Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Tue, 16 Feb 2016 01:03:15 +0300
Subject: [PATCH 07/20] Makefile for Windows llvm build
---
Makefile.llvm | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 Makefile.llvm
diff --git a/Makefile.llvm b/Makefile.llvm
new file mode 100644
index 0000000..557a6a8
--- /dev/null
+++ b/Makefile.llvm
@@ -0,0 +1,34 @@
+#
+# 3 proxy Makefile for GCC/windows
+#
+# You can try to remove -DWITH_STD_MALLOC to CFLAGS to use optimized malloc
+# libraries
+#
+# remove -DNOODBC from CFLAGS and add -lodbc to LDFLAGS to compile with ODBC
+# library support
+
+
+BUILDDIR = ../bin/
+CC = clang
+CFLAGS = -O2 -c -pthread -static -DWITH_STD_MALLOC -DNOIPV6
+COUT = -o
+LN = clang
+LDFLAGS = -O2 -static -s
+DLFLAGS = -shared
+DLSUFFICS = .dll
+LIBS = -lws2_32 -lodbc32 -ladvapi32
+LNOUT = -o
+EXESUFFICS = .exe
+OBJSUFFICS = .o
+DEFINEOPTION = -D
+COMPFILES = *.tmp
+REMOVECOMMAND = rm -f
+TYPECOMMAND = cat
+COMPATLIBS =
+MAKEFILE = Makefile.win
+PLUGINS = utf8tocp1251 WindowsAuthentication TrafficPlugin StringsPlugin PCREPlugin
+
+include Makefile.inc
+
+allplugins:
+ for /D %%i in ($(PLUGINS)) do (copy Makefile plugins\%%i && copy Makefile.var plugins\%%i && cd plugins\%%i && nmake && del *.o &&cd ..\..)
From 3b8e7741b36c422bef0540453955c0510326b438 Mon Sep 17 00:00:00 2001
From: z3APA3A <3APA3A@3proxy.ru>
Date: Tue, 16 Feb 2016 15:29:51 +0300
Subject: [PATCH 08/20] Compilation warnings cleanup
---
Makefile.win | 2 +-
src/3proxy.c | 16 ++---
src/auth.c | 46 +++++++-------
src/common.c | 14 ++---
src/conf.c | 12 ++--
src/dighosts.c | 4 +-
src/dnspr.c | 8 +--
src/ftppr.c | 14 ++---
src/icqpr.c | 20 +++----
src/plugins/PCREPlugin/pcre_plugin.c | 30 +++++-----
.../WindowsAuthentication.c | 4 +-
src/plugins/utf8tocp1251/utf8tocp1251.c | 2 +-
src/proxy.c | 25 ++++----
src/proxy.h | 2 +-
src/proxymain.c | 46 +++++++-------
src/smtpp.c | 60 +++++++++----------
src/sockgetchar.c | 6 +-
src/sockmap.c | 16 ++---
src/socks.c | 4 +-
src/structures.h | 12 ++--
src/udppm.c | 2 +-
21 files changed, 173 insertions(+), 172 deletions(-)
diff --git a/Makefile.win b/Makefile.win
index edcb889..55b0f0c 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -13,7 +13,7 @@ CC = gcc
CFLAGS = -O2 -s -c -mthreads -DWITH_STD_MALLOC -DNOIPV6
COUT = -o
LN = gcc
-LDFLAGS = -O2 -s -mthreads
+LDFLAGS = -O2 -s -mthreads
DLFLAGS = -shared
DLSUFFICS = .dll
LIBS = -lws2_32 -lodbc32 -ladvapi32
diff --git a/src/3proxy.c b/src/3proxy.c
index f5b7f07..5e5f66c 100644
--- a/src/3proxy.c
+++ b/src/3proxy.c
@@ -87,7 +87,7 @@ void __stdcall CommandHandler( DWORD dwCommand )
void __stdcall ServiceMain(int argc, unsigned char* argv[] )
{
- hSrv = RegisterServiceCtrlHandler(conf.stringtable[1], (LPHANDLER_FUNCTION)CommandHandler);
+ hSrv = RegisterServiceCtrlHandler((LPCSTR)conf.stringtable[1], (LPHANDLER_FUNCTION)CommandHandler);
if( hSrv == 0 ) return;
SetStatus( SERVICE_START_PENDING, 0, 1 );
@@ -394,7 +394,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
"By clicking Yes you confirm you read and accepted License Agreement.\n"
"You can use Administration/Services to control %s service.",
conf.stringtable[1], conf.stringtable[2]);
- if(MessageBox(NULL, (char *)tmpbuf, conf.stringtable[2], MB_YESNO|MB_ICONASTERISK) != IDYES) return 1;
+ if(MessageBox(NULL, (LPCSTR)tmpbuf, (LPCSTR)conf.stringtable[2], MB_YESNO|MB_ICONASTERISK) != IDYES) return 1;
*tmpbuf = '\"';
@@ -415,7 +415,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
perror("Failed to open Service Manager");
RETURN(101);
}
- if (!(sch = CreateService(sch, conf.stringtable[1], conf.stringtable[2], GENERIC_EXECUTE, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, (char *)tmpbuf, NULL, NULL, NULL, NULL, NULL))){
+ if (!(sch = CreateService(sch, (LPCSTR)conf.stringtable[1], (LPCSTR)conf.stringtable[2], GENERIC_EXECUTE, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, (char *)tmpbuf, NULL, NULL, NULL, NULL, NULL))){
perror("Failed to create service");
RETURN(103);
}
@@ -436,10 +436,10 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
RETURN(104);
}
if(RegSetValueEx( runsrv,
- conf.stringtable[1],
+ (LPCSTR)conf.stringtable[1],
0,
REG_EXPAND_SZ,
- (char *)tmpbuf,
+ (BYTE *)tmpbuf,
(int)strlen((char *)tmpbuf)+1)!=ERROR_SUCCESS){
perror("Failed to set registry value");
RETURN(105);
@@ -457,7 +457,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
perror("Failed to open Service Manager\n");
RETURN(106);
}
- if (!(sch = OpenService(sch, conf.stringtable[1], DELETE))){
+ if (!(sch = OpenService(sch, (LPCSTR)conf.stringtable[1], DELETE))){
perror("Failed to open service");
RETURN(107);
}
@@ -476,7 +476,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
perror("Failed to open registry");
RETURN(109);
}
- if(RegDeleteValue(runsrv, conf.stringtable[1]) != ERROR_SUCCESS){
+ if(RegDeleteValue(runsrv, (LPCSTR)conf.stringtable[1]) != ERROR_SUCCESS){
perror("Failed to clear registry");
RETURN(110);
}
@@ -528,7 +528,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
if(service){
SERVICE_TABLE_ENTRY ste[] =
{
- { conf.stringtable[1], (LPSERVICE_MAIN_FUNCTION)ServiceMain},
+ { (LPSTR)conf.stringtable[1], (LPSERVICE_MAIN_FUNCTION)ServiceMain},
{ NULL, NULL }
};
if(!StartServiceCtrlDispatcher( ste ))cyclestep();
diff --git a/src/auth.c b/src/auth.c
index d42d5c5..05c9e2e 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -43,9 +43,9 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
len = sprintf((char *)buf, "CONNECT ");
if(redir->type == R_CONNECTP && param->hostname) {
char * needreplace;
- needreplace = strchr(param->hostname, ':');
+ needreplace = strchr((char *)param->hostname, ':');
if(needreplace) buf[len++] = '[';
- len =+ sprintf((char *)buf + len, "%.256s", param->hostname);
+ len += sprintf((char *)buf + len, "%.256s", (char *)param->hostname);
if(needreplace) buf[len++] = ']';
}
else {
@@ -372,19 +372,19 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
for(hstentry = acentry->dstnames; hstentry; hstentry = hstentry->next){
switch(hstentry->matchtype){
case 0:
- if(strstr(param->hostname, hstentry->name)) match = 1;
+ if(strstr((char *)param->hostname, (char *)hstentry->name)) match = 1;
break;
case 1:
- if(strstr(param->hostname, hstentry->name) == (char *)param->hostname) match = 1;
+ if(strstr((char *)param->hostname, (char *)hstentry->name) == (char *)param->hostname) match = 1;
break;
case 2:
- if(strstr(param->hostname, hstentry->name) == (char *)(param->hostname + i - (strlen(hstentry->name)))) match = 1;
+ if(strstr((char *)param->hostname, (char *)hstentry->name) == (char *)(param->hostname + i - (strlen((char *)hstentry->name)))) match = 1;
break;
default:
- if(!strcmp(param->hostname, hstentry->name)) match = 1;
+ if(!strcmp((char *)param->hostname, (char *)hstentry->name)) match = 1;
break;
}
if(match) break;
@@ -654,13 +654,13 @@ int cacheauth(struct clientparam * param){
continue;
}
- if(((!(conf.authcachetype&2)) || (param->username && ac->username && !strcmp(ac->username, param->username))) &&
+ if(((!(conf.authcachetype&2)) || (param->username && ac->username && !strcmp(ac->username, (char *)param->username))) &&
((!(conf.authcachetype&1)) || (*SAFAMILY(&ac->sa) == *SAFAMILY(¶m->sincr) && !memcmp(SAADDR(&ac->sa), ¶m->sincr, SAADDRLEN(&ac->sa)))) &&
- (!(conf.authcachetype&4) || (ac->password && param->password && !strcmp(ac->password, param->password)))) {
+ (!(conf.authcachetype&4) || (ac->password && param->password && !strcmp(ac->password, (char *)param->password)))) {
if(param->username){
myfree(param->username);
}
- param->username = mystrdup(ac->username);
+ param->username = (unsigned char *)mystrdup(ac->username);
pthread_mutex_unlock(&hash_mutex);
return 0;
}
@@ -688,18 +688,18 @@ int doauth(struct clientparam * param){
if(conf.authcachetype && authfuncs->authenticate && authfuncs->authenticate != cacheauth && param->username && (!(conf.authcachetype&4) || (!param->pwtype && param->password))){
pthread_mutex_lock(&hash_mutex);
for(ac = authc; ac; ac = ac->next){
- if((!(conf.authcachetype&2) || !strcmp(ac->username, param->username)) &&
+ if((!(conf.authcachetype&2) || !strcmp(ac->username, (char *)param->username)) &&
(!(conf.authcachetype&1) || (*SAFAMILY(&ac->sa) == *SAFAMILY(¶m->sincr) && !memcmp(SAADDR(&ac->sa), ¶m->sincr, SAADDRLEN(&ac->sa)))) &&
- (!(conf.authcachetype&4) || (ac->password && !strcmp(ac->password, param->password)))) {
+ (!(conf.authcachetype&4) || (ac->password && !strcmp(ac->password, (char *)param->password)))) {
ac->expires = conf.time + conf.authcachetime;
- if(strcmp(ac->username, param->username)){
+ if(strcmp(ac->username, (char *)param->username)){
tmp = ac->username;
- ac->username = mystrdup(param->username);
+ ac->username = mystrdup((char *)param->username);
myfree(tmp);
}
if((conf.authcachetype&4)){
tmp = ac->password;
- ac->password = mystrdup(param->password);
+ ac->password = mystrdup((char *)param->password);
myfree(tmp);
}
ac->sa = param->sincr;
@@ -710,10 +710,10 @@ int doauth(struct clientparam * param){
ac = myalloc(sizeof(struct authcache));
if(ac){
ac->expires = conf.time + conf.authcachetime;
- ac->username = mystrdup(param->username);
+ ac->username = mystrdup((char *)param->username);
ac->sa = param->sincr;
ac->password = NULL;
- if((conf.authcachetype&4) && param->password) ac->password = mystrdup(param->password);
+ if((conf.authcachetype&4) && param->password) ac->password = mystrdup((char *)param->password);
}
ac->next = authc;
authc = ac;
@@ -775,7 +775,7 @@ int dnsauth(struct clientparam * param){
((u&0xFF000000)>>24));
}
- if(!udpresolve(*SAFAMILY(¶m->sincr), buf, addr, NULL, param, 1)) return 6;
+ if(!udpresolve(*SAFAMILY(¶m->sincr), (unsigned char *)buf, (unsigned char *)addr, NULL, param, 1)) return 6;
if(!memcmp(SAADDR(¶m->sincr), addr, SAADDRLEN(¶m->sincr))) return 6;
return param->username? 0:4;
@@ -1187,7 +1187,7 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
}
*s2 = 0;
if(param->username)myfree(param->username);
- param->username = mystrdup (buf + k + 13);
+ param->username = (unsigned char *)mystrdup ((char *)buf + k + 13);
return udpresolve(af,param->username, value, NULL, NULL, 2);
}
@@ -1324,20 +1324,20 @@ void logsql(struct clientparam * param, const unsigned char *s) {
if(param->nolog) return;
pthread_mutex_lock(&log_mutex);
- len = dobuf(param, tmpbuf, s, "\'");
+ len = dobuf(param, tmpbuf, s, (unsigned char *)"\'");
if(attempt > 5){
time_t t;
t = time(0);
if (t - attempt_time < 180){
- sqlerr(tmpbuf);
+ sqlerr((char *)tmpbuf);
return;
}
}
if(!hstmt){
if(!init_sql(sqlstring)) {
- sqlerr(tmpbuf);
+ sqlerr((char *)tmpbuf);
return;
}
}
@@ -1346,13 +1346,13 @@ void logsql(struct clientparam * param, const unsigned char *s) {
if(ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO){
close_sql();
if(!init_sql(sqlstring)){
- sqlerr(tmpbuf);
+ sqlerr((char *)tmpbuf);
return;
}
if(hstmt) {
ret = SQLExecDirect(hstmt, (SQLCHAR *)tmpbuf, (SQLINTEGER)len);
if(ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO){
- sqlerr(tmpbuf);
+ sqlerr((char *)tmpbuf);
return;
}
attempt = 0;
diff --git a/src/common.c b/src/common.c
index 9ae590a..29f81c4 100644
--- a/src/common.c
+++ b/src/common.c
@@ -216,12 +216,12 @@ int ceparseargs(const char *str){
#endif
-void parsehost(int family, char *host, struct sockaddr *sa){
+void parsehost(int family, unsigned char *host, struct sockaddr *sa){
char *sp=NULL,*se=NULL;
unsigned short port;
- if(*host == '[') se=strchr(host, ']');
- if ( (sp = strchr(se?se:host, ':')) ) *sp = 0;
+ if(*host == '[') se=strchr((char *)host, ']');
+ if ( (sp = strchr(se?se:(char *)host, ':')) ) *sp = 0;
if(se){
*se = 0;
}
@@ -297,7 +297,7 @@ int parseconnusername(char *username, struct clientparam *param, int extpasswd,
if(!username || !*username) return 1;
if ((sb=strchr(username, conf.delimchar)) == NULL){
if(!param->hostname && param->remsock == INVALID_SOCKET) return 2;
- if(param->hostname)parsehostname(param->hostname, param, port);
+ if(param->hostname)parsehostname((char *)param->hostname, param, port);
return parseusername(username, param, extpasswd);
}
while ((se=strchr(sb+1, conf.delimchar)))sb=se;
@@ -466,7 +466,7 @@ int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char
break;
case 'N':
- if(param->service >=0 && param->service < 15) {
+ if(param->service < 15) {
len = (conf.stringtable)? (int)strlen((char *)conf.stringtable[SERVICES + param->service]) : 0;
if(len > 20) len = 20;
memcpy(buf+i, (len)?conf.stringtable[SERVICES + param->service]:(unsigned char*)"-", (len)?len:1);
@@ -648,14 +648,14 @@ int doconnect(struct clientparam * param){
}
if(!*SAPORT(¶m->sinsr))*SAPORT(¶m->sinsr) = *SAPORT(¶m->req);
if ((param->remsock=so._socket(SASOCK(¶m->sinsr), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {return (11);}
- so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (unsigned char *)&lg, sizeof(lg));
+ so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
#ifdef REUSE
{
int opt;
#ifdef SO_REUSEADDR
opt = 1;
- so._setsockopt(param->remsock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&opt, sizeof(int));
+ so._setsockopt(param->remsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
#endif
#ifdef SO_REUSEPORT
opt = 1;
diff --git a/src/conf.c b/src/conf.c
index 68318a3..e4b3caf 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -735,7 +735,7 @@ static int h_nolog(int argc, unsigned char **argv){
return(1);
}
while(acl->next) acl = acl->next;
- if(!strcmp(argv[0],"nolog")) acl->nolog = 1;
+ if(!strcmp((char *)argv[0],"nolog")) acl->nolog = 1;
else acl->weight = atoi((char*)argv[1]);
return 0;
}
@@ -748,14 +748,14 @@ int scanipl(unsigned char *arg, struct iplist *dst){
#endif
char * slash, *dash;
int masklen, addrlen;
- if((slash = strchr(arg, '/'))) *slash = 0;
- if((dash = strchr(arg,'-'))) *dash = 0;
+ if((slash = strchr((char *)arg, '/'))) *slash = 0;
+ if((dash = strchr((char *)arg,'-'))) *dash = 0;
if(!getip46(46, arg, (struct sockaddr *)&sa)) return 1;
memcpy(&dst->ip_from, SAADDR(&sa), SAADDRLEN(&sa));
dst->family = *SAFAMILY(&sa);
if(dash){
- if(!getip46(46, dash+1, (struct sockaddr *)&sa)) return 2;
+ if(!getip46(46, (unsigned char *)dash+1, (struct sockaddr *)&sa)) return 2;
memcpy(&dst->ip_to, SAADDR(&sa), SAADDRLEN(&sa));
if(*SAFAMILY(&sa) != dst->family || memcmp(&dst->ip_to, &dst->ip_from, SAADDRLEN(&sa)) < 0) return 3;
return 0;
@@ -1262,7 +1262,7 @@ static int h_plugin(int argc, unsigned char **argv){
#ifdef _WINCE
hi = LoadLibraryW((LPCWSTR)CEToUnicode(argv[1]));
#else
- hi = LoadLibrary(argv[1]);
+ hi = LoadLibrary((char *)argv[1]);
#endif
if(!hi) {
fprintf(stderr, "Failed to load %s, code %d\n", argv[1], (int)GetLastError());
@@ -1271,7 +1271,7 @@ static int h_plugin(int argc, unsigned char **argv){
#ifdef _WINCE
fp = GetProcAddressW(hi, (LPCWSTR)CEToUnicode(argv[2]));
#else
- fp = GetProcAddress(hi, argv[2]);
+ fp = GetProcAddress(hi, (char *)argv[2]);
#endif
if(!fp) {
printf("%s not found in %s, code: %d\n", argv[2], argv[1], (int)GetLastError());
diff --git a/src/dighosts.c b/src/dighosts.c
index 2df5150..ccf9c43 100644
--- a/src/dighosts.c
+++ b/src/dighosts.c
@@ -19,7 +19,7 @@ int sockgetchar(SOCKET sock, int timeosec, int timeousec){
FD_ZERO(&fds);
FD_SET(sock, &fds);
if (select (((int)sock)+1, &fds, NULL, NULL, &tv)!=1) return EOF;
- if (recv(sock, &buf, 1, 0)!=1) return EOF;
+ if (recv(sock, (char *)&buf, 1, 0)!=1) return EOF;
return((int)buf);
}
@@ -95,7 +95,7 @@ int main(int argc, char *argv[]){
fprintf(stderr, "Unable to connect: %s\n", host);
return 8;
}
- if(send(sock, buf, (int)strlen((char *)buf), 0) != (int)strlen((char *)buf)) return 9;
+ if(send(sock, (char *)buf, (int)strlen((char *)buf), 0) != (int)strlen((char *)buf)) return 9;
while( (i = sockgetline(sock, buf, sizeof(buf) - 1, '\n', 30)) > 2);
if(i<1) return 9;
if(!(fp = fopen(argv[argc-1], "w"))) {
diff --git a/src/dnspr.c b/src/dnspr.c
index 45d4355..078447c 100644
--- a/src/dnspr.c
+++ b/src/dnspr.c
@@ -39,7 +39,7 @@ void * dnsprchild(struct clientparam* param) {
}
buf = bbuf+2;
size = sizeof(param->sincr);
- i = so._recvfrom(param->srv->srvsock, buf, BUFSIZE, 0, (struct sockaddr *)¶m->sincr, &size);
+ i = so._recvfrom(param->srv->srvsock, (char *)buf, BUFSIZE, 0, (struct sockaddr *)¶m->sincr, &size);
size = sizeof(param->sinsl);
getsockname(param->srv->srvsock, (struct sockaddr *)¶m->sincl, &size);
#ifdef _WIN32
@@ -47,7 +47,7 @@ void * dnsprchild(struct clientparam* param) {
RETURN(818);
}
ioctlsocket(param->clisock, FIONBIO, &ul);
- if(so._setsockopt(param->clisock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&ul, sizeof(int))) {RETURN(820);};
+ if(so._setsockopt(param->clisock, SOL_SOCKET, SO_REUSEADDR, (char *)&ul, sizeof(int))) {RETURN(820);};
if(so._bind(param->clisock,(struct sockaddr *)¶m->sincl,SASIZE(¶m->sincl))) {
RETURN(822);
}
@@ -195,8 +195,8 @@ CLEANRET:
sprintf((char *)buf, "%04x/%s/",
(unsigned)type,
host?host:"");
- if(ip && type == 0x01 || type == 0x1c){
- myinet_ntop(type == 0x01? AF_INET:AF_INET6, addr, buf+strlen(buf), 64);
+ if((ip && type == 0x01) || type == 0x1c){
+ myinet_ntop(type == 0x01? AF_INET:AF_INET6, addr, (char *)buf+strlen((char *)buf), 64);
}
(*param->srv->logfunc)(param, buf);
}
diff --git a/src/ftppr.c b/src/ftppr.c
index 7c9cb00..820e9cc 100644
--- a/src/ftppr.c
+++ b/src/ftppr.c
@@ -76,7 +76,7 @@ void * ftpprchild(struct clientparam* param) {
{
int action, reqbufsize, reqsize;
reqbufsize = BUFSIZE;
- reqsize = (int)strlen(buf) + 1;
+ reqsize = (int)strlen((char *)buf) + 1;
action = handlereqfilters(param, &buf, &reqbufsize, 0, &reqsize);
if(action == HANDLED){
@@ -94,7 +94,7 @@ void * ftpprchild(struct clientparam* param) {
{
int action, reqbufsize, reqsize;
reqbufsize = BUFSIZE;
- reqsize = (int)strlen(buf) + 1;
+ reqsize = (int)strlen((char *)buf) + 1;
action = handlehdrfilterscli(param, &buf, &reqbufsize, 0, &reqsize);
if(action == HANDLED){
@@ -150,13 +150,13 @@ void * ftpprchild(struct clientparam* param) {
clidatasock = INVALID_SOCKET;
RETURN(826);
}
- sprintf(buf, "200 OK\r\n");
+ sprintf((char *)buf, "200 OK\r\n");
}
#ifndef WITHMAIN
{
int action, reqbufsize, reqsize;
reqbufsize = BUFSIZE;
- reqsize = (int)strlen(buf) + 1;
+ reqsize = (int)strlen((char *)buf) + 1;
action = handlehdrfilterssrv(param, &buf, &reqbufsize, 0, &reqsize);
if(action == HANDLED){
@@ -184,7 +184,7 @@ void * ftpprchild(struct clientparam* param) {
{
int action, reqbufsize, reqsize;
reqbufsize = BUFSIZE;
- reqsize = (int)strlen(buf) + 1;
+ reqsize = (int)strlen((char *)buf) + 1;
action = handlehdrfilterscli(param, &buf, &reqbufsize, 0, &reqsize);
if(action == HANDLED){
@@ -239,8 +239,8 @@ void * ftpprchild(struct clientparam* param) {
}
sc = param->remsock;
param->remsock = ss;
- so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (unsigned char *)&lg, sizeof(lg));
- so._setsockopt(clidatasock, SOL_SOCKET, SO_LINGER, (unsigned char *)&lg, sizeof(lg));
+ so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
+ so._setsockopt(clidatasock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
param->clisock = clidatasock;
res = sockmap(param, conf.timeouts[CONNECTION_S]);
if(param->remsock != INVALID_SOCKET) {
diff --git a/src/icqpr.c b/src/icqpr.c
index 74ac8e7..bd45687 100644
--- a/src/icqpr.c
+++ b/src/icqpr.c
@@ -128,11 +128,11 @@ static int searchcookie(struct clientparam *param, struct flap_header * flap, in
icq_cookie_mutex_init = 1;
}
pthread_mutex_lock(&icq_cookie_mutex);
- for(ic = icq_cookies; ic; ic = ic->next)if(!strcmp(param->username, ic->id))break;
+ for(ic = icq_cookies; ic; ic = ic->next)if(!strcmp((char *)param->username, ic->id))break;
if(!ic){
ic = myalloc(sizeof(struct icq_cookie));
memset(ic, 0, sizeof(struct icq_cookie));
- ic->id = mystrdup(param->username);
+ ic->id = mystrdup((char *)param->username);
ic->next = icq_cookies;
icq_cookies = ic;
}
@@ -202,10 +202,10 @@ static FILTER_ACTION icq_srv(void *fc, struct clientparam * param, unsigned char
state->state = ONCHAN;
}
else {
- if(!state->leftinstate)param->srv->logfunc(param, "Warning: need resync");
+ if(!state->leftinstate)param->srv->logfunc(param, (unsigned char *)"Warning: need resync");
state->leftinstate++;
if(state->leftinstate > 65535){
- param->srv->logfunc(param, "Out of Sync");
+ param->srv->logfunc(param, (unsigned char *)"Out of Sync");
return REJECT;
}
}
@@ -214,7 +214,7 @@ static FILTER_ACTION icq_srv(void *fc, struct clientparam * param, unsigned char
break;
case ONCHAN:
if (*start >= 10){
- param->srv->logfunc(param, "Warning: Wrong channel");
+ param->srv->logfunc(param, (unsigned char *)"Warning: Wrong channel");
state->state = ONBEGIN;
}
else {
@@ -234,15 +234,15 @@ static FILTER_ACTION icq_srv(void *fc, struct clientparam * param, unsigned char
case ONSEQ2:
state->gotseq += *start;
if(state->gotseq != state->srvseq){
- char smallbuf[64];
+ unsigned char smallbuf[64];
if(((state->gotseq < state->srvseq) || ((state->gotseq - state->srvseq) > 10 )) && (!state->resyncseq || state->gotseq != state->resyncseq)){
- sprintf(smallbuf, "Warning: Wrong sequence, expected: %04hx got: %04hx", state->srvseq, state->gotseq);
+ sprintf((char *)smallbuf, "Warning: Wrong sequence, expected: %04hx got: %04hx", state->srvseq, state->gotseq);
param->srv->logfunc(param, smallbuf);
state->state = ONBEGIN;
state->resyncseq = state->gotseq;
break;
}
- sprintf(smallbuf, "Warning: %hu flaps are lost on resync", state->gotseq - state->srvseq );
+ sprintf((char *)smallbuf, "Warning: %d flaps are lost on resync", state->gotseq - state->srvseq );
param->srv->logfunc(param, smallbuf);
state->srvseq = state->gotseq;
*(start-1) = (state->seq>>8);
@@ -339,7 +339,7 @@ static int readflap(struct clientparam * param, int direction, unsigned char *bu
if(flap->id != 0x2a) return 2;
len = ntohs(flap->size);
if(len > buflen-6) return 3;
- i = sockgetlinebuf(param, direction, flap->data, len, EOF, conf.timeouts[STRING_S]);
+ i = sockgetlinebuf(param, direction, (unsigned char *)flap->data, len, EOF, conf.timeouts[STRING_S]);
if(len != i) return 4;
return 0;
@@ -418,7 +418,7 @@ void * icqprchild(struct clientparam* param) {
for(ic = icq_cookies; ic; ic=ic->next){
if(ic->size && ic->size == tlv->size && !memcmp(ic->cookie, tlv->data, ntohs(tlv->size))){
parsehostname((char *)ic->connectstring, param, ntohs(param->srv->targetport));
- if(!param->username && ic->id) param->username = mystrdup(ic->id);
+ if(!param->username && ic->id) param->username = (unsigned char *)mystrdup(ic->id);
break;
}
}
diff --git a/src/plugins/PCREPlugin/pcre_plugin.c b/src/plugins/PCREPlugin/pcre_plugin.c
index f04d9c1..f7b74ee 100644
--- a/src/plugins/PCREPlugin/pcre_plugin.c
+++ b/src/plugins/PCREPlugin/pcre_plugin.c
@@ -144,7 +144,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
if(!pcrefd->re) return pcrefd->action;
for(; offset < *length_p; nreplaces++){
- count = pcre_exec(pcrefd->re, NULL, *buf_p, *length_p, offset, 0, ovector, 48);
+ count = pcre_exec(pcrefd->re, NULL, (char *)*buf_p, *length_p, offset, 0, ovector, 48);
if(count <= 0) break;
if(!(replace = pcrefd->replace) || param->nooverwritefilter) return pcrefd->action;
@@ -195,7 +195,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
}
memcpy(newbuf, *buf_p, ovector[0]);
(*pl->myfree)(*buf_p);
- *buf_p = newbuf;
+ *buf_p = (unsigned char *)newbuf;
*bufsize_p = ovector[0] + replen + 1;
}
memcpy(*buf_p + ovector[0], tmpbuf, replen);
@@ -229,15 +229,15 @@ static int h_pcre(int argc, unsigned char **argv){
struct filter *newf;
char *replace = NULL;
- if(!strncmp(argv[2], "allow",5)) action = PASS;
- else if(!strncmp(argv[2], "deny",4)) action = REJECT;
- else if(!strncmp(argv[2], "remove",6)) action = REMOVE;
- else if(!strncmp(argv[2], "dunno",5)) action = CONTINUE;
+ if(!strncmp((char *)argv[2], "allow",5)) action = PASS;
+ else if(!strncmp((char *)argv[2], "deny",4)) action = REJECT;
+ else if(!strncmp((char *)argv[2], "remove",6)) action = REMOVE;
+ else if(!strncmp((char *)argv[2], "dunno",5)) action = CONTINUE;
else return 1;
- if(!strncmp(argv[0], "pcre_rewrite", 12)) {
+ if(!strncmp((char *)argv[0], "pcre_rewrite", 12)) {
int i,j;
offset = 5;
- replace = pl->mystrdup(argv[4]);
+ replace = pl->mystrdup((char *)argv[4]);
if(!replace) return 9;
for(i=0, j=0; replace[i]; i++, j++){
if(replace[i] == '\\'){
@@ -266,7 +266,7 @@ static int h_pcre(int argc, unsigned char **argv){
replace[j] = 0;
}
if(!(acl = pl->make_ace(argc - offset, argv + offset))) return 2;
- acl->nolog = (strstr(argv[2],"log") == 0);
+ acl->nolog = (strstr((char *)argv[2],"log") == 0);
if(*argv[3] && !(*argv[3] == '*' && !argv[3][1]) ){
re = pcre_compile((char *)argv[3], pcre_options, &errptr, &offset, NULL);
if(!re) {
@@ -296,11 +296,11 @@ static int h_pcre(int argc, unsigned char **argv){
newf->data = flt;
newf->filter_open = pcre_filter_open;
newf->filter_client = pcre_filter_client;
- if(strstr(argv[1], "request"))newf->filter_request = pcre_filter_buffer;
- if(strstr(argv[1], "cliheader"))newf->filter_header_cli = pcre_filter_buffer;
- if(strstr(argv[1], "clidata"))newf->filter_data_cli = pcre_filter_buffer;
- if(strstr(argv[1], "srvheader"))newf->filter_header_srv = pcre_filter_buffer;
- if(strstr(argv[1], "srvdata"))newf->filter_data_srv = pcre_filter_buffer;
+ if(strstr((char *)argv[1], "request"))newf->filter_request = pcre_filter_buffer;
+ if(strstr((char *)argv[1], "cliheader"))newf->filter_header_cli = pcre_filter_buffer;
+ if(strstr((char *)argv[1], "clidata"))newf->filter_data_cli = pcre_filter_buffer;
+ if(strstr((char *)argv[1], "srvheader"))newf->filter_header_srv = pcre_filter_buffer;
+ if(strstr((char *)argv[1], "srvdata"))newf->filter_data_srv = pcre_filter_buffer;
newf->filter_clear = pcre_filter_clear;
newf->filter_close = pcre_filter_close;
@@ -334,7 +334,7 @@ static int h_pcre_options(int argc, unsigned char **argv){
pcre_options = 0;
for(j=1; j Q: Why proxy crash on request processing? Q: Why doesn't APOP/CRAM-MD5 authentication work with POP3 proxy?
@@ -128,6 +129,13 @@
невозможен. Защитить соединение можно с помощью TLS (например, stunnel) или
IPSec.
+ A: Возможно, недостаточен размер стека потока по-умолчанию, это может + быть при использовани каких-либо сторонних плагинов (PAM, ODBC) или на + некоторых платформах (некоторые версии FreeBSD на amd64). Можно решить + проблему с помощью опции 'stacksize' или '-S', поддерживаемых в 0.8.4 и выше. +