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
);
119 AddConsoleAliasW(LPCWSTR lpSource
,
123 USHORT SourceBufferLength
= (USHORT
)wcslen(lpSource
) * sizeof(WCHAR
);
124 USHORT TargetBufferLength
= (USHORT
)(lpTarget
? wcslen(lpTarget
) * sizeof(WCHAR
) : 0);
126 DPRINT1("AddConsoleAliasW entered with lpSource '%S' lpTarget '%S' lpExeName '%S'\n",
127 lpSource
, lpTarget
, lpExeName
);
129 return IntAddConsoleAlias(lpSource
,
143 AddConsoleAliasA(LPCSTR lpSource
,
147 USHORT SourceBufferLength
= (USHORT
)strlen(lpSource
) * sizeof(CHAR
);
148 USHORT TargetBufferLength
= (USHORT
)(lpTarget
? strlen(lpTarget
) * sizeof(CHAR
) : 0);
150 DPRINT1("AddConsoleAliasA entered with lpSource '%s' lpTarget '%s' lpExeName '%s'\n",
151 lpSource
, lpTarget
, lpExeName
);
153 return IntAddConsoleAlias(lpSource
,
163 IntGetConsoleAlias(LPVOID Source
,
164 USHORT SourceBufferLength
,
166 USHORT TargetBufferLength
,
170 CONSOLE_API_MESSAGE ApiMessage
;
171 PCONSOLE_ADDGETALIAS ConsoleAliasRequest
= &ApiMessage
.Data
.ConsoleAliasRequest
;
172 PCSR_CAPTURE_BUFFER CaptureBuffer
;
174 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
176 if (Source
== NULL
|| Target
== NULL
)
178 SetLastError(ERROR_INVALID_PARAMETER
);
182 if (lpExeName
== NULL
|| NumChars
== 0)
184 SetLastError(ERROR_INVALID_PARAMETER
);
188 ConsoleAliasRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
190 /* Determine the needed sizes */
191 ConsoleAliasRequest
->SourceLength
= SourceBufferLength
;
192 ConsoleAliasRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
193 ConsoleAliasRequest
->Unicode
=
194 ConsoleAliasRequest
->Unicode2
= bUnicode
;
196 ConsoleAliasRequest
->TargetLength
= TargetBufferLength
;
198 /* Allocate a Capture Buffer */
199 CaptureBuffer
= CsrAllocateCaptureBuffer(3, ConsoleAliasRequest
->SourceLength
+
200 ConsoleAliasRequest
->ExeLength
+
201 ConsoleAliasRequest
->TargetLength
);
204 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
205 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
209 /* Capture the strings */
210 CsrCaptureMessageBuffer(CaptureBuffer
,
212 ConsoleAliasRequest
->SourceLength
,
213 (PVOID
*)&ConsoleAliasRequest
->Source
);
215 CsrCaptureMessageBuffer(CaptureBuffer
,
217 ConsoleAliasRequest
->ExeLength
,
218 (PVOID
*)&ConsoleAliasRequest
->ExeName
);
220 /* Allocate space for the target buffer */
221 CsrAllocateMessagePointer(CaptureBuffer
,
222 ConsoleAliasRequest
->TargetLength
,
223 (PVOID
*)&ConsoleAliasRequest
->Target
);
225 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
227 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAlias
),
228 sizeof(*ConsoleAliasRequest
));
229 if (!NT_SUCCESS(ApiMessage
.Status
))
231 CsrFreeCaptureBuffer(CaptureBuffer
);
232 BaseSetLastNTError(ApiMessage
.Status
);
234 if (ApiMessage
.Status
== STATUS_BUFFER_TOO_SMALL
)
235 return ConsoleAliasRequest
->TargetLength
;
240 /* Copy the returned target string into the user buffer */
241 RtlCopyMemory(Target
,
242 ConsoleAliasRequest
->Target
,
243 ConsoleAliasRequest
->TargetLength
);
245 /* Release the capture buffer and exit */
246 CsrFreeCaptureBuffer(CaptureBuffer
);
248 return ConsoleAliasRequest
->TargetLength
;
257 GetConsoleAliasW(LPWSTR lpSource
,
258 LPWSTR lpTargetBuffer
,
259 DWORD TargetBufferLength
,
262 DPRINT1("GetConsoleAliasW entered with lpSource '%S' lpExeName '%S'\n",
263 lpSource
, lpExeName
);
265 return IntGetConsoleAlias(lpSource
,
266 (USHORT
)wcslen(lpSource
) * sizeof(WCHAR
),
279 GetConsoleAliasA(LPSTR lpSource
,
280 LPSTR lpTargetBuffer
,
281 DWORD TargetBufferLength
,
284 DPRINT1("GetConsoleAliasA entered with lpSource '%s' lpExeName '%s'\n",
285 lpSource
, lpExeName
);
287 return IntGetConsoleAlias(lpSource
,
288 (USHORT
)strlen(lpSource
) * sizeof(CHAR
),
297 IntGetConsoleAliases(LPVOID AliasBuffer
,
298 DWORD AliasBufferLength
,
302 CONSOLE_API_MESSAGE ApiMessage
;
303 PCONSOLE_GETALLALIASES GetAllAliasesRequest
= &ApiMessage
.Data
.GetAllAliasesRequest
;
304 PCSR_CAPTURE_BUFFER CaptureBuffer
;
306 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
308 if (lpExeName
== NULL
|| NumChars
== 0)
310 SetLastError(ERROR_INVALID_PARAMETER
);
314 GetAllAliasesRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
316 /* Determine the needed sizes */
317 GetAllAliasesRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
318 GetAllAliasesRequest
->Unicode
=
319 GetAllAliasesRequest
->Unicode2
= bUnicode
;
321 GetAllAliasesRequest
->AliasesBufferLength
= AliasBufferLength
;
323 /* Allocate a Capture Buffer */
324 CaptureBuffer
= CsrAllocateCaptureBuffer(2, GetAllAliasesRequest
->ExeLength
+
325 GetAllAliasesRequest
->AliasesBufferLength
);
328 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
329 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
333 /* Capture the exe name and allocate space for the aliases buffer */
334 CsrCaptureMessageBuffer(CaptureBuffer
,
336 GetAllAliasesRequest
->ExeLength
,
337 (PVOID
*)&GetAllAliasesRequest
->ExeName
);
339 CsrAllocateMessagePointer(CaptureBuffer
,
340 GetAllAliasesRequest
->AliasesBufferLength
,
341 (PVOID
*)&GetAllAliasesRequest
->AliasesBuffer
);
343 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
345 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliases
),
346 sizeof(*GetAllAliasesRequest
));
347 if (!NT_SUCCESS(ApiMessage
.Status
))
349 CsrFreeCaptureBuffer(CaptureBuffer
);
350 BaseSetLastNTError(ApiMessage
.Status
);
354 /* Copy the returned aliases string into the user buffer */
355 RtlCopyMemory(AliasBuffer
,
356 GetAllAliasesRequest
->AliasesBuffer
,
357 GetAllAliasesRequest
->AliasesBufferLength
);
359 /* Release the capture buffer and exit */
360 CsrFreeCaptureBuffer(CaptureBuffer
);
362 return GetAllAliasesRequest
->AliasesBufferLength
;
371 GetConsoleAliasesW(LPWSTR AliasBuffer
,
372 DWORD AliasBufferLength
,
375 DPRINT1("GetConsoleAliasesW entered with lpExeName '%S'\n",
378 return IntGetConsoleAliases(AliasBuffer
,
390 GetConsoleAliasesA(LPSTR AliasBuffer
,
391 DWORD AliasBufferLength
,
394 DPRINT1("GetConsoleAliasesA entered with lpExeName '%s'\n",
397 return IntGetConsoleAliases(AliasBuffer
,
405 IntGetConsoleAliasesLength(LPVOID lpExeName
, BOOLEAN bUnicode
)
407 CONSOLE_API_MESSAGE ApiMessage
;
408 PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest
= &ApiMessage
.Data
.GetAllAliasesLengthRequest
;
409 PCSR_CAPTURE_BUFFER CaptureBuffer
;
411 USHORT NumChars
= (USHORT
)(lpExeName
? (bUnicode
? wcslen(lpExeName
) : strlen(lpExeName
)) : 0);
413 if (lpExeName
== NULL
|| NumChars
== 0)
415 SetLastError(ERROR_INVALID_PARAMETER
);
419 GetAllAliasesLengthRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
420 GetAllAliasesLengthRequest
->ExeLength
= NumChars
* (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
421 GetAllAliasesLengthRequest
->Unicode
=
422 GetAllAliasesLengthRequest
->Unicode2
= bUnicode
;
424 CaptureBuffer
= CsrAllocateCaptureBuffer(1, GetAllAliasesLengthRequest
->ExeLength
);
427 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
428 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
432 CsrCaptureMessageBuffer(CaptureBuffer
,
434 GetAllAliasesLengthRequest
->ExeLength
,
435 (PVOID
)&GetAllAliasesLengthRequest
->ExeName
);
437 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
439 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliasesLength
),
440 sizeof(*GetAllAliasesLengthRequest
));
442 CsrFreeCaptureBuffer(CaptureBuffer
);
444 if (!NT_SUCCESS(ApiMessage
.Status
))
446 BaseSetLastNTError(ApiMessage
.Status
);
450 return GetAllAliasesLengthRequest
->Length
;
459 GetConsoleAliasesLengthW(LPWSTR lpExeName
)
461 return IntGetConsoleAliasesLength(lpExeName
, TRUE
);
470 GetConsoleAliasesLengthA(LPSTR lpExeName
)
472 return IntGetConsoleAliasesLength(lpExeName
, FALSE
);
477 IntGetConsoleAliasExes(PVOID lpExeNameBuffer
,
478 DWORD ExeNameBufferLength
,
481 CONSOLE_API_MESSAGE ApiMessage
;
482 PCONSOLE_GETALIASESEXES GetAliasesExesRequest
= &ApiMessage
.Data
.GetAliasesExesRequest
;
483 PCSR_CAPTURE_BUFFER CaptureBuffer
;
485 GetAliasesExesRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
486 GetAliasesExesRequest
->Length
= ExeNameBufferLength
;
487 GetAliasesExesRequest
->Unicode
= bUnicode
;
489 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ExeNameBufferLength
);
492 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
493 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
497 CsrAllocateMessagePointer(CaptureBuffer
,
499 (PVOID
*)&GetAliasesExesRequest
->ExeNames
);
501 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
503 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliasExes
),
504 sizeof(*GetAliasesExesRequest
));
505 if (!NT_SUCCESS(ApiMessage
.Status
))
507 CsrFreeCaptureBuffer(CaptureBuffer
);
508 BaseSetLastNTError(ApiMessage
.Status
);
512 RtlCopyMemory(lpExeNameBuffer
,
513 GetAliasesExesRequest
->ExeNames
,
514 GetAliasesExesRequest
->Length
);
516 CsrFreeCaptureBuffer(CaptureBuffer
);
518 return GetAliasesExesRequest
->Length
;
526 GetConsoleAliasExesW(LPWSTR lpExeNameBuffer
,
527 DWORD ExeNameBufferLength
)
529 DPRINT1("GetConsoleAliasExesW called\n");
530 return IntGetConsoleAliasExes(lpExeNameBuffer
, ExeNameBufferLength
, TRUE
);
539 GetConsoleAliasExesA(LPSTR lpExeNameBuffer
,
540 DWORD ExeNameBufferLength
)
542 DPRINT1("GetConsoleAliasExesA called\n");
543 return IntGetConsoleAliasExes(lpExeNameBuffer
, ExeNameBufferLength
, FALSE
);
548 IntGetConsoleAliasExesLength(BOOLEAN bUnicode
)
550 CONSOLE_API_MESSAGE ApiMessage
;
551 PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest
= &ApiMessage
.Data
.GetAliasesExesLengthRequest
;
553 GetAliasesExesLengthRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
554 GetAliasesExesLengthRequest
->Unicode
= bUnicode
;
556 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
558 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetAliasExesLength
),
559 sizeof(*GetAliasesExesLengthRequest
));
560 if (!NT_SUCCESS(ApiMessage
.Status
))
562 BaseSetLastNTError(ApiMessage
.Status
);
566 return GetAliasesExesLengthRequest
->Length
;
575 GetConsoleAliasExesLengthW(VOID
)
577 DPRINT1("GetConsoleAliasExesLengthW called\n");
578 return IntGetConsoleAliasExesLength(TRUE
);
587 GetConsoleAliasExesLengthA(VOID
)
589 DPRINT1("GetConsoleAliasExesLengthA called\n");
590 return IntGetConsoleAliasExesLength(FALSE
);