From 7cd6676786dccdd58ddb866b5b455317b1f2eb6c Mon Sep 17 00:00:00 2001 From: Fabian Mauchle Date: Fri, 30 Apr 2021 13:09:44 +0200 Subject: [PATCH] add timeout for dynamic lookup --- radsecproxy.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/radsecproxy.c b/radsecproxy.c index ca160aa..eb9fd79 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -2125,10 +2126,12 @@ struct realm *adddynamicrealmserver(struct realm *realm, char *id) { } int dynamicconfig(struct server *server) { - int ok, fd[2], status; + int ok = 0, fd[2], status; pid_t pid; struct clsrvconf *conf = server->conf; struct gconffile *cf = NULL; + struct pollfd fds[1]; + FILE *pipein; /* for now we only learn hostname/address */ debug(DBG_DBG, "dynamicconfig: need dynamic server config for %s", server->dynamiclookuparg); @@ -2156,10 +2159,20 @@ int dynamicconfig(struct server *server) { } close(fd[1]); - pushgconffile(&cf, fdopen(fd[0], "r"), conf->dynamiclookupcommand); - ok = getgenericconfig(&cf, NULL, "Server", CONF_CBK, confserver_cb, - (void *) conf, NULL); - freegconf(&cf); + pipein = fdopen(fd[0], "r"); + fds[0].fd = fd[0]; + fds[0].events = POLLIN; + status = poll(fds, 1, 5000); + if (status < 0) { + debugerrno(errno, DBG_ERR, "dynamicconfig: error while waiting for command output"); + } else if (status ==0) { + debug(DBG_WARN, "dynamicconfig: command did not return anything in time"); + kill(pid, SIGKILL); + } else { + pushgconffile(&cf, pipein, conf->dynamiclookupcommand); + ok = getgenericconfig(&cf, NULL, "Server", CONF_CBK, confserver_cb, (void *) conf, NULL); + freegconf(&cf); + } if (waitpid(pid, &status, 0) < 0) { debugerrno(errno, DBG_ERR, "dynamicconfig: wait error");