Skip to content

Commit 5de160b

Browse files
committed
refactor(credentials): use member function to change keychain key name.
Only valid for Windows. Signed-off-by: Camila Ayres <[email protected]>
1 parent f7c91b0 commit 5de160b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/libsync/creds/keychainchunk.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ void Job::setAppName(const QString &appName)
9393
_appName = appName;
9494
}
9595

96+
#ifdef Q_OS_WIN
97+
void Job::jobKeyPrependAppName(QString &key)
98+
{
99+
// NOTE: The following is normally done in AbstractCredentials::keychainKey
100+
// when an _account is specified by our other ctr overload (see 'kck' in this file).
101+
key.prepend(_appName + "_");
102+
}
103+
#endif
104+
96105
/*
97106
* WriteJob
98107
*/
@@ -112,7 +121,7 @@ WriteJob::WriteJob(const QString &key, const QByteArray &data, QObject *parent)
112121
: WriteJob(nullptr, key, data, parent)
113122
{
114123
#ifdef Q_OS_WIN
115-
_key.prepend(_appName + "_");
124+
jobKeyPrependAppName(_key);
116125
#endif
117126
}
118127

@@ -233,7 +242,7 @@ ReadJob::ReadJob(const QString &key, QObject *parent)
233242
: ReadJob(nullptr, key, false, parent)
234243
{
235244
#ifdef Q_OS_WIN
236-
_key.prepend(_appName + "_");
245+
jobKeyPrependAppName(_key);
237246
#endif
238247
}
239248

@@ -366,7 +375,7 @@ DeleteJob::DeleteJob(const QString &key, QObject *parent)
366375
: DeleteJob(nullptr, key, false, parent)
367376
{
368377
#ifdef Q_OS_WIN
369-
_key.prepend(_appName + "_");
378+
jobKeyPrependAppName(_key);
370379
#endif
371380
}
372381

src/libsync/creds/keychainchunk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ class OWNCLOUDSYNC_EXPORT Job : public QObject
7070
*/
7171
void setAppName(const QString &AppName);
7272

73+
#ifdef Q_OS_WIN
74+
/**
75+
* On Windows the credential keys aren't namespaced properly
76+
* by qtkeychain. To work around that we manually add namespacing
77+
* to the generated keys. See #6125.
78+
* It's safe to do that since the key format is changing for 2.4
79+
* anyway to include the account ids. That means old keys can be
80+
* migrated to new namespaced keys on windows for 2.4.
81+
*/
82+
void jobKeyPrependAppName(QString &key);
83+
#endif
84+
7385
protected:
7486
QString _serviceName;
7587
Account *_account = nullptr;

0 commit comments

Comments
 (0)