From: Alan T. DeKok Date: Mon, 29 Jan 2018 18:44:55 +0000 (-0500) Subject: parse ENV subsection before loading modules or threads X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c1e0f80da08cce09bbe5ecb99b06a76b6f4ced6;p=thirdparty%2Ffreeradius-server.git parse ENV subsection before loading modules or threads so that we don't have to set LD_PRELOAD on the command line for stupid libraries --- diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 490be1c4ae4..ec44fbb1336 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -755,6 +755,49 @@ do {\ return -1; } + /* + * Parse environment variables first. + */ + subcs = cf_section_find(cs, "ENV", NULL); + if (subcs) { + char const *attr, *value; + CONF_PAIR *cp; + CONF_ITEM *ci; + + for (ci = cf_item_next(subcs, NULL); + ci != NULL; + ci = cf_item_next(subcs, ci)) { + if (!cf_item_is_pair(ci)) { + cf_log_err(ci, "Unexpected item in ENV section"); + talloc_free(cs); + return -1; + } + + cp = cf_item_to_pair(ci); + if (cf_pair_operator(cp) != T_OP_EQ) { + cf_log_err(ci, "Invalid operator for item in ENV section"); + talloc_free(cs); + return -1; + } + + attr = cf_pair_attr(cp); + value = cf_pair_value(cp); + if (!value) { + if (unsetenv(attr) < 0) { + cf_log_err(ci, "Failed deleting environment variable %s: %s", attr, fr_syserror(errno)); + talloc_free(cs); + return -1; + } + } else { + if (setenv(attr, value, 1) < 0) { + cf_log_err(ci, "Failed setting environment variable %s: %s", attr, fr_syserror(errno)); + talloc_free(cs); + return -1; + } + } + } /* loop over pairs in ENV */ + } /* there's an ENV subsection */ + /* * If there was no log destination set on the command line, * set it now.