mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
Import from WINE 25.04.05 (just because we have old version sitting in our SVN, which shows failures even on WinXP).
Now "advapi32_test registry" has 0 failures on Windows XP Pro. (and generally should have 0 failures under ROS too...) svn path=/trunk/; revision=14860
This commit is contained in:
parent
aa182938a2
commit
11e90a8e41
7 changed files with 2020 additions and 1703 deletions
|
@ -41,6 +41,30 @@ static BOOL (WINAPI *pCryptEnumProvidersA)(DWORD, DWORD*, DWORD, DWORD*, LPSTR,
|
|||
static BOOL (WINAPI *pCryptGetDefaultProviderA)(DWORD, DWORD*, DWORD, LPSTR, DWORD*);
|
||||
static BOOL (WINAPI *pCryptReleaseContext)(HCRYPTPROV, DWORD);
|
||||
static BOOL (WINAPI *pCryptSetProviderExA)(LPCSTR, DWORD, DWORD*, DWORD);
|
||||
static BOOL (WINAPI *pCryptCreateHash)(HCRYPTPROV, ALG_ID, HCRYPTKEY, DWORD, HCRYPTHASH*);
|
||||
static BOOL (WINAPI *pCryptDestroyHash)(HCRYPTHASH);
|
||||
static BOOL (WINAPI *pCryptGenRandom)(HCRYPTPROV, DWORD, BYTE*);
|
||||
static BOOL (WINAPI *pCryptContextAddRef)(HCRYPTPROV, DWORD*, DWORD dwFlags);
|
||||
static BOOL (WINAPI *pCryptGenKey)(HCRYPTPROV, ALG_ID, DWORD, HCRYPTKEY*);
|
||||
static BOOL (WINAPI *pCryptDestroyKey)(HCRYPTKEY);
|
||||
static BOOL (WINAPI *pCryptDecrypt)(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, BYTE*, DWORD*);
|
||||
static BOOL (WINAPI *pCryptDeriveKey)(HCRYPTPROV, ALG_ID, HCRYPTHASH, DWORD, HCRYPTKEY*);
|
||||
static BOOL (WINAPI *pCryptDuplicateHash)(HCRYPTHASH, DWORD*, DWORD, HCRYPTHASH*);
|
||||
static BOOL (WINAPI *pCryptDuplicateKey)(HCRYPTKEY, DWORD*, DWORD, HCRYPTKEY*);
|
||||
static BOOL (WINAPI *pCryptEncrypt)(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, BYTE*, DWORD*, DWORD);
|
||||
static BOOL (WINAPI *pCryptExportKey)(HCRYPTKEY, HCRYPTKEY, DWORD, DWORD, BYTE*, DWORD*);
|
||||
static BOOL (WINAPI *pCryptGetHashParam)(HCRYPTHASH, DWORD, BYTE*, DWORD*, DWORD);
|
||||
static BOOL (WINAPI *pCryptGetKeyParam)(HCRYPTKEY, DWORD, BYTE*, DWORD*, DWORD);
|
||||
static BOOL (WINAPI *pCryptGetProvParam)(HCRYPTPROV, DWORD, BYTE*, DWORD*, DWORD);
|
||||
static BOOL (WINAPI *pCryptGetUserKey)(HCRYPTPROV, DWORD, HCRYPTKEY*);
|
||||
static BOOL (WINAPI *pCryptHashData)(HCRYPTHASH, BYTE*, DWORD, DWORD);
|
||||
static BOOL (WINAPI *pCryptHashSessionKey)(HCRYPTHASH, HCRYPTKEY, DWORD);
|
||||
static BOOL (WINAPI *pCryptImportKey)(HCRYPTPROV, BYTE*, DWORD, HCRYPTKEY, DWORD, HCRYPTKEY*);
|
||||
static BOOL (WINAPI *pCryptSignHashW)(HCRYPTHASH, DWORD, LPCWSTR, DWORD, BYTE*, DWORD*);
|
||||
static BOOL (WINAPI *pCryptSetHashParam)(HCRYPTKEY, DWORD, BYTE*, DWORD);
|
||||
static BOOL (WINAPI *pCryptSetKeyParam)(HCRYPTKEY, DWORD, BYTE*, DWORD);
|
||||
static BOOL (WINAPI *pCryptSetProvParam)(HCRYPTPROV, DWORD, BYTE*, DWORD);
|
||||
static BOOL (WINAPI *pCryptVerifySignatureW)(HCRYPTHASH, BYTE*, DWORD, HCRYPTKEY, LPCWSTR, DWORD);
|
||||
|
||||
static void init_function_pointers(void)
|
||||
{
|
||||
|
@ -54,10 +78,33 @@ static void init_function_pointers(void)
|
|||
pCryptGetDefaultProviderA = (void*)GetProcAddress(hadvapi32, "CryptGetDefaultProviderA");
|
||||
pCryptReleaseContext = (void*)GetProcAddress(hadvapi32, "CryptReleaseContext");
|
||||
pCryptSetProviderExA = (void*)GetProcAddress(hadvapi32, "CryptSetProviderExA");
|
||||
pCryptCreateHash = (void*)GetProcAddress(hadvapi32, "CryptCreateHash");
|
||||
pCryptDestroyHash = (void*)GetProcAddress(hadvapi32, "CryptDestroyHash");
|
||||
pCryptGenRandom = (void*)GetProcAddress(hadvapi32, "CryptGenRandom");
|
||||
pCryptContextAddRef = (void*)GetProcAddress(hadvapi32, "CryptContextAddRef");
|
||||
pCryptGenKey = (void*)GetProcAddress(hadvapi32, "CryptGenKey");
|
||||
pCryptDestroyKey = (void*)GetProcAddress(hadvapi32, "CryptDestroyKey");
|
||||
pCryptDecrypt = (void*)GetProcAddress(hadvapi32, "CryptDecrypt");
|
||||
pCryptDeriveKey = (void*)GetProcAddress(hadvapi32, "CryptDeriveKey");
|
||||
pCryptDuplicateHash = (void*)GetProcAddress(hadvapi32, "CryptDuplicateHash");
|
||||
pCryptDuplicateKey = (void*)GetProcAddress(hadvapi32, "CryptDuplicateKey");
|
||||
pCryptEncrypt = (void*)GetProcAddress(hadvapi32, "CryptEncrypt");
|
||||
pCryptExportKey = (void*)GetProcAddress(hadvapi32, "CryptExportKey");
|
||||
pCryptGetHashParam = (void*)GetProcAddress(hadvapi32, "CryptGetHashParam");
|
||||
pCryptGetKeyParam = (void*)GetProcAddress(hadvapi32, "CryptGetKeyParam");
|
||||
pCryptGetProvParam = (void*)GetProcAddress(hadvapi32, "CryptGetProvParam");
|
||||
pCryptGetUserKey = (void*)GetProcAddress(hadvapi32, "CryptGetUserKey");
|
||||
pCryptHashData = (void*)GetProcAddress(hadvapi32, "CryptHashData");
|
||||
pCryptHashSessionKey = (void*)GetProcAddress(hadvapi32, "CryptHashSessionKey");
|
||||
pCryptImportKey = (void*)GetProcAddress(hadvapi32, "CryptImportKey");
|
||||
pCryptSignHashW = (void*)GetProcAddress(hadvapi32, "CryptSignHashW");
|
||||
pCryptSetHashParam = (void*)GetProcAddress(hadvapi32, "CryptSetHashParam");
|
||||
pCryptSetKeyParam = (void*)GetProcAddress(hadvapi32, "CryptSetKeyParam");
|
||||
pCryptSetProvParam = (void*)GetProcAddress(hadvapi32, "CryptSetProvParam");
|
||||
pCryptVerifySignatureW = (void*)GetProcAddress(hadvapi32, "CryptVerifySignatureW");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void init_environment(void)
|
||||
{
|
||||
HCRYPTPROV hProv;
|
||||
|
@ -138,7 +185,7 @@ static void test_acquire_context(void)
|
|||
hProv = 0;
|
||||
SetLastError(0xdeadbeef);
|
||||
result = pCryptAcquireContextA(&hProv, szKeySet, szRsaBaseProv, PROV_RSA_FULL, 0);
|
||||
ok(result && (GetLastError() == ERROR_ENVVAR_NOT_FOUND || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_RING2_STACK_IN_USE), "%d/%ld\n", result, GetLastError());
|
||||
ok(result && (GetLastError() == ERROR_ENVVAR_NOT_FOUND || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_RING2_STACK_IN_USE || GetLastError() == NTE_FAIL), "%d/%ld\n", result, GetLastError());
|
||||
|
||||
if (hProv)
|
||||
pCryptReleaseContext(hProv, 0);
|
||||
|
@ -147,12 +194,153 @@ static void test_acquire_context(void)
|
|||
hProv = 0;
|
||||
SetLastError(0xdeadbeef);
|
||||
result = pCryptAcquireContextA(&hProv, szKeySet, "", PROV_RSA_FULL, 0);
|
||||
ok(result && (GetLastError() == ERROR_ENVVAR_NOT_FOUND || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_RING2_STACK_IN_USE), "%d/%ld\n", result, GetLastError());
|
||||
ok(result && (GetLastError() == ERROR_ENVVAR_NOT_FOUND || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_RING2_STACK_IN_USE || GetLastError() == NTE_FAIL), "%d/%ld\n", result, GetLastError());
|
||||
|
||||
if (hProv)
|
||||
pCryptReleaseContext(hProv, 0);
|
||||
}
|
||||
|
||||
static void test_incorrect_api_usage(void)
|
||||
{
|
||||
BOOL result;
|
||||
HCRYPTPROV hProv, hProv2;
|
||||
HCRYPTHASH hHash, hHash2;
|
||||
HCRYPTKEY hKey, hKey2;
|
||||
BYTE temp;
|
||||
DWORD dwLen, dwTemp;
|
||||
|
||||
/* This is to document incorrect api usage in the
|
||||
* "Uru - Ages beyond Myst Demo" installer as reported by Paul Vriens.
|
||||
*
|
||||
* The installer destroys a hash object after having released the context
|
||||
* with which the hash was created. This is not allowed according to MSDN,
|
||||
* since CryptReleaseContext destroys all hash and key objects belonging to
|
||||
* the respective context. However, while wine used to crash, Windows is more
|
||||
* robust here and returns an ERROR_INVALID_PARAMETER code.
|
||||
*/
|
||||
|
||||
result = pCryptAcquireContextA(&hProv, szBadKeySet, szRsaBaseProv,
|
||||
PROV_RSA_FULL, CRYPT_NEWKEYSET);
|
||||
ok (result, "%08lx\n", GetLastError());
|
||||
if (!result) return;
|
||||
|
||||
result = pCryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash);
|
||||
ok (result, "%ld\n", GetLastError());
|
||||
if (!result) return;
|
||||
|
||||
result = pCryptGenKey(hProv, CALG_RC4, 0, &hKey);
|
||||
ok (result, "%ld\n", GetLastError());
|
||||
if (!result) return;
|
||||
|
||||
result = pCryptGenKey(hProv, CALG_RC4, 0, &hKey2);
|
||||
ok (result, "%ld\n", GetLastError());
|
||||
if (!result) return;
|
||||
|
||||
result = pCryptDestroyKey(hKey2);
|
||||
ok (result, "%ld\n", GetLastError());
|
||||
|
||||
dwTemp = CRYPT_MODE_ECB;
|
||||
result = pCryptSetKeyParam(hKey2, KP_MODE, (BYTE*)&dwTemp, sizeof(DWORD));
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptAcquireContextA(&hProv2, szBadKeySet, NULL, PROV_RSA_FULL,
|
||||
CRYPT_DELETEKEYSET);
|
||||
ok (result, "%ld\n", GetLastError());
|
||||
if (!result) return;
|
||||
|
||||
result = pCryptReleaseContext(hProv, 0);
|
||||
ok (result, "%ld\n", GetLastError());
|
||||
if (!result) return;
|
||||
|
||||
result = pCryptReleaseContext(hProv, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptGenRandom(hProv, 1, &temp);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
#ifdef CRASHES_ON_NT40
|
||||
result = pCryptContextAddRef(hProv, NULL, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
#endif
|
||||
|
||||
result = pCryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptDecrypt(hKey, (HCRYPTHASH)NULL, TRUE, 0, &temp, &dwLen);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptEncrypt(hKey, (HCRYPTHASH)NULL, TRUE, 0, &temp, &dwLen, 1);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptDeriveKey(hProv, CALG_RC4, hHash, 0, &hKey2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
#ifdef CRASHES_ON_NT40
|
||||
result = pCryptDuplicateHash(hHash, NULL, 0, &hHash2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptDuplicateKey(hKey, NULL, 0, &hKey2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
#endif
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptExportKey(hKey, (HCRYPTPROV)NULL, 0, 0, &temp, &dwLen);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptGenKey(hProv, CALG_RC4, 0, &hKey2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptGetHashParam(hHash, 0, &temp, &dwLen, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptGetKeyParam(hKey, 0, &temp, &dwLen, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptGetProvParam(hProv, 0, &temp, &dwLen, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptGetUserKey(hProv, 0, &hKey2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptHashData(hHash, &temp, 1, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptHashSessionKey(hHash, hKey, 0);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptImportKey(hProv, &temp, 1, (HCRYPTKEY)NULL, 0, &hKey2);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
dwLen = 1;
|
||||
result = pCryptSignHashW(hHash, 0, NULL, 0, &temp, &dwLen);
|
||||
ok (!result && (GetLastError() == ERROR_INVALID_PARAMETER ||
|
||||
GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptSetKeyParam(hKey, 0, &temp, 1);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptSetHashParam(hHash, 0, &temp, 1);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptSetProvParam(hProv, 0, &temp, 1);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptVerifySignatureW(hHash, &temp, 1, hKey, NULL, 0);
|
||||
ok (!result && (GetLastError() == ERROR_INVALID_PARAMETER ||
|
||||
GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptDestroyHash(hHash);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
|
||||
result = pCryptDestroyKey(hKey);
|
||||
ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%ld\n", GetLastError());
|
||||
}
|
||||
|
||||
static BOOL FindProvRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName,
|
||||
DWORD *pcbProvName, DWORD *pdwProvCount)
|
||||
{
|
||||
|
@ -565,6 +753,7 @@ START_TEST(crypt)
|
|||
if(pCryptAcquireContextA && pCryptReleaseContext) {
|
||||
init_environment();
|
||||
test_acquire_context();
|
||||
test_incorrect_api_usage();
|
||||
clean_up_environment();
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static DWORD delete_key( HKEY hkey )
|
|||
if (ret) break;
|
||||
}
|
||||
if (ret != ERROR_NO_MORE_ITEMS) return ret;
|
||||
RegDeleteKeyA( hkey, NULL );
|
||||
RegDeleteKeyA( hkey, "" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ static void create_test_entries(void)
|
|||
static void test_enum_value(void)
|
||||
{
|
||||
DWORD res;
|
||||
HKEY test_key;
|
||||
char value[20], data[20];
|
||||
WCHAR valueW[20], dataW[20];
|
||||
DWORD val_count, data_count, type;
|
||||
|
@ -82,18 +83,22 @@ static void test_enum_value(void)
|
|||
static const WCHAR testW[] = {'T','e','s','t',0};
|
||||
static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
|
||||
|
||||
/* create the working key for new 'Test' value */
|
||||
res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
|
||||
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res);
|
||||
|
||||
/* check NULL data with zero length */
|
||||
res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, NULL, 0 );
|
||||
res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
|
||||
if (GetVersion() & 0x80000000)
|
||||
ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
|
||||
else
|
||||
ok( !res, "RegSetValueExA returned %ld\n", res );
|
||||
res = RegSetValueExA( hkey_main, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
|
||||
ok( !res, "RegSetValueExA returned %ld\n", res );
|
||||
res = RegSetValueExA( hkey_main, "Test", 0, REG_BINARY, NULL, 0 );
|
||||
ok( !res, "RegSetValueExA returned %ld\n", res );
|
||||
res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
|
||||
ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
|
||||
res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
|
||||
ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
|
||||
|
||||
res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
|
||||
res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
|
||||
ok( res == 0, "RegSetValueExA failed error %ld\n", res );
|
||||
|
||||
/* overflow both name and data */
|
||||
|
@ -102,7 +107,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
strcpy( value, "xxxxxxxxxx" );
|
||||
strcpy( data, "xxxxxxxxxx" );
|
||||
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
ok( val_count == 2, "val_count set to %ld\n", val_count );
|
||||
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
||||
|
@ -116,7 +121,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
strcpy( value, "xxxxxxxxxx" );
|
||||
strcpy( data, "xxxxxxxxxx" );
|
||||
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
/* Win9x returns 2 as specified by MSDN but NT returns 3... */
|
||||
ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count );
|
||||
|
@ -134,7 +139,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
strcpy( value, "xxxxxxxxxx" );
|
||||
strcpy( data, "xxxxxxxxxx" );
|
||||
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
ok( val_count == 0, "val_count set to %ld\n", val_count );
|
||||
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
||||
|
@ -151,7 +156,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
strcpy( value, "xxxxxxxxxx" );
|
||||
strcpy( data, "xxxxxxxxxx" );
|
||||
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
ok( val_count == 20, "val_count set to %ld\n", val_count );
|
||||
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
||||
|
@ -165,7 +170,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
strcpy( value, "xxxxxxxxxx" );
|
||||
strcpy( data, "xxxxxxxxxx" );
|
||||
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
|
||||
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
|
||||
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
|
||||
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
||||
|
@ -176,9 +181,9 @@ static void test_enum_value(void)
|
|||
/* Unicode tests */
|
||||
|
||||
SetLastError(0);
|
||||
res = RegSetValueExW( hkey_main, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
|
||||
res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
|
||||
if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
||||
goto CLEANUP;
|
||||
return;
|
||||
ok( res == 0, "RegSetValueExW failed error %ld\n", res );
|
||||
|
||||
/* overflow both name and data */
|
||||
|
@ -187,7 +192,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
memcpy( valueW, xxxW, sizeof(xxxW) );
|
||||
memcpy( dataW, xxxW, sizeof(xxxW) );
|
||||
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
ok( val_count == 2, "val_count set to %ld\n", val_count );
|
||||
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
||||
|
@ -201,7 +206,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
memcpy( valueW, xxxW, sizeof(xxxW) );
|
||||
memcpy( dataW, xxxW, sizeof(xxxW) );
|
||||
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
ok( val_count == 3, "val_count set to %ld\n", val_count );
|
||||
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
||||
|
@ -215,7 +220,7 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
memcpy( valueW, xxxW, sizeof(xxxW) );
|
||||
memcpy( dataW, xxxW, sizeof(xxxW) );
|
||||
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
||||
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
|
||||
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
||||
|
@ -229,17 +234,13 @@ static void test_enum_value(void)
|
|||
type = 1234;
|
||||
memcpy( valueW, xxxW, sizeof(xxxW) );
|
||||
memcpy( dataW, xxxW, sizeof(xxxW) );
|
||||
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
||||
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
|
||||
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
|
||||
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
||||
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
||||
ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
|
||||
ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
|
||||
|
||||
CLEANUP:
|
||||
/* cleanup */
|
||||
RegDeleteValueA( hkey_main, "Test" );
|
||||
}
|
||||
|
||||
static void test_query_value_ex()
|
||||
|
@ -269,8 +270,8 @@ static void test_reg_open_key()
|
|||
/* open same key twice */
|
||||
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
|
||||
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
||||
ok(hkResult != hkPreserve && hkResult != NULL,
|
||||
"expected hkResult != hkPreserve and hkResult != NULL\n");
|
||||
ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
|
||||
ok(hkResult != NULL, "hkResult != NULL\n");
|
||||
RegCloseKey(hkResult);
|
||||
|
||||
/* open nonexistent key
|
||||
|
@ -314,7 +315,8 @@ static void test_reg_open_key()
|
|||
*/
|
||||
hkResult = hkPreserve;
|
||||
ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
|
||||
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
|
||||
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
|
||||
"expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
|
||||
ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
|
||||
RegCloseKey(hkResult);
|
||||
|
||||
|
@ -336,12 +338,89 @@ static void test_reg_close_key()
|
|||
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
||||
|
||||
/* try to close the key twice */
|
||||
ret = RegCloseKey(hkHandle);
|
||||
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
|
||||
ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
|
||||
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
|
||||
"expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %ld\n", ret);
|
||||
|
||||
/* try to close a NULL handle */
|
||||
ret = RegCloseKey(NULL);
|
||||
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
|
||||
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
|
||||
"expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
|
||||
}
|
||||
|
||||
static void test_reg_delete_key()
|
||||
{
|
||||
DWORD ret;
|
||||
|
||||
ret = RegDeleteKey(hkey_main, NULL);
|
||||
ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_ACCESS_DENIED,
|
||||
"expected ERROR_INVALID_PARAMETER or ERROR_ACCESS_DENIED, got %ld\n", ret);
|
||||
}
|
||||
|
||||
static void test_reg_save_key()
|
||||
{
|
||||
DWORD ret;
|
||||
|
||||
ret = RegSaveKey(hkey_main, "saved_key", NULL);
|
||||
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
||||
}
|
||||
|
||||
static void test_reg_load_key()
|
||||
{
|
||||
DWORD ret;
|
||||
HKEY hkHandle;
|
||||
|
||||
ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
|
||||
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
||||
|
||||
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
|
||||
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
||||
|
||||
RegCloseKey(hkHandle);
|
||||
}
|
||||
|
||||
static void test_reg_unload_key()
|
||||
{
|
||||
DWORD ret;
|
||||
|
||||
ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
|
||||
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
||||
|
||||
DeleteFile("saved_key");
|
||||
}
|
||||
|
||||
static BOOL set_privileges(LPCSTR privilege, BOOL set)
|
||||
{
|
||||
TOKEN_PRIVILEGES tp;
|
||||
HANDLE hToken;
|
||||
LUID luid;
|
||||
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
||||
return FALSE;
|
||||
|
||||
if(!LookupPrivilegeValue(NULL, privilege, &luid))
|
||||
{
|
||||
CloseHandle(hToken);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Luid = luid;
|
||||
|
||||
if (set)
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
else
|
||||
tp.Privileges[0].Attributes = 0;
|
||||
|
||||
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
|
||||
if (GetLastError() != ERROR_SUCCESS)
|
||||
{
|
||||
CloseHandle(hToken);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CloseHandle(hToken);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
START_TEST(registry)
|
||||
|
@ -349,10 +428,24 @@ START_TEST(registry)
|
|||
setup_main_key();
|
||||
create_test_entries();
|
||||
test_enum_value();
|
||||
#if 0
|
||||
test_query_value_ex();
|
||||
test_reg_open_key();
|
||||
test_reg_close_key();
|
||||
test_reg_delete_key();
|
||||
|
||||
/* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
|
||||
if (set_privileges(SE_BACKUP_NAME, TRUE) &&
|
||||
set_privileges(SE_RESTORE_NAME, TRUE))
|
||||
{
|
||||
test_reg_save_key();
|
||||
test_reg_load_key();
|
||||
test_reg_unload_key();
|
||||
|
||||
set_privileges(SE_BACKUP_NAME, FALSE);
|
||||
set_privileges(SE_RESTORE_NAME, FALSE);
|
||||
}
|
||||
#endif
|
||||
/* cleanup */
|
||||
delete_key( hkey_main );
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ typedef BOOL (WINAPI *fnBuildTrusteeWithSidA)( TRUSTEE *trustee, PSID psid );
|
|||
typedef BOOL (WINAPI *fnBuildTrusteeWithNameA)( TRUSTEE *trustee, LPSTR str );
|
||||
typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str );
|
||||
typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid );
|
||||
typedef BOOL (WINAPI *fnGetFileSecurityA)(LPCSTR, SECURITY_INFORMATION,
|
||||
PSECURITY_DESCRIPTOR, DWORD, LPDWORD);
|
||||
|
||||
static HMODULE hmod;
|
||||
|
||||
|
@ -38,6 +40,7 @@ fnBuildTrusteeWithSidA pBuildTrusteeWithSidA;
|
|||
fnBuildTrusteeWithNameA pBuildTrusteeWithNameA;
|
||||
fnConvertSidToStringSidA pConvertSidToStringSidA;
|
||||
fnConvertStringSidToSidA pConvertStringSidToSidA;
|
||||
fnGetFileSecurityA pGetFileSecurityA;
|
||||
|
||||
struct sidRef
|
||||
{
|
||||
|
@ -109,10 +112,12 @@ void test_sid()
|
|||
ok( r, "failed to allocate sid\n" );
|
||||
r = pConvertSidToStringSidA( psid, &str );
|
||||
ok( r, "failed to convert sid\n" );
|
||||
if (r)
|
||||
{
|
||||
ok( !strcmp( str, refs[i].refStr ),
|
||||
"incorrect sid, expected %s, got %s\n", refs[i].refStr, str );
|
||||
if( str )
|
||||
LocalFree( str );
|
||||
}
|
||||
if( psid )
|
||||
FreeSid( psid );
|
||||
|
||||
|
@ -287,7 +292,7 @@ static void test_lookupPrivilegeName(void)
|
|||
luid.LowPart = i;
|
||||
cchName = sizeof(buf);
|
||||
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
|
||||
ok( ret && GetLastError() != ERROR_NO_SUCH_PRIVILEGE,
|
||||
ok( ret || GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
|
||||
"LookupPrivilegeNameA(0.%ld) failed: %ld\n", i, GetLastError());
|
||||
}
|
||||
/* check a bogus LUID */
|
||||
|
@ -398,6 +403,35 @@ static void test_luid(void)
|
|||
test_lookupPrivilegeValue();
|
||||
}
|
||||
|
||||
static void test_FileSecurity(void)
|
||||
{
|
||||
char directory[MAX_PATH];
|
||||
DWORD retval, outSize;
|
||||
BOOL result;
|
||||
BYTE buffer[0x40];
|
||||
|
||||
pGetFileSecurityA = (fnGetFileSecurityA)
|
||||
GetProcAddress( hmod, "GetFileSecurityA" );
|
||||
if( !pGetFileSecurityA )
|
||||
return;
|
||||
|
||||
retval = GetTempPathA(sizeof(directory), directory);
|
||||
if (!retval) {
|
||||
trace("GetTempPathA failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(directory, "\\Should not exist");
|
||||
|
||||
SetLastError(NO_ERROR);
|
||||
result = pGetFileSecurityA( directory,OWNER_SECURITY_INFORMATION,buffer,0x40,&outSize);
|
||||
ok(!result, "GetFileSecurityA should fail for not existing directories/files\n");
|
||||
ok( (GetLastError() == ERROR_FILE_NOT_FOUND ) ||
|
||||
(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) ,
|
||||
"last error ERROR_FILE_NOT_FOUND / ERROR_CALL_NOT_IMPLEMENTED (98) "
|
||||
"expected, got %ld\n", GetLastError());
|
||||
}
|
||||
|
||||
START_TEST(security)
|
||||
{
|
||||
init();
|
||||
|
@ -405,4 +439,5 @@ START_TEST(security)
|
|||
test_sid();
|
||||
test_trustee();
|
||||
test_luid();
|
||||
test_FileSecurity();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue