Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
6.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: dllmain.cpp
  8. //
  9. // Contents: Microsoft Internet Security Authenticode Policy Provider
  10. //
  11. // Functions: DllMain
  12. // DllRegisterServer
  13. // DllUnregisterServer
  14. // OpenTrustedPublisherStore
  15. // OpenDisallowedStore
  16. //
  17. // *** local functions ***
  18. // SPNew
  19. //
  20. // History: 28-May-1997 pberkman created
  21. //
  22. //--------------------------------------------------------------------------
  23. #include "global.hxx"
  24. HINSTANCE hinst;
  25. //////////////////////////////////////////////////////////////////////////////////////
  26. //
  27. // standard DLL exports ...
  28. //
  29. //
  30. BOOL WINAPI SoftpubDllMain(HANDLE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
  31. {
  32. switch (fdwReason) {
  33. case DLL_PROCESS_ATTACH:
  34. hinst = (HINSTANCE)hInstDLL;
  35. break;
  36. case DLL_PROCESS_DETACH:
  37. break;
  38. case DLL_THREAD_DETACH:
  39. default:
  40. break;
  41. }
  42. return(TRUE);
  43. }
  44. HCERTSTORE
  45. WINAPI
  46. _OpenHKCUStore(
  47. IN LPCWSTR pwszStore
  48. )
  49. {
  50. HCERTSTORE hStore;
  51. hStore = CertOpenStore(
  52. CERT_STORE_PROV_SYSTEM_W,
  53. 0,
  54. NULL,
  55. CERT_SYSTEM_STORE_CURRENT_USER |
  56. CERT_STORE_MAXIMUM_ALLOWED_FLAG |
  57. CERT_STORE_SHARE_CONTEXT_FLAG,
  58. (const void *) pwszStore
  59. );
  60. if (hStore) {
  61. CertControlStore(
  62. hStore,
  63. 0, // dwFlags
  64. CERT_STORE_CTRL_AUTO_RESYNC,
  65. NULL // pvCtrlPara
  66. );
  67. }
  68. return hStore;
  69. }
  70. HCERTSTORE
  71. WINAPI
  72. OpenTrustedPublisherStore()
  73. {
  74. return _OpenHKCUStore(L"TrustedPublisher");
  75. }
  76. HCERTSTORE
  77. WINAPI
  78. OpenDisallowedStore()
  79. {
  80. return _OpenHKCUStore(L"Disallowed");
  81. }
  82. #include "wvtver1.h"
  83. STDAPI SoftpubDllRegisterServer(void)
  84. {
  85. GUID gV1UISup = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
  86. GUID gV1UINoBad = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
  87. GUID gV2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  88. GUID gV2TrstTest = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
  89. GUID gCert = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
  90. CRYPT_REGISTER_ACTIONID sRegAID;
  91. CRYPT_PROVIDER_REGDEFUSAGE sDefUsage;
  92. BOOL fRet;
  93. fRet = TRUE;
  94. memset(&sDefUsage, 0x00, sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
  95. sDefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
  96. sDefUsage.pgActionID = &gV2;
  97. fRet &= WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &sDefUsage);
  98. memset(&sRegAID, 0x00, sizeof(CRYPT_REGISTER_ACTIONID));
  99. sRegAID.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  100. sRegAID.sInitProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  101. sRegAID.sInitProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  102. sRegAID.sInitProvider.pwszFunctionName = SP_INIT_FUNCTION;
  103. sRegAID.sObjectProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  104. sRegAID.sObjectProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  105. sRegAID.sObjectProvider.pwszFunctionName = SP_OBJTRUST_FUNCTION;
  106. sRegAID.sSignatureProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  107. sRegAID.sSignatureProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  108. sRegAID.sSignatureProvider.pwszFunctionName = SP_SIGTRUST_FUNCTION;
  109. sRegAID.sCertificateProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  110. sRegAID.sCertificateProvider.pwszDLLName = WT_PROVIDER_DLL_NAME;
  111. sRegAID.sCertificateProvider.pwszFunctionName = WT_PROVIDER_CERTTRUST_FUNCTION;
  112. sRegAID.sCertificatePolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  113. sRegAID.sCertificatePolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  114. sRegAID.sCertificatePolicyProvider.pwszFunctionName = SP_CHKCERT_FUNCTION;
  115. sRegAID.sFinalPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  116. sRegAID.sFinalPolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  117. sRegAID.sFinalPolicyProvider.pwszFunctionName = SP_FINALPOLICY_FUNCTION;
  118. sRegAID.sCleanupProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  119. sRegAID.sCleanupProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  120. sRegAID.sCleanupProvider.pwszFunctionName = SP_CLEANUPPOLICY_FUNCTION;
  121. //
  122. // V2
  123. //
  124. fRet &= WintrustAddActionID(&gV2, 0, &sRegAID);
  125. //
  126. // support for V1
  127. //
  128. fRet &= WintrustAddActionID(&gV1UISup, 0, &sRegAID);
  129. fRet &= WintrustAddActionID(&gV1UINoBad, 0, &sRegAID);
  130. sRegAID.sInitProvider.pwszFunctionName = SP_GENERIC_CERT_INIT_FUNCTION;
  131. fRet &= WintrustAddActionID(&gCert, 0, &sRegAID);
  132. sRegAID.sInitProvider.pwszFunctionName = SP_INIT_FUNCTION;
  133. //
  134. // testing support
  135. //
  136. sRegAID.sTestPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  137. sRegAID.sTestPolicyProvider.pwszDLLName = SP_POLICY_PROVIDER_DLL_NAME;
  138. sRegAID.sTestPolicyProvider.pwszFunctionName = SP_TESTDUMPPOLICY_FUNCTION_TEST;
  139. fRet &= WintrustAddActionID(&gV2TrstTest, 0, &sRegAID);
  140. memset(&sRegAID.sTestPolicyProvider, 0x00, sizeof(CRYPT_TRUST_REG_ENTRY));
  141. if (fRet)
  142. {
  143. HTTPSRegisterServer();
  144. OfficeRegisterServer();
  145. DriverRegisterServer();
  146. GenericChainRegisterServer();
  147. return(S_OK);
  148. }
  149. return(S_FALSE);
  150. }
  151. STDAPI SoftpubDllUnregisterServer(void)
  152. {
  153. GUID gV1UISup = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
  154. GUID gV1UINoBad = V1_WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
  155. GUID gV2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  156. GUID gV2TrstTest = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
  157. GUID gCert = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
  158. WintrustRemoveActionID(&gV1UISup);
  159. WintrustRemoveActionID(&gV1UINoBad);
  160. WintrustRemoveActionID(&gV2);
  161. WintrustRemoveActionID(&gV2TrstTest);
  162. WintrustRemoveActionID(&gCert);
  163. HTTPSUnregisterServer();
  164. OfficeUnregisterServer();
  165. DriverUnregisterServer();
  166. GenericChainUnregisterServer();
  167. return(S_OK);
  168. }