diff options
author | jucasaca <jcsanz@libreoffice.org> | 2021-09-03 13:26:32 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-09 21:21:43 +0200 |
commit | 34219c3cb737371afb4a29604e95f0e87966f02a (patch) | |
tree | 6688199be00da67e1a2d605e39ac127bf10efc89 /connectivity/source | |
parent | dbd367e57669a82b7ea82f112d3d8c1a105d8d41 (diff) |
tdf#143905: Parse password from connection string
Parse user and password, so its possible to connect to a
firebird server more over embeded and file
Change-Id: Idbfa526e2a29f6f8bed5165f57844350c8b6d127
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121638
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/drivers/firebird/Connection.cxx | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index cc4ee39ff155..6c150fe2fb8f 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -211,8 +211,8 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& std::string dpbBuffer; { - char userName[256] = ""; - char userPassword[256] = ""; + OString userName; + OString userPassword; dpbBuffer.push_back(isc_dpb_version1); dpbBuffer.push_back(isc_dpb_sql_dialect); @@ -233,28 +233,42 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& if (m_bIsEmbedded || m_bIsFile) { - strcpy(userName,"sysdba"); - strcpy(userPassword,"masterkey"); + userName = "sysdba"; + userPassword = "masterkey"; } else { - // TODO: parse password from connection string as needed? + for (const auto& rIter : info) + { + if (rIter.Name == "user") + { + if (OUString value; rIter.Value >>= value) + userName = OUStringToOString(value, RTL_TEXTENCODING_UTF8); + } + else if (rIter.Name == "password") + { + if (OUString value; rIter.Value >>= value) + userPassword = OUStringToOString(value, RTL_TEXTENCODING_UTF8); + } + } } - if (strlen(userName)) + if (!userName.isEmpty()) { - int nUsernameLength = strlen(userName); + const sal_Int32 nMaxUsername = 255; //max size + int nUsernameLength = std::min(userName.getLength(), nMaxUsername); dpbBuffer.push_back(isc_dpb_user_name); dpbBuffer.push_back(nUsernameLength); - dpbBuffer.append(userName); + dpbBuffer.append(userName.getStr(), nUsernameLength); } - if (strlen(userPassword)) + if (!userPassword.isEmpty()) { - int nPasswordLength = strlen(userPassword); + const sal_Int32 nMaxPassword = 255; //max size + int nPasswordLength = std::min(userPassword.getLength(), nMaxPassword); dpbBuffer.push_back(isc_dpb_password); dpbBuffer.push_back(nPasswordLength); - dpbBuffer.append(userPassword); + dpbBuffer.append(userPassword.getStr(), nPasswordLength); } } |