ReactOS  0.4.15-dev-2776-g4130f0b
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 
14 typedef VOID (WINAPI *PNETLOGONMAIN)(INT ArgCount, PWSTR *ArgVector);
15 
17 
18 static VOID WINAPI NetlogonServiceMain(DWORD dwArgc, PWSTR *pszArgv);
19 static 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 
31 static
32 VOID
33 WINAPI
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 
64 static
65 VOID
66 WINAPI
68  _In_ DWORD fdwControl)
69 {
70  TRACE("SamSsControlHandler(%lu)\n", fdwControl);
71 }
72 
73 
74 static
75 VOID
76 WINAPI
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 
97  ServiceStatus.dwWaitHint = 0x7530;
98 
100 
104 
106 }
107 
108 
109 static
110 DWORD
111 WINAPI
113  _In_ PVOID pParameter)
114 {
115  HANDLE hEvent;
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");
140  dwError = WaitForSingleObject(hEvent, INFINITE);
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 
167 NTSTATUS
168 WINAPI
170 {
171  HANDLE hThread;
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 */
#define CloseHandle
Definition: compat.h:598
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwCurrentState
Definition: winsvc.h:100
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: sctrl.c:742
static VOID WINAPI SamSsServiceMain(DWORD dwArgc, PWSTR *pszArgv)
BOOL WINAPI StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
Definition: sctrl.c:1134
int32_t INT
Definition: typedefs.h:58
VOID(WINAPI * PNETLOGONMAIN)(INT ArgCount, PWSTR *ArgVector)
Definition: service.c:14
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:682
static HANDLE hEvent
Definition: comm.c:54
VOID WINAPI I_ScIsSecurityProcess(VOID)
Definition: sctrl.c:853
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
SERVICE_STATUS_HANDLE hStatus
Definition: w32time.c:14
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD dwCheckPoint
Definition: winsvc.h:104
#define FALSE
Definition: types.h:117
NTSTATUS WINAPI ServiceInit(VOID)
Definition: service.c:169
#define SERVICE_RUNNING
Definition: winsvc.h:24
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:136
#define LoadLibraryW(x)
Definition: compat.h:606
static VOID WINAPI SamSsControlHandler(_In_ DWORD fdwControl)
Definition: service.c:67
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:607
#define WAIT_OBJECT_0
Definition: winbase.h:403
DWORD dwWaitHint
Definition: winsvc.h:105
static SERVICE_STATUS ServiceStatus
Definition: browser.c:22
#define WINAPI
Definition: msvc.h:6
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:963
DWORD dwThreadId
Definition: fdebug.c:31
static const WCHAR L[]
Definition: oid.c:1250
static DWORD WINAPI DispatcherThread(_In_ PVOID pParameter)
Definition: service.c:112
#define VOID
Definition: acefi.h:82
#define SYNCHRONIZE
Definition: nt_native.h:61
#define ERR(fmt,...)
Definition: debug.h:110
#define _In_
Definition: no_sal2.h:158
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define NULL
Definition: types.h:112
HANDLE hThread
Definition: wizard.c:28
static VOID WINAPI NetlogonServiceMain(DWORD dwArgc, PWSTR *pszArgv)
#define GetProcAddress(x, y)
Definition: compat.h:612
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define INFINITE
Definition: serial.h:102
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
SERVICE_TABLE_ENTRYW ServiceTable[]
Definition: service.c:21