KWallet

kwalletd.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2002-2004 George Staikos <staikos@kde.org>
4 SPDX-FileCopyrightText: 2008 Michael Leupold <lemma@confuego.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef _KWALLETD_H_
10#define _KWALLETD_H_
11
12#include "kwalletbackend.h"
13#include <QDBusConnection>
14#include <QDBusContext>
15#include <QDBusServiceWatcher>
16#include <QHash>
17#include <QPointer>
18#include <QString>
19
20#include "ktimeout.h"
21#include "kwalletsessionstore.h"
22
23class KDirWatch;
24class KTimeout;
25
26// @Private
27class KWalletTransaction;
28class KWalletSessionStore;
29class KWalletFreedesktopService;
30
31class KWalletD : public QObject, protected QDBusContext
32{
34
35public:
36 KWalletD();
37 ~KWalletD() override;
38
39 static QString encodeWalletName(const QString &name);
40 static QString decodeWalletName(const QString &mangledName);
41
42 int nextTransactionId() const;
43 int
44 openAsync(const QString &wallet, qlonglong wId, const QString &appid, bool handleSession, const QDBusConnection &connection, const QDBusMessage &message);
45 // Close and lock the wallet
46 // Accepts "message" for working from other QDBusContexts
47 int close(int handle, bool force, const QString &appid, const QDBusMessage &message);
48public Q_SLOTS:
49
50 // Is the wallet enabled? If not, all open() calls fail.
51 bool isEnabled() const;
52
53 // Open and unlock the wallet
54 int open(const QString &wallet, qlonglong wId, const QString &appid);
55
56 // Open and unlock the wallet with this path
57 int openPath(const QString &path, qlonglong wId, const QString &appid);
58
59 // Open the wallet asynchronously
60 int openAsync(const QString &wallet, qlonglong wId, const QString &appid, bool handleSession);
61
62 // Open and unlock the wallet with this path asynchronously
63 int openPathAsync(const QString &path, qlonglong wId, const QString &appid, bool handleSession);
64
65 // Close and lock the wallet
66 // If force = true, will close it for all users. Behave. This
67 // can break applications, and is generally intended for use by
68 // the wallet manager app only.
69 int close(const QString &wallet, bool force);
70 int close(int handle, bool force, const QString &appid);
71
72 // Save to disk but leave open
73 Q_NOREPLY void sync(int handle, const QString &appid);
74
75 // Physically deletes the wallet from disk.
76 int deleteWallet(const QString &wallet);
77
78 // Returns true if the wallet is open
79 bool isOpen(const QString &wallet);
80 bool isOpen(int handle);
81
82 // List the users of this wallet
83 QStringList users(const QString &wallet) const;
84
85 // Change the password of this wallet
86 void changePassword(const QString &wallet, qlonglong wId, const QString &appid);
87
88 // A list of all wallets
89 QStringList wallets() const;
90
91 // A list of all folders in this wallet
92 QStringList folderList(int handle, const QString &appid);
93
94 // Does this wallet have this folder?
95 bool hasFolder(int handle, const QString &folder, const QString &appid);
96
97 // Create this folder
98 bool createFolder(int handle, const QString &folder, const QString &appid);
99
100 // Remove this folder
101 bool removeFolder(int handle, const QString &folder, const QString &appid);
102
103 // List of entries in this folder
104 QStringList entryList(int handle, const QString &folder, const QString &appid);
105
106 // Read an entry. If the entry does not exist, it just
107 // returns an empty result. It is your responsibility to check
108 // hasEntry() first.
109 QByteArray readEntry(int handle, const QString &folder, const QString &key, const QString &appid);
110 QByteArray readMap(int handle, const QString &folder, const QString &key, const QString &appid);
111 QString readPassword(int handle, const QString &folder, const QString &key, const QString &appid);
112
113#if KWALLET_BUILD_DEPRECATED_SINCE(5, 72)
114 // use entriesList()
115 QVariantMap readEntryList(int handle, const QString &folder, const QString &key, const QString &appid);
116#endif
117
118#if KWALLET_BUILD_DEPRECATED_SINCE(5, 72)
119 // use mapList()
120 QVariantMap readMapList(int handle, const QString &folder, const QString &key, const QString &appid);
121#endif
122
123#if KWALLET_BUILD_DEPRECATED_SINCE(5, 72)
124 // use passwordList()
125 QVariantMap readPasswordList(int handle, const QString &folder, const QString &key, const QString &appid);
126#endif
127
128 QVariantMap entriesList(int handle, const QString &folder, const QString &appid);
129 QVariantMap mapList(int handle, const QString &folder, const QString &appid);
130 QVariantMap passwordList(int handle, const QString &folder, const QString &appid);
131
132 // Rename an entry. rc=0 on success.
133 int renameEntry(int handle, const QString &folder, const QString &oldName, const QString &newName, const QString &appid);
134 // Rename the wallet
135 int renameWallet(const QString &oldName, const QString &newName);
136
137 // Write an entry. rc=0 on success.
138 int writeEntry(int handle, const QString &folder, const QString &key, const QByteArray &value, int entryType, const QString &appid);
139 int writeEntry(int handle, const QString &folder, const QString &key, const QByteArray &value, const QString &appid);
140 int writeMap(int handle, const QString &folder, const QString &key, const QByteArray &value, const QString &appid);
141 int writePassword(int handle, const QString &folder, const QString &key, const QString &value, const QString &appid);
142
143 // Does the entry exist?
144 bool hasEntry(int handle, const QString &folder, const QString &key, const QString &appid);
145
146 // What type is the entry?
147 int entryType(int handle, const QString &folder, const QString &key, const QString &appid);
148
149 // Remove an entry. rc=0 on success.
150 int removeEntry(int handle, const QString &folder, const QString &key, const QString &appid);
151
152 // Disconnect an app from a wallet
153 bool disconnectApplication(const QString &wallet, const QString &application);
154
155 void reconfigure();
156
157 // Determine
158 bool folderDoesNotExist(const QString &wallet, const QString &folder);
159 bool keyDoesNotExist(const QString &wallet, const QString &folder, const QString &key);
160
161 void closeAllWallets();
162
163 QString networkWallet();
164
165 QString localWallet();
166
167 void screenSaverChanged(bool);
168
169 // Open a wallet using a pre-hashed password. This is only useful in cooperation
170 // with the kwallet PAM module. It's also less secure than manually entering the
171 // password as the password hash is transmitted using D-Bus.
172 int pamOpen(const QString &wallet, const QByteArray &passwordHash, int sessionTimeout);
173
175 void walletAsyncOpened(int id, int handle); // used to notify KWallet::Wallet
176 void walletListDirty();
177 void walletCreated(const QString &wallet);
178 void walletOpened(const QString &wallet);
179 void walletDeleted(const QString &wallet);
180 void walletClosed(const QString &wallet); // clazy:exclude=overloaded-signal
181
182 // TODO KF6 remove this signal, replaced by walletClosedId(int)
183 void walletClosed(int handle); // clazy:exclude=overloaded-signal
184
185 // since 5.81
186 void walletClosedId(int handle);
187
188 void allWalletsClosed();
189 void folderListUpdated(const QString &wallet);
190 void folderUpdated(const QString &, const QString &);
191 void entryUpdated(const QString &, const QString &, const QString &);
192 void entryRenamed(const QString &, const QString &, const QString &, const QString &);
193 void entryDeleted(const QString &, const QString &, const QString &);
194 void applicationDisconnected(const QString &wallet, const QString &application);
195
196private Q_SLOTS:
197 void slotServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
198 void emitWalletListDirty();
199 void timedOutClose(int handle);
200 void timedOutSync(int handle);
201 void notifyFailures();
202 void processTransactions();
203 void activatePasswordDialog();
204#ifdef Q_WS_X11
205 void connectToScreenSaver();
206#endif
207
208private:
209 // Internal - open a wallet
210 int internalOpen(const QString &appid, const QString &wallet, bool isPath, WId w, bool modal, const QString &service);
211 // Internal - close this wallet.
212 int internalClose(KWallet::Backend *const w, const int handle, const bool force, const bool saveBeforeClose = true);
213
214 bool isAuthorizedApp(const QString &appid, const QString &wallet, WId w);
215 // This also validates the handle. May return NULL.
216 KWallet::Backend *getWallet(const QString &appid, int handle);
217 // Generate a new unique handle.
218 int generateHandle();
219 // Emit signals about closing wallets
220 void doCloseSignals(int, const QString &);
221 void emitFolderUpdated(const QString &, const QString &);
222 void emitEntryUpdated(const QString &, const QString &, const QString &);
223 void emitEntryRenamed(const QString &, const QString &, const QString &, const QString &);
224 void emitEntryDeleted(const QString &, const QString &, const QString &);
225 // Implicitly allow access for this application
226 bool implicitAllow(const QString &wallet, const QString &app);
227 bool implicitDeny(const QString &wallet, const QString &app);
228
229 void doTransactionChangePassword(const QString &appid, const QString &wallet, qlonglong wId);
230 void doTransactionOpenCancelled(const QString &appid, const QString &wallet, const QString &service);
231 int doTransactionOpen(const QString &appid, const QString &wallet, bool isPath, qlonglong wId, bool modal, const QString &service);
232 void initiateSync(int handle);
233
234 void setupDialog(QWidget *dialog, WId wId, const QString &appid, bool modal);
235 void checkActiveDialog();
236
237 QPair<int, KWallet::Backend *> findWallet(const QString &walletName) const;
238
239 typedef QHash<int, KWallet::Backend *> Wallets;
240 Wallets _wallets;
241 KDirWatch *_dw;
242 int _failed;
243
244 // configuration values
245 bool _leaveOpen, _closeIdle, _launchManager, _enabled;
246 bool _openPrompt, _firstUse, _showingFailureNotify;
247 int _idleTime;
248 QMap<QString, QStringList> _implicitAllowMap, _implicitDenyMap;
249 KTimeout _closeTimers;
250 KTimeout _syncTimers;
251 const int _syncTime;
252 static bool _processing;
253
254 KWalletTransaction *_curtrans; // current transaction
255 QList<KWalletTransaction *> _transactions;
256 QPointer<QWidget> activeDialog;
257
258#ifdef Q_WS_X11
259 QDBusInterface *screensaver;
260#endif
261
262 // sessions
263 KWalletSessionStore _sessions;
264 QDBusServiceWatcher _serviceWatcher;
265
266 std::unique_ptr<KWalletFreedesktopService> _fdoService;
267
268 bool _useGpg;
269};
270
271#endif
QDBusConnection connection() const const
const QDBusMessage & message() const const
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.