2019-07-29 09:09:09 +02:00
|
|
|
#![deny(warnings)]
|
|
|
|
|
2018-09-29 09:54:16 +02:00
|
|
|
extern crate actix;
|
2019-07-12 07:28:46 +02:00
|
|
|
extern crate env_logger;
|
2019-09-04 03:06:37 +02:00
|
|
|
extern crate rpassword;
|
2018-09-29 09:54:16 +02:00
|
|
|
|
2019-09-14 15:44:08 +02:00
|
|
|
extern crate kanidm;
|
2019-07-15 01:15:25 +02:00
|
|
|
extern crate structopt;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2019-05-08 02:39:46 +02:00
|
|
|
|
2019-09-14 15:44:08 +02:00
|
|
|
use kanidm::config::Configuration;
|
|
|
|
use kanidm::core::{
|
2019-09-14 10:21:41 +02:00
|
|
|
backup_server_core, create_server_core, recover_account_core, reset_sid_core,
|
|
|
|
restore_server_core, verify_server_core,
|
2019-07-29 09:09:18 +02:00
|
|
|
};
|
2019-07-15 01:15:25 +02:00
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
2019-09-14 10:21:41 +02:00
|
|
|
struct CommonOpt {
|
2019-07-15 01:15:25 +02:00
|
|
|
#[structopt(short = "d", long = "debug")]
|
|
|
|
debug: bool,
|
|
|
|
#[structopt(parse(from_os_str), short = "D", long = "db_path")]
|
|
|
|
db_path: PathBuf,
|
|
|
|
}
|
|
|
|
|
2019-09-14 10:21:41 +02:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct ServerOpt {
|
|
|
|
#[structopt(parse(from_os_str), short = "C", long = "ca")]
|
|
|
|
ca_path: Option<PathBuf>,
|
|
|
|
#[structopt(parse(from_os_str), short = "c", long = "cert")]
|
|
|
|
cert_path: Option<PathBuf>,
|
|
|
|
#[structopt(parse(from_os_str), short = "k", long = "key")]
|
|
|
|
key_path: Option<PathBuf>,
|
|
|
|
#[structopt(short = "r", long = "domain")]
|
|
|
|
domain: String,
|
|
|
|
#[structopt(short = "b", long = "bindaddr")]
|
|
|
|
bind: Option<String>,
|
|
|
|
#[structopt(flatten)]
|
|
|
|
commonopts: CommonOpt,
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:15:25 +02:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct BackupOpt {
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
path: PathBuf,
|
|
|
|
#[structopt(flatten)]
|
2019-09-14 10:21:41 +02:00
|
|
|
commonopts: CommonOpt,
|
2019-07-15 01:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct RestoreOpt {
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
path: PathBuf,
|
|
|
|
#[structopt(flatten)]
|
2019-09-14 10:21:41 +02:00
|
|
|
commonopts: CommonOpt,
|
2019-07-15 01:15:25 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 03:06:37 +02:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct RecoverAccountOpt {
|
|
|
|
#[structopt(short)]
|
|
|
|
name: String,
|
|
|
|
#[structopt(flatten)]
|
2019-09-14 10:21:41 +02:00
|
|
|
commonopts: CommonOpt,
|
2019-09-04 03:06:37 +02:00
|
|
|
}
|
|
|
|
|
2019-07-15 01:15:25 +02:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
enum Opt {
|
|
|
|
#[structopt(name = "server")]
|
|
|
|
Server(ServerOpt),
|
|
|
|
#[structopt(name = "backup")]
|
|
|
|
Backup(BackupOpt),
|
|
|
|
#[structopt(name = "restore")]
|
|
|
|
Restore(RestoreOpt),
|
2019-07-29 09:09:09 +02:00
|
|
|
#[structopt(name = "verify")]
|
2019-09-14 10:21:41 +02:00
|
|
|
Verify(CommonOpt),
|
2019-09-04 03:06:37 +02:00
|
|
|
#[structopt(name = "recover_account")]
|
|
|
|
RecoverAccount(RecoverAccountOpt),
|
2019-09-14 10:21:41 +02:00
|
|
|
#[structopt(name = "reset_server_id")]
|
|
|
|
ResetServerId(CommonOpt),
|
2019-07-15 01:15:25 +02:00
|
|
|
}
|
2018-11-11 22:59:09 +01:00
|
|
|
|
2019-09-06 05:05:27 +02:00
|
|
|
impl Opt {
|
|
|
|
fn debug(&self) -> bool {
|
|
|
|
match self {
|
2019-09-14 10:21:41 +02:00
|
|
|
Opt::Server(sopt) => sopt.commonopts.debug,
|
|
|
|
Opt::Verify(sopt) | Opt::ResetServerId(sopt) => sopt.debug,
|
|
|
|
Opt::Backup(bopt) => bopt.commonopts.debug,
|
|
|
|
Opt::Restore(ropt) => ropt.commonopts.debug,
|
|
|
|
Opt::RecoverAccount(ropt) => ropt.commonopts.debug,
|
2019-09-06 05:05:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 09:54:16 +02:00
|
|
|
fn main() {
|
2019-07-15 01:15:25 +02:00
|
|
|
// Read cli args, determine if we should backup/restore
|
|
|
|
let opt = Opt::from_args();
|
|
|
|
|
2019-07-12 07:28:46 +02:00
|
|
|
// Read our config (if any)
|
2019-07-15 01:15:25 +02:00
|
|
|
let mut config = Configuration::new();
|
|
|
|
// Apply any cli overrides?
|
2019-07-12 07:28:46 +02:00
|
|
|
|
|
|
|
// Configure the server logger. This could be adjusted based on what config
|
|
|
|
// says.
|
2019-09-06 05:05:27 +02:00
|
|
|
if opt.debug() {
|
2019-09-14 15:44:08 +02:00
|
|
|
::std::env::set_var("RUST_LOG", "actix_web=info,kanidm=debug");
|
2019-09-06 05:05:27 +02:00
|
|
|
} else {
|
2019-09-14 15:44:08 +02:00
|
|
|
::std::env::set_var("RUST_LOG", "actix_web=info,kanidm=info");
|
2019-09-06 05:05:27 +02:00
|
|
|
}
|
2019-07-12 07:28:46 +02:00
|
|
|
env_logger::init();
|
|
|
|
|
2019-07-15 01:15:25 +02:00
|
|
|
match opt {
|
|
|
|
Opt::Server(sopt) => {
|
|
|
|
info!("Running in server mode ...");
|
|
|
|
|
2019-09-14 10:21:41 +02:00
|
|
|
config.update_db_path(&sopt.commonopts.db_path);
|
|
|
|
config.update_tls(&sopt.ca_path, &sopt.cert_path, &sopt.key_path);
|
|
|
|
config.update_bind(&sopt.bind);
|
|
|
|
config.domain = sopt.domain.clone();
|
2019-07-15 01:15:25 +02:00
|
|
|
|
2019-09-14 15:44:08 +02:00
|
|
|
let sys = actix::System::new("kanidm-server");
|
2019-07-15 01:15:25 +02:00
|
|
|
create_server_core(config);
|
|
|
|
let _ = sys.run();
|
|
|
|
}
|
|
|
|
Opt::Backup(bopt) => {
|
|
|
|
info!("Running in backup mode ...");
|
|
|
|
|
2019-09-14 10:21:41 +02:00
|
|
|
config.update_db_path(&bopt.commonopts.db_path);
|
2019-07-15 01:15:25 +02:00
|
|
|
|
|
|
|
let p = match bopt.path.to_str() {
|
|
|
|
Some(p) => p,
|
|
|
|
None => {
|
|
|
|
error!("Invalid backup path");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
backup_server_core(config, p);
|
|
|
|
}
|
|
|
|
Opt::Restore(ropt) => {
|
|
|
|
info!("Running in restore mode ...");
|
|
|
|
|
2019-09-14 10:21:41 +02:00
|
|
|
config.update_db_path(&ropt.commonopts.db_path);
|
2018-09-29 09:54:16 +02:00
|
|
|
|
2019-07-15 01:15:25 +02:00
|
|
|
let p = match ropt.path.to_str() {
|
|
|
|
Some(p) => p,
|
|
|
|
None => {
|
|
|
|
error!("Invalid restore path");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
restore_server_core(config, p);
|
|
|
|
}
|
2019-07-29 09:09:09 +02:00
|
|
|
Opt::Verify(vopt) => {
|
|
|
|
info!("Running in restore mode ...");
|
|
|
|
|
|
|
|
config.update_db_path(&vopt.db_path);
|
|
|
|
verify_server_core(config);
|
|
|
|
}
|
2019-09-04 03:06:37 +02:00
|
|
|
Opt::RecoverAccount(raopt) => {
|
|
|
|
info!("Running account recovery ...");
|
|
|
|
|
|
|
|
let password = rpassword::prompt_password_stderr("new password: ").unwrap();
|
2019-09-14 10:21:41 +02:00
|
|
|
config.update_db_path(&raopt.commonopts.db_path);
|
2019-09-04 03:06:37 +02:00
|
|
|
|
|
|
|
recover_account_core(config, raopt.name, password);
|
|
|
|
}
|
2019-09-14 10:21:41 +02:00
|
|
|
Opt::ResetServerId(vopt) => {
|
|
|
|
info!("Resetting server id. THIS MAY BREAK REPLICATION");
|
|
|
|
|
|
|
|
config.update_db_path(&vopt.db_path);
|
|
|
|
reset_sid_core(config);
|
|
|
|
}
|
2019-07-15 01:15:25 +02:00
|
|
|
}
|
2018-09-29 09:54:16 +02:00
|
|
|
}
|