Skip to content

Commit 5ecebde

Browse files
committed
Implement auditd network reconfigure
n src/auditd-listen.c, auditd_tcp_listen_reconfigure() updates some network configuration parameters but leaves a FIXME when the TCP listener port or queue changes. Safe Reconfiguration Strategy 1. Enable networking – When tcp_listen_port changes from 0 to a valid port, call auditd_tcp_listen_init() so the daemon begins accepting connections. 2. Disable networking – If a listener is active and the new configuration sets tcp_listen_port to 0, keep the current listener running and log via audit_msg() that disabling networking requires a daemon restart. 3. Port or transport changes – If tcp_listen_port changes to a different port or the transport value changes, log to syslog that a restart is needed because clients cannot discover the new settings. Continue using the existing listener. 4. Queue length changes – If tcp_listen_queue changes while the port stays the same, restart the listener (auditd_tcp_listen_uninit() then auditd_tcp_listen_init()). Notify via audit_msg() that existing connections were dropped and should reconnect. 5. Unchanged settings – Continue updating other parameters (e.g., tcp_client_max_idle) without restarting the listener.
1 parent 4cc7065 commit 5ecebde

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

src/auditd-listen.c

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,34 +1188,70 @@ static void periodic_reconfigure(const struct daemon_conf *config)
11881188
}
11891189

11901190
void auditd_tcp_listen_reconfigure(const struct daemon_conf *nconf,
1191-
struct daemon_conf *oconf)
1191+
struct daemon_conf *oconf)
11921192
{
1193+
struct ev_loop *loop = ev_default_loop(EVFLAG_AUTO);
11931194
use_libwrap = nconf->use_libwrap;
1194-
1195+
11951196
/* Look at network things that do not need restarting */
11961197
if (oconf->tcp_client_min_port != nconf->tcp_client_min_port ||
1197-
oconf->tcp_client_max_port != nconf->tcp_client_max_port ||
1198-
oconf->tcp_max_per_addr != nconf->tcp_max_per_addr) {
1198+
oconf->tcp_client_max_port != nconf->tcp_client_max_port ||
1199+
oconf->tcp_max_per_addr != nconf->tcp_max_per_addr) {
11991200
oconf->tcp_client_min_port = nconf->tcp_client_min_port;
12001201
oconf->tcp_client_max_port = nconf->tcp_client_max_port;
12011202
oconf->tcp_max_per_addr = nconf->tcp_max_per_addr;
12021203
auditd_set_ports(oconf->tcp_client_min_port,
1203-
oconf->tcp_client_max_port,
1204-
oconf->tcp_max_per_addr);
1204+
oconf->tcp_client_max_port,
1205+
oconf->tcp_max_per_addr);
12051206
}
12061207
if (oconf->tcp_client_max_idle != nconf->tcp_client_max_idle) {
12071208
oconf->tcp_client_max_idle = nconf->tcp_client_max_idle;
12081209
periodic_reconfigure(oconf);
12091210
}
1211+
12101212
if (oconf->tcp_listen_port != nconf->tcp_listen_port ||
1211-
oconf->tcp_listen_queue != nconf->tcp_listen_queue) {
1212-
oconf->tcp_listen_port = nconf->tcp_listen_port;
1213-
oconf->tcp_listen_queue = nconf->tcp_listen_queue;
1214-
// FIXME: need to restart the network stuff
1213+
oconf->tcp_listen_queue != nconf->tcp_listen_queue ||
1214+
oconf->transport != nconf->transport) {
1215+
int port_chg = oconf->tcp_listen_port !=
1216+
nconf->tcp_listen_port;
1217+
int queue_chg = oconf->tcp_listen_queue !=
1218+
nconf->tcp_listen_queue;
1219+
int trans_chg = oconf->transport != nconf->transport;
1220+
if (port_chg && oconf->tcp_listen_port == 0 &&
1221+
nconf->tcp_listen_port != 0) {
1222+
audit_msg(LOG_NOTICE,
1223+
"starting TCP listener on %lu",
1224+
nconf->tcp_listen_port);
1225+
oconf->tcp_listen_port = nconf->tcp_listen_port;
1226+
oconf->tcp_listen_queue = nconf->tcp_listen_queue;
1227+
oconf->transport = nconf->transport;
1228+
if (auditd_tcp_listen_init(loop, oconf))
1229+
audit_msg(LOG_ERR, "failed to start listener");
1230+
} else if (port_chg) {
1231+
if (nconf->tcp_listen_port == 0)
1232+
audit_msg(LOG_NOTICE,
1233+
"TCP listener disabled; restart required");
1234+
else
1235+
audit_msg(LOG_NOTICE,
1236+
"tcp_listen_port change requires restart");
1237+
oconf->tcp_listen_port = nconf->tcp_listen_port;
1238+
oconf->tcp_listen_queue = nconf->tcp_listen_queue;
1239+
} else if (trans_chg) {
1240+
audit_msg(LOG_NOTICE,
1241+
"transport change requires restart");
1242+
} else if (queue_chg) {
1243+
audit_msg(LOG_NOTICE,
1244+
"tcp_listen_queue changed - restarting listener");
1245+
auditd_tcp_listen_uninit(loop, oconf);
1246+
oconf->tcp_listen_queue = nconf->tcp_listen_queue;
1247+
if (auditd_tcp_listen_init(loop, oconf))
1248+
audit_msg(LOG_ERR,"failed to restart listener");
1249+
}
12151250
}
1251+
12161252
free((void *)oconf->krb5_principal);
1217-
// Copying the config for now. Should compare if the same
1218-
// and recredential if needed.
1253+
// Copying the config for now. Should compare if the same and
1254+
// recredential if needed.
12191255
oconf->krb5_principal = nconf->krb5_principal;
12201256
}
12211257

0 commit comments

Comments
 (0)