2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/alias.c
5 * PURPOSE: Win32 Console Client Alias support functions
6 * PROGRAMMERS: David Welch (welch@cwcom.net) (welch@mcmail.com)
7 * Christoph von Wittich (christoph_vw@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
11 /* INCLUDES *******************************************************************/
19 /* FUNCTIONS ******************************************************************/
22 IntAddConsoleAlias(LPCVOID Source
,
23 USHORT SourceBufferLength
,
25 USHORT TargetBufferLength
,
29 CONSOLE_API_MESSAGE ApiMessage
;
30 PCONSOLE_ADDGETALIAS ConsoleAliasRequest
= &ApiMessage
.Data
.ConsoleAliasRequest
;
31 PCSR_CAPTURE_BUFFER CaptureBuffer
;
32 ULONG CapturedStrings
;
34 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
36 if (lpExeName
== NULL
|| NumChars
== 0)
38 SetLastError(ERROR_INVALID_PARAMETER
);
42 ConsoleAliasRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
44 /* Determine the needed sizes */
45 ConsoleAliasRequest
->SourceLength
= SourceBufferLength
;
46 ConsoleAliasRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
47 ConsoleAliasRequest
->Unicode
=
48 ConsoleAliasRequest
->Unicode2
= bUnicode
;
52 if (Target
) /* The target can be optional */
54 ConsoleAliasRequest
->TargetLength
= TargetBufferLength
;
59 ConsoleAliasRequest
->TargetLength
= 0;
62 /* Allocate a Capture Buffer */
63 CaptureBuffer
= CsrAllocateCaptureBuffer(CapturedStrings
,
64 ConsoleAliasRequest
->SourceLength
+
65 ConsoleAliasRequest
->ExeLength
+
66 ConsoleAliasRequest
->TargetLength
);
67 if (CaptureBuffer
== NULL
)
69 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
70 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
74 /* Capture the strings */
75 CsrCaptureMessageBuffer(CaptureBuffer
,
77 ConsoleAliasRequest
->SourceLength
,
78 (PVOID
*)&ConsoleAliasRequest
->Source
);
80 CsrCaptureMessageBuffer(CaptureBuffer
,
82 ConsoleAliasRequest
->ExeLength
,
83 (PVOID
*)&ConsoleAliasRequest
->ExeName
);
85 if (Target
) /* The target can be optional */
87 CsrCaptureMessageBuffer(CaptureBuffer
,
89 ConsoleAliasRequest
->TargetLength
,
90 (PVOID
*)&ConsoleAliasRequest
->Target
);
94 ConsoleAliasRequest
->Target
= NULL
;
97 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
99 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepAddAlias
),
100 sizeof(*ConsoleAliasRequest
));
102 CsrFreeCaptureBuffer(CaptureBuffer
);
104 if (!NT_SUCCESS(ApiMessage
.Status
))
106 BaseSetLastNTError(ApiMessage
.Status
);
120 AddConsoleAliasW(LPCWSTR lpSource
,
124 USHORT SourceBufferLength
= (USHORT
)wcslen(lpSource
) * sizeof(WCHAR
);
125 USHORT TargetBufferLength
= (USHORT
)(lpTarget
? wcslen(lpTarget
) * sizeof(WCHAR
) : 0);
127 DPRINT1("AddConsoleAliasW entered with lpSource '%S' lpTarget '%S' lpExeName '%S'\n",
128 lpSource
, lpTarget
, lpExeName
);
130 return IntAddConsoleAlias(lpSource
,
145 AddConsoleAliasA(LPCSTR lpSource
,
149 USHORT SourceBufferLength
= (USHORT
)strlen(lpSource
) * sizeof(CHAR
);
150 USHORT TargetBufferLength
= (USHORT
)(lpTarget
? strlen(lpTarget
) * sizeof(CHAR
) : 0);
152 DPRINT1("AddConsoleAliasA entered with lpSource '%s' lpTarget '%s' lpExeName '%s'\n",
153 lpSource
, lpTarget
, lpExeName
);
155 return IntAddConsoleAlias(lpSource
,
165 IntGetConsoleAlias(LPVOID Source
,
166 USHORT SourceBufferLength
,
168 USHORT TargetBufferLength
,
172 CONSOLE_API_MESSAGE ApiMessage
;
173 PCONSOLE_ADDGETALIAS ConsoleAliasRequest
= &ApiMessage
.Data
.ConsoleAliasRequest
;
174 PCSR_CAPTURE_BUFFER CaptureBuffer
;
176 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
178 if (Source
== NULL
|| Target
== NULL
)
180 SetLastError(ERROR_INVALID_PARAMETER
);
184 if (lpExeName
== NULL
|| NumChars
== 0)
186 SetLastError(ERROR_INVALID_PARAMETER
);
190 ConsoleAliasRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
192 /* Determine the needed sizes */
193 ConsoleAliasRequest
->SourceLength
= SourceBufferLength
;
194 ConsoleAliasRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
195 ConsoleAliasRequest
->Unicode
=
196 ConsoleAliasRequest
->Unicode2
= bUnicode
;
198 ConsoleAliasRequest
->TargetLength
= TargetBufferLength
;
200 /* Allocate a Capture Buffer */
201 CaptureBuffer
= CsrAllocateCaptureBuffer(3, ConsoleAliasRequest
->SourceLength
+
202 ConsoleAliasRequest
->ExeLength
+
203 ConsoleAliasRequest
->TargetLength
);
206 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
207 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
211 /* Capture the strings */
212 CsrCaptureMessageBuffer(CaptureBuffer
,
214 ConsoleAliasRequest
->SourceLength
,
215 (PVOID
*)&ConsoleAliasRequest
->Source
);
217 CsrCaptureMessageBuffer(CaptureBuffer
,
219 ConsoleAliasRequest
->ExeLength
,
220 (PVOID
*)&ConsoleAliasRequest
->ExeName
);
222 /* Allocate space for the target buffer */
223 CsrAllocateMessagePointer(CaptureBuffer
,
224 ConsoleAliasRequest
->TargetLength
,
225 (PVOID
*)&ConsoleAliasRequest
->Target
);
227 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
229 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAlias
),
230 sizeof(*ConsoleAliasRequest
));
231 if (!NT_SUCCESS(ApiMessage
.Status
))
233 CsrFreeCaptureBuffer(CaptureBuffer
);
234 BaseSetLastNTError(ApiMessage
.Status
);
236 if (ApiMessage
.Status
== STATUS_BUFFER_TOO_SMALL
)
237 return ConsoleAliasRequest
->TargetLength
;
242 /* Copy the returned target string into the user buffer */
243 RtlCopyMemory(Target
,
244 ConsoleAliasRequest
->Target
,
245 ConsoleAliasRequest
->TargetLength
);
247 /* Release the capture buffer and exit */
248 CsrFreeCaptureBuffer(CaptureBuffer
);
250 return ConsoleAliasRequest
->TargetLength
;
260 GetConsoleAliasW(LPWSTR lpSource
,
261 LPWSTR lpTargetBuffer
,
262 DWORD TargetBufferLength
,
265 DPRINT1("GetConsoleAliasW entered with lpSource '%S' lpExeName '%S'\n",
266 lpSource
, lpExeName
);
268 return IntGetConsoleAlias(lpSource
,
269 (USHORT
)wcslen(lpSource
) * sizeof(WCHAR
),
283 GetConsoleAliasA(LPSTR lpSource
,
284 LPSTR lpTargetBuffer
,
285 DWORD TargetBufferLength
,
288 DPRINT1("GetConsoleAliasA entered with lpSource '%s' lpExeName '%s'\n",
289 lpSource
, lpExeName
);
291 return IntGetConsoleAlias(lpSource
,
292 (USHORT
)strlen(lpSource
) * sizeof(CHAR
),
301 IntGetConsoleAliases(LPVOID AliasBuffer
,
302 DWORD AliasBufferLength
,
306 CONSOLE_API_MESSAGE ApiMessage
;
307 PCONSOLE_GETALLALIASES GetAllAliasesRequest
= &ApiMessage
.Data
.GetAllAliasesRequest
;
308 PCSR_CAPTURE_BUFFER CaptureBuffer
;
310 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
312 if (lpExeName
== NULL
|| NumChars
== 0)
314 SetLastError(ERROR_INVALID_PARAMETER
);
318 GetAllAliasesRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
320 /* Determine the needed sizes */
321 GetAllAliasesRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
322 GetAllAliasesRequest
->Unicode
=
323 GetAllAliasesRequest
->Unicode2
= bUnicode
;
325 GetAllAliasesRequest
->AliasesBufferLength
= AliasBufferLength
;
327 /* Allocate a Capture Buffer */
328 CaptureBuffer
= CsrAllocateCaptureBuffer(2, GetAllAliasesRequest
->ExeLength
+
329 GetAllAliasesRequest
->AliasesBufferLength
);
332 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
333 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
337 /* Capture the exe name and allocate space for the aliases buffer */
338 CsrCaptureMessageBuffer(CaptureBuffer
,
340 GetAllAliasesRequest
->ExeLength
,
341 (PVOID
*)&GetAllAliasesRequest
->ExeName
);
343 CsrAllocateMessagePointer(CaptureBuffer
,
344 GetAllAliasesRequest
->AliasesBufferLength
,
345 (PVOID
*)&GetAllAliasesRequest
->AliasesBuffer
);
347 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
349 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliases
),
350 sizeof(*GetAllAliasesRequest
));
351 if (!NT_SUCCESS(ApiMessage
.Status
))
353 CsrFreeCaptureBuffer(CaptureBuffer
);
354 BaseSetLastNTError(ApiMessage
.Status
);
358 /* Copy the returned aliases string into the user buffer */
359 RtlCopyMemory(AliasBuffer
,
360 GetAllAliasesRequest
->AliasesBuffer
,
361 GetAllAliasesRequest
->AliasesBufferLength
);
363 /* Release the capture buffer and exit */
364 CsrFreeCaptureBuffer(CaptureBuffer
);
366 return GetAllAliasesRequest
->AliasesBufferLength
;
376 GetConsoleAliasesW(LPWSTR AliasBuffer
,
377 DWORD AliasBufferLength
,
380 DPRINT1("GetConsoleAliasesW entered with lpExeName '%S'\n",
383 return IntGetConsoleAliases(AliasBuffer
,
396 GetConsoleAliasesA(LPSTR AliasBuffer
,
397 DWORD AliasBufferLength
,
400 DPRINT1("GetConsoleAliasesA entered with lpExeName '%s'\n",
403 return IntGetConsoleAliases(AliasBuffer
,
411 IntGetConsoleAliasesLength(LPVOID lpExeName
, BOOLEAN bUnicode
)
413 CONSOLE_API_MESSAGE ApiMessage
;
414 PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest
= &ApiMessage
.Data
.GetAllAliasesLengthRequest
;
415 PCSR_CAPTURE_BUFFER CaptureBuffer
;
417 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
419 if (lpExeName
== NULL
|| NumChars
== 0)
421 SetLastError(ERROR_INVALID_PARAMETER
);
425 GetAllAliasesLengthRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
426 GetAllAliasesLengthRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
427 GetAllAliasesLengthRequest
->Unicode
=
428 GetAllAliasesLengthRequest
->Unicode2
= bUnicode
;
430 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GetAllAliasesLengthRequest
->ExeLength
);
433 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
434 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
438 CsrCaptureMessageBuffer(CaptureBuffer
,
440 GetAllAliasesLengthRequest
->ExeLength
,
441 (PVOID
)&GetAllAliasesLengthRequest
->ExeName
);
443 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
445 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliasesLength
),
446 sizeof(*GetAllAliasesLengthRequest
));
448 CsrFreeCaptureBuffer(CaptureBuffer
);
450 if (!NT_SUCCESS(ApiMessage
.Status
))
452 BaseSetLastNTError(ApiMessage
.Status
);
456 return GetAllAliasesLengthRequest
->Length
;
466 GetConsoleAliasesLengthW(LPWSTR lpExeName
)
468 return IntGetConsoleAliasesLength(lpExeName
, TRUE
);
478 GetConsoleAliasesLengthA(LPSTR lpExeName
)
480 return IntGetConsoleAliasesLength(lpExeName
, FALSE
);
485 IntGetConsoleAliasExes(PVOID lpExeNameBuffer
,
486 DWORD ExeNameBufferLength
,
489 CONSOLE_API_MESSAGE ApiMessage
;
490 PCONSOLE_GETALIASESEXES GetAliasesExesRequest
= &ApiMessage
.Data
.GetAliasesExesRequest
;
491 PCSR_CAPTURE_BUFFER CaptureBuffer
;
493 GetAliasesExesRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
494 GetAliasesExesRequest
->Length
= ExeNameBufferLength
;
495 GetAliasesExesRequest
->Unicode
= bUnicode
;
497 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ExeNameBufferLength
);
500 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
501 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
505 CsrAllocateMessagePointer(CaptureBuffer
,
507 (PVOID
*)&GetAliasesExesRequest
->ExeNames
);
509 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
511 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliasExes
),
512 sizeof(*GetAliasesExesRequest
));
513 if (!NT_SUCCESS(ApiMessage
.Status
))
515 CsrFreeCaptureBuffer(CaptureBuffer
);
516 BaseSetLastNTError(ApiMessage
.Status
);
520 RtlCopyMemory(lpExeNameBuffer
,
521 GetAliasesExesRequest
->ExeNames
,
522 GetAliasesExesRequest
->Length
);
524 CsrFreeCaptureBuffer(CaptureBuffer
);
526 return GetAliasesExesRequest
->Length
;
535 GetConsoleAliasExesW(LPWSTR lpExeNameBuffer
,
536 DWORD ExeNameBufferLength
)
538 DPRINT1("GetConsoleAliasExesW called\n");
539 return IntGetConsoleAliasExes(lpExeNameBuffer
, ExeNameBufferLength
, TRUE
);
549 GetConsoleAliasExesA(LPSTR lpExeNameBuffer
,
550 DWORD ExeNameBufferLength
)
552 DPRINT1("GetConsoleAliasExesA called\n");
553 return IntGetConsoleAliasExes(lpExeNameBuffer
, ExeNameBufferLength
, FALSE
);
558 IntGetConsoleAliasExesLength(BOOLEAN bUnicode
)
560 CONSOLE_API_MESSAGE ApiMessage
;
561 PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest
= &ApiMessage
.Data
.GetAliasesExesLengthRequest
;
563 GetAliasesExesLengthRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
564 GetAliasesExesLengthRequest
->Unicode
= bUnicode
;
566 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
568 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliasExesLength
),
569 sizeof(*GetAliasesExesLengthRequest
));
570 if (!NT_SUCCESS(ApiMessage
.Status
))
572 BaseSetLastNTError(ApiMessage
.Status
);
576 return GetAliasesExesLengthRequest
->Length
;
586 GetConsoleAliasExesLengthW(VOID
)
588 DPRINT1("GetConsoleAliasExesLengthW called\n");
589 return IntGetConsoleAliasExesLength(TRUE
);
599 GetConsoleAliasExesLengthA(VOID
)
601 DPRINT1("GetConsoleAliasExesLengthA called\n");
602 return IntGetConsoleAliasExesLength(FALSE
);