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.

190 lines
4.2 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // Copyright (C) Microsoft Corporation, 1999 - 2001. All rights reserved.
  4. //
  5. // MSHDSP.DLL is a sample WMDM Service Provider(SP) that enumerates fixed drives.
  6. // This sample shows you how to implement an SP according to the WMDM documentation.
  7. // This sample uses fixed drives on your PC to emulate portable media, and
  8. // shows the relationship between different interfaces and objects. Each hard disk
  9. // volume is enumerated as a device and directories and files are enumerated as
  10. // Storage objects under respective devices. You can copy non-SDMI compliant content
  11. // to any device that this SP enumerates. To copy an SDMI compliant content to a
  12. // device, the device must be able to report a hardware embedded serial number.
  13. // Hard disks do not have such serial numbers.
  14. //
  15. // To build this SP, you are recommended to use the MSHDSP.DSP file under Microsoft
  16. // Visual C++ 6.0 and run REGSVR32.EXE to register the resulting MSHDSP.DLL. You can
  17. // then build the sample application from the WMDMAPP directory to see how it gets
  18. // loaded by the application. However, you need to obtain a certificate from
  19. // Microsoft to actually run this SP. This certificate would be in the KEY.C file
  20. // under the INCLUDE directory for one level up.
  21. // MDServiceProvider.cpp : Implementation of CMDServiceProvider
  22. #include "hdspPCH.h"
  23. #include "key.c"
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMDServiceProvider
  26. CMDServiceProvider::~CMDServiceProvider()
  27. {
  28. if( m_hThread )
  29. {
  30. CloseHandle( m_hThread );
  31. }
  32. if( g_pAppSCServer )
  33. {
  34. delete g_pAppSCServer;
  35. g_pAppSCServer = NULL;
  36. }
  37. }
  38. CMDServiceProvider::CMDServiceProvider()
  39. {
  40. g_pAppSCServer = new CSecureChannelServer();
  41. if( g_pAppSCServer )
  42. {
  43. g_pAppSCServer->SetCertificate(
  44. SAC_CERT_V1,
  45. (BYTE*)abCert, sizeof(abCert),
  46. (BYTE*)abPVK, sizeof(abPVK)
  47. );
  48. }
  49. m_hThread = NULL;
  50. g_CriticalSection.Lock();
  51. ZeroMemory(
  52. g_GlobalDeviceInfo,
  53. sizeof(MDSPGLOBALDEVICEINFO)*MDSP_MAX_DEVICE_OBJ
  54. );
  55. g_CriticalSection.Unlock();
  56. return;
  57. }
  58. STDMETHODIMP CMDServiceProvider::GetDeviceCount(DWORD * pdwCount)
  59. {
  60. HRESULT hr = E_FAIL;
  61. CHAR szDrive[] = "?:";
  62. INT i;
  63. INT cnt;
  64. CFRg( g_pAppSCServer );
  65. if( !(g_pAppSCServer->fIsAuthenticated()) )
  66. {
  67. CORg( WMDM_E_NOTCERTIFIED );
  68. }
  69. CARg( pdwCount );
  70. for( i=0, cnt=0; i<MDSP_MAX_DRIVE_COUNT; i++ )
  71. {
  72. szDrive[0] = 'A' + i;
  73. if( UtilGetDriveType(szDrive) == DRIVE_FIXED )
  74. {
  75. cnt++;
  76. }
  77. }
  78. *pdwCount = cnt;
  79. hr = S_OK;
  80. Error:
  81. hrLogDWORD("IMDServiceProvider::GetDeviceCount returned 0x%08lx", hr, hr);
  82. return hr;
  83. }
  84. STDMETHODIMP CMDServiceProvider::EnumDevices(IMDSPEnumDevice **ppEnumDevice)
  85. {
  86. HRESULT hr = E_FAIL;
  87. CComObject<CMDSPEnumDevice> *pEnumObj;
  88. CFRg( g_pAppSCServer );
  89. if( !(g_pAppSCServer->fIsAuthenticated()) )
  90. {
  91. CORg( WMDM_E_NOTCERTIFIED );
  92. }
  93. hr = CComObject<CMDSPEnumDevice>::CreateInstance( &pEnumObj );
  94. if( SUCCEEDED(hr) )
  95. {
  96. hr = pEnumObj->QueryInterface(
  97. IID_IMDSPEnumDevice,
  98. reinterpret_cast<void**>(ppEnumDevice)
  99. );
  100. if( FAILED(hr) )
  101. {
  102. delete pEnumObj;
  103. goto Error;
  104. }
  105. }
  106. hr = S_OK;
  107. Error:
  108. hrLogDWORD("IMDServiceProvider::EnumDevices returned 0x%08lx", hr, hr);
  109. return hr;
  110. }
  111. STDMETHODIMP CMDServiceProvider::SACAuth(
  112. DWORD dwProtocolID,
  113. DWORD dwPass,
  114. BYTE *pbDataIn,
  115. DWORD dwDataInLen,
  116. BYTE **ppbDataOut,
  117. DWORD *pdwDataOutLen)
  118. {
  119. HRESULT hr = E_FAIL;
  120. CFRg( g_pAppSCServer );
  121. hr = g_pAppSCServer->SACAuth(
  122. dwProtocolID,
  123. dwPass,
  124. pbDataIn, dwDataInLen,
  125. ppbDataOut, pdwDataOutLen
  126. );
  127. CORg( hr );
  128. hr = S_OK;
  129. Error:
  130. hrLogDWORD("IComponentAuthenticate::SACAuth returned 0x%08lx", hr, hr);
  131. return hr;
  132. }
  133. STDMETHODIMP CMDServiceProvider::SACGetProtocols(
  134. DWORD **ppdwProtocols,
  135. DWORD *pdwProtocolCount)
  136. {
  137. HRESULT hr = E_FAIL;
  138. CFRg( g_pAppSCServer );
  139. hr = g_pAppSCServer->SACGetProtocols(
  140. ppdwProtocols,
  141. pdwProtocolCount
  142. );
  143. CORg( hr );
  144. hr = S_OK;
  145. Error:
  146. hrLogDWORD("IComponentAuthenticate::SACGetProtocols returned 0x%08lx", hr, hr);
  147. return hr;
  148. }