signon 8.54

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

crypto-handlers.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of signon
4 *
5 * Copyright (C) 2009-2011 Nokia Corporation.
6 *
7 * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
8 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * version 2.1 as published by the Free Software Foundation.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25
32 #ifndef SIGNON_CRYPTSETUP_HANDLER_H
33 #define SIGNON_CRYPTSETUP_HANDLER_H
34
35 #include <QProcess>
36 #include <QMap>
37 #include <QFile>
38
39
44 class SystemCommandLineCallHandler: public QObject
45 {
46 Q_OBJECT
47
48 public:
52 SystemCommandLineCallHandler();
53
57 ~SystemCommandLineCallHandler();
58
67 bool makeCall(const QString &appPath,
68 const QStringList &args,
69 bool readOutput = false);
70
75 QByteArray output() const { return m_output; }
76
77 private Q_SLOTS:
78 void error(QProcess::ProcessError err);
79
80 private:
81 QProcess m_process;
82 QByteArray m_output;
83
84 Q_DISABLE_COPY(SystemCommandLineCallHandler);
85 };
86
91 struct PartitionHandler
92 {
93 enum {
94 Ext2 = 0,
95 Ext3,
96 Ext4
97 };
103 static bool createPartitionFile(const QString &fileName,
104 const quint32 fileSize);
105
113 static bool formatPartitionFile(const QString &fileName,
114 const quint32 fileSystemType);
115
116 private:
120 PartitionHandler();
121 Q_DISABLE_COPY(PartitionHandler)
122 };
123
124
128 struct MountHandler
129 {
137 static bool mount(const QString &source,
138 const QString &target,
139 const QString &fileSystemType = QLatin1String("ext2"));
145 static bool umount(const QString &target);
146
147 private:
151 MountHandler();
152 Q_DISABLE_COPY(MountHandler)
153 };
154
155
161 struct LosetupHandler
162 {
168 static bool setupDevice(const QString &deviceName,
169 const QString &blockDevice);
170
175 static QString findAvailableDevice();
176
182 static bool releaseDevice(const QString &deviceName);
183
184 private:
188 LosetupHandler();
189 Q_DISABLE_COPY(LosetupHandler)
190 };
191
192
199 struct CryptsetupHandler
200 {
206 static bool formatFile(const QByteArray &key, const QString &deviceName);
207
214 static bool openFile(const QByteArray &key,
215 const QString &deviceName,
216 const QString &deviceMap);
217
222 static bool closeFile(const QString &deviceName);
223
229 static bool removeFile(const QString &deviceName);
230
240 static bool addKeySlot(const QString &deviceName,
241 const QByteArray &key,
242 const QByteArray &existingKey);
243
251 static bool removeKeySlot(const QString &deviceName,
252 const QByteArray &key,
253 const QByteArray &remainingKey);
254
259 static bool loadDmMod();
260
264 static QString error();
265
266 private:
270 CryptsetupHandler();
271 Q_DISABLE_COPY(CryptsetupHandler)
272 };
273
274 #endif // SIGNON_CRYPTSETUP_HANDLER_H
LosetupHandler::setupDevice
static bool setupDevice(const QString &deviceName, const QString &blockDevice)
Mounts a block device to loopback device.
Definition: crypto-handlers.cpp:203
SystemCommandLineCallHandler::makeCall
bool makeCall(const QString &appPath, const QStringList &args, bool readOutput=false)
Executes the application at appPath in a separate child process.
Definition: crypto-handlers.cpp:68
PartitionHandler::formatPartitionFile
static bool formatPartitionFile(const QString &fileName, const quint32 fileSystemType)
Formats a file (block device) for a specific file system type (ext2,ext3,ext4)
Definition: crypto-handlers.cpp:142
PartitionHandler::createPartitionFile
static bool createPartitionFile(const QString &fileName, const quint32 fileSize)
Creates a random data file of fileSize Mb.
Definition: crypto-handlers.cpp:113
CryptsetupHandler
Wraps the libcryptsetup API functionality.
Definition: crypto-handlers.h:199
SystemCommandLineCallHandler::~SystemCommandLineCallHandler
~SystemCommandLineCallHandler()
Destructor.
Definition: crypto-handlers.cpp:64
PartitionHandler::Ext2
Definition: crypto-handlers.h:94
SystemCommandLineCallHandler::output
QByteArray output() const
Definition: crypto-handlers.h:75
CryptsetupHandler::formatFile
static bool formatFile(const QByteArray &key, const QString &deviceName)
Formats the file system.
Definition: crypto-handlers.cpp:313
SystemCommandLineCallHandler::SystemCommandLineCallHandler
SystemCommandLineCallHandler()
Basic constructor.
Definition: crypto-handlers.cpp:58
PartitionHandler
Definition: crypto-handlers.h:91
CryptsetupHandler::loadDmMod
static bool loadDmMod()
Loads the dm_mod kernel module.
Definition: crypto-handlers.cpp:652
CryptsetupHandler::closeFile
static bool closeFile(const QString &deviceName)
Closes the file system.
Definition: crypto-handlers.cpp:464
MountHandler::umount
static bool umount(const QString &target)
Unmounts a block device from a specific location.
Definition: crypto-handlers.cpp:173
CryptsetupHandler::error
static QString error()
Definition: crypto-handlers.cpp:660
LosetupHandler
Handles mounting, unmounting of loopback devices.
Definition: crypto-handlers.h:161
CryptsetupHandler::removeFile
static bool removeFile(const QString &deviceName)
Removes the file system.
Definition: crypto-handlers.cpp:492
MountHandler
Handles mounting and unmounting of file systems.
Definition: crypto-handlers.h:128
SystemCommandLineCallHandler
Handles calls to system command line tools.
Definition: crypto-handlers.h:44
CryptsetupHandler::removeKeySlot
static bool removeKeySlot(const QString &deviceName, const QByteArray &key, const QByteArray &remainingKey)
Removes a key ocupying an encryption header slot.
Definition: crypto-handlers.cpp:614
CryptsetupHandler::addKeySlot
static bool addKeySlot(const QString &deviceName, const QByteArray &key, const QByteArray &existingKey)
Adds a key to a free encryption header slot.
Definition: crypto-handlers.cpp:533
PartitionHandler::Ext3
Definition: crypto-handlers.h:95
PartitionHandler::Ext4
Definition: crypto-handlers.h:96
MountHandler::mount
static bool mount(const QString &source, const QString &target, const QString &fileSystemType=QLatin1String("ext2"))
Mounts a block device to a specific location.
Definition: crypto-handlers.cpp:162
LosetupHandler::releaseDevice
static bool releaseDevice(const QString &deviceName)
Releases a used loopback device.
Definition: crypto-handlers.cpp:229
LosetupHandler::findAvailableDevice
static QString findAvailableDevice()
Finds an available loopback device.
Definition: crypto-handlers.cpp:212
CryptsetupHandler::openFile
static bool openFile(const QByteArray &key, const QString &deviceName, const QString &deviceMap)
Opens the file system.
Definition: crypto-handlers.cpp:404