Bug 1005748: Add basic UNC support to NtPathToDosPath; r=ehsan

--HG--
extra : rebase_source : 78c56f036a705c624721c705c51b1c4a0aefcdc0
This commit is contained in:
Aaron Klotz 2014-05-12 13:32:28 -06:00
parent ab1ec3649a
commit cdfc458acb
2 changed files with 24 additions and 11 deletions

View File

@ -80,15 +80,22 @@ NtPathToDosPath(const nsAString& aNtPath, nsAString& aDosPath)
// Advance to the next NUL character in logicalDrives
while (*cur++);
} while (cur != end);
// Code for handling UNC paths would go here, if eventually required.
#if defined(DEBUG)
// Try to handle UNC paths. NB: This must happen after we've checked drive
// mappings in case a UNC path is mapped to a drive!
NS_NAMED_LITERAL_STRING(uncPrefix, "\\\\");
NS_NAMED_LITERAL_STRING(deviceMupPrefix, "\\Device\\Mup\\");
uint32_t deviceMupPrefixLen = deviceMupPrefix.Length();
if (ntPathLen >= deviceMupPrefixLen &&
Substring(aNtPath, 0, deviceMupPrefixLen).Equals(deviceMupPrefix)) {
NS_WARNING("UNC paths not yet supported in NtPathToDosPath");
if (StringBeginsWith(aNtPath, deviceMupPrefix)) {
aDosPath = uncPrefix;
aDosPath += Substring(aNtPath, deviceMupPrefix.Length());
return true;
}
NS_NAMED_LITERAL_STRING(deviceLanmanRedirectorPrefix,
"\\Device\\LanmanRedirector\\");
if (StringBeginsWith(aNtPath, deviceLanmanRedirectorPrefix)) {
aDosPath = uncPrefix;
aDosPath += Substring(aNtPath, deviceLanmanRedirectorPrefix.Length());
return true;
}
#endif // defined(DEBUG)
return false;
}

View File

@ -177,10 +177,16 @@ int main(int argc, char* argv[])
fail("Socket");
result = 1;
}
// currently UNC paths that are not mapped to drive letters are unsupported,
// so this should fail
if (TestNtPathToDosPath(L"\\Device\\Mup\\127.0.0.1\\C$", nullptr)) {
fail("Unmapped UNC path");
// UNC path (using MUP)
if (!TestNtPathToDosPath(L"\\Device\\Mup\\127.0.0.1\\C$",
L"\\\\127.0.0.1\\C$")) {
fail("Unmapped UNC path (\\Device\\Mup\\)");
result = 1;
}
// UNC path (using LanmanRedirector)
if (!TestNtPathToDosPath(L"\\Device\\LanmanRedirector\\127.0.0.1\\C$",
L"\\\\127.0.0.1\\C$")) {
fail("Unmapped UNC path (\\Device\\LanmanRedirector\\)");
result = 1;
}
DriveMapping drvMapping(NS_LITERAL_STRING("\\\\127.0.0.1\\C$"));