KERNEL: pull WINDIR and WINSYSDIR from config before using hardcoded defaults (possible fix for WWN #234, #235 c:\\windows is not accessible Error)

Alex Villací­s Lasso a_villacis at palosanto.com
Thu Aug 19 20:01:53 CDT 2004


Alex Villací­s Lasso wrote:

> Alexandre Julliard wrote:
>
>> Alex Villací­s Lasso <a_villacis at palosanto.com> writes:
>>
>>  
>>
>>> Changelog:
>>> * if windir or winsysdir environment vars are undefined, pull values
>>> from config file before falling to hardcoded values
>>>   
>>
>>
>> This of course defeats the whole purpose of the use of environment
>> variables, which is to get rid of the config file. If the environment
>> variables are not set it's because the user's config is wrong, they
>> should be set in HKLM\System\CurrentControlSet\Control\SessionManager
>> or (preferably) in HKCU\Environment. The code is supposed to migrate
>> them automatically, but this may not always work if the registry
>> already contains other values, in which case it needs to be fixed by
>> hand. Going back to the config file is definitely not the right way.
>>
>>  
>>
> Thanks for pointing me to misc/registry.c, it helped a LOT.
>
> Upon examination of the function convert_environment(), I realized the 
> following: the function
> queries HKEY_CURRENT_USER/Environment with a call to NtCreateKey(). If 
> the call succeeds,
> but the result is something other than REG_CREATED_NEW_KEY, the 
> function terminates in
> the assumption that the environment was already migrated in a previous 
> invocation of Wine.
>
> The problem is, this assumption is false when the user has a Windows 
> partition for a Wine drive,
> and the user has environment variables of his/her own in the registry. 
> For example, I am a cygwin user
> and I have a Win2k registry with the variables VISUAL, CVS_RSH, and 
> CVSROOT already defined.
> When the function sees that HKEY_CURRENT_USER/Environment already 
> exists (because it was
> taken from the native Windows registry), it (incorrectly) skips the 
> migration of the config file variables.
>
> The obvious solution (implemented by this patch) is to remove the 
> assumption about
> HKEY_CURRENT_USER/Environment being newly created, and instead test 
> for every value before
> migrating.
>
> I hope this is definitely the right way.
>
> Changelog:
> * Do not assume HKEY_CURRENT_USER/Environment exists ==> config file 
> was migrated. Instead test
>   for every key to migrate under HKEY_CURRENT_USER/Environment
>
> Alex Villacis Lasso
>
UPDATE: %Systemroot% should also be migrated. This patch combines this 
and the previous fix into one.
-------------- next part --------------
--- wine-20040813/misc/registry.c	2004-07-29 20:35:52.000000000 -0500
+++ wine-20040813-patch/misc/registry.c	2004-08-19 19:47:12.000000000 -0500
@@ -242,7 +242,7 @@
 }
 
 /******************************************************************/
-/* WINDOWS 31 REGISTRY LOADER, supplied by Tor Sjøwall, tor at sn.no */
+/* WINDOWS 31 REGISTRY LOADER, supplied by Tor Sjwall, tor at sn.no */
 /*
     reghack - windows 3.11 registry data format demo program.
 
@@ -277,7 +277,7 @@
     deduced from the reg.dat file by me. Mistakes may
     have been made. I claim no rights and give no guarantees for this program.
 
-    Tor Sjøwall, tor at sn.no
+    Tor Sjwall, tor at sn.no
 */
 
 /* reg.dat header format */
@@ -1861,6 +1861,7 @@
     static const WCHAR windowsW[] = {'w','i','n','d','o','w','s',0};
     static const WCHAR systemW[] = {'s','y','s','t','e','m',0};
     static const WCHAR windirW[] = {'w','i','n','d','i','r',0};
+    static const WCHAR systemrootW[] = {'S','y','s','t','e','m','r','o','o','t',0};
     static const WCHAR winsysdirW[] = {'w','i','n','s','y','s','d','i','r',0};
     static const WCHAR envW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
     static const WCHAR tempW[] = {'T','E','M','P',0};
@@ -1894,59 +1895,83 @@
         NtClose( hkey_old );
         return;
     }
-    if (disp != REG_CREATED_NEW_KEY) goto done;
 
