[NTDLL/KERNEL32]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 20 Oct 2012 21:03:32 +0000 (21:03 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 20 Oct 2012 21:03:32 +0000 (21:03 +0000)
- Use new naming scheme.

[CSRSRV]
- Continuing headers reorganization.
- Activate new code.

[CSRSRV/WIN32CSR]
- Move some code into basesrv.

[BASESRV]
- Add basesrv.dll
The names of the APIs tables come from http://j00ru.vexillium.org/csrss_list/api_list.html as usual,
however I used the NT 4 ones for testing purposes only. After that I will update them to 2k3 version
and add function stubs. Also some variable names are deduced from the subsystems/win32/csrss/csrsrv/server.c ones.

svn path=/branches/ros-csrss/; revision=57587

27 files changed:
dll/ntdll/csr/api.c
dll/win32/kernel32/client/dosdev.c
dll/win32/kernel32/client/file/deviceio.c
dll/win32/kernel32/client/file/filename.c
dll/win32/kernel32/client/proc.c
dll/win32/kernel32/client/vdm.c
include/reactos/subsys/csrss/csrss.h
include/reactos/subsys/win/base.h
include/reactos/subsys/win/console.h [moved from include/reactos/subsys/csrss/csrcons.h with 55% similarity]
include/reactos/subsys/win/windows.h
subsystems/win/basesrv/CMakeLists.txt [new file with mode: 0644]
subsystems/win/basesrv/basesrv.def [deleted file]
subsystems/win/basesrv/basesrv.h
subsystems/win/basesrv/basesrv.rc
subsystems/win/basesrv/basesrv.spec [new file with mode: 0644]
subsystems/win/basesrv/init.c
subsystems/win/basesrv/main.c [deleted file]
subsystems/win/basesrv/server.c
subsystems/win32/csrsrv/api/process.c
subsystems/win32/csrsrv/api/wapi.c
subsystems/win32/csrsrv/init.c
subsystems/win32/csrsrv/procsup.c
subsystems/win32/csrsrv/server.c
win32ss/user/win32csr/CMakeLists.txt
win32ss/user/win32csr/dllmain.c
win32ss/user/win32csr/file.c [deleted file]
win32ss/user/win32csr/file.h [deleted file]

index 965fe5c..9b5b054 100644 (file)
@@ -48,7 +48,7 @@ CsrSetPriorityClass(HANDLE hProcess,
     /* Call it */
     Status = CsrClientCallServer(&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_SRV_SERVER, CsrpSetPriorityClass),
+                                 CSR_CREATE_API_NUMBER(CSRSRV_SERVERDLL_INDEX, CsrpSetPriorityClass),
                                  sizeof(CSR_SET_PRIORITY_CLASS));
     
     /* Return what we got, if requested */
@@ -63,7 +63,7 @@ CsrSetPriorityClass(HANDLE hProcess,
  */
 NTSTATUS
 NTAPI
-CsrIdentifyAlertableThread (VOID)
+CsrIdentifyAlertableThread(VOID)
 {
     NTSTATUS Status;
     CSR_API_MESSAGE ApiMessage;
@@ -77,7 +77,7 @@ CsrIdentifyAlertableThread (VOID)
     /* Call it */
     Status = CsrClientCallServer(&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_SRV_SERVER, CsrpIdentifyAlertable),
+                                 CSR_CREATE_API_NUMBER(CSRSRV_SERVERDLL_INDEX, CsrpIdentifyAlertable),
                                  sizeof(CSR_SET_PRIORITY_CLASS));
 
     /* Return to caller */
index 3da3ec8..2882de5 100644 (file)
@@ -4,7 +4,7 @@
  * PROJECT:         ReactOS system libraries
  * FILE:            lib/kernel32/file/dosdev.c
  * PURPOSE:         Dos device functions
- * PROGRAMMER:      Ariadne ( ariadne@xs4all.nl)
+ * PROGRAMMER:      Ariadne (ariadne@xs4all.nl)
  * UPDATE HISTORY:
  *                  Created 01/11/98
  */
@@ -183,7 +183,7 @@ DefineDosDeviceW(
 
         Status = CsrClientCallServer(&Request,
                                      CaptureBuffer,
-                                     CSR_CREATE_API_NUMBER(CSR_CONSOLE, DEFINE_DOS_DEVICE),
+                                     CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepDefineDosDevice),
                                      sizeof(CSR_API_MESSAGE));
         CsrFreeCaptureBuffer(CaptureBuffer);
 
index 28eab55..4d67961 100644 (file)
@@ -31,7 +31,7 @@ NotifySoundSentry(VOID)
     {
         CsrClientCallServer(&ApiMessage,
                             NULL,
-                            CSR_CREATE_API_NUMBER(CSR_NATIVE, SOUND_SENTRY),
+                            CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSoundSentryNotification),
                             sizeof(CSR_API_MESSAGE));
     }
 }
