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

parse XML configuration files #159

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jokeyrhyme
Copy link
Contributor

@jokeyrhyme jokeyrhyme commented Oct 27, 2024

based on reading https://dbus.freedesktop.org/doc/dbus-daemon.1.html#configuration_file

Fixes #78 and #79 and #148

Related to #23 and #146

TODOs for follow-up PRs:

  • <selinux>
  • <associate>
  • <apparmor>
  • protect against circular <include> / <includedirs>
  • <include if_selinux_enabled=...>
  • <include selinux_root_relative=...>
  • <listen> better than String values (e.g. parse and validate into more useful type)
  • <auth> better than String, is there an enum of specific values we support
  • validate/warn when using < standard_session_servicedirs /> in a system config
  • validate/warn when using <standard_system_servicedirs /> in a session config
  • validate DOCTYPE
  • validate root element is <busconfig>
  • implement Ord / PartialOrd trait for Policy to facilitate use during evaluation
  • provide default XML configuration files

@jokeyrhyme jokeyrhyme marked this pull request as draft October 27, 2024 03:29
@jokeyrhyme jokeyrhyme changed the title 78 parse xml configuration files parse XML configuration files Oct 27, 2024
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch from bcea200 to 07e1119 Compare October 29, 2024 06:35
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch 2 times, most recently from 9320376 to 6402177 Compare November 10, 2024 01:22
Cargo.toml Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

Mostly have nitpicks but overall it looks pretty good already. Let's try and get it merged soon.

src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 15, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 15, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 15, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 15, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 15, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 16, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 16, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 16, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 16, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 16, 2024
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 16, 2024
@jokeyrhyme jokeyrhyme marked this pull request as ready for review November 17, 2024 10:46
@jokeyrhyme
Copy link
Contributor Author

As mentioned over on Matrix, I propose that we tackle AppArmor/SELinux support in a follow-up PR

Aside from that, I believe we've got a mostly-complete implementation of the XML configuration format, although we don't handle all the same error cases as in #23 or #146

@zeenix
Copy link
Collaborator

zeenix commented Nov 17, 2024

As mentioned over on Matrix, I propose that we tackle AppArmor/SELinux support in a follow-up PR

Sure thing.

Aside from that, I believe we've got a mostly-complete implementation of the XML configuration format

Awesome! I'll have a look soon.

although we don't handle all the same error cases as in #23 or #146

That's ok, we can handle them later. If you could list them here, that would be great though, just to ensure that we don't end up leaving something very important/critical.

Also do we add tests to parse system and session configuration from /usr/share/dbus-1/system.conf and /usr/share/dbus-1/session.conf? I think we should and make it linux-specific.

@jokeyrhyme
Copy link
Contributor Author

Also do we add tests to parse system and session configuration from /usr/share/dbus-1/system.conf and /usr/share/dbus-1/session.conf? I think we should and make it linux-specific.

Do you mean I should copy the default configuration files from dbus-broker in as tests? Or should busd try to read these files by default if run with --session or --system ?

@zeenix
Copy link
Collaborator

zeenix commented Nov 17, 2024

Also do we add tests to parse system and session configuration from /usr/share/dbus-1/system.conf and /usr/share/dbus-1/session.conf? I think we should and make it linux-specific.

Do you mean I should copy the default configuration files from dbus-broker in as tests? Or should busd try to read these files by default if run with --session or --system ?

So busd should most definitely read them from those paths and later when we've some build configuration (#77), we can make the paths configurable at build time too. I was saying we should have tests that also try to load from those paths on Linux but we can also copy them into the repo to keep the tests self-contained (then the tests don't need to be linux-only).

@jokeyrhyme
Copy link
Contributor Author

I've updated the TODO checklist in the PR description

jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 18, 2024
@jokeyrhyme jokeyrhyme marked this pull request as draft November 18, 2024 09:18
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch 2 times, most recently from 57ae57a to 102cf3a Compare November 30, 2024 01:10
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Nov 30, 2024
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch from eb3abf1 to 78aa1f2 Compare December 7, 2024 22:10
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Dec 7, 2024
Copy link
Collaborator

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

Getting real close now. Could you please:

  1. do a self-review, going line by line to ensure everything is in order. I see things like use of eprintln etc.
  2. See that the commit logs are in order. E.g I see a commit not even bothering with . at the end of sentences and one of them using past tense to describe the changes in the commit. BTW, you can write Fixes #1, #2, ....
  3. Squash the last fixup commit into the appropriate commit(s).

I'm guessing you have tested both --system as well?

src/bin/busd.rs Outdated Show resolved Hide resolved
src/config/limits.rs Outdated Show resolved Hide resolved
src/config/mod.rs Outdated Show resolved Hide resolved
@jokeyrhyme jokeyrhyme marked this pull request as draft December 9, 2024 09:27
This crate offers a serde-compatible Deserializer for XML data.
We can deserialize an XML file using the "serde" and "quick-xml" crates.
Creating a struct type with nested structs within is a direct
approach that works well with `#[derive(Deserialize)]`. However, the
result isn't optimal for consumption, and also makes it very difficult
to implement aspects of the business logic that are sensitive to the
order of certain XML elements, e.g. `<bus>`, `<include>`, etc.

So our approach is to first deserialize into a `Vec<Element>` (inspired
by @elmarco 's work over in dbus2#23 ). Importantly, by starting with this
intermediate representation, we can preserve the XML author's intention
regarding the order of elements.

Then we replace any `<include>` and `<includedir>` elements with the
parsed contents the XML files to which they refer, further replacing any
`<include>` and `<includedir>` elements within those.

Finally, we can make one final iteration over the `Vec<Element>` to
produce the final optimally-structured `Config`.

Fixes dbus2#78
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch from 78aa1f2 to 2b9ab6e Compare December 9, 2024 10:30
@jokeyrhyme
Copy link
Contributor Author

I'm guessing you have tested both --system as well?

Yep, I've run it in a container to confirm that it listens on the expected system socket

However, I've not yet tried using this as a replacement for the actual system bus on my machine

@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch from 2b9ab6e to 1f9d177 Compare December 9, 2024 10:33
@jokeyrhyme jokeyrhyme marked this pull request as ready for review December 9, 2024 10:35
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch from 1f9d177 to 2dbc4fd Compare December 9, 2024 10:36
tests/config.rs Outdated Show resolved Hide resolved
src/bin/busd.rs Outdated Show resolved Hide resolved
@jokeyrhyme jokeyrhyme marked this pull request as draft December 11, 2024 09:28
@jokeyrhyme jokeyrhyme force-pushed the 78-parse-xml-configuration-files branch from 2dbc4fd to 2c8b75c Compare December 11, 2024 09:36
@jokeyrhyme jokeyrhyme marked this pull request as ready for review December 11, 2024 09:36
jokeyrhyme added a commit to jokeyrhyme/busd that referenced this pull request Dec 14, 2024
We'll borrow this from dbus2#159 so that we can be clearer about the default
address.
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.

Ability to parse D-Bus configuration file(s)
2 participants