kernel32: Fix failure reporting in WritePrivateProfile* and add tests.

Conformance tests based on work by Fabian Maurer, with some adaptations.

Signed-off-by: Paul Graham <development@omega-software.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Graham 2018-01-27 21:11:10 +01:00 committed by Alexandre Julliard
parent 030e4db2e4
commit 39899fd11a
2 changed files with 41 additions and 5 deletions

View File

@ -1391,7 +1391,7 @@ BOOL WINAPI WritePrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
SetLastError(ERROR_FILE_NOT_FOUND); SetLastError(ERROR_FILE_NOT_FOUND);
} else { } else {
ret = PROFILE_SetString( section, entry, string, FALSE); ret = PROFILE_SetString( section, entry, string, FALSE);
PROFILE_FlushFile(); if (ret) ret = PROFILE_FlushFile();
} }
} }
@ -1447,11 +1447,10 @@ BOOL WINAPI WritePrivateProfileSectionW( LPCWSTR section,
else if (PROFILE_Open( filename, TRUE )) { else if (PROFILE_Open( filename, TRUE )) {
if (!string) {/* delete the named section*/ if (!string) {/* delete the named section*/
ret = PROFILE_SetString(section,NULL,NULL, FALSE); ret = PROFILE_SetString(section,NULL,NULL, FALSE);
PROFILE_FlushFile();
} else { } else {
PROFILE_DeleteAllKeys(section); PROFILE_DeleteAllKeys(section);
ret = TRUE; ret = TRUE;
while(*string) { while(*string && ret) {
LPWSTR buf = HeapAlloc( GetProcessHeap(), 0, (strlenW(string)+1) * sizeof(WCHAR) ); LPWSTR buf = HeapAlloc( GetProcessHeap(), 0, (strlenW(string)+1) * sizeof(WCHAR) );
strcpyW( buf, string ); strcpyW( buf, string );
if((p = strchrW( buf, '='))) { if((p = strchrW( buf, '='))) {
@ -1461,8 +1460,8 @@ BOOL WINAPI WritePrivateProfileSectionW( LPCWSTR section,
HeapFree( GetProcessHeap(), 0, buf ); HeapFree( GetProcessHeap(), 0, buf );
string += strlenW(string)+1; string += strlenW(string)+1;
} }
PROFILE_FlushFile();
} }
if (ret) ret = PROFILE_FlushFile();
} }
RtlLeaveCriticalSection( &PROFILE_CritSect ); RtlLeaveCriticalSection( &PROFILE_CritSect );
@ -1744,7 +1743,7 @@ BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key,
if (PROFILE_Open( filename, TRUE )) { if (PROFILE_Open( filename, TRUE )) {
ret = PROFILE_SetString( section, key, outstring, FALSE); ret = PROFILE_SetString( section, key, outstring, FALSE);
PROFILE_FlushFile(); if (ret) ret = PROFILE_FlushFile();
} }
RtlLeaveCriticalSection( &PROFILE_CritSect ); RtlLeaveCriticalSection( &PROFILE_CritSect );

View File

@ -25,6 +25,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "windows.h" #include "windows.h"
#include "sddl.h"
#define KEY "ProfileInt" #define KEY "ProfileInt"
#define SECTION "Test" #define SECTION "Test"
@ -534,6 +535,41 @@ static BOOL emptystr_ok(CHAR emptystr[MAX_PATH])
return TRUE; return TRUE;
} }
static void test_profile_directory_readonly(void)
{
BOOL ret;
CHAR path_folder[MAX_PATH];
CHAR path_file[MAX_PATH];
const char *sddl_string_everyone_readonly = "D:PAI(A;;0x1200a9;;;WD)";
SECURITY_ATTRIBUTES attributes = {0};
char lpStruct[] = { 's', 't', 'r', 'i', 'n', 'g' };
attributes.nLength = sizeof(attributes);
ret = ConvertStringSecurityDescriptorToSecurityDescriptorA(sddl_string_everyone_readonly, SDDL_REVISION_1, &attributes.lpSecurityDescriptor, NULL);
ok(ret == TRUE, "ConvertStringSecurityDescriptorToSecurityDescriptor failed: %d\n", GetLastError());
GetTempPathA(MAX_PATH, path_folder);
lstrcatA(path_folder, "wine-test");
strcpy(path_file, path_folder);
lstrcatA(path_file, "\\tmp.ini");
ret = CreateDirectoryA(path_folder, &attributes);
ok(ret == TRUE, "CreateDirectoryA failed: %d\n", GetLastError());
ret = WritePrivateProfileStringA("App", "key", "string", path_file);
ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
ret = WritePrivateProfileSectionA("App", "key=string", path_file);
ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
ret = WritePrivateProfileStructA("App", "key", lpStruct, sizeof(lpStruct), path_file);
ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
ret = RemoveDirectoryA(path_folder);
ok(ret == TRUE, "RemoveDirectoryA failed: %d\n", GetLastError());
}
static void test_GetPrivateProfileString(const char *content, const char *descript) static void test_GetPrivateProfileString(const char *content, const char *descript)
{ {
DWORD ret, len; DWORD ret, len;
@ -1132,6 +1168,7 @@ START_TEST(profile)
test_profile_existing(); test_profile_existing();
test_profile_delete_on_close(); test_profile_delete_on_close();
test_profile_refresh(); test_profile_refresh();
test_profile_directory_readonly();
test_GetPrivateProfileString( test_GetPrivateProfileString(
"[section1]\r\n" "[section1]\r\n"
"name1=val1\r\n" "name1=val1\r\n"