ReactOS 0.4.15-dev-7942-gd23573b
svchost.h File Reference
#include <ndk/rtlfuncs.h>
#include <ndk/kdtypes.h>
#include <dpfilter.h>
#include <rpc.h>
#include <svc.h>
Include dependency graph for svchost.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DOMAIN_SID_DATA
 
struct  _SID_DATA
 
struct  _SVCHOST_OPTIONS
 
struct  _SVCHOST_DLL
 
struct  _SVCHOST_SERVICE
 
struct  _SVCHOST_CALLBACK_CONTEXT
 

Macros

#define WIN32_NO_STATUS
 
#define WIN32_LEAN_AND_MEAN
 
#define NTOS_MODE_USER
 
#define SvchostDbgPrint(lev, fmt, ...)
 
#define DBG_ERR(fmt, ...)   SvchostDbgPrint(1, fmt, __VA_ARGS__)
 
#define DBG_TRACE(fmt, ...)   SvchostDbgPrint(4, fmt, __VA_ARGS__)
 
#define SVCHOST_RPC_INIT_COMPLETE   1
 
#define SVCHOST_NBT_INIT_COMPLETE   2
 
#define SVCHOST_SID_INIT_COMPLETE   4
 

Typedefs

typedef VOID(WINAPIPSVCHOST_INIT_GLOBALS) (_In_ PSVCHOST_GLOBAL_DATA Globals)
 
typedef struct _DOMAIN_SID_DATA DOMAIN_SID_DATA
 
typedef struct _SID_DATA SID_DATA
 
typedef struct _SVCHOST_OPTIONS SVCHOST_OPTIONS
 
typedef struct _SVCHOST_OPTIONSPSVCHOST_OPTIONS
 
typedef struct _SVCHOST_DLL SVCHOST_DLL
 
typedef struct _SVCHOST_DLLPSVCHOST_DLL
 
typedef struct _SVCHOST_SERVICE SVCHOST_SERVICE
 
typedef struct _SVCHOST_SERVICEPSVCHOST_SERVICE
 
typedef struct _SVCHOST_CALLBACK_CONTEXT SVCHOST_CALLBACK_CONTEXT
 
typedef struct _SVCHOST_CALLBACK_CONTEXTPSVCHOST_CALLBACK_CONTEXT
 

Functions

NTSTATUS NTAPI RpcpInitRpcServer (VOID)
 
NTSTATUS NTAPI RpcpStopRpcServer (_In_ RPC_IF_HANDLE IfSpec)
 
NTSTATUS NTAPI RpcpStopRpcServerEx (_In_ RPC_IF_HANDLE IfSpec)
 
NTSTATUS NTAPI RpcpStartRpcServer (_In_ PCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
 
VOID WINAPI SvchostBuildSharedGlobals (VOID)
 
VOID WINAPI SvchostCharLowerW (_In_ LPCWSTR lpSrcStr)
 
NTSTATUS NTAPI ScCreateWellKnownSids (VOID)
 
VOID WINAPI MemInit (_In_ HANDLE Heap)
 
BOOL WINAPI MemFree (_In_ LPVOID lpMem)
 
PVOID WINAPI MemAlloc (_In_ DWORD dwFlags, _In_ DWORD dwBytes)
 
VOID WINAPI SvcNetBiosInit (VOID)
 
VOID WINAPI SvcNetBiosClose (VOID)
 
VOID WINAPI SvcNetBiosOpen (VOID)
 
DWORD WINAPI SvcNetBiosReset (_In_ UCHAR LanaNum)
 
BOOL WINAPI InitializeSecurity (_In_ DWORD dwParam, _In_ DWORD dwAuthnLevel, _In_ DWORD dwImpLevel, _In_ DWORD dwCapabilities)
 
DWORD WINAPI RegQueryDword (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _Out_ PDWORD pdwValue)
 
DWORD WINAPI RegQueryString (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData)
 
DWORD WINAPI RegQueryStringA (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ LPCSTR *ppszData)
 
DWORD WINAPI SvcRegisterStopCallback (_Out_ PHANDLE phNewWaitObject, _In_ PCWSTR ServiceName, _In_ HANDLE hObject, _In_ PSVCHOST_STOP_CALLBACK pfnStopCallback, _In_ PVOID pContext, _In_ ULONG dwFlags)
 

Variables

PSVCHOST_GLOBAL_DATA g_pSvchostSharedGlobals
 

Macro Definition Documentation

◆ DBG_ERR

#define DBG_ERR (   fmt,
  ... 
)    SvchostDbgPrint(1, fmt, __VA_ARGS__)

