Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2011-04-19 14:02:06 +0400
committerCorinna Vinschen <corinna@vinschen.de>2011-04-19 14:02:06 +0400
commitb18cb86be7509b4125732f2b25ff3a6e5f423fa2 (patch)
tree164ae9a4323b29a4e444114b747a1c12558f8889 /winsup/cygwin/libc
parentcbc26145e8aeb272ae0df172c1dd84be11b75b81 (diff)
* Makefile.in (DLL_IMPORTS): Drop advapi32.dll.
* autoload.cc: Enable autoloading advapi32 functions. * environ.cc (regopt): Use wide char arguments in reg_key functions. * fhandler_console.cc (beep): Ditto. Use WCHAR throughout. * registry.cc (reg_key): Rewrite reg_key class to use native NT registry functions. Use WCHAR string parameters throughout. Use PCWSTR rather than const WCHAR. Drop multibyte char functionality. Drop unused methods. (get_registry_hive_path): Use RtlQueryRegistryValues to fetch path from registry. (load_registry_hive): Drop useless check for user hive being available. Load hive using NtLoadKey. * registry.h: Accommodate above changes. * sched.cc (sched_rr_get_interval): Use wide char arguments in reg_key functions. * shared.cc (init_installation_root): Ditto. (shared_info::init_obcaseinsensitive): Use RtlQueryRegistryValues to fetch obcaseinsensitive value. (shared_info::heap_slop_size): Use wide char arguments in reg_key functions. (shared_info::heap_chunk_size): Ditto. * syscalls.cc (gethostid): Ditto. * winsup.h (__WIDE): Define. (_WIDE): Define. * libc/minires-os-if.c (get_registry_dns_items): Don't fetch values from registry. Just extract them from given UNICODE_STRING parameter. (get_registry_dns): Fetch all registry values at once using RtlQueryRegistryValues.
Diffstat (limited to 'winsup/cygwin/libc')
-rw-r--r--winsup/cygwin/libc/minires-os-if.c91
1 files changed, 55 insertions, 36 deletions
diff --git a/winsup/cygwin/libc/minires-os-if.c b/winsup/cygwin/libc/minires-os-if.c
index 3715c0847..eb788f2c6 100644
--- a/winsup/cygwin/libc/minires-os-if.c
+++ b/winsup/cygwin/libc/minires-os-if.c
@@ -1,6 +1,6 @@
/* minires-os-if.c. Stub synchronous resolver for Cygwin.
- Copyright 2006, 2007, 2008, 2009 Red Hat, Inc.
+ Copyright 2006, 2007, 2008, 2009, 2011 Red Hat, Inc.
Written by Pierre A. Humblet <Pierre.Humblet@ieee.org>
@@ -27,6 +27,9 @@ details. */
#include <windows.h>
#include <iphlpapi.h>
#include <windns.h>
+#include <ntdef.h>
+#include "ntdll.h"
+#include <wchar.h>
/***********************************************************************
* write_record: Translates a Windows DNS record into a compressed record
@@ -291,36 +294,25 @@ done:
*
get_registry_items: returns dns items from the registry
- kHey: Handle to registry key
- KeyValue: key value to read
+ in: Unicode representation of registry value "value".
what: 0 addresses ; 1 search list
***********************************************************************/
-static void get_registry_dns_items(HKEY hKey, LPCTSTR KeyValue,
- res_state statp, int what)
+static void get_registry_dns_items(PUNICODE_STRING in, res_state statp,
+ int what)
{
- DWORD size = 0;
- LONG res;
- LPBYTE list;
int debug = statp->options & RES_DEBUG;
- res = RegQueryValueEx( hKey, KeyValue, NULL, NULL, NULL, &size);
- DPRINTF(debug, "value %s, error %lu (Windows), size %lu\n",
- KeyValue, res, size);
- if ((res == ERROR_SUCCESS) && (size > 1)) {
- if (!(list = (LPBYTE) alloca(size))) {
- DPRINTF(debug, "alloca: %s\n", strerror(errno));
- }
- else if ((res = RegQueryValueEx( hKey, KeyValue, NULL, NULL, list,
- &size )) != ERROR_SUCCESS) {
- DPRINTF(debug, "RegQueryValueEx: error %lu (Windows)\n", res);
- }
- else if (what == 0) { /* Get the addresses */
- BYTE *ap, *srch;
+ if (in->Length) {
+ char list[in->Length];
+ size_t size = wcstombs (list, in->Buffer, in->Length);
+ if (what == 0) { /* Get the addresses */
+ char *ap, *srch;
int numAddresses = 0;
for (ap = list; ap < list + size && *ap; ap = srch) {
/* The separation character can be 0, ' ', or ','. */
- for (srch = ap; *srch && (isdigit(*srch) || *srch == '.' ); srch++);
+ for (srch = ap; *srch && (isdigit((unsigned) *srch) || *srch == '.' );
+ srch++);
*srch++ = 0;
if (numAddresses < DIM(statp->nsaddr_list)) {
DPRINTF(debug, "server \"%s\"\n", ap);
@@ -334,7 +326,7 @@ static void get_registry_dns_items(HKEY hKey, LPCTSTR KeyValue,
statp->nscount = numAddresses;
}
else /* Parse the search line */
- minires_get_search((char *) list, statp);
+ minires_get_search(list, statp);
}
return;
}
@@ -351,25 +343,52 @@ static void get_registry_dns_items(HKEY hKey, LPCTSTR KeyValue,
static void get_registry_dns(res_state statp)
{
- HKEY hKey;
- DWORD res;
- const char *keyName = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
+ NTSTATUS status;
+ const PCWSTR keyName = L"Tcpip\\Parameters";
DPRINTF(statp->options & RES_DEBUG, "key %s\n", keyName);
- if ((res = RegOpenKeyEx( HKEY_LOCAL_MACHINE, keyName, 0,
- KEY_QUERY_VALUE | KEY_READ, &hKey)) != ERROR_SUCCESS) {
- DPRINTF(statp->options & RES_DEBUG, "RegOpenKeyEx: error %lu (Windows)\n", res);
- return;
- }
+ status = RtlCheckRegistryKey (RTL_REGISTRY_SERVICES, keyName);
+ if (!NT_SUCCESS (status))
+ {
+ DPRINTF (statp->options & RES_DEBUG, "RtlCheckRegistryKey: status %p\n",
+ status);
+ return;
+ }
+
+ UNICODE_STRING uns = { 0, 0, NULL };
+ UNICODE_STRING udns = { 0, 0, NULL };
+ UNICODE_STRING usl = { 0, 0, NULL };
+ RTL_QUERY_REGISTRY_TABLE tab[4] = {
+ { NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
+ L"NameServer", &uns, REG_NONE, NULL, 0 },
+ { NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
+ L"DhcpNameServer", &udns, REG_NONE, NULL, 0 },
+ { NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
+ L"SearchList", &usl, REG_NONE, NULL, 0 },
+ };
+
+ status = RtlQueryRegistryValues (RTL_REGISTRY_SERVICES, keyName, tab,
+ NULL, NULL);
+ if (!NT_SUCCESS (status))
+ {
+ DPRINTF (statp->options & RES_DEBUG,
+ "RtlQueryRegistryValues: status %p\n", status);
+ return;
+ }
if (statp->nscount == 0)
- get_registry_dns_items(hKey, "NameServer", statp, 0);
+ get_registry_dns_items(&uns, statp, 0);
if (statp->nscount == 0)
- get_registry_dns_items(hKey, "DhcpNameServer", statp, 0);
+ get_registry_dns_items(&udns, statp, 0);
if (statp->dnsrch[0] == NULL)
- get_registry_dns_items(hKey, "SearchList", statp, 1);
-
- RegCloseKey(hKey);
+ get_registry_dns_items(&usl, statp, 1);
+
+ if (uns.Buffer)
+ RtlFreeUnicodeString (&uns);
+ if (udns.Buffer)
+ RtlFreeUnicodeString (&udns);
+ if (usl.Buffer)
+ RtlFreeUnicodeString (&usl);
return;
}