From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id C2C061FF171 for ; Fri, 29 Nov 2024 15:28:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8EAB51AFCA; Fri, 29 Nov 2024 15:28:04 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 29 Nov 2024 15:28:01 +0100 Message-Id: <20241129142801.3334969-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241129142801.3334969-1-d.csapak@proxmox.com> References: <20241129142801.3334969-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [fd.rs, dir.rs] Subject: [pbs-devel] [PATCH proxmox v2 2/2] sys: open directories with O_CLOEXEC 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" so they don't linger around in case of a daemon reload. Signed-off-by: Dominik Csapak --- new in v2 proxmox-sys/src/fd.rs | 2 +- proxmox-sys/src/fs/dir.rs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/proxmox-sys/src/fd.rs b/proxmox-sys/src/fd.rs index 8d85bd2e..386e4222 100644 --- a/proxmox-sys/src/fd.rs +++ b/proxmox-sys/src/fd.rs @@ -24,7 +24,7 @@ pub fn change_cloexec(fd: RawFd, on: bool) -> Result<(), anyhow::Error> { } pub(crate) fn cwd() -> Result { - open(".", OFlag::O_DIRECTORY, stat::Mode::empty()) + open(".", crate::fs::DIR_FLAGS, stat::Mode::empty()) } pub fn open

(path: &P, oflag: OFlag, mode: Mode) -> Result diff --git a/proxmox-sys/src/fs/dir.rs b/proxmox-sys/src/fs/dir.rs index c903ab87..a093ed99 100644 --- a/proxmox-sys/src/fs/dir.rs +++ b/proxmox-sys/src/fs/dir.rs @@ -14,6 +14,9 @@ use proxmox_lang::try_block; use crate::fs::{fchown, CreateOptions}; +/// The default [`OFlag`] we want to use when opening directories. +pub(crate) const DIR_FLAGS: OFlag = OFlag::O_DIRECTORY.union(OFlag::O_CLOEXEC); + /// Creates directory at the provided path with specified ownership. /// /// Errors if the directory already exists. @@ -66,7 +69,7 @@ pub fn ensure_dir_exists>( Err(err) => bail!("unable to create directory {path:?} - {err}",), } - let fd = nix::fcntl::open(path, OFlag::O_DIRECTORY, stat::Mode::empty()) + let fd = nix::fcntl::open(path, DIR_FLAGS, stat::Mode::empty()) .map(|fd| unsafe { OwnedFd::from_raw_fd(fd) }) .map_err(|err| format_err!("unable to open created directory {path:?} - {err}"))?; // umask defaults to 022 so make sure the mode is fully honowed: @@ -120,7 +123,7 @@ fn create_path_do( Some(Component::Prefix(_)) => bail!("illegal prefix path component encountered"), Some(Component::RootDir) => { let _ = iter.next(); - crate::fd::open(c"/", OFlag::O_DIRECTORY, stat::Mode::empty())? + crate::fd::open(c"/", DIR_FLAGS, stat::Mode::empty())? } Some(Component::CurDir) => { let _ = iter.next(); @@ -128,7 +131,7 @@ fn create_path_do( } Some(Component::ParentDir) => { let _ = iter.next(); - crate::fd::open(c"..", OFlag::O_DIRECTORY, stat::Mode::empty())? + crate::fd::open(c"..", DIR_FLAGS, stat::Mode::empty())? } Some(Component::Normal(_)) => { // simply do not advance the iterator, heavy lifting happens in create_path_at_do() @@ -154,7 +157,7 @@ fn create_path_at_do( None => return Ok(created), Some(Component::ParentDir) => { - at = crate::fd::openat(&at, c"..", OFlag::O_DIRECTORY, stat::Mode::empty())?; + at = crate::fd::openat(&at, c"..", DIR_FLAGS, stat::Mode::empty())?; } Some(Component::Normal(path)) => { @@ -175,7 +178,7 @@ fn create_path_at_do( Err(e) => return Err(e.into()), Ok(_) => true, }; - at = crate::fd::openat(&at, path, OFlag::O_DIRECTORY, stat::Mode::empty())?; + at = crate::fd::openat(&at, path, DIR_FLAGS, stat::Mode::empty())?; if let (true, Some(opts)) = (created, opts) { if opts.owner.is_some() || opts.group.is_some() { @@ -222,7 +225,7 @@ pub fn make_tmp_dir>( if let Some(options) = options { if let Err(err) = try_block!({ - let mut fd = crate::fd::open(&path, OFlag::O_DIRECTORY, stat::Mode::empty())?; + let mut fd = crate::fd::open(&path, DIR_FLAGS, stat::Mode::empty())?; options.apply_to(&mut fd, &path)?; Ok::<(), Error>(()) }) { -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel