lib:param: Add lpcfg_parse_enum_vals()
authorAndreas Schneider <asn@samba.org>
Wed, 22 Jul 2020 15:48:25 +0000 (17:48 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 19 Aug 2020 16:22:40 +0000 (16:22 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/param/loadparm.c
lib/param/loadparm.h

index 0511bdb41e4f5703478550f82a8765d9f9ab9673..5309561b398bc89ed4c8158aa31f5846de98dea5 100644 (file)
@@ -3678,3 +3678,33 @@ char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
                                             raw_value,
                                             lp_sub->private_data);
 }
+
+/**
+ * @brief Parse a string value of a given parameter to its integer enum value.
+ *
+ * @param[in]  param_name    The parameter name (e.g. 'client smb encrypt')
+ *
+ * @param[in]  param_value   The parameter value (e.g. 'required').
+ *
+ * @return The integer value of the enum the param_value matches or INT32_MIN
+ * on error.
+ */
+int32_t lpcfg_parse_enum_vals(const char *param_name,
+                             const char *param_value)
+{
+       struct parm_struct *parm = NULL;
+       int32_t ret = INT32_MIN;
+       bool ok;
+
+       parm = lpcfg_parm_struct(NULL, param_name);
+       if (parm == NULL) {
+               return INT32_MIN;
+       }
+
+       ok = lp_set_enum_parm(parm, param_value, &ret);
+       if (!ok) {
+               return INT32_MIN;
+       }
+
+       return ret;
+}
index 323fcf84523d39f48c3ea36e7cb9043590a0064d..e66ce2324b46f3d2972904b010d3b0eaa4b140e4 100644 (file)
@@ -316,6 +316,8 @@ bool lp_do_section(const char *pszSectionName, void *userdata);
 bool store_lp_set_cmdline(const char *pszParmName, const char *pszParmValue);
 
 int num_parameters(void);
+int32_t lpcfg_parse_enum_vals(const char *param_name,
+                             const char *param_value);
 
 struct loadparm_substitution;
 #ifdef LOADPARM_SUBSTITUTION_INTERNALS