trifectatechfoundation / sudo-rs

A memory safe implementation of sudo and su.
Other
2.88k stars 77 forks source link

refactor sudo CLI #774

Closed japaric closed 10 months ago

japaric commented 12 months ago

currently there's a SudoAction enum, a SudoOptions struct and a validate method in the cli module. ideally, the validate function / method should returned a cooked / sanitized action enum where its variants contain the flags that are valid for that particular action. something like the code block below

pub enum CookedSudoAction {
    Help, // no options can be passed here
    Run {
        flag_user: Option<String>,
        flag_group: Option<String>,
        // ..
        cmnd_args: Vec<String>, // not-empty vector
    },
    Validate {
        // no cmnd_args field here
    }
    // ...
}

the goal is to discard the fields in SudoOptions that do not apply to a particular action so that when handling a particular "action" later in the pipeline one does not accept an invalid option / flag by mistake. thus validate should consume SudoOptions

one could even add extra validation at this step and represent flag_{user,group} as NameOrId rather than as a string.