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.

258 lines
6.1 KiB

  1. //
  2. // Include Files
  3. //
  4. #include "stdafx.h"
  5. #include "common.h"
  6. #include "iisdebug.h"
  7. #include "strfn.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12. BOOL
  13. IsUNCName(
  14. IN const CString & strDirPath
  15. )
  16. /*++
  17. Routine Description:
  18. Determine if the given string path is a UNC path.
  19. Arguments:
  20. const CString & strDirPath : Directory path string
  21. Return Value:
  22. TRUE if the path is a UNC path, FALSE otherwise.
  23. Notes:
  24. Any string of the form \\foo\bar\whatever is considered a UNC path,
  25. with the exception of \\.\device paths. No validation for the
  26. existance occurs, only for the correct format.
  27. --*/
  28. {
  29. if (strDirPath.GetLength() >= 5) // It must be at least as long as \\x\y,
  30. { //
  31. LPCTSTR lp = strDirPath; //
  32. if (*lp == _T('\\') // It must begin with \\,
  33. && *(lp + 1) == _T('\\') //
  34. && *(lp + 2) != _T('.') // This is a device.
  35. && _tcschr(lp + 3, _T('\\')) // And have at least one more \ after that
  36. )
  37. {
  38. //
  39. // Yes, it's a UNC path
  40. //
  41. return TRUE;
  42. }
  43. }
  44. //
  45. // No, it's not
  46. //
  47. return FALSE;
  48. }
  49. BOOL
  50. _EXPORT
  51. GetSpecialPathRealPath(
  52. IN const CString & strDirPath,
  53. OUT CString & strDestination
  54. )
  55. {
  56. BOOL bReturn = FALSE;
  57. LPCTSTR lpszSpecialStuff = _T("\\\\?\\");
  58. LPCTSTR lpszUNCDevice = _T("UNC\\");
  59. // Default it with something
  60. strDestination = strDirPath;
  61. // Check for the "special stuff"
  62. BOOL bIsSpecialPath = (0 == _tcsnccmp(strDirPath, lpszSpecialStuff, lstrlen(lpszSpecialStuff)));
  63. // check if we need to verifiy that it is indeeded a valid devicepath
  64. if (bIsSpecialPath)
  65. {
  66. CString strTempPath;
  67. // verify that this is indeed a valid special path
  68. // grab everyting after the part we're interested in...
  69. //
  70. // and check if that is a fully qualified path
  71. // or a fully qualified UNC path.
  72. //
  73. // 1) \\?\c:\temp\testind.dll
  74. // 2) \\?\UNC\MyUnc\testing.dll
  75. //
  76. // check for #1
  77. strTempPath = strDirPath.Right(strDirPath.GetLength() - lstrlen(lpszSpecialStuff));
  78. // check if it starts with UNC
  79. if (0 == _tcsnccmp(strTempPath, lpszUNCDevice, lstrlen(lpszUNCDevice)))
  80. {
  81. CString strTempPath2;
  82. strTempPath2 = strTempPath.Right(strTempPath.GetLength() - lstrlen(lpszUNCDevice));
  83. DebugTrace(_T("SpecialPath:%s,it's a UNC path!\r\n"),strTempPath2);
  84. // Append on the extra ("\\\\") when returning the munged path
  85. strDestination = _T("\\\\") + strTempPath2;
  86. bReturn = TRUE;
  87. }
  88. else
  89. {
  90. // check if the path if fully qualified and
  91. // if it's valid
  92. if (!PathIsRelative(strTempPath))
  93. {
  94. DebugTrace(_T("SpecialPath:%s,it's NOT a UNC path!\r\n"),strTempPath);
  95. strDestination = strTempPath;
  96. bReturn = TRUE;
  97. }
  98. }
  99. }
  100. return bReturn;
  101. }
  102. BOOL
  103. _EXPORT
  104. IsSpecialPath(
  105. IN const CString & strDirPath,
  106. IN BOOL bCheckIfValid
  107. )
  108. /*++
  109. Routine Description:
  110. Determine if the given path is of the form:
  111. 1) \\?\c:\temp\testind.dll
  112. 2) \\?\UNC\MyUnc\testing.dll
  113. Arguments:
  114. const CString & strDirPath : Directory path string
  115. BOOL bCheckIfValid : to say "return true only if it's a "special path" and if it's valid"
  116. Return Value:
  117. TRUE if the path given is a special path,
  118. FALSE if it is not.
  119. if bCheckIfValid = TRUE then:
  120. TRUE if the path given is a special path and it's valid
  121. FALSE if it is not.
  122. --*/
  123. {
  124. BOOL bIsSpecialPath = FALSE;
  125. LPCTSTR lpszSpecialStuff = _T("\\\\?\\");
  126. LPCTSTR lpszUNCDevice = _T("UNC\\");
  127. // Check for the "special stuff"
  128. bIsSpecialPath = (0 == _tcsnccmp(strDirPath, lpszSpecialStuff, lstrlen(lpszSpecialStuff)));
  129. // check if we need to verifiy that it is indeeded a valid devicepath
  130. if (bIsSpecialPath && bCheckIfValid)
  131. {
  132. bIsSpecialPath = FALSE;
  133. CString strTempPath;
  134. // verify that this is indeed a valid special path
  135. // grab everyting after the part we're interested in...
  136. //
  137. // and check if that is a fully qualified path
  138. // or a fully qualified UNC path.
  139. //
  140. // 1) \\?\c:\temp\testind.dll
  141. // 2) \\?\UNC\MyUnc\testing.dll
  142. //
  143. // check for #1
  144. strTempPath = strDirPath.Right(strDirPath.GetLength() - lstrlen(lpszSpecialStuff));
  145. // check if it starts with UNC
  146. if (0 == _tcsnccmp(strTempPath, lpszUNCDevice, lstrlen(lpszUNCDevice)))
  147. {
  148. bIsSpecialPath = TRUE;
  149. DebugTrace(_T("SpecialPath:%s,it's a UNC path!\r\n"),strTempPath);
  150. }
  151. else
  152. {
  153. // check if the path if fully qualified and
  154. // if it's valid
  155. if (!PathIsRelative(strTempPath))
  156. {
  157. bIsSpecialPath = TRUE;
  158. DebugTrace(_T("SpecialPath:%s,it's NOT a UNC path!\r\n"),strTempPath);
  159. }
  160. }
  161. }
  162. return bIsSpecialPath;
  163. }
  164. BOOL
  165. _EXPORT
  166. IsDevicePath(
  167. IN const CString & strDirPath
  168. )
  169. /*++
  170. Routine Description:
  171. Determine if the given path is of the form "\\.\foobar"
  172. Arguments:
  173. const CString & strDirPath : Directory path string
  174. Return Value:
  175. TRUE if the path given is a device path,
  176. FALSE if it is not.
  177. --*/
  178. {
  179. LPCTSTR lpszDevice = _T("\\\\.\\");
  180. return (0 == _tcsnccmp(strDirPath, lpszDevice, lstrlen(lpszDevice)));
  181. }
  182. BOOL PathIsValid(LPCTSTR path)
  183. {
  184. LPCTSTR p = path;
  185. BOOL rc = TRUE;
  186. if (p == NULL || *p == 0)
  187. return FALSE;
  188. while (*p != 0)
  189. {
  190. switch (*p)
  191. {
  192. case TEXT('|'):
  193. case TEXT('>'):
  194. case TEXT('<'):
  195. case TEXT('/'):
  196. case TEXT('?'):
  197. case TEXT('*'):
  198. // case TEXT(';'):
  199. // case TEXT(','):
  200. case TEXT('"'):
  201. rc = FALSE;
  202. break;
  203. default:
  204. if (*p < TEXT(' '))
  205. {
  206. rc = FALSE;
  207. }
  208. break;
  209. }
  210. if (!rc)
  211. {
  212. break;
  213. }
  214. p++;
  215. }
  216. return rc;
  217. }