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 56FEB6F5D5 for ; Mon, 30 Aug 2021 13:15:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3707F1A1B4 for ; Mon, 30 Aug 2021 13:15:20 +0200 (CEST) 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 id 239461A021 for ; Mon, 30 Aug 2021 13:15:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id DE604441E6 for ; Mon, 30 Aug 2021 13:15:11 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Mon, 30 Aug 2021 13:14:59 +0200 Message-Id: <20210830111505.38694-10-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210830111505.38694-1-h.laimer@proxmox.com> References: <20210830111505.38694-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.180 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pbs-devel] [PATCH v2 proxmox-backup 09/15] pbs-manager: add 'send-command' command 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: Mon, 30 Aug 2021 11:15:51 -0000 Relays a command to the superuser commandSocket, this is necessary because the path to the socket is prefixed with a '\0' and can therefore not really be addressed from outside the rust code. --- src/bin/proxmox-backup-manager.rs | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 93d6de57..a07f69f1 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -197,6 +197,43 @@ async fn task_stop(param: Value) -> Result { Ok(Value::Null) } +#[api( + input: { + properties: { + command: { + description: "The command.", + type: String, + }, + args: { + description: "The argument string.", + optional: true, + type: String, + } + } + } +)] +/// Send command to control socket. +async fn send_command(param: Value) -> Result { + let command_str = required_string_param(¶m, "command")?; + let args = match required_string_param(¶m, "args") { + Ok(args) => args, + Err(_) => "", + }; + + let api_pid = proxmox_backup::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?; + let sock = proxmox_backup::server::ctrl_sock_from_pid(api_pid); + proxmox_backup::server::send_raw_command( + sock, + &format!( + "{{\"command\":\"{}\",\"args\":\"{}\"}}\n", + command_str, args + ), + ) + .await?; + + Ok(Value::Null) +} + fn task_mgmt_cli() -> CommandLineInterface { let task_log_cmd_def = CliCommand::new(&API_METHOD_TASK_LOG) @@ -392,6 +429,10 @@ fn main() { .insert("report", CliCommand::new(&API_METHOD_REPORT) ) + .insert( + "send-command", + CliCommand::new(&API_METHOD_SEND_COMMAND).arg_param(&["command"]), + ) .insert("versions", CliCommand::new(&API_METHOD_GET_VERSIONS) ); -- 2.30.2