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.

185 lines
5.2 KiB

  1. /*++
  2. Module Name:
  3. wrapmaps.cpp
  4. Abstract:
  5. wrapper classes for the mapper classes provided by phillich. See the headers in iismap.hxx
  6. These wrappers simplify the code interfaces for accessing the data.
  7. Author:
  8. Boyd Multerer boydm
  9. Boyd Multerer boydm 4/16/97
  10. --*/
  11. //C:\nt\public\sdk\lib\i386
  12. #include "stdafx.h"
  13. #include "WrapMaps.h"
  14. #include <wincrypt.h>
  15. //#define IISMDB_INDEX_CERT11_CERT 0
  16. //#define IISMDB_INDEX_CERT11_NT_ACCT 1
  17. //#define IISMDB_INDEX_CERT11_NAME 2
  18. //#define IISMDB_INDEX_CERT11_ENABLED 3
  19. //#define IISMDB_INDEX_CERT11_NB 4
  20. //----------------------------------------------------------------
  21. BOOL C11Mapping::GetCertificate( PUCHAR* ppCert, DWORD* pcbCert )
  22. {
  23. *ppCert = (PUCHAR)m_pCert;
  24. *pcbCert = m_cbCert;
  25. return TRUE;
  26. }
  27. //----------------------------------------------------------------
  28. BOOL C11Mapping::SetCertificate( PUCHAR pCert, DWORD cbCert )
  29. {
  30. // we want to store a copy of the certificate - first free any existing cert
  31. if ( m_pCert )
  32. {
  33. GlobalFree( m_pCert );
  34. cbCert = 0;
  35. m_pCert = NULL;
  36. }
  37. // copy in the new one
  38. m_pCert = (PVOID)GlobalAlloc( GPTR, cbCert );
  39. if ( !m_pCert ) return FALSE;
  40. CopyMemory( m_pCert, pCert, cbCert );
  41. m_cbCert = cbCert;
  42. return TRUE;
  43. }
  44. //----------------------------------------------------------------
  45. BOOL C11Mapping::GetNTAccount( CString &szAccount )
  46. {
  47. szAccount = m_szAccount;
  48. return TRUE;
  49. }
  50. //----------------------------------------------------------------
  51. BOOL C11Mapping::SetNTAccount( CString szAccount )
  52. {
  53. m_szAccount = szAccount;
  54. return TRUE;
  55. }
  56. //----------------------------------------------------------------
  57. BOOL C11Mapping::GetNTPassword( CStrPassword &szPassword )
  58. {
  59. szPassword = m_szPassword;
  60. return TRUE;
  61. }
  62. //----------------------------------------------------------------
  63. BOOL C11Mapping::SetNTPassword( CString szPassword )
  64. {
  65. m_szPassword = szPassword;
  66. return TRUE;
  67. }
  68. //----------------------------------------------------------------
  69. BOOL C11Mapping::GetMapName( CString &szName )
  70. {
  71. szName = m_szName;
  72. return TRUE;
  73. }
  74. //----------------------------------------------------------------
  75. BOOL C11Mapping::SetMapName( CString szName )
  76. {
  77. m_szName = szName;
  78. return TRUE;
  79. }
  80. //----------------------------------------------------------------
  81. CString& C11Mapping::QueryNodeName()
  82. {
  83. return m_szNodeName;
  84. }
  85. //----------------------------------------------------------------
  86. BOOL C11Mapping::SetNodeName( CString szName )
  87. {
  88. m_szNodeName = szName;
  89. return TRUE;
  90. }
  91. // QueryCertHash is used only when accessing IIS6 and higher
  92. // it will return Hash of the cert in the hex string form
  93. CString& C11Mapping::QueryCertHash()
  94. {
  95. HRESULT hr = E_FAIL;
  96. const int SHA1_HASH_SIZE = 20;
  97. BYTE rgbHash[ SHA1_HASH_SIZE ];
  98. DWORD cbSize = SHA1_HASH_SIZE;
  99. #ifndef HEX_DIGIT
  100. #define HEX_DIGIT( nDigit ) \
  101. (CHAR)((nDigit) > 9 ? \
  102. (nDigit) - 10 + 'a' \
  103. : (nDigit) + '0')
  104. #endif
  105. if ( m_szCertHash.IsEmpty() )
  106. {
  107. PCCERT_CONTEXT pCertContext = NULL;
  108. pCertContext= CertCreateCertificateContext(X509_ASN_ENCODING, (const BYTE *)m_pCert, m_cbCert);
  109. if ( pCertContext == NULL )
  110. {
  111. hr = HRESULT_FROM_WIN32( GetLastError() );
  112. return m_szCertHash; // return empty cert hash
  113. }
  114. //
  115. // get hash of the certificate to be verified
  116. //
  117. if ( !CertGetCertificateContextProperty( pCertContext,
  118. CERT_SHA1_HASH_PROP_ID,
  119. rgbHash,
  120. &cbSize ) )
  121. {
  122. hr = HRESULT_FROM_WIN32( GetLastError() );
  123. CertFreeCertificateContext( pCertContext );
  124. pCertContext = NULL;
  125. return m_szCertHash; // return empty cert hash
  126. }
  127. CertFreeCertificateContext( pCertContext );
  128. pCertContext = NULL;
  129. //
  130. // convert to text
  131. //
  132. for (int i = 0; i < sizeof(rgbHash); i ++ )
  133. {
  134. m_szCertHash += HEX_DIGIT( ( rgbHash[ i ] >> 4 ) );
  135. m_szCertHash += HEX_DIGIT( ( rgbHash[ i ] & 0x0F ) );
  136. }
  137. }
  138. return m_szCertHash;
  139. }
  140. //----------------------------------------------------------------
  141. // the enabled flag is considered try if the SIZE of data is greater
  142. // than zero. Apparently the content doesn't matter.
  143. BOOL C11Mapping::GetMapEnabled( BOOL* pfEnabled )
  144. {
  145. *pfEnabled = m_fEnabled;
  146. return TRUE;
  147. }
  148. //----------------------------------------------------------------
  149. // the enabled flag is considered try if the SIZE of data is greater
  150. // than zero. Apparently the content doesn't matter.
  151. BOOL C11Mapping::SetMapEnabled( BOOL fEnabled )
  152. {
  153. m_fEnabled = fEnabled;
  154. return TRUE;
  155. }