/*********************************************************************** * get_use_dns_option */ static BOOL get_use_dns_option(void) { static const WCHAR NetworkW[] = {'S','o','f','t','w','a','r','e','\\', 'W','i','n','e','\\','N','e','t','w','o','r','k',0}; static const WCHAR UseDNSW[] = {'U','s','e','D','n','s','C','o','m','p','u','t','e','r','N','a','m','e',0}; char tmp[80]; HANDLE root, hkey; DWORD dummy; OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; BOOL ret = TRUE; _init_attr( &attr, &nameW ); RtlOpenCurrentUser( KEY_READ, &root ); attr.RootDirectory = root; RtlInitUnicodeString( &nameW, NetworkW ); /* @@ Wine registry key: HKCU\Software\Wine\Network */ if (!NtOpenKey( &hkey, KEY_READ, &attr )) { RtlInitUnicodeString( &nameW, UseDNSW ); if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) { WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; ret = IS_OPTION_TRUE( str[0] ); } NtClose( hkey ); } NtClose( root ); return ret; }
/*************************************************************************** * get_standard_key * * Return a handle to the standard DllOverrides registry section. */ static HANDLE get_standard_key(void) { static const WCHAR DllOverridesW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\', 'D','l','l','O','v','e','r','r','i','d','e','s',0}; static HANDLE std_key = (HANDLE)-1; if (std_key == (HANDLE)-1) { OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; HANDLE root; RtlOpenCurrentUser( KEY_ALL_ACCESS, &root ); attr.Length = sizeof(attr); attr.RootDirectory = root; attr.ObjectName = &nameW; attr.Attributes = 0; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; RtlInitUnicodeString( &nameW, DllOverridesW ); /* @@ Wine registry key: HKCU\Software\Wine\DllOverrides */ if (NtOpenKey( &std_key, KEY_ALL_ACCESS, &attr )) std_key = 0; NtClose( root ); } return std_key; }
/*********************************************************************** * RELAY16_InitDebugLists * * Build the relay include/exclude function lists. */ void RELAY16_InitDebugLists(void) { OBJECT_ATTRIBUTES attr; UNICODE_STRING name; char buffer[1024]; HANDLE root, hkey; DWORD count; WCHAR *str; static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\', 'W','i','n','e','\\', 'D','e','b','u','g',0}; static const WCHAR RelayIncludeW[] = {'R','e','l','a','y','I','n','c','l','u','d','e',0}; static const WCHAR RelayExcludeW[] = {'R','e','l','a','y','E','x','c','l','u','d','e',0}; static const WCHAR SnoopIncludeW[] = {'S','n','o','o','p','I','n','c','l','u','d','e',0}; static const WCHAR SnoopExcludeW[] = {'S','n','o','o','p','E','x','c','l','u','d','e',0}; RtlOpenCurrentUser( KEY_READ, &root ); attr.Length = sizeof(attr); attr.RootDirectory = root; attr.ObjectName = &name; attr.Attributes = 0; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; RtlInitUnicodeString( &name, configW ); /* @@ Wine registry key: HKCU\Software\Wine\Debug */ if (NtOpenKey( &hkey, KEY_READ, &attr )) hkey = 0; NtClose( root ); if (!hkey) return; str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)buffer)->Data; RtlInitUnicodeString( &name, RelayIncludeW ); if (!NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(buffer), &count )) { debug_relay_includelist = build_list( str ); } RtlInitUnicodeString( &name, RelayExcludeW ); if (!NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(buffer), &count )) { debug_relay_excludelist = build_list( str ); } RtlInitUnicodeString( &name, SnoopIncludeW ); if (!NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(buffer), &count )) { debug_snoop_includelist = build_list( str ); } RtlInitUnicodeString( &name, SnoopExcludeW ); if (!NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(buffer), &count )) { debug_snoop_excludelist = build_list( str ); } NtClose( hkey ); }
NTSTATUS NTAPI ExpSetCurrentUserUILanguage(IN PWSTR MuiName, IN LANGID LanguageId) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"Control Panel\\Desktop"); UNICODE_STRING ValueName; WCHAR ValueBuffer[8]; ULONG ValueLength; HANDLE UserHandle; HANDLE KeyHandle; NTSTATUS Status; PAGED_CODE(); /* Setup the key name */ RtlInitUnicodeString(&ValueName, MuiName); /* Open the use key */ Status = RtlOpenCurrentUser(KEY_WRITE, &UserHandle); if (!NT_SUCCESS(Status)) return Status; /* Initialize the attributes */ InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, UserHandle, NULL); /* Open the key */ Status = ZwOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); if (NT_SUCCESS(Status)) { /* Setup the value name */ ValueLength = swprintf(ValueBuffer, L"%04lX", (ULONG)LanguageId); /* Set the length for the call and set the value */ ValueLength = (ValueLength + 1) * sizeof(WCHAR); Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, ValueBuffer, ValueLength); /* Close the handle for this key */ ZwClose(KeyHandle); } /* Close the user key and return status */ ZwClose(UserHandle); return Status; }
/*************************************************************************** * get_app_key * * Get the registry key for the app-specific DllOverrides list. */ static HANDLE get_app_key( const WCHAR *app_name ) { OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; HANDLE root; WCHAR *str; static const WCHAR AppDefaultsW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\', 'A','p','p','D','e','f','a','u','l','t','s','\\',0}; static const WCHAR DllOverridesW[] = {'\\','D','l','l','O','v','e','r','r','i','d','e','s',0}; static HANDLE app_key = (HANDLE)-1; if (app_key != (HANDLE)-1) return app_key; str = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(AppDefaultsW) + sizeof(DllOverridesW) + strlenW(app_name) * sizeof(WCHAR) ); if (!str) return 0; strcpyW( str, AppDefaultsW ); strcatW( str, app_name ); strcatW( str, DllOverridesW ); RtlOpenCurrentUser( KEY_ALL_ACCESS, &root ); attr.Length = sizeof(attr); attr.RootDirectory = root; attr.ObjectName = &nameW; attr.Attributes = 0; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; RtlInitUnicodeString( &nameW, str ); /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DllOverrides */ if (NtOpenKey( &app_key, KEY_ALL_ACCESS, &attr )) app_key = 0; NtClose( root ); RtlFreeHeap( GetProcessHeap(), 0, str ); return app_key; }
/* IO_pp_init * * Read the ppdev entries from wine.conf, open the device and check * for necessary IOCTRL * Report verbose about possible errors */ char IO_pp_init(void) { char name[80]; char buffer[256]; HANDLE root, hkey; int i,idx=0,fd,res,userbase,nports=0; char * timeout; char ret=1; int lasterror; OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\', 'W','i','n','e','\\','V','D','M','\\','p','p','d','e','v',0}; TRACE("\n"); RtlOpenCurrentUser( KEY_ALL_ACCESS, &root ); attr.Length = sizeof(attr); attr.RootDirectory = root; attr.ObjectName = &nameW; attr.Attributes = 0; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; RtlInitUnicodeString( &nameW, configW ); /* @@ Wine registry key: HKCU\Software\Wine\VDM\ppdev */ if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) hkey = 0; NtClose( root ); if (!hkey) return 1; for (;;) { DWORD total_size, len; char temp[256]; KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)temp; if (NtEnumerateValueKey( hkey, idx, KeyValueFullInformation, temp, sizeof(temp), &total_size )) break; if (info->Type != REG_SZ) break; RtlUnicodeToMultiByteN( name, sizeof(name)-1, &len, info->Name, info->NameLength ); name[len] = 0; RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)(temp + info->DataOffset), total_size-info->DataOffset ); buffer[len] = 0; idx++; if(nports >4) { FIXME("Make the PPDeviceList larger than 5 elements\n"); break; } TRACE("Device '%s' at virtual userbase '%s'\n", buffer,name); timeout = strchr(buffer,','); if (timeout) *timeout++=0; fd=open(buffer,O_RDWR); lasterror=errno; if (fd == -1) { WARN("Configuration: No access to %s Cause: %s\n",buffer,strerror(lasterror)); WARN("Rejecting configuration item\n"); if (lasterror == ENODEV) ERR("Is the ppdev module loaded?\n"); continue; } userbase = strtol(name, NULL, 16); if ( errno == ERANGE) { WARN("Configuration: Invalid base %s for %s\n",name,buffer); WARN("Rejecting configuration item\n"); continue; } if (ioctl (fd,PPCLAIM,0)) { ERR("PPCLAIM rejected %s\n",buffer); ERR("Perhaps the device is already in use or nonexistent\n"); continue; } if (nports > 0) { for (i=0; i<= nports; i++) { if (PPDeviceList[i].userbase == userbase) { WARN("Configuration: %s uses the same virtual ports as %s\n", buffer,PPDeviceList[0].devicename); WARN("Configuration: Rejecting configuration item\n"); userbase = 0; break; } } if (!userbase) continue; } /* Check for the minimum required IOCTLS */ if ((ioctl(fd,PPRDATA,&res))|| (ioctl(fd,PPRSTATUS,&res))|| (ioctl(fd,PPRCONTROL,&res))) { ERR("PPUSER IOCTL not available for parport device %s\n",buffer); continue; } if (ioctl (fd,PPRELEASE,0)) { ERR("PPRELEASE rejected %s\n",buffer); ERR("Perhaps the device is already in use or nonexistent\n"); continue; } PPDeviceList[nports].devicename = malloc(sizeof(buffer)+1); if (!PPDeviceList[nports].devicename) { ERR("No (more) space for devicename\n"); break; } strcpy(PPDeviceList[nports].devicename,buffer); PPDeviceList[nports].fd = fd; PPDeviceList[nports].userbase = userbase; PPDeviceList[nports].lastaccess=GetTickCount(); if (timeout) { PPDeviceList[nports].timeout = strtol(timeout, NULL, 10); if (errno == ERANGE) { WARN("Configuration: Invalid timeout %s in configuration for %s, Setting to 0\n", timeout,buffer); PPDeviceList[nports].timeout = 0; } } else PPDeviceList[nports].timeout = 0; nports++; } TRACE("found %d ports\n",nports); NtClose( hkey ); PPDeviceNum= nports; if (nports > 1) /* sort in ascending order for userbase for faster access */ qsort (PPDeviceList,PPDeviceNum,sizeof(PPDeviceStruct),IO_pp_sort); if (nports) ret=0; for (idx= 0;idx<PPDeviceNum; idx++) TRACE("found device %s userbase %x fd %x timeout %d\n", PPDeviceList[idx].devicename, PPDeviceList[idx].userbase, PPDeviceList[idx].fd,PPDeviceList[idx].timeout); /* FIXME: register a timer callback perhaps every 30 seconds to release unused ports Set lastaccess = 0 as indicator when port was released */ return ret; }
BOOLEAN ConCfgOpenUserSettings(LPCWSTR ConsoleTitle, PHKEY hSubKey, REGSAM samDesired, BOOLEAN Create) { BOOLEAN RetVal = TRUE; NTSTATUS Status; WCHAR szBuffer[MAX_PATH] = L"Console\\"; WCHAR szBuffer2[MAX_PATH] = L""; HKEY hKey; // CurrentUserKeyHandle /* * Console properties are stored under the HKCU\Console\* key. * * We use the original console title as the subkey name for storing * console properties. We need to distinguish whether we were launched * via the console application directly or via a shortcut. * * If the title of the console corresponds to a path (more precisely, * if the title is of the form: C:\ReactOS\<some_path>\<some_app.exe>), * then use the corresponding unexpanded path and with the backslashes * replaced by underscores, to make the registry happy, * i.e. %SystemRoot%_<some_path>_<some_app.exe> */ /* Open the per-user registry key where the console properties are saved */ Status = RtlOpenCurrentUser(/*samDesired*/MAXIMUM_ALLOWED, (PHANDLE)&/*CurrentUserKeyHandle*/hKey); if (!NT_SUCCESS(Status)) { DPRINT1("RtlOpenCurrentUser failed, Status = 0x%08lx\n", Status); SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } /* * Try to open properties via the console title: * to make the registry happy, replace all the * backslashes by underscores. */ TranslateConsoleName(szBuffer2, ConsoleTitle, MAX_PATH); /* Create the registry path */ wcsncat(szBuffer, szBuffer2, MAX_PATH - wcslen(szBuffer) - 1); /* Create or open the registry key */ if (Create) { /* Create the key */ RetVal = (RegCreateKeyExW(hKey, szBuffer, 0, NULL, REG_OPTION_NON_VOLATILE, samDesired, NULL, hSubKey, NULL) == ERROR_SUCCESS); } else { /* Open the key */ RetVal = (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS); } /* Close the parent key and return success or not */ NtClose(hKey); return RetVal; }
NTSTATUS NTAPI ExpGetCurrentUserUILanguage(IN PWSTR MuiName, OUT LANGID* LanguageId) { UCHAR ValueBuffer[256]; PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"Control Panel\\International"); UNICODE_STRING ValueName; UNICODE_STRING ValueString; ULONG ValueLength; ULONG Value; HANDLE UserKey; HANDLE KeyHandle; NTSTATUS Status; PAGED_CODE(); /* Setup the key name */ RtlInitUnicodeString(&ValueName, MuiName); /* Open the use key */ Status = RtlOpenCurrentUser(KEY_READ, &UserKey); if (!NT_SUCCESS(Status)) return Status; /* Initialize the attributes and open the key */ InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, UserKey, NULL); Status = ZwOpenKey(&KeyHandle, KEY_QUERY_VALUE,&ObjectAttributes); if (NT_SUCCESS(Status)) { /* Set buffer and query the current value */ ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer; Status = ZwQueryValueKey(KeyHandle, &ValueName, KeyValuePartialInformation, ValueBuffer, sizeof(ValueBuffer), &ValueLength); if (NT_SUCCESS(Status)) { /* Success, is the value the right type? */ if (ValueInfo->Type == REG_SZ) { /* It is. Initialize the data and convert it */ RtlInitUnicodeString(&ValueString, (PWSTR)ValueInfo->Data); Status = RtlUnicodeStringToInteger(&ValueString, 16, &Value); if (NT_SUCCESS(Status)) { /* Return the language */ *LanguageId = (USHORT)Value; } } else { /* Fail */ Status = STATUS_UNSUCCESSFUL; } /* Close the key */ ZwClose(KeyHandle); } } /* Close the user key and return */ ZwClose(UserKey); return Status; }
NTSTATUS NTAPI NtSetDefaultLocale(IN BOOLEAN UserProfile, IN LCID DefaultLocaleId) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; UNICODE_STRING LocaleString; HANDLE KeyHandle; ULONG ValueLength; WCHAR ValueBuffer[20]; HANDLE UserKey; NTSTATUS Status; UCHAR KeyValueBuffer[256]; PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation; PAGED_CODE(); /* Check if we have a profile */ if (UserProfile) { /* Open the user's key */ Status = RtlOpenCurrentUser(KEY_WRITE, &UserKey); if (!NT_SUCCESS(Status)) return(Status); /* Initialize the registry location */ RtlInitUnicodeString(&KeyName, L"Control Panel\\International"); RtlInitUnicodeString(&ValueName, L"Locale"); } else { /* Initialize the system registry location */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet" L"\\Control\\Nls\\Language"); RtlInitUnicodeString(&ValueName, L"Default"); UserKey = NULL; } /* Initailize the object attributes */ InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, UserKey, NULL); /* Check if we don't have a default locale yet */ if (!DefaultLocaleId) { /* Open the key for reading */ Status = ZwOpenKey(&KeyHandle, KEY_QUERY_VALUE, &ObjectAttributes); if (!NT_SUCCESS(Status)) { KeyHandle = NULL; goto Cleanup; } /* Query the key value */ KeyValueInformation = (PKEY_VALUE_PARTIAL_INFORMATION)KeyValueBuffer; Status = ZwQueryValueKey(KeyHandle, &ValueName, KeyValuePartialInformation, KeyValueInformation, sizeof(KeyValueBuffer), &ValueLength); if (!NT_SUCCESS(Status)) { goto Cleanup; } /* Check if this is a REG_DWORD */ if ((KeyValueInformation->Type == REG_DWORD) && (KeyValueInformation->DataLength == sizeof(ULONG))) { /* It contains the LCID as a DWORD */ DefaultLocaleId = *((ULONG*)KeyValueInformation->Data); } /* Otherwise check for a REG_SZ */ else if (KeyValueInformation->Type == REG_SZ) { /* Initialize a unicode string from the value data */ LocaleString.Buffer = (PWCHAR)KeyValueInformation->Data; LocaleString.Length = (USHORT)KeyValueInformation->DataLength; LocaleString.MaximumLength = LocaleString.Length; /* Convert the hex string to a number */ RtlUnicodeStringToInteger(&LocaleString, 16, &DefaultLocaleId); } else { Status = STATUS_UNSUCCESSFUL; } } else { /* Otherwise, open the key */ Status = ZwOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); if (NT_SUCCESS(Status)) { /* Check if we had a profile */ if (UserProfile) { /* Fill in the buffer */ ValueLength = swprintf(ValueBuffer, L"%08lx", (ULONG)DefaultLocaleId); } else { /* Fill in the buffer */ ValueLength = swprintf(ValueBuffer, L"%04lx", (ULONG)DefaultLocaleId & 0xFFFF); } /* Set the length for the registry call */ ValueLength = (ValueLength + 1) * sizeof(WCHAR); /* Now write the actual value */ Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, ValueBuffer, ValueLength); } } Cleanup: /* Close the locale key */ if (KeyHandle) { ObCloseHandle(KeyHandle, KernelMode); } /* Close the user key */ if (UserKey) { ObCloseHandle(UserKey, KernelMode); } /* Check for success */ if (NT_SUCCESS(Status)) { /* Check if it was for a user */ if (UserProfile) { /* Set the session wide thread locale */ MmSetSessionLocaleId(DefaultLocaleId); } else { /* Set system locale */ PsDefaultSystemLocaleId = DefaultLocaleId; } } /* Return status */ return Status; }
VOID LinkGetRegistryValues( LPWSTR ConsoleTitle, LPLNKPROPNTCONSOLE lpCon ) /*++ Routine Description: This routine reads in values from the registry and places them in the supplied structure. Arguments: pStateInfo - optional pointer to structure to receive information Return Value: current page number --*/ { HKEY hCurrentUserKey; HKEY hConsoleKey; HKEY hTitleKey; NTSTATUS Status; LPWSTR TranslatedTitle; DWORD dwValue; DWORD i; WCHAR awchFaceName[LF_FACESIZE]; WCHAR awchBuffer[ 16 ]; // // Impersonate the client process // if (!CsrImpersonateClient(NULL)) { KdPrint(("CONSRV: GetRegistryValues Impersonate failed\n")); return; } // // Open the current user registry key // Status = RtlOpenCurrentUser(MAXIMUM_ALLOWED, &hCurrentUserKey); if (!NT_SUCCESS(Status)) { CsrRevertToSelf(); return; } // // Open the console registry key // Status = MyRegOpenKey(hCurrentUserKey, CONSOLE_REGISTRY_STRING, &hConsoleKey); if (!NT_SUCCESS(Status)) { NtClose(hCurrentUserKey); CsrRevertToSelf(); return; } // // If there is no structure to fill out, just bail out // if (!lpCon) goto CloseKeys; // // Open the console title subkey, if there is one // if (ConsoleTitle && (*ConsoleTitle != L'\0')) { TranslatedTitle = TranslateConsoleTitle(ConsoleTitle); if (TranslatedTitle == NULL) goto GetDefaultConsole; Status = MyRegOpenKey( hConsoleKey, TranslatedTitle, &hTitleKey); HeapFree(pConHeap,0,TranslatedTitle); if (!NT_SUCCESS(Status)) goto GetDefaultConsole; } else { GetDefaultConsole: hTitleKey = hConsoleKey; } // // Initial screen fill // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_FILLATTR, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->wFillAttribute = (WORD)dwValue; } // // Initial popup fill // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_POPUPATTR, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->wPopupFillAttribute = (WORD)dwValue; } // // Initial insert mode // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_INSERTMODE, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->bInsertMode = !!dwValue; } // // Initial quick edit mode // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_QUICKEDIT, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->bQuickEdit = !!dwValue; } #ifdef _X86_ // // Initial full screen mode // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_FULLSCR, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->bFullScreen = !!dwValue; } #endif // // Initial screen buffer size // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_BUFFERSIZE, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->dwScreenBufferSize.X = LOWORD(dwValue); lpCon->dwScreenBufferSize.Y = HIWORD(dwValue); } // // Initial window size // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_WINDOWSIZE, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->dwWindowSize.X = LOWORD(dwValue); lpCon->dwWindowSize.Y = HIWORD(dwValue); } // // Initial window position // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_WINDOWPOS, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->dwWindowOrigin.X = (SHORT)LOWORD(dwValue); lpCon->dwWindowOrigin.Y = (SHORT)HIWORD(dwValue); lpCon->bAutoPosition = FALSE; } // // Initial font size // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_FONTSIZE, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->dwFontSize.X = LOWORD(dwValue); lpCon->dwFontSize.Y = HIWORD(dwValue); } // // Initial font family // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_FONTFAMILY, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->uFontFamily = dwValue; } // // Initial font weight // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_FONTWEIGHT, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->uFontWeight = dwValue; } // // Initial font face name // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_FACENAME, sizeof(awchFaceName), (PBYTE)awchFaceName))) { RtlCopyMemory(lpCon->FaceName, awchFaceName, sizeof(awchFaceName)); } // // Initial cursor size // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_CURSORSIZE, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->uCursorSize = dwValue; } // // Initial history buffer size // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_HISTORYSIZE, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->uHistoryBufferSize = dwValue; } // // Initial number of history buffers // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_HISTORYBUFS, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->uNumberOfHistoryBuffers = dwValue; } // // Initial history duplication mode // if (NT_SUCCESS(MyRegQueryValue(hTitleKey, CONSOLE_REGISTRY_HISTORYNODUP, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->bHistoryNoDup = dwValue; } // // Initial color table // for (i=0; i<16; i++) { wsprintf(awchBuffer, CONSOLE_REGISTRY_COLORTABLE, i); if (NT_SUCCESS(MyRegQueryValue(hTitleKey, awchBuffer, sizeof(dwValue), (PBYTE)&dwValue))) { lpCon->ColorTable[i] = dwValue; } } // // Close the registry keys // if (hTitleKey != hConsoleKey) { NtClose(hTitleKey); } CloseKeys: NtClose(hConsoleKey); NtClose(hCurrentUserKey); CsrRevertToSelf(); }
NTSTATUS NTAPI NtSetDefaultLocale(IN BOOLEAN UserProfile, IN LCID DefaultLocaleId) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; ULONG ValueLength; WCHAR ValueBuffer[20]; HANDLE UserKey; NTSTATUS Status; PAGED_CODE(); /* Check if we have a profile */ if (UserProfile) { /* Open the user's key */ Status = RtlOpenCurrentUser(KEY_WRITE, &UserKey); if (!NT_SUCCESS(Status)) return(Status); /* Initialize the registry location */ RtlInitUnicodeString(&KeyName, L"Control Panel\\International"); RtlInitUnicodeString(&ValueName, L"Locale"); } else { /* Initialize the system registry location */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet" L"\\Control\\Nls\\Language"); RtlInitUnicodeString(&ValueName, L"Default"); UserKey = NULL; } /* Initailize the object attributes */ InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, UserKey, NULL); /* Check if we don' thave a default locale yet */ if (!DefaultLocaleId) { DPRINT1("TODO\n"); Status = STATUS_SUCCESS; ASSERT(FALSE); } else { /* Otherwise, open the key */ Status = ZwOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); if (NT_SUCCESS(Status)) { /* Check if we had a profile */ if (UserProfile) { /* Fill in the buffer */ ValueLength = swprintf(ValueBuffer, L"%08lx", (ULONG)DefaultLocaleId); } else { /* Fill in the buffer */ ValueLength = swprintf(ValueBuffer, L"%04lx", (ULONG)DefaultLocaleId & 0xFFFF); } /* Set the length for the registry call */ ValueLength = (ValueLength + 1) * sizeof(WCHAR); /* Now write the actual value */ Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, ValueBuffer, ValueLength); /* And close the key */ ZwClose(KeyHandle); } } /* Close the user key */ if (UserKey) { ObCloseHandle(UserKey, KernelMode); } /* Check for success */ if (NT_SUCCESS(Status)) { /* Check if it was for a user */ if (UserProfile) { /* Set thread locale */ PsDefaultThreadLocaleId = DefaultLocaleId; } else { /* Set system locale */ PsDefaultSystemLocaleId = DefaultLocaleId; } } /* Return status */ return Status; }
NTSTATUS BaseSrvNlsLogon( BOOL fLogon) { HANDLE hUserHandle; /* HKEY_CURRENT_USER equivalent */ HANDLE hKeyHandle; OBJECT_ATTRIBUTES ObjA; /* object attributes structure */ UNICODE_STRING ObKeyName; /* key name */ ULONG rc = 0L; /* return code */ if (fLogon) { /* * Logging ON. * - open keys * * NOTE: Registry Notification is done by the RIT in user server. */ rc = RtlOpenCurrentUser( MAXIMUM_ALLOWED, &hUserHandle ); if (!NT_SUCCESS( rc )) { KdPrint(("NLSAPI (BaseSrv): Could NOT Open HKEY_CURRENT_USER - %lx.\n", rc)); return ( rc ); } RtlInitUnicodeString( &ObKeyName, L"Control Panel\\International" ); InitializeObjectAttributes( &ObjA, &ObKeyName, OBJ_CASE_INSENSITIVE, hUserHandle, NULL ); /* * Open key for READ and NOTIFY access. */ rc = NtOpenKey( &hCPanelIntlKeyRead, KEY_READ | KEY_NOTIFY, &ObjA ); /* * Open key for WRITE access. */ if (!NT_SUCCESS( NtOpenKey( &hCPanelIntlKeyWrite, KEY_WRITE, &ObjA ) )) { KdPrint(("NLSAPI (BaseSrv): Could NOT Open Registry Key %wZ for Write - %lx.\n", &ObKeyName, rc)); hCPanelIntlKeyWrite = NULL; } /* * Close the handle to the current user (HKEY_CURRENT_USER). */ NtClose( hUserHandle ); /* * Check for error from first NtOpenKey. */ if (!NT_SUCCESS( rc )) { KdPrint(("NLSAPI (BaseSrv): Could NOT Open Registry Key %wZ for Read - %lx.\n", &ObKeyName, rc)); hCPanelIntlKeyRead = NULL; if (hCPanelIntlKeyWrite != NULL) { NtClose( hCPanelIntlKeyWrite ); hCPanelIntlKeyWrite = NULL; } return ( rc ); } } else { /* * Logging OFF. * - close keys * - zero out info */ if (hCPanelIntlKeyRead != NULL) { NtClose( hCPanelIntlKeyRead ); hCPanelIntlKeyRead = NULL; } if (hCPanelIntlKeyWrite != NULL) { NtClose( hCPanelIntlKeyWrite ); hCPanelIntlKeyWrite = NULL; } /* * Get the cache mutant. */ NtWaitForSingleObject( hNlsCacheMutant, FALSE, NULL ); /* * Set the cache to be invalid. */ pNlsRegUserInfo->fCacheValid = FALSE; /* * Zero out info. */ RtlZeroMemory(pNlsRegUserInfo, sizeof(NLS_USER_INFO)); /* * Make the system locale the user locale. */ NtQueryDefaultLocale( FALSE, &(pNlsRegUserInfo->UserLocaleId) ); /* * Release the cache mutant. */ NtReleaseMutant( hNlsCacheMutant, NULL ); } /* * Return success. */ return ( STATUS_SUCCESS ); }
BOOLEAN NTAPI BaseSrvIsVdmAllowed(VOID) { NTSTATUS Status; BOOLEAN VdmAllowed = TRUE; HANDLE RootKey, KeyHandle; UNICODE_STRING KeyName, ValueName, MachineKeyName; OBJECT_ATTRIBUTES Attributes; UCHAR ValueBuffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG)]; PKEY_VALUE_PARTIAL_INFORMATION ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer; ULONG ActualSize; /* Initialize the unicode strings */ RtlInitUnicodeString(&MachineKeyName, L"\\Registry\\Machine"); RtlInitUnicodeString(&KeyName, VDM_POLICY_KEY_NAME); RtlInitUnicodeString(&ValueName, VDM_DISALLOWED_VALUE_NAME); InitializeObjectAttributes(&Attributes, &MachineKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); /* Open the local machine key */ Status = NtOpenKey(&RootKey, KEY_READ, &Attributes); if (!NT_SUCCESS(Status)) return FALSE; InitializeObjectAttributes(&Attributes, &KeyName, OBJ_CASE_INSENSITIVE, RootKey, NULL); /* Open the policy key in the local machine hive, if it exists */ if (NT_SUCCESS(NtOpenKey(&KeyHandle, KEY_READ, &Attributes))) { /* Read the value, if it's set */ if (NT_SUCCESS(NtQueryValueKey(KeyHandle, &ValueName, KeyValuePartialInformation, ValueInfo, sizeof(ValueBuffer), &ActualSize))) { if (*((PULONG)ValueInfo->Data)) { /* The VDM has been disabled in the registry */ VdmAllowed = FALSE; } } NtClose(KeyHandle); } /* Close the local machine key */ NtClose(RootKey); /* If it's disabled system-wide, there's no need to check the user key */ if (!VdmAllowed) return FALSE; /* Open the current user key of the client */ if (!CsrImpersonateClient(NULL)) return VdmAllowed; Status = RtlOpenCurrentUser(KEY_READ, &RootKey); CsrRevertToSelf(); /* If that fails, return the system-wide setting */ if (!NT_SUCCESS(Status)) return VdmAllowed; InitializeObjectAttributes(&Attributes, &KeyName, OBJ_CASE_INSENSITIVE, RootKey, NULL); /* Open the policy key in the current user hive, if it exists */ if (NT_SUCCESS(NtOpenKey(&KeyHandle, KEY_READ, &Attributes))) { /* Read the value, if it's set */ if (NT_SUCCESS(NtQueryValueKey(KeyHandle, &ValueName, KeyValuePartialInformation, ValueInfo, sizeof(ValueBuffer), &ActualSize))) { if (*((PULONG)ValueInfo->Data)) { /* The VDM has been disabled in the registry */ VdmAllowed = FALSE; } } NtClose(KeyHandle); } return VdmAllowed; }
BOOL CliGetImeHotKeysFromRegistry() { BOOL fFoundAny = FALSE; HANDLE hCurrentUserKey; HANDLE hKeyHotKeys; OBJECT_ATTRIBUTES Obja; UNICODE_STRING SubKeyName; NTSTATUS Status; ULONG uIndex; // // Open the current user registry key // Status = RtlOpenCurrentUser(MAXIMUM_ALLOWED, &hCurrentUserKey); if (!NT_SUCCESS(Status)) { return fFoundAny; } RtlInitUnicodeString( &SubKeyName, szRegImeHotKey ); InitializeObjectAttributes( &Obja, &SubKeyName, OBJ_CASE_INSENSITIVE, hCurrentUserKey, NULL); Status = NtOpenKey( &hKeyHotKeys, KEY_READ, &Obja ); if (!NT_SUCCESS(Status)) { NtClose( hCurrentUserKey ); return fFoundAny; } for (uIndex = 0; TRUE; uIndex++) { BYTE KeyBuffer[sizeof(KEY_BASIC_INFORMATION) + 16 * sizeof(WCHAR)]; PKEY_BASIC_INFORMATION pKeyInfo; ULONG ResultLength; pKeyInfo = (PKEY_BASIC_INFORMATION)KeyBuffer; Status = NtEnumerateKey(hKeyHotKeys, uIndex, KeyBasicInformation, pKeyInfo, sizeof( KeyBuffer ), &ResultLength ); if (NT_SUCCESS(Status)) { if (CliSetSingleHotKey(pKeyInfo, hKeyHotKeys)) { fFoundAny = TRUE; } } else if (Status == STATUS_NO_MORE_ENTRIES) { break; } } NtClose(hKeyHotKeys); NtClose(hCurrentUserKey); return fFoundAny; }