2020-06-18 02:30:42 +02:00
|
|
|
#![deny(warnings)]
|
2020-08-04 04:58:11 +02:00
|
|
|
#![warn(unused_extern_crates)]
|
|
|
|
#![deny(clippy::unwrap_used)]
|
|
|
|
#![deny(clippy::expect_used)]
|
|
|
|
#![deny(clippy::panic)]
|
|
|
|
#![deny(clippy::unreachable)]
|
|
|
|
#![deny(clippy::await_holding_lock)]
|
|
|
|
#![deny(clippy::needless_pass_by_value)]
|
|
|
|
#![deny(clippy::trivially_copy_pass_by_ref)]
|
|
|
|
|
2020-02-13 00:43:01 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
use log::debug;
|
2021-08-08 01:54:21 +02:00
|
|
|
use std::path::PathBuf;
|
2020-02-13 00:43:01 +01:00
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
use futures::executor::block_on;
|
|
|
|
|
2020-02-15 01:27:25 +01:00
|
|
|
use kanidm_unix_common::client::call_daemon;
|
2020-02-29 05:02:14 +01:00
|
|
|
use kanidm_unix_common::unix_config::KanidmUnixdConfig;
|
2020-02-13 00:43:01 +01:00
|
|
|
use kanidm_unix_common::unix_proto::{ClientRequest, ClientResponse};
|
|
|
|
|
2021-02-13 04:46:22 +01:00
|
|
|
include!("./opt/ssh_authorizedkeys.rs");
|
2020-02-13 00:43:01 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2021-02-13 04:46:22 +01:00
|
|
|
let opt = SshAuthorizedOpt::from_args();
|
2020-02-13 00:43:01 +01:00
|
|
|
if opt.debug {
|
|
|
|
::std::env::set_var("RUST_LOG", "kanidm=debug,kanidm_client=debug");
|
|
|
|
} else {
|
|
|
|
::std::env::set_var("RUST_LOG", "kanidm=info,kanidm_client=info");
|
|
|
|
}
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
debug!("Starting authorized keys tool ...");
|
2020-02-29 05:02:14 +01:00
|
|
|
|
2020-09-08 04:46:10 +02:00
|
|
|
let cfg = match KanidmUnixdConfig::new().read_options_from_optional_config("/etc/kanidm/unixd")
|
|
|
|
{
|
|
|
|
Ok(c) => c,
|
2021-08-08 01:54:21 +02:00
|
|
|
Err(e) => {
|
|
|
|
error!("Failed to parse /etc/kanidm/unixd: {:?}", e);
|
2020-09-08 04:46:10 +02:00
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
2020-02-29 05:02:14 +01:00
|
|
|
|
2021-08-08 01:54:21 +02:00
|
|
|
debug!(
|
|
|
|
"Using kanidm_unixd socket path: {:?}",
|
|
|
|
cfg.sock_path.as_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
// see if the kanidm_unixd socket exists and quit if not
|
|
|
|
if !PathBuf::from(&cfg.sock_path).exists() {
|
|
|
|
error!(
|
|
|
|
"Failed to find unix socket at {}, quitting!",
|
|
|
|
cfg.sock_path.as_str()
|
|
|
|
);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
2020-06-18 02:30:42 +02:00
|
|
|
let req = ClientRequest::SshKey(opt.account_id);
|
2020-02-13 00:43:01 +01:00
|
|
|
|
2020-02-29 05:02:14 +01:00
|
|
|
match block_on(call_daemon(cfg.sock_path.as_str(), req)) {
|
2020-02-13 00:43:01 +01:00
|
|
|
Ok(r) => match r {
|
|
|
|
ClientResponse::SshKeys(sk) => sk.iter().for_each(|k| {
|
|
|
|
println!("{}", k);
|
|
|
|
}),
|
|
|
|
_ => {
|
2021-08-08 01:54:21 +02:00
|
|
|
error!("Error calling kanidm_unixd: unexpected response -> {:?}", r);
|
2020-02-13 00:43:01 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
2021-08-08 01:54:21 +02:00
|
|
|
error!("Error calling kanidm_unixd -> {:?}", e);
|
2020-02-13 00:43:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|