/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * 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/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
staticbool sysconf_SC_GETPW_R_SIZE_MAX(std::size_t * value) { #ifdefined _SC_GETPW_R_SIZE_MAX long m;
errno = 0;
m = sysconf(_SC_GETPW_R_SIZE_MAX); if (m == -1) { /* _SC_GETPW_R_SIZE_MAX has no limit; some platforms like certain FreeBSD versions support sysconf(_SC_GETPW_R_SIZE_MAX) in a broken
way and always set EINVAL, so be resilient here: */ returnfalse;
}
SAL_WARN_IF( m < 0 || o3tl::make_unsigned(m) >= std::numeric_limits<std::size_t>::max(), "sal.osl", "m < 0 || (unsigned long) m >= std::numeric_limits::max()");
*value = static_cast<std::size_t>(m); returntrue; #else /* some platforms like macOS 1.3 do not define _SC_GETPW_R_SIZE_MAX: */ returnfalse; #endif
}
static oslSecurityImpl * growSecurityImpl(
oslSecurityImpl * impl, std::size_t * bufSize)
{
std::size_t n = 0;
oslSecurityImpl * p = nullptr; if (impl == nullptr) { if (!sysconf_SC_GETPW_R_SIZE_MAX(&n)) { /* choose something sensible (the callers of growSecurityImpl will
detect it if the allocated buffer is too small: */
n = 1024;
}
} elseif (*bufSize <= std::numeric_limits<std::size_t>::max() / 2) {
n = 2 * *bufSize;
} if (n != 0) { if (n <= std::numeric_limits<std::size_t>::max()
- offsetof(oslSecurityImpl, m_buffer))
{
*bufSize = n;
n += offsetof(oslSecurityImpl, m_buffer);
} else {
*bufSize = std::numeric_limits<std::size_t>::max()
- offsetof(oslSecurityImpl, m_buffer);
n = std::numeric_limits<std::size_t>::max();
}
p = static_cast<oslSecurityImpl *>(realloc(impl, n)); if (p != nullptr) { // coverity[overrun-buffer-arg] - theoretically massive n is not due to // a negative parameter being interpreted as unsigned
memset (p, 0, n);
}
} if (p == nullptr) {
free(impl);
} return p;
}
if (rtl::Bootstrap::get("HOME", pValue))
{ autoconst pStrValue = OUStringToOString(pValue, RTL_TEXTENCODING_UTF8); if (!pStrValue.isEmpty())
{
*pszDirectory = pStrValue; returntrue;
}
}
} #endif
#ifdef IOS
{ // Let's pretend the app-specific "Documents" directory is the home directory for now
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *userDirectory = [paths objectAtIndex:0]; autoconst len = [userDirectory length]; if (len <= std::numeric_limits<sal_Int32>::max())
{
*pszDirectory = OString([userDirectory UTF8String], len); return sal_True;
}
} #endif
/* if current user, check also environment for HOME */ if (getuid() == pSecImpl->m_pPasswd.pw_uid)
{ char *pStr = nullptr; #ifdef __sun char buffer[8192];
if (pStr == nullptr || pStr[0] == '\0' || access(pStr, 0) != 0)
{ // a default equal to $HOME/.config should be used.
OString home; if (!osl_psz_getHomeDir(Security, &home)) returnfalse; autoconst config = OString(home + "/.config");
// try to create dir if not present bool dirOK = true; if (mkdir(config.getStr(), S_IRWXU) != 0)
{ int e = errno; if (e != EEXIST)
{
SAL_WARN( "sal.osl", "mkdir(" << config << "): errno=" << e);
dirOK = false;
}
} if (dirOK)
{ // check file type and permissions struct stat st; if (stat(config.getStr(), &st) != 0)
{
SAL_INFO("sal.osl","Could not stat $HOME/.config");
dirOK = false;
} else
{ if (!S_ISDIR(st.st_mode))
{
SAL_INFO("sal.osl", "$HOME/.config is not a directory");
dirOK = false;
} if (!(st.st_mode & S_IRUSR && st.st_mode & S_IWUSR && st.st_mode & S_IXUSR))
{
SAL_INFO("sal.osl", "$HOME/.config has bad permissions");
dirOK = false;
}
}
}
// if !dirOK, resort to HOME if (dirOK)
home = config;
*pszDirectory = home;
} else
{ autoconst len = std::strlen(pStr); if (len > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max())) { returnfalse;
}
*pszDirectory = OString(pStr, len);
}
returntrue;
}
#else
/* * FIXME: rewrite to use more flexible * NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) * as soon as we can bump the baseline to Tiger (for NSApplicationSupportDirectory) and have * support for Objective-C in the build environment
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.