2020-06-18 02:30:42 +02:00
|
|
|
#![deny(warnings)]
|
2020-02-29 05:02:14 +01:00
|
|
|
#[macro_use]
|
2021-12-17 04:54:13 +01:00
|
|
|
extern crate tracing;
|
2020-02-29 05:02:14 +01:00
|
|
|
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
use futures::executor::block_on;
|
|
|
|
|
|
|
|
use kanidm_unix_common::client::call_daemon;
|
|
|
|
use kanidm_unix_common::unix_config::KanidmUnixdConfig;
|
|
|
|
use kanidm_unix_common::unix_proto::{ClientRequest, ClientResponse};
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct ClientOpt {
|
|
|
|
#[structopt(short = "d", long = "debug")]
|
|
|
|
debug: bool,
|
|
|
|
#[structopt(short = "D", long = "name")]
|
|
|
|
account_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let opt = ClientOpt::from_args();
|
|
|
|
if opt.debug {
|
|
|
|
::std::env::set_var("RUST_LOG", "kanidm=debug,kanidm_client=debug");
|
|
|
|
}
|
2021-12-17 04:54:13 +01:00
|
|
|
tracing_subscriber::fmt::init();
|
2020-02-29 05:02:14 +01:00
|
|
|
|
2021-12-17 04:54:13 +01:00
|
|
|
debug!("Starting pam auth tester tool ...");
|
2020-02-29 05:02:14 +01:00
|
|
|
|
|
|
|
let cfg = KanidmUnixdConfig::new()
|
|
|
|
.read_options_from_optional_config("/etc/kanidm/unixd")
|
|
|
|
.expect("Failed to parse /etc/kanidm/unixd");
|
|
|
|
|
2022-04-27 05:35:26 +02:00
|
|
|
let password = rpassword::prompt_password("Enter unix password: ").unwrap();
|
2020-02-29 05:02:14 +01:00
|
|
|
|
|
|
|
let req = ClientRequest::PamAuthenticate(opt.account_id.clone(), password);
|
2020-06-18 02:30:42 +02:00
|
|
|
let sereq = ClientRequest::PamAccountAllowed(opt.account_id);
|
2020-02-29 05:02:14 +01:00
|
|
|
|
|
|
|
match block_on(call_daemon(cfg.sock_path.as_str(), req)) {
|
|
|
|
Ok(r) => match r {
|
|
|
|
ClientResponse::PamStatus(Some(true)) => {
|
|
|
|
info!("auth success!");
|
|
|
|
}
|
|
|
|
ClientResponse::PamStatus(Some(false)) => {
|
|
|
|
info!("auth failed!");
|
|
|
|
}
|
|
|
|
ClientResponse::PamStatus(None) => {
|
|
|
|
info!("user unknown");
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// unexpected response.
|
|
|
|
error!("Error: unexpected response -> {:?}", r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
error!("Error -> {:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match block_on(call_daemon(cfg.sock_path.as_str(), sereq)) {
|
|
|
|
Ok(r) => match r {
|
|
|
|
ClientResponse::PamStatus(Some(true)) => {
|
|
|
|
info!("auth success!");
|
|
|
|
}
|
|
|
|
ClientResponse::PamStatus(Some(false)) => {
|
|
|
|
info!("auth failed!");
|
|
|
|
}
|
|
|
|
ClientResponse::PamStatus(None) => {
|
|
|
|
info!("user unknown");
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// unexpected response.
|
|
|
|
error!("Error: unexpected response -> {:?}", r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
error!("Error -> {:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|