mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 02:25:40 +08:00
adding state to socket functions
This commit is contained in:
parent
d83c1f47f8
commit
8198db8617
40
src/auth.c
40
src/auth.c
@ -62,7 +62,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
len += sprintf((char *)buf + len, "\r\n");
|
||||
}
|
||||
len += sprintf((char *)buf + len, "\r\n");
|
||||
if(socksend(param->remsock, buf, len, conf.timeouts[CHAIN_TO]) != (int)strlen((char *)buf))
|
||||
if(socksend(param, param->remsock, buf, len, conf.timeouts[CHAIN_TO]) != (int)strlen((char *)buf))
|
||||
return 31;
|
||||
param->statssrv64+=len;
|
||||
param->nwrites++;
|
||||
@ -99,7 +99,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
memcpy(buf+len, hostname, hostnamelen);
|
||||
len += hostnamelen;
|
||||
}
|
||||
if(socksend(param->remsock, buf, len, conf.timeouts[CHAIN_TO]) < len){
|
||||
if(socksend(param, param->remsock, buf, len, conf.timeouts[CHAIN_TO]) < len){
|
||||
return 41;
|
||||
}
|
||||
param->statssrv64+=len;
|
||||
@ -122,7 +122,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
buf[0] = 5;
|
||||
buf[1] = 1;
|
||||
buf[2] = user? 2 : 0;
|
||||
if(socksend(param->remsock, buf, 3, conf.timeouts[CHAIN_TO]) != 3){
|
||||
if(socksend(param, param->remsock, buf, 3, conf.timeouts[CHAIN_TO]) != 3){
|
||||
return 51;
|
||||
}
|
||||
param->statssrv64+=len;
|
||||
@ -144,7 +144,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
buf[inbuf] = pass?(unsigned char)strlen((char *)pass):0;
|
||||
if(pass)memcpy(buf+inbuf+1, pass, buf[inbuf]);
|
||||
inbuf += buf[inbuf] + 1;
|
||||
if(socksend(param->remsock, buf, inbuf, conf.timeouts[CHAIN_TO]) != inbuf){
|
||||
if(socksend(param, param->remsock, buf, inbuf, conf.timeouts[CHAIN_TO]) != inbuf){
|
||||
return 51;
|
||||
}
|
||||
param->statssrv64+=inbuf;
|
||||
@ -175,7 +175,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
}
|
||||
memcpy(buf+len, SAPORT(addr), 2);
|
||||
len += 2;
|
||||
if(socksend(param->remsock, buf, len, conf.timeouts[CHAIN_TO]) != len){
|
||||
if(socksend(param, param->remsock, buf, len, conf.timeouts[CHAIN_TO]) != len){
|
||||
return 51;
|
||||
}
|
||||
param->statssrv64+=len;
|
||||
@ -739,7 +739,7 @@ int checkACL(struct clientparam * param){
|
||||
dup = *acentry;
|
||||
res = handleredirect(param, &dup);
|
||||
if(!res) break;
|
||||
if(param->remsock != INVALID_SOCKET) so._closesocket(param->remsock);
|
||||
if(param->remsock != INVALID_SOCKET) so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
}
|
||||
return res;
|
||||
@ -1232,10 +1232,10 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
|
||||
usetcp = nservers[i].usetcp;
|
||||
*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,(struct sockaddr *)sinsl,SASIZE(sinsl))){
|
||||
so._shutdown(sock, SHUT_RDWR);
|
||||
so._closesocket(sock);
|
||||
if((sock=so._socket(so.state, SASOCK(sinsl), usetcp?SOCK_STREAM:SOCK_DGRAM, usetcp?IPPROTO_TCP:IPPROTO_UDP)) == INVALID_SOCKET) break;
|
||||
if(so._bind(so.state, sock,(struct sockaddr *)sinsl,SASIZE(sinsl))){
|
||||
so._shutdown(so.state, sock, SHUT_RDWR);
|
||||
so._closesocket(so.state, sock);
|
||||
break;
|
||||
}
|
||||
if(makeauth && !SAISNULL(&authnserver.addr)){
|
||||
@ -1245,9 +1245,9 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
|
||||
*sinsr = nservers[i].addr;
|
||||
}
|
||||
if(usetcp){
|
||||
if(connectwithpoll(sock,(struct sockaddr *)sinsr,SASIZE(sinsr),CONNECT_TO)) {
|
||||
so._shutdown(sock, SHUT_RDWR);
|
||||
so._closesocket(sock);
|
||||
if(connectwithpoll(so.state, sock,(struct sockaddr *)sinsr,SASIZE(sinsr),CONNECT_TO)) {
|
||||
so._shutdown(so.state, sock, SHUT_RDWR);
|
||||
so._closesocket(so.state, sock);
|
||||
break;
|
||||
}
|
||||
#ifdef TCP_NODELAY
|
||||
@ -1287,15 +1287,15 @@ unsigned long udpresolve(int af, unsigned char * name, unsigned char * value, un
|
||||
len+=2;
|
||||
}
|
||||
|
||||
if(socksendto(sock, (struct sockaddr *)sinsr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
|
||||
so._shutdown(sock, SHUT_RDWR);
|
||||
so._closesocket(sock);
|
||||
if(socksendto(NULL, sock, (struct sockaddr *)sinsr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
|
||||
so._shutdown(so.state, sock, SHUT_RDWR);
|
||||
so._closesocket(so.state, sock);
|
||||
continue;
|
||||
}
|
||||
if(param) param->statscli64 += len;
|
||||
len = sockrecvfrom(sock, (struct sockaddr *)sinsr, buf, 4096, conf.timeouts[DNS_TO]*1000);
|
||||
so._shutdown(sock, SHUT_RDWR);
|
||||
so._closesocket(sock);
|
||||
len = sockrecvfrom(NULL, sock, (struct sockaddr *)sinsr, buf, 4096, conf.timeouts[DNS_TO]*1000);
|
||||
so._shutdown(so.state, sock, SHUT_RDWR);
|
||||
so._closesocket(so.state, sock);
|
||||
if(len <= 13) {
|
||||
continue;
|
||||
}
|
||||
@ -1305,7 +1305,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, (struct sockaddr *)sinsr, buf+len, us-len, conf.timeouts[DNS_TO]*1000) != us-len)) {
|
||||
if(us > 4096 || us < len || (us > len && sockrecvfrom(NULL, sock, (struct sockaddr *)sinsr, buf+len, us-len, conf.timeouts[DNS_TO]*1000) != us-len)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -541,8 +541,8 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
/*
|
||||
if(auth) {
|
||||
*/
|
||||
if(sockfd >= 0) so._closesocket(sockfd);
|
||||
if ((sockfd = so._socket(SASOCK(&saremote), SOCK_DGRAM, 0)) < 0) {
|
||||
if(sockfd >= 0) so._closesocket(so.state, sockfd);
|
||||
if ((sockfd = so._socket(so.state, SASOCK(&saremote), SOCK_DGRAM, 0)) < 0) {
|
||||
return 4;
|
||||
}
|
||||
remsock = sockfd;
|
||||
@ -550,8 +550,8 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
}
|
||||
else remsock = radiuslist[loop].logsock;
|
||||
*/
|
||||
so._bind(param->remsock,(struct sockaddr *)&radiuslist[loop].localaddr,SASIZE(&radiuslist[loop].localaddr));
|
||||
len = so._sendto(remsock, (char *)&packet, total_length, 0,
|
||||
so._bind(so.state, remsock,(struct sockaddr *)&radiuslist[loop].localaddr,SASIZE(&radiuslist[loop].localaddr));
|
||||
len = so._sendto(so.state, remsock, (char *)&packet, total_length, 0,
|
||||
(struct sockaddr *)&saremote, sizeof(saremote));
|
||||
if(len != ntohs(packet.length)){
|
||||
continue;
|
||||
@ -560,13 +560,13 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = remsock;
|
||||
fds[0].events = POLLIN;
|
||||
if(so._poll(fds, 1, conf.timeouts[SINGLEBYTE_L]*1000) <= 0) {
|
||||
if(so._poll(so.state, fds, 1, conf.timeouts[SINGLEBYTE_L]*1000) <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
salen = sizeof(saremote);
|
||||
|
||||
data_len = so._recvfrom(remsock, (char *)&rpacket, sizeof(packet)-16,
|
||||
data_len = so._recvfrom(so.state, remsock, (char *)&rpacket, sizeof(packet)-16,
|
||||
0, (struct sockaddr *)&saremote, &salen);
|
||||
|
||||
|
||||
@ -648,7 +648,7 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
res = 4;
|
||||
}
|
||||
CLEANRET:
|
||||
if(sockfd >= 0) so._closesocket(sockfd);
|
||||
if(sockfd >= 0) so._closesocket(so.state, sockfd);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
185
src/common.c
185
src/common.c
@ -189,37 +189,138 @@ int
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
SOCKET WINAPI def_socket(void* state, int domain, int type, int protocol){
|
||||
return socket(domain, type, protocol);
|
||||
}
|
||||
SOCKET WINAPI def_accept(void* state, SOCKET s, struct sockaddr * addr, int * addrlen){
|
||||
return accept(s, addr, addrlen);
|
||||
}
|
||||
int WINAPI def_bind(void* state, SOCKET s, const struct sockaddr *addr, int addrlen){
|
||||
return bind(s, addr, addrlen);
|
||||
}
|
||||
int WINAPI def_listen(void* state, SOCKET s, int backlog){
|
||||
return listen(s, backlog);
|
||||
}
|
||||
int WINAPI def_connect(void* state, SOCKET s, const struct sockaddr *name, int namelen){
|
||||
return connect(s, name, namelen);
|
||||
}
|
||||
int WINAPI def_getpeername(void* state, SOCKET s, struct sockaddr * name, int * namelen){
|
||||
return getpeername(s, struct name, namelen);
|
||||
}
|
||||
int WINAPI def_getsockname(void* state, SOCKET s, struct sockaddr * name, int * namelen){
|
||||
return getsockname(s, name, namelen);
|
||||
}
|
||||
int WINAPI def_getsockopt(void* state, SOCKET s, int level, int optname, char * optval, int * optlen){
|
||||
return getsockopts(s, level, optname, optval, optlen);
|
||||
}
|
||||
int WINAPI def_poll(void* state, struct pollfd *fds, unsigned int nfds, int timeout){
|
||||
#ifndef WITH_POLL
|
||||
#ifndef WITH_WSAPOLL
|
||||
return mypoll(fds, nfds, timeout);
|
||||
#else
|
||||
return WSAPoll(fds, nfds, timeout);
|
||||
#endif
|
||||
#else
|
||||
return poll(fds, nfds, timeout);
|
||||
#endif
|
||||
}
|
||||
int WINAPI def_send(void* state, SOCKET s, const char *msg, int len, int flags){
|
||||
return send(state, s, msg, len, flags);
|
||||
}
|
||||
int WINAPI def_sendto(void* state, SOCKET s, const char *msg, int len, int flags, const struct sockaddr *to, int tolen){
|
||||
return sendto(state, s, msg, len, flags, to, tolen);
|
||||
}
|
||||
|
||||
int WINAPI def_recv(void* state, SOCKET s, char *buf, int len, int flags){
|
||||
return recv(s, buf, len, flags);
|
||||
}
|
||||
int WINAPI def_recvfrom(void* state, SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen){
|
||||
return recvfrom(s, buf, len, flags, from, fromlen);
|
||||
}
|
||||
int WINAPI def_shutdown(void* state, SOCKET s, int how){
|
||||
return shutdown(s, how);
|
||||
}
|
||||
int WINAPI def_closesocket(void* state, SOCKET s){
|
||||
return closesocket(s);
|
||||
}
|
||||
#else
|
||||
SOCKET def_socket(void* state, int domain, int type, int protocol){
|
||||
return socket(domain, type, protocol);
|
||||
}
|
||||
SOCKET def_accept(void* state, SOCKET s, struct sockaddr * addr, socklen_t* addrlen){
|
||||
return accept(s, addr, addrlen);
|
||||
}
|
||||
int def_bind(void* state, SOCKET s, const struct sockaddr *addr, socklen_t addrlen){
|
||||
return bind(s, addr, addrlen);
|
||||
}
|
||||
int def_getpeername(void* state, SOCKET s, struct sockaddr * name, socklen_t* namelen){
|
||||
return getpeername(s, name, namelen);
|
||||
}
|
||||
int def_getsockname(void* state, SOCKET s, struct sockaddr * name, socklen_t* namelen){
|
||||
return getsockname(s, name, namelen);
|
||||
}
|
||||
int def_listen(void* state, SOCKET s, int backlog){
|
||||
return listen(s, backlog);
|
||||
}
|
||||
int def_connect(void* state, SOCKET s, const struct sockaddr *name, socklen_t namelen){
|
||||
return connect(s, name, namelen);
|
||||
}
|
||||
int def_getsockopt(void* state, SOCKET s, int level, int optname, void * optval, socklen_t * optlen){
|
||||
return getsockopt(s, level, optname, optval, optlen);
|
||||
}
|
||||
int def_setsockopt(void* state, int s, int level, int optname, const void *optval, socklen_t optlen){
|
||||
return setsockopt(s, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
int def_poll(void* state, struct pollfd *fds, nfds_t nfds, int timeout){
|
||||
#ifndef WITH_POLL
|
||||
return mypoll(fds, nfds, timeout);
|
||||
#else
|
||||
return poll(fds, nfds, timeout);
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t def_send(void* state, SOCKET s, const void *msg, size_t len, int flags){
|
||||
return send(s, msg, len, flags);
|
||||
}
|
||||
ssize_t def_sendto(void* state, SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen){
|
||||
return sendto(s, msg, len, flags, to, tolen);
|
||||
}
|
||||
ssize_t def_recv(void* state, SOCKET s, void *buf, size_t len, int flags){
|
||||
return recv(s, buf, len, flags);
|
||||
}
|
||||
ssize_t def_recvfrom(void* state, SOCKET s, void * buf, size_t len, int flags, struct sockaddr * from, socklen_t* fromlen){
|
||||
return recvfrom(s, buf, len, flags, from, fromlen);
|
||||
}
|
||||
int def_shutdown(void* state, SOCKET s, int how){
|
||||
return shutdown(s, how);
|
||||
}
|
||||
int def_closesocket(void* state, SOCKET s){
|
||||
return close(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct sockfuncs so = {
|
||||
NULL,
|
||||
NULL,
|
||||
socket,
|
||||
accept,
|
||||
bind,
|
||||
listen,
|
||||
connect,
|
||||
getpeername,
|
||||
getsockname,
|
||||
getsockopt,
|
||||
setsockopt,
|
||||
#ifndef WITH_POLL
|
||||
#ifndef WITH_WSAPOLL
|
||||
mypoll,
|
||||
#else
|
||||
WSAPoll,
|
||||
#endif
|
||||
#else
|
||||
poll,
|
||||
#endif
|
||||
(void *)send,
|
||||
(void *)sendto,
|
||||
(void *)recv,
|
||||
(void *)recvfrom,
|
||||
shutdown,
|
||||
#ifdef _WIN32
|
||||
closesocket
|
||||
#else
|
||||
close
|
||||
#endif
|
||||
def_socket,
|
||||
def_accept,
|
||||
def_bind,
|
||||
def_listen,
|
||||
def_connect,
|
||||
def_getpeername,
|
||||
def_getsockname,
|
||||
def_getsockopt,
|
||||
def_setsockopt,
|
||||
def_poll,
|
||||
def_send,
|
||||
def_sendto,
|
||||
def_recv,
|
||||
def_recvfrom,
|
||||
def_shutdown,
|
||||
def_closesocket
|
||||
};
|
||||
|
||||
#ifdef _WINCE
|
||||
@ -369,7 +470,7 @@ int parseconnusername(char *username, struct clientparam *param, int extpasswd,
|
||||
}
|
||||
|
||||
|
||||
int connectwithpoll(SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to){
|
||||
int connectwithpoll(void *state, SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to){
|
||||
struct pollfd fds[1];
|
||||
#ifdef _WIN32
|
||||
unsigned long ul = 1;
|
||||
@ -377,14 +478,14 @@ int connectwithpoll(SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to){
|
||||
#else
|
||||
fcntl(sock,F_SETFL, O_NONBLOCK | fcntl(sock,F_GETFL));
|
||||
#endif
|
||||
if(so._connect(sock,sa,size)) {
|
||||
if(so._connect(state, sock,sa,size)) {
|
||||
if(errno != EAGAIN && errno != EINPROGRESS) return (13);
|
||||
}
|
||||
if(!errno) return 0;
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = sock;
|
||||
fds[0].events = POLLOUT|POLLIN;
|
||||
if(so._poll(fds, 1, to*1000) <= 0 || !(fds[0].revents & POLLOUT)) {
|
||||
if(so._poll(state, fds, 1, to*1000) <= 0 || !(fds[0].revents & POLLOUT)) {
|
||||
return (13);
|
||||
}
|
||||
return 0;
|
||||
@ -402,7 +503,7 @@ int doconnect(struct clientparam * param){
|
||||
return 0;
|
||||
if (param->remsock != INVALID_SOCKET){
|
||||
size = sizeof(param->sinsr);
|
||||
if(so._getpeername(param->remsock, (struct sockaddr *)¶m->sinsr, &size)==-1) {return (14);}
|
||||
if(so._getpeername(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsr, &size)==-1) {return (14);}
|
||||
}
|
||||
else {
|
||||
struct linger lg = {1,conf.timeouts[SINGLEBYTE_S]};
|
||||
@ -415,7 +516,7 @@ int doconnect(struct clientparam * param){
|
||||
memcpy(SAADDR(¶m->sinsr), SAADDR(¶m->req), SAADDRLEN(¶m->req));
|
||||
}
|
||||
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);}
|
||||
if ((param->remsock=so._socket(param->sostate, SASOCK(¶m->sinsr), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {return (11);}
|
||||
if(SAISNULL(¶m->sinsl)){
|
||||
#ifndef NOIPV6
|
||||
if(*SAFAMILY(¶m->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6;
|
||||
@ -426,48 +527,48 @@ int doconnect(struct clientparam * param){
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
setopts(param->remsock, param->srv->srvsockopts);
|
||||
|
||||
so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
so._setsockopt(param->sostate, 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, (char *)&opt, sizeof(int));
|
||||
so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
so._setsockopt(param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
|
||||
so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined SO_BINDTODEVICE
|
||||
if(param->srv->obindtodevice) {
|
||||
if(so._setsockopt(param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1))
|
||||
if(so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1))
|
||||
return 12;
|
||||
}
|
||||
#elif defined IP_BOUND_IF
|
||||
if(param->srv->obindtodevice) {
|
||||
int idx;
|
||||
idx = if_nametoindex(param->srv->obindtodevice);
|
||||
if(!idx || (*SAFAMILY(¶m->sinsl) == AF_INET && so._setsockopt(param->remsock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))))
|
||||
if(!idx || (*SAFAMILY(¶m->sinsl) == AF_INET && so._setsockopt(param->sostate, param->remsock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))))
|
||||
return 12;
|
||||
#ifndef NOIPV6
|
||||
if(*SAFAMILY(¶m->sinsl) == AF_INET6 && so._setsockopt(param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 12;
|
||||
if(*SAFAMILY(¶m->sinsl) == AF_INET6 && so._setsockopt(param->sostate, param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 12;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if(so._bind(param->remsock, (struct sockaddr*)¶m->sinsl, SASIZE(¶m->sinsl))==-1) {
|
||||
if(so._bind(param->sostate, param->remsock, (struct sockaddr*)¶m->sinsl, SASIZE(¶m->sinsl))==-1) {
|
||||
return 12;
|
||||
}
|
||||
|
||||
if(param->operation >= 256 || (param->operation & CONNECT)){
|
||||
if(connectwithpoll(param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr),CONNECT_TO)) {
|
||||
if(connectwithpoll(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr),CONNECT_TO)) {
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
size = sizeof(param->sinsl);
|
||||
if(so._getsockname(param->remsock, (struct sockaddr *)¶m->sinsl, &size)==-1) {return (15);}
|
||||
if(so._getsockname(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsl, &size)==-1) {return (15);}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
22
src/dnspr.c
22
src/dnspr.c
@ -39,16 +39,16 @@ void * dnsprchild(struct clientparam* param) {
|
||||
}
|
||||
buf = bbuf+2;
|
||||
size = sizeof(param->sincr);
|
||||
i = so._recvfrom(param->srv->srvsock, (char *)buf, BUFSIZE, 0, (struct sockaddr *)¶m->sincr, &size);
|
||||
i = so._recvfrom(param->sostate, 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
|
||||
if((param->clisock=so._socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
if((param->clisock=so._socket(param->sostate, AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
RETURN(818);
|
||||
}
|
||||
ioctlsocket(param->clisock, FIONBIO, &ul);
|
||||
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))) {
|
||||
if(so._setsockopt(param->sostate, param->clisock, SOL_SOCKET, SO_REUSEADDR, (char *)&ul, sizeof(int))) {RETURN(820);};
|
||||
if(so._bind(param->sostate, param->clisock,(struct sockaddr *)¶m->sincl,SASIZE(¶m->sincl))) {
|
||||
RETURN(822);
|
||||
}
|
||||
|
||||
@ -130,17 +130,17 @@ void * dnsprchild(struct clientparam* param) {
|
||||
else ip = 0;
|
||||
}
|
||||
if(!ip && numservers){
|
||||
if((param->remsock=so._socket(SASOCK(&nservers[0].addr), nservers[0].usetcp? SOCK_STREAM:SOCK_DGRAM, nservers[0].usetcp?IPPROTO_TCP:IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
if((param->remsock=so._socket(param->sostate, SASOCK(&nservers[0].addr), nservers[0].usetcp? SOCK_STREAM:SOCK_DGRAM, nservers[0].usetcp?IPPROTO_TCP:IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
RETURN(818);
|
||||
}
|
||||
memset(¶m->sinsl, 0, sizeof(param->sinsl));
|
||||
*SAFAMILY(¶m->sinsl) = *SAFAMILY(&nservers[0].addr);
|
||||
if(so._bind(param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
if(so._bind(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
RETURN(819);
|
||||
}
|
||||
param->sinsr = nservers[0].addr;
|
||||
if(nservers[0].usetcp) {
|
||||
if(connectwithpoll(param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr),CONNECT_TO)) RETURN(830);
|
||||
if(connectwithpoll(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr),CONNECT_TO)) RETURN(830);
|
||||
buf-=2;
|
||||
*(unsigned short*)buf = htons(i);
|
||||
i+=2;
|
||||
@ -153,12 +153,12 @@ void * dnsprchild(struct clientparam* param) {
|
||||
#endif
|
||||
}
|
||||
|
||||
if(socksendto(param->remsock, (struct sockaddr *)¶m->sinsr, buf, i, conf.timeouts[SINGLEBYTE_L]*1000) != i){
|
||||
if(socksendto(param, param->remsock, (struct sockaddr *)¶m->sinsr, buf, i, conf.timeouts[SINGLEBYTE_L]*1000) != i){
|
||||
RETURN(820);
|
||||
}
|
||||
param->statscli64 += i;
|
||||
param->nwrites++;
|
||||
len = sockrecvfrom(param->remsock, (struct sockaddr *)¶m->sinsr, buf, BUFSIZE, conf.timeouts[DNS_TO]*1000);
|
||||
len = sockrecvfrom(param, param->remsock, (struct sockaddr *)¶m->sinsr, buf, BUFSIZE, conf.timeouts[DNS_TO]*1000);
|
||||
if(len <= 13) {
|
||||
RETURN(821);
|
||||
}
|
||||
@ -174,7 +174,7 @@ void * dnsprchild(struct clientparam* param) {
|
||||
if(len != us) RETURN(832);
|
||||
}
|
||||
if(buf[6] || buf[7]){
|
||||
if(socksendto(param->clisock, (struct sockaddr *)¶m->sincr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
|
||||
if(socksendto(param, param->clisock, (struct sockaddr *)¶m->sincr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
|
||||
RETURN(822);
|
||||
}
|
||||
RETURN(0);
|
||||
@ -185,7 +185,7 @@ void * dnsprchild(struct clientparam* param) {
|
||||
buf[2] = 0x85;
|
||||
buf[3] = 0x83;
|
||||
}
|
||||
res = socksendto(param->clisock, (struct sockaddr *)¶m->sincr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000);
|
||||
res = socksendto(param, param->clisock, (struct sockaddr *)¶m->sincr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000);
|
||||
if(res != len){RETURN(819);}
|
||||
if(!ip) {RETURN(888);}
|
||||
|
||||
|
28
src/ftp.c
28
src/ftp.c
@ -29,7 +29,7 @@ int ftplogin(struct clientparam *param, char *nbuf, int *innbuf) {
|
||||
return 702;
|
||||
}
|
||||
sprintf(buf, "USER %.128s\r\n", param->extusername?param->extusername:(unsigned char *)"anonymous");
|
||||
if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
if((int)socksend(param, param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
return 703;
|
||||
}
|
||||
param->statscli64 += (int)strlen(buf);
|
||||
@ -46,7 +46,7 @@ int ftplogin(struct clientparam *param, char *nbuf, int *innbuf) {
|
||||
param->extpassword:(unsigned char *)"")
|
||||
:(unsigned char *)"3proxy@");
|
||||
res = (int)strlen(buf);
|
||||
if((int)socksend(param->remsock, (unsigned char *)buf, res, conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
if((int)socksend(param, param->remsock, (unsigned char *)buf, res, conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
return 705;
|
||||
}
|
||||
param->statscli64 += res;
|
||||
@ -77,7 +77,7 @@ int ftpcd(struct clientparam *param, unsigned char* path, char *nbuf, int *innbu
|
||||
int inbuf = 0;
|
||||
|
||||
sprintf(buf, "CWD %.512s\r\n", path);
|
||||
if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
if((int)socksend(param, param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
return 711;
|
||||
}
|
||||
param->statscli64 += (int)strlen(buf);
|
||||
@ -110,7 +110,7 @@ int ftpres(struct clientparam *param, unsigned char * buf, int l){
|
||||
int ftpsyst(struct clientparam *param, unsigned char *buf, unsigned len){
|
||||
int i;
|
||||
|
||||
if(socksend(param->remsock, (unsigned char *)"SYST\r\n", 6, conf.timeouts[STRING_S]) != 6){
|
||||
if(socksend(param, param->remsock, (unsigned char *)"SYST\r\n", 6, conf.timeouts[STRING_S]) != 6){
|
||||
return 721;
|
||||
}
|
||||
param->statscli64 += 6;
|
||||
@ -129,7 +129,7 @@ int ftppwd(struct clientparam *param, unsigned char *buf, unsigned len){
|
||||
int i;
|
||||
char *b, *e;
|
||||
|
||||
if(socksend(param->remsock, (unsigned char *)"PWD\r\n", 5, conf.timeouts[STRING_S]) != 5){
|
||||
if(socksend(param, param->remsock, (unsigned char *)"PWD\r\n", 5, conf.timeouts[STRING_S]) != 5){
|
||||
return 731;
|
||||
}
|
||||
param->statscli64 += 5;
|
||||
@ -154,7 +154,7 @@ int ftptype(struct clientparam *param, unsigned char* f_type){
|
||||
int i;
|
||||
|
||||
sprintf(buf, "TYPE %.512s\r\n", f_type);
|
||||
if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
if((int)socksend(param, param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
return 741;
|
||||
}
|
||||
param->statscli64 += (int)strlen(buf);
|
||||
@ -176,7 +176,7 @@ SOCKET ftpdata(struct clientparam *param){
|
||||
unsigned short b5, b6;
|
||||
SASIZETYPE sasize;
|
||||
|
||||
if(socksend(param->remsock, (unsigned char *)"PASV\r\n", 6, conf.timeouts[STRING_S]) != 6){
|
||||
if(socksend(param, param->remsock, (unsigned char *)"PASV\r\n", 6, conf.timeouts[STRING_S]) != 6){
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
param->statscli64 += 6;
|
||||
@ -189,9 +189,9 @@ SOCKET ftpdata(struct clientparam *param){
|
||||
if(!(sb = strchr(buf+4, '(')) || !(se= strchr(sb, ')'))) return INVALID_SOCKET;
|
||||
if(sscanf(sb+1, "%lu,%lu,%lu,%lu,%hu,%hu", &b1, &b2, &b3, &b4, &b5, &b6)!=6) return INVALID_SOCKET;
|
||||
sasize = sizeof(param->sinsl);
|
||||
if(so._getsockname(param->remsock, (struct sockaddr *)¶m->sinsl, &sasize)){return INVALID_SOCKET;}
|
||||
if(so._getsockname(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsl, &sasize)){return INVALID_SOCKET;}
|
||||
sasize = sizeof(param->sinsr);
|
||||
if(so._getpeername(param->remsock, (struct sockaddr *)¶m->sinsr, &sasize)){return INVALID_SOCKET;}
|
||||
if(so._getpeername(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsr, &sasize)){return INVALID_SOCKET;}
|
||||
rem = param->remsock;
|
||||
param->remsock = INVALID_SOCKET;
|
||||
param->req = param->sinsr;
|
||||
@ -201,7 +201,7 @@ SOCKET ftpdata(struct clientparam *param){
|
||||
param->operation = FTP_DATA;
|
||||
if((param->res = (*param->srv->authfunc)(param))) {
|
||||
if(param->remsock != INVALID_SOCKET) {
|
||||
so._closesocket(param->remsock);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
}
|
||||
memset(¶m->sinsl, 0, sizeof(param->sinsl));
|
||||
@ -227,8 +227,8 @@ SOCKET ftpcommand(struct clientparam *param, unsigned char * command, unsigned c
|
||||
sprintf(buf, "%.15s%s%.512s\r\n", command, arg?
|
||||
(unsigned char *)" ":(unsigned char *)"",
|
||||
arg?arg:(unsigned char *)"");
|
||||
if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
so._closesocket(s);
|
||||
if((int)socksend(param, param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){
|
||||
so._closesocket(param->sostate, s);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
param->statscli64 += (int)strlen(buf);
|
||||
@ -236,11 +236,11 @@ SOCKET ftpcommand(struct clientparam *param, unsigned char * command, unsigned c
|
||||
while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){
|
||||
}
|
||||
if(i < 3) {
|
||||
so._closesocket(s);
|
||||
so._closesocket(param->sostate, s);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
if(buf[0] != '1') {
|
||||
so._closesocket(s);
|
||||
so._closesocket(param->sostate, s);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
return s;
|
||||
|
90
src/ftppr.c
90
src/ftppr.c
@ -29,7 +29,7 @@ void * ftpprchild(struct clientparam* param) {
|
||||
param->operation = CONNECT;
|
||||
lg.l_onoff = 1;
|
||||
lg.l_linger = conf.timeouts[STRING_L];;
|
||||
if(socksend(param->ctrlsock, (unsigned char *)"220 Ready\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (801);}
|
||||
if(socksend(param, param->ctrlsock, (unsigned char *)"220 Ready\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (801);}
|
||||
for(;;){
|
||||
i = sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 10, '\n', conf.timeouts[CONNECTION_S]);
|
||||
if(!i) {
|
||||
@ -44,13 +44,13 @@ void * ftpprchild(struct clientparam* param) {
|
||||
if (!strncasecmp((char *)buf, "OPEN ", 5)){
|
||||
if(parsehostname((char *)buf+5, param, 21)){RETURN(803);}
|
||||
if(param->remsock != INVALID_SOCKET) {
|
||||
so._shutdown(param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->remsock);
|
||||
so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
}
|
||||
if((res = (*param->srv->authfunc)(param))) {RETURN(res);}
|
||||
param->ctrlsocksrv = param->remsock;
|
||||
if(socksend(param->ctrlsock, (unsigned char *)"220 Ready\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (801);}
|
||||
if(socksend(param, param->ctrlsock, (unsigned char *)"220 Ready\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (801);}
|
||||
status = 1;
|
||||
}
|
||||
else if (!strncasecmp((char *)buf, "USER ", 5)){
|
||||
@ -59,7 +59,7 @@ void * ftpprchild(struct clientparam* param) {
|
||||
if((res = (*param->srv->authfunc)(param))) {RETURN(res);}
|
||||
param->ctrlsocksrv = param->remsock;
|
||||
}
|
||||
if(socksend(param->ctrlsock, (unsigned char *)"331 ok\r\n", 8, conf.timeouts[STRING_S])!=8) {RETURN (807);}
|
||||
if(socksend(param, param->ctrlsock, (unsigned char *)"331 ok\r\n", 8, conf.timeouts[STRING_S])!=8) {RETURN (807);}
|
||||
status = 2;
|
||||
|
||||
}
|
||||
@ -68,7 +68,7 @@ void * ftpprchild(struct clientparam* param) {
|
||||
inbuf = BUFSIZE;
|
||||
res = ftplogin(param, (char *)buf, &inbuf);
|
||||
param->res = res;
|
||||
if(inbuf && inbuf != BUFSIZE && socksend(param->ctrlsock, buf, inbuf, conf.timeouts[STRING_S])!=inbuf) {RETURN (807);}
|
||||
if(inbuf && inbuf != BUFSIZE && socksend(param, param->ctrlsock, buf, inbuf, conf.timeouts[STRING_S])!=inbuf) {RETURN (807);}
|
||||
if(!res) status = 3;
|
||||
sprintf((char *)buf, "%.128s@%.128s%c%hu", param->extusername, param->hostname, (ntohs(*SAPORT(¶m->sinsr))==21)?0:':', ntohs(*SAPORT(¶m->sinsr)));
|
||||
req = mystrdup((char *)buf);
|
||||
@ -105,27 +105,27 @@ void * ftpprchild(struct clientparam* param) {
|
||||
}
|
||||
#endif
|
||||
if(sc != INVALID_SOCKET) {
|
||||
so._shutdown(sc, SHUT_RDWR);
|
||||
so._closesocket(sc);
|
||||
so._shutdown(param->sostate, sc, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, sc);
|
||||
sc = INVALID_SOCKET;
|
||||
}
|
||||
if(ss != INVALID_SOCKET) {
|
||||
so._shutdown(ss, SHUT_RDWR);
|
||||
so._closesocket(ss);
|
||||
so._shutdown(param->sostate, ss, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, ss);
|
||||
ss = INVALID_SOCKET;
|
||||
}
|
||||
if(clidatasock != INVALID_SOCKET) {
|
||||
so._shutdown(clidatasock, SHUT_RDWR);
|
||||
so._closesocket(clidatasock);
|
||||
so._shutdown(param->sostate, clidatasock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, clidatasock);
|
||||
clidatasock = INVALID_SOCKET;
|
||||
}
|
||||
if ((clidatasock=socket(SASOCK(¶m->sincl), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {RETURN(821);}
|
||||
*SAPORT(¶m->sincl) = 0;
|
||||
if(so._bind(clidatasock, (struct sockaddr *)¶m->sincl, SASIZE(¶m->sincl))){RETURN(822);}
|
||||
if(so._bind(param->sostate, clidatasock, (struct sockaddr *)¶m->sincl, SASIZE(¶m->sincl))){RETURN(822);}
|
||||
if (pasv) {
|
||||
if(so._listen(clidatasock, 1)) {RETURN(823);}
|
||||
if(so._listen(param->sostate, clidatasock, 1)) {RETURN(823);}
|
||||
sasize = sizeof(param->sincl);
|
||||
if(so._getsockname(clidatasock, (struct sockaddr *)¶m->sincl, &sasize)){RETURN(824);}
|
||||
if(so._getsockname(param->sostate, clidatasock, (struct sockaddr *)¶m->sincl, &sasize)){RETURN(824);}
|
||||
if(pasv == 1){
|
||||
if(*SAFAMILY(¶m->sincl) == AF_INET)
|
||||
sprintf((char *)buf, "227 OK (%u,%u,%u,%u,%u,%u)\r\n",
|
||||
@ -153,8 +153,8 @@ void * ftpprchild(struct clientparam* param) {
|
||||
|
||||
if(sscanf((char *)buf+5, "%lu,%lu,%lu,%lu,%hu,%hu", &b1, &b2, &b3, &b4, &b5, &b6)!=6) {RETURN(828);}
|
||||
*SAPORT(¶m->sincr) = htons((unsigned short)((b5<<8)^b6));
|
||||
if(connectwithpoll(clidatasock, (struct sockaddr *)¶m->sincr, SASIZE(¶m->sincr),CONNECT_TO)) {
|
||||
so._closesocket(clidatasock);
|
||||
if(connectwithpoll(param->sostate, clidatasock, (struct sockaddr *)¶m->sincr, SASIZE(¶m->sincr),CONNECT_TO)) {
|
||||
so._closesocket(param->sostate, clidatasock);
|
||||
clidatasock = INVALID_SOCKET;
|
||||
RETURN(826);
|
||||
}
|
||||
@ -173,7 +173,7 @@ void * ftpprchild(struct clientparam* param) {
|
||||
if(action != PASS) RETURN(879);
|
||||
}
|
||||
#endif
|
||||
if(socksend(param->ctrlsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S])!=(int)strlen((char *)buf)) {RETURN (825);}
|
||||
if(socksend(param, param->ctrlsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S])!=(int)strlen((char *)buf)) {RETURN (825);}
|
||||
status = 4;
|
||||
}
|
||||
else if (status == 4 && (
|
||||
@ -208,15 +208,15 @@ void * ftpprchild(struct clientparam* param) {
|
||||
fds.fd = clidatasock;
|
||||
fds.events = POLLIN;
|
||||
|
||||
res = so._poll (&fds, 1, conf.timeouts[STRING_L]*1000);
|
||||
res = so._poll (param->sostate, &fds, 1, conf.timeouts[STRING_L]*1000);
|
||||
if(res != 1) {
|
||||
RETURN(857);
|
||||
}
|
||||
sasize = sizeof(param->sincr);
|
||||
ss = so._accept(clidatasock, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
ss = so._accept(param->sostate, clidatasock, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
if (ss == INVALID_SOCKET) { RETURN (858);}
|
||||
so._shutdown(clidatasock, SHUT_RDWR);
|
||||
so._closesocket(clidatasock);
|
||||
so._shutdown(param->sostate, clidatasock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, clidatasock);
|
||||
clidatasock = ss;
|
||||
ss = INVALID_SOCKET;
|
||||
}
|
||||
@ -226,20 +226,20 @@ void * ftpprchild(struct clientparam* param) {
|
||||
status = 3;
|
||||
ss = ftpcommand(param, buf, arg? buf+5 : NULL);
|
||||
if (ss == INVALID_SOCKET) {
|
||||
so._shutdown(clidatasock, SHUT_RDWR);
|
||||
so._closesocket(clidatasock);
|
||||
so._shutdown(param->sostate, clidatasock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, clidatasock);
|
||||
clidatasock = INVALID_SOCKET;
|
||||
|
||||
if(socksend(param->ctrlsock, (unsigned char *)"550 err\r\n", 9, conf.timeouts[STRING_S])!=9) {RETURN (831);}
|
||||
if(socksend(param, param->ctrlsock, (unsigned char *)"550 err\r\n", 9, conf.timeouts[STRING_S])!=9) {RETURN (831);}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(socksend(param->ctrlsock, (unsigned char *)"125 data\r\n", 10, conf.timeouts[STRING_S]) != 10) {
|
||||
if(socksend(param, param->ctrlsock, (unsigned char *)"125 data\r\n", 10, conf.timeouts[STRING_S]) != 10) {
|
||||
param->remsock = INVALID_SOCKET;
|
||||
RETURN (832);
|
||||
}
|
||||
if(param->srvoffset < param->srvinbuf)while((i = sockgetlinebuf(param, SERVER, buf, BUFSIZE, '\n', 0)) > 3){
|
||||
if(socksend(param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN(833);}
|
||||
if(socksend(param, param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN(833);}
|
||||
if(isnumber(*buf) && buf[3] != '-') {
|
||||
ressent = 1;
|
||||
break;
|
||||
@ -247,17 +247,17 @@ void * ftpprchild(struct clientparam* param) {
|
||||
}
|
||||
sc = param->remsock;
|
||||
param->remsock = ss;
|
||||
so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
so._setsockopt(clidatasock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
so._setsockopt(param->sostate, clidatasock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
param->clisock = clidatasock;
|
||||
res = mapsocket(param, conf.timeouts[CONNECTION_S]);
|
||||
if(param->remsock != INVALID_SOCKET) {
|
||||
so._shutdown (param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->remsock);
|
||||
so._shutdown (param->sostate, param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
}
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
so._shutdown (param->clisock, SHUT_RDWR);
|
||||
so._closesocket(param->clisock);
|
||||
so._shutdown (param->sostate, param->clisock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->clisock);
|
||||
}
|
||||
param->clisock = param->ctrlsock;
|
||||
param->remsock = sc;
|
||||
@ -266,7 +266,7 @@ void * ftpprchild(struct clientparam* param) {
|
||||
clidatasock = INVALID_SOCKET;
|
||||
if(!ressent){
|
||||
while((i = sockgetlinebuf(param, SERVER, buf, BUFSIZE, '\n', conf.timeouts[STRING_L])) > 3){
|
||||
if(socksend(param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN(833);}
|
||||
if(socksend(param, param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN(833);}
|
||||
if(isnumber(*buf) && buf[3] != '-') break;
|
||||
}
|
||||
if(i < 3) {RETURN(834);}
|
||||
@ -274,7 +274,7 @@ void * ftpprchild(struct clientparam* param) {
|
||||
}
|
||||
else {
|
||||
if(status < 3) {
|
||||
if(socksend(param->remsock, (unsigned char *)"530 login\r\n", 11, conf.timeouts[STRING_S])!=1) {RETURN (810);}
|
||||
if(socksend(param, param->remsock, (unsigned char *)"530 login\r\n", 11, conf.timeouts[STRING_S])!=1) {RETURN (810);}
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp((char *)buf, "QUIT", 4)) status = 5;
|
||||
@ -282,18 +282,18 @@ void * ftpprchild(struct clientparam* param) {
|
||||
i = (int)strlen((char *)buf);
|
||||
buf[i++] = '\r';
|
||||
buf[i++] = '\n';
|
||||
if(socksend(param->remsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (811);}
|
||||
if(socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (811);}
|
||||
param->statscli64+=(i);
|
||||
param->nwrites++;
|
||||
while((i = sockgetlinebuf(param, SERVER, buf, BUFSIZE, '\n', conf.timeouts[STRING_L])) > 0){
|
||||
if(socksend(param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (812);}
|
||||
if(socksend(param, param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (812);}
|
||||
if(i > 4 && isnumber(*buf) && buf[3] != '-') break;
|
||||
}
|
||||
if(status == 5) {RETURN (0);}
|
||||
if(i < 3) {RETURN (813);}
|
||||
}
|
||||
sasize = sizeof(param->sincr);
|
||||
if(so._getpeername(param->ctrlsock, (struct sockaddr *)¶m->sincr, &sasize)){RETURN(819);}
|
||||
if(so._getpeername(param->sostate, param->ctrlsock, (struct sockaddr *)¶m->sincr, &sasize)){RETURN(819);}
|
||||
if(req && (param->statscli64 || param->statssrv64)){
|
||||
dolog(param, (unsigned char *)req);
|
||||
}
|
||||
@ -302,19 +302,19 @@ void * ftpprchild(struct clientparam* param) {
|
||||
CLEANRET:
|
||||
|
||||
if(sc != INVALID_SOCKET) {
|
||||
so._shutdown(sc, SHUT_RDWR);
|
||||
so._closesocket(sc);
|
||||
so._shutdown(param->sostate, sc, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, sc);
|
||||
}
|
||||
if(ss != INVALID_SOCKET) {
|
||||
so._shutdown(ss, SHUT_RDWR);
|
||||
so._closesocket(ss);
|
||||
so._shutdown(param->sostate, ss, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, ss);
|
||||
}
|
||||
if(clidatasock != INVALID_SOCKET) {
|
||||
so._shutdown(clidatasock, SHUT_RDWR);
|
||||
so._closesocket(clidatasock);
|
||||
so._shutdown(param->sostate, clidatasock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, clidatasock);
|
||||
}
|
||||
sasize = sizeof(param->sincr);
|
||||
so._getpeername(param->ctrlsock, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
so._getpeername(param->sostate, param->ctrlsock, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
if(param->res != 0 || param->statscli64 || param->statssrv64 ){
|
||||
dolog(param, (unsigned char *)((req && (param->res > 802))? req:NULL));
|
||||
}
|
||||
|
@ -108,9 +108,9 @@ int delSSL(SOCKET s){
|
||||
struct sockfuncs sso;
|
||||
|
||||
#ifdef _WIN32
|
||||
static int WINAPI ssl_send(SOCKET s, const void *msg, int len, int flags){
|
||||
static int WINAPI ssl_send(void *state, SOCKET s, const void *msg, int len, int flags){
|
||||
#else
|
||||
static ssize_t ssl_send(SOCKET s, const void *msg, size_t len, int flags){
|
||||
static ssize_t ssl_send(void *state, SOCKET s, const void *msg, size_t len, int flags){
|
||||
#endif
|
||||
struct SSLqueue *sslq;
|
||||
|
||||
@ -127,14 +127,14 @@ static ssize_t ssl_send(SOCKET s, const void *msg, size_t len, int flags){
|
||||
return res;
|
||||
}
|
||||
|
||||
return sso._send(s, msg, len, flags);
|
||||
return sso._send(sso.state, s, msg, len, flags);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
static int WINAPI ssl_sendto(SOCKET s, const void *msg, int len, int flags, const struct sockaddr *to, int tolen){
|
||||
static int WINAPI ssl_sendto(void *state, SOCKET s, const void *msg, int len, int flags, const struct sockaddr *to, int tolen){
|
||||
#else
|
||||
static ssize_t ssl_sendto(SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen){
|
||||
static ssize_t ssl_sendto(void *state, SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen){
|
||||
#endif
|
||||
struct SSLqueue *sslq;
|
||||
|
||||
@ -151,13 +151,13 @@ static ssize_t ssl_sendto(SOCKET s, const void *msg, size_t len, int flags, cons
|
||||
return res;
|
||||
}
|
||||
|
||||
return sso._sendto(s, msg, len, flags, to, tolen);
|
||||
return sso._sendto(sso.state, s, msg, len, flags, to, tolen);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static int WINAPI ssl_recvfrom(SOCKET s, void *msg, int len, int flags, struct sockaddr *from, int *fromlen){
|
||||
static int WINAPI ssl_recvfrom(void *state, SOCKET s, void *msg, int len, int flags, struct sockaddr *from, int *fromlen){
|
||||
#else
|
||||
static ssize_t ssl_recvfrom(SOCKET s, void *msg, size_t len, int flags, struct sockaddr *from, SASIZETYPE *fromlen){
|
||||
static ssize_t ssl_recvfrom(void *state, SOCKET s, void *msg, size_t len, int flags, struct sockaddr *from, SASIZETYPE *fromlen){
|
||||
#endif
|
||||
struct SSLqueue *sslq;
|
||||
|
||||
@ -173,13 +173,13 @@ static ssize_t ssl_recvfrom(SOCKET s, void *msg, size_t len, int flags, struct
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return sso._recvfrom(s, msg, len, flags, from, fromlen);
|
||||
return sso._recvfrom(sso.state, s, msg, len, flags, from, fromlen);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static int WINAPI ssl_recv(SOCKET s, void *msg, int len, int flags){
|
||||
static int WINAPI ssl_recv(void *state, SOCKET s, void *msg, int len, int flags){
|
||||
#else
|
||||
static ssize_t ssl_recv(SOCKET s, void *msg, size_t len, int flags){
|
||||
static ssize_t ssl_recv(void *state, SOCKET s, void *msg, size_t len, int flags){
|
||||
#endif
|
||||
struct SSLqueue *sslq;
|
||||
|
||||
@ -196,15 +196,15 @@ static ssize_t ssl_recv(SOCKET s, void *msg, size_t len, int flags){
|
||||
return res;
|
||||
}
|
||||
|
||||
return sso._recv(s, msg, len, flags);
|
||||
return sso._recv(sso.state, s, msg, len, flags);
|
||||
}
|
||||
|
||||
static int WINAPI ssl_closesocket(SOCKET s){
|
||||
static int WINAPI ssl_closesocket(void *state, SOCKET s){
|
||||
delSSL(s);
|
||||
return sso._closesocket(s);
|
||||
return sso._closesocket(sso.state, s);
|
||||
}
|
||||
|
||||
static int WINAPI ssl_poll(struct pollfd *fds, unsigned int nfds, int timeout){
|
||||
static int WINAPI ssl_poll(void *state, struct pollfd *fds, unsigned int nfds, int timeout){
|
||||
struct SSLqueue *sslq = NULL;
|
||||
unsigned int i;
|
||||
int ret = 0;
|
||||
@ -217,7 +217,7 @@ static int WINAPI ssl_poll(struct pollfd *fds, unsigned int nfds, int timeout){
|
||||
}
|
||||
if(ret) return ret;
|
||||
|
||||
ret = sso._poll(fds, nfds, timeout);
|
||||
ret = sso._poll(state, fds, nfds, timeout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
14
src/pop3p.c
14
src/pop3p.c
@ -15,14 +15,14 @@ void * pop3pchild(struct clientparam* param) {
|
||||
unsigned char buf[320];
|
||||
unsigned char *se;
|
||||
|
||||
if(socksend(param->clisock, (unsigned char *)"+OK Proxy\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (611);}
|
||||
if(socksend(param, param->clisock, (unsigned char *)"+OK Proxy\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (611);}
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
while(i > 4 && strncasecmp((char *)buf, "USER", 4)){
|
||||
if(!strncasecmp((char *)buf, "QUIT", 4)){
|
||||
socksend(param->clisock, (unsigned char *)"+OK\r\n", 5,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"+OK\r\n", 5,conf.timeouts[STRING_S]);
|
||||
RETURN(0);
|
||||
}
|
||||
socksend(param->clisock, (unsigned char *)"-ERR need USER first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"-ERR need USER first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
}
|
||||
if(i<6) {RETURN(612);}
|
||||
@ -38,9 +38,9 @@ void * pop3pchild(struct clientparam* param) {
|
||||
if( i < 3 ) {RETURN(621);}
|
||||
buf[i] = 0;
|
||||
if(strncasecmp((char *)buf, "+OK", 3)||!strncasecmp((char *)buf+4, "PROXY", 5)){RETURN(622);}
|
||||
if( socksend(param->remsock, (unsigned char *)"USER ", 5, conf.timeouts[STRING_S])!= 5 ||
|
||||
socksend(param->remsock, param->extusername, (int)strlen((char *)param->extusername), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2)
|
||||
if( socksend(param, param->remsock, (unsigned char *)"USER ", 5, conf.timeouts[STRING_S])!= 5 ||
|
||||
socksend(param, param->remsock, param->extusername, (int)strlen((char *)param->extusername), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2)
|
||||
{RETURN(623);}
|
||||
param->statscli64 += (uint64_t)(strlen((char *)param->extusername) + 7);
|
||||
param->nwrites++;
|
||||
@ -53,7 +53,7 @@ CLEANRET:
|
||||
}
|
||||
else dolog(param, NULL);
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 611 && param->res <700)) socksend(param->clisock, (unsigned char *)"-ERR\r\n", 6,conf.timeouts[STRING_S]);
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 611 && param->res <700)) socksend(param, param->clisock, (unsigned char *)"-ERR\r\n", 6,conf.timeouts[STRING_S]);
|
||||
}
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
|
78
src/proxy.c
78
src/proxy.c
@ -253,15 +253,15 @@ for(;;){
|
||||
fds[0].events = POLLIN;
|
||||
fds[1].fd = param->remsock;
|
||||
fds[1].events = POLLIN;
|
||||
res = so._poll(fds, 2, conf.timeouts[STRING_S]*1000);
|
||||
res = so._poll(param->sostate, fds, 2, conf.timeouts[STRING_S]*1000);
|
||||
if(res<=0) {
|
||||
RETURN(555);
|
||||
}
|
||||
if((fds[1].revents & (POLLIN|POLLHUP|POLLERR|POLLNVAL))) {
|
||||
if(param->transparent || (!param->redirected && param->redirtype == R_HTTP)) RETURN(555);
|
||||
ckeepalive = 0;
|
||||
so._shutdown(param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->remsock);
|
||||
so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
param->redirected = 0;
|
||||
param->redirtype = 0;
|
||||
@ -282,8 +282,8 @@ for(;;){
|
||||
if(!param->transparent && !param->srv->transparent && (i<=prefix || strncasecmp((char *)buf, (char *)req, prefix))){
|
||||
ckeepalive = 0;
|
||||
if(param->remsock != INVALID_SOCKET){
|
||||
so._shutdown(param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->remsock);
|
||||
so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
}
|
||||
param->remsock = INVALID_SOCKET;
|
||||
param->redirected = 0;
|
||||
@ -408,7 +408,7 @@ for(;;){
|
||||
memcpy(buf, proxy_stringtable[13], i);
|
||||
genchallenge(param, (char *)param->password, (char *)buf + i);
|
||||
memcpy(buf + strlen((char *)buf), "\r\n\r\n", 5);
|
||||
socksend(param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
ckeepalive = keepalive = 1;
|
||||
goto REQUESTEND;
|
||||
}
|
||||
@ -448,7 +448,7 @@ for(;;){
|
||||
}
|
||||
if( i > 11 && !strncasecmp((char *)(buf+inbuf), "Expect: 100", 11)){
|
||||
keepalive = 1;
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[17], (int)strlen(proxy_stringtable[17]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[17], (int)strlen(proxy_stringtable[17]), conf.timeouts[STRING_S]);
|
||||
continue;
|
||||
}
|
||||
if(param->transparent && i > 6 && !strncasecmp((char *)buf + inbuf, "Host:", 5)){
|
||||
@ -530,7 +530,7 @@ for(;;){
|
||||
if(param->srv->needuser > 1 && !param->username) {RETURN(4);}
|
||||
if((res = (*param->srv->authfunc)(param))) {
|
||||
if (res <= 10 || haveconnection || param->transparent) RETURN(res);
|
||||
so._closesocket(param->remsock);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
param->redirected = 0;
|
||||
param->redirtype = 0;
|
||||
@ -555,7 +555,7 @@ for(;;){
|
||||
param->nolongdatfilter = 0;
|
||||
|
||||
if(isconnect && param->redirtype != R_HTTP) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[8], (int)strlen(proxy_stringtable[8]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[8], (int)strlen(proxy_stringtable[8]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
|
||||
if (param->npredatfilters){
|
||||
@ -644,13 +644,13 @@ for(;;){
|
||||
}
|
||||
if(ftps == INVALID_SOCKET){RETURN(780);}
|
||||
if(!mode){
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[8], (int)strlen(proxy_stringtable[8]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[8], (int)strlen(proxy_stringtable[8]), conf.timeouts[STRING_S]);
|
||||
s = param->remsock;
|
||||
param->remsock = ftps;
|
||||
if((param->operation == FTP_PUT) && (contentlength64 > 0)) param->waitclient64 = contentlength64;
|
||||
res = mapsocket(param, conf.timeouts[CONNECTION_L]);
|
||||
if (res == 99) res = 0;
|
||||
so._closesocket(ftps);
|
||||
so._closesocket(param->sostate, ftps);
|
||||
ftps = INVALID_SOCKET;
|
||||
param->remsock = s;
|
||||
}
|
||||
@ -790,9 +790,9 @@ for(;;){
|
||||
if((bufsize - inbuf) < LINESIZE){
|
||||
if (bufsize > 20000){
|
||||
if(!headsent++){
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[9], (int)strlen(proxy_stringtable[9]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[9], (int)strlen(proxy_stringtable[9]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
if((unsigned)socksend(param->clisock, buf, inbuf, conf.timeouts[STRING_S]) != inbuf){
|
||||
if((unsigned)socksend(param, param->clisock, buf, inbuf, conf.timeouts[STRING_S]) != inbuf){
|
||||
RETURN(781);
|
||||
}
|
||||
inbuf = 0;
|
||||
@ -806,7 +806,7 @@ for(;;){
|
||||
}
|
||||
memcpy(buf+inbuf, "<hr>", 4);
|
||||
inbuf += 4;
|
||||
so._closesocket(ftps);
|
||||
so._closesocket(param->sostate, ftps);
|
||||
ftps = INVALID_SOCKET;
|
||||
param->remsock = s;
|
||||
if(inbuf){
|
||||
@ -821,9 +821,9 @@ for(;;){
|
||||
"Connection: keep-alive\r\n"
|
||||
"Content-Length: %d\r\n\r\n",
|
||||
inbuf);
|
||||
socksend(param->clisock, (unsigned char *)ftpbuf, (int)strlen(ftpbuf), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)ftpbuf, (int)strlen(ftpbuf), conf.timeouts[STRING_S]);
|
||||
}
|
||||
socksend(param->clisock, buf, inbuf, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, buf, inbuf, conf.timeouts[STRING_S]);
|
||||
if(res){RETURN(res);}
|
||||
if(!headsent)goto REQUESTEND;
|
||||
}
|
||||
@ -854,11 +854,11 @@ for(;;){
|
||||
else {
|
||||
#ifdef TCP_CORK
|
||||
int opt = 1;
|
||||
so._setsockopt(param->remsock, IPPROTO_TCP, TCP_CORK, (unsigned char *)&opt, sizeof(int));
|
||||
so._setsockopt(param->sostate, param->remsock, IPPROTO_TCP, TCP_CORK, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
redirect = 1;
|
||||
res = (int)strlen((char *)req);
|
||||
if(socksend(param->remsock, req , res, conf.timeouts[STRING_L]) != res) {
|
||||
if(socksend(param, param->remsock, req , res, conf.timeouts[STRING_L]) != res) {
|
||||
RETURN(518);
|
||||
}
|
||||
param->statscli64 += res;
|
||||
@ -900,13 +900,13 @@ for(;;){
|
||||
sprintf((char*)buf + strlen((char *)buf), "\r\n");
|
||||
}
|
||||
sprintf((char*)buf+strlen((char *)buf), "\r\n");
|
||||
if ((res = socksend(param->remsock, buf+reqlen, (int)strlen((char *)buf+reqlen), conf.timeouts[STRING_S])) != (int)strlen((char *)buf+reqlen)) {
|
||||
if ((res = socksend(param, param->remsock, buf+reqlen, (int)strlen((char *)buf+reqlen), conf.timeouts[STRING_S])) != (int)strlen((char *)buf+reqlen)) {
|
||||
RETURN(518);
|
||||
}
|
||||
#ifdef TCP_CORK
|
||||
{
|
||||
int opt = 0;
|
||||
so._setsockopt(param->remsock, IPPROTO_TCP, TCP_CORK, (unsigned char *)&opt, sizeof(int));
|
||||
so._setsockopt(param->sostate, param->remsock, IPPROTO_TCP, TCP_CORK, (unsigned char *)&opt, sizeof(int));
|
||||
}
|
||||
#endif
|
||||
param->statscli64 += res;
|
||||
@ -1050,7 +1050,7 @@ for(;;){
|
||||
(hascontent && ckeepalive)?"keep-alive":"close");
|
||||
}
|
||||
sprintf((char*)buf + strlen((char *)buf), "\r\n");
|
||||
if((socksend(param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S])) != (int)strlen((char *)buf)) {
|
||||
if((socksend(param, param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S])) != (int)strlen((char *)buf)) {
|
||||
RETURN(521);
|
||||
}
|
||||
}
|
||||
@ -1059,7 +1059,7 @@ for(;;){
|
||||
if(param->chunked){
|
||||
unsigned char smallbuf[32];
|
||||
while ((i = sockgetlinebuf(param, SERVER, smallbuf, 30, '\n', conf.timeouts[STRING_S])) == 2) {
|
||||
if (socksend(param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i){
|
||||
if (socksend(param, param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i){
|
||||
RETURN(533);
|
||||
}
|
||||
if(param->chunked == 2) break;
|
||||
@ -1068,12 +1068,12 @@ for(;;){
|
||||
keepalive = 0;
|
||||
break;
|
||||
}
|
||||
if (socksend(param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i){
|
||||
if (socksend(param, param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i){
|
||||
RETURN(535);
|
||||
}
|
||||
if(param->chunked == 2) {
|
||||
if((i = sockgetlinebuf(param, SERVER, smallbuf, 30, '\n', conf.timeouts[STRING_S])) != 2) RETURN(534);
|
||||
if (socksend(param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i){
|
||||
if (socksend(param, param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i){
|
||||
RETURN(533);
|
||||
}
|
||||
break;
|
||||
@ -1107,8 +1107,8 @@ for(;;){
|
||||
REQUESTEND:
|
||||
|
||||
if((!ckeepalive || !keepalive) && param->remsock != INVALID_SOCKET){
|
||||
so._shutdown(param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->remsock);
|
||||
so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
RETURN(0);
|
||||
}
|
||||
@ -1123,41 +1123,41 @@ CLEANRET:
|
||||
if(param->res != 555 && param->res && param->clisock != INVALID_SOCKET && (param->res < 90 || param->res >=800 || param->res == 100 ||(param->res > 500 && param->res< 800))) {
|
||||
if((param->res>=509 && param->res < 517) || param->res > 900) while( (i = sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, '\n', conf.timeouts[STRING_S])) > 2);
|
||||
if(param->res == 10) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[2], (int)strlen(proxy_stringtable[2]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[2], (int)strlen(proxy_stringtable[2]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if (res == 700 || res == 701){
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[16], (int)strlen(proxy_stringtable[16]), conf.timeouts[STRING_S]);
|
||||
socksend(param->clisock, (unsigned char *)ftpbuf, inftpbuf, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[16], (int)strlen(proxy_stringtable[16]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)ftpbuf, inftpbuf, conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res == 100 || (param->res >10 && param->res < 20) || (param->res >701 && param->res <= 705)) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[1], (int)strlen(proxy_stringtable[1]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[1], (int)strlen(proxy_stringtable[1]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res >=20 && param->res < 30) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[6], (int)strlen(proxy_stringtable[6]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[6], (int)strlen(proxy_stringtable[6]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res >=30 && param->res < 80) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[5], (int)strlen(proxy_stringtable[5]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[5], (int)strlen(proxy_stringtable[5]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res == 1 || (!param->srv->needuser && param->res < 10)) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[11], (int)strlen(proxy_stringtable[11]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[11], (int)strlen(proxy_stringtable[11]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res < 10) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[param->srv->usentlm?12:7], (int)strlen(proxy_stringtable[param->srv->usentlm?12:7]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[param->srv->usentlm?12:7], (int)strlen(proxy_stringtable[param->srv->usentlm?12:7]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res == 999) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[4], (int)strlen(proxy_stringtable[4]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[4], (int)strlen(proxy_stringtable[4]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res == 519) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[3], (int)strlen(proxy_stringtable[3]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[3], (int)strlen(proxy_stringtable[3]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res == 517) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[15], (int)strlen(proxy_stringtable[15]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[15], (int)strlen(proxy_stringtable[15]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res == 780) {
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[10], (int)strlen(proxy_stringtable[10]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[10], (int)strlen(proxy_stringtable[10]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(param->res >= 511 && param->res<=516){
|
||||
socksend(param->clisock, (unsigned char *)proxy_stringtable[0], (int)strlen(proxy_stringtable[0]), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)proxy_stringtable[0], (int)strlen(proxy_stringtable[0]), conf.timeouts[STRING_S]);
|
||||
}
|
||||
}
|
||||
logurl(param, (char *)buf, (char *)req, ftp);
|
||||
|
@ -155,9 +155,9 @@ extern int timetoexit;
|
||||
extern struct extparam conf;
|
||||
|
||||
int sockmap(struct clientparam * param, int timeo, int usesplice);
|
||||
int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to);
|
||||
int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int sockrecvfrom(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bufsize, int to);
|
||||
int socksendto(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
|
||||
|
||||
int sockgetcharcli(struct clientparam * param, int timeosec, int timeousec);
|
||||
@ -277,7 +277,7 @@ void srvinit2(struct srvparam * srv, struct clientparam *param);
|
||||
void srvfree(struct srvparam * srv);
|
||||
unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsigned char *ext, ROTATION lt, time_t t);
|
||||
int readconfig(FILE * fp);
|
||||
int connectwithpoll(SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to);
|
||||
int connectwithpoll(void *state, SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to);
|
||||
|
||||
|
||||
int myrand(void * entropy, int len);
|
||||
|
@ -22,12 +22,12 @@ void * threadfunc (void *p) {
|
||||
fds.events = POLLIN;
|
||||
fds.revents = 0;
|
||||
for(i=5+(param->srv->maxchild>>10); i; i--){
|
||||
if(so._poll(&fds, 1, 1000*CONNBACK_TO)!=1){
|
||||
if(so._poll(param->sostate, &fds, 1, 1000*CONNBACK_TO)!=1){
|
||||
dolog(param, (unsigned char *)"Connect back not received, check connback client");
|
||||
i = 0;
|
||||
break;
|
||||
}
|
||||
param->remsock = so._accept(param->srv->cbsock, (struct sockaddr*)¶m->sinsr, &size);
|
||||
param->remsock = so._accept(param->sostate, param->srv->cbsock, (struct sockaddr*)¶m->sinsr, &size);
|
||||
if(param->remsock == INVALID_SOCKET) {
|
||||
dolog(param, (unsigned char *)"Connect back accept() failed");
|
||||
continue;
|
||||
@ -45,14 +45,14 @@ void * threadfunc (void *p) {
|
||||
if(param->srv->acl) param->res = checkACL(param);
|
||||
if(param->res){
|
||||
dolog(param, (unsigned char *)"Connect back ACL failed");
|
||||
so._closesocket(param->remsock);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if(socksendto(param->remsock, (struct sockaddr*)¶m->sinsr, (unsigned char *)"C", 1, CONNBACK_TO*1000) != 1){
|
||||
if(socksendto(param, param->remsock, (struct sockaddr*)¶m->sinsr, (unsigned char *)"C", 1, CONNBACK_TO*1000) != 1){
|
||||
dolog(param, (unsigned char *)"Connect back sending command failed");
|
||||
so._closesocket(param->remsock);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
continue;
|
||||
}
|
||||
@ -397,7 +397,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#ifndef _WIN32
|
||||
case 'I':
|
||||
size = sizeof(defparam.sincl);
|
||||
if(so._getsockname(0, (struct sockaddr*)&defparam.sincl, &size) ||
|
||||
if(so._getsockname(srv.so.state, 0, (struct sockaddr*)&defparam.sincl, &size) ||
|
||||
*SAFAMILY(&defparam.sincl) != AF_INET) error = 1;
|
||||
|
||||
else inetd = 1;
|
||||
@ -553,8 +553,8 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if(!isudp){
|
||||
lg.l_onoff = 1;
|
||||
lg.l_linger = conf.timeouts[STRING_L];
|
||||
so._setsockopt(0, SOL_SOCKET, SO_LINGER, (unsigned char *)&lg, sizeof(lg));
|
||||
so._setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (unsigned char *)&opt, sizeof(int));
|
||||
so._setsockopt(srv.so.state, 0, SOL_SOCKET, SO_LINGER, (unsigned char *)&lg, sizeof(lg));
|
||||
so._setsockopt(srv.so.state, 0, SOL_SOCKET, SO_OOBINLINE, (unsigned char *)&opt, sizeof(int));
|
||||
}
|
||||
defparam.clisock = 0;
|
||||
if(! (newparam = myalloc (sizeof(defparam)))){
|
||||
@ -594,10 +594,10 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if(srv.srvsock == INVALID_SOCKET){
|
||||
|
||||
if(!isudp){
|
||||
sock=so._socket(SASOCK(&srv.intsa), SOCK_STREAM, IPPROTO_TCP);
|
||||
sock=so._socket(srv.so.state, SASOCK(&srv.intsa), SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
else {
|
||||
sock=so._socket(SASOCK(&srv.intsa), SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock=so._socket(srv.so.state, SASOCK(&srv.intsa), SOCK_DGRAM, IPPROTO_UDP);
|
||||
}
|
||||
if( sock == INVALID_SOCKET) {
|
||||
perror("socket()");
|
||||
@ -611,13 +611,13 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#endif
|
||||
srv.srvsock = sock;
|
||||
opt = 1;
|
||||
if(so._setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
|
||||
if(so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
so._setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||
so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||
#endif
|
||||
#if defined SO_BINDTODEVICE
|
||||
if(srv.ibindtodevice && so._setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, srv.ibindtodevice, strlen(srv.ibindtodevice) + 1)) {
|
||||
if(srv.ibindtodevice && so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_BINDTODEVICE, srv.ibindtodevice, strlen(srv.ibindtodevice) + 1)) {
|
||||
dolog(&defparam, "failed to bind device");
|
||||
return -12;
|
||||
}
|
||||
@ -630,7 +630,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
return -12;
|
||||
}
|
||||
#ifndef NOIPV6
|
||||
if((*SAFAMILY(&srv.intsa) == AF_INET6 && so._setsockopt(sock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx)))) {
|
||||
if((*SAFAMILY(&srv.intsa) == AF_INET6 && so._setsockopt(srv.so.state, sock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx)))) {
|
||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||
return -12;
|
||||
}
|
||||
@ -639,17 +639,17 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#endif
|
||||
}
|
||||
size = sizeof(srv.intsa);
|
||||
for(sleeptime = SLEEPTIME * 100; so._bind(sock, (struct sockaddr*)&srv.intsa, SASIZE(&srv.intsa))==-1; usleep(sleeptime)) {
|
||||
for(sleeptime = SLEEPTIME * 100; so._bind(srv.so.state, sock, (struct sockaddr*)&srv.intsa, SASIZE(&srv.intsa))==-1; usleep(sleeptime)) {
|
||||
sprintf((char *)buf, "bind(): %s", strerror(errno));
|
||||
if(!srv.silent)dolog(&defparam, buf);
|
||||
sleeptime = (sleeptime<<1);
|
||||
if(!sleeptime) {
|
||||
so._closesocket(sock);
|
||||
so._closesocket(srv.so.state, sock);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
if(!isudp){
|
||||
if(so._listen (sock, srv.backlog?srv.backlog : 1+(srv.maxchild>>3))==-1) {
|
||||
if(so._listen (srv.so.state, sock, srv.backlog?srv.backlog : 1+(srv.maxchild>>3))==-1) {
|
||||
sprintf((char *)buf, "listen(): %s", strerror(errno));
|
||||
if(!srv.silent)dolog(&defparam, buf);
|
||||
return -4;
|
||||
@ -665,24 +665,24 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
}
|
||||
if(iscbl){
|
||||
parsehost(srv.family, cbl_string, (struct sockaddr *)&cbsa);
|
||||
if((srv.cbsock=so._socket(SASOCK(&cbsa), SOCK_STREAM, IPPROTO_TCP))==INVALID_SOCKET) {
|
||||
if((srv.cbsock=so._socket(srv.so.state, SASOCK(&cbsa), SOCK_STREAM, IPPROTO_TCP))==INVALID_SOCKET) {
|
||||
dolog(&defparam, (unsigned char *)"Failed to allocate connect back socket");
|
||||
return -6;
|
||||
}
|
||||
opt = 1;
|
||||
so._setsockopt(srv.cbsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||
so._setsockopt(srv.so.state, srv.cbsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
so._setsockopt(srv.cbsock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||
so._setsockopt(srv.so.state, srv.cbsock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||
#endif
|
||||
|
||||
setopts(srv.cbsock, srv.cbssockopts);
|
||||
|
||||
if(so._bind(srv.cbsock, (struct sockaddr*)&cbsa, SASIZE(&cbsa))==-1) {
|
||||
if(so._bind(srv.so.state, srv.cbsock, (struct sockaddr*)&cbsa, SASIZE(&cbsa))==-1) {
|
||||
dolog(&defparam, (unsigned char *)"Failed to bind connect back socket");
|
||||
return -7;
|
||||
}
|
||||
if(so._listen(srv.cbsock, 1 + (srv.maxchild>>4))==-1) {
|
||||
if(so._listen(srv.so.state, srv.cbsock, 1 + (srv.maxchild>>4))==-1) {
|
||||
dolog(&defparam, (unsigned char *)"Failed to listen connect back socket");
|
||||
return -8;
|
||||
}
|
||||
@ -711,7 +711,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if (iscbc) break;
|
||||
if (conf.paused != srv.paused) break;
|
||||
if (srv.fds.events & POLLIN) {
|
||||
error = so._poll(&srv.fds, 1, 1000);
|
||||
error = so._poll(srv.so.state, &srv.fds, 1, 1000);
|
||||
}
|
||||
else {
|
||||
usleep(SLEEPTIME);
|
||||
@ -730,20 +730,20 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if(!isudp){
|
||||
size = sizeof(defparam.sincr);
|
||||
if(iscbc){
|
||||
new_sock=so._socket(SASOCK(&defparam.sincr), SOCK_STREAM, IPPROTO_TCP);
|
||||
new_sock=so._socket(srv.so.state, SASOCK(&defparam.sincr), SOCK_STREAM, IPPROTO_TCP);
|
||||
if(new_sock != INVALID_SOCKET){
|
||||
setopts(new_sock, srv.cbcsockopts);
|
||||
|
||||
parsehost(srv.family, cbc_string, (struct sockaddr *)&defparam.sincr);
|
||||
if(connectwithpoll(new_sock,(struct sockaddr *)&defparam.sincr,SASIZE(&defparam.sincr),CONNBACK_TO)) {
|
||||
so._closesocket(new_sock);
|
||||
if(connectwithpoll(srv.so.state, new_sock,(struct sockaddr *)&defparam.sincr,SASIZE(&defparam.sincr),CONNBACK_TO)) {
|
||||
so._closesocket(srv.so.state, new_sock);
|
||||
new_sock = INVALID_SOCKET;
|
||||
usleep(SLEEPTIME);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(sockrecvfrom(new_sock,(struct sockaddr*)&defparam.sincr,buf,1,60*1000) != 1 || *buf!='C') {
|
||||
so._closesocket(new_sock);
|
||||
if(sockrecvfrom(NULL, new_sock,(struct sockaddr*)&defparam.sincr,buf,1,60*1000) != 1 || *buf!='C') {
|
||||
so._closesocket(srv.so.state, new_sock);
|
||||
new_sock = INVALID_SOCKET;
|
||||
usleep(SLEEPTIME);
|
||||
continue;
|
||||
@ -755,7 +755,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
}
|
||||
}
|
||||
else {
|
||||
new_sock = so._accept(sock, (struct sockaddr*)&defparam.sincr, &size);
|
||||
new_sock = so._accept(srv.so.state, sock, (struct sockaddr*)&defparam.sincr, &size);
|
||||
if(new_sock == INVALID_SOCKET){
|
||||
#ifdef _WIN32
|
||||
switch(WSAGetLastError()){
|
||||
@ -803,7 +803,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
setopts(new_sock, srv.clisockopts);
|
||||
}
|
||||
size = sizeof(defparam.sincl);
|
||||
if(so._getsockname(new_sock, (struct sockaddr *)&defparam.sincl, &size)){
|
||||
if(so._getsockname(srv.so.state, new_sock, (struct sockaddr *)&defparam.sincl, &size)){
|
||||
sprintf((char *)buf, "getsockname(): %s", strerror(errno));
|
||||
if(!srv.silent)dolog(&defparam, buf);
|
||||
continue;
|
||||
@ -816,14 +816,14 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
lg.l_onoff = 1;
|
||||
lg.l_linger = conf.timeouts[STRING_L];
|
||||
|
||||
so._setsockopt(new_sock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
so._setsockopt(new_sock, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
|
||||
so._setsockopt(srv.so.state, new_sock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
so._setsockopt(srv.so.state, new_sock, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
|
||||
}
|
||||
else {
|
||||
srv.fds.events = 0;
|
||||
}
|
||||
if(! (newparam = myalloc (sizeof(defparam)))){
|
||||
if(!isudp) so._closesocket(new_sock);
|
||||
if(!isudp) so._closesocket(srv.so.state, new_sock);
|
||||
defparam.res = 21;
|
||||
if(!srv.silent)dolog(&defparam, (unsigned char *)"Memory Allocation Failed");
|
||||
usleep(SLEEPTIME);
|
||||
@ -978,9 +978,9 @@ void srvinit2(struct srvparam * srv, struct clientparam *param){
|
||||
}
|
||||
|
||||
void srvfree(struct srvparam * srv){
|
||||
if(srv->srvsock != INVALID_SOCKET) so._closesocket(srv->srvsock);
|
||||
if(srv->srvsock != INVALID_SOCKET) so._closesocket(srv->so.state, srv->srvsock);
|
||||
srv->srvsock = INVALID_SOCKET;
|
||||
if(srv->cbsock != INVALID_SOCKET) so._closesocket(srv->cbsock);
|
||||
if(srv->cbsock != INVALID_SOCKET) so._closesocket(srv->so.state, srv->cbsock);
|
||||
srv->cbsock = INVALID_SOCKET;
|
||||
srv->service = S_ZOMBIE;
|
||||
while(srv->child) usleep(SLEEPTIME * 100);
|
||||
@ -1051,20 +1051,20 @@ void freeparam(struct clientparam * param) {
|
||||
if(param->extusername) myfree(param->extusername);
|
||||
if(param->extpassword) myfree(param->extpassword);
|
||||
if(param->ctrlsocksrv != INVALID_SOCKET && param->ctrlsocksrv != param->remsock) {
|
||||
so._shutdown(param->ctrlsocksrv, SHUT_RDWR);
|
||||
so._closesocket(param->ctrlsocksrv);
|
||||
so._shutdown(param->sostate, param->ctrlsocksrv, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->ctrlsocksrv);
|
||||
}
|
||||
if(param->ctrlsock != INVALID_SOCKET && param->ctrlsock != param->clisock) {
|
||||
so._shutdown(param->ctrlsock, SHUT_RDWR);
|
||||
so._closesocket(param->ctrlsock);
|
||||
so._shutdown(param->sostate, param->ctrlsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->ctrlsock);
|
||||
}
|
||||
if(param->remsock != INVALID_SOCKET) {
|
||||
so._shutdown(param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->remsock);
|
||||
so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
}
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
so._shutdown(param->clisock, SHUT_RDWR);
|
||||
so._closesocket(param->clisock);
|
||||
so._shutdown(param->sostate, param->clisock, SHUT_RDWR);
|
||||
so._closesocket(param->sostate, param->clisock);
|
||||
}
|
||||
myfree(param);
|
||||
}
|
||||
|
48
src/smtpp.c
48
src/smtpp.c
@ -30,7 +30,7 @@ int readreply (struct clientparam* param) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
socksend(param->clisock, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, buf, i, conf.timeouts[STRING_S]);
|
||||
} while (i > 3 && buf[3] == '-');
|
||||
if(i < 3) {
|
||||
myfree(buf);
|
||||
@ -60,7 +60,7 @@ int readcommand (struct clientparam* param) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
socksend(param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
if(!strncasecmp((char *)buf, "STARTTLS", 8) || !strncasecmp((char *)buf, "TURN", 4)){
|
||||
ret = 22;
|
||||
}
|
||||
@ -82,13 +82,13 @@ int readdata (struct clientparam* param) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
socksendto(param->remsock, (struct sockaddr *)¶m->sinsr, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
}
|
||||
if(i < 1) {
|
||||
myfree(buf);
|
||||
return 0;
|
||||
}
|
||||
socksend(param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
myfree(buf);
|
||||
return 1;
|
||||
}
|
||||
@ -101,20 +101,20 @@ void * smtppchild(struct clientparam* param) {
|
||||
char * command = NULL;
|
||||
int login = 0;
|
||||
|
||||
if(socksend(param->clisock, (unsigned char *)"220 Proxy\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (611);}
|
||||
if(socksend(param, param->clisock, (unsigned char *)"220 Proxy\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (611);}
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
while(i > 4 && (strncasecmp((char *)buf, "AUTH PLAIN", 10) || !(login = 2)) && (strncasecmp((char *)buf, "AUTH LOGIN", 10) || !(login = 1))){
|
||||
if(!strncasecmp((char *)buf, "QUIT", 4)){
|
||||
socksend(param->clisock, (unsigned char *)"221 Proxy\r\n", 11,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"221 Proxy\r\n", 11,conf.timeouts[STRING_S]);
|
||||
RETURN(0);
|
||||
}
|
||||
else if(!strncasecmp((char *)buf, "HELO ", 5)){
|
||||
socksend(param->clisock, (unsigned char *)"250 Proxy\r\n", 11,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"250 Proxy\r\n", 11,conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(!strncasecmp((char *)buf, "EHLO ", 5)){
|
||||
socksend(param->clisock, (unsigned char *)ehlo, sizeof(ehlo) - 1,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)ehlo, sizeof(ehlo) - 1,conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(!param->hostname) socksend(param->clisock, (unsigned char *)"571 need AUTH first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
else if(!param->hostname) socksend(param, param->clisock, (unsigned char *)"571 need AUTH first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
else {
|
||||
login = -1;
|
||||
buf[i] = 0;
|
||||
@ -125,7 +125,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
}
|
||||
if(!login) {RETURN(662);}
|
||||
if(login == 1){
|
||||
socksend(param->clisock, (unsigned char *)"334 VXNlcm5hbWU6\r\n", 18,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"334 VXNlcm5hbWU6\r\n", 18,conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 3) {RETURN(663);}
|
||||
buf[i-2] = 0;
|
||||
@ -133,7 +133,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
if(i < 1) {RETURN(664);}
|
||||
username[i] = 0;
|
||||
parseconnusername((char *)username, param, 0, 25);
|
||||
socksend(param->clisock, (unsigned char *)"334 UGFzc3dvcmQ6\r\n", 18,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"334 UGFzc3dvcmQ6\r\n", 18,conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 2) {RETURN(665);}
|
||||
buf[i-2] = 0;
|
||||
@ -149,7 +149,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
i = de64(buf+11,username,255);
|
||||
}
|
||||
else {
|
||||
socksend(param->clisock, (unsigned char *)"334\r\n", 5,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"334\r\n", 5,conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 3) {RETURN(667);}
|
||||
buf[i-2] = 0;
|
||||
@ -189,7 +189,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
i = sprintf((char *)buf, "EHLO [");
|
||||
i += myinet_ntop(*SAFAMILY(¶m->sinsl), SAADDR(¶m->sinsl), (char *)buf+strlen((char *)buf), 64);
|
||||
i += sprintf((char *)buf+strlen((char *)buf), "]\r\n");
|
||||
if(socksend(param->remsock, buf, i, conf.timeouts[STRING_S])!= i) {RETURN(673);}
|
||||
if(socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S])!= i) {RETURN(673);}
|
||||
param->statscli64+=i;
|
||||
param->nwrites++;
|
||||
login = 0;
|
||||
@ -204,29 +204,29 @@ void * smtppchild(struct clientparam* param) {
|
||||
if(i<3) {RETURN(672);}
|
||||
if(!command || (param->extusername && param->extpassword)){
|
||||
if(!param->extusername || !*param->extusername || !param->extpassword || !*param->extpassword || !login){
|
||||
socksend(param->clisock, (unsigned char *)"235 auth required\r\n", 19,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"235 auth required\r\n", 19,conf.timeouts[STRING_S]);
|
||||
}
|
||||
if ((login & 1)) {
|
||||
socksend(param->remsock, (unsigned char *)"AUTH LOGIN\r\n", 12, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"AUTH LOGIN\r\n", 12, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=12;
|
||||
param->nwrites++;
|
||||
i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(680);}
|
||||
en64(param->extusername, buf, (int)strlen((char *)param->extusername));
|
||||
socksend(param->remsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=(i+2);
|
||||
param->nwrites+=2;
|
||||
i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(681);}
|
||||
en64(param->extpassword, buf, (int)strlen((char *)param->extpassword));
|
||||
socksend(param->remsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=(i+2);
|
||||
param->nwrites+=2;
|
||||
}
|
||||
else if((login & 2)){
|
||||
socksend(param->remsock, (unsigned char *)"AUTH PLAIN\r\n", 12, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"AUTH PLAIN\r\n", 12, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=(12);
|
||||
param->nwrites++;
|
||||
i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
@ -240,8 +240,8 @@ void * smtppchild(struct clientparam* param) {
|
||||
i+=res;
|
||||
en64(username, buf, i);
|
||||
i = (int)strlen((char *)buf);
|
||||
socksend(param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=(i+2);
|
||||
param->nwrites+=2;
|
||||
}
|
||||
@ -266,7 +266,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
}
|
||||
#endif
|
||||
i = (int)strlen(command);
|
||||
if(res != 2) socksend(param->remsock, (unsigned char *)command, i, conf.timeouts[STRING_S]);
|
||||
if(res != 2) socksend(param, param->remsock, (unsigned char *)command, i, conf.timeouts[STRING_S]);
|
||||
}
|
||||
#ifndef WITHMAIN
|
||||
|
||||
@ -296,7 +296,7 @@ CLEANRET:
|
||||
}
|
||||
else dolog(param, NULL);
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 661 && param->res <700)) socksend(param->clisock, (unsigned char *)"571 \r\n", 6,conf.timeouts[STRING_S]);
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 661 && param->res <700)) socksend(param, param->clisock, (unsigned char *)"571 \r\n", 6,conf.timeouts[STRING_S]);
|
||||
}
|
||||
if(command) myfree(command);
|
||||
freeparam(param);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
int sent = 0;
|
||||
int res;
|
||||
struct pollfd fds;
|
||||
@ -16,10 +16,10 @@ int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
fds.events = POLLOUT;
|
||||
do {
|
||||
if(conf.timetoexit) return 0;
|
||||
res = so._poll(&fds, 1, to*1000);
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if(res < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||
if(res < 1) break;
|
||||
res = so._send(sock, (char *)buf + sent, bufsize - sent, 0);
|
||||
res = param?param->srv->so._send(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0) : so._send(so.state, sock, (char *)buf + sent, bufsize - sent, 0);
|
||||
if(res < 0) {
|
||||
if(errno == EAGAIN || errno == EINTR) continue;
|
||||
break;
|
||||
@ -30,7 +30,7 @@ int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
}
|
||||
|
||||
|
||||
int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
int socksendto(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
int sent = 0;
|
||||
int res;
|
||||
struct pollfd fds;
|
||||
@ -39,10 +39,10 @@ int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufs
|
||||
do {
|
||||
if(conf.timetoexit) return 0;
|
||||
fds.events = POLLOUT;
|
||||
res = so._poll(&fds, 1, to);
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if(res < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||
if(res < 1) break;
|
||||
res = so._sendto(sock, (char *)buf + sent, bufsize - sent, 0, sin, SASIZE(sin));
|
||||
res = param?param->srv->so._sendto(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0, sin, SASIZE(sin)):so._sendto(so.state, sock, (char *)buf + sent, bufsize - sent, 0, sin, SASIZE(sin));
|
||||
if(res < 0) {
|
||||
if(errno != EAGAIN && errno != EINTR) break;
|
||||
continue;
|
||||
@ -52,7 +52,7 @@ int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufs
|
||||
return sent;
|
||||
}
|
||||
|
||||
int sockrecvfrom(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
struct pollfd fds;
|
||||
SASIZETYPE sasize;
|
||||
int res;
|
||||
@ -60,10 +60,11 @@ int sockrecvfrom(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bu
|
||||
fds.fd = sock;
|
||||
fds.events = POLLIN;
|
||||
if(conf.timetoexit) return EOF;
|
||||
if (so._poll(&fds, 1, to)<1) return 0;
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if (res<1) return 0;
|
||||
sasize = SASIZE(sin);
|
||||
do {
|
||||
res = so._recvfrom(sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize);
|
||||
res = param?param->srv->so._recvfrom(param->sostate, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize):so._recvfrom(so.state, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize);
|
||||
} while (res < 0 && (errno == EAGAIN || errno == EINTR));
|
||||
return res;
|
||||
}
|
||||
@ -80,7 +81,7 @@ int sockgetcharcli(struct clientparam * param, int timeosec, int timeousec){
|
||||
return (int)param->clibuf[param->clioffset++];
|
||||
}
|
||||
param->clioffset = param->cliinbuf = 0;
|
||||
if ((len = sockrecvfrom(param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf, param->clibufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
if ((len = sockrecvfrom(param, param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf, param->clibufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
param->cliinbuf = len;
|
||||
param->clioffset = 1;
|
||||
return (int)*param->clibuf;
|
||||
@ -100,7 +101,7 @@ int sockfillbuffcli(struct clientparam * param, unsigned long size, int timeosec
|
||||
}
|
||||
if(size <= param->cliinbuf) return size;
|
||||
size -= param->cliinbuf;
|
||||
if((len = sockrecvfrom(param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf + param->cliinbuf, (param->clibufsize - param->cliinbuf) < size? param->clibufsize - param->cliinbuf:size, timeosec*1000)) > 0){
|
||||
if((len = sockrecvfrom(param, param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf + param->cliinbuf, (param->clibufsize - param->cliinbuf) < size? param->clibufsize - param->cliinbuf:size, timeosec*1000)) > 0){
|
||||
param->cliinbuf += len;
|
||||
}
|
||||
return param->cliinbuf;
|
||||
@ -120,7 +121,7 @@ int sockfillbuffsrv(struct clientparam * param, unsigned long size, int timeosec
|
||||
}
|
||||
if(size <= param->srvinbuf) return size;
|
||||
size -= param->srvinbuf;
|
||||
if((len = sockrecvfrom(param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf + param->srvinbuf, (param->srvbufsize - param->srvinbuf) < size? param->srvbufsize - param->srvinbuf:size, timeosec*1000)) > 0){
|
||||
if((len = sockrecvfrom(param, param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf + param->srvinbuf, (param->srvbufsize - param->srvinbuf) < size? param->srvbufsize - param->srvinbuf:size, timeosec*1000)) > 0){
|
||||
param->srvinbuf += len;
|
||||
param->nreads++;
|
||||
param->statssrv64 += len;
|
||||
@ -145,7 +146,7 @@ int sockgetcharsrv(struct clientparam * param, int timeosec, int timeousec){
|
||||
return (int)param->srvbuf[param->srvoffset++];
|
||||
}
|
||||
param->srvoffset = param->srvinbuf = 0;
|
||||
if ((len = sockrecvfrom(param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf, param->srvbufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
if ((len = sockrecvfrom(param, param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf, param->srvbufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
param->srvinbuf = len;
|
||||
param->srvoffset = 1;
|
||||
param->nreads++;
|
||||
|
@ -180,7 +180,7 @@ log(logbuf);
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = param->clisock;
|
||||
fds[1].fd = param->remsock;
|
||||
so._poll(fds, 2, sleeptime);
|
||||
so._poll(param->sostate, fds, 2, sleeptime);
|
||||
sleeptime = 0;
|
||||
}
|
||||
if((param->srv->logdumpsrv && (param->statssrv64 > param->srv->logdumpsrv)) ||
|
||||
@ -214,7 +214,7 @@ log("send to server from buf");
|
||||
if(fromclient) TOCLIENTBUF = 1;
|
||||
}
|
||||
sasize = sizeof(param->sinsr);
|
||||
res = so._sendto(param->remsock, (char *)param->clibuf + param->clioffset, (int)MIN(inclientbuf, fromclient), 0, (struct sockaddr*)¶m->sinsr, sasize);
|
||||
res = so._sendto(param->sostate, param->remsock, (char *)param->clibuf + param->clioffset, (int)MIN(inclientbuf, fromclient), 0, (struct sockaddr*)¶m->sinsr, sasize);
|
||||
if(res <= 0) {
|
||||
TOSERVER = 0;
|
||||
if(errno && errno != EAGAIN && errno != EINTR){
|
||||
@ -259,7 +259,7 @@ log("send to client from buf");
|
||||
continue;
|
||||
}
|
||||
sasize = sizeof(param->sincr);
|
||||
res = so._sendto(param->clisock, (char *)param->srvbuf + param->srvoffset, (int)MIN(inserverbuf,fromserver), 0, (struct sockaddr*)¶m->sincr, sasize);
|
||||
res = so._sendto(param->sostate, param->clisock, (char *)param->srvbuf + param->srvoffset, (int)MIN(inserverbuf,fromserver), 0, (struct sockaddr*)¶m->sincr, sasize);
|
||||
if(res <= 0) {
|
||||
TOCLIENT = 0;
|
||||
if(errno && errno != EAGAIN && errno != EINTR){
|
||||
@ -433,7 +433,7 @@ log("done read from server to pipe\n");
|
||||
log("read from client to buf");
|
||||
#endif
|
||||
sasize = sizeof(param->sincr);
|
||||
res = so._recvfrom(param->clisock, (char *)param->clibuf + param->cliinbuf, (int)MIN((uint64_t)param->clibufsize - param->cliinbuf, fromclient-inclientbuf), 0, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
res = so._recvfrom(param->sostate, param->clisock, (char *)param->clibuf + param->cliinbuf, (int)MIN((uint64_t)param->clibufsize - param->cliinbuf, fromclient-inclientbuf), 0, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
if(res <= 0) {
|
||||
FROMCLIENT = 0;
|
||||
if(res == 0 || (errno && errno != EINTR && errno !=EAGAIN)){
|
||||
@ -461,7 +461,7 @@ log("done read from client to buf");
|
||||
log("read from server to buf");
|
||||
#endif
|
||||
sasize = sizeof(param->sinsr);
|
||||
res = so._recvfrom(param->remsock, (char *)param->srvbuf + param->srvinbuf, (int)MIN((uint64_t)param->srvbufsize - param->srvinbuf, fromserver-inserverbuf), 0, (struct sockaddr *)¶m->sinsr, &sasize);
|
||||
res = so._recvfrom(param->sostate, param->remsock, (char *)param->srvbuf + param->srvinbuf, (int)MIN((uint64_t)param->srvbufsize - param->srvinbuf, fromserver-inserverbuf), 0, (struct sockaddr *)¶m->sinsr, &sasize);
|
||||
if(res <= 0) {
|
||||
FROMSERVER = 0;
|
||||
if(res == 0 || (errno && errno != EINTR && errno !=EAGAIN)) {
|
||||
@ -706,7 +706,7 @@ log("ready reading from server pipe");
|
||||
#ifdef WITHLOG
|
||||
log("entering poll");
|
||||
#endif
|
||||
res = so._poll(fds, fdsc, timeo*1000);
|
||||
res = so._poll(param->sostate, fds, fdsc, timeo*1000);
|
||||
#ifdef WITHLOG
|
||||
log("leaving poll");
|
||||
#endif
|
||||
|
50
src/socks.c
50
src/socks.c
@ -65,7 +65,7 @@ void * sockschild(struct clientparam* param) {
|
||||
}
|
||||
buf[0] = 5;
|
||||
buf[1] = (param->srv->needuser > 1 && !havepass)? 255 : havepass;
|
||||
if(socksend(param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(401);}
|
||||
if(socksend(param, param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(401);}
|
||||
if (param->srv->needuser > 1 && !havepass) RETURN(4);
|
||||
if (havepass) {
|
||||
if (((res = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_L], 0))) != 1) {
|
||||
@ -81,7 +81,7 @@ void * sockschild(struct clientparam* param) {
|
||||
if(!param->password)param->password = (unsigned char *)mystrdup((char *)buf);
|
||||
buf[0] = 1;
|
||||
buf[1] = 0;
|
||||
if(socksend(param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(481);}
|
||||
if(socksend(param, param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(481);}
|
||||
}
|
||||
if ((c = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_L], 0)) != 5) {
|
||||
RETURN(421);
|
||||
@ -189,7 +189,7 @@ void * sockschild(struct clientparam* param) {
|
||||
#else
|
||||
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);}
|
||||
if ((param->remsock=so._socket(param->sostate, 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;
|
||||
#ifdef REUSE
|
||||
if (command == 2){
|
||||
@ -197,11 +197,11 @@ void * sockschild(struct clientparam* param) {
|
||||
|
||||
#ifdef SO_REUSEADDR
|
||||
opt = 1;
|
||||
so._setsockopt(param->remsock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&opt, sizeof(int));
|
||||
so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
so._setsockopt(param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
|
||||
so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -230,23 +230,23 @@ void * sockschild(struct clientparam* param) {
|
||||
#endif
|
||||
|
||||
if(command > 1) {
|
||||
if(so._bind(param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
if(so._bind(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
if(so._bind(param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl)))RETURN (12);
|
||||
if(so._bind(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl)))RETURN (12);
|
||||
#if SOCKSTRACE > 0
|
||||
fprintf(stderr, "%hu bound to communicate with server\n", *SAPORT(¶m->sins));
|
||||
fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
sasize = SASIZE(¶m->sinsl);
|
||||
so._getsockname(param->remsock, (struct sockaddr *)¶m->sinsl, &sasize);
|
||||
so._getsockname(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsl, &sasize);
|
||||
if(command == 3) {
|
||||
param->ctrlsock = param->clisock;
|
||||
param->clisock = so._socket(SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP);
|
||||
param->clisock = so._socket(param->sostate, SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(param->clisock == INVALID_SOCKET) {RETURN(11);}
|
||||
sin = param->sincl;
|
||||
*SAPORT(&sin) = 0;
|
||||
if(so._bind(param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
|
||||
if(so._bind(param->sostate, param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
|
||||
#if SOCKSTRACE > 0
|
||||
fprintf(stderr, "%hu binded to communicate with client\n",
|
||||
ntohs(*SAPORT(&sin))
|
||||
@ -268,8 +268,8 @@ CLEANRET:
|
||||
int repcode;
|
||||
|
||||
sasize = sizeof(sin);
|
||||
if(command != 3 && param->remsock != INVALID_SOCKET) so._getsockname(param->remsock, (struct sockaddr *)&sin, &sasize);
|
||||
else so._getsockname(param->clisock, (struct sockaddr *)&sin, &sasize);
|
||||
if(command != 3 && param->remsock != INVALID_SOCKET) so._getsockname(param->sostate, param->remsock, (struct sockaddr *)&sin, &sasize);
|
||||
else so._getsockname(param->sostate, param->clisock, (struct sockaddr *)&sin, &sasize);
|
||||
#if SOCKSTRACE > 0
|
||||
fprintf(stderr, "Sending confirmation to client with code %d for %s with %s:%hu\n",
|
||||
param->res,
|
||||
@ -293,14 +293,14 @@ fflush(stderr);
|
||||
buf[3] = (*SAFAMILY(&sin) == AF_INET)?1:4;
|
||||
memcpy(buf+4, SAADDR(&sin), SAADDRLEN(&sin));
|
||||
memcpy(buf+4+SAADDRLEN(&sin), SAPORT(&sin), 2);
|
||||
socksend((command == 3)?param->ctrlsock:param->clisock, buf, 6+SAADDRLEN(&sin), conf.timeouts[STRING_S]);
|
||||
socksend(param, (command == 3)?param->ctrlsock:param->clisock, buf, 6+SAADDRLEN(&sin), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else{
|
||||
buf[0] = 0;
|
||||
buf[1] = 90 + !!(repcode);
|
||||
memcpy(buf+2, SAPORT(&sin), 2);
|
||||
memcpy(buf+4, SAADDR(&sin), 4);
|
||||
socksend(param->clisock, buf, 8, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, buf, 8, conf.timeouts[STRING_S]);
|
||||
}
|
||||
|
||||
|
||||
@ -326,19 +326,19 @@ fflush(stderr);
|
||||
param->res = mapsocket(param, conf.timeouts[CONNECTION_L]);
|
||||
break;
|
||||
case 2:
|
||||
so._listen (param->remsock, 1);
|
||||
so._listen (param->sostate, param->remsock, 1);
|
||||
|
||||
fds[0].fd = param->remsock;
|
||||
fds[1].fd = param->clisock;
|
||||
fds[0].events = fds[1].events = POLLIN;
|
||||
res = so._poll(fds, 2, conf.timeouts[CONNECTION_L] * 1000);
|
||||
res = so._poll(param->sostate, fds, 2, conf.timeouts[CONNECTION_L] * 1000);
|
||||
if (res < 1 || fds[1].revents) {
|
||||
res = 460;
|
||||
break;
|
||||
}
|
||||
sasize = sizeof(param->sinsr);
|
||||
s = so._accept(param->remsock, (struct sockaddr *)¶m->sinsr, &sasize);
|
||||
so._closesocket(param->remsock);
|
||||
s = so._accept(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsr, &sasize);
|
||||
so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = s;
|
||||
if(s == INVALID_SOCKET) {
|
||||
param->res = 462;
|
||||
@ -370,12 +370,12 @@ fflush(stderr);
|
||||
buf[3] = (*SAFAMILY(¶m->sinsr) == AF_INET)?1:4;
|
||||
memcpy(buf+4, SAADDR(¶m->sinsr), SAADDRLEN(¶m->sinsr));
|
||||
memcpy(buf+4+SAADDRLEN(¶m->sinsr), SAPORT(¶m->sinsr), 2);
|
||||
socksend(param->clisock, buf, 6+SAADDRLEN(¶m->sinsr), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, buf, 6+SAADDRLEN(¶m->sinsr), conf.timeouts[STRING_S]);
|
||||
}
|
||||
else {
|
||||
memcpy (buf+2, SAPORT(¶m->sinsr), 2);
|
||||
memcpy (buf+4, SAADDR(¶m->sinsr), 4);
|
||||
socksend(param->clisock, buf, 8, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, buf, 8, conf.timeouts[STRING_S]);
|
||||
}
|
||||
|
||||
param->res = mapsocket(param, conf.timeouts[CONNECTION_S]);
|
||||
@ -392,7 +392,7 @@ fflush(stderr);
|
||||
fds[2].fd = param->ctrlsock;
|
||||
fds[2].events = fds[1].events = fds[0].events = POLLIN;
|
||||
|
||||
res = so._poll(fds, 3, conf.timeouts[CONNECTION_L]*1000);
|
||||
res = so._poll(param->sostate, fds, 3, conf.timeouts[CONNECTION_L]*1000);
|
||||
if(res <= 0) {
|
||||
param->res = 463;
|
||||
break;
|
||||
@ -403,7 +403,7 @@ fflush(stderr);
|
||||
}
|
||||
if (fds[1].revents) {
|
||||
sasize = sizeof(sin);
|
||||
if((len = so._recvfrom(param->clisock, (char *)buf, 65535, 0, (struct sockaddr *)&sin, &sasize)) <= 10) {
|
||||
if((len = so._recvfrom(param->sostate, param->clisock, (char *)buf, 65535, 0, (struct sockaddr *)&sin, &sasize)) <= 10) {
|
||||
param->res = 464;
|
||||
break;
|
||||
}
|
||||
@ -441,7 +441,7 @@ fflush(stderr);
|
||||
|
||||
sasize = sizeof(param->sinsr);
|
||||
if(len > (int)i){
|
||||
socksendto(param->remsock, (struct sockaddr *)¶m->sinsr, buf+i, len - i, conf.timeouts[SINGLEBYTE_L]*1000);
|
||||
socksendto(param, param->remsock, (struct sockaddr *)¶m->sinsr, buf+i, len - i, conf.timeouts[SINGLEBYTE_L]*1000);
|
||||
param->statscli64+=(len - i);
|
||||
param->nwrites++;
|
||||
#if SOCKSTRACE > 1
|
||||
@ -464,7 +464,7 @@ fflush(stderr);
|
||||
sasize = sizeof(param->sinsr);
|
||||
buf[0]=buf[1]=buf[2]=0;
|
||||
buf[3]=(*SAFAMILY(¶m->sinsl) == AF_INET)?1:4;
|
||||
if((len = so._recvfrom(param->remsock, (char *)buf+6+SAADDRLEN(¶m->sinsl), 65535 - (6+SAADDRLEN(¶m->sinsl)), 0, (struct sockaddr *)¶m->sinsr, &sasize)) <= 0) {
|
||||
if((len = so._recvfrom(param->sostate, param->remsock, (char *)buf+6+SAADDRLEN(¶m->sinsl), 65535 - (6+SAADDRLEN(¶m->sinsl)), 0, (struct sockaddr *)¶m->sinsr, &sasize)) <= 0) {
|
||||
param->res = 468;
|
||||
break;
|
||||
}
|
||||
@ -473,7 +473,7 @@ fflush(stderr);
|
||||
memcpy(buf+4, SAADDR(¶m->sinsr), SAADDRLEN(¶m->sinsr));
|
||||
memcpy(buf+4+SAADDRLEN(¶m->sinsr), SAPORT(¶m->sinsr), 2);
|
||||
sasize = sizeof(sin);
|
||||
socksendto(param->clisock, (struct sockaddr *)&sin, buf, len + 6 + SAADDRLEN(¶m->sinsr), conf.timeouts[SINGLEBYTE_L]*1000);
|
||||
socksendto(param, param->clisock, (struct sockaddr *)&sin, buf, len + 6 + SAADDRLEN(¶m->sinsr), conf.timeouts[SINGLEBYTE_L]*1000);
|
||||
#if SOCKSTRACE > 1
|
||||
fprintf(stderr, "UDP packet relayed to client from %hu size %d\n",
|
||||
ntohs(*SAPORT(¶m->sinsr)),
|
||||
|
@ -423,39 +423,39 @@ struct sockfuncs {
|
||||
void * state;
|
||||
void (*freefunc)(void* state);
|
||||
#ifdef _WIN32
|
||||
SOCKET (WINAPI *_socket)(int domain, int type, int protocol);
|
||||
SOCKET (WINAPI *_accept)(SOCKET s, struct sockaddr * addr, int * addrlen);
|
||||
int (WINAPI *_bind)(SOCKET s, const struct sockaddr *addr, int addrlen);
|
||||
int (WINAPI *_listen)(SOCKET s, int backlog);
|
||||
int (WINAPI *_connect)(SOCKET s, const struct sockaddr *name, int namelen);
|
||||
int (WINAPI *_getpeername)(SOCKET s, struct sockaddr * name, int * namelen);
|
||||
int (WINAPI *_getsockname)(SOCKET s, struct sockaddr * name, int * namelen);
|
||||
int (WINAPI *_getsockopt)(SOCKET s, int level, int optname, char * optval, int * optlen);
|
||||
int (WINAPI *_setsockopt)(SOCKET s, int level, int optname, const char *optval, int optlen);
|
||||
int (WINAPI *_poll)(struct pollfd *fds, unsigned int nfds, int timeout);
|
||||
int (WINAPI *_send)(SOCKET s, const char *msg, int len, int flags);
|
||||
int (WINAPI *_sendto)(SOCKET s, const char *msg, int len, int flags, const struct sockaddr *to, int tolen);
|
||||
int (WINAPI *_recv)(SOCKET s, char *buf, int len, int flags);
|
||||
int (WINAPI *_recvfrom)(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen);
|
||||
int (WINAPI *_shutdown)(SOCKET s, int how);
|
||||
int (WINAPI *_closesocket)(SOCKET s);
|
||||
SOCKET (WINAPI *_socket)(void* state, int domain, int type, int protocol);
|
||||
SOCKET (WINAPI *_accept)(void* state, SOCKET s, struct sockaddr * addr, int * addrlen);
|
||||
int (WINAPI *_bind)(void* state, SOCKET s, const struct sockaddr *addr, int addrlen);
|
||||
int (WINAPI *_listen)(void* state, SOCKET s, int backlog);
|
||||
int (WINAPI *_connect)(void* state, SOCKET s, const struct sockaddr *name, int namelen);
|
||||
int (WINAPI *_getpeername)(void* state, SOCKET s, struct sockaddr * name, int * namelen);
|
||||
int (WINAPI *_getsockname)(void* state, SOCKET s, struct sockaddr * name, int * namelen);
|
||||
int (WINAPI *_getsockopt)(void* state, SOCKET s, int level, int optname, char * optval, int * optlen);
|
||||
int (WINAPI *_setsockopt)(void* state, SOCKET s, int level, int optname, const char *optval, int optlen);
|
||||
int (WINAPI *_poll)(void* state, struct pollfd *fds, unsigned int nfds, int timeout);
|
||||
int (WINAPI *_send)(void* state, SOCKET s, const char *msg, int len, int flags);
|
||||
int (WINAPI *_sendto)(void* state, SOCKET s, const char *msg, int len, int flags, const struct sockaddr *to, int tolen);
|
||||
int (WINAPI *_recv)(void* state, SOCKET s, char *buf, int len, int flags);
|
||||
int (WINAPI *_recvfrom)(void* state, SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen);
|
||||
int (WINAPI *_shutdown)(void* state, SOCKET s, int how);
|
||||
int (WINAPI *_closesocket)(void* state, SOCKET s);
|
||||
#else
|
||||
SOCKET (*_socket)(int domain, int type, int protocol);
|
||||
SOCKET (*_accept)(SOCKET s, struct sockaddr * addr, socklen_t * addrlen);
|
||||
int (*_bind)(SOCKET s, const struct sockaddr *addr, socklen_t addrlen);
|
||||
int (*_listen)(SOCKET s, int backlog);
|
||||
int (*_connect)(SOCKET s, const struct sockaddr *name, socklen_t namelen);
|
||||
int (*_getpeername)(SOCKET s, struct sockaddr * name, socklen_t * namelen);
|
||||
int (*_getsockname)(SOCKET s, struct sockaddr * name, socklen_t * namelen);
|
||||
int (*_getsockopt)(SOCKET s, int level, int optname, void * optval, socklen_t * optlen);
|
||||
int (*_setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen);
|
||||
int (*_poll)(struct pollfd *fds, unsigned int nfds, int timeout);
|
||||
ssize_t (*_send)(SOCKET s, const void *msg, size_t len, int flags);
|
||||
ssize_t (*_sendto)(SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen);
|
||||
ssize_t (*_recv)(SOCKET s, void *buf, size_t len, int flags);
|
||||
ssize_t (*_recvfrom)(SOCKET s, void * buf, size_t len, int flags, struct sockaddr * from, SASIZETYPE * fromlen);
|
||||
int (*_shutdown)(SOCKET s, int how);
|
||||
int (*_closesocket)(SOCKET s);
|
||||
SOCKET (*_socket)(void* state, int domain, int type, int protocol);
|
||||
SOCKET (*_accept)(void* state, SOCKET s, struct sockaddr * addr, socklen_t * addrlen);
|
||||
int (*_bind)(void* state, SOCKET s, const struct sockaddr *addr, socklen_t addrlen);
|
||||
int (*_listen)(void* state, SOCKET s, int backlog);
|
||||
int (*_connect)(void* state, SOCKET s, const struct sockaddr *name, socklen_t namelen);
|
||||
int (*_getpeername)(void* state, SOCKET s, struct sockaddr * name, socklen_t * namelen);
|
||||
int (*_getsockname)(void* state, SOCKET s, struct sockaddr * name, socklen_t * namelen);
|
||||
int (*_getsockopt)(void* state, SOCKET s, int level, int optname, void * optval, socklen_t * optlen);
|
||||
int (*_setsockopt)(void* state, int s, int level, int optname, const void *optval, socklen_t optlen);
|
||||
int (*_poll)(void* state, struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
ssize_t (*_send)(void* state, SOCKET s, const void *msg, size_t len, int flags);
|
||||
ssize_t (*_sendto)(void* state, SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen);
|
||||
ssize_t (*_recv)(void* state, SOCKET s, void *buf, size_t len, int flags);
|
||||
ssize_t (*_recvfrom)(void* state, SOCKET s, void * buf, size_t len, int flags, struct sockaddr * from, SASIZETYPE * fromlen);
|
||||
int (*_shutdown)(void* state, SOCKET s, int how);
|
||||
int (*_closesocket)(void* state, SOCKET s);
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -743,9 +743,9 @@ struct pluginlink {
|
||||
struct auth *authfuncs;
|
||||
struct commands * commandhandlers;
|
||||
void * (*findbyname)(const char *name);
|
||||
int (*socksend)(SOCKET sock, unsigned char * buf, int bufsize, int to);
|
||||
int (*socksendto)(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int (*sockrecvfrom)(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int (*socksend)(struct clientparam *param, SOCKET sock, unsigned char * buf, int bufsize, int to);
|
||||
int (*socksendto)(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int (*sockrecvfrom)(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int (*sockgetcharcli)(struct clientparam * param, int timeosec, int timeousec);
|
||||
int (*sockgetcharsrv)(struct clientparam * param, int timeosec, int timeousec);
|
||||
int (*sockgetlinebuf)(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, int delim, int to);
|
||||
|
14
src/udppm.c
14
src/udppm.c
@ -48,7 +48,7 @@ void * udppmchild(struct clientparam* param) {
|
||||
RETURN (21);
|
||||
}
|
||||
param->cliinbuf = param->clioffset = 0;
|
||||
i = sockrecvfrom(param->srv->srvsock, (struct sockaddr *)¶m->sincr, param->clibuf, param->clibufsize, 0);
|
||||
i = sockrecvfrom(param, param->srv->srvsock, (struct sockaddr *)¶m->sincr, param->clibuf, param->clibufsize, 0);
|
||||
if(i<=0){
|
||||
param->srv->fds.events = POLLIN;
|
||||
RETURN (214);
|
||||
@ -56,15 +56,15 @@ void * udppmchild(struct clientparam* param) {
|
||||
param->cliinbuf = i;
|
||||
|
||||
#ifdef _WIN32
|
||||
if((param->clisock=so._socket(SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
if((param->clisock=so._socket(param->sostate, SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
RETURN(818);
|
||||
}
|
||||
if(so._setsockopt(param->clisock, SOL_SOCKET, SO_REUSEADDR, (char *)&ul, sizeof(int))) {RETURN(820);};
|
||||
if(so._setsockopt(param->sostate, param->clisock, SOL_SOCKET, SO_REUSEADDR, (char *)&ul, sizeof(int))) {RETURN(820);};
|
||||
ul = 1;
|
||||
ioctlsocket(param->clisock, FIONBIO, &ul);
|
||||
size = sizeof(param->sinsl);
|
||||
if(so._getsockname(param->srv->srvsock, (struct sockaddr *)¶m->sinsl, &size)) {RETURN(21);};
|
||||
if(so._bind(param->clisock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
if(so._getsockname(param->sostate, param->srv->srvsock, (struct sockaddr *)¶m->sinsl, &size)) {RETURN(21);};
|
||||
if(so._bind(param->sostate, param->clisock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
RETURN(822);
|
||||
}
|
||||
#else
|
||||
@ -77,8 +77,8 @@ void * udppmchild(struct clientparam* param) {
|
||||
memcpy(¶m->sinsl, ¶m->srv->extsa, SASIZE(¶m->req));
|
||||
#endif
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
if ((param->remsock=so._socket(SASOCK(¶m->sinsl), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {RETURN (11);}
|
||||
if(so._bind(param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {RETURN (12);}
|
||||
if ((param->remsock=so._socket(param->sostate, SASOCK(¶m->sinsl), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {RETURN (11);}
|
||||
if(so._bind(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {RETURN (12);}
|
||||
#ifdef _WIN32
|
||||
ul = 1;
|
||||
ioctlsocket(param->remsock, FIONBIO, &ul);
|
||||
|
@ -55,12 +55,12 @@ char * aceaction (int action){
|
||||
|
||||
static void stdpr(struct printparam* pp, char *buf, int inbuf){
|
||||
if((pp->inbuf + inbuf > 1024) || !buf) {
|
||||
socksend(pp->cp->clisock, (unsigned char *)pp->buf, pp->inbuf, conf.timeouts[STRING_S]);
|
||||
socksend(pp->cp, pp->cp->clisock, (unsigned char *)pp->buf, pp->inbuf, conf.timeouts[STRING_S]);
|
||||
pp->inbuf = 0;
|
||||
if(!buf) return;
|
||||
}
|
||||
if(inbuf >= 1000){
|
||||
socksend(pp->cp->clisock, (unsigned char *)buf, inbuf, conf.timeouts[STRING_S]);
|
||||
socksend(pp->cp, pp->cp->clisock, (unsigned char *)buf, inbuf, conf.timeouts[STRING_S]);
|
||||
}
|
||||
else {
|
||||
memcpy(pp->buf + pp->inbuf, buf, inbuf);
|
||||
|
Loading…
Reference in New Issue
Block a user