system/term: Improve resolution for setting a valid PAM_TTY#1591
Open
3v1n0 wants to merge 5 commits into
Open
Conversation
2 tasks
ecbdd7e to
6b038c3
Compare
Resolve the terminal path by checking stdin, stdout, and stderr in order, instead of only stdin. This matches sudo's stdio probing fallback behavior and improves PAM_TTY detection when stdin is redirected but another stdio fd is still attached to the controlling terminal. For example when using tools such as sshuttle Helps with: trifectatechfoundation#1593
Resolve PAM_TTY on Linux by first reading the controlling tty device
from /proc/self/stat, then mapping that device to a path using
sudo.ws-compatible resolution order:
- /proc/self/fd/{0,1,2} when the fd device matches
- /dev/console
- /dev/pts
- /dev scan fallback
If device-based resolution does not succeed, fall back to probing other
standard tty names (stdin/stdout/stderr) as before.
Actually closes: trifectatechfoundation#1260
Closes: trifectatechfoundation#1593
Note that this test was failing despite trifectatechfoundation#1260 being advertised as fixed Closes: trifectatechfoundation#1393
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In sudo-rs we're just trying to use stdin as
PAM_TTY, but this may not be available if some input is redirected.For example, using tools such as
sshuttlewithsudo-rs,PAM_TTY, is currently unset while it's/dev/pts/3with sudo.wsNow, the first commit would be enough to handle this in a simple way, but I also implemented a logic (for linux only, although BSDs can be added too), to follow the same logic that sudo is using to pick the TTY in a follow-up commit. Not sure if we have to go that deep though.
A simpler reproducer is (bug visible when uising
--close-stdinor--stdin-devnull):Closes: #1593