Sandboxie/SandboxiePlus/SandMan/Windows/OptionsAccess.cpp

611 lines
20 KiB
C++
Raw Normal View History

2021-10-16 16:19:51 +01:00
#include "stdafx.h"
#include "OptionsWindow.h"
#include "SandMan.h"
#include "SettingsWindow.h"
#include "../MiscHelpers/Common/Settings.h"
#include "../MiscHelpers/Common/Common.h"
#include "../MiscHelpers/Common/ComboInputDialog.h"
#include "../MiscHelpers/Common/SettingsWidgets.h"
2022-08-28 11:43:08 +01:00
#include "../MiscHelpers/Common/CheckableMessageBox.h"
2021-10-16 16:19:51 +01:00
#include "Helpers/WinAdmin.h"
void COptionsWindow::CreateAccess()
{
2021-11-13 08:28:32 +00:00
// Resource Access
connect(ui.chkPrivacy, SIGNAL(clicked(bool)), this, SLOT(OnAccessChanged()));
connect(ui.chkUseSpecificity, SIGNAL(clicked(bool)), this, SLOT(OnAccessChanged()));
connect(ui.chkCloseForBox, SIGNAL(clicked(bool)), this, SLOT(OnAccessChanged()));
connect(ui.chkNoOpenForBox, SIGNAL(clicked(bool)), this, SLOT(OnAccessChanged()));
//
2021-10-16 16:19:51 +01:00
connect(ui.btnAddFile, SIGNAL(clicked(bool)), this, SLOT(OnAddFile()));
QMenu* pFileBtnMenu = new QMenu(ui.btnAddFile);
pFileBtnMenu->addAction(tr("Browse for File"), this, SLOT(OnBrowseFile()));
pFileBtnMenu->addAction(tr("Browse for Folder"), this, SLOT(OnBrowseFolder()));
ui.btnAddFile->setPopupMode(QToolButton::MenuButtonPopup);
ui.btnAddFile->setMenu(pFileBtnMenu);
connect(ui.btnAddKey, SIGNAL(clicked(bool)), this, SLOT(OnAddKey()));
connect(ui.btnAddIPC, SIGNAL(clicked(bool)), this, SLOT(OnAddIPC()));
connect(ui.btnAddWnd, SIGNAL(clicked(bool)), this, SLOT(OnAddWnd()));
connect(ui.btnAddCOM, SIGNAL(clicked(bool)), this, SLOT(OnAddCOM()));
connect(ui.chkShowAccessTmpl, SIGNAL(clicked(bool)), this, SLOT(OnShowAccessTmpl()));
connect(ui.btnDelAccess, SIGNAL(clicked(bool)), this, SLOT(OnDelAccess()));
//connect(ui.treeAccess, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(OnAccessItemClicked(QTreeWidgetItem*, int)));
connect(ui.treeAccess, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(OnAccessItemDoubleClicked(QTreeWidgetItem*, int)));
connect(ui.treeAccess, SIGNAL(itemSelectionChanged()), this, SLOT(OnAccessSelectionChanged()));
2021-12-03 19:26:09 +00:00
connect(ui.treeAccess, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(OnAccessChanged(QTreeWidgetItem *, int)));
2021-10-16 16:19:51 +01:00
}
2021-11-13 08:28:32 +00:00
void COptionsWindow::OnAccessChanged()
{
2022-08-15 08:35:36 +01:00
if (sender() == ui.chkPrivacy || sender() == ui.chkUseSpecificity) {
if (ui.chkPrivacy->isChecked() || (ui.chkUseSpecificity->isEnabled() && ui.chkUseSpecificity->isChecked()))
theGUI->CheckCertificate(this);
}
2021-11-13 08:28:32 +00:00
UpdateAccessPolicy();
2022-08-14 16:40:55 +01:00
if ((sender() == ui.chkPrivacy || sender() == ui.chkRestrictDevices) && !(ui.chkPrivacy->isChecked() || ui.chkRestrictDevices->isChecked())) {
ui.chkUseSpecificity->setChecked(m_pBox->GetBool("UseRuleSpecificity", false));
}
2021-11-13 08:28:32 +00:00
m_AccessChanged = true;
OnOptChanged();
}
void COptionsWindow::UpdateAccessPolicy()
{
2022-08-14 16:40:55 +01:00
ui.chkUseSpecificity->setEnabled(!(ui.chkPrivacy->isChecked() || ui.chkRestrictDevices->isChecked()));
2022-08-09 17:19:46 +01:00
if (ui.chkPrivacy->isChecked() || ui.chkRestrictDevices->isChecked()) {
2021-11-13 08:28:32 +00:00
ui.chkUseSpecificity->setChecked(true);
}
}
2021-10-16 16:19:51 +01:00
QTreeWidgetItem* COptionsWindow::GetAccessEntry(EAccessType Type, const QString& Program, EAccessMode Mode, const QString& Path)
{
for (int i = 0; i < ui.treeAccess->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeAccess->topLevelItem(i);
if (pItem->data(0, Qt::UserRole).toInt() == Type
&& pItem->data(1, Qt::UserRole).toString().compare(Program, Qt::CaseInsensitive) == 0
&& pItem->data(2, Qt::UserRole).toInt() == Mode
&& pItem->data(3, Qt::UserRole).toString().compare(Path, Qt::CaseInsensitive) == 0)
return pItem;
}
return NULL;
}
void COptionsWindow::SetAccessEntry(EAccessType Type, const QString& Program, EAccessMode Mode, const QString& Path)
{
if (GetAccessEntry(Type, Program, Mode, Path) != NULL)
return; // already set
m_AccessChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
AddAccessEntry(Type, Mode, Program, Path);
}
void COptionsWindow::DelAccessEntry(EAccessType Type, const QString& Program, EAccessMode Mode, const QString& Path)
{
if(QTreeWidgetItem* pItem = GetAccessEntry(Type, Program, Mode, Path))
{
delete pItem;
m_AccessChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
}
QString COptionsWindow::AccessTypeToName(EAccessEntry Type)
{
switch (Type)
{
2021-11-13 08:28:32 +00:00
case eNormalFilePath: return "NormalFilePath";
2021-10-16 16:19:51 +01:00
case eOpenFilePath: return "OpenFilePath";
case eOpenPipePath: return "OpenPipePath";
case eClosedFilePath: return "ClosedFilePath";
case eReadFilePath: return "ReadFilePath";
case eWriteFilePath: return "WriteFilePath";
2021-11-13 08:28:32 +00:00
case eNormalKeyPath: return "NormalKeyPath";
2021-10-16 16:19:51 +01:00
case eOpenKeyPath: return "OpenKeyPath";
2021-11-13 08:28:32 +00:00
case eOpenConfPath: return "OpenConfPath";
2021-10-16 16:19:51 +01:00
case eClosedKeyPath: return "ClosedKeyPath";
case eReadKeyPath: return "ReadKeyPath";
case eWriteKeyPath: return "WriteKeyPath";
2021-11-13 08:28:32 +00:00
case eNormalIpcPath: return "NormalIpcPath";
2021-10-16 16:19:51 +01:00
case eOpenIpcPath: return "OpenIpcPath";
case eClosedIpcPath: return "ClosedIpcPath";
2022-03-29 18:36:23 +01:00
case eReadIpcPath: return "ReadIpcPath";
2021-10-16 16:19:51 +01:00
case eOpenWinClass: return "OpenWinClass";
case eOpenCOM: return "OpenClsid";
case eClosedCOM: return "ClosedClsid";
case eClosedCOM_RT: return "ClosedRT";
}
return "Unknown";
}
void COptionsWindow::LoadAccessList()
{
2021-11-13 08:28:32 +00:00
ui.chkPrivacy->setChecked(m_pBox->GetBool("UsePrivacyMode", false));
ui.chkUseSpecificity->setChecked(m_pBox->GetBool("UseRuleSpecificity", false));
2021-10-16 16:19:51 +01:00
ui.chkCloseForBox->setChecked(m_pBox->GetBool("AlwaysCloseForBoxed", true));
2021-11-13 08:28:32 +00:00
ui.chkNoOpenForBox->setChecked(m_pBox->GetBool("DontOpenForBoxed", true));
2021-10-16 16:19:51 +01:00
ui.treeAccess->clear();
for (int i = 0; i < eMaxAccessType; i++)
{
foreach(const QString& Value, m_pBox->GetTextList(AccessTypeToName((EAccessEntry)i), m_Template))
ParseAndAddAccessEntry((EAccessEntry)i, Value);
2021-12-03 19:26:09 +00:00
foreach(const QString& Value, m_pBox->GetTextList(AccessTypeToName((EAccessEntry)i) + "Disabled", m_Template))
ParseAndAddAccessEntry((EAccessEntry)i, Value, true);
2021-10-16 16:19:51 +01:00
}
LoadAccessListTmpl();
2021-11-13 08:28:32 +00:00
UpdateAccessPolicy();
2021-10-16 16:19:51 +01:00
m_AccessChanged = false;
}
void COptionsWindow::LoadAccessListTmpl(bool bUpdate)
{
if (ui.chkShowAccessTmpl->isChecked())
{
foreach(const QString& Template, m_pBox->GetTemplates())
{
for (int i = 0; i < eMaxAccessType; i++)
{
foreach(const QString& Value, m_pBox->GetTextListTmpl(AccessTypeToName((EAccessEntry)i), Template))
2021-12-03 19:26:09 +00:00
ParseAndAddAccessEntry((EAccessEntry)i, Value, false, Template);
2021-10-16 16:19:51 +01:00
}
}
}
else if (bUpdate)
{
for (int i = 0; i < ui.treeAccess->topLevelItemCount(); )
{
QTreeWidgetItem* pItem = ui.treeAccess->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1) {
delete pItem;
continue; // entry from template
}
i++;
}
}
}
2021-12-03 19:26:09 +00:00
void COptionsWindow::ParseAndAddAccessEntry(EAccessEntry EntryType, const QString& Value, bool disabled, const QString& Template)
2021-10-16 16:19:51 +01:00
{
EAccessType Type;
EAccessMode Mode;
switch (EntryType)
{
2021-11-13 08:28:32 +00:00
case eNormalFilePath: Type = eFile; Mode = eNormal; break;
case eOpenFilePath: Type = eFile; Mode = eOpen; break;
case eOpenPipePath: Type = eFile; Mode = eOpen4All; break;
2021-10-16 16:19:51 +01:00
case eClosedFilePath: Type = eFile; Mode = eClosed; break;
case eReadFilePath: Type = eFile; Mode = eReadOnly; break;
2022-02-13 11:55:52 +00:00
case eWriteFilePath: Type = eFile; Mode = eBoxOnly; break;
2021-10-16 16:19:51 +01:00
2021-11-13 08:28:32 +00:00
case eNormalKeyPath: Type = eKey; Mode = eNormal; break;
case eOpenKeyPath: Type = eKey; Mode = eOpen; break;
case eOpenConfPath: Type = eKey; Mode = eOpen4All;break;
2021-10-16 16:19:51 +01:00
case eClosedKeyPath: Type = eKey; Mode = eClosed; break;
case eReadKeyPath: Type = eKey; Mode = eReadOnly; break;
2022-02-13 11:55:52 +00:00
case eWriteKeyPath: Type = eKey; Mode = eBoxOnly; break;
2021-10-16 16:19:51 +01:00
2021-11-13 08:28:32 +00:00
case eNormalIpcPath: Type = eIPC; Mode = eNormal; break;
case eOpenIpcPath: Type = eIPC; Mode = eOpen; break;
2021-10-16 16:19:51 +01:00
case eClosedIpcPath: Type = eIPC; Mode = eClosed; break;
2022-02-13 11:55:52 +00:00
case eReadIpcPath: Type = eIPC; Mode = eReadOnly; break;
2021-10-16 16:19:51 +01:00
2021-11-13 08:28:32 +00:00
case eOpenWinClass: Type = eWnd; Mode = eOpen; break;
2021-10-16 16:19:51 +01:00
2021-11-13 08:28:32 +00:00
case eOpenCOM: Type = eCOM; Mode = eOpen; break;
2021-10-16 16:19:51 +01:00
case eClosedCOM: Type = eCOM; Mode = eClosed; break;
case eClosedCOM_RT: Type = eCOM; Mode = eClosedRT; break;
default: return;
}
//
// Mind this special cases
// OpenIpcPath=$:program.exe <- full access into the address space of a target process running outside the sandbox.
// OpenWinClass=$:program.exe <- permits to use the PostThreadMessage API to send a message directly to a thread running outside the sandbox.
// This form of the setting does not support wildcards.
//
QStringList Values = Value.split(",");
if (Values.count() >= 2)
2021-12-03 19:26:09 +00:00
AddAccessEntry(Type, Mode, Values[0], Values[1], disabled, Template);
2021-10-16 16:19:51 +01:00
else // all programs
2021-12-03 19:26:09 +00:00
AddAccessEntry(Type, Mode, "", Values[0], disabled, Template);
2021-10-16 16:19:51 +01:00
}
QString COptionsWindow::GetAccessModeStr(EAccessMode Mode)
{
switch (Mode)
{
2021-11-13 08:28:32 +00:00
case eNormal: return tr("Normal");
case eOpen: return tr("Open");
case eOpen4All: return tr("Open for All");
2021-10-16 16:19:51 +01:00
case eClosed: return tr("Closed");
case eClosedRT: return tr("Closed RT");
case eReadOnly: return tr("Read Only");
2022-02-13 11:55:52 +00:00
case eBoxOnly: return tr("Box Only (Write Only)");
2021-10-16 16:19:51 +01:00
}
return tr("Unknown");
}
QString COptionsWindow::GetAccessTypeStr(EAccessType Type)
{
switch (Type)
{
case eFile: return tr("File/Folder");
case eKey: return tr("Registry");
case eIPC: return tr("IPC Path");
case eWnd: return tr("Wnd Class");
case eCOM: return tr("COM Object");
}
return tr("Unknown");
}
void COptionsWindow::OnBrowseFile()
{
QString Value = QFileDialog::getOpenFileName(this, tr("Select File"), "", tr("All Files (*.*)")).replace("/", "\\");
if (Value.isEmpty())
return;
2021-11-13 08:28:32 +00:00
AddAccessEntry(eFile, eOpen, "", Value);
2021-10-16 16:19:51 +01:00
m_AccessChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnBrowseFolder()
{
QString Value = QFileDialog::getExistingDirectory(this, tr("Select Directory")).replace("/", "\\");
if (Value.isEmpty())
return;
2021-11-13 08:28:32 +00:00
AddAccessEntry(eFile, eOpen, "", Value);
2021-10-16 16:19:51 +01:00
m_AccessChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
2021-12-03 19:26:09 +00:00
void COptionsWindow::AddAccessEntry(EAccessType Type, EAccessMode Mode, QString Program, const QString& Path, bool disabled, const QString& Template)
2021-10-16 16:19:51 +01:00
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
pItem->setText(0, GetAccessTypeStr(Type) + (Template.isEmpty() ? "" : " (" + Template + ")"));
pItem->setData(0, Qt::UserRole, !Template.isEmpty() ? -1 : (int)Type);
pItem->setData(1, Qt::UserRole, Program);
bool bAll = Program.isEmpty();
if (bAll)
Program = tr("All Programs");
bool Not = Program.left(1) == "!";
if (Not)
Program.remove(0, 1);
if (Program.left(1) == "<")
Program = tr("Group: %1").arg(Program.mid(1, Program.length() - 2));
else if(!bAll)
m_Programs.insert(Program);
pItem->setText(1, (Not ? "NOT " : "") + Program);
pItem->setText(2, GetAccessModeStr(Mode));
pItem->setData(2, Qt::UserRole, (int)Mode);
2022-08-28 11:43:08 +01:00
//////////////////////////////////////////////////////////
// File and Registry entries auto append a '*' wildcard
// when thay don't contain any.
// Prepanding '|' disables this behavioure
//
2022-07-28 07:40:57 +01:00
QString sPath = Path;
2022-08-28 11:43:08 +01:00
if (Type == eFile || Type == eKey) {
if (!sPath.isEmpty() && sPath.left(1) != "|" && !sPath.contains("*") && sPath.right(1) != "*")
2022-07-28 07:40:57 +01:00
sPath.append("*");
}
pItem->setText(3, sPath);
2021-10-16 16:19:51 +01:00
pItem->setData(3, Qt::UserRole, Path);
2021-12-03 19:26:09 +00:00
if(Template.isEmpty())
pItem->setCheckState(0, disabled ? Qt::Unchecked : Qt::Checked);
2021-10-16 16:19:51 +01:00
ui.treeAccess->addTopLevelItem(pItem);
}
QString COptionsWindow::MakeAccessStr(EAccessType Type, EAccessMode Mode)
{
switch (Type)
{
case eFile:
switch (Mode)
{
2021-11-13 08:28:32 +00:00
case eNormal: return "NormalFilePath";
case eOpen: return "OpenFilePath";
case eOpen4All: return "OpenPipePath";
2021-10-16 16:19:51 +01:00
case eClosed: return "ClosedFilePath";
case eReadOnly: return "ReadFilePath";
2022-02-13 11:55:52 +00:00
case eBoxOnly: return "WriteFilePath";
2021-10-16 16:19:51 +01:00
}
break;
case eKey:
switch (Mode)
{
2021-11-13 08:28:32 +00:00
case eNormal: return "NormalKeyPath";
case eOpen: return "OpenKeyPath";
case eOpen4All: return "OpenConfPath";
2021-10-16 16:19:51 +01:00
case eClosed: return "ClosedKeyPath";
case eReadOnly: return "ReadKeyPath";
2022-02-13 11:55:52 +00:00
case eBoxOnly: return "WriteKeyPath";
2021-10-16 16:19:51 +01:00
}
break;
case eIPC:
switch (Mode)
{
2021-11-13 08:28:32 +00:00
case eNormal: return "NormalIpcPath";
case eOpen: return "OpenIpcPath";
2021-10-16 16:19:51 +01:00
case eClosed: return "ClosedIpcPath";
2022-02-13 11:55:52 +00:00
case eReadOnly: return "ReadIpcPath";
2021-10-16 16:19:51 +01:00
}
break;
case eWnd:
switch (Mode)
{
2021-11-13 08:28:32 +00:00
case eOpen: return "OpenWinClass";
2021-10-16 16:19:51 +01:00
}
break;
case eCOM:
switch (Mode)
{
2021-11-13 08:28:32 +00:00
case eOpen: return "OpenClsid";
2021-10-16 16:19:51 +01:00
case eClosed: return "ClosedClsid";
case eClosedRT: return "ClosedRT";
}
break;
}
return "Unknown";
}
/*void COptionsWindow::OnAccessItemClicked(QTreeWidgetItem* pItem, int Column)
{
if (Column != 0)
return;
CloseAccessEdit(pItem);
}*/
void COptionsWindow::CloseAccessEdit(bool bSave)
{
for (int i = 0; i < ui.treeAccess->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeAccess->topLevelItem(i);
CloseAccessEdit(pItem, bSave);
}
}
void COptionsWindow::CloseAccessEdit(QTreeWidgetItem* pItem, bool bSave)
{
QWidget* pProgram = ui.treeAccess->itemWidget(pItem, 1);
if (!pProgram)
return;
if (bSave)
{
2022-07-10 19:00:26 +01:00
QHBoxLayout* pLayout = (QHBoxLayout*)pProgram->layout();
QToolButton* pNot = (QToolButton*)pLayout->itemAt(0)->widget();
QComboBox* pCombo = (QComboBox*)pLayout->itemAt(1)->widget();
QComboBox* pMode = (QComboBox*)ui.treeAccess->itemWidget(pItem, 2);
QLineEdit* pPath = (QLineEdit*)ui.treeAccess->itemWidget(pItem, 3);
QString Program = pCombo->currentText();
int Index = pCombo->findText(Program);
if (Index != -1)
Program = pCombo->itemData(Index, Qt::UserRole).toString();
if (!Program.isEmpty() && Program.left(1) != "<")
m_Programs.insert(Program);
2021-10-16 16:19:51 +01:00
if (pItem->data(0, Qt::UserRole).toInt() == eCOM && !pPath->text().isEmpty())
{
bool isGUID = pPath->text().length() == 38 && pPath->text().left(1) == "{" && pPath->text().right(1) == "}";
switch (pMode->currentData().toInt())
{
2021-11-13 08:28:32 +00:00
case eOpen:
2021-10-16 16:19:51 +01:00
case eClosed:
if (!isGUID) {
QMessageBox::critical(this, "SandboxiePlus", tr("COM objects must be specified by their GUID, like: {00000000-0000-0000-0000-000000000000}"));
return;
}
break;
case eClosedRT:
if (isGUID) {
QMessageBox::critical(this, "SandboxiePlus", tr("RT interfaces must be specified by their name."));
return;
}
break;
}
}
2022-08-28 11:43:08 +01:00
if (pItem->data(0, Qt::UserRole).toInt() == eIPC && pMode->currentData().toInt() == eOpen
&& ((pPath->text() == "*" && pItem->data(3, Qt::UserRole).toString() != "*")
|| (pPath->text() == "\\*" && pItem->data(3, Qt::UserRole).toString() != "\\*"))
&& !m_BoxTemplates.contains("BoxedCOM"))
{
if (theConf->GetInt("Options/WarnOpenCOM", -1) == -1) {
bool State = false;
2022-08-28 13:21:35 +01:00
if (CCheckableMessageBox::question(this, "Sandboxie-Plus", tr("Opening all IPC access also opens COM access, do you still want to restrict COM to the sandbox?")
2022-08-28 11:43:08 +01:00
, tr("Don't ask in future"), &State, QDialogButtonBox::Yes | QDialogButtonBox::No, QDialogButtonBox::Yes) == QDialogButtonBox::Yes)
SetTemplate("BoxedCOM", true); // Normal overrides Open even without rule specificity :D
if (State)
theConf->SetValue("Options/WarnOpenCOM", 1);
}
}
2021-10-16 16:19:51 +01:00
pItem->setText(1, (pNot->isChecked() ? "NOT " : "") + pCombo->currentText());
pItem->setData(1, Qt::UserRole, (pNot->isChecked() ? "!" : "") + Program);
pItem->setText(2, GetAccessModeStr((EAccessMode)pMode->currentData().toInt()));
pItem->setData(2, Qt::UserRole, pMode->currentData());
pItem->setText(3, pPath->text());
pItem->setData(3, Qt::UserRole, pPath->text());
m_AccessChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
ui.treeAccess->setItemWidget(pItem, 1, NULL);
ui.treeAccess->setItemWidget(pItem, 2, NULL);
ui.treeAccess->setItemWidget(pItem, 3, NULL);
}
QList<COptionsWindow::EAccessMode> COptionsWindow::GetAccessModes(EAccessType Type)
{
switch (Type)
{
2022-02-13 11:55:52 +00:00
case eFile: return QList<EAccessMode>() << eNormal << eOpen << eOpen4All << eClosed << eReadOnly << eBoxOnly;
case eKey: return QList<EAccessMode>() << eNormal << eOpen << eOpen4All << eClosed << eReadOnly << eBoxOnly;
2022-03-29 18:36:23 +01:00
case eIPC: return QList<EAccessMode>() << eNormal << eOpen << eClosed << eReadOnly;
2021-11-13 08:28:32 +00:00
case eWnd: return QList<EAccessMode>() << eOpen;
case eCOM: return QList<EAccessMode>() << eOpen << eClosed << eClosedRT;
2021-10-16 16:19:51 +01:00
}
return QList<EAccessMode>();
}
void COptionsWindow::OnAccessItemDoubleClicked(QTreeWidgetItem* pItem, int Column)
{
//if (Column == 0)
// return;
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1) {
QMessageBox::warning(this, "SandboxiePlus", tr("Template values can not be edited."));
return;
}
QString Program = pItem->data(1, Qt::UserRole).toString();
QWidget* pProgram = new QWidget();
pProgram->setAutoFillBackground(true);
QHBoxLayout* pLayout = new QHBoxLayout();
pLayout->setMargin(0);
pLayout->setSpacing(0);
pProgram->setLayout(pLayout);
QToolButton* pNot = new QToolButton(pProgram);
pNot->setText("!");
pNot->setCheckable(true);
if (Program.left(1) == "!"){
pNot->setChecked(true);
Program.remove(0, 1);
}
pLayout->addWidget(pNot);
QComboBox* pCombo = new QComboBox(pProgram);
pCombo->addItem(tr("All Programs"), "");
2021-11-13 08:28:32 +00:00
foreach(const QString Group, GetCurrentGroups()){
QString GroupName = Group.mid(1, Group.length() - 2);
2021-12-03 19:26:09 +00:00
pCombo->addItem(tr("Group: %1").arg(GroupName), Group);
2021-10-16 16:19:51 +01:00
}
foreach(const QString & Name, m_Programs)
pCombo->addItem(Name, Name);
pCombo->setEditable(true);
int Index = pCombo->findData(Program);
pCombo->setCurrentIndex(Index);
if(Index == -1)
pCombo->setCurrentText(Program);
pLayout->addWidget(pCombo);
ui.treeAccess->setItemWidget(pItem, 1, pProgram);
QComboBox* pMode = new QComboBox();
foreach(EAccessMode Mode, GetAccessModes((EAccessType)Type))
pMode->addItem(GetAccessModeStr(Mode), (int)Mode);
pMode->setCurrentIndex(pMode->findData(pItem->data(2, Qt::UserRole)));
ui.treeAccess->setItemWidget(pItem, 2, pMode);
QLineEdit* pPath = new QLineEdit();
pPath->setText(pItem->data(3, Qt::UserRole).toString());
ui.treeAccess->setItemWidget(pItem, 3, pPath);
}
2021-12-03 19:26:09 +00:00
void COptionsWindow::OnAccessChanged(QTreeWidgetItem* pItem, int Column)
{
if (Column != 0)
return;
m_AccessChanged = true;
OnOptChanged();
}
2021-10-16 16:19:51 +01:00
void COptionsWindow::DeleteAccessEntry(QTreeWidgetItem* pItem)
{
if (!pItem)
return;
if (pItem->data(0, Qt::UserRole).toInt() == -1) {
QMessageBox::warning(this, "SandboxiePlus", tr("Template values can not be removed."));
return;
}
delete pItem;
}
void COptionsWindow::OnDelAccess()
{
DeleteAccessEntry(ui.treeAccess->currentItem());
m_AccessChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::SaveAccessList()
{
2021-11-13 08:28:32 +00:00
WriteAdvancedCheck(ui.chkPrivacy, "UsePrivacyMode", "y", "");
WriteAdvancedCheck(ui.chkUseSpecificity, "UseRuleSpecificity", "y", "");
2021-10-16 16:19:51 +01:00
WriteAdvancedCheck(ui.chkCloseForBox, "AlwaysCloseForBoxed", "", "n");
2021-11-13 08:28:32 +00:00
WriteAdvancedCheck(ui.chkNoOpenForBox, "DontOpenForBoxed", "", "n");
2021-10-16 16:19:51 +01:00
CloseAccessEdit(true);
2021-12-06 19:59:29 +00:00
QStringList Keys = QStringList()
2021-11-13 08:28:32 +00:00
<< "NormalFilePath" << "OpenFilePath" << "OpenPipePath" << "ClosedFilePath" << "ReadFilePath" << "WriteFilePath"
<< "NormalKeyPath" << "OpenKeyPath" << "OpenConfPath" << "ClosedKeyPath" << "ReadKeyPath" << "WriteKeyPath"
2022-02-13 11:55:52 +00:00
<< "NormalIpcPath"<< "OpenIpcPath" << "ClosedIpcPath" << "ReadIpcPath" << "OpenWinClass" << "OpenClsid" << "ClosedClsid" << "ClosedRT";
2021-10-16 16:19:51 +01:00
QMap<QString, QList<QString>> AccessMap;
for (int i = 0; i < ui.treeAccess->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeAccess->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1)
continue; // entry from template
int Mode = pItem->data(2, Qt::UserRole).toInt();
QString Program = pItem->data(1, Qt::UserRole).toString();
QString Value = pItem->data(3, Qt::UserRole).toString();
2022-04-02 16:01:13 +01:00
if (!Program.isEmpty())
2021-10-16 16:19:51 +01:00
Value.prepend(Program + ",");
2021-12-03 19:26:09 +00:00
QString AccessStr = MakeAccessStr((EAccessType)Type, (EAccessMode)Mode);
if (pItem->checkState(0) == Qt::Unchecked)
AccessStr += "Disabled";
AccessMap[AccessStr].append(Value);
2021-10-16 16:19:51 +01:00
}
2021-12-06 19:59:29 +00:00
foreach(const QString & Key, Keys) {
2021-10-16 16:19:51 +01:00
WriteTextList(Key, AccessMap[Key]);
2021-12-03 19:26:09 +00:00
WriteTextList(Key + "Disabled", AccessMap[Key + "Disabled"]);
}
2021-10-16 16:19:51 +01:00
m_AccessChanged = false;
}