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.

211 lines
7.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: cisvc.hxx
  7. //
  8. // Contents: Interfaces to CI Filter service
  9. //
  10. // History: 07-Jun-94 DwightKr Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #if !defined( __CIFILTERSERVICECONTROLS_HXX__ )
  14. #define __CIFILTERSERVICECONTROLS_HXX__
  15. static WCHAR * wcsCiFilterServiceName = L"CiFilter";
  16. //+-------------------------------------------------------------------------
  17. //
  18. // Class: CCiFilterServiceCommand
  19. //
  20. // Purpose: To build 1-byte command buffers used to transmit command to
  21. // the Ci Filter Service.
  22. //
  23. // History: 23-Jun-94 DwightKr Created
  24. //
  25. // Notes: The SMALLEST legal user-defined command issued to a service
  26. // is 128. In fact, the allowable range is 128-255. Hence
  27. // we'll force the high bits such that they are the service
  28. // command, and by making the smallest command code 4, the top
  29. // bit in the command byte will always be 1, hence the smallest
  30. // numerical value will be 128.
  31. //
  32. //--------------------------------------------------------------------------
  33. class CCiFilterServiceCommand
  34. {
  35. public:
  36. enum ServiceCommand { SERVICE_DELETE_DRIVE=4,
  37. SERVICE_ADD_DRIVE,
  38. SERVICE_REFRESH,
  39. SERVICE_SCANDISK };
  40. enum ServiceOperand { SERVICE_REFRESH_REGISTRY,
  41. SERVICE_REFRESH_DRIVELIST };
  42. inline CCiFilterServiceCommand(ServiceCommand Action,
  43. const ULONG drive);
  44. inline CCiFilterServiceCommand( ULONG ulCommand );
  45. inline operator DWORD () { return *((DWORD *) this) & 0xFF; }
  46. inline WCHAR const GetDriveLetter() { return (WCHAR) (_operand + L'A'); }
  47. inline unsigned const GetOperand() { return (unsigned) _operand; }
  48. inline unsigned const GetAction() { return _action; }
  49. private:
  50. const ULONG _operand : 5; // Allows for 32 drives
  51. const ULONG _action : 3; // Smallest command must be 4
  52. };
  53. //+-------------------------------------------------------------------------
  54. //--------------------------------------------------------------------------
  55. inline CCiFilterServiceCommand::CCiFilterServiceCommand(ServiceCommand action,
  56. const ULONG operand) :
  57. _action(action),
  58. _operand(operand)
  59. {
  60. }
  61. //+-------------------------------------------------------------------------
  62. //--------------------------------------------------------------------------
  63. inline CCiFilterServiceCommand::CCiFilterServiceCommand( ULONG ulCommand ) :
  64. _action( (ulCommand >> 5) & 0x7 ),
  65. _operand( ulCommand & 0x1F )
  66. {
  67. }
  68. //+-------------------------------------------------------------------------
  69. //
  70. // Class: CControlCiFilterService
  71. //
  72. // Purpose: To allow applications to send CI Filter Service specific
  73. // commands to the service.
  74. //
  75. // History: 23-Jun-94 DwightKr Created
  76. //
  77. // Notes: This is the interface applications can use to communicate
  78. // with the CI Filter Service. Currently two operations on the
  79. // service are supported: disable filtering on a specific drive,
  80. // and enable filtering. These operations are for the current
  81. // session only. If then system is rebooted, then all OFS drives
  82. // will be enabled.
  83. //
  84. // To perminately disable filtering on a OFS drive, a bit in the
  85. // OFS volume must be set to disable filtering permenatly.
  86. //
  87. // The CControlCiFilterService object can be used as follows:
  88. //
  89. // {
  90. // CControlCiFIlterService controlCiService;
  91. //
  92. // if ( !controlCiService.Ok() ) return GetLastError();
  93. // BOOL fSuccess = controlCiService.StopFiltering( L"D:" );
  94. //
  95. // .
  96. // .
  97. // .
  98. //
  99. //
  100. // fSuccess = controlCiService.StartFiltering( L"D:" );
  101. // }
  102. //
  103. //
  104. //--------------------------------------------------------------------------
  105. class CControlCiFilterService
  106. {
  107. public :
  108. CControlCiFilterService() :
  109. _hManager( OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT ) ),
  110. _hService( OpenService( _hManager, wcsCiFilterServiceName, SERVICE_ALL_ACCESS ) )
  111. {
  112. }
  113. ~CControlCiFilterService()
  114. {
  115. CloseServiceHandle( _hService );
  116. CloseServiceHandle( _hManager );
  117. }
  118. BOOL Ok() const { return (_hManager != NULL && _hService != NULL); }
  119. BOOL StartFiltering( WCHAR * wcsDrive )
  120. {
  121. int drive = StringToDrive( wcsDrive );
  122. if ( -1 == drive )
  123. {
  124. SetLastError( ERROR_INVALID_PARAMETER );
  125. return FALSE;
  126. }
  127. CCiFilterServiceCommand command(CCiFilterServiceCommand::SERVICE_ADD_DRIVE,
  128. drive);
  129. return ControlService(_hService, command, &_Status);
  130. }
  131. BOOL StopFiltering( WCHAR * wcsDrive )
  132. {
  133. int drive = StringToDrive( wcsDrive );
  134. if ( -1 == drive )
  135. {
  136. SetLastError( ERROR_INVALID_PARAMETER );
  137. return FALSE;
  138. }
  139. CCiFilterServiceCommand command(CCiFilterServiceCommand::SERVICE_DELETE_DRIVE,
  140. drive);
  141. return ControlService(_hService, command, &_Status);
  142. }
  143. BOOL ScanDisk( WCHAR * wcsDrive )
  144. {
  145. int drive = StringToDrive( wcsDrive );
  146. if ( -1 == drive )
  147. {
  148. SetLastError( ERROR_INVALID_PARAMETER );
  149. return FALSE;
  150. }
  151. CCiFilterServiceCommand command(CCiFilterServiceCommand::SERVICE_SCANDISK,
  152. drive);
  153. return ControlService(_hService, command, &_Status);
  154. }
  155. BOOL Refresh()
  156. {
  157. CCiFilterServiceCommand command(CCiFilterServiceCommand::SERVICE_REFRESH,
  158. CCiFilterServiceCommand::SERVICE_REFRESH_DRIVELIST );
  159. return ControlService(_hService, command, &_Status);
  160. }
  161. SERVICE_STATUS * GetStatus() { return &_Status; }
  162. private:
  163. int StringToDrive(WCHAR * wcsDrive)
  164. {
  165. if ( *wcsDrive >= L'a' && *wcsDrive <= L'z' )
  166. return *wcsDrive - L'a';
  167. else if ( *wcsDrive >= L'A' && *wcsDrive <= L'Z' )
  168. return *wcsDrive - L'A';
  169. else
  170. return -1;
  171. }
  172. SERVICE_STATUS _Status;
  173. const SC_HANDLE _hManager;
  174. const SC_HANDLE _hService;
  175. };
  176. #endif