xattr: api cleanup
Make `flistxattr()` return a `ListXAttr` helper which provides an iterator over `&CStr`. This exposes the property that xattr names are a zero-terminated string without simply being an opaque "byte vector". Using &[u8] as a type here is too lax. Also let `fgetxattr` take a `CStr`. While this may be a burden on the caller, we usually already have zero-terminated strings on the call site. Currently we only use this method coming from `flistxattr` after all. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
@ -287,7 +287,7 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> {
|
||||
Err(err) => bail!("read_xattrs failed for {:?} - {}", self.full_path(), err),
|
||||
};
|
||||
|
||||
for name in xattr_names.split(|c| *c == b'\0') {
|
||||
for name in &xattr_names {
|
||||
// Only extract the relevant extended attributes
|
||||
if !xattr::is_valid_xattr_name(&name) {
|
||||
continue;
|
||||
@ -307,7 +307,7 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> {
|
||||
}
|
||||
} else if self.has_features(flags::WITH_XATTRS) {
|
||||
xattrs.push(PxarXAttr {
|
||||
name: name.to_vec(),
|
||||
name: name.to_bytes().to_vec(),
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! *pxar* format decoder.
|
||||
//!
|
||||
//! This module contain the code to decode *pxar* archive files.
|
||||
use std::ffi::CString;
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{Read, Write};
|
||||
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
||||
@ -164,9 +164,10 @@ impl<R: Read> SequentialDecoder<R> {
|
||||
.position(|c| *c == b'\0')
|
||||
.ok_or_else(|| format_err!("no value found in xattr"))?;
|
||||
|
||||
let (name, value) = buffer.split_at(separator);
|
||||
if !xattr::is_valid_xattr_name(name) || xattr::is_security_capability(name) {
|
||||
bail!("incorrect xattr name - {}.", String::from_utf8_lossy(name));
|
||||
let (name, value) = buffer.split_at(separator + 1);
|
||||
let c_name = unsafe { CStr::from_bytes_with_nul_unchecked(name) };
|
||||
if !xattr::is_valid_xattr_name(c_name) || xattr::is_security_capability(c_name) {
|
||||
bail!("incorrect xattr name - {:?}.", c_name);
|
||||
}
|
||||
|
||||
Ok(PxarXAttr {
|
||||
|
Reference in New Issue
Block a user