ReactOS  0.4.15-dev-509-g96a357b
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 807 of file init.c.

808 {
810  PSID SystemSid;
811  ULONG Length;
812  PSECURITY_DESCRIPTOR SystemSd;
813  PACL Dacl;
815 
816  /* Initialize the System SID */
819  0, 0, 0, 0, 0, 0, 0,
820  &SystemSid);
821 
822  /* Get the length of the SID */
823  Length = RtlLengthSid(SystemSid) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
824 
825  /* Allocate a buffer for the Security Descriptor, with SID and DACL */
827 
828  /* Set the pointer to the DACL */
830 
831  /* Now create the SD itself */
833  if (!NT_SUCCESS(Status)) goto Quit;
834 
835  /* Create the DACL for it */
837 
838  /* Create the ACE */
840  if (!NT_SUCCESS(Status)) goto Quit;
841 
842  /* Clear the DACL in the SD */
844  if (!NT_SUCCESS(Status)) goto Quit;
845 
846 Quit:
847  if (!NT_SUCCESS(Status))
848  {
849  RtlFreeHeap(CsrHeap, 0, SystemSd);
850  SystemSd = NULL;
851  }
852 
853  /* Free the SID and return*/
854  RtlFreeSid(SystemSid);
855  *LocalSystemSd = SystemSd;
856  return Status;
857 }
#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 WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
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)
uint32_t ULONG_PTR
Definition: typedefs.h:64
#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 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:1552
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 420 of file init.c.