index 6a3e210..1e94be3 100644 (file)
@@ -160,7 +160,7 @@ GetTempFileNameW(IN LPCWSTR lpPathName,
         {
             CsrClientCallServer(&ApiMessage,
                                 NULL,
-                                CSR_CREATE_API_NUMBER(CSR_NATIVE, GET_TEMP_FILE),
+                                CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetTempFile),
                                 sizeof(CSR_API_MESSAGE));
             if (ApiMessage.Data.GetTempFile.UniqueID == 0)
             {
index 601e688..921c669 100644 (file)
@@ -494,7 +494,6 @@ WINAPI
 BasepNotifyCsrOfThread(IN HANDLE ThreadHandle,
                        IN PCLIENT_ID ClientId)
 {
-    ULONG Request = CREATE_THREAD;
     CSR_API_MESSAGE CsrRequest;
     NTSTATUS Status;
 
@@ -508,7 +507,7 @@ BasepNotifyCsrOfThread(IN HANDLE ThreadHandle,
     /* Call CSR */
     Status = CsrClientCallServer(&CsrRequest,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, Request),
+                                 CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateThread),
                                  sizeof(CSR_API_MESSAGE));
     if (!NT_SUCCESS(Status) || !NT_SUCCESS(CsrRequest.Status))
     {
@@ -538,7 +537,6 @@ BasepCreateFirstThread(HANDLE ProcessHandle,
     INITIAL_TEB InitialTeb;
     NTSTATUS Status;
     HANDLE hThread;
-    ULONG Request = CREATE_PROCESS;
     CSR_API_MESSAGE CsrRequest;
     DPRINT("BasepCreateFirstThread. hProcess: %lx\n", ProcessHandle);
 
@@ -584,7 +582,7 @@ BasepCreateFirstThread(HANDLE ProcessHandle,
     /* Call CSR */
     Status = CsrClientCallServer(&CsrRequest,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, Request),
+                                 CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateProcess),
                                  sizeof(CSR_API_MESSAGE));
     if (!NT_SUCCESS(Status) || !NT_SUCCESS(CsrRequest.Status))
     {
@@ -1182,7 +1180,7 @@ GetProcessShutdownParameters(OUT LPDWORD lpdwLevel,
     /* Ask CSRSS for shutdown information */
     Status = CsrClientCallServer(&CsrRequest,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, GET_SHUTDOWN_PARAMETERS),
+                                 CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetProcessShutdownParam),
                                  sizeof(CSR_API_MESSAGE));
     if (!(NT_SUCCESS(Status)) || !(NT_SUCCESS(CsrRequest.Status)))
     {
@@ -1213,7 +1211,7 @@ SetProcessShutdownParameters(IN DWORD dwLevel,
     CsrRequest.Data.SetShutdownParametersRequest.Flags = dwFlags;
     Status = CsrClientCallServer(&CsrRequest,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, SET_SHUTDOWN_PARAMETERS),
+                                 CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetProcessShutdownParam),
                                  sizeof(CSR_API_MESSAGE));
     if (!NT_SUCCESS(Status) || !NT_SUCCESS(CsrRequest.Status))
     {
@@ -1760,7 +1758,7 @@ ExitProcess(IN UINT uExitCode)
         CsrRequest.Data.TerminateProcessRequest.uExitCode = uExitCode;
         CsrClientCallServer(&CsrRequest,
                             NULL,
-                            CSR_CREATE_API_NUMBER(CSR_NATIVE, TERMINATE_PROCESS),
+                            CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepExitProcess),
                             sizeof(CSR_API_MESSAGE));
 
         /* Now do it again */
index 166cd21..8035587 100644 (file)
@@ -134,7 +134,7 @@ BaseUpdateVDMEntry(IN ULONG UpdateIndex,
     /* Send the message to CSRSS */
     Status = CsrClientCallServer(&Msg,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, UPDATE_VDM_ENTRY),
+                                 CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepUpdateVDMEntry),
                                  sizeof(Msg));
     if (!(NT_SUCCESS(Status)) || !(NT_SUCCESS(Msg.Status)))
     {
@@ -178,7 +178,7 @@ BaseCheckForVDM(IN HANDLE ProcessHandle,
     /* Call CSRSS */
     Status = CsrClientCallServer(&Msg,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_VDM_EXIT_CODE),
+                                 CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCheckVDM /* BasepGetVDMExitCode */),
                                  sizeof(Msg));
     if (!NT_SUCCESS(Status)) return FALSE;
 
index 0638562..c3f233d 100644 (file)
@@ -3,9 +3,9 @@
 #ifndef __INCLUDE_CSRSS_CSRSS_H
 #define __INCLUDE_CSRSS_CSRSS_H
 
-#define CSR_NATIVE     0x0000
-#define CSR_CONSOLE    0x0001
-#define CSR_GUI        0x0002
+#define CSR_NATIVE     0x0000   // CSRSRV
+#define CSR_CONSOLE    0x0001   // WIN32CSR
+#define CSR_GUI        0x0002   // WINSRV
 #define CONSOLE_INPUT_MODE_VALID  (0x0f)
 #define CONSOLE_OUTPUT_MODE_VALID (0x03)
 
 
 typedef VOID (CALLBACK *PCONTROLDISPATCHER)(DWORD);
 
-typedef struct
-{
-    ULONG Dummy;
-} CSRSS_CONNECT_PROCESS, *PCSRSS_CONNECT_PROCESS;
-
-typedef struct _BASE_SXS_CREATEPROCESS_MSG
-{
-    ULONG Flags;
-    ULONG ProcessParameterFlags;
-    HANDLE FileHandle;    
-    UNICODE_STRING SxsWin32ExePath;
-    UNICODE_STRING SxsNtExePath;
-    SIZE_T OverrideManifestOffset;
-    ULONG OverrideManifestSize;
-    SIZE_T OverridePolicyOffset;
-    ULONG OverridePolicySize;
-    PVOID PEManifestAddress;
-    ULONG PEManifestSize;
-    UNICODE_STRING CultureFallbacks;
-    ULONG Unknown[7];
-    UNICODE_STRING AssemblyName;
-} BASE_SXS_CREATEPROCESS_MSG, *PBASE_SXS_CREATEPROCESS_MSG;
-
-typedef struct
-{
-    //
-    // NT-type structure (BASE_CREATEPROCESS_MSG)
-    //
-    HANDLE ProcessHandle;
-    HANDLE ThreadHandle;
-    CLIENT_ID ClientId;
-    ULONG CreationFlags;
-    ULONG VdmBinaryType;
-    ULONG VdmTask;
-    HANDLE hVDM;
-    BASE_SXS_CREATEPROCESS_MSG Sxs;
-    PVOID PebAddressNative;
-    ULONG PebAddressWow64;
-    USHORT ProcessorArchitecture;
-
-    //
-    // ReactOS Data
-    //
-    BOOL bInheritHandles;
-} CSRSS_CREATE_PROCESS, *PCSRSS_CREATE_PROCESS;
-
-typedef struct
-{
-    CLIENT_ID ClientId;
-    HANDLE ThreadHandle;
-} CSRSS_CREATE_THREAD, *PCSRSS_CREATE_THREAD;
-
-typedef struct
-{
-    UINT uExitCode;
-} CSRSS_TERMINATE_PROCESS, *PCSRSS_TERMINATE_PROCESS;
-
 typedef struct
 {
     USHORT nMaxIds;
@@ -78,8 +21,6 @@ typedef struct
     ULONG nProcessIdsTotal;
 } CSRSS_GET_PROCESS_LIST, *PCSRSS_GET_PROCESS_LIST;
 
-#include "csrcons.h"
-
 typedef struct
 {
     HANDLE  UniqueThread;
@@ -97,18 +38,6 @@ typedef struct
     DWORD Reserved;
 } CSRSS_EXIT_REACTOS, *PCSRSS_EXIT_REACTOS;
 
-typedef struct
-{
-    DWORD Level;
-    DWORD Flags;
-} CSRSS_SET_SHUTDOWN_PARAMETERS, *PCSRSS_SET_SHUTDOWN_PARAMETERS;
-
-typedef struct
-{
-    DWORD Level;
-    DWORD Flags;
-} CSRSS_GET_SHUTDOWN_PARAMETERS, *PCSRSS_GET_SHUTDOWN_PARAMETERS;
-
 typedef struct
 {
     HANDLE Handle;
@@ -160,239 +89,21 @@ typedef struct
     HANDLE InputWaitHandle;
 } CSRSS_GET_INPUT_WAIT_HANDLE, *PCSRSS_GET_INPUT_WAIT_HANDLE;
 
-typedef struct
-{
-    UINT UniqueID;
-} CSRSS_GET_TEMP_FILE, *PCSRSS_GET_TEMP_FILE;
-
-typedef struct
-{
-    UNICODE_STRING DeviceName;
-    UNICODE_STRING TargetName;
-    DWORD dwFlags;
-} CSRSS_DEFINE_DOS_DEVICE, *PCSRSS_DEFINE_DOS_DEVICE;
-
-typedef struct
-{
-    ULONG VideoMode;
-} CSRSS_SOUND_SENTRY, *PCSRSS_SOUND_SENTRY;
-
-typedef struct
-{
-    ULONG iTask;
-    ULONG BinaryType;
-    HANDLE ConsoleHandle;
-    HANDLE VDMProcessHandle;
-    HANDLE WaitObjectForParent;
-    USHORT EntryIndex;
-    USHORT VDMCreationState;
-} CSRSS_UPDATE_VDM_ENTRY, *PCSRSS_UPDATE_VDM_ENTRY;
-
-typedef struct
-{
-    HANDLE ConsoleHandle;
-    HANDLE hParent;
-    ULONG ExitCode;
-} CSRSS_GET_VDM_EXIT_CODE, *PCSRSS_GET_VDM_EXIT_CODE;
-
-typedef struct
-{
-    ULONG iTask;
-    HANDLE ConsoleHandle;
-    ULONG BinaryType;
-    HANDLE WaitObjectForParent;
-    HANDLE StdIn;
-    HANDLE StdOut;
-    HANDLE StdErr;
-    ULONG CodePage;
-    ULONG dwCreationFlags;
-    PCHAR CmdLine;
-    PCHAR appName;
-    PCHAR PifFile;
-    PCHAR CurDirectory;
-    PCHAR Env;
-    ULONG EnvLen;
-    PVOID StartupInfo;
-    PCHAR Desktop;
-    ULONG DesktopLen;
-    PCHAR Title;
-    ULONG TitleLen;
-    PCHAR Reserved;
-    ULONG ReservedLen;
-    USHORT CmdLen;
-    USHORT AppLen;
-    USHORT PifLen;
-    USHORT CurDirectoryLen;
-    USHORT CurDrive;
-    USHORT VDMState;
-} CSRSS_CHECK_VDM, *PCSRSS_CHECK_VDM;
-
 #define CSR_API_MESSAGE_HEADER_SIZE(Type)       (FIELD_OFFSET(CSR_API_MESSAGE, Data) + sizeof(Type))
-#define CSRSS_MAX_WRITE_CONSOLE                 (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE))
-#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR     (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR))
-#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB   (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB))
-#define CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR      (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR))
-#define CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB    (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB))
 
-#define CREATE_PROCESS                  (0x0)
-#define TERMINATE_PROCESS               (0x1)
-#define WRITE_CONSOLE                   (0x2)
-#define READ_CONSOLE                    (0x3)
-#define ALLOC_CONSOLE                   (0x4)
-#define FREE_CONSOLE                    (0x5)
-#define CONNECT_PROCESS                 (0x6)
-#define SCREEN_BUFFER_INFO              (0x7)
-#define SET_CURSOR                      (0x8)
-#define FILL_OUTPUT                     (0x9)
-#define READ_INPUT                      (0xA)
-#define WRITE_CONSOLE_OUTPUT_CHAR       (0xB)
-#define WRITE_CONSOLE_OUTPUT_ATTRIB     (0xC)
-#define FILL_OUTPUT_ATTRIB              (0xD)
-#define GET_CURSOR_INFO                 (0xE)
-#define SET_CURSOR_INFO                 (0xF)
-#define SET_ATTRIB                      (0x10)
-#define GET_CONSOLE_MODE                (0x11)
-#define SET_CONSOLE_MODE                (0x12)
-#define CREATE_SCREEN_BUFFER            (0x13)
-#define SET_SCREEN_BUFFER               (0x14)
-#define SET_TITLE                       (0x15)
-#define GET_TITLE                       (0x16)
-#define WRITE_CONSOLE_OUTPUT            (0x17)
-#define FLUSH_INPUT_BUFFER              (0x18)
-#define SCROLL_CONSOLE_SCREEN_BUFFER    (0x19)
-#define READ_CONSOLE_OUTPUT_CHAR        (0x1A)
-#define READ_CONSOLE_OUTPUT_ATTRIB      (0x1B)
-#define GET_NUM_INPUT_EVENTS            (0x1C)
 #define REGISTER_SERVICES_PROCESS       (0x1D)
 #define EXIT_REACTOS                    (0x1E)
-#define GET_SHUTDOWN_PARAMETERS         (0x1F)
-#define SET_SHUTDOWN_PARAMETERS         (0x20)
-#define PEEK_CONSOLE_INPUT              (0x21)
-#define READ_CONSOLE_OUTPUT             (0x22)
-#define WRITE_CONSOLE_INPUT             (0x23)
-#define GET_INPUT_HANDLE                (0x24)
-#define GET_OUTPUT_HANDLE               (0x25)
 #define CLOSE_HANDLE                    (0x26)
 #define VERIFY_HANDLE                   (0x27)
 #define DUPLICATE_HANDLE                (0x28)
-#define SETGET_CONSOLE_HW_STATE         (0x29)
-#define GET_CONSOLE_WINDOW              (0x2A)
 #define CREATE_DESKTOP                  (0x2B)
 #define SHOW_DESKTOP                    (0x2C)
 #define HIDE_DESKTOP                    (0x2D)
-#define SET_CONSOLE_ICON                (0x2E)
 #define SET_LOGON_NOTIFY_WINDOW         (0x2F)
 #define REGISTER_LOGON_PROCESS          (0x30)
-#define GET_CONSOLE_CP                  (0x31)
-#define SET_CONSOLE_CP                  (0x32)
-#define GET_CONSOLE_OUTPUT_CP           (0x33)
-#define SET_CONSOLE_OUTPUT_CP           (0x34)
 #define GET_INPUT_WAIT_HANDLE           (0x35)
 #define GET_PROCESS_LIST                (0x36)
 #define START_SCREEN_SAVER              (0x37)
-#define ADD_CONSOLE_ALIAS               (0x38)
-#define GET_CONSOLE_ALIAS               (0x39)
-#define GET_ALL_CONSOLE_ALIASES         (0x3A)
-#define GET_ALL_CONSOLE_ALIASES_LENGTH  (0x3B)
-#define GET_CONSOLE_ALIASES_EXES        (0x3C)
-#define GET_CONSOLE_ALIASES_EXES_LENGTH (0x3D)
-#define GENERATE_CTRL_EVENT             (0x3E)
-#define CREATE_THREAD                   (0x3F)
-#define SET_SCREEN_BUFFER_SIZE          (0x40)
-#define GET_CONSOLE_SELECTION_INFO      (0x41)
-#define GET_COMMAND_HISTORY_LENGTH      (0x42)
-#define GET_COMMAND_HISTORY             (0x43)
-#define EXPUNGE_COMMAND_HISTORY         (0x44)
-#define SET_HISTORY_NUMBER_COMMANDS     (0x45)
-#define GET_HISTORY_INFO                (0x46)
-#define SET_HISTORY_INFO                (0x47)
-#define GET_TEMP_FILE                   (0x48)
-#define DEFINE_DOS_DEVICE               (0x49)
-#define SOUND_SENTRY                    (0x50)
-#define UPDATE_VDM_ENTRY                (0x51)
-#define GET_VDM_EXIT_CODE               (0x52)
-#define CHECK_VDM                       (0x53)
-
-
-typedef struct _NLS_USER_INFO
-{
-    WCHAR iCountry[80];
-    WCHAR sCountry[80];
-    WCHAR sList[80];
-    WCHAR iMeasure[80];
-    WCHAR iPaperSize[80];
-    WCHAR sDecimal[80];
-    WCHAR sThousand[80];
-    WCHAR sGrouping[80];
-    WCHAR iDigits[80];
-    WCHAR iLZero[80];
-    WCHAR iNegNumber[80];
-    WCHAR sNativeDigits[80];
-    WCHAR iDigitSubstitution[80];
-    WCHAR sCurrency[80];
-    WCHAR sMonDecSep[80];
-    WCHAR sMonThouSep[80];
-    WCHAR sMonGrouping[80];
-    WCHAR iCurrDigits[80];
-    WCHAR iCurrency[80];
-    WCHAR iNegCurr[80];
-    WCHAR sPosSign[80];
-    WCHAR sNegSign[80];
-    WCHAR sTimeFormat[80];
-    WCHAR s1159[80];
-    WCHAR s2359[80];
-    WCHAR sShortDate[80];
-    WCHAR sYearMonth[80];
-    WCHAR sLongDate[80];
-    WCHAR iCalType[80];
-    WCHAR iFirstDay[80];
-    WCHAR iFirstWeek[80];
-    WCHAR sLocale[80];
-    WCHAR sLocaleName[85];
-    LCID UserLocaleId;
-    LUID InteractiveUserLuid;
-    CHAR InteractiveUserSid[68]; // SECURITY_MAX_SID_SIZE to make ROS happy
-    ULONG ulCacheUpdateCount;
-} NLS_USER_INFO, *PNLS_USER_INFO;
-
-
-typedef struct _BASE_STATIC_SERVER_DATA
-{
-    UNICODE_STRING WindowsDirectory;
-    UNICODE_STRING WindowsSystemDirectory;
-    UNICODE_STRING NamedObjectDirectory;
-    USHORT WindowsMajorVersion;
-    USHORT WindowsMinorVersion;
-    USHORT BuildNumber;
-    USHORT CSDNumber;
-    USHORT RCNumber;
-    WCHAR CSDVersion[128];
-    SYSTEM_BASIC_INFORMATION SysInfo;
-    SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay;
-    PVOID IniFileMapping;
-    NLS_USER_INFO NlsUserInfo;
-    BOOLEAN DefaultSeparateVDM;
-    BOOLEAN IsWowTaskReady;
-    UNICODE_STRING WindowsSys32x86Directory;
-    BOOLEAN fTermsrvAppInstallMode;
-    TIME_ZONE_INFORMATION tziTermsrvClientTimeZone;
-    KSYSTEM_TIME ktTermsrvClientBias;
-    ULONG TermsrvClientTimeZoneId;
-    BOOLEAN LUIDDeviceMapsEnabled;
-    ULONG TermsrvClientTimeZoneChangeNum;
-} BASE_STATIC_SERVER_DATA, *PBASE_STATIC_SERVER_DATA;
-
 
-/* Types used in the new CSR. Temporarly here for proper compile of NTDLL */
-// Not used at the moment...
-typedef enum _CSR_SRV_API_NUMBER
-{
-    CsrpClientConnect,
-    CsrpThreadConnect,
-    CsrpProfileControl,
-    CsrpIdentifyAlertable,
-    CsrpSetPriorityClass,
-    CsrpMaxApiNumber
-} CSR_SRV_API_NUMBER, *PCSR_SRV_API_NUMBER;
 
 #endif /* __INCLUDE_CSRSS_CSRSS_H */
index a064f1b..b69587b 100644 (file)
@@ -1,16 +1,17 @@
-#if !defined(__INCLUDE_WIN_BASE_H)
-#define __INCLUDE_WIN_BASE_H
+/*** Public header for BASESRV and the rest ***/
 
-#include <csr/protocol.h>
+#ifndef __INCLUDE_WIN_BASE_H
+#define __INCLUDE_WIN_BASE_H
 
-/* w32 base server */
+//#include <csr/protocol.h>
 
-#define WIN_SRV_BASE 1
+/* Base Server */
 
 typedef VOID (CALLBACK * BASE_PROCESS_CREATE_NOTIFY_ROUTINE)(PVOID);
 
 NTSTATUS WINAPI BaseSetProcessCreateNotify (BASE_PROCESS_CREATE_NOTIFY_ROUTINE);
-NTSTATUS WINAPI ServerDllInitialization (ULONG,LPWSTR*);
+CSR_SERVER_DLL_INIT(ServerDllInitialization);
 
-#endif /* ndef __INCLUDE_WIN_BASE_H */
+#endif // __INCLUDE_WIN_BASE_H
 
+/* EOF */
similarity index 55%
rename from include/reactos/subsys/csrss/csrcons.h
rename to include/reactos/subsys/win/console.h
index ce7e7d0..6bb5785 100644 (file)
@@ -7,6 +7,72 @@
 
 #include <drivers/blue/ntddblue.h>
 
+
+
+#define CSRSS_MAX_WRITE_CONSOLE                 (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE))
+#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR     (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR))
+#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB   (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB))
+#define CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR      (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR))
+#define CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB    (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB))
+
+#define WRITE_CONSOLE                   (0x2)
+#define READ_CONSOLE                    (0x3)
+#define ALLOC_CONSOLE                   (0x4)
+#define FREE_CONSOLE                    (0x5)
+#define SCREEN_BUFFER_INFO              (0x7)
+#define SET_CURSOR                      (0x8)
+#define FILL_OUTPUT                     (0x9)
+#define READ_INPUT                      (0xA)
+#define WRITE_CONSOLE_OUTPUT_CHAR       (0xB)
+#define WRITE_CONSOLE_OUTPUT_ATTRIB     (0xC)
+#define FILL_OUTPUT_ATTRIB              (0xD)
+#define GET_CURSOR_INFO                 (0xE)
+#define SET_CURSOR_INFO                 (0xF)
+#define SET_ATTRIB                      (0x10)
+#define GET_CONSOLE_MODE                (0x11)
+#define SET_CONSOLE_MODE                (0x12)
+#define CREATE_SCREEN_BUFFER            (0x13)
+#define SET_SCREEN_BUFFER               (0x14)
+#define SET_TITLE                       (0x15)
+#define GET_TITLE                       (0x16)
+#define WRITE_CONSOLE_OUTPUT            (0x17)
+#define FLUSH_INPUT_BUFFER              (0x18)
+#define SCROLL_CONSOLE_SCREEN_BUFFER    (0x19)
+#define READ_CONSOLE_OUTPUT_CHAR        (0x1A)
+#define READ_CONSOLE_OUTPUT_ATTRIB      (0x1B)
+#define GET_NUM_INPUT_EVENTS            (0x1C)
+#define PEEK_CONSOLE_INPUT              (0x21)
+#define READ_CONSOLE_OUTPUT             (0x22)
+#define WRITE_CONSOLE_INPUT             (0x23)
+#define GET_INPUT_HANDLE                (0x24)
+#define GET_OUTPUT_HANDLE               (0x25)
+#define SETGET_CONSOLE_HW_STATE         (0x29)
+#define GET_CONSOLE_WINDOW              (0x2A)
+#define SET_CONSOLE_ICON                (0x2E)
+#define GET_CONSOLE_CP                  (0x31)
+#define SET_CONSOLE_CP                  (0x32)
+#define GET_CONSOLE_OUTPUT_CP           (0x33)
+#define SET_CONSOLE_OUTPUT_CP           (0x34)
+#define ADD_CONSOLE_ALIAS               (0x38)
+#define GET_CONSOLE_ALIAS               (0x39)
+#define GET_ALL_CONSOLE_ALIASES         (0x3A)
+#define GET_ALL_CONSOLE_ALIASES_LENGTH  (0x3B)
+#define GET_CONSOLE_ALIASES_EXES        (0x3C)
+#define GET_CONSOLE_ALIASES_EXES_LENGTH (0x3D)
+#define GENERATE_CTRL_EVENT             (0x3E)
+#define SET_SCREEN_BUFFER_SIZE          (0x40)
+#define GET_CONSOLE_SELECTION_INFO      (0x41)
+#define GET_COMMAND_HISTORY_LENGTH      (0x42)
+#define GET_COMMAND_HISTORY             (0x43)
+#define EXPUNGE_COMMAND_HISTORY         (0x44)
+#define SET_HISTORY_NUMBER_COMMANDS     (0x45)
+#define GET_HISTORY_INFO                (0x46)
+#define SET_HISTORY_INFO                (0x47)
+
+
+
+
+
 typedef struct
 {
     HANDLE ConsoleHandle;
@@ -387,6 +453,77 @@ typedef struct
     UINT CodePage;
 } CSRSS_SET_CONSOLE_OUTPUT_CP, *PCSRSS_SET_CONSOLE_OUTPUT_CP;
 
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
+                CSRSS_WRITE_CONSOLE WriteConsoleRequest;
+                CSRSS_READ_CONSOLE ReadConsoleRequest;
+                CSRSS_ALLOC_CONSOLE AllocConsoleRequest;
+                CSRSS_FREE_CONSOLE FreeConsoleRequest;
+                CSRSS_SCREEN_BUFFER_INFO ScreenBufferInfoRequest;
+                CSRSS_SET_CURSOR SetCursorRequest;
+                CSRSS_FILL_OUTPUT FillOutputRequest;
+                CSRSS_FILL_OUTPUT_ATTRIB FillOutputAttribRequest;
+                CSRSS_READ_INPUT ReadInputRequest;
+                CSRSS_WRITE_CONSOLE_OUTPUT_CHAR WriteConsoleOutputCharRequest;
+                CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB WriteConsoleOutputAttribRequest;
+                CSRSS_GET_CURSOR_INFO GetCursorInfoRequest;
+                CSRSS_SET_CURSOR_INFO SetCursorInfoRequest;
+                CSRSS_SET_ATTRIB SetAttribRequest;
+                CSRSS_SET_CONSOLE_MODE SetConsoleModeRequest;
+                CSRSS_GET_CONSOLE_MODE GetConsoleModeRequest;
+                CSRSS_CREATE_SCREEN_BUFFER CreateScreenBufferRequest;
+                CSRSS_SET_SCREEN_BUFFER SetScreenBufferRequest;
+                CSRSS_SET_TITLE SetTitleRequest;
+                CSRSS_GET_TITLE GetTitleRequest;
+                CSRSS_WRITE_CONSOLE_OUTPUT WriteConsoleOutputRequest;
+                CSRSS_FLUSH_INPUT_BUFFER FlushInputBufferRequest;
+                CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER ScrollConsoleScreenBufferRequest;
+                CSRSS_READ_CONSOLE_OUTPUT_CHAR ReadConsoleOutputCharRequest;
+                CSRSS_READ_CONSOLE_OUTPUT_ATTRIB ReadConsoleOutputAttribRequest;
+                CSRSS_PEEK_CONSOLE_INPUT PeekConsoleInputRequest;
+                CSRSS_READ_CONSOLE_OUTPUT ReadConsoleOutputRequest;
+                CSRSS_WRITE_CONSOLE_INPUT WriteConsoleInputRequest;
+                CSRSS_GET_INPUT_HANDLE GetInputHandleRequest;
+                CSRSS_GET_OUTPUT_HANDLE GetOutputHandleRequest;
+                CSRSS_SETGET_CONSOLE_HW_STATE ConsoleHardwareStateRequest;
+                CSRSS_GET_CONSOLE_WINDOW GetConsoleWindowRequest;
+                CSRSS_SET_CONSOLE_ICON SetConsoleIconRequest;
+                CSRSS_ADD_CONSOLE_ALIAS AddConsoleAlias;
+                CSRSS_GET_CONSOLE_ALIAS GetConsoleAlias;
+                CSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAlias;
+                CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH GetAllConsoleAliasesLength;
+                CSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes;
+                CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength;
+                CSRSS_GENERATE_CTRL_EVENT GenerateCtrlEvent;
+                CSRSS_GET_NUM_INPUT_EVENTS GetNumInputEventsRequest;
+                CSRSS_SET_SCREEN_BUFFER_SIZE SetScreenBufferSize;
+                CSRSS_GET_CONSOLE_SELECTION_INFO GetConsoleSelectionInfo;
+                CSRSS_GET_COMMAND_HISTORY_LENGTH GetCommandHistoryLength;
+                CSRSS_GET_COMMAND_HISTORY GetCommandHistory;
+                CSRSS_EXPUNGE_COMMAND_HISTORY ExpungeCommandHistory;
+                CSRSS_SET_HISTORY_NUMBER_COMMANDS SetHistoryNumberCommands;
+                CSRSS_GET_HISTORY_INFO GetHistoryInfo;
+                CSRSS_SET_HISTORY_INFO SetHistoryInfo;
+                CSRSS_GET_CONSOLE_CP GetConsoleCodePage;
+                CSRSS_SET_CONSOLE_CP SetConsoleCodePage;
+                CSRSS_GET_CONSOLE_OUTPUT_CP GetConsoleOutputCodePage;
+                CSRSS_SET_CONSOLE_OUTPUT_CP SetConsoleOutputCodePage;
+
+#endif
+
+
+
 #endif // __CSRCONS_H__
 
 /* EOF */
index 0e42ea0..5883ff4 100644 (file)
@@ -4,12 +4,10 @@
 #include <csr/protocol.h>
 
 /* w32 console server */
-#define WIN_SRV_WIN_CONSOLE  2
-NTSTATUS WINAPI ConServerDllInitialization (ULONG,LPWSTR*);
+CSR_SERVER_DLL_INIT(ConServerDllInitialization);
 
 /* w32 user server */
-#define WIN_SRV_WIN_USER     3
-NTSTATUS WINAPI UserServerDllInitialization (ULONG,LPWSTR*);
+CSR_SERVER_DLL_INIT(UserServerDllInitialization);
 
 #endif /* ndef __INCLUDE_WIN_WINDOWS_H */
 
diff --git a/subsystems/win/basesrv/CMakeLists.txt b/subsystems/win/basesrv/CMakeLists.txt
new file mode 100644 (file)
index 0000000..61c4723
--- /dev/null
@@ -0,0 +1,24 @@
+
+include_directories(${REACTOS_SOURCE_DIR}/subsystems/win32/csrss/include
+                    ${REACTOS_SOURCE_DIR}/include/reactos/subsys)
+
+spec2def(basesrv.dll basesrv.spec)
+
+list(APPEND SOURCE
+    init.c
+    server.c
+    basesrv.rc
+    ${CMAKE_CURRENT_BINARY_DIR}/basesrv.def)
+
+add_library(basesrv SHARED ${SOURCE})
+
+target_link_libraries(basesrv ${PSEH_LIB})
+
+set_module_type(basesrv win32dll)
+
+add_importlibs(basesrv ntdll csrsrv)
+
+#add_pch(basesrv w32csr.h)
+
+add_dependencies(basesrv bugcodes)
+add_cd_file(TARGET basesrv DESTINATION reactos/system32 FOR all)
diff --git a/subsystems/win/basesrv/basesrv.def b/subsystems/win/basesrv/basesrv.def
deleted file mode 100644 (file)
index ae74aea..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-; $Id$
-LIBRARY basesrv.dll
-EXPORTS
-BaseSetProcessCreateNotify@4
-ServerDllInitialization@8
-; EOF
index fe5cdb9..a9edde6 100644 (file)
@@ -1,3 +1,5 @@
+/*** Private header for BASESRV ***/
+
 #pragma once
 
 /* PSDK/NDK Headers */
@@ -7,5 +9,281 @@
 #define NTOS_MODE_USER
 #include <ndk/ntndk.h>
 
-#include <csr/server.h>
+/* CSRSS Header */
+#include <csrss/server.h>
+
+
 #include <win/base.h>
+
+
+
+#define BASESRV_SERVERDLL_INDEX         1
+#define BASESRV_FIRST_API_NUMBER        0
+
+
+// Windows NT 4 table, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_NT
+// It is for testing purposes. After that I will update it to 2k3 version and add stubs.
+typedef enum _BASESRV_API_NUMBER
+{
+    BasepCreateProcess = BASESRV_FIRST_API_NUMBER,
+    BasepCreateThread,
+    BasepGetTempFile,
+    BasepExitProcess,
+    // BasepDebugProcess,
+    BasepCheckVDM,
+    BasepUpdateVDMEntry,
+    // BasepGetNextVDMCommand,
+    // BasepExitVDM,
+    // BasepIsFirstVDM,
+    BasepGetVDMExitCode,
+    // BasepSetReenterCount,
+    BasepSetProcessShutdownParam,
+    BasepGetProcessShutdownParam,
+    // BasepNlsSetUserInfo,
+    // BasepNlsSetMultipleUserInfo,
+    // BasepNlsCreateSortSection,
+    // BasepNlsPreserveSection,
+    // BasepSetVDMCurDirs,
+    // BasepGetVDMCurDirs,
+    // BasepBatNotification,
+    // BasepRegisterWowExec,
+    BasepSoundSentryNotification,
+    // BasepRefreshIniFileMapping,
+    BasepDefineDosDevice,
+
+    BasepMaxApiNumber
+} BASESRV_API_NUMBER, *PBASESRV_API_NUMBER;
+
+
+typedef struct _BASE_SXS_CREATEPROCESS_MSG
+{
+    ULONG Flags;
+    ULONG ProcessParameterFlags;
+    HANDLE FileHandle;    
+    UNICODE_STRING SxsWin32ExePath;
+    UNICODE_STRING SxsNtExePath;
+    SIZE_T OverrideManifestOffset;
+    ULONG OverrideManifestSize;
+    SIZE_T OverridePolicyOffset;
+    ULONG OverridePolicySize;
+    PVOID PEManifestAddress;
+    ULONG PEManifestSize;
+    UNICODE_STRING CultureFallbacks;
+    ULONG Unknown[7];
+    UNICODE_STRING AssemblyName;
+} BASE_SXS_CREATEPROCESS_MSG, *PBASE_SXS_CREATEPROCESS_MSG;
+
+typedef struct
+{
+    //
+    // NT-type structure (BASE_CREATEPROCESS_MSG)
+    //
+    HANDLE ProcessHandle;
+    HANDLE ThreadHandle;
+    CLIENT_ID ClientId;
+    ULONG CreationFlags;
+    ULONG VdmBinaryType;
+    ULONG VdmTask;
+    HANDLE hVDM;
+    BASE_SXS_CREATEPROCESS_MSG Sxs;
+    PVOID PebAddressNative;
+    ULONG PebAddressWow64;
+    USHORT ProcessorArchitecture;
+
+    //
+    // ReactOS Data
+    //
+    BOOL bInheritHandles;
+} BASE_CREATE_PROCESS, *PBASE_CREATE_PROCESS;
+
+typedef struct
+{
+    CLIENT_ID ClientId;
+    HANDLE ThreadHandle;
+} BASE_CREATE_THREAD, *PBASE_CREATE_THREAD;
+
+typedef struct
+{
+    UINT uExitCode;
+} BASE_EXIT_PROCESS, *PBASE_EXIT_PROCESS;
+
+typedef struct
+{
+    UINT UniqueID;
+} BASE_GET_TEMP_FILE, *PBASE_GET_TEMP_FILE;
+
+typedef struct
+{
+    ULONG iTask;
+    HANDLE ConsoleHandle;
+    ULONG BinaryType;
+    HANDLE WaitObjectForParent;
+    HANDLE StdIn;
+    HANDLE StdOut;
+    HANDLE StdErr;
+    ULONG CodePage;
+    ULONG dwCreationFlags;
+    PCHAR CmdLine;
+    PCHAR appName;
+    PCHAR PifFile;
+    PCHAR CurDirectory;
+    PCHAR Env;
+    ULONG EnvLen;
+    PVOID StartupInfo;
+    PCHAR Desktop;
+    ULONG DesktopLen;
+    PCHAR Title;
+    ULONG TitleLen;
+    PCHAR Reserved;
+    ULONG ReservedLen;
+    USHORT CmdLen;
+    USHORT AppLen;
+    USHORT PifLen;
+    USHORT CurDirectoryLen;
+    USHORT CurDrive;
+    USHORT VDMState;
+} BASE_CHECK_VDM, *PBASE_CHECK_VDM;
+
+typedef struct
+{
+    ULONG iTask;
+    ULONG BinaryType;
+    HANDLE ConsoleHandle;
+    HANDLE VDMProcessHandle;
+    HANDLE WaitObjectForParent;
+    USHORT EntryIndex;
+    USHORT VDMCreationState;
+} BASE_UPDATE_VDM_ENTRY, *PBASE_UPDATE_VDM_ENTRY;
+
+typedef struct
+{
+    HANDLE ConsoleHandle;
+    HANDLE hParent;
+    ULONG ExitCode;
+} BASE_GET_VDM_EXIT_CODE, *PBASE_GET_VDM_EXIT_CODE;
+
+typedef struct
+{
+    DWORD Level;
+    DWORD Flags;
+} BASE_SET_PROCESS_SHUTDOWN_PARAMS, *PBASE_SET_PROCESS_SHUTDOWN_PARAMS;
+
+typedef struct
+{
+    DWORD Level;
+    DWORD Flags;
+} BASE_GET_PROCESS_SHUTDOWN_PARAMS, *PBASE_GET_PROCESS_SHUTDOWN_PARAMS;
+
+typedef struct
+{
+    ULONG VideoMode;
+} BASE_SOUND_SENTRY, *PBASE_SOUND_SENTRY;
+
+typedef struct
+{
+    UNICODE_STRING DeviceName;
+    UNICODE_STRING TargetName;
+    DWORD dwFlags;
+} BASE_DEFINE_DOS_DEVICE, *PBASE_DEFINE_DOS_DEVICE;
+
+
+typedef struct _BASE_API_MESSAGE
+{
+    PORT_MESSAGE Header;
+
+    PCSR_CAPTURE_BUFFER CsrCaptureData;
+    CSR_API_NUMBER ApiNumber;
+    ULONG Status;
+    ULONG Reserved;
+    union
+    {
+        BASE_CREATE_PROCESS CreateProcessRequest;
+        BASE_CREATE_THREAD CreateThreadRequest;
+        BASE_EXIT_PROCESS ExitProcessRequest; // CSRSS_TERMINATE_PROCESS TerminateProcessRequest;
+        BASE_GET_TEMP_FILE GetTempFile;
+        BASE_CHECK_VDM CheckVdm;
+        BASE_UPDATE_VDM_ENTRY UpdateVdmEntry;
+        BASE_GET_VDM_EXIT_CODE GetVdmExitCode;
+        BASE_SET_PROCESS_SHUTDOWN_PARAMS SetShutdownParametersRequest; // CSRSS_SET_SHUTDOWN_PARAMETERS
+        BASE_GET_PROCESS_SHUTDOWN_PARAMS GetShutdownParametersRequest; // CSRSS_GET_SHUTDOWN_PARAMETERS
+        BASE_SOUND_SENTRY SoundSentryRequest;
+        BASE_DEFINE_DOS_DEVICE DefineDosDeviceRequest;
+    } Data;
+} BASE_API_MESSAGE, *PBASE_API_MESSAGE;
+
+
+
+
+
+
+
+
+typedef struct _NLS_USER_INFO
+{
+    WCHAR iCountry[80];
+    WCHAR sCountry[80];
+    WCHAR sList[80];
+    WCHAR iMeasure[80];
+    WCHAR iPaperSize[80];
+    WCHAR sDecimal[80];
+    WCHAR sThousand[80];
+    WCHAR sGrouping[80];
+    WCHAR iDigits[80];
+    WCHAR iLZero[80];
+    WCHAR iNegNumber[80];
+    WCHAR sNativeDigits[80];
+    WCHAR iDigitSubstitution[80];
+    WCHAR sCurrency[80];
+    WCHAR sMonDecSep[80];
+    WCHAR sMonThouSep[80];
+    WCHAR sMonGrouping[80];
+    WCHAR iCurrDigits[80];
+    WCHAR iCurrency[80];
+    WCHAR iNegCurr[80];
+    WCHAR sPosSign[80];
+    WCHAR sNegSign[80];
+    WCHAR sTimeFormat[80];
+    WCHAR s1159[80];
+    WCHAR s2359[80];
+    WCHAR sShortDate[80];
+    WCHAR sYearMonth[80];
+    WCHAR sLongDate[80];
+    WCHAR iCalType[80];
+    WCHAR iFirstDay[80];
+    WCHAR iFirstWeek[80];
+    WCHAR sLocale[80];
+    WCHAR sLocaleName[85];
+    LCID UserLocaleId;
+    LUID InteractiveUserLuid;
+    CHAR InteractiveUserSid[68]; // SECURITY_MAX_SID_SIZE to make ROS happy
+    ULONG ulCacheUpdateCount;
+} NLS_USER_INFO, *PNLS_USER_INFO;
+
+
+typedef struct _BASE_STATIC_SERVER_DATA
+{
+    UNICODE_STRING WindowsDirectory;
+    UNICODE_STRING WindowsSystemDirectory;
+    UNICODE_STRING NamedObjectDirectory;
+    USHORT WindowsMajorVersion;
+    USHORT WindowsMinorVersion;
+    USHORT BuildNumber;
+    USHORT CSDNumber;
+    USHORT RCNumber;
+    WCHAR CSDVersion[128];
+    SYSTEM_BASIC_INFORMATION SysInfo;
+    SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay;
+    PVOID IniFileMapping;
+    NLS_USER_INFO NlsUserInfo;
+    BOOLEAN DefaultSeparateVDM;
+    BOOLEAN IsWowTaskReady;
+    UNICODE_STRING WindowsSys32x86Directory;
+    BOOLEAN fTermsrvAppInstallMode;
+    TIME_ZONE_INFORMATION tziTermsrvClientTimeZone;
+    KSYSTEM_TIME ktTermsrvClientBias;
+    ULONG TermsrvClientTimeZoneId;
+    BOOLEAN LUIDDeviceMapsEnabled;
+    ULONG TermsrvClientTimeZoneChangeNum;
+} BASE_STATIC_SERVER_DATA, *PBASE_STATIC_SERVER_DATA;
+
+
index a603259..bfd2c93 100644 (file)
@@ -1,5 +1,5 @@
 #define REACTOS_VERSION_DLL
-#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS/Win32 base usermode server\0"
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS BASE API Server DLL\0"
 #define REACTOS_STR_INTERNAL_NAME      "basesrv\0"
 #define REACTOS_STR_ORIGINAL_FILENAME  "basesrv.dll\0"
 #include <reactos/version.rc>
diff --git a/subsystems/win/basesrv/basesrv.spec b/subsystems/win/basesrv/basesrv.spec
new file mode 100644 (file)
index 0000000..d9a4b8d
--- /dev/null
@@ -0,0 +1,2 @@
+@ stdcall BaseSetProcessCreateNotify(ptr)
+@ stdcall ServerDllInitialization(ptr)
index 93dcffa..dd7f5d1 100644 (file)
-/* $Id$
- *
- * init.c - ReactOS/Win32 base enviroment subsystem server
- *
- * ReactOS Operating System
- *
- * --------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * --------------------------------------------------------------------
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS/Win32 base enviroment subsystem server
+ * FILE:            subsystems/win/basesrv/init.c
+ * PURPOSE:         Initialization
+ * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
+
 #include "basesrv.h"
 
 #define NDEBUG
 #include <debug.h>
 
-HANDLE BaseApiPort = (HANDLE) 0;
+HANDLE DllHandle = NULL;
+HANDLE BaseApiPort = NULL;
 
-/**********************************************************************
- * NAME                                                        PRIVATE
- *     BaseStaticServerThread/1
- */
-VOID WINAPI BaseStaticServerThread (PVOID x)
+extern LIST_ENTRY DosDeviceHistory;
+extern RTL_CRITICAL_SECTION BaseDefineDosDeviceCritSec;
+
+// Windows NT 4 tables, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_NT
+// It is for testing purposes. After that I will update it to 2k3 version and add stubs.
+// Some names are also deduced from the subsystems/win32/csrss/csrsrv/server.c ones.
+PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
+{
+    BaseSrvCreateProcess,
+    BaseSrvCreateThread,
+    BaseSrvGetTempFile,
+    BaseSrvExitProcess,
+    // BaseSrvDebugProcess,
+    BaseSrvCheckVDM,
+    BaseSrvUpdateVDMEntry,
+    // BaseSrvGetNextVDMCommand,
+    // BaseSrvExitVDM,
+    // BaseSrvIsFirstVDM,
+    BaseSrvGetVDMExitCode,
+    // BaseSrvSetReenterCount,
+    BaseSrvSetProcessShutdownParam,
+    BaseSrvGetProcessShutdownParam,
+    // BaseSrvNlsSetUserInfo,
+    // BaseSrvNlsSetMultipleUserInfo,
+    // BaseSrvNlsCreateSortSection,
+    // BaseSrvNlsPreserveSection,
+    // BaseSrvSetVDMCurDirs,
+    // BaseSrvGetVDMCurDirs,
+    // BaseSrvBatNotification,
+    // BaseSrvRegisterWowExec,
+    BaseSrvSoundSentryNotification,
+    // BaseSrvRefreshIniFileMapping,
+    BaseSrvDefineDosDevice
+};
+
+BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber] =
+{
+    TRUE,    // SrvCreateProcess,
+    TRUE,    // SrvCreateThread,
+    TRUE,    // SrvGetTempFile,
+    FALSE,   // SrvExitProcess,
+    // FALSE,   // SrvDebugProcess,
+    TRUE,    // SrvCheckVDM,
+    TRUE,    // SrvUpdateVDMEntry
+    // TRUE,    // SrvGetNextVDMCommand
+    // TRUE,    // SrvExitVDM
+    // TRUE,    // SrvIsFirstVDM
+    TRUE,    // SrvGetVDMExitCode
+    // TRUE,    // SrvSetReenterCount
+    TRUE,    // SrvSetProcessShutdownParam
+    TRUE,    // SrvGetProcessShutdownParam
+    // TRUE,    // SrvNlsSetUserInfo
+    // TRUE,    // SrvNlsSetMultipleUserInfo
+    // TRUE,    // SrvNlsCreateSortSection
+    // TRUE,    // SrvNlsPreserveSection
+    // TRUE,    // SrvSetVDMCurDirs
+    // TRUE,    // SrvGetVDMCurDirs
+    // TRUE,    // SrvBatNotification
+    // TRUE,    // SrvRegisterWowExec
+    TRUE,    // SrvSoundSentryNotification
+    // TRUE,    // SrvRefreshIniFileMapping
+    TRUE,    // SrvDefineDosDevice
+    // FALSE
+};
+
+PCHAR BaseServerApiNameTable[BasepMaxApiNumber] =
+{
+    "BaseCreateProcess",
+    "BaseCreateThread",
+    "BaseGetTempFile",
+    "BaseExitProcess",
+    // "BaseDebugProcess",
+    "BaseCheckVDM",
+    "BaseUpdateVDMEntry",
+    // "BaseGetNextVDMCommand",
+    // "BaseExitVDM",
+    // "BaseIsFirstVDM",
+    "BaseGetVDMExitCode",
+    // "BaseSetReenterCount",
+    "BaseSetProcessShutdownParam",
+    "BaseGetProcessShutdownParam",
+    // "BaseNlsSetUserInfo",
+    // "BaseNlsSetMultipleUserInfo",
+    // "BaseNlsCreateSortSection",
+    // "BaseNlsPreserveSection",
+    // "BaseSetVDMCurDirs",
+    // "BaseGetVDMCurDirs",
+    // "BaseBatNotification",
+    // "BaseRegisterWowExec",
+    "BaseSoundSentryNotification",
+    // "BaseSrvRefreshIniFileMapping"
+    "BaseDefineDosDevice",
+    // NULL
+};
+
+
+/* FUNCTIONS ******************************************************************/
+
+VOID
+NTAPI
+BasepFakeStaticServerData(VOID)
+{
+    NTSTATUS Status;
+    WCHAR Buffer[MAX_PATH];
+    PWCHAR HeapBuffer;
+    UNICODE_STRING SystemRootString;
+    UNICODE_STRING UnexpandedSystemRootString = RTL_CONSTANT_STRING(L"%SystemRoot%");
+    UNICODE_STRING BaseSrvCSDString;
+    UNICODE_STRING BaseSrvWindowsDirectory;
+    UNICODE_STRING BaseSrvWindowsSystemDirectory;
+    UNICODE_STRING BnoString;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    ULONG SessionId;
+    HANDLE BaseSrvNamedObjectDirectory;
+    HANDLE BaseSrvRestrictedObjectDirectory;
+    PACL BnoDacl, BnoRestrictedDacl;
+    PSECURITY_DESCRIPTOR BnoSd;
+    HANDLE SymHandle;
+    UNICODE_STRING DirectoryName, SymlinkName;
+    ULONG LuidEnabled;
+    RTL_QUERY_REGISTRY_TABLE BaseServerRegistryConfigurationTable[2] =
+    {
+        {
+            NULL,
+            RTL_QUERY_REGISTRY_DIRECT,
+            L"CSDVersion",
+            &BaseSrvCSDString,
+            REG_NONE, NULL, 0
+        },
+
+        {0}
+    };
+
+    /* Get the session ID */
+    SessionId = NtCurrentPeb()->SessionId;
+
+    /* Get the Windows directory */
+    RtlInitEmptyUnicodeString(&SystemRootString, Buffer, sizeof(Buffer));
+    Status = RtlExpandEnvironmentStrings_U(NULL,
+                                           &UnexpandedSystemRootString,
+                                           &SystemRootString,
+                                           NULL);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Create the base directory */
+    Buffer[SystemRootString.Length / sizeof(WCHAR)] = UNICODE_NULL;
+    Status = RtlCreateUnicodeString(&BaseSrvWindowsDirectory,
+                                    SystemRootString.Buffer);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Create the system directory */
+    wcscat(SystemRootString.Buffer, L"\\System32");
+    Status = RtlCreateUnicodeString(&BaseSrvWindowsSystemDirectory,
+                                    SystemRootString.Buffer);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* FIXME: Check Session ID */
+    wcscpy(Buffer, L"\\BaseNamedObjects");
+    RtlInitUnicodeString(&BnoString, Buffer);
+
+    /* Allocate the server data */
+    BaseStaticServerData = RtlAllocateHeap(CsrSrvSharedSectionHeap,
+                                           HEAP_ZERO_MEMORY,
+                                           sizeof(BASE_STATIC_SERVER_DATA));
+    ASSERT(BaseStaticServerData != NULL);
+
+    /* Process timezone information */
+    BaseStaticServerData->TermsrvClientTimeZoneId = TIME_ZONE_ID_INVALID;
+    BaseStaticServerData->TermsrvClientTimeZoneChangeNum = 0;
+    Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
+                                      &BaseStaticServerData->TimeOfDay,
+                                      sizeof(BaseStaticServerData->TimeOfDay),
+                                      NULL);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Make a shared heap copy of the Windows directory */
+    BaseStaticServerData->WindowsDirectory = BaseSrvWindowsDirectory;
+    HeapBuffer = RtlAllocateHeap(CsrSrvSharedSectionHeap,
+                                 0,
+                                 BaseSrvWindowsDirectory.MaximumLength);
+    ASSERT(HeapBuffer);
+    RtlCopyMemory(HeapBuffer,
+                  BaseStaticServerData->WindowsDirectory.Buffer,
+                  BaseSrvWindowsDirectory.MaximumLength);
+    BaseStaticServerData->WindowsDirectory.Buffer = HeapBuffer;
+
+    /* Make a shared heap copy of the System directory */
+    BaseStaticServerData->WindowsSystemDirectory = BaseSrvWindowsSystemDirectory;
+    HeapBuffer = RtlAllocateHeap(CsrSrvSharedSectionHeap,
+                                 0,
+                                 BaseSrvWindowsSystemDirectory.MaximumLength);
+    ASSERT(HeapBuffer);
+    RtlCopyMemory(HeapBuffer,
+                  BaseStaticServerData->WindowsSystemDirectory.Buffer,
+                  BaseSrvWindowsSystemDirectory.MaximumLength);
+    BaseStaticServerData->WindowsSystemDirectory.Buffer = HeapBuffer;
+
+    /* This string is not used */
+    RtlInitEmptyUnicodeString(&BaseStaticServerData->WindowsSys32x86Directory,
+                              NULL,
+                              0);
+
+    /* Make a shared heap copy of the BNO directory */
+    BaseStaticServerData->NamedObjectDirectory = BnoString;
+    BaseStaticServerData->NamedObjectDirectory.MaximumLength = BnoString.Length +
+                                                               sizeof(UNICODE_NULL);
+    HeapBuffer = RtlAllocateHeap(CsrSrvSharedSectionHeap,
+                                 0,
+                                 BaseStaticServerData->NamedObjectDirectory.MaximumLength);
+    ASSERT(HeapBuffer);
+    RtlCopyMemory(HeapBuffer,
+                  BaseStaticServerData->NamedObjectDirectory.Buffer,
+                  BaseStaticServerData->NamedObjectDirectory.MaximumLength);
+    BaseStaticServerData->NamedObjectDirectory.Buffer = HeapBuffer;
+
+    /*
+     * Confirmed that in Windows, CSDNumber and RCNumber are actually Length
+     * and MaximumLength of the CSD String, since the same UNICODE_STRING is
+     * being queried twice, the first time as a ULONG!
+     *
+     * Somehow, in Windows this doesn't cause a buffer overflow, but it might
+     * in ReactOS, so this code is disabled until someone figures out WTF.
+     */
+    BaseStaticServerData->CSDNumber = 0;
+    BaseStaticServerData->RCNumber = 0;
+
+    /* Initialize the CSD string and query its value from the registry */
+    RtlInitEmptyUnicodeString(&BaseSrvCSDString, Buffer, sizeof(Buffer));
+    Status = RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT,
+                                    L"",
+                                    BaseServerRegistryConfigurationTable,
+                                    NULL,
+                                    NULL);
+    if (NT_SUCCESS(Status))
+    {
+        /* Copy into the shared buffer */
+        wcsncpy(BaseStaticServerData->CSDVersion,
+                BaseSrvCSDString.Buffer,
+                BaseSrvCSDString.Length / sizeof(WCHAR));
+    }
+    else
+    {
+        /* NULL-terminate to indicate nothing is there */
+        BaseStaticServerData->CSDVersion[0] = UNICODE_NULL;
+    }
+
+    /* Cache the system information */
+    Status = NtQuerySystemInformation(SystemBasicInformation,
+                                      &BaseStaticServerData->SysInfo,
+                                      sizeof(BaseStaticServerData->SysInfo),
+                                      NULL);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* FIXME: Should query the registry for these */
+    BaseStaticServerData->DefaultSeparateVDM = FALSE;
+    BaseStaticServerData->IsWowTaskReady = FALSE;
+
+    /* Allocate a security descriptor and create it */
+    BnoSd = RtlAllocateHeap(CsrHeap, 0, 1024);
+    ASSERT(BnoSd);
+    Status = RtlCreateSecurityDescriptor(BnoSd, SECURITY_DESCRIPTOR_REVISION);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Create the BNO and \Restricted DACLs */
+    Status = CreateBaseAcls(&BnoDacl, &BnoRestrictedDacl);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Set the BNO DACL as active for now */
+    Status = RtlSetDaclSecurityDescriptor(BnoSd, TRUE, BnoDacl, FALSE);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Create the BNO directory */
+    RtlInitUnicodeString(&BnoString, L"\\BaseNamedObjects");
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &BnoString,
+                               OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               BnoSd);
+    Status = NtCreateDirectoryObject(&BaseSrvNamedObjectDirectory,
+                                     DIRECTORY_ALL_ACCESS,
+                                     &ObjectAttributes);
+    ASSERT(NT_SUCCESS(Status));
+
+    /* Check if we are session 0 */
+    if (SessionId == 0)
+    {
+        /* Mark this as a session 0 directory */
+        Status = NtSetInformationObject(BaseSrvNamedObjectDirectory,
+                                        ObjectSessionInformation,
+                                        NULL,
+                                        0);
+        ASSERT(NT_SUCCESS(Status));
+    }
+
+    /* Check if LUID device maps are enabled */
+    Status = NtQueryInformationProcess(NtCurrentProcess(),
+                                       ProcessLUIDDeviceMapsEnabled,
+                                       &LuidEnabled,
+                                       sizeof(LuidEnabled),
+                                       NULL);
+    ASSERT(NT_SUCCESS(Status));
+    BaseStaticServerData->LUIDDeviceMapsEnabled = LuidEnabled;
+    if (!BaseStaticServerData->LUIDDeviceMapsEnabled)
+    {
+        /* Make Global point back to BNO */
+        RtlInitUnicodeString(&DirectoryName, L"Global");
+        RtlInitUnicodeString(&SymlinkName, L"\\BaseNamedObjects");
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &DirectoryName,
+                                   OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
+                                   BaseSrvNamedObjectDirectory,
+                                   BnoSd);
+        Status = NtCreateSymbolicLinkObject(&SymHandle,
+                                            SYMBOLIC_LINK_ALL_ACCESS,
+                                            &ObjectAttributes,
+                                            &SymlinkName);
+        if ((NT_SUCCESS(Status)) && SessionId == 0) NtClose(SymHandle);
+
+        /* Make local point back to \Sessions\x\BNO */
+        RtlInitUnicodeString(&DirectoryName, L"Local");
+        ASSERT(SessionId == 0);
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &DirectoryName,
+                                   OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
+                                   BaseSrvNamedObjectDirectory,
+                                   BnoSd);
+        Status = NtCreateSymbolicLinkObject(&SymHandle,
+                                            SYMBOLIC_LINK_ALL_ACCESS,
+                                            &ObjectAttributes,
+                                            &SymlinkName);
+        if ((NT_SUCCESS(Status)) && SessionId == 0) NtClose(SymHandle);
+
+        /* Make Session point back to BNOLINKS */
+        RtlInitUnicodeString(&DirectoryName, L"Session");
+        RtlInitUnicodeString(&SymlinkName, L"\\Sessions\\BNOLINKS");
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &DirectoryName,
+                                   OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
+                                   BaseSrvNamedObjectDirectory,
+                                   BnoSd);
+        Status = NtCreateSymbolicLinkObject(&SymHandle,
+                                            SYMBOLIC_LINK_ALL_ACCESS,
+                                            &ObjectAttributes,
+                                            &SymlinkName);
+        if ((NT_SUCCESS(Status)) && SessionId == 0) NtClose(SymHandle);
+
+        /* Create the BNO\Restricted directory and set the restricted DACL */
+        RtlInitUnicodeString(&DirectoryName, L"Restricted");
+        Status = RtlSetDaclSecurityDescriptor(BnoSd, TRUE, BnoRestrictedDacl, FALSE);
+        ASSERT(NT_SUCCESS(Status));
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &DirectoryName,
+                                   OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
+                                   BaseSrvNamedObjectDirectory,
+                                   BnoSd);
+        Status = NtCreateDirectoryObject(&BaseSrvRestrictedObjectDirectory,
+                                         DIRECTORY_ALL_ACCESS,
+                                         &ObjectAttributes);
+        ASSERT(NT_SUCCESS(Status));
+    }
+
+    /* Finally, set the pointer */
+    CsrSrvSharedStaticServerData[CSR_CONSOLE] = BaseStaticServerData;
+}
+
+
+VOID WINAPI BaseStaticServerThread(PVOID x)
 {
-       NTSTATUS Status = STATUS_SUCCESS;
-       PPORT_MESSAGE Request = (PPORT_MESSAGE) x;
-       PPORT_MESSAGE Reply = NULL;
-       ULONG MessageType = 0;
-
-       DPRINT("BASESRV: %s called\n", __FUNCTION__);
-
-       MessageType = Request->u2.s2.Type;
-       DPRINT("BASESRV: %s received a message (Type=%d)\n",
-               __FUNCTION__, MessageType);
-       switch (MessageType)
-       {
-               default:
-                       Reply = Request;
-                       Status = NtReplyPort (BaseApiPort, Reply);
-                       break;
-       }
+    NTSTATUS Status = STATUS_SUCCESS;
+    PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
+    PPORT_MESSAGE Reply = NULL;
+    ULONG MessageType = 0;
+
+    DPRINT("BASESRV: %s called\n", __FUNCTION__);
+
+    MessageType = Request->u2.s2.Type;
+    DPRINT("BASESRV: %s received a message (Type=%d)\n",
+           __FUNCTION__, MessageType);
+    switch (MessageType)
+    {
+        default:
+            Reply = Request;
+            Status = NtReplyPort(BaseApiPort, Reply);
+            break;
+    }
 }
 
 
