wintrust: Fix removing a catalog file.
authorPaul Vriens <Paul.Vriens.Wine@gmail.com>
Thu, 8 Jan 2009 12:36:42 +0000 (13:36 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 8 Jan 2009 13:52:31 +0000 (14:52 +0100)
dlls/wintrust/crypt.c
dlls/wintrust/tests/crypt.c

index 99989fdb2bdb5b801a0aa7cd3f5fa2f71f0cad41..8049f33dcf96d41ac4f5253fc4c8ebf90c1783cb 100644 (file)
@@ -471,7 +471,32 @@ BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogF
         SetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
-    return DeleteFileW(pwszCatalogFile);
+
+    /* Only delete when there is a filename and no path */
+    if (pwszCatalogFile && pwszCatalogFile[0] != 0 &&
+        !strchrW(pwszCatalogFile, '\\') && !strchrW(pwszCatalogFile, '/') &&
+        !strchrW(pwszCatalogFile, ':'))
+    {
+        static const WCHAR slashW[] = {'\\',0};
+        WCHAR *target;
+        DWORD len;
+
+        len = strlenW(ca->path) + strlenW(pwszCatalogFile) + 2;
+        if (!(target = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
+        {
+            SetLastError(ERROR_OUTOFMEMORY);
+            return FALSE;
+        }
+        strcpyW(target, ca->path);
+        strcatW(target, slashW);
+        strcatW(target, pwszCatalogFile);
+
+        DeleteFileW(target);
+
+        HeapFree(GetProcessHeap(), 0, target);
+    }
+
+    return TRUE;
 }
 
 /***********************************************************************
index b1b7bc5bd68e253f765f7bef5edf7054365dc881..383fe8bc2db3584d67ce8a7ddde2fddea4535905 100644 (file)
@@ -433,6 +433,7 @@ static void test_CryptCATAdminAddRemoveCatalog(void)
     }
     WideCharToMultiByte(CP_ACP, 0, info.wszCatalogFile, -1, catfile, MAX_PATH, 0, 0);
     if ((p = strrchr(catfile, '\\'))) p++;
+    memset(catfileW, 0, sizeof(catfileW));
     MultiByteToWideChar(0, 0, p, -1, catfileW, MAX_PATH);
 
     /* winetest.cat will be created */
@@ -458,19 +459,17 @@ static void test_CryptCATAdminAddRemoveCatalog(void)
 
     /* Remove the catalog file with the unique name */
     ret = pCryptCATAdminRemoveCatalog(hcatadmin, catfileW, 0);
-    todo_wine
     ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
 
     /* Remove the winetest.cat catalog file, first with the full path. This should not succeed
      * according to MSDN */
     ret = pCryptCATAdminRemoveCatalog(hcatadmin, info.wszCatalogFile, 0);
     ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
-    /* The call succeeds but the file is not removed */
+    /* The call succeeded with the full path but the file is not removed */
     attrs = GetFileAttributes(catfilepath);
-    todo_wine
     ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected %s to exist\n", catfilepath);
+    /* Given only the filename the file is removed */
     ret = pCryptCATAdminRemoveCatalog(hcatadmin, basenameW, 0);
-    todo_wine
     ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
     attrs = GetFileAttributes(catfilepath);
     ok(attrs == INVALID_FILE_ATTRIBUTES, "Expected %s to be removed\n", catfilepath);