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

Function read_sshd_config

resources/sshdconfig/src/util.rs:231–246  ·  view source on GitHub ↗

Reads `sshd_config` file. # Arguments `input` - Optional `PathBuf` with `sshd_config` filepath. # Errors This function will return an error if the file cannot be found or read.

(input: Option<PathBuf>)

Source from the content-addressed store, hash-verified

229///
230/// This function will return an error if the file cannot be found or read.
231pub fn read_sshd_config(input: Option<PathBuf>) -> Result<String, SshdConfigError> {
232 let filepath = get_default_sshd_config_path(input)?;
233 if filepath.exists() {
234 let mut sshd_config_content = String::new();
235 if let Ok(mut file) = std::fs::OpenOptions::new().read(true).open(&filepath) {
236 use std::io::Read;
237 file.read_to_string(&mut sshd_config_content)
238 .map_err(|e| SshdConfigError::CommandError(e.to_string()))?;
239 } else {
240 return Err(SshdConfigError::CommandError(t!("util.sshdConfigReadFailed", path = filepath.display()).to_string()));
241 }
242 Ok(sshd_config_content)
243 } else {
244 Err(SshdConfigError::FileNotFound(filepath.display().to_string()))
245 }
246}
247
248

Callers 1

get_sshd_settingsFunction · 0.85

Calls 3

newFunction · 0.50
openMethod · 0.45

Tested by

no test coverage detected