From fa41515d3497f05ef3d422c42eb4d863bd446e9b Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 12 May 2024 07:58:51 +0300 Subject: [PATCH] kutils: lock from all KPasswdStore methods also the implementation internally opens the store if it is not open already Signed-off-by: Ivailo Monev --- kutils/kpasswdstore/kpasswdstore.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/kutils/kpasswdstore/kpasswdstore.cpp b/kutils/kpasswdstore/kpasswdstore.cpp index e4683cb3..39714066 100644 --- a/kutils/kpasswdstore/kpasswdstore.cpp +++ b/kutils/kpasswdstore/kpasswdstore.cpp @@ -120,31 +120,38 @@ bool KPasswdStore::openStore(const qlonglong windowid) void KPasswdStore::setCacheOnly(const bool cacheonly) { d->ensureInterface(); + KLockFile klockfile(getLockName(d->cookie, d->storeid)); + klockfile.lock(); d->interface->call("setCacheOnly", d->cookie, d->storeid, cacheonly); + klockfile.unlock(); } bool KPasswdStore::cacheOnly() const { d->ensureInterface(); + KLockFile klockfile(getLockName(d->cookie, d->storeid)); + klockfile.lock(); QDBusReply result = d->interface->call("cacheOnly", d->cookie, d->storeid); + klockfile.unlock(); return result.value(); } QString KPasswdStore::getPasswd(const QByteArray &key, const qlonglong windowid) { - if (!openStore(windowid) && !cacheOnly()) { - return QString(); - } + d->ensureInterface(); + KLockFile klockfile(getLockName(d->cookie, d->storeid)); + klockfile.lock(); QDBusReply result = d->interface->call("getPasswd", d->cookie, d->storeid, key, windowid); return result.value(); } bool KPasswdStore::storePasswd(const QByteArray &key, const QString &passwd, const qlonglong windowid) { - if (!openStore(windowid) && !cacheOnly()) { - return false; - } + d->ensureInterface(); + KLockFile klockfile(getLockName(d->cookie, d->storeid)); + klockfile.lock(); QDBusReply result = d->interface->call("storePasswd", d->cookie, d->storeid, key, passwd, windowid); + klockfile.unlock(); return result.value(); }