diff options
author | Anton Fedchin <afedchin@users.noreply.github.com> | 2018-04-02 08:47:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 08:47:56 +0300 |
commit | 57b491fd373b35dc21e4fcf0fcd3126a006c0d0d (patch) | |
tree | 0fd5aa63acc53770b80ae07cdc4d9c03ad14bf46 | |
parent | 3848940f289d1c40c211480453a0cd22ec825763 (diff) | |
parent | de7d6c8c018a9763a1d5339e605e2e11b139ada3 (diff) |
Merge pull request #13713 from afedchin/fix-url-auth
[filesystem] don't change auths for an url if the auth is set explicitly
-rw-r--r-- | xbmc/filesystem/Directory.cpp | 49 | ||||
-rw-r--r-- | xbmc/filesystem/File.cpp | 24 |
2 files changed, 50 insertions, 23 deletions
diff --git a/xbmc/filesystem/Directory.cpp b/xbmc/filesystem/Directory.cpp index 10c251c8fe..a8f57291a9 100644 --- a/xbmc/filesystem/Directory.cpp +++ b/xbmc/filesystem/Directory.cpp @@ -165,12 +165,14 @@ bool CDirectory::GetDirectory(const CURL& url, CFileItemList &items, const CHint pDirectory->SetFlags(hints.flags); bool result = false, cancel = false; + CURL authUrl = CURL(realURL); + while (!result && !cancel) { const std::string pathToUrl(url.Get()); - CURL authUrl = CURL(realURL); - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + // don't change auth if it's set explicitly + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); if (g_application.IsCurrentThread() && allowThreads && !URIUtils::IsSpecial(pathToUrl)) @@ -195,22 +197,47 @@ bool CDirectory::GetDirectory(const CURL& url, CFileItemList &items, const CHint if (!result) { - if (!cancel && g_application.IsCurrentThread() && pDirectory->ProcessRequirements()) - continue; + if (!cancel) + { + if (g_application.IsCurrentThread() && pDirectory->ProcessRequirements()) + { + authUrl.SetUserName(""); + authUrl.SetPassword(""); + continue; + } + } CLog::Log(LOGERROR, "%s - Error getting %s", __FUNCTION__, url.GetRedacted().c_str()); return false; } } - // hide credentials + // hide credentials if necessary if (CPasswordManager::GetInstance().IsURLSupported(realURL)) { for (int i = 0; i < items.Size(); ++i) { CFileItemPtr item = items[i]; CURL itemUrl = item->GetURL(); - itemUrl.SetUserName(""); - itemUrl.SetPassword(""); + // for explicitly credetials + if (!realURL.GetUserName().empty()) + { + // credentials was changed i.e. were stored in the password + // manager, in this case we can hide them from an item URL, + // otherwise we have to keep cretendials in an item URL + if ( realURL.GetUserName() != authUrl.GetUserName() + || realURL.GetPassWord() != authUrl.GetPassWord()) + { + // hide credentials + itemUrl.SetUserName(""); + itemUrl.SetPassword(""); + } + } + else + { + // hide credentials in any other cases + itemUrl.SetUserName(""); + itemUrl.SetPassword(""); + } item->SetPath(itemUrl.Get()); } } @@ -288,7 +315,7 @@ bool CDirectory::Create(const CURL& url) { CURL realURL = URIUtils::SubstitutePath(url); - if (CPasswordManager::GetInstance().IsURLSupported(realURL)) + if (CPasswordManager::GetInstance().IsURLSupported(realURL) && realURL.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(realURL); std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL)); @@ -327,7 +354,7 @@ bool CDirectory::Exists(const CURL& url, bool bUseCache /* = true */) return false; } - if (CPasswordManager::GetInstance().IsURLSupported(realURL)) + if (CPasswordManager::GetInstance().IsURLSupported(realURL) && realURL.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(realURL); std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL)); @@ -360,7 +387,7 @@ bool CDirectory::Remove(const CURL& url) { CURL realURL = URIUtils::SubstitutePath(url); CURL authUrl = realURL; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL)); @@ -386,7 +413,7 @@ bool CDirectory::RemoveRecursive(const CURL& url) { CURL realURL = URIUtils::SubstitutePath(url); CURL authUrl = realURL; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); std::unique_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realURL)); diff --git a/xbmc/filesystem/File.cpp b/xbmc/filesystem/File.cpp index 7a2bc3143c..3b02c6e9b0 100644 --- a/xbmc/filesystem/File.cpp +++ b/xbmc/filesystem/File.cpp @@ -316,7 +316,7 @@ bool CFile::Open(const CURL& file, const unsigned int flags) return false; CURL authUrl(url); - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); try @@ -342,7 +342,7 @@ bool CFile::Open(const CURL& file, const unsigned int flags) if (pNewUrl.get()) { CURL newAuthUrl(*pNewUrl); - if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl) && newAuthUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(newAuthUrl); if (!m_pFile->Open(newAuthUrl)) @@ -403,7 +403,7 @@ bool CFile::OpenForWrite(const CURL& file, bool bOverWrite) { CURL url = URIUtils::SubstitutePath(file); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); m_pFile = CFileFactory::CreateLoader(url); @@ -435,7 +435,7 @@ bool CFile::Exists(const CURL& file, bool bUseCache /* = true */) { CURL url(URIUtils::SubstitutePath(file)); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); try @@ -480,7 +480,7 @@ bool CFile::Exists(const CURL& file, bool bUseCache /* = true */) return false; } CURL newAuthUrl = *pNewUrl; - if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl) && newAuthUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(newAuthUrl); return pImp->Exists(newAuthUrl); @@ -528,7 +528,7 @@ int CFile::Stat(const CURL& file, struct __stat64* buffer) CURL url(URIUtils::SubstitutePath(file)); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); try @@ -555,7 +555,7 @@ int CFile::Stat(const CURL& file, struct __stat64* buffer) if (pImp.get()) { CURL newAuthUrl = *pNewUrl; - if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(newAuthUrl) && newAuthUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(newAuthUrl); if (!pImp->Stat(newAuthUrl, buffer)) @@ -878,7 +878,7 @@ bool CFile::Delete(const CURL& file) { CURL url(URIUtils::SubstitutePath(file)); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); @@ -916,10 +916,10 @@ bool CFile::Rename(const CURL& file, const CURL& newFile) CURL urlnew(URIUtils::SubstitutePath(newFile)); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); CURL authUrlNew = urlnew; - if (CPasswordManager::GetInstance().IsURLSupported(authUrlNew)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrlNew) && authUrlNew.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrlNew); std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); @@ -954,7 +954,7 @@ bool CFile::SetHidden(const CURL& file, bool hidden) { CURL url(URIUtils::SubstitutePath(file)); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); std::unique_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); @@ -1236,7 +1236,7 @@ bool CFileStream::Open(const CURL& filename) m_file = CFileFactory::CreateLoader(url); CURL authUrl = url; - if (CPasswordManager::GetInstance().IsURLSupported(authUrl)) + if (CPasswordManager::GetInstance().IsURLSupported(authUrl) && authUrl.GetUserName().empty()) CPasswordManager::GetInstance().AuthenticateURL(authUrl); if(m_file && m_file->Open(authUrl)) |