1 | // -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*- |
2 | /* |
3 | This file is part of the KDE libraries |
4 | |
5 | Copyright (c) 2002-2004 George Staikos <staikos@kde.org> |
6 | Copyright (c) 2008 Michael Leupold <lemma@confuego.org> |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | |
23 | */ |
24 | #ifndef _KWALLETD_H_ |
25 | #define _KWALLETD_H_ |
26 | |
27 | #include <QtCore/QString> |
28 | #include <QImage> |
29 | #include <QtCore/QHash> |
30 | #include "kwalletbackend.h" |
31 | #include <QtCore/QPointer> |
32 | #include <time.h> |
33 | #include <stdlib.h> |
34 | #include <QtDBus/QtDBus> |
35 | #include <QDBusServiceWatcher> |
36 | |
37 | #include "ktimeout.h" |
38 | #include "kwalletsessionstore.h" |
39 | |
40 | class KDirWatch; |
41 | class KTimeout; |
42 | |
43 | // @Private |
44 | class KWalletTransaction; |
45 | class KWalletSessionStore; |
46 | |
47 | class KWalletD : public QObject, protected QDBusContext { |
48 | Q_OBJECT |
49 | |
50 | public: |
51 | KWalletD(); |
52 | virtual ~KWalletD(); |
53 | |
54 | public Q_SLOTS: |
55 | // Is the wallet enabled? If not, all open() calls fail. |
56 | bool isEnabled() const; |
57 | |
58 | // Open and unlock the wallet |
59 | int open(const QString& wallet, qlonglong wId, const QString& appid); |
60 | |
61 | // Open and unlock the wallet with this path |
62 | int openPath(const QString& path, qlonglong wId, const QString& appid); |
63 | |
64 | // Open the wallet asynchronously |
65 | int openAsync(const QString& wallet, qlonglong wId, const QString& appid, |
66 | bool handleSession); |
67 | |
68 | // Open and unlock the wallet with this path asynchronously |
69 | int openPathAsync(const QString& path, qlonglong wId, const QString& appid, |
70 | bool handleSession); |
71 | |
72 | // Close and lock the wallet |
73 | // If force = true, will close it for all users. Behave. This |
74 | // can break applications, and is generally intended for use by |
75 | // the wallet manager app only. |
76 | int close(const QString& wallet, bool force); |
77 | int close(int handle, bool force, const QString& appid); |
78 | |
79 | // Save to disk but leave open |
80 | Q_NOREPLY void sync(int handle, const QString& appid); |
81 | |
82 | // Physically deletes the wallet from disk. |
83 | int deleteWallet(const QString& wallet); |
84 | |
85 | // Returns true if the wallet is open |
86 | bool isOpen(const QString& wallet); |
87 | bool isOpen(int handle); |
88 | |
89 | // List the users of this wallet |
90 | QStringList users(const QString& wallet) const; |
91 | |
92 | // Change the password of this wallet |
93 | void changePassword(const QString& wallet, qlonglong wId, const QString& appid); |
94 | |
95 | // A list of all wallets |
96 | QStringList wallets() const; |
97 | |
98 | // A list of all folders in this wallet |
99 | QStringList folderList(int handle, const QString& appid); |
100 | |
101 | // Does this wallet have this folder? |
102 | bool hasFolder(int handle, const QString& folder, const QString& appid); |
103 | |
104 | // Create this folder |
105 | bool createFolder(int handle, const QString& folder, const QString& appid); |
106 | |
107 | // Remove this folder |
108 | bool removeFolder(int handle, const QString& folder, const QString& appid); |
109 | |
110 | // List of entries in this folder |
111 | QStringList entryList(int handle, const QString& folder, const QString& appid); |
112 | |
113 | // Read an entry. If the entry does not exist, it just |
114 | // returns an empty result. It is your responsibility to check |
115 | // hasEntry() first. |
116 | QByteArray readEntry(int handle, const QString& folder, const QString& key, const QString& appid); |
117 | QByteArray readMap(int handle, const QString& folder, const QString& key, const QString& appid); |
118 | QString readPassword(int handle, const QString& folder, const QString& key, const QString& appid); |
119 | QVariantMap readEntryList(int handle, const QString& folder, const QString& key, const QString& appid); |
120 | QVariantMap readMapList(int handle, const QString& folder, const QString& key, const QString& appid); |
121 | QVariantMap readPasswordList(int handle, const QString& folder, const QString& key, const QString& appid); |
122 | |
123 | // Rename an entry. rc=0 on success. |
124 | int renameEntry(int handle, const QString& folder, const QString& oldName, const QString& newName, const QString& appid); |
125 | |
126 | // Write an entry. rc=0 on success. |
127 | int writeEntry(int handle, const QString& folder, const QString& key, const QByteArray& value, int entryType, const QString& appid); |
128 | int writeEntry(int handle, const QString& folder, const QString& key, const QByteArray& value, const QString& appid); |
129 | int writeMap(int handle, const QString& folder, const QString& key, const QByteArray& value, const QString& appid); |
130 | int writePassword(int handle, const QString& folder, const QString& key, const QString& value, const QString& appid); |
131 | |
132 | // Does the entry exist? |
133 | bool hasEntry(int handle, const QString& folder, const QString& key, const QString& appid); |
134 | |
135 | // What type is the entry? |
136 | int entryType(int handle, const QString& folder, const QString& key, const QString& appid); |
137 | |
138 | // Remove an entry. rc=0 on success. |
139 | int removeEntry(int handle, const QString& folder, const QString& key, const QString& appid); |
140 | |
141 | // Disconnect an app from a wallet |
142 | bool disconnectApplication(const QString& wallet, const QString& application); |
143 | |
144 | void reconfigure(); |
145 | |
146 | // Determine |
147 | bool folderDoesNotExist(const QString& wallet, const QString& folder); |
148 | bool keyDoesNotExist(const QString& wallet, const QString& folder, const QString& key); |
149 | |
150 | void closeAllWallets(); |
151 | |
152 | QString networkWallet(); |
153 | |
154 | QString localWallet(); |
155 | |
156 | void screenSaverChanged(bool); |
157 | |
158 | // Open a wallet using a pre-hashed password. This is only useful in cooperation |
159 | // with the kwallet PAM module. It's also less secure than manually entering the |
160 | // password as the password hash is transmitted using D-Bus. |
161 | int pamOpen(const QString &wallet, const QByteArray &passwordHash, int sessionTimeout); |
162 | |
163 | Q_SIGNALS: |
164 | void walletAsyncOpened(int id, int handle); // used to notify KWallet::Wallet |
165 | void walletListDirty(); |
166 | void walletCreated(const QString& wallet); |
167 | void walletOpened(const QString& wallet); |
168 | void walletDeleted(const QString& wallet); |
169 | void walletClosed(const QString& wallet); |
170 | void walletClosed(int handle); |
171 | void allWalletsClosed(); |
172 | void folderListUpdated(const QString& wallet); |
173 | void folderUpdated(const QString&, const QString&); |
174 | void applicationDisconnected(const QString& wallet, const QString& application); |
175 | |
176 | private Q_SLOTS: |
177 | void slotServiceOwnerChanged(const QString& name, const QString &oldOwner, |
178 | const QString &newOwner); |
179 | void emitWalletListDirty(); |
180 | void timedOutClose(int handle); |
181 | void timedOutSync(int handle); |
182 | void notifyFailures(); |
183 | void processTransactions(); |
184 | void activatePasswordDialog(); |
185 | #ifdef Q_WS_X11 |
186 | void connectToScreenSaver(); |
187 | #endif |
188 | |
189 | private: |
190 | // Internal - open a wallet |
191 | int internalOpen(const QString& appid, const QString& wallet, bool isPath, WId w, |
192 | bool modal, const QString& service); |
193 | // Internal - close this wallet. |
194 | int internalClose(KWallet::Backend *w, int handle, bool force); |
195 | |
196 | bool isAuthorizedApp(const QString& appid, const QString& wallet, WId w); |
197 | // This also validates the handle. May return NULL. |
198 | KWallet::Backend* getWallet(const QString& appid, int handle); |
199 | // Generate a new unique handle. |
200 | int generateHandle(); |
201 | // Emit signals about closing wallets |
202 | void doCloseSignals(int,const QString&); |
203 | void emitFolderUpdated(const QString&, const QString&); |
204 | // Implicitly allow access for this application |
205 | bool implicitAllow(const QString& wallet, const QString& app); |
206 | bool implicitDeny(const QString& wallet, const QString& app); |
207 | |
208 | void doTransactionChangePassword(const QString& appid, const QString& wallet, qlonglong wId); |
209 | void doTransactionOpenCancelled(const QString& appid, const QString& wallet, |
210 | const QString& service); |
211 | int doTransactionOpen(const QString& appid, const QString& wallet, bool isPath, |
212 | qlonglong wId, bool modal, const QString& service); |
213 | void initiateSync(int handle); |
214 | |
215 | void setupDialog( QWidget* dialog, WId wId, const QString& appid, bool modal ); |
216 | void checkActiveDialog(); |
217 | |
218 | QPair<int, KWallet::Backend*> findWallet(const QString& walletName) const; |
219 | |
220 | typedef QHash<int, KWallet::Backend *> Wallets; |
221 | Wallets _wallets; |
222 | KDirWatch *_dw; |
223 | int _failed; |
224 | |
225 | // configuration values |
226 | bool _leaveOpen, _closeIdle, _launchManager, _enabled; |
227 | bool _openPrompt, _firstUse, _showingFailureNotify; |
228 | int _idleTime; |
229 | QMap<QString,QStringList> _implicitAllowMap, _implicitDenyMap; |
230 | KTimeout _closeTimers; |
231 | KTimeout _syncTimers; |
232 | const int _syncTime; |
233 | static bool _processing; |
234 | |
235 | KWalletTransaction *_curtrans; // current transaction |
236 | QList<KWalletTransaction*> _transactions; |
237 | QPointer< QWidget > activeDialog; |
238 | |
239 | #ifdef Q_WS_X11 |
240 | QDBusInterface *screensaver; |
241 | #endif |
242 | |
243 | // sessions |
244 | KWalletSessionStore _sessions; |
245 | QDBusServiceWatcher _serviceWatcher; |
246 | |
247 | bool _useGpg; |
248 | }; |
249 | |
250 | |
251 | #endif |
252 | |