-    /* convert TEMP */
+    /* Test for existence of TEMP */
     RtlInitUnicodeString( &nameW, tempW );
-    if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+    if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
     {
-        NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
-        RtlInitUnicodeString( &nameW, tmpW );
-        NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
-        MESSAGE( "Converted temp dir to new entry HKCU\\Environment \"TEMP\" = %s\n",
-                 debugstr_w( (WCHAR*)info->Data ) );
+        /* convert TEMP */
+        RtlInitUnicodeString( &nameW, tempW );
+        if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+        {
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            RtlInitUnicodeString( &nameW, tmpW );
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            MESSAGE( "Converted temp dir to new entry HKCU\\Environment \"TEMP\" = %s\n",
+                    debugstr_w( (WCHAR*)info->Data ) );
+        }
     }
 
-    /* convert PATH */
+    /* Test for existence of PATH */
     RtlInitUnicodeString( &nameW, pathW );
-    if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+    if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
     {
-        NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
-        MESSAGE( "Converted path dir to new entry HKCU\\Environment \"PATH\" = %s\n",
-                 debugstr_w( (WCHAR*)info->Data ) );
+        /* convert PATH */
+        RtlInitUnicodeString( &nameW, pathW );
+        if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+        {
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            MESSAGE( "Converted path dir to new entry HKCU\\Environment \"PATH\" = %s\n",
+                    debugstr_w( (WCHAR*)info->Data ) );
+        }
     }
 
-    /* convert USERPROFILE */
-    RtlInitUnicodeString( &nameW, profileW );
-    if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
-    {
-        RtlInitUnicodeString( &nameW, userprofileW );
-        NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
-        MESSAGE( "Converted profile dir to new entry HKCU\\Environment \"USERPROFILE\" = %s\n",
-                 debugstr_w( (WCHAR*)info->Data ) );
+    /* Test for existence of USERPROFILE */
+    RtlInitUnicodeString( &nameW, userprofileW );
+    if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+    {
+        /* convert USERPROFILE */
+        RtlInitUnicodeString( &nameW, profileW );
+        if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+        {
+            RtlInitUnicodeString( &nameW, userprofileW );
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            MESSAGE( "Converted profile dir to new entry HKCU\\Environment \"USERPROFILE\" = %s\n",
+                    debugstr_w( (WCHAR*)info->Data ) );
+        }
     }
 
-    /* convert windir */
-    RtlInitUnicodeString( &nameW, windowsW );
-    if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
-    {
-        RtlInitUnicodeString( &nameW, windirW );
-        NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
-        MESSAGE( "Converted windows dir to new entry HKCU\\Environment \"windir\" = %s\n",
-                 debugstr_w( (WCHAR*)info->Data ) );
+    /* Test for existence of windir */
+    RtlInitUnicodeString( &nameW, windirW );
+    if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+    {
+        /* convert windir */
+        RtlInitUnicodeString( &nameW, windowsW );
+        if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+        {
+            RtlInitUnicodeString( &nameW, windirW );
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            RtlInitUnicodeString( &nameW, systemrootW );
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            MESSAGE( "Converted windows dir to new entry HKCU\\Environment \"windir\" = %s\n",
+                    debugstr_w( (WCHAR*)info->Data ) );
+        }
     }
-
-    /* convert winsysdir */
-    RtlInitUnicodeString( &nameW, systemW );
-    if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
-    {
-        RtlInitUnicodeString( &nameW, winsysdirW );
-        NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
-        MESSAGE( "Converted system dir to new entry HKCU\\Environment \"winsysdir\" = %s\n",
-                 debugstr_w( (WCHAR*)info->Data ) );
+        
+    /* Test for existence of winsysdir */
+    RtlInitUnicodeString( &nameW, winsysdirW );
+    if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+    {
+        /* convert winsysdir */
+        RtlInitUnicodeString( &nameW, systemW );
+        if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
+        {
+            RtlInitUnicodeString( &nameW, winsysdirW );
+            NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
+            MESSAGE( "Converted system dir to new entry HKCU\\Environment \"winsysdir\" = %s\n",
+                    debugstr_w( (WCHAR*)info->Data ) );
+        }
     }
-
-done:
     NtClose( hkey_old );
     NtClose( hkey_env );
 }


More information about the wine-patches mailing list