ReactOS  0.4.14-dev-342-gdc047f9
init.c File Reference
#include "srv.h"
#include <winreg.h>
#include <ndk/cmfuncs.h>
#include <debug.h>
Include dependency graph for init.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI CsrSetProcessSecurity (VOID)
 
NTSTATUS NTAPI CsrSetDirectorySecurity (IN HANDLE ObjectDirectory)
 
NTSTATUS NTAPI GetDosDevicesProtection (OUT PSECURITY_DESCRIPTOR DosDevicesSd)
 
VOID NTAPI FreeDosDevicesProtection (IN PSECURITY_DESCRIPTOR DosDevicesSd)
 
NTSTATUS NTAPI CsrCreateSessionObjectDirectory (IN ULONG Session)
 
NTSTATUS NTAPI CsrParseServerCommandLine (IN ULONG ArgumentCount, IN PCHAR Arguments[])
 
NTSTATUS NTAPI CsrInitCsrRootProcess (VOID)
 
NTSTATUS NTAPI CsrCreateLocalSystemSD (OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
 
NTSTATUS NTAPI CsrSbApiPortInitialize (VOID)
 
NTSTATUS NTAPI CsrServerInitialization (IN ULONG ArgumentCount, IN PCHAR Arguments[])
 
VOID NTAPI CsrPopulateDosDevices (VOID)
 
BOOL NTAPI DllMain (IN HINSTANCE hInstanceDll, IN DWORD dwReason, IN LPVOID lpReserved)
 

Variables

ULONG CsrDebug = 0
 
HANDLE CsrHeap = NULL
 
HANDLE CsrObjectDirectory = NULL
 
UNICODE_STRING CsrDirectoryName
 
UNICODE_STRING CsrSbApiPortName
 
HANDLE CsrSbApiPort = NULL
 
PCSR_THREAD CsrSbApiRequestThreadPtr
 
HANDLE CsrSmApiPort = NULL
 
HANDLE hSbApiPort = NULL
 
HANDLE CsrApiPort = NULL
 
ULONG CsrMaxApiRequestThreads
 
ULONG CsrTotalPerProcessDataLength
 
ULONG SessionId
 
HANDLE BNOLinksDirectory
 
HANDLE SessionObjectDirectory
 
HANDLE DosDevicesDirectory
 
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file init.c.

Function Documentation

◆ CsrCreateLocalSystemSD()

NTSTATUS NTAPI CsrCreateLocalSystemSD ( OUT PSECURITY_DESCRIPTOR LocalSystemSd)

this API is used with CsrPopulateDosDevices, deprecated in r55585. NTSTATUS NTAPI CsrPopulateDosDevicesDirectory(IN HANDLE DosDevicesDirectory, IN PPROCESS_DEVICEMAP_INFORMATION DeviceMap);

Definition at line 801 of file init.c.

802 {
804  PSID SystemSid;
805  ULONG Length;
806  PSECURITY_DESCRIPTOR SystemSd;
807  PACL Dacl;
809 
810  /* Initialize the System SID */
813  0, 0, 0, 0, 0, 0, 0,
814  &SystemSid);
815 
816  /* Get the length of the SID */
817  Length = RtlLengthSid(SystemSid) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
818 
819  /* Allocate a buffer for the Security Descriptor, with SID and DACL */
821 
822  /* Set the pointer to the DACL */
824 
825  /* Now create the SD itself */
827  if (!NT_SUCCESS(Status)) goto Quit;
828 
829  /* Create the DACL for it */
831 
832  /* Create the ACE */
834  if (!NT_SUCCESS(Status)) goto Quit;
835 
836  /* Clear the DACL in the SD */
838  if (!NT_SUCCESS(Status)) goto Quit;
839 
840 Quit:
841  if (!NT_SUCCESS(Status))
842  {
843  RtlFreeHeap(CsrHeap, 0, SystemSd);
844  SystemSd = NULL;
845  }
846 
847  /* Free the SID and return*/
848  RtlFreeSid(SystemSid);
849  *LocalSystemSd = SystemSd;
850  return Status;
851 }
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
#define TRUE
Definition: types.h:120
#define SECURITY_DESCRIPTOR_MIN_LENGTH
Definition: setypes.h:761
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
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 WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define ACL_REVISION2
Definition: setypes.h:43
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
static SID_IDENTIFIER_AUTHORITY NtSidAuthority
Definition: samrpc.c:14
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
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
struct _ACL * PACL
Definition: security.c:104
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
Status
Definition: gdiplustypes.h:24
#define ACL_REVISION
Definition: setypes.h:39
#define PORT_ALL_ACCESS
Definition: lpctypes.h:47
unsigned int ULONG
Definition: retypes.h:1
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrSbApiPortInitialize().

◆ CsrCreateSessionObjectDirectory()

NTSTATUS NTAPI CsrCreateSessionObjectDirectory ( IN ULONG  Session)

Definition at line 414 of file init.c.

415 {
416  WCHAR SessionBuffer[512], BnoBuffer[512];
417  UNICODE_STRING SessionString, BnoString;
419  HANDLE BnoHandle;
420  SECURITY_DESCRIPTOR DosDevicesSd;
422 
423  /* Generate the Session BNOLINKS Directory name */
424  swprintf(SessionBuffer, L"%ws\\BNOLINKS", SESSION_ROOT);
425  RtlInitUnicodeString(&SessionString, SessionBuffer);
426 
427  /* Create it */
429  &SessionString,
431  NULL,
432  NULL);
436  if (!NT_SUCCESS(Status))
437  {
438  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
439  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
440  return Status;
441  }
442 
443  /* Now add the Session ID */
444  swprintf(SessionBuffer, L"%ld", Session);
445  RtlInitUnicodeString(&SessionString, SessionBuffer);
446 
447  /* Check if this is the first Session */
448  if (Session)
449  {
450  /* Not the first, so the name will be slighly more complex */
451  swprintf(BnoBuffer, L"%ws\\%ld\\BaseNamedObjects", SESSION_ROOT, Session);
452  RtlInitUnicodeString(&BnoString, BnoBuffer);
453  }
454  else
455  {
456  /* Use the direct name */
457  RtlInitUnicodeString(&BnoString, L"\\BaseNamedObjects");
458  }
459 
460  /* Create the symlink */
462  &SessionString,
465  NULL);
466  Status = NtCreateSymbolicLinkObject(&BnoHandle,
469  &BnoString);
470  if (!NT_SUCCESS(Status))
471  {
472  DPRINT1("CSRSS: NtCreateSymbolicLinkObject failed in "
473  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
474  return Status;
475  }
476 
477  /* Create the \DosDevices Security Descriptor */
478  Status = GetDosDevicesProtection(&DosDevicesSd);
479  if (!NT_SUCCESS(Status)) return Status;
480 
481  /* Now create a directory for this session */
482  swprintf(SessionBuffer, L"%ws\\%ld", SESSION_ROOT, Session);
483  RtlInitUnicodeString(&SessionString, SessionBuffer);
484 
485  /* Create the directory */
487  &SessionString,
489  0,
490  &DosDevicesSd);
494  if (!NT_SUCCESS(Status))
495  {
496  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
497  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
498  FreeDosDevicesProtection(&DosDevicesSd);
499  return Status;
500  }
501 
502  /* Next, create a directory for this session's DOS Devices */
503  RtlInitUnicodeString(&SessionString, L"DosDevices");
505  &SessionString,
508  &DosDevicesSd);
512  if (!NT_SUCCESS(Status))
513  {
514  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
515  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
516  }
517 
518  /* Release the Security Descriptor */
519  FreeDosDevicesProtection(&DosDevicesSd);
520 
521  /* Return */
522  return Status;
523 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI GetDosDevicesProtection(OUT PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:199
LONG NTSTATUS
Definition: precomp.h:26
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
VOID NTAPI FreeDosDevicesProtection(IN PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:382
#define OBJ_OPENIF
Definition: winternl.h:229
HANDLE DosDevicesDirectory
Definition: init.c:39
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
HANDLE SessionObjectDirectory
Definition: init.c:38
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:773
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
HANDLE BNOLinksDirectory
Definition: init.c:37
#define SESSION_ROOT
Definition: srv.h:44

Referenced by CsrParseServerCommandLine().

◆ CsrInitCsrRootProcess()

NTSTATUS NTAPI CsrInitCsrRootProcess ( VOID  )

Definition at line 723 of file init.c.

724 {
725  PVOID ProcessData;
726  PCSR_SERVER_DLL ServerDll;
727  ULONG i = 0;
728 
729  /* All Server DLLs are now loaded, allocate a heap for the Root Process */
730  ProcessData = RtlAllocateHeap(CsrHeap,
733  if (!ProcessData)
734  {
735  DPRINT1("CSRSRV:%s: RtlAllocateHeap failed (Status=%08lx)\n",
737  return STATUS_NO_MEMORY;
738  }
739 
740  /*
741  * Our Root Process was never officially initialized,
742  * so write the data for each Server DLL manually.
743  */
744 
745  /* Loop every DLL */
746  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
747  {
748  /* Get the current Server */
749  ServerDll = CsrLoadedServerDll[i];
750 
751  /* Is it loaded, and does it have per process data? */
752  if (ServerDll && ServerDll->SizeOfProcessData)
753  {
754  /* It does, give it part of our allocated heap */
755  CsrRootProcess->ServerData[i] = ProcessData;
756 
757  /* Move to the next heap position */
758  ProcessData = (PVOID)((ULONG_PTR)ProcessData +
759  ServerDll->SizeOfProcessData);
760  }
761  else
762  {
763  /* Nothing for this Server DLL */
765  }
766  }
767 
768  /* Now initialize the Root Process manually as well */
769  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
770  {
771  /* Get the current Server */
772  ServerDll = CsrLoadedServerDll[i];
773 
774  /* Is it loaded, and does it a callback for new processes? */
775  if (ServerDll && ServerDll->NewProcessCallback)
776  {
777  /* Call the callback */
779  }
780  }
781 
782  return STATUS_SUCCESS;
783 }
ULONG SizeOfProcessData
Definition: csrsrv.h:234
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
uint32_t ULONG_PTR
Definition: typedefs.h:63
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
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
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
PVOID ServerData[ANYSIZE_ARRAY]
Definition: csrsrv.h:60
ULONG CsrTotalPerProcessDataLength
Definition: init.c:35
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
PCSR_NEWPROCESS_CALLBACK NewProcessCallback
Definition: csrsrv.h:239
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define __FUNCTION__
Definition: types.h:112
HANDLE CsrHeap
Definition: init.c:25
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by CsrServerInitialization().

◆ CsrParseServerCommandLine()

NTSTATUS NTAPI CsrParseServerCommandLine ( IN ULONG  ArgumentCount,
IN PCHAR  Arguments[] 
)

Definition at line 544 of file init.c.

546 {
548  PCHAR ParameterName = NULL, ParameterValue = NULL, EntryPoint, ServerString;
549  ULONG i, DllIndex;
552 
553  /* Set the Defaults */
557 
558  /* Save our Session ID, and create a Directory for it */
559  SessionId = NtCurrentPeb()->SessionId;
561  if (!NT_SUCCESS(Status))
562  {
563  DPRINT1("CSRSS: CsrCreateSessionObjectDirectory failed (%lx)\n",
564  Status);
565 
566  /* It's not fatal if the session ID isn't zero */
567  if (SessionId != 0) return Status;
569  }
570 
571  /* Loop through every argument */
572  for (i = 1; i < ArgumentCount; i++)
573  {
574  /* Split Name and Value */
575  ParameterName = Arguments[i];
579  DPRINT("Name=%s, Value=%s\n", ParameterName, ParameterValue);
580 
581  /* Check for Object Directory */
582  if (_stricmp(ParameterName, "ObjectDirectory") == 0)
583  {
584  /* Check if a session ID is specified */
585  if (SessionId != 0)
586  {
587  DPRINT1("Sessions not yet implemented\n");
588  ASSERT(SessionId);
589  }
590 
591  /* Initialize the directory name */
594  &AnsiString,
595  TRUE);
596  ASSERT(NT_SUCCESS(Status) || SessionId != 0);
597  if (!NT_SUCCESS(Status)) return Status;
598 
599  /* Create it */
603  NULL,
604  NULL);
608  if (!NT_SUCCESS(Status)) return Status;
609 
610  /* Secure it */
612  if (!NT_SUCCESS(Status)) return Status;
613  }
614  else if (_stricmp(ParameterName, "SubSystemType") == 0)
615  {
616  /* Ignored */
617  }
618  else if (_stricmp(ParameterName, "MaxRequestThreads") == 0)
619  {
621  0,
623  }
624  else if (_stricmp(ParameterName, "RequestThreads") == 0)
625  {
626  /* Ignored */
628  }
629  else if (_stricmp(ParameterName, "ProfileControl") == 0)
630  {
631  /* Ignored */
632  }
633  else if (_stricmp(ParameterName, "SharedSection") == 0)
634  {
635  /* Create the Section */
637  if (!NT_SUCCESS(Status))
638  {
639  DPRINT1("CSRSS: *** Invalid syntax for %s=%s (Status == %X)\n",
641  return Status;
642  }
643 
644  /* Load us */
645  Status = CsrLoadServerDll("CSRSS" /* "CSRSRV" */, NULL, CSRSRV_SERVERDLL_INDEX);
646  }
647  else if (_stricmp(ParameterName, "ServerDll") == 0)
648  {
649  /* Loop the command line */
650  EntryPoint = NULL;
652  ServerString = ParameterValue;
653  while (*ServerString)
654  {
655  /* Check for the Entry Point */
656  if ((*ServerString == ':') && (!EntryPoint))
657  {
658  /* Found it. Add a nullchar and save it */
659  *ServerString++ = ANSI_NULL;
660  EntryPoint = ServerString;
661  }
662 
663  /* Check for the Dll Index */
664  if (*ServerString++ == ',') break;
665  }
666 
667  /* Did we find something to load? */
668  if (!*ServerString)
669  {
670  DPRINT1("CSRSS: *** Invalid syntax for ServerDll=%s (Status == %X)\n",
672  return Status;
673  }
674 
675  /* Convert it to a ULONG */
676  Status = RtlCharToInteger(ServerString, 10, &DllIndex);
677 
678  /* Add a null char if it was valid */
679  if (NT_SUCCESS(Status)) ServerString[-1] = ANSI_NULL;
680 
681  /* Load it */
682  if (CsrDebug & 1) DPRINT1("CSRSS: Loading ServerDll=%s:%s\n", ParameterValue, EntryPoint);
683  Status = CsrLoadServerDll(ParameterValue, EntryPoint, DllIndex);
684  if (!NT_SUCCESS(Status))
685  {
686  DPRINT1("CSRSS: *** Failed loading ServerDll=%s (Status == 0x%x)\n",
688  return Status;
689  }
690  }
691  else if (_stricmp(ParameterName, "Windows") == 0)
692  {
693  /* Ignored */
694  // Check whether we want to start in pure GUI or pure CLI.
695  }
696  else
697  {
698  /* Invalid parameter on the command line */
700  }
701  }
702 
703  /* Return status */
704  return Status;
705 }
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI NTSTATUS NTAPI RtlCharToInteger(PCSZ String, ULONG Base, PULONG Value)
Definition: unicode.c:261
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI CsrSetDirectorySecurity(IN HANDLE ObjectDirectory)
Definition: init.c:176
#define OBJ_PERMANENT
Definition: winternl.h:226
#define _stricmp
Definition: cat.c:22
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define OBJ_OPENIF
Definition: winternl.h:229
HANDLE CsrObjectDirectory
Definition: init.c:26
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
#define ANSI_NULL
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI CsrSrvCreateSharedSection(IN PCHAR ParameterValue)
Definition: server.c:335
NTSTATUS NTAPI CsrCreateSessionObjectDirectory(IN ULONG Session)
Definition: init.c:414
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG CsrMaxApiRequestThreads
Definition: init.c:34
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_opt_ PWSTR _In_ PWSTR _Inout_ PULONG ParameterValue
Definition: classpnp.h:1209
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:773
ULONG CsrTotalPerProcessDataLength
Definition: init.c:35
#define NtCurrentPeb()
Definition: FLS.c:20
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
_In_opt_ PWSTR _In_ PWSTR ParameterName
Definition: classpnp.h:1209
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING CsrDirectoryName
Definition: init.c:27
NTSTATUS NTAPI CsrLoadServerDll(IN PCHAR DllString, IN PCHAR EntryPoint OPTIONAL, IN ULONG ServerId)
Definition: server.c:116
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
ULONG CsrDebug
Definition: init.c:23
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG SessionId
Definition: init.c:33

Referenced by CsrServerInitialization().

◆ CsrPopulateDosDevices()

VOID NTAPI CsrPopulateDosDevices ( VOID  )

Definition at line 1089 of file init.c.

1090 {
1091  DPRINT1("Deprecated API in r55585.\n");
1092  return;
1093 }
#define DPRINT1
Definition: precomp.h:8

◆ CsrSbApiPortInitialize()

NTSTATUS NTAPI CsrSbApiPortInitialize ( VOID  )

Definition at line 869 of file init.c.

870 {
871  ULONG Size;
872  PSECURITY_DESCRIPTOR PortSd;
875  HANDLE hRequestThread;
877 
878  /* Calculate how much space we'll need for the Port Name */
879  Size = CsrDirectoryName.Length + sizeof(SB_PORT_NAME) + sizeof(WCHAR);
880 
881  /* Create the buffer for it */
884 
885  /* Setup the rest of the empty string */
888 
889  /* Now append the full port name */
893  if (CsrDebug & 2) DPRINT1("CSRSS: Creating %wZ port and associated thread\n", &CsrSbApiPortName);
894 
895  /* Create Security Descriptor for this Port */
896  Status = CsrCreateLocalSystemSD(&PortSd);
897  if (!NT_SUCCESS(Status)) return Status;
898 
899  /* Initialize the Attributes */
902  0,
903  NULL,
904  PortSd);
905 
906  /* Create the Port Object */
909  sizeof(SB_CONNECTION_INFO),
910  sizeof(SB_API_MSG),
911  32 * sizeof(SB_API_MSG));
912  if (PortSd) RtlFreeHeap(CsrHeap, 0, PortSd);
913 
914  if (NT_SUCCESS(Status))
915  {
916  /* Create the Thread to handle the API Requests */
918  NULL,
919  TRUE,
920  0,
921  0,
922  0,
924  NULL,
925  &hRequestThread,
926  &ClientId);
927  if (NT_SUCCESS(Status))
928  {
929  /* Add it as a Static Server Thread */
931  &ClientId,
932  0);
933 
934  /* Activate it */
935  Status = NtResumeThread(hRequestThread, NULL);
936  }
937  }
938 
939  return Status;
940 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define SB_PORT_NAME
Definition: srv.h:47
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PCSR_THREAD CsrSbApiRequestThreadPtr
Definition: init.c:30
VOID NTAPI CsrSbApiRequestThread(IN PVOID Parameter)
Definition: session.c:484
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
PCSR_THREAD NTAPI CsrAddStaticServerThread(IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
Definition: thredsup.c:511
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:212
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CsrCreateLocalSystemSD(OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
Definition: init.c:801
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
HANDLE CsrSbApiPort
Definition: init.c:29
unsigned short USHORT
Definition: pedump.c:61
#define UNICODE_PATH_SEP
Definition: connect.c:33
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING CsrDirectoryName
Definition: init.c:27
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
ULONG CsrDebug
Definition: init.c:23
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrServerInitialization().

◆ CsrServerInitialization()

NTSTATUS NTAPI CsrServerInitialization ( IN ULONG  ArgumentCount,
IN PCHAR  Arguments[] 
)

Definition at line 965 of file init.c.

967 {
969 
970  /* Cache System Basic Information so we don't always request it */
972  &CsrNtSysInfo,
973  sizeof(SYSTEM_BASIC_INFORMATION),
974  NULL);
975  if (!NT_SUCCESS(Status))
976  {
977  DPRINT1("CSRSRV:%s: NtQuerySystemInformation failed (Status=0x%08lx)\n",
979  return Status;
980  }
981 
982  /* Save our Heap */
983  CsrHeap = RtlGetProcessHeap();
984 
985  /* Set our Security Descriptor to protect the process */
987  if (!NT_SUCCESS(Status))
988  {
989  DPRINT1("CSRSRV:%s: CsrSetProcessSecurity failed (Status=0x%08lx)\n",
991  return Status;
992  }
993 
994  /* Set up Session Support */
996  if (!NT_SUCCESS(Status))
997  {
998  DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=0x%08lx)\n",
1000  return Status;
1001  }
1002 
1003  /* Set up Process Support and allocate the CSR Root Process */
1005  if (!NT_SUCCESS(Status))
1006  {
1007  DPRINT1("CSRSRV:%s: CsrInitializeProcessStructure failed (Status=0x%08lx)\n",
1008  __FUNCTION__, Status);
1009  return Status;
1010  }
1011 
1012  /* Parse the command line */
1013  Status = CsrParseServerCommandLine(ArgumentCount, Arguments);
1014  if (!NT_SUCCESS(Status))
1015  {
1016  DPRINT1("CSRSRV:%s: CsrParseServerCommandLine failed (Status=0x%08lx)\n",
1017  __FUNCTION__, Status);
1018  return Status;
1019  }
1020 
1021  /* Finish to initialize the CSR Root Process */
1023  if (!NT_SUCCESS(Status))
1024  {
1025  DPRINT1("CSRSRV:%s: CsrInitCsrRootProcess failed (Status=0x%08lx)\n",
1026  __FUNCTION__, Status);
1027  return Status;
1028  }
1029 
1030  /* Now initialize our API Port */
1032  if (!NT_SUCCESS(Status))
1033  {
1034  DPRINT1("CSRSRV:%s: CsrApiPortInitialize failed (Status=0x%08lx)\n",
1035  __FUNCTION__, Status);
1036  return Status;
1037  }
1038 
1039  /* Initialize the API Port for SM communication */
1041  if (!NT_SUCCESS(Status))
1042  {
1043  DPRINT1("CSRSRV:%s: CsrSbApiPortInitialize failed (Status=0x%08lx)\n",
1044  __FUNCTION__, Status);
1045  return Status;
1046  }
1047 
1048  /* We're all set! Connect to SM! */
1050  CsrSbApiPort,
1052  &CsrSmApiPort);
1053  if (!NT_SUCCESS(Status))
1054  {
1055  DPRINT1("CSRSRV:%s: SmConnectToSm failed (Status=0x%08lx)\n",
1056  __FUNCTION__, Status);
1057  return Status;
1058  }
1059 
1060  /* Have us handle Hard Errors */
1062  if (!NT_SUCCESS(Status))
1063  {
1064  DPRINT1("CSRSRV:%s: NtSetDefaultHardErrorPort failed (Status=0x%08lx)\n",
1065  __FUNCTION__, Status);
1066  return Status;
1067  }
1068 
1069  /* Return status */
1070  return Status;
1071 }
NTSTATUS NTAPI CsrParseServerCommandLine(IN ULONG ArgumentCount, IN PCHAR Arguments[])
Definition: init.c:544
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
NTSTATUS NTAPI CsrInitializeProcessStructure(VOID)
Definition: procsup.c:254
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI CsrSetProcessSecurity(VOID)
Definition: init.c:62
NTSTATUS NTAPI NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
Definition: harderr.c:742
NTSTATUS NTAPI CsrSbApiPortInitialize(VOID)
Definition: init.c:869
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
smooth NULL
Definition: ftsmooth.c:416
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
Definition: init.c:40
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CsrInitCsrRootProcess(VOID)
Definition: init.c:723
Status
Definition: gdiplustypes.h:24
HANDLE CsrSbApiPort
Definition: init.c:29
HANDLE CsrSmApiPort
Definition: init.c:31
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI SmConnectToSm(IN PUNICODE_STRING SbApiPortName, IN HANDLE SbApiPort, IN ULONG ImageType, OUT PHANDLE SmApiPort)
Definition: smclient.c:68
NTSTATUS NTAPI CsrApiPortInitialize(VOID)
Definition: api.c:882
NTSTATUS NTAPI CsrInitializeNtSessionList(VOID)
Definition: session.c:53
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define __FUNCTION__
Definition: types.h:112
HANDLE CsrHeap
Definition: init.c:25
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
HANDLE CsrApiPort
Definition: init.c:33

Referenced by _main().

◆ CsrSetDirectorySecurity()

NTSTATUS NTAPI CsrSetDirectorySecurity ( IN HANDLE  ObjectDirectory)

Definition at line 176 of file init.c.

177 {
178  /* FIXME: Implement */
179  return STATUS_SUCCESS;
180 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by CsrParseServerCommandLine().

◆ CsrSetProcessSecurity()

NTSTATUS NTAPI CsrSetProcessSecurity ( VOID  )

Definition at line 62 of file init.c.

63 {
65  HANDLE hToken, hProcess = NtCurrentProcess();
66  ULONG Length;
67  PTOKEN_USER TokenInfo = NULL;
68  PSECURITY_DESCRIPTOR ProcSd = NULL;
69  PACL Dacl;
70  PSID UserSid;
71 
72  /* Open our token */
74  if (!NT_SUCCESS(Status)) goto Quickie;
75 
76  /* Get the Token User Length */
78 
79  /* Allocate space for it */
81  if (!TokenInfo)
82  {
84  goto Quickie;
85  }
86 
87  /* Now query the data */
88  Status = NtQueryInformationToken(hToken, TokenUser, TokenInfo, Length, &Length);
89  NtClose(hToken);
90  if (!NT_SUCCESS(Status)) goto Quickie;
91 
92  /* Now check the SID Length */
93  UserSid = TokenInfo->User.Sid;
94  Length = RtlLengthSid(UserSid) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
95 
96  /* Allocate a buffer for the Security Descriptor, with SID and DACL */
98  if (!ProcSd)
99  {
101  goto Quickie;
102  }
103 
104  /* Set the pointer to the DACL */
106 
107  /* Now create the SD itself */
109  if (!NT_SUCCESS(Status))
110  {
111  DPRINT1("CSRSS: SD creation failed - status = %lx\n", Status);
112  goto Quickie;
113  }
114 
115  /* Create the DACL for it*/
117  if (!NT_SUCCESS(Status))
118  {
119  DPRINT1("CSRSS: DACL creation failed - status = %lx\n", Status);
120  goto Quickie;
121  }
122 
123  /* Create the ACE */
125  ACL_REVISION,
130  UserSid);
131  if (!NT_SUCCESS(Status))
132  {
133  DPRINT1("CSRSS: ACE creation failed - status = %lx\n", Status);
134  goto Quickie;
135  }
136 
137  /* Clear the DACL in the SD */
139  if (!NT_SUCCESS(Status))
140  {
141  DPRINT1("CSRSS: set DACL failed - status = %lx\n", Status);
142  goto Quickie;
143  }
144 
145  /* Write the SD into the Process */
147  if (!NT_SUCCESS(Status))
148  {
149  DPRINT1("CSRSS: set process DACL failed - status = %lx\n", Status);
150  goto Quickie;
151  }
152 
153  /* Free the memory and return */
154 Quickie:
155  if (ProcSd) RtlFreeHeap(CsrHeap, 0, ProcSd);
156  RtlFreeHeap(CsrHeap, 0, TokenInfo);
157  return Status;
158 }
#define TRUE
Definition: types.h:120
#define SECURITY_DESCRIPTOR_MIN_LENGTH
Definition: setypes.h:761
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
NTSTATUS NTAPI NtOpenProcessToken(IN HANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
Definition: security.c:350
#define PROCESS_SUSPEND_RESUME
Definition: pstypes.h:159
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define PROCESS_DUP_HANDLE
#define ACL_REVISION2
Definition: setypes.h:43
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Definition: token.c:1839
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _ACL * PACL
Definition: security.c:104
#define PROCESS_VM_WRITE
Definition: pstypes.h:154
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS WINAPI NtSetSecurityObject(HANDLE Handle, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
Status
Definition: gdiplustypes.h:24
#define PROCESS_TERMINATE
Definition: pstypes.h:149
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
#define ACL_REVISION
Definition: setypes.h:39
#define PROCESS_VM_READ
Definition: pstypes.h:153
unsigned int ULONG
Definition: retypes.h:1
SID_AND_ATTRIBUTES User
Definition: setypes.h:956
#define PROCESS_VM_OPERATION
Definition: pstypes.h:152
HANDLE CsrHeap
Definition: init.c:25
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125

Referenced by CsrServerInitialization().

◆ DllMain()

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

Definition at line 1097 of file init.c.

1100 {
1101  /* We don't do much */
1102  UNREFERENCED_PARAMETER(hInstanceDll);
1104  UNREFERENCED_PARAMETER(lpReserved);
1105 
1106  return TRUE;
1107 }
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
DWORD dwReason
Definition: misc.cpp:154

◆ FreeDosDevicesProtection()

VOID NTAPI FreeDosDevicesProtection ( IN PSECURITY_DESCRIPTOR  DosDevicesSd)

Definition at line 382 of file init.c.

383 {
384  PACL Dacl;
385  BOOLEAN Present, Default;
387 
388  /* Get the DACL corresponding to this SD */
389  Status = RtlGetDaclSecurityDescriptor(DosDevicesSd, &Present, &Dacl, &Default);
391  ASSERT(Present);
392  ASSERT(Dacl != NULL);
393 
394  /* Free it */
395  if ((NT_SUCCESS(Status)) && (Dacl)) RtlFreeHeap(CsrHeap, 0, Dacl);
396 }
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlGetDaclSecurityDescriptor(_In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _Out_ PBOOLEAN DaclPresent, _Out_ PACL *Dacl, _Out_ PBOOLEAN DaclDefaulted)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
Status
Definition: gdiplustypes.h:24
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrCreateSessionObjectDirectory().

◆ GetDosDevicesProtection()

NTSTATUS NTAPI GetDosDevicesProtection ( OUT PSECURITY_DESCRIPTOR  DosDevicesSd)

Definition at line 199 of file init.c.

200 {
204  PSID WorldSid, CreatorSid, AdminSid, SystemSid;
205  UCHAR KeyValueBuffer[0x40];
206  PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
208  ULONG ProtectionMode = 0;
210  PACL Dacl;
212  HANDLE hKey;
214  ULONG ResultLength, SidLength, AclLength;
215 
216  /* Create the SD */
219 
220  /* Initialize the System SID */
223  0, 0, 0, 0, 0, 0, 0,
224  &SystemSid);
226 
227  /* Initialize the World SID */
230  0, 0, 0, 0, 0, 0, 0,
231  &WorldSid);
233 
234  /* Initialize the Admin SID */
238  0, 0, 0, 0, 0, 0,
239  &AdminSid);
241 
242  /* Initialize the Creator SID */
243  Status = RtlAllocateAndInitializeSid(&CreatorAuthority, 1,
245  0, 0, 0, 0, 0, 0, 0,
246  &CreatorSid);
248 
249  /* Open the Session Manager Key */
252  &KeyName,
254  NULL,
255  NULL);
257  if (NT_SUCCESS(Status))
258  {
259  /* Read the key value */
260  RtlInitUnicodeString(&KeyName, L"ProtectionMode");
261  Status = NtQueryValueKey(hKey,
262  &KeyName,
264  KeyValueBuffer,
265  sizeof(KeyValueBuffer),
266  &ResultLength);
267 
268  /* Make sure it's what we expect it to be */
269  KeyValuePartialInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyValueBuffer;
270  if ((NT_SUCCESS(Status)) && (KeyValuePartialInfo->Type == REG_DWORD) &&
271  (*(PULONG)KeyValuePartialInfo->Data))
272  {
273  /* Save the Protection Mode */
274  ProtectionMode = *(PULONG)KeyValuePartialInfo->Data;
275  }
276 
277  /* Close the handle */
278  NtClose(hKey);
279  }
280 
281  /* Check the Protection Mode */
282  if (ProtectionMode & 3)
283  {
284  /* Calculate SID Lengths */
285  SidLength = RtlLengthSid(CreatorSid) + RtlLengthSid(SystemSid) +
287  AclLength = sizeof(ACL) + 3 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
288 
289  /* Allocate memory for the DACL */
291  ASSERT(Dacl != NULL);
292 
293  /* Build the ACL and add 3 ACEs */
302 
303  /* Edit the ACEs to make them inheritable */
304  Status = RtlGetAce(Dacl, 0, (PVOID*)&Ace);
306  Ace->Header.AceFlags |= OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE;
307  Status = RtlGetAce(Dacl, 1, (PVOID*)&Ace);
309  Ace->Header.AceFlags |= OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE;
310  Status = RtlGetAce(Dacl, 2, (PVOID*)&Ace);
313 
314  /* Set this DACL with the SD */
317  goto Quickie;
318  }
319  else
320  {
321  /* Calculate SID Lengths */
322  SidLength = RtlLengthSid(WorldSid) + RtlLengthSid(SystemSid);
323  AclLength = sizeof(ACL) + 3 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
324 
325  /* Allocate memory for the DACL */
327  ASSERT(Dacl != NULL);
328 
329  /* Build the ACL and add 3 ACEs */
338 
339  /* Edit the last ACE to make it inheritable */
340  Status = RtlGetAce(Dacl, 2, (PVOID*)&Ace);
343 
344  /* Set this DACL with the SD */
347  goto Quickie;
348  }
349 
350 /* FIXME: failure cases! Fail: */
351  /* Free the memory */
352  RtlFreeHeap(CsrHeap, 0, Dacl);
353 
354 /* FIXME: semi-failure cases! Quickie: */
355 Quickie:
356  /* Free the SIDs */
357  RtlFreeSid(CreatorSid);
360  RtlFreeSid(SystemSid);
361 
362  /* Return */
363  return Status;
364 }
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 GENERIC_ALL
Definition: nt_native.h:92
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
#define TRUE
Definition: types.h:120
static PSID AdminSid
Definition: msgina.c:39
#define KEY_READ
Definition: nt_native.h:1023
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 NTAPI RtlGetAce(PACL Acl, ULONG AceIndex, PVOID *Ace)
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
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 WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define GENERIC_WRITE
Definition: nt_native.h:90
Definition: card.h:12
#define ACL_REVISION2
Definition: setypes.h:43
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
static SID_IDENTIFIER_AUTHORITY NtSidAuthority
Definition: samrpc.c:14
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
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 CONTAINER_INHERIT_ACE
Definition: setypes.h:715
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 SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
#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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SECURITY_CREATOR_OWNER_RID
Definition: setypes.h:517
_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
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
unsigned int * PULONG
Definition: retypes.h:1
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define ACL_REVISION
Definition: setypes.h:39
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
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define INHERIT_ONLY_ACE
Definition: setypes.h:717
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define REG_DWORD
Definition: sdbapi.c:596
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624
#define OBJECT_INHERIT_ACE
Definition: setypes.h:714
HANDLE CsrHeap
Definition: init.c:25
_In_ ULONG AclLength
Definition: rtlfuncs.h:1844
#define SECURITY_CREATOR_SID_AUTHORITY
Definition: setypes.h:505

Referenced by CsrCreateSessionObjectDirectory().

Variable Documentation

◆ BNOLinksDirectory

HANDLE BNOLinksDirectory

Definition at line 37 of file init.c.

Referenced by CsrCreateSessionObjectDirectory().

◆ CsrApiPort

HANDLE CsrApiPort = NULL

Definition at line 33 of file init.c.

Referenced by CsrServerInitialization(), and UserClientConnect().

◆ CsrDebug

◆ CsrDirectoryName

UNICODE_STRING CsrDirectoryName

Definition at line 27 of file init.c.

Referenced by CsrApiPortInitialize(), CsrParseServerCommandLine(), and CsrSbApiPortInitialize().

◆ CsrHeap

◆ CsrMaxApiRequestThreads

ULONG CsrMaxApiRequestThreads

Definition at line 34 of file init.c.

Referenced by CsrParseServerCommandLine(), and CsrpCheckRequestThreads().

◆ CsrNtSysInfo

Definition at line 40 of file init.c.

Referenced by CsrServerInitialization(), and CsrSrvCreateSharedSection().

◆ CsrObjectDirectory

HANDLE CsrObjectDirectory = NULL

Definition at line 26 of file init.c.

Referenced by CsrParseServerCommandLine().

◆ CsrSbApiPort

HANDLE CsrSbApiPort = NULL

Definition at line 29 of file init.c.

Referenced by CsrSbApiPortInitialize(), CsrSbApiRequestThread(), and CsrServerInitialization().

◆ CsrSbApiPortName

UNICODE_STRING CsrSbApiPortName

Definition at line 28 of file init.c.

Referenced by CsrSbApiPortInitialize(), and CsrServerInitialization().

◆ CsrSbApiRequestThreadPtr

PCSR_THREAD CsrSbApiRequestThreadPtr

Definition at line 30 of file init.c.

Referenced by CsrSbApiPortInitialize().

◆ CsrSmApiPort

HANDLE CsrSmApiPort = NULL

Definition at line 31 of file init.c.

Referenced by CsrDereferenceNtSession(), and CsrServerInitialization().

◆ CsrTotalPerProcessDataLength

ULONG CsrTotalPerProcessDataLength

◆ DosDevicesDirectory

HANDLE DosDevicesDirectory

Definition at line 39 of file init.c.

Referenced by CsrCreateSessionObjectDirectory().

◆ hSbApiPort

HANDLE hSbApiPort = NULL

Definition at line 32 of file init.c.

Referenced by SmCompleteSession(), and SmConnectApiPort().

◆ SessionId

ULONG SessionId

Definition at line 36 of file init.c.

◆ SessionObjectDirectory

HANDLE SessionObjectDirectory

Definition at line 38 of file init.c.

Referenced by CsrCreateSessionObjectDirectory().