[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/LOOLWSD.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Jan 6 21:58:26 PST 2016


 loolwsd/ChildProcessSession.cpp |   35 ++++++-----------------------------
 loolwsd/LOOLSession.cpp         |    5 +++++
 loolwsd/LOOLSession.hpp         |    3 +++
 loolwsd/LOOLWSD.hpp             |    3 ++-
 4 files changed, 16 insertions(+), 30 deletions(-)

New commits:
commit 06c20923c5f981a26e0921a9645666cbd9b66f39
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Jan 7 00:33:54 2016 -0500

    loolwsd: Kit is given the jailed path
    
    Change-Id: I5b475798c7f654aaa3e0032332d5aa97a103a4c8
    Reviewed-on: https://gerrit.libreoffice.org/21185
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 8434b61..a24bb96 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -242,37 +242,14 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
 
     std::string timestamp;
     parseDocOptions(tokens, part, timestamp);
-    Log::info("docURL: [" + _docURL + "].");
-    URI aUri;
-    try
-    {
-        aUri = URI(_docURL);
-    }
-    catch (const Poco::SyntaxException&)
-    {
-        sendTextFrame("error: cmd=load kind=uriinvalid");
-        return false;
-    }
 
-    if (aUri.empty())
-    {
-        sendTextFrame("error: cmd=load kind=uriempty");
-        return false;
-    }
+    assert(!_docURL.empty());
+    assert(!_jailedFilePath.empty());
 
     if (_loKitDocument == nullptr)
-        Log::info("Loading new document from URI: [" + aUri.toString() + "].");
+        Log::info("Loading new document from URI: [" + _jailedFilePath + "].");
     else
-        Log::info("Loading view to document from URI: [" + aUri.toString() + "].");
-
-    // The URL in the request is the original one, not visible in the chroot jail.
-    // The child process uses the fixed name JailedDocumentRoot.
-    if (aUri.isRelative() || aUri.getScheme() == "file")
-    {
-        aUri = URI( URI("file://"), Path(JailedDocumentRoot + std::to_string(Process::id()),
-                    Path(aUri.getPath()).getFileName()).toString() );
-        Log::info("Local URI: [" + aUri.toString() + "].");
-    }
+        Log::info("Loading view to document from URI: [" + _jailedFilePath + "].");
 
     if (_loKitDocument != nullptr)
     {
@@ -283,9 +260,9 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
         if ( LIBREOFFICEKIT_HAS(_loKit, registerCallback))
             _loKit->pClass->registerCallback(_loKit, myCallback, this);
 
-        if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, aUri.toString().c_str())) == nullptr)
+        if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, _jailedFilePath.c_str())) == nullptr)
         {
-            Log::error("Failed to load: " + aUri.toString() + ", error: " + _loKit->pClass->getError(_loKit));
+            Log::error("Failed to load: " + _jailedFilePath + ", error: " + _loKit->pClass->getError(_loKit));
             sendTextFrame("error: cmd=load kind=failed");
             return false;
         }
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 038dcfe..a730937 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -151,6 +151,11 @@ void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std:
             _docURL = tokens[i].substr(strlen("url="));
             ++offset;
         }
+        else if (tokens[i].find("jail=") == 0)
+        {
+            _jailedFilePath = tokens[i].substr(strlen("jail="));
+            ++offset;
+        }
         else if (tokens[i].find("timestamp=") == 0)
         {
             timestamp = tokens[i].substr(strlen("timestamp="));
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 2e3f213..a5f3678 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -92,6 +92,9 @@ protected:
     // The actual URL, also in the child, even if the child never accesses that.
     std::string _docURL;
 
+    // The Jailed document path.
+    std::string _jailedFilePath;
+
     /// Document options: a JSON string, containing options (rendering, also possibly load in the future).
     std::string _docOptions;
 
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 44ad381..57397ed 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -75,7 +75,8 @@ public:
             // chroot/jailId/user/doc/childId/file.ext
             const auto jailedFilePath = Poco::Path(docPath, filename).toString();
 
-            uriJailed = Poco::URI(Poco::URI("file://"), jailedFilePath);
+            const auto localPath = Poco::Path(JailedDocumentRoot, childId);
+            uriJailed = Poco::URI(Poco::URI("file://"), Poco::Path(localPath, filename).toString());
 
             Log::info("Public URI [" + uriPublic.toString() +
                       "] jailed to [" + uriJailed.toString() + "].");


More information about the Libreoffice-commits mailing list