feat(daemon): enforce per-module/per-host caps and shared auth lockout
Wire the shared registry into the accept loop (parent claims a slot before fork, blocks SIGCHLD across fork+pid publication, and reclaims the dead child's slot from the SIGCHLD handler so per-module/per-source counts are released even on SIGKILL). The connection child records the selected module and normalized peer IP once the config frame names them: an over-cap module or source is refused at the config gate with an audit log, and a source that exceeded the auth-failure threshold is refused before a SCRAM challenge (the counter is shared across children and cleared on success). The existing global cap and host ACLs are untouched.
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Cross-process daemon registry (daemon_limits.c). Only an opaque pointer is
|
||||
* stored here so the transport layer does not depend on daemon config. */
|
||||
struct DaemonLimitRegistry;
|
||||
|
||||
typedef struct Server {
|
||||
struct sockaddr_storage address;
|
||||
unsigned int address_length;
|
||||
@@ -14,6 +18,7 @@ typedef struct Server {
|
||||
void* ssl_ctx;
|
||||
unsigned int max_connections;
|
||||
volatile unsigned int active_connections;
|
||||
struct DaemonLimitRegistry* limit_registry;
|
||||
} Server;
|
||||
|
||||
typedef struct Client {
|
||||
@@ -48,6 +53,14 @@ Server* server_create(int port);
|
||||
/* Override the listener's connection cap (the global daemon `max connections`
|
||||
* value). A non-positive value is ignored so the default cap stands. */
|
||||
void server_set_max_connections(Server* server, unsigned int max_connections);
|
||||
/* Install the shared per-module / per-source registry used by the accept loop
|
||||
* to reserve a slot for each forked child. NULL disables the accounting (the
|
||||
* global cap and ACLs still apply). */
|
||||
void server_set_limit_registry(Server* server, struct DaemonLimitRegistry* registry);
|
||||
/* Slot reserved for the connection child currently running (set by the parent
|
||||
* before fork, inherited by the child). Returns DAEMON_LIMITS_NO_SLOT (-1)
|
||||
* outside the accept-loop child path. */
|
||||
int transport_tcp_current_slot(void);
|
||||
bool server_listen(Server* server, void (*handler)(int file_descriptor));
|
||||
void server_accept_loop(Server* server, void (*child_fn)(int, void*), void* child_ctx,
|
||||
const char* log_fmt);
|
||||
|
||||
Reference in New Issue
Block a user