mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-26 23:59:41 +08:00
acl: a rule's port may name the service it came through (#665)
A port in a rule's targetportlist may carry a service port after a slash, X-Y/S, or, for any destination, */S: the rule matches only requests that arrived through the service listening on the port S, the port of its proxy -p or socks -p, whatever their destination. The limiters are shared by all the services of a configuration, so this is how a limit is given to the connections of one service alone: connlim 5 60 * * * */1080 denies the sixth concurrent connection of the service on port 1080. The destination port and the service port are both ranges or single ports, a slash with nothing after it is refused, and a rule without a slash is what it always was.
This commit is contained in:
1 parent
a2e400622b
commit
59756eeb62
7 files changed
+144
-14
No files matched your search
@@ -310,6 +310,17 @@ 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 */
|
||||
if(acentry->viaports) {
|
||||
int viaport = ntohs(*SAPORT(¶m->srv->intsa));
|
||||
|
||||
for (portentry = acentry->viaports; portentry; portentry = portentry->next)
|
||||
if(viaport >= portentry->startport && viaport <= portentry->endport) {
|
||||
break;
|
||||
}
|
||||
if(!portentry) return 0;
|
||||
}
|
||||
if(preauth && acentry->ports) {
|
||||
dstdep = 1;
|
||||
}
|
||||
|
||||
+35
-13
@@ -1385,6 +1385,23 @@ int scanipl(unsigned char *arg, struct iplist *dst){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Appends a port or a port range to a list: 0, or 1 for one that is
|
||||
neither, or for want of memory. */
|
||||
static int portadd(struct portlist **head, const char *s){
|
||||
struct portlist **tail;
|
||||
uint16_t start = 0, end = 0;
|
||||
int res;
|
||||
|
||||
for(tail = head; *tail; tail = &(*tail)->next);
|
||||
res = sscanf(s, "%hu-%hu", &start, &end);
|
||||
if(res < 1) return 1;
|
||||
if(!(*tail = malloc(sizeof(struct portlist)))) return 1;
|
||||
(*tail)->next = NULL;
|
||||
(*tail)->startport = start;
|
||||
(*tail)->endport = (res == 1)? start : end;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ace * make_ace (int argc, unsigned char ** argv){
|
||||
struct ace * acl;
|
||||
unsigned char *arg;
|
||||
@@ -1484,24 +1501,29 @@ 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 {
|
||||
if(!acl->ports) {
|
||||
acl->ports = portl = malloc(sizeof(struct portlist));
|
||||
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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
portl->next = malloc(sizeof(struct portlist));
|
||||
portl = portl -> next;
|
||||
if(strcmp((char *)arg, "*")) {
|
||||
if(portadd(&acl->ports, (char *)arg)) {
|
||||
fprintf(stderr, "Invalid port or port range, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
if(!portl) {
|
||||
fprintf(stderr, "No memory for ACL entry, line %d\n", linenum);
|
||||
return(NULL);
|
||||
}
|
||||
memset(portl, 0, sizeof(struct portlist));
|
||||
res = sscanf((char *)arg, "%hu-%hu", &portl->startport, &portl->endport);
|
||||
if(res < 1) {
|
||||
else if(!via) {
|
||||
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 (res == 1) portl->endport = portl->startport;
|
||||
} while((arg = (unsigned char *)strtok((char *)NULL, ",")));
|
||||
}
|
||||
if(argc > 4 && strcmp("*", (char *)argv[4])) {
|
||||
|
||||
@@ -418,6 +418,10 @@ static void * ef_ace_ports(struct node * node){
|
||||
return ((struct ace *)node->value) -> ports;
|
||||
}
|
||||
|
||||
static void * ef_ace_viaports(struct node * node){
|
||||
return ((struct ace *)node->value) -> viaports;
|
||||
}
|
||||
|
||||
static void * ef_ace_chain(struct node * node){
|
||||
return ((struct ace *)node->value) -> chains;
|
||||
}
|
||||
@@ -851,6 +855,7 @@ 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"},
|
||||
{"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"},
|
||||
|
||||
@@ -1221,6 +1221,7 @@ void freeacl(struct ace *ac){
|
||||
for(ipl = ac->src; ipl; ipl = (struct iplist *)itfree(ipl, ipl->next));
|
||||
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(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);
|
||||
|
||||
@@ -413,6 +413,7 @@ struct ace {
|
||||
struct iplist *src, *dst;
|
||||
struct hostname *dstnames;
|
||||
struct portlist *ports;
|
||||
struct portlist *viaports;
|
||||
struct chain *chains;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user