Source code of Windows XP (NT5)
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.

164 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1990-91 Microsoft Corporation
  3. Module Name:
  4. pathcan.c
  5. Abstract:
  6. Net path canonicalization routines:
  7. NetpwCanonicalize
  8. Notes:
  9. The Nt versions of these routines are kept in the NetApi Dll and are
  10. (usually) called locally. If the caller specifies a remote computer
  11. name then we try to RPC the request. If that fails the wrapper routine
  12. which attempts RPC will call down-level.
  13. OLDPATHS support has been removed from this module in keeping with the
  14. N-1 (this product and its immediate predecessor) philosophy of NT.
  15. Therefore, we always expect a down-level server to be able to handle a
  16. remoted canonicalization request. We don't cover for Lan Manager 1.x
  17. Types of paths we expect to receive in this routine:
  18. - relative path
  19. e.g. foo\bar
  20. - absolute path (path specified from root, but no drive or computer name)
  21. e.g. \foo\bar
  22. - UNC path
  23. e.g. \\computer\share\foo
  24. - disk path (full path specified with disk drive)
  25. e.g. d:\foo\bar
  26. Author:
  27. Richard L Firth (rfirth) 06-Jan-1992
  28. from an original script by danny glasser (dannygl)
  29. Revision History:
  30. --*/
  31. #include "nticanon.h"
  32. //
  33. // routines
  34. //
  35. NET_API_STATUS
  36. NetpwPathCanonicalize(
  37. IN LPTSTR PathName,
  38. IN LPTSTR Outbuf,
  39. IN DWORD OutbufLen,
  40. IN LPTSTR Prefix OPTIONAL,
  41. IN OUT LPDWORD PathType,
  42. IN DWORD Flags
  43. )
  44. /*++
  45. Routine Description:
  46. NetpPathCanonicalize produces the canonical version of the specified
  47. pathname.
  48. The canonical form of PRN is LPT1
  49. The canonical form of AUX is COM1
  50. If the value of <PathType> on entry has not been determined
  51. by a prior (successful) call to NetpPathType, it must be set to 0.
  52. Even if it is set to the correct non-zero value on entry, it may be
  53. changed by this function, since the canonicalized version of a name
  54. may be of a different type than the original version (e.g. if the
  55. prefix is used).
  56. Arguments:
  57. PathName - The pathname to canonicalize
  58. Outbuf - The place to store the canonicalized version of the pathname
  59. OutbufLen - The size, in bytes, of <Outbuf>
  60. Prefix - Optional prefix to use when canonicalizing a relative pathname
  61. PathType - The place to store the type. If the type does not contain
  62. zero on function entry, the function assumes that this type
  63. has been determined already by a call to NetpPathType
  64. Flags - Flags to determine operation. MBZ
  65. Return Value:
  66. NET_API_STATUS
  67. Success - NERR_Success
  68. Failure - ERROR_INVALID_PARAMETER
  69. ERROR_INVALID_NAME
  70. NERR_BufTooSmall
  71. --*/
  72. {
  73. DWORD rc = 0;
  74. BOOL noPrefix = ((Prefix == NULL) || (*Prefix == TCHAR_EOS));
  75. DWORD typeOfPrefix;
  76. DWORD typeOfPath;
  77. #ifdef CANONDBG
  78. NetpKdPrint(("NetpwPathCanonicalize\n"));
  79. #endif
  80. typeOfPath = *PathType;
  81. if (Flags & INPCA_FLAGS_RESERVED) {
  82. return ERROR_INVALID_PARAMETER;
  83. }
  84. //
  85. // Determine type of pathname, if it hasn't been determined yet
  86. // Abort on error
  87. //
  88. if (!typeOfPath) {
  89. if (rc = NetpwPathType(PathName, &typeOfPath, 0)) {
  90. return rc;
  91. }
  92. }
  93. //
  94. // Validate prefix, if there is one
  95. // Abort on error
  96. //
  97. if (!noPrefix) {
  98. if (rc = NetpwPathType(Prefix, &typeOfPrefix, 0)) {
  99. return rc;
  100. }
  101. }
  102. //
  103. // Set the output buffer to the null string (or return with an error, if
  104. // it's zero length). Note that we've already set the caller's
  105. // <PathType> parameter.
  106. //
  107. if (OutbufLen == 0) {
  108. return NERR_BufTooSmall;
  109. } else {
  110. *Outbuf = TCHAR_EOS;
  111. }
  112. rc = CanonicalizePathName(Prefix, PathName, Outbuf, OutbufLen, NULL);
  113. if (rc == NERR_Success) {
  114. rc = NetpwPathType(Outbuf, PathType, 0);
  115. }
  116. return rc;
  117. }