summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2020-12-10 14:24:05 +0100
committerSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-04-19 09:22:57 +0200
commiteac00017e34e77343b9ac3638bed9c75115a23fe (patch)
treecdbfb83b09325602e5ef1099051390413ad0a93c /sal
parent9f06c54ca1819b6d4df48f33772cfa5ceb90dccd (diff)
[API CHANGE] Do not call getaddrinfo if we just want the hostname
Similiar to afc41a467fdfabb2cd0879be3e4f1879a1d1dc91 , don't call getaddrinfo in getLocalHostname which calls DNS. This causes a lag when creating the lockfile on opening a document if the network is flaky/disabled. See tdf#97931 and tdf#47179 for some problems caused by this. For the one case where it is expected to call DNS, add a separate function to restore the old behavior. The (semantic) [API CHANGE] is in osl_getLocalHostname, it does no longer return a FQDN. Change-Id: I43455715a474ff6770351d1ce007c28aeb08f32e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107554 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/oslsocket.hxx24
-rw-r--r--sal/osl/unx/file_url.cxx7
-rw-r--r--sal/osl/unx/socket.cxx20
3 files changed, 46 insertions, 5 deletions
diff --git a/sal/inc/oslsocket.hxx b/sal/inc/oslsocket.hxx
new file mode 100644
index 000000000000..52260c263190
--- /dev/null
+++ b/sal/inc/oslsocket.hxx
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <rtl/ustring.h>
+#include <osl/socket.h>
+
+/** Retrieve this machines hostname as fully qualified domain name (FQDN).
+ Note that this might be slower than calling osl_getLocalHostname
+ since DNS needs to be queried to determine the FQDN.
+ @param strLocalHostname out-parameter. The string that receives the local host name.
+ @retval sal_True upon success
+ @retval sal_False
+*/
+oslSocketResult osl_getLocalHostnameFQDN(rtl_uString** strLocalHostname);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file
diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx
index 54ec0c02ac46..ba5ccc766e6c 100644
--- a/sal/osl/unx/file_url.cxx
+++ b/sal/osl/unx/file_url.cxx
@@ -36,6 +36,7 @@
#include <osl/file.hxx>
#include <osl/security.hxx>
#include <osl/socket.h>
+#include <oslsocket.hxx>
#include <osl/diagnose.h>
#include <osl/thread.h>
#include <osl/process.h>
@@ -246,7 +247,7 @@ template<typename T> oslFileError getSystemPathFromFileUrl(
if (url.indexOf('?', i) != -1 || url.indexOf('#', i) != -1)
return osl_File_E_INVAL;
// 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
+ // not supporting an additional final dot, for simplicity) reported by osl_getLocalHostnameFQDN
// (and, in each case, ignoring case of ASCII letters):
if (url.getLength() - i >= 2 && url[i] == '/' && url[i + 1] == '/')
{
@@ -265,7 +266,9 @@ template<typename T> oslFileError getSystemPathFromFileUrl(
!= 0))
{
OUString hostname;
- if (osl_getLocalHostname(&hostname.pData) != osl_Socket_Ok
+ // The 'file' URI Scheme does imply that we want a FQDN in this case
+ // See https://tools.ietf.org/html/rfc8089#section-3
+ if (osl_getLocalHostnameFQDN(&hostname.pData) != osl_Socket_Ok
|| (rtl_ustr_compareIgnoreAsciiCase_WithLength(
url.pData->buffer + i, j - i, hostname.getStr(), hostname.getLength())
!= 0))
diff --git a/sal/osl/unx/socket.cxx b/sal/osl/unx/socket.cxx
index 56a8f6cd63ac..0c93e2928500 100644
--- a/sal/osl/unx/socket.cxx
+++ b/sal/osl/unx/socket.cxx
@@ -36,6 +36,7 @@
#include "sockimpl.hxx"
#include "unixerrnostring.hxx"
+#include <oslsocket.hxx>
/* defines for poll */
#ifdef HAVE_POLL_H
@@ -865,9 +866,11 @@ void SAL_CALL osl_destroyHostAddr (oslHostAddr pAddr)
}
}
-oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **ustrLocalHostname)
+namespace
+{
+oslSocketResult lcl_getLocalHostname(rtl_uString **ustrLocalHostname, bool bUseFQDN)
{
- static auto const init = []() -> std::pair<oslSocketResult, OUString> {
+ static auto const init = [bUseFQDN]() -> std::pair<oslSocketResult, OUString> {
char LocalHostname[256] = "";
#ifdef SYSV
@@ -887,7 +890,7 @@ oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **ustrLocalHostname)
LocalHostname[sizeof(LocalHostname)-1] = 0;
/* check if we have an FQDN */
- if (strchr(LocalHostname, '.') == nullptr)
+ if (bUseFQDN && strchr(LocalHostname, '.') == nullptr)
{
oslHostAddr Addr;
@@ -915,6 +918,17 @@ oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **ustrLocalHostname)
return init.first;
}
+}
+
+oslSocketResult SAL_CALL osl_getLocalHostname(rtl_uString **ustrLocalHostname)
+{
+ return lcl_getLocalHostname(ustrLocalHostname, false);
+}
+
+oslSocketResult osl_getLocalHostnameFQDN(rtl_uString **ustrLocalHostname)
+{
+ return lcl_getLocalHostname(ustrLocalHostname, true);
+}
oslSocketAddr SAL_CALL osl_resolveHostname(rtl_uString *ustrHostname)
{