advapi32: Add RegLoadKey tests

James Hawkins truiken at gmail.com
Mon Apr 25 16:39:10 CDT 2005


Hey,

Changelog
* Add more RegLoadKey tests and respective fixes

-- 
James Hawkins
-------------- next part --------------
Index: dlls/advapi32/tests/registry.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/tests/registry.c,v
retrieving revision 1.24
diff -u -p -r1.24 registry.c
--- dlls/advapi32/tests/registry.c	19 Apr 2005 12:00:04 -0000	1.24
+++ dlls/advapi32/tests/registry.c	25 Apr 2005 21:37:27 -0000
@@ -370,9 +370,64 @@ static void test_reg_load_key()
     DWORD ret;
     HKEY hkHandle;
 
+    /* send in NULL hKey */
+    ret = RegLoadKey(NULL, "Test", "saved_key");
+    ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
+
+    /* lpSubKey is NULL */
+    ret = RegLoadKey(HKEY_LOCAL_MACHINE, NULL, "saved_key");
+    ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
+
+    /* lpSubKey is an empty string */
+    ret = RegLoadKey(HKEY_LOCAL_MACHINE, "", "saved_key");
+    ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
+
+    /* lpFile is NULL */
+    ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", NULL);
+    ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
+
+    /* lpFile is an empty string */
+    ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "");
+    ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
+    
+    /* hKey gets checked first */
+    ret = RegLoadKey(NULL, NULL, NULL);
+    ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
+
+    /* send in HKEY_CLASSES_ROOT for hKey */
+    ret = RegLoadKey(HKEY_CLASSES_ROOT, "Test", "saved_key");
+    ok(ret == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %ld\n", ret);
+
+    /* send in HKEY_CURRENT_USER for hKey */
+    ret = RegLoadKey(HKEY_CURRENT_USER, "Test", "saved_key");
+    ok(ret == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %ld\n", ret);
+
+    /* lpFile is a non-existent file 
+     * the file exists upon return
+     * a key named lpSubKey is created under hKey with no subkeys or values
+     */
+    ret = RegLoadKey(HKEY_USERS, "Test2", "idontexist");
+    ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
+
+    /* make sure the empty key was created */
+    ret = RegOpenKey(HKEY_USERS, "Test2", &hkHandle);
+    ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
+
+    RegCloseKey(hkHandle);
+
+    /* unload the key to check for the file's existence */
+    ret = RegUnLoadKey(HKEY_USERS, "Test2");
+    ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
+
+    /* try to open the newly created file */
+    CreateFile("idontexist", 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+    ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
+
+    /* load a previously saved key */
     ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
     ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
 
+    /* make sure the key was created */
     ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
     ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
 
@@ -386,6 +441,7 @@ static void test_reg_unload_key()
     ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
     ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
 
+    DeleteFile("idontexist");
     DeleteFile("saved_key");
 }
 
Index: dlls/advapi32/registry.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/registry.c,v
retrieving revision 1.75
diff -u -p -r1.75 registry.c
--- dlls/advapi32/registry.c	16 Apr 2005 10:49:10 -0000	1.75
+++ dlls/advapi32/registry.c	25 Apr 2005 21:37:28 -0000
@@ -1596,6 +1596,8 @@ LONG WINAPI RegLoadKeyW( HKEY hkey, LPCW
     UNICODE_STRING subkeyW, filenameW;
 
     if (!(hkey = get_special_root_hkey(hkey))) return ERROR_INVALID_HANDLE;
+    if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
+    if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
 
     destkey.Length = sizeof(destkey);
     destkey.RootDirectory = hkey;               /* root key: HKLM or HKU */
Index: server/registry.c
===================================================================
RCS file: /home/wine/wine/server/registry.c,v
retrieving revision 1.67
diff -u -p -r1.67 registry.c
--- server/registry.c	24 Apr 2005 17:35:52 -0000	1.67
+++ server/registry.c	25 Apr 2005 21:37:28 -0000
@@ -1340,7 +1340,7 @@ static void load_keys( struct key *key, 
     if ((read_next_line( &info ) != 1) ||
         strcmp( info.buffer, "WINE REGISTRY Version 2" ))
     {
-        set_error( STATUS_NOT_REGISTRY_FILE );
+        set_error( STATUS_SUCCESS );
         goto done;
     }
 
@@ -1382,6 +1382,19 @@ static void load_registry( struct key *k
 {
     struct file *file;
     int fd;
+
+    static const WCHAR machineW[] = { 'M','A','C','H','I','N','E',0 };
+    static const WCHAR userW[] = { 'U','S','E','R',0 };
+
+    if (key && key->parent)
+    {
+        if (strcmpiW( key->parent->name, machineW ) && 
+            strcmpiW( key->parent->name, userW ))
+        {
+            set_error( STATUS_ACCESS_DENIED );
+            return;
+        }
+    }
 
     if (!(file = get_file_obj( current->process, handle, GENERIC_READ ))) return;
     fd = dup( get_file_unix_fd( file ) );


More information about the wine-patches mailing list