ReactOS 0.4.15-dev-8109-gd7be748
service.c
Go to the documentation of this file.
1/*
2 * PROJECT: Local Security Authority Server DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/lsasrv/service.c
5 * PURPOSE: Security service
6 * COPYRIGHT: Copyright 2016, 2019 Eric Kohl <eric.kohl@reactos.org>
7 */
8
9/* INCLUDES ****************************************************************/
10
11#include "lsasrv.h"
12#include <winsvc.h>
13
14typedef VOID (WINAPI *PNETLOGONMAIN)(INT ArgCount, PWSTR *ArgVector);
15
17
18static VOID WINAPI NetlogonServiceMain(DWORD dwArgc, PWSTR *pszArgv);
19static VOID WINAPI SamSsServiceMain(DWORD dwArgc, PWSTR *pszArgv);
20
22{
23 {L"NETLOGON", NetlogonServiceMain},
24 {L"SAMSS", SamSsServiceMain},
25 {NULL, NULL}
26};
27
28
29/* FUNCTIONS ***************************************************************/
30
31static
32VOID
35 _In_ DWORD dwArgc,
36 _In_ PWSTR *pszArgv)
37{
38 HINSTANCE hNetlogon = NULL;
39 PNETLOGONMAIN pNetlogonMain = NULL;
40
41 TRACE("NetlogonServiceMain(%lu %p)\n", dwArgc, pszArgv);
42
43 hNetlogon = LoadLibraryW(L"Netlogon.dll");
44 if (hNetlogon == NULL)
45 {
46 ERR("LoadLibrary() failed!\n");
47 return;
48 }
49
50 pNetlogonMain = (PNETLOGONMAIN)GetProcAddress(hNetlogon, "NlNetlogonMain");
51 if (pNetlogonMain == NULL)
52 {
53 ERR("GetProcAddress(NlNetlogonMain) failed!\n");
54 FreeLibrary(hNetlogon);
55 return;
56 }
57
58 TRACE("NlNetlogonMain %p\n", pNetlogonMain);
59
60 pNetlogonMain(dwArgc, pszArgv);
61}
62
63
64static
65VOID
68 _In_ DWORD fdwControl)
69{
70 TRACE("SamSsControlHandler(%lu)\n", fdwControl);
71}
72
73
74static
75VOID
78 _In_ DWORD dwArgc,
79 _In_ PWSTR *pszArgv)
80{
83
84 TRACE("SamSsServiceMain(%lu %p)\n", dwArgc, pszArgv);
85
88 if (hStatus == NULL)
89 return;
90
98
100
104
106}
107
108
109static
110DWORD
111WINAPI
113 _In_ PVOID pParameter)
114{
116 DWORD dwError;
117
118 TRACE("DispatcherThread(%p)\n", pParameter);
119
120 /* Create or open the SECURITY_SERVICES_STARTED event */
122 TRUE,
123 FALSE,
124 L"SECURITY_SERVICES_STARTED");
125 if (hEvent == NULL)
126 {
127 dwError = GetLastError();
128 if (dwError != ERROR_ALREADY_EXISTS)
129 return dwError;
130
132 FALSE,
133 L"SECURITY_SERVICES_STARTED");
134 if (hEvent == NULL)
135 return GetLastError();
136 }
137
138 /* Wait for the SECURITY_SERVICES_STARTED event to be signaled */
139 TRACE("Waiting for the SECURITY_SERVICES_STARTED event!\n");
141 TRACE("WaitForSingleObject returned %lu\n", dwError);
142
143 /* Close the event handle */
145
146 /* Fail, if the event was not signaled */
147 if (dwError != WAIT_OBJECT_0)
148 {
149 ERR("Wait failed!\n");
150 return dwError;
151 }
152
153 /* This is the security process */
155
156 /* Start the services */
157 TRACE("Start the security services!\n");
159 return GetLastError();
160
161 TRACE("Done!\n");
162
163 return ERROR_SUCCESS;
164}
165
166
168WINAPI
170{
173
174 TRACE("ServiceInit()\n");
175
177 0,
179 NULL,
180 0,
181 &dwThreadId);
182 if (hThread == NULL)
183 return (NTSTATUS)GetLastError();
184
185 return STATUS_SUCCESS;
186}
187
188/* EOF */
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
#define VOID
Definition: acefi.h:82
LONG NTSTATUS
Definition: precomp.h:26
static SERVICE_STATUS ServiceStatus
Definition: browser.c:22
#define ERR(fmt,...)
Definition: debug.h:113
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
static VOID WINAPI SamSsControlHandler(_In_ DWORD fdwControl)
Definition: service.c:67
VOID(WINAPI * PNETLOGONMAIN)(INT ArgCount, PWSTR *ArgVector)
Definition: service.c:14
static VOID WINAPI NetlogonServiceMain(DWORD dwArgc, PWSTR *pszArgv)
NTSTATUS WINAPI ServiceInit(VOID)
Definition: service.c:169
SERVICE_TABLE_ENTRYW ServiceTable[]
Definition: service.c:21
static VOID WINAPI SamSsServiceMain(DWORD dwArgc, PWSTR *pszArgv)
VOID WINAPI I_ScIsSecurityProcess(VOID)
Definition: sctrl.c:853
static DWORD WINAPI DispatcherThread(_In_ PVOID pParameter)
Definition: service.c:112
#define INFINITE
Definition: serial.h:102
DWORD dwThreadId
Definition: fdebug.c:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
static HANDLE hEvent
Definition: comm.c:54
#define _In_
Definition: ms_sal.h:308
HANDLE hThread
Definition: wizard.c:28
#define SYNCHRONIZE
Definition: nt_native.h:61
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
Definition: sctrl.c:1134
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: sctrl.c:742
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwControlsAccepted
Definition: winsvc.h:101
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwCurrentState
Definition: winsvc.h:100
DWORD dwCheckPoint
Definition: winsvc.h:104
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:682
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
SERVICE_STATUS_HANDLE hStatus
Definition: w32time.c:14
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WINAPI
Definition: msvc.h:6
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:963