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

does not preserve EUID #7

Open
jlgerber opened this issue Jun 7, 2019 · 0 comments
Open

does not preserve EUID #7

jlgerber opened this issue Jun 7, 2019 · 0 comments

Comments

@jlgerber
Copy link

jlgerber commented Jun 7, 2019

I have an executable that uses shellfn::shell to execute a command and the executable has the SUID bit set, but the euid does not get preserved in the shell, whereas it does with the std library subprocess.
to test this I wrote an executable that does this:

use nix::unistd::{getuid, geteuid};

fn main() {
    println!("euid {:?} {:?}", getuid(), geteuid());
}

and then wrote an executable to shell out and call it:


use shellfn::shell;
use nix::unistd::{getuid, geteuid};

fn main() {
    println!("euid {:?} {:?}", getuid(), geteuid());

    let info = _info().unwrap();
    //let info = _info2();
    println!("subprocess {}", info);
}

#[shell]
fn _info() -> Result<String, Box<std::error::Error>> { r#"
    ./subpuid
"# }

fn _info2() -> String {
    let output = std::process::Command::new("./subpuid")
                     .output()
                     .expect("failed to execute process");

   let scow = String::from_utf8_lossy(&output.stdout);
   let mut op = String::new();
   op.push_str(&scow);
   op
}

If you change the owner on the main command and set its euid bit (chmod u+s fllename) then run it, you will see that the EUID gets lost when compiled with _info but not _info2.

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

No branches or pull requests

1 participant