mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-26 23:59:41 +08:00
acl: the targetlist names the service by its addresses, too
C/C++ CI Linux / ubuntu-24.04-arm (push) Canceled after 0s
C/C++ CI Linux / ubuntu-latest (push) Canceled after 0s
C/C++ CI MacOS / macos-15 (push) Canceled after 0s
C/C++ CI Windows / windows-2022 (push) Canceled after 0s
C/C++ CI cmake / macos-15 (push) Canceled after 0s
C/C++ CI cmake / ubuntu-24.04-arm (push) Canceled after 0s
C/C++ CI cmake / ubuntu-latest (push) Canceled after 0s
C/C++ CI cmake / windows-2022 (push) Canceled after 0s
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Canceled after 0s
C/C++ CI Linux / ubuntu-24.04-arm (push) Canceled after 0s
C/C++ CI Linux / ubuntu-latest (push) Canceled after 0s
C/C++ CI MacOS / macos-15 (push) Canceled after 0s
C/C++ CI Windows / windows-2022 (push) Canceled after 0s
C/C++ CI cmake / macos-15 (push) Canceled after 0s
C/C++ CI cmake / ubuntu-24.04-arm (push) Canceled after 0s
C/C++ CI cmake / ubuntu-latest (push) Canceled after 0s
C/C++ CI cmake / windows-2022 (push) Canceled after 0s
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Canceled after 0s
One @ in the targetlist and one in the targetportlist delimit the lists of destinations from the lists of the services the request came through — the addresses it listens on in the first, its ports in the second, both sides written as any other list: allow * * 192.168.1.0/24@10.0.0.1 443@1080,1090 matches only requests of the service on 10.0.0.1:1080 or :1090. A side of the @ may be left out: @1080 names a port alone, *@10.0.0.1 an address alone, and an @ with nothing after it is refused; an IPv6 address needs no brackets there, no port follows it. The targetlist and the targetportlist are parsed by the same functions now — ipadd() over scanipl() and portadd() — the chains of inline allocations in make_ace() gone, and with them the mixed form of a service named by an address and a port behind one @, which the two fields make unnecessary.
This commit is contained in:
1 parent
84737399f2
commit
642ef96272
3 files changed
+65
-108
No files matched your search
+16
-10
@@ -936,20 +936,26 @@ quoted or written \fB$$\fR, since a lone dollar outside quotes begins the name
|
|||||||
of a file to include. The same patterns, and the same prefix, are used by the
|
of a file to include. The same patterns, and the same prefix, are used by the
|
||||||
\fBhttp\fR command, see BUILT IN HTTP SERVER. Regular expressions are matched
|
\fBhttp\fR command, see BUILT IN HTTP SERVER. Regular expressions are matched
|
||||||
per request and cost more than a wildmask, which is enough for most rules.
|
per request and cost more than a wildmask, which is enough for most rules.
|
||||||
Targetportlist may contain ports (X) or port ranges lists (X-Y). A port may
|
Targetlist and targetportlist may name, after one @, the service the
|
||||||
carry the service the request came through after an @, as X-Y@S or, for any
|
request came through: the targetlist by the addresses it listens on,
|
||||||
destination, @S: the rule matches only requests that arrived through the
|
the targetportlist by its ports, the lists before and after the @ each
|
||||||
service S — the address it listens on, its port, or both, the address in
|
written as any other —
|
||||||
brackets when IPv6 (@1080, @10.0.0.1, @10.0.0.1:1080, @[::1]:1080). The
|
|
||||||
limiters are shared by all the services, so this is how a limit is given to
|
.br
|
||||||
one service's connections alone, e.g.
|
allow * * 192.168.1.0/24@10.0.0.1 443@1080,1090
|
||||||
|
.br
|
||||||
|
|
||||||
|
matches only requests of the service on 10.0.0.1:1080 or :1090. A side
|
||||||
|
of the @ may be left out: * (any) before it, or nothing after it —
|
||||||
|
@1080 names a port alone, *@10.0.0.1 an address alone, and an @ with
|
||||||
|
nothing after it is refused. An IPv6 address needs no brackets there,
|
||||||
|
for no port follows it. The limiters are shared by all the services,
|
||||||
|
so this is how a limit is given to one service's connections alone:
|
||||||
.br
|
.br
|
||||||
connlim 5 60 * * * @1080
|
connlim 5 60 * * * @1080
|
||||||
.br
|
.br
|
||||||
denies the sixth concurrent connection of the service on port 1080,
|
denies the sixth concurrent connection of the service on port 1080,
|
||||||
whatever it connects to. A comma ends an entry, so several services are
|
whatever it connects to. For any field *
|
||||||
listed by repeating it: *@1080,*@1090 names the two, and a bare
|
|
||||||
@1080,1090 would leave 1090 a destination port. For any field *
|
|
||||||
sign means ANY. If access list is empty it\'s assumed to be
|
sign means ANY. If access list is empty it\'s assumed to be
|
||||||
.br
|
.br
|
||||||
allow *
|
allow *
|
||||||
|
|||||||
+33
-82
@@ -1416,53 +1416,27 @@ static int ipadd(struct iplist **head, const char *s){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The part after the @ of a port in a rule: the service the request
|
/* The part of a field after its one @: the service the request came
|
||||||
came through, by its port, its address, or both, the address in
|
through, named by the addresses it listens on in the targetlist and
|
||||||
brackets when IPv6 — 1080, 10.0.0.1, 10.0.0.1:1080, [::1]:1080.
|
by its ports in the targetportlist, the lists written as any other. */
|
||||||
Digits alone, or with a dash, are a port or a port range; anything
|
static unsigned char * viapart(unsigned char *field, int argi, int argc){
|
||||||
else is an address, with a port behind a colon. 0, or 1 for what is
|
|
||||||
none of these. *ip and *port point into s, or stay NULL. */
|
|
||||||
static int viasplit(unsigned char *s, unsigned char **ip, unsigned char **port){
|
|
||||||
unsigned char *close;
|
|
||||||
|
|
||||||
*ip = *port = NULL;
|
if(argi < argc){
|
||||||
if(!*s) return 1;
|
unsigned char *via = (unsigned char *)strchr((char *)field, '@');
|
||||||
if(*s == '['){
|
|
||||||
close = (unsigned char *)strchr((char *)s, ']');
|
if(via) *via++ = 0;
|
||||||
if(!close || close == s + 1) return 1;
|
return via;
|
||||||
*ip = s + 1;
|
|
||||||
*close = 0;
|
|
||||||
s = close + 1;
|
|
||||||
if(!*s) return 0;
|
|
||||||
if(*s != ':') return 1;
|
|
||||||
s++;
|
|
||||||
if(!*s) return 1;
|
|
||||||
*port = s;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
if(*s != '-' && strspn((char *)s, "0123456789-") == strlen((char *)s)){
|
return NULL;
|
||||||
*port = s;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
close = (unsigned char *)strchr((char *)s, ':');
|
|
||||||
if(close && isnumber(*(close+1))){
|
|
||||||
*close = 0;
|
|
||||||
*ip = s;
|
|
||||||
*port = close + 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*ip = s;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ace * make_ace (int argc, unsigned char ** argv){
|
struct ace * make_ace (int argc, unsigned char ** argv){
|
||||||
struct ace * acl;
|
struct ace * acl;
|
||||||
unsigned char *arg;
|
unsigned char *arg, *via;
|
||||||
struct iplist *ipl=NULL;
|
|
||||||
struct portlist *portl=NULL;
|
|
||||||
struct userlist *userl=NULL;
|
struct userlist *userl=NULL;
|
||||||
struct hostname *hostnamel=NULL;
|
struct hostname *hostnamel=NULL;
|
||||||
int res;
|
struct iplist tmpip={NULL};
|
||||||
|
int arglen;
|
||||||
|
|
||||||
acl = malloc(sizeof(struct ace));
|
acl = malloc(sizeof(struct ace));
|
||||||
if(!acl) return acl;
|
if(!acl) return acl;
|
||||||
@@ -1490,30 +1464,16 @@ struct ace * make_ace (int argc, unsigned char ** argv){
|
|||||||
if(argc > 1 && strcmp("*", (char *)argv[1])) {
|
if(argc > 1 && strcmp("*", (char *)argv[1])) {
|
||||||
arg = (unsigned char *)strtok((char *)argv[1], ",");
|
arg = (unsigned char *)strtok((char *)argv[1], ",");
|
||||||
if(arg) do {
|
if(arg) do {
|
||||||
if(!acl->src) {
|
if(ipadd(&acl->src, (char *)arg)) {
|
||||||
acl->src = ipl = malloc(sizeof(struct iplist));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ipl->next = malloc(sizeof(struct iplist));
|
|
||||||
ipl = ipl -> next;
|
|
||||||
}
|
|
||||||
if(!ipl) {
|
|
||||||
fprintf(stderr, "No memory for ACL entry, line %d\n", linenum);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
memset(ipl, 0, sizeof(struct iplist));
|
|
||||||
if (scanipl(arg, ipl)) {
|
|
||||||
fprintf(stderr, "Invalid IP, IP range or CIDR, line %d\n", linenum);
|
fprintf(stderr, "Invalid IP, IP range or CIDR, line %d\n", linenum);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||||
}
|
}
|
||||||
|
via = viapart(argv[2], 2, argc);
|
||||||
if(argc > 2 && strcmp("*", (char *)argv[2])) {
|
if(argc > 2 && strcmp("*", (char *)argv[2])) {
|
||||||
arg = (unsigned char *)strtok((char *)argv[2], ",");
|
arg = (unsigned char *)strtok((char *)argv[2], ",");
|
||||||
if(arg) do {
|
if(arg) do {
|
||||||
int arglen;
|
|
||||||
struct iplist tmpip={NULL};
|
|
||||||
|
|
||||||
arglen = (int)strlen((char *)arg);
|
arglen = (int)strlen((char *)arg);
|
||||||
if(scanipl(arg, &tmpip)){
|
if(scanipl(arg, &tmpip)){
|
||||||
if(!arglen) continue;
|
if(!arglen) continue;
|
||||||
@@ -1535,54 +1495,45 @@ struct ace * make_ace (int argc, unsigned char ** argv){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if(ipadd(&acl->dst, (char *)arg)) {
|
||||||
if(!acl->dst) {
|
|
||||||
acl->dst = ipl = malloc(sizeof(struct iplist));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ipl->next = malloc(sizeof(struct iplist));
|
|
||||||
ipl = ipl -> next;
|
|
||||||
}
|
|
||||||
if(!ipl) {
|
|
||||||
fprintf(stderr, "No memory for ACL entry, line %d\n", linenum);
|
fprintf(stderr, "No memory for ACL entry, line %d\n", linenum);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
*ipl = tmpip;
|
|
||||||
}
|
}
|
||||||
}while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
}while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||||
}
|
}
|
||||||
|
if(via){
|
||||||
|
if(!*via || !(arg = (unsigned char *)strtok((char *)via, ","))) {
|
||||||
|
fprintf(stderr, "Invalid IP, IP range or CIDR, line %d\n", linenum);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
if(ipadd(&acl->viasrc, (char *)arg)) {
|
||||||
|
fprintf(stderr, "Invalid IP, IP range or CIDR, line %d\n", linenum);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||||
|
}
|
||||||
|
via = viapart(argv[3], 3, argc);
|
||||||
if(argc > 3 && strcmp("*", (char *)argv[3])) {
|
if(argc > 3 && strcmp("*", (char *)argv[3])) {
|
||||||
arg = (unsigned char *)strtok((char *)argv[3], ",");
|
arg = (unsigned char *)strtok((char *)argv[3], ",");
|
||||||
if(arg) do {
|
if(arg) do {
|
||||||
unsigned char *via = (unsigned char *)strchr((char *)arg, '@');
|
|
||||||
|
|
||||||
if(via) *via++ = 0;
|
|
||||||
if(*arg && strcmp((char *)arg, "*")) {
|
|
||||||
if(portadd(&acl->ports, (char *)arg)) {
|
if(portadd(&acl->ports, (char *)arg)) {
|
||||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
}
|
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||||
else if(!via) {
|
|
||||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
|
||||||
return(NULL);
|
|
||||||
}
|
}
|
||||||
if(via){
|
if(via){
|
||||||
unsigned char *ip, *port;
|
if(!*via || !(arg = (unsigned char *)strtok((char *)via, ","))) {
|
||||||
|
|
||||||
if(viasplit(via, &ip, &port)) {
|
|
||||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
if(ip && ipadd(&acl->viasrc, (char *)ip)) {
|
do {
|
||||||
fprintf(stderr, "Invalid IP, IP range or CIDR, line %d\n", linenum);
|
if(portadd(&acl->viaports, (char *)arg)) {
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
if(port && portadd(&acl->viaports, (char *)port)) {
|
|
||||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||||
}
|
}
|
||||||
if(argc > 4 && strcmp("*", (char *)argv[4])) {
|
if(argc > 4 && strcmp("*", (char *)argv[4])) {
|
||||||
|
|||||||
+16
-16
@@ -1,10 +1,10 @@
|
|||||||
"""A port in a rule may name the service the request came through.
|
"""A rule names, after one @, the service the request came through.
|
||||||
|
|
||||||
The rules of the limiters are shared by all the services, so there has
|
The rules of the limiters are shared by all the services, so there has
|
||||||
been no way to limit the connections of one service alone. After an @ a
|
been no way to limit the connections of one service alone. The
|
||||||
port in a rule names that service — by its port, by the address it
|
targetlist names the service after its @ by the addresses it listens
|
||||||
listens on, or by both: @1080, @10.0.0.1, @[::1]:1080 — and, with no
|
on, the targetportlist by its ports — each side written as any other
|
||||||
destination written, any destination. A deny so written closes one
|
list, a side left out standing for any. A deny so written closes one
|
||||||
service, a connlim so written caps one service, and neither touches
|
service, a connlim so written caps one service, and neither touches
|
||||||
another service of the same configuration.
|
another service of the same configuration.
|
||||||
"""
|
"""
|
||||||
@@ -74,13 +74,13 @@ def run(t):
|
|||||||
t.eq(200, result.get("status", 0),
|
t.eq(200, result.get("status", 0),
|
||||||
"and the request the limit waited for finishes whole")
|
"and the request the limit waited for finishes whole")
|
||||||
|
|
||||||
# a service named by its address, and by its address and port
|
# a service named by its address, in the targetlist
|
||||||
if t.has_ipv6():
|
if t.has_ipv6():
|
||||||
fifth, sixth = t.free_port(), t.free_port()
|
fifth, sixth = t.free_port(), t.free_port()
|
||||||
t.start("viaport_ip", f"""
|
t.start("viaport_ip", f"""
|
||||||
log
|
log
|
||||||
auth iponly
|
auth iponly
|
||||||
deny * * * @[::1]
|
deny * * *@::1 *
|
||||||
allow *
|
allow *
|
||||||
proxy -p{fifth} -i127.0.0.1
|
proxy -p{fifth} -i127.0.0.1
|
||||||
proxy -p{sixth} -i::1
|
proxy -p{sixth} -i::1
|
||||||
@@ -92,24 +92,24 @@ def run(t):
|
|||||||
t.ne(200, r.status if r else 0,
|
t.ne(200, r.status if r else 0,
|
||||||
"the service the rule names by its address is refused")
|
"the service the rule names by its address is refused")
|
||||||
|
|
||||||
# an @ with nothing after it is refused
|
# several services named by one rule: the list after the @
|
||||||
out = t.run_config("viaport_bad",
|
|
||||||
"log\nallow * * * 443@\nnot_a_command\n")
|
|
||||||
t.contains(out, "Invalid port or port range",
|
|
||||||
"a service with nothing after the @ is refused")
|
|
||||||
|
|
||||||
# several services in one rule: the entry repeated with each
|
|
||||||
sev1, sev2 = t.free_port(), t.free_port()
|
sev1, sev2 = t.free_port(), t.free_port()
|
||||||
t.start("viaport_both", f"""
|
t.start("viaport_both", f"""
|
||||||
log
|
log
|
||||||
auth iponly
|
auth iponly
|
||||||
deny * * * @{sev1},@{sev2}
|
deny * * * @{sev1},{sev2}
|
||||||
allow *
|
allow *
|
||||||
proxy -p{sev1}
|
proxy -p{sev1}
|
||||||
proxy -p{sev2}
|
proxy -p{sev2}
|
||||||
""", ports=[sev1, sev2])
|
""", ports=[sev1, sev2])
|
||||||
|
|
||||||
t.ne(200, t.http(url, proxy=f"127.0.0.1:{sev1}").status,
|
t.ne(200, t.http(url, proxy=f"127.0.0.1:{sev1}").status,
|
||||||
"the first service a repeated entry names is refused")
|
"the first service the rule names is refused")
|
||||||
t.ne(200, t.http(url, proxy=f"127.0.0.1:{sev2}").status,
|
t.ne(200, t.http(url, proxy=f"127.0.0.1:{sev2}").status,
|
||||||
"and so is the second")
|
"and so is the second")
|
||||||
|
|
||||||
|
# an @ with nothing after it is refused
|
||||||
|
out = t.run_config("viaport_bad",
|
||||||
|
"log\nallow * * * 443@\nnot_a_command\n")
|
||||||
|
t.contains(out, "Invalid port or port range",
|
||||||
|
"a service with nothing after the @ is refused")
|
||||||
Reference in new issue
Block a user