Juan Lang : crypt32: Implement CertAddCTLContextToStore.

Alexandre Julliard julliard at winehq.org
Tue Sep 2 08:32:52 CDT 2008


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

Author: Juan Lang <juan.lang at gmail.com>
Date:   Fri Aug 29 07:59:37 2008 -0700

crypt32: Implement CertAddCTLContextToStore.

---

 dlls/crypt32/ctl.c       |   85 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/store.c     |    9 -----
 dlls/crypt32/tests/ctl.c |    4 --
 3 files changed, 85 insertions(+), 13 deletions(-)

diff --git a/dlls/crypt32/ctl.c b/dlls/crypt32/ctl.c
index 12ee19d..9b6d2e0 100644
--- a/dlls/crypt32/ctl.c
+++ b/dlls/crypt32/ctl.c
@@ -29,6 +29,91 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
 
+#define CtlContext_CopyProperties(to, from) \
+ Context_CopyProperties((to), (from), sizeof(CTL_CONTEXT))
+
+BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore,
+ PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition,
+ PCCTL_CONTEXT* ppStoreContext)
+{
+    PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
+    BOOL ret = TRUE;
+    PCCTL_CONTEXT toAdd = NULL, existing = NULL;
+
+    TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCtlContext, dwAddDisposition,
+     ppStoreContext);
+
+    if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
+    {
+        existing = CertFindCTLInStore(hCertStore, 0, 0, CTL_FIND_EXISTING,
+         pCtlContext, NULL);
+    }
+
+    switch (dwAddDisposition)
+    {
+    case CERT_STORE_ADD_ALWAYS:
+        toAdd = CertDuplicateCTLContext(pCtlContext);
+        break;
+    case CERT_STORE_ADD_NEW:
+        if (existing)
+        {
+            TRACE("found matching CTL, not adding\n");
+            SetLastError(CRYPT_E_EXISTS);
+            ret = FALSE;
+        }
+        else
+            toAdd = CertDuplicateCTLContext(pCtlContext);
+        break;
+    case CERT_STORE_ADD_NEWER:
+        if (existing)
+        {
+            LONG newer = CompareFileTime(&existing->pCtlInfo->ThisUpdate,
+             &pCtlContext->pCtlInfo->ThisUpdate);
+
+            if (newer < 0)
+                toAdd = CertDuplicateCTLContext(pCtlContext);
+            else
+            {
+                TRACE("existing CTL is newer, not adding\n");
+                SetLastError(CRYPT_E_EXISTS);
+                ret = FALSE;
+            }
+        }
+        else
+            toAdd = CertDuplicateCTLContext(pCtlContext);
+        break;
+    case CERT_STORE_ADD_REPLACE_EXISTING:
+        toAdd = CertDuplicateCTLContext(pCtlContext);
+        break;
+    case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES:
+        toAdd = CertDuplicateCTLContext(pCtlContext);
+        if (existing)
+            CtlContext_CopyProperties(toAdd, existing);
+        break;
+    case CERT_STORE_ADD_USE_EXISTING:
+        if (existing)
+            CtlContext_CopyProperties(existing, pCtlContext);
+        break;
+    default:
+        FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
+        ret = FALSE;
+    }
+
+    if (toAdd)
+    {
+        if (store)
+            ret = store->ctls.addContext(store, (void *)toAdd,
+             (void *)existing, (const void **)ppStoreContext);
+        else if (ppStoreContext)
+            *ppStoreContext = CertDuplicateCTLContext(toAdd);
+        CertFreeCTLContext(toAdd);
+    }
+    CertFreeCTLContext(existing);
+
+    TRACE("returning %d\n", ret);
+    return ret;
+}
+
 BOOL WINAPI CertAddEncodedCTLToStore(HCERTSTORE hCertStore,
  DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded, DWORD cbCtlEncoded,
  DWORD dwAddDisposition, PCCTL_CONTEXT *ppCtlContext)
diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c
index 180740c..6d9177e 100644
--- a/dlls/crypt32/store.c
+++ b/dlls/crypt32/store.c
@@ -1091,15 +1091,6 @@ PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore,
     return ret;
 }
 
-BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore,
- PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition,
- PCCTL_CONTEXT* ppStoreContext)
-{
-    FIXME("(%p, %p, %08x, %p): stub\n", hCertStore, pCtlContext,
-     dwAddDisposition, ppStoreContext);
-    return TRUE;
-}
-
 HCERTSTORE WINAPI CertDuplicateStore(HCERTSTORE hCertStore)
 {
     WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
diff --git a/dlls/crypt32/tests/ctl.c b/dlls/crypt32/tests/ctl.c
index b6cccb2..168b05d 100644
--- a/dlls/crypt32/tests/ctl.c
+++ b/dlls/crypt32/tests/ctl.c
@@ -333,7 +333,6 @@ static void testAddCTLToStore(void)
         if (ctl)
             numCTLs++;
     } while (ctl);
-    todo_wine
     ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
     CertCloseStore(store, 0);
 
@@ -350,7 +349,6 @@ static void testAddCTLToStore(void)
      signedCTLWithCTLInnerContentAndBadSig,
      sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_NEW,
      NULL);
-    todo_wine
     ok(!ret && GetLastError() == CRYPT_E_EXISTS,
      "expected CRYPT_E_EXISTS, got %08x\n", GetLastError());
     CertCloseStore(store, 0);
@@ -376,7 +374,6 @@ static void testAddCTLToStore(void)
         if (ctl)
             numCTLs++;
     } while (ctl);
-    todo_wine
     ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
     CertCloseStore(store, 0);
 
@@ -401,7 +398,6 @@ static void testAddCTLToStore(void)
         if (ctl)
             numCTLs++;
     } while (ctl);
-    todo_wine
     ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
     CertCloseStore(store, 0);
 }




More information about the wine-cvs mailing list