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