mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
port: a reservation kept only while the configuration in force has it
Once reserved, a port is dropped when a configuration comes in force that neither reserves it anew nor has a service on it: after chroot no reservation can be made again, only the usage of the socket a service takes over keeps it. The reservation of the configuration before no longer waits for its last client to let it go: the reload releases it at once, the socket living on where a service of the new one has claimed it, closing where none has.
This commit is contained in:
1 parent
17306f63f9
commit
eec09dc4e9
4 files changed
+74
-14
No files matched your search
+19
-2
@@ -442,7 +442,9 @@ static int h_threadpool(int argc, unsigned char **argv){
|
||||
/* Reserves a listening socket while the configuration is read: a
|
||||
privileged port is opened before setuid and chroot take the rights
|
||||
away, and a service of the configuration on the same address takes
|
||||
the socket over when it starts. */
|
||||
the socket over when it starts. After chroot no reservation can be
|
||||
made again: a reload keeps the port only while the configuration in
|
||||
force reserves it anew or has a service on it. */
|
||||
static int h_port(int argc, unsigned char **argv){
|
||||
struct portreservation *r;
|
||||
PROXYSOCKADDRTYPE sa;
|
||||
@@ -2461,7 +2463,9 @@ void freeconf(struct extparam *confp){
|
||||
while(confp->reservations){
|
||||
pr = confp->reservations;
|
||||
confp->reservations = pr->next;
|
||||
maindropreserved(pr->listener);
|
||||
/* dropped already at the reload, the configuration after it neither
|
||||
reserving the port nor using it */
|
||||
if(pr->listener) maindropreserved(pr->listener);
|
||||
free(pr);
|
||||
}
|
||||
|
||||
@@ -2610,6 +2614,7 @@ int reload (void){
|
||||
int error = -2;
|
||||
struct extparam *old = conf, *new;
|
||||
struct deferred *d;
|
||||
struct portreservation *pr;
|
||||
|
||||
if(!(new = malloc(sizeof(*new)))) return -1;
|
||||
*new = confdefaults;
|
||||
@@ -2677,6 +2682,18 @@ int reload (void){
|
||||
/* the new services take over the listening sockets of the old ones on
|
||||
the same addresses, which then stop accepting, and start */
|
||||
for(d = deferred; d; d = d->next) mainclaim(d->service);
|
||||
/* A port reserved before setuid and chroot is dropped now, unless the
|
||||
configuration in force reserves it anew or has a service on it:
|
||||
after chroot no reservation can be made again, only the usage of
|
||||
the socket a service takes over keeps it */
|
||||
for(pr = old->reservations; pr; pr = pr->next){
|
||||
struct portreservation *pn;
|
||||
|
||||
for(pn = new->reservations; pn; pn = pn->next) if(pn->listener == pr->listener) break;
|
||||
if(pn) continue;
|
||||
maindropreserved(pr->listener);
|
||||
pr->listener = NULL;
|
||||
}
|
||||
old->paused++;
|
||||
while((d = deferred)){
|
||||
deferred = d->next;
|
||||
|
||||
+8
-6
@@ -545,12 +545,14 @@ static void slotrelease(struct srvparam *srv){
|
||||
/* The port command: the listening socket opened here, at the time the
|
||||
configuration is read, while the rights to open a privileged port may
|
||||
still be had — before setuid and chroot. A service of the configuration
|
||||
on the same address, with the same bind-time options, takes the socket
|
||||
over when it starts; a reservation no service takes keeps the port until
|
||||
the configuration is left. A reservation of the configuration before
|
||||
already holds the port: its socket is shared, both reservations dropping
|
||||
their hold with the configuration that made them. NULL if the socket
|
||||
cannot be opened. */
|
||||
on the same address, of the same type, takes the socket over when it
|
||||
starts; a port no service takes stays reserved while the configuration
|
||||
in force has it: a reload drops it unless the new configuration
|
||||
reserves it anew or a service of it claims it — after chroot only the
|
||||
usage of the socket keeps it. A reservation of the configuration
|
||||
before already holds the port: its socket is shared, the holds dropped
|
||||
when the configurations that made them are left or a reload without
|
||||
a claim on it comes. NULL if the socket cannot be opened. */
|
||||
void * mainreserve(int isudp, PROXYSOCKADDRTYPE *sa, const struct sockoptset *opts, int maxseg){
|
||||
struct listener *l, *nl;
|
||||
SOCKET sock;
|
||||
|
||||
Reference in new issue
Block a user