/// read_all_keys reads all of the authorized keys files in a given
/// directory. it returns an error if there is a nested directory, if any
/// file operations fail, or if it can't parse any of the authorized_keys
/// files
read_all_keys reads all of the authorized keys files in a given
directory. it returns an error if there is a nested directory, if any
file operations fail, or if it can't parse any of the authorized_keys
files
read_all_keys reads all of the authorized keys files in a given directory . it returns an error if there is a nested directory if any file operations fail or if it can ' t parse any of the authorized_keys files
fn read_all_keys(dir: &Path) -> Result<HashMap<String, AuthorizedKeySet>> {
        let dir_contents =
            fs::read_dir(&dir).chain_err(|| format!("failed to read from directory {:?}", dir))?;
        let mut keys = HashMap::new();
        for entry in dir_contents {
            let entry =
                entry.chain_err(|| format!("failed to read entry in directory {:?}", dir))?;
            let path = entry.path();
            if path.is_dir() {
                // if it's a directory, we don't know what to do
                return Err(format!("'{:?}' is a directory", path).into());
            } else {
                let name = path
                    .file_name()
                    .ok_or_else(|| format!("failed to get filename for '{:?}'", path))?
                    .to_str()
                    .ok_or_else(|| format!("failed to convert filename '{:?}' to string", path))?;
                let from =
                    File::open(&path).chain_err(|| format!("failed to open file {:?}", path))?;
                let keyset = AuthorizedKeys::read_keys(from)?;
                keys.insert(
                    name.to_string(),
                    AuthorizedKeySet {
                        filename: name.to_string(),
                        disabled: keyset.is_empty(),
                        keys: keyset,
                    },
                );
            }
        }
        Ok(keys)
    }
fn read_all_keys ( dir : & Path ) -> Result < HashMap < String , AuthorizedKeySet > > { let dir_contents = fs :: read_dir ( & dir ) . chain_err ( | | format ! ( " " dir ) ) ? ; let mut keys = HashMap :: new ( ) ; for entry in dir_contents { let entry = entry . chain_err ( | | format ! ( " " dir ) ) ? ; let path = entry . path ( ) ; if path . is_dir ( ) { // if it's a directory, we don't know what to do return Err ( format ! ( " " path ) . into ( ) ) ; } else { let name = path . file_name ( ) . ok_or_else ( | | format ! ( " " path ) ) ? . to_str ( ) . ok_or_else ( | | format ! ( " " path ) ) ? ; let from = File :: open ( & path ) . chain_err ( | | format ! ( " " path ) ) ? ; let keyset = AuthorizedKeys :: read_keys ( from ) ? ; keys . insert ( name . to_string ( ) , AuthorizedKeySet { filename : name . to_string ( ) , disabled : keyset . is_empty ( ) , keys : keyset , } , ) ; } } Ok ( keys ) }
read_all_keys reads all of the authorized keys files in a given
directory.
read_all_keys reads all of the authorized keys files in a given directory .
dir
&Path