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

Replace os_regex with RE2 in the Agent #152

Open
2 of 7 tasks
Tracked by #17
cborla opened this issue Sep 13, 2024 · 4 comments
Open
2 of 7 tasks
Tracked by #17

Replace os_regex with RE2 in the Agent #152

cborla opened this issue Sep 13, 2024 · 4 comments
Labels

Comments

@cborla
Copy link
Member

cborla commented Sep 13, 2024

Parent issue:

Description

Deprecate or remove the non-standard os_regex library and replace it with the standard RE2 library. This will improve compatibility and long-term maintainability of the Inventory module.

Tasks

  • Check if 5.0's agent suits all the conditions to use RE2.
  • Identify where os_regex is used in the codebase.
  • Replace os_regex with RE2.
  • Refactor the affected code for compatibility.
  • Test the implementation to ensure functionality.

Testing tasks

  • Ensure all unit tests pass after the replacement.
  • Test compatibility on all supported platforms.
@cborla cborla added level/task Task issue type/enhancement Enhancement issue module/agent phase/mvp Minimum Viable Product labels Sep 13, 2024
@cborla cborla changed the title Refactor libraries dependencies in the inventory Refactor library dependencies in the Inventory module Sep 13, 2024
@LucioDonda LucioDonda self-assigned this Sep 13, 2024
@cborla cborla changed the title Refactor library dependencies in the Inventory module Replace os_regex with RE2 in the Inventory Module Sep 13, 2024
@cborla cborla changed the title Replace os_regex with RE2 in the Inventory Module Replace os_regex with RE2 in the Inventory Module Sep 13, 2024
@LucioDonda
Copy link
Member

Update 16/09/2024

  • Check if 5.0's agent suits all the conditions to use RE2.:
    • based on some analysis it can be used without any problem, from c++14 it works. included in vcpk and basic examples checked.
    • Additional performance check here
  • Identify where os_regex is used in the codebase:
    • OS_PRegex: os_string (1) and maybe in the configurations parser.
    • w_regexec: version_op (7) in the future if used maybe on remoted_op and wdb_global
    • w_sql_regex: Not used since 4.8.0 .
  • Starting Replacement generating based UTs to be used for check In the newest version.

@LucioDonda
Copy link
Member

Update 17/09/2024

  • Starting migration.
    • working on some issues regarding compilation of C and C++ alongside

@LucioDonda
Copy link
Member

Update 18/09/2024

After the team daily I came across that I was pointing to the wrong file. New analysis was made:

  1. int OSRegex_Compile(const char *pattern, OSRegex *reg, int flags);
    Brief: Compile a regular expression to be used later
    Usage:

    • expression.c (1)
      Tests (wrap):
    • test_expression (4)
    • github unit tests (8)
  2. const char *OSRegex_Execute(const char *str, OSRegex *reg) __attribute__((nonnull(2)));
    Brief: Compares an already compiled OSRegex regular expression with a string
    Usage:

    • Internal Only (os_regex.c and os_regex_execute.c)
      Tests (wrap):
    • wm_github
  3. const char *OSRegex_Execute_ex(const char *str, OSRegex *reg, regex_matching *regex_match) __attribute__((nonnull(2))); Brief: Compares an already compiled OSRegex regular expression with a string (+ struct for pattern matches)
    Usage:

    • expression.c
      • Internal
        Tests:
    • test_expression
    • wraps schedule_scan , github
  4. void OSRegex_FreePattern(OSRegex *reg);
    Brief: Release all the memory created by the compilation/execution phases
    Usage:

    • expression.c
    • Internal
      Tests:
    • wrap: github
  5. int OS_Regex(const char *pattern, const char *str);
    Brief: wrapper around the compile/execute functions. It should only be used when the pattern is only going to be used once.
    Usage:

    • logcollector (1)
    • common (rootcheck dir) (2)
    • wm_sca (1)
  6. int OSMatch_Compile(const char *pattern, OSMatch *reg, int flags);
    Brief: Compile a pattern to be used later.
    Usage:

    • expression.c
      Tests:
    • fim (test_create_db, test_fim_diff_changes, test_registry)
  7. int OSMatch_Execute(const char *str, size_t str_len, OSMatch *reg);
    Brief: Compare an already compiled pattern with a not NULL string.
    Usage:

    • expression.c
    • fim (create_db, fim_diff_changes, registry)
    • rootcheck.c
  8. void OSMatch_FreePattern(OSMatch *reg);
    Brief: Release all the memory created by the compilation/execution phases */
    Usage:

    • expression.c
      Tests:
    • fim (create_db, registry)
  9. int OS_Match2(const char *pattern, const char *str) __attribute__((nonnull(2)));
    Brief: No Info
    Usage:

    • rootcheck (common)
    • wm_sca

10) int OS_WordMatch(const char *pattern, const char *str) __attribute__((nonnull));
Brief: Searches for pattern in the string
OS_Match ??

  1. char **OS_StrBreak(char match, const char *str, size_t size);
    Brief: Split a string into multiples pieces, divided by a char "match".
    Usage:
    • debug_op (1)
    • schedule_scan (3)
    • string_op (1)
    • version_op
    • config.c
      wm_sca

12) size_t OS_StrHowClosedMatch(const char *str1, const char *str2);
Brief: Returns the number of characters that both strings have in similar

  1. int OS_StrStartsWith(const char *str, const char *pattern) __attribute__((nonnull));
    Brief: Verifies if a string starts with the provided pattern.

  2. int OS_StrIsNum(const char *str);
    Brief: Checks if a specific string is numeric (like "129544") */
    Usage:

    • Schedule_scan
      Tests:
    • test_ schedule scan
  3. void OSRegex_free_regex_matching (regex_matching *reg);
    Brief: Free memory of regex_matching struct
    Usage:

    • expression.c (4)
    • validate_op

@cborla cborla changed the title Replace os_regex with RE2 in the Inventory Module Replace os_regex with RE2 in the Agent Oct 2, 2024
@cborla
Copy link
Member Author

cborla commented Oct 3, 2024

I will move this issue to backlog again because it has no priority.

@cborla cborla added phase/feature complete Feature complete and removed phase/mvp Minimum Viable Product labels Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants