mirror of
https://github.com/3proxy/3proxy.git
synced 2026-09-29 16:55:51 +08:00
Compare commits
No commits in common. "48d72538e153acac69e0370eca1948a36887241f" and "f265ea0b52013d965810f8968fa500774856cd04" have entirely different histories.
48d72538e1
...
f265ea0b52
@ -64,13 +64,6 @@ void * ftpprchild(struct clientparam* param) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if (!strncasecmp((char *)buf, "PASS ", 5)){
|
else if (!strncasecmp((char *)buf, "PASS ", 5)){
|
||||||
/* The user name carries the server to log in to, and it arrives
|
|
||||||
with USER. Without it there is nothing to log in to, and what
|
|
||||||
follows would read the name and the host as if there were. */
|
|
||||||
if(!param->hostname || !param->extusername){
|
|
||||||
socksend(param, param->ctrlsock, (unsigned char *)"503 Login with USER first\r\n", 27, conf.timeouts[STRING_S]);
|
|
||||||
RETURN(805);
|
|
||||||
}
|
|
||||||
param->extpassword = (unsigned char *)strdup((char *)buf+5);
|
param->extpassword = (unsigned char *)strdup((char *)buf+5);
|
||||||
inbuf = BUFSIZE;
|
inbuf = BUFSIZE;
|
||||||
res = ftplogin(param, (char *)buf, &inbuf);
|
res = ftplogin(param, (char *)buf, &inbuf);
|
||||||
|
|||||||
@ -159,10 +159,7 @@ void * smtppchild(struct clientparam* param) {
|
|||||||
i = de64(buf,username,255);
|
i = de64(buf,username,255);
|
||||||
if(i < 1) {RETURN(664);}
|
if(i < 1) {RETURN(664);}
|
||||||
username[i] = 0;
|
username[i] = 0;
|
||||||
/* The name has to carry the host to connect to, and the answer says
|
parseconnusername((char *)username, param, 0, 587);
|
||||||
whether it did: without one there is nowhere to go, and what follows
|
|
||||||
reads the name as if there were. */
|
|
||||||
if(parseconnusername((char *)username, param, 0, 587)) {RETURN(669);}
|
|
||||||
socksend(param, 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]);
|
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||||
if(i < 2) {RETURN(665);}
|
if(i < 2) {RETURN(665);}
|
||||||
@ -187,7 +184,7 @@ void * smtppchild(struct clientparam* param) {
|
|||||||
}
|
}
|
||||||
if(i < 3 || *username) {RETURN(668);}
|
if(i < 3 || *username) {RETURN(668);}
|
||||||
username[i] = 0;
|
username[i] = 0;
|
||||||
if(parseconnusername((char *)username+1, param, 0, 587)) {RETURN(670);}
|
parseconnusername((char *)username+1, param, 0, 587);
|
||||||
res = (int)strlen((char *)username+1) + 2;
|
res = (int)strlen((char *)username+1) + 2;
|
||||||
if(res < i){
|
if(res < i){
|
||||||
if(param->extpassword) free(param->extpassword);
|
if(param->extpassword) free(param->extpassword);
|
||||||
|
|||||||
@ -14,19 +14,12 @@ def _windows():
|
|||||||
net.ipv4.ip_local_port_range; a window outside it is ignored and an
|
net.ipv4.ip_local_port_range; a window outside it is ignored and an
|
||||||
ordinary ephemeral port is used, so a fixed low window would be
|
ordinary ephemeral port is used, so a fixed low window would be
|
||||||
measuring the kernel's own choice rather than the setting.
|
measuring the kernel's own choice rather than the setting.
|
||||||
|
|
||||||
Everywhere else the range is honoured by binding a port out of it at
|
|
||||||
random, ten times before giving up and letting the system choose. A port
|
|
||||||
which carried a connection a moment ago cannot be bound again while it
|
|
||||||
waits out its close - four minutes of it on Windows - so the window has
|
|
||||||
to be wide enough that ten tries do not all land on one. The window the
|
|
||||||
kernel picks from on Linux needs no such room, since it skips them.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open("/proc/sys/net/ipv4/ip_local_port_range") as fp:
|
with open("/proc/sys/net/ipv4/ip_local_port_range") as fp:
|
||||||
low, high = (int(part) for part in fp.read().split()[:2])
|
low, high = (int(part) for part in fp.read().split()[:2])
|
||||||
except (OSError, ValueError):
|
except (OSError, ValueError):
|
||||||
return (21400, 21899), (22000, 22499)
|
return (21400, 21449), (21500, 21549)
|
||||||
base = low + 1000 if low + 1150 <= high else low
|
base = low + 1000 if low + 1150 <= high else low
|
||||||
return (base, base + 49), (base + 100, base + 149)
|
return (base, base + 49), (base + 100, base + 149)
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,6 @@ configurations it needs, starts them, and states what it expects:
|
|||||||
import base64
|
import base64
|
||||||
import http.client
|
import http.client
|
||||||
import os
|
import os
|
||||||
import random
|
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
@ -34,11 +33,6 @@ import threading
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
# Ports handed out in this run: a service which has finished may still be
|
|
||||||
# in TIME_WAIT, and another case binding the same port would fail for it.
|
|
||||||
_PORTS_TAKEN = set()
|
|
||||||
|
|
||||||
|
|
||||||
class Response:
|
class Response:
|
||||||
"""A reply, or the reason there wasn't one."""
|
"""A reply, or the reason there wasn't one."""
|
||||||
|
|
||||||
@ -152,30 +146,14 @@ class Tester:
|
|||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
def free_port(self):
|
def free_port(self):
|
||||||
"""A port nothing is listening on, and nothing is likely to take.
|
"""A port nothing is listening on. Closed again before it is used,
|
||||||
|
which is racy in principle and reliable enough in practice."""
|
||||||
Asking the system for an ephemeral port hands back one out of the
|
s = socket.socket()
|
||||||
range it also draws outgoing connections from - 32768 up on Linux,
|
try:
|
||||||
49152 up on Windows - so between the check here and the bind in the
|
s.bind(("127.0.0.1", 0))
|
||||||
service, a connection somewhere else in the suite can take it. That
|
return s.getsockname()[1]
|
||||||
shows up as a service which never listens, or a bind() error deep in
|
finally:
|
||||||
a case which has nothing to do with ports. Ports are taken from below
|
s.close()
|
||||||
both ranges instead, and none is handed out twice in a run.
|
|
||||||
"""
|
|
||||||
for _ in range(200):
|
|
||||||
port = random.randint(10000, 19999)
|
|
||||||
if port in _PORTS_TAKEN:
|
|
||||||
continue
|
|
||||||
sock = socket.socket()
|
|
||||||
try:
|
|
||||||
sock.bind(("127.0.0.1", port))
|
|
||||||
except OSError:
|
|
||||||
continue
|
|
||||||
finally:
|
|
||||||
sock.close()
|
|
||||||
_PORTS_TAKEN.add(port)
|
|
||||||
return port
|
|
||||||
raise RuntimeError("no free port in the range the suite uses")
|
|
||||||
|
|
||||||
def write_config(self, name, config):
|
def write_config(self, name, config):
|
||||||
path = os.path.join(self.tmpdir, name + ".cfg")
|
path = os.path.join(self.tmpdir, name + ".cfg")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user