summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvenaas <venaas>2007-11-28 14:11:47 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2007-11-28 14:11:47 +0000
commit18592cef57c5a05d97dbdc56df5a1191bce494b0 (patch)
tree4ee4854dfced9db4c40c3d0902d8068c0cd6ef39
parentcbd283e0022dd394799786c6504c85df7fd40b5b (diff)
working include support for individual files
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@199 e88ac4ed-0b26-0410-9574-a7f39faa03bf
-rw-r--r--gconfig.c33
-rw-r--r--gconfig.h2
-rw-r--r--radsecproxy.c20
3 files changed, 35 insertions, 20 deletions
diff --git a/gconfig.c b/gconfig.c
index 05efcec..b286426 100644
--- a/gconfig.c
+++ b/gconfig.c
@@ -56,10 +56,12 @@ FILE *pushgconffile(struct gconffile **cf, const char *path) {
debug(DBG_INFO, "could not read config file %s", path);
return NULL;
}
+ debug(DBG_DBG, "opened config file %s", path);
if (!*cf) {
newcf = malloc(sizeof(struct gconffile) * 2);
if (!newcf)
debugx(1, DBG_ERR, "malloc failed");
+ newcf[1].file = NULL;
newcf[1].path = NULL;
} else {
for (i = 0; (*cf)[i].path; i++);
@@ -80,8 +82,10 @@ FILE *popgconffile(struct gconffile **cf) {
if (!*cf)
return NULL;
for (i = 0; (*cf)[i].path; i++);
- if (i && (*cf)[0].file)
+ if (i && (*cf)[0].file) {
fclose((*cf)[0].file);
+ debug(DBG_DBG, "closing config file %s", (*cf)[0].path);
+ }
if (i < 2) {
free(*cf);
*cf = NULL;
@@ -101,15 +105,23 @@ FILE *popgconffile(struct gconffile **cf) {
* ...
* }
*/
-void getgenericconfig(FILE *f, char *block, ...) {
+void getgenericconfig(struct gconffile **cf, char *block, ...) {
va_list ap;
char line[1024];
/* initialise lots of stuff to avoid stupid compiler warnings */
char *tokens[3], *s, *opt = NULL, *val = NULL, *word, *optval, **str = NULL, ***mstr = NULL;
int type = 0, tcount, conftype = 0, n;
- void (*cbk)(FILE *, char *, char *, char *) = NULL;
-
- while (fgets(line, 1024, f)) {
+
+ void (*cbk)(struct gconffile **, char *, char *, char *) = NULL;
+
+ if (!cf || !*cf || !(*cf)->file)
+ return;
+ for (;;) {
+ if (!fgets(line, 1024, (*cf)->file)) {
+ if (popgconffile(cf))
+ continue;
+ return;
+ }
s = line;
for (tcount = 0; tcount < 3; tcount++) {
s = strtokenquote(s, &tokens[tcount], " \t\r\n", "\"'", tcount ? NULL : "#");
@@ -155,7 +167,12 @@ void getgenericconfig(FILE *f, char *block, ...) {
if (!*val)
debugx(1, DBG_ERR, "configuration error, option %s needs a non-empty value", opt);
-
+
+ if (conftype == CONF_STR && !strcasecmp(opt, "include")) {
+ pushgconffile(cf, val);
+ continue;
+ }
+
va_start(ap, block);
while ((word = va_arg(ap, char *))) {
type = va_arg(ap, int);
@@ -171,7 +188,7 @@ void getgenericconfig(FILE *f, char *block, ...) {
debugx(1, DBG_ERR, "getgeneralconfig: internal parameter error");
break;
case CONF_CBK:
- cbk = va_arg(ap, void (*)(FILE *, char *, char *, char *));
+ cbk = va_arg(ap, void (*)(struct gconffile **, char *, char *, char *));
break;
default:
debugx(1, DBG_ERR, "getgeneralconfig: internal parameter error");
@@ -226,7 +243,7 @@ void getgenericconfig(FILE *f, char *block, ...) {
if (!optval)
debugx(1, DBG_ERR, "malloc failed");
sprintf(optval, "%s %s", opt, val);
- cbk(f, optval, opt, val);
+ cbk(cf, optval, opt, val);
free(optval);
break;
default:
diff --git a/gconfig.h b/gconfig.h
index f580169..11c4000 100644
--- a/gconfig.h
+++ b/gconfig.h
@@ -7,6 +7,6 @@ struct gconffile {
FILE *file;
};
-void getgenericconfig(FILE *f, char *block, ...);
+void getgenericconfig(struct gconffile **cf, char *block, ...);
FILE *pushgconffile(struct gconffile **cf, const char *path);
FILE *popgconffile(struct gconffile **cf);
diff --git a/radsecproxy.c b/radsecproxy.c
index aa01bb9..2f3c99b 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -2523,7 +2523,7 @@ int addrewriteattr(struct clsrvconf *conf, char *rewriteattr) {
return 1;
}
-void confclient_cb(FILE *f, char *block, char *opt, char *val) {
+void confclient_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char *type = NULL, *tls = NULL, *matchcertattr = NULL, *rewriteattr = NULL;
struct clsrvconf *conf;
@@ -2534,7 +2534,7 @@ void confclient_cb(FILE *f, char *block, char *opt, char *val) {
debugx(1, DBG_ERR, "malloc failed");
memset(conf, 0, sizeof(struct clsrvconf));
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"type", CONF_STR, &type,
"host", CONF_STR, &conf->host,
"secret", CONF_STR, &conf->secret,
@@ -2583,7 +2583,7 @@ void confclient_cb(FILE *f, char *block, char *opt, char *val) {
}
}
-void confserver_cb(FILE *f, char *block, char *opt, char *val) {
+void confserver_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char *type = NULL, *tls = NULL, *matchcertattr = NULL, *statusserver = NULL;
struct clsrvconf *conf;
@@ -2594,7 +2594,7 @@ void confserver_cb(FILE *f, char *block, char *opt, char *val) {
debugx(1, DBG_ERR, "malloc failed");
memset(conf, 0, sizeof(struct clsrvconf));
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"type", CONF_STR, &type,
"host", CONF_STR, &conf->host,
"port", CONF_STR, &conf->port,
@@ -2650,12 +2650,12 @@ void confserver_cb(FILE *f, char *block, char *opt, char *val) {
}
}
-void confrealm_cb(FILE *f, char *block, char *opt, char *val) {
+void confrealm_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char **servers = NULL, *msg = NULL;
debug(DBG_DBG, "confrealm_cb called for %s", block);
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"server", CONF_MSTR, &servers,
"ReplyMessage", CONF_STR, &msg,
NULL
@@ -2665,12 +2665,12 @@ void confrealm_cb(FILE *f, char *block, char *opt, char *val) {
free(servers);
}
-void conftls_cb(FILE *f, char *block, char *opt, char *val) {
+void conftls_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char *cacertfile = NULL, *cacertpath = NULL, *certfile = NULL, *certkeyfile = NULL, *certkeypwd = NULL;
debug(DBG_DBG, "conftls_cb called for %s", block);
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"CACertificateFile", CONF_STR, &cacertfile,
"CACertificatePath", CONF_STR, &cacertpath,
"CertificateFile", CONF_STR, &certfile,
@@ -2688,12 +2688,10 @@ void conftls_cb(FILE *f, char *block, char *opt, char *val) {
}
void getmainconfig(const char *configfile) {
- FILE *f;
char *loglevel = NULL;
struct gconffile *cfs;
cfs = openconfigfile(configfile);
- f = cfs->file;
memset(&options, 0, sizeof(options));
clconfs = list_create();
@@ -2712,7 +2710,7 @@ void getmainconfig(const char *configfile) {
if (!tlsconfs)
debugx(1, DBG_ERR, "malloc failed");
- getgenericconfig(f, NULL,
+ getgenericconfig(&cfs, NULL,
"ListenUDP", CONF_STR, &options.listenudp,
"ListenTCP", CONF_STR, &options.listentcp,
"ListenAccountingUDP", CONF_STR, &options.listenaccudp,