Sandboxie/SandboxiePlus/SandMan/Windows/NewBoxWindow.cpp

118 lines
4.1 KiB
C++
Raw Normal View History

2021-10-16 16:19:51 +01:00
#include "stdafx.h"
#include "NewBoxWindow.h"
#include "SandMan.h"
#include "../MiscHelpers/Common/Settings.h"
2022-04-16 14:12:32 +01:00
#include "Views/SbieView.h"
2021-10-16 16:19:51 +01:00
CNewBoxWindow::CNewBoxWindow(QWidget *parent)
: QDialog(parent)
{
Qt::WindowFlags flags = windowFlags();
flags |= Qt::CustomizeWindowHint;
//flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
//flags &= ~Qt::WindowMinMaxButtonsHint;
//flags |= Qt::WindowMinimizeButtonHint;
//flags &= ~Qt::WindowCloseButtonHint;
flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
setWindowFlags(flags);
ui.setupUi(this);
this->setWindowTitle(tr("Sandboxie-Plus - Create New Box"));
connect(ui.buttonBox, SIGNAL(accepted()), SLOT(CreateBox()));
connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
QMap<QString, CSandBoxPtr> Boxes = theAPI->GetAllBoxes();
for (int i=0;; i++) {
QString NewName = tr("New Box");
if (i > 0) NewName.append(" " + QString::number(i));
if (Boxes.contains(NewName.toLower().replace(" ", "_")))
continue;
ui.txtName->setText(NewName);
break;
}
2021-11-13 08:28:32 +00:00
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eHardenedPlus), tr("Hardened Sandbox with Data Protection"), (int)CSandBoxPlus::eHardenedPlus);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eHardened), tr("Security Hardened Sandbox"), (int)CSandBoxPlus::eHardened);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eDefaultPlus), tr("Sandbox with Data Protection"), (int)CSandBoxPlus::eDefaultPlus);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eDefault), tr("Standard Isolation Sandbox (Default)"), (int)CSandBoxPlus::eDefault);
//ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eInsecure), tr("UNSECURE Configuration (please change)"), (int)CSandBoxPlus::eInsecure);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBoxPlus), tr("Application Compartment with Data Protection"), (int)CSandBoxPlus::eAppBoxPlus);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBox), tr("Application Compartment (NO Isolation)"), (int)CSandBoxPlus::eAppBox);
2021-10-16 16:19:51 +01:00
2021-11-13 08:28:32 +00:00
connect(ui.cmbBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(OnBoxTypChanged()));
ui.cmbBoxType->setCurrentIndex(3); // default
2021-10-16 16:19:51 +01:00
ui.txtName->setFocus();
//restoreGeometry(theConf->GetBlob("NewBoxWindow/Window_Geometry"));
}
CNewBoxWindow::~CNewBoxWindow()
{
//theConf->SetBlob("NewBoxWindow/Window_Geometry", saveGeometry());
}
2021-11-13 08:28:32 +00:00
void CNewBoxWindow::OnBoxTypChanged()
2021-10-16 16:19:51 +01:00
{
2021-11-13 08:28:32 +00:00
int BoxType = ui.cmbBoxType->currentData().toInt();
ui.lblBoxInfo->setText(theGUI->GetBoxDescription(BoxType));
if(BoxType != CSandBoxPlus::eDefault && BoxType != CSandBoxPlus::eHardened)
theGUI->CheckCertificate();
2021-10-16 16:19:51 +01:00
}
void CNewBoxWindow::CreateBox()
{
m_Name = ui.txtName->text();
2021-11-13 08:28:32 +00:00
int BoxType = ui.cmbBoxType->currentData().toInt();
2021-10-16 16:19:51 +01:00
2022-04-16 14:01:01 +01:00
if (!theGUI->GetBoxView()->TestNameAndWarn(m_Name))
return;
m_Name.replace(" ", "_");
2021-11-13 08:28:32 +00:00
SB_STATUS Status = theAPI->CreateBox(m_Name, true);
2021-10-16 16:19:51 +01:00
if (!Status.IsError())
{
CSandBoxPtr pBox = theAPI->GetBoxByName(m_Name);
2021-11-13 08:28:32 +00:00
switch (BoxType)
2021-10-16 16:19:51 +01:00
{
2021-11-13 08:28:32 +00:00
case CSandBoxPlus::eHardenedPlus:
case CSandBoxPlus::eHardened:
//pBox->SetBool("NoSecurityIsolation", false);
pBox->SetBool("DropAdminRights", true);
//pBox->SetBool("MsiInstallerExemptions", false);
pBox->SetBool("UsePrivacyMode", BoxType == CSandBoxPlus::eHardenedPlus);
break;
case CSandBoxPlus::eDefaultPlus:
case CSandBoxPlus::eDefault:
//pBox->SetBool("NoSecurityIsolation", false);
//pBox->SetBool("DropAdminRights", false);
//pBox->SetBool("MsiInstallerExemptions", false);
//pBox->SetBool("RunServicesAsSystem", false);
pBox->SetBool("UsePrivacyMode", BoxType == CSandBoxPlus::eDefaultPlus);
2021-10-16 16:19:51 +01:00
break;
2021-11-13 08:28:32 +00:00
case CSandBoxPlus::eAppBoxPlus:
case CSandBoxPlus::eAppBox:
pBox->SetBool("NoSecurityIsolation", true);
//pBox->SetBool("RunServicesAsSystem", true);
pBox->SetBool("UsePrivacyMode", BoxType == CSandBoxPlus::eAppBoxPlus);
2022-02-04 21:08:25 +00:00
//pBox->InsertText("Template", "NoUACProxy"); // proxy is always needed for exes in the box
2021-10-16 16:19:51 +01:00
break;
}
}
if(Status.IsError())
CSandMan::CheckResults(QList<SB_STATUS>() << Status);
else
accept();
}