memorysafety / sudo-rs

A memory safe implementation of sudo and su.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Visudo should check env variables

oneElectron opened this issue · comments

ogsudo's visudo reads env variables in order to find the users preferred editor.
This should also be implemented in sudo-rs's visudo.

Additional context

ogsudo looks at the following environment variables in this order to find an editor:

  • SUDO_EDITOR
  • VISUAL
  • EDITOR

If ogsudo's visudo cannot find the editor in one of those places it falls back to the editor set at build time (default is vi).

I would like to work on this issue myself.

Upon closer inpection visudo does include this functionality, however setting the EDITOR variable does not work (but VISUAL and SUDO_EDITOR do work).

That's interesting, there's no special handling for EDITOR, it just happens to be the last one we check:

sudo-rs/src/sudoers/mod.rs

Lines 119 to 133 in 7a2de41

pub(crate) fn solve_editor_path(&self) -> Option<PathBuf> {
if self.settings.flags.contains("env_editor") {
for key in ["SUDO_EDITOR", "VISUAL", "EDITOR"] {
if let Some(var) = std::env::var_os(key) {
let path = Path::new(&var);
if can_execute(path) {
return Some(path.to_owned());
}
}
}
}
None
}
}

Sorry I have made a slight mistake. I thought it wasn't working, but it turns out that I set the EDITOR variable to a command, not the path to the command. I have opened a new issue for this problem: #724