[Libreoffice-commits] core.git: framework/qa framework/source include/osl odk/examples offapi/com sal/osl sal/util
Samuel Mehrbrodt
Samuel.Mehrbrodt at cib.de
Tue Mar 8 15:36:17 UTC 2016
framework/qa/complex/path_substitution/PathSubstitutionTest.java | 1 +
framework/source/services/substitutepathvars.cxx | 8 ++++++++
include/osl/security.h | 10 ++++++++++
include/osl/security.hxx | 6 ++++--
include/osl/security_decl.hxx | 4 +++-
odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java | 2 +-
offapi/com/sun/star/util/PathSubstitution.idl | 4 +++-
sal/osl/unx/security.cxx | 7 ++++++-
sal/osl/w32/security.c | 5 +++++
sal/util/sal.map | 5 +++++
10 files changed, 46 insertions(+), 6 deletions(-)
New commits:
commit 16fb0d3d0f68708c183c53bd18660a23970b77fe
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date: Mon Mar 7 21:52:20 2016 +0100
tdf#98407 PathSubstitution: Add substitution for $(username)
This allows to use the username as a placeholder in the config paths (Autotext, Gallery, etc)
Change-Id: I76434e980cd8ec8785a5587d0bc5fdd67dc42de2
Reviewed-on: https://gerrit.libreoffice.org/22901
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
Tested-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/framework/qa/complex/path_substitution/PathSubstitutionTest.java b/framework/qa/complex/path_substitution/PathSubstitutionTest.java
index 8d85ade..abf83cd 100644
--- a/framework/qa/complex/path_substitution/PathSubstitutionTest.java
+++ b/framework/qa/complex/path_substitution/PathSubstitutionTest.java
@@ -54,6 +54,7 @@ public class PathSubstitutionTest
substVars.add("$(home)", true, true);
substVars.add("$(temp)", true, true);
substVars.add("$(lang)", false, false);
+ substVars.add("$(username)", false, false);
substVars.add("$(langid)", false, false);
substVars.add("$(vlang)", false, false);
// path won't resubstitute
diff --git a/framework/source/services/substitutepathvars.cxx b/framework/source/services/substitutepathvars.cxx
index daeeb3d..17375a4 100644
--- a/framework/source/services/substitutepathvars.cxx
+++ b/framework/source/services/substitutepathvars.cxx
@@ -167,6 +167,7 @@ enum PreDefVariable
PREDEFVAR_HOME,
PREDEFVAR_TEMP,
PREDEFVAR_PATH,
+ PREDEFVAR_USERNAME,
PREDEFVAR_LANGID,
PREDEFVAR_VLANG,
PREDEFVAR_INSTPATH,
@@ -350,6 +351,7 @@ static const FixedVariable aFixedVarTable[] =
{ "$(home)", PREDEFVAR_HOME, true },
{ "$(temp)", PREDEFVAR_TEMP, true },
{ "$(path)", PREDEFVAR_PATH, true },
+ { "$(username)", PREDEFVAR_USERNAME, false },
{ "$(langid)", PREDEFVAR_LANGID, false },
{ "$(vlang)", PREDEFVAR_VLANG, false },
{ "$(instpath)", PREDEFVAR_INSTPATH, true },
@@ -1239,6 +1241,12 @@ void SubstitutePathVariables::SetPredefinedPathVariables()
m_aPreDefVars.m_FixedVar[ PREDEFVAR_PROG ] = m_aPreDefVars.m_FixedVar[ PREDEFVAR_PROGPATH ];
}
+ // Set $(username)
+ OUString aSystemUser;
+ ::osl::Security aSecurity;
+ aSecurity.getUserName( aSystemUser, false );
+ m_aPreDefVars.m_FixedVar[ PREDEFVAR_USERNAME ] = aSystemUser;
+
// Detect the language type of the current office
m_aPreDefVars.m_eLanguageType = LANGUAGE_ENGLISH_US;
OUString aLocaleStr( utl::ConfigManager::getLocale() );
diff --git a/include/osl/security.h b/include/osl/security.h
index 2199f3a..deefb58 100644
--- a/include/osl/security.h
+++ b/include/osl/security.h
@@ -118,6 +118,16 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserIdent(
SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserName(
oslSecurity Security, rtl_uString **strName);
+/** Get the login name for the user of this security handle,
+ excluding the domain name on Windows.
+ @param[in] Security the security handle.
+ @param[out] strName the string that receives the user name on success.
+ @return True, if the security handle is valid, otherwise False.
+ @since LibreOffice 5.2
+*/
+SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getShortUserName(
+ oslSecurity Security, rtl_uString **strName);
+
/** Get the home directory of the user of this security handle.
@param[in] Security the security handle.
@param[out] strDirectory the string that receives the directory path on success.
diff --git a/include/osl/security.hxx b/include/osl/security.hxx
index 57ab17d..a1a905e 100644
--- a/include/osl/security.hxx
+++ b/include/osl/security.hxx
@@ -69,9 +69,11 @@ inline bool Security::getUserIdent( rtl::OUString& strIdent) const
}
-inline bool Security::getUserName( rtl::OUString& strName ) const
+inline bool Security::getUserName( rtl::OUString& strName, bool bIncludeDomain ) const
{
- return osl_getUserName( m_handle, &strName.pData );
+ if (bIncludeDomain)
+ return osl_getUserName( m_handle, &strName.pData );
+ return osl_getShortUserName( m_handle, &strName.pData );
}
diff --git a/include/osl/security_decl.hxx b/include/osl/security_decl.hxx
index 6eb0a01..a809f06 100644
--- a/include/osl/security_decl.hxx
+++ b/include/osl/security_decl.hxx
@@ -76,9 +76,11 @@ public:
/** get the name of the logged in user.
@param[out] strName is the OUString which returns the name
+ @param[in] bIncludeDomain Include the Domain name (like "ORG\username"). Affects Windows only.
+ This parameter is available since LibreOffice 5.2.
@return True, if any user is successfully logged in, otherwise False
*/
- inline bool SAL_CALL getUserName( rtl::OUString& strName) const;
+ inline bool SAL_CALL getUserName( rtl::OUString& strName, bool bIncludeDomain=true ) const;
/** get the home directory of the logged in user.
@param[out] strDirectory is the OUString which returns the directory name
diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java
index 5e0b999..a9eb133 100644
--- a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java
+++ b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java
@@ -44,7 +44,7 @@ public class PathSubstitutionTest {
* the path substitution service.
*/
private static String[] predefinedPathVariables = {
- "$(home)","$(inst)","$(prog)","$(temp)","$(user)",
+ "$(home)","$(inst)","$(prog)","$(temp)","$(user)", "$(username)",
"$(work)","$(path)","$(langid)","$(vlang)"
};
diff --git a/offapi/com/sun/star/util/PathSubstitution.idl b/offapi/com/sun/star/util/PathSubstitution.idl
index 0b30fec..c0d99bc 100644
--- a/offapi/com/sun/star/util/PathSubstitution.idl
+++ b/offapi/com/sun/star/util/PathSubstitution.idl
@@ -58,6 +58,8 @@ module com { module sun { module star { module util {
<dd>The current temporary directory.</dd>
<dt>\$(path)</dt>
<dd>The value of PATH environment variable.</dd>
+ <dt>\$(username)</dt>
+ <dd>The username (login name) of the currently active user, excluding the domain name on Windows. (Available since LibreOffice 5.2)</dd>
<dt>\$(langid)</dt>
<dd>The language code used by the Office, like 0x0009=English, 0x0409=English US.</dd>
<dt>\$(vlang)</dt>
@@ -65,7 +67,7 @@ module com { module sun { module star { module util {
</dl>
<p>
Attention: Most predefined variables describe an absolute path.
- The only exceptions are: \$(langid) and \$(vlang).
+ The only exceptions are: \$(username), \$(langid) and \$(vlang).
Therefore the service implementation should only substitute variables which
are located at the start of a provided path string or are part of a multi-path.
This special service is not designed to be a text substiution but shall
diff --git a/sal/osl/unx/security.cxx b/sal/osl/unx/security.cxx
index 16a5f74..c4d9d29 100644
--- a/sal/osl/unx/security.cxx
+++ b/sal/osl/unx/security.cxx
@@ -66,7 +66,7 @@ static bool sysconf_SC_GETPW_R_SIZE_MAX(std::size_t * value) {
way and always set EINVAL, so be resilient here: */
return false;
} else {
- SAL_WARN_IF( m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max(), "sal.osl",
+ SAL_WARN_IF( m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max(), "sal.osl",
"m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max()");
*value = (std::size_t) m;
return true;
@@ -261,6 +261,11 @@ sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **ustrName)
return bRet;
}
+sal_Bool SAL_CALL osl_getShortUserName(oslSecurity Security, rtl_uString **ustrName)
+{
+ return osl_getUserName(Security, ustrName); // No domain name on unix
+}
+
static bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* pszName, sal_uInt32 nMax)
{
oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl *>(Security);
diff --git a/sal/osl/w32/security.c b/sal/osl/w32/security.c
index da13ce6..1d31eef 100644
--- a/sal/osl/w32/security.c
+++ b/sal/osl/w32/security.c
@@ -424,6 +424,11 @@ sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **strName)
return getUserNameImpl(Security, strName, sal_True);
}
+sal_Bool SAL_CALL osl_getShortUserName(oslSecurity Security, rtl_uString **strName)
+{
+ return getUserNameImpl(Security, strName, sal_False);
+}
+
sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory)
{
rtl_uString *ustrSysDir = NULL;
diff --git a/sal/util/sal.map b/sal/util/sal.map
index e3f920c..1ccac61 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -690,6 +690,11 @@ LIBO_UDK_5.1 { # symbols available in >= LibO 5.1
rtl_uString_newReplaceFirstToAsciiL;
} LIBO_UDK_5.0;
+LIBO_UDK_5.2 { # symbols available in >= LibO 5.2
+ global:
+ osl_getShortUserName;
+} LIBO_UDK_5.1;
+
PRIVATE_1.0 {
global:
osl_detail_ObjectRegistry_storeAddresses;
More information about the Libreoffice-commits
mailing list