summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hostport.c27
-rw-r--r--hostport.h2
-rw-r--r--radsecproxy.c83
-rw-r--r--radsecproxy.h2
4 files changed, 85 insertions, 29 deletions
diff --git a/hostport.c b/hostport.c
index 9360299..238af0e 100644
--- a/hostport.c
+++ b/hostport.c
@@ -173,18 +173,27 @@ int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) {
return 0;
}
-int addhostport(struct list **hostports, char *hostport, char *portdefault, uint8_t prefixok) {
+int addhostport(struct list **hostports, char **hostport, char *portdefault, uint8_t prefixok) {
struct hostportres *hp;
+ int i;
- hp = newhostport(hostport, portdefault, prefixok);
- if (!hp)
- return 0;
- if (!*hostports)
+ if (!*hostports) {
*hostports = list_create();
- if (!*hostports || !list_push(*hostports, hp)) {
- freehostport(hp);
- debug(DBG_ERR, "addhostport: malloc failed");
- return 0;
+ if (!*hostports) {
+ debug(DBG_ERR, "addhostport: malloc failed");
+ return 0;
+ }
+ }
+
+ for (i = 0; hostport[i]; i++) {
+ hp = newhostport(hostport[i], portdefault, prefixok);
+ if (!hp)
+ return 0;
+ if (!list_push(*hostports, hp)) {
+ freehostport(hp);
+ debug(DBG_ERR, "addhostport: malloc failed");
+ return 0;
+ }
}
return 1;
}
diff --git a/hostport.h b/hostport.h
index ff3a309..d28f8ee 100644
--- a/hostport.h
+++ b/hostport.h
@@ -14,7 +14,7 @@ struct hostportres {
};
struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok);
-int addhostport(struct list **hostports, char *hostport, char *portdefault, uint8_t prefixok);
+int addhostport(struct list **hostports, char **hostport, char *portdefault, uint8_t prefixok);
void freehostport(struct hostportres *hp);
void freehostports(struct list *hostports);
int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive);
diff --git a/radsecproxy.c b/radsecproxy.c
index 8df4e1d..79625ca 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -1738,7 +1738,7 @@ void *clientwr(void *arg) {
}
if (!resolvehostports(conf->hostports, conf->pdef->socktype)) {
- debug(DBG_WARN, "failed to resolve host %s port %s", conf->hostsrc ? conf->hostsrc : "(null)", conf->portsrc ? conf->portsrc : "(null)");
+ debug(DBG_WARN, "clientwr: resolve failed");
server->dynstartup = 0;
sleep(900);
goto errexit;
@@ -2470,7 +2470,8 @@ int setttlattr(struct options *opts, char *defaultattr) {
void freeclsrvconf(struct clsrvconf *conf) {
free(conf->name);
- free(conf->hostsrc);
+ if (conf->hostsrc)
+ freegconfmstr(conf->hostsrc);
free(conf->portsrc);
free(conf->secret);
free(conf->tls);
@@ -2519,10 +2520,51 @@ int mergeconfstring(char **dst, char **src) {
return 1;
}
+char **mstringcopy(char **in) {
+ char **out;
+ int n;
+
+ if (!in)
+ return NULL;
+
+ for (n = 0; in[n]; n++);
+ out = malloc((n + 1) * sizeof(char *));
+ if (!out)
+ return NULL;
+ for (n = 0; in[n]; n++) {
+ out[n] = stringcopy(in[n], 0);
+ if (!out[n]) {
+ freegconfmstr(out);
+ return NULL;
+ }
+ }
+ out[n] = NULL;
+ return out;
+}
+
+int mergeconfmstring(char ***dst, char ***src) {
+ char **t;
+
+ if (*src) {
+ *dst = *src;
+ *src = NULL;
+ return 1;
+ }
+ if (*dst) {
+ t = mstringcopy(*dst);
+ if (!t) {
+ debug(DBG_ERR, "malloc failed");
+ return 0;
+ }
+ *dst = t;
+ }
+ return 1;
+}
+
/* assumes dst is a shallow copy */
int mergesrvconf(struct clsrvconf *dst, struct clsrvconf *src) {
if (!mergeconfstring(&dst->name, &src->name) ||
- !mergeconfstring(&dst->hostsrc, &src->hostsrc) ||
+ !mergeconfmstring(&dst->hostsrc, &src->hostsrc) ||
!mergeconfstring(&dst->portsrc, &src->portsrc) ||
!mergeconfstring(&dst->secret, &src->secret) ||
!mergeconfstring(&dst->tls, &src->tls) ||
@@ -2557,7 +2599,7 @@ int confclient_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
if (!getgenericconfig(cf, block,
"type", CONF_STR, &conftype,
- "host", CONF_STR, &conf->hostsrc,
+ "host", CONF_MSTR, &conf->hostsrc,
"secret", CONF_STR, &conf->secret,
#if defined(RADPROT_TLS) || defined(RADPROT_DTLS)
"tls", CONF_STR, &conf->tls,
@@ -2575,9 +2617,14 @@ int confclient_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
debugx(1, DBG_ERR, "configuration error");
conf->name = stringcopy(val, 0);
- if (!conf->hostsrc)
- conf->hostsrc = stringcopy(val, 0);
- if (!conf->name || !conf->hostsrc)
+ if (conf->name && !conf->hostsrc) {
+ conf->hostsrc = malloc(2 * sizeof(char *));
+ if (conf->hostsrc) {
+ conf->hostsrc[0] = stringcopy(val, 0);
+ conf->hostsrc[1] = NULL;
+ }
+ }
+ if (!conf->name || !conf->hostsrc || !conf->hostsrc[0])
debugx(1, DBG_ERR, "malloc failed");
if (!conftype)
@@ -2627,7 +2674,7 @@ int confclient_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
if (!addhostport(&conf->hostports, conf->hostsrc, conf->pdef->portdefault, 1) ||
!resolvehostports(conf->hostports, conf->pdef->socktype))
- debugx(1, DBG_ERR, "failed to resolve %s, exiting", conf->hostsrc ? conf->hostsrc : "(null)");
+ debugx(1, DBG_ERR, "resolve failed, exiting");
if (!conf->secret) {
if (!conf->pdef->secretdefault)
@@ -2685,7 +2732,7 @@ int compileserverconfig(struct clsrvconf *conf, const char *block) {
}
if (!conf->dynamiclookupcommand && !resolvehostports(conf->hostports, conf->pdef->socktype)) {
- debug(DBG_ERR, "resolve host %s port %s, exiting", conf->hostsrc ? conf->hostsrc : "(null)", conf->portsrc ? conf->portsrc : "(null)");
+ debug(DBG_ERR, "resolve failed, exiting");
return 0;
}
return 1;
@@ -2713,7 +2760,7 @@ int confserver_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
if (!getgenericconfig(cf, block,
"type", CONF_STR, &conftype,
- "host", CONF_STR, &conf->hostsrc,
+ "host", CONF_MSTR, &conf->hostsrc,
"port", CONF_STR, &conf->portsrc,
"secret", CONF_STR, &conf->secret,
#if defined(RADPROT_TLS) || defined(RADPROT_DTLS)
@@ -2736,17 +2783,17 @@ int confserver_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
}
conf->name = stringcopy(val, 0);
- if (!conf->name) {
+ if (conf->name && !conf->hostsrc) {
+ conf->hostsrc = malloc(2 * sizeof(char *));
+ if (conf->hostsrc) {
+ conf->hostsrc[0] = stringcopy(val, 0);
+ conf->hostsrc[1] = NULL;
+ }
+ }
+ if (!conf->name || !conf->hostsrc || !conf->hostsrc[0]) {
debug(DBG_ERR, "malloc failed");
goto errexit;
}
- if (!conf->hostsrc) {
- conf->hostsrc = stringcopy(val, 0);
- if (!conf->hostsrc) {
- debug(DBG_ERR, "malloc failed");
- goto errexit;
- }
- }
if (!conftype) {
debug(DBG_ERR, "error in block %s, option type missing", block);
diff --git a/radsecproxy.h b/radsecproxy.h
index 3794272..c06ec07 100644
--- a/radsecproxy.h
+++ b/radsecproxy.h
@@ -79,7 +79,7 @@ struct clsrvconf {
char *name;
uint8_t type; /* RAD_UDP/RAD_TLS/RAD_TCP */
const struct protodefs *pdef;
- char *hostsrc;
+ char **hostsrc;
char *portsrc;
struct list *hostports;
char *secret;