Definition at line 34 of file svchost.h.

◆ DBG_TRACE

#define DBG_TRACE (   fmt,
  ... 
)    SvchostDbgPrint(4, fmt, __VA_ARGS__)

Definition at line 35 of file svchost.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 15 of file svchost.h.

◆ SVCHOST_NBT_INIT_COMPLETE

#define SVCHOST_NBT_INIT_COMPLETE   2

Definition at line 49 of file svchost.h.

◆ SVCHOST_RPC_INIT_COMPLETE

#define SVCHOST_RPC_INIT_COMPLETE   1

Definition at line 48 of file svchost.h.

◆ SVCHOST_SID_INIT_COMPLETE

#define SVCHOST_SID_INIT_COMPLETE   4

Definition at line 50 of file svchost.h.

◆ SvchostDbgPrint

#define SvchostDbgPrint (   lev,
  fmt,
  ... 
)
Value:
DPFLTR_MASK | lev, \
"[SVCHOST] %lx.%lx: " fmt, \
__VA_ARGS__);
@ DPFLTR_SVCHOST_ID
Definition: dpfilter.h:56
#define DPFLTR_MASK
Definition: kdtypes.h:34
NTSYSAPI ULONG __cdecl DbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ _Printf_format_string_ PCSTR Format,...)
Definition: dsound.c:943
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158

Definition at line 26 of file svchost.h.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 13 of file svchost.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 12 of file svchost.h.

Typedef Documentation

◆ DOMAIN_SID_DATA

◆ PSVCHOST_CALLBACK_CONTEXT

◆ PSVCHOST_DLL

◆ PSVCHOST_INIT_GLOBALS

typedef VOID(WINAPI * PSVCHOST_INIT_GLOBALS) (_In_ PSVCHOST_GLOBAL_DATA Globals)

Definition at line 40 of file svchost.h.

◆ PSVCHOST_OPTIONS

◆ PSVCHOST_SERVICE

◆ SID_DATA

◆ SVCHOST_CALLBACK_CONTEXT

◆ SVCHOST_DLL

◆ SVCHOST_OPTIONS

◆ SVCHOST_SERVICE

Function Documentation

◆ InitializeSecurity()

BOOL WINAPI InitializeSecurity ( _In_ DWORD  dwParam,
_In_ DWORD  dwAuthnLevel,
_In_ DWORD  dwImpLevel,
_In_ DWORD  dwCapabilities 
)

Definition at line 161 of file security.cxx.

167{
168 HRESULT hr;
169 PACL pAcl;
170 PSECURITY_DESCRIPTOR pSecurityDescriptor;
171 IGlobalOptions *pGlobalOptions;
172 ASSERT(dwParam != 0);
173
174 /* Create a valid SD and ACL based on the current thread's token */
175 if (DwInitializeSdFromThreadToken(&pSecurityDescriptor, &pAcl) == ERROR_SUCCESS)
176 {
177 /* It worked -- initialize COM without DDE support */
179 }
180 else
181 {
182 /* Don't keep going if we don't have an SD */
183 hr = E_FAIL;
184 }
185
186 /* Did we make it? */
187 if (SUCCEEDED(hr))
188 {
189 /* Indeed, initialize COM security now */
190 DBG_TRACE("Calling CoInitializeSecurity (dwAuthCapabilities = 0x%08x)\n",
191 dwCapabilities);
192 hr = CoInitializeSecurity(pSecurityDescriptor,
193 -1,
194 NULL,
195 NULL,
196 dwAuthnLevel,
197 dwImpLevel,
198 NULL,
199 dwCapabilities,
200 NULL);
201 if (FAILED(hr)) DBG_ERR("CoInitializeSecurity returned hr=0x%08x\n", hr);
202 }
203
204 /* Free the SD and ACL since we no longer need it */
205 MemFree(pSecurityDescriptor);
206 LocalFree(pAcl);
207
208 /* Did we initialize COM correctly? */
209 if (SUCCEEDED(hr))
210 {
211 /* Get the COM Global Options Interface */
213 NULL,
214 CLSCTX_INPROC_SERVER,
215 IID_IGlobalOptions,
216 (LPVOID*)&pGlobalOptions);
217 if (SUCCEEDED(hr))
218 {
219 /* Use it to disable COM exception handling */
220 hr = pGlobalOptions->Set(COMGLB_EXCEPTION_HANDLING,
222 pGlobalOptions->Release();
224 }
225 }
226
227 /* Return whether all COM calls were successful or not */
228 return SUCCEEDED(hr);
229}
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
const CLSID CLSID_GlobalOptions
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc, SOLE_AUTHENTICATION_SERVICE *asAuthSvc, void *pReserved1, DWORD dwAuthnLevel, DWORD dwImpLevel, void *pReserved2, DWORD dwCapabilities, void *pReserved3)
Definition: compobj.c:4122
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
HRESULT Set([in] GLOBALOPT_PROPERTIES property, [in] ULONG_PTR value)
ULONG Release()
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define ASSERT(a)
Definition: mode.c:44
@ COINIT_DISABLE_OLE1DDE
Definition: objbase.h:280
@ COMGLB_EXCEPTION_DONOT_HANDLE
Definition: objidl.idl:2430
DWORD WINAPI DwInitializeSdFromThreadToken(_Out_ PVOID *ppSecurityDescriptor, _Out_ PACL *ppAcl)
Definition: security.cxx:27
HRESULT hr
Definition: shlfolder.c:183
#define DBG_ERR(fmt,...)
Definition: svchost.h:34
#define DBG_TRACE(fmt,...)
Definition: svchost.h:35

Referenced by CallPerInstanceInitFunctions().

◆ MemAlloc()

PVOID WINAPI MemAlloc ( _In_ DWORD  dwFlags,
_In_ DWORD  dwBytes 
)

Definition at line 78 of file globals.c.

82{
83 /* Allocate memory from the heap */
84 return HeapAlloc(g_hHeap, dwFlags, dwBytes);
85}
HANDLE g_hHeap
Definition: globals.c:52
#define HeapAlloc
Definition: compat.h:733
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by SvchostBuildSharedGlobals().

◆ MemFree()

BOOL WINAPI MemFree ( _In_ LPVOID  lpMem)

Definition at line 68 of file globals.c.

71{
72 /* Free memory back into the heap */
73 return HeapFree(g_hHeap, 0, lpMem);
74}
#define HeapFree(x, y, z)
Definition: compat.h:735

◆ MemInit()

VOID WINAPI MemInit ( _In_ HANDLE  Heap)

Definition at line 58 of file globals.c.

61{
62 /* Save the heap handle */
63 g_hHeap = Heap;
64}

Referenced by wmainCRTStartup().

◆ RegQueryDword()

DWORD WINAPI RegQueryDword ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_Out_ PDWORD  pdwValue 
)

Definition at line 78 of file registry.c.

83{
84 DWORD dwError, cbData, dwType;
85 ASSERT(hKey);
86 ASSERT(pszValueName);
87 ASSERT(pdwValue);
88
89 /* Attempt to read 4 bytes */
90 cbData = sizeof(DWORD);
91 dwError = RegQueryValueExW(hKey, pszValueName, 0, &dwType, 0, &cbData);
92
93 /* If we didn't get back a DWORD... */
94 if ((dwError == ERROR_SUCCESS) && (dwType != REG_DWORD))
95 {
96 /* Zero out the output and fail */
97 *pdwValue = 0;
98 dwError = ERROR_INVALID_DATATYPE;
99 }
100
101 /* All done! */
102 return dwError;
103}
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define DWORD
Definition: nt_native.h:44
#define REG_DWORD
Definition: sdbapi.c:596
#define ERROR_INVALID_DATATYPE
Definition: winerror.h:1111

Referenced by FDebugBreakForService(), and ReadPerInstanceRegistryParameters().

◆ RegQueryString()

DWORD WINAPI RegQueryString ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_In_ DWORD  dwExpectedType,
_Out_ PBYTE ppbData 
)

Definition at line 107 of file registry.c.

113{
115 ASSERT(hKey);
116 ASSERT(pszValueName);
117
118 /* Call the helper function */
120 pszValueName,
121 dwExpectedType,
122 ppbData,
123 &dwSize);
124}
DWORD WINAPI RegQueryValueWithAlloc(_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData, _Out_ PDWORD pdwSize)
Definition: registry.c:17
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by ReadPerInstanceRegistryParameters(), and RegQueryStringA().

◆ RegQueryStringA()