-NTSTATUS WINAPI ServerDllInitialization (ULONG ArgumentCount, LPWSTR *Argument)
+CSR_SERVER_DLL_INIT(ServerDllInitialization)
+{
+    // NTSTATUS Status = STATUS_SUCCESS;
+
+/*
+    DPRINT("BASSRV: %s(%ld,...) called\n", __FUNCTION__, ArgumentCount);
+
+    BaseApiPort = CsrQueryApiPort ();
+    Status = CsrAddStaticServerThread(BaseStaticServerThread);
+    if (NT_SUCCESS(Status))
+    {
+        //TODO initialize the BASE server
+    }
+    return STATUS_SUCCESS;
+*/
+
+    /* Setup the DLL Object */
+    LoadedServerDll->ApiBase = BASESRV_FIRST_API_NUMBER; // ApiNumberBase
+    LoadedServerDll->HighestApiSupported = BasepMaxApiNumber; // MaxApiNumber
+    LoadedServerDll->DispatchTable = BaseServerApiDispatchTable;
+    LoadedServerDll->ValidTable = BaseServerApiServerValidTable;
+    LoadedServerDll->NameTable = BaseServerApiNameTable;
+    LoadedServerDll->SizeOfProcessData = 0;
+    LoadedServerDll->ConnectCallback = NULL;
+    LoadedServerDll->DisconnectCallback = NULL;
+
+    BasepFakeStaticServerData();
+
+    RtlInitializeCriticalSection(&BaseDefineDosDeviceCritSec);
+    InitializeListHead(&DosDeviceHistory);
+
+    /* All done */
+    return STATUS_SUCCESS;
+}
+
+BOOL
+NTAPI
+DllMain(IN HANDLE hDll,
+        IN DWORD dwReason,
+        IN LPVOID lpReserved)
 {
-       NTSTATUS Status = STATUS_SUCCESS;
+    UNREFERENCED_PARAMETER(dwReason);
+    UNREFERENCED_PARAMETER(lpReserved);
 
-       DPRINT("BASSRV: %s(%ld,...) called\n", __FUNCTION__, ArgumentCount);
+    if (DLL_PROCESS_ATTACH == dwReason)
+    {
+        DllHandle = hDll;
+    }
+    else if (DLL_PROCESS_DETACH == dwReason)
+    {
+        BaseCleanupDefineDosDevice();
+    }
 
-       BaseApiPort = CsrQueryApiPort ();
-       Status = CsrAddStaticServerThread (BaseStaticServerThread);
-       if (NT_SUCCESS(Status))
-       {
-               //TODO initialize the BASE server
-       }
-       return STATUS_SUCCESS;
+    return TRUE;
 }
 
 /* EOF */
