Author: hbelusca
Date: Thu Nov 15 21:02:01 2012
New Revision: 57712
URL:
http://svn.reactos.org/svn/reactos?rev=57712&view=rev
Log:
[KERNEL32/CONSRV]
- 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.
Modified:
branches/ros-csrss/dll/win32/kernel32/client/console/alias.c
branches/ros-csrss/include/reactos/subsys/win/conmsg.h
branches/ros-csrss/win32ss/user/consrv/alias.c
Modified: branches/ros-csrss/dll/win32/kernel32/client/console/alias.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/cl…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/client/console/alias.c [iso-8859-1] (original)
+++ branches/ros-csrss/dll/win32/kernel32/client/console/alias.c [iso-8859-1] Thu Nov 15
21:02:01 2012
@@ -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(a)cwcom.net) (welch(a)mcmail.com)
* Christoph von Wittich (christoph_vw(a)reactos.org)
* Johannes Anderwald (janderwald(a)reactos.org)
@@ -15,10 +15,11 @@
#define NDEBUG
#include <debug.h>
+
/* FUNCTIONS ******************************************************************/
/*
- * @unimplemented
+ * @implemented
*/
BOOL
WINAPI
@@ -26,54 +27,77 @@
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;
-
- Size = (ExeLength + SourceLength + TargetLength) * sizeof(WCHAR);
- RequestLength = sizeof(CSR_API_MESSAGE) + Size;
-
- Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, RequestLength);
- Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE));
-
- wcscpy(Ptr, lpSource);
- Request->Data.AddConsoleAlias.SourceLength = SourceLength;
- Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE) + SourceLength *
sizeof(WCHAR));
-
- wcscpy(Ptr, lpExeName);
- Request->Data.AddConsoleAlias.ExeLength = ExeLength;
- Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE) + (ExeLength +
SourceLength)* sizeof(WCHAR));
-
- if (lpTarget) /* target can be optional */
- wcscpy(Ptr, lpTarget);
-
- Request->Data.AddConsoleAlias.TargetLength = TargetLength;
-
- Status = CsrClientCallServer(Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE, ADD_CONSOLE_ALIAS),
- RequestLength);
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
+ /* Determine the needed sizes */
+ ConsoleAlias->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
+ ConsoleAlias->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+ CapturedStrings = 2;
+
+ if (lpTarget) /* The target can be optional */
+ {
+ ConsoleAlias->TargetLength = (wcslen(lpTarget) + 1) * sizeof(WCHAR);
+ CapturedStrings++;
+ }
+ else
+ {
+ ConsoleAlias->TargetLength = 0;
+ }
+
+ /* 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;
+ }
+
+ /* Capture the strings */
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpSource,
+ ConsoleAlias->SourceLength,
+ &ConsoleAlias->Source);
+
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ ConsoleAlias->ExeLength,
+ &ConsoleAlias->Exe);
+
+ if (lpTarget) /* The target can be optional */
+ {
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpTarget,
+ ConsoleAlias->TargetLength,
+ &ConsoleAlias->Target);
+ }
+ else
+ {
+ ConsoleAlias->Target = NULL;
+ }
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepAddAlias),
+ sizeof(CSRSS_CONSOLE_ALIAS));
+
+ CsrFreeCaptureBuffer(CaptureBuffer);
+
+ 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 @@
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 @@
DWORD TargetBufferLength,
LPWSTR lpExeName)
{
- PCSR_API_MESSAGE Request;
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_CONSOLE_ALIAS ConsoleAlias = &ApiMessage.Data.ConsoleAlias;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- NTSTATUS Status;
- ULONG Size;
- ULONG ExeLength;
- ULONG SourceLength;
- ULONG RequestLength;
- WCHAR * Ptr;
-
- 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 @@
return 0;
}
- ExeLength = wcslen(lpExeName) + 1;
- SourceLength = wcslen(lpSource) + 1;
-
- Size = (ExeLength + SourceLength) * sizeof(WCHAR);
-
- 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);
+ /* Determine the needed sizes */
+ ConsoleAlias->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
+ ConsoleAlias->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+
+ ConsoleAlias->Target = NULL;
+ ConsoleAlias->TargetLength = 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;
-
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return 0;
+ }
+
+ /* Capture the strings */
CsrCaptureMessageBuffer(CaptureBuffer,
- NULL,
- TargetBufferLength,
- (PVOID*)&Request->Data.GetConsoleAlias.TargetBuffer);
-
- Request->Data.GetConsoleAlias.TargetBufferLength = TargetBufferLength;
-
- Ptr = (LPWSTR)((ULONG_PTR)Request + sizeof(CSR_API_MESSAGE));
- wcscpy(Ptr, lpSource);
- Ptr += SourceLength;
- wcscpy(Ptr, lpExeName);
-
- Request->Data.GetConsoleAlias.ExeLength = ExeLength;
- Request->Data.GetConsoleAlias.SourceLength = SourceLength;
-
- Status = CsrClientCallServer(Request,
+ (PVOID)lpSource,
+ ConsoleAlias->SourceLength,
+ &ConsoleAlias->Source);
+
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ ConsoleAlias->ExeLength,
+ &ConsoleAlias->Exe);
+
+ /* Allocate space for the target buffer */
+ CsrAllocateMessagePointer(CaptureBuffer,
+ ConsoleAlias->TargetLength,
+ (PVOID*)&ConsoleAlias->Target);
+
+ 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))
- {
- RtlFreeHeap(GetProcessHeap(), 0, Request);
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGetAlias),
+ sizeof(CSRSS_CONSOLE_ALIAS));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ {
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,158 +290,67 @@
*/
DWORD
WINAPI
-GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
- DWORD ExeNameBufferLength)
-{
- CSR_API_MESSAGE Request;
- PCSR_CAPTURE_BUFFER CaptureBuffer;
- NTSTATUS Status;
-
- DPRINT("GetConsoleAliasExesW entered\n");
-
- CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength);
- if (!CaptureBuffer)
- {
- DPRINT1("CsrAllocateCaptureBuffer failed!\n");
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
-
- CsrAllocateMessagePointer(CaptureBuffer,
- ExeNameBufferLength,
- (PVOID*)&Request.Data.GetConsoleAliasesExes.ExeNames);
- Request.Data.GetConsoleAliasesExes.Length = ExeNameBufferLength;
-
- Status = CsrClientCallServer(&Request,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
GET_CONSOLE_ALIASES_EXES),
- sizeof(CSR_API_MESSAGE));
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
- {
- BaseSetLastNTError(Status);
- CsrFreeCaptureBuffer(CaptureBuffer);
- return 0;
- }
-
- memcpy(lpExeNameBuffer,
- Request.Data.GetConsoleAliasesExes.ExeNames,
- Request.Data.GetConsoleAliasesExes.BytesWritten);
-
- CsrFreeCaptureBuffer(CaptureBuffer);
- return Request.Data.GetConsoleAliasesExes.BytesWritten;
-}
-
-
-/*
- * @implemented
- */
-DWORD
-WINAPI
-GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
- DWORD ExeNameBufferLength)
-{
- LPWSTR lpwExeNameBuffer;
- DWORD dwResult;
-
- DPRINT("GetConsoleAliasExesA entered\n");
-
- lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength *
sizeof(WCHAR));
-
- dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength *
sizeof(WCHAR));
-
- if (dwResult)
- dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult /
sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL);
-
- HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer);
- return dwResult;
-}
-
-
-/*
- * @implemented
- */
-DWORD
-WINAPI
-GetConsoleAliasExesLengthW(VOID)
-{
- CSR_API_MESSAGE Request;
- NTSTATUS Status;
-
- DPRINT("GetConsoleAliasExesLengthW entered\n");
-
- Request.Data.GetConsoleAliasesExesLength.Length = 0;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
GET_CONSOLE_ALIASES_EXES_LENGTH),
- sizeof(CSR_API_MESSAGE));
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
- {
- BaseSetLastNTError(Status);
- return 0;
- }
-
- return Request.Data.GetConsoleAliasesExesLength.Length;
-}
-
-
-/*
- * @implemented
- */
-DWORD
-WINAPI
-GetConsoleAliasExesLengthA(VOID)
-{
- DWORD dwLength;
-
- DPRINT("GetConsoleAliasExesLengthA entered\n");
-
- dwLength = GetConsoleAliasExesLengthW();
-
- if (dwLength)
- dwLength /= sizeof(WCHAR);
-
- return dwLength;
-}
-
-
-/*
- * @implemented
- */
-DWORD
-WINAPI
GetConsoleAliasesW(LPWSTR AliasBuffer,
DWORD AliasBufferLength,
LPWSTR ExeName)
{
- CSR_API_MESSAGE Request;
NTSTATUS Status;
- DWORD dwLength;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAliases =
&ApiMessage.Data.GetAllConsoleAliases;
+ PCSR_CAPTURE_BUFFER CaptureBuffer;
DPRINT("GetConsoleAliasesW entered\n");
- dwLength = GetConsoleAliasesLengthW(ExeName);
- if (!dwLength || dwLength > AliasBufferLength)
- return 0;
-
- Request.Data.GetAllConsoleAlias.AliasBuffer = AliasBuffer;
- Request.Data.GetAllConsoleAlias.AliasBufferLength = AliasBufferLength;
- Request.Data.GetAllConsoleAlias.lpExeName = ExeName;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
GET_ALL_CONSOLE_ALIASES),
- sizeof(CSR_API_MESSAGE));
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+ /* 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");
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return 0;
+ }
+
+ /* Capture the exe name and allocate space for the aliases buffer */
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)ExeName,
+ GetAllConsoleAliases->ExeLength,
+ (PVOID*)&GetAllConsoleAliases->ExeName);
+
+ CsrAllocateMessagePointer(CaptureBuffer,
+ GetAllConsoleAliases->AliasesBufferLength,
+ (PVOID*)&GetAllConsoleAliases->AliasesBuffer);
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ 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);
return 0;
}
- return Request.Data.GetAllConsoleAlias.BytesWritten / sizeof(WCHAR);
+ /* 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 GetAllConsoleAliases->AliasesBufferLength; // / sizeof(WCHAR); (original
code)
}
@@ -443,17 +370,17 @@
DPRINT("GetConsoleAliasesA entered\n");
if (ExeName)
- BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*) &lpwExeName);
+ BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*)&lpwExeName);
lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR));
- dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength, lpwExeName);
+ dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength * sizeof(WCHAR),
lpwExeName);
if (lpwExeName)
- RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpwExeName);
+ RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpwExeName);
if (dwRetVal)
- dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal, AliasBuffer,
AliasBufferLength, NULL, NULL);
+ dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal /**/ /
sizeof(WCHAR) /**/, AliasBuffer, AliasBufferLength, NULL, NULL);
HeapFree(GetProcessHeap(), 0, lpwAliasBuffer);
return dwRetVal;
@@ -467,26 +394,51 @@
WINAPI
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("GetConsoleAliasesLengthW entered\n");
- Request.Data.GetAllConsoleAliasesLength.lpExeName = lpExeName;
- Request.Data.GetAllConsoleAliasesLength.Length = 0;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
GET_ALL_CONSOLE_ALIASES_LENGTH),
- sizeof(CSR_API_MESSAGE));
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+ if (lpExeName == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+
+ GetAllConsoleAliasesLength->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+ GetAllConsoleAliasesLength->Length = 0;
+
+ /* 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));
+
+ CsrFreeCaptureBuffer(CaptureBuffer);
+
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
{
BaseSetLastNTError(Status);
return 0;
}
- return Request.Data.GetAllConsoleAliasesLength.Length;
+ return GetAllConsoleAliasesLength->Length;
}
@@ -501,7 +453,7 @@
LPWSTR lpExeNameW = NULL;
if (lpExeName)
- BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
+ BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW);
dwRetVal = GetConsoleAliasesLengthW(lpExeNameW);
if (dwRetVal)
@@ -509,9 +461,138 @@
/* Clean up */
if (lpExeNameW)
- RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
+ RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW);
return dwRetVal;
}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
+ DWORD ExeNameBufferLength)
+{
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes =
&ApiMessage.Data.GetConsoleAliasesExes;
+ PCSR_CAPTURE_BUFFER CaptureBuffer;
+
+ DPRINT("GetConsoleAliasExesW entered\n");
+
+ /* Allocate a Capture Buffer */
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength);
+ if (!CaptureBuffer)
+ {
+ DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return 0;
+ }
+
+ GetConsoleAliasesExes->Length = ExeNameBufferLength;
+
+ /* Allocate space for the exe name buffer */
+ CsrAllocateMessagePointer(CaptureBuffer,
+ ExeNameBufferLength,
+ (PVOID*)&GetConsoleAliasesExes->ExeNames);
+
+ 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;
+ }
+
+ /* 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;
+}
+
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
+ DWORD ExeNameBufferLength)
+{
+ LPWSTR lpwExeNameBuffer;
+ DWORD dwResult;
+
+ DPRINT("GetConsoleAliasExesA entered\n");
+
+ lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength *
sizeof(WCHAR));
+
+ dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength *
sizeof(WCHAR));
+
+ if (dwResult)
+ dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult /
sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL);
+
+ HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer);
+ return dwResult;
+}
+
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetConsoleAliasExesLengthW(VOID)
+{
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength =
&ApiMessage.Data.GetConsoleAliasesExesLength;
+
+ DPRINT("GetConsoleAliasExesLengthW entered\n");
+
+ GetConsoleAliasesExesLength->Length = 0;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGetAliasExesLength),
+ sizeof(CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH));
+
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ {
+ BaseSetLastNTError(Status);
+ return 0;
+ }
+
+ return GetConsoleAliasesExesLength->Length;
+}
+
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetConsoleAliasExesLengthA(VOID)
+{
+ DWORD dwLength;
+
+ DPRINT("GetConsoleAliasExesLengthA entered\n");
+
+ dwLength = GetConsoleAliasExesLengthW();
+
+ if (dwLength)
+ dwLength /= sizeof(WCHAR);
+
+ return dwLength;
+}
+
/* EOF */
Modified: branches/ros-csrss/include/reactos/subsys/win/conmsg.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsy…
==============================================================================
--- branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] (original)
+++ branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] Thu Nov 15
21:02:01 2012
@@ -416,39 +416,41 @@
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;
-
-typedef struct
-{
- LPWSTR lpExeName;
- DWORD BytesWritten;
- DWORD AliasBufferLength;
- LPWSTR AliasBuffer;
+
+
+
+
+
+
+
+
+typedef struct
+{
+ 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
+{
+ 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 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 @@
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
{
@@ -512,6 +496,38 @@
DWORD dwFlags;
} 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
{
@@ -580,22 +596,24 @@
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_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_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;
Modified: branches/ros-csrss/win32ss/user/consrv/alias.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/a…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/alias.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/alias.c [iso-8859-1] Thu Nov 15 21:02:01 2012
@@ -7,7 +7,7 @@
* Johannes Anderwald
*/
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
#include "consrv.h"
#include "conio.h"
@@ -16,21 +16,24 @@
#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
@@ -99,7 +102,7 @@
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;
@@ -111,7 +114,6 @@
}
return NULL;
}
-
VOID
IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
@@ -218,6 +220,7 @@
}
return 0;
}
+
UINT
IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT
TargetBufferLength)
{
@@ -244,6 +247,7 @@
TargetBuffer[Offset] = L'\0';
return Offset * sizeof(WCHAR);
}
+
VOID
IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry)
{
@@ -261,11 +265,13 @@
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 @@
}
}
+
+/* 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));
-
- 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);
-
- DPRINT("SrvAddConsoleAlias entered ApiMessage %p lpSource %p lpExeName %p
lpTarget %p\n", ApiMessage, lpSource, lpExeName, lpTarget);
+ 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 = ConsoleAlias->Source;
+ lpTarget = (ConsoleAlias->TargetLength != 0 ? ConsoleAlias->Target : NULL);
+ lpExeName = ConsoleAlias->Exe;
+
+ 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 @@
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(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;
-
-
- DPRINT("SrvGetConsoleAlias entered lpExeName %p lpSource %p TargetBuffer %p
TargetBufferLength %u\n",
- lpExeName, lpSource, lpTarget, GetConsoleAlias->TargetBufferLength);
-
- if (GetConsoleAlias->ExeLength == 0 || lpTarget == NULL ||
- GetConsoleAlias->TargetBufferLength == 0 ||
GetConsoleAlias->SourceLength == 0)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
+ 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 lpExeName %p lpSource %p TargetBuffer %p TargetLength
%u\n",
+ lpExeName, lpSource, lpTarget, ConsoleAlias->TargetLength);
+
+ if (ConsoleAlias->ExeLength == 0 || lpTarget == NULL ||
+ ConsoleAlias->TargetLength == 0 || ConsoleAlias->SourceLength == 0)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ ApiMessage->Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
if (!NT_SUCCESS(ApiMessage->Status))
{
return ApiMessage->Status;
@@ -396,71 +431,87 @@
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)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
+ if ( !CsrValidateMessageBuffer(ApiMessage,
+ (PVOID)&GetAllConsoleAliases->ExeName,
+ GetAllConsoleAliases->ExeLength,
+ sizeof(BYTE)) ||
+ !CsrValidateMessageBuffer(ApiMessage,
+ (PVOID)&GetAllConsoleAliases->AliasesBuffer,
+ GetAllConsoleAliases->AliasesBufferLength,
+ sizeof(BYTE)) )
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ 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);
-
- GetAllConsoleAlias->BytesWritten = BytesWritten;
+ GetAllConsoleAliases->AliasesBuffer,
+
GetAllConsoleAliases->AliasesBufferLength);
+
+ GetAllConsoleAliases->AliasesBufferLength = BytesWritten;
ConioUnlockConsole(Console);
return STATUS_SUCCESS;
}
@@ -472,18 +523,26 @@
PALIAS_HEADER Header;
UINT Length;
- if (GetAllConsoleAliasesLength->lpExeName == NULL)
- {
- return STATUS_INVALID_PARAMETER;
- }
-
- ApiMessage->Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID)&GetAllConsoleAliasesLength->ExeName,
+ GetAllConsoleAliasesLength->ExeLength,
+ sizeof(BYTE)))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ 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 @@
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 @@
return STATUS_INVALID_PARAMETER;
}
+/*
if (!Win32CsrValidateBuffer(CsrGetClientThread()->Process,
GetConsoleAliasesExes->ExeNames,
GetConsoleAliasesExes->Length,
@@ -533,12 +601,13 @@
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 @@
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 @@
}
return ApiMessage->Status;
}
+
+/* EOF */