[KERNEL32][CONSRV]
[reactos.git] / win32ss / user / winsrv / consrv / alias.c
1 /*
2 * LICENSE: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/alias.c
5 * PURPOSE: Alias support functions
6 * PROGRAMMERS: Christoph Wittich
7 * Johannes Anderwald
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include "consrv.h"
13
14 #define NDEBUG
15 #include <debug.h>
16
17 /* TYPES **********************************************************************/
18
19 typedef struct _ALIAS_ENTRY
20 {
21 UNICODE_STRING Source;
22 UNICODE_STRING Target;
23 struct _ALIAS_ENTRY* Next;
24 } ALIAS_ENTRY, *PALIAS_ENTRY;
25
26 typedef struct _ALIAS_HEADER
27 {
28 UNICODE_STRING ExeName;
29 PALIAS_ENTRY Data;
30 struct _ALIAS_HEADER* Next;
31 } ALIAS_HEADER, *PALIAS_HEADER;
32
33
34
35
36 BOOLEAN
37 ConvertInputAnsiToUnicode(PCONSOLE Console,
38 PVOID Source,
39 USHORT SourceLength,
40 // BOOLEAN IsUnicode,
41 PWCHAR* Target,
42 PUSHORT TargetLength)
43 {
44 ASSERT(Source && Target && TargetLength);
45
46 /* Use the console input CP for the conversion */
47 *TargetLength = MultiByteToWideChar(Console->InputCodePage, 0,
48 Source, SourceLength,
49 NULL, 0);
50 *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
51 if (*Target == NULL) return FALSE;
52
53 MultiByteToWideChar(Console->InputCodePage, 0,
54 Source, SourceLength,
55 *Target, *TargetLength);
56
57 /* The returned Length was in number of WCHARs, convert it in bytes */
58 *TargetLength *= sizeof(WCHAR);
59
60 return TRUE;
61 }
62
63 BOOLEAN
64 ConvertInputUnicodeToAnsi(PCONSOLE Console,
65 PVOID Source,
66 USHORT SourceLength,
67 // BOOLEAN IsAnsi,
68 PCHAR/* * */ Target,
69 /*P*/USHORT TargetLength)
70 {
71 ASSERT(Source && Target && TargetLength);
72
73 /* Use the console input CP for the conversion */
74 // *TargetLength = WideCharToMultiByte(Console->InputCodePage, 0,
75 // Source, SourceLength,
76 // NULL, 0, NULL, NULL);
77 // *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
78 // if (*Target == NULL) return FALSE;
79
80 WideCharToMultiByte(Console->InputCodePage, 0,
81 Source, SourceLength,
82 /* * */Target, /* * */TargetLength,
83 NULL, NULL);
84
85 // /* The returned Length was in number of WCHARs, convert it in bytes */
86 // *TargetLength *= sizeof(WCHAR);
87
88 return TRUE;
89 }
90
91
92
93
94 /* PRIVATE FUNCTIONS **********************************************************/
95
96 static PALIAS_HEADER
97 IntFindAliasHeader(PCONSOLE Console,
98 PVOID ExeName,
99 USHORT ExeLength,
100 BOOLEAN UnicodeExe)
101 {
102 UNICODE_STRING ExeNameU;
103
104 PALIAS_HEADER RootHeader = Console->Aliases;
105 INT Diff;
106
107 if (ExeName == NULL) return NULL;
108
109 if (UnicodeExe)
110 {
111 ExeNameU.Buffer = ExeName;
112 /* Length is in bytes */
113 ExeNameU.MaximumLength = ExeLength;
114 }
115 else
116 {
117 if (!ConvertInputAnsiToUnicode(Console,
118 ExeName, ExeLength,
119 &ExeNameU.Buffer, &ExeNameU.MaximumLength))
120 {
121 return NULL;
122 }
123 }
124 ExeNameU.Length = ExeNameU.MaximumLength;
125
126 while (RootHeader)
127 {
128 Diff = RtlCompareUnicodeString(&RootHeader->ExeName, &ExeNameU, TRUE);
129 if (!Diff)
130 {
131 if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
132 return RootHeader;
133 }
134 if (Diff > 0) break;
135
136 RootHeader = RootHeader->Next;
137 }
138
139 if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
140 return NULL;
141 }
142
143 static PALIAS_HEADER
144 IntCreateAliasHeader(PCONSOLE Console,
145 PVOID ExeName,
146 USHORT ExeLength,
147 BOOLEAN UnicodeExe)
148 {
149 UNICODE_STRING ExeNameU;
150
151 PALIAS_HEADER Entry;
152
153 if (ExeName == NULL) return NULL;
154
155 if (UnicodeExe)
156 {
157 ExeNameU.Buffer = ExeName;
158 /* Length is in bytes */
159 ExeNameU.MaximumLength = ExeLength;
160 }
161 else
162 {
163 if (!ConvertInputAnsiToUnicode(Console,
164 ExeName, ExeLength,
165 &ExeNameU.Buffer, &ExeNameU.MaximumLength))
166 {
167 return NULL;
168 }
169 }
170 ExeNameU.Length = ExeNameU.MaximumLength;
171
172 Entry = ConsoleAllocHeap(0, sizeof(ALIAS_HEADER) + ExeNameU.Length);
173 if (!Entry)
174 {
175 if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
176 return Entry;
177 }
178
179 Entry->ExeName.Buffer = (PWSTR)(Entry + 1);
180 Entry->ExeName.Length = 0;
181 Entry->ExeName.MaximumLength = ExeNameU.Length;
182 RtlCopyUnicodeString(&Entry->ExeName, &ExeNameU);
183
184 Entry->Data = NULL;
185 Entry->Next = NULL;
186
187 if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
188 return Entry;
189 }
190
191 static VOID
192 IntInsertAliasHeader(PALIAS_HEADER* RootHeader,
193 PALIAS_HEADER NewHeader)
194 {
195 PALIAS_HEADER CurrentHeader;
196 PALIAS_HEADER *LastLink = RootHeader;
197 INT Diff;
198
199 while ((CurrentHeader = *LastLink) != NULL)
200 {
201 Diff = RtlCompareUnicodeString(&NewHeader->ExeName, &CurrentHeader->ExeName, TRUE);
202 if (Diff < 0) break;
203
204 LastLink = &CurrentHeader->Next;
205 }
206
207 *LastLink = NewHeader;
208 NewHeader->Next = CurrentHeader;
209 }
210
211 static PALIAS_ENTRY
212 IntGetAliasEntry(PCONSOLE Console,
213 PALIAS_HEADER Header,
214 PVOID Source,
215 USHORT SourceLength,
216 BOOLEAN Unicode)
217 {
218 UNICODE_STRING SourceU;
219
220 PALIAS_ENTRY Entry;
221 INT Diff;
222
223 if (Header == NULL || Source == NULL) return NULL;
224
225 if (Unicode)
226 {
227 SourceU.Buffer = Source;
228 /* Length is in bytes */
229 SourceU.MaximumLength = SourceLength;
230 }
231 else
232 {
233 if (!ConvertInputAnsiToUnicode(Console,
234 Source, SourceLength,
235 &SourceU.Buffer, &SourceU.MaximumLength))
236 {
237 return NULL;
238 }
239 }
240 SourceU.Length = SourceU.MaximumLength;
241
242 Entry = Header->Data;
243 while (Entry)
244 {
245 Diff = RtlCompareUnicodeString(&Entry->Source, &SourceU, TRUE);
246 if (!Diff)
247 {
248 if (!Unicode) ConsoleFreeHeap(SourceU.Buffer);
249 return Entry;
250 }
251 if (Diff > 0) break;
252
253 Entry = Entry->Next;
254 }
255
256 if (!Unicode) ConsoleFreeHeap(SourceU.Buffer);
257 return NULL;
258 }
259
260 static PALIAS_ENTRY
261 IntCreateAliasEntry(PCONSOLE Console,
262 PVOID Source,
263 USHORT SourceLength,
264 PVOID Target,
265 USHORT TargetLength,
266 BOOLEAN Unicode)
267 {
268 UNICODE_STRING SourceU;
269 UNICODE_STRING TargetU;
270
271 PALIAS_ENTRY Entry;
272
273 if (Unicode)
274 {
275 SourceU.Buffer = Source;
276 TargetU.Buffer = Target;
277 /* Length is in bytes */
278 SourceU.MaximumLength = SourceLength;
279 TargetU.MaximumLength = TargetLength;
280 }
281 else
282 {
283 if (!ConvertInputAnsiToUnicode(Console,
284 Source, SourceLength,
285 &SourceU.Buffer, &SourceU.MaximumLength))
286 {
287 return NULL;
288 }
289
290 if (!ConvertInputAnsiToUnicode(Console,
291 Target, TargetLength,
292 &TargetU.Buffer, &TargetU.MaximumLength))
293 {
294 ConsoleFreeHeap(SourceU.Buffer);
295 return NULL;
296 }
297 }
298 SourceU.Length = SourceU.MaximumLength;
299 TargetU.Length = TargetU.MaximumLength;
300
301 Entry = ConsoleAllocHeap(0, sizeof(ALIAS_ENTRY) +
302 SourceU.Length + TargetU.Length);
303 if (!Entry)
304 {
305 if (!Unicode)
306 {
307 ConsoleFreeHeap(TargetU.Buffer);
308 ConsoleFreeHeap(SourceU.Buffer);
309 }
310 return Entry;
311 }
312
313 Entry->Source.Buffer = (PWSTR)(Entry + 1);
314 Entry->Source.Length = 0;
315 Entry->Source.MaximumLength = SourceU.Length;
316 RtlCopyUnicodeString(&Entry->Source, &SourceU);
317
318 Entry->Target.Buffer = (PWSTR)((ULONG_PTR)Entry->Source.Buffer + Entry->Source.MaximumLength);
319 Entry->Target.Length = 0;
320 Entry->Target.MaximumLength = TargetU.Length;
321 RtlCopyUnicodeString(&Entry->Target, &TargetU);
322
323 Entry->Next = NULL;
324
325 if (!Unicode)
326 {
327 ConsoleFreeHeap(TargetU.Buffer);
328 ConsoleFreeHeap(SourceU.Buffer);
329 }
330 return Entry;
331 }
332
333 static VOID
334 IntInsertAliasEntry(PALIAS_HEADER Header,
335 PALIAS_ENTRY NewEntry)
336 {
337 PALIAS_ENTRY CurrentEntry;
338 PALIAS_ENTRY *LastLink = &Header->Data;
339 INT Diff;
340
341 while ((CurrentEntry = *LastLink) != NULL)
342 {
343 Diff = RtlCompareUnicodeString(&NewEntry->Source, &CurrentEntry->Source, TRUE);
344 if (Diff < 0) break;
345
346 LastLink = &CurrentEntry->Next;
347 }
348
349 *LastLink = NewEntry;
350 NewEntry->Next = CurrentEntry;
351 }
352
353 static VOID
354 IntDeleteAliasEntry(PALIAS_HEADER Header,
355 PALIAS_ENTRY Entry)
356 {
357 PALIAS_ENTRY *LastLink = &Header->Data;
358 PALIAS_ENTRY CurEntry;
359
360 while ((CurEntry = *LastLink) != NULL)
361 {
362 if (CurEntry == Entry)
363 {
364 *LastLink = Entry->Next;
365 ConsoleFreeHeap(Entry);
366 return;
367 }
368 LastLink = &CurEntry->Next;
369 }
370 }
371
372 static UINT
373 IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader,
374 BOOLEAN IsUnicode)
375 {
376 UINT Length = 0;
377
378 while (RootHeader)
379 {
380 Length += RootHeader->ExeName.Length + sizeof(WCHAR); // NULL-termination
381 RootHeader = RootHeader->Next;
382 }
383
384 /*
385 * Quick and dirty way of getting the number of bytes of the
386 * corresponding ANSI string from the one in UNICODE.
387 */
388 if (!IsUnicode)
389 Length /= sizeof(WCHAR);
390
391 return Length;
392 }
393
394 static UINT
395 IntGetAllConsoleAliasesLength(PALIAS_HEADER Header,
396 BOOLEAN IsUnicode)
397 {
398 UINT Length = 0;
399 PALIAS_ENTRY CurEntry = Header->Data;
400
401 while (CurEntry)
402 {
403 Length += CurEntry->Source.Length;
404 Length += CurEntry->Target.Length;
405 Length += 2 * sizeof(WCHAR); // '=' and NULL-termination
406 CurEntry = CurEntry->Next;
407 }
408
409 /*
410 * Quick and dirty way of getting the number of bytes of the
411 * corresponding ANSI string from the one in UNICODE.
412 */
413 if (!IsUnicode)
414 Length /= sizeof(WCHAR);
415
416 return Length;
417 }
418
419 VOID
420 IntDeleteAllAliases(PCONSOLE Console)
421 {
422 PALIAS_HEADER Header, NextHeader;
423 PALIAS_ENTRY Entry, NextEntry;
424
425 for (Header = Console->Aliases; Header; Header = NextHeader)
426 {
427 NextHeader = Header->Next;
428 for (Entry = Header->Data; Entry; Entry = NextEntry)
429 {
430 NextEntry = Entry->Next;
431 ConsoleFreeHeap(Entry);
432 }
433 ConsoleFreeHeap(Header);
434 }
435 }
436
437
438 /* PUBLIC SERVER APIS *********************************************************/
439
440 CSR_API(SrvAddConsoleAlias)
441 {
442 NTSTATUS Status;
443 PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
444 PCONSOLE Console;
445 PALIAS_HEADER Header;
446 PALIAS_ENTRY Entry;
447 PVOID lpTarget;
448
449 DPRINT1("SrvAddConsoleAlias entered ApiMessage %p\n", ApiMessage);
450
451 if ( !CsrValidateMessageBuffer(ApiMessage,
452 (PVOID*)&ConsoleAliasRequest->Source,
453 ConsoleAliasRequest->SourceLength,
454 sizeof(BYTE)) ||
455 !CsrValidateMessageBuffer(ApiMessage,
456 (PVOID*)&ConsoleAliasRequest->Target,
457 ConsoleAliasRequest->TargetLength,
458 sizeof(BYTE)) ||
459 !CsrValidateMessageBuffer(ApiMessage,
460 (PVOID*)&ConsoleAliasRequest->ExeName,
461 ConsoleAliasRequest->ExeLength,
462 sizeof(BYTE)) )
463 {
464 return STATUS_INVALID_PARAMETER;
465 }
466
467 lpTarget = (ConsoleAliasRequest->TargetLength != 0 ? ConsoleAliasRequest->Target : NULL);
468
469 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
470 if (!NT_SUCCESS(Status)) return Status;
471
472 Status = STATUS_SUCCESS;
473
474 Header = IntFindAliasHeader(Console,
475 ConsoleAliasRequest->ExeName,
476 ConsoleAliasRequest->ExeLength,
477 ConsoleAliasRequest->Unicode2);
478 if (!Header && lpTarget != NULL)
479 {
480 Header = IntCreateAliasHeader(Console,
481 ConsoleAliasRequest->ExeName,
482 ConsoleAliasRequest->ExeLength,
483 ConsoleAliasRequest->Unicode2);
484 if (!Header)
485 {
486 Status = STATUS_NO_MEMORY;
487 goto Quit;
488 }
489
490 IntInsertAliasHeader(&Console->Aliases, Header);
491 }
492
493 if (lpTarget == NULL) // Delete the entry
494 {
495 Entry = IntGetAliasEntry(Console, Header,
496 ConsoleAliasRequest->Source,
497 ConsoleAliasRequest->SourceLength,
498 ConsoleAliasRequest->Unicode);
499 if (!Entry)
500 {
501 Status = STATUS_UNSUCCESSFUL;
502 goto Quit;
503 }
504
505 IntDeleteAliasEntry(Header, Entry);
506 }
507 else // Add the entry
508 {
509 Entry = IntCreateAliasEntry(Console,
510 ConsoleAliasRequest->Source,
511 ConsoleAliasRequest->SourceLength,
512 ConsoleAliasRequest->Target,
513 ConsoleAliasRequest->TargetLength,
514 ConsoleAliasRequest->Unicode);
515 if (!Entry)
516 {
517 Status = STATUS_NO_MEMORY;
518 goto Quit;
519 }
520
521 IntInsertAliasEntry(Header, Entry);
522 }
523
524 Quit:
525 ConSrvReleaseConsole(Console, TRUE);
526 return Status;
527 }
528
529 CSR_API(SrvGetConsoleAlias)
530 {
531 NTSTATUS Status;
532 PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
533 PCONSOLE Console;
534 PALIAS_HEADER Header;
535 PALIAS_ENTRY Entry;
536 UINT Length;
537 PVOID lpTarget;
538
539 DPRINT1("SrvGetConsoleAlias entered ApiMessage %p\n", ApiMessage);
540
541 if ( !CsrValidateMessageBuffer(ApiMessage,
542 (PVOID*)&ConsoleAliasRequest->Source,
543 ConsoleAliasRequest->SourceLength,
544 sizeof(BYTE)) ||
545 !CsrValidateMessageBuffer(ApiMessage,
546 (PVOID*)&ConsoleAliasRequest->Target,
547 ConsoleAliasRequest->TargetLength,
548 sizeof(BYTE)) ||
549 !CsrValidateMessageBuffer(ApiMessage,
550 (PVOID*)&ConsoleAliasRequest->ExeName,
551 ConsoleAliasRequest->ExeLength,
552 sizeof(BYTE)) )
553 {
554 return STATUS_INVALID_PARAMETER;
555 }
556
557 lpTarget = ConsoleAliasRequest->Target;
558
559 if (ConsoleAliasRequest->ExeLength == 0 || lpTarget == NULL ||
560 ConsoleAliasRequest->TargetLength == 0 || ConsoleAliasRequest->SourceLength == 0)
561 {
562 return STATUS_INVALID_PARAMETER;
563 }
564
565 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
566 if (!NT_SUCCESS(Status)) return Status;
567
568 Header = IntFindAliasHeader(Console,
569 ConsoleAliasRequest->ExeName,
570 ConsoleAliasRequest->ExeLength,
571 ConsoleAliasRequest->Unicode2);
572 if (!Header)
573 {
574 Status = STATUS_UNSUCCESSFUL;
575 goto Quit;
576 }
577
578 Entry = IntGetAliasEntry(Console, Header,
579 ConsoleAliasRequest->Source,
580 ConsoleAliasRequest->SourceLength,
581 ConsoleAliasRequest->Unicode);
582 if (!Entry)
583 {
584 Status = STATUS_UNSUCCESSFUL;
585 goto Quit;
586 }
587
588 if (ConsoleAliasRequest->Unicode)
589 {
590 Length = Entry->Target.Length + sizeof(WCHAR);
591 if (Length > ConsoleAliasRequest->TargetLength) // FIXME: Refine computation.
592 {
593 Status = STATUS_BUFFER_TOO_SMALL;
594 goto Quit;
595 }
596
597 RtlCopyMemory(lpTarget, Entry->Target.Buffer, Entry->Target.Length);
598 ConsoleAliasRequest->TargetLength = Length;
599 }
600 else
601 {
602 Length = (Entry->Target.Length + sizeof(WCHAR)) / sizeof(WCHAR);
603 if (Length > ConsoleAliasRequest->TargetLength) // FIXME: Refine computation.
604 {
605 Status = STATUS_BUFFER_TOO_SMALL;
606 goto Quit;
607 }
608
609 ConvertInputUnicodeToAnsi(Console,
610 Entry->Target.Buffer, Entry->Target.Length,
611 lpTarget, Entry->Target.Length / sizeof(WCHAR));
612 ConsoleAliasRequest->TargetLength = Length;
613 }
614
615 Quit:
616 ConSrvReleaseConsole(Console, TRUE);
617 return Status;
618 }
619
620 CSR_API(SrvGetConsoleAliases)
621 {
622 NTSTATUS Status;
623 PCONSOLE_GETALLALIASES GetAllAliasesRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesRequest;
624 PCONSOLE Console;
625 ULONG BytesWritten = 0;
626 PALIAS_HEADER Header;
627
628 DPRINT1("SrvGetConsoleAliases entered ApiMessage %p\n", ApiMessage);
629
630 if ( !CsrValidateMessageBuffer(ApiMessage,
631 (PVOID)&GetAllAliasesRequest->ExeName,
632 GetAllAliasesRequest->ExeLength,
633 sizeof(BYTE)) ||
634 !CsrValidateMessageBuffer(ApiMessage,
635 (PVOID)&GetAllAliasesRequest->AliasesBuffer,
636 GetAllAliasesRequest->AliasesBufferLength,
637 sizeof(BYTE)) )
638 {
639 return STATUS_INVALID_PARAMETER;
640 }
641
642 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
643 if (!NT_SUCCESS(Status)) return Status;
644
645 Header = IntFindAliasHeader(Console,
646 GetAllAliasesRequest->ExeName,
647 GetAllAliasesRequest->ExeLength,
648 GetAllAliasesRequest->Unicode2);
649 if (!Header) goto Quit;
650
651 if (IntGetAllConsoleAliasesLength(Header, GetAllAliasesRequest->Unicode) > GetAllAliasesRequest->AliasesBufferLength)
652 {
653 Status = STATUS_BUFFER_OVERFLOW;
654 goto Quit;
655 }
656
657 {
658 LPSTR TargetBufferA;
659 LPWSTR TargetBufferW;
660 UINT TargetBufferLength = GetAllAliasesRequest->AliasesBufferLength;
661
662 PALIAS_ENTRY CurEntry = Header->Data;
663 UINT Offset = 0;
664 UINT SourceLength, TargetLength;
665
666 if (GetAllAliasesRequest->Unicode)
667 {
668 TargetBufferW = GetAllAliasesRequest->AliasesBuffer;
669 TargetBufferLength /= sizeof(WCHAR);
670 }
671 else
672 {
673 TargetBufferA = GetAllAliasesRequest->AliasesBuffer;
674 }
675
676 while (CurEntry)
677 {
678 SourceLength = CurEntry->Source.Length / sizeof(WCHAR);
679 TargetLength = CurEntry->Target.Length / sizeof(WCHAR);
680 if (Offset + TargetLength + SourceLength + 2 > TargetBufferLength)
681 {
682 Status = STATUS_BUFFER_OVERFLOW;
683 break;
684 }
685
686 if (GetAllAliasesRequest->Unicode)
687 {
688 RtlCopyMemory(&TargetBufferW[Offset], CurEntry->Source.Buffer, SourceLength * sizeof(WCHAR));
689 Offset += SourceLength;
690 TargetBufferW[Offset++] = L'=';
691 RtlCopyMemory(&TargetBufferW[Offset], CurEntry->Target.Buffer, TargetLength * sizeof(WCHAR));
692 Offset += TargetLength;
693 TargetBufferW[Offset++] = L'\0';
694 }
695 else
696 {
697 ConvertInputUnicodeToAnsi(Console,
698 CurEntry->Source.Buffer, SourceLength * sizeof(WCHAR),
699 &TargetBufferA[Offset], SourceLength);
700 Offset += SourceLength;
701 TargetBufferA[Offset++] = '=';
702 ConvertInputUnicodeToAnsi(Console,
703 CurEntry->Target.Buffer, TargetLength * sizeof(WCHAR),
704 &TargetBufferA[Offset], TargetLength);
705 Offset += TargetLength;
706 TargetBufferA[Offset++] = '\0';
707 }
708
709 CurEntry = CurEntry->Next;
710 }
711
712 if (GetAllAliasesRequest->Unicode)
713 BytesWritten = Offset * sizeof(WCHAR);
714 else
715 BytesWritten = Offset;
716 }
717
718 Quit:
719 GetAllAliasesRequest->AliasesBufferLength = BytesWritten;
720
721 ConSrvReleaseConsole(Console, TRUE);
722 return Status;
723 }
724
725 CSR_API(SrvGetConsoleAliasesLength)
726 {
727 NTSTATUS Status;
728 PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesLengthRequest;
729 PCONSOLE Console;
730 PALIAS_HEADER Header;
731
732 DPRINT1("SrvGetConsoleAliasesLength entered ApiMessage %p\n", ApiMessage);
733
734 if (!CsrValidateMessageBuffer(ApiMessage,
735 (PVOID)&GetAllAliasesLengthRequest->ExeName,
736 GetAllAliasesLengthRequest->ExeLength,
737 sizeof(BYTE)))
738 {
739 return STATUS_INVALID_PARAMETER;
740 }
741
742 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
743 if (!NT_SUCCESS(Status)) return Status;
744
745 Header = IntFindAliasHeader(Console,
746 GetAllAliasesLengthRequest->ExeName,
747 GetAllAliasesLengthRequest->ExeLength,
748 GetAllAliasesLengthRequest->Unicode2);
749 if (Header)
750 {
751 GetAllAliasesLengthRequest->Length =
752 IntGetAllConsoleAliasesLength(Header,
753 GetAllAliasesLengthRequest->Unicode);
754 Status = STATUS_SUCCESS;
755 }
756 else
757 {
758 GetAllAliasesLengthRequest->Length = 0;
759 }
760
761 ConSrvReleaseConsole(Console, TRUE);
762 return Status;
763 }
764
765 CSR_API(SrvGetConsoleAliasExes)
766 {
767 NTSTATUS Status;
768 PCONSOLE_GETALIASESEXES GetAliasesExesRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesRequest;
769 PCONSOLE Console;
770 UINT BytesWritten = 0;
771
772 DPRINT1("SrvGetConsoleAliasExes entered\n");
773
774 if (!CsrValidateMessageBuffer(ApiMessage,
775 (PVOID*)&GetAliasesExesRequest->ExeNames,
776 GetAliasesExesRequest->Length,
777 sizeof(BYTE)))
778 {
779 return STATUS_INVALID_PARAMETER;
780 }
781
782 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
783 if (!NT_SUCCESS(Status)) return Status;
784
785 if (IntGetConsoleAliasesExesLength(Console->Aliases, GetAliasesExesRequest->Unicode) > GetAliasesExesRequest->Length)
786 {
787 Status = STATUS_BUFFER_OVERFLOW;
788 goto Quit;
789 }
790
791 {
792 PALIAS_HEADER RootHeader = Console->Aliases;
793
794 LPSTR TargetBufferA;
795 LPWSTR TargetBufferW;
796 UINT TargetBufferSize = GetAliasesExesRequest->Length;
797
798 UINT Offset = 0;
799 UINT Length;
800
801 if (GetAliasesExesRequest->Unicode)
802 {
803 TargetBufferW = GetAliasesExesRequest->ExeNames;
804 TargetBufferSize /= sizeof(WCHAR);
805 }
806 else
807 {
808 TargetBufferA = GetAliasesExesRequest->ExeNames;
809 }
810
811 while (RootHeader)
812 {
813 Length = RootHeader->ExeName.Length / sizeof(WCHAR);
814 if (Offset + Length + 1 > TargetBufferSize)
815 {
816 Status = STATUS_BUFFER_OVERFLOW;
817 break;
818 }
819
820 if (GetAliasesExesRequest->Unicode)
821 {
822 RtlCopyMemory(&TargetBufferW[Offset], RootHeader->ExeName.Buffer, Length * sizeof(WCHAR));
823 Offset += Length;
824 TargetBufferW[Offset++] = L'\0';
825 }
826 else
827 {
828 ConvertInputUnicodeToAnsi(Console,
829 RootHeader->ExeName.Buffer, Length * sizeof(WCHAR),
830 &TargetBufferA[Offset], Length);
831 Offset += Length;
832 TargetBufferA[Offset++] = '\0';
833 }
834
835 RootHeader = RootHeader->Next;
836 }
837
838 if (GetAliasesExesRequest->Unicode)
839 BytesWritten = Offset * sizeof(WCHAR);
840 else
841 BytesWritten = Offset;
842 }
843
844 Quit:
845 GetAliasesExesRequest->Length = BytesWritten;
846
847 ConSrvReleaseConsole(Console, TRUE);
848 return Status;
849 }
850
851 CSR_API(SrvGetConsoleAliasExesLength)
852 {
853 NTSTATUS Status;
854 PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesLengthRequest;
855 PCONSOLE Console;
856
857 DPRINT1("SrvGetConsoleAliasExesLength entered ApiMessage %p\n", ApiMessage);
858
859 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
860 if (!NT_SUCCESS(Status)) return Status;
861
862 GetAliasesExesLengthRequest->Length =
863 IntGetConsoleAliasesExesLength(Console->Aliases,
864 GetAliasesExesLengthRequest->Unicode);
865
866 ConSrvReleaseConsole(Console, TRUE);
867 return Status;
868 }
869
870 /* EOF */