diff --git a/subsystems/win/basesrv/main.c b/subsystems/win/basesrv/main.c
deleted file mode 100644 (file)
index 3a72567..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* $Id$
- *
- * dllmain.c - ReactOS/Win32 base enviroment subsystem server
- *
- * ReactOS Operating System
- *
- * --------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * --------------------------------------------------------------------
- */
-#include "basesrv.h"
-
-#define NDEBUG
-#include <debug.h>
-
-HANDLE DllHandle = 0;
-
-/* FUNCTIONS *****************************************************************/
-
-BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
-{
-  if (DLL_PROCESS_ATTACH == dwReason)
-    {
-      DllHandle = hDll;
-    }
-
-  return TRUE;
-}
-
-/* EOF */
index f5d0e92..1a676d6 100644 (file)
-/* $Id$
- *
- * server.c - ReactOS/Win32 base enviroment subsystem server
- *
- * ReactOS Operating System
- *
- * --------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * --------------------------------------------------------------------
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS/Win32 base enviroment subsystem server
+ * FILE:            subsystems/win/basesrv/server.c
+ * PURPOSE:         Initialization
+ * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
+
 #include "basesrv.h"
 
 #define NDEBUG
 #include <debug.h>
 
-/*=====================================================================
- *     PUBLIC API
- *===================================================================*/
 
