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

switch: please provide a graceful destructor for SwitchUserGuard #31

Open
lucab opened this issue Oct 23, 2018 · 0 comments
Open

switch: please provide a graceful destructor for SwitchUserGuard #31

lucab opened this issue Oct 23, 2018 · 0 comments
Assignees

Comments

@lucab
Copy link

lucab commented Oct 23, 2018

Currently, the only way to revert the effects of a switch_user_group is to drop the returned SwitchUserGuard. However, Drop is not allowed to fail, so any internal failure directly translates to a panic:

impl Drop for SwitchUserGuard {
    fn drop(&mut self) {
        // Panic on error here, as failing to set values back
        // is a possible security breach.
        set_effective_uid(self.uid).unwrap();
        set_effective_gid(self.gid).unwrap();
    }
}

As a consumer of this crate, I'd like to have a way to switch back to the original state (consuming the guard at the same time) and get back a Result to handle the error case as usual.

I guess the signature would be something like:

pub fn reset (self /* : SwitchUserGuard */) -> IOResult<()> 
@lucab lucab changed the title switch: please provide a graceful destructor SwitchUserGuard switch: please provide a graceful destructor for SwitchUserGuard Oct 23, 2018
@ogham ogham self-assigned this Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants