File indexing completed on 2024-04-21 16:20:07
0001 /* 0002 SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com> 0003 SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com> 0004 SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef PLASMA_NM_SECRET_AGENT_H 0010 #define PLASMA_NM_SECRET_AGENT_H 0011 0012 #include <NetworkManagerQt/SecretAgent> 0013 0014 namespace KWallet 0015 { 0016 class Wallet; 0017 } 0018 0019 class PasswordDialog; 0020 0021 class SecretsRequest 0022 { 0023 public: 0024 enum Type { 0025 GetSecrets, 0026 SaveSecrets, 0027 DeleteSecrets, 0028 }; 0029 explicit SecretsRequest(Type _type) 0030 : type(_type) 0031 { 0032 } 0033 inline bool operator==(const QString &other) const 0034 { 0035 return callId == other; 0036 } 0037 Type type; 0038 QString callId; 0039 NMVariantMapMap connection; 0040 QDBusObjectPath connection_path; 0041 QString setting_name; 0042 QStringList hints; 0043 NetworkManager::SecretAgent::GetSecretsFlags flags = NetworkManager::SecretAgent::None; 0044 /** 0045 * When a user connection is called on GetSecrets, 0046 * the secret agent is supposed to save the secrets 0047 * typed by user, when true proccessSaveSecrets 0048 * should skip the DBus reply. 0049 */ 0050 bool saveSecretsWithoutReply = false; 0051 QDBusMessage message; 0052 PasswordDialog *dialog = nullptr; 0053 }; 0054 0055 class Q_DECL_EXPORT SecretAgent : public NetworkManager::SecretAgent 0056 { 0057 Q_OBJECT 0058 public: 0059 explicit SecretAgent(QObject *parent = nullptr); 0060 explicit SecretAgent(NetworkManager::SecretAgent::Capabilities capabilities, QObject *parent = nullptr); 0061 0062 ~SecretAgent() override; 0063 0064 Q_SIGNALS: 0065 void secretsError(const QString &connectionPath, const QString &message) const; 0066 0067 public Q_SLOTS: 0068 NMVariantMapMap GetSecrets(const NMVariantMapMap &, const QDBusObjectPath &, const QString &, const QStringList &, uint) override; 0069 void SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) override; 0070 void DeleteSecrets(const NMVariantMapMap &, const QDBusObjectPath &) override; 0071 void CancelGetSecrets(const QDBusObjectPath &, const QString &) override; 0072 0073 private Q_SLOTS: 0074 void dialogAccepted(); 0075 void dialogRejected(); 0076 void killDialogs(); 0077 void walletOpened(bool success); 0078 void walletClosed(); 0079 0080 private: 0081 void processNext(); 0082 /** 0083 * @brief processGetSecrets requests 0084 * @param request the request we are processing 0085 * @param ignoreWallet true if the code should avoid Wallet 0086 * normally if it failed to open 0087 * @return true if the item was processed 0088 */ 0089 bool processGetSecrets(SecretsRequest &request) const; 0090 bool processSaveSecrets(SecretsRequest &request) const; 0091 bool processDeleteSecrets(SecretsRequest &request) const; 0092 /** 0093 * @brief useWallet checks if the KWallet system is enabled 0094 * and tries to open it async. 0095 * @return return true if the method should use the wallet, 0096 * the caller MUST always check if the wallet is opened. 0097 */ 0098 bool useWallet() const; 0099 0100 /** 0101 * @brief hasSecrets verifies if the desired connection has secrets to store 0102 * @param connection map with or without secrets 0103 * @return true if the connection has secrets, false otherwise 0104 */ 0105 bool hasSecrets(const NMVariantMapMap &connection) const; 0106 void sendSecrets(const NMVariantMapMap &secrets, const QDBusMessage &message) const; 0107 0108 mutable bool m_openWalletFailed; 0109 mutable KWallet::Wallet *m_wallet; 0110 mutable PasswordDialog *m_dialog; 0111 QList<SecretsRequest> m_calls; 0112 0113 void importSecretsFromPlainTextFiles(); 0114 }; 0115 0116 #endif // PLASMA_NM_SECRET_AGENT_H