-NTSTATUS WINAPI BaseSetProcessCreateNotify (BASE_PROCESS_CREATE_NOTIFY_ROUTINE ProcessCreateNotifyProc)
+extern NTSTATUS CallProcessCreated(PCSR_PROCESS, PCSR_PROCESS); // TODO: Import it from csrsrv/init.c
+
+CSR_API(BaseSrvCreateProcess)
+{
+    NTSTATUS Status;
+    HANDLE ProcessHandle, ThreadHandle;
+    PCSR_THREAD CsrThread;
+    PCSR_PROCESS Process, NewProcess;
+    ULONG Flags, VdmPower = 0, DebugFlags = 0;
+
+    /* Get the current client thread */
+    CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread != NULL);
+
+    Process = CsrThread->Process;
+
+    /* Extract the flags out of the process handle */
+    Flags = (ULONG_PTR)ApiMessage->Data.CreateProcessRequest.ProcessHandle & 3;
+    ApiMessage->Data.CreateProcessRequest.ProcessHandle = (HANDLE)((ULONG_PTR)ApiMessage->Data.CreateProcessRequest.ProcessHandle & ~3);
+
+    /* Duplicate the process handle */
+    Status = NtDuplicateObject(Process->ProcessHandle,
+                               ApiMessage->Data.CreateProcessRequest.ProcessHandle,
+                               NtCurrentProcess(),
+                               &ProcessHandle,
+                               0,
+                               0,
+                               DUPLICATE_SAME_ACCESS);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to duplicate process handle\n");
+        return Status;
+    }
+
+    /* Duplicate the thread handle */
+    Status = NtDuplicateObject(Process->ProcessHandle,
+                               ApiMessage->Data.CreateProcessRequest.ThreadHandle,
+                               NtCurrentProcess(),
+                               &ThreadHandle,
+                               0,
+                               0,
+                               DUPLICATE_SAME_ACCESS);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to duplicate process handle\n");
+        NtClose(ProcessHandle);
+        return Status;
+    }
+
+    /* See if this is a VDM process */
+    if (VdmPower)
+    {
+        /* Request VDM powers */
+        Status = NtSetInformationProcess(ProcessHandle,
+                                         ProcessWx86Information,
+                                         &VdmPower,
+                                         sizeof(VdmPower));
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT1("Failed to get VDM powers\n");
+            NtClose(ProcessHandle);
+            NtClose(ThreadHandle);
+            return Status;
+        }
+    }
+
+    /* Convert some flags. FIXME: More need conversion */
+    if (ApiMessage->Data.CreateProcessRequest.CreationFlags & CREATE_NEW_PROCESS_GROUP)
+    {
+        DebugFlags |= CsrProcessCreateNewGroup;
+    }
+
+    /* FIXME: SxS Stuff */
+
+    /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
+    Status = CsrCreateProcess(ProcessHandle,
+                              ThreadHandle,
+                              &ApiMessage->Data.CreateProcessRequest.ClientId,
+                              Process->NtSession,
+                              DebugFlags,
+                              NULL);
+    if (Status == STATUS_THREAD_IS_TERMINATING)
+    {
+        DPRINT1("Thread already dead\n");
+        return Status;
+    }
+
+    /* Check for other failures */
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create process/thread structures: %lx\n", Status);
+        return Status;
+    }
+
+    /* FIXME: Should notify user32 */
+
+    /* FIXME: VDM vodoo */
+
+    /* ReactOS Compatibility */
+    Status = CsrLockProcessByClientId(ApiMessage->Data.CreateProcessRequest.ClientId.UniqueProcess, &NewProcess);
+    ASSERT(Status == STATUS_SUCCESS);
+    if (!(ApiMessage->Data.CreateProcessRequest.CreationFlags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
+    {
+        NewProcess->ParentConsole = Process->Console;
+        NewProcess->bInheritHandles = ApiMessage->Data.CreateProcessRequest.bInheritHandles;
+    }
+    RtlInitializeCriticalSection(&NewProcess->HandleTableLock);
+    CallProcessCreated(Process, NewProcess);
+    CsrUnlockProcess(NewProcess);
+
+    /* Return the result of this operation */
+    return Status;
+}
+
+CSR_API(BaseSrvCreateThread)
+{
+    PCSR_THREAD CurrentThread;
+    HANDLE ThreadHandle;
+    NTSTATUS Status;
+    PCSR_PROCESS CsrProcess;
+
+    /* Get the current CSR thread */
+    CurrentThread = CsrGetClientThread();
+    if (!CurrentThread)
+    {
+        DPRINT1("Server Thread TID: [%lx.%lx]\n",
+        ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess,
+        ApiMessage->Data.CreateThreadRequest.ClientId.UniqueThread);
+        return STATUS_SUCCESS; // server-to-server
+    }
+
+    /* Get the CSR Process for this request */
+    CsrProcess = CurrentThread->Process;
+    if (CsrProcess->ClientId.UniqueProcess !=
+        ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess)
+    {
+        /* This is a remote thread request -- is it within the server itself? */
+        if (ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess)
+        {
+            /* Accept this without any further work */
+            return STATUS_SUCCESS;
+        }
+
+        /* Get the real CSR Process for the remote thread's process */
+        Status = CsrLockProcessByClientId(ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess,
+                                          &CsrProcess);
+        if (!NT_SUCCESS(Status)) return Status;
+    }
+
+    /* Duplicate the thread handle so we can own it */
+    Status = NtDuplicateObject(CurrentThread->Process->ProcessHandle,
+                               ApiMessage->Data.CreateThreadRequest.ThreadHandle,
+                               NtCurrentProcess(),
+                               &ThreadHandle,
+                               0,
+                               0,
+                               DUPLICATE_SAME_ACCESS);
+    if (NT_SUCCESS(Status))
+    {
+        /* Call CSRSRV to tell it about the new thread */
+        Status = CsrCreateThread(CsrProcess,
+                                 ThreadHandle,
+                                 &ApiMessage->Data.CreateThreadRequest.ClientId);
+    }
+
+    /* Unlock the process and return */
+    if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess);
+    return Status;
+}
+
+CSR_API(BaseSrvGetTempFile)
+{
+    static UINT CsrGetTempFileUnique = 0;
+
+    /* Return 16-bits ID */
+    ApiMessage->Data.GetTempFile.UniqueID = (++CsrGetTempFileUnique & 0xFFFF);
+
+    DPRINT("Returning: %u\n", ApiMessage->Data.GetTempFile.UniqueID);
+
+    return STATUS_SUCCESS;
+}
+
+CSR_API(BaseSrvExitProcess)
+{
+    PCSR_THREAD CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread != NULL);
+
+    /* Set magic flag so we don't reply this message back */
+    ApiMessage->ApiNumber = 0xBABE;
+
+    /* Remove the CSR_THREADs and CSR_PROCESS */
+    return CsrDestroyProcess(&CsrThread->ClientId,
+                             (NTSTATUS)ApiMessage->Data.TerminateProcessRequest.uExitCode);
+}
+
+CSR_API(BaseSrvGetProcessShutdownParam)
+{
+    PCSR_THREAD CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread);
+
+    ApiMessage->Data.GetShutdownParametersRequest.Level = CsrThread->Process->ShutdownLevel;
+    ApiMessage->Data.GetShutdownParametersRequest.Flags = CsrThread->Process->ShutdownFlags;
+
+    return STATUS_SUCCESS;
+}
+
+CSR_API(BaseSrvSetProcessShutdownParam)
+{
+    PCSR_THREAD CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread);
+
+    CsrThread->Process->ShutdownLevel = ApiMessage->Data.SetShutdownParametersRequest.Level;
+    CsrThread->Process->ShutdownFlags = ApiMessage->Data.SetShutdownParametersRequest.Flags;
+
+    return STATUS_SUCCESS;
+}
+
+
+/***
+ *** Sound sentry
+ ***/
+
+typedef BOOL (WINAPI *PUSER_SOUND_SENTRY)(VOID);
+BOOL NTAPI FirstSoundSentry(VOID);
+
+PUSER_SOUND_SENTRY _UserSoundSentry = FirstSoundSentry;
+
+BOOL
+NTAPI
+FailSoundSentry(VOID)
+{
+    /* In case the function can't be found/is unimplemented */
+    return FALSE;
+}
+
+BOOL
+NTAPI
+FirstSoundSentry(VOID)
+{
+    UNICODE_STRING DllString = RTL_CONSTANT_STRING(L"winsrv");
+    STRING FuncString = RTL_CONSTANT_STRING("_UserSoundSentry");
+    HANDLE DllHandle;
+    NTSTATUS Status;
+    PUSER_SOUND_SENTRY NewSoundSentry = FailSoundSentry;
+
+    /* Load winsrv manually */
+    Status = LdrGetDllHandle(NULL, NULL, &DllString, &DllHandle);
+    if (NT_SUCCESS(Status))
+    {
+        /* If it was found, get SoundSentry export */
+        Status = LdrGetProcedureAddress(DllHandle,
+                                        &FuncString,
+                                        0,
+                                        (PVOID*)&NewSoundSentry);
+    }
+    
+    /* Set it as the callback for the future, and call it */
+    _UserSoundSentry = NewSoundSentry;
+    return _UserSoundSentry();
+}
+
+CSR_API(BaseSrvSoundSentryNotification)
+{
+    /* Call the API and see if it succeeds */
+    return _UserSoundSentry() ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
+}
+
+
+/***
+ *** Dos Devices (C) Pierre Schweitzer (pierre.schweitzer@reactos.org)
+ ***/
+
+typedef struct tagCSRSS_DOS_DEVICE_HISTORY_ENTRY
 {
-       NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
+    UNICODE_STRING Device;
+    UNICODE_STRING Target;
+    LIST_ENTRY Entry;
+} CSRSS_DOS_DEVICE_HISTORY_ENTRY, *PCSRSS_DOS_DEVICE_HISTORY_ENTRY;
+
+LIST_ENTRY DosDeviceHistory;
+RTL_CRITICAL_SECTION BaseDefineDosDeviceCritSec;
+
+CSR_API(BaseSrvDefineDosDevice)
+{
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    HANDLE LinkHandle = NULL;
+    NTSTATUS Status;
+    UNICODE_STRING DeviceName = {0};
+    UNICODE_STRING RequestDeviceName = {0};
+    UNICODE_STRING LinkTarget = {0};
+    PUNICODE_STRING RequestLinkTarget;
+    ULONG Length;
+    SID_IDENTIFIER_AUTHORITY WorldAuthority = {SECURITY_WORLD_SID_AUTHORITY};
+    SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
+    PSECURITY_DESCRIPTOR SecurityDescriptor;
+    PACL Dacl;
+    PSID AdminSid;
+    PSID SystemSid;
+    PSID WorldSid;
+    ULONG SidLength;
+    PCSRSS_DOS_DEVICE_HISTORY_ENTRY HistoryEntry;
+    PLIST_ENTRY Entry;
+    PLIST_ENTRY ListHead;
+    BOOLEAN Matched, AddHistory;
+    DWORD dwFlags;
+    PWSTR lpBuffer;
+
+    DPRINT("CsrDefineDosDevice entered, Flags:%d, DeviceName:%wZ, TargetName:%wZ\n",
+           ApiMessage->Data.DefineDosDeviceRequest.dwFlags,
+           &ApiMessage->Data.DefineDosDeviceRequest.DeviceName,
+           &ApiMessage->Data.DefineDosDeviceRequest.TargetName);
+
+    Matched = AddHistory = FALSE;
+    HistoryEntry = NULL;
+    AdminSid = SystemSid = WorldSid = NULL;
+    SecurityDescriptor = NULL;
+    ListHead = &DosDeviceHistory;
+    dwFlags = ApiMessage->Data.DefineDosDeviceRequest.dwFlags;
+
+    /* Validate the flags */
+    if ( (dwFlags & 0xFFFFFFF0) ||
+        ((dwFlags & DDD_EXACT_MATCH_ON_REMOVE) &&
+            ! (dwFlags & DDD_REMOVE_DEFINITION)) )
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    Status = RtlEnterCriticalSection(&BaseDefineDosDeviceCritSec);
+    if (! NT_SUCCESS(Status))
+    {
+        DPRINT1("RtlEnterCriticalSection() failed (Status %lx)\n",
+                Status);
+        return Status;
+    }
+
+    _SEH2_TRY
+    {
+        Status =
+            RtlUpcaseUnicodeString(&RequestDeviceName,
+                                   &ApiMessage->Data.DefineDosDeviceRequest.DeviceName,
+                                   TRUE);
+        if (! NT_SUCCESS(Status))
+            _SEH2_LEAVE;
+
+        RequestLinkTarget =
+            &ApiMessage->Data.DefineDosDeviceRequest.TargetName;
+        lpBuffer = (PWSTR) RtlAllocateHeap(Win32CsrApiHeap,
+                                           HEAP_ZERO_MEMORY,
+                                           RequestDeviceName.MaximumLength + 5 * sizeof(WCHAR));
+        if (! lpBuffer)
+        {
+            DPRINT1("Failed to allocate memory\n");
+            Status = STATUS_NO_MEMORY;
+            _SEH2_LEAVE;
+        }
+
+        swprintf(lpBuffer,
+                 L"\\??\\%wZ",
+                 &RequestDeviceName);
+        RtlInitUnicodeString(&DeviceName,
+                             lpBuffer);
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &DeviceName,
+                                   OBJ_CASE_INSENSITIVE,
+                                   NULL,
+                                   NULL);
+        Status = NtOpenSymbolicLinkObject(&LinkHandle,
+                                          DELETE | 0x1,
+                                          &ObjectAttributes);
+        if (NT_SUCCESS(Status))
+        {
+            Status = NtQuerySymbolicLinkObject(LinkHandle,
+                                               &LinkTarget,
+                                               &Length);
+            if (! NT_SUCCESS(Status) &&
+                Status == STATUS_BUFFER_TOO_SMALL)
+            {
+                LinkTarget.Length = 0;
+                LinkTarget.MaximumLength = Length;
+                LinkTarget.Buffer = (PWSTR)
+                    RtlAllocateHeap(Win32CsrApiHeap,
+                                    HEAP_ZERO_MEMORY,
+                                    Length);
+                if (! LinkTarget.Buffer)
+                {
+                    DPRINT1("Failed to allocate memory\n");
+                    Status = STATUS_NO_MEMORY;
+                    _SEH2_LEAVE;
+                }
+
+                Status = NtQuerySymbolicLinkObject(LinkHandle,
+                                                   &LinkTarget,
+                                                   &Length);
+            }
+
+            if (! NT_SUCCESS(Status))
+            {
+                DPRINT1("NtQuerySymbolicLinkObject(%wZ) failed (Status %lx)\n",
+                     &DeviceName, Status);
+                _SEH2_LEAVE;
+            }
+
+            if ((dwFlags & DDD_REMOVE_DEFINITION))
+            {
+                /* If no target name specified we remove the current symlink target */
+                if (RequestLinkTarget->Length == 0)
+                    Matched = TRUE;
+                else
+                {
+                    if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE)
+                        Matched = ! RtlCompareUnicodeString(RequestLinkTarget,
+                                                            &LinkTarget,
+                                                            TRUE);
+                    else
+                        Matched = RtlPrefixUnicodeString(RequestLinkTarget,
+                                                         &LinkTarget,
+                                                         TRUE);
+                }
+
+                if (Matched && IsListEmpty(ListHead))
+                {
+                    /* Current symlink target macthed and there is nothing to revert to */
+                    RequestLinkTarget = NULL;
+                }
+                else if (Matched && ! IsListEmpty(ListHead))
+                {
+                    /* Fetch the first history entry we come across for the device name */
+                    /* This will become the current symlink target for the device name */
+                    Matched = FALSE;
+                    Entry = ListHead->Flink;
+                    while (Entry != ListHead)
+                    {
+                        HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
+                            CONTAINING_RECORD(Entry,
+                                              CSRSS_DOS_DEVICE_HISTORY_ENTRY,
+                                              Entry);
+                        Matched =
+                            ! RtlCompareUnicodeString(&RequestDeviceName,
+                                                      &HistoryEntry->Device,
+                                                      FALSE);
+                        if (Matched)
+                        {
+                            RemoveEntryList(&HistoryEntry->Entry);
+                            RequestLinkTarget = &HistoryEntry->Target;
+                            break;
+                        }
+                        Entry = Entry->Flink;
+                        HistoryEntry = NULL;
+                    }
+
+                    /* Nothing to revert to so delete the symlink */
+                    if (! Matched)
+                        RequestLinkTarget = NULL;
+                }
+                else if (! Matched)
+                {
+                    /* Locate a previous symlink target as we did not get a hit earlier */
+                    /* If we find one we need to remove it */
+                    Entry = ListHead->Flink;
+                    while (Entry != ListHead)
+                    {
+                        HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
+                            CONTAINING_RECORD(Entry,
+                                              CSRSS_DOS_DEVICE_HISTORY_ENTRY,
+                                              Entry);
+                        Matched =
+                            ! RtlCompareUnicodeString(&RequestDeviceName,
+                                                      &HistoryEntry->Device,
+                                                      FALSE);
+                        if (! Matched)
+                        {
+                            HistoryEntry = NULL;
+                            Entry = Entry->Flink;
+                            continue;
+                        }
+
+                        Matched = FALSE;
+                        if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE)
+                        {
+                            if (! RtlCompareUnicodeString(RequestLinkTarget,
+                                                          &HistoryEntry->Target,
+                                                          TRUE))
+                            {
+                                Matched = TRUE;
+                            }
+                        }
+                        else if (RtlPrefixUnicodeString(RequestLinkTarget,
+                                                        &HistoryEntry->Target,
+                                                        TRUE))
+                        {
+                            Matched = TRUE;
+                        }
+
+                        if (Matched)
+                        {
+                            RemoveEntryList(&HistoryEntry->Entry);
+                            break;
+                        }
+                        Entry = Entry->Flink;
+                        HistoryEntry = NULL;
+                    }
+
+                    /* Leave existing symlink as is */
+                    if (! Matched)
+                        Status = STATUS_OBJECT_NAME_NOT_FOUND;
+                    else
+                        Status = STATUS_SUCCESS;
+                    _SEH2_LEAVE;
+                }
+            }
+            else
+            {
+                AddHistory = TRUE;
+            }
+
+            Status = NtMakeTemporaryObject(LinkHandle);
+            if (! NT_SUCCESS(Status))
+            {
+                DPRINT1("NtMakeTemporaryObject(%wZ) failed (Status %lx)\n",
+                     &DeviceName, Status);
+                _SEH2_LEAVE;
+            }
+
+            Status = NtClose(LinkHandle);
+            LinkHandle = NULL;
+            if (! NT_SUCCESS(Status))
+            {
+                DPRINT1("NtClose(%wZ) failed (Status %lx)\n",
+                     &DeviceName, Status);
+                _SEH2_LEAVE;
+            }
+        }
+
+        /* Don't create symlink if we don't have a target */
+        if (! RequestLinkTarget || RequestLinkTarget->Length == 0)
+            _SEH2_LEAVE;
+
+        if (AddHistory)
+        {
+            HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
+                RtlAllocateHeap(Win32CsrApiHeap,
+                                HEAP_ZERO_MEMORY,
+                                sizeof(CSRSS_DOS_DEVICE_HISTORY_ENTRY));
+            if (! HistoryEntry)
+            {
+                DPRINT1("Failed to allocate memory\n");
+                Status = STATUS_NO_MEMORY;
+                _SEH2_LEAVE;
+            }
 
-       DPRINT("BASESRV: %s(%08lx) called\n", __FUNCTION__, ProcessCreateNotifyProc);
-       return Status;
+            HistoryEntry->Target.Buffer =
+                RtlAllocateHeap(Win32CsrApiHeap,
+                                HEAP_ZERO_MEMORY,
+                                LinkTarget.Length);
+            if (! HistoryEntry->Target.Buffer)
+            {
+                DPRINT1("Failed to allocate memory\n");
+                Status = STATUS_NO_MEMORY;
+                _SEH2_LEAVE;
+            }
+            HistoryEntry->Target.Length =
+                HistoryEntry->Target.MaximumLength =
+                    LinkTarget.Length;
+            RtlCopyUnicodeString(&HistoryEntry->Target,
+                                 &LinkTarget);
+
+            HistoryEntry->Device.Buffer =
+                RtlAllocateHeap(Win32CsrApiHeap,
+                                HEAP_ZERO_MEMORY,
+                                RequestDeviceName.Length);
+            if (! HistoryEntry->Device.Buffer)
+            {
+                DPRINT1("Failed to allocate memory\n");
+                Status = STATUS_NO_MEMORY;
+                _SEH2_LEAVE;
+            }
+            HistoryEntry->Device.Length =
+                HistoryEntry->Device.MaximumLength =
+                    RequestDeviceName.Length;
+            RtlCopyUnicodeString(&HistoryEntry->Device,
+                                 &RequestDeviceName);
+
+            /* Remember previous symlink target for this device */
+            InsertHeadList(ListHead,
+                           &HistoryEntry->Entry);
+            HistoryEntry = NULL;
+        }
+
+        RtlAllocateAndInitializeSid(&WorldAuthority,
+                                    1,
+                                    SECURITY_WORLD_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    &WorldSid);
+
+        RtlAllocateAndInitializeSid(&SystemAuthority,
+                                    1,
+                                    SECURITY_LOCAL_SYSTEM_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    &SystemSid);
+
+        RtlAllocateAndInitializeSid(&SystemAuthority,
+                                    2,
+                                    SECURITY_BUILTIN_DOMAIN_RID,
+                                    DOMAIN_ALIAS_RID_ADMINS,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    SECURITY_NULL_RID,
+                                    &AdminSid);
+
+        SidLength = RtlLengthSid(SystemSid) +
+            RtlLengthSid(AdminSid) +
+            RtlLengthSid(WorldSid);
+        Length = sizeof(ACL) + SidLength + 3 * sizeof(ACCESS_ALLOWED_ACE);
+
+        SecurityDescriptor = RtlAllocateHeap(Win32CsrApiHeap,
+                                             0,
+                                             SECURITY_DESCRIPTOR_MIN_LENGTH + Length);
+        if (! SecurityDescriptor)
+        {
+            DPRINT1("Failed to allocate memory\n");
+            Status = STATUS_NO_MEMORY;
+            _SEH2_LEAVE;
+        }
+
+        Dacl = (PACL)((ULONG_PTR)SecurityDescriptor + SECURITY_DESCRIPTOR_MIN_LENGTH);
+        Status = RtlCreateSecurityDescriptor(SecurityDescriptor,
+                                             SECURITY_DESCRIPTOR_REVISION);
+        if (! NT_SUCCESS(Status))
+        {
+            DPRINT1("RtlCreateSecurityDescriptor() failed (Status %lx)\n",
+                 Status);
+            _SEH2_LEAVE;
+        }
+
+        Status = RtlCreateAcl(Dacl,
+                              Length,
+                              ACL_REVISION);
+        if (! NT_SUCCESS(Status))
+        {
+            DPRINT1("RtlCreateAcl() failed (Status %lx)\n",
+                 Status);
+            _SEH2_LEAVE;
+        }
+
+        (void) RtlAddAccessAllowedAce(Dacl,
+                                      ACL_REVISION,
+                                      GENERIC_ALL,
+                                      SystemSid);
+        (void) RtlAddAccessAllowedAce(Dacl,
+                                      ACL_REVISION,
+                                      GENERIC_ALL,
+                                      AdminSid);
+        (void) RtlAddAccessAllowedAce(Dacl,
+                                      ACL_REVISION,
+                                      STANDARD_RIGHTS_READ,
+                                      WorldSid);
+
+        Status = RtlSetDaclSecurityDescriptor(SecurityDescriptor,
+                                              TRUE,
+                                              Dacl,
+                                              FALSE);
+        if (! NT_SUCCESS(Status))
+        {
+            DPRINT1("RtlSetDaclSecurityDescriptor() failed (Status %lx)\n",
+                 Status);
+            _SEH2_LEAVE;
+        }
+
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &DeviceName,
+                                   OBJ_CASE_INSENSITIVE,
+                                   NULL,
+                                   SecurityDescriptor);
+        Status = NtCreateSymbolicLinkObject(&LinkHandle,
+                                            SYMBOLIC_LINK_ALL_ACCESS,
+                                            &ObjectAttributes,
+                                            RequestLinkTarget);
+        if (NT_SUCCESS(Status))
+        {
+            Status = NtMakePermanentObject(LinkHandle);
+            if (! NT_SUCCESS(Status))
+            {
+                DPRINT1("NtMakePermanentObject(%wZ) failed (Status %lx)\n",
+                     &DeviceName, Status);
+            }
+        }
+        else
+        {
+            DPRINT1("NtCreateSymbolicLinkObject(%wZ) failed (Status %lx)\n",
+                 &DeviceName, Status);
+        }
+    }
+    _SEH2_FINALLY
+    {
+        (void) RtlLeaveCriticalSection(&BaseDefineDosDeviceCritSec);
+        if (DeviceName.Buffer)
+            (void) RtlFreeHeap(Win32CsrApiHeap,
+                               0,
+                               DeviceName.Buffer);
+        if (LinkTarget.Buffer)
+            (void) RtlFreeHeap(Win32CsrApiHeap,
+                               0,
+                               LinkTarget.Buffer);
+        if (SecurityDescriptor)
+            (void) RtlFreeHeap(Win32CsrApiHeap,
+                               0,
+                               SecurityDescriptor);
+        if (LinkHandle)
+            (void) NtClose(LinkHandle);
+        if (SystemSid)
+            (void) RtlFreeSid(SystemSid);
+        if (AdminSid)
+            (void) RtlFreeSid(AdminSid);
+        if (WorldSid)
+            (void) RtlFreeSid(WorldSid);
+        RtlFreeUnicodeString(&RequestDeviceName);
+        if (HistoryEntry)
+        {
+            if (HistoryEntry->Target.Buffer)
+                (void) RtlFreeHeap(Win32CsrApiHeap,
+                                   0,
+                                   HistoryEntry->Target.Buffer);
+            if (HistoryEntry->Device.Buffer)
+                (void) RtlFreeHeap(Win32CsrApiHeap,
+                                   0,
+                                   HistoryEntry->Device.Buffer);
+            (void) RtlFreeHeap(Win32CsrApiHeap,
+                               0,
+                               HistoryEntry);
+        }
+    }
+    _SEH2_END
+
+    DPRINT("CsrDefineDosDevice Exit, Statux: 0x%x\n", Status);
+    return Status;
+}
+
+VOID BaseCleanupDefineDosDevice(VOID)
+{
+    PLIST_ENTRY Entry, ListHead;
+    PCSRSS_DOS_DEVICE_HISTORY_ENTRY HistoryEntry;
+
+    (void) RtlDeleteCriticalSection(&BaseDefineDosDeviceCritSec);
+
+    ListHead = &DosDeviceHistory;
+    Entry = ListHead->Flink;
+    while (Entry != ListHead)
+    {
+        HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
+            CONTAINING_RECORD(Entry,
+                              CSRSS_DOS_DEVICE_HISTORY_ENTRY,
+                              Entry);
+        Entry = Entry->Flink;
+
+        if (HistoryEntry)
+        {
+            if (HistoryEntry->Target.Buffer)
+                (void) RtlFreeHeap(Win32CsrApiHeap,
+                                   0,
+                                   HistoryEntry->Target.Buffer);
+            if (HistoryEntry->Device.Buffer)
+                (void) RtlFreeHeap(Win32CsrApiHeap,
+                                   0,
+                                   HistoryEntry->Device.Buffer);
+            (void) RtlFreeHeap(Win32CsrApiHeap,
+                               0,
+                               HistoryEntry);
+        }
+    }
+}
+
+
+
+
+
+
+/* PUBLIC API *****************************************************************/
+
+NTSTATUS NTAPI BaseSetProcessCreateNotify(IN BASE_PROCESS_CREATE_NOTIFY_ROUTINE ProcessCreateNotifyProc)
+{
+    DPRINT("BASESRV: %s(%08lx) called\n", __FUNCTION__, ProcessCreateNotifyProc);
+    return STATUS_NOT_IMPLEMENTED;
 }
 
 /* EOF */
