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 )
{
ui . setupUi ( this ) ;
connect ( ui . buttonBox , SIGNAL ( accepted ( ) ) , SLOT ( CreateBox ( ) ) ) ;
connect ( ui . buttonBox , SIGNAL ( rejected ( ) ) , SLOT ( reject ( ) ) ) ;
ui . txtName - > setText ( tr ( " New Box " ) ) ;
ui . cmbTemplates - > addItem ( tr ( " Hardened " ) ) ;
ui . cmbTemplates - > addItem ( tr ( " Default " ) ) ;
ui . cmbTemplates - > setCurrentIndex ( eDefault ) ;
2020-12-22 17:51:47 +00:00
ui . cmbTemplates - > addItem ( tr ( " Legacy (old sbie behaviour) " ) ) ;
2020-12-22 14:50:58 +00:00
ui . cmbBoxes - > addItems ( theAPI - > GetAllBoxes ( ) . keys ( ) ) ;
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 ( ) ;
2020-12-22 14:50:58 +00:00
restoreGeometry ( theConf - > GetBlob ( " NewBoxWindow/Window_Geometry " ) ) ;
}
CNewBoxWindow : : ~ CNewBoxWindow ( )
{
theConf - > SetBlob ( " NewBoxWindow/Window_Geometry " , saveGeometry ( ) ) ;
}
void CNewBoxWindow : : OnPreset ( )
{
ui . cmbTemplates - > setEnabled ( ui . radTemplate - > isChecked ( ) ) ;
ui . cmbBoxes - > setEnabled ( ui . radCopy - > isChecked ( ) ) ;
}
void CNewBoxWindow : : CreateBox ( )
{
QString Name = ui . txtName - > text ( ) ;
Name . replace ( " " , " _ " ) ;
SB_STATUS Status = theAPI - > CreateBox ( Name ) ;
if ( ! Status . IsError ( ) )
{
CSandBoxPtr pBox = theAPI - > GetBoxByName ( Name ) ;
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 )
{
Status = theAPI - > SbieIniSet ( Name , I - > first , I - > second , CSbieAPI : : eIniInsert ) ;
if ( Status . IsError ( ) )
break ;
}
}
}
else switch ( ui . cmbTemplates - > currentIndex ( ) )
{
case eHardened :
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " DropAdminRights " , true ) ;
2021-01-06 12:19:13 +00:00
//pBox.objectCast<CSandBoxPlus>()->SetBool("ProtectRpcSs", true); // not compatible with RunServicesAsSystem=n which is on by default
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " ClosePrintSpooler " , true ) ;
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " OpenSmartCard " , false ) ;
2020-12-22 14:50:58 +00:00
break ;
case eLegacy :
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " UnrestrictedSCM " , true ) ;
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " ExposeBoxedSystem " , true ) ;
2021-01-06 12:19:13 +00:00
//pBox.objectCast<CSandBoxPlus>()->SetBool("RunServicesAsSystem", true); // legacy behavioure but there should be no normal use cases which require this
pBox . objectCast < CSandBoxPlus > ( ) - > SetBool ( " OpenPrintSpooler " , true ) ;
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
}