[wintrust] Use the return value of CryptRegisterOIDFunction.

Paul Vriens Paul.Vriens at xs4all.nl
Mon Sep 11 04:23:20 CDT 2006


Hi,

now that CryptRegisterOIDFunction is fixed, we can use the return value and
last error if needed.

One could argue whether all this checking is necessary. When the first
registry write fails, the rest will fail most likely as well. I think however
that this provides some more insight in the function. DllRegisterServer is not
a function that will be called everyday in a normal enviroment, so the extra
checks will have no negative impact on normal operation.

Changelog
  Use the return value of CryptRegisterOIDFunction.

Cheers,

Paul
---
 dlls/wintrust/register.c |   77 +++++++++++++++++++++++++++++-----------------
 1 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/dlls/wintrust/register.c b/dlls/wintrust/register.c
index c9baea5..a00617f 100644
--- a/dlls/wintrust/register.c
+++ b/dlls/wintrust/register.c
@@ -727,6 +727,7 @@ HRESULT WINAPI DllRegisterServer(void)
     static const CHAR WVTAsn1SpcSpOpusInfoDecode[]            = "WVTAsn1SpcSpOpusInfoDecode";
     HRESULT Res = S_OK;
     HKEY Key;
+    BOOL Ret;
 
     TRACE("\n");
 
@@ -740,39 +741,57 @@ HRESULT WINAPI DllRegisterServer(void)
      * - One call to CryptSIPRemoveProvider (do we need that?)
      */
 
+    /* Testing on native shows that when an error is encountered in one of the CryptRegisterOIDFunction calls
+     * the rest of these calls is skipped. Registering is however continued for the trust providers.
+     *
+     * We are not totally in line with native as there all decoding functions are registered after all encoding
+     * functions.
+     */
 #define WINTRUST_REGISTEROID( oid, encode_funcname, decode_funcname ) \
