From fcfca9106c858dba2856dea1a37eee50462f33db Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 21 Feb 2011 16:45:17 +0000 Subject: [PATCH] ENH: systemCall: added allowSystemOperations checking. Added to argList. --- .../codeStream/codeStreamTools.C | 2 +- src/OpenFOAM/global/argList/argList.C | 11 ++++++ .../functionObjects/systemCall/systemCall.C | 34 ++++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C index 1667d2be4e7..07c0d09c1d5 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C @@ -131,7 +131,7 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const << "because of security issues. If you trust the code you can" << " enable this" << endl << "facility be adding to the InfoSwitches setting in the system" - << " controlDict" << endl + << " controlDict:" << endl << endl << " allowSystemOperations 1" << endl << endl diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 1d23a86c9cb..08cc78f762e 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -32,6 +32,7 @@ License #include "JobInfo.H" #include "labelList.H" #include "regIOobject.H" +#include "codeStreamTools.H" #include <cctype> @@ -787,6 +788,16 @@ Foam::argList::argList regIOobject::fileModificationChecking ] << endl; + + Info<< "allowSystemOperations : "; + if (codeStreamTools::allowSystemOperations) + { + Info<< "Allowing user-supplied system call operations" << endl; + } + else + { + Info<< "Disallowing user-supplied system call operations" << endl; + } } if (Pstream::master() && bannerEnabled) diff --git a/src/postProcessing/functionObjects/systemCall/systemCall.C b/src/postProcessing/functionObjects/systemCall/systemCall.C index 5f12e9689ce..664589750cf 100644 --- a/src/postProcessing/functionObjects/systemCall/systemCall.C +++ b/src/postProcessing/functionObjects/systemCall/systemCall.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,8 +24,8 @@ License \*---------------------------------------------------------------------------*/ #include "systemCall.H" -#include "dictionary.H" #include "Time.H" +#include "codeStreamTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -71,6 +71,30 @@ void Foam::systemCall::read(const dictionary& dict) << "no executeCalls, endCalls or writeCalls defined." << endl; } + else if (!codeStreamTools::allowSystemOperations) + { + FatalErrorIn + ( + "systemCall::read(const dictionary&)" + ) << "Executing user-supplied system calls is not" + << " enabled by default" << endl + << "because of security issues. If you trust the case you can" + << " enable this" << endl + << "facility be adding to the InfoSwitches setting in the system" + << " controlDict:" << endl + << endl + << " allowSystemOperations 1" << endl + << endl + << "The system controlDict is either" << endl + << endl + << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << endl + << endl + << "or" << endl + << endl + << " $WM_PROJECT_DIR/etc/controlDict" << endl + << endl + << exit(FatalError); + } } @@ -78,7 +102,7 @@ void Foam::systemCall::execute() { forAll(executeCalls_, callI) { - ::system(executeCalls_[callI].c_str()); + Foam::system(executeCalls_[callI].c_str()); } } @@ -87,7 +111,7 @@ void Foam::systemCall::end() { forAll(endCalls_, callI) { - ::system(endCalls_[callI].c_str()); + Foam::system(endCalls_[callI].c_str()); } } @@ -96,7 +120,7 @@ void Foam::systemCall::write() { forAll(writeCalls_, callI) { - ::system(writeCalls_[callI].c_str()); + Foam::system(writeCalls_[callI].c_str()); } } -- GitLab