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>)
| 229 | /// |
| 230 | /// This function will return an error if the file cannot be found or read. |
| 231 | pub 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 |
no test coverage detected