[KERNEL32/CONSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 15 Nov 2012 21:02:01 +0000 (21:02 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 15 Nov 2012 21:02:01 +0000 (21:02 +0000)
- Use capture buffers to pass (variable-length) strings to the console server.
- Merge the CSRSS_ADD_CONSOLE_ALIAS and CSRSS_GET_CONSOLE_ALIAS structures into a unique structure CSRSS_CONSOLE_ALIAS.

TODO: Check what happens to the "/ sizeof(WCHAR);" in GetConsoleAliasesW.

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

dll/win32/kernel32/client/console/alias.c
include/reactos/subsys/win/conmsg.h
win32ss/user/consrv/alias.c

index aa8356e..d432113 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
- * FILE:            dll/win32/kernel32/client/console/console.c
- * PURPOSE:         Win32 server console functions
+ * FILE:            dll/win32/kernel32/client/console/alias.c
+ * PURPOSE:         Win32 Console Client Alias support functions
  * PROGRAMMERS:     David Welch (welch@cwcom.net) (welch@mcmail.com)
  *                  Christoph von Wittich (christoph_vw@reactos.org)
  *                  Johannes Anderwald (janderwald@reactos.org)
 #define NDEBUG
 #include <debug.h>
 
+
 /* FUNCTIONS ******************************************************************/
 
 /*
- * @unimplemented
+ * @implemented
  */
 BOOL
 WINAPI
@@ -26,54 +27,77 @@ AddConsoleAliasW(LPCWSTR lpSource,
                  LPCWSTR lpTarget,
                  LPCWSTR lpExeName)
 {
-    PCSR_API_MESSAGE Request;
     NTSTATUS Status;
-    ULONG SourceLength;
-    ULONG TargetLength = 0;
-    ULONG ExeLength;
-    ULONG Size;
-    ULONG RequestLength;
-    WCHAR * Ptr;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_ALIAS ConsoleAlias = &ApiMessage.Data.ConsoleAlias;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
+    ULONG CapturedStrings;
 
     DPRINT("AddConsoleAliasW enterd with lpSource %S lpTarget %S lpExeName %S\n", lpSource, lpTarget, lpExeName);
 
-    ExeLength = wcslen(lpExeName) + 1;
-    SourceLength = wcslen(lpSource)+ 1;
-    if (lpTarget)
-        TargetLength = wcslen(lpTarget) + 1;
+    /* Determine the needed sizes */
+    ConsoleAlias->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
+    ConsoleAlias->ExeLength    = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+    CapturedStrings = 2;
 
-    Size = (ExeLength + SourceLength + TargetLength) * sizeof(WCHAR);
-    RequestLength = sizeof(CSR_API_MESSAGE) + Size;
+    if (lpTarget) /* The target can be optional */
+    {
+        ConsoleAlias->TargetLength = (wcslen(lpTarget) + 1) * sizeof(WCHAR);
+        CapturedStrings++;
+    }
+    else
+    {
+        ConsoleAlias->TargetLength = 0;
+    }
 
-    Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, RequestLength);
-    Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE));
+    /* Allocate a Capture Buffer */
+    CaptureBuffer = CsrAllocateCaptureBuffer(CapturedStrings,
+                                             ConsoleAlias->SourceLength +
+                                             ConsoleAlias->ExeLength    +
+                                             ConsoleAlias->TargetLength);
+    if (CaptureBuffer == NULL)
+    {
+        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return FALSE;
+    }
 
-    wcscpy(Ptr, lpSource);
-    Request->Data.AddConsoleAlias.SourceLength = SourceLength;
-    Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE) + SourceLength * sizeof(WCHAR));
+    /* Capture the strings */
+    CsrCaptureMessageBuffer(CaptureBuffer,
+                            (PVOID)lpSource,
+                            ConsoleAlias->SourceLength,
+                            &ConsoleAlias->Source);
 
-    wcscpy(Ptr, lpExeName);
-    Request->Data.AddConsoleAlias.ExeLength = ExeLength;
-    Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE) + (ExeLength + SourceLength)* sizeof(WCHAR));
+    CsrCaptureMessageBuffer(CaptureBuffer,
+                            (PVOID)lpExeName,
+                            ConsoleAlias->ExeLength,
+                            &ConsoleAlias->Exe);
 
-    if (lpTarget) /* target can be optional */
-        wcscpy(Ptr, lpTarget);
+    if (lpTarget) /* The target can be optional */
+    {
+        CsrCaptureMessageBuffer(CaptureBuffer,
+                                (PVOID)lpTarget,
+                                ConsoleAlias->TargetLength,
+                                &ConsoleAlias->Target);
+    }
+    else
+    {
+        ConsoleAlias->Target = NULL;
+    }
 
-    Request->Data.AddConsoleAlias.TargetLength = TargetLength;
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 CaptureBuffer,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAddAlias),
+                                 sizeof(CSRSS_CONSOLE_ALIAS));
 
-    Status = CsrClientCallServer(Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, ADD_CONSOLE_ALIAS),
-                                 RequestLength);
+    CsrFreeCaptureBuffer(CaptureBuffer);
 
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
-        RtlFreeHeap(GetProcessHeap(), 0, Request);
         return FALSE;
     }
 
-    RtlFreeHeap(GetProcessHeap(), 0, Request);
     return TRUE;
 }
 
@@ -93,21 +117,21 @@ AddConsoleAliasA(LPCSTR lpSource,
     BOOL bRetVal;
 
     if (lpSource)
-        BasepAnsiStringToHeapUnicodeString(lpSource, (LPWSTR*) &lpSourceW);
+        BasepAnsiStringToHeapUnicodeString(lpSource, (LPWSTR*)&lpSourceW);
     if (lpTarget)
-        BasepAnsiStringToHeapUnicodeString(lpTarget, (LPWSTR*) &lpTargetW);
+        BasepAnsiStringToHeapUnicodeString(lpTarget, (LPWSTR*)&lpTargetW);
     if (lpExeName)
-        BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
+        BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW);
 
     bRetVal = AddConsoleAliasW(lpSourceW, lpTargetW, lpExeNameW);
 
     /* Clean up */
     if (lpSourceW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpSourceW);
+        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpSourceW);
     if (lpTargetW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpTargetW);
+        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpTargetW);
     if (lpExeNameW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
+        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW);
 
     return bRetVal;
 }
@@ -123,16 +147,12 @@ GetConsoleAliasW(LPWSTR lpSource,
                  DWORD TargetBufferLength,
                  LPWSTR lpExeName)
 {
-    PCSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
     NTSTATUS Status;
-    ULONG Size;
-    ULONG ExeLength;
-    ULONG SourceLength;
-    ULONG RequestLength;
-    WCHAR * Ptr;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_ALIAS ConsoleAlias = &ApiMessage.Data.ConsoleAlias;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    DPRINT("GetConsoleAliasW entered lpSource %S lpExeName %S\n", lpSource, lpExeName);
+    DPRINT("GetConsoleAliasW entered with lpSource %S lpExeName %S\n", lpSource, lpExeName);
 
     if (lpTargetBuffer == NULL)
     {
@@ -140,63 +160,61 @@ GetConsoleAliasW(LPWSTR lpSource,
         return 0;
     }
 
-    ExeLength = wcslen(lpExeName) + 1;
-    SourceLength = wcslen(lpSource) + 1;
+    /* Determine the needed sizes */
+    ConsoleAlias->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
+    ConsoleAlias->ExeLength    = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
 
-    Size = (ExeLength + SourceLength) * sizeof(WCHAR);
+    ConsoleAlias->Target = NULL;
+    ConsoleAlias->TargetLength = TargetBufferLength;
 
-    RequestLength = Size + sizeof(CSR_API_MESSAGE);
-    Request = RtlAllocateHeap(GetProcessHeap(), 0, RequestLength);
-    if (Request == NULL)
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
-    }
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, TargetBufferLength);
+    /* Allocate a Capture Buffer */
+    CaptureBuffer = CsrAllocateCaptureBuffer(3, ConsoleAlias->SourceLength +
+                                                ConsoleAlias->ExeLength    +
+                                                ConsoleAlias->TargetLength);
     if (!CaptureBuffer)
     {
         DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        RtlFreeHeap(GetProcessHeap(), 0, Request);
         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
         return 0;
     }
 
-    Request->Data.GetConsoleAlias.TargetBuffer = NULL;
-
+    /* Capture the strings */
     CsrCaptureMessageBuffer(CaptureBuffer,
-                            NULL,
-                            TargetBufferLength,
-                            (PVOID*)&Request->Data.GetConsoleAlias.TargetBuffer);
-
-    Request->Data.GetConsoleAlias.TargetBufferLength = TargetBufferLength;
+                            (PVOID)lpSource,
+                            ConsoleAlias->SourceLength,
+                            &ConsoleAlias->Source);
 
-    Ptr = (LPWSTR)((ULONG_PTR)Request + sizeof(CSR_API_MESSAGE));
-    wcscpy(Ptr, lpSource);
-    Ptr += SourceLength;
-    wcscpy(Ptr, lpExeName);
+    CsrCaptureMessageBuffer(CaptureBuffer,
+                            (PVOID)lpExeName,
+                            ConsoleAlias->ExeLength,
+                            &ConsoleAlias->Exe);
 
-    Request->Data.GetConsoleAlias.ExeLength = ExeLength;
-    Request->Data.GetConsoleAlias.SourceLength = SourceLength;
+    /* Allocate space for the target buffer */
+    CsrAllocateMessagePointer(CaptureBuffer,
+                              ConsoleAlias->TargetLength,
+                              (PVOID*)&ConsoleAlias->Target);
 
-    Status = CsrClientCallServer(Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_ALIAS),
-                                 sizeof(CSR_API_MESSAGE) + Size);
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAlias),
+                                 sizeof(CSRSS_CONSOLE_ALIAS));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
-        RtlFreeHeap(GetProcessHeap(), 0, Request);
         CsrFreeCaptureBuffer(CaptureBuffer);
         BaseSetLastNTError(Status);
         return 0;
     }
 
-    wcscpy(lpTargetBuffer, Request->Data.GetConsoleAlias.TargetBuffer);
-    RtlFreeHeap(GetProcessHeap(), 0, Request);
+    /* Copy the returned target string into the user buffer */
+    // wcscpy(lpTargetBuffer, ConsoleAlias->Target);
+    memcpy(lpTargetBuffer,
+           ConsoleAlias->Target,
+           ConsoleAlias->TargetLength);
+
+    /* Release the capture buffer and exits */
     CsrFreeCaptureBuffer(CaptureBuffer);
 
-    return Request->Data.GetConsoleAlias.BytesWritten;
+    return ConsoleAlias->TargetLength;
 }
 
 
