Skip to content
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

Let fim_check_ignore to act on FIM directories #13264

Merged
merged 3 commits into from Jun 30, 2022

Conversation

jotacarma90
Copy link
Member

@jotacarma90 jotacarma90 commented Apr 28, 2022

Related issue
#10555

Description

This PR is to introduce the necessary change in the fim_checker function, so that the ignores checking is done for both files and directories. This way we avoid going through a whole directory that was already being ignored from the beginning.
It is not possible to do the same with the restrict check, since by traversing the directories it is not possible to be sure that in a lower depth the restrict condition will not be satisfied.

Configuration options

    <directories>/test/ignore</directories>
    <ignore>/test/ignore/noalerts</ignore>

Logs/Alerts example

Executing:
touch /test/ignore/noalerts/subdir1/subdir2/subdir3/file1

Then fim_checker does not need to traverse all subdirectories, since the ignored path was /test/ignore/noalerts:

2022/04/28 12:49:55 wazuh-syscheckd[29232] create_db.c:1207 at fim_check_ignore(): DEBUG: (6204): Ignoring path '/test/ignore/noalerts' due to '/test/ignore/noalerts'

Tests

  • Compilation without warnings in every supported platform
    • Linux
    • Windows
  • Source installation
  • QA templates contemplate the added capabilities

@jotacarma90 jotacarma90 force-pushed the 10555-fix-ignore-restrict-directories branch from 1d8e400 to 17312d1 Compare April 28, 2022 13:14
@jotacarma90 jotacarma90 changed the base branch from 9103-replace-fim-db-dbsync to 4.3 April 28, 2022 14:49
@jotacarma90 jotacarma90 force-pushed the 10555-fix-ignore-restrict-directories branch from f162f0b to f382c42 Compare April 28, 2022 14:56
@jotacarma90 jotacarma90 marked this pull request as ready for review April 28, 2022 14:57
FrancoRivero
FrancoRivero previously approved these changes Apr 28, 2022
Copy link
Contributor

@FrancoRivero FrancoRivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -952,7 +952,7 @@ static void test_fim_audit_json(void **state) {
static void test_fim_check_ignore_strncasecmp(void **state) {
int ret;

expect_string(__wrap__mdebug2, formatted_msg, "(6204): Ignoring 'file' '/EtC/dumPDateS' due to '/etc/dumpdates'");
expect_string(__wrap__mdebug2, formatted_msg, "(6204): Ignoring path '/EtC/dumPDateS' due to pattern '/etc/dumpdates'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the constant FIM_IGNORE_ENTRY or FIM_IGNORE_SREGEX

@@ -968,7 +968,7 @@ static void test_fim_check_ignore_strncasecmp(void **state) {
if(!ExpandEnvironmentStrings(path, expanded_path, OS_MAXSTR))
fail();

snprintf(debug_msg, OS_MAXSTR, "(6204): Ignoring 'file' '%s' due to '%s'", expanded_path, syscheck.ignore[0]);
snprintf(debug_msg, OS_MAXSTR, "(6204): Ignoring path '%s' due to pattern '%s'", expanded_path, syscheck.ignore[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the constant FIM_IGNORE_ENTRY or FIM_IGNORE_SREGEX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -983,9 +983,9 @@ static void test_fim_check_ignore_regex(void **state) {
int ret;

#ifndef TEST_WINAGENT
expect_string(__wrap__mdebug2, formatted_msg, "(6205): Ignoring 'file' '/test/files/test.swp' due to sregex '.log$|.swp$'");
expect_string(__wrap__mdebug2, formatted_msg, "(6205): Ignoring path '/test/files/test.swp' due to sregex '.log$|.swp$'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the constant FIM_IGNORE_ENTRY or FIM_IGNORE_SREGEX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1743,7 +1743,7 @@ static void test_fim_checker_fim_regular_ignore(void **state) {
expect_string(__wrap_HasFilesystem, path, "/etc/mtab");
will_return(__wrap_HasFilesystem, 0);

expect_string(__wrap__mdebug2, formatted_msg, "(6204): Ignoring 'file' '/etc/mtab' due to '/etc/mtab'");
expect_string(__wrap__mdebug2, formatted_msg, "(6204): Ignoring path '/etc/mtab' due to pattern '/etc/mtab'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the constant FIM_IGNORE_ENTRY or FIM_IGNORE_SREGEX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -2602,7 +2602,7 @@ static void test_fim_checker_fim_regular_ignore(void **state) {
expect_string(__wrap_HasFilesystem, path, expanded_path);
will_return(__wrap_HasFilesystem, 0);

snprintf(debug_msg, OS_MAXSTR, "(6204): Ignoring 'file' '%s' due to '%s'", expanded_path, expanded_path);
snprintf(debug_msg, OS_MAXSTR, "(6204): Ignoring path '%s' due to pattern '%s'", expanded_path, expanded_path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the constant FIM_IGNORE_ENTRY or FIM_IGNORE_SREGEX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jotacarma90 jotacarma90 changed the base branch from 4.3 to 4.4 May 6, 2022 12:48
@antoniomanuelfr antoniomanuelfr self-requested a review May 6, 2022 12:52
antoniomanuelfr
antoniomanuelfr previously approved these changes May 6, 2022
chemamartinez
chemamartinez previously approved these changes May 6, 2022
@jmv74211
Copy link
Contributor

jmv74211 commented Jun 21, 2022

QA review

@chemamartinez chemamartinez force-pushed the 10555-fix-ignore-restrict-directories branch from e8bbd9c to 83accfe Compare June 22, 2022 10:36
@chemamartinez chemamartinez changed the base branch from 4.4 to master June 22, 2022 10:36
@chemamartinez chemamartinez dismissed stale reviews from antoniomanuelfr, FrancoRivero, and themself June 22, 2022 10:36

The base branch was changed.

@chemamartinez chemamartinez merged commit 2efe60e into master Jun 30, 2022
@chemamartinez chemamartinez deleted the 10555-fix-ignore-restrict-directories branch June 30, 2022 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants