Juan Lang : wintrust: Implement WTHelperGetKnownUsages.

Alexandre Julliard julliard at winehq.org
Wed Oct 1 14:09:23 CDT 2008


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

Author: Juan Lang <juan.lang at gmail.com>
Date:   Tue Sep 30 10:11:30 2008 -0700

wintrust: Implement WTHelperGetKnownUsages.

---

 dlls/wintrust/tests/softpub.c |    8 ----
 dlls/wintrust/wintrust_main.c |   81 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/dlls/wintrust/tests/softpub.c b/dlls/wintrust/tests/softpub.c
index 4bb45c4..5509bce 100644
--- a/dlls/wintrust/tests/softpub.c
+++ b/dlls/wintrust/tests/softpub.c
@@ -479,17 +479,14 @@ static void test_get_known_usages(void)
     }
     SetLastError(0xdeadbeef);
     ret = pWTHelperGetKnownUsages(0, NULL);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
      "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     SetLastError(0xdeadbeef);
     ret = pWTHelperGetKnownUsages(1, NULL);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
      "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     SetLastError(0xdeadbeef);
     ret = pWTHelperGetKnownUsages(0, &usages);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
      "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     /* A value of 1 for the first parameter seems to imply the value is
@@ -498,9 +495,7 @@ static void test_get_known_usages(void)
     SetLastError(0xdeadbeef);
     usages = NULL;
     ret = pWTHelperGetKnownUsages(1, &usages);
-    todo_wine
     ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
-    todo_wine
     ok(usages != NULL, "expected a pointer\n");
     if (ret && usages)
     {
@@ -523,17 +518,14 @@ static void test_get_known_usages(void)
      */
     SetLastError(0xdeadbeef);
     ret = pWTHelperGetKnownUsages(2, &usages);
-    todo_wine
     ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
     ok(usages == NULL, "expected pointer to be cleared\n");
     SetLastError(0xdeadbeef);
     usages = NULL;
     ret = pWTHelperGetKnownUsages(2, &usages);
-    todo_wine
     ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
     SetLastError(0xdeadbeef);
     ret = pWTHelperGetKnownUsages(2, NULL);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
      "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 }
diff --git a/dlls/wintrust/wintrust_main.c b/dlls/wintrust/wintrust_main.c
index 2cfc898..091c0d4 100644
--- a/dlls/wintrust/wintrust_main.c
+++ b/dlls/wintrust/wintrust_main.c
@@ -735,13 +735,90 @@ HANDLE WINAPI WTHelperGetFileHandle(WINTRUST_DATA *data)
         return INVALID_HANDLE_VALUE;
 }
 
+static BOOL WINAPI WINTRUST_enumUsages(PCCRYPT_OID_INFO pInfo, void *pvArg)
+{
+    PCCRYPT_OID_INFO **usages = (PCCRYPT_OID_INFO **)pvArg;
+    DWORD cUsages;
+    BOOL ret;
+
+    if (!*usages)
+    {
+        cUsages = 0;
+        *usages = WINTRUST_Alloc(2 * sizeof(PCCRYPT_OID_INFO));
+    }
+    else
+    {
+        PCCRYPT_OID_INFO *ptr;
+
+        /* Count the existing usages.
+         * FIXME: make sure the new usage doesn't duplicate any in the list?
+         */
+        for (cUsages = 0, ptr = *usages; *ptr; ptr++, cUsages++)
+            ;
+        *usages = WINTRUST_ReAlloc((CRYPT_OID_INFO *)*usages,
+         (cUsages + 1) * sizeof(PCCRYPT_OID_INFO));
+    }
+    if (*usages)
+    {
+        (*usages)[cUsages] = pInfo;
+        (*usages)[cUsages + 1] = NULL;
+        ret = TRUE;
+    }
+    else
+    {
+        SetLastError(ERROR_OUTOFMEMORY);
+        ret = FALSE;
+    }
+    return ret;
+}
+
 /***********************************************************************
  *		WTHelperGetKnownUsages(WINTRUST.@)
+ *
+ * Enumerates the known enhanced key usages as an array of PCCRYPT_OID_INFOs.
+ *
+ * PARAMS
+ *  action      [In]     1 => allocate and return known usages, 2 => free previously
+ *                       allocated usages.
+ *  usages      [In/Out] If action == 1, *usages is set to an array of
+ *                       PCCRYPT_OID_INFO *.  The array is terminated with a NULL
+ *                       pointer.
+ *                       If action == 2, *usages is freed.
+ *
+ * RETURNS
+ *  TRUE on success, FALSE on failure.
  */
 BOOL WINAPI WTHelperGetKnownUsages(DWORD action, PCCRYPT_OID_INFO **usages)
 {
-    FIXME("(%d, %p): stub\n", action, usages);
-    return FALSE;
+    BOOL ret;
+
+    TRACE("(%d, %p)\n", action, usages);
+
+    if (!usages)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    if (action == 1)
+    {
+        *usages = NULL;
+        ret = CryptEnumOIDInfo(CRYPT_ENHKEY_USAGE_OID_GROUP_ID, 0, usages,
+         WINTRUST_enumUsages);
+    }
+    else if (action == 2)
+    {
+        WINTRUST_Free((CRYPT_OID_INFO *)*usages);
+        *usages = NULL;
+        ret = TRUE;
+    }
+    else
+    {
+        WARN("unknown action %d\n", action);
+        SetLastError(ERROR_INVALID_PARAMETER);
+        ret = FALSE;
+    }
+    return ret;
 }
 
 static const WCHAR Software_Publishing[] = {




More information about the wine-cvs mailing list