[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp wsd/Storage.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Jun 7 04:02:48 UTC 2017


 wsd/DocumentBroker.cpp |    3 ++-
 wsd/LOOLWSD.cpp        |    8 +++++++-
 wsd/LOOLWSD.hpp        |    7 +++++++
 wsd/Storage.hpp        |    4 +++-
 4 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 194faa6d693416ece2e17da34871b109e5243a6f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Tue Jun 6 23:43:48 2017 -0400

    wsd: force readonly for view file types per discovery.xml
    
    File extensions marked as view (as opposed to edit)
    in discovery.xml are now forced to be read-only,
    regardless of what the client tries to request.
    
    Change-Id: I3eb00c33ff716800dc317f7377281c6d5f0909d7
    Reviewed-on: https://gerrit.libreoffice.org/38480
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a80b9395..d2c44b63 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -431,7 +431,8 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s
         username = wopifileinfo->_username;
         userExtraInfo = wopifileinfo->_userExtraInfo;
 
-        if (!wopifileinfo->_userCanWrite)
+        if (!wopifileinfo->_userCanWrite ||
+            LOOLWSD::IsViewFileExtension(wopiStorage->getFileExtension()))
         {
             LOG_DBG("Setting the session as readonly");
             session->setReadOnly();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 445027e2..07d371c8 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -550,6 +550,7 @@ std::string LOOLWSD::LOKitVersion;
 std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
 Util::RuntimeConstant<bool> LOOLWSD::SSLEnabled;
 Util::RuntimeConstant<bool> LOOLWSD::SSLTermination;
+std::set<std::string> LOOLWSD::ViewFileExtensions;
 
 static std::string UnitTestLibrary;
 
@@ -2176,7 +2177,12 @@ private:
 
         for (unsigned long it = 0; it < listNodes->length(); ++it)
         {
-            static_cast<Element*>(listNodes->item(it))->setAttribute(urlsrc, uriValue);
+            Element* elem = static_cast<Element*>(listNodes->item(it));
+            elem->setAttribute(urlsrc, uriValue);
+
+            // Set the View extensions cache as well.
+            if (elem->getAttribute("name") == "view")
+                LOOLWSD::ViewFileExtensions.insert(elem->getAttribute("ext"));
         }
 
         std::ostringstream ostrXML;
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 46538dc0..a608c6c1 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -55,6 +55,7 @@ public:
     static std::atomic<unsigned> NumConnections;
     static bool TileCachePersistent;
     static std::unique_ptr<TraceFileWriter> TraceDumper;
+    static std::set<std::string> ViewFileExtensions;
 
     /// Flag to shutdown the server.
     std::atomic<bool> ShutdownFlag;
@@ -81,6 +82,12 @@ public:
         return LOOLWSD::SSLTermination.get();
     }
 
+    /// Return truee iff extension is marked as view action in discovery.xml.
+    static bool IsViewFileExtension(const std::string& extension)
+    {
+        return ViewFileExtensions.find(extension) != ViewFileExtensions.end();
+    }
+
     /// Returns the value of the specified application configuration,
     /// of the default, if one doesn't exist.
     template<typename T>
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 60c73275..09002bde 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -95,7 +95,9 @@ public:
     void forceSave() { _forceSave = true; }
 
     /// Returns the basic information about the file.
-    FileInfo getFileInfo() { return _fileInfo; }
+    const FileInfo& getFileInfo() const { return _fileInfo; }
+
+    std::string getFileExtension() const { return Poco::Path(_fileInfo._filename).getExtension(); }
 
     /// Returns a local file path for the given URI.
     /// If necessary copies the file locally first.


More information about the Libreoffice-commits mailing list