Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. object.c
  5. Abstract:
  6. Resource DLL for disks.
  7. Author:
  8. Rod Gamache (rodga) 18-Dec-1995
  9. Revision History:
  10. --*/
  11. #include "ntos.h"
  12. #include "zwapi.h"
  13. #include "windef.h"
  14. #include "stdio.h"
  15. #include "stdlib.h"
  16. #include "clusdskp.h"
  17. #include <strsafe.h> // Should be included last.
  18. extern POBJECT_TYPE IoDeviceObjectType;
  19. #ifdef ALLOC_PRAGMA
  20. //#pragma alloc_text(INIT, GetSymbolicLink)
  21. #endif // ALLOC_PRAGMA
  22. VOID
  23. GetSymbolicLink(
  24. IN PWCHAR RootName,
  25. IN OUT PWCHAR ObjectName // Assume this points at a MAX_PATH len buffer
  26. )
  27. {
  28. PWCHAR destEnd;
  29. NTSTATUS Status;
  30. OBJECT_ATTRIBUTES ObjectAttributes;
  31. HANDLE LinkHandle;
  32. WCHAR Buffer[MAX_PATH];
  33. UNICODE_STRING UnicodeString;
  34. size_t charRemaining;
  35. if ( FAILED( StringCchCopyExW( Buffer,
  36. RTL_NUMBER_OF(Buffer) - 1,
  37. RootName,
  38. &destEnd,
  39. &charRemaining,
  40. 0 ) ) ) {
  41. return;
  42. }
  43. if ( !destEnd || !charRemaining ||
  44. FAILED( StringCchCatW( destEnd,
  45. charRemaining,
  46. ObjectName ) ) ) {
  47. return;
  48. }
  49. //
  50. // Make the output buffer empty in case we fail.
  51. //
  52. *ObjectName = '\0';
  53. RtlInitUnicodeString(&UnicodeString, Buffer);
  54. InitializeObjectAttributes(&ObjectAttributes,
  55. &UnicodeString,
  56. OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
  57. NULL,
  58. NULL
  59. );
  60. // Open the given symbolic link object
  61. Status = ZwOpenSymbolicLinkObject(&LinkHandle,
  62. GENERIC_READ,
  63. &ObjectAttributes);
  64. if (!NT_SUCCESS(Status)) {
  65. ClusDiskPrint((1,
  66. "[ClusDisk] GetSymbolicLink: ZwOpenSymbolicLink "
  67. "failed, status = %08X., Name = [%ws]\n",
  68. Status, UnicodeString.Buffer));
  69. return;
  70. }
  71. // Go get the target of the symbolic link
  72. UnicodeString.Length = 0;
  73. UnicodeString.Buffer = ObjectName;
  74. UnicodeString.MaximumLength = (USHORT)(MAX_PATH);
  75. Status = ZwQuerySymbolicLinkObject(LinkHandle, &UnicodeString, NULL);
  76. ZwClose(LinkHandle);
  77. if (!NT_SUCCESS(Status)) {
  78. ClusDiskPrint((1,
  79. "[ClusDisk] GetSymbolicLink: ZwQuerySymbolicLink failed, status = %08X.\n",
  80. Status));
  81. return;
  82. }
  83. // Add NULL terminator
  84. UnicodeString.Buffer[UnicodeString.Length/sizeof(WCHAR)] = '\0';
  85. return;
  86. } // GetSymbolicLink