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.

109 lines
2.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: chains.cpp
  8. //
  9. // Contents: Microsoft Internet Security Trust Provider
  10. //
  11. // Functions: AddToSignerChain
  12. // AddToCertChain
  13. // AddToStoreChain
  14. // AllocateNewChain
  15. // DeallocateCertChain
  16. // DeallocateStoreChain
  17. //
  18. // History: 29-May-1997 pberkman created
  19. //
  20. //--------------------------------------------------------------------------
  21. #include "global.hxx"
  22. BOOL AddToSignerChain(CRYPT_PROVIDER_SGNR *psSgnr2Add, DWORD *pcSgnrs, CRYPT_PROVIDER_SGNR **ppSgnrChain)
  23. {
  24. return(AllocateNewChain(sizeof(CRYPT_PROVIDER_SGNR), psSgnr2Add, pcSgnrs, (void **)ppSgnrChain,
  25. psSgnr2Add->cbStruct));
  26. }
  27. BOOL AddToCertChain(CRYPT_PROVIDER_CERT *pPCert2Add, DWORD *pcPCerts,
  28. CRYPT_PROVIDER_CERT **ppPCertChain)
  29. {
  30. return(AllocateNewChain(sizeof(CRYPT_PROVIDER_CERT), pPCert2Add, pcPCerts, (void **)ppPCertChain,
  31. pPCert2Add->cbStruct));
  32. }
  33. BOOL AddToStoreChain(HCERTSTORE hStore2Add, DWORD *pcChain, HCERTSTORE **pphStoreChain)
  34. {
  35. return(AllocateNewChain(sizeof(HCERTSTORE), (void *)&hStore2Add, pcChain, (void **)pphStoreChain,
  36. sizeof(HCERTSTORE)));
  37. }
  38. BOOL AllocateNewChain(DWORD cbMember, void *pNewMember, DWORD *pcChain, void **ppChain, DWORD cbAssumeSize)
  39. {
  40. void *pNewChain;
  41. DWORD cNew;
  42. if (cbAssumeSize > cbMember)
  43. {
  44. //
  45. // the client is using structures more current that we are...
  46. //
  47. SetLastError(ERROR_INVALID_PARAMETER);
  48. return(FALSE);
  49. }
  50. cNew = *pcChain + 1;
  51. if (!(pNewChain = (void *)WVTNew(cbMember * cNew)))
  52. {
  53. return(FALSE);
  54. }
  55. memset(pNewChain, 0x00, cbMember * cNew);
  56. for (int i = 0; i < (int)*pcChain; i++)
  57. {
  58. memcpy((char *)pNewChain + (i * cbMember), (char *)*ppChain + (i * cbMember), cbMember);
  59. }
  60. DELETE_OBJECT(*ppChain);
  61. memcpy((char *)pNewChain + ((cNew - 1) * cbMember), pNewMember, cbAssumeSize);
  62. *ppChain = pNewChain;
  63. *pcChain = cNew;
  64. return(TRUE);
  65. }
  66. void DeallocateCertChain(DWORD csPCert, CRYPT_PROVIDER_CERT **pasPCertChain)
  67. {
  68. CRYPT_PROVIDER_CERT *pas;
  69. pas = *pasPCertChain;
  70. for (int i = 0; i < (int)csPCert; i++)
  71. {
  72. if (pas[i].pCert)
  73. {
  74. CertFreeCertificateContext(pas[i].pCert);
  75. }
  76. if (pas[i].pTrustListContext)
  77. {
  78. CertFreeCTLContext(pas[i].pTrustListContext);
  79. }
  80. }
  81. }
  82. void DeallocateStoreChain(DWORD csStore, HCERTSTORE *pphStoreChain)
  83. {
  84. for (int i = 0; i < (int)csStore; i++)
  85. {
  86. CertCloseStore(pphStoreChain[i], 0);
  87. }
  88. }