diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-03-07 21:52:20 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-03-08 15:35:54 +0000 |
commit | 16fb0d3d0f68708c183c53bd18660a23970b77fe (patch) | |
tree | 8e86df69dcf4ab52368a0a1d767dff62930549fd | |
parent | f9ddda353851b019c2eb8a427ee9f8042f8107b0 (diff) |
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@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | framework/qa/complex/path_substitution/PathSubstitutionTest.java | 1 | ||||
-rw-r--r-- | framework/source/services/substitutepathvars.cxx | 8 | ||||
-rw-r--r-- | include/osl/security.h | 10 | ||||
-rw-r--r-- | include/osl/security.hxx | 6 | ||||
-rw-r--r-- | include/osl/security_decl.hxx | 4 | ||||
-rw-r--r-- | odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java | 2 | ||||
-rw-r--r-- | offapi/com/sun/star/util/PathSubstitution.idl | 4 | ||||
-rw-r--r-- | sal/osl/unx/security.cxx | 7 | ||||
-rw-r--r-- | sal/osl/w32/security.c | 5 | ||||
-rw-r--r-- | sal/util/sal.map | 5 |
10 files changed, 46 insertions, 6 deletions
diff --git a/framework/qa/complex/path_substitution/PathSubstitutionTest.java b/framework/qa/complex/path_substitution/PathSubstitutionTest.java index 8d85ade376c0..abf83cdce99b 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 daeeb3d1c320..17375a4de32b 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 2199f3abc6de..deefb5894047 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 57ab17de4c46..a1a905ee888a 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 6eb0a01da90e..a809f06698bd 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 5e0b9991e871..a9eb1337bf75 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 0b30fec48130..c0d99bc9f549 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 16a5f74cba36..c4d9d29fa405 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 da13ce64665c..1d31eeffd9ba 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 e3f920c7e33c..1ccac615b67f 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; |