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.

255 lines
6.1 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // � 1999 Microsoft Corporation. All rights reserved.
  4. //
  5. // Refer to your End User License Agreement for details on your rights/restrictions to use these sample files.
  6. //
  7. // MSHDSP.DLL is a sample WMDM Service Provider(SP) that enumerates fixed drives.
  8. // This sample shows you how to implement an SP according to the WMDM documentation.
  9. // This sample uses fixed drives on your PC to emulate portable media, and
  10. // shows the relationship between different interfaces and objects. Each hard disk
  11. // volume is enumerated as a device and directories and files are enumerated as
  12. // Storage objects under respective devices. You can copy non-SDMI compliant content
  13. // to any device that this SP enumerates. To copy an SDMI compliant content to a
  14. // device, the device must be able to report a hardware embedded serial number.
  15. // Hard disks do not have such serial numbers.
  16. //
  17. // To build this SP, you are recommended to use the MSHDSP.DSP file under Microsoft
  18. // Visual C++ 6.0 and run REGSVR32.EXE to register the resulting MSHDSP.DLL. You can
  19. // then build the sample application from the WMDMAPP directory to see how it gets
  20. // loaded by the application. However, you need to obtain a certificate from
  21. // Microsoft to actually run this SP. This certificate would be in the KEY.C file
  22. // under the INCLUDE directory for one level up.
  23. // MDServiceProvider.cpp : Implementation of CMDServiceProvider
  24. #include "hdspPCH.h"
  25. #include "key.c"
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMDServiceProvider
  28. CMDServiceProvider::~CMDServiceProvider()
  29. {
  30. if( m_hThread )
  31. {
  32. CloseHandle( m_hThread );
  33. }
  34. if( g_pAppSCServer )
  35. {
  36. delete g_pAppSCServer;
  37. g_pAppSCServer = NULL;
  38. }
  39. }
  40. CMDServiceProvider::CMDServiceProvider()
  41. {
  42. g_pAppSCServer = new CSecureChannelServer();
  43. if( g_pAppSCServer )
  44. {
  45. g_pAppSCServer->SetCertificate(
  46. SAC_CERT_V1,
  47. (BYTE*)abCert, sizeof(abCert),
  48. (BYTE*)abPVK, sizeof(abPVK)
  49. );
  50. }
  51. m_hThread = NULL;
  52. g_CriticalSection.Lock();
  53. ZeroMemory(
  54. g_GlobalDeviceInfo,
  55. sizeof(MDSPGLOBALDEVICEINFO)*MDSP_MAX_DEVICE_OBJ
  56. );
  57. g_bIsWinNT=IsWinNT();
  58. g_CriticalSection.Unlock();
  59. return;
  60. }
  61. static LPCSTR rgLyraKeys[] =
  62. {
  63. "Software\\Thomson Consumer Electronics, Inc\\USB CompactFlash External Drive",
  64. "Software\\Thomson Consumer Electronics, Inc\\CompactFlash External Drive",
  65. "Software\\Thomson Multimedia\\USB CompactFlash External Drive",
  66. "Software\\Thomson Multimedia\\CompactFlash External Drive"
  67. };
  68. STDMETHODIMP CMDServiceProvider::GetDeviceCount(DWORD * pdwCount)
  69. {
  70. HRESULT hr = E_FAIL;
  71. CHAR szDrive[] = "?:";
  72. INT i = 0;
  73. INT cnt = 0;
  74. BOOL fFoundLyraKey = FALSE;
  75. HKEY hKey = NULL;
  76. CFRg( g_pAppSCServer );
  77. if( !(g_pAppSCServer->fIsAuthenticated()) )
  78. {
  79. CORg( WMDM_E_NOTCERTIFIED );
  80. }
  81. CARg( pdwCount );
  82. for( i = 0;
  83. (!fFoundLyraKey) && (i < sizeof(rgLyraKeys)/sizeof(rgLyraKeys[0]));
  84. i++ )
  85. {
  86. if( ERROR_SUCCESS == RegOpenKeyExA( HKEY_LOCAL_MACHINE,
  87. rgLyraKeys[i],
  88. 0,
  89. KEY_READ,
  90. &hKey ) )
  91. {
  92. fFoundLyraKey = TRUE;
  93. }
  94. }
  95. if( fFoundLyraKey )
  96. {
  97. for( i=LYRA_START_DRIVE_NUM; i<MDSP_MAX_DRIVE_COUNT; i++ )
  98. {
  99. szDrive[0] = 'A' + i;
  100. if( UtilGetLyraDriveType(szDrive) == DRIVE_LYRA_TYPE )
  101. {
  102. cnt++;
  103. }
  104. }
  105. }
  106. *pdwCount = cnt;
  107. hr = S_OK;
  108. Error:
  109. hrLogDWORD("IMDServiceProvider::GetDeviceCount returned 0x%08lx", hr, hr);
  110. if( NULL != hKey )
  111. {
  112. RegCloseKey( hKey );
  113. }
  114. return hr;
  115. }
  116. STDMETHODIMP CMDServiceProvider::EnumDevices(IMDSPEnumDevice **ppEnumDevice)
  117. {
  118. HRESULT hr = E_FAIL;
  119. CComObject<CMDSPEnumDevice> *pEnumObj;
  120. INT i = 0;
  121. BOOL fFoundLyraKey = FALSE;
  122. HKEY hKey = NULL;
  123. CFRg( g_pAppSCServer );
  124. if( !(g_pAppSCServer->fIsAuthenticated()) )
  125. {
  126. CORg( WMDM_E_NOTCERTIFIED );
  127. }
  128. CARg( ppEnumDevice );
  129. for( i = 0;
  130. (!fFoundLyraKey) && (i < sizeof(rgLyraKeys)/sizeof(rgLyraKeys[0]));
  131. i++ )
  132. {
  133. if( ERROR_SUCCESS == RegOpenKeyExA( HKEY_LOCAL_MACHINE,
  134. rgLyraKeys[i],
  135. 0,
  136. KEY_READ,
  137. &hKey ) )
  138. {
  139. fFoundLyraKey = TRUE;
  140. }
  141. }
  142. if( !fFoundLyraKey )
  143. {
  144. *ppEnumDevice = NULL;
  145. return( E_FAIL );
  146. }
  147. hr = CComObject<CMDSPEnumDevice>::CreateInstance( &pEnumObj );
  148. if( SUCCEEDED(hr) )
  149. {
  150. hr = pEnumObj->QueryInterface(
  151. IID_IMDSPEnumDevice,
  152. reinterpret_cast<void**>(ppEnumDevice)
  153. );
  154. if( FAILED(hr) )
  155. {
  156. delete pEnumObj;
  157. goto Error;
  158. }
  159. }
  160. hr = S_OK;
  161. Error:
  162. hrLogDWORD("IMDServiceProvider::EnumDevices returned 0x%08lx", hr, hr);
  163. if( NULL != hKey )
  164. {
  165. RegCloseKey( hKey );
  166. }
  167. return hr;
  168. }
  169. STDMETHODIMP CMDServiceProvider::SACAuth(
  170. DWORD dwProtocolID,
  171. DWORD dwPass,
  172. BYTE *pbDataIn,
  173. DWORD dwDataInLen,
  174. BYTE **ppbDataOut,
  175. DWORD *pdwDataOutLen)
  176. {
  177. HRESULT hr = E_FAIL;
  178. CFRg( g_pAppSCServer );
  179. hr = g_pAppSCServer->SACAuth(
  180. dwProtocolID,
  181. dwPass,
  182. pbDataIn, dwDataInLen,
  183. ppbDataOut, pdwDataOutLen
  184. );
  185. CORg( hr );
  186. hr = S_OK;
  187. Error:
  188. hrLogDWORD("IComponentAuthenticate::SACAuth returned 0x%08lx", hr, hr);
  189. return hr;
  190. }
  191. STDMETHODIMP CMDServiceProvider::SACGetProtocols(
  192. DWORD **ppdwProtocols,
  193. DWORD *pdwProtocolCount)
  194. {
  195. HRESULT hr = E_FAIL;
  196. CFRg( g_pAppSCServer );
  197. hr = g_pAppSCServer->SACGetProtocols(
  198. ppdwProtocols,
  199. pdwProtocolCount
  200. );
  201. CORg( hr );
  202. hr = S_OK;
  203. Error:
  204. hrLogDWORD("IComponentAuthenticate::SACGetProtocols returned 0x%08lx", hr, hr);
  205. return hr;
  206. }