From: Markus Frank <m.frank@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 2/3] pbs-client: added options to skip xattr/acl/ownership/permissions
Date: Thu, 18 Aug 2022 13:06:53 +0200 [thread overview]
Message-ID: <20220818110654.56988-3-m.frank@proxmox.com> (raw)
In-Reply-To: <20220818110654.56988-1-m.frank@proxmox.com>
Also added WITH_OWNER and WITH_PERMISSION to Default-Flags,
because otherwise it would be needed to activly set these flags and most
filesystems that support XATTR and ACL also support
POSIX-Permissions & Ownership.
Signed-off-by: Markus Frank <m.frank@proxmox.com>
---
v2:
* created new WITH_OWNER Flag and use WITH_PERMISSIONS for skipping chmod
* removed redundant if
pbs-client/src/pxar/flags.rs | 6 +++++
pbs-client/src/pxar/metadata.rs | 40 +++++++++++++++++++++------------
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/pbs-client/src/pxar/flags.rs b/pbs-client/src/pxar/flags.rs
index d46c8af3..b3280de7 100644
--- a/pbs-client/src/pxar/flags.rs
+++ b/pbs-client/src/pxar/flags.rs
@@ -71,6 +71,9 @@ bitflags! {
/// Preserve XFS/ext4/ZFS project quota ID
const WITH_QUOTA_PROJID = 0x0001_0000_0000;
+ /// UNIX OWNERSHIP
+ const WITH_OWNER = 0x0002_0000_0000;
+
/// Support ".pxarexclude" files
const EXCLUDE_FILE = 0x1000_0000_0000_0000;
/// Exclude submounts
@@ -105,6 +108,7 @@ bitflags! {
Flags::WITH_2SEC_TIME.bits() |
Flags::WITH_READ_ONLY.bits() |
Flags::WITH_PERMISSIONS.bits() |
+ Flags::WITH_OWNER.bits() |
Flags::WITH_SYMLINKS.bits() |
Flags::WITH_DEVICE_NODES.bits() |
Flags::WITH_FIFOS.bits() |
@@ -135,6 +139,8 @@ bitflags! {
Flags::WITH_FLAG_PROJINHERIT.bits() |
Flags::WITH_SUBVOLUME.bits() |
Flags::WITH_SUBVOLUME_RO.bits() |
+ Flags::WITH_PERMISSIONS.bits() |
+ Flags::WITH_OWNER.bits() |
Flags::WITH_XATTRS.bits() |
Flags::WITH_ACL.bits() |
Flags::WITH_SELINUX.bits() |
diff --git a/pbs-client/src/pxar/metadata.rs b/pbs-client/src/pxar/metadata.rs
index 22bc5f9d..be1911a7 100644
--- a/pbs-client/src/pxar/metadata.rs
+++ b/pbs-client/src/pxar/metadata.rs
@@ -100,19 +100,7 @@ pub fn apply(
on_error: &mut (dyn FnMut(Error) -> Result<(), Error> + Send),
) -> Result<(), Error> {
let c_proc_path = CString::new(format!("/proc/self/fd/{}", fd)).unwrap();
-
- unsafe {
- // UID and GID first, as this fails if we lose access anyway.
- c_result!(libc::chown(
- c_proc_path.as_ptr(),
- metadata.stat.uid,
- metadata.stat.gid
- ))
- .map(drop)
- .or_else(allow_notsupp)
- .map_err(|err| format_err!("failed to set ownership: {}", err))
- .or_else(&mut *on_error)?;
- }
+ apply_ownership(flags, c_proc_path.as_ptr(), metadata, &mut *on_error)?;
let mut skip_xattrs = false;
apply_xattrs(flags, c_proc_path.as_ptr(), metadata, &mut skip_xattrs)
@@ -125,7 +113,7 @@ pub fn apply(
// Finally mode and time. We may lose access with mode, but the changing the mode also
// affects times.
- if !metadata.is_symlink() {
+ if !metadata.is_symlink() && flags.contains(Flags::WITH_PERMISSIONS) {
c_result!(unsafe {
libc::chmod(c_proc_path.as_ptr(), perms_from_metadata(metadata)?.bits())
})
@@ -162,6 +150,30 @@ pub fn apply(
Ok(())
}
+pub fn apply_ownership(
+ flags: Flags,
+ c_proc_path: *const libc::c_char,
+ metadata: &Metadata,
+ on_error: &mut (dyn FnMut(Error) -> Result<(), Error> + Send),
+) -> Result<(), Error> {
+ if !flags.contains(Flags::WITH_OWNER) {
+ return Ok(());
+ }
+ unsafe {
+ // UID and GID first, as this fails if we lose access anyway.
+ c_result!(libc::chown(
+ c_proc_path,
+ metadata.stat.uid,
+ metadata.stat.gid
+ ))
+ .map(drop)
+ .or_else(allow_notsupp)
+ .map_err(|err| format_err!("failed to set ownership: {}", err))
+ .or_else(&mut *on_error)?;
+ }
+ Ok(())
+}
+
fn add_fcaps(
flags: Flags,
c_proc_path: *const libc::c_char,
--
2.30.2
next prev parent reply other threads:[~2022-08-18 11:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-18 11:06 [pbs-devel] [PATCH proxmox-backup v2 0/3] pbs-client: feature #3923 Markus Frank
2022-08-18 11:06 ` [pbs-devel] [PATCH proxmox-backup v2 1/3] pbs-client: added overwrite-existing-files to PxarExtractOptions Markus Frank
2022-08-18 11:06 ` Markus Frank [this message]
2022-08-18 11:06 ` [pbs-devel] [PATCH proxmox-backup v2 3/3] proxmox-backup-client: added ignore-acl/xattr/ownership/permission & overwrite parameters Markus Frank
2022-08-18 12:03 ` Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220818110654.56988-3-m.frank@proxmox.com \
--to=m.frank@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.