Update indentation.

svn path=/trunk/; revision=18686
This commit is contained in:
Eric Kohl 2005-10-22 19:46:00 +00:00
parent cf54e94b6e
commit 1060e47c32
3 changed files with 997 additions and 978 deletions

File diff suppressed because it is too large Load diff

View file

@ -18,30 +18,30 @@
typedef struct _SCMGR_HANDLE
{
DWORD Tag;
DWORD RefCount;
DWORD DesiredAccess;
DWORD Tag;
DWORD RefCount;
DWORD DesiredAccess;
} SCMGR_HANDLE;
typedef struct _MANAGER_HANDLE
{
SCMGR_HANDLE Handle;
SCMGR_HANDLE Handle;
/* FIXME: Insert more data here */
/* FIXME: Insert more data here */
WCHAR DatabaseName[1];
WCHAR DatabaseName[1];
} MANAGER_HANDLE, *PMANAGER_HANDLE;
typedef struct _SERVICE_HANDLE
{
SCMGR_HANDLE Handle;
SCMGR_HANDLE Handle;
DWORD DesiredAccess;
PSERVICE ServiceEntry;
DWORD DesiredAccess;
PSERVICE ServiceEntry;
/* FIXME: Insert more data here */
/* FIXME: Insert more data here */
} SERVICE_HANDLE, *PSERVICE_HANDLE;
@ -103,37 +103,37 @@ ScmServiceMapping = {SERVICE_READ,
VOID
ScmStartRpcServer(VOID)
{
RPC_STATUS Status;
RPC_STATUS Status;
DPRINT("ScmStartRpcServer() called");
DPRINT("ScmStartRpcServer() called");
Status = RpcServerUseProtseqEpW(L"ncacn_np",
10,
L"\\pipe\\ntsvcs",
NULL);
if (Status != RPC_S_OK)
{
DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
return;
}
Status = RpcServerUseProtseqEpW(L"ncacn_np",
10,
L"\\pipe\\ntsvcs",
NULL);
if (Status != RPC_S_OK)
{
DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
return;
}
Status = RpcServerRegisterIf(svcctl_ServerIfHandle,
NULL,
NULL);
if (Status != RPC_S_OK)
{
DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status);
return;
}
Status = RpcServerRegisterIf(svcctl_ServerIfHandle,
NULL,
NULL);
if (Status != RPC_S_OK)
{
DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status);
return;
}
Status = RpcServerListen(1, 20, TRUE);
if (Status != RPC_S_OK)
{
DPRINT1("RpcServerListen() failed (Status %lx)\n", Status);
return;
}
Status = RpcServerListen(1, 20, TRUE);
if (Status != RPC_S_OK)
{
DPRINT1("RpcServerListen() failed (Status %lx)\n", Status);
return;
}
DPRINT("ScmStartRpcServer() done");
DPRINT("ScmStartRpcServer() done");
}
@ -141,27 +141,27 @@ static DWORD
ScmCreateManagerHandle(LPWSTR lpDatabaseName,
SC_HANDLE *Handle)
{
PMANAGER_HANDLE Ptr;
PMANAGER_HANDLE Ptr;
if (lpDatabaseName == NULL)
lpDatabaseName = SERVICES_ACTIVE_DATABASEW;
if (lpDatabaseName == NULL)
lpDatabaseName = SERVICES_ACTIVE_DATABASEW;
Ptr = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(MANAGER_HANDLE) + wcslen(lpDatabaseName) * sizeof(WCHAR));
if (Ptr == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
Ptr = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(MANAGER_HANDLE) + wcslen(lpDatabaseName) * sizeof(WCHAR));
if (Ptr == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
Ptr->Handle.Tag = MANAGER_TAG;
Ptr->Handle.RefCount = 1;
Ptr->Handle.Tag = MANAGER_TAG;
Ptr->Handle.RefCount = 1;
/* FIXME: initialize more data here */
/* FIXME: initialize more data here */
wcscpy(Ptr->DatabaseName, lpDatabaseName);
wcscpy(Ptr->DatabaseName, lpDatabaseName);
*Handle = (SC_HANDLE)Ptr;
*Handle = (SC_HANDLE)Ptr;
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -169,23 +169,23 @@ static DWORD
ScmCreateServiceHandle(PSERVICE lpServiceEntry,
SC_HANDLE *Handle)
{
PSERVICE_HANDLE Ptr;
PSERVICE_HANDLE Ptr;
Ptr = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(SERVICE_HANDLE));
if (Ptr == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
Ptr = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(SERVICE_HANDLE));
if (Ptr == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
Ptr->Handle.Tag = SERVICE_TAG;
Ptr->Handle.RefCount = 1;
Ptr->Handle.Tag = SERVICE_TAG;
Ptr->Handle.RefCount = 1;
/* FIXME: initialize more data here */
Ptr->ServiceEntry = lpServiceEntry;
/* FIXME: initialize more data here */
Ptr->ServiceEntry = lpServiceEntry;
*Handle = (SC_HANDLE)Ptr;
*Handle = (SC_HANDLE)Ptr;
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -193,29 +193,29 @@ static DWORD
ScmCheckAccess(SC_HANDLE Handle,
DWORD dwDesiredAccess)
{
PMANAGER_HANDLE hMgr;
PMANAGER_HANDLE hMgr;
hMgr = (PMANAGER_HANDLE)Handle;
if (hMgr->Handle.Tag == MANAGER_TAG)
{
RtlMapGenericMask(&dwDesiredAccess,
&ScmManagerMapping);
hMgr = (PMANAGER_HANDLE)Handle;
if (hMgr->Handle.Tag == MANAGER_TAG)
{
RtlMapGenericMask(&dwDesiredAccess,
&ScmManagerMapping);
hMgr->Handle.DesiredAccess = dwDesiredAccess;
hMgr->Handle.DesiredAccess = dwDesiredAccess;
return ERROR_SUCCESS;
}
else if (hMgr->Handle.Tag == SERVICE_TAG)
{
RtlMapGenericMask(&dwDesiredAccess,
&ScmServiceMapping);
return ERROR_SUCCESS;
}
else if (hMgr->Handle.Tag == SERVICE_TAG)
{
RtlMapGenericMask(&dwDesiredAccess,
&ScmServiceMapping);
hMgr->Handle.DesiredAccess = dwDesiredAccess;
hMgr->Handle.DesiredAccess = dwDesiredAccess;
return ERROR_SUCCESS;
}
return ERROR_SUCCESS;
}
return ERROR_INVALID_HANDLE;
return ERROR_INVALID_HANDLE;
}
@ -224,50 +224,50 @@ unsigned long
ScmrCloseServiceHandle(handle_t BindingHandle,
unsigned int hScObject)
{
PMANAGER_HANDLE hManager;
PMANAGER_HANDLE hManager;
DPRINT("ScmrCloseServiceHandle() called\n");
DPRINT("ScmrCloseServiceHandle() called\n");
DPRINT("hScObject = %X\n", hScObject);
DPRINT("hScObject = %X\n", hScObject);
if (hScObject == 0)
return ERROR_INVALID_HANDLE;
hManager = (PMANAGER_HANDLE)hScObject;
if (hManager->Handle.Tag == MANAGER_TAG)
{
DPRINT("Found manager handle\n");
hManager->Handle.RefCount--;
if (hManager->Handle.RefCount == 0)
{
/* FIXME: add cleanup code */
HeapFree(GetProcessHeap(), 0, hManager);
}
DPRINT("ScmrCloseServiceHandle() done\n");
return ERROR_SUCCESS;
}
else if (hManager->Handle.Tag == SERVICE_TAG)
{
DPRINT("Found service handle\n");
hManager->Handle.RefCount--;
if (hManager->Handle.RefCount == 0)
{
/* FIXME: add cleanup code */
HeapFree(GetProcessHeap(), 0, hManager);
}
DPRINT("ScmrCloseServiceHandle() done\n");
return ERROR_SUCCESS;
}
DPRINT1("Invalid handle tag (Tag %lx)\n", hManager->Handle.Tag);
if (hScObject == 0)
return ERROR_INVALID_HANDLE;
hManager = (PMANAGER_HANDLE)hScObject;
if (hManager->Handle.Tag == MANAGER_TAG)
{
DPRINT("Found manager handle\n");
hManager->Handle.RefCount--;
if (hManager->Handle.RefCount == 0)
{
/* FIXME: add cleanup code */
HeapFree(GetProcessHeap(), 0, hManager);
}
DPRINT("ScmrCloseServiceHandle() done\n");
return ERROR_SUCCESS;
}
else if (hManager->Handle.Tag == SERVICE_TAG)
{
DPRINT("Found service handle\n");
hManager->Handle.RefCount--;
if (hManager->Handle.RefCount == 0)
{
/* FIXME: add cleanup code */
HeapFree(GetProcessHeap(), 0, hManager);
}
DPRINT("ScmrCloseServiceHandle() done\n");
return ERROR_SUCCESS;
}
DPRINT1("Invalid handle tag (Tag %lx)\n", hManager->Handle.Tag);
return ERROR_INVALID_HANDLE;
}
@ -278,39 +278,39 @@ ScmrControlService(handle_t BindingHandle,
unsigned long dwControl,
LPSERVICE_STATUS lpServiceStatus)
{
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
DPRINT1("ScmrControlService() called\n");
DPRINT1("ScmrControlService() called\n");
hSvc = (PSERVICE_HANDLE)hService;
if (hSvc->Handle.Tag != SERVICE_TAG)
{
DPRINT1("Invalid handle tag!\n");
return ERROR_INVALID_HANDLE;
}
hSvc = (PSERVICE_HANDLE)hService;
if (hSvc->Handle.Tag != SERVICE_TAG)
{
DPRINT1("Invalid handle tag!\n");
return ERROR_INVALID_HANDLE;
}
/* FIXME: Check access rights */
/* FIXME: Check access rights */
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
/* FIXME: Send control code to the service */
/* FIXME: Send control code to the service */
/* Return service status information */
RtlCopyMemory(lpServiceStatus,
&lpService->Status,
sizeof(SERVICE_STATUS));
/* Return service status information */
RtlCopyMemory(lpServiceStatus,
&lpService->Status,
sizeof(SERVICE_STATUS));
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -319,37 +319,37 @@ unsigned long
ScmrDeleteService(handle_t BindingHandle,
unsigned int hService)
{
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
DWORD dwError;
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
DWORD dwError;
DPRINT1("ScmrDeleteService() called\n");
DPRINT1("ScmrDeleteService() called\n");
hSvc = (PSERVICE_HANDLE)hService;
if (hSvc->Handle.Tag != SERVICE_TAG)
return ERROR_INVALID_HANDLE;
hSvc = (PSERVICE_HANDLE)hService;
if (hSvc->Handle.Tag != SERVICE_TAG)
return ERROR_INVALID_HANDLE;
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
STANDARD_RIGHTS_REQUIRED))
return ERROR_ACCESS_DENIED;
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
STANDARD_RIGHTS_REQUIRED))
return ERROR_ACCESS_DENIED;
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
/* FIXME: Acquire service database lock exclusively */
/* FIXME: Acquire service database lock exclusively */
/* Mark service for delete */
dwError = ScmMarkServiceForDelete(lpService);
/* Mark service for delete */
dwError = ScmMarkServiceForDelete(lpService);
/* FIXME: Release service database lock */
/* FIXME: Release service database lock */
DPRINT1("ScmrDeleteService() done\n");
DPRINT1("ScmrDeleteService() done\n");
return dwError;
return dwError;
}
@ -359,24 +359,24 @@ ScmrLockServiceDatabase(handle_t BindingHandle,
unsigned int hSCManager,
unsigned int *hLock)
{
PMANAGER_HANDLE hMgr;
PMANAGER_HANDLE hMgr;
DPRINT("ScmrLockServiceDatabase() called\n");
DPRINT("ScmrLockServiceDatabase() called\n");
*hLock = 0;
*hLock = 0;
hMgr = (PMANAGER_HANDLE)hSCManager;
if (hMgr->Handle.Tag != MANAGER_TAG)
return ERROR_INVALID_HANDLE;
hMgr = (PMANAGER_HANDLE)hSCManager;
if (hMgr->Handle.Tag != MANAGER_TAG)
return ERROR_INVALID_HANDLE;
if (!RtlAreAllAccessesGranted(hMgr->Handle.DesiredAccess,
SC_MANAGER_LOCK))
return ERROR_ACCESS_DENIED;
if (!RtlAreAllAccessesGranted(hMgr->Handle.DesiredAccess,
SC_MANAGER_LOCK))
return ERROR_ACCESS_DENIED;
/* FIXME: Lock the database */
*hLock = 0x12345678; /* Dummy! */
/* FIXME: Lock the database */
*hLock = 0x12345678; /* Dummy! */
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -384,8 +384,8 @@ ScmrLockServiceDatabase(handle_t BindingHandle,
unsigned long
ScmrQueryServiceObjectSecurity(handle_t BindingHandle)
{
DPRINT1("ScmrQueryServiceSecurity() is unimplemented\n");
return ERROR_CALL_NOT_IMPLEMENTED;
DPRINT1("ScmrQueryServiceSecurity() is unimplemented\n");
return ERROR_CALL_NOT_IMPLEMENTED;
}
@ -393,8 +393,8 @@ ScmrQueryServiceObjectSecurity(handle_t BindingHandle)
unsigned long
ScmrSetServiceObjectSecurity(handle_t BindingHandle)
{
DPRINT1("ScmrSetServiceSecurity() is unimplemented\n");
return ERROR_CALL_NOT_IMPLEMENTED;
DPRINT1("ScmrSetServiceSecurity() is unimplemented\n");
return ERROR_CALL_NOT_IMPLEMENTED;
}
@ -404,36 +404,38 @@ ScmrQueryServiceStatus(handle_t BindingHandle,
unsigned int hService,
LPSERVICE_STATUS lpServiceStatus)
{
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
DPRINT("ScmrQueryServiceStatus() called\n");
DPRINT("ScmrQueryServiceStatus() called\n");
hSvc = (PSERVICE_HANDLE)hService;
if (hSvc->Handle.Tag != SERVICE_TAG)
{
DPRINT1("Invalid handle tag!\n");
return ERROR_INVALID_HANDLE;
}
hSvc = (PSERVICE_HANDLE)hService;
if (hSvc->Handle.Tag != SERVICE_TAG)
{
DPRINT1("Invalid handle tag!\n");
return ERROR_INVALID_HANDLE;
}
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
SERVICE_QUERY_STATUS))
{
DPRINT1("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
return ERROR_ACCESS_DENIED;
}
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
SERVICE_QUERY_STATUS))
{
DPRINT1("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
return ERROR_ACCESS_DENIED;
}
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
/* Return service status information */
RtlCopyMemory(lpServiceStatus, &lpService->Status, sizeof(SERVICE_STATUS));
/* Return service status information */
RtlCopyMemory(lpServiceStatus,
&lpService->Status,
sizeof(SERVICE_STATUS));
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -441,9 +443,9 @@ ScmrQueryServiceStatus(handle_t BindingHandle,
unsigned long
ScmrSetServiceStatus(handle_t BindingHandle)
{
DPRINT1("ScmrSetServiceStatus() is unimplemented\n");
/* FIXME */
return ERROR_CALL_NOT_IMPLEMENTED;
DPRINT1("ScmrSetServiceStatus() is unimplemented\n");
/* FIXME */
return ERROR_CALL_NOT_IMPLEMENTED;
}
@ -452,9 +454,9 @@ unsigned long
ScmrUnlockServiceDatabase(handle_t BindingHandle,
unsigned int hLock)
{
DPRINT1("ScmrUnlockServiceDatabase() called\n");
/* FIXME */
return ERROR_SUCCESS;
DPRINT1("ScmrUnlockServiceDatabase() called\n");
/* FIXME */
return ERROR_SUCCESS;
}
@ -463,9 +465,9 @@ unsigned long
ScmrNotifyBootConfigStatus(handle_t BindingHandle,
unsigned long BootAcceptable)
{
DPRINT1("ScmrNotifyBootConfigStatus() called\n");
/* FIXME */
return ERROR_SUCCESS;
DPRINT1("ScmrNotifyBootConfigStatus() called\n");
/* FIXME */
return ERROR_SUCCESS;
}
@ -729,40 +731,40 @@ ScmrOpenSCManagerW(handle_t BindingHandle,
unsigned long dwDesiredAccess,
unsigned int *hScm)
{
DWORD dwError;
SC_HANDLE hHandle;
DWORD dwError;
SC_HANDLE hHandle;
DPRINT("ScmrOpenSCManagerW() called\n");
DPRINT("lpMachineName = %p\n", lpMachineName);
DPRINT("lpMachineName: %S\n", lpMachineName);
DPRINT("lpDataBaseName = %p\n", lpDatabaseName);
DPRINT("lpDataBaseName: %S\n", lpDatabaseName);
DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess);
DPRINT("ScmrOpenSCManagerW() called\n");
DPRINT("lpMachineName = %p\n", lpMachineName);
DPRINT("lpMachineName: %S\n", lpMachineName);
DPRINT("lpDataBaseName = %p\n", lpDatabaseName);
DPRINT("lpDataBaseName: %S\n", lpDatabaseName);
DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess);
dwError = ScmCreateManagerHandle(lpDatabaseName,
&hHandle);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCreateManagerHandle() failed (Error %lu)\n", dwError);
return dwError;
}
dwError = ScmCreateManagerHandle(lpDatabaseName,
&hHandle);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCreateManagerHandle() failed (Error %lu)\n", dwError);
return dwError;
}
/* Check the desired access */
dwError = ScmCheckAccess(hHandle,
dwDesiredAccess | SC_MANAGER_CONNECT);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError);
HeapFree(GetProcessHeap(), 0, hHandle);
return dwError;
}
/* Check the desired access */
dwError = ScmCheckAccess(hHandle,
dwDesiredAccess | SC_MANAGER_CONNECT);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError);
HeapFree(GetProcessHeap(), 0, hHandle);
return dwError;
}
*hScm = (unsigned int)hHandle;
DPRINT("*hScm = %x\n", *hScm);
*hScm = (unsigned int)hHandle;
DPRINT("*hScm = %x\n", *hScm);
DPRINT("ScmrOpenSCManagerW() done\n");
DPRINT("ScmrOpenSCManagerW() done\n");
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -774,59 +776,59 @@ ScmrOpenServiceW(handle_t BindingHandle,
unsigned long dwDesiredAccess,
unsigned int *hService)
{
PSERVICE lpService;
PMANAGER_HANDLE hManager;
SC_HANDLE hHandle;
DWORD dwError;
PSERVICE lpService;
PMANAGER_HANDLE hManager;
SC_HANDLE hHandle;
DWORD dwError;
DPRINT("ScmrOpenServiceW() called\n");
DPRINT("hSCManager = %x\n", hSCManager);
DPRINT("lpServiceName = %p\n", lpServiceName);
DPRINT("lpServiceName: %S\n", lpServiceName);
DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess);
DPRINT("ScmrOpenServiceW() called\n");
DPRINT("hSCManager = %x\n", hSCManager);
DPRINT("lpServiceName = %p\n", lpServiceName);
DPRINT("lpServiceName: %S\n", lpServiceName);
DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess);
hManager = (PMANAGER_HANDLE)hSCManager;
if (hManager->Handle.Tag != MANAGER_TAG)
{
DPRINT1("Invalid manager handle!\n");
return ERROR_INVALID_HANDLE;
}
hManager = (PMANAGER_HANDLE)hSCManager;
if (hManager->Handle.Tag != MANAGER_TAG)
{
DPRINT1("Invalid manager handle!\n");
return ERROR_INVALID_HANDLE;
}
/* FIXME: Lock the service list */
/* FIXME: Lock the service list */
/* Get service database entry */
lpService = ScmGetServiceEntryByName(lpServiceName);
if (lpService == NULL)
{
DPRINT1("Could not find a service!\n");
return ERROR_SERVICE_DOES_NOT_EXIST;
}
/* Get service database entry */
lpService = ScmGetServiceEntryByName(lpServiceName);
if (lpService == NULL)
{
DPRINT1("Could not find a service!\n");
return ERROR_SERVICE_DOES_NOT_EXIST;
}
/* Create a service handle */
dwError = ScmCreateServiceHandle(lpService,
&hHandle);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCreateServiceHandle() failed (Error %lu)\n", dwError);
return dwError;
}
/* Create a service handle */
dwError = ScmCreateServiceHandle(lpService,
&hHandle);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCreateServiceHandle() failed (Error %lu)\n", dwError);
return dwError;
}
/* Check the desired access */
dwError = ScmCheckAccess(hHandle,
dwDesiredAccess);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError);
HeapFree(GetProcessHeap(), 0, hHandle);
return dwError;
}
/* Check the desired access */
dwError = ScmCheckAccess(hHandle,
dwDesiredAccess);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError);
HeapFree(GetProcessHeap(), 0, hHandle);
return dwError;
}
*hService = (unsigned int)hHandle;
DPRINT("*hService = %x\n", *hService);
*hService = (unsigned int)hHandle;
DPRINT("*hService = %x\n", *hService);
DPRINT("ScmrOpenServiceW() done\n");
DPRINT("ScmrOpenServiceW() done\n");
return ERROR_SUCCESS;
return ERROR_SUCCESS;
}
@ -839,33 +841,33 @@ ScmrOpenSCManagerA(handle_t BindingHandle,
unsigned long dwDesiredAccess,
unsigned int *hScm)
{
UNICODE_STRING MachineName;
UNICODE_STRING DatabaseName;
DWORD dwError;
UNICODE_STRING MachineName;
UNICODE_STRING DatabaseName;
DWORD dwError;
DPRINT("ScmrOpenSCManagerA() called\n");
DPRINT("ScmrOpenSCManagerA() called\n");
if (lpMachineName)
RtlCreateUnicodeStringFromAsciiz(&MachineName,
lpMachineName);
if (lpMachineName)
RtlCreateUnicodeStringFromAsciiz(&MachineName,
lpMachineName);
if (lpDatabaseName)
RtlCreateUnicodeStringFromAsciiz(&DatabaseName,
lpDatabaseName);
if (lpDatabaseName)
RtlCreateUnicodeStringFromAsciiz(&DatabaseName,
lpDatabaseName);
dwError = ScmrOpenSCManagerW(BindingHandle,
lpMachineName ? MachineName.Buffer : NULL,
lpDatabaseName ? DatabaseName.Buffer : NULL,
dwDesiredAccess,
hScm);
dwError = ScmrOpenSCManagerW(BindingHandle,
lpMachineName ? MachineName.Buffer : NULL,
lpDatabaseName ? DatabaseName.Buffer : NULL,
dwDesiredAccess,
hScm);
if (lpMachineName)
RtlFreeUnicodeString(&MachineName);
if (lpMachineName)
RtlFreeUnicodeString(&MachineName);
if (lpDatabaseName)
RtlFreeUnicodeString(&DatabaseName);
if (lpDatabaseName)
RtlFreeUnicodeString(&DatabaseName);
return dwError;
return dwError;
}
@ -877,36 +879,36 @@ ScmrOpenServiceA(handle_t BindingHandle,
unsigned long dwDesiredAccess,
unsigned int *hService)
{
UNICODE_STRING ServiceName;
DWORD dwError;
UNICODE_STRING ServiceName;
DWORD dwError;
DPRINT("ScmrOpenServiceA() called\n");
DPRINT("ScmrOpenServiceA() called\n");
RtlCreateUnicodeStringFromAsciiz(&ServiceName,
lpServiceName);
RtlCreateUnicodeStringFromAsciiz(&ServiceName,
lpServiceName);
dwError = ScmrOpenServiceW(BindingHandle,
hSCManager,
ServiceName.Buffer,
dwDesiredAccess,
hService);
dwError = ScmrOpenServiceW(BindingHandle,
hSCManager,
ServiceName.Buffer,
dwDesiredAccess,
hService);
RtlFreeUnicodeString(&ServiceName);
RtlFreeUnicodeString(&ServiceName);
return dwError;
return dwError;
}
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
}
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
HeapFree(GetProcessHeap(), 0, ptr);
HeapFree(GetProcessHeap(), 0, ptr);
}
/* EOF */

