ReactOS  0.4.14-dev-1025-gd1ac13c
alias.c
Go to the documentation of this file.
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  struct _ALIAS_ENTRY* Next;
25 
26 typedef struct _ALIAS_HEADER
27 {
32 
33 
34 
35 
36 BOOLEAN
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
65  PVOID Source,
66  USHORT SourceLength,
67  // BOOLEAN IsAnsi,
68  PCHAR/* * */ Target,
69  /*P*/USHORT TargetLength)
70 {
71  ASSERT(Source && Target && TargetLength);
72 
73  /*
74  * From MSDN:
75  * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
76  * If they are the same, the function fails, and GetLastError returns
77  * ERROR_INVALID_PARAMETER."
78  */
80 
81  /* Use the console input CP for the conversion */
82  // *TargetLength = WideCharToMultiByte(Console->InputCodePage, 0,
83  // Source, SourceLength,
84  // NULL, 0, NULL, NULL);
85  // *Target = ConsoleAllocHeap(0, *TargetLength * sizeof(WCHAR));
86  // if (*Target == NULL) return FALSE;
87 
88  WideCharToMultiByte(Console->InputCodePage, 0,
89  Source, SourceLength,
90  /* * */Target, /* * */TargetLength,
91  NULL, NULL);
92 
93  // /* The returned Length was in number of WCHARs, convert it in bytes */
94  // *TargetLength *= sizeof(WCHAR);
95 
96  return TRUE;
97 }
98 
99 
100 
101 
102 /* PRIVATE FUNCTIONS **********************************************************/
103 
104 static PALIAS_HEADER
106  PVOID ExeName,
107  USHORT ExeLength,
108  BOOLEAN UnicodeExe)
109 {
110  UNICODE_STRING ExeNameU;
111 
112  PALIAS_HEADER RootHeader = Console->Aliases;
113  INT Diff;
114 
115  if (ExeName == NULL) return NULL;
116 
117  if (UnicodeExe)
118  {
119  ExeNameU.Buffer = ExeName;
120  /* Length is in bytes */
121  ExeNameU.MaximumLength = ExeLength;
122  }
123  else
124  {
126  ExeName, ExeLength,
127  &ExeNameU.Buffer, &ExeNameU.MaximumLength))
128  {
129  return NULL;
130  }
131  }
132  ExeNameU.Length = ExeNameU.MaximumLength;
133 
134  while (RootHeader)
135  {
136  Diff = RtlCompareUnicodeString(&RootHeader->ExeName, &ExeNameU, TRUE);
137  if (!Diff)
138  {
139  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
140  return RootHeader;
141  }
142  if (Diff > 0) break;
143 
144  RootHeader = RootHeader->Next;
145  }
146 
147  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
148  return NULL;
149 }
150 
151 static PALIAS_HEADER
153  PVOID ExeName,
154  USHORT ExeLength,
155  BOOLEAN UnicodeExe)
156 {
157  UNICODE_STRING ExeNameU;
158 
160 
161  if (ExeName == NULL) return NULL;
162 
163  if (UnicodeExe)
164  {
165  ExeNameU.Buffer = ExeName;
166  /* Length is in bytes */
167  ExeNameU.MaximumLength = ExeLength;
168  }
169  else
170  {
172  ExeName, ExeLength,
173  &ExeNameU.Buffer, &ExeNameU.MaximumLength))
174  {
175  return NULL;
176  }
177  }
178  ExeNameU.Length = ExeNameU.MaximumLength;
179 
180  Entry = ConsoleAllocHeap(0, sizeof(ALIAS_HEADER) + ExeNameU.Length);
181  if (!Entry)
182  {
183  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
184  return Entry;
185  }
186 
187  Entry->ExeName.Buffer = (PWSTR)(Entry + 1);
188  Entry->ExeName.Length = 0;
189  Entry->ExeName.MaximumLength = ExeNameU.Length;
190  RtlCopyUnicodeString(&Entry->ExeName, &ExeNameU);
191 
192  Entry->Data = NULL;
193  Entry->Next = NULL;
194 
195  if (!UnicodeExe) ConsoleFreeHeap(ExeNameU.Buffer);
196  return Entry;
197 }
198 
199 static VOID
201  PALIAS_HEADER NewHeader)
202 {
203  PALIAS_HEADER CurrentHeader;
204  PALIAS_HEADER *LastLink = RootHeader;
205  INT Diff;
206 
207  while ((CurrentHeader = *LastLink) != NULL)
208  {
209  Diff = RtlCompareUnicodeString(&NewHeader->ExeName, &CurrentHeader->ExeName, TRUE);
210  if (Diff < 0) break;
211 
212  LastLink = &CurrentHeader->Next;
213  }
214 
215  *LastLink = NewHeader;
216  NewHeader->Next = CurrentHeader;
217 }
218 
219 static PALIAS_ENTRY
222  PVOID Source,
223  USHORT SourceLength,
224  BOOLEAN Unicode)
225 {
226  UNICODE_STRING SourceU;
227 
229  INT Diff;
230 
231  if (Header == NULL || Source == NULL) return NULL;
232 
233  if (Unicode)
234  {
235  SourceU.Buffer = Source;
236  /* Length is in bytes */
237  SourceU.MaximumLength = SourceLength;
238  }
239  else
240  {
242  Source, SourceLength,
243  &SourceU.Buffer, &SourceU.MaximumLength))
244  {
245  return NULL;
246  }
247  }
248  SourceU.Length = SourceU.MaximumLength;
249 
250  Entry = Header->Data;
251  while (Entry)
252  {
253  Diff = RtlCompareUnicodeString(&Entry->Source, &SourceU, TRUE);
254  if (!Diff)
255  {
256  if (!Unicode) ConsoleFreeHeap(SourceU.Buffer);
257  return Entry;
258  }
259  if (Diff > 0) break;
260 
261  Entry = Entry->Next;
262  }
263 
264  if (!Unicode) ConsoleFreeHeap(SourceU.Buffer);
265  return NULL;
266 }
267 
268 static PALIAS_ENTRY
270  PVOID Source,
271  USHORT SourceLength,
272  PVOID Target,
273  USHORT TargetLength,
274  BOOLEAN Unicode)
275 {
276  UNICODE_STRING SourceU;
277  UNICODE_STRING TargetU;
278 
280 
281  if (Unicode)
282  {
283  SourceU.Buffer = Source;
284  TargetU.Buffer = Target;
285  /* Length is in bytes */
286  SourceU.MaximumLength = SourceLength;
287  TargetU.MaximumLength = TargetLength;
288  }
289  else
290  {
292  Source, SourceLength,
293  &SourceU.Buffer, &SourceU.MaximumLength))
294  {
295  return NULL;
296  }
297 
299  Target, TargetLength,
300  &TargetU.Buffer, &TargetU.MaximumLength))
301  {
302  ConsoleFreeHeap(SourceU.Buffer);
303  return NULL;
304  }
305  }
306  SourceU.Length = SourceU.MaximumLength;
307  TargetU.Length = TargetU.MaximumLength;
308 
309  Entry = ConsoleAllocHeap(0, sizeof(ALIAS_ENTRY) +
310  SourceU.Length + TargetU.Length);
311  if (!Entry)
312  {
313  if (!Unicode)
314  {
315  ConsoleFreeHeap(TargetU.Buffer);
316  ConsoleFreeHeap(SourceU.Buffer);
317  }
318  return Entry;
319  }
320 
321  Entry->Source.Buffer = (PWSTR)(Entry + 1);
322  Entry->Source.Length = 0;
323  Entry->Source.MaximumLength = SourceU.Length;
324  RtlCopyUnicodeString(&Entry->Source, &SourceU);
325 
326  Entry->Target.Buffer = (PWSTR)((ULONG_PTR)Entry->Source.Buffer + Entry->Source.MaximumLength);
327  Entry->Target.Length = 0;
328  Entry->Target.MaximumLength = TargetU.Length;
329  RtlCopyUnicodeString(&Entry->Target, &TargetU);
330 
331  Entry->Next = NULL;
332 
333  if (!Unicode)
334  {
335  ConsoleFreeHeap(TargetU.Buffer);
336  ConsoleFreeHeap(SourceU.Buffer);
337  }
338  return Entry;
339 }
340 
341 static VOID
343  PALIAS_ENTRY NewEntry)
344 {
345  PALIAS_ENTRY CurrentEntry;
346  PALIAS_ENTRY *LastLink = &Header->Data;
347  INT Diff;
348 
349  while ((CurrentEntry = *LastLink) != NULL)
350  {
351  Diff = RtlCompareUnicodeString(&NewEntry->Source, &CurrentEntry->Source, TRUE);
352  if (Diff < 0) break;
353 
354  LastLink = &CurrentEntry->Next;
355  }
356 
357  *LastLink = NewEntry;
358  NewEntry->Next = CurrentEntry;
359 }
360 
361 static VOID
364 {
365  PALIAS_ENTRY *LastLink = &Header->Data;
366  PALIAS_ENTRY CurEntry;
367 
368  while ((CurEntry = *LastLink) != NULL)
369  {
370  if (CurEntry == Entry)
371  {
372  *LastLink = Entry->Next;
374  return;
375  }
376  LastLink = &CurEntry->Next;
377  }
378 }
379 
380 static UINT
382  BOOLEAN IsUnicode)
383 {
384  UINT Length = 0;
385 
386  while (RootHeader)
387  {
388  Length += RootHeader->ExeName.Length + sizeof(WCHAR); // NULL-termination
389  RootHeader = RootHeader->Next;
390  }
391 
392  /*
393  * Quick and dirty way of getting the number of bytes of the
394  * corresponding ANSI string from the one in UNICODE.
395  */
396  if (!IsUnicode)
397  Length /= sizeof(WCHAR);
398 
399  return Length;
400 }
401 
402 static UINT
404  BOOLEAN IsUnicode)
405 {
406  UINT Length = 0;
407  PALIAS_ENTRY CurEntry = Header->Data;
408 
409  while (CurEntry)
410  {
411  Length += CurEntry->Source.Length;
412  Length += CurEntry->Target.Length;
413  Length += 2 * sizeof(WCHAR); // '=' and NULL-termination
414  CurEntry = CurEntry->Next;
415  }
416 
417  /*
418  * Quick and dirty way of getting the number of bytes of the
419  * corresponding ANSI string from the one in UNICODE.
420  */
421  if (!IsUnicode)
422  Length /= sizeof(WCHAR);
423 
424  return Length;
425 }
426 
427 VOID
429 {
430  PALIAS_HEADER Header, NextHeader;
431  PALIAS_ENTRY Entry, NextEntry;
432 
433  for (Header = Console->Aliases; Header; Header = NextHeader)
434  {
435  NextHeader = Header->Next;
436  for (Entry = Header->Data; Entry; Entry = NextEntry)
437  {
438  NextEntry = Entry->Next;
440  }
442  }
443 }
444 
445 
446 /* PUBLIC SERVER APIS *********************************************************/
447 
448 /* API_NUMBER: ConsolepAddAlias */
449 CSR_API(SrvAddConsoleAlias)
450 {
452  PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
456  PVOID lpTarget;
457 
458  DPRINT("SrvAddConsoleAlias entered ApiMessage %p\n", ApiMessage);
459 
460  if ( !CsrValidateMessageBuffer(ApiMessage,
461  (PVOID*)&ConsoleAliasRequest->Source,
462  ConsoleAliasRequest->SourceLength,
463  sizeof(BYTE)) ||
464  !CsrValidateMessageBuffer(ApiMessage,
465  (PVOID*)&ConsoleAliasRequest->Target,
466  ConsoleAliasRequest->TargetLength,
467  sizeof(BYTE)) ||
468  !CsrValidateMessageBuffer(ApiMessage,
469  (PVOID*)&ConsoleAliasRequest->ExeName,
470  ConsoleAliasRequest->ExeLength,
471  sizeof(BYTE)) )
472  {
474  }
475 
476  lpTarget = (ConsoleAliasRequest->TargetLength != 0 ? ConsoleAliasRequest->Target : NULL);
477 
479  &Console, TRUE);
480  if (!NT_SUCCESS(Status)) return Status;
481 
483 
485  ConsoleAliasRequest->ExeName,
486  ConsoleAliasRequest->ExeLength,
487  ConsoleAliasRequest->Unicode2);
488  if (!Header && lpTarget != NULL)
489  {
491  ConsoleAliasRequest->ExeName,
492  ConsoleAliasRequest->ExeLength,
493  ConsoleAliasRequest->Unicode2);
494  if (!Header)
495  {
497  goto Quit;
498  }
499 
500  IntInsertAliasHeader(&Console->Aliases, Header);
501  }
502 
503  if (lpTarget == NULL) // Delete the entry
504  {
506  ConsoleAliasRequest->Source,
507  ConsoleAliasRequest->SourceLength,
508  ConsoleAliasRequest->Unicode);
509  if (!Entry)
510  {
512  goto Quit;
513  }
514 
516  }
517  else // Add the entry
518  {
520  ConsoleAliasRequest->Source,
521  ConsoleAliasRequest->SourceLength,
522  ConsoleAliasRequest->Target,
523  ConsoleAliasRequest->TargetLength,
524  ConsoleAliasRequest->Unicode);
525  if (!Entry)
526  {
528  goto Quit;
529  }
530 
532  }
533 
534 Quit:
536  return Status;
537 }
538 
539 /* API_NUMBER: ConsolepGetAlias */
540 CSR_API(SrvGetConsoleAlias)
541 {
543  PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
547  UINT Length;
548  PVOID lpTarget;
549 
550  DPRINT("SrvGetConsoleAlias entered ApiMessage %p\n", ApiMessage);
551 
552  if ( !CsrValidateMessageBuffer(ApiMessage,
553  (PVOID*)&ConsoleAliasRequest->Source,
554  ConsoleAliasRequest->SourceLength,
555  sizeof(BYTE)) ||
556  !CsrValidateMessageBuffer(ApiMessage,
557  (PVOID*)&ConsoleAliasRequest->Target,
558  ConsoleAliasRequest->TargetLength,
559  sizeof(BYTE)) ||
560  !CsrValidateMessageBuffer(ApiMessage,
561  (PVOID*)&ConsoleAliasRequest->ExeName,
562  ConsoleAliasRequest->ExeLength,
563  sizeof(BYTE)) )
564  {
566  }
567 
568  lpTarget = ConsoleAliasRequest->Target;
569 
570  if (ConsoleAliasRequest->ExeLength == 0 || lpTarget == NULL ||
571  ConsoleAliasRequest->TargetLength == 0 || ConsoleAliasRequest->SourceLength == 0)
572  {
574  }
575 
577  &Console, TRUE);
578  if (!NT_SUCCESS(Status)) return Status;
579 
581  ConsoleAliasRequest->ExeName,
582  ConsoleAliasRequest->ExeLength,
583  ConsoleAliasRequest->Unicode2);
584  if (!Header)
585  {
587  goto Quit;
588  }
589 
591  ConsoleAliasRequest->Source,
592  ConsoleAliasRequest->SourceLength,
593  ConsoleAliasRequest->Unicode);
594  if (!Entry)
595  {
597  goto Quit;
598  }
599 
600  if (ConsoleAliasRequest->Unicode)
601  {
602  Length = Entry->Target.Length + sizeof(WCHAR);
603  if (Length > ConsoleAliasRequest->TargetLength) // FIXME: Refine computation.
604  {
606  goto Quit;
607  }
608 
609  RtlCopyMemory(lpTarget, Entry->Target.Buffer, Entry->Target.Length);
610  ConsoleAliasRequest->TargetLength = Length;
611  }
612  else
613  {
614  Length = (Entry->Target.Length + sizeof(WCHAR)) / sizeof(WCHAR);
615  if (Length > ConsoleAliasRequest->TargetLength) // FIXME: Refine computation.
616  {
618  goto Quit;
619  }
620 
622  Entry->Target.Buffer, Entry->Target.Length,
623  lpTarget, Entry->Target.Length / sizeof(WCHAR));
624  ConsoleAliasRequest->TargetLength = Length;
625  }
626 
627 Quit:
629  return Status;
630 }
631 
632 /* API_NUMBER: ConsolepGetAliases */
633 CSR_API(SrvGetConsoleAliases)
634 {
636  PCONSOLE_GETALLALIASES GetAllAliasesRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesRequest;
638  ULONG BytesWritten = 0;
640 
641  DPRINT("SrvGetConsoleAliases entered ApiMessage %p\n", ApiMessage);
642 
643  if ( !CsrValidateMessageBuffer(ApiMessage,
644  (PVOID)&GetAllAliasesRequest->ExeName,
645  GetAllAliasesRequest->ExeLength,
646  sizeof(BYTE)) ||
647  !CsrValidateMessageBuffer(ApiMessage,
648  (PVOID)&GetAllAliasesRequest->AliasesBuffer,
649  GetAllAliasesRequest->AliasesBufferLength,
650  sizeof(BYTE)) )
651  {
653  }
654 
656  &Console, TRUE);
657  if (!NT_SUCCESS(Status)) return Status;
658 
660  GetAllAliasesRequest->ExeName,
661  GetAllAliasesRequest->ExeLength,
662  GetAllAliasesRequest->Unicode2);
663  if (!Header) goto Quit;
664 
665  if (IntGetAllConsoleAliasesLength(Header, GetAllAliasesRequest->Unicode) > GetAllAliasesRequest->AliasesBufferLength)
666  {
668  goto Quit;
669  }
670 
671  {
672  LPSTR TargetBufferA;
673  LPWSTR TargetBufferW;
674  UINT TargetBufferLength = GetAllAliasesRequest->AliasesBufferLength;
675 
676  PALIAS_ENTRY CurEntry = Header->Data;
677  UINT Offset = 0;
678  UINT SourceLength, TargetLength;
679 
680  if (GetAllAliasesRequest->Unicode)
681  {
682  TargetBufferW = GetAllAliasesRequest->AliasesBuffer;
683  TargetBufferLength /= sizeof(WCHAR);
684  }
685  else
686  {
687  TargetBufferA = GetAllAliasesRequest->AliasesBuffer;
688  }
689 
690  while (CurEntry)
691  {
692  SourceLength = CurEntry->Source.Length / sizeof(WCHAR);
693  TargetLength = CurEntry->Target.Length / sizeof(WCHAR);
694  if (Offset + TargetLength + SourceLength + 2 > TargetBufferLength)
695  {
697  break;
698  }
699 
700  if (GetAllAliasesRequest->Unicode)
701  {
702  RtlCopyMemory(&TargetBufferW[Offset], CurEntry->Source.Buffer, SourceLength * sizeof(WCHAR));
703  Offset += SourceLength;
704  TargetBufferW[Offset++] = L'=';
705  RtlCopyMemory(&TargetBufferW[Offset], CurEntry->Target.Buffer, TargetLength * sizeof(WCHAR));
706  Offset += TargetLength;
707  TargetBufferW[Offset++] = L'\0';
708  }
709  else
710  {
712  CurEntry->Source.Buffer, SourceLength * sizeof(WCHAR),
713  &TargetBufferA[Offset], SourceLength);
714  Offset += SourceLength;
715  TargetBufferA[Offset++] = '=';
717  CurEntry->Target.Buffer, TargetLength * sizeof(WCHAR),
718  &TargetBufferA[Offset], TargetLength);
719  Offset += TargetLength;
720  TargetBufferA[Offset++] = '\0';
721  }
722 
723  CurEntry = CurEntry->Next;
724  }
725 
726  if (GetAllAliasesRequest->Unicode)
727  BytesWritten = Offset * sizeof(WCHAR);
728  else
730  }
731 
732 Quit:
733  GetAllAliasesRequest->AliasesBufferLength = BytesWritten;
734 
736  return Status;
737 }
738 
739 /* API_NUMBER: ConsolepGetAliasesLength */
740 CSR_API(SrvGetConsoleAliasesLength)
741 {
743  PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesLengthRequest;
746 
747  DPRINT("SrvGetConsoleAliasesLength entered ApiMessage %p\n", ApiMessage);
748 
749  if (!CsrValidateMessageBuffer(ApiMessage,
750  (PVOID)&GetAllAliasesLengthRequest->ExeName,
751  GetAllAliasesLengthRequest->ExeLength,
752  sizeof(BYTE)))
753  {
755  }
756 
758  &Console, TRUE);
759  if (!NT_SUCCESS(Status)) return Status;
760 
762  GetAllAliasesLengthRequest->ExeName,
763  GetAllAliasesLengthRequest->ExeLength,
764  GetAllAliasesLengthRequest->Unicode2);
765  if (Header)
766  {
767  GetAllAliasesLengthRequest->Length =
769  GetAllAliasesLengthRequest->Unicode);
771  }
772  else
773  {
774  GetAllAliasesLengthRequest->Length = 0;
775  }
776 
778  return Status;
779 }
780 
781 /* API_NUMBER: ConsolepGetAliasExes */
782 CSR_API(SrvGetConsoleAliasExes)
783 {
785  PCONSOLE_GETALIASESEXES GetAliasesExesRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesRequest;
787  UINT BytesWritten = 0;
788 
789  DPRINT("SrvGetConsoleAliasExes entered\n");
790 
791  if (!CsrValidateMessageBuffer(ApiMessage,
792  (PVOID*)&GetAliasesExesRequest->ExeNames,
793  GetAliasesExesRequest->Length,
794  sizeof(BYTE)))
795  {
797  }
798 
800  &Console, TRUE);
801  if (!NT_SUCCESS(Status)) return Status;
802 
803  if (IntGetConsoleAliasesExesLength(Console->Aliases, GetAliasesExesRequest->Unicode) > GetAliasesExesRequest->Length)
804  {
806  goto Quit;
807  }
808 
809  {
810  PALIAS_HEADER RootHeader = Console->Aliases;
811 
812  LPSTR TargetBufferA;
813  LPWSTR TargetBufferW;
814  UINT TargetBufferSize = GetAliasesExesRequest->Length;
815 
816  UINT Offset = 0;
817  UINT Length;
818 
819  if (GetAliasesExesRequest->Unicode)
820  {
821  TargetBufferW = GetAliasesExesRequest->ExeNames;
822  TargetBufferSize /= sizeof(WCHAR);
823  }
824  else
825  {
826  TargetBufferA = GetAliasesExesRequest->ExeNames;
827  }
828 
829  while (RootHeader)
830  {
831  Length = RootHeader->ExeName.Length / sizeof(WCHAR);
832  if (Offset + Length + 1 > TargetBufferSize)
833  {
835  break;
836  }
837 
838  if (GetAliasesExesRequest->Unicode)
839  {
840  RtlCopyMemory(&TargetBufferW[Offset], RootHeader->ExeName.Buffer, Length * sizeof(WCHAR));
841  Offset += Length;
842  TargetBufferW[Offset++] = L'\0';
843  }
844  else
845  {
847  RootHeader->ExeName.Buffer, Length * sizeof(WCHAR),
848  &TargetBufferA[Offset], Length);
849  Offset += Length;
850  TargetBufferA[Offset++] = '\0';
851  }
852 
853  RootHeader = RootHeader->Next;
854  }
855 
856  if (GetAliasesExesRequest->Unicode)
857  BytesWritten = Offset * sizeof(WCHAR);
858  else
860  }
861 
862 Quit:
863  GetAliasesExesRequest->Length = BytesWritten;
864 
866  return Status;
867 }
868 
869 /* API_NUMBER: ConsolepGetAliasExesLength */
870 CSR_API(SrvGetConsoleAliasExesLength)
871 {
873  PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesLengthRequest;
875 
876  DPRINT("SrvGetConsoleAliasExesLength entered ApiMessage %p\n", ApiMessage);
877 
879  &Console, TRUE);
880  if (!NT_SUCCESS(Status)) return Status;
881 
882  GetAliasesExesLengthRequest->Length =
884  GetAliasesExesLengthRequest->Unicode);
885 
887  return Status;
888 }
889 
890 /* EOF */
signed char * PCHAR
Definition: retypes.h:7
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
VOID IntDeleteAllAliases(PCONSRV_CONSOLE Console)
Definition: alias.c:428
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
CSR_API(SrvAddConsoleAlias)
Definition: alias.c:449
#define WideCharToMultiByte
Definition: compat.h:101
struct _Entry Entry
Definition: kefuncs.h:627
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:55
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
static PALIAS_ENTRY IntCreateAliasEntry(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PVOID Target, USHORT TargetLength, BOOLEAN Unicode)
Definition: alias.c:269
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
BOOLEAN Unicode2
Definition: conmsg.h:738
struct _ALIAS_ENTRY * PALIAS_ENTRY
uint16_t * PWCHAR
Definition: typedefs.h:55
#define PCONSRV_CONSOLE
Definition: conio.h:27
char * LPSTR
Definition: xmlstorage.h:182
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
int32_t INT
Definition: typedefs.h:57
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _ALIAS_HEADER ALIAS_HEADER
uint32_t ULONG_PTR
Definition: typedefs.h:64
PALIAS_ENTRY Data
Definition: alias.c:30
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: Header.h:8
BOOLEAN ConvertInputAnsiToUnicode(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PWCHAR *Target, PUSHORT TargetLength)
Definition: alias.c:37
ULONG AliasesBufferLength
Definition: conmsg.h:748
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
UNICODE_STRING Target
Definition: alias.c:23
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static VOID IntInsertAliasHeader(PALIAS_HEADER *RootHeader, PALIAS_HEADER NewHeader)
Definition: alias.c:200
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
USHORT SourceLength
Definition: conmsg.h:731
static VOID IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry)
Definition: alias.c:362
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
struct _ALIAS_HEADER * PALIAS_HEADER
static const WCHAR L[]
Definition: oid.c:1250
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
UNICODE_STRING ExeName
Definition: alias.c:29
unsigned char BYTE
Definition: mem.h:68
UNICODE_STRING Source
Definition: alias.c:22
Definition: alias.c:19
Status
Definition: gdiplustypes.h:24
struct _ALIAS_ENTRY * Next
Definition: alias.c:21
struct _ALIAS_HEADER * Next
Definition: alias.c:28
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define MultiByteToWideChar
Definition: compat.h:100
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOLEAN ConvertInputUnicodeToAnsi(PCONSRV_CONSOLE Console, PVOID Source, USHORT SourceLength, PCHAR Target, USHORT TargetLength)
Definition: alias.c:64
static PALIAS_ENTRY IntGetAliasEntry(PCONSRV_CONSOLE Console, PALIAS_HEADER Header, PVOID Source, USHORT SourceLength, BOOLEAN Unicode)
Definition: alias.c:220
static UINT IntGetAllConsoleAliasesLength(PALIAS_HEADER Header, BOOLEAN IsUnicode)
Definition: alias.c:403
unsigned int ULONG
Definition: retypes.h:1
USHORT TargetLength
Definition: conmsg.h:732
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
static PALIAS_HEADER IntCreateAliasHeader(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: alias.c:152
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static UINT IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader, BOOLEAN IsUnicode)
Definition: alias.c:381
return STATUS_SUCCESS
Definition: btrfs.c:2938
static VOID IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
Definition: alias.c:342
struct _ALIAS_ENTRY ALIAS_ENTRY
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82
static PALIAS_HEADER IntFindAliasHeader(PCONSRV_CONSOLE Console, PVOID ExeName, USHORT ExeLength, BOOLEAN UnicodeExe)
Definition: alias.c:105