]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fixup the dependency code to cache the default sections for version numbers and features
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 14 Sep 2019 00:20:13 +0000 (19:20 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 14 Sep 2019 00:21:50 +0000 (19:21 -0500)
src/lib/server/dependency.c
src/lib/server/dependency.h

index e73220b9e0d6f6bfcfcc8487d484e6ec9c81f073..e77a94306921c521af48239506dcd2797c35170a 100644 (file)
@@ -42,6 +42,8 @@ char const    *radiusd_version_short = RADIUSD_VERSION_STRING;
 #endif
 
 static long ssl_built = OPENSSL_VERSION_NUMBER;
+static CONF_SECTION *default_feature_cs;               //!< Default configuration section to add features to.
+static CONF_SECTION *default_version_cs;               //!< Default configuration section to add features to.
 
 /** Check built and linked versions of OpenSSL match
  *
@@ -265,16 +267,21 @@ int rad_check_lib_magic(uint64_t magic)
  * This allows the user to create configurations that work with
  * across multiple environments.
  *
- * @param cs to add feature pair to.
- * @param name of feature.
- * @param enabled Whether the feature is present/enabled.
+ * @param[in] cs               to add feature pair to. May be NULL
+ *                             in which case the cs passed to
+ *                             dependency_feature_init() is used.
+ * @param[in] name             of feature.
+ * @param[in] enabled          Whether the feature is present/enabled.
  * @return
  *     - 0 on success.
  *     - -1 on failure.
  */
 int dependency_feature_add(CONF_SECTION *cs, char const *name, bool enabled)
 {
-       if (!cs) return -1;
+       if (!cs) cs = default_feature_cs;
+       if (!fr_cond_assert_msg(cs, "dependency_features_init() must be called before calling %s", __FUNCTION__)) {
+               return -1;
+       }
 
        if (!cf_pair_find(cs, name)) {
                CONF_PAIR *cp;
@@ -300,9 +307,11 @@ int dependency_feature_add(CONF_SECTION *cs, char const *name, bool enabled)
  * The version pairs are there primarily to work around defects
  * in libraries or the server.
  *
- * @param cs to add feature pair to.
- * @param name of library or feature.
- * @param version Humanly readable version text.
+ * @param[in] cs               to add feature pair to. May be NULL
+ *                             in which case the cs passed to
+ *                             dependency_feature_init() is used.
+ * @param[in] name             of library or feature.
+ * @param[in] version Humanly  readable version text.
  * @return
  *     - 0 on success.
  *     - -1 on failure.
@@ -311,7 +320,10 @@ int dependency_version_number_add(CONF_SECTION *cs, char const *name, char const
 {
        CONF_PAIR *old;
 
-       if (!cs) return -1;
+       if (!cs) cs = default_version_cs;
+       if (!fr_cond_assert_msg(cs, "dependency_version_numbers_init() must be called before calling %s", __FUNCTION__)) {
+               return -1;
+       }
 
        old = cf_pair_find(cs, name);
        if (!old) {
@@ -338,6 +350,8 @@ int dependency_version_number_add(CONF_SECTION *cs, char const *name, char const
  */
 void dependency_features_init(CONF_SECTION *cs)
 {
+       default_feature_cs = cs;
+
        dependency_feature_add(cs, "accounting",
 #ifdef WITH_ACCOUNTING
                                true
@@ -556,6 +570,8 @@ void dependency_version_numbers_init(CONF_SECTION *cs)
 {
        char buffer[128];
 
+       default_version_cs = cs;
+
        dependency_version_number_add(cs, "freeradius-server", radiusd_version_short);
 
        snprintf(buffer, sizeof(buffer), "%i.%i.*", talloc_version_major(), talloc_version_minor());
index d04eec28e29fdcd0d71ad4449b60f672bb6439e5..f036ecfc13452030c561393ddebb0f4ca3827a07 100644 (file)
@@ -44,7 +44,7 @@ char const    *ssl_version_range(uint32_t low, uint32_t high);
 char const     *ssl_version(void);
 int            dependency_feature_add(CONF_SECTION *cs, char const *name, bool enabled);
 int            dependency_version_number_add(CONF_SECTION *cs, char const *name, char const *version);
-void           dependency_features_init(CONF_SECTION *cs);
+void           dependency_features_init(CONF_SECTION *cs) CC_HINT(nonnull);
 void           dependency_version_numbers_init(CONF_SECTION *cs);
 void           dependency_version_print(void);