diff --git a/reactos/subsys/system/services/database.c b/reactos/subsys/system/services/database.c index 5966c14460a..6c3b9f1622e 100644 --- a/reactos/subsys/system/services/database.c +++ b/reactos/subsys/system/services/database.c @@ -58,29 +58,29 @@ static RTL_RESOURCE DatabaseLock; PSERVICE ScmGetServiceEntryByName(LPWSTR lpServiceName) { - PLIST_ENTRY ServiceEntry; - PSERVICE CurrentService; + PLIST_ENTRY ServiceEntry; + PSERVICE CurrentService; - DPRINT("ScmGetServiceEntryByName() called\n"); + DPRINT("ScmGetServiceEntryByName() called\n"); - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) { - CurrentService = CONTAINING_RECORD(ServiceEntry, - SERVICE, - ServiceListEntry); - if (_wcsicmp(CurrentService->lpServiceName, lpServiceName) == 0) - { - DPRINT("Found service: '%S'\n", CurrentService->lpServiceName); - return CurrentService; - } + CurrentService = CONTAINING_RECORD(ServiceEntry, + SERVICE, + ServiceListEntry); + if (_wcsicmp(CurrentService->lpServiceName, lpServiceName) == 0) + { + DPRINT("Found service: '%S'\n", CurrentService->lpServiceName); + return CurrentService; + } - ServiceEntry = ServiceEntry->Flink; + ServiceEntry = ServiceEntry->Flink; } - DPRINT("Couldn't find a matching service\n"); + DPRINT("Couldn't find a matching service\n"); - return NULL; + return NULL; } @@ -135,11 +135,11 @@ CreateGroupOrderListRoutine(PWSTR ValueName, static NTSTATUS STDCALL CreateGroupListRoutine(PWSTR ValueName, - ULONG ValueType, - PVOID ValueData, - ULONG ValueLength, - PVOID Context, - PVOID EntryContext) + ULONG ValueType, + PVOID ValueData, + ULONG ValueLength, + PVOID Context, + PVOID EntryContext) { PSERVICE_GROUP Group; RTL_QUERY_REGISTRY_TABLE QueryTable[2]; @@ -185,734 +185,735 @@ CreateGroupListRoutine(PWSTR ValueName, static NTSTATUS STDCALL CreateServiceListEntry(LPWSTR lpServiceName) { - RTL_QUERY_REGISTRY_TABLE QueryTable[6]; - UNICODE_STRING ServiceName; - PSERVICE Service = NULL; - NTSTATUS Status; + RTL_QUERY_REGISTRY_TABLE QueryTable[6]; + UNICODE_STRING ServiceName; + PSERVICE Service = NULL; + NTSTATUS Status; - DPRINT("Service: '%wZ'\n", ServiceName); + DPRINT("Service: '%wZ'\n", ServiceName); - /* Allocate service entry */ - Service = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - sizeof(SERVICE) + ((wcslen(lpServiceName) + 1) * sizeof(WCHAR))); - if (Service == NULL) + /* Allocate service entry */ + Service = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(SERVICE) + ((wcslen(lpServiceName) + 1) * sizeof(WCHAR))); + if (Service == NULL) { - return STATUS_INSUFFICIENT_RESOURCES; + return STATUS_INSUFFICIENT_RESOURCES; } - /* Copy service name */ - wcscpy(Service->szServiceName, lpServiceName); - Service->lpServiceName = Service->szServiceName; + /* Copy service name */ + wcscpy(Service->szServiceName, lpServiceName); + Service->lpServiceName = Service->szServiceName; - /* Get service data */ - RtlZeroMemory(&QueryTable, - sizeof(QueryTable)); + /* Get service data */ + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); - QueryTable[0].Name = L"Start"; - QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; - QueryTable[0].EntryContext = &Service->dwStartType; + QueryTable[0].Name = L"Start"; + QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; + QueryTable[0].EntryContext = &Service->dwStartType; - QueryTable[1].Name = L"Type"; - QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; - QueryTable[1].EntryContext = &Service->Status.dwServiceType; + QueryTable[1].Name = L"Type"; + QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; + QueryTable[1].EntryContext = &Service->Status.dwServiceType; - QueryTable[2].Name = L"ErrorControl"; - QueryTable[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; - QueryTable[2].EntryContext = &Service->dwErrorControl; + QueryTable[2].Name = L"ErrorControl"; + QueryTable[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; + QueryTable[2].EntryContext = &Service->dwErrorControl; - QueryTable[3].Name = L"Group"; - QueryTable[3].Flags = RTL_QUERY_REGISTRY_DIRECT; - QueryTable[3].EntryContext = &Service->ServiceGroup; + QueryTable[3].Name = L"Group"; + QueryTable[3].Flags = RTL_QUERY_REGISTRY_DIRECT; + QueryTable[3].EntryContext = &Service->ServiceGroup; - QueryTable[4].Name = L"Tag"; - QueryTable[4].Flags = RTL_QUERY_REGISTRY_DIRECT; - QueryTable[4].EntryContext = &Service->dwTag; + QueryTable[4].Name = L"Tag"; + QueryTable[4].Flags = RTL_QUERY_REGISTRY_DIRECT; + QueryTable[4].EntryContext = &Service->dwTag; - Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES, - lpServiceName, - QueryTable, - NULL, - NULL); - if (!NT_SUCCESS(Status)) + Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES, + lpServiceName, + QueryTable, + NULL, + NULL); + if (!NT_SUCCESS(Status)) { - PrintString("RtlQueryRegistryValues() failed (Status %lx)\n", Status); - HeapFree(GetProcessHeap(), 0, Service); - return Status; + PrintString("RtlQueryRegistryValues() failed (Status %lx)\n", Status); + HeapFree(GetProcessHeap(), 0, Service); + return Status; } - DPRINT("ServiceName: '%S'\n", Service->lpServiceName); - DPRINT("ServiceGroup: '%wZ'\n", &Service->ServiceGroup); - DPRINT("Start %lx Type %lx Tag %lx ErrorControl %lx\n", - Service->dwStartType, - Service->Status.dwServiceType, - Service->dwTag, - Service->dwErrorControl); + DPRINT("ServiceName: '%S'\n", Service->lpServiceName); + DPRINT("ServiceGroup: '%wZ'\n", &Service->ServiceGroup); + DPRINT("Start %lx Type %lx Tag %lx ErrorControl %lx\n", + Service->dwStartType, + Service->Status.dwServiceType, + Service->dwTag, + Service->dwErrorControl); - /* Append service entry */ - InsertTailList(&ServiceListHead, - &Service->ServiceListEntry); + /* Append service entry */ + InsertTailList(&ServiceListHead, + &Service->ServiceListEntry); - Service->Status.dwCurrentState = SERVICE_STOPPED; - Service->Status.dwControlsAccepted = 0; - Service->Status.dwWin32ExitCode = 0; - Service->Status.dwServiceSpecificExitCode = 0; - Service->Status.dwCheckPoint = 0; - Service->Status.dwWaitHint = 2000; /* 2 seconds */ + Service->Status.dwCurrentState = SERVICE_STOPPED; + Service->Status.dwControlsAccepted = 0; + Service->Status.dwWin32ExitCode = 0; + Service->Status.dwServiceSpecificExitCode = 0; + Service->Status.dwCheckPoint = 0; + Service->Status.dwWaitHint = 2000; /* 2 seconds */ - return STATUS_SUCCESS; + return STATUS_SUCCESS; } NTSTATUS ScmCreateServiceDataBase(VOID) { - RTL_QUERY_REGISTRY_TABLE QueryTable[2]; - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING ServicesKeyName = - RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services"); - UNICODE_STRING SubKeyName; - HKEY ServicesKey; - ULONG Index; - NTSTATUS Status; + RTL_QUERY_REGISTRY_TABLE QueryTable[2]; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING ServicesKeyName = + RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services"); + UNICODE_STRING SubKeyName; + HKEY ServicesKey; + ULONG Index; + NTSTATUS Status; - PKEY_BASIC_INFORMATION KeyInfo = NULL; - ULONG KeyInfoLength = 0; - ULONG ReturnedLength; + PKEY_BASIC_INFORMATION KeyInfo = NULL; + ULONG KeyInfoLength = 0; + ULONG ReturnedLength; - DPRINT("ScmCreateServiceDataBase() called\n"); + DPRINT("ScmCreateServiceDataBase() called\n"); - /* Initialize basic variables */ - InitializeListHead(&GroupListHead); - InitializeListHead(&ServiceListHead); + /* Initialize basic variables */ + InitializeListHead(&GroupListHead); + InitializeListHead(&ServiceListHead); - /* Initialize the database lock */ - RtlInitializeResource(&DatabaseLock); + /* Initialize the database lock */ + RtlInitializeResource(&DatabaseLock); - /* Build group order list */ - RtlZeroMemory(&QueryTable, - sizeof(QueryTable)); + /* Build group order list */ + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); - QueryTable[0].Name = L"List"; - QueryTable[0].QueryRoutine = CreateGroupListRoutine; + QueryTable[0].Name = L"List"; + QueryTable[0].QueryRoutine = CreateGroupListRoutine; - Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, - L"ServiceGroupOrder", - QueryTable, - NULL, - NULL); - if (!NT_SUCCESS(Status)) - return Status; + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"ServiceGroupOrder", + QueryTable, + NULL, + NULL); + if (!NT_SUCCESS(Status)) + return Status; - RtlInitUnicodeString(&ServicesKeyName, - L"\\Registry\\Machine\\System\\CurrentControlSet\\Services"); + RtlInitUnicodeString(&ServicesKeyName, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Services"); - InitializeObjectAttributes(&ObjectAttributes, - &ServicesKeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); + InitializeObjectAttributes(&ObjectAttributes, + &ServicesKeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); - Status = RtlpNtOpenKey(&ServicesKey, - KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, - &ObjectAttributes, - 0); - if (!NT_SUCCESS(Status)) - return Status; + Status = RtlpNtOpenKey(&ServicesKey, + KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, + &ObjectAttributes, + 0); + if (!NT_SUCCESS(Status)) + return Status; - /* Allocate key info buffer */ - KeyInfoLength = sizeof(KEY_BASIC_INFORMATION) + MAX_PATH * sizeof(WCHAR); - KeyInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, KeyInfoLength); - if (KeyInfo == NULL) + /* Allocate key info buffer */ + KeyInfoLength = sizeof(KEY_BASIC_INFORMATION) + MAX_PATH * sizeof(WCHAR); + KeyInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, KeyInfoLength); + if (KeyInfo == NULL) { - NtClose(ServicesKey); - return STATUS_INSUFFICIENT_RESOURCES; + NtClose(ServicesKey); + return STATUS_INSUFFICIENT_RESOURCES; } - Index = 0; - while (TRUE) + Index = 0; + while (TRUE) { - Status = NtEnumerateKey(ServicesKey, - Index, - KeyBasicInformation, - KeyInfo, - KeyInfoLength, - &ReturnedLength); - if (NT_SUCCESS(Status)) - { - if (KeyInfo->NameLength < MAX_PATH * sizeof(WCHAR)) - { + Status = NtEnumerateKey(ServicesKey, + Index, + KeyBasicInformation, + KeyInfo, + KeyInfoLength, + &ReturnedLength); + if (NT_SUCCESS(Status)) + { + if (KeyInfo->NameLength < MAX_PATH * sizeof(WCHAR)) + { + SubKeyName.Length = KeyInfo->NameLength; + SubKeyName.MaximumLength = KeyInfo->NameLength + sizeof(WCHAR); + SubKeyName.Buffer = KeyInfo->Name; + SubKeyName.Buffer[SubKeyName.Length / sizeof(WCHAR)] = 0; - SubKeyName.Length = KeyInfo->NameLength; - SubKeyName.MaximumLength = KeyInfo->NameLength + sizeof(WCHAR); - SubKeyName.Buffer = KeyInfo->Name; - SubKeyName.Buffer[SubKeyName.Length / sizeof(WCHAR)] = 0; + DPRINT("KeyName: '%wZ'\n", &SubKeyName); + Status = CreateServiceListEntry(SubKeyName.Buffer); - DPRINT("KeyName: '%wZ'\n", &SubKeyName); - Status = CreateServiceListEntry(SubKeyName.Buffer); + /* Ignore services without proper registry. */ + if (Status == STATUS_OBJECT_NAME_NOT_FOUND) + { + Status = STATUS_SUCCESS; + } + } + } - /* Ignore services without proper registry. */ - if (Status == STATUS_OBJECT_NAME_NOT_FOUND) - { - Status = STATUS_SUCCESS; - } - } - } + if (!NT_SUCCESS(Status)) + break; - if (!NT_SUCCESS(Status)) - break; - - Index++; + Index++; } - HeapFree(GetProcessHeap(), 0, KeyInfo); - NtClose(ServicesKey); + HeapFree(GetProcessHeap(), 0, KeyInfo); + NtClose(ServicesKey); - DPRINT("ScmCreateServiceDataBase() done\n"); + DPRINT("ScmCreateServiceDataBase() done\n"); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static NTSTATUS ScmCheckDriver(PSERVICE Service) { - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING DirName; - HANDLE DirHandle; - NTSTATUS Status; - POBJECT_DIRECTORY_INFORMATION DirInfo; - ULONG BufferLength; - ULONG DataLength; - ULONG Index; - PLIST_ENTRY GroupEntry; - PSERVICE_GROUP CurrentGroup; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING DirName; + HANDLE DirHandle; + NTSTATUS Status; + POBJECT_DIRECTORY_INFORMATION DirInfo; + ULONG BufferLength; + ULONG DataLength; + ULONG Index; + PLIST_ENTRY GroupEntry; + PSERVICE_GROUP CurrentGroup; - DPRINT("ScmCheckDriver(%S) called\n", Service->lpServiceName); + DPRINT("ScmCheckDriver(%S) called\n", Service->lpServiceName); - if (Service->Status.dwServiceType == SERVICE_KERNEL_DRIVER) + if (Service->Status.dwServiceType == SERVICE_KERNEL_DRIVER) { - RtlInitUnicodeString(&DirName, - L"\\Driver"); + RtlInitUnicodeString(&DirName, + L"\\Driver"); } - else + else { - RtlInitUnicodeString(&DirName, - L"\\FileSystem"); + RtlInitUnicodeString(&DirName, + L"\\FileSystem"); } - InitializeObjectAttributes(&ObjectAttributes, - &DirName, - 0, - NULL, - NULL); + InitializeObjectAttributes(&ObjectAttributes, + &DirName, + 0, + NULL, + NULL); - Status = NtOpenDirectoryObject(&DirHandle, - DIRECTORY_QUERY | DIRECTORY_TRAVERSE, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) + Status = NtOpenDirectoryObject(&DirHandle, + DIRECTORY_QUERY | DIRECTORY_TRAVERSE, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) { - return Status; + return Status; } - BufferLength = sizeof(OBJECT_DIRECTORY_INFORMATION) + - 2 * MAX_PATH * sizeof(WCHAR); - DirInfo = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - BufferLength); + BufferLength = sizeof(OBJECT_DIRECTORY_INFORMATION) + + 2 * MAX_PATH * sizeof(WCHAR); + DirInfo = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + BufferLength); - Index = 0; - while (TRUE) + Index = 0; + while (TRUE) { - Status = NtQueryDirectoryObject(DirHandle, - DirInfo, - BufferLength, - TRUE, - FALSE, - &Index, - &DataLength); - if (Status == STATUS_NO_MORE_ENTRIES) - { - /* FIXME: Add current service to 'failed service' list */ - DPRINT("Service '%S' failed\n", Service->lpServiceName); - break; - } + Status = NtQueryDirectoryObject(DirHandle, + DirInfo, + BufferLength, + TRUE, + FALSE, + &Index, + &DataLength); + if (Status == STATUS_NO_MORE_ENTRIES) + { + /* FIXME: Add current service to 'failed service' list */ + DPRINT("Service '%S' failed\n", Service->lpServiceName); + break; + } - if (!NT_SUCCESS(Status)) - break; + if (!NT_SUCCESS(Status)) + break; - DPRINT("Comparing: '%S' '%wZ'\n", Service->lpServiceName, &DirInfo->ObjectName); + DPRINT("Comparing: '%S' '%wZ'\n", Service->lpServiceName, &DirInfo->ObjectName); - if (_wcsicmp(Service->lpServiceName, DirInfo->ObjectName.Buffer) == 0) - { - DPRINT("Found: '%S' '%wZ'\n", Service->lpServiceName, &DirInfo->ObjectName); + if (_wcsicmp(Service->lpServiceName, DirInfo->ObjectName.Buffer) == 0) + { + DPRINT("Found: '%S' '%wZ'\n", + Service->lpServiceName, &DirInfo->ObjectName); - /* Mark service as 'running' */ - Service->Status.dwCurrentState = SERVICE_RUNNING; + /* Mark service as 'running' */ + Service->Status.dwCurrentState = SERVICE_RUNNING; - /* Find the driver's group and mark it as 'running' */ - if (Service->ServiceGroup.Buffer != NULL) - { - GroupEntry = GroupListHead.Flink; - while (GroupEntry != &GroupListHead) - { - CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry); + /* Find the driver's group and mark it as 'running' */ + if (Service->ServiceGroup.Buffer != NULL) + { + GroupEntry = GroupListHead.Flink; + while (GroupEntry != &GroupListHead) + { + CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry); - DPRINT("Checking group '%wZ'\n", &CurrentGroup->GroupName); - if (RtlEqualUnicodeString(&Service->ServiceGroup, &CurrentGroup->GroupName, TRUE)) - { - CurrentGroup->ServicesRunning = TRUE; - } + DPRINT("Checking group '%wZ'\n", &CurrentGroup->GroupName); + if (RtlEqualUnicodeString(&Service->ServiceGroup, &CurrentGroup->GroupName, TRUE)) + { + CurrentGroup->ServicesRunning = TRUE; + } - GroupEntry = GroupEntry->Flink; - } - } - break; - } + GroupEntry = GroupEntry->Flink; + } + } + break; + } } - HeapFree(GetProcessHeap(), - 0, - DirInfo); - NtClose(DirHandle); + HeapFree(GetProcessHeap(), + 0, + DirInfo); + NtClose(DirHandle); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } VOID ScmGetBootAndSystemDriverState(VOID) { - PLIST_ENTRY ServiceEntry; - PSERVICE CurrentService; + PLIST_ENTRY ServiceEntry; + PSERVICE CurrentService; - DPRINT("ScmGetBootAndSystemDriverState() called\n"); + DPRINT("ScmGetBootAndSystemDriverState() called\n"); - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) { - CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); + CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); - if (CurrentService->dwStartType == SERVICE_BOOT_START || - CurrentService->dwStartType == SERVICE_SYSTEM_START) - { - /* Check driver */ - DPRINT(" Checking service: %S\n", CurrentService->lpServiceName); + if (CurrentService->dwStartType == SERVICE_BOOT_START || + CurrentService->dwStartType == SERVICE_SYSTEM_START) + { + /* Check driver */ + DPRINT(" Checking service: %S\n", CurrentService->lpServiceName); - ScmCheckDriver(CurrentService); - } - ServiceEntry = ServiceEntry->Flink; + ScmCheckDriver(CurrentService); + } + + ServiceEntry = ServiceEntry->Flink; } - DPRINT("ScmGetBootAndSystemDriverState() done\n"); + DPRINT("ScmGetBootAndSystemDriverState() done\n"); } static NTSTATUS ScmSendStartCommand(PSERVICE Service, LPWSTR Arguments) { - PSCM_START_PACKET StartPacket; - DWORD TotalLength; + PSCM_START_PACKET StartPacket; + DWORD TotalLength; #if 0 - DWORD Length; + DWORD Length; #endif - PWSTR Ptr; - DWORD Count; + PWSTR Ptr; + DWORD Count; - DPRINT("ScmSendStartCommand() called\n"); + DPRINT("ScmSendStartCommand() called\n"); - /* Calculate the total length of the start command line */ - TotalLength = wcslen(Service->lpServiceName) + 1; + /* Calculate the total length of the start command line */ + TotalLength = wcslen(Service->lpServiceName) + 1; #if 0 - if (Arguments != NULL) - { - Ptr = Arguments; - while (*Ptr) + if (Arguments != NULL) { - Length = wcslen(Ptr) + 1; - TotalLength += Length; - Ptr += Length; + Ptr = Arguments; + while (*Ptr) + { + Length = wcslen(Ptr) + 1; + TotalLength += Length; + Ptr += Length; + } } - } #endif - TotalLength++; + TotalLength++; - /* Allocate start command packet */ - StartPacket = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - sizeof(SCM_START_PACKET) + (TotalLength - 1) * sizeof(WCHAR)); - if (StartPacket == NULL) - return STATUS_INSUFFICIENT_RESOURCES; + /* Allocate start command packet */ + StartPacket = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(SCM_START_PACKET) + (TotalLength - 1) * sizeof(WCHAR)); + if (StartPacket == NULL) + return STATUS_INSUFFICIENT_RESOURCES; - StartPacket->Command = SCM_START_COMMAND; - StartPacket->Size = TotalLength; - Ptr = &StartPacket->Arguments[0]; - wcscpy(Ptr, Service->lpServiceName); - Ptr += (wcslen(Service->lpServiceName) + 1); + StartPacket->Command = SCM_START_COMMAND; + StartPacket->Size = TotalLength; + Ptr = &StartPacket->Arguments[0]; + wcscpy(Ptr, Service->lpServiceName); + Ptr += (wcslen(Service->lpServiceName) + 1); - /* FIXME: Copy argument list */ + /* FIXME: Copy argument list */ - *Ptr = 0; + *Ptr = 0; - /* Send the start command */ - WriteFile(Service->ControlPipeHandle, - StartPacket, - sizeof(SCM_START_PACKET) + (TotalLength - 1) * sizeof(WCHAR), - &Count, - NULL); + /* Send the start command */ + WriteFile(Service->ControlPipeHandle, + StartPacket, + sizeof(SCM_START_PACKET) + (TotalLength - 1) * sizeof(WCHAR), + &Count, + NULL); - /* FIXME: Read the reply */ + /* FIXME: Read the reply */ - HeapFree(GetProcessHeap(), - 0, - StartPacket); + HeapFree(GetProcessHeap(), + 0, + StartPacket); - DPRINT("ScmSendStartCommand() done\n"); + DPRINT("ScmSendStartCommand() done\n"); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static NTSTATUS ScmStartUserModeService(PSERVICE Service) { - RTL_QUERY_REGISTRY_TABLE QueryTable[3]; - PROCESS_INFORMATION ProcessInformation; - STARTUPINFOW StartupInfo; - UNICODE_STRING ImagePath; - ULONG Type; - BOOL Result; - NTSTATUS Status; + RTL_QUERY_REGISTRY_TABLE QueryTable[3]; + PROCESS_INFORMATION ProcessInformation; + STARTUPINFOW StartupInfo; + UNICODE_STRING ImagePath; + ULONG Type; + BOOL Result; + NTSTATUS Status; - RtlInitUnicodeString(&ImagePath, NULL); + RtlInitUnicodeString(&ImagePath, NULL); - /* Get service data */ - RtlZeroMemory(&QueryTable, - sizeof(QueryTable)); + /* Get service data */ + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); - QueryTable[0].Name = L"Type"; - QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; - QueryTable[0].EntryContext = &Type; + QueryTable[0].Name = L"Type"; + QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; + QueryTable[0].EntryContext = &Type; - QueryTable[1].Name = L"ImagePath"; - QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; - QueryTable[1].EntryContext = &ImagePath; + QueryTable[1].Name = L"ImagePath"; + QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; + QueryTable[1].EntryContext = &ImagePath; - Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES, - Service->lpServiceName, - QueryTable, - NULL, - NULL); - if (!NT_SUCCESS(Status)) + Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES, + Service->lpServiceName, + QueryTable, + NULL, + NULL); + if (!NT_SUCCESS(Status)) { - DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status); - return Status; + DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status); + return Status; } - DPRINT("ImagePath: '%S'\n", ImagePath.Buffer); - DPRINT("Type: %lx\n", Type); + DPRINT("ImagePath: '%S'\n", ImagePath.Buffer); + DPRINT("Type: %lx\n", Type); - /* Create '\\.\pipe\net\NtControlPipe' instance */ - Service->ControlPipeHandle = CreateNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe", - PIPE_ACCESS_DUPLEX, - PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, - 100, - 8000, - 4, - 30000, - NULL); - DPRINT("CreateNamedPipeW() done\n"); - if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE) + /* Create '\\.\pipe\net\NtControlPipe' instance */ + Service->ControlPipeHandle = CreateNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe", + PIPE_ACCESS_DUPLEX, + PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, + 100, + 8000, + 4, + 30000, + NULL); + DPRINT("CreateNamedPipeW() done\n"); + if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE) { - DPRINT1("Failed to create control pipe!\n"); - return STATUS_UNSUCCESSFUL; + DPRINT1("Failed to create control pipe!\n"); + return STATUS_UNSUCCESSFUL; } - StartupInfo.cb = sizeof(StartupInfo); - StartupInfo.lpReserved = NULL; - StartupInfo.lpDesktop = NULL; - StartupInfo.lpTitle = NULL; - StartupInfo.dwFlags = 0; - StartupInfo.cbReserved2 = 0; - StartupInfo.lpReserved2 = 0; + StartupInfo.cb = sizeof(StartupInfo); + StartupInfo.lpReserved = NULL; + StartupInfo.lpDesktop = NULL; + StartupInfo.lpTitle = NULL; + StartupInfo.dwFlags = 0; + StartupInfo.cbReserved2 = 0; + StartupInfo.lpReserved2 = 0; - Result = CreateProcessW(ImagePath.Buffer, - NULL, - NULL, - NULL, - FALSE, - DETACHED_PROCESS | CREATE_SUSPENDED, - NULL, - NULL, - &StartupInfo, - &ProcessInformation); - RtlFreeUnicodeString(&ImagePath); + Result = CreateProcessW(ImagePath.Buffer, + NULL, + NULL, + NULL, + FALSE, + DETACHED_PROCESS | CREATE_SUSPENDED, + NULL, + NULL, + &StartupInfo, + &ProcessInformation); + RtlFreeUnicodeString(&ImagePath); - if (!Result) + if (!Result) { - /* Close control pipe */ - CloseHandle(Service->ControlPipeHandle); - Service->ControlPipeHandle = INVALID_HANDLE_VALUE; + /* Close control pipe */ + CloseHandle(Service->ControlPipeHandle); + Service->ControlPipeHandle = INVALID_HANDLE_VALUE; - DPRINT1("Starting '%S' failed!\n", Service->lpServiceName); - return STATUS_UNSUCCESSFUL; + DPRINT1("Starting '%S' failed!\n", Service->lpServiceName); + return STATUS_UNSUCCESSFUL; } - DPRINT("Process Id: %lu Handle %lx\n", - ProcessInformation.dwProcessId, - ProcessInformation.hProcess); - DPRINT("Thread Id: %lu Handle %lx\n", - ProcessInformation.dwThreadId, - ProcessInformation.hThread); + DPRINT("Process Id: %lu Handle %lx\n", + ProcessInformation.dwProcessId, + ProcessInformation.hProcess); + DPRINT("Thread Id: %lu Handle %lx\n", + ProcessInformation.dwThreadId, + ProcessInformation.hThread); - /* Get process and thread ids */ - Service->ProcessId = ProcessInformation.dwProcessId; - Service->ThreadId = ProcessInformation.dwThreadId; + /* Get process and thread ids */ + Service->ProcessId = ProcessInformation.dwProcessId; + Service->ThreadId = ProcessInformation.dwThreadId; - /* Resume Thread */ - ResumeThread(ProcessInformation.hThread); + /* Resume Thread */ + ResumeThread(ProcessInformation.hThread); - /* Connect control pipe */ - if (ConnectNamedPipe(Service->ControlPipeHandle, NULL)) + /* Connect control pipe */ + if (ConnectNamedPipe(Service->ControlPipeHandle, NULL)) { - DWORD dwProcessId = 0; - DWORD dwRead = 0; + DWORD dwProcessId = 0; + DWORD dwRead = 0; - DPRINT("Control pipe connected!\n"); + DPRINT("Control pipe connected!\n"); - /* Read thread id from pipe */ - if (!ReadFile(Service->ControlPipeHandle, - (LPVOID)&dwProcessId, - sizeof(DWORD), - &dwRead, - NULL)) - { - DPRINT1("Reading the service control pipe failed (Error %lu)\n", - GetLastError()); - Status = STATUS_UNSUCCESSFUL; - } - else - { - DPRINT("Received process id %lu\n", dwProcessId); + /* Read thread id from pipe */ + if (!ReadFile(Service->ControlPipeHandle, + (LPVOID)&dwProcessId, + sizeof(DWORD), + &dwRead, + NULL)) + { + DPRINT1("Reading the service control pipe failed (Error %lu)\n", + GetLastError()); + Status = STATUS_UNSUCCESSFUL; + } + else + { + DPRINT("Received process id %lu\n", dwProcessId); - /* FIXME: Send start command */ + /* FIXME: Send start command */ - Status = STATUS_SUCCESS; - } + Status = STATUS_SUCCESS; + } } - else + else { - DPRINT("Connecting control pipe failed!\n"); + DPRINT("Connecting control pipe failed!\n"); - /* Close control pipe */ - CloseHandle(Service->ControlPipeHandle); - Service->ControlPipeHandle = INVALID_HANDLE_VALUE; - Service->ProcessId = 0; - Service->ThreadId = 0; - Status = STATUS_UNSUCCESSFUL; + /* Close control pipe */ + CloseHandle(Service->ControlPipeHandle); + Service->ControlPipeHandle = INVALID_HANDLE_VALUE; + Service->ProcessId = 0; + Service->ThreadId = 0; + Status = STATUS_UNSUCCESSFUL; } - ScmSendStartCommand(Service, NULL); + ScmSendStartCommand(Service, NULL); - /* Close process and thread handle */ - CloseHandle(ProcessInformation.hThread); - CloseHandle(ProcessInformation.hProcess); + /* Close process and thread handle */ + CloseHandle(ProcessInformation.hThread); + CloseHandle(ProcessInformation.hProcess); - return Status; + return Status; } static NTSTATUS ScmStartService(PSERVICE Service, - PSERVICE_GROUP Group) + PSERVICE_GROUP Group) { - WCHAR szDriverPath[MAX_PATH]; - UNICODE_STRING DriverPath; - NTSTATUS Status; + WCHAR szDriverPath[MAX_PATH]; + UNICODE_STRING DriverPath; + NTSTATUS Status; - DPRINT("ScmStartService() called\n"); + DPRINT("ScmStartService() called\n"); - Service->ControlPipeHandle = INVALID_HANDLE_VALUE; - DPRINT("Service->Type: %lu\n", Service->Status.dwServiceType); + Service->ControlPipeHandle = INVALID_HANDLE_VALUE; + DPRINT("Service->Type: %lu\n", Service->Status.dwServiceType); - if (Service->Status.dwServiceType == SERVICE_KERNEL_DRIVER || - Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER || - Service->Status.dwServiceType == SERVICE_RECOGNIZER_DRIVER) + if (Service->Status.dwServiceType == SERVICE_KERNEL_DRIVER || + Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER || + Service->Status.dwServiceType == SERVICE_RECOGNIZER_DRIVER) { - /* Load driver */ - wcscpy(szDriverPath, - L"\\Registry\\Machine\\System\\CurrentControlSet\\Services"); - wcscat(szDriverPath, - Service->lpServiceName); + /* Load driver */ + wcscpy(szDriverPath, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Services"); + wcscat(szDriverPath, + Service->lpServiceName); - RtlInitUnicodeString(&DriverPath, - szDriverPath); + RtlInitUnicodeString(&DriverPath, + szDriverPath); - DPRINT(" Path: %wZ\n", &DriverPath); - Status = NtLoadDriver(&DriverPath); + DPRINT(" Path: %wZ\n", &DriverPath); + Status = NtLoadDriver(&DriverPath); } - else + else { - /* Start user-mode service */ - Status = ScmStartUserModeService(Service); + /* Start user-mode service */ + Status = ScmStartUserModeService(Service); } - DPRINT("ScmStartService() done (Status %lx)\n", Status); + DPRINT("ScmStartService() done (Status %lx)\n", Status); - if (NT_SUCCESS(Status)) + if (NT_SUCCESS(Status)) { - if (Group != NULL) - { - Group->ServicesRunning = TRUE; - } - Service->Status.dwCurrentState = SERVICE_RUNNING; + if (Group != NULL) + { + Group->ServicesRunning = TRUE; + } + Service->Status.dwCurrentState = SERVICE_RUNNING; } #if 0 - else + else { - switch (Service->ErrorControl) - { - case SERVICE_ERROR_NORMAL: - /* FIXME: Log error */ - break; + switch (Service->ErrorControl) + { + case SERVICE_ERROR_NORMAL: + /* FIXME: Log error */ + break; - case SERVICE_ERROR_SEVERE: - if (IsLastKnownGood == FALSE) - { - /* FIXME: Boot last known good configuration */ - } - break; + case SERVICE_ERROR_SEVERE: + if (IsLastKnownGood == FALSE) + { + /* FIXME: Boot last known good configuration */ + } + break; - case SERVICE_ERROR_CRITICAL: - if (IsLastKnownGood == FALSE) - { - /* FIXME: Boot last known good configuration */ - } - else - { - /* FIXME: BSOD! */ - } - break; - } + case SERVICE_ERROR_CRITICAL: + if (IsLastKnownGood == FALSE) + { + /* FIXME: Boot last known good configuration */ + } + else + { + /* FIXME: BSOD! */ + } + break; + } } #endif - return Status; + return Status; } VOID ScmAutoStartServices(VOID) { - PLIST_ENTRY GroupEntry; - PLIST_ENTRY ServiceEntry; - PSERVICE_GROUP CurrentGroup; - PSERVICE CurrentService; - ULONG i; + PLIST_ENTRY GroupEntry; + PLIST_ENTRY ServiceEntry; + PSERVICE_GROUP CurrentGroup; + PSERVICE CurrentService; + ULONG i; - /* Clear 'ServiceVisited' flag */ - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) + /* Clear 'ServiceVisited' flag */ + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) { CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); CurrentService->ServiceVisited = FALSE; ServiceEntry = ServiceEntry->Flink; } - /* Start all services which are members of an existing group */ - GroupEntry = GroupListHead.Flink; - while (GroupEntry != &GroupListHead) + /* Start all services which are members of an existing group */ + GroupEntry = GroupListHead.Flink; + while (GroupEntry != &GroupListHead) { - CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry); + CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry); - DPRINT("Group '%wZ'\n", &CurrentGroup->GroupName); + DPRINT("Group '%wZ'\n", &CurrentGroup->GroupName); - /* Start all services witch have a valid tag */ - for (i = 0; i < CurrentGroup->TagCount; i++) + /* Start all services witch have a valid tag */ + for (i = 0; i < CurrentGroup->TagCount; i++) { - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) - { - CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) + { + CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); - if ((RtlEqualUnicodeString(&CurrentGroup->GroupName, &CurrentService->ServiceGroup, TRUE)) && - (CurrentService->dwStartType == SERVICE_AUTO_START) && - (CurrentService->ServiceVisited == FALSE) && - (CurrentService->dwTag == CurrentGroup->TagArray[i])) - { - CurrentService->ServiceVisited = TRUE; - ScmStartService(CurrentService, - CurrentGroup); - } + if ((RtlEqualUnicodeString(&CurrentGroup->GroupName, &CurrentService->ServiceGroup, TRUE)) && + (CurrentService->dwStartType == SERVICE_AUTO_START) && + (CurrentService->ServiceVisited == FALSE) && + (CurrentService->dwTag == CurrentGroup->TagArray[i])) + { + CurrentService->ServiceVisited = TRUE; + ScmStartService(CurrentService, + CurrentGroup); + } - ServiceEntry = ServiceEntry->Flink; - } + ServiceEntry = ServiceEntry->Flink; + } } - /* Start all services which have an invalid tag or which do not have a tag */ - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) - { - CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); + /* Start all services which have an invalid tag or which do not have a tag */ + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) + { + CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); - if ((RtlEqualUnicodeString(&CurrentGroup->GroupName, &CurrentService->ServiceGroup, TRUE)) && - (CurrentService->dwStartType == SERVICE_AUTO_START) && - (CurrentService->ServiceVisited == FALSE)) - { - CurrentService->ServiceVisited = TRUE; - ScmStartService(CurrentService, - CurrentGroup); - } + if ((RtlEqualUnicodeString(&CurrentGroup->GroupName, &CurrentService->ServiceGroup, TRUE)) && + (CurrentService->dwStartType == SERVICE_AUTO_START) && + (CurrentService->ServiceVisited == FALSE)) + { + CurrentService->ServiceVisited = TRUE; + ScmStartService(CurrentService, + CurrentGroup); + } - ServiceEntry = ServiceEntry->Flink; - } + ServiceEntry = ServiceEntry->Flink; + } - GroupEntry = GroupEntry->Flink; + GroupEntry = GroupEntry->Flink; } - /* Start all services which are members of any non-existing group */ - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) + /* Start all services which are members of any non-existing group */ + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) { - CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); + CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); - if ((CurrentService->ServiceGroup.Length != 0) && - (CurrentService->dwStartType == SERVICE_AUTO_START) && - (CurrentService->ServiceVisited == FALSE)) - { - CurrentService->ServiceVisited = TRUE; - ScmStartService(CurrentService, - NULL); - } + if ((CurrentService->ServiceGroup.Length != 0) && + (CurrentService->dwStartType == SERVICE_AUTO_START) && + (CurrentService->ServiceVisited == FALSE)) + { + CurrentService->ServiceVisited = TRUE; + ScmStartService(CurrentService, + NULL); + } - ServiceEntry = ServiceEntry->Flink; + ServiceEntry = ServiceEntry->Flink; } - /* Start all services which are not a member of any group */ - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) + /* Start all services which are not a member of any group */ + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) { - CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); + CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); - if ((CurrentService->ServiceGroup.Length == 0) && - (CurrentService->dwStartType == SERVICE_AUTO_START) && - (CurrentService->ServiceVisited == FALSE)) - { - CurrentService->ServiceVisited = TRUE; - ScmStartService(CurrentService, - NULL); - } + if ((CurrentService->ServiceGroup.Length == 0) && + (CurrentService->dwStartType == SERVICE_AUTO_START) && + (CurrentService->ServiceVisited == FALSE)) + { + CurrentService->ServiceVisited = TRUE; + ScmStartService(CurrentService, + NULL); + } - ServiceEntry = ServiceEntry->Flink; + ServiceEntry = ServiceEntry->Flink; } - /* Clear 'ServiceVisited' flag again */ - ServiceEntry = ServiceListHead.Flink; - while (ServiceEntry != &ServiceListHead) + /* Clear 'ServiceVisited' flag again */ + ServiceEntry = ServiceListHead.Flink; + while (ServiceEntry != &ServiceListHead) { - CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); - CurrentService->ServiceVisited = FALSE; - ServiceEntry = ServiceEntry->Flink; + CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry); + CurrentService->ServiceVisited = FALSE; + ServiceEntry = ServiceEntry->Flink; } } @@ -920,9 +921,9 @@ ScmAutoStartServices(VOID) DWORD ScmMarkServiceForDelete(PSERVICE pService) { - DPRINT1("ScmMarkServiceForDelete() called\n"); + DPRINT1("ScmMarkServiceForDelete() called\n"); - return ERROR_SUCCESS; + return ERROR_SUCCESS; } /* EOF */ diff --git a/reactos/subsys/system/services/rpcserver.c b/reactos/subsys/system/services/rpcserver.c index 58b8535fc05..01417340a0b 100644 --- a/reactos/subsys/system/services/rpcserver.c +++ b/reactos/subsys/system/services/rpcserver.c @@ -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 */ diff --git a/reactos/subsys/system/services/services.c b/reactos/subsys/system/services/services.c index feb56658294..f834c5611dd 100644 --- a/reactos/subsys/system/services/services.c +++ b/reactos/subsys/system/services/services.c @@ -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 */