index 46c4ce9..97f5a8e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * subsystems/win32/csrss/csrsrv/api/process.c
  *
- * "\windows\ApiPort" port process management functions
+ * 
  *
  * ReactOS Operating System
  */
@@ -13,7 +13,7 @@
 #define NDEBUG
 #include <debug.h>
     
-extern NTSTATUS CallProcessCreated(PCSR_PROCESS, PCSR_PROCESS);
+
 
 /* GLOBALS *******************************************************************/
 
@@ -30,207 +30,4 @@ extern NTSTATUS CallProcessCreated(PCSR_PROCESS, PCSR_PROCESS);
  *** corresponding indexes, and the third one of names (not very efficient...).
  ***/
 
-CSR_API(BaseSrvCreateProcess)
-{
-     NTSTATUS Status;
-     HANDLE ProcessHandle, ThreadHandle;
-     PCSR_THREAD CsrThread;
-     PCSR_PROCESS Process, NewProcess;
-     ULONG Flags, VdmPower = 0, DebugFlags = 0;
-
-     /* Get the current client thread */
-     CsrThread = CsrGetClientThread();
-     ASSERT(CsrThread != NULL);
-
-     Process = CsrThread->Process;
-
-     /* Extract the flags out of the process handle */
-     Flags = (ULONG_PTR)ApiMessage->Data.CreateProcessRequest.ProcessHandle & 3;
-     ApiMessage->Data.CreateProcessRequest.ProcessHandle = (HANDLE)((ULONG_PTR)ApiMessage->Data.CreateProcessRequest.ProcessHandle & ~3);
-
-     /* Duplicate the process handle */
-     Status = NtDuplicateObject(Process->ProcessHandle,
-                                ApiMessage->Data.CreateProcessRequest.ProcessHandle,
-                                NtCurrentProcess(),
-                                &ProcessHandle,
-                                0,
-                                0,
-                                DUPLICATE_SAME_ACCESS);
-     if (!NT_SUCCESS(Status))
-     {
-         DPRINT1("Failed to duplicate process handle\n");
-         return Status;
-     }
-
-     /* Duplicate the thread handle */
-     Status = NtDuplicateObject(Process->ProcessHandle,
-                                ApiMessage->Data.CreateProcessRequest.ThreadHandle,
-                                NtCurrentProcess(),
-                                &ThreadHandle,
-                                0,
-                                0,
-                                DUPLICATE_SAME_ACCESS);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("Failed to duplicate process handle\n");
-        NtClose(ProcessHandle);
-        return Status;
-    }
-
-    /* See if this is a VDM process */
-    if (VdmPower)
-    {
-        /* Request VDM powers */
-        Status = NtSetInformationProcess(ProcessHandle,
-                                         ProcessWx86Information,
-                                         &VdmPower,
-                                         sizeof(VdmPower));
-        if (!NT_SUCCESS(Status))
-        {
-            DPRINT1("Failed to get VDM powers\n");
-            NtClose(ProcessHandle);
-            NtClose(ThreadHandle);
-            return Status;
-        }
-    }
-    
-    /* Convert some flags. FIXME: More need conversion */
-    if (ApiMessage->Data.CreateProcessRequest.CreationFlags & CREATE_NEW_PROCESS_GROUP)
-    {
-        DebugFlags |= CsrProcessCreateNewGroup;
-    }
-
-    /* FIXME: SxS Stuff */
-
-    /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
-    Status = CsrCreateProcess(ProcessHandle,
-                              ThreadHandle,
-                              &ApiMessage->Data.CreateProcessRequest.ClientId,
-                              Process->NtSession,
-                              DebugFlags,
-                              NULL);
-    if (Status == STATUS_THREAD_IS_TERMINATING)
-    {
-        DPRINT1("Thread already dead\n");
-        return Status;
-    }
-
-    /* Check for other failures */
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("Failed to create process/thread structures: %lx\n", Status);
-        return Status;
-    }
-
-    /* FIXME: Should notify user32 */
-
-    /* FIXME: VDM vodoo */
-    
-    /* ReactOS Compatibility */
-    Status = CsrLockProcessByClientId(ApiMessage->Data.CreateProcessRequest.ClientId.UniqueProcess, &NewProcess);
-    ASSERT(Status == STATUS_SUCCESS);
-    if (!(ApiMessage->Data.CreateProcessRequest.CreationFlags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
-    {
-        NewProcess->ParentConsole = Process->Console;
-        NewProcess->bInheritHandles = ApiMessage->Data.CreateProcessRequest.bInheritHandles;
-    }
-    RtlInitializeCriticalSection(&NewProcess->HandleTableLock);
-    CallProcessCreated(Process, NewProcess);
-    CsrUnlockProcess(NewProcess);
-
-    /* Return the result of this operation */
-    return Status;
-}
-
-CSR_API(BaseSrvCreateThread)
-{
-    PCSR_THREAD CurrentThread;
-    HANDLE ThreadHandle;
-    NTSTATUS Status;
-    PCSR_PROCESS CsrProcess;
-    
-    /* Get the current CSR thread */
-    CurrentThread = CsrGetClientThread();
-    if (!CurrentThread)
-    {
-        DPRINT1("Server Thread TID: [%lx.%lx]\n",
-                ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess,
-                ApiMessage->Data.CreateThreadRequest.ClientId.UniqueThread);
-        return STATUS_SUCCESS; // server-to-server
-    }
-
-    /* Get the CSR Process for this request */
-    CsrProcess = CurrentThread->Process;
-    if (CsrProcess->ClientId.UniqueProcess !=
-        ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess)
-    {
-        /* This is a remote thread request -- is it within the server itself? */
-        if (ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess)
-        {
-            /* Accept this without any further work */
-            return STATUS_SUCCESS;
-        }
-
-        /* Get the real CSR Process for the remote thread's process */
-        Status = CsrLockProcessByClientId(ApiMessage->Data.CreateThreadRequest.ClientId.UniqueProcess,
-                                          &CsrProcess);
-        if (!NT_SUCCESS(Status)) return Status;
-    }
-
-    /* Duplicate the thread handle so we can own it */
-    Status = NtDuplicateObject(CurrentThread->Process->ProcessHandle,
-                               ApiMessage->Data.CreateThreadRequest.ThreadHandle,
-                               NtCurrentProcess(),
-                               &ThreadHandle,
-                               0,
-                               0,
-                               DUPLICATE_SAME_ACCESS);
-    if (NT_SUCCESS(Status))
-    {
-        /* Call CSRSRV to tell it about the new thread */
-        Status = CsrCreateThread(CsrProcess,
-                                 ThreadHandle,
-                                 &ApiMessage->Data.CreateThreadRequest.ClientId);
-    }
-
-    /* Unlock the process and return */
-    if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess);
-    return Status;
-}
-
-CSR_API(BaseSrvExitProcess)
-{
-    PCSR_THREAD CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread != NULL);
-
-    /* Set magic flag so we don't reply this message back */
-    ApiMessage->ApiNumber = 0xBABE;
-
-    /* Remove the CSR_THREADs and CSR_PROCESS */
-    return CsrDestroyProcess(&CsrThread->ClientId,
-                             (NTSTATUS)ApiMessage->Data.TerminateProcessRequest.uExitCode);
-}
-
-CSR_API(BaseSrvGetProcessShutdownParam)
-{
-    PCSR_THREAD CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread);
-
-    ApiMessage->Data.GetShutdownParametersRequest.Level = CsrThread->Process->ShutdownLevel;
-    ApiMessage->Data.GetShutdownParametersRequest.Flags = CsrThread->Process->ShutdownFlags;
-
-    return STATUS_SUCCESS;
-}
-
-CSR_API(BaseSrvSetProcessShutdownParam)
-{
-    PCSR_THREAD CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread);
-
-    CsrThread->Process->ShutdownLevel = ApiMessage->Data.SetShutdownParametersRequest.Level;
-    CsrThread->Process->ShutdownFlags = ApiMessage->Data.SetShutdownParametersRequest.Flags;
-
-    return STATUS_SUCCESS;
-}
-
 /* EOF */
index 271710c..e88c602 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * subsystems/win32/csrss/csrsrv/api/wapi.c
  *
+ * "\windows\ApiPort" port process management functions
  * CSRSS port message processing
  *
  * ReactOS Operating System
@@ -25,6 +26,7 @@ extern ULONG CsrMaxApiRequestThreads;
 
 /* FUNCTIONS *****************************************************************/
 
+#if 0
 NTSTATUS FASTCALL
 CsrApiRegisterDefinitions(PCSRSS_API_DEFINITION NewDefinitions)
 {
@@ -61,6 +63,7 @@ CsrApiRegisterDefinitions(PCSRSS_API_DEFINITION NewDefinitions)
 
   return STATUS_SUCCESS;
 }
+#endif
 
 /*
 VOID
@@ -146,7 +149,7 @@ NTAPI
 CsrCallServerFromServer(PCSR_API_MESSAGE ReceiveMsg,
                         PCSR_API_MESSAGE ReplyMsg)
 {
-#if 0 // real code
+#if 1 // Real code
     ULONG ServerId;
     PCSR_SERVER_DLL ServerDll;
     ULONG ApiId;
@@ -199,6 +202,7 @@ CsrCallServerFromServer(PCSR_API_MESSAGE ReceiveMsg,
     _SEH2_TRY
     {
         /* Call the API and get the result */
+        /// CsrApiCallHandler(ReplyMsg, /*ProcessData*/ &ReplyCode); ///
         Status = (ServerDll->DispatchTable[ApiId])(ReceiveMsg, &Reply);
 
         /* Return the result, no matter what it is */
index ea5db55..6be1bbd 100644 (file)
@@ -60,6 +60,7 @@ CallHardError(IN PCSR_THREAD ThreadData,
     }
 }
 
+#if 0
 NTSTATUS
 CallProcessCreated(IN PCSR_PROCESS SourceProcessData,
                    IN PCSR_PROCESS TargetProcessData)
@@ -85,22 +86,11 @@ CallProcessCreated(IN PCSR_PROCESS SourceProcessData,
 
     return Status;
 }
+#endif
 
-/***
- *** Some APIs from here will go to basesrv.dll, some others to winsrv.dll.
- *** Furthermore, this structure uses the old definition of APIs list.
- *** The new one is in fact three arrays, one of APIs pointers, one other of
- *** corresponding indexes, and the third one of names (not very efficient...).
- ***/
 CSRSS_API_DEFINITION NativeDefinitions[] =
 {
-    CSRSS_DEFINE_API(CREATE_PROCESS,               BaseSrvCreateProcess),
-    CSRSS_DEFINE_API(CREATE_THREAD,                BaseSrvCreateThread),
-    CSRSS_DEFINE_API(TERMINATE_PROCESS,            BaseSrvExitProcess),
-    CSRSS_DEFINE_API(REGISTER_SERVICES_PROCESS,    SrvRegisterServicesProcess),
-    CSRSS_DEFINE_API(GET_SHUTDOWN_PARAMETERS,      BaseSrvGetProcessShutdownParam),
-    CSRSS_DEFINE_API(SET_SHUTDOWN_PARAMETERS,      BaseSrvSetProcessShutdownParam),
-    { 0, 0, NULL }
+    CSRSS_DEFINE_API(REGISTER_SERVICES_PROCESS, SrvRegisterServicesProcess), // winsrv.dll
 };
 
 /* === INIT ROUTINES === */
