diff options
-rw-r--r-- | include/osl/socket.h | 3 | ||||
-rw-r--r-- | sal/inc/oslsocket.hxx | 24 | ||||
-rw-r--r-- | sal/osl/unx/file_url.cxx | 7 | ||||
-rw-r--r-- | sal/osl/unx/socket.cxx | 20 |
4 files changed, 47 insertions, 7 deletions
diff --git a/include/osl/socket.h b/include/osl/socket.h index 864e8df88d84..0492dd3179ab 100644 --- a/include/osl/socket.h +++ b/include/osl/socket.h @@ -906,8 +906,7 @@ SAL_DLLPUBLIC void SAL_CALL osl_getHostnameOfHostAddr(const oslHostAddr Addr, rt */ SAL_DLLPUBLIC oslSocketAddr SAL_CALL osl_getSocketAddrOfHostAddr(const oslHostAddr Addr); -/** Retrieve this machines hostname. - May not always be a fully qualified domain name (FQDN). +/** Retrieve this machines hostname (NOT the FQDN) @param strLocalHostname out-parameter. The string that receives the local host name. @retval sal_True upon success @retval sal_False 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) { |