Skip to content

Commit

Permalink
Add configuration for file verification flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed May 22, 2024
1 parent e050fcd commit 02a741a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Breaking Changes

- `FileVerifyFlags` member names changed to strip the `VERIFY_` prefix.

### Added

- `FileOptions::verify()`

### Changed

- As RHEL 7 (thus, CentOS 7 and other derivatives) goes out-of-support on June 30, 2024, support for legacy
Expand Down
32 changes: 16 additions & 16 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,25 +532,25 @@ bitflags! {
bitflags! {
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub struct FileVerifyFlags: u32 {
const VERIFY_NONE = 0;
const VERIFY_MD5 = 1 << 0; // from %verify(md5) - obsolete */
const VERIFY_FILEDIGEST = 1 << 0; // from %verify(filedigest) */
const VERIFY_FILESIZE = 1 << 1; // from %verify(size) */
const VERIFY_LINKTO = 1 << 2; // from %verify(link)
const VERIFY_USER = 1 << 3; // from %verify(user)
const VERIFY_GROUP = 1 << 4; // from %verify(group)
const VERIFY_MTIME = 1 << 5; // from %verify(mtime)
const VERIFY_MODE = 1 << 6; // from %verify(mode)
const VERIFY_RDEV = 1 << 7; // from %verify(rdev)
const VERIFY_CAPS = 1 << 8; // from %verify(caps)
const NONE = 0;
const MD5 = 1 << 0; // from %verify(md5) - obsolete */
const FILEDIGEST = 1 << 0; // from %verify(filedigest) */
const FILESIZE = 1 << 1; // from %verify(size) */
const LINKTO = 1 << 2; // from %verify(link)
const USER = 1 << 3; // from %verify(user)
const GROUP = 1 << 4; // from %verify(group)
const MTIME = 1 << 5; // from %verify(mtime)
const MODE = 1 << 6; // from %verify(mode)
const RDEV = 1 << 7; // from %verify(rdev)
const CAPS = 1 << 8; // from %verify(caps)
// bits 9-14 unused, reserved for rpmVerifyAttrs
const VERIFY_CONTEXTS = 1 << 15; // verify: from --nocontexts
const CONTEXTS = 1 << 15; // verify: from --nocontexts
// bits 16-22 used in rpmVerifyFlags
// bits 23-27 used in rpmQueryFlags
const VERIFY_READLINKFAIL= 1 << 28; // readlink failed
const VERIFY_READFAIL = 1 << 29; // file read failed
const VERIFY_LSTATFAIL = 1 << 30; // lstat failed
const VERIFY_LGETFILECONFAIL = 1 << 31; // lgetfilecon failed
const READLINKFAIL= 1 << 28; // readlink failed
const READFAIL = 1 << 29; // file read failed
const LSTATFAIL = 1 << 30; // lstat failed
const LGETFILECONFAIL = 1 << 31; // lgetfilecon failed
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/rpm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ impl PackageBuilder {
// and then later check if any were set
caps: options.caps,
sha_checksum,
verify_flags: options.verify_flags,
};

self.directories.insert(dir);
Expand Down Expand Up @@ -720,7 +721,7 @@ impl PackageBuilder {
dir_indixes.push(index as u32);
base_names.push(entry.base_name.to_owned());
// @todo: is there a use case for not performing all verifications? and are we performing those verifications currently anyway?
file_verify_flags.push(FileVerifyFlags::all().bits());
file_verify_flags.push(entry.verify_flags.bits());
let content = entry.content.to_owned();
let mut writer = cpio::newc::Builder::new(cpio_path)
.mode(entry.mode.into())
Expand Down
13 changes: 13 additions & 0 deletions src/rpm/headers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct PackageFileEntry {
pub base_name: String,
pub dir: String,
pub caps: Option<FileCaps>,
pub verify_flags: FileVerifyFlags,
pub(crate) content: Vec<u8>,
}

Expand Down Expand Up @@ -194,6 +195,7 @@ pub struct FileOptions {
pub(crate) flag: FileFlags,
pub(crate) inherit_permissions: bool,
pub(crate) caps: Option<FileCaps>,
pub(crate) verify_flags: FileVerifyFlags,
}

impl FileOptions {
Expand All @@ -213,6 +215,7 @@ impl FileOptions {
flag: FileFlags::empty(),
inherit_permissions: true,
caps: None,
verify_flags: FileVerifyFlags::all(),
},
}
}
Expand Down Expand Up @@ -277,6 +280,16 @@ impl FileOptionsBuilder {
Ok(self)
}

/// Direct which aspects of the file you would like RPM to verify.
///
/// By default, every aspect of the file will be checked.
///
/// See: `%verify` from specfile syntax
pub fn verify(mut self, flags: FileVerifyFlags) -> Self {
self.inner.verify_flags = flags;
self
}

/// Indicates that a file is documentation.
///
/// See: `%doc` from specfile syntax
Expand Down

0 comments on commit 02a741a

Please sign in to comment.