ReactOS  0.4.14-dev-1007-g90d795b
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 STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI BaseSrvNlsConnect(IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
Definition: nls.c:135
PKPROCESS CsrProcess
Definition: videoprt.c:37
smooth NULL
Definition: ftsmooth.c:416
struct _BASESRV_API_CONNECTINFO * PBASESRV_API_CONNECTINFO
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1

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 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
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;
376  PSECURITY_DESCRIPTOR BnoSd;
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);
412  ASSERT(Success);
413 
414  /* Create the system directory */
415  wcscat(SystemRootString.Buffer, L"\\System32");
416  Success = RtlCreateUnicodeString(&BaseSrvWindowsSystemDirectory,
417  SystemRootString.Buffer);
418  ASSERT(Success);
419 
420  /* Create the kernel32 path */
421  wcscat(SystemRootString.Buffer, L"\\kernel32.dll");
423  SystemRootString.Buffer);
424  ASSERT(Success);
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 */
439  sizeof(BASE_STATIC_SERVER_DATA));
441 
442  /* Process timezone information */
448  NULL);
450 
451  /* Make a shared heap copy of the Windows directory */
452  BaseStaticServerData->WindowsDirectory = BaseSrvWindowsDirectory;
453  HeapBuffer = RtlAllocateHeap(BaseSrvSharedHeap,
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;
464  HeapBuffer = RtlAllocateHeap(BaseSrvSharedHeap,
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);
482  HeapBuffer = RtlAllocateHeap(BaseSrvSharedHeap,
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 */
527  sizeof(BaseStaticServerData->SysInfo),
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);
596  Status = NtCreateSymbolicLinkObject(&SymHandle,
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);
610  Status = NtCreateSymbolicLinkObject(&SymHandle,
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);
624  Status = NtCreateSymbolicLinkObject(&SymHandle,
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 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
UNICODE_STRING BaseSrvKernel32DllPath
Definition: nls.c:25
NTSYSAPI NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING *, UNICODE_STRING *, ULONG *)
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
HANDLE BaseSrvHeap
Definition: init.c:29
#define RTL_REGISTRY_WINDOWS_NT
Definition: nt_native.h:164
NTSTATUS NTAPI CreateBaseAcls(OUT PACL *Dacl, OUT PACL *RestrictedDacl)
Definition: init.c:175
UNICODE_STRING WindowsDirectory
Definition: base.h:113
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN DefaultSeparateVDM
Definition: base.h:126
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
#define TIME_ZONE_ID_INVALID
Definition: winbase.h:283
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
uint16_t * PWCHAR
Definition: typedefs.h:55
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
#define OBJ_OPENIF
Definition: winternl.h:229
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSectionAndSpinCount(_In_ PRTL_CRITICAL_SECTION CriticalSection, _In_ ULONG SpinCount)
UNICODE_STRING WindowsSystemDirectory
Definition: base.h:114
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define UNICODE_NULL
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
NTSTATUS NTAPI BaseSrvInitializeIniFileMappings(IN PBASE_STATIC_SERVER_DATA StaticServerData)
Definition: init.c:154
UNICODE_STRING NamedObjectDirectory
Definition: base.h:115
unsigned char BOOLEAN
BOOLEAN LUIDDeviceMapsEnabled
Definition: base.h:133
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: init.c:31
#define NtCurrentProcess()
Definition: nt_native.h:1657
SYSTEM_BASIC_INFORMATION SysInfo
Definition: base.h:122
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOLEAN IsWowTaskReady
Definition: base.h:127
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING WindowsSys32x86Directory
Definition: base.h:128
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define OBJ_PERMANENT
Definition: winternl.h:226
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:773
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define NtCurrentPeb()
Definition: FLS.c:20
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
HANDLE BaseSrvSharedHeap
Definition: init.c:30
WCHAR CSDVersion[128]
Definition: base.h:121
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID NTAPI BaseSrvNLSInit(IN PBASE_STATIC_SERVER_DATA StaticData)
Definition: nls.c:112
#define BOOLEAN
Definition: pedump.c:73
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
RTL_CRITICAL_SECTION BaseSrvDDDBSMCritSec
Definition: dosdev.c:27
ULONG TermsrvClientTimeZoneChangeNum
Definition: base.h:134
#define REG_NONE
Definition: nt_native.h:1492
SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay
Definition: base.h:123
ULONG TermsrvClientTimeZoneId
Definition: base.h:132
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
ULONG SessionId
Definition: init.c:33
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

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 }
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
PINIFILE_MAPPING BaseSrvIniFileMapping
Definition: init.c:36
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
HANDLE BaseSrvSharedHeap
Definition: init.c:30
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2938

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");
204  Status = NtQueryValueKey(hKey,
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 ||
226  !NT_SUCCESS(NtQuerySystemInformation(SystemObjectSecurityMode, &ObjectSecurityMode, sizeof(ULONG), NULL)))
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 */
348 FreeAndReturn:
349  RtlFreeSid(RestrictedSid);
351  RtlFreeSid(SystemSid);
352 
353 Return:
354  return Status;
355 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
HANDLE BaseSrvHeap
Definition: init.c:29
#define KEY_READ
Definition: nt_native.h:1023
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
LONG NTSTATUS
Definition: precomp.h:26
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define SM_REG_KEY
Definition: basesrv.h:73
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
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
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
#define ACL_REVISION2
Definition: setypes.h:43
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:526
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#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)
#define DIRECTORY_CREATE_SUBDIRECTORY
Definition: nt_native.h:1257
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:499
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
ULONG ProtectionMode
Definition: init.c:34
#define SECURITY_WORLD_RID
Definition: setypes.h:513
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define READ_CONTROL
Definition: nt_native.h:58
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
PSID WorldSid
Definition: globals.c:15
Status
Definition: gdiplustypes.h:24
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int * PULONG
Definition: retypes.h:1
#define SECURITY_RESTRICTED_CODE_RID
Definition: setypes.h:541
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
unsigned int ULONG
Definition: retypes.h:1
#define DIRECTORY_QUERY
Definition: nt_native.h:1254
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_DWORD
Definition: sdbapi.c:596
ULONG ACCESS_MASK
Definition: nt_native.h:40
_In_ ULONG AclLength
Definition: rtlfuncs.h:1844
SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: database.c:19
ULONG SessionId
Definition: init.c:33

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 }
HANDLE BaseSrvDllInstance
Definition: init.c:25
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI BaseClientConnectRoutine(IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
Definition: init.c:659
VOID BaseInitializeVDM(VOID)
Definition: vdm.c:588
#define BASESRV_FIRST_API_NUMBER
Definition: basemsg.h:16
VOID NTAPI BaseInitializeStaticServerData(IN PCSR_SERVER_DLL LoadedServerDll)
Definition: init.c:359
VOID NTAPI BaseClientDisconnectRoutine(IN PCSR_PROCESS CsrProcess)
Definition: init.c:684
PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]
Definition: init.c:39
VOID BaseInitDefineDosDevice(VOID)
Definition: dosdev.c:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER]
Definition: init.c:74

◆ DllMain()

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

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 }
VOID BaseCleanupDefineDosDevice(VOID)
Definition: dosdev.c:39
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
DWORD dwReason
Definition: misc.cpp:154
#define DLL_PROCESS_DETACH
Definition: compat.h:119

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

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