-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add systemd support to the config_parser utility #460
Conversation
Miauwkeru
commented
Nov 27, 2023
- Force parsed_data to always be a dictionary
- Improve API for config_tree functionality
8e335cc
to
3ba0dc0
Compare
Codecov ReportAttention:
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
1a9bdcd
to
67e140e
Compare
@@ -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: |
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.
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.
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.
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
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.
Could you provide a changelog or example to showcase the difference in output?
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.
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
andsystemd
records would have an additionaltype
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
7dc2a3e
to
e53fb6c
Compare
1f50d10
to
eb8aca9
Compare
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.
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?
dissect/target/filesystems/config.py
Outdated
@@ -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, |
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.
parser_items: Optional[Union[dict, ConfigurationParser, Any]] = None, | |
parser_items: Optional[Union[dict, ConfigurationParser, str, list]] = None, |
I can make a pr in the future that would replace the |
5d6f534
to
4c7a35c
Compare
- made as_dict behaviour consistent - Able to use Any kind of iterable as ``collapse`` argument - always put everything as dict - add tests for those things
Co-authored-by: Stefan de Reuver <[email protected]>
Co-authored-by: Stefan de Reuver <[email protected]>
baedde4
to
7177f42
Compare
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]>
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]>
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]>