diff options
author | Rash419 <rashesh.padia@collabora.com> | 2022-04-07 12:21:46 +0530 |
---|---|---|
committer | Rashesh Padia <rasheshpadia419@gmail.com> | 2022-05-18 22:49:55 +0530 |
commit | b4e6a3fbbf3f7261117c2ecb83def8ae17d21713 (patch) | |
tree | b0e2fb96f84eeec5c363ee50b218074a9dea7ba1 | |
parent | Translated using Weblate (Nepali) (diff) | |
download | online-b4e6a3fbbf3f7261117c2ecb83def8ae17d21713.tar.gz online-b4e6a3fbbf3f7261117c2ecb83def8ae17d21713.zip |
wsd: cleanup setting firsthost code
we added AllHosts to give admin the err log that host is not in alias_groups but now as we removed the host list entries from configuration we don't need that log
Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I8b5e9e6b7df7df59befb496c12966c7ddc60c707
-rw-r--r-- | common/Util.hpp | 5 | ||||
-rw-r--r-- | wsd/COOLWSD.cpp | 2 | ||||
-rw-r--r-- | wsd/HostUtil.cpp | 52 | ||||
-rw-r--r-- | wsd/HostUtil.hpp | 5 | ||||
-rw-r--r-- | wsd/Storage.cpp | 4 |
5 files changed, 24 insertions, 44 deletions
diff --git a/common/Util.hpp b/common/Util.hpp index d470e798fa..7556b25392 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -1062,6 +1062,11 @@ int main(int argc, char**argv) Util::matchRegex(_denied, subject)); } + bool empty() const + { + return _allowed.empty() && _denied.empty(); + } + private: const bool _allowByDefault; std::set<std::string> _allowed; diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index a45d33412f..0dc61f51e2 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -1817,8 +1817,6 @@ void COOLWSD::innerInitialize(Application& self) { "ssl.termination", "true" }, { "storage.filesystem[@allow]", "false" }, // "storage.ssl.enable" - deliberately not set; for back-compat - { "storage.wopi.host[0]", "localhost" }, - { "storage.wopi.host[0][@allow]", "true" }, { "storage.wopi.max_file_size", "0" }, { "storage.wopi[@allow]", "true" }, { "storage.wopi.locking.refresh", "900" }, diff --git a/wsd/HostUtil.cpp b/wsd/HostUtil.cpp index 0bbdc53d94..4a716c9042 100644 --- a/wsd/HostUtil.cpp +++ b/wsd/HostUtil.cpp @@ -11,7 +11,6 @@ Util::RegexListMatcher HostUtil::WopiHosts; std::map<std::string, std::string> HostUtil::AliasHosts; -std::set<std::string> HostUtil::AllHosts; std::string HostUtil::FirstHost; bool HostUtil::WopiEnabled; @@ -57,32 +56,6 @@ bool HostUtil::allowedWopiHost(const std::string& host) return WopiEnabled && WopiHosts.match(host); } -bool HostUtil::allowedAlias(const Poco::URI& uri) -{ - if (Util::iequal(config::getString("storage.wopi.alias_groups[@mode]", "first"), "compat")) - { - return true; - } - - if (AllHosts.empty()) - { - if (FirstHost != uri.getAuthority()) - { - LOG_ERR("Only allowed host is: " - << FirstHost - << ", To use multiple host/aliases check alias_groups tag in configuration"); - return false; - } - } - else if (!Util::matchRegex(AllHosts, uri.getAuthority())) - { - LOG_ERR("Host: " << uri.getAuthority() - << " is denied, It is not defined in alias_groups configuration"); - return false; - } - return true; -} - void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) { //set alias_groups mode to compat @@ -97,13 +70,11 @@ void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) { LOG_ERR("Admins didnot set the alias_groups mode to 'groups'"); AliasHosts.clear(); - AllHosts.clear(); return; } } AliasHosts.clear(); - AllHosts.clear(); for (size_t i = 0;; i++) { @@ -124,8 +95,6 @@ void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) { const Poco::URI realUri(uri); HostUtil::addWopiHost(realUri.getHost(), allow); - - AllHosts.insert(realUri.getAuthority()); } catch (const Poco::Exception& exc) { @@ -156,7 +125,6 @@ void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) const Poco::URI aUri(aliasUri.getScheme() + "://" + x + ':' + std::to_string(aliasUri.getPort())); AliasHosts.insert({ aUri.getAuthority(), realUri.getAuthority() }); - AllHosts.insert(aUri.getAuthority()); HostUtil::addWopiHost(aUri.getHost(), allow); } } @@ -205,10 +173,24 @@ const Poco::URI HostUtil::getNewLockedUri(Poco::URI& uri) void HostUtil::setFirstHost(const Poco::URI& uri) { - if (AllHosts.empty() && FirstHost.empty()) + if (Util::iequal(config::getString("storage.wopi.alias_groups[@mode]", "first"), "compat")) + { + return; + } + + if (WopiHosts.empty()) + { + if (FirstHost.empty()) + { + FirstHost = uri.getAuthority(); + addWopiHost(uri.getHost(), true); + } + } + else if(!FirstHost.empty() && FirstHost != uri.getAuthority()) { - FirstHost = uri.getAuthority(); - addWopiHost(uri.getHost(), true); + LOG_ERR("Only allowed host is: " + << FirstHost + << ", To use multiple host/aliases check alias_groups tag in configuration"); } } diff --git a/wsd/HostUtil.hpp b/wsd/HostUtil.hpp index 3f92a288af..377d08364e 100644 --- a/wsd/HostUtil.hpp +++ b/wsd/HostUtil.hpp @@ -21,8 +21,6 @@ private: static std::map<std::string, std::string> AliasHosts; /// When group configuration is not defined only the firstHost gets access static std::string FirstHost; - /// This contains all real and aliases host from group configuration - static std::set<std::string> AllHosts; static bool WopiEnabled; @@ -42,8 +40,6 @@ public: /// add host to WopiHosts static void addWopiHost(std::string host, bool allow); - static bool allowedAlias(const Poco::URI& uri); - static bool allowedWopiHost(const std::string& host); static bool isWopiEnabled() { return WopiEnabled; } @@ -51,7 +47,6 @@ public: /// replace the authority of aliashost to realhost if it matches static const Poco::URI getNewLockedUri(Poco::URI& uri); - /// set FirstHost static void setFirstHost(const Poco::URI& uri); }; diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index e9e05abc2b..f9547d98dd 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -236,7 +236,7 @@ std::unique_ptr<StorageBase> StorageBase::create(const Poco::URI& uri, const std const auto& targetHost = uri.getHost(); bool allowed(false); HostUtil::setFirstHost(uri); - if ((HostUtil::allowedAlias(uri) && HostUtil::allowedWopiHost(targetHost)) || + if (HostUtil::allowedWopiHost(targetHost) || isLocalhost(targetHost)) { allowed = true; @@ -247,7 +247,7 @@ std::unique_ptr<StorageBase> StorageBase::create(const Poco::URI& uri, const std const auto hostAddresses(Poco::Net::DNS::resolve(targetHost)); for (auto &address : hostAddresses.addresses()) { - if (HostUtil::allowedAlias(uri) && HostUtil::allowedWopiHost(address.toString())) + if (HostUtil::allowedWopiHost(address.toString())) { allowed = true; break; |