Unix extra lines cleaned up.
[reactos.git] / reactos / lib / advapi32 / service / scm.c
1 /* $Id: scm.c,v 1.14 2002/12/26 17:23:27 robd Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/service/scm.c
6 * PURPOSE: Service control manager functions
7 * PROGRAMMER: Emanuele Aliberti
8 * UPDATE HISTORY:
9 * 19990413 EA created
10 * 19990515 EA
11 */
12
13 /* INCLUDES ******************************************************************/
14
15 #define NTOS_MODE_USER
16 #include <ntos.h>
17 #include <windows.h>
18 #include <tchar.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22 /**********************************************************************
23 * ChangeServiceConfigA
24 */
25 BOOL
26 STDCALL
27 ChangeServiceConfigA(
28 SC_HANDLE hService,
29 DWORD dwServiceType,
30 DWORD dwStartType,
31 DWORD dwErrorControl,
32 LPCSTR lpBinaryPathName,
33 LPCSTR lpLoadOrderGroup,
34 LPDWORD lpdwTagId,
35 LPCSTR lpDependencies,
36 LPCSTR lpServiceStartName,
37 LPCSTR lpPassword,
38 LPCSTR lpDisplayName)
39 {
40 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
41 return FALSE;
42 }
43
44
45 /**********************************************************************
46 * ChangeServiceConfigW
47 */
48 BOOL
49 STDCALL
50 ChangeServiceConfigW(
51 SC_HANDLE hService,
52 DWORD dwServiceType,
53 DWORD dwStartType,
54 DWORD dwErrorControl,
55 LPCWSTR lpBinaryPathName,
56 LPCWSTR lpLoadOrderGroup,
57 LPDWORD lpdwTagId,
58 LPCWSTR lpDependencies,
59 LPCWSTR lpServiceStartName,
60 LPCWSTR lpPassword,
61 LPCWSTR lpDisplayName)
62 {
63 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
64 return FALSE;
65 }
66
67
68 /**********************************************************************
69 * CloseServiceHandle
70 */
71 BOOL
72 STDCALL
73 CloseServiceHandle(SC_HANDLE hSCObject)
74 {
75 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
76 return FALSE;
77 }
78
79
80 /**********************************************************************
81 * ControlService
82 */
83 BOOL
84 STDCALL
85 ControlService(SC_HANDLE hService,
86 DWORD dwControl,
87 LPSERVICE_STATUS lpServiceStatus)
88 {
89 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
90 return FALSE;
91 }
92
93
94 /**********************************************************************
95 * CreateServiceA
96 */
97 SC_HANDLE
98 STDCALL
99 CreateServiceA(
100 SC_HANDLE hSCManager,
101 LPCSTR lpServiceName,
102 LPCSTR lpDisplayName,
103 DWORD dwDesiredAccess,
104 DWORD dwServiceType,
105 DWORD dwStartType,
106 DWORD dwErrorControl,
107 LPCSTR lpBinaryPathName,
108 LPCSTR lpLoadOrderGroup,
109 LPDWORD lpdwTagId,
110 LPCSTR lpDependencies,
111 LPCSTR lpServiceStartName,
112 LPCSTR lpPassword)
113 {
114 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
115 return NULL;
116 }
117
118
119 /**********************************************************************
120 * CreateServiceW
121 */
122 SC_HANDLE
123 STDCALL
124 CreateServiceW(
125 SC_HANDLE hSCManager,
126 LPCWSTR lpServiceName,
127 LPCWSTR lpDisplayName,
128 DWORD dwDesiredAccess,
129 DWORD dwServiceType,
130 DWORD dwStartType,
131 DWORD dwErrorControl,
132 LPCWSTR lpBinaryPathName,
133 LPCWSTR lpLoadOrderGroup,
134 LPDWORD lpdwTagId,
135 LPCWSTR lpDependencies,
136 LPCWSTR lpServiceStartName,
137 LPCWSTR lpPassword)
138 {
139 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
140 return NULL;
141 }
142
143
144 /**********************************************************************
145 * DeleteService
146 */
147 BOOL
148 STDCALL
149 DeleteService(SC_HANDLE hService)
150 {
151 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
152 return FALSE;
153 }
154
155
156 /**********************************************************************
157 * EnumDependentServicesA
158 */
159 BOOL
160 STDCALL
161 EnumDependentServicesA(
162 SC_HANDLE hService,
163 DWORD dwServiceState,
164 LPENUM_SERVICE_STATUSA lpServices,
165 DWORD cbBufSize,
166 LPDWORD pcbBytesNeeded,
167 LPDWORD lpServicesReturned)
168 {
169 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
170 return FALSE;
171 }
172
173
174 /**********************************************************************
175 * EnumDependentServicesW
176 */
177 BOOL
178 STDCALL
179 EnumDependentServicesW(
180 SC_HANDLE hService,
181 DWORD dwServiceState,
182 LPENUM_SERVICE_STATUSW lpServices,
183 DWORD cbBufSize,
184 LPDWORD pcbBytesNeeded,
185 LPDWORD lpServicesReturned)
186 {
187 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
188 return FALSE;
189 }
190
191
192 /**********************************************************************
193 * EnumServiceGroupW
194 *
195 * (unknown)
196 */
197 BOOL
198 STDCALL
199 EnumServiceGroupW (
200 DWORD Unknown0,
201 DWORD Unknown1,
202 DWORD Unknown2,
203 DWORD Unknown3,
204 DWORD Unknown4,
205 DWORD Unknown5,
206 DWORD Unknown6,
207 DWORD Unknown7,
208 DWORD Unknown8)
209 {
210 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
211 return FALSE;
212 }
213
214
215 /**********************************************************************
216 * EnumServicesStatusA
217 */
218 BOOL
219 STDCALL
220 EnumServicesStatusA (
221 SC_HANDLE hSCManager,
222 DWORD dwServiceType,
223 DWORD dwServiceState,
224 LPENUM_SERVICE_STATUSA lpServices,
225 DWORD cbBufSize,
226 LPDWORD pcbBytesNeeded,
227 LPDWORD lpServicesReturned,
228 LPDWORD lpResumeHandle)
229 {
230 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
231 return FALSE;
232 }
233
234
235 /**********************************************************************
236 * EnumServicesStatusExA
237 */
238 BOOL
239 STDCALL
240 EnumServicesStatusExA(SC_HANDLE hSCManager,
241 SC_ENUM_TYPE InfoLevel,
242 DWORD dwServiceType,
243 DWORD dwServiceState,
244 LPBYTE lpServices,
245 DWORD cbBufSize,
246 LPDWORD pcbBytesNeeded,
247 LPDWORD lpServicesReturned,
248 LPDWORD lpResumeHandle,
249 LPCSTR pszGroupName)
250 {
251 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
252 return FALSE;
253 }
254
255
256 /**********************************************************************
257 * EnumServicesStatusExW
258 */
259 BOOL
260 STDCALL
261 EnumServicesStatusExW(SC_HANDLE hSCManager,
262 SC_ENUM_TYPE InfoLevel,
263 DWORD dwServiceType,
264 DWORD dwServiceState,
265 LPBYTE lpServices,
266 DWORD cbBufSize,
267 LPDWORD pcbBytesNeeded,
268 LPDWORD lpServicesReturned,
269 LPDWORD lpResumeHandle,
270 LPCWSTR pszGroupName)
271 {
272 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
273 return FALSE;
274 }
275
276
277 /**********************************************************************
278 * EnumServicesStatusW
279 */
280 BOOL
281 STDCALL
282 EnumServicesStatusW(
283 SC_HANDLE hSCManager,
284 DWORD dwServiceType,
285 DWORD dwServiceState,
286 LPENUM_SERVICE_STATUSW lpServices,
287 DWORD cbBufSize,
288 LPDWORD pcbBytesNeeded,
289 LPDWORD lpServicesReturned,
290 LPDWORD lpResumeHandle)
291 {
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
293 return FALSE;
294 }
295
296
297 /**********************************************************************
298 * GetServiceDisplayNameA
299 */
300 BOOL
301 STDCALL
302 GetServiceDisplayNameA(
303 SC_HANDLE hSCManager,
304 LPCSTR lpServiceName,
305 LPSTR lpDisplayName,
306 LPDWORD lpcchBuffer)
307 {
308 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
309 return FALSE;
310 }
311
312
313 /**********************************************************************
314 * GetServiceDisplayNameW
315 */
316 BOOL
317 STDCALL
318 GetServiceDisplayNameW(
319 SC_HANDLE hSCManager,
320 LPCWSTR lpServiceName,
321 LPWSTR lpDisplayName,
322 LPDWORD lpcchBuffer)
323 {
324 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
325 return FALSE;
326 }
327
328
329 /**********************************************************************
330 * GetServiceKeyNameA
331 */
332 BOOL
333 STDCALL
334 GetServiceKeyNameA(
335 SC_HANDLE hSCManager,
336 LPCSTR lpDisplayName,
337 LPSTR lpServiceName,
338 LPDWORD lpcchBuffer)
339 {
340 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
341 return FALSE;
342 }
343
344
345 /**********************************************************************
346 * GetServiceKeyNameW
347 */
348 BOOL
349 STDCALL
350 GetServiceKeyNameW(
351 SC_HANDLE hSCManager,
352 LPCWSTR lpDisplayName,
353 LPWSTR lpServiceName,
354 LPDWORD lpcchBuffer)
355 {
356 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
357 return FALSE;
358 }
359
360 /**********************************************************************
361 * LockServiceDatabase
362 */
363 SC_LOCK
364 STDCALL
365 LockServiceDatabase(SC_HANDLE hSCManager)
366 {
367 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
368 return NULL;
369 }
370
371
372 /**********************************************************************
373 * OpenSCManagerA
374 */
375 SC_HANDLE STDCALL
376 OpenSCManagerA(LPCSTR lpMachineName,
377 LPCSTR lpDatabaseName,
378 DWORD dwDesiredAccess)
379 {
380 SC_HANDLE Handle;
381 UNICODE_STRING MachineNameW;
382 UNICODE_STRING DatabaseNameW;
383 ANSI_STRING MachineNameA;
384 ANSI_STRING DatabaseNameA;
385
386 RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName);
387 RtlAnsiStringToUnicodeString(&MachineNameW,
388 &MachineNameA,
389 TRUE);
390 RtlInitAnsiString(&DatabaseNameA, (LPSTR)lpDatabaseName);
391 RtlAnsiStringToUnicodeString(&DatabaseNameW,
392 &DatabaseNameA,
393 TRUE);
394
395 Handle = OpenSCManagerW(MachineNameW.Buffer,
396 DatabaseNameW.Buffer,
397 dwDesiredAccess);
398
399 RtlFreeHeap(GetProcessHeap(),
400 0,
401 MachineNameW.Buffer);
402 RtlFreeHeap(GetProcessHeap(),
403 0,
404 DatabaseNameW.Buffer);
405
406 return(Handle);
407 }
408
409
410 /**********************************************************************
411 * OpenSCManagerW
412 */
413 SC_HANDLE STDCALL OpenSCManagerW(LPCWSTR lpMachineName,
414 LPCWSTR lpDatabaseName,
415 DWORD dwDesiredAccess)
416 {
417 HANDLE hPipe;
418 DWORD dwMode;
419 DWORD dwWait;
420 BOOL fSuccess;
421 HANDLE hStartEvent;
422 LPWSTR lpszPipeName = L"\\\\.\\pipe\\Ntsvcs";
423
424 if(lpMachineName == NULL || wcslen(lpMachineName) == 0)
425 {
426 if(lpDatabaseName != NULL && wcscmp(lpDatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
427 { return(NULL); }
428
429 // Only connect to scm when event "SvcctrlStartEvent_A3725DX" is signaled
430 hStartEvent = OpenEvent(SYNCHRONIZE, FALSE, _T("SvcctrlStartEvent_A3725DX"));
431 if(hStartEvent == NULL)
432 {
433 SetLastError(ERROR_DATABASE_DOES_NOT_EXIST);
434 return (NULL);
435 }
436 dwWait = WaitForSingleObject(hStartEvent, INFINITE);
437 if(dwWait == WAIT_FAILED)
438 {
439 SetLastError(ERROR_ACCESS_DENIED);
440 return (NULL);
441 }
442 CloseHandle(hStartEvent);
443
444 // Try to open a named pipe; wait for it, if necessary
445 while(1)
446 {
447 hPipe = CreateFileW(lpszPipeName, // pipe name
448 dwDesiredAccess,
449 0, // no sharing
450 NULL, // no security attributes
451 OPEN_EXISTING, // opens existing pipe
452 0, // default attributes
453 NULL); // no template file
454
455 // Break if the pipe handle is valid
456 if(hPipe != INVALID_HANDLE_VALUE)
457 break;
458
459 // Exit if an error other than ERROR_PIPE_BUSY occurs
460 if(GetLastError()!= ERROR_PIPE_BUSY)
461 { return(NULL); }
462
463 // All pipe instances are busy, so wait for 20 seconds
464 if(!WaitNamedPipeW(lpszPipeName, 20000))
465 { return(NULL); }
466 }
467
468 // The pipe connected; change to message-read mode
469 dwMode = PIPE_READMODE_MESSAGE;
470 fSuccess = SetNamedPipeHandleState(
471 hPipe, // pipe handle
472 &dwMode, // new pipe mode
473 NULL, // don't set maximum bytes
474 NULL); // don't set maximum time
475 if(!fSuccess)
476 {
477 CloseHandle(hPipe);
478 return(NULL);
479 }
480 #if 0
481 // Send a message to the pipe server
482 lpvMessage = (argc > 1) ? argv[1] : "default message";
483
484 fSuccess = WriteFile(
485 hPipe, // pipe handle
486 lpvMessage, // message
487 strlen(lpvMessage) + 1, // message length
488 &cbWritten, // bytes written
489 NULL); // not overlapped
490 if(!fSuccess)
491 {
492 CloseHandle(hPipe);
493 return(NULL);
494 }
495
496 do
497 {
498 // Read from the pipe
499 fSuccess = ReadFile(
500 hPipe, // pipe handle
501 chBuf, // buffer to receive reply
502 512, // size of buffer
503 &cbRead, // number of bytes read
504 NULL); // not overlapped
505
506 if(! fSuccess && GetLastError() != ERROR_MORE_DATA)
507 break;
508
509 // Reply from the pipe is written to STDOUT.
510 if(!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), chBuf, cbRead, &cbWritten, NULL))
511 break;
512 } while(!fSuccess); // repeat loop if ERROR_MORE_DATA
513
514 //CloseHandle(hPipe);
515 #endif
516 return(hPipe);
517 }
518 else
519 {
520 /* FIXME: Connect to remote SCM */
521 return(NULL);
522 }
523 }
524
525
526 /**********************************************************************
527 * OpenServiceA
528 */
529 SC_HANDLE STDCALL
530 OpenServiceA(SC_HANDLE hSCManager,
531 LPCSTR lpServiceName,
532 DWORD dwDesiredAccess)
533 {
534 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
535 return(NULL);
536 }
537
538
539 /**********************************************************************
540 * OpenServiceW
541 */
542 SC_HANDLE
543 STDCALL
544 OpenServiceW(
545 SC_HANDLE hSCManager,
546 LPCWSTR lpServiceName,
547 DWORD dwDesiredAccess
548 )
549 {
550 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
551 return NULL;
552 }
553
554
555 /**********************************************************************
556 * PrivilegedServiceAuditAlarmA
557 */
558 BOOL
559 STDCALL
560 PrivilegedServiceAuditAlarmA(
561 LPCSTR SubsystemName,
562 LPCSTR ServiceName,
563 HANDLE ClientToken,
564 PPRIVILEGE_SET Privileges,
565 BOOL AccessGranted)
566 {
567 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
568 return FALSE;
569 }
570
571
572 /**********************************************************************
573 * PrivilegedServiceAuditAlarmW
574 */
575 BOOL
576 STDCALL
577 PrivilegedServiceAuditAlarmW(
578 LPCWSTR SubsystemName,
579 LPCWSTR ServiceName,
580 HANDLE ClientToken,
581 PPRIVILEGE_SET Privileges,
582 BOOL AccessGranted)
583 {
584 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
585 return 1;
586 }
587
588
589 /**********************************************************************
590 * QueryServiceConfigA
591 */
592 BOOL
593 STDCALL
594 QueryServiceConfigA(
595 SC_HANDLE hService,
596 LPQUERY_SERVICE_CONFIGA lpServiceConfig,
597 DWORD cbBufSize,
598 LPDWORD pcbBytesNeeded)
599 {
600 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
601 return FALSE;
602 }
603
604
605 /**********************************************************************
606 * QueryServiceConfigW
607 */
608 BOOL
609 STDCALL
610 QueryServiceConfigW(
611 SC_HANDLE hService,
612 LPQUERY_SERVICE_CONFIGW lpServiceConfig,
613 DWORD cbBufSize,
614 LPDWORD pcbBytesNeeded)
615 {
616 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
617 return FALSE;
618 }
619
620
621 /**********************************************************************
622 * QueryServiceLockStatusA
623 */
624 BOOL
625 STDCALL
626 QueryServiceLockStatusA(
627 SC_HANDLE hSCManager,
628 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus,
629 DWORD cbBufSize,
630 LPDWORD pcbBytesNeeded)
631 {
632 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
633 return FALSE;
634 }
635
636
637 /**********************************************************************
638 * QueryServiceLockStatusW
639 */
640 BOOL
641 STDCALL
642 QueryServiceLockStatusW(
643 SC_HANDLE hSCManager,
644 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus,
645 DWORD cbBufSize,
646 LPDWORD pcbBytesNeeded)
647 {
648 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
649 return FALSE;
650 }
651
652
653 /**********************************************************************
654 * QueryServiceObjectSecurity
655 */
656 BOOL
657 STDCALL
658 QueryServiceObjectSecurity(
659 SC_HANDLE hService,
660 SECURITY_INFORMATION dwSecurityInformation,
661 PSECURITY_DESCRIPTOR lpSecurityDescriptor,
662 DWORD cbBufSize,
663 LPDWORD pcbBytesNeeded)
664 {
665 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
666 return FALSE;
667 }
668
669
670 /**********************************************************************
671 * QueryServiceStatus
672 */
673 BOOL
674 STDCALL
675 QueryServiceStatus(
676 SC_HANDLE hService,
677 LPSERVICE_STATUS lpServiceStatus)
678 {
679 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
680 return FALSE;
681 }
682
683
684 /**********************************************************************
685 * QueryServiceStatusEx
686 */
687 BOOL
688 STDCALL
689 QueryServiceStatusEx(SC_HANDLE hService,
690 SC_STATUS_TYPE InfoLevel,
691 LPBYTE lpBuffer,
692 DWORD cbBufSize,
693 LPDWORD pcbBytesNeeded)
694 {
695 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
696 return FALSE;
697 }
698
699
700 /**********************************************************************
701 * StartServiceA
702 */
703 BOOL
704 STDCALL
705 StartServiceA(
706 SC_HANDLE hService,
707 DWORD dwNumServiceArgs,
708 LPCSTR *lpServiceArgVectors)
709 {
710 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
711 return FALSE;
712 }
713
714
715
716
717 /**********************************************************************
718 * StartServiceW
719 */
720 BOOL
721 STDCALL
722 StartServiceW(
723 SC_HANDLE hService,
724 DWORD dwNumServiceArgs,
725 LPCWSTR *lpServiceArgVectors)
726 {
727 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
728 return FALSE;
729 }
730
731
732 /**********************************************************************
733 * UnlockServiceDatabase
734 */
735 BOOL
736 STDCALL
737 UnlockServiceDatabase(SC_LOCK ScLock)
738 {
739 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
740 return FALSE;
741 }
742
743
744 /* EOF */