Support request filters for SOCKS, support broken BIND request from some clients

This commit is contained in:
Vladimir Dubrovin 2023-07-12 15:55:50 +03:00
parent 8b57982a09
commit dc7e098e6b

View File

@ -132,7 +132,8 @@ void * sockschild(struct clientparam* param) {
buf[i] = (unsigned char)res; buf[i] = (unsigned char)res;
} }
buf[i] = 0; buf[i] = 0;
if(!getip46(param->srv->family, buf, (struct sockaddr *) &param->req)) RETURN(100); if(command != 1 && param->srv->family != 6 && (!strcmp((char *)buf, "0.0.0.0") || !strcmp((char *)buf, "0"))) param->req = param->srv->extsa;
else if(!getip46(param->srv->family, buf, (struct sockaddr *) &param->req)) RETURN(100);
param->sinsr = param->req; param->sinsr = param->req;
break; break;
default: default:
@ -203,7 +204,24 @@ void * sockschild(struct clientparam* param) {
RETURN(res); RETURN(res);
} }
#ifndef WITHMAIN
if(param->nreqfilters && buf){
int reqbufsize = BUFSIZE, reqsize, action;
sprintf((char *)buf, "%s ", commands[command]);
if(param->hostname){
sprintf((char *)buf + strlen((char *)buf), "%.265s", param->hostname);
}
else
myinet_ntop(*SAFAMILY(&param->req), SAADDR(&param->req), (char *)buf + strlen((char *)buf), 64);
sprintf((char *)buf+strlen((char *)buf), ":%hu", ntohs(*SAPORT(&param->req)));
reqsize = strlen((char *)buf);
action = handlereqfilters(param, &buf, &reqbufsize, 0, &reqsize);
if(action == HANDLED){
RETURN(0);
}
if(action != PASS) RETURN(517);
}
#endif
if(command > 1) { if(command > 1) {
if(so._bind(param->remsock,(struct sockaddr *)&param->sinsl,SASIZE(&param->sinsl))) { if(so._bind(param->remsock,(struct sockaddr *)&param->sinsl,SASIZE(&param->sinsl))) {
@ -233,6 +251,11 @@ fflush(stderr);
} }
param->res = 0; param->res = 0;
CLEANRET: CLEANRET:
if(param->clisock != INVALID_SOCKET){ if(param->clisock != INVALID_SOCKET){
@ -274,6 +297,8 @@ fflush(stderr);
socksend(param->clisock, buf, 8, conf.timeouts[STRING_S]); socksend(param->clisock, buf, 8, conf.timeouts[STRING_S]);
} }
if (param->npredatfilters){ if (param->npredatfilters){
int action; int action;