Skip to content

Commit

Permalink
rename sudo CLI structs
Browse files Browse the repository at this point in the history
to avoid future collision with su/visudo CLI structs
  • Loading branch information
japaric authored and pvdrz committed Nov 2, 2023
1 parent fbe5474 commit a926ce6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
68 changes: 34 additions & 34 deletions src/sudo/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub mod help;
mod tests;

pub enum SudoAction {
Edit(EditOptions),
Help(HelpOptions),
List(ListOptions),
RemoveTimestamp(RemoveTimestampOptions),
ResetTimestamp(ResetTimestampOptions),
Run(RunOptions),
Validate(ValidateOptions),
Version(VersionOptions),
Edit(SudoEditOptions),
Help(SudoHelpOptions),
List(SudoListOptions),
RemoveTimestamp(SudoRemoveTimestampOptions),
ResetTimestamp(SudoResetTimestampOptions),
Run(SudoRunOptions),
Validate(SudoValidateOptions),
Version(SudoVersionOptions),
}

impl SudoAction {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl SudoAction {
}

#[cfg(test)]
pub fn try_into_run(self) -> Result<RunOptions, Self> {
pub fn try_into_run(self) -> Result<SudoRunOptions, Self> {
if let Self::Run(v) = self {
Ok(v)
} else {
Expand All @@ -96,9 +96,9 @@ impl SudoAction {
}

// sudo -h | -K | -k | -V
pub struct HelpOptions {}
pub struct SudoHelpOptions {}

impl TryFrom<SudoOptions> for HelpOptions {
impl TryFrom<SudoOptions> for SudoHelpOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand All @@ -113,9 +113,9 @@ impl TryFrom<SudoOptions> for HelpOptions {
}

// sudo -h | -K | -k | -V
pub struct VersionOptions {}
pub struct SudoVersionOptions {}

impl TryFrom<SudoOptions> for VersionOptions {
impl TryFrom<SudoOptions> for SudoVersionOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand All @@ -130,9 +130,9 @@ impl TryFrom<SudoOptions> for VersionOptions {
}

// sudo -h | -K | -k | -V
pub struct RemoveTimestampOptions {}
pub struct SudoRemoveTimestampOptions {}

impl TryFrom<SudoOptions> for RemoveTimestampOptions {
impl TryFrom<SudoOptions> for SudoRemoveTimestampOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand All @@ -147,9 +147,9 @@ impl TryFrom<SudoOptions> for RemoveTimestampOptions {
}

// sudo -h | -K | -k | -V
pub struct ResetTimestampOptions {}
pub struct SudoResetTimestampOptions {}

impl TryFrom<SudoOptions> for ResetTimestampOptions {
impl TryFrom<SudoOptions> for SudoResetTimestampOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand All @@ -164,7 +164,7 @@ impl TryFrom<SudoOptions> for ResetTimestampOptions {
}

// sudo -v [-ABkNnS] [-g group] [-h host] [-p prompt] [-u user]
pub struct ValidateOptions {
pub struct SudoValidateOptions {
// -k
pub reset_timestamp: bool,
// -n
Expand All @@ -177,7 +177,7 @@ pub struct ValidateOptions {
pub user: Option<SudoString>,
}

impl TryFrom<SudoOptions> for ValidateOptions {
impl TryFrom<SudoOptions> for SudoValidateOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand All @@ -204,7 +204,7 @@ impl TryFrom<SudoOptions> for ValidateOptions {
}

// sudo -e [-ABkNnS] [-r role] [-t type] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...
pub struct EditOptions {
pub struct SudoEditOptions {
// -k
pub reset_timestamp: bool,
// -n
Expand All @@ -220,7 +220,7 @@ pub struct EditOptions {
pub positional_args: Vec<String>,
}

impl TryFrom<SudoOptions> for EditOptions {
impl TryFrom<SudoOptions> for SudoEditOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -255,7 +255,7 @@ impl TryFrom<SudoOptions> for EditOptions {
}

// sudo -l [-ABkNnS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command [arg ...]]
pub struct ListOptions {
pub struct SudoListOptions {
// -l OR -l -l
pub list: List,

Expand All @@ -275,7 +275,7 @@ pub struct ListOptions {
pub positional_args: Vec<String>,
}

impl TryFrom<SudoOptions> for ListOptions {
impl TryFrom<SudoOptions> for SudoListOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -312,7 +312,7 @@ impl TryFrom<SudoOptions> for ListOptions {
}

// sudo [-ABbEHnPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i | -s] [command [arg ...]]
pub struct RunOptions {
pub struct SudoRunOptions {
// -E
pub preserve_env: Vec<String>,
// -k
Expand All @@ -336,7 +336,7 @@ pub struct RunOptions {
pub positional_args: Vec<String>,
}

impl TryFrom<SudoOptions> for RunOptions {
impl TryFrom<SudoOptions> for SudoRunOptions {
type Error = String;

fn try_from(mut opts: SudoOptions) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -762,9 +762,9 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
Ok(())
}

impl From<ListOptions> for OptionsForContext {
fn from(opts: ListOptions) -> Self {
let ListOptions {
impl From<SudoListOptions> for OptionsForContext {
fn from(opts: SudoListOptions) -> Self {
let SudoListOptions {
group,
non_interactive,
positional_args,
Expand Down Expand Up @@ -793,9 +793,9 @@ impl From<ListOptions> for OptionsForContext {
}
}

impl From<ValidateOptions> for OptionsForContext {
fn from(opts: ValidateOptions) -> Self {
let ValidateOptions {
impl From<SudoValidateOptions> for OptionsForContext {
fn from(opts: SudoValidateOptions) -> Self {
let SudoValidateOptions {
group,
non_interactive,
reset_timestamp,
Expand All @@ -820,9 +820,9 @@ impl From<ValidateOptions> for OptionsForContext {
}
}

impl From<RunOptions> for OptionsForContext {
fn from(opts: RunOptions) -> Self {
let RunOptions {
impl From<SudoRunOptions> for OptionsForContext {
fn from(opts: SudoRunOptions) -> Self {
let SudoRunOptions {
chdir,
group,
login,
Expand Down
4 changes: 2 additions & 2 deletions src/sudo/env/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::{CommandAndArguments, Context, Environment};
use crate::sudo::{
cli::{RunOptions, SudoAction},
cli::{SudoAction, SudoRunOptions},
env::environment::get_target_environment,
};
use crate::system::{Group, Process, User};
Expand Down Expand Up @@ -75,7 +75,7 @@ fn parse_env_commands(input: &str) -> Vec<(&str, Environment)> {
.collect()
}

fn create_test_context(sudo_options: &RunOptions) -> Context {
fn create_test_context(sudo_options: &SudoRunOptions) -> Context {
let path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".to_string();
let command =
CommandAndArguments::build_from_args(None, sudo_options.positional_args.clone(), &path);
Expand Down
6 changes: 3 additions & 3 deletions src/sudo/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::OsStr;
use std::process::exit;

use super::cli::{RunOptions, ValidateOptions};
use super::cli::{SudoRunOptions, SudoValidateOptions};
use crate::common::context::OptionsForContext;
use crate::common::{Context, Environment, Error};
use crate::exec::{ExecOutput, ExitReason};
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct Pipeline<Policy: PolicyPlugin, Auth: AuthPlugin> {
}

impl<Policy: PolicyPlugin, Auth: AuthPlugin> Pipeline<Policy, Auth> {
pub fn run(mut self, cmd_opts: RunOptions) -> Result<(), Error> {
pub fn run(mut self, cmd_opts: SudoRunOptions) -> Result<(), Error> {
let pre = self.policy.init()?;
let mut context = build_context(cmd_opts.into(), &pre)?;

Expand Down Expand Up @@ -100,7 +100,7 @@ impl<Policy: PolicyPlugin, Auth: AuthPlugin> Pipeline<Policy, Auth> {
Ok(())
}

pub fn run_validate(mut self, cmd_opts: ValidateOptions) -> Result<(), Error> {
pub fn run_validate(mut self, cmd_opts: SudoValidateOptions) -> Result<(), Error> {
let pre = self.policy.init()?;
let context = build_context(cmd_opts.into(), &pre)?;

Expand Down
4 changes: 2 additions & 2 deletions src/sudo/pipeline/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::{borrow::Cow, ops::ControlFlow, path::Path};
use crate::{
common::{Context, Error},
pam::CLIConverser,
sudo::{cli::ListOptions, pam::PamAuthenticator, SudoersPolicy},
sudo::{cli::SudoListOptions, pam::PamAuthenticator, SudoersPolicy},
sudoers::{Authorization, ListRequest, Policy, Request, Sudoers},
system::User,
};

use super::{Pipeline, PolicyPlugin};

impl Pipeline<SudoersPolicy, PamAuthenticator<CLIConverser>> {
pub(in crate::sudo) fn run_list(mut self, cmd_opts: ListOptions) -> Result<(), Error> {
pub(in crate::sudo) fn run_list(mut self, cmd_opts: SudoListOptions) -> Result<(), Error> {
let verbose_list_mode = cmd_opts.list.is_verbose();
let other_user = cmd_opts
.other_user
Expand Down

0 comments on commit a926ce6

Please sign in to comment.