advapi32: Fix GetServiceKeyNameW behavior to pass the tests.

This commit is contained in:
Alexandre Julliard 2009-01-21 23:32:29 +01:00
parent a882bb6a2c
commit c795150932
4 changed files with 19 additions and 11 deletions

View File

@ -1565,6 +1565,7 @@ BOOL WINAPI GetServiceKeyNameW( SC_HANDLE hSCManager, LPCWSTR lpDisplayName,
LPWSTR lpServiceName, LPDWORD lpcchBuffer )
{
DWORD err;
WCHAR buffer[2];
TRACE("%p %s %p %p\n", hSCManager,
debugstr_w(lpServiceName), lpDisplayName, lpcchBuffer);
@ -1575,10 +1576,20 @@ BOOL WINAPI GetServiceKeyNameW( SC_HANDLE hSCManager, LPCWSTR lpDisplayName,
return 0;
}
/* provide a buffer if the caller didn't */
if (!lpServiceName || *lpcchBuffer < 2)
{
lpServiceName = buffer;
/* A size of 1 would be enough, but tests show that Windows returns 2,
* probably because of a WCHAR/bytes mismatch in their code.
*/
*lpcchBuffer = 2;
}
__TRY
{
err = svcctl_GetServiceKeyNameW(hSCManager, lpDisplayName, lpServiceName,
lpServiceName ? *lpcchBuffer : 0, lpcchBuffer);
*lpcchBuffer, lpcchBuffer);
}
__EXCEPT(rpc_filter)
{

View File

@ -760,7 +760,7 @@ static void test_get_servicekeyname(void)
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST,
"Expected ERROR_SERVICE_DOES_NOT_EXIST, got %d\n", GetLastError());
todo_wine ok(servicesize == 15, "Service size expected 15, got %d\n", servicesize);
ok(servicesize == 15, "Service size expected 15, got %d\n", servicesize);
ok(servicenameW[0] == 0, "Service name not empty\n");
servicesize = 0;
@ -776,7 +776,7 @@ static void test_get_servicekeyname(void)
lstrcpyW( servicenameW, abcW );
ret = GetServiceKeyNameW(scm_handle, deadbeefW, servicenameW, &servicesize);
ok(!ret, "Expected failure\n");
todo_wine ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST,
"Expected ERROR_SERVICE_DOES_NOT_EXIST, got %d\n", GetLastError());
ok(servicenameW[0] == 'A', "Service name changed\n");
@ -794,10 +794,10 @@ static void test_get_servicekeyname(void)
lstrcpyW( servicenameW, abcW );
ret = GetServiceKeyNameW(scm_handle, deadbeefW, servicenameW, &servicesize);
ok(!ret, "Expected failure\n");
todo_wine ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST,
"Expected ERROR_SERVICE_DOES_NOT_EXIST, got %d\n", GetLastError());
todo_wine ok(servicenameW[0] == 'A', "Service name changed\n");
ok(servicenameW[0] == 'A', "Service name changed\n");
servicesize = 2;
strcpy(servicename, "ABC");
@ -805,14 +805,14 @@ static void test_get_servicekeyname(void)
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST,
"Expected ERROR_SERVICE_DOES_NOT_EXIST, got %d\n", GetLastError());
ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
todo_wine ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(servicename[0] == 0, "Service name not empty\n");
servicesize = 2;
lstrcpyW( servicenameW, abcW );
ret = GetServiceKeyNameW(scm_handle, deadbeefW, servicenameW, &servicesize);
ok(!ret, "Expected failure\n");
todo_wine ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(servicesize == 2, "Service size expected 2, got %d\n", servicesize);
ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST,
"Expected ERROR_SERVICE_DOES_NOT_EXIST, got %d\n", GetLastError());
ok(servicenameW[0] == 0, "Service name not empty\n");

View File

@ -240,7 +240,7 @@ typedef [switch_type(DWORD)] union
[in] LPCWSTR lpServiceDisplayName,
[out,size_is(cchBufSize)] WCHAR lpBuffer[],
[in] DWORD cchBufSize,
[out] DWORD *cchLength);
[in,out] DWORD *cchLength);
/* Not compatible with Windows function 0x16 */
DWORD svcctl_SCSetServiceBitsA(/* FIXME */);

View File

@ -261,10 +261,7 @@ DWORD svcctl_GetServiceKeyNameW(
service_unlock(entry);
}
else
{
*cchLength = 1;
err = ERROR_SERVICE_DOES_NOT_EXIST;
}
scmdatabase_unlock(manager->db);