@@ -272,16 +290,30 @@ GetConsoleAliasA(LPSTR lpSource,
  */
 DWORD
 WINAPI
-GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
-                     DWORD ExeNameBufferLength)
+GetConsoleAliasesW(LPWSTR AliasBuffer,
+                   DWORD AliasBufferLength,
+                   LPWSTR ExeName)
 {
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAliases = &ApiMessage.Data.GetAllConsoleAliases;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    DPRINT("GetConsoleAliasExesW entered\n");
+    DPRINT("GetConsoleAliasesW entered\n");
 
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength);
+    /* Determine the needed sizes */
+    GetAllConsoleAliases->ExeLength = GetConsoleAliasesLengthW(ExeName);
+    if (GetAllConsoleAliases->ExeLength == 0 ||
+        GetAllConsoleAliases->ExeLength > AliasBufferLength)
+    {
+        return 0;
+    }
+
+    GetAllConsoleAliases->AliasesBufferLength = AliasBufferLength;
+
+    /* Allocate a Capture Buffer */
+    CaptureBuffer = CsrAllocateCaptureBuffer(2, GetAllConsoleAliases->ExeLength +
+                                                GetAllConsoleAliases->AliasesBufferLength);
     if (!CaptureBuffer)
     {
         DPRINT1("CsrAllocateCaptureBuffer failed!\n");
@@ -289,29 +321,36 @@ GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
         return 0;
     }
 
+    /* Capture the exe name and allocate space for the aliases buffer */
+    CsrCaptureMessageBuffer(CaptureBuffer,
+                            (PVOID)ExeName,
+                            GetAllConsoleAliases->ExeLength,
+                            (PVOID*)&GetAllConsoleAliases->ExeName);
+
     CsrAllocateMessagePointer(CaptureBuffer,
-                              ExeNameBufferLength,
-                              (PVOID*)&Request.Data.GetConsoleAliasesExes.ExeNames);
-    Request.Data.GetConsoleAliasesExes.Length = ExeNameBufferLength;
+                              GetAllConsoleAliases->AliasesBufferLength,
+                              (PVOID*)&GetAllConsoleAliases->AliasesBuffer);
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_ALIASES_EXES),
-                                 sizeof(CSR_API_MESSAGE));
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliases),
+                                 sizeof(CSRSS_GET_ALL_CONSOLE_ALIASES));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
-        CsrFreeCaptureBuffer(CaptureBuffer);
         return 0;
     }
 
-    memcpy(lpExeNameBuffer,
-           Request.Data.GetConsoleAliasesExes.ExeNames,
-           Request.Data.GetConsoleAliasesExes.BytesWritten);
+    /* Copy the returned aliases string into the user buffer */
+    // wcscpy(AliasBuffer, GetAllConsoleAliases->AliasesBuffer);
+    memcpy(AliasBuffer,
+           GetAllConsoleAliases->AliasesBuffer,
+           GetAllConsoleAliases->AliasesBufferLength);
 
+    /* Release the capture buffer and exits */
     CsrFreeCaptureBuffer(CaptureBuffer);
-    return Request.Data.GetConsoleAliasesExes.BytesWritten;
+
+    return GetAllConsoleAliases->AliasesBufferLength; // / sizeof(WCHAR); (original code)
 }
 
 
@@ -320,23 +359,31 @@ GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
  */
 DWORD
 WINAPI
-GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
-                     DWORD ExeNameBufferLength)
+GetConsoleAliasesA(LPSTR AliasBuffer,
+                   DWORD AliasBufferLength,
+                   LPSTR ExeName)
 {
-    LPWSTR lpwExeNameBuffer;
-    DWORD dwResult;
+    DWORD dwRetVal = 0;
+    LPWSTR lpwExeName = NULL;
+    LPWSTR lpwAliasBuffer;
 
-    DPRINT("GetConsoleAliasExesA entered\n");
+    DPRINT("GetConsoleAliasesA entered\n");
 
-    lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength * sizeof(WCHAR));
+    if (ExeName)
+        BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*)&lpwExeName);
 
-    dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength * sizeof(WCHAR));
+    lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR));
 
-    if (dwResult)
-        dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult / sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL);
+    dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength * sizeof(WCHAR), lpwExeName);
 
-    HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer);
-    return dwResult;
+    if (lpwExeName)
+        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpwExeName);
+
+    if (dwRetVal)
+        dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal /**/ / sizeof(WCHAR) /**/, AliasBuffer, AliasBufferLength, NULL, NULL);
+
+    HeapFree(GetProcessHeap(), 0, lpwAliasBuffer);
+    return dwRetVal;
 }
 
 
@@ -345,27 +392,53 @@ GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
  */
 DWORD
 WINAPI
-GetConsoleAliasExesLengthW(VOID)
+GetConsoleAliasesLengthW(LPWSTR lpExeName)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH GetAllConsoleAliasesLength = &ApiMessage.Data.GetAllConsoleAliasesLength;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    DPRINT("GetConsoleAliasExesLengthW entered\n");
+    DPRINT("GetConsoleAliasesLengthW entered\n");
+
+    if (lpExeName == NULL)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return 0;
+    }
 
-    Request.Data.GetConsoleAliasesExesLength.Length = 0;
+    GetAllConsoleAliasesLength->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+    GetAllConsoleAliasesLength->Length = 0;
 
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_ALIASES_EXES_LENGTH),
-                                 sizeof(CSR_API_MESSAGE));
+    /* Allocate a Capture Buffer */
+    CaptureBuffer = CsrAllocateCaptureBuffer(1, GetAllConsoleAliasesLength->ExeLength);
+    if (!CaptureBuffer)
+    {
+        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return 0;
+    }
+
+    /* Capture the exe name */
+    CsrCaptureMessageBuffer(CaptureBuffer,
+                            (PVOID)lpExeName,
+                            GetAllConsoleAliasesLength->ExeLength,
+                            (PVOID)&GetAllConsoleAliasesLength->ExeName);
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 CaptureBuffer,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasesLength),
+                                 sizeof(CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH));
 
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+    CsrFreeCaptureBuffer(CaptureBuffer);
+
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return 0;
     }
 
