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
3.2 KiB

  1. //
  2. // Copyright (C) 1993-1999 Microsoft Corporation. All Rights Reserved.
  3. //
  4. // MODULE: rdscred.cpp
  5. //
  6. // PURPOSE: Implements RDS credential management
  7. //
  8. // FUNCTIONS:
  9. // InitT120Credentials(VOID)
  10. //
  11. // COMMENTS:
  12. //
  13. //
  14. // AUTHOR: Claus Giloi
  15. //
  16. #include <precomp.h>
  17. #include <wincrypt.h>
  18. #include <tsecctrl.h>
  19. #include <nmmkcert.h>
  20. extern INmSysInfo2 * g_pNmSysInfo; // Interface to SysInfo
  21. BOOL InitT120Credentials(VOID)
  22. {
  23. HCERTSTORE hStore;
  24. PCCERT_CONTEXT pCertContext = NULL;
  25. BOOL bRet = FALSE;
  26. // Open the "MY" local machine certificate store. This one will be
  27. // used when we're running as a service
  28. hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM,
  29. X509_ASN_ENCODING,
  30. 0,
  31. CERT_SYSTEM_STORE_LOCAL_MACHINE,
  32. L"MY" );
  33. if ( NULL != hStore )
  34. {
  35. #ifdef DUMPCERTS
  36. DumpCertStore(this, "Local Machine Store MY", hStore);
  37. #endif // DUMPCERTS
  38. // Check the local machine store for a certificate - any!
  39. pCertContext = CertFindCertificateInStore(hStore,
  40. X509_ASN_ENCODING,
  41. 0,
  42. CERT_FIND_ANY,
  43. NULL,
  44. NULL);
  45. CertCloseStore( hStore, 0);
  46. }
  47. if ( NULL == pCertContext )
  48. {
  49. // Open the "_NMSTR" local machine certificate store.
  50. hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM,
  51. X509_ASN_ENCODING,
  52. 0,
  53. CERT_SYSTEM_STORE_LOCAL_MACHINE,
  54. WSZNMSTORE );
  55. if ( NULL != hStore )
  56. {
  57. #ifdef DUMPCERTS
  58. DumpCertStore(this, "Local Machine Store _NMSTR", hStore);
  59. #endif // DUMPCERTS
  60. // Check the local machine store for a certificate - any!
  61. pCertContext = CertFindCertificateInStore(hStore,
  62. X509_ASN_ENCODING,
  63. 0,
  64. CERT_FIND_ANY,
  65. NULL,
  66. NULL);
  67. CertCloseStore( hStore, 0);
  68. }
  69. }
  70. if ( NULL == pCertContext )
  71. {
  72. WARNING_OUT(("No service context cert found!"));
  73. return bRet;
  74. }
  75. DWORD dwResult = -1;
  76. g_pNmSysInfo->ProcessSecurityData(
  77. TPRTCTRL_SETX509CREDENTIALS,
  78. (DWORD_PTR)pCertContext, 0,
  79. &dwResult);
  80. if ( !dwResult )
  81. {
  82. bRet = TRUE;
  83. }
  84. else
  85. {
  86. ERROR_OUT(("InitT120Credentials - failed in T.120"));
  87. }
  88. CertFreeCertificateContext ( pCertContext );
  89. return bRet;
  90. }
  91.