From: hama Date: Sun, 2 Oct 2016 08:40:01 +0000 (+0200) Subject: rebackgui: enforce shadow dir, format check X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=64130a96aba19273a3edbe89a74e6900579e7899;p=reqt rebackgui: enforce shadow dir, format check * creation of the shadow directory with sudo (if not exists) * no crash if ';' is missed in the target * new ReProcess.cpp --- diff --git a/.gitignore b/.gitignore index 76d98cb..f39780d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ appl/build-reidos-Desktop-Debug/ .metadata 2github +.rebackgui.target +appl/build-rebackgui-Desktop_Qt_5_6_0_GCC_64bit-Debug/ +appl/rebackgui/.rebackgui.target diff --git a/appl/rebackgui/BackupEngine.cpp b/appl/rebackgui/BackupEngine.cpp index 4a4cb32..639cda2 100644 --- a/appl/rebackgui/BackupEngine.cpp +++ b/appl/rebackgui/BackupEngine.cpp @@ -935,6 +935,39 @@ void SearchTargetTask::searchOneDirectory(const QString& target, } } +/** + * Creates the base directory for shadowing. + * + * @param base the full path of the base directory + * @return true: the base directory exists and is writeable + */ +bool SearchTargetTask::ensureShadowBase(const QString& base){ + bool rc = ReFileUtils::isDirectory(base); + if (! rc){ +#if defined __linux__ + QStringList args; + args << "/bin/mkdir" << base; + QByteArray errorMsg; + ReSuccess_t rc2 = ReProcess::executeSilent("/usr/bin/sudo", args, 30, &errorMsg); + if (! rc2) + error(QString(errorMsg)); + + rc = ReFileUtils::isDirectory(base); +#endif + } +#if defined __linux__ + if (rc){ + QStringList args; + args.clear(); args << "/bin/chmod" << "uog=rwx" << base; + QByteArray errorMsg; + ReSuccess_t rc2 = ReProcess::executeSilent("/usr/bin/sudo", args, 30, &errorMsg); + if (! rc2) + error(QString(errorMsg)); + } +#endif + return rc; +} + /** * Moves a target directory to the shadow directory and delegate the removing files. * @@ -949,20 +982,19 @@ void SearchTargetTask::moveToShadow(const QString& target, const QString& relPat QString targetName = shadowDir; int pos = targetName.length() / 2; while(pos < shadowDir.length()){ - char cc = '0' - 1; - do{ - targetName[pos] = ++cc; - } while (cc <= 'Z' && QFileInfo(targetName).exists()); - if (cc <= 'Z'){ - if (rename(I18N::s2b(shadowDir).constData(), - I18N::s2b(targetName).constData()) != 0) - error(QObject::tr("kann Schattenverzeichnis nicht umbenennen: %1 -> %2") - .arg(shadowDir, targetName)); - else break; - } - pos++; + char cc = '0' - 1; + do{ + targetName[pos] = ++cc; + } while (cc <= 'Z' && QFileInfo(targetName).exists()); + if (cc <= 'Z'){ + if (rename(I18N::s2b(shadowDir).constData(), + I18N::s2b(targetName).constData()) != 0) + error(QObject::tr("kann Schattenverzeichnis nicht umbenennen: %1 -> %2") + .arg(shadowDir, targetName)); + else break; + } + pos++; } - } if (! ReFileUtils::makeDirWithParents(shadowDir)){ @@ -987,6 +1019,7 @@ void SearchTargetTask::run() qint64 start = QDateTime::currentMSecsSinceEpoch(); m_searchReady = false; QString targetDir, sourceDir; + ensureShadowBase(m_shadowBaseDir); for (int ix = 0; ! m_shouldStop && ix < m_sourceDirs.size(); ix++){ sourceDir = m_sourceDirs.at(ix); targetDir = m_targetDirs.at(ix); diff --git a/appl/rebackgui/BackupEngine.hpp b/appl/rebackgui/BackupEngine.hpp index 598eac1..5b68fc2 100644 --- a/appl/rebackgui/BackupEngine.hpp +++ b/appl/rebackgui/BackupEngine.hpp @@ -191,6 +191,7 @@ public: public: virtual void run(); private: + bool ensureShadowBase(const QString& base); void moveToShadow(const QString& target, const QString& relPath, int index); bool removeOlder(const QString& directory, const QDateTime& time); void searchOneDirectory(const QString& target, const QString& source, diff --git a/appl/rebackgui/BackupUtils.cpp b/appl/rebackgui/BackupUtils.cpp index 41e5d13..ed5c8f8 100644 --- a/appl/rebackgui/BackupUtils.cpp +++ b/appl/rebackgui/BackupUtils.cpp @@ -13,6 +13,7 @@ enum { LOC_FIND_TARGET_1 = LOC_FIRST_OF(LOC_REBACKGUI_BACKUPUTILS), // 20501 LOC_FIND_TARGET_2, // 20502 + LOC_FIND_TARGET_3, // 20503 }; @@ -89,29 +90,34 @@ QString BackupUtils::findTarget(const BackupItem& item, MainWindow& mainWindow, rc = item.m_target.mid(1); } else { ReBlockDevices& devices = ReBlockDevices::instance(); - QStringList parts = item.m_target.split(';'); - QStringList args; - QString label = parts.at(0); - QString relativePath = parts.at(1); - if (label.startsWith("L=")) - label = label.mid(2); - const ReBlockDevice* device = devices.findByLabel(label); - if (device != NULL){ - ReMountInfo& mountInfo = ReMountInfo::instance(); - if (mountInfo.m_mountPointOfDevice.contains(device->m_device)){ - rc = mountInfo.m_mountPointOfDevice.value(device->m_device); - + OS_SEPARATOR + relativePath; - } else { - QStringList args; - QString mountPath = "/media/" + label; - ReFileUtils::makeDir(mountPath, mainWindow.logger()); + if (item.m_target.indexOf(';') < 0) { + mainWindow.say(LOG_ERROR, QObject::tr("wrong target format. Missing ';': %1").arg( + item.m_target)); + } else { + QStringList parts = item.m_target.split(';'); + QStringList args; + QString label = parts.at(0); + QString relativePath = parts.at(1); + if (label.startsWith("L=")) + label = label.mid(2); + const ReBlockDevice* device = devices.findByLabel(label); + if (device != NULL){ + ReMountInfo& mountInfo = ReMountInfo::instance(); + if (mountInfo.m_mountPointOfDevice.contains(device->m_device)){ + rc = mountInfo.m_mountPointOfDevice.value(device->m_device) + + OS_SEPARATOR + relativePath; + } else { + QStringList args; + QString mountPath = "/media/" + label; + ReFileUtils::makeDir(mountPath, mainWindow.logger()); - if (ReMountInfo::mount(device->m_device, mountPath, &mainWindow)){ - tempoararyMounted = device->m_device; - } - } - } - } + if (ReMountInfo::mount(device->m_device, mountPath, &mainWindow)){ + tempoararyMounted = device->m_device; + } + } + } + } + } #elif defined _WIN32 (void) tempoararyMounted; QStringList drives = ReFileUtils::findRootDirs(); diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 1f41ef4..a172085 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -16,7 +16,7 @@ #include "base/retrace.hpp" DECLARE_TRACER(s_traceMain, "/tmp/bup_main.log"); -const QString VERSION("2016.06.01"); +const QString VERSION("2016.10.01"); /** * Constructor. diff --git a/appl/refind/ReProcess.cpp b/appl/refind/ReProcess.cpp new file mode 120000 index 0000000..81ea9b6 --- /dev/null +++ b/appl/refind/ReProcess.cpp @@ -0,0 +1 @@ +../../base/ReProcess.cpp \ No newline at end of file