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

Add systemd support to the config_parser utility #460

Merged
merged 23 commits into from
Dec 12, 2023

Conversation

Miauwkeru
Copy link
Contributor

  • Force parsed_data to always be a dictionary
  • Improve API for config_tree functionality

@Miauwkeru Miauwkeru force-pushed the DIS-2158_add-systemd-support-to-config-parser branch 3 times, most recently from 8e335cc to 3ba0dc0 Compare November 27, 2023 12:58
Copy link

codecov bot commented Nov 27, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (7461516) 73.93% compared to head (3ce0603) 74.02%.

Files Patch % Lines
dissect/target/filesystems/config.py 70.96% 9 Missing ⚠️
dissect/target/plugins/os/unix/linux/services.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #460      +/-   ##
==========================================
+ Coverage   73.93%   74.02%   +0.08%     
==========================================
  Files         259      259              
  Lines       20886    20945      +59     
==========================================
+ Hits        15443    15505      +62     
+ Misses       5443     5440       -3     
Flag Coverage Δ
unittests 74.02% <94.08%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Miauwkeru Miauwkeru force-pushed the DIS-2158_add-systemd-support-to-config-parser branch from 1a9bdcd to 67e140e Compare November 29, 2023 15:39
@Miauwkeru Miauwkeru requested a review from Horofic November 29, 2023 15:39
@Miauwkeru Miauwkeru marked this pull request as ready for review November 29, 2023 15:47
@@ -107,45 +104,19 @@ def should_ignore_file(needle: str, haystack: list) -> bool:
return False


def parse_systemd_config(fh: TextIO) -> str:
def create_systemd_string(parsed_systemd_dict: dict[str, dict]) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this defeat the purpose of the whole config parsing? Ideally you want to make use of the new parsing features, and change the unix services plugin to dynamically include the parsed key / value pairs in the record output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just changed it to have the same behavior as before but using the config parser.
It wasn't my intent yet to make a record with dynamic value pairs, tho I can also just do that...

Then this is a heads-up for the @JSCU-CNI , as the output of this plugin will change drastically

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide a changelog or example to showcase the difference in output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the current changes, the record would change from (created with rdump -L):

--[ RECORD 1 ]--
       hostname = test
         domain = None
             ts = 2022-06-03 21:28:07+00:00
           name = dbus-fi.w1.wpa_supplicant1.service
         config = Unit_Description="WPA supplicant" Unit_Before="network.target" Unit_After="dbus.service" Unit_Wants="network.target" Unit_IgnoreOnIsolate="true" Service_Type="dbus" Service_BusName="fi.w1.wpa_supplicant1" Service_ExecStart="/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant" Service_ExecReload="/bin/kill -HUP $MAINPID" Install_WantedBy="multi-user.target" Install_Alias="dbus-fi.w1.wpa_supplicant1.service"
         source = /etc/systemd/system/dbus-fi.w1.wpa_supplicant1.service
        _source = /home/user/media/test
_classification = None
     _generated = 2023-12-06 15:38:25.286011+00:00
       _version = 1

where all the information is in config, to the following:

--[ RECORD 1 ]--
            hostname = test
              domain = None
                  ts = 2022-06-03 21:28:07+00:00
                type = systemd
                name = dbus-fi.w1.wpa_supplicant1.service
              source = /etc/systemd/system/dbus-fi.w1.wpa_supplicant1.service
    Unit_Description = WPA supplicant
         Unit_Before = network.target
          Unit_After = dbus.service
          Unit_Wants = network.target
Unit_IgnoreOnIsolate = true
        Service_Type = dbus
     Service_BusName = fi.w1.wpa_supplicant1
   Service_ExecStart = /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
  Service_ExecReload = /bin/kill -HUP $MAINPID
    Install_WantedBy = multi-user.target
       Install_Alias = dbus-fi.w1.wpa_supplicant1.service
             _source = /home/user/media/test
     _classification = None
          _generated = 2023-12-06 15:39:41.306051+00:00
            _version = 1
  • Both initd and systemd records would have an additional type field for the type of service.
  • config would not exists anymore
  • All previous config values would be inserted into the record itself as key value pairs.
  • If the the value is empty, it will be set to None

@Miauwkeru Miauwkeru force-pushed the DIS-2158_add-systemd-support-to-config-parser branch from 7dc2a3e to e53fb6c Compare December 6, 2023 13:43
@Miauwkeru Miauwkeru requested a review from Horofic December 6, 2023 13:43
@Miauwkeru Miauwkeru force-pushed the DIS-2158_add-systemd-support-to-config-parser branch 2 times, most recently from 1f50d10 to eb8aca9 Compare December 6, 2023 15:48
Copy link
Contributor

@Horofic Horofic left a comment

Choose a reason for hiding this comment

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

I'm still torn on whether going the "Filesystem" route is the right course. A lot of functions act like a that of a file system but have some side-effect or caveat you end up needing to explain in your documentation.

This also makes using the API not that intuitive as you would think, because you need to account for these specifics.

Going more into the route what the Registry is currently doing might make the API more clear. Thoughts @Miauwkeru, @Schamper?

@@ -86,15 +95,27 @@ def __init__(
fs: Filesystem,
path: str,
entry: FilesystemEntry,
parser_items: Optional[Union[dict, Any]] = None,
parser_items: Optional[Union[dict, ConfigurationParser, Any]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
parser_items: Optional[Union[dict, ConfigurationParser, Any]] = None,
parser_items: Optional[Union[dict, ConfigurationParser, str, list]] = None,

@Miauwkeru
Copy link
Contributor Author

I'm still torn on whether going the "Filesystem" route is the right course. A lot of functions act like a that of a file system but have some side-effect or caveat you end up needing to explain in your documentation.

This also makes using the API not that intuitive as you would think, because you need to account for these specifics.

Going more into the route what the Registry is currently doing might make the API more clear. Thoughts @Miauwkeru, @Schamper?

I can make a pr in the future that would replace the Filesystem route with the Registry one, so we can see whether it would make the API clearer. I don't think it would fit in this PR though.

@Miauwkeru Miauwkeru force-pushed the DIS-2158_add-systemd-support-to-config-parser branch from 5d6f534 to 4c7a35c Compare December 8, 2023 15:06
@Miauwkeru Miauwkeru requested a review from Horofic December 8, 2023 15:06
@Miauwkeru Miauwkeru requested a review from Horofic December 12, 2023 12:02
Horofic
Horofic previously approved these changes Dec 12, 2023
@Miauwkeru Miauwkeru force-pushed the DIS-2158_add-systemd-support-to-config-parser branch from baedde4 to 7177f42 Compare December 12, 2023 12:34
@Miauwkeru Miauwkeru merged commit 3a298a4 into main Dec 12, 2023
@Miauwkeru Miauwkeru deleted the DIS-2158_add-systemd-support-to-config-parser branch December 12, 2023 13:06
JSCU-CNI pushed a commit to JSCU-CNI/dissect.target that referenced this pull request Jan 2, 2024
API changes:
- made as_dict behaviour consistent
- Able to use any kind of Iterable as a `collapse` argument
- always put everything as dict
- add tests for those for the things above

Other additions:
- Adds a `ScopeManager` to create a base scoping mechanism
- Raise a `FileNotFoundError` when `entry.get()` is None
- Improve documentation of everything, using sphinx style.

(DIS-2158)

---
Co-authored-by: Stefan de Reuver <[email protected]>
Poeloe pushed a commit that referenced this pull request Feb 29, 2024
API changes:
- made as_dict behaviour consistent
- Able to use any kind of Iterable as a `collapse` argument
- always put everything as dict
- add tests for those for the things above

Other additions:
- Adds a `ScopeManager` to create a base scoping mechanism
- Raise a `FileNotFoundError` when `entry.get()` is None
- Improve documentation of everything, using sphinx style.

(DIS-2158)

---
Co-authored-by: Stefan de Reuver <[email protected]>
Zawadidone pushed a commit to Zawadidone/dissect.target that referenced this pull request Apr 5, 2024
API changes:
- made as_dict behaviour consistent
- Able to use any kind of Iterable as a `collapse` argument
- always put everything as dict
- add tests for those for the things above

Other additions:
- Adds a `ScopeManager` to create a base scoping mechanism
- Raise a `FileNotFoundError` when `entry.get()` is None
- Improve documentation of everything, using sphinx style.

(DIS-2158)

---
Co-authored-by: Stefan de Reuver <[email protected]>
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.

3 participants