Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 6c595ad

Browse files
authored
Merge pull request #249 from jan-cerny/remove_old_code
Use only library calls to generate remediation
2 parents d80bb55 + e97539b commit 6c595ad

File tree

4 files changed

+2
-135
lines changed

4 files changed

+2
-135
lines changed

CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ endif()
4949
# Local scanning tools
5050
option(SCAP_WORKBENCH_LOCAL_SCAN_ENABLED "If enabled, scanning of local machine is possible from workbench. Else the option is disabled in the GUI." TRUE)
5151

52-
option(SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION "If enabled, result-based remediation roles will be generated by calls to the libopenscap library (instead of being generated by the oscap subprocess). Requires openscap>=1.2.16" FALSE)
53-
54-
if (SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION)
55-
if(${OPENSCAP_VERSION_MAJOR} LESS 2 AND ${OPENSCAP_VERSION_MINOR} LESS 3 AND ${OPENSCAP_VERSION_PATCH} LESS 16) # i.e. oscap<1.2.16
56-
message(FATAL_ERROR "Library-powered generation of result-based remediation roles is supported only if you have oscap>=1.2.16, whereas you have oscap==${OPENSCAP_VERSION}")
57-
endif()
52+
if(${OPENSCAP_VERSION_MAJOR} LESS 2 AND ${OPENSCAP_VERSION_MINOR} LESS 3 AND ${OPENSCAP_VERSION_PATCH} LESS 16) # i.e. oscap<1.2.16
53+
message(FATAL_ERROR "Library-powered generation of result-based remediation roles is supported only if you have oscap>=1.2.16, whereas you have oscap==${OPENSCAP_VERSION}")
5854
endif()
5955

6056
find_program(NICE_EXECUTABLE NAMES nice) # fully optional, local scan still available when missing

include/Config.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#define SCAP_WORKBENCH_LOCAL_PKEXEC_OSCAP_PATH "@CMAKE_INSTALL_FULL_LIBEXECDIR@/scap-workbench-pkexec-oscap.sh"
4141
#define SCAP_WORKBENCH_LOCAL_RPM_EXTRACT_PATH "@CMAKE_INSTALL_FULL_LIBEXECDIR@/scap-workbench-rpm-extract.sh"
4242
#define SCAP_WORKBENCH_REMOTE_OSCAP_PATH "oscap"
43-
#cmakedefine SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION
4443
#cmakedefine SCAP_WORKBENCH_LOCAL_SSH_FOUND
4544
#define SCAP_WORKBENCH_LOCAL_SSH_PATH "@SSH_EXECUTABLE@"
4645
#cmakedefine SCAP_WORKBENCH_LOCAL_SETSID_FOUND

include/RemediationRoleSaver.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,45 +93,6 @@ class PuppetProfileRemediationSaver : public ProfileBasedRemediationSaver
9393
};
9494

9595

96-
#ifndef SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION
97-
/// Base for all result-based remediation generators that uses oscap process
98-
class ResultBasedProcessRemediationSaver : public RemediationSaverBase
99-
{
100-
public:
101-
ResultBasedProcessRemediationSaver(
102-
QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath,
103-
const QString& saveMessage, const QString& filetypeExtension, const QString& filetypeTemplate, const QString& fixType);
104-
105-
private:
106-
virtual void saveToFile(const QString& filename);
107-
SpacelessQTemporaryFile mArfFile;
108-
QString tailoring;
109-
};
110-
111-
112-
class BashResultRemediationSaver : public ResultBasedProcessRemediationSaver
113-
{
114-
public:
115-
BashResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath);
116-
};
117-
118-
119-
class AnsibleResultRemediationSaver : public ResultBasedProcessRemediationSaver
120-
{
121-
public:
122-
AnsibleResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath);
123-
};
124-
125-
126-
class PuppetResultRemediationSaver : public ResultBasedProcessRemediationSaver
127-
{
128-
public:
129-
PuppetResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath);
130-
};
131-
132-
#else // i.e. SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION is defined
133-
134-
/// Base for all result-based remediation generators that uses the openscap library
13596
class ResultBasedLibraryRemediationSaver : public RemediationSaverBase
13697
{
13798
public:
@@ -165,7 +126,5 @@ class PuppetResultRemediationSaver : public ResultBasedLibraryRemediationSaver
165126
PuppetResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath);
166127
};
167128

168-
#endif // SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION
169-
170129

171130
#endif // SCAP_WORKBENCH_REMEDIATION_ROLE_SAVER_H_

src/RemediationRoleSaver.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ extern "C"
3535
#include <xccdf_benchmark.h>
3636
#include <xccdf_policy.h>
3737
#include <xccdf_session.h>
38-
#ifdef SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION
39-
// vvv This include is used only for library-based generation of result-base remediation roles
40-
// vvv and it requires (relatively recent) openscap 1.2.16
4138
#include <ds_rds_session.h>
42-
#endif
4339
}
4440

4541

@@ -163,88 +159,6 @@ PuppetProfileRemediationSaver::PuppetProfileRemediationSaver(QWidget* parentWind
163159
puppetSaveMessage, puppetFiletypeExtension, puppetFiletypeTemplate, puppetFixType)
164160
{}
165161

166-
#ifndef SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION
167-
ResultBasedProcessRemediationSaver::ResultBasedProcessRemediationSaver(
168-
QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath,
169-
const QString& saveMessage, const QString& filetypeExtension, const QString& filetypeTemplate, const QString& fixType):
170-
RemediationSaverBase(parentWindow, saveMessage, filetypeExtension, filetypeTemplate, fixType)
171-
{
172-
mArfFile.setAutoRemove(true);
173-
mArfFile.open();
174-
mArfFile.write(arfContents);
175-
mArfFile.close();
176-
tailoring = tailoringFilePath;
177-
}
178-
179-
void ResultBasedProcessRemediationSaver::saveToFile(const QString& filename)
180-
{
181-
QStringList args;
182-
args.append("xccdf");
183-
args.append("generate");
184-
args.append("fix");
185-
186-
args.append("--template");
187-
args.append(mTemplateString);
188-
args.append("--output");
189-
args.append(filename);
190-
191-
// vvv This will work, if there is only one result ID in the ARF file, it will be picked no matter what the argument value is.
192-
// However, ommitting --result-id "" won't work.
193-
args.append("--result-id");
194-
args.append("");
195-
196-
if (!tailoring.isNull()) {
197-
args.append("--tailoring-file");
198-
args.append(tailoring.toUtf8().constData());
199-
}
200-
201-
args.append(mArfFile.fileName());
202-
203-
// Launching a process and going through its output is something we do already in OscapScannerLocal::evaluate()
204-
// This is a lightweight launch though.
205-
QProcess process(mParentWindow);
206-
207-
SpacelessQTemporaryDir workingDir;
208-
process.setWorkingDirectory(workingDir.path());
209-
QString program(SCAP_WORKBENCH_LOCAL_OSCAP_PATH);
210-
211-
process.start(program, args);
212-
process.waitForStarted();
213-
214-
const unsigned int remediationGenerationTimeout = 10000;
215-
216-
const int process_finished_on_time = process.waitForFinished(remediationGenerationTimeout);
217-
218-
if (!process_finished_on_time)
219-
{
220-
QString message = QObject::tr("The process that was supposed to generate remediations didn't finish on time (i.e. within %1 secs), so it was terminated.").arg(remediationGenerationTimeout / 1000);
221-
process.kill();
222-
throw std::runtime_error(message.toUtf8().constData());
223-
}
224-
225-
if (process.exitCode() != 0)
226-
{
227-
QString completeErrorMessage(QObject::tr("Exit code of 'oscap' was %1: %2"));
228-
throw std::runtime_error(completeErrorMessage.arg(process.exitCode()).arg(QString(process.readAllStandardError())).toUtf8().constData());
229-
}
230-
}
231-
232-
BashResultRemediationSaver::BashResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath):
233-
ResultBasedProcessRemediationSaver(parentWindow, arfContents, tailoringFilePath,
234-
bashSaveMessage, bashFiletypeExtension, bashFiletypeTemplate, bashFixTemplate)
235-
{}
236-
237-
AnsibleResultRemediationSaver::AnsibleResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath):
238-
ResultBasedProcessRemediationSaver(parentWindow, arfContents, tailoringFilePath,
239-
ansibleSaveMessage, ansibleFiletypeExtension, ansibleFiletypeTemplate, ansibleFixType)
240-
{}
241-
242-
PuppetResultRemediationSaver::PuppetResultRemediationSaver(QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath):
243-
ResultBasedProcessRemediationSaver(parentWindow, arfContents, tailoringFilePath,
244-
puppetSaveMessage, puppetFiletypeExtension, puppetFiletypeTemplate, puppetFixType)
245-
{}
246-
247-
#else // i.e. SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION is defined
248162
ResultBasedLibraryRemediationSaver::ResultBasedLibraryRemediationSaver(
249163
QWidget* parentWindow, const QByteArray& arfContents, const QString& tailoringFilePath,
250164
const QString& saveMessage, const QString& filetypeExtension, const QString& filetypeTemplate, const QString& fixType):
@@ -343,4 +257,3 @@ PuppetResultRemediationSaver::PuppetResultRemediationSaver(QWidget* parentWindow
343257
puppetSaveMessage, puppetFiletypeExtension, puppetFiletypeTemplate, puppetFixType)
344258
{}
345259

346-
#endif // SCAP_WORKBENCH_USE_LIBRARY_FOR_RESULT_BASED_REMEDIATION_ROLES_GENERATION

0 commit comments

Comments
 (0)