DWORD WINAPI RegQueryStringA ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_In_ DWORD  dwExpectedType,
_Out_ LPCSTR ppszData 
)

Definition at line 128 of file registry.c.

134{
135 DWORD dwError;
136 LPWSTR pbLocalData;
137 DWORD cchValueName, cbMultiByte;
138 LPSTR pszData;
139 ASSERT(hKey);
140 ASSERT(pszValueName);
141 ASSERT(ppszData);
142
143 /* Assume failure */
144 *ppszData = NULL;
145
146 /* Query the string in Unicode first */
147 dwError = RegQueryString(hKey,
148 pszValueName,
149 dwExpectedType,
150 (PBYTE*)&pbLocalData);
151 if (dwError != ERROR_SUCCESS) return dwError;
152
153 /* Get the length of the Unicode string */
154 cchValueName = lstrlenW(pbLocalData);
155
156 /* See how much space it would take to convert to ANSI */
157 cbMultiByte = WideCharToMultiByte(CP_ACP,
158 0,
159 pbLocalData,
160 cchValueName + 1,
161 NULL,
162 0,
163 NULL,
164 NULL);
165 if (cbMultiByte != 0)
166 {
167 /* Allocate the space, assuming failure */
168 dwError = ERROR_OUTOFMEMORY;
169 pszData = MemAlloc(0, cbMultiByte);
170 if (pszData != NULL)
171 {
172 /* What do you know, it worked! */
173 dwError = ERROR_SUCCESS;
174
175 /* Now do the real conversion */
177 0,
178 pbLocalData,
179 cchValueName + 1,
180 pszData,
181 cbMultiByte,
182 NULL,
183 NULL) != 0)
184 {
185 /* It worked, return the data back to the caller */
186 *ppszData = pszData;
187 }
188 else
189 {
190 /* It failed, free our buffer and get the error code */
191 MemFree(pszData);
192 dwError = GetLastError();
193 }
194 }
195 }
196
197 /* Free the original Unicode string and return the error */
198 MemFree(pbLocalData);
199 return dwError;
200}
PVOID MemAlloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: utils.c:33
DWORD WINAPI RegQueryString(_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData)
Definition: registry.c:107
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define lstrlenW
Definition: compat.h:750
BYTE * PBYTE
Definition: pedump.c:66
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
char * LPSTR
Definition: xmlstorage.h:182
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by GetServiceMainFunctions().

◆ RpcpInitRpcServer()

NTSTATUS NTAPI RpcpInitRpcServer ( VOID  )

Definition at line 22 of file rpcsrv.c.

25{
26 /* Clear the reference count and initialize the critical section */
29}
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
LONG RpcpNumInstances
Definition: rpcsrv.c:15

Referenced by SvchostBuildSharedGlobals().

◆ RpcpStartRpcServer()

NTSTATUS NTAPI RpcpStartRpcServer ( _In_ PCWSTR  IfName,
_In_ RPC_IF_HANDLE  IfSpec 
)

Definition at line 131 of file rpcsrv.c.

135{
136 NTSTATUS ntStatus;
137
138 /* Acquire the lock while we instantiate a new interface */
140
141 /* Add this interface to the service */
142 ntStatus = RpcpAddInterface(IfName, IfSpec);
143 if (!ntStatus)
144 {
145 /* Increment the reference count to see if this was the first interface */
146 if (++RpcpNumInstances == 1)
147 {
148 /* It was, so put the server into listening mode now */
149 ntStatus = RpcServerListen(1, 12345, TRUE);
150 if (ntStatus == RPC_S_ALREADY_LISTENING) ntStatus = STATUS_SUCCESS;
151 }
152 }
153
154 /* Release the lock and return back the result to the caller */
156 return I_RpcMapWin32Status(ntStatus);
157}
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1520
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:740
NTSTATUS NTAPI RpcpAddInterface(_In_ PCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:83
#define STATUS_SUCCESS
Definition: shellext.h:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define RPC_S_ALREADY_LISTENING
Definition: winerror.h:1024

Referenced by SvchostBuildSharedGlobals().

◆ RpcpStopRpcServer()

NTSTATUS NTAPI RpcpStopRpcServer ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 33 of file rpcsrv.c.

36{
37 RPC_STATUS rpcStatus;
38
39 /* Unregister the interface */
40 rpcStatus = RpcServerUnregisterIf(IfSpec, NULL, TRUE);
41
42 /* Acquire the lock while we dereference the RPC services */
44 if (--RpcpNumInstances == 0)
45 {
46 /* All RPC services stopped, rundown the server */
49 }
50
51 /* Release the lock and return the unregister result */
53 return I_RpcMapWin32Status(rpcStatus);
54}
RPC_STATUS WINAPI RpcMgmtWaitServerListen(void)
Definition: rpc_server.c:1539
RPC_STATUS WINAPI RpcServerUnregisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, UINT WaitForCallsToComplete)
Definition: rpc_server.c:1202
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596
long RPC_STATUS
Definition: rpc.h:52