@@ -708,7 +698,7 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
             }
 
             /* Load us */
-            Status = CsrLoadServerDll("CSRSS" /* "CSRSRV" */, NULL, CSR_SRV_SERVER);
+            Status = CsrLoadServerDll("CSRSS" /* "CSRSRV" */, NULL, CSRSRV_SERVERDLL_INDEX);
         }
         else if (_stricmp(ParameterName, "ServerDLL") == 0)
         {
@@ -1032,11 +1022,13 @@ CsrServerInitialization(IN ULONG ArgumentCount,
         return Status;
     }
 
+#if 0
     Status = CsrApiRegisterDefinitions(NativeDefinitions);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("CSRSRV failed in %s with status %lx\n", "CsrApiRegisterDefinitions", Status);
     }
+#endif
 
     /* Now initialize our API Port */
     Status = CsrApiPortInitialize();
@@ -1047,17 +1039,6 @@ CsrServerInitialization(IN ULONG ArgumentCount,
         return Status;
     }
 
-    ////////////////////////////    ADDED    ////////////////////////////
-    /*
-    /\* Initialize Win32csr *\/
-    Status = CsrLoadServerDll("win32csr", "Win32CsrInitialization", 2);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("CSRSRV failed in %s with status %lx\n", "CsrLoadServerDll", Status);
-    }
-    */
-    ////////////////////////////  END ADDED  ////////////////////////////
-
     /* Initialize the API Port for SM communication */
     Status = CsrSbApiPortInitialize();
     if (!NT_SUCCESS(Status))
index 180892d..52a4427 100644 (file)
@@ -26,7 +26,7 @@ SECURITY_QUALITY_OF_SERVICE CsrSecurityQos =
     FALSE
 };
 ULONG CsrProcessSequenceCount = 5;
-extern ULONG CsrTotalPerProcessDataLength; // remove 'extern' if not needed.
+extern ULONG CsrTotalPerProcessDataLength;
 
 
 /* PRIVATE FUNCTIONS **********************************************************/
index 1ca428e..ea149b8 100644 (file)
@@ -1,12 +1,13 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS CSR Sub System
+ * PROJECT:         ReactOS CSR SubSystem
  * FILE:            subsystems/win32/csrss/csrsrv/server.c
  * PURPOSE:         CSR Server DLL Server Functions
  * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
  */
 
 /* INCLUDES ******************************************************************/
+
 #include "srv.h"
 
 #define NDEBUG
 
 /* DATA **********************************************************************/
 
-PCSR_API_ROUTINE CsrServerApiDispatchTable[5] =
+/*** Must go elsewhere ***/
+#define CSR_SERVER_DLL_MAX 4
+
+#define CSRSRV_SERVERDLL_INDEX          0
+#define CSRSRV_FIRST_API_NUMBER         0
+
+typedef enum _CSR_SRV_API_NUMBER
+{
+    CsrpClientConnect = CSRSRV_FIRST_API_NUMBER,
+    CsrpThreadConnect,
+    CsrpProfileControl,
+    CsrpIdentifyAlertable,
+    CsrpSetPriorityClass,
+
+    CsrpMaxApiNumber
+} CSR_SRV_API_NUMBER, *PCSR_SRV_API_NUMBER;
+/*************************/
+
+PCSR_API_ROUTINE CsrServerApiDispatchTable[CsrpMaxApiNumber] =
 {
     CsrSrvClientConnect,
     CsrSrvUnusedFunction,
@@ -23,7 +42,7 @@ PCSR_API_ROUTINE CsrServerApiDispatchTable[5] =
     CsrSrvSetPriorityClass
 };
 
-BOOLEAN CsrServerApiServerValidTable[5] =
+BOOLEAN CsrServerApiServerValidTable[CsrpMaxApiNumber] =
 {
     TRUE,
     FALSE,
@@ -32,7 +51,7 @@ BOOLEAN CsrServerApiServerValidTable[5] =
     TRUE
 };
 
