5 /* INCLUDES *****************************************************************/
12 /* FUNCTIONS ****************************************************************/
15 ScmLoadDriver(PSERVICE lpService
)
17 WCHAR szDriverPath
[MAX_PATH
];
18 UNICODE_STRING DriverPath
;
21 /* Build the driver path */
23 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
25 lpService
->lpServiceName
);
27 RtlInitUnicodeString(&DriverPath
,
30 /* FIXME: Acquire privilege */
32 DPRINT(" Path: %wZ\n", &DriverPath
);
33 Status
= NtLoadDriver(&DriverPath
);
35 /* FIXME: Release privilege */
42 ScmUnloadDriver(PSERVICE lpService
)
44 WCHAR szDriverPath
[MAX_PATH
];
45 UNICODE_STRING DriverPath
;
47 DWORD dwError
= ERROR_SUCCESS
;
49 /* Build the driver path */
51 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
53 lpService
->lpServiceName
);
55 RtlInitUnicodeString(&DriverPath
,
58 /* FIXME: Acquire privilege */
60 Status
= NtUnloadDriver(&DriverPath
);
62 /* FIXME: Release privilege */
64 if (!NT_SUCCESS(Status
))
66 dwError
= RtlNtStatusToDosError(Status
);
74 ScmGetDriverStatus(PSERVICE lpService
,
75 LPSERVICE_STATUS lpServiceStatus
)
77 OBJECT_ATTRIBUTES ObjectAttributes
;
78 UNICODE_STRING DirName
;
80 NTSTATUS Status
= STATUS_SUCCESS
;
81 POBJECT_DIRECTORY_INFORMATION DirInfo
;
85 DWORD dwError
= ERROR_SUCCESS
;
86 BOOLEAN bFound
= FALSE
;
88 DPRINT1("ScmGetDriverStatus() called\n");
90 memset(lpServiceStatus
, 0, sizeof(SERVICE_STATUS
));
92 if (lpService
->Status
.dwServiceType
== SERVICE_KERNEL_DRIVER
)
94 RtlInitUnicodeString(&DirName
,
99 RtlInitUnicodeString(&DirName
,
103 InitializeObjectAttributes(&ObjectAttributes
,
109 Status
= NtOpenDirectoryObject(&DirHandle
,
110 DIRECTORY_QUERY
| DIRECTORY_TRAVERSE
,
112 if (!NT_SUCCESS(Status
))
114 DPRINT1("NtOpenDirectoryObject() failed!\n");
115 return RtlNtStatusToDosError(Status
);
118 BufferLength
= sizeof(OBJECT_DIRECTORY_INFORMATION
) +
119 2 * MAX_PATH
* sizeof(WCHAR
);
120 DirInfo
= HeapAlloc(GetProcessHeap(),
127 Status
= NtQueryDirectoryObject(DirHandle
,
134 if (Status
== STATUS_NO_MORE_ENTRIES
)
136 DPRINT("No more services\n");
140 if (!NT_SUCCESS(Status
))
143 DPRINT("Comparing: '%S' '%wZ'\n", lpService
->lpServiceName
, &DirInfo
->ObjectName
);
145 if (_wcsicmp(lpService
->lpServiceName
, DirInfo
->ObjectName
.Buffer
) == 0)
147 DPRINT1("Found: '%S' '%wZ'\n",
148 lpService
->lpServiceName
, &DirInfo
->ObjectName
);
155 HeapFree(GetProcessHeap(),
160 if (!NT_SUCCESS(Status
))
162 DPRINT1("Status: %lx\n", Status
);
163 return RtlNtStatusToDosError(Status
);
166 if ((bFound
== TRUE
) &&
167 (lpService
->Status
.dwCurrentState
!= SERVICE_STOP_PENDING
))
169 if (lpService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
171 lpService
->Status
.dwWin32ExitCode
= ERROR_SUCCESS
;
172 lpService
->Status
.dwServiceSpecificExitCode
= ERROR_SUCCESS
;
173 lpService
->Status
.dwCheckPoint
= 0;
174 lpService
->Status
.dwWaitHint
= 0;
175 lpService
->Status
.dwControlsAccepted
= 0;
179 lpService
->Status
.dwCurrentState
= SERVICE_RUNNING
;
180 lpService
->Status
.dwControlsAccepted
= SERVICE_ACCEPT_STOP
;
182 if (lpService
->Status
.dwWin32ExitCode
== ERROR_SERVICE_NEVER_STARTED
)
183 lpService
->Status
.dwWin32ExitCode
= ERROR_SUCCESS
;
188 lpService
->Status
.dwCurrentState
= SERVICE_STOPPED
;
189 lpService
->Status
.dwControlsAccepted
= 0;
190 lpService
->Status
.dwCheckPoint
= 0;
191 lpService
->Status
.dwWaitHint
= 0;
193 if (lpService
->Status
.dwCurrentState
== SERVICE_STOP_PENDING
)
194 lpService
->Status
.dwWin32ExitCode
= ERROR_SUCCESS
;
196 lpService
->Status
.dwWin32ExitCode
= ERROR_GEN_FAILURE
;
199 if (lpServiceStatus
!= NULL
)
201 memcpy(lpServiceStatus
,
203 sizeof(SERVICE_STATUS
));
206 DPRINT1("ScmGetDriverStatus() done (Error: %lu)\n", dwError
);
208 return ERROR_SUCCESS
;
213 ScmControlDriver(PSERVICE lpService
,
215 LPSERVICE_STATUS lpServiceStatus
)
219 DPRINT("ScmControlDriver() called\n");
223 case SERVICE_CONTROL_STOP
:
224 if (lpService
->Status
.dwCurrentState
!= SERVICE_RUNNING
)
226 dwError
= ERROR_INVALID_SERVICE_CONTROL
;
230 dwError
= ScmUnloadDriver(lpService
);
231 if (dwError
== ERROR_SUCCESS
)
233 lpService
->Status
.dwControlsAccepted
= 0;
234 lpService
->Status
.dwCurrentState
= SERVICE_STOPPED
;
238 case SERVICE_CONTROL_INTERROGATE
:
239 dwError
= ScmGetDriverStatus(lpService
,
244 dwError
= ERROR_INVALID_SERVICE_CONTROL
;
248 DPRINT("ScmControlDriver() done (Erorr: %lu)\n", dwError
);