File indexing completed on 2024-06-09 04:00:42

0001 /*
0002     SPDX-FileCopyrightText: 2009 Pino Toscano <pino@kde.org>
0003     SPDX-FileCopyrightText: 2009-2012 Lukáš Tinkl <ltinkl@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef UDISKSSTORAGEACCESS_H
0009 #define UDISKSSTORAGEACCESS_H
0010 
0011 #include "udisksdeviceinterface.h"
0012 #include <solid/devices/ifaces/storageaccess.h>
0013 
0014 #include <QDBusError>
0015 #include <QDBusMessage>
0016 
0017 namespace Solid
0018 {
0019 namespace Backends
0020 {
0021 namespace UDisks2
0022 {
0023 class StorageAccess : public DeviceInterface, virtual public Solid::Ifaces::StorageAccess
0024 {
0025     Q_OBJECT
0026     Q_INTERFACES(Solid::Ifaces::StorageAccess)
0027 
0028 public:
0029     StorageAccess(Device *device);
0030     ~StorageAccess() override;
0031 
0032     bool isAccessible() const override;
0033     QString filePath() const override;
0034     bool isIgnored() const override;
0035     bool setup() override;
0036     bool teardown() override;
0037     bool isEncrypted() const override;
0038 
0039 Q_SIGNALS:
0040     void accessibilityChanged(bool accessible, const QString &udi) override;
0041     void setupDone(Solid::ErrorType error, QVariant errorData, const QString &udi) override;
0042     void teardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi) override;
0043     void setupRequested(const QString &udi) override;
0044     void teardownRequested(const QString &udi) override;
0045 
0046 public Q_SLOTS:
0047     Q_SCRIPTABLE Q_NOREPLY void passphraseReply(const QString &passphrase);
0048 
0049 private Q_SLOTS:
0050     void slotDBusReply(const QDBusMessage &reply);
0051     void slotDBusError(const QDBusError &error);
0052 
0053     void connectDBusSignals();
0054 
0055     void slotSetupRequested();
0056     void slotSetupDone(int error, const QString &errorString);
0057     void slotTeardownRequested();
0058     void slotTeardownDone(int error, const QString &errorString);
0059 
0060     void checkAccessibility();
0061 
0062 private:
0063     /// @return true if this device is luks and unlocked
0064     bool isLuksDevice() const;
0065 
0066     void updateCache();
0067 
0068     bool mount();
0069     bool unmount();
0070 
0071     bool requestPassphrase();
0072     void callCryptoSetup(const QString &passphrase);
0073     bool callCryptoTeardown(bool actOnParent = false);
0074 
0075     QString generateReturnObjectPath();
0076     QString clearTextPath() const;
0077 
0078 private:
0079     bool m_isAccessible;
0080     bool m_setupInProgress;
0081     bool m_teardownInProgress;
0082     bool m_passphraseRequested;
0083     QString m_lastReturnObject;
0084 
0085     static const int s_unmountTimeout = 0x7fffffff;
0086 };
0087 }
0088 }
0089 }
0090 
0091 #endif // UDISKSSTORAGEACCESS_H