71 lines
2.1 KiB
Rust
71 lines
2.1 KiB
Rust
|
/*
|
||
|
* Copyright (c) 2023 Emma Tebibyte
|
||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU Affero General Public License as published by the Free
|
||
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
||
|
* later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||
|
* details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||
|
*/
|
||
|
|
||
|
use std::{
|
||
|
env,
|
||
|
fs::File,
|
||
|
io::stdin,
|
||
|
};
|
||
|
|
||
|
use keepass::{
|
||
|
db::NodeRef,
|
||
|
Database,
|
||
|
DatabaseKey,
|
||
|
};
|
||
|
|
||
|
use yacexits::{ EX_UNAVAILABLE, EX_TEMPFAIL, exit};
|
||
|
|
||
|
fn main() {
|
||
|
let argv = env::args().collect::<Vec<String>>();
|
||
|
|
||
|
let mut file = match File::open(&argv[1]) {
|
||
|
Ok(file) => file,
|
||
|
Err(err) => {
|
||
|
eprintln!("{}: {:?}", argv[0], err);
|
||
|
exit(1);
|
||
|
},
|
||
|
};
|
||
|
|
||
|
let mut password = String::new();
|
||
|
stdin().read_line(&mut password).unwrap_or_else(|_| {
|
||
|
eprintln!("{}: {}: No such file or directory.", argv[0], argv[1]);
|
||
|
exit(EX_UNAVAILABLE);
|
||
|
});
|
||
|
|
||
|
password.pop();
|
||
|
|
||
|
let key = DatabaseKey::new().with_password(&password);
|
||
|
let db = Database::open(&mut file, key).unwrap_or_else(|_| {
|
||
|
eprintln!("{}: Incorrect key.", argv[0]);
|
||
|
exit(EX_TEMPFAIL);
|
||
|
});
|
||
|
|
||
|
for item in &db.root {
|
||
|
match item {
|
||
|
NodeRef::Group(_) => {},
|
||
|
NodeRef::Entry(entry) => {
|
||
|
let title = entry.get_title().unwrap_or("[title]");
|
||
|
let url = entry.get_url().unwrap_or("[url]");
|
||
|
let username = entry.get_username().unwrap_or("[username]");
|
||
|
let password = entry.get_password().unwrap_or("[password]");
|
||
|
println!("{}␞{}␞{}␞{}", title, url, username, password)
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
}
|