-    return Request.Data.GetConsoleAliasesExesLength.Length;
+    return GetAllConsoleAliasesLength->Length;
 }
 
 
@@ -374,18 +447,23 @@ GetConsoleAliasExesLengthW(VOID)
  */
 DWORD
 WINAPI
-GetConsoleAliasExesLengthA(VOID)
+GetConsoleAliasesLengthA(LPSTR lpExeName)
 {
-    DWORD dwLength;
+    DWORD dwRetVal = 0;
+    LPWSTR lpExeNameW = NULL;
 
-    DPRINT("GetConsoleAliasExesLengthA entered\n");
+    if (lpExeName)
+        BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW);
 
-    dwLength = GetConsoleAliasExesLengthW();
+    dwRetVal = GetConsoleAliasesLengthW(lpExeNameW);
+    if (dwRetVal)
+        dwRetVal /= sizeof(WCHAR);
 
-    if (dwLength)
-        dwLength /= sizeof(WCHAR);
+    /* Clean up */
+    if (lpExeNameW)
+        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW);
 
-    return dwLength;
+    return dwRetVal;
 }
 
 
@@ -394,36 +472,52 @@ GetConsoleAliasExesLengthA(VOID)
  */
 DWORD
 WINAPI
-GetConsoleAliasesW(LPWSTR AliasBuffer,
-                   DWORD AliasBufferLength,
-                   LPWSTR ExeName)
+GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
+                     DWORD ExeNameBufferLength)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
-    DWORD dwLength;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes = &ApiMessage.Data.GetConsoleAliasesExes;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    DPRINT("GetConsoleAliasesW entered\n");
+    DPRINT("GetConsoleAliasExesW entered\n");
 
-    dwLength = GetConsoleAliasesLengthW(ExeName);
-    if (!dwLength || dwLength > AliasBufferLength)
+    /* Allocate a Capture Buffer */
+    CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength);
+    if (!CaptureBuffer)
+    {
+        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
         return 0;
+    }
 
-    Request.Data.GetAllConsoleAlias.AliasBuffer = AliasBuffer;
-    Request.Data.GetAllConsoleAlias.AliasBufferLength = AliasBufferLength;
-    Request.Data.GetAllConsoleAlias.lpExeName = ExeName;
+    GetConsoleAliasesExes->Length = ExeNameBufferLength;
 
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_ALL_CONSOLE_ALIASES),
-                                 sizeof(CSR_API_MESSAGE));
+    /* Allocate space for the exe name buffer */
+    CsrAllocateMessagePointer(CaptureBuffer,
+                              ExeNameBufferLength,
+                              (PVOID*)&GetConsoleAliasesExes->ExeNames);
 
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 CaptureBuffer,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExes),
+                                 sizeof(CSRSS_GET_CONSOLE_ALIASES_EXES));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
+        CsrFreeCaptureBuffer(CaptureBuffer);
         BaseSetLastNTError(Status);
         return 0;
     }
 
-    return Request.Data.GetAllConsoleAlias.BytesWritten / sizeof(WCHAR);
+    /* Copy the returned target string into the user buffer */
+    memcpy(lpExeNameBuffer,
+           GetConsoleAliasesExes->ExeNames,
+           GetConsoleAliasesExes->Length);
+
+    /* Release the capture buffer and exits */
+    CsrFreeCaptureBuffer(CaptureBuffer);
+
+    return GetConsoleAliasesExes->Length;
 }
 
 
@@ -432,31 +526,23 @@ GetConsoleAliasesW(LPWSTR AliasBuffer,
  */
 DWORD
 WINAPI
-GetConsoleAliasesA(LPSTR AliasBuffer,
-                   DWORD AliasBufferLength,
-                   LPSTR ExeName)
+GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
+                     DWORD ExeNameBufferLength)
 {
-    DWORD dwRetVal = 0;
-    LPWSTR lpwExeName = NULL;
-    LPWSTR lpwAliasBuffer;
-
-    DPRINT("GetConsoleAliasesA entered\n");
-
-    if (ExeName)
-        BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*) &lpwExeName);
+    LPWSTR lpwExeNameBuffer;
+    DWORD dwResult;
 
-    lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR));
+    DPRINT("GetConsoleAliasExesA entered\n");
 
-    dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength, lpwExeName);
+    lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength * sizeof(WCHAR));
 
-    if (lpwExeName)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpwExeName);
+    dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength * sizeof(WCHAR));
 
-    if (dwRetVal)
-        dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal, AliasBuffer, AliasBufferLength, NULL, NULL);
+    if (dwResult)
+        dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult / sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL);
 
-    HeapFree(GetProcessHeap(), 0, lpwAliasBuffer);
-    return dwRetVal;
+    HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer);
+    return dwResult;
 }
 
 
@@ -465,28 +551,28 @@ GetConsoleAliasesA(LPSTR AliasBuffer,
  */
 DWORD
 WINAPI
-GetConsoleAliasesLengthW(LPWSTR lpExeName)
+GetConsoleAliasExesLengthW(VOID)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength = &ApiMessage.Data.GetConsoleAliasesExesLength;
 
-    DPRINT("GetConsoleAliasesLengthW entered\n");
+    DPRINT("GetConsoleAliasExesLengthW entered\n");
 
-    Request.Data.GetAllConsoleAliasesLength.lpExeName = lpExeName;
-    Request.Data.GetAllConsoleAliasesLength.Length = 0;
+    GetConsoleAliasesExesLength->Length = 0;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_ALL_CONSOLE_ALIASES_LENGTH),
-                                 sizeof(CSR_API_MESSAGE));
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExesLength),
+                                 sizeof(CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH));
 
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return 0;
     }
 
-    return Request.Data.GetAllConsoleAliasesLength.Length;
+    return GetConsoleAliasesExesLength->Length;
 }
 
 
@@ -495,23 +581,18 @@ GetConsoleAliasesLengthW(LPWSTR lpExeName)
  */
 DWORD
 WINAPI
-GetConsoleAliasesLengthA(LPSTR lpExeName)
+GetConsoleAliasExesLengthA(VOID)
 {
-    DWORD dwRetVal = 0;
-    LPWSTR lpExeNameW = NULL;
+    DWORD dwLength;
 
-    if (lpExeName)
-        BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
+    DPRINT("GetConsoleAliasExesLengthA entered\n");
 
-    dwRetVal = GetConsoleAliasesLengthW(lpExeNameW);
-    if (dwRetVal)
-        dwRetVal /= sizeof(WCHAR);
+    dwLength = GetConsoleAliasExesLengthW();
 
-    /* Clean up */
-    if (lpExeNameW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
+    if (dwLength)
+        dwLength /= sizeof(WCHAR);
 
-    return dwRetVal;
+    return dwLength;
 }
 
 /* EOF */
index 6b0ee8e..d597192 100644 (file)
@@ -416,39 +416,41 @@ typedef struct
     HICON  WindowIcon;
 } CSRSS_SET_CONSOLE_ICON, *PCSRSS_SET_CONSOLE_ICON;
 
-typedef struct
-{
-    ULONG SourceLength;
-    ULONG ExeLength;
-    ULONG TargetLength;
-} CSRSS_ADD_CONSOLE_ALIAS, *PCSRSS_ADD_CONSOLE_ALIAS;
+
+
+
+
+
+
+
 
 typedef struct
 {
-    ULONG SourceLength;
-    ULONG ExeLength;
-    ULONG BytesWritten;
-    ULONG TargetBufferLength;
-    PVOID TargetBuffer;
-} CSRSS_GET_CONSOLE_ALIAS, *PCSRSS_GET_CONSOLE_ALIAS;
+    ULONG  SourceLength;
+    ULONG  TargetLength; // Also used for storing the number of bytes written.
+    ULONG  ExeLength;
+    LPWSTR Source;
+    LPWSTR Target;
+    LPWSTR Exe;
+} CSRSS_CONSOLE_ALIAS, *PCSRSS_CONSOLE_ALIAS;
 
 typedef struct
 {
-    LPWSTR lpExeName;
-    DWORD BytesWritten;
-    DWORD AliasBufferLength;
-    LPWSTR AliasBuffer;
+    DWORD ExeLength;
+    DWORD AliasesBufferLength;
+    LPWSTR ExeName;
+    LPWSTR AliasesBuffer;
 } CSRSS_GET_ALL_CONSOLE_ALIASES, *PCSRSS_GET_ALL_CONSOLE_ALIASES;
 
 typedef struct
 {
-    LPWSTR lpExeName;
     DWORD Length;
+    DWORD ExeLength;
+    LPWSTR ExeName;
 } CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH, *PCSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH;
 
 typedef struct
 {
-    DWORD BytesWritten;
     DWORD Length;
     LPWSTR ExeNames;
 } CSRSS_GET_CONSOLE_ALIASES_EXES, *PCSRSS_GET_CONSOLE_ALIASES_EXES;
@@ -458,28 +460,10 @@ typedef struct
     DWORD Length;
 } CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH, *PCSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH;
 
-typedef struct
-{
-    DWORD Event;
-    DWORD ProcessGroup;
-} CSRSS_GENERATE_CTRL_EVENT, *PCSRSS_GENERATE_CTRL_EVENT;
 
-typedef struct
-{
-    HANDLE ConsoleHandle;
-    DWORD NumInputEvents;
-} CSRSS_GET_NUM_INPUT_EVENTS, *PCSRSS_GET_NUM_INPUT_EVENTS;
 
-typedef struct
-{
-    HANDLE OutputHandle;
-    COORD Size;
-} CSRSS_SET_SCREEN_BUFFER_SIZE, *PCSRSS_SET_SCREEN_BUFFER_SIZE;
 
-typedef struct
-{
-    CONSOLE_SELECTION_INFO Info;
-} CSRSS_GET_CONSOLE_SELECTION_INFO, *PCSRSS_GET_CONSOLE_SELECTION_INFO;
+
 
 typedef struct
 {
@@ -513,6 +497,38 @@ typedef struct
 } CSRSS_GET_HISTORY_INFO, *PCSRSS_GET_HISTORY_INFO,
   CSRSS_SET_HISTORY_INFO, *PCSRSS_SET_HISTORY_INFO;;
 
