ReactOS 0.4.15-dev-7906-g1b85a5f
globals.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Service Host
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: base/services/svchost/globals.c
5 * PURPOSE: Functions to initialize global settings and support
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "svchost.h"
12
13/* GLOBALS *******************************************************************/
14
21
23{
36};
37
39{
48};
49
53
54/* FUNCTIONS *****************************************************************/
55
56VOID
59 _In_ HANDLE Heap
60 )
61{
62 /* Save the heap handle */
63 g_hHeap = Heap;
64}
65
66BOOL
69 _In_ LPVOID lpMem
70 )
71{
72 /* Free memory back into the heap */
73 return HeapFree(g_hHeap, 0, lpMem);
74}
75
80 _In_ DWORD dwBytes
81 )
82{
83 /* Allocate memory from the heap */
84 return HeapAlloc(g_hHeap, dwFlags, dwBytes);
85}
86
87VOID
90 VOID
91 )
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}
159
160VOID
161WINAPI
163 _In_ LPCWSTR lpSrcStr
164 )
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}
185
187NTAPI
190 _In_ ULONG DomainId,
191 _Out_ PSID *DestinationSid
192 )
193{
194 ULONG sidCount, sidLength;
196
197 /* Get the length of the SID based onthe number of subauthorities */
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 */
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 */
228 }
229
230 /* Return back to the caller */
231 return status;
232}
233
235NTAPI
237 _Out_ PSID *Sid,
240 )
241{
243
244 /* Allocate room for the SID */
245 *Sid = RtlAllocateHeap(RtlGetProcessHeap(),
246 0,
248 if (*Sid)
249 {
250 /* Initialize it, we're done */
253 }
254 else
255 {
256 /* No memory, we'll fail */
258 }
259
260 /* Return what happened */
261 return Status;
262}
263
265NTAPI
267 VOID
268 )
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}
308
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
LONG NTSTATUS
Definition: precomp.h:26
HANDLE g_hHeap
Definition: globals.c:52
PSID LocalSid
Definition: globals.c:15
VOID WINAPI MemInit(_In_ HANDLE Heap)
Definition: globals.c:58
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
VOID WINAPI SvchostBuildSharedGlobals(VOID)
Definition: globals.c:89
PSID WorldSid
Definition: globals.c:15
PSID AliasGuestsSid
Definition: globals.c:18
BOOL WINAPI MemFree(_In_ LPVOID lpMem)
Definition: globals.c:68
SID_DATA SidData[12]
Definition: globals.c:22
VOID WINAPI SvchostCharLowerW(_In_ LPCWSTR lpSrcStr)
Definition: globals.c:162
NTSTATUS NTAPI ScCreateWellKnownSids(VOID)
Definition: globals.c:266
PSID NetworkSid
Definition: globals.c:15
PSID AliasPrintOpsSid
Definition: globals.c:19
NTSTATUS NTAPI ScAllocateAndInitializeSid(_Out_ PSID *Sid, _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, _In_ ULONG SubAuthorityCount)
Definition: globals.c:236
PSID InteractiveSid
Definition: globals.c:15
PSID NetworkServiceSid
Definition: globals.c:16
PVOID WINAPI MemAlloc(_In_ DWORD dwFlags, _In_ DWORD dwBytes)
Definition: globals.c:78
NTSTATUS NTAPI ScDomainIdToSid(_In_ PSID SourceSid, _In_ ULONG DomainId, _Out_ PSID *DestinationSid)
Definition: globals.c:188
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 BuiltinDomainSid
Definition: globals.c:16
PSID AliasBackupOpsSid
Definition: globals.c:20
PSID ServiceLogonSid
Definition: globals.c:15
DOMAIN_SID_DATA DomainSidData[8]
Definition: globals.c:38
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
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI BOOLEAN WINAPI RtlCopySid(DWORD, PSID, PSID)
INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
Definition: lang.c:2417
#define ASSERT(a)
Definition: mode.c:44
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54
_In_ PSID_IDENTIFIER_AUTHORITY _In_ UCHAR SubAuthorityCount
Definition: rtlfuncs.h:1515
_In_ PSID SourceSid
Definition: rtlfuncs.h:1359
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1133
_In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
Definition: rtlfuncs.h:1513
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
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
#define STATUS_SUCCESS
Definition: shellext.h:65
DWORD SubAuthority
Definition: svchost.h:68
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
Definition: ps.c:97
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
#define DBG_ERR(fmt,...)
Definition: svchost.h:34
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
#define LCMAP_LOWERCASE
Definition: winnls.h:184
#define SECURITY_ANONYMOUS_LOGON_RID
Definition: setypes.h:563
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:653
#define DOMAIN_ALIAS_RID_GUESTS
Definition: setypes.h:654
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define SECURITY_LOCAL_SID_AUTHORITY
Definition: setypes.h:530
#define SECURITY_LOCAL_RID
Definition: setypes.h:542
#define SECURITY_SERVICE_RID
Definition: setypes.h:562
#define SECURITY_INTERACTIVE_RID
Definition: setypes.h:559
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:527
#define SECURITY_WORLD_RID
Definition: setypes.h:541
#define DOMAIN_ALIAS_RID_SYSTEM_OPS
Definition: setypes.h:658
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:568
#define SECURITY_NULL_RID
Definition: setypes.h:540
#define DOMAIN_ALIAS_RID_ACCOUNT_OPS
Definition: setypes.h:657
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
#define DOMAIN_ALIAS_RID_BACKUP_OPS
Definition: setypes.h:660
#define DOMAIN_ALIAS_RID_PRINT_OPS
Definition: setypes.h:659
#define SECURITY_LOCAL_SERVICE_RID
Definition: setypes.h:575
* PSID_IDENTIFIER_AUTHORITY
Definition: setypes.h:464
#define DOMAIN_ALIAS_RID_POWER_USERS
Definition: setypes.h:655
#define SECURITY_NULL_SID_AUTHORITY
Definition: setypes.h:524
#define SECURITY_NETWORK_RID
Definition: setypes.h:557
#define SECURITY_NETWORK_SERVICE_RID
Definition: setypes.h:576
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185