diff options
author | Pierre Humblet <phumblet@phumblet.no-ip.org> | 2004-12-03 02:00:37 +0000 |
---|---|---|
committer | Pierre Humblet <phumblet@phumblet.no-ip.org> | 2004-12-03 02:00:37 +0000 |
commit | 8151e674bafcd9a4a54caa1cba6685737354cc6b (patch) | |
tree | b2e00e4b4bfbb14c8c1240dbb85d041bd0604a50 /winsup/cygwin/registry.cc | |
parent | 3263f819aa5e0d90a9a7203b3c98156bb4012229 (diff) | |
download | newlib-8151e674bafcd9a4a54caa1cba6685737354cc6b.zip newlib-8151e674bafcd9a4a54caa1cba6685737354cc6b.tar.gz newlib-8151e674bafcd9a4a54caa1cba6685737354cc6b.tar.bz2 |
2004-12-03 Pierre Humblet <pierre.humblet@ieee.org>
* registry.h (reg_key::reg_key): Change arguments.
* shared_info.h (class mount_info): Remove had_to_create_mount_areas.
* registry.cc (reg_key::reg_key): Change constructors to always handle
HKLM and to avoid relying on HKCU.
Do not set mount_table->had_to_create_mount_areas.
* path.cc (mount_info::conv_to_win32_path): Improve update of
sys_mount_table_counter.
(mount_info::read_mounts): Use new reg_key constructor.
(mount_info::add_reg_mount): Ditto.
(mount_info::del_reg_mount): Ditto.
(mount_info::read_cygdrive_info_from_registry): Ditto.
(mount_info::write_cygdrive_info_to_registry): Ditto.
Update cygwin_shared->sys_mount_table_counter after registry update.
(mount_info::get_cygdrive_info): Ditto.
* shared.cc (shared_info::heap_chunk_size): Use new reg_key constructor.
* environ.cc (regopt): Ditto.
Diffstat (limited to 'winsup/cygwin/registry.cc')
-rw-r--r-- | winsup/cygwin/registry.cc | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/winsup/cygwin/registry.cc b/winsup/cygwin/registry.cc index 1ff84b7..d2756a8 100644 --- a/winsup/cygwin/registry.cc +++ b/winsup/cygwin/registry.cc @@ -13,8 +13,12 @@ details. */ #include "registry.h" #include "security.h" #include <cygwin/version.h> - -static char NO_COPY cygnus_class[] = "cygnus"; +#include "path.h" +#include "fhandler.h" +#include "dtable.h" +#include "cygerrno.h" +#include "cygheap.h" +static const char cygnus_class[] = "cygnus"; reg_key::reg_key (HKEY top, REGSAM access, ...) { @@ -24,30 +28,46 @@ reg_key::reg_key (HKEY top, REGSAM access, ...) va_end (av); } -reg_key::reg_key (REGSAM access, ...) +/* Opens a key under the appropriate Cygwin key. + Do not use HKCU per MS KB 199190 */ + +reg_key::reg_key (bool isHKLM, REGSAM access, ...) { va_list av; + HKEY top; - new (this) reg_key (HKEY_CURRENT_USER, access, "SOFTWARE", - CYGWIN_INFO_CYGNUS_REGISTRY_NAME, - CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL); - - HKEY top = key; + if (isHKLM) + top = HKEY_LOCAL_MACHINE; + else + { + char name[128]; + const char *names[2] = {cygheap->user.get_windows_id (name), ".DEFAULT"}; + for (int i = 0; i < 2; i++) + { + key_is_invalid = RegOpenKeyEx (HKEY_USERS, names[i], 0, access, &top); + if (key_is_invalid == ERROR_SUCCESS) + goto OK; + debug_printf ("HKU\\%s failed, Win32 error %ld", names[i], key_is_invalid); + } + return; + } +OK: + new (this) reg_key (top, access, "SOFTWARE", + CYGWIN_INFO_CYGNUS_REGISTRY_NAME, + CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL); + if (top != HKEY_LOCAL_MACHINE) + RegCloseKey (top); + if (key_is_invalid) + return; + + top = key; va_start (av, access); - build_reg (top, KEY_READ, av); + build_reg (top, access, av); va_end (av); if (top != key) RegCloseKey (top); } -reg_key::reg_key (REGSAM access) -{ - new (this) reg_key (HKEY_CURRENT_USER, access, "SOFTWARE", - CYGWIN_INFO_CYGNUS_REGISTRY_NAME, - CYGWIN_INFO_CYGWIN_REGISTRY_NAME, - CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL); -} - void reg_key::build_reg (HKEY top, REGSAM access, va_list av) { @@ -62,16 +82,15 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av) while ((name = va_arg (av, char *)) != NULL) { - DWORD disp; int res = RegCreateKeyExA (r, name, 0, - cygnus_class, + (char *) cygnus_class, REG_OPTION_NON_VOLATILE, access, &sec_none_nih, &key, - &disp); + NULL); if (r != top) RegCloseKey (r); r = key; @@ -81,12 +100,6 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av) debug_printf ("failed to create key %s in the registry", name); break; } - - /* If we're considering the mounts key, check if it had to - be created and set had_to_create appropriately. */ - if (strcmp (name, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME) == 0) - if (disp == REG_CREATED_NEW_KEY) - mount_table->had_to_create_mount_areas++; } } |