* fhandler_registry.cc (DEFAULT_VALUE_NAME): Remove constant.
(encode_regname): Encode empty (default) name to "@". Encode "@" to "%40". Change error return to -1. (decode_regname): Decode "@" to empty name. Decode "%40" to "@". (fhandler_registry::exists): Skip check for keys if name is empty. Remove check for DEFAULT_VALUE_NAME, now handled by decode_regname (). (fhandler_registry::readdir): Remove check for empty name, now handled by encode_regname (). (fhandler_registry::open): Remove check for DEFAULT_VALUE_NAME. (fhandler_registry::open_key): Fail with ENOENT if key name is empty.
This commit is contained in:
parent
1348f65bb9
commit
2cc8b9e014
|
@ -1,3 +1,16 @@
|
||||||
|
2008-12-16 Christian Franke <franke@computer.org>
|
||||||
|
|
||||||
|
* fhandler_registry.cc (DEFAULT_VALUE_NAME): Remove constant.
|
||||||
|
(encode_regname): Encode empty (default) name to "@".
|
||||||
|
Encode "@" to "%40". Change error return to -1.
|
||||||
|
(decode_regname): Decode "@" to empty name. Decode "%40" to "@".
|
||||||
|
(fhandler_registry::exists): Skip check for keys if name is empty.
|
||||||
|
Remove check for DEFAULT_VALUE_NAME, now handled by decode_regname ().
|
||||||
|
(fhandler_registry::readdir): Remove check for empty name, now
|
||||||
|
handled by encode_regname ().
|
||||||
|
(fhandler_registry::open): Remove check for DEFAULT_VALUE_NAME.
|
||||||
|
(fhandler_registry::open_key): Fail with ENOENT if key name is empty.
|
||||||
|
|
||||||
2008-12-15 Corinna Vinschen <corinna@vinschen.de>
|
2008-12-15 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* syscalls.cc (gen_full_path_at): Use isabspath instead of isdirsep
|
* syscalls.cc (gen_full_path_at): Use isabspath instead of isdirsep
|
||||||
|
|
|
@ -75,9 +75,6 @@ static const char *special_dot_files[] =
|
||||||
static const int SPECIAL_DOT_FILE_COUNT =
|
static const int SPECIAL_DOT_FILE_COUNT =
|
||||||
(sizeof (special_dot_files) / sizeof (const char *)) - 1;
|
(sizeof (special_dot_files) / sizeof (const char *)) - 1;
|
||||||
|
|
||||||
/* Name given to default values */
|
|
||||||
static const char *DEFAULT_VALUE_NAME = "@";
|
|
||||||
|
|
||||||
static HKEY open_key (const char *name, REGSAM access, DWORD wow64, bool isValue);
|
static HKEY open_key (const char *name, REGSAM access, DWORD wow64, bool isValue);
|
||||||
|
|
||||||
/* Return true if char must be encoded.
|
/* Return true if char must be encoded.
|
||||||
|
@ -89,30 +86,35 @@ must_encode (char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode special chars in registry key or value name.
|
/* Encode special chars in registry key or value name.
|
||||||
|
* Returns 0: success, -1: error.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
encode_regname (char * dst, const char * src, bool add_val)
|
encode_regname (char * dst, const char * src, bool add_val)
|
||||||
{
|
{
|
||||||
int di = 0;
|
int di = 0;
|
||||||
for (int si = 0; src[si]; si++)
|
if (!src[0])
|
||||||
{
|
dst[di++] = '@'; // Default value.
|
||||||
char c = src[si];
|
else
|
||||||
if (must_encode (c) ||
|
for (int si = 0; src[si]; si++)
|
||||||
(c == '.' && si == 0 && (!src[1] || (src[1] == '.' && !src[2]))))
|
{
|
||||||
{
|
char c = src[si];
|
||||||
if (di + 3 >= NAME_MAX + 1)
|
if (must_encode (c) ||
|
||||||
return ENAMETOOLONG;
|
(si == 0 && ((c == '.' && (!src[1] || (src[1] == '.' && !src[2]))) ||
|
||||||
__small_sprintf (dst + di, "%%%02x", c);
|
(c == '@' && !src[1]))))
|
||||||
di += 3;
|
{
|
||||||
}
|
if (di + 3 >= NAME_MAX + 1)
|
||||||
else
|
return -1;
|
||||||
dst[di++] = c;
|
__small_sprintf (dst + di, "%%%02x", c);
|
||||||
}
|
di += 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dst[di++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
if (add_val)
|
if (add_val)
|
||||||
{
|
{
|
||||||
if (di + 4 >= NAME_MAX + 1)
|
if (di + 4 >= NAME_MAX + 1)
|
||||||
return ENAMETOOLONG;
|
return -1;
|
||||||
memcpy (dst + di, "%val", 4);
|
memcpy (dst + di, "%val", 4);
|
||||||
di += 4;
|
di += 4;
|
||||||
}
|
}
|
||||||
|
@ -129,32 +131,39 @@ decode_regname (char * dst, const char * src, int len = -1)
|
||||||
{
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen (src);
|
len = strlen (src);
|
||||||
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int di = 0;
|
if (len > 4 && !memcmp (src + len - 4, "%val", 4))
|
||||||
for (int si = 0; si < len; si++)
|
|
||||||
{
|
{
|
||||||
char c = src[si];
|
len -= 4;
|
||||||
if (c == '%')
|
res = 1;
|
||||||
{
|
|
||||||
if (si + 4 == len && !memcmp (src + si, "%val", 4))
|
|
||||||
{
|
|
||||||
res = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (si + 2 >= len)
|
|
||||||
return -1;
|
|
||||||
char s[] = {src[si+1], src[si+2], '\0'};
|
|
||||||
char *p;
|
|
||||||
c = strtoul (s, &p, 16);
|
|
||||||
if (!(must_encode (c) ||
|
|
||||||
(c == '.' && si == 0 && (len == 3 || (src[3] == '.' && len == 4)))))
|
|
||||||
return -1;
|
|
||||||
dst[di++] = c;
|
|
||||||
si += 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
dst[di++] = c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int di = 0;
|
||||||
|
if (len == 1 && src[0] == '@')
|
||||||
|
; // Default value.
|
||||||
|
else
|
||||||
|
for (int si = 0; si < len; si++)
|
||||||
|
{
|
||||||
|
char c = src[si];
|
||||||
|
if (c == '%')
|
||||||
|
{
|
||||||
|
if (si + 2 >= len)
|
||||||
|
return -1;
|
||||||
|
char s[] = {src[si+1], src[si+2], '\0'};
|
||||||
|
char *p;
|
||||||
|
c = strtoul (s, &p, 16);
|
||||||
|
if (!(must_encode (c) ||
|
||||||
|
(si == 0 && ((c == '.' && (len == 3 || (src[3] == '.' && len == 4))) ||
|
||||||
|
(c == '@' && len == 3)))))
|
||||||
|
return -1;
|
||||||
|
dst[di++] = c;
|
||||||
|
si += 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dst[di++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
dst[di] = 0;
|
dst[di] = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +273,7 @@ fhandler_registry::exists ()
|
||||||
if (hKey == (HKEY) INVALID_HANDLE_VALUE)
|
if (hKey == (HKEY) INVALID_HANDLE_VALUE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!val_only)
|
if (!val_only && dec_file[0])
|
||||||
{
|
{
|
||||||
while (ERROR_SUCCESS ==
|
while (ERROR_SUCCESS ==
|
||||||
(error = RegEnumKeyEx (hKey, index++, buf, &buf_size,
|
(error = RegEnumKeyEx (hKey, index++, buf, &buf_size,
|
||||||
|
@ -292,8 +301,7 @@ fhandler_registry::exists ()
|
||||||
NULL, NULL))
|
NULL, NULL))
|
||||||
|| (error == ERROR_MORE_DATA))
|
|| (error == ERROR_MORE_DATA))
|
||||||
{
|
{
|
||||||
if ( (buf[0] == '\0' && strcasematch (file, DEFAULT_VALUE_NAME))
|
if (strcasematch (buf, dec_file))
|
||||||
|| strcasematch (buf, dec_file))
|
|
||||||
{
|
{
|
||||||
file_type = -1;
|
file_type = -1;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -501,25 +509,22 @@ retry:
|
||||||
if (dir->__d_position & REG_ENUM_VALUES_MASK)
|
if (dir->__d_position & REG_ENUM_VALUES_MASK)
|
||||||
dir->__d_position += 0x10000;
|
dir->__d_position += 0x10000;
|
||||||
|
|
||||||
if (*buf == 0)
|
{
|
||||||
strcpy (de->d_name, DEFAULT_VALUE_NAME);
|
/* Append "%val" if value name is identical to a previous key name. */
|
||||||
else
|
unsigned h = hash_path_name (1, buf);
|
||||||
{
|
bool add_val = false;
|
||||||
/* Append "%val" if value name is identical to a previous key name. */
|
if (! (dir->__d_position & REG_ENUM_VALUES_MASK))
|
||||||
unsigned h = hash_path_name (1, buf);
|
d_hash (dir)->set (h);
|
||||||
bool add_val = false;
|
else if (d_hash (dir)->is_set (h)
|
||||||
if (! (dir->__d_position & REG_ENUM_VALUES_MASK))
|
&& key_exists ((HKEY) dir->__handle, buf, wow64))
|
||||||
d_hash (dir)->set (h);
|
add_val = true;
|
||||||
else if (d_hash (dir)->is_set (h)
|
|
||||||
&& key_exists ((HKEY) dir->__handle, buf, wow64))
|
|
||||||
add_val = true;
|
|
||||||
|
|
||||||
if (encode_regname (de->d_name, buf, add_val))
|
if (encode_regname (de->d_name, buf, add_val))
|
||||||
{
|
{
|
||||||
buf_size = NAME_MAX + 1;
|
buf_size = NAME_MAX + 1;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir->__d_position & REG_ENUM_VALUES_MASK)
|
if (dir->__d_position & REG_ENUM_VALUES_MASK)
|
||||||
de->d_type = DT_REG;
|
de->d_type = DT_REG;
|
||||||
|
@ -695,11 +700,7 @@ fhandler_registry::open (int flags, mode_t mode)
|
||||||
flags |= O_DIROPEN;
|
flags |= O_DIROPEN;
|
||||||
|
|
||||||
set_io_handle (handle);
|
set_io_handle (handle);
|
||||||
|
value_name = cstrdup (dec_file);
|
||||||
if (strcasematch (dec_file, DEFAULT_VALUE_NAME))
|
|
||||||
value_name = cstrdup ("");
|
|
||||||
else
|
|
||||||
value_name = cstrdup (dec_file);
|
|
||||||
|
|
||||||
if (!(flags & O_DIROPEN) && !fill_filebuf ())
|
if (!(flags & O_DIROPEN) && !fill_filebuf ())
|
||||||
{
|
{
|
||||||
|
@ -852,7 +853,7 @@ open_key (const char *name, REGSAM access, DWORD wow64, bool isValue)
|
||||||
if (*name == 0 && isValue == true)
|
if (*name == 0 && isValue == true)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (val_only)
|
if (val_only || !component[0])
|
||||||
{
|
{
|
||||||
set_errno (ENOENT);
|
set_errno (ENOENT);
|
||||||
if (parentOpened)
|
if (parentOpened)
|
||||||
|
|
Loading…
Reference in New Issue