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.

112 lines
3.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: initprov.cpp
  8. //
  9. // Contents: Microsoft Internet Security Authenticode Policy Provider
  10. //
  11. // Functions: SoftpubInitialize
  12. //
  13. // History: 05-Jun-1997 pberkman created
  14. //
  15. //--------------------------------------------------------------------------
  16. #include "global.hxx"
  17. static char *pwszUsageOID = szOID_PKIX_KP_CODE_SIGNING;
  18. HRESULT WINAPI SoftpubInitialize(CRYPT_PROVIDER_DATA *pProvData)
  19. {
  20. if (!(pProvData->padwTrustStepErrors) ||
  21. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS))
  22. {
  23. return(S_FALSE);
  24. }
  25. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = ERROR_SUCCESS;
  26. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FILEIO] = ERROR_SUCCESS;
  27. if (!(_ISINSTRUCT(CRYPT_PROVIDER_DATA, pProvData->cbStruct, fRecallWithState)) ||
  28. (!(pProvData->fRecallWithState)))
  29. {
  30. if (_ISINSTRUCT(CRYPT_PROVIDER_DATA, pProvData->cbStruct, pszUsageOID))
  31. {
  32. pProvData->pszUsageOID = pwszUsageOID;
  33. }
  34. }
  35. //
  36. // for file type calls, make sure the file handle is valid -- open if necessary.
  37. //
  38. HANDLE *phFile;
  39. const WCHAR *pcwszFile;
  40. switch (pProvData->pWintrustData->dwUnionChoice)
  41. {
  42. case WTD_CHOICE_FILE:
  43. phFile = &pProvData->pWintrustData->pFile->hFile;
  44. pcwszFile = pProvData->pWintrustData->pFile->pcwszFilePath;
  45. break;
  46. case WTD_CHOICE_CATALOG:
  47. phFile = &pProvData->pWintrustData->pCatalog->hMemberFile;
  48. pcwszFile = pProvData->pWintrustData->pCatalog->pcwszMemberFilePath;
  49. break;
  50. case WTD_CHOICE_BLOB:
  51. pcwszFile = NULL;
  52. break;
  53. default:
  54. return(ERROR_SUCCESS);
  55. }
  56. if (!(pProvData->pPDSip))
  57. {
  58. if (!(pProvData->pPDSip = (PROVDATA_SIP *)pProvData->psPfns->pfnAlloc(sizeof(PROVDATA_SIP))))
  59. {
  60. pProvData->dwError = GetLastError();
  61. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_SYSTEM_ERROR;
  62. return(S_FALSE);
  63. }
  64. pProvData->dwSubjectChoice = CPD_CHOICE_SIP;
  65. memset(pProvData->pPDSip, 0x00, sizeof(PROVDATA_SIP));
  66. pProvData->pPDSip->cbStruct = sizeof(PROVDATA_SIP);
  67. }
  68. if (pcwszFile)
  69. {
  70. //
  71. // we're looking at a file based object...
  72. //
  73. pProvData->fOpenedFile = FALSE;
  74. if (!(*phFile) || (*phFile == INVALID_HANDLE_VALUE))
  75. {
  76. if ((*phFile = CreateFileU(pcwszFile,
  77. GENERIC_READ,
  78. FILE_SHARE_READ, // we're only reading!
  79. NULL,
  80. OPEN_EXISTING,
  81. FILE_ATTRIBUTE_NORMAL,
  82. NULL)) == INVALID_HANDLE_VALUE)
  83. {
  84. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FILEIO] = GetLastError();
  85. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = CRYPT_E_FILE_ERROR;
  86. }
  87. else
  88. {
  89. pProvData->fOpenedFile = TRUE;
  90. }
  91. }
  92. }
  93. return(ERROR_SUCCESS);
  94. }