MCPcopy Create free account
hub / github.com/PowerShell/DSC / set_default_shell

Function set_default_shell

resources/sshdconfig/src/set.rs:128–161  ·  view source on GitHub ↗
(shell: String, cmd_option: Option<String>, escape_arguments: Option<bool>)

Source from the content-addressed store, hash-verified

126
127#[cfg(windows)]
128fn set_default_shell(shell: String, cmd_option: Option<String>, escape_arguments: Option<bool>) -> Result<(), SshdConfigError> {
129 debug!("{}", t!("set.settingDefaultShell"));
130 if shell.is_empty() {
131 remove_registry(DEFAULT_SHELL)?;
132 } else {
133 // TODO: if shell contains quotes, we need to remove them
134 let shell_path = Path::new(&shell);
135 if shell_path.is_relative() && shell_path.components().any(|c| c == std::path::Component::ParentDir) {
136 return Err(SshdConfigError::InvalidInput(t!("set.shellPathMustNotBeRelative").to_string()));
137 }
138 if !shell_path.exists() {
139 return Err(SshdConfigError::InvalidInput(t!("set.shellPathDoesNotExist", shell = shell).to_string()));
140 }
141 set_registry(DEFAULT_SHELL, RegistryValueData::String(shell))?;
142 }
143
144 if let Some(cmd_option) = cmd_option {
145 set_registry(DEFAULT_SHELL_CMD_OPTION, RegistryValueData::String(cmd_option.clone()))?;
146 } else {
147 remove_registry(DEFAULT_SHELL_CMD_OPTION)?;
148 }
149
150 if let Some(escape_args) = escape_arguments {
151 let mut escape_data = 0;
152 if escape_args {
153 escape_data = 1;
154 }
155 set_registry(DEFAULT_SHELL_ESCAPE_ARGS, RegistryValueData::DWord(escape_data))?;
156 } else {
157 remove_registry(DEFAULT_SHELL_ESCAPE_ARGS)?;
158 }
159
160 Ok(())
161}
162
163#[cfg(not(windows))]
164fn set_default_shell(_shell: String, _cmd_option: Option<String>, _escape_arguments: Option<bool>) -> Result<(), SshdConfigError> {

Callers 1

invoke_setFunction · 0.85

Calls 4

remove_registryFunction · 0.85
set_registryFunction · 0.85
newFunction · 0.50
is_emptyMethod · 0.45

Tested by

no test coverage detected