Commit 9c2d8c73 authored by Paul Vriens's avatar Paul Vriens Committed by Alexandre Julliard

advapi32/service: Fix GetServiceDisplayNameA for service with no displayname.

parent 641e6452
...@@ -2353,7 +2353,32 @@ BOOL WINAPI GetServiceDisplayNameW( SC_HANDLE hSCManager, LPCWSTR lpServiceName, ...@@ -2353,7 +2353,32 @@ BOOL WINAPI GetServiceDisplayNameW( SC_HANDLE hSCManager, LPCWSTR lpServiceName,
*lpcchBuffer = (size / sizeof(WCHAR)) - 1; *lpcchBuffer = (size / sizeof(WCHAR)) - 1;
} }
else if (ret == ERROR_FILE_NOT_FOUND) else if (ret == ERROR_FILE_NOT_FOUND)
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST); {
HKEY hkey;
if (!RegOpenKeyW(hscm->hkey, lpServiceName, &hkey))
{
INT len = lstrlenW(lpServiceName);
BOOL r = FALSE;
if ((*lpcchBuffer <= len) || (!lpDisplayName && *lpcchBuffer))
SetLastError(ERROR_INSUFFICIENT_BUFFER);
else if (lpDisplayName && *lpcchBuffer)
{
/* No displayname, but the service exists and the buffer
* is big enough. We should return the servicename.
*/
lstrcpyW(lpDisplayName, lpServiceName);
r = TRUE;
}
*lpcchBuffer = len;
RegCloseKey(hkey);
return r;
}
else
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
}
else else
SetLastError(ret); SetLastError(ret);
return FALSE; return FALSE;
......
...@@ -561,13 +561,10 @@ static void test_get_displayname(void) ...@@ -561,13 +561,10 @@ static void test_get_displayname(void)
displaysize = -1; displaysize = -1;
ret = GetServiceDisplayNameA(scm_handle, servicename, NULL, &displaysize); ret = GetServiceDisplayNameA(scm_handle, servicename, NULL, &displaysize);
ok(!ret, "Expected failure\n"); ok(!ret, "Expected failure\n");
todo_wine
{
ok(displaysize == lstrlen(servicename) * 2, ok(displaysize == lstrlen(servicename) * 2,
"Expected the displaysize to be twice the size of the servicename\n"); "Expected the displaysize to be twice the size of the servicename\n");
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError()); "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
}
/* Buffer is too small */ /* Buffer is too small */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
...@@ -575,18 +572,13 @@ static void test_get_displayname(void) ...@@ -575,18 +572,13 @@ static void test_get_displayname(void)
displaysize = (tempsize / 2); displaysize = (tempsize / 2);
ret = GetServiceDisplayNameA(scm_handle, servicename, displayname, &displaysize); ret = GetServiceDisplayNameA(scm_handle, servicename, displayname, &displaysize);
ok(!ret, "Expected failure\n"); ok(!ret, "Expected failure\n");
todo_wine
{
ok(displaysize == tempsize, "Expected the needed buffersize\n"); ok(displaysize == tempsize, "Expected the needed buffersize\n");
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError()); "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
}
/* Get the displayname */ /* Get the displayname */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = GetServiceDisplayNameA(scm_handle, servicename, displayname, &displaysize); ret = GetServiceDisplayNameA(scm_handle, servicename, displayname, &displaysize);
todo_wine
{
ok(ret, "Expected success\n"); ok(ret, "Expected success\n");
ok(!lstrcmpi(displayname, servicename), ok(!lstrcmpi(displayname, servicename),
"Expected displayname to be %s, got %s\n", servicename, displayname); "Expected displayname to be %s, got %s\n", servicename, displayname);
...@@ -594,7 +586,6 @@ static void test_get_displayname(void) ...@@ -594,7 +586,6 @@ static void test_get_displayname(void)
GetLastError() == ERROR_IO_PENDING /* W2K */ || GetLastError() == ERROR_IO_PENDING /* W2K */ ||
GetLastError() == 0xdeadbeef /* NT4, XP, Vista */, GetLastError() == 0xdeadbeef /* NT4, XP, Vista */,
"Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError()); "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
}
/* Delete the service */ /* Delete the service */
ret = DeleteService(svc_handle); ret = DeleteService(svc_handle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment