-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Union #818 #821 #822 #823
base: main
Are you sure you want to change the base?
Union #818 #821 #822 #823
Changes from all commits
a78c9cb
8a368fa
aca1d59
7ef3bf7
5ab3ee7
c4211aa
6ce258f
d2f67a7
584350e
62669b1
10e145f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -947,4 +947,22 @@ bool IsCommodore(void* log) | |
FREE_MEMORY(textResult); | ||
|
||
return status; | ||
} | ||
} | ||
|
||
enum SelinuxState { | ||
SelinuxUnknown = 0, | ||
SelinuxFound, | ||
SelinuxNotFound, | ||
}; | ||
static enum SelinuxState g_selinuxState = SelinuxUnknown; | ||
|
||
bool DetectSelinux(void* log) | ||
{ | ||
if (g_selinuxState != SelinuxUnknown) | ||
{ | ||
return g_selinuxState == SelinuxFound; | ||
} | ||
|
||
g_selinuxState = (0 == CheckTextIsFoundInFile("/sys/kernel/security/lsm", "selinux", NULL, log)) ? SelinuxFound : SelinuxNotFound; | ||
return g_selinuxState == SelinuxFound; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: line 969 appears blank, remove |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -872,6 +872,29 @@ int GetDirectoryAccess(const char* name, unsigned int* ownerId, unsigned int* gr | |
return GetAccess(true, name, ownerId, groupId, mode, log); | ||
} | ||
|
||
static int RestoreSelinuxContext(const char* target, void* log) | ||
{ | ||
char* restoreCommand = NULL; | ||
char* textResult = NULL; | ||
int status = 0; | ||
|
||
if (NULL == (restoreCommand = FormatAllocateString("restorecon -F '%s'", target))) | ||
{ | ||
OsConfigLogError(log, "RestoreSelinuxContext: out of memory"); | ||
return ENOMEM; | ||
} | ||
|
||
if (0 != (status = ExecuteCommand(NULL, restoreCommand, false, false, 0, 0, &textResult, NULL, log))) | ||
{ | ||
OsConfigLogError(log, "RestoreSelinuxContext: restorecon failed %d: %s", status, textResult); | ||
} | ||
|
||
FREE_MEMORY(textResult); | ||
FREE_MEMORY(restoreCommand); | ||
|
||
return status; | ||
} | ||
|
||
int RenameFile(const char* original, const char* target, void* log) | ||
{ | ||
int status = 0; | ||
|
@@ -893,6 +916,11 @@ int RenameFile(const char* original, const char* target, void* log) | |
status = (0 == errno) ? ENOENT : errno; | ||
} | ||
|
||
if (DetectSelinux(log)) | ||
{ | ||
RestoreSelinuxContext(target, log); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a one line comment that describes why this is necessary? |
||
|
||
return status; | ||
} | ||
|
||
|
@@ -946,6 +974,11 @@ int RenameFileWithOwnerAndAccess(const char* original, const char* target, void* | |
status = (0 == errno) ? ENOENT : errno; | ||
} | ||
|
||
if (DetectSelinux(log)) | ||
{ | ||
RestoreSelinuxContext(target, log); | ||
} | ||
|
||
return status; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ static bool g_tdnfIsPresent = false; | |
static bool g_dnfIsPresent = false; | ||
static bool g_yumIsPresent = false; | ||
static bool g_zypperIsPresent = false; | ||
static bool g_aptGetUpdateExecuted = false; | ||
|
||
int IsPresent(const char* what, void* log) | ||
{ | ||
|
@@ -178,6 +179,27 @@ int CheckPackageNotInstalled(const char* packageName, char** reason, void* log) | |
return result; | ||
} | ||
|
||
void AptGetUpdateOnce(void* log) | ||
{ | ||
const char* command = "apt-get update"; | ||
int status = 0; | ||
if (g_aptGetUpdateExecuted) | ||
{ | ||
return; | ||
} | ||
|
||
if (0 == (status = ExecuteCommand(NULL, command, false, false, 0, 0, NULL, NULL, log))) | ||
{ | ||
OsConfigLogInfo(log, "AptGetUpdateOnce: apt-get update was successful"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
g_aptGetUpdateExecuted = true; | ||
} | ||
else | ||
{ | ||
OsConfigLogError(log, "AptGetUpdateOnce: apt-get update failed with %d", status); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
} | ||
|
||
int InstallOrUpdatePackage(const char* packageName, void* log) | ||
{ | ||
const char* commandTemplate = "%s install -y %s"; | ||
|
@@ -187,6 +209,7 @@ int InstallOrUpdatePackage(const char* packageName, void* log) | |
|
||
if (g_aptGetIsPresent) | ||
{ | ||
AptGetUpdateOnce(log); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
status = CheckOrInstallPackage(commandTemplate, g_aptGet, packageName, log); | ||
} | ||
else if (g_tdnfIsPresent) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,19 @@ target_include_directories(moduletest PRIVATE ${MODULES_INC_DIR} ${CMAKE_CURRENT | |
add_custom_command(TARGET moduletest POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:moduletest> ${CMAKE_BINARY_DIR}/moduletest | ||
DEPENDS $<TARGET_FILE:moduletest> | ||
) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra newlines |
||
|
||
|
||
set(SRC ${moduletest_SOURCE_DIR}/recipes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a CMake set(MOFS
${OsConfigResourceSsh_SOURCE_DIR}/LinuxSshServerSecurityBaseline.mof
${OsConfigResourceAsb_SOURCE_DIR}/AzureLinuxBaseline.mof
)
list(JOIN MOF_LIST " " flat_string)
add_custom_command(
OUTPUT ${SRC}/SecurityBaselineTests.json
DEPENDS ${SRC}/create-asb-json.sh ${SRC}/mof-to-json.awk ${SRC}/SecurityBaselineTests.json-header ${SRC}/SecurityBaselineTests.json-mid ${SRC}/SecurityBaselineTests.json-footer ${MOF1} ${MOF2}
COMMAND ./create-asb-json.sh ${MOF_LIST} >${SRC}/SecurityBaselineTests.json
WORKING_DIRECTORY ${SRC}
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
set(MOF1 ${OsConfigResourceSsh_SOURCE_DIR}/LinuxSshServerSecurityBaseline.mof) | ||
set(MOF2 ${OsConfigResourceAsb_SOURCE_DIR}/AzureLinuxBaseline.mof) | ||
|
||
add_custom_command( | ||
OUTPUT ${SRC}/SecurityBaselineTests.json | ||
DEPENDS ${SRC}/create-asb-json.sh ${SRC}/mof-to-json.awk ${SRC}/SecurityBaselineTests.json-header ${SRC}/SecurityBaselineTests.json-mid ${SRC}/SecurityBaselineTests.json-footer ${MOF1} ${MOF2} | ||
COMMAND ./create-asb-json.sh ${MOF1} ${MOF2} >${SRC}/SecurityBaselineTests.json | ||
WORKING_DIRECTORY ${SRC} | ||
) | ||
add_custom_target(generate-asb-test-json | ||
DEPENDS ${SRC}/SecurityBaselineTests.json | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all explicit initializations and complete with a typedef like this, for example: