]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
parse ENV subsection before loading modules or threads
authorAlan T. DeKok <aland@freeradius.org>
Mon, 29 Jan 2018 18:44:55 +0000 (13:44 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 29 Jan 2018 18:44:55 +0000 (13:44 -0500)
so that we don't have to set LD_PRELOAD on the command line
for stupid libraries

src/main/mainconfig.c

index 490be1c4ae4089ac4adbf3ab680f99693262f830..ec44fbb13365e32d7f3eb89fffc4d757b8084bb7 100644 (file)
@@ -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.