-PCHAR CsrServerApiNameTable[5] =
+PCHAR CsrServerApiNameTable[CsrpMaxApiNumber] =
 {
     "ClientConnect",
     "ThreadConnect",
@@ -65,9 +84,7 @@ HANDLE CsrSrvSharedSection;
  * @remarks None.
  *
  *--*/
-NTSTATUS
-NTAPI
-CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll)
+CSR_SERVER_DLL_INIT(CsrServerDllInitialization)
 {
     /* Setup the DLL Object */
     LoadedServerDll->ApiBase = 0;
@@ -133,7 +150,7 @@ CsrLoadServerDll(IN PCHAR DllString,
     if (!NT_SUCCESS(Status)) return Status;
 
     /* If we are loading ourselves, don't actually load us */
-    if (ServerId != CSR_SRV_SERVER)
+    if (ServerId != CSRSRV_SERVERDLL_INDEX)
     {
         /* Load the DLL */
         Status = LdrLoadDll(NULL, 0, &TempString, &hServerDll);
@@ -186,8 +203,7 @@ CsrLoadServerDll(IN PCHAR DllString,
     {
         /* Initialize a string for the entrypoint, or use the default */
         RtlInitAnsiString(&EntryPointString,
-                          !(EntryPoint) ? "ServerDllInitialization" :
-                                          EntryPoint);
+                          EntryPoint ? EntryPoint : "ServerDllInitialization");
 
         /* Get a pointer to it */
         Status = LdrGetProcedureAddress(hServerDll,
@@ -207,8 +223,6 @@ CsrLoadServerDll(IN PCHAR DllString,
     {
         /* Get the result from the Server DLL */
         Status = ServerDllInitProcedure(ServerDll);
-
-        /* Check for Success */
         if (NT_SUCCESS(Status))
         {
             /*
@@ -227,11 +241,13 @@ CsrLoadServerDll(IN PCHAR DllString,
                 CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
             }
 
-            /* ReactOS Specific hax */
+#if 0 /* HACK: ReactOS Specific hax. REMOVE IT. */
             if (ServerDll->HighestApiSupported == 0xDEADBABE)
             {
+                // CSRSS_API_DEFINITIONS == Old structure.
                 Status = CsrApiRegisterDefinitions((PVOID)ServerDll->DispatchTable);
             }
+#endif
         }
         else
         {
@@ -275,9 +291,6 @@ NTAPI
 CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage,
                     IN OUT PULONG Reply OPTIONAL)
 {
-    /* Hack */
-    return STATUS_SUCCESS;
-#if 0
     NTSTATUS Status;
     PCSR_CLIENT_CONNECT ClientConnect;
     PCSR_SERVER_DLL ServerDll;
@@ -326,7 +339,6 @@ CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage,
 
     /* Return status */
     return Status;
-#endif
 }
 
 /*++
@@ -628,7 +640,7 @@ CsrSetCallingSpooler(ULONG Reserved)
  * @remarks None.
  *
  *--*/
-LONG
+EXCEPTION_DISPOSITION
 NTAPI
 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
 {
index f07f8dd..8983ada 100644 (file)
@@ -19,7 +19,6 @@ list(APPEND SOURCE
     desktopbg.c
     dllmain.c
     exitros.c
-    file.c
     guiconsole.c
     handle.c
     harderror.c
index ad93d92..ad5e25c 100644 (file)
@@ -9,19 +9,85 @@
 /* INCLUDES ******************************************************************/
 #define NDEBUG
 #include "w32csr.h"
-#include "file.h"
 #include <debug.h>
 
 /* Not defined in any header file */
 extern VOID WINAPI PrivateCsrssManualGuiCheck(LONG Check);
-extern LIST_ENTRY DosDeviceHistory;
-extern RTL_CRITICAL_SECTION Win32CsrDefineDosDeviceCritSec;
 
 /* GLOBALS *******************************************************************/
 
 HANDLE Win32CsrApiHeap;
 HINSTANCE Win32CsrDllHandle = NULL;
 
+PCSR_API_ROUTINE Win32CsrApiDefinitions[] =
+{
+    CsrGetHandle,
+    CsrGetHandle,
+    CsrCloseHandle,
+    CsrVerifyHandle,
+    CsrDuplicateHandle,
+    CsrGetInputWaitHandle,
+    CsrWriteConsole,
+    CsrReadConsole,
+    CsrAllocConsole,
+    CsrFreeConsole,
+    CsrGetScreenBufferInfo,
+    CsrSetCursor,
+    CsrFillOutputChar,
+    CsrReadInputEvent,
+    CsrWriteConsoleOutputChar,
+    CsrWriteConsoleOutputAttrib,
+    CsrFillOutputAttrib,
+    CsrGetCursorInfo,
+    CsrSetCursorInfo,
+    CsrSetTextAttrib,
+    CsrGetConsoleMode,
+    CsrSetConsoleMode,
+    CsrCreateScreenBuffer,
+    CsrSetScreenBuffer,
+    CsrSetTitle,
+    CsrGetTitle,
+    CsrWriteConsoleOutput,
+    CsrFlushInputBuffer,
+    CsrScrollConsoleScreenBuffer,
+    CsrReadConsoleOutputChar,
+    CsrReadConsoleOutputAttrib,
+    CsrGetNumberOfConsoleInputEvents,
+    CsrExitReactos,
+    CsrPeekConsoleInput,
+    CsrReadConsoleOutput,
+    CsrWriteConsoleInput,
+    CsrHardwareStateProperty,
+    CsrGetConsoleWindow,
+    CsrCreateDesktop,
+    CsrShowDesktop,
+    CsrHideDesktop,
+    CsrSetConsoleIcon,
+    CsrSetLogonNotifyWindow,
+    CsrRegisterLogonProcess,
+    CsrGetConsoleCodePage,
+    CsrSetConsoleCodePage,
+    CsrGetConsoleOutputCodePage,
+    CsrSetConsoleOutputCodePage,
+    CsrGetProcessList,
+    CsrAddConsoleAlias,
+    CsrGetConsoleAlias,
+    CsrGetAllConsoleAliases,
+    CsrGetAllConsoleAliasesLength,
+    CsrGetConsoleAliasesExes,
+    CsrGetConsoleAliasesExesLength,
+    CsrGenerateCtrlEvent,
+    CsrSetScreenBufferSize,
+    CsrGetConsoleSelectionInfo,
+    CsrGetCommandHistoryLength,
+    CsrGetCommandHistory,
+    CsrExpungeCommandHistory,
+    CsrSetHistoryNumberCommands,
+    CsrGetHistoryInfo,
+    CsrSetHistoryInfo
+};
+
+/*
 static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] =
 {
     CSRSS_DEFINE_API(GET_INPUT_HANDLE,             CsrGetHandle),
@@ -88,11 +154,9 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] =
     CSRSS_DEFINE_API(SET_HISTORY_NUMBER_COMMANDS,  CsrSetHistoryNumberCommands),
     CSRSS_DEFINE_API(GET_HISTORY_INFO,             CsrGetHistoryInfo),
     CSRSS_DEFINE_API(SET_HISTORY_INFO,             CsrSetHistoryInfo),
-    CSRSS_DEFINE_API(GET_TEMP_FILE,                CsrGetTempFile),
-    CSRSS_DEFINE_API(DEFINE_DOS_DEVICE,            CsrDefineDosDevice),
-    CSRSS_DEFINE_API(SOUND_SENTRY,                 CsrSoundSentry),
     { 0, 0, NULL }
 };
+*/
 
 static HHOOK hhk = NULL;
 
@@ -268,10 +332,6 @@ DllMain(HANDLE hDll,
 //   BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
     }
 
-    if (DLL_PROCESS_DETACH == dwReason)
-    {
-        CsrCleanupDefineDosDevice();
-    }
     return TRUE;
 }
 
@@ -324,9 +384,7 @@ CreateSystemThreads(PVOID pParam)
     return 0;
 }
 
-NTSTATUS
-WINAPI
-Win32CsrInitialization(IN PCSR_SERVER_DLL ServerDll)
+CSR_SERVER_DLL_INIT(Win32CsrInitialization)
 {
     HANDLE ServerThread;
     CLIENT_ID ClientId;
@@ -334,23 +392,25 @@ Win32CsrInitialization(IN PCSR_SERVER_DLL ServerDll)
 
     Win32CsrApiHeap = RtlGetProcessHeap();
     
-    CsrpInitVideo();
+    CsrpInitVideo(); // Must go into winsrv.dll
 
     NtUserInitialize(0, NULL, NULL);
 
     PrivateCsrssManualGuiCheck(0);
-    CsrInitConsoleSupport();
-
-    /* HACK */
-    ServerDll->DispatchTable = (PVOID)Win32CsrApiDefinitions;
-    ServerDll->HighestApiSupported = 0xDEADBABE;
-    
-    ServerDll->HardErrorCallback = Win32CsrHardError;
-    ServerDll->NewProcessCallback = Win32CsrDuplicateHandleTable;
-    ServerDll->DisconnectCallback = Win32CsrReleaseConsole;
-
-    RtlInitializeCriticalSection(&Win32CsrDefineDosDeviceCritSec);
-    InitializeListHead(&DosDeviceHistory);
+    CsrInitConsoleSupport(); // Go into consrv.dll
+
+    /* Setup the DLL Object */
+    LoadedServerDll->ApiBase = BASESRV_FIRST_API_NUMBER; // ApiNumberBase
+    LoadedServerDll->HighestApiSupported = BasepMaxApiNumber; // MaxApiNumber
+    LoadedServerDll->DispatchTable = Win32CsrApiDefinitions;
+    // LoadedServerDll->ValidTable = BaseServerApiServerValidTable;
+    // LoadedServerDll->NameTable = BaseServerApiNameTable;
+    // LoadedServerDll->SizeOfProcessData = 0;
+    // LoadedServerDll->ConnectCallback = NULL;
+    // LoadedServerDll->DisconnectCallback = NULL;
+    LoadedServerDll->HardErrorCallback = Win32CsrHardError;
+    LoadedServerDll->NewProcessCallback = Win32CsrDuplicateHandleTable;
+    LoadedServerDll->DisconnectCallback = Win32CsrReleaseConsole;
 
     /* Start Raw Input Threads */
     Status = RtlCreateUserThread(NtCurrentProcess(), NULL, TRUE, 0, 0, 0, (PTHREAD_START_ROUTINE)CreateSystemThreads, (PVOID)0, &ServerThread, &ClientId);
diff --git a/win32ss/user/win32csr/file.c b/win32ss/user/win32csr/file.c
deleted file mode 100644 (file)
index 5ac4f2d..0000000
+++ /dev/null
@@ -1,586 +0,0 @@
-/*
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS system libraries
- * FILE:            subsys/csrss/win32csr/file.c
- * PURPOSE:         File handling
- * PROGRAMMERS:     Pierre Schweitzer (pierre.schweitzer@reactos.org)
- * NOTE:            Belongs to basesrv.dll
- */
-
-/* INCLUDES ******************************************************************/
-
-#include <w32csr.h>
-#define NDEBUG
-#include <debug.h>
-#include "file.h"
-
-/* GLOBALS *******************************************************************/
-
-typedef BOOL (WINAPI *PUSER_SOUND_SENTRY)(VOID);
-BOOL
-WINAPI
-FirstSoundSentry(VOID);
-
-UINT CsrGetTempFileUnique;
-LIST_ENTRY DosDeviceHistory;
-RTL_CRITICAL_SECTION Win32CsrDefineDosDeviceCritSec;
-PUSER_SOUND_SENTRY _UserSoundSentry = FirstSoundSentry;
-
-/* FUNCTIONS *****************************************************************/
-
-BOOL
-WINAPI
-FailSoundSentry(VOID)
-{
-    /* In case the function can't be found/is unimplemented */
-    return FALSE;
-}
-
-BOOL
-WINAPI
-FirstSoundSentry(VOID)
-{
-    UNICODE_STRING DllString = RTL_CONSTANT_STRING(L"winsrv");
-    STRING FuncString = RTL_CONSTANT_STRING("_UserSoundSentry");
-    HANDLE DllHandle;
-    NTSTATUS Status;
-    PUSER_SOUND_SENTRY NewSoundSentry = FailSoundSentry;
-
-    /* Load winsrv manually */
-    Status = LdrGetDllHandle(NULL, NULL, &DllString, &DllHandle);
-    if (NT_SUCCESS(Status))
-    {
-        /* If it was found, get SoundSentry export */
-        Status = LdrGetProcedureAddress(DllHandle,
-                                        &FuncString,
-                                        0,
-                                        (PVOID*)&NewSoundSentry);
-    }
-    
-    /* Set it as the callback for the future, and call it */
-    _UserSoundSentry = NewSoundSentry;
-    return _UserSoundSentry();
-}
-
-CSR_API(CsrSoundSentry)
-{
-    /* Call the API and see if it suceeds */
-    return _UserSoundSentry() ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
-}
-
-CSR_API(CsrGetTempFile)
-{
-    DPRINT("CsrGetTempFile entered\n");
-
-    /* Return 16-bits ID */
-    ApiMessage->Data.GetTempFile.UniqueID = (++CsrGetTempFileUnique & 0xFFFF);
-
-    DPRINT("Returning: %u\n", ApiMessage->Data.GetTempFile.UniqueID);
-
-    return STATUS_SUCCESS;
-}
-
-CSR_API(CsrDefineDosDevice)
-{
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    HANDLE LinkHandle = NULL;
-    NTSTATUS Status;
-    UNICODE_STRING DeviceName = {0};
-    UNICODE_STRING RequestDeviceName = {0};
-    UNICODE_STRING LinkTarget = {0};
-    PUNICODE_STRING RequestLinkTarget;
-    ULONG Length;
-    SID_IDENTIFIER_AUTHORITY WorldAuthority = {SECURITY_WORLD_SID_AUTHORITY};
-    SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
-    PSECURITY_DESCRIPTOR SecurityDescriptor;
-    PACL Dacl;
-    PSID AdminSid;
-    PSID SystemSid;
-    PSID WorldSid;
-    ULONG SidLength;
-    PCSRSS_DOS_DEVICE_HISTORY_ENTRY HistoryEntry;
-    PLIST_ENTRY Entry;
-    PLIST_ENTRY ListHead;
-    BOOLEAN Matched, AddHistory;
-    DWORD dwFlags;
-    PWSTR lpBuffer;
-
-    DPRINT("CsrDefineDosDevice entered, Flags:%d, DeviceName:%wZ, TargetName:%wZ\n",
-           ApiMessage->Data.DefineDosDeviceRequest.dwFlags,
-           &ApiMessage->Data.DefineDosDeviceRequest.DeviceName,
-           &ApiMessage->Data.DefineDosDeviceRequest.TargetName);
-
-    Matched = AddHistory = FALSE;
-    HistoryEntry = NULL;
-    AdminSid = SystemSid = WorldSid = NULL;
-    SecurityDescriptor = NULL;
-    ListHead = &DosDeviceHistory;
-    dwFlags = ApiMessage->Data.DefineDosDeviceRequest.dwFlags;
-
-    /* Validate the flags */
-    if ( (dwFlags & 0xFFFFFFF0) ||
-        ((dwFlags & DDD_EXACT_MATCH_ON_REMOVE) &&
-            ! (dwFlags & DDD_REMOVE_DEFINITION)) )
-    {
-        return STATUS_INVALID_PARAMETER;
-    }
-
-    Status = RtlEnterCriticalSection(&Win32CsrDefineDosDeviceCritSec);
-    if (! NT_SUCCESS(Status))
-    {
-        DPRINT1("RtlEnterCriticalSection() failed (Status %lx)\n",
-                Status);
-        return Status;
-    }
-
-    _SEH2_TRY
-    {
-        Status =
-            RtlUpcaseUnicodeString(&RequestDeviceName,
-                                   &ApiMessage->Data.DefineDosDeviceRequest.DeviceName,
-                                   TRUE);
-        if (! NT_SUCCESS(Status))
-            _SEH2_LEAVE;
-
-        RequestLinkTarget =
-            &ApiMessage->Data.DefineDosDeviceRequest.TargetName;
-        lpBuffer = (PWSTR) RtlAllocateHeap(Win32CsrApiHeap,
-                                           HEAP_ZERO_MEMORY,
-                                           RequestDeviceName.MaximumLength + 5 * sizeof(WCHAR));
-        if (! lpBuffer)
-        {
-            DPRINT1("Failed to allocate memory\n");
-            Status = STATUS_NO_MEMORY;
-            _SEH2_LEAVE;
-        }
-
-        swprintf(lpBuffer,
-                 L"\\??\\%wZ",
-                 &RequestDeviceName);
-        RtlInitUnicodeString(&DeviceName,
-                             lpBuffer);
-        InitializeObjectAttributes(&ObjectAttributes,
-                                   &DeviceName,
-                                   OBJ_CASE_INSENSITIVE,
-                                   NULL,
-                                   NULL);
-        Status = NtOpenSymbolicLinkObject(&LinkHandle,
-                                          DELETE | 0x1,
-                                          &ObjectAttributes);
-        if (NT_SUCCESS(Status))
-        {
-            Status = NtQuerySymbolicLinkObject(LinkHandle,
-                                               &LinkTarget,
-                                               &Length);
-            if (! NT_SUCCESS(Status) &&
-                Status == STATUS_BUFFER_TOO_SMALL)
-            {
-                LinkTarget.Length = 0;
-                LinkTarget.MaximumLength = Length;
-                LinkTarget.Buffer = (PWSTR)
-                    RtlAllocateHeap(Win32CsrApiHeap,
-                                    HEAP_ZERO_MEMORY,
-                                    Length);
-                if (! LinkTarget.Buffer)
-                {
-                    DPRINT1("Failed to allocate memory\n");
-                    Status = STATUS_NO_MEMORY;
-                    _SEH2_LEAVE;
-                }
-
-                Status = NtQuerySymbolicLinkObject(LinkHandle,
-                                                   &LinkTarget,
-                                                   &Length);
-            }
-
-            if (! NT_SUCCESS(Status))
-            {
-                DPRINT1("NtQuerySymbolicLinkObject(%wZ) failed (Status %lx)\n",
-                     &DeviceName, Status);
-                _SEH2_LEAVE;
-            }
-
-            if ((dwFlags & DDD_REMOVE_DEFINITION))
-            {
-                /* If no target name specified we remove the current symlink target */
-                if (RequestLinkTarget->Length == 0)
-                    Matched = TRUE;
-                else
-                {
-                    if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE)
-                        Matched = ! RtlCompareUnicodeString(RequestLinkTarget,
-                                                            &LinkTarget,
-                                                            TRUE);
-                    else
-                        Matched = RtlPrefixUnicodeString(RequestLinkTarget,
-                                                         &LinkTarget,
-                                                         TRUE);
-                }
-
-                if (Matched && IsListEmpty(ListHead))
-                {
-                    /* Current symlink target macthed and there is nothing to revert to */
-                    RequestLinkTarget = NULL;
-                }
-                else if (Matched && ! IsListEmpty(ListHead))
-                {
-                    /* Fetch the first history entry we come across for the device name */
-                    /* This will become the current symlink target for the device name */
-                    Matched = FALSE;
-                    Entry = ListHead->Flink;
-                    while (Entry != ListHead)
-                    {
-                        HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
-                            CONTAINING_RECORD(Entry,
-                                              CSRSS_DOS_DEVICE_HISTORY_ENTRY,
-                                              Entry);
-                        Matched =
-                            ! RtlCompareUnicodeString(&RequestDeviceName,
-                                                      &HistoryEntry->Device,
-                                                      FALSE);
-                        if (Matched)
-                        {
-                            RemoveEntryList(&HistoryEntry->Entry);
-                            RequestLinkTarget = &HistoryEntry->Target;
-                            break;
-                        }
-                        Entry = Entry->Flink;
-                        HistoryEntry = NULL;
-                    }
-
-                    /* Nothing to revert to so delete the symlink */
-                    if (! Matched)
-                        RequestLinkTarget = NULL;
-                }
-                else if (! Matched)
-                {
-                    /* Locate a previous symlink target as we did not get a hit earlier */
-                    /* If we find one we need to remove it */
-                    Entry = ListHead->Flink;
-                    while (Entry != ListHead)
-                    {
-                        HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
-                            CONTAINING_RECORD(Entry,
-                                              CSRSS_DOS_DEVICE_HISTORY_ENTRY,
-                                              Entry);
-                        Matched =
-                            ! RtlCompareUnicodeString(&RequestDeviceName,
-                                                      &HistoryEntry->Device,
-                                                      FALSE);
-                        if (! Matched)
-                        {
-                            HistoryEntry = NULL;
-                            Entry = Entry->Flink;
-                            continue;
-                        }
-
-                        Matched = FALSE;
-                        if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE)
-                        {
-                            if (! RtlCompareUnicodeString(RequestLinkTarget,
-                                                          &HistoryEntry->Target,
-                                                          TRUE))
-                            {
-                                Matched = TRUE;
-                            }
-                        }
-                        else if (RtlPrefixUnicodeString(RequestLinkTarget,
-                                                        &HistoryEntry->Target,
-                                                        TRUE))
-                        {
-                            Matched = TRUE;
-                        }
-
-                        if (Matched)
-                        {
-                            RemoveEntryList(&HistoryEntry->Entry);
-                            break;
-                        }
-                        Entry = Entry->Flink;
-                        HistoryEntry = NULL;
-                    }
-
-                    /* Leave existing symlink as is */
-                    if (! Matched)
-                        Status = STATUS_OBJECT_NAME_NOT_FOUND;
-                    else
-                        Status = STATUS_SUCCESS;
-                    _SEH2_LEAVE;
-                }
-            }
-            else
-            {
-                AddHistory = TRUE;
-            }
-
-            Status = NtMakeTemporaryObject(LinkHandle);
-            if (! NT_SUCCESS(Status))
-            {
-                DPRINT1("NtMakeTemporaryObject(%wZ) failed (Status %lx)\n",
-                     &DeviceName, Status);
-                _SEH2_LEAVE;
-            }
-
-            Status = NtClose(LinkHandle);
-            LinkHandle = NULL;
-            if (! NT_SUCCESS(Status))
-            {
-                DPRINT1("NtClose(%wZ) failed (Status %lx)\n",
-                     &DeviceName, Status);
-                _SEH2_LEAVE;
-            }
-        }
-
-        /* Don't create symlink if we don't have a target */
-        if (! RequestLinkTarget || RequestLinkTarget->Length == 0)
-            _SEH2_LEAVE;
-
-        if (AddHistory)
-        {
-            HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
-                RtlAllocateHeap(Win32CsrApiHeap,
-                                HEAP_ZERO_MEMORY,
-                                sizeof(CSRSS_DOS_DEVICE_HISTORY_ENTRY));
-            if (! HistoryEntry)
-            {
-                DPRINT1("Failed to allocate memory\n");
-                Status = STATUS_NO_MEMORY;
-                _SEH2_LEAVE;
-            }
-
-            HistoryEntry->Target.Buffer =
-                RtlAllocateHeap(Win32CsrApiHeap,
-                                HEAP_ZERO_MEMORY,
-                                LinkTarget.Length);
-            if (! HistoryEntry->Target.Buffer)
-            {
-                DPRINT1("Failed to allocate memory\n");
-                Status = STATUS_NO_MEMORY;
-                _SEH2_LEAVE;
-            }
-            HistoryEntry->Target.Length =
-                HistoryEntry->Target.MaximumLength =
-                    LinkTarget.Length;
-            RtlCopyUnicodeString(&HistoryEntry->Target,
-                                 &LinkTarget);
-
-            HistoryEntry->Device.Buffer =
-                RtlAllocateHeap(Win32CsrApiHeap,
-                                HEAP_ZERO_MEMORY,
-                                RequestDeviceName.Length);
-            if (! HistoryEntry->Device.Buffer)
-            {
-                DPRINT1("Failed to allocate memory\n");
-                Status = STATUS_NO_MEMORY;
-                _SEH2_LEAVE;
-            }
-            HistoryEntry->Device.Length =
-                HistoryEntry->Device.MaximumLength =
-                    RequestDeviceName.Length;
-            RtlCopyUnicodeString(&HistoryEntry->Device,
-                                 &RequestDeviceName);
-
-            /* Remember previous symlink target for this device */
-            InsertHeadList(ListHead,
-                           &HistoryEntry->Entry);
-            HistoryEntry = NULL;
-        }
-
-        RtlAllocateAndInitializeSid(&WorldAuthority,
-                                    1,
-                                    SECURITY_WORLD_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    &WorldSid);
-
-        RtlAllocateAndInitializeSid(&SystemAuthority,
-                                    1,
-                                    SECURITY_LOCAL_SYSTEM_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    &SystemSid);
-
-        RtlAllocateAndInitializeSid(&SystemAuthority,
-                                    2,
-                                    SECURITY_BUILTIN_DOMAIN_RID,
-                                    DOMAIN_ALIAS_RID_ADMINS,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    SECURITY_NULL_RID,
-                                    &AdminSid);
-
-        SidLength = RtlLengthSid(SystemSid) +
-            RtlLengthSid(AdminSid) +
-            RtlLengthSid(WorldSid);
-        Length = sizeof(ACL) + SidLength + 3 * sizeof(ACCESS_ALLOWED_ACE);
-
-        SecurityDescriptor = RtlAllocateHeap(Win32CsrApiHeap,
-                                             0,
-                                             SECURITY_DESCRIPTOR_MIN_LENGTH + Length);
-        if (! SecurityDescriptor)
-        {
-            DPRINT1("Failed to allocate memory\n");
-            Status = STATUS_NO_MEMORY;
-            _SEH2_LEAVE;
-        }
-
-        Dacl = (PACL)((ULONG_PTR)SecurityDescriptor + SECURITY_DESCRIPTOR_MIN_LENGTH);
-        Status = RtlCreateSecurityDescriptor(SecurityDescriptor,
-                                             SECURITY_DESCRIPTOR_REVISION);
-        if (! NT_SUCCESS(Status))
-        {
-            DPRINT1("RtlCreateSecurityDescriptor() failed (Status %lx)\n",
-                 Status);
-            _SEH2_LEAVE;
-        }
-
-        Status = RtlCreateAcl(Dacl,
-                              Length,
-                              ACL_REVISION);
-        if (! NT_SUCCESS(Status))
-        {
-            DPRINT1("RtlCreateAcl() failed (Status %lx)\n",
-                 Status);
-            _SEH2_LEAVE;
-        }
-
-        (void) RtlAddAccessAllowedAce(Dacl,
-                                      ACL_REVISION,
-                                      GENERIC_ALL,
-                                      SystemSid);
-        (void) RtlAddAccessAllowedAce(Dacl,
-                                      ACL_REVISION,
-                                      GENERIC_ALL,
-                                      AdminSid);
-        (void) RtlAddAccessAllowedAce(Dacl,
-                                      ACL_REVISION,
-                                      STANDARD_RIGHTS_READ,
-                                      WorldSid);
-
-        Status = RtlSetDaclSecurityDescriptor(SecurityDescriptor,
-                                              TRUE,
-                                              Dacl,
-                                              FALSE);
-        if (! NT_SUCCESS(Status))
-        {
-            DPRINT1("RtlSetDaclSecurityDescriptor() failed (Status %lx)\n",
-                 Status);
-            _SEH2_LEAVE;
-        }
-
-        InitializeObjectAttributes(&ObjectAttributes,
-                                   &DeviceName,
-                                   OBJ_CASE_INSENSITIVE,
-                                   NULL,
-                                   SecurityDescriptor);
-        Status = NtCreateSymbolicLinkObject(&LinkHandle,
-                                            SYMBOLIC_LINK_ALL_ACCESS,
-                                            &ObjectAttributes,
-                                            RequestLinkTarget);
-        if (NT_SUCCESS(Status))
-        {
-            Status = NtMakePermanentObject(LinkHandle);
-            if (! NT_SUCCESS(Status))
-            {
-                DPRINT1("NtMakePermanentObject(%wZ) failed (Status %lx)\n",
-                     &DeviceName, Status);
-            }
-        }
-        else
-        {
-            DPRINT1("NtCreateSymbolicLinkObject(%wZ) failed (Status %lx)\n",
-                 &DeviceName, Status);
-        }
-    }
-    _SEH2_FINALLY
-    {
-        (void) RtlLeaveCriticalSection(&Win32CsrDefineDosDeviceCritSec);
-        if (DeviceName.Buffer)
-            (void) RtlFreeHeap(Win32CsrApiHeap,
-                               0,
-                               DeviceName.Buffer);
-        if (LinkTarget.Buffer)
-            (void) RtlFreeHeap(Win32CsrApiHeap,
-                               0,
-                               LinkTarget.Buffer);
-        if (SecurityDescriptor)
-            (void) RtlFreeHeap(Win32CsrApiHeap,
-                               0,
-                               SecurityDescriptor);
-        if (LinkHandle)
-            (void) NtClose(LinkHandle);
-        if (SystemSid)
-            (void) RtlFreeSid(SystemSid);
-        if (AdminSid)
-            (void) RtlFreeSid(AdminSid);
-        if (WorldSid)
-            (void) RtlFreeSid(WorldSid);
-        RtlFreeUnicodeString(&RequestDeviceName);
-        if (HistoryEntry)
-        {
-            if (HistoryEntry->Target.Buffer)
-                (void) RtlFreeHeap(Win32CsrApiHeap,
-                                   0,
-                                   HistoryEntry->Target.Buffer);
-            if (HistoryEntry->Device.Buffer)
-                (void) RtlFreeHeap(Win32CsrApiHeap,
-                                   0,
-                                   HistoryEntry->Device.Buffer);
-            (void) RtlFreeHeap(Win32CsrApiHeap,
-                               0,
-                               HistoryEntry);
-        }
-    }
-    _SEH2_END
-
-    DPRINT("CsrDefineDosDevice Exit, Statux: 0x%x\n", Status);
-    return Status;
-}
-
-void CsrCleanupDefineDosDevice(void)
-{
-    PLIST_ENTRY Entry, ListHead;
-    PCSRSS_DOS_DEVICE_HISTORY_ENTRY HistoryEntry;
-
-    (void) RtlDeleteCriticalSection(&Win32CsrDefineDosDeviceCritSec);
-
-    ListHead = &DosDeviceHistory;
-    Entry = ListHead->Flink;
-    while (Entry != ListHead)
-    {
-        HistoryEntry = (PCSRSS_DOS_DEVICE_HISTORY_ENTRY)
-            CONTAINING_RECORD(Entry,
-                              CSRSS_DOS_DEVICE_HISTORY_ENTRY,
-                              Entry);
-        Entry = Entry->Flink;
-
-        if (HistoryEntry)
-        {
-            if (HistoryEntry->Target.Buffer)
-                (void) RtlFreeHeap(Win32CsrApiHeap,
-                                   0,
-                                   HistoryEntry->Target.Buffer);
-            if (HistoryEntry->Device.Buffer)
-                (void) RtlFreeHeap(Win32CsrApiHeap,
-                                   0,
-                                   HistoryEntry->Device.Buffer);
-            (void) RtlFreeHeap(Win32CsrApiHeap,
-                               0,
-                               HistoryEntry);
-        }
-    }
-}
-/* EOF */
diff --git a/win32ss/user/win32csr/file.h b/win32ss/user/win32csr/file.h
deleted file mode 100644 (file)
index fa33b62..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS system libraries
- * FILE:            subsystem/win32/csrss/win32csr/file.h
- * PURPOSE:         File handling
- * PROGRAMMERS:     Pierre Schweitzer (pierre.schweitzer@reactos.org)
- * NOTE:            Belongs to basesrv.dll
- */
-
-#pragma once
-
-#include "api.h"
-
-typedef struct tagCSRSS_DOS_DEVICE_HISTORY_ENTRY
-{
-    UNICODE_STRING Device;
-    UNICODE_STRING Target;
-    LIST_ENTRY Entry;
-} CSRSS_DOS_DEVICE_HISTORY_ENTRY, *PCSRSS_DOS_DEVICE_HISTORY_ENTRY;
-
-/* Api functions */
-CSR_API(CsrGetTempFile);
-CSR_API(CsrDefineDosDevice);
-
-/* functions */
-void CsrCleanupDefineDosDevice();
-
-/* EOF */