421 {
422  WCHAR SessionBuffer[512], BnoBuffer[512];
423  UNICODE_STRING SessionString, BnoString;
425  HANDLE BnoHandle;
426  SECURITY_DESCRIPTOR DosDevicesSd;
428 
429  /* Generate the Session BNOLINKS Directory name */
430  swprintf(SessionBuffer, L"%ws\\BNOLINKS", SESSION_ROOT);
431  RtlInitUnicodeString(&SessionString, SessionBuffer);
432 
433  /* Create it */
435  &SessionString,
437  NULL,
438  NULL);
442  if (!NT_SUCCESS(Status))
443  {
444  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
445  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
446  return Status;
447  }
448 
449  /* Now add the Session ID */
450  swprintf(SessionBuffer, L"%ld", Session);
451  RtlInitUnicodeString(&SessionString, SessionBuffer);
452 
453  /* Check if this is the first Session */
454  if (Session)
455  {
456  /* Not the first, so the name will be slighly more complex */
457  swprintf(BnoBuffer, L"%ws\\%ld\\BaseNamedObjects", SESSION_ROOT, Session);
458  RtlInitUnicodeString(&BnoString, BnoBuffer);
459  }
460  else
461  {
462  /* Use the direct name */
463  RtlInitUnicodeString(&BnoString, L"\\BaseNamedObjects");
464  }
465 
466  /* Create the symlink */
468  &SessionString,
471  NULL);
472  Status = NtCreateSymbolicLinkObject(&BnoHandle,
475  &BnoString);
476  if (!NT_SUCCESS(Status))
477  {
478  DPRINT1("CSRSS: NtCreateSymbolicLinkObject failed in "
479  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
480  return Status;
481  }
482 
483  /* Create the \DosDevices Security Descriptor */
484  Status = GetDosDevicesProtection(&DosDevicesSd);
485  if (!NT_SUCCESS(Status)) return Status;
486 
487  /* Now create a directory for this session */
488  swprintf(SessionBuffer, L"%ws\\%ld", SESSION_ROOT, Session);
489  RtlInitUnicodeString(&SessionString, SessionBuffer);
490 
491  /* Create the directory */
493  &SessionString,
495  0,
496  &DosDevicesSd);
500  if (!NT_SUCCESS(Status))
501  {
502  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
503  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
504  FreeDosDevicesProtection(&DosDevicesSd);
505  return Status;
506  }
507 
508  /* Next, create a directory for this session's DOS Devices */
509  RtlInitUnicodeString(&SessionString, L"DosDevices");
511  &SessionString,
514  &DosDevicesSd);
518  if (!NT_SUCCESS(Status))
519  {
520  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
521  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
522  }
523 
524  /* Release the Security Descriptor */
525  FreeDosDevicesProtection(&DosDevicesSd);
526 
527  /* Return */
528  return Status;
529 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS NTAPI GetDosDevicesProtection(OUT PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:205
LONG NTSTATUS
Definition: precomp.h:26
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
#define OBJ_OPENIF
Definition: winternl.h:229
VOID NTAPI FreeDosDevicesProtection(IN PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:388
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
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 729 of file init.c.

730 {
731  PVOID ProcessData;
732  PCSR_SERVER_DLL ServerDll;
733  ULONG i = 0;
734 
735  /* All Server DLLs are now loaded, allocate a heap for the Root Process */
736  ProcessData = RtlAllocateHeap(CsrHeap,
739  if (!ProcessData)
740  {
741  DPRINT1("CSRSRV:%s: RtlAllocateHeap failed (Status=%08lx)\n",
743  return STATUS_NO_MEMORY;
744  }
745 
746  /*
747  * Our Root Process was never officially initialized,
748  * so write the data for each Server DLL manually.
749  */
750 
751  /* Loop every DLL */
752  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
753  {
754  /* Get the current Server */
755  ServerDll = CsrLoadedServerDll[i];
756 
757  /* Is it loaded, and does it have per process data? */
758  if (ServerDll && ServerDll->SizeOfProcessData)
759  {
760  /* It does, give it part of our allocated heap */
761  CsrRootProcess->ServerData[i] = ProcessData;
762 
763  /* Move to the next heap position */
764  ProcessData = (PVOID)((ULONG_PTR)ProcessData +
765  ServerDll->SizeOfProcessData);
766  }
767  else
768  {
769  /* Nothing for this Server DLL */
771  }
772  }
773 
774  /* Now initialize the Root Process manually as well */
775  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
776  {
777  /* Get the current Server */
778  ServerDll = CsrLoadedServerDll[i];
779 
780  /* Is it loaded, and does it a callback for new processes? */
781  if (ServerDll && ServerDll->NewProcessCallback)
782  {
783  /* Call the callback */
785  }
786  }
787 
788  return STATUS_SUCCESS;
789 }
ULONG SizeOfProcessData
Definition: csrsrv.h:234
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
uint32_t ULONG_PTR
Definition: typedefs.h:64
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:3014
#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 550 of file init.c.

552 {
554  PCHAR ParameterName = NULL, ParameterValue = NULL, EntryPoint, ServerString;
555  ULONG i, DllIndex;
558 
559  /* Set the Defaults */
563 
564  /* Save our Session ID, and create a Directory for it */
565  SessionId = NtCurrentPeb()->SessionId;
567  if (!NT_SUCCESS(Status))
568  {
569  DPRINT1("CSRSS: CsrCreateSessionObjectDirectory failed (%lx)\n",
570  Status);
571 
572  /* It's not fatal if the session ID isn't zero */
573  if (SessionId != 0) return Status;
575  }
576 
577  /* Loop through every argument */
578  for (i = 1; i < ArgumentCount; i++)
579  {
580  /* Split Name and Value */
581  ParameterName = Arguments[i];
585  DPRINT("Name=%s, Value=%s\n", ParameterName, ParameterValue);
586 
587  /* Check for Object Directory */
588  if (_stricmp(ParameterName, "ObjectDirectory") == 0)
589  {
590  /* Check if a session ID is specified */
591  if (SessionId != 0)
592  {
593  DPRINT1("Sessions not yet implemented\n");
594  ASSERT(SessionId);
595  }
596 
597  /* Initialize the directory name */
600  &AnsiString,
601  TRUE);
602  ASSERT(NT_SUCCESS(Status) || SessionId != 0);
603  if (!NT_SUCCESS(Status)) return Status;
604 
605  /* Create it */
609  NULL,
610  NULL);
614  if (!NT_SUCCESS(Status)) return Status;
615 
616  /* Secure it */
618  if (!NT_SUCCESS(Status)) return Status;
619  }
620  else if (_stricmp(ParameterName, "SubSystemType") == 0)
621  {
622  /* Ignored */
623  }
624  else if (_stricmp(ParameterName, "MaxRequestThreads") == 0)
625  {
627  0,
629  }
630  else if (_stricmp(ParameterName, "RequestThreads") == 0)
631  {
632  /* Ignored */
634  }
635  else if (_stricmp(ParameterName, "ProfileControl") == 0)
636  {
637  /* Ignored */
638  }
639  else if (_stricmp(ParameterName, "SharedSection") == 0)
640  {
641  /* Create the Section */
643  if (!NT_SUCCESS(Status))
644  {
645  DPRINT1("CSRSS: *** Invalid syntax for %s=%s (Status == %X)\n",
647  return Status;
648  }
649 
650  /* Load us */
651  Status = CsrLoadServerDll("CSRSS" /* "CSRSRV" */, NULL, CSRSRV_SERVERDLL_INDEX);
652  }
653  else if (_stricmp(ParameterName, "ServerDll") == 0)
654  {
655  /* Loop the command line */
656  EntryPoint = NULL;
658  ServerString = ParameterValue;
659  while (*ServerString)
660  {
661  /* Check for the Entry Point */
662  if ((*ServerString == ':') && (!EntryPoint))
663  {
664  /* Found it. Add a nullchar and save it */
665  *ServerString++ = ANSI_NULL;
666  EntryPoint = ServerString;
667  }
668 
669  /* Check for the Dll Index */
670  if (*ServerString++ == ',') break;
671  }
672 
673  /* Did we find something to load? */
674  if (!*ServerString)
675  {
676  DPRINT1("CSRSS: *** Invalid syntax for ServerDll=%s (Status == %X)\n",
678  return Status;
679  }
680 
681  /* Convert it to a ULONG */
682  Status = RtlCharToInteger(ServerString, 10, &DllIndex);
683 
684  /* Add a null char if it was valid */
685  if (NT_SUCCESS(Status)) ServerString[-1] = ANSI_NULL;
686 
687  /* Load it */
688  if (CsrDebug & 1) DPRINT1("CSRSS: Loading ServerDll=%s:%s\n", ParameterValue, EntryPoint);
689  Status = CsrLoadServerDll(ParameterValue, EntryPoint, DllIndex);
690  if (!NT_SUCCESS(Status))
691  {
692  DPRINT1("CSRSS: *** Failed loading ServerDll=%s (Status == 0x%x)\n",
694  return Status;
695  }
696  }
697  else if (_stricmp(ParameterName, "Windows") == 0)
698  {
699  /* Ignored */
700  // Check whether we want to start in pure GUI or pure CLI.
701  }
702  else
703  {
704  /* Invalid parameter on the command line */
706  }
707  }
708 
709  /* Return status */
710  return Status;
711 }
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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI CsrSetDirectorySecurity(IN HANDLE ObjectDirectory)
Definition: init.c:182
#define _stricmp
Definition: cat.c:22
#define OBJ_OPENIF
Definition: winternl.h:229
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
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:351
NTSTATUS NTAPI CsrCreateSessionObjectDirectory(IN ULONG Session)
Definition: init.c:420
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG CsrMaxApiRequestThreads
Definition: init.c:34
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_opt_ PWSTR _In_ PWSTR _Inout_ PULONG ParameterValue
Definition: classpnp.h:1209
#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
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:3014
ULONG SessionId
Definition: init.c:33

Referenced by CsrServerInitialization().

◆ CsrPopulateDosDevices()

VOID NTAPI CsrPopulateDosDevices ( VOID  )

Definition at line 1095 of file init.c.

1096 {
1097  DPRINT1("Deprecated API in r55585.\n");
1098  return;
1099 }
#define DPRINT1
Definition: precomp.h:8

◆ CsrSbApiPortInitialize()

NTSTATUS NTAPI CsrSbApiPortInitialize ( VOID  )

Definition at line 875 of file init.c.

876 {
877  ULONG Size;
878  PSECURITY_DESCRIPTOR PortSd;
881  HANDLE hRequestThread;
883 
884  /* Calculate how much space we'll need for the Port Name */
885  Size = CsrDirectoryName.Length + sizeof(SB_PORT_NAME) + sizeof(WCHAR);
886 
887  /* Create the buffer for it */
890 
891  /* Setup the rest of the empty string */
894 
895  /* Now append the full port name */
899  if (CsrDebug & 2) DPRINT1("CSRSS: Creating %wZ port and associated thread\n", &CsrSbApiPortName);
900 
901  /* Create Security Descriptor for this Port */
902  Status = CsrCreateLocalSystemSD(&PortSd);
903  if (!NT_SUCCESS(Status)) return Status;
904 
905  /* Initialize the Attributes */
908  0,
909  NULL,
910  PortSd);
911 
912  /* Create the Port Object */
915  sizeof(SB_CONNECTION_INFO),
916  sizeof(SB_API_MSG),
917  32 * sizeof(SB_API_MSG));
918  if (PortSd) RtlFreeHeap(CsrHeap, 0, PortSd);
919 
920  if (NT_SUCCESS(Status))
921  {
922  /* Create the Thread to handle the API Requests */
924  NULL,
925  TRUE,
926  0,
927  0,
928  0,
930  NULL,
931  &hRequestThread,
932  &ClientId);
933  if (NT_SUCCESS(Status))
934  {
935  /* Add it as a Static Server Thread */
937  &ClientId,
938  0);
939 
940  /* Activate it */
941  Status = NtResumeThread(hRequestThread, NULL);
942  }
943  }
944 
945  return Status;
946 }
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:1163
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:807
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:361
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 971 of file init.c.

973 {
975 
976  /* Cache System Basic Information so we don't always request it */
978  &CsrNtSysInfo,
979  sizeof(SYSTEM_BASIC_INFORMATION),
980  NULL);
981  if (!NT_SUCCESS(Status))
982  {
983  DPRINT1("CSRSRV:%s: NtQuerySystemInformation failed (Status=0x%08lx)\n",
985  return Status;
986  }
987 
988  /* Save our Heap */
989  CsrHeap = RtlGetProcessHeap();
990 
991  /* Set our Security Descriptor to protect the process */
993  if (!NT_SUCCESS(Status))
994  {
995  DPRINT1("CSRSRV:%s: CsrSetProcessSecurity failed (Status=0x%08lx)\n",
997  return Status;
998  }
999 
1000  /* Set up Session Support */
1002  if (!NT_SUCCESS(Status))
1003  {
1004  DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=0x%08lx)\n",
1005  __FUNCTION__, Status);
1006  return Status;
1007  }
1008 
1009  /* Set up Process Support and allocate the CSR Root Process */
1011  if (!NT_SUCCESS(Status))
1012  {
1013  DPRINT1("CSRSRV:%s: CsrInitializeProcessStructure failed (Status=0x%08lx)\n",
1014  __FUNCTION__, Status);
1015  return Status;
1016  }
1017 
1018  /* Parse the command line */
1019  Status = CsrParseServerCommandLine(ArgumentCount, Arguments);
1020  if (!NT_SUCCESS(Status))
1021  {
1022  DPRINT1("CSRSRV:%s: CsrParseServerCommandLine failed (Status=0x%08lx)\n",
1023  __FUNCTION__, Status);
1024  return Status;
1025  }
1026 
1027  /* Finish to initialize the CSR Root Process */
1029  if (!NT_SUCCESS(Status))
1030  {
1031  DPRINT1("CSRSRV:%s: CsrInitCsrRootProcess failed (Status=0x%08lx)\n",
1032  __FUNCTION__, Status);
1033  return Status;
1034  }
1035 
1036  /* Now initialize our API Port */
1038  if (!NT_SUCCESS(Status))
1039  {
1040  DPRINT1("CSRSRV:%s: CsrApiPortInitialize failed (Status=0x%08lx)\n",
1041  __FUNCTION__, Status);
1042  return Status;
1043  }
1044 
1045  /* Initialize the API Port for SM communication */
1047  if (!NT_SUCCESS(Status))
1048  {
1049  DPRINT1("CSRSRV:%s: CsrSbApiPortInitialize failed (Status=0x%08lx)\n",
1050  __FUNCTION__, Status);
1051  return Status;
1052  }
1053 
1054  /* We're all set! Connect to SM! */
1056  CsrSbApiPort,
1058  &CsrSmApiPort);
1059  if (!NT_SUCCESS(Status))
1060  {
1061  DPRINT1("CSRSRV:%s: SmConnectToSm failed (Status=0x%08lx)\n",
1062  __FUNCTION__, Status);
1063  return Status;
1064  }
1065 
1066  /* Have us handle Hard Errors */
1068  if (!NT_SUCCESS(Status))
1069  {
1070  DPRINT1("CSRSRV:%s: NtSetDefaultHardErrorPort failed (Status=0x%08lx)\n",
1071  __FUNCTION__, Status);
1072  return Status;
1073  }
1074 
1075  /* Return status */
1076  return Status;
1077 }
NTSTATUS NTAPI CsrParseServerCommandLine(IN ULONG ArgumentCount, IN PCHAR Arguments[])
Definition: init.c:550
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:875
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:729
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:896
NTSTATUS NTAPI CsrInitializeNtSessionList(VOID)
Definition: session.c:53
return STATUS_SUCCESS
Definition: btrfs.c:3014
#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 182 of file init.c.