Referenced by SvchostBuildSharedGlobals().

◆ RpcpStopRpcServerEx()

NTSTATUS NTAPI RpcpStopRpcServerEx ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 58 of file rpcsrv.c.

61{
62 RPC_STATUS rpcStatus;
63
64 /* Unregister the interface */
65 rpcStatus = RpcServerUnregisterIfEx(IfSpec, NULL, TRUE);
66
67 /* Acquire the lock while we dereference the RPC services */
69 if (--RpcpNumInstances == 0)
70 {
71 /* All RPC services stopped, rundown the server */
74 }
75
76 /* Release the lock and return the unregister result */
78 return I_RpcMapWin32Status(rpcStatus);
79}
RPC_STATUS WINAPI RpcServerUnregisterIfEx(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, int RundownContextHandles)
Definition: rpc_server.c:1253

Referenced by SvchostBuildSharedGlobals().

◆ ScCreateWellKnownSids()

NTSTATUS NTAPI ScCreateWellKnownSids ( VOID  )

Definition at line 266 of file globals.c.

269{
270 ULONG i;
272
273 /* Loop the non-domain SIDs */
274 for (i = 0; i < RTL_NUMBER_OF(SidData); i++)
275 {
276 /* Convert our optimized structure into an actual SID */
278 &SidData[i].Authority,
279 1);
280
281 if (!NT_SUCCESS(Status))
282 {
283 DBG_ERR("ScAllocateAndInitializeSid failed for %u\n", i);
284 break;
285 }
286
287 /* Write the correct sub-authority */
289 }
290
291 /* Now loop the domain SIDs */
292 for (i = 0; i < RTL_NUMBER_OF(DomainSidData); i++)
293 {
294 /* Convert our optimized structure into an actual SID */
296 DomainSidData[i].SubAuthority,
298 if (!NT_SUCCESS(Status))
299 {
300 DBG_ERR("ScDomainIdToSid failed for %u\n", i);
301 break;
302 }
303 }
304
305 /* If we got to the end, return success */
307}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
SID_DATA SidData[12]
Definition: globals.c:22
NTSTATUS NTAPI ScAllocateAndInitializeSid(_Out_ PSID *Sid, _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, _In_ ULONG SubAuthorityCount)
Definition: globals.c:236
NTSTATUS NTAPI ScDomainIdToSid(_In_ PSID SourceSid, _In_ ULONG DomainId, _Out_ PSID *DestinationSid)
Definition: globals.c:188
PSID BuiltinDomainSid
Definition: globals.c:16
DOMAIN_SID_DATA DomainSidData[8]
Definition: globals.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1133
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
DWORD SubAuthority
Definition: svchost.h:68
uint32_t ULONG
Definition: typedefs.h:59

Referenced by SvchostBuildSharedGlobals().

◆ SvchostBuildSharedGlobals()

VOID WINAPI SvchostBuildSharedGlobals ( VOID  )

Definition at line 89 of file globals.c.

92{
94
95 /* Is RPC initialized? */
97 {
98 /* Nope, go initialize it */
99 if (!NT_SUCCESS(RpcpInitRpcServer())) return;
100
101 /* This is now done */
103 }
104
105 /* Is NetBIOS initialized? */
107 {
108 /* Nope, set it up */
110
111 /* This is now done */
113 }
114
115 /* Do we have the global SIDs initialized? */
117 {
118 /* Create the SIDs we'll export in the global structure */
119 if (!NT_SUCCESS(ScCreateWellKnownSids())) return;
120
121 /* This is now done */
123 }
124
125 /* Allocate memory for the globals */
127 sizeof(*g_pSvchostSharedGlobals));
128 if (g_pSvchostSharedGlobals == NULL) return;
129
130 /* Write the pointers to the SIDs */
149
150 /* Write the pointers to the callbacks */
158}
PSID LocalSid
Definition: globals.c:15
PSID AliasUsersSid
Definition: globals.c:17
PSID AliasSystemOpsSid
Definition: globals.c:18
PSID AuthenticatedUserSid
Definition: globals.c:17
PSVCHOST_GLOBAL_DATA g_pSvchostSharedGlobals
Definition: globals.c:50
PSID AnonymousLogonSid
Definition: globals.c:17
PSID AliasPowerUsersSid
Definition: globals.c:18
PSID WorldSid
Definition: globals.c:15
PSID AliasGuestsSid
Definition: globals.c:18
NTSTATUS NTAPI ScCreateWellKnownSids(VOID)
Definition: globals.c:266
PSID NetworkSid
Definition: globals.c:15
PSID AliasPrintOpsSid
Definition: globals.c:19
PSID NetworkServiceSid
Definition: globals.c:16
PVOID WINAPI MemAlloc(_In_ DWORD dwFlags, _In_ DWORD dwBytes)
Definition: globals.c:78
PSID AliasAccountOpsSid
Definition: globals.c:18
PSID AliasAdminsSid
Definition: globals.c:17
PSID LocalSystemSid
Definition: globals.c:16
DWORD g_SvchostInitFlag
Definition: globals.c:51
PSID AliasBackupOpsSid
Definition: globals.c:20
PSID LocalServiceSid
Definition: globals.c:16
PSID NullSid
Definition: globals.c:15
DWORD WINAPI SvcNetBiosReset(_In_ UCHAR LanaNum)
Definition: netbios.c:124
VOID WINAPI SvcNetBiosClose(VOID)
Definition: netbios.c:96
VOID WINAPI SvcNetBiosOpen(VOID)
Definition: netbios.c:112
VOID WINAPI SvcNetBiosInit(VOID)
Definition: netbios.c:84
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NTSTATUS NTAPI RpcpStopRpcServer(_In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:33
NTSTATUS NTAPI RpcpStartRpcServer(_In_ PCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:131
NTSTATUS NTAPI RpcpInitRpcServer(VOID)
Definition: rpcsrv.c:22
NTSTATUS NTAPI RpcpStopRpcServerEx(_In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:58
PNET_BIOS_OPEN NetBiosOpen
Definition: svc.h:117
PSID LocalSystemSid
Definition: svc.h:98
PSID AliasAdminsSid
Definition: svc.h:104
PSTOP_RPC_SERVER_EX StopRpcServerEx
Definition: svc.h:116
PSID AliasAccountOpsSid
Definition: svc.h:108
PSID NetworkServiceSid
Definition: svc.h:100
PNET_BIOS_RESET NetBiosReset
Definition: svc.h:119
PSID AliasUsersSid
Definition: svc.h:105
PSID AliasPrintOpsSid
Definition: svc.h:110
PSID AnonymousLogonSid
Definition: svc.h:103
PSID NetworkSid
Definition: svc.h:97
PSID BuiltinDomainSid
Definition: svc.h:101
PSID AliasGuestsSid
Definition: svc.h:106
PSID AliasPowerUsersSid
Definition: svc.h:107
PREGISTER_STOP_CALLBACK RegisterStopCallback
Definition: svc.h:123
PSID LocalServiceSid
Definition: svc.h:99
PSID AuthenticatedUserSid
Definition: svc.h:102
PSTOP_RPC_SERVER StopRpcServer
Definition: svc.h:115
PSTART_RPC_SERVER StartRpcServer
Definition: svc.h:114
PNET_BIOS_CLOSE NetBiosClose
Definition: svc.h:118
PSID AliasSystemOpsSid
Definition: svc.h:109
PSID AliasBackupOpsSid
Definition: svc.h:111
DWORD WINAPI SvcRegisterStopCallback(_Out_ PHANDLE phNewWaitObject, _In_ PCWSTR ServiceName, _In_ HANDLE hObject, _In_ PSVCHOST_STOP_CALLBACK pfnStopCallback, _In_ PVOID pContext, _In_ ULONG dwFlags)
Definition: svchost.c:518
#define SVCHOST_NBT_INIT_COMPLETE
Definition: svchost.h:49
#define SVCHOST_SID_INIT_COMPLETE
Definition: svchost.h:50
#define SVCHOST_RPC_INIT_COMPLETE
Definition: svchost.h:48

Referenced by ServiceStarter().

◆ SvchostCharLowerW()

VOID WINAPI SvchostCharLowerW ( _In_ LPCWSTR  lpSrcStr)

Definition at line 162 of file globals.c.

165{
166 DWORD cchSrc;
167
168 /* If there's nothing to do, bail out */
169 if (lpSrcStr == NULL) return;
170
171 /* Get the length of the input string */
172 cchSrc = wcslen(lpSrcStr);
173
174 /* Call the locale API to lower-case it */
177 lpSrcStr,
178 cchSrc + 1,
179 (LPWSTR)lpSrcStr,
180 cchSrc + 1) == FALSE)
181 {
182 DBG_ERR("SvchostCharLowerW failed for %ws\n", lpSrcStr);
183 }
184}
#define FALSE
Definition: types.h:117
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
Definition: lang.c:2417
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define LCMAP_LOWERCASE
Definition: winnls.h:184

Referenced by BuildCommandOptions(), and GetServiceMainFunctions().

◆ SvcNetBiosClose()

VOID WINAPI SvcNetBiosClose ( VOID  )

Definition at line 96 of file netbios.c.

99{
100 /* While holding the lock, drop a reference*/
102 if ((GlobalNetBiosUseCount != 0) && (--GlobalNetBiosUseCount == 0))
103 {
104 /* All references are gone, clear all LANA's */
106 }
108}
DWORD LanaFlags[8]
Definition: netbios.c:19
LONG GlobalNetBiosUseCount
Definition: netbios.c:18
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
#define ZeroMemory
Definition: winbase.h:1712

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosInit()

VOID WINAPI SvcNetBiosInit ( VOID  )

Definition at line 84 of file netbios.c.

87{
88 /* Initialize NetBIOS-related structures and variables */
92}
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosOpen()

VOID WINAPI SvcNetBiosOpen ( VOID  )

Definition at line 112 of file netbios.c.

115{
116 /* Increment the reference counter while holding the lock */
120}

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosReset()

DWORD WINAPI SvcNetBiosReset ( _In_ UCHAR  LanaNum)

Definition at line 124 of file netbios.c.

127{
128 DWORD dwError = ERROR_SUCCESS;
129 UCHAR nbtError;
130 NCB ncb;
131
132 /* Block all other NetBIOS operations */
134
135 /* Is this LANA enabled? */
136 if (!LanaFlagIsSet(LanaNum))
137 {
138 /* Yep, build a reset packet */
139 ZeroMemory(&ncb, sizeof(ncb));
140 ncb.ncb_lsn = 0;
141 ncb.ncb_command = NCBRESET;
142 ncb.ncb_callname[0] = 0xFE; // Max Sessions
143 ncb.ncb_callname[1] = 0;
144 ncb.ncb_callname[2] = 0xFD; // Max Names
145 ncb.ncb_callname[3] = 0;
146 ncb.ncb_lana_num = LanaNum;
147
148 /* Send it */
149 nbtError = Netbios(&ncb);
150
151 /* Convert the status to Win32 format */
152 dwError = SvcNetBiosStatusToApiStatus(nbtError);
153
154 /* Enable the LANA if the reset worked */
155 if (dwError == ERROR_SUCCESS) SetLanaFlag(LanaNum);
156 }
157
158 /* Drop the lock and return */
160 return dwError;
161}
BOOL WINAPI LanaFlagIsSet(_In_ UCHAR Lana)
Definition: netbios.c:60
DWORD WINAPI SvcNetBiosStatusToApiStatus(_In_ DWORD NetBiosError)
Definition: netbios.c:26
VOID WINAPI SetLanaFlag(_In_ UCHAR Lana)
Definition: netbios.c:72
UCHAR WINAPI Netbios(PNCB ncb)
Definition: netbios.c:785
#define NCBRESET
Definition: nb30.h:38
Definition: nb30.h:148
UCHAR ncb_lana_num
Definition: nb30.h:160
UCHAR ncb_callname[NCBNAMSZ]
Definition: nb30.h:155
UCHAR ncb_command
Definition: nb30.h:149
UCHAR ncb_lsn
Definition: nb30.h:151
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by SvchostBuildSharedGlobals().

◆ SvcRegisterStopCallback()

DWORD WINAPI SvcRegisterStopCallback ( _Out_ PHANDLE  phNewWaitObject,
_In_ PCWSTR  ServiceName,
_In_ HANDLE  hObject,
_In_ PSVCHOST_STOP_CALLBACK  pfnStopCallback,
_In_ PVOID  pContext,
_In_ ULONG  dwFlags 
)

Definition at line 518 of file svchost.c.

526{
527 ULONG i;
528 PSVCHOST_CALLBACK_CONTEXT pSvcsStopCbContext = NULL;
529 PSVCHOST_SERVICE pService = NULL;
530 DWORD dwError = ERROR_SUCCESS;
531
532 /* All parameters must be present */
533 if ((phNewWaitObject == NULL) ||
534 (ServiceName == NULL) ||
535 (hObject == NULL) ||
536 (pfnStopCallback == NULL))
537 {
538 /* Fail otherwise */
540 }
541
542 /* Don't allow new DLLs while we send notifications */
544
545 /* Scan all registered services */
546 for (i = 0; i < ServiceCount; i++)
547 {
548 /* Search for the service entry matching this service name */
549 if (lstrcmpiW(ServiceName, ServiceArray[i].pszServiceName) == 0)
550 {
551 /* Found it */
552 pService = &ServiceArray[i];
553 break;
554 }
555 }
556
557 /* Do we have a service? Does it already have a callback? */
558 if ((pService == NULL) || (pService->pfnStopCallback != NULL))
559 {
560 /* Affirmative, nothing for us to do */
561 dwError = ERROR_INVALID_DATA;
562 DBG_ERR("Service %ws missing or already registered for callback, "
563 "status %d\n",
565 dwError);
566 goto Quickie;
567 }
568
569 /* Allocate our internal context */
570 pSvcsStopCbContext = MemAlloc(HEAP_ZERO_MEMORY, sizeof(*pSvcsStopCbContext));
571 if (pSvcsStopCbContext == NULL)
572 {
573 /* We failed, bail out */
574 dwError = ERROR_NOT_ENOUGH_MEMORY;
575 DBG_ERR("MemAlloc for context block for service %ws failed, status "
576 "%d\n",
578 dwError);
579 goto Quickie;
580 }
581
582 /* Setup the context and register for the wait */
583 pSvcsStopCbContext->pContext = pContext;
584 pSvcsStopCbContext->pService = pService;
585 if (RegisterWaitForSingleObject(phNewWaitObject,
586 hObject,
588 pSvcsStopCbContext,
589 INFINITE,
590 dwFlags))
591 {
592 /* We now have an active thread associated with this wait */
593 pService->cServiceActiveThreadCount++;
594 pService->pfnStopCallback = pfnStopCallback;
595 DBG_TRACE("Registered stop callback for service %ws, active threads %d\n",
597 pService->cServiceActiveThreadCount);
598 }
599 else
600 {
601 /* Registration failed, bail out */
602 dwError = GetLastError();
603 DBG_ERR("Registration for stop callback for service %ws failed, "
604 "status %d\n",
606 dwError);
607 }
608
609Quickie:
610 /* Drop the lock, and free the context if we failed */
612 if (dwError != ERROR_SUCCESS) MemFree(pSvcsStopCbContext);
613 return dwError;
614}
static WCHAR ServiceName[]
Definition: browser.c:19
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define INFINITE
Definition: serial.h:102
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
PSVCHOST_SERVICE pService
Definition: svchost.h:119
LONG cServiceActiveThreadCount
Definition: svchost.h:108
PSVCHOST_STOP_CALLBACK pfnStopCallback
Definition: svchost.h:110
PSVCHOST_SERVICE ServiceArray
Definition: svchost.c:21
CRITICAL_SECTION ListLock
Definition: svchost.c:18
VOID WINAPI SvchostStopCallback(_In_ PVOID Context, _In_ BOOLEAN TimerOrWaitFired)
Definition: svchost.c:483
DWORD ServiceCount
Definition: svchost.c:19
BOOL WINAPI RegisterWaitForSingleObject(OUT PHANDLE phNewWaitObject, IN HANDLE hObject, IN WAITORTIMERCALLBACK Callback, IN PVOID Context, IN ULONG dwMilliseconds, IN ULONG dwFlags)
Definition: synch.c:850
#define ERROR_INVALID_DATA
Definition: winerror.h:116

Referenced by SvchostBuildSharedGlobals().

Variable Documentation

◆ g_pSvchostSharedGlobals

PSVCHOST_GLOBAL_DATA g_pSvchostSharedGlobals
extern

Definition at line 50 of file globals.c.

Referenced by ServiceStarter(), and SvchostBuildSharedGlobals().