diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2021-02-23 17:19:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-23 17:19:53 +0100 |
| commit | 8365f26d8352df4042b11f8b284ab7c216c1e31d (patch) | |
| tree | 66a0bf6861ab23b55275202c267c5c94995760f3 /src/envfs.cpp | |
| parent | 0ca21d9a5e120b86ef164df552ab68bc90398dd9 (diff) | |
| parent | d22d77d921e9915b3209e1a447d628c0f2d01baa (diff) | |
Merge pull request #1424 from isanae/dl-share
Network shares for envfs
Diffstat (limited to 'src/envfs.cpp')
| -rw-r--r-- | src/envfs.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/envfs.cpp b/src/envfs.cpp index 9317eb70..dfea6598 100644 --- a/src/envfs.cpp +++ b/src/envfs.cpp @@ -232,8 +232,8 @@ void forEachEntryImpl( if (status < 0) { log::error( - "NtOpenFile() failed for '{}', {}", - toString(poa), formatSystemMessage(status)); + "failed to open directory '{}': {}", + toString(poa), formatNtMessage(status)); return; } @@ -264,8 +264,9 @@ void forEachEntryImpl( break; } else if (status < 0) { log::error( - "NtQueryDirectoryFile() failed for '{}', {}", - toString(poa), formatSystemMessage(status)); + "failed to read directory '{}': {}", + toString(poa), formatNtMessage(status)); + break; } @@ -321,6 +322,23 @@ void forEachEntryImpl( } } +std::wstring makeNtPath(const std::wstring& path) +{ + constexpr const wchar_t* nt_prefix = L"\\??\\"; + constexpr const wchar_t* nt_unc_prefix = L"\\??\\UNC\\"; + constexpr const wchar_t* share_prefix = L"\\\\"; + + if (path.starts_with(nt_prefix)) { + // already an nt path + return path; + } else if (path.starts_with(share_prefix)) { + // network shared need \??\UNC\ as a prefix + return nt_unc_prefix + path.substr(2); + } else { + // prepend the \??\ prefix + return nt_prefix + path; + } +} void DirectoryWalker::forEachEntry( const std::wstring& path, void* cx, @@ -335,7 +353,7 @@ void DirectoryWalker::forEachEntry( NtClose = (NtClose_type)::GetProcAddress(m.get(), "NtClose"); } - const std::wstring ntpath = std::wstring(L"\\??\\") + path; + const std::wstring ntpath = makeNtPath(path); UNICODE_STRING ObjectName = {}; ObjectName.Buffer = const_cast<wchar_t*>(ntpath.c_str()); |
