mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-26 23:59:41 +08:00
acl: a rule's port names the service it came through by @, not by a slash
The part after the @ of a port in a rule names the service: by its port, by the address it listens on, or by both, the address in brackets when IPv6 — connlim 5 60 * * * @1080 connlim 5 60 * * * @10.0.0.1:1080 deny * * * @[::1] A slash, as the delimiter of the first take, would have read as a CIDR habit the day a service is named inside an address list, and @ cannot appear in a port or an address. Digits alone are a port, a dashed pair a port range, anything else an address with a port behind a colon; an @ with nothing after it is refused. The destination port before the @ is unchanged, and so is every rule without one.
This commit is contained in:
1 parent
59756eeb62
commit
c099e632c8
7 files changed
+126
-32
No files matched your search
@@ -310,8 +310,16 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
}
|
||||
if(!ipentry && !hstentry) return 0;
|
||||
}
|
||||
/* the service the request came through, by the port it listens on:
|
||||
what the part after the slash of a port in a rule names */
|
||||
/* the service the request came through, by the port it listens on
|
||||
and by its address: what the part after the @ of a port in a
|
||||
rule names */
|
||||
if(acentry->viasrc) {
|
||||
for (ipentry = acentry->viasrc; ipentry; ipentry = ipentry->next)
|
||||
if(IPInentry((struct sockaddr *)¶m->srv->intsa, ipentry)) {
|
||||
break;
|
||||
}
|
||||
if(!ipentry) return 0;
|
||||
}
|
||||
if(acentry->viaports) {
|
||||
int viaport = ntohs(*SAPORT(¶m->srv->intsa));
|
||||
|
||||
|
||||
+71
-12
@@ -1402,6 +1402,59 @@ static int portadd(struct portlist **head, const char *s){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Appends an IP, an IP range or a CIDR to a list: 0, or 1 for one that
|
||||
is none of them, or for want of memory. */
|
||||
static int ipadd(struct iplist **head, const char *s){
|
||||
struct iplist **tail, tmp;
|
||||
|
||||
for(tail = head; *tail; tail = &(*tail)->next);
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
if(scanipl((unsigned char *)s, &tmp)) return 1;
|
||||
if(!(*tail = malloc(sizeof(struct iplist)))) return 1;
|
||||
**tail = tmp;
|
||||
(*tail)->next = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The part after the @ of a port in a rule: the service the request
|
||||
came through, by its port, its address, or both, the address in
|
||||
brackets when IPv6 — 1080, 10.0.0.1, 10.0.0.1:1080, [::1]:1080.
|
||||
Digits alone, or with a dash, are a port or a port range; anything
|
||||
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(!*s) return 1;
|
||||
if(*s == '['){
|
||||
close = (unsigned char *)strchr((char *)s, ']');
|
||||
if(!close || close == s + 1) return 1;
|
||||
*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)){
|
||||
*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 * acl;
|
||||
unsigned char *arg;
|
||||
@@ -1501,16 +1554,10 @@ struct ace * make_ace (int argc, unsigned char ** argv){
|
||||
if(argc > 3 && strcmp("*", (char *)argv[3])) {
|
||||
arg = (unsigned char *)strtok((char *)argv[3], ",");
|
||||
if(arg) do {
|
||||
unsigned char *via = (unsigned char *)strchr((char *)arg, '/');
|
||||
unsigned char *via = (unsigned char *)strchr((char *)arg, '@');
|
||||
|
||||
if(via) {
|
||||
*via++ = 0;
|
||||
if(!*via || !*arg) {
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
if(strcmp((char *)arg, "*")) {
|
||||
if(via) *via++ = 0;
|
||||
if(*arg && strcmp((char *)arg, "*")) {
|
||||
if(portadd(&acl->ports, (char *)arg)) {
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
@@ -1520,9 +1567,21 @@ struct ace * make_ace (int argc, unsigned char ** argv){
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
if(via && portadd(&acl->viaports, (char *)via)) {
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
if(via) {
|
||||
unsigned char *ip, *port;
|
||||
|
||||
if(viasplit(via, &ip, &port)) {
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
if(ip && ipadd(&acl->viasrc, (char *)ip)) {
|
||||
fprintf(stderr, "Invalid IP, IP range or CIDR, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
if(port && portadd(&acl->viaports, (char *)port)) {
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||
}
|
||||
|
||||
+6
-1
@@ -422,6 +422,10 @@ static void * ef_ace_viaports(struct node * node){
|
||||
return ((struct ace *)node->value) -> viaports;
|
||||
}
|
||||
|
||||
static void * ef_ace_viasrc(struct node * node){
|
||||
return ((struct ace *)node->value) -> viasrc;
|
||||
}
|
||||
|
||||
static void * ef_ace_chain(struct node * node){
|
||||
return ((struct ace *)node->value) -> chains;
|
||||
}
|
||||
@@ -855,7 +859,8 @@ static struct property prop_ace[] = {
|
||||
{"dst", ef_ace_dst, TYPE_IPLIST, "list of destination ips"},
|
||||
{"dstnames", ef_ace_dstnames, TYPE_HOSTNAME, "list of destination hostnames"},
|
||||
{"ports", ef_ace_ports, TYPE_PORTLIST, "list of destination ports"},
|
||||
{"viaports", ef_ace_viaports, TYPE_PORTLIST, "list of the services' ports it matches"},
|
||||
{"viaports", ef_ace_viaports, TYPE_PORTLIST, "the services' ports it matches"},
|
||||
{"viasrc", ef_ace_viasrc, TYPE_IPLIST, "the services' addresses it matches"},
|
||||
{"chain", ef_ace_chain, TYPE_CHAIN, "redirect to parent(s)"},
|
||||
{"wdays", ef_ace_weekdays, TYPE_WEEKDAYS, "days of week"},
|
||||
{"periods", ef_ace_period, TYPE_PERIOD, "time of the day"},
|
||||
|
||||
@@ -1222,6 +1222,7 @@ void freeacl(struct ace *ac){
|
||||
for(ipl = ac->dst; ipl; ipl = (struct iplist *)itfree(ipl,ipl->next));
|
||||
for(pl = ac->ports; pl; pl = (struct portlist *)itfree(pl, pl->next));
|
||||
for(pl = ac->viaports; pl; pl = (struct portlist *)itfree(pl, pl->next));
|
||||
for(ipl = ac->viasrc; ipl; ipl = (struct iplist *)itfree(ipl, ipl->next));
|
||||
for(pel = ac->periods; pel; pel = (struct period *)itfree(pel, pel->next));
|
||||
for(ul = ac->users; ul; ul = (struct userlist *)itfree(ul, ul->next)){
|
||||
if(ul->user)free(ul->user);
|
||||
|
||||
@@ -414,6 +414,7 @@ struct ace {
|
||||
struct hostname *dstnames;
|
||||
struct portlist *ports;
|
||||
struct portlist *viaports;
|
||||
struct iplist *viasrc;
|
||||
struct chain *chains;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user