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

Mixed consuming/mutable reference access to RulesetCreated::add_rule #19

Closed
wants to merge 4 commits into from

Conversation

andreaphylum
Copy link

This patch takes the ideas discussed in #16 and implements a wrapper type, RulesetCreatedMut (following the standard library convention of using Mut to refer to mutable references, e.g. AsMut vs. AsRef).

  • A RulesetCreated::as_mut method is created, which returns an instance of the newtype.
  • The main, now non-consuming implementations are moved into the RulesetCreatedMut::add_rule and RulesetCreatedMut::add_rules methods, and are called by the original methods via as_mut() before returning self.
  • The set_no_new_privs method is copied over, as it is a one-liner.

This should hopefully not be a breaking change for other dependents of rust-landlock, as the consuming API is left intact.

Having to explicitly go through as_mut to access the non-consuming methods might not be super intuitive, but I think it is a good, low-impact compromise.

There's still the issue of having to maintain duplicated methods going forward, but I believe that in order to implement any future method on the consuming side it would be enough to do a trivial call to the non-consuming side.

Thank you for your work on rust-landlock!

Signed-off-by: Andrea Venuta <andrea@phylum.io>
Signed-off-by: Andrea Venuta <andrea@phylum.io>
Signed-off-by: Andrea Venuta <andrea@phylum.io>
Signed-off-by: Andrea Venuta <andrea@phylum.io>
@andreaphylum
Copy link
Author

Hi! Just wanted to follow up on this. Are the changes in this PR something you'd be interested in integrating upstream? We're considering releasing our abstraction project on crates.io. At the moment it relies on our fork, but we'd like to use an official release as we won't be able to publish the crate otherwise.

Again, thank you for your work!

@l0kod
Copy link
Member

l0kod commented Oct 23, 2022

Hi @andreaphylum! Thanks for your PR. I've been busy and didn't want to rush this review, but I'll do it next week.

Copy link
Member

@l0kod l0kod left a comment

Choose a reason for hiding this comment

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

I like the code, it is clean and well split, but I think we can do simpler with #20. What do you think?

///
/// drop(ruleset);
/// ```
pub fn as_mut(&mut self) -> RulesetCreatedMut<'_> {
Copy link
Member

Choose a reason for hiding this comment

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

as_mut() is the same as the one provided by the AsMut trait, but it is not the same signature. I think it is not a good idea.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, this was an unfortunate compromise I had to settle upon eventually, as implementing AsMut had some issues that made the rest of the code significantly more convoluted and need many more workarounds.

l0kod added a commit to l0kod/rust-landlock that referenced this pull request Oct 28, 2022
This enables to make add_rule(), add_rules() and set_no_new_privs()
available from a RulesetCreated reference.

Users need to import the RulesetCreatedRef trait to call such methods.

Closes landlock-lsm#19

Signed-off-by: Mickaël Salaün <mic@digikod.net>
l0kod added a commit to l0kod/rust-landlock that referenced this pull request Nov 4, 2022
This enables to make add_rule(), add_rules() and set_no_new_privs()
available from a RulesetCreated reference.

Implement AsMut<RulesetCreated>, required by RulesetCreatedAttr.

Users need to import the RulesetCreatedAttr trait to call such methods.

Closes landlock-lsm#19

Signed-off-by: Mickaël Salaün <mic@digikod.net>
l0kod added a commit to l0kod/rust-landlock that referenced this pull request Nov 4, 2022
This enables to make add_rule(), add_rules() and set_no_new_privs()
available from a RulesetCreated reference.

Implement AsMut<RulesetCreated>, required by RulesetCreatedAttr.

Users need to import the RulesetCreatedAttr trait to call such methods.

Closes landlock-lsm#19

Signed-off-by: Mickaël Salaün <mic@digikod.net>
l0kod added a commit to l0kod/rust-landlock that referenced this pull request Nov 4, 2022
This enables to make add_rule(), add_rules() and set_no_new_privs()
available from a RulesetCreated reference.

Implement AsMut<RulesetCreated>, required by RulesetCreatedAttr.

Users need to import the RulesetCreatedAttr trait to call such methods.

Closes landlock-lsm#19

Signed-off-by: Mickaël Salaün <mic@digikod.net>
@l0kod l0kod closed this in d841d42 Nov 9, 2022
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.

2 participants