Skip to content

Commit

Permalink
Refine the timing of when the ipbind table is initialized.
Browse files Browse the repository at this point in the history
Turns out there are modules such as `mod_autohost` which will create ipbind
entries _before_ the rest of the core engine adds its entries, such as in
a `core.postparse` event listener.

Which was fine -- until [this commit](proftpd@9d55ce4) unconditionally cleared that ipbind
table, effectively erasing the efforts of such modules.  Oops.

The intent is to ensure that, when searching for relevant ipbind entries, the
table has been properly cleared of any junk values.  Definitely a desirable
starting state.  We just have to be more careful about how we do it.
  • Loading branch information
Castaglia committed Aug 21, 2021
1 parent f769671 commit 11d613b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,25 @@ extern xaset_t *server_list;
extern server_rec *main_server;

static pr_ipbind_t *ipbind_table[PR_BINDINGS_TABLE_SIZE];
static int ipbind_table_initialized = FALSE;

static pool *binding_pool = NULL;
static pr_ipbind_t *ipbind_default_server = NULL,
*ipbind_localhost_server = NULL;

static const char *trace_channel = "binding";

static void trace_ipbind_table(void);

static void init_ipbind_table(void) {
if (ipbind_table_initialized == TRUE) {
return;
}

memset(ipbind_table, 0, sizeof(ipbind_table));
ipbind_table_initialized = TRUE;
}

/* Server cleanup callback function */
static void server_cleanup_cb(void *conn) {
*((conn_t **) conn) = NULL;
Expand Down Expand Up @@ -451,6 +464,9 @@ int pr_ipbind_create(server_rec *server, const pr_netaddr_t *addr,
return -1;
}

/* Ensure the ipbind table has been initialized. */
init_ipbind_table();

i = ipbind_hash_addr(addr);
pr_trace_msg(trace_channel, 29, "hashed address '%s' to index %u",
pr_netaddr_get_ipstr(addr), i);
Expand Down Expand Up @@ -566,6 +582,9 @@ pr_ipbind_t *pr_ipbind_find(const pr_netaddr_t *addr, unsigned int port,
return NULL;
}

/* Ensure the ipbind table has been initialized. */
init_ipbind_table();

i = ipbind_hash_addr(addr);

for (ipbind = ipbind_table[i]; ipbind; ipbind = ipbind->ib_next) {
Expand Down Expand Up @@ -1186,6 +1205,7 @@ void free_bindings(void) {
}

memset(ipbind_table, 0, sizeof(ipbind_table));
ipbind_table_initialized = FALSE;

/* Mark all listening conns as "unclaimed"; any that remaining unclaimed
* after init_bindings() can be closed.
Expand Down Expand Up @@ -1460,7 +1480,8 @@ static int init_standalone_bindings(void) {
server_rec *serv = NULL;
unsigned char *default_server = NULL, is_default = FALSE;

memset(ipbind_table, 0, sizeof(ipbind_table));
/* Ensure the ipbind table has been initialized. */
init_ipbind_table();

/* If a port is set to zero, the address/port is not bound to a socket
* at all.
Expand Down

0 comments on commit 11d613b

Please sign in to comment.