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.

88 lines
2.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: syscert.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV hProv,
  12. const char * szSubsystemProtocol) {
  13. DWORD dwFlags = CERT_STORE_NO_CRYPT_RELEASE_FLAG;
  14. if (0 == _stricmp(szSubsystemProtocol, "SPC"))
  15. dwFlags |= CERT_SYSTEM_STORE_LOCAL_MACHINE;
  16. else
  17. dwFlags |= CERT_SYSTEM_STORE_CURRENT_USER;
  18. return CertOpenStore(
  19. CERT_STORE_PROV_SYSTEM_A,
  20. 0, // dwEncodingType
  21. hProv,
  22. dwFlags,
  23. (const void *) szSubsystemProtocol
  24. );
  25. }
  26. HCERTSTORE WINAPI CertOpenSystemStoreW(HCRYPTPROV hProv,
  27. const WCHAR * wcsSubsystemProtocol) {
  28. DWORD dwFlags = CERT_STORE_NO_CRYPT_RELEASE_FLAG;
  29. if (0 == _wcsicmp(wcsSubsystemProtocol, L"SPC"))
  30. dwFlags |= CERT_SYSTEM_STORE_LOCAL_MACHINE;
  31. else
  32. dwFlags |= CERT_SYSTEM_STORE_CURRENT_USER;
  33. return CertOpenStore(
  34. CERT_STORE_PROV_SYSTEM_W,
  35. 0, // dwEncodingType
  36. hProv,
  37. dwFlags,
  38. (const void *) wcsSubsystemProtocol
  39. );
  40. }
  41. BOOL WINAPI CertAddEncodedCertificateToSystemStoreA(
  42. const char * szCertStoreName,
  43. const BYTE * pbCertEncoded,
  44. DWORD cbCertEncoded
  45. )
  46. {
  47. HCERTSTORE hStore = NULL;
  48. BOOL fOk;
  49. fOk =
  50. (hStore = CertOpenSystemStoreA(NULL, szCertStoreName)) != NULL &&
  51. CertAddEncodedCertificateToStore(hStore, X509_ASN_ENCODING,
  52. pbCertEncoded, cbCertEncoded, CERT_STORE_ADD_USE_EXISTING,
  53. NULL);
  54. if(hStore != NULL)
  55. CertCloseStore(hStore, 0);
  56. return(fOk);
  57. }
  58. BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(
  59. const WCHAR * wcsCertStoreName,
  60. const BYTE * pbCertEncoded,
  61. DWORD cbCertEncoded
  62. )
  63. {
  64. HCERTSTORE hStore = NULL;
  65. BOOL fOk;
  66. fOk =
  67. (hStore = CertOpenSystemStoreW(NULL, wcsCertStoreName)) != NULL &&
  68. CertAddEncodedCertificateToStore(hStore, X509_ASN_ENCODING,
  69. pbCertEncoded, cbCertEncoded, CERT_STORE_ADD_USE_EXISTING, NULL);
  70. if(hStore != NULL)
  71. CertCloseStore(hStore, 0);
  72. return(fOk);
  73. }