[Libreoffice-commits] core.git: connectivity/source
jucasaca (via logerrit)
logerrit at kemper.freedesktop.org
Thu Sep 9 19:22:16 UTC 2021
connectivity/source/drivers/firebird/Connection.cxx | 36 +++++++++++++-------
1 file changed, 25 insertions(+), 11 deletions(-)
New commits:
commit 34219c3cb737371afb4a29604e95f0e87966f02a
Author: jucasaca <jcsanz at libreoffice.org>
AuthorDate: Fri Sep 3 13:26:32 2021 +0200
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Sep 9 21:21:43 2021 +0200
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 at collabora.com>
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);
}
}
More information about the Libreoffice-commits
mailing list