Windows: Add an API for reading a multistring from registry
The _krb5_parse_reg_value_as_string() used to concatenate multi-strings using a space to be compatible with krb5_config_get_strings() and friends. Add a new function that can read a multi-string with an arbitrary delimiter character _krb5_parse_reg_value_as_multi_string().
This commit is contained in:
@@ -40,6 +40,20 @@
|
|||||||
/**
|
/**
|
||||||
* Parse a registry value as a string
|
* Parse a registry value as a string
|
||||||
*
|
*
|
||||||
|
* @see _krb5_parse_reg_value_as_multi_string()
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
_krb5_parse_reg_value_as_string(krb5_context context,
|
||||||
|
HKEY key, const char * valuename,
|
||||||
|
DWORD type, DWORD cb_data)
|
||||||
|
{
|
||||||
|
return _krb5_parse_reg_value_as_multi_string(context, key, valuename,
|
||||||
|
type, cb_data, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a registry value as a multi string
|
||||||
|
*
|
||||||
* The following registry value types are handled:
|
* The following registry value types are handled:
|
||||||
*
|
*
|
||||||
* - REG_DWORD: The decimal string representation is used as the
|
* - REG_DWORD: The decimal string representation is used as the
|
||||||
@@ -50,14 +64,15 @@
|
|||||||
* - REG_EXPAND_SZ: Environment variables in the string are expanded
|
* - REG_EXPAND_SZ: Environment variables in the string are expanded
|
||||||
* and the result is used as the value.
|
* and the result is used as the value.
|
||||||
*
|
*
|
||||||
* - REG_MULTI_SZ: The list of strings is concatenated using a ' ' as
|
* - REG_MULTI_SZ: The list of strings is concatenated using the
|
||||||
* a separator. No quoting is performed.
|
* separator. No quoting is performed.
|
||||||
*
|
*
|
||||||
* Any other value type is rejected.
|
* Any other value type is rejected.
|
||||||
*
|
*
|
||||||
* @param [in]valuename Name of the registry value to be queried
|
* @param [in]valuename Name of the registry value to be queried
|
||||||
* @param [in]type Type of the value. REG_NONE if unknown
|
* @param [in]type Type of the value. REG_NONE if unknown
|
||||||
* @param [in]cbdata Size of value. 0 if unknown.
|
* @param [in]cbdata Size of value. 0 if unknown.
|
||||||
|
* @param [in]separator Separator character for concatenating strings.
|
||||||
*
|
*
|
||||||
* @a type and @a cbdata are only considered valid if both are
|
* @a type and @a cbdata are only considered valid if both are
|
||||||
* specified.
|
* specified.
|
||||||
@@ -67,9 +82,9 @@
|
|||||||
* krb5_set_error_message().
|
* krb5_set_error_message().
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
_krb5_parse_reg_value_as_string(krb5_context context,
|
_krb5_parse_reg_value_as_multi_string(krb5_context context,
|
||||||
HKEY key, const char * valuename,
|
HKEY key, const char * valuename,
|
||||||
DWORD type, DWORD cb_data)
|
DWORD type, DWORD cb_data, char *separator)
|
||||||
{
|
{
|
||||||
LONG rcode = ERROR_MORE_DATA;
|
LONG rcode = ERROR_MORE_DATA;
|
||||||
DWORD cb_alloc;
|
DWORD cb_alloc;
|
||||||
@@ -242,7 +257,7 @@ have_data:
|
|||||||
|
|
||||||
iter += len;
|
iter += len;
|
||||||
if (iter[1] != '\0')
|
if (iter[1] != '\0')
|
||||||
*iter++ = ' ';
|
*iter++ = *separator;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -760,8 +760,8 @@ _krb5_get_default_config_config_files_from_registry()
|
|||||||
|
|
||||||
rcode = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName, 0, KEY_READ, &key);
|
rcode = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName, 0, KEY_READ, &key);
|
||||||
if (rcode == ERROR_SUCCESS) {
|
if (rcode == ERROR_SUCCESS) {
|
||||||
config_file = _krb5_parse_reg_value_as_string(NULL, key, "config",
|
config_file = _krb5_parse_reg_value_as_multi_string(NULL, key, "config",
|
||||||
REG_NONE, 0);
|
REG_NONE, 0, PATH_SEP);
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,8 +770,8 @@ _krb5_get_default_config_config_files_from_registry()
|
|||||||
|
|
||||||
rcode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_READ, &key);
|
rcode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_READ, &key);
|
||||||
if (rcode == ERROR_SUCCESS) {
|
if (rcode == ERROR_SUCCESS) {
|
||||||
config_file = _krb5_parse_reg_value_as_string(NULL, key, "config",
|
config_file = _krb5_parse_reg_value_as_multi_string(NULL, key, "config",
|
||||||
REG_NONE, 0);
|
REG_NONE, 0, PATH_SEP);
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user