ReactOS  0.4.12-dev-75-g00dd17e
svchost.h File Reference
#include <rpc.h>
#include <ndk/rtlfuncs.h>
#include <ndk/kdtypes.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  _SVCHOST_GLOBALS
 
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 DPFLTR_SVCHOST_ID   28
 
#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(CALLBACKPSVCHOST_STOP_CALLBACK) (_In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWaitFired)
 
typedef struct _SVCHOST_GLOBALS SVCHOST_GLOBALS
 
typedef struct _SVCHOST_GLOBALSPSVCHOST_GLOBALS
 
typedef VOID(WINAPIPSVCHOST_INIT_GLOBALS) (_In_ PSVCHOST_GLOBALS 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_ LPCWSTR 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 (_In_ PHANDLE phNewWaitObject, _In_ LPCWSTR ServiceName, _In_ HANDLE hObject, _In_ PSVCHOST_STOP_CALLBACK pfnStopCallback, _In_ PVOID pContext, _In_ ULONG dwFlags)
 

Variables

PSVCHOST_GLOBALS g_pSvchostSharedGlobals
 

Macro Definition Documentation

◆ DBG_ERR

◆ DBG_TRACE

◆ DPFLTR_SVCHOST_ID

#define DPFLTR_SVCHOST_ID   28

Definition at line 22 of file svchost.h.

◆ SVCHOST_NBT_INIT_COMPLETE

#define SVCHOST_NBT_INIT_COMPLETE   2

Definition at line 92 of file svchost.h.

Referenced by SvchostBuildSharedGlobals().

◆ SVCHOST_RPC_INIT_COMPLETE

#define SVCHOST_RPC_INIT_COMPLETE   1

Definition at line 91 of file svchost.h.

Referenced by SvchostBuildSharedGlobals().

◆ SVCHOST_SID_INIT_COMPLETE

#define SVCHOST_SID_INIT_COMPLETE   4

Definition at line 93 of file svchost.h.

Referenced by SvchostBuildSharedGlobals().

◆ SvchostDbgPrint

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

Definition at line 27 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_GLOBALS

◆ PSVCHOST_INIT_GLOBALS

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

Definition at line 85 of file svchost.h.

◆ PSVCHOST_OPTIONS

◆ PSVCHOST_SERVICE

◆ PSVCHOST_STOP_CALLBACK

typedef VOID(CALLBACK * PSVCHOST_STOP_CALLBACK) (_In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWaitFired)

Definition at line 43 of file svchost.h.

◆ SID_DATA

◆ SVCHOST_CALLBACK_CONTEXT

◆ SVCHOST_DLL

◆ SVCHOST_GLOBALS

◆ 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.

Referenced by CallPerInstanceInitFunctions().

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();
223  ASSERT(SUCCEEDED(hr));
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
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DBG_ERR(fmt,...)
Definition: svchost.h:35
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:4034
#define E_FAIL
Definition: ddrawi.h:102
const CLSID CLSID_GlobalOptions
ULONG Release()
smooth NULL
Definition: ftsmooth.c:416
HRESULT Set([in] GLOBALOPT_PROPERTIES property, [in] ULONG_PTR value)
LONG HRESULT
Definition: typedefs.h:77
DWORD WINAPI DwInitializeSdFromThreadToken(_Out_ PVOID *ppSecurityDescriptor, _Out_ PACL *ppAcl)
Definition: security.cxx:27
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DBG_TRACE(fmt,...)
Definition: svchost.h:36
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3237
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1938
#define SUCCEEDED(hr)
Definition: intsafe.h:57

◆ MemAlloc()

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

Definition at line 78 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

82 {
83  /* Allocate memory from the heap */
84  return HeapAlloc(g_hHeap, dwFlags, dwBytes);
85 }
HANDLE g_hHeap
Definition: globals.c:52
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175

◆ 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 }
HANDLE g_hHeap
Definition: globals.c:52
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ MemInit()

VOID WINAPI MemInit ( _In_ HANDLE  Heap)

Definition at line 58 of file globals.c.

Referenced by wmainCRTStartup().

61 {
62  /* Save the heap handle */
63  g_hHeap = Heap;
64 }
HANDLE g_hHeap
Definition: globals.c:52

◆ RegQueryDword()

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

Definition at line 78 of file registry.c.

Referenced by FDebugBreakForService(), and ReadPerInstanceRegistryParameters().

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 }
#define ERROR_INVALID_DATATYPE
Definition: winerror.h:1111
static DWORD
Definition: registry.c:44
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LONG WINAPI RegQueryValueExW(IN HKEY hKey, IN LPCWSTR lpValueName, IN PULONG lpReserved, OUT PULONG lpType OPTIONAL, OUT PUCHAR lpData OPTIONAL, IN OUT PULONG lpcbData OPTIONAL)
Definition: registry.c:862
#define REG_DWORD
Definition: sdbapi.c:539

◆ RegQueryString()

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

Definition at line 107 of file registry.c.

Referenced by ReadPerInstanceRegistryParameters(), and RegQueryStringA().

113 {
114  DWORD dwSize;
115  ASSERT(hKey);
116  ASSERT(pszValueName);
117 
118  /* Call the helper function */
119  return RegQueryValueWithAlloc(hKey,
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
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

◆ RegQueryStringA()

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

Definition at line 128 of file registry.c.

Referenced by GetServiceMainFunctions().

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 }
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
char * LPSTR
Definition: xmlstorage.h:182
#define lstrlenW
Definition: compat.h:407
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI RegQueryString(_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData)
Definition: registry.c:107
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BYTE * PBYTE
Definition: pedump.c:66
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ RpcpInitRpcServer()

NTSTATUS NTAPI RpcpInitRpcServer ( VOID  )

Definition at line 22 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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

◆ RpcpStartRpcServer()

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

Definition at line 131 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI RpcpAddInterface(_In_ LPCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:83
LONG NTSTATUS
Definition: precomp.h:26
LONG RpcpNumInstances
Definition: rpcsrv.c:15
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1527
#define RPC_S_ALREADY_LISTENING
Definition: winerror.h:1024
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
return STATUS_SUCCESS
Definition: btrfs.c:2710
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

◆ RpcpStopRpcServer()

NTSTATUS NTAPI RpcpStopRpcServer ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 33 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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 }
#define TRUE
Definition: types.h:120
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1599
LONG RpcpNumInstances
Definition: rpcsrv.c:15
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
RPC_STATUS WINAPI RpcServerUnregisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, UINT WaitForCallsToComplete)
Definition: rpc_server.c:1209
long RPC_STATUS
Definition: rpc.h:52
smooth NULL
Definition: ftsmooth.c:416
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
RPC_STATUS WINAPI RpcMgmtWaitServerListen(void)
Definition: rpc_server.c:1546
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

◆ RpcpStopRpcServerEx()

NTSTATUS NTAPI RpcpStopRpcServerEx ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 58 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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 }
#define TRUE
Definition: types.h:120
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1599
LONG RpcpNumInstances
Definition: rpcsrv.c:15
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
long RPC_STATUS
Definition: rpc.h:52
RPC_STATUS WINAPI RpcServerUnregisterIfEx(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, int RundownContextHandles)
Definition: rpc_server.c:1260
smooth NULL
Definition: ftsmooth.c:416
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
RPC_STATUS WINAPI RpcMgmtWaitServerListen(void)
Definition: rpc_server.c:1546
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

◆ ScCreateWellKnownSids()

NTSTATUS NTAPI ScCreateWellKnownSids ( VOID  )

Definition at line 266 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

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  if (!NT_SUCCESS(Status)) break;
281 
282  /* Write the correct sub-authority */
284  }
285 
286  /* Now loop the domain SIDs */
287  for (i = 0; i < RTL_NUMBER_OF(DomainSidData); i++)
288  {
289  /* Convert our optimized structure into an actual SID */
291  DomainSidData[i].SubAuthority,
292  &DomainSidData[i].Sid);
293  if (!NT_SUCCESS(Status)) break;
294  }
295 
296  /* If we got to the end, return success */
298 }
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
DOMAIN_SID_DATA DomainSidData[8]
Definition: globals.c:38
DWORD SubAuthority
Definition: svchost.h:111
PSID BuiltinDomainSid
Definition: globals.c:16
GLenum GLclampf GLint i
Definition: glfuncs.h:14
SID_DATA SidData[12]
Definition: globals.c:22
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1104
NTSTATUS NTAPI ScAllocateAndInitializeSid(_Out_ PVOID *Sid, _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, _In_ ULONG SubAuthorityCount)
Definition: globals.c:236
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI ScDomainIdToSid(_In_ PSID SourceSid, _In_ ULONG DomainId, _Out_ PSID *DestinationSid)
Definition: globals.c:188
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2710

◆ SvchostBuildSharedGlobals()

VOID WINAPI SvchostBuildSharedGlobals ( VOID  )

Definition at line 89 of file globals.c.

Referenced by ServiceStarter().

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 */
109  SvcNetBiosInit();
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 }
NTSTATUS NTAPI RpcpStartRpcServer(_In_ LPCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:131
PSVCHOST_GLOBALS g_pSvchostSharedGlobals
Definition: globals.c:50
PSID AliasUsersSid
Definition: globals.c:17
PVOID AnonymousLogonSid
Definition: svchost.h:63
PVOID LocalServiceSid
Definition: svchost.h:59
PSID AnonymousLogonSid
Definition: globals.c:17
PSID AliasGuestsSid
Definition: globals.c:18
#define SVCHOST_SID_INIT_COMPLETE
Definition: svchost.h:93
PVOID AliasAdminsSid
Definition: svchost.h:64
PSID AliasSystemOpsSid
Definition: globals.c:18
PVOID AliasPrintOpsSid
Definition: svchost.h:70
PVOID AuthenticatedUserSid
Definition: svchost.h:62
PVOID AliasPowerUsersSid
Definition: svchost.h:67
NTSTATUS NTAPI RpcpInitRpcServer(VOID)
Definition: rpcsrv.c:22
PSID BuiltinDomainSid
Definition: globals.c:16
PSID LocalSid
Definition: globals.c:15
PVOID RpcpStopRpcServerEx
Definition: svchost.h:74
PVOID SvcNetBiosClose
Definition: svchost.h:76
DWORD g_SvchostInitFlag
Definition: globals.c:51
PVOID RpcpStartRpcServer
Definition: svchost.h:72
PVOID NetworkServiceSid
Definition: svchost.h:60
PVOID NetworkSid
Definition: svchost.h:57
#define SVCHOST_NBT_INIT_COMPLETE
Definition: svchost.h:92
smooth NULL
Definition: ftsmooth.c:416
PVOID SvcNetBiosOpen
Definition: svchost.h:75
PSID AliasAdminsSid
Definition: globals.c:17
PVOID NullSid
Definition: svchost.h:54
VOID WINAPI SvcNetBiosInit(VOID)
Definition: netbios.c:84
VOID WINAPI SvcNetBiosClose(VOID)
Definition: netbios.c:96
DWORD WINAPI SvcRegisterStopCallback(_In_ PHANDLE phNewWaitObject, _In_ LPCWSTR ServiceName, _In_ HANDLE hObject, _In_ PSVCHOST_STOP_CALLBACK pfnStopCallback, _In_ PVOID pContext, _In_ ULONG dwFlags)
Definition: svchost.c:518
PVOID SvcRegisterStopCallback
Definition: svchost.h:78
PSID NetworkSid
Definition: globals.c:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
PSID LocalSystemSid
Definition: globals.c:16
PVOID LocalSystemSid
Definition: svchost.h:58
PSID AuthenticatedUserSid
Definition: globals.c:17
PVOID AliasSystemOpsSid
Definition: svchost.h:69
PSID LocalServiceSid
Definition: globals.c:16
PSID NullSid
Definition: globals.c:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI RpcpStopRpcServerEx(_In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:58
PSID AliasPrintOpsSid
Definition: globals.c:19
PSID WorldSid
Definition: globals.c:15
PVOID SvcNetBiosReset
Definition: svchost.h:77
PVOID RpcpStopRpcServer
Definition: svchost.h:73
PVOID AliasGuestsSid
Definition: svchost.h:66
PVOID AliasUsersSid
Definition: svchost.h:65
NTSTATUS NTAPI RpcpStopRpcServer(_In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:33
PSID NetworkServiceSid
Definition: globals.c:16
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
NTSTATUS NTAPI ScCreateWellKnownSids(VOID)
Definition: globals.c:266
PSID AliasPowerUsersSid
Definition: globals.c:18
DWORD WINAPI SvcNetBiosReset(_In_ UCHAR LanaNum)
Definition: netbios.c:124
PVOID LocalSid
Definition: svchost.h:56
PSID AliasBackupOpsSid
Definition: globals.c:20
PVOID WorldSid
Definition: svchost.h:55
PVOID AliasBackupOpsSid
Definition: svchost.h:71
PVOID BuiltinDomainSid
Definition: svchost.h:61
PVOID WINAPI MemAlloc(_In_ DWORD dwFlags, _In_ DWORD dwBytes)
Definition: globals.c:78
PVOID AliasAccountOpsSid
Definition: svchost.h:68
VOID WINAPI SvcNetBiosOpen(VOID)
Definition: netbios.c:112
#define SVCHOST_RPC_INIT_COMPLETE
Definition: svchost.h:91
PSID AliasAccountOpsSid
Definition: globals.c:18

◆ SvchostCharLowerW()

VOID WINAPI SvchostCharLowerW ( _In_ LPCWSTR  lpSrcStr)

Definition at line 162 of file globals.c.

Referenced by BuildCommandOptions(), and GetServiceMainFunctions().

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 DBG_ERR(fmt,...)
Definition: svchost.h:35
INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
Definition: lang.c:1645
#define LCMAP_LOWERCASE
Definition: winnls.h:181
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

◆ SvcNetBiosClose()

VOID WINAPI SvcNetBiosClose ( VOID  )

Definition at line 96 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

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 */
105  ZeroMemory(LanaFlags, sizeof(LanaFlags));
106  }
108 }
DWORD LanaFlags[8]
Definition: netbios.c:19
#define ZeroMemory
Definition: winbase.h:1635
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LONG GlobalNetBiosUseCount
Definition: netbios.c:18
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ SvcNetBiosInit()

VOID WINAPI SvcNetBiosInit ( VOID  )

Definition at line 84 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

87 {
88  /* Initialize NetBIOS-related structures and variables */
91  ZeroMemory(LanaFlags, sizeof(LanaFlags));
92 }
DWORD LanaFlags[8]
Definition: netbios.c:19
#define ZeroMemory
Definition: winbase.h:1635
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
LONG GlobalNetBiosUseCount
Definition: netbios.c:18

◆ SvcNetBiosOpen()

VOID WINAPI SvcNetBiosOpen ( VOID  )

Definition at line 112 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

115 {
116  /* Increment the reference counter while holding the lock */
120 }
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LONG GlobalNetBiosUseCount
Definition: netbios.c:18
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ SvcNetBiosReset()

DWORD WINAPI SvcNetBiosReset ( _In_ UCHAR  LanaNum)

Definition at line 124 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
UCHAR WINAPI Netbios(PNCB ncb)
Definition: netbios.c:785
UCHAR ncb_callname[NCBNAMSZ]
Definition: nb30.h:155
Definition: nb30.h:148
#define ZeroMemory
Definition: winbase.h:1635
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
VOID WINAPI SetLanaFlag(_In_ UCHAR Lana)
Definition: netbios.c:72
#define NCBRESET
Definition: nb30.h:38
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOL WINAPI LanaFlagIsSet(_In_ UCHAR Lana)
Definition: netbios.c:60
UCHAR ncb_lana_num
Definition: nb30.h:160
DWORD WINAPI SvcNetBiosStatusToApiStatus(_In_ DWORD NetBiosError)
Definition: netbios.c:26
UCHAR ncb_lsn
Definition: nb30.h:151
UCHAR ncb_command
Definition: nb30.h:149
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ SvcRegisterStopCallback()

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

Definition at line 518 of file svchost.c.

Referenced by SvchostBuildSharedGlobals().

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",
564  ServiceName,
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",
577  ServiceName,
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",
596  ServiceName,
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",
605  ServiceName,
606  dwError);
607  }
608 
609 Quickie:
610  /* Drop the lock, and free the context if we failed */
612  if (dwError != ERROR_SUCCESS) MemFree(pSvcsStopCbContext);
613  return dwError;
614 }
LONG cServiceActiveThreadCount
Definition: svchost.h:151
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DBG_ERR(fmt,...)
Definition: svchost.h:35
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
PSVCHOST_SERVICE pService
Definition: svchost.h:162
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
PSVCHOST_STOP_CALLBACK pfnStopCallback
Definition: svchost.h:153
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
GLenum GLclampf GLint i
Definition: glfuncs.h:14
CRITICAL_SECTION ListLock
Definition: svchost.c:18
smooth NULL
Definition: ftsmooth.c:416
DWORD ServiceCount
Definition: svchost.c:19
LPTSTR ServiceName
Definition: ServiceMain.c:15
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID WINAPI SvchostStopCallback(_In_ PVOID Context, _In_ BOOLEAN TimerOrWaitFired)
Definition: svchost.c:483
#define DBG_TRACE(fmt,...)
Definition: svchost.h:36
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
PSVCHOST_SERVICE ServiceArray
Definition: svchost.c:21
#define ERROR_INVALID_DATA
Definition: winerror.h:116
BOOL WINAPI RegisterWaitForSingleObject(OUT PHANDLE phNewWaitObject, IN HANDLE hObject, IN WAITORTIMERCALLBACK Callback, IN PVOID Context, IN ULONG dwMilliseconds, IN ULONG dwFlags)
Definition: synch.c:796
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define INFINITE
Definition: serial.h:102

Variable Documentation

◆ g_pSvchostSharedGlobals

PSVCHOST_GLOBALS g_pSvchostSharedGlobals

Definition at line 50 of file globals.c.

Referenced by ServiceStarter().