View file

@ -47,14 +47,14 @@ VOID
PrintString(LPCSTR fmt, ...)
{
#ifdef DBG
CHAR buffer[512];
va_list ap;
CHAR buffer[512];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
OutputDebugStringA(buffer);
OutputDebugStringA(buffer);
#endif
}
@ -62,46 +62,46 @@ PrintString(LPCSTR fmt, ...)
BOOL
ScmCreateStartEvent(PHANDLE StartEvent)
{
HANDLE hEvent;
HANDLE hEvent;
hEvent = CreateEvent(NULL,
TRUE,
FALSE,
TEXT("SvcctrlStartEvent_A3725DX"));
if (hEvent == NULL)
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
hEvent = OpenEvent(EVENT_ALL_ACCESS,
hEvent = CreateEvent(NULL,
TRUE,
FALSE,
TEXT("SvcctrlStartEvent_A3725DX"));
if (hEvent == NULL)
{
return FALSE;
}
}
else
if (hEvent == NULL)
{
return FALSE;
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
hEvent = OpenEvent(EVENT_ALL_ACCESS,
FALSE,
TEXT("SvcctrlStartEvent_A3725DX"));
if (hEvent == NULL)
{
return FALSE;
}
}
else
{
return FALSE;
}
}
}
*StartEvent = hEvent;
*StartEvent = hEvent;
return TRUE;
return TRUE;
}
BOOL
ScmNamedPipeHandleRequest(PVOID Request,
DWORD RequestSize,
PVOID Reply,
LPDWORD ReplySize)
DWORD RequestSize,
PVOID Reply,
LPDWORD ReplySize)
{
DbgPrint("SCM READ: %s\n", Request);
DbgPrint("SCM READ: %s\n", Request);
*ReplySize = 0;
return FALSE;
*ReplySize = 0;
return FALSE;
}
@ -113,38 +113,47 @@ ScmNamedPipeThread(LPVOID Context)
DWORD cbReplyBytes;
DWORD cbBytesRead;
DWORD cbWritten;
BOOL fSuccess;
BOOL bSuccess;
HANDLE hPipe;
hPipe = (HANDLE)Context;
DPRINT("ScmNamedPipeThread(%x) - Accepting SCM commands through named pipe\n", hPipe);
for (;;) {
fSuccess = ReadFile(hPipe,
for (;;)
{
bSuccess = ReadFile(hPipe,
&chRequest,
PIPE_BUFSIZE,
&cbBytesRead,
NULL);
if (!fSuccess || cbBytesRead == 0) {
if (!bSuccess || cbBytesRead == 0)
{
break;
}
if (ScmNamedPipeHandleRequest(&chRequest, cbBytesRead, &chReply, &cbReplyBytes)) {
fSuccess = WriteFile(hPipe,
if (ScmNamedPipeHandleRequest(&chRequest, cbBytesRead, &chReply, &cbReplyBytes))
{
bSuccess = WriteFile(hPipe,
&chReply,
cbReplyBytes,
&cbWritten,
NULL);
if (!fSuccess || cbReplyBytes != cbWritten) {
if (!bSuccess || cbReplyBytes != cbWritten)
{
break;
}
}
}
DPRINT("ScmNamedPipeThread(%x) - Disconnecting named pipe connection\n", hPipe);
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
DPRINT("ScmNamedPipeThread(%x) - Done.\n", hPipe);
return ERROR_SUCCESS;
}
@ -153,7 +162,7 @@ BOOL
ScmCreateNamedPipe(VOID)
{
DWORD dwThreadId;
BOOL fConnected;
BOOL bConnected;
HANDLE hThread;
HANDLE hPipe;
@ -167,17 +176,19 @@ ScmCreateNamedPipe(VOID)
PIPE_BUFSIZE,
PIPE_TIMEOUT,
NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
if (hPipe == INVALID_HANDLE_VALUE)
{
DPRINT("CreateNamedPipe() failed (%d)\n", GetLastError());
return FALSE;
}
DPRINT("CreateNamedPipe() - calling ConnectNamedPipe(%x)\n", hPipe);
fConnected = ConnectNamedPipe(hPipe,
NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
DPRINT("CreateNamedPipe() - ConnectNamedPipe() returned %d\n", fConnected);
bConnected = ConnectNamedPipe(hPipe,
NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
DPRINT("CreateNamedPipe() - ConnectNamedPipe() returned %d\n", bConnected);
if (fConnected) {
if (bConnected)
{
DPRINT("Pipe connected\n");
hThread = CreateThread(NULL,
0,
@ -185,14 +196,17 @@ ScmCreateNamedPipe(VOID)
(LPVOID)hPipe,
0,
&dwThreadId);
if (!hThread) {
if (!hThread)
{
DPRINT("Could not create thread (%d)\n", GetLastError());
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
DPRINT("CreateNamedPipe() - returning FALSE\n");
return FALSE;
return FALSE;
}
} else {
}
else
{
DPRINT("Pipe not connected\n");
CloseHandle(hPipe);
DPRINT("CreateNamedPipe() - returning FALSE\n");
@ -210,10 +224,12 @@ ScmNamedPipeListenerThread(LPVOID Context)
DPRINT("ScmNamedPipeListenerThread(%x) - aka SCM.\n", Context);
// hPipe = (HANDLE)Context;
for (;;) {
for (;;)
{
DPRINT("SCM: Waiting for new connection on named pipe...\n");
/* Create named pipe */
if (!ScmCreateNamedPipe()) {
if (!ScmCreateNamedPipe())
{
DPRINT1("\nSCM: Failed to create named pipe\n");
break;
//ExitThread(0);
@ -229,44 +245,44 @@ ScmNamedPipeListenerThread(LPVOID Context)
BOOL
StartScmNamedPipeThreadListener(VOID)
{
DWORD dwThreadId;
HANDLE hThread;
DWORD dwThreadId;
HANDLE hThread;
hThread = CreateThread(NULL,
0,
ScmNamedPipeListenerThread,
NULL, /*(LPVOID)hPipe,*/
0,
&dwThreadId);
if (!hThread)
{
DPRINT1("SERVICES: Could not create thread (Status %lx)\n", GetLastError());
return FALSE;
}
hThread = CreateThread(NULL,
0,
ScmNamedPipeListenerThread,
NULL, /*(LPVOID)hPipe,*/
0,
&dwThreadId);
if (!hThread)
{
DPRINT1("SERVICES: Could not create thread (Status %lx)\n", GetLastError());
return FALSE;
}
return TRUE;
return TRUE;
}
VOID FASTCALL
AcquireLoadDriverPrivilege(VOID)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
/* Get a token for this process */
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
/* Get the LUID for the debug privilege */
LookupPrivilegeValue(NULL, SE_LOAD_DRIVER_NAME, &tkp.Privileges[0].Luid);
/* Get a token for this process */
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
/* Get the LUID for the debug privilege */
LookupPrivilegeValue(NULL, SE_LOAD_DRIVER_NAME, &tkp.Privileges[0].Luid);
/* One privilege to set */
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
/* One privilege to set */
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
/* Get the debug privilege for this process */
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
/* Get the debug privilege for this process */
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
}
@ -276,79 +292,79 @@ WinMain(HINSTANCE hInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HANDLE hScmStartEvent;
HANDLE hEvent;
NTSTATUS Status;
HANDLE hScmStartEvent;
HANDLE hEvent;
NTSTATUS Status;
DPRINT("SERVICES: Service Control Manager\n");
DPRINT("SERVICES: Service Control Manager\n");
/* Acquire privileges to load drivers */
AcquireLoadDriverPrivilege();
/* Acquire privileges to load drivers */
AcquireLoadDriverPrivilege();
/* Create start event */
if (!ScmCreateStartEvent(&hScmStartEvent))
{
DPRINT1("SERVICES: Failed to create start event\n");
ExitThread(0);
}
/* Create start event */
if (!ScmCreateStartEvent(&hScmStartEvent))
{
DPRINT1("SERVICES: Failed to create start event\n");
ExitThread(0);
}
DPRINT("SERVICES: created start event with handle %x.\n", hScmStartEvent);
DPRINT("SERVICES: created start event with handle %x.\n", hScmStartEvent);
// ScmInitThreadManager();
// ScmInitThreadManager();
/* FIXME: more initialization */
/* FIXME: more initialization */
/* Create the service database */
Status = ScmCreateServiceDataBase();
if (!NT_SUCCESS(Status))
{
DPRINT1("SERVICES: failed to create SCM database (Status %lx)\n", Status);
ExitThread(0);
}
/* Create the service database */
Status = ScmCreateServiceDataBase();
if (!NT_SUCCESS(Status))
{
DPRINT1("SERVICES: failed to create SCM database (Status %lx)\n", Status);
ExitThread(0);
}
/* Update service database */
ScmGetBootAndSystemDriverState();
/* Update service database */
ScmGetBootAndSystemDriverState();
/* Start the RPC server */
ScmStartRpcServer();
/* Start the RPC server */
ScmStartRpcServer();
/* Register service process with CSRSS */
// RegisterServicesProcess(GetCurrentProcessId());
/* Register service process with CSRSS */
// RegisterServicesProcess(GetCurrentProcessId());
DPRINT("SERVICES: Initialized.\n");
DPRINT("SERVICES: Initialized.\n");
/* Signal start event */
SetEvent(hScmStartEvent);
/* Signal start event */
SetEvent(hScmStartEvent);
#if 0
/* FIXME: register event handler (used for system shutdown) */
SetConsoleCtrlHandler(...);
/* FIXME: register event handler (used for system shutdown) */
SetConsoleCtrlHandler(...);
#endif
/* Start auto-start services */
ScmAutoStartServices();
/* Start auto-start services */
ScmAutoStartServices();
/* FIXME: more to do ? */
/* FIXME: more to do ? */
DPRINT("SERVICES: Running.\n");
DPRINT("SERVICES: Running.\n");
#if 1
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
WaitForSingleObject(hEvent, INFINITE);
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
WaitForSingleObject(hEvent, INFINITE);
#else
for (;;)
{
NtYieldExecution();
}
for (;;)
{
NtYieldExecution();
}
#endif
DPRINT("SERVICES: Finished.\n");
DPRINT("SERVICES: Finished.\n");
ExitThread(0);
ExitThread(0);
return 0;
return 0;
}
/* EOF */