From 7ee54f74e6ea1fac7351847f401f13d74e45203d Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang@gmail.com>
Date: Tue, 3 Nov 2009 13:54:15 -0800
Subject: [PATCH] Implement CertAddEncodedCertificateToSystemStoreA/W

---
 dlls/crypt32/cert.c       |   38 ++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/crypt32.spec |    4 ++--
 include/wincrypt.h        |    7 +++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index 634c643..4f3df32 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -71,6 +71,44 @@ BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore,
     return ret;
 }
 
+BOOL WINAPI CertAddEncodedCertificateToSystemStoreA(LPCSTR pszCertStoreName,
+ const BYTE *pbCertEncoded, DWORD cbCertEncoded)
+{
+    HCERTSTORE store;
+    BOOL ret = FALSE;
+
+    TRACE("(%s, %p, %d)\n", debugstr_a(pszCertStoreName), pbCertEncoded,
+     cbCertEncoded);
+
+    store = CertOpenSystemStoreA(0, pszCertStoreName);
+    if (store)
+    {
+        ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
+         pbCertEncoded, cbCertEncoded, CERT_STORE_ADD_USE_EXISTING, NULL);
+        CertCloseStore(store, 0);
+    }
+    return ret;
+}
+
+BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName,
+ const BYTE *pbCertEncoded, DWORD cbCertEncoded)
+{
+    HCERTSTORE store;
+    BOOL ret = FALSE;
+
+    TRACE("(%s, %p, %d)\n", debugstr_w(pszCertStoreName), pbCertEncoded,
+     cbCertEncoded);
+
+    store = CertOpenSystemStoreW(0, pszCertStoreName);
+    if (store)
+    {
+        ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
+         pbCertEncoded, cbCertEncoded, CERT_STORE_ADD_USE_EXISTING, NULL);
+        CertCloseStore(store, 0);
+    }
+    return ret;
+}
+
 BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore,
  PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
  PCCERT_CONTEXT *ppCertContext)
diff --git a/dlls/crypt32/crypt32.spec b/dlls/crypt32/crypt32.spec
index ef5d6e6..b096c09 100644
--- a/dlls/crypt32/crypt32.spec
+++ b/dlls/crypt32/crypt32.spec
@@ -5,8 +5,8 @@
 @ stdcall CertAddEncodedCRLToStore(ptr long ptr long long ptr)
 @ stdcall CertAddEncodedCTLToStore(ptr long ptr long long ptr)
 @ stdcall CertAddEncodedCertificateToStore(ptr long ptr long long ptr)
-@ stub CertAddEncodedCertificateToSystemStoreA
-@ stub CertAddEncodedCertificateToSystemStoreW
+@ stdcall CertAddEncodedCertificateToSystemStoreA(str ptr long)
+@ stdcall CertAddEncodedCertificateToSystemStoreW(wstr ptr long)
 @ stdcall CertAddEnhancedKeyUsageIdentifier(ptr str)
 @ stdcall CertAddSerializedElementToStore(ptr ptr long long long long ptr ptr)
 @ stdcall CertAddStoreToCollection(ptr ptr long long)
diff --git a/include/wincrypt.h b/include/wincrypt.h
index 32b523d..4e2f60b 100644
--- a/include/wincrypt.h
+++ b/include/wincrypt.h
@@ -4054,6 +4054,13 @@ BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore,
  DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded,
  DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext);
 
+BOOL WINAPI CertAddEncodedCertificateToSystemStoreA(LPCSTR pszCertStoreName,
+ const BYTE *pbCertEncoded, DWORD cbCertEncoded);
+BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName,
+ const BYTE *pbCertEncoded, DWORD cbCertEncoded);
+#define CertAddEncodedCertificateToSystemStore \
+ WINELIB_NAME_AW(CertAddEncodedCertificateToSystemStore)
+
 BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore,
  DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded,
  DWORD dwAddDisposition, PCCRL_CONTEXT *ppCrlContext);
-- 
1.6.0.6