+
+
+
+
+
+
+
+
+
+typedef struct
+{
+    DWORD Event;
+    DWORD ProcessGroup;
+} CSRSS_GENERATE_CTRL_EVENT, *PCSRSS_GENERATE_CTRL_EVENT;
+
+typedef struct
+{
+    HANDLE ConsoleHandle;
+    DWORD NumInputEvents;
+} CSRSS_GET_NUM_INPUT_EVENTS, *PCSRSS_GET_NUM_INPUT_EVENTS;
+
+typedef struct
+{
+    HANDLE OutputHandle;
+    COORD Size;
+} CSRSS_SET_SCREEN_BUFFER_SIZE, *PCSRSS_SET_SCREEN_BUFFER_SIZE;
+
+typedef struct
+{
+    CONSOLE_SELECTION_INFO Info;
+} CSRSS_GET_CONSOLE_SELECTION_INFO, *PCSRSS_GET_CONSOLE_SELECTION_INFO;
+
 typedef struct
 {
     UINT CodePage;
@@ -580,22 +596,24 @@ typedef struct _CONSOLE_API_MESSAGE
         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_CONSOLE_ALIAS ConsoleAlias;
+        CSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAliases;
         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_GET_COMMAND_HISTORY_LENGTH GetCommandHistoryLength;
         CSRSS_EXPUNGE_COMMAND_HISTORY ExpungeCommandHistory;
         CSRSS_SET_HISTORY_NUMBER_COMMANDS SetHistoryNumberCommands;
         CSRSS_GET_HISTORY_INFO GetHistoryInfo;
         CSRSS_SET_HISTORY_INFO SetHistoryInfo;
+
+        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_CONSOLE_CP GetConsoleCodePage;
         CSRSS_SET_CONSOLE_CP SetConsoleCodePage;
         CSRSS_GET_CONSOLE_OUTPUT_CP GetConsoleOutputCodePage;
index d9a40d5..f488be2 100644 (file)
@@ -7,7 +7,7 @@
  *                  Johannes Anderwald
  */
 
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
 
 #include "consrv.h"
 #include "conio.h"
 #include <debug.h>
 
 
+/* TYPES **********************************************************************/
+
 typedef struct tagALIAS_ENTRY
 {
     LPCWSTR lpSource;
     LPCWSTR lpTarget;
-    struct tagALIAS_ENTRY * Next;
+    struct tagALIAS_ENTRY* Next;
 } ALIAS_ENTRY, *PALIAS_ENTRY;
 
 typedef struct tagALIAS_HEADER
 {
     LPCWSTR lpExeName;
     PALIAS_ENTRY Data;
-    struct tagALIAS_HEADER * Next;
-
+    struct tagALIAS_HEADER* Next;
 } ALIAS_HEADER, *PALIAS_HEADER;
 
 
+/* PRIVATE FUNCTIONS **********************************************************/
+
 static
 PALIAS_HEADER
 IntFindAliasHeader(PALIAS_HEADER RootHeader, LPCWSTR lpExeName)
@@ -99,7 +102,7 @@ IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName)
     while(RootHeader)
     {
         INT diff;
-        DPRINT("IntGetAliasEntry>lpSource %S\n", RootHeader->lpSource);
+        DPRINT("IntGetAliasEntry->lpSource %S\n", RootHeader->lpSource);
         diff = _wcsicmp(RootHeader->lpSource, lpSrcName);
         if (!diff)
             return RootHeader;
@@ -112,7 +115,6 @@ IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName)
     return NULL;
 }
 
-
 VOID
 IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
 {
@@ -218,6 +220,7 @@ IntGetAllConsoleAliasesLength(PALIAS_HEADER Header)
     }
     return 0;
 }
+
 UINT
 IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT TargetBufferLength)
 {
@@ -244,6 +247,7 @@ IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT TargetBu
     TargetBuffer[Offset] = L'\0';
     return Offset * sizeof(WCHAR);
 }
+
 VOID
 IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry)
 {
@@ -261,11 +265,13 @@ IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry)
         LastLink = &CurEntry->Next;
     }
 }
+
 VOID
 IntDeleteAllAliases(PALIAS_HEADER RootHeader)
 {
     PALIAS_HEADER Header, NextHeader;
     PALIAS_ENTRY Entry, NextEntry;
+
     for (Header = RootHeader; Header; Header = NextHeader)
     {
         NextHeader = Header->Next;
@@ -278,33 +284,47 @@ IntDeleteAllAliases(PALIAS_HEADER RootHeader)
     }
 }
 