-    CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname); \
-    CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname)
-
-    WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, WVTAsn1SpcPeImageDataEncode, WVTAsn1SpcPeImageDataDecode);
-    WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, WVTAsn1SpcPeImageDataEncode, WVTAsn1SpcPeImageDataDecode);
-    WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode);
-    WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode);
-    WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode);
-    WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode);
-    WINTRUST_REGISTEROID(SPC_LINK_OBJID, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode);
-    WINTRUST_REGISTEROID(SPC_LINK_STRUCT, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode);
-    WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, WVTAsn1SpcSigInfoEncode, WVTAsn1SpcSigInfoDecode);
-    WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, WVTAsn1SpcSigInfoEncode, WVTAsn1SpcSigInfoDecode);
-    WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, WVTAsn1SpcIndirectDataContentEncode, WVTAsn1SpcIndirectDataContentDecode);
-    WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, WVTAsn1SpcIndirectDataContentEncode, WVTAsn1SpcIndirectDataContentDecode);
-    WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, WVTAsn1SpcSpAgencyInfoEncode, WVTAsn1SpcSpAgencyInfoDecode);
-    WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, WVTAsn1SpcSpAgencyInfoEncode, WVTAsn1SpcSpAgencyInfoDecode);
-    WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, WVTAsn1SpcMinimalCriteriaInfoEncode, WVTAsn1SpcMinimalCriteriaInfoDecode);
-    WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, WVTAsn1SpcMinimalCriteriaInfoEncode, WVTAsn1SpcMinimalCriteriaInfoDecode);
-    WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, WVTAsn1SpcFinancialCriteriaInfoEncode, WVTAsn1SpcFinancialCriteriaInfoDecode);
-    WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, WVTAsn1SpcFinancialCriteriaInfoEncode, WVTAsn1SpcFinancialCriteriaInfoDecode);
-    WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, WVTAsn1SpcStatementTypeEncode, WVTAsn1SpcStatementTypeDecode);
-    WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, WVTAsn1SpcStatementTypeEncode, WVTAsn1SpcStatementTypeDecode);
-    WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, WVTAsn1CatNameValueEncode, WVTAsn1CatNameValueDecode);
-    WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, WVTAsn1CatNameValueEncode, WVTAsn1CatNameValueDecode);
-    WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, WVTAsn1CatMemberInfoEncode, WVTAsn1CatMemberInfoDecode);
-    WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, WVTAsn1CatMemberInfoEncode, WVTAsn1CatMemberInfoDecode);
-    WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, WVTAsn1SpcSpOpusInfoEncode, WVTAsn1SpcSpOpusInfoDecode);
-    WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, WVTAsn1SpcSpOpusInfoEncode, WVTAsn1SpcSpOpusInfoDecode);
+    Ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname); \
+    if (!Ret) \
+    { \
+        Res = HRESULT_FROM_WIN32(GetLastError()); \
+        goto add_trust_providers; \
+    } \
+    Ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname); \
+    if (!Ret) \
+    { \
+        Res = HRESULT_FROM_WIN32(GetLastError()); \
+        goto add_trust_providers; \
+    }
+
+    WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, WVTAsn1SpcPeImageDataEncode, WVTAsn1SpcPeImageDataDecode)
+    WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, WVTAsn1SpcPeImageDataEncode, WVTAsn1SpcPeImageDataDecode)
+    WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode)
+    WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode)
+    WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode)
+    WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode)
+    WINTRUST_REGISTEROID(SPC_LINK_OBJID, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode)
+    WINTRUST_REGISTEROID(SPC_LINK_STRUCT, WVTAsn1SpcLinkEncode, WVTAsn1SpcLinkDecode)
+    WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, WVTAsn1SpcSigInfoEncode, WVTAsn1SpcSigInfoDecode)
+    WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, WVTAsn1SpcSigInfoEncode, WVTAsn1SpcSigInfoDecode)
+    WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, WVTAsn1SpcIndirectDataContentEncode, WVTAsn1SpcIndirectDataContentDecode)
+    WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, WVTAsn1SpcIndirectDataContentEncode, WVTAsn1SpcIndirectDataContentDecode)
+    WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, WVTAsn1SpcSpAgencyInfoEncode, WVTAsn1SpcSpAgencyInfoDecode)
+    WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, WVTAsn1SpcSpAgencyInfoEncode, WVTAsn1SpcSpAgencyInfoDecode)
+    WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, WVTAsn1SpcMinimalCriteriaInfoEncode, WVTAsn1SpcMinimalCriteriaInfoDecode)
+    WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, WVTAsn1SpcMinimalCriteriaInfoEncode, WVTAsn1SpcMinimalCriteriaInfoDecode)
+    WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, WVTAsn1SpcFinancialCriteriaInfoEncode, WVTAsn1SpcFinancialCriteriaInfoDecode)
+    WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, WVTAsn1SpcFinancialCriteriaInfoEncode, WVTAsn1SpcFinancialCriteriaInfoDecode)
+    WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, WVTAsn1SpcStatementTypeEncode, WVTAsn1SpcStatementTypeDecode)
+    WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, WVTAsn1SpcStatementTypeEncode, WVTAsn1SpcStatementTypeDecode)
+    WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, WVTAsn1CatNameValueEncode, WVTAsn1CatNameValueDecode)
+    WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, WVTAsn1CatNameValueEncode, WVTAsn1CatNameValueDecode)
+    WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, WVTAsn1CatMemberInfoEncode, WVTAsn1CatMemberInfoDecode)
+    WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, WVTAsn1CatMemberInfoEncode, WVTAsn1CatMemberInfoDecode)
+    WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, WVTAsn1SpcSpOpusInfoEncode, WVTAsn1SpcSpOpusInfoDecode)
+    WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, WVTAsn1SpcSpOpusInfoEncode, WVTAsn1SpcSpOpusInfoDecode)
 
 #undef WINTRUST_REGISTEROID
 
+add_trust_providers:
+
     /* Testing on W2K3 shows:
      * If we cannot open HKLM\Software\Microsoft\Cryptography\Providers\Trust
      * for writing, DllRegisterServer returns S_FALSE. If the key can be opened 
-- 
1.4.2




More information about the wine-patches mailing list