ReactOS 0.4.15-dev-5666-gc548b97
init.c File Reference
#include "basesrv.h"
#include "vdm.h"
#include <winreg.h>
#include <debug.h>
#include "api.h"
Include dependency graph for init.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI BaseSrvInitializeIniFileMappings (IN PBASE_STATIC_SERVER_DATA StaticServerData)
 
NTSTATUS NTAPI CreateBaseAcls (OUT PACL *Dacl, OUT PACL *RestrictedDacl)
 
VOID NTAPI BaseInitializeStaticServerData (IN PCSR_SERVER_DLL LoadedServerDll)
 
NTSTATUS NTAPI BaseClientConnectRoutine (IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
 
VOID NTAPI BaseClientDisconnectRoutine (IN PCSR_PROCESS CsrProcess)
 
 CSR_SERVER_DLL_INIT (ServerDllInitialization)
 
BOOL NTAPI DllMain (IN HINSTANCE hInstanceDll, IN DWORD dwReason, IN LPVOID lpReserved)
 

Variables

HANDLE BaseSrvDllInstance = NULL
 
UNICODE_STRING BaseSrvKernel32DllPath
 
HANDLE BaseSrvHeap = NULL
 
HANDLE BaseSrvSharedHeap = NULL
 
PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL
 
ULONG SessionId = 0
 
ULONG ProtectionMode = 0
 
PINIFILE_MAPPING BaseSrvIniFileMapping
 
PCSR_API_ROUTINE BaseServerApiDispatchTable [BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]
 
BOOLEAN BaseServerApiServerValidTable [BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 18 of file init.c.

Function Documentation

◆ BaseClientConnectRoutine()

NTSTATUS NTAPI BaseClientConnectRoutine ( IN PCSR_PROCESS  CsrProcess,
IN OUT PVOID  ConnectionInfo,
IN OUT PULONG  ConnectionInfoLength 
)

Definition at line 659 of file init.c.

662{
663 PBASESRV_API_CONNECTINFO ConnectInfo = (PBASESRV_API_CONNECTINFO)ConnectionInfo;
664
665 if ( ConnectionInfo == NULL ||
666 ConnectionInfoLength == NULL ||
667 *ConnectionInfoLength != sizeof(*ConnectInfo) )
668 {
669 DPRINT1("BASESRV: Connection failed - ConnectionInfo = 0x%p ; ConnectionInfoLength = 0x%p (%lu), expected %lu\n",
670 ConnectionInfo,
671 ConnectionInfoLength,
672 ConnectionInfoLength ? *ConnectionInfoLength : (ULONG)-1,
673 sizeof(*ConnectInfo));
674
676 }
677
678 /* Do the NLS connection */
679 return BaseSrvNlsConnect(CsrProcess, ConnectionInfo, ConnectionInfoLength);
680}
#define DPRINT1
Definition: precomp.h:8
struct _BASESRV_API_CONNECTINFO * PBASESRV_API_CONNECTINFO
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI BaseSrvNlsConnect(IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
Definition: nls.c:140
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PKPROCESS CsrProcess
Definition: videoprt.c:39

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseClientDisconnectRoutine()

VOID NTAPI BaseClientDisconnectRoutine ( IN PCSR_PROCESS  CsrProcess)

Definition at line 684 of file init.c.

685{
686 /* Cleanup VDM resources */
688}
VOID BaseSrvCleanupVDMResources(IN PCSR_PROCESS CsrProcess)
Definition: vdm.c:297

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseInitializeStaticServerData()

VOID NTAPI BaseInitializeStaticServerData ( IN PCSR_SERVER_DLL  LoadedServerDll)

Definition at line 359 of file init.c.

360{
363 WCHAR BnoBuffer[100];
365 PWCHAR HeapBuffer;
366 UNICODE_STRING SystemRootString;
367 UNICODE_STRING UnexpandedSystemRootString = RTL_CONSTANT_STRING(L"%SystemRoot%");
368 UNICODE_STRING BaseSrvCSDString;
369 UNICODE_STRING BaseSrvWindowsDirectory;
370 UNICODE_STRING BaseSrvWindowsSystemDirectory;
371 UNICODE_STRING BnoString;
373 HANDLE BaseSrvNamedObjectDirectory;
374 HANDLE BaseSrvRestrictedObjectDirectory;
375 PACL BnoDacl, BnoRestrictedDacl;
377 HANDLE SymHandle;
378 UNICODE_STRING DirectoryName, SymlinkName;
379 ULONG LuidEnabled;
380 RTL_QUERY_REGISTRY_TABLE BaseServerRegistryConfigurationTable[2] =
381 {
382 {
383 NULL,
385 L"CSDVersion",
386 &BaseSrvCSDString,
387 REG_NONE, NULL, 0
388 },
389
390 {0}
391 };
392
393 /* Initialize the memory */
394 BaseSrvHeap = RtlGetProcessHeap(); // Initialize our own heap.
395 BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
396
397 /* Get the session ID */
398 SessionId = NtCurrentPeb()->SessionId;
399
400 /* Get the Windows directory */
401 RtlInitEmptyUnicodeString(&SystemRootString, Buffer, sizeof(Buffer));
403 &UnexpandedSystemRootString,
404 &SystemRootString,
405 NULL);
407
408 /* Create the base directory */
409 Buffer[SystemRootString.Length / sizeof(WCHAR)] = UNICODE_NULL;
410 Success = RtlCreateUnicodeString(&BaseSrvWindowsDirectory,
411 SystemRootString.Buffer);
413
414 /* Create the system directory */
415 wcscat(SystemRootString.Buffer, L"\\System32");
416 Success = RtlCreateUnicodeString(&BaseSrvWindowsSystemDirectory,
417 SystemRootString.Buffer);
419
420 /* Create the kernel32 path */
421 wcscat(SystemRootString.Buffer, L"\\kernel32.dll");
423 SystemRootString.Buffer);
425
426 if (SessionId != 0)
427 {
428 swprintf(BnoBuffer, L"\\Sessions\\%ld\\BaseNamedObjects", SessionId);
429 }
430 else
431 {
432 wcscpy(BnoBuffer, L"\\BaseNamedObjects");
433 }
434 RtlInitUnicodeString(&BnoString, BnoBuffer);
435
436 /* Allocate the server data */
441
442 /* Process timezone information */
448 NULL);
450
451 /* Make a shared heap copy of the Windows directory */
452 BaseStaticServerData->WindowsDirectory = BaseSrvWindowsDirectory;
454 0,
455 BaseSrvWindowsDirectory.MaximumLength);
456 ASSERT(HeapBuffer);
457 RtlCopyMemory(HeapBuffer,
459 BaseSrvWindowsDirectory.MaximumLength);
461
462 /* Make a shared heap copy of the System directory */
463 BaseStaticServerData->WindowsSystemDirectory = BaseSrvWindowsSystemDirectory;
465 0,
466 BaseSrvWindowsSystemDirectory.MaximumLength);
467 ASSERT(HeapBuffer);
468 RtlCopyMemory(HeapBuffer,
470 BaseSrvWindowsSystemDirectory.MaximumLength);
472
473 /* This string is not used */
474 RtlInitEmptyUnicodeString(&BaseStaticServerData->WindowsSys32x86Directory,
475 NULL,
476 0);
477
478 /* Make a shared heap copy of the BNO directory */
481 sizeof(UNICODE_NULL);
483 0,
485 ASSERT(HeapBuffer);
486 RtlCopyMemory(HeapBuffer,
490
491 /*
492 * Confirmed that in Windows, CSDNumber and RCNumber are actually Length
493 * and MaximumLength of the CSD String, since the same UNICODE_STRING is
494 * being queried twice, the first time as a ULONG!
495 *
496 * Somehow, in Windows this doesn't cause a buffer overflow, but it might
497 * in ReactOS, so this code is disabled until someone figures out WTF.
498 */
501
502 /* Initialize the CSD string and query its value from the registry */
503 RtlInitEmptyUnicodeString(&BaseSrvCSDString, Buffer, sizeof(Buffer));
505 L"",
506 BaseServerRegistryConfigurationTable,
507 NULL,
508 NULL);
509 if (NT_SUCCESS(Status))
510 {
511 /* Copy into the shared buffer */
513 BaseSrvCSDString.Buffer,
514 BaseSrvCSDString.Length / sizeof(WCHAR));
515 }
516 else
517 {
518 /* Indicate nothing is there */
519 BaseSrvCSDString.Length = 0;
520 }
521 /* NULL-terminate */
522 BaseStaticServerData->CSDVersion[BaseSrvCSDString.Length / sizeof(WCHAR)] = UNICODE_NULL;
523
524 /* Cache the system information */
528 NULL);
530
531 /* Setup the ini file mappings */
534
535 /* FIXME: Should query the registry for these */
538
539 /* Allocate a security descriptor and create it */
540 BnoSd = RtlAllocateHeap(BaseSrvHeap, 0, 1024);
541 ASSERT(BnoSd);
544
545 /* Create the BNO and \Restricted DACLs */
546 Status = CreateBaseAcls(&BnoDacl, &BnoRestrictedDacl);
548
549 /* Set the BNO DACL as active for now */
550 Status = RtlSetDaclSecurityDescriptor(BnoSd, TRUE, BnoDacl, FALSE);
552
553 /* Create the BNO directory */
555 &BnoString,
557 NULL,
558 BnoSd);
559 Status = NtCreateDirectoryObject(&BaseSrvNamedObjectDirectory,
563
564 /* Check if we are session 0 */
565 if (SessionId == 0)
566 {
567 /* Mark this as a session 0 directory */
568 Status = NtSetInformationObject(BaseSrvNamedObjectDirectory,
569 ObjectSessionInformation,
570 NULL,
571 0);
573 }
574
575 /* Check if LUID device maps are enabled */
578 &LuidEnabled,
579 sizeof(LuidEnabled),
580 NULL);
583
584 /* Initialize Global */
587 {
588 /* Make Global point back to BNO */
589 RtlInitUnicodeString(&DirectoryName, L"Global");
590 RtlInitUnicodeString(&SymlinkName, L"\\BaseNamedObjects");
592 &DirectoryName,
594 BaseSrvNamedObjectDirectory,
595 BnoSd);
599 &SymlinkName);
600 if ((NT_SUCCESS(Status)) && SessionId == 0) NtClose(SymHandle);
601
602 /* Make local point back to \Sessions\x\BNO */
603 RtlInitUnicodeString(&DirectoryName, L"Local");
604 ASSERT(SessionId == 0);
606 &DirectoryName,
608 BaseSrvNamedObjectDirectory,
609 BnoSd);
613 &BnoString);
614 if ((NT_SUCCESS(Status)) && SessionId == 0) NtClose(SymHandle);
615
616 /* Make Session point back to BNOLINKS */
617 RtlInitUnicodeString(&DirectoryName, L"Session");
618 RtlInitUnicodeString(&SymlinkName, L"\\Sessions\\BNOLINKS");
620 &DirectoryName,
622 BaseSrvNamedObjectDirectory,
623 BnoSd);
627 &SymlinkName);
628 if ((NT_SUCCESS(Status)) && SessionId == 0) NtClose(SymHandle);
629
630 /* Create the BNO\Restricted directory and set the restricted DACL */
631 RtlInitUnicodeString(&DirectoryName, L"Restricted");
632 Status = RtlSetDaclSecurityDescriptor(BnoSd, TRUE, BnoRestrictedDacl, FALSE);
635 &DirectoryName,
637 BaseSrvNamedObjectDirectory,
638 BnoSd);
639 Status = NtCreateDirectoryObject(&BaseSrvRestrictedObjectDirectory,
643 }
644 else
645 {
646 /* That should never happen */
647 ASSERT(FALSE);
648 }
649
650 /* Initialize NLS */
652
653 /* Finally, set the pointer */
654 LoadedServerDll->SharedSection = BaseStaticServerData;
655}
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
RTL_CRITICAL_SECTION BaseSrvDDDBSMCritSec
Definition: dosdev.c:27
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Definition: bufpool.h:45
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define swprintf
Definition: precomp.h:40
@ Success
Definition: eventcreate.c:712
@ SystemTimeOfDayInformation
Definition: ntddk_ex.h:14
@ SystemBasicInformation
Definition: ntddk_ex.h:11
Status
Definition: gdiplustypes.h:25
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
NTSYSAPI NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING *, UNICODE_STRING *, ULONG *)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
@ ProcessLUIDDeviceMapsEnabled
Definition: winternl.h:884
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define ASSERT(a)
Definition: mode.c:44
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSectionAndSpinCount(_In_ PRTL_CRITICAL_SECTION CriticalSection, _In_ ULONG SpinCount)
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define RTL_REGISTRY_WINDOWS_NT
Definition: nt_native.h:164
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define REG_NONE
Definition: nt_native.h:1492
#define UNICODE_NULL
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:765
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
#define BOOLEAN
Definition: pedump.c:73
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
BOOLEAN LUIDDeviceMapsEnabled
Definition: base.h:141
ULONG TermsrvClientTimeZoneChangeNum
Definition: base.h:142
UNICODE_STRING NamedObjectDirectory
Definition: base.h:123
BOOLEAN IsWowTaskReady
Definition: base.h:135
UNICODE_STRING WindowsDirectory
Definition: base.h:121
ULONG TermsrvClientTimeZoneId
Definition: base.h:140
SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay
Definition: base.h:131
BOOLEAN DefaultSeparateVDM
Definition: base.h:134
UNICODE_STRING WindowsSys32x86Directory
Definition: base.h:136
SYSTEM_BASIC_INFORMATION SysInfo
Definition: base.h:130
UNICODE_STRING WindowsSystemDirectory
Definition: base.h:122
WCHAR CSDVersion[128]
Definition: base.h:129
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG SessionId
Definition: init.c:40
VOID NTAPI BaseSrvNLSInit(IN PBASE_STATIC_SERVER_DATA StaticData)
Definition: nls.c:117
HANDLE BaseSrvSharedHeap
Definition: init.c:30
UNICODE_STRING BaseSrvKernel32DllPath
Definition: nls.c:25
NTSTATUS NTAPI CreateBaseAcls(OUT PACL *Dacl, OUT PACL *RestrictedDacl)
Definition: init.c:175
HANDLE BaseSrvHeap
Definition: init.c:29
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: init.c:31
NTSTATUS NTAPI BaseSrvInitializeIniFileMappings(IN PBASE_STATIC_SERVER_DATA StaticServerData)
Definition: init.c:154
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint16_t * PWCHAR
Definition: typedefs.h:56
#define TIME_ZONE_ID_INVALID
Definition: winbase.h:286
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseSrvInitializeIniFileMappings()

