From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A0AA7C0E43 for ; Fri, 12 Jan 2024 17:17:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C8AED34AAC for ; Fri, 12 Jan 2024 17:16:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 12 Jan 2024 17:16:55 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id ABFF14912E for ; Fri, 12 Jan 2024 17:16:55 +0100 (CET) From: Christoph Heiss To: pbs-devel@lists.proxmox.com Date: Fri, 12 Jan 2024 17:16:05 +0100 Message-ID: <20240112161614.1012311-11-c.heiss@proxmox.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240112161614.1012311-1-c.heiss@proxmox.com> References: <20240112161614.1012311-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup v3 10/13] manager: add subcommand for managing AD realms X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Jan 2024 16:17:28 -0000 Signed-off-by: Christoph Heiss --- pbs-config/src/domains.rs | 4 + src/bin/proxmox-backup-manager.rs | 1 + src/bin/proxmox_backup_manager/ad.rs | 105 +++++++++++++++++++++++++ src/bin/proxmox_backup_manager/ldap.rs | 2 +- src/bin/proxmox_backup_manager/mod.rs | 2 + 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/bin/proxmox_backup_manager/ad.rs diff --git a/pbs-config/src/domains.rs b/pbs-config/src/domains.rs index dcf47f83..4a9beec3 100644 --- a/pbs-config/src/domains.rs +++ b/pbs-config/src/domains.rs @@ -100,3 +100,7 @@ pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap) pub fn complete_ldap_realm_name(_arg: &str, _param: &HashMap) -> Vec { complete_realm_of_type("ldap") } + +pub fn complete_ad_realm_name(_arg: &str, _param: &HashMap) -> Vec { + complete_realm_of_type("ad") +} diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 115207f3..84d7fe2e 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -437,6 +437,7 @@ async fn run() -> Result<(), Error> { .insert("disk", disk_commands()) .insert("dns", dns_commands()) .insert("ldap", ldap_commands()) + .insert("ad", ad_commands()) .insert("network", network_commands()) .insert("node", node_commands()) .insert("user", user_commands()) diff --git a/src/bin/proxmox_backup_manager/ad.rs b/src/bin/proxmox_backup_manager/ad.rs new file mode 100644 index 00000000..90b34143 --- /dev/null +++ b/src/bin/proxmox_backup_manager/ad.rs @@ -0,0 +1,105 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; + +use pbs_api_types::REALM_ID_SCHEMA; + +use crate::api2; + +#[api( + input: { + properties: { + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// List configured AD realms +fn list_ad_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + let output_format = get_output_format(¶m); + + let info = &api2::config::access::ad::API_METHOD_LIST_AD_REALMS; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options() + .column(ColumnConfig::new("realm")) + .column(ColumnConfig::new("server1")) + .column(ColumnConfig::new("comment")); + + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); + + Ok(Value::Null) +} + +#[api( + input: { + properties: { + realm: { + schema: REALM_ID_SCHEMA, + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// Show AD realm configuration +pub fn show_ad_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + let output_format = get_output_format(¶m); + + let info = &api2::config::access::ad::API_METHOD_READ_AD_REALM; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options(); + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); + + Ok(Value::Null) +} + +pub fn ad_commands() -> CommandLineInterface { + let cmd_def = CliCommandMap::new() + .insert("list", CliCommand::new(&API_METHOD_LIST_AD_REALMS)) + .insert( + "show", + CliCommand::new(&crate::API_METHOD_SHOW_AD_REALM) + .arg_param(&["realm"]) + .completion_cb("realm", pbs_config::domains::complete_ad_realm_name), + ) + .insert( + "create", + CliCommand::new(&api2::config::access::ad::API_METHOD_CREATE_AD_REALM) + .arg_param(&["realm"]) + .completion_cb("realm", pbs_config::domains::complete_ad_realm_name), + ) + .insert( + "update", + CliCommand::new(&api2::config::access::ad::API_METHOD_UPDATE_AD_REALM) + .arg_param(&["realm"]) + .completion_cb("realm", pbs_config::domains::complete_ad_realm_name), + ) + .insert( + "delete", + CliCommand::new(&api2::config::access::ldap::API_METHOD_DELETE_LDAP_REALM) + .arg_param(&["realm"]) + .completion_cb("realm", pbs_config::domains::complete_ad_realm_name), + ) + .insert( + "sync", + CliCommand::new(&crate::API_METHOD_SYNC_LDAP_REALM) + .arg_param(&["realm"]) + .completion_cb("realm", pbs_config::domains::complete_ad_realm_name), + ); + + cmd_def.into() +} diff --git a/src/bin/proxmox_backup_manager/ldap.rs b/src/bin/proxmox_backup_manager/ldap.rs index 7ff4ad1d..196825a6 100644 --- a/src/bin/proxmox_backup_manager/ldap.rs +++ b/src/bin/proxmox_backup_manager/ldap.rs @@ -98,7 +98,7 @@ fn show_ldap_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result Result { +pub async fn sync_ldap_realm(param: Value) -> Result { let realm = required_string_param(¶m, "realm")?; let client = connect_to_localhost()?; diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 8a1c140c..b60dd684 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -2,6 +2,8 @@ mod acl; pub use acl::*; mod acme; pub use acme::*; +mod ad; +pub use ad::*; mod cert; pub use cert::*; mod datastore; -- 2.42.0