-
Notifications
You must be signed in to change notification settings - Fork 3
tools: source the "Permission denied" message from the OS (#159) #171
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
Open
pierre-warnier
wants to merge
4
commits into
main
Choose a base branch
from
feat/159-os-sourced-error-messages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6ea1a48
shadow-core, tools: source the EACCES message from the OS (#159)
pierre-warnier 15f8ecc
shadow-core: strip Rust's "(os error N)" suffix from strerror
pierre-warnier dbfec6e
shadow-core: use uucore::error::strip_errno instead of hand-rolling
pierre-warnier 92f639d
shadow-core: drop the single-use strerror wrapper
pierre-warnier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| pub mod cli; | ||
| pub mod error; | ||
| pub mod os_error; | ||
| pub mod passwd; | ||
| pub mod validate; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // This file is part of the shadow-rs package. | ||
| // | ||
| // For the full copyright and license information, please view the LICENSE | ||
| // file that was distributed with this source code. | ||
|
|
||
| //! Error text sourced from the operating system instead of hardcoded. | ||
| //! | ||
| //! Wording for conditions that map to a libc `errno` is taken from the OS | ||
| //! (libc's `strerror`, surfaced through [`std::io::Error`]) rather than | ||
| //! carried as a string literal in our tree. This keeps the text matching the | ||
| //! host OS and lets glibc translate it on localized systems — the same way | ||
| //! GNU coreutils renders system errors (e.g. `cat: /tmp: Is a directory`). | ||
| //! See issue #159. | ||
|
|
||
| /// The OS message for `EACCES` ("Permission denied"), sourced from libc. | ||
| /// | ||
| /// Rendered as "Permission denied" on English locales and the translated | ||
| /// equivalent elsewhere; on a libc that does not translate (musl) it is the | ||
| /// untranslated English text. `strip_errno` (the helper uucore uses for its | ||
| /// own I/O errors) drops the " (os error N)" suffix that `io::Error`'s | ||
| /// `Display` appends, leaving the bare OS message — matching coreutils output. | ||
| #[must_use] | ||
| pub fn permission_denied() -> String { | ||
| uucore::error::strip_errno(&std::io::Error::from_raw_os_error(libc::EACCES)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn permission_denied_is_bare_os_message() { | ||
| let msg = permission_denied(); | ||
| // Non-empty, and the bare OS text — not Rust's "... (os error 13)" | ||
| // rendering (the regression that suffix-stripping prevents). We assert | ||
| // the shape, not the exact wording, since libc may localize it. | ||
| assert!(!msg.is_empty()); | ||
| assert!(!msg.contains("(os error"), "got: {msg:?}"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 am not sure we need this function either, just call the previous line
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.
Happy to — one consideration:
permission_denied()is called from 13 sites across 9 tools (the root-check guard in chage, chpasswd, groupadd, groupdel, groupmod, passwd, useradd, userdel, usermod). Inlining means repeatinguucore::error::strip_errno(&std::io::Error::from_raw_os_error(libc::EACCES))at each one.Do you still prefer inlining it everywhere, or would you rather a different shape — e.g. argument-less
PermissionDeniederror variants that render the OS message in their ownDisplay? Happy to go whichever way you think reads best.