trifectatechfoundation / sudo-rs

A memory safe implementation of sudo and su.
Other
2.9k stars 79 forks source link

`sudoers/@include`: expand `%h` to hostname #734

Closed xy2i closed 1 year ago

xy2i commented 1 year ago

We don't want to compute the hostname each time, as it may change between invocations.

This needs a small refactor: the hostname is computed in Context, but by this time the sudoers file is already parsed and analyzed:

let sudoers = self.policy.init()?; <- can't put context here
let context = super::build_context(cmd_opts, &sudoers)?;

But things like the hostname and the current user don't depend on sudoers and command line opts. Split these out into another context, SystemContext, and pass them when analyzing the sudoers file.

Fixes https://github.com/memorysafety/sudo-rs/issues/676

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 40.65% and project coverage change: -0.05% :warning:

Comparison is base (81fe097) 54.67% compared to head (f37c8f2) 54.62%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #734 +/- ## ========================================== - Coverage 54.67% 54.62% -0.05% ========================================== Files 71 71 Lines 9665 9720 +55 ========================================== + Hits 5284 5310 +26 - Misses 4381 4410 +29 ``` | [Files Changed](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety) | Coverage Δ | | |---|---|---| | [src/sudo/mod.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3N1ZG8vbW9kLnJz) | `0.00% <0.00%> (ø)` | | | [src/sudo/pipeline.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3N1ZG8vcGlwZWxpbmUucnM=) | `0.00% <0.00%> (ø)` | | | [src/sudo/pipeline/list.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3N1ZG8vcGlwZWxpbmUvbGlzdC5ycw==) | `0.00% <0.00%> (ø)` | | | [src/visudo/mod.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3Zpc3Vkby9tb2QucnM=) | `0.00% <0.00%> (ø)` | | | [src/sudoers/mod.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3N1ZG9lcnMvbW9kLnJz) | `68.12% <25.00%> (-1.37%)` | :arrow_down: | | [src/common/context.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL2NvbW1vbi9jb250ZXh0LnJz) | `83.67% <88.88%> (-0.42%)` | :arrow_down: | | [src/sudoers/test/mod.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3N1ZG9lcnMvdGVzdC9tb2QucnM=) | `98.42% <100.00%> (+0.09%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/734/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

squell commented 1 year ago

Thanks for your contribution! 🎉 Someone will review it next week.

squell commented 1 year ago

Related: #740; if we decide to merge that this one should probably close.

rnijveld commented 1 year ago

Closing in favor of #740