183 {
184  /* FIXME: Implement */
185  return STATUS_SUCCESS;
186 }
return STATUS_SUCCESS
Definition: btrfs.c:3014

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 */
79  {
80  NtClose(hToken);
81  goto Quickie;
82  }
83 
84  /* Allocate space for it */
86  if (!TokenInfo)
87  {
88  NtClose(hToken);
90  goto Quickie;
91  }
92 
93  /* Now query the data */
94  Status = NtQueryInformationToken(hToken, TokenUser, TokenInfo, Length, &Length);
95  NtClose(hToken);
96  if (!NT_SUCCESS(Status)) goto Quickie;
97 
98  /* Now check the SID Length */
99  UserSid = TokenInfo->User.Sid;
100  Length = RtlLengthSid(UserSid) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
101 
102  /* Allocate a buffer for the Security Descriptor, with SID and DACL */
104  if (!ProcSd)
105  {
107  goto Quickie;
108  }
109 
110  /* Set the pointer to the DACL */
112 
113  /* Now create the SD itself */
115  if (!NT_SUCCESS(Status))
116  {
117  DPRINT1("CSRSS: SD creation failed - status = %lx\n", Status);
118  goto Quickie;
119  }
120 
121  /* Create the DACL for it*/
123  if (!NT_SUCCESS(Status))
124  {
125  DPRINT1("CSRSS: DACL creation failed - status = %lx\n", Status);
126  goto Quickie;
127  }
128 
129  /* Create the ACE */
131  ACL_REVISION,
136  UserSid);
137  if (!NT_SUCCESS(Status))
138  {
139  DPRINT1("CSRSS: ACE creation failed - status = %lx\n", Status);
140  goto Quickie;
141  }
142 
143  /* Clear the DACL in the SD */
145  if (!NT_SUCCESS(Status))
146  {
147  DPRINT1("CSRSS: set DACL failed - status = %lx\n", Status);
148  goto Quickie;
149  }
150 
151  /* Write the SD into the Process */
153  if (!NT_SUCCESS(Status))
154  {
155  DPRINT1("CSRSS: set process DACL failed - status = %lx\n", Status);
156  goto Quickie;
157  }
158 
159  /* Free the memory and return */
160 Quickie:
161  if (ProcSd) RtlFreeHeap(CsrHeap, 0, ProcSd);
162  if (TokenInfo) RtlFreeHeap(CsrHeap, 0, TokenInfo);
163  return Status;
164 }
#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
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
#define PROCESS_SUSPEND_RESUME
Definition: pstypes.h:159
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
uint32_t ULONG_PTR
Definition: typedefs.h:64
#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 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:1552
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 
)

@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 1103 of file init.c.

1106 {
1107  /* We don't do much */
1108  UNREFERENCED_PARAMETER(hInstanceDll);
1110  UNREFERENCED_PARAMETER(lpReserved);
1111 
1112  return TRUE;
1113 }
#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 388 of file init.c.

389 {
390  PACL Dacl;
391  BOOLEAN Present, Default;
393 
394  /* Get the DACL corresponding to this SD */
395  Status = RtlGetDaclSecurityDescriptor(DosDevicesSd, &Present, &Dacl, &Default);
397  ASSERT(Present);
398  ASSERT(Dacl != NULL);
399 
400  /* Free it */
401  if ((NT_SUCCESS(Status)) && (Dacl)) RtlFreeHeap(CsrHeap, 0, Dacl);
402 }
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:1552
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 205 of file init.c.

206 {
210  PSID WorldSid, CreatorSid, AdminSid, SystemSid;
211  UCHAR KeyValueBuffer[0x40];
212  PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
214  ULONG ProtectionMode = 0;
216  PACL Dacl;
218  HANDLE hKey;
220  ULONG ResultLength, SidLength, AclLength;
221 
222  /* Create the SD */
225 
226  /* Initialize the System SID */
229  0, 0, 0, 0, 0, 0, 0,
230  &SystemSid);
232 
233  /* Initialize the World SID */
236  0, 0, 0, 0, 0, 0, 0,
237  &WorldSid);
239 
240  /* Initialize the Admin SID */
244  0, 0, 0, 0, 0, 0,
245  &AdminSid);
247 
248  /* Initialize the Creator SID */
249  Status = RtlAllocateAndInitializeSid(&CreatorAuthority, 1,
251  0, 0, 0, 0, 0, 0, 0,
252  &CreatorSid);
254 
255  /* Open the Session Manager Key */
258  &KeyName,
260  NULL,
261  NULL);
263  if (NT_SUCCESS(Status))
264  {
265  /* Read the key value */
266  RtlInitUnicodeString(&KeyName, L"ProtectionMode");
267  Status = NtQueryValueKey(hKey,
268  &KeyName,
270  KeyValueBuffer,
271  sizeof(KeyValueBuffer),
272  &ResultLength);
273 
274  /* Make sure it's what we expect it to be */
275  KeyValuePartialInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyValueBuffer;
276  if ((NT_SUCCESS(Status)) && (KeyValuePartialInfo->Type == REG_DWORD) &&
277  (*(PULONG)KeyValuePartialInfo->Data))
278  {
279  /* Save the Protection Mode */
280  ProtectionMode = *(PULONG)KeyValuePartialInfo->Data;
281  }
282 
283  /* Close the handle */
284  NtClose(hKey);
285  }
286 
287  /* Check the Protection Mode */
288  if (ProtectionMode & 3)
289  {
290  /* Calculate SID Lengths */
291  SidLength = RtlLengthSid(CreatorSid) + RtlLengthSid(SystemSid) +
293  AclLength = sizeof(ACL) + 3 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
294 
295  /* Allocate memory for the DACL */
297  ASSERT(Dacl != NULL);
298 
299  /* Build the ACL and add 3 ACEs */
308 
309  /* Edit the ACEs to make them inheritable */
310  Status = RtlGetAce(Dacl, 0, (PVOID*)&Ace);
312  Ace->Header.AceFlags |= OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE;
313  Status = RtlGetAce(Dacl, 1, (PVOID*)&Ace);
315  Ace->Header.AceFlags |= OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE;
316  Status = RtlGetAce(Dacl, 2, (PVOID*)&Ace);
319 
320  /* Set this DACL with the SD */
323  goto Quickie;
324  }
325  else
326  {
327  /* Calculate SID Lengths */
328  SidLength = RtlLengthSid(WorldSid) + RtlLengthSid(SystemSid);
329  AclLength = sizeof(ACL) + 3 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
330 
331  /* Allocate memory for the DACL */
333  ASSERT(Dacl != NULL);
334 
335  /* Build the ACL and add 3 ACEs */
344 
345  /* Edit the last ACE to make it inheritable */
346  Status = RtlGetAce(Dacl, 2, (PVOID*)&Ace);
349 
350  /* Set this DACL with the SD */
353  goto Quickie;
354  }
355 
356 /* FIXME: failure cases! Fail: */
357  /* Free the memory */
358  RtlFreeHeap(CsrHeap, 0, Dacl);
359 
360 /* FIXME: semi-failure cases! Quickie: */
361 Quickie:
362  /* Free the SIDs */
363  RtlFreeSid(CreatorSid);
366  RtlFreeSid(SystemSid);
367 
368  /* Return */
369  return Status;
370 }
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
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
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 WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
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 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 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
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:1552
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().