+
+/* PUBLIC SERVER APIS *********************************************************/
+
 CSR_API(SrvAddConsoleAlias)
 {
-    PCSRSS_ADD_CONSOLE_ALIAS AddConsoleAlias = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AddConsoleAlias;
+    PCSRSS_CONSOLE_ALIAS ConsoleAlias = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAlias;
     PCSRSS_CONSOLE Console;
     PALIAS_HEADER Header;
     PALIAS_ENTRY Entry;
-    WCHAR * lpExeName;
-    WCHAR * lpSource;
-    WCHAR * lpTarget;
-    //ULONG TotalLength;
-    //WCHAR * Ptr;
-
-    //TotalLength = AddConsoleAlias->SourceLength + AddConsoleAlias->ExeLength + AddConsoleAlias->TargetLength;
-    //Ptr = (WCHAR*)((ULONG_PTR)ApiMessage + sizeof(CSR_API_MESSAGE));
+    LPWSTR lpSource, lpTarget, lpExeName;
+
+    DPRINT("SrvAddConsoleAlias entered ApiMessage %p\n", ApiMessage);
+
+    if ( !CsrValidateMessageBuffer(ApiMessage,
+                                   &ConsoleAlias->Source,
+                                   ConsoleAlias->SourceLength,
+                                   sizeof(BYTE))                    ||
+         !CsrValidateMessageBuffer(ApiMessage,
+                                   &ConsoleAlias->Target,
+                                   ConsoleAlias->TargetLength,
+                                   sizeof(BYTE))                    ||
+         !CsrValidateMessageBuffer(ApiMessage,
+                                   &ConsoleAlias->Exe,
+                                   ConsoleAlias->ExeLength,
+                                   sizeof(BYTE)) )
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
 
-    lpSource = (WCHAR*)((ULONG_PTR)ApiMessage + sizeof(CSR_API_MESSAGE));
-    lpExeName = (WCHAR*)((ULONG_PTR)ApiMessage + sizeof(CSR_API_MESSAGE) + AddConsoleAlias->SourceLength * sizeof(WCHAR));
-    lpTarget = (AddConsoleAlias->TargetLength != 0 ? lpExeName + AddConsoleAlias->ExeLength : NULL);
+    lpSource  = ConsoleAlias->Source;
+    lpTarget  = (ConsoleAlias->TargetLength != 0 ? ConsoleAlias->Target : NULL);
+    lpExeName = ConsoleAlias->Exe;
 
-    DPRINT("SrvAddConsoleAlias entered ApiMessage %p lpSource %p lpExeName %p lpTarget %p\n", ApiMessage, lpSource, lpExeName, lpTarget);
+    DPRINT("SrvAddConsoleAlias lpSource %p lpExeName %p lpTarget %p\n", lpSource, lpExeName, lpTarget);
 
     if (lpExeName == NULL || lpSource == NULL)
     {
         return STATUS_INVALID_PARAMETER;
     }
 
-    ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+    ApiMessage->Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (!NT_SUCCESS(ApiMessage->Status))
     {
         return ApiMessage->Status;
@@ -322,7 +342,7 @@ CSR_API(SrvAddConsoleAlias)
         IntInsertAliasHeader(&Console->Aliases, Header);
     }
 
-    if (lpTarget == NULL) // delete the entry
+    if (lpTarget == NULL) // Delete the entry
     {
         Entry = IntGetAliasEntry(Header, lpSource);
         if (Entry)
@@ -353,30 +373,45 @@ CSR_API(SrvAddConsoleAlias)
 
 CSR_API(SrvGetConsoleAlias)
 {
-    PCSRSS_GET_CONSOLE_ALIAS GetConsoleAlias = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleAlias;
+    PCSRSS_CONSOLE_ALIAS ConsoleAlias = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAlias;
     PCSRSS_CONSOLE Console;
     PALIAS_HEADER Header;
     PALIAS_ENTRY Entry;
     UINT Length;
-    WCHAR * lpExeName;
-    WCHAR * lpSource;
-    WCHAR * lpTarget;
-
-    lpSource = (LPWSTR)((ULONG_PTR)ApiMessage + sizeof(CSR_API_MESSAGE));
-    lpExeName = lpSource + GetConsoleAlias->SourceLength;
-    lpTarget = GetConsoleAlias->TargetBuffer;
+    LPWSTR lpSource, lpTarget, lpExeName;
+
+    DPRINT("SrvGetConsoleAlias entered ApiMessage %p\n", ApiMessage);
+
+    if ( !CsrValidateMessageBuffer(ApiMessage,
+                                   &ConsoleAlias->Source,
+                                   ConsoleAlias->SourceLength,
+                                   sizeof(BYTE))                    ||
+         !CsrValidateMessageBuffer(ApiMessage,
+                                   &ConsoleAlias->Target,
+                                   ConsoleAlias->TargetLength,
+                                   sizeof(BYTE))                    ||
+         !CsrValidateMessageBuffer(ApiMessage,
+                                   &ConsoleAlias->Exe,
+                                   ConsoleAlias->ExeLength,
+                                   sizeof(BYTE)) )
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
 
+    lpSource  = ConsoleAlias->Source;
+    lpTarget  = ConsoleAlias->Target;
+    lpExeName = ConsoleAlias->Exe;
 
-    DPRINT("SrvGetConsoleAlias entered lpExeName %p lpSource %p TargetBuffer %p TargetBufferLength %u\n",
-           lpExeName, lpSource, lpTarget, GetConsoleAlias->TargetBufferLength);
+    DPRINT("SrvGetConsoleAlias lpExeName %p lpSource %p TargetBuffer %p TargetLength %u\n",
+           lpExeName, lpSource, lpTarget, ConsoleAlias->TargetLength);
 
-    if (GetConsoleAlias->ExeLength == 0 || lpTarget == NULL ||
-            GetConsoleAlias->TargetBufferLength == 0 || GetConsoleAlias->SourceLength == 0)
+    if (ConsoleAlias->ExeLength == 0 || lpTarget == NULL ||
+            ConsoleAlias->TargetLength == 0 || ConsoleAlias->SourceLength == 0)
     {
         return STATUS_INVALID_PARAMETER;
     }
 
-    ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+    ApiMessage->Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (!NT_SUCCESS(ApiMessage->Status))
     {
         return ApiMessage->Status;
@@ -396,71 +431,87 @@ CSR_API(SrvGetConsoleAlias)
         return STATUS_INVALID_PARAMETER;
     }
 
-    Length = (wcslen(Entry->lpTarget)+1) * sizeof(WCHAR);
-    if (Length > GetConsoleAlias->TargetBufferLength)
+    Length = (wcslen(Entry->lpTarget) + 1) * sizeof(WCHAR);
+    if (Length > ConsoleAlias->TargetLength)
     {
         ConioUnlockConsole(Console);
         return STATUS_BUFFER_TOO_SMALL;
     }
 
+/*
     if (!Win32CsrValidateBuffer(CsrGetClientThread()->Process, lpTarget,
-                                GetConsoleAlias->TargetBufferLength, 1))
+                                ConsoleAlias->TargetLength, 1))
     {
         ConioUnlockConsole(Console);
         return STATUS_ACCESS_VIOLATION;
     }
+*/
 
     wcscpy(lpTarget, Entry->lpTarget);
-    GetConsoleAlias->BytesWritten = Length;
+    ConsoleAlias->TargetLength = Length;
     ConioUnlockConsole(Console);
     return STATUS_SUCCESS;
 }
 
 CSR_API(SrvGetConsoleAliases)
 {
-    PCSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAlias = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllConsoleAlias;
+    PCSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAliases = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllConsoleAliases;
     PCSRSS_CONSOLE Console;
     ULONG BytesWritten;
     PALIAS_HEADER Header;
 
-    if (GetAllConsoleAlias->lpExeName == NULL)
+    if ( !CsrValidateMessageBuffer(ApiMessage,
+                                   (PVOID)&GetAllConsoleAliases->ExeName,
+                                   GetAllConsoleAliases->ExeLength,
+                                   sizeof(BYTE))                    ||
+         !CsrValidateMessageBuffer(ApiMessage,
+                                   (PVOID)&GetAllConsoleAliases->AliasesBuffer,
+                                   GetAllConsoleAliases->AliasesBufferLength,
+                                   sizeof(BYTE)) )
     {
         return STATUS_INVALID_PARAMETER;
     }
 
-    ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+    if (GetAllConsoleAliases->ExeName == NULL)
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    ApiMessage->Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (!NT_SUCCESS(ApiMessage->Status))
     {
         return ApiMessage->Status;
     }
 
-    Header = IntFindAliasHeader(Console->Aliases, GetAllConsoleAlias->lpExeName);
+    Header = IntFindAliasHeader(Console->Aliases, GetAllConsoleAliases->ExeName);
     if (!Header)
     {
         ConioUnlockConsole(Console);
         return STATUS_INVALID_PARAMETER;
     }
 
-    if (IntGetAllConsoleAliasesLength(Header) > GetAllConsoleAlias->AliasBufferLength)
+    if (IntGetAllConsoleAliasesLength(Header) > GetAllConsoleAliases->AliasesBufferLength)
     {
         ConioUnlockConsole(Console);
         return STATUS_BUFFER_OVERFLOW;
     }
 
+/*
     if (!Win32CsrValidateBuffer(CsrGetClientThread()->Process,
-                                GetAllConsoleAlias->AliasBuffer,
-                                GetAllConsoleAlias->AliasBufferLength,
+                                GetAllConsoleAliases->AliasesBuffer,
+                                GetAllConsoleAliases->AliasesBufferLength,
                                 1))
     {
         ConioUnlockConsole(Console);
         return STATUS_ACCESS_VIOLATION;
     }
+*/
 
     BytesWritten = IntGetAllConsoleAliases(Header,
-                                           GetAllConsoleAlias->AliasBuffer,
-                                           GetAllConsoleAlias->AliasBufferLength);
+                                           GetAllConsoleAliases->AliasesBuffer,
+                                           GetAllConsoleAliases->AliasesBufferLength);
 
-    GetAllConsoleAlias->BytesWritten = BytesWritten;
+    GetAllConsoleAliases->AliasesBufferLength = BytesWritten;
     ConioUnlockConsole(Console);
     return STATUS_SUCCESS;
 }
@@ -472,18 +523,26 @@ CSR_API(SrvGetConsoleAliasesLength)
     PALIAS_HEADER Header;
     UINT Length;
 
-    if (GetAllConsoleAliasesLength->lpExeName == NULL)
+    if (!CsrValidateMessageBuffer(ApiMessage,
+                                  (PVOID)&GetAllConsoleAliasesLength->ExeName,
+                                  GetAllConsoleAliasesLength->ExeLength,
+                                  sizeof(BYTE)))
     {
         return STATUS_INVALID_PARAMETER;
     }
 
-    ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+    if (GetAllConsoleAliasesLength->ExeName == NULL)
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    ApiMessage->Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (!NT_SUCCESS(ApiMessage->Status))
     {
         return ApiMessage->Status;
     }
 
-    Header = IntFindAliasHeader(Console->Aliases, GetAllConsoleAliasesLength->lpExeName);
+    Header = IntFindAliasHeader(Console->Aliases, GetAllConsoleAliasesLength->ExeName);
     if (!Header)
     {
         ConioUnlockConsole(Console);
@@ -505,7 +564,15 @@ CSR_API(SrvGetConsoleAliasExes)
 
     DPRINT("SrvGetConsoleAliasExes entered\n");
 
-    ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+    if (!CsrValidateMessageBuffer(ApiMessage,
+                                  (PVOID)&GetConsoleAliasesExes->ExeNames,
+                                  GetConsoleAliasesExes->Length,
+                                  sizeof(BYTE)))
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    ApiMessage->Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (!NT_SUCCESS(ApiMessage->Status))
     {
         return ApiMessage->Status;
@@ -525,6 +592,7 @@ CSR_API(SrvGetConsoleAliasExes)
         return STATUS_INVALID_PARAMETER;
     }
 
+/*
     if (!Win32CsrValidateBuffer(CsrGetClientThread()->Process,
                                 GetConsoleAliasesExes->ExeNames,
                                 GetConsoleAliasesExes->Length,
@@ -533,12 +601,13 @@ CSR_API(SrvGetConsoleAliasExes)
         ConioUnlockConsole(Console);
         return STATUS_ACCESS_VIOLATION;
     }
+*/
 
     BytesWritten = IntGetConsoleAliasesExes(Console->Aliases,
                                             GetConsoleAliasesExes->ExeNames,
                                             GetConsoleAliasesExes->Length);
 
-    GetConsoleAliasesExes->BytesWritten = BytesWritten;
+    GetConsoleAliasesExes->Length = BytesWritten;
     ConioUnlockConsole(Console);
     return STATUS_SUCCESS;
 }
@@ -549,7 +618,7 @@ CSR_API(SrvGetConsoleAliasExesLength)
     PCSRSS_CONSOLE Console;
     DPRINT("SrvGetConsoleAliasExesLength entered\n");
 
-    ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+    ApiMessage->Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
     if (NT_SUCCESS(ApiMessage->Status))
     {
         GetConsoleAliasesExesLength->Length = IntGetConsoleAliasesExesLength(Console->Aliases);
@@ -557,3 +626,5 @@ CSR_API(SrvGetConsoleAliasExesLength)
     }
     return ApiMessage->Status;
 }
+
+/* EOF */