ReactOS  0.4.12-dev-57-g7050ac4
globals.c File Reference
#include "svchost.h"
Include dependency graph for globals.c:

Go to the source code of this file.

Functions

VOID WINAPI MemInit (_In_ HANDLE Heap)
 
BOOL WINAPI MemFree (_In_ LPVOID lpMem)
 
PVOID WINAPI MemAlloc (_In_ DWORD dwFlags, _In_ DWORD dwBytes)
 
VOID WINAPI SvchostBuildSharedGlobals (VOID)
 
VOID WINAPI SvchostCharLowerW (_In_ LPCWSTR lpSrcStr)
 
NTSTATUS NTAPI ScDomainIdToSid (_In_ PSID SourceSid, _In_ ULONG DomainId, _Out_ PSID *DestinationSid)
 
NTSTATUS NTAPI ScAllocateAndInitializeSid (_Out_ PVOID *Sid, _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, _In_ ULONG SubAuthorityCount)
 
NTSTATUS NTAPI ScCreateWellKnownSids (VOID)
 

Variables

PSID NullSid
 
PSID WorldSid
 
PSID LocalSid
 
PSID NetworkSid
 
PSID InteractiveSid
 
PSID ServiceLogonSid
 
PSID LocalSystemSid
 
PSID LocalServiceSid
 
PSID NetworkServiceSid
 
PSID BuiltinDomainSid
 
PSID AuthenticatedUserSid
 
PSID AnonymousLogonSid
 
PSID AliasAdminsSid
 
PSID AliasUsersSid
 
PSID AliasGuestsSid
 
PSID AliasPowerUsersSid
 
PSID AliasAccountOpsSid
 
PSID AliasSystemOpsSid
 
PSID AliasPrintOpsSid
 
PSID AliasBackupOpsSid
 
SID_DATA SidData [12]
 
DOMAIN_SID_DATA DomainSidData [8]
 
PSVCHOST_GLOBALS g_pSvchostSharedGlobals
 
DWORD g_SvchostInitFlag
 
HANDLE g_hHeap
 

Function Documentation

◆ 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

◆ ScAllocateAndInitializeSid()

NTSTATUS NTAPI ScAllocateAndInitializeSid ( _Out_ PVOID Sid,
_In_ PSID_IDENTIFIER_AUTHORITY  IdentifierAuthority,
_In_ ULONG  SubAuthorityCount 
)

Definition at line 236 of file globals.c.

Referenced by ScCreateWellKnownSids().

241 {
243 
244  /* Allocate room for the SID */
245  *Sid = RtlAllocateHeap(RtlGetProcessHeap(),
246  0,
248  if (*Sid)
249  {
250  /* Initialize it, we're done */
252  Status = STATUS_SUCCESS;
253  }
254  else
255  {
256  /* No memory, we'll fail */
257  Status = STATUS_NO_MEMORY;
258  }
259 
260  /* Return what happened */
261  return Status;
262 }
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1104
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
_In_ PSID_IDENTIFIER_AUTHORITY _In_ UCHAR SubAuthorityCount
Definition: rtlfuncs.h:1487
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
Definition: rtlfuncs.h:1487
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54

◆ 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

◆ ScDomainIdToSid()

NTSTATUS NTAPI ScDomainIdToSid ( _In_ PSID  SourceSid,
_In_ ULONG  DomainId,
_Out_ PSID DestinationSid 
)

Definition at line 188 of file globals.c.

Referenced by ScCreateWellKnownSids().

193 {
194  ULONG sidCount, sidLength;
196 
197  /* Get the length of the SID based onthe number of subauthorities */
198  sidCount = *RtlSubAuthorityCountSid(SourceSid);
199  sidLength = RtlLengthRequiredSid(sidCount + 1);
200 
201  /* Allocate it */
202  *DestinationSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, sidLength);
203  if (*DestinationSid)
204  {
205  /* Make a copy of it */
206  status = RtlCopySid(sidLength, *DestinationSid, SourceSid);
207  if (NT_SUCCESS(status))
208  {
209  /* Increase the subauthority count */
210  ++*RtlSubAuthorityCountSid(*DestinationSid);
211 
212  /* And add the specific domain RID we're creating */
213  *RtlSubAuthoritySid(*DestinationSid, sidCount) = DomainId;
214 
215  /* Everything worked */
216  status = STATUS_SUCCESS;
217  }
218  else
219  {
220  /* The SID copy failed, so free the SID we just allocated */
221  RtlFreeHeap(RtlGetProcessHeap(), 0, *DestinationSid);
222  }
223  }
224  else
225  {
226  /* No space for the SID, bail out */
227  status = STATUS_NO_MEMORY;
228  }
229 
230  /* Return back to the caller */
231  return status;
232 }
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
_In_ PSID SourceSid
Definition: rtlfuncs.h:1333
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI BOOLEAN WINAPI RtlCopySid(DWORD, PSID, PSID)
return STATUS_SUCCESS
Definition: btrfs.c:2710
static SERVICE_STATUS status
Definition: service.c:31
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54

◆ 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

Variable Documentation

◆ AliasAccountOpsSid

PSID AliasAccountOpsSid

Definition at line 18 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasAdminsSid

PSID AliasAdminsSid

Definition at line 17 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasBackupOpsSid

PSID AliasBackupOpsSid

Definition at line 20 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasGuestsSid

PSID AliasGuestsSid

Definition at line 18 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasPowerUsersSid

PSID AliasPowerUsersSid

Definition at line 18 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasPrintOpsSid

PSID AliasPrintOpsSid

Definition at line 19 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasSystemOpsSid

PSID AliasSystemOpsSid

Definition at line 18 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AliasUsersSid

PSID AliasUsersSid

Definition at line 17 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AnonymousLogonSid

PSID AnonymousLogonSid

Definition at line 17 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ AuthenticatedUserSid

PSID AuthenticatedUserSid

Definition at line 17 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ BuiltinDomainSid

◆ DomainSidData

DOMAIN_SID_DATA DomainSidData[8]
Initial value:
=
{
}
PSID AliasUsersSid
Definition: globals.c:17
#define DOMAIN_ALIAS_RID_GUESTS
Definition: setypes.h:626
PSID AliasGuestsSid
Definition: globals.c:18
#define DOMAIN_ALIAS_RID_ACCOUNT_OPS
Definition: setypes.h:629
PSID AliasSystemOpsSid
Definition: globals.c:18
#define DOMAIN_ALIAS_RID_POWER_USERS
Definition: setypes.h:627
PSID AliasAdminsSid
Definition: globals.c:17
#define DOMAIN_ALIAS_RID_BACKUP_OPS
Definition: setypes.h:632
#define DOMAIN_ALIAS_RID_SYSTEM_OPS
Definition: setypes.h:630
PSID AliasPrintOpsSid
Definition: globals.c:19
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:625
PSID AliasPowerUsersSid
Definition: globals.c:18
#define DOMAIN_ALIAS_RID_PRINT_OPS
Definition: setypes.h:631
PSID AliasBackupOpsSid
Definition: globals.c:20
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624
PSID AliasAccountOpsSid
Definition: globals.c:18

Definition at line 38 of file globals.c.

◆ g_hHeap

HANDLE g_hHeap

Definition at line 52 of file globals.c.

◆ g_pSvchostSharedGlobals

PSVCHOST_GLOBALS g_pSvchostSharedGlobals

Definition at line 50 of file globals.c.

Referenced by ServiceStarter().

◆ g_SvchostInitFlag

DWORD g_SvchostInitFlag

Definition at line 51 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ InteractiveSid

PSID InteractiveSid

Definition at line 15 of file globals.c.

◆ LocalServiceSid

PSID LocalServiceSid

Definition at line 16 of file globals.c.

Referenced by LsapCreatePolicySd(), and SvchostBuildSharedGlobals().

◆ LocalSid

PSID LocalSid

Definition at line 15 of file globals.c.

Referenced by LogonUserExW(), MyLogonUser(), and SvchostBuildSharedGlobals().

◆ LocalSystemSid

◆ NetworkServiceSid

PSID NetworkServiceSid

Definition at line 16 of file globals.c.

Referenced by LsapCreatePolicySd(), and SvchostBuildSharedGlobals().

◆ NetworkSid

PSID NetworkSid

Definition at line 15 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ NullSid

PSID NullSid

Definition at line 15 of file globals.c.

Referenced by SvchostBuildSharedGlobals().

◆ ServiceLogonSid

PSID ServiceLogonSid

Definition at line 15 of file globals.c.

◆ SidData

SID_DATA SidData[12]
Initial value:
=
{
}
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:540
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
PSID AnonymousLogonSid
Definition: globals.c:17
#define SECURITY_NETWORK_RID
Definition: setypes.h:529
#define SECURITY_INTERACTIVE_RID
Definition: setypes.h:531
#define SECURITY_NULL_SID_AUTHORITY
Definition: setypes.h:496
PSID BuiltinDomainSid
Definition: globals.c:16
PSID LocalSid
Definition: globals.c:15
#define SECURITY_LOCAL_SID_AUTHORITY
Definition: setypes.h:502
#define SECURITY_LOCAL_SERVICE_RID
Definition: setypes.h:547
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:526
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
PSID NetworkSid
Definition: globals.c:15
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:499
PSID LocalSystemSid
Definition: globals.c:16
#define SECURITY_LOCAL_RID
Definition: setypes.h:514
PSID AuthenticatedUserSid
Definition: globals.c:17
#define SECURITY_WORLD_RID
Definition: setypes.h:513
#define SECURITY_ANONYMOUS_LOGON_RID
Definition: setypes.h:535
PSID LocalServiceSid
Definition: globals.c:16
PSID NullSid
Definition: globals.c:15
#define SECURITY_NULL_RID
Definition: setypes.h:512
PSID WorldSid
Definition: globals.c:15
#define SECURITY_NETWORK_SERVICE_RID
Definition: setypes.h:548
PSID InteractiveSid
Definition: globals.c:15
PSID NetworkServiceSid
Definition: globals.c:16
#define SECURITY_SERVICE_RID
Definition: setypes.h:534
PSID ServiceLogonSid
Definition: globals.c:15

Definition at line 22 of file globals.c.

◆ WorldSid