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

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jul 30 08:55:56 CDT 2007


Module: wine
Branch: master
Commit: 9c2d8c73aac775b1b98e378879bef815bc1ee430
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9c2d8c73aac775b1b98e378879bef815bc1ee430

Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date:   Sun Jul 29 22:42:17 2007 +0200

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

---

 dlls/advapi32/service.c       |   27 ++++++++++++++++++++++++++-
 dlls/advapi32/tests/service.c |    9 ---------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index f0592fb..bab2479 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -2353,7 +2353,32 @@ BOOL WINAPI GetServiceDisplayNameW( SC_HANDLE hSCManager, LPCWSTR lpServiceName,
             *lpcchBuffer = (size / sizeof(WCHAR)) - 1;
         }
         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
             SetLastError(ret);
         return FALSE;
diff --git a/dlls/advapi32/tests/service.c b/dlls/advapi32/tests/service.c
index 13eec9f..a4eae98 100644
--- a/dlls/advapi32/tests/service.c
+++ b/dlls/advapi32/tests/service.c
@@ -561,13 +561,10 @@ static void test_get_displayname(void)
     displaysize = -1;
     ret = GetServiceDisplayNameA(scm_handle, servicename, NULL, &displaysize);
     ok(!ret, "Expected failure\n");
-    todo_wine
-    {
     ok(displaysize == lstrlen(servicename) * 2,
        "Expected the displaysize to be twice the size of the servicename\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
-    }
 
     /* Buffer is too small */
     SetLastError(0xdeadbeef);
@@ -575,18 +572,13 @@ static void test_get_displayname(void)
     displaysize = (tempsize / 2);
     ret = GetServiceDisplayNameA(scm_handle, servicename, displayname, &displaysize);
     ok(!ret, "Expected failure\n");
-    todo_wine
-    {
     ok(displaysize == tempsize, "Expected the needed buffersize\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
-    }
 
     /* Get the displayname */
     SetLastError(0xdeadbeef);
     ret = GetServiceDisplayNameA(scm_handle, servicename, displayname, &displaysize);
-    todo_wine
-    {
     ok(ret, "Expected success\n");
     ok(!lstrcmpi(displayname, servicename),
        "Expected displayname to be %s, got %s\n", servicename, displayname);
@@ -594,7 +586,6 @@ static void test_get_displayname(void)
        GetLastError() == ERROR_IO_PENDING /* W2K */ ||
        GetLastError() == 0xdeadbeef       /* NT4, XP, Vista */,
        "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
-    }
 
     /* Delete the service */
     ret = DeleteService(svc_handle);




More information about the wine-cvs mailing list