signon
8.58
|
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of signon 00004 * 00005 * Copyright (C) 2009-2011 Nokia Corporation. 00006 * 00007 * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com> 00008 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public License 00012 * version 2.1 as published by the Free Software Foundation. 00013 * 00014 * This library is distributed in the hope that it will be useful, but 00015 * WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00022 * 02110-1301 USA 00023 */ 00024 00025 00032 #ifndef SIGNON_CRYPTSETUP_HANDLER_H 00033 #define SIGNON_CRYPTSETUP_HANDLER_H 00034 00035 #include <QProcess> 00036 #include <QMap> 00037 #include <QFile> 00038 00039 00044 class SystemCommandLineCallHandler: public QObject 00045 { 00046 Q_OBJECT 00047 00048 public: 00052 SystemCommandLineCallHandler(); 00053 00057 ~SystemCommandLineCallHandler(); 00058 00067 bool makeCall(const QString &appPath, 00068 const QStringList &args, 00069 bool readOutput = false); 00070 00075 QByteArray output() const { return m_output; } 00076 00077 private Q_SLOTS: 00078 void error(QProcess::ProcessError err); 00079 00080 private: 00081 QProcess m_process; 00082 QByteArray m_output; 00083 00084 Q_DISABLE_COPY(SystemCommandLineCallHandler); 00085 }; 00086 00091 struct PartitionHandler 00092 { 00093 enum { 00094 Ext2 = 0, 00095 Ext3, 00096 Ext4 00097 }; 00103 static bool createPartitionFile(const QString &fileName, 00104 const quint32 fileSize); 00105 00113 static bool formatPartitionFile(const QString &fileName, 00114 const quint32 fileSystemType); 00115 00116 private: 00120 PartitionHandler(); 00121 Q_DISABLE_COPY(PartitionHandler) 00122 }; 00123 00124 00128 struct MountHandler 00129 { 00137 static bool mount(const QString &source, 00138 const QString &target, 00139 const QString &fileSystemType = QLatin1String("ext2")); 00145 static bool umount(const QString &target); 00146 00147 private: 00151 MountHandler(); 00152 Q_DISABLE_COPY(MountHandler) 00153 }; 00154 00155 00161 struct LosetupHandler 00162 { 00168 static bool setupDevice(const QString &deviceName, 00169 const QString &blockDevice); 00170 00175 static QString findAvailableDevice(); 00176 00182 static bool releaseDevice(const QString &deviceName); 00183 00184 private: 00188 LosetupHandler(); 00189 Q_DISABLE_COPY(LosetupHandler) 00190 }; 00191 00192 00199 struct CryptsetupHandler 00200 { 00206 static bool formatFile(const QByteArray &key, const QString &deviceName); 00207 00214 static bool openFile(const QByteArray &key, 00215 const QString &deviceName, 00216 const QString &deviceMap); 00217 00222 static bool closeFile(const QString &deviceName); 00223 00229 static bool removeFile(const QString &deviceName); 00230 00240 static bool addKeySlot(const QString &deviceName, 00241 const QByteArray &key, 00242 const QByteArray &existingKey); 00243 00251 static bool removeKeySlot(const QString &deviceName, 00252 const QByteArray &key, 00253 const QByteArray &remainingKey); 00254 00259 static bool loadDmMod(); 00260 00264 static QString error(); 00265 00266 private: 00270 CryptsetupHandler(); 00271 Q_DISABLE_COPY(CryptsetupHandler) 00272 }; 00273 00274 #endif // SIGNON_CRYPTSETUP_HANDLER_H