NTSTATUS NTAPI BaseSrvInitializeIniFileMappings ( IN PBASE_STATIC_SERVER_DATA  StaticServerData)

Definition at line 154 of file init.c.

155{
156 /* Allocate the mapping blob */
159 sizeof(*BaseSrvIniFileMapping));
161 {
162 DPRINT1("BASESRV: Unable to allocate memory in shared heap for IniFileMapping\n");
163 return STATUS_NO_MEMORY;
164 }
165
166 /* Set it*/
167 StaticServerData->IniFileMapping = BaseSrvIniFileMapping;
168
169 /* FIXME: Do the work to initialize the mappings */
170 return STATUS_SUCCESS;
171}
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_SUCCESS
Definition: shellext.h:65
PINIFILE_MAPPING BaseSrvIniFileMapping
Definition: init.c:36

Referenced by BaseInitializeStaticServerData().

◆ CreateBaseAcls()

NTSTATUS NTAPI CreateBaseAcls ( OUT PACL Dacl,
OUT PACL RestrictedDacl 
)

Definition at line 175 of file init.c.

177{
178 PSID SystemSid, WorldSid, RestrictedSid;
182 UCHAR KeyValueBuffer[0x40];
183 PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
187 HANDLE hKey;
189 ULONG ObjectSecurityMode;
190 ACCESS_MASK WorldAccess, RestrictedAccess;
191
192 /* Open the Session Manager Key */
195 &KeyName,
197 NULL,
198 NULL);
200 if (NT_SUCCESS(Status))
201 {
202 /* Read the key value */
203 RtlInitUnicodeString(&KeyName, L"ProtectionMode");
205 &KeyName,
207 KeyValueBuffer,
208 sizeof(KeyValueBuffer),
209 &ResultLength);
210
211 /* Make sure it's what we expect it to be */
212 KeyValuePartialInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyValueBuffer;
213 if ((NT_SUCCESS(Status)) && (KeyValuePartialInfo->Type == REG_DWORD) &&
214 (*(PULONG)KeyValuePartialInfo->Data))
215 {
216 /* Save the Protection Mode */
217 ProtectionMode = *(PULONG)KeyValuePartialInfo->Data;
218 }
219
220 /* Close the handle */
221 NtClose(hKey);
222 }
223
224 /* Get object security mode */
225 if (SessionId == 0 ||
227 {
228 ObjectSecurityMode = 0;
229 }
230
231 /* Allocate the System SID */
234 0, 0, 0, 0, 0, 0, 0,
235 &SystemSid);
236 if (!NT_SUCCESS(Status))
237 {
238 return Status;
239 }
240
241 /* Allocate the World SID */
244 0, 0, 0, 0, 0, 0, 0,
245 &WorldSid);
246 if (!NT_SUCCESS(Status))
247 {
248 RtlFreeSid(SystemSid);
249 goto Return;
250 }
251
252 /* Allocate the restricted SID */
255 0, 0, 0, 0, 0, 0, 0,
256 &RestrictedSid);
257 if (!NT_SUCCESS(Status))
258 {
260 RtlFreeSid(SystemSid);
261 goto Return;
262 }
263
264 /* Allocate one ACL with 3 ACEs each for one SID */
265 AclLength = sizeof(ACL) + 3 * sizeof(ACCESS_ALLOWED_ACE) +
266 RtlLengthSid(SystemSid) +
268 RtlLengthSid(RestrictedSid);
270 if (*Dacl == NULL)
271 {
273 goto FreeAndReturn;
274 }
275
276 /* Set the correct header fields */
278 if (!NT_SUCCESS(Status))
279 {
281 goto FreeAndReturn;
282 }
283
284 /* Setup access for anyone depending on object security mode */
285 if (ObjectSecurityMode != 0)
286 {
287 /*
288 * If we have restrictions on security mode, make it read only
289 * it also means session ID is not 0
290 */
291 WorldAccess = DIRECTORY_QUERY | DIRECTORY_TRAVERSE;
292 }
293 else
294 {
295 /* Otherwise, open wide */
297 }
298
299 /* Give the appropriate rights to each SID */
302 {
304 }
305
306 /* Now allocate the restricted DACL */
307 *RestrictedDacl = RtlAllocateHeap(BaseSrvHeap, 0, AclLength);
308 if (*RestrictedDacl == NULL)
309 {
312 goto FreeAndReturn;
313 }
314
315 /* Initialize it */
316 Status = RtlCreateAcl(*RestrictedDacl, AclLength, ACL_REVISION2);
317 if (!NT_SUCCESS(Status))
318 {
319 RtlFreeHeap(BaseSrvHeap, 0, *RestrictedDacl);
321 goto FreeAndReturn;
322 }
323
324 /* Setup access for restricted sid depending on session id and protection mode */
325 if (SessionId == 0 || (ProtectionMode & 3) == 0)
326 {
327 /* If we have no session ID or if protection mode is not set, then open wide */
329 }
330 else
331 {
332 /* Otherwise, make read only */
333 RestrictedAccess = READ_CONTROL | DIRECTORY_QUERY | DIRECTORY_TRAVERSE;
334 }
335
336 /* And add the same ACEs as before */
337 Status = RtlAddAccessAllowedAce(*RestrictedDacl, ACL_REVISION2, WorldAccess, WorldSid);
338 if (NT_SUCCESS(Status))
339 {
340 Status = RtlAddAccessAllowedAce(*RestrictedDacl, ACL_REVISION2, DIRECTORY_ALL_ACCESS, SystemSid);
341 if (NT_SUCCESS(Status))
342 {
343 Status = RtlAddAccessAllowedAce(*RestrictedDacl, ACL_REVISION2, RestrictedAccess, RestrictedSid);
344 }
345 }
346
347 /* The SIDs are captured, can free them now */
348FreeAndReturn:
349 RtlFreeSid(RestrictedSid);
351 RtlFreeSid(SystemSid);
352
353Return:
354 return Status;
355}
PSID WorldSid
Definition: globals.c:15
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: security.c:40
ULONG ProtectionMode
Definition: init.c:34
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
FxAutoRegKey hKey
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
unsigned int * PULONG
Definition: retypes.h:1
struct _ACL ACL
@ SystemObjectSecurityMode
Definition: extypes.h:287
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1593
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
@ KeyValuePartialInformation
Definition: nt_native.h:1182
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define KEY_READ
Definition: nt_native.h:1023
#define DIRECTORY_QUERY
Definition: nt_native.h:1254
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define READ_CONTROL
Definition: nt_native.h:58
#define DIRECTORY_CREATE_SUBDIRECTORY
Definition: nt_native.h:1257
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
#define REG_DWORD
Definition: sdbapi.c:596
#define SM_REG_KEY
Definition: srv.h:41
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_In_ ULONG AclLength
Definition: rtlfuncs.h:1842
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:527
#define SECURITY_WORLD_RID
Definition: setypes.h:541
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define ACL_REVISION2
Definition: setypes.h:43
#define SECURITY_RESTRICTED_CODE_RID
Definition: setypes.h:569
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by BaseInitializeStaticServerData().

◆ CSR_SERVER_DLL_INIT()

CSR_SERVER_DLL_INIT ( ServerDllInitialization  )

Definition at line 690 of file init.c.

691{
692 /* Setup the DLL Object */
693 LoadedServerDll->ApiBase = BASESRV_FIRST_API_NUMBER;
694 LoadedServerDll->HighestApiSupported = BasepMaxApiNumber;
695 LoadedServerDll->DispatchTable = BaseServerApiDispatchTable;
696 LoadedServerDll->ValidTable = BaseServerApiServerValidTable;
697#ifdef CSR_DBG
698 LoadedServerDll->NameTable = BaseServerApiNameTable;
699#endif
700 LoadedServerDll->SizeOfProcessData = 0;
701 LoadedServerDll->ConnectCallback = BaseClientConnectRoutine;
702 LoadedServerDll->DisconnectCallback = BaseClientDisconnectRoutine;
703 LoadedServerDll->ShutdownProcessCallback = NULL;
704
705 BaseSrvDllInstance = LoadedServerDll->ServerHandle;
706
707 BaseInitializeStaticServerData(LoadedServerDll);
708
709 /* Initialize DOS devices management */
711
712 /* Initialize VDM support */
714
715 /* All done */
716 return STATUS_SUCCESS;
717}
#define BASESRV_FIRST_API_NUMBER
Definition: basemsg.h:16
@ BasepMaxApiNumber
Definition: basemsg.h:53
VOID BaseInitDefineDosDevice(VOID)
Definition: dosdev.c:34
NTSTATUS NTAPI BaseClientConnectRoutine(IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
Definition: init.c:659
VOID NTAPI BaseClientDisconnectRoutine(IN PCSR_PROCESS CsrProcess)
Definition: init.c:684
BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]
Definition: init.c:74
PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]
Definition: init.c:39
HANDLE BaseSrvDllInstance
Definition: init.c:25
VOID NTAPI BaseInitializeStaticServerData(IN PCSR_SERVER_DLL LoadedServerDll)
Definition: init.c:359
VOID BaseInitializeVDM(VOID)
Definition: vdm.c:588

◆ DllMain()

BOOL NTAPI DllMain ( IN HINSTANCE  hInstanceDll,
IN DWORD  dwReason,
IN LPVOID  lpReserved 
)

@DllMain

Core routine of the Utility Manager's library.

Parameters
[in]hDllInstanceThe entry point instance of the library.
[in]fdwReasonThe reason argument to indicate the motive DllMain is being called.
[in]lpvReservedReserved.
Returns
Returns TRUE when main call initialization has succeeded, FALSE otherwise.

Definition at line 721 of file init.c.

724{
725 UNREFERENCED_PARAMETER(hInstanceDll);
727 UNREFERENCED_PARAMETER(lpReserved);
728
730 {
732 }
733
734 return TRUE;
735}
DWORD dwReason
Definition: misc.cpp:154
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
VOID BaseCleanupDefineDosDevice(VOID)
Definition: dosdev.c:39

Variable Documentation

◆ BaseServerApiDispatchTable

Definition at line 39 of file init.c.

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseServerApiServerValidTable

BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]

Definition at line 74 of file init.c.

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseSrvDllInstance

HANDLE BaseSrvDllInstance = NULL

Definition at line 25 of file init.c.

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseSrvHeap

◆ BaseSrvIniFileMapping

PINIFILE_MAPPING BaseSrvIniFileMapping

Definition at line 36 of file init.c.

Referenced by BaseSrvInitializeIniFileMappings().

◆ BaseSrvKernel32DllPath

UNICODE_STRING BaseSrvKernel32DllPath
extern

Definition at line 25 of file nls.c.

Referenced by BaseInitializeStaticServerData(), and BaseSrvDelayLoadKernel32().

◆ BaseSrvSharedHeap

HANDLE BaseSrvSharedHeap = NULL

Definition at line 30 of file init.c.

Referenced by BaseInitializeStaticServerData(), and BaseSrvInitializeIniFileMappings().

◆ BaseStaticServerData

PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL

Definition at line 31 of file init.c.

Referenced by BaseInitializeStaticServerData().

◆ ProtectionMode

ULONG ProtectionMode = 0

Definition at line 34 of file init.c.

Referenced by CreateBaseAcls(), CSR_API(), and GetDosDevicesProtection().

◆ SessionId

ULONG SessionId = 0

Definition at line 33 of file init.c.