2020-12-22 14:50:58 +00:00
# include "stdafx.h"
# include "NewBoxWindow.h"
# include "SandMan.h"
# include "../MiscHelpers/Common/Settings.h"
CNewBoxWindow : : CNewBoxWindow ( QWidget * parent )
: QDialog ( parent )
{
2021-01-26 20:58:43 +00:00
this - > setWindowTitle ( tr ( " Sandboxie-Plus - Create New Box " ) ) ;
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 ) ;
2020-12-22 14:50:58 +00:00
ui . setupUi ( this ) ;
connect ( ui . buttonBox , SIGNAL ( accepted ( ) ) , SLOT ( CreateBox ( ) ) ) ;
connect ( ui . buttonBox , SIGNAL ( rejected ( ) ) , SLOT ( reject ( ) ) ) ;
2021-01-26 20:58:43 +00:00
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 ;
}
2020-12-22 14:50:58 +00:00
ui . cmbTemplates - > addItem ( tr ( " Hardened " ) ) ;
ui . cmbTemplates - > addItem ( tr ( " Default " ) ) ;
ui . cmbTemplates - > setCurrentIndex ( eDefault ) ;
2021-01-26 20:58:43 +00:00
ui . cmbTemplates - > addItem ( tr ( " Legacy Sandboxie Behaviour " ) ) ;
2021-06-05 09:53:58 +01:00
// leniant
// open
2020-12-22 14:50:58 +00:00
2021-01-26 20:58:43 +00:00
foreach ( const CSandBoxPtr & pBox , Boxes )
ui . cmbBoxes - > addItem ( pBox - > GetName ( ) ) ;
2020-12-22 14:50:58 +00:00
connect ( ui . radTemplate , SIGNAL ( toggled ( bool ) ) , this , SLOT ( OnPreset ( ) ) ) ;
connect ( ui . radCopy , SIGNAL ( toggled ( bool ) ) , this , SLOT ( OnPreset ( ) ) ) ;
ui . radTemplate - > setChecked ( true ) ;
2021-01-02 08:03:16 +00:00
ui . txtName - > setFocus ( ) ;
2021-01-26 20:58:43 +00:00
//restoreGeometry(theConf->GetBlob("NewBoxWindow/Window_Geometry"));
2020-12-22 14:50:58 +00:00
}
CNewBoxWindow : : ~ CNewBoxWindow ( )
{
2021-01-26 20:58:43 +00:00
//theConf->SetBlob("NewBoxWindow/Window_Geometry", saveGeometry());
2020-12-22 14:50:58 +00:00
}
void CNewBoxWindow : : OnPreset ( )
{
ui . cmbTemplates - > setEnabled ( ui . radTemplate - > isChecked ( ) ) ;
ui . cmbBoxes - > setEnabled ( ui . radCopy - > isChecked ( ) ) ;
}
void CNewBoxWindow : : CreateBox ( )
{
2021-01-26 20:58:43 +00:00
m_Name = ui . txtName - > text ( ) ;
m_Name . replace ( " " , " _ " ) ;
2020-12-22 14:50:58 +00:00
2021-01-26 20:58:43 +00:00
SB_STATUS Status = theAPI - > CreateBox ( m_Name ) ;
2020-12-22 14:50:58 +00:00
if ( ! Status . IsError ( ) )
{
2021-01-26 20:58:43 +00:00
CSandBoxPtr pBox = theAPI - > GetBoxByName ( m_Name ) ;
2020-12-22 14:50:58 +00:00
if ( ui . radCopy - > isChecked ( ) )
{
QList < QPair < QString , QString > > Settings ;
CSandBoxPtr pSrcBox = theAPI - > GetBoxByName ( ui . cmbBoxes - > currentText ( ) ) ;
2020-12-23 18:17:24 +00:00
qint32 status = 0 ;
if ( ! pSrcBox . isNull ( ) ) Settings = pSrcBox - > GetIniSection ( & status ) ;
2020-12-22 14:50:58 +00:00
if ( Settings . isEmpty ( ) )
2020-12-23 18:17:24 +00:00
Status = SB_ERR ( SB_FailedCopyConf , QVariantList ( ) < < ui . cmbBoxes - > currentText ( ) < < ( quint32 ) status ) ;
2020-12-22 14:50:58 +00:00
else
{
for ( QList < QPair < QString , QString > > : : iterator I = Settings . begin ( ) ; I ! = Settings . end ( ) ; + + I )
{
2021-01-26 20:58:43 +00:00
Status = theAPI - > SbieIniSet ( m_Name , I - > first , I - > second , CSbieAPI : : eIniInsert ) ;
2020-12-22 14:50:58 +00:00
if ( Status . IsError ( ) )
break ;
}
}
}
else switch ( ui . cmbTemplates - > currentIndex ( ) )
{
case eHardened :
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " DropAdminRights " , true ) ;
2021-06-05 13:34:11 +01:00
//pBox.objectCast<CSandBoxPlus>()->SetBool("FakeAdminRights", true); // Note: making the app think it has admin rights has no security downsides, but it can help with compatibility
2021-01-06 12:19:13 +00:00
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " ClosePrintSpooler " , true ) ;
2020-12-22 14:50:58 +00:00
break ;
case eLegacy :
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " UnrestrictedSCM " , true ) ;
2021-06-05 09:53:58 +01:00
//pBox.objectCast<CSandBoxPlus>()->SetBool("ExposeBoxedSystem", true);
2021-06-05 13:34:11 +01:00
//pBox.objectCast<CSandBoxPlus>()->SetBool("RunServicesAsSystem", true); // legacy behaviour, but there should be no normal use cases which require this
2021-01-06 12:19:13 +00:00
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " OpenPrintSpooler " , true ) ;
2021-06-05 09:53:58 +01:00
pBox . objectCast < CSandBoxPlus > ( ) - > InsertText ( " Template " , " OpenSmartCard " ) ;
default :
2021-06-05 13:34:11 +01:00
pBox . objectCast < CSandBoxPlus > ( ) - > InsertText ( " Template " , " OpenBluetooth " ) ; // most Unity games needs that, besides most modern games are Unity based
2020-12-22 14:50:58 +00:00
break ;
}
}
2020-12-22 15:02:30 +00:00
if ( Status . IsError ( ) )
CSandMan : : CheckResults ( QList < SB_STATUS > ( ) < < Status ) ;
else
accept ( ) ;
2020-12-22 17:51:47 +00:00
}