sal/osl/unx/file_url.cxx |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

New commits:
commit f90e26b6313a2a7e492337f5957e49f5a512e5e7
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Wed Feb 6 10:20:16 2019 +0100
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Wed Feb 6 11:18:27 2019 +0100

    tdf#107461: For Unix-like OS, support file://<hostname>/... URLs
    
    ...where <hostname> matches whatever osl_getLocalHostname reports.  (And, 
for
    simplicity, don't support variations where e.g. one of the two FQDNs has an
    optional final dot while the other has not.)
    
    (It is not clear to me whether a similar change should also be done for the
    Windows-specific code in sal/osl/w32/file_url.cxx.  On Windows, file URLs 
with a
    host component are generally interpreted as UNC pathnames, and in some local
    test on a Windows 8 machine whose hostname is reported as "win8", passing a 
URL
    like <file://win8/Users/me/Documents/...> (i.e., without a C: drive letter) 
to
    LO already worked to access files on the default drive C: at least.)
    
    Change-Id: I7a69b6d4ca76a71223def7b90d7c3b8b731ee86d
    Reviewed-on: https://gerrit.libreoffice.org/67437
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx
index 24fa04c7bfa6..0661975926fe 100644
--- a/sal/osl/unx/file_url.cxx
+++ b/sal/osl/unx/file_url.cxx
@@ -30,6 +30,7 @@
 
 #include <osl/file.hxx>
 #include <osl/security.hxx>
+#include <osl/socket.h>
 #include <osl/diagnose.h>
 #include <osl/thread.h>
 #include <osl/process.h>
@@ -136,7 +137,9 @@ oslFileError getSystemPathFromFileUrl(
     // Handle query or fragment:
     if (url.indexOf('?', i) != -1 || url.indexOf('#', i) != -1)
         return osl_File_E_INVAL;
-    // Handle authority:
+    // Handle authority, supporting a host of "localhost", "127.0.0.1", or the 
exact value (e.g.,
+    // not supporting an additional final dot, for simplicity) reported by 
osl_getLocalHostname
+    // (and, in each case, ignoring case of ASCII letters):
     if (url.getLength() - i >= 2 && url[i] == '/' && url[i + 1] == '/')
     {
         i += 2;
@@ -153,7 +156,14 @@ oslFileError getSystemPathFromFileUrl(
                     RTL_CONSTASCII_STRINGPARAM("127.0.0.1"))
                 != 0))
         {
-            return osl_File_E_INVAL;
+            OUString hostname;
+            if (osl_getLocalHostname(&hostname.pData) != osl_Socket_Ok
+                || (rtl_ustr_compareIgnoreAsciiCase_WithLength(
+                        url.pData->buffer + i, j - i, hostname.getStr(), 
hostname.getLength())
+                    != 0))
+            {
+                return osl_File_E_INVAL;
+            }
         }
         i = j;
     }
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to