-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Disable tests that fail on FreeBSD. Disable tests that are failing on FreeBSD. The "ambient" versions of these tests are also failing, so this appears to be platform-specific behavior rather than cap-std's behavior. * Don't install `curl`; just use the default one. * Check for opening `..` in the FreeBSD `RESOLVE_BENEATH` check. Change the `RESOLVE_BENEATH` check to check for the behavior of opening `..` on FreeBSD. * Add a freebsd-14-0-snap entry to the Cirrus CI config. FreeBSD 14 supports the RESOLVE_BENEATH semantics where `..` is a capability error even when the base fd is the root directory.
- Loading branch information
1 parent
5e32356
commit 465c70b
Showing
9 changed files
with
72 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
use rustix::fs::{statat, AtFlags}; | ||
use std::fs; | ||
use rustix::cstr; | ||
use rustix::fs::{openat, statat, AtFlags, Mode, OFlags, CWD}; | ||
use rustix::io::Errno; | ||
use std::sync::atomic::{AtomicBool, Ordering::Relaxed}; | ||
|
||
static WORKING: AtomicBool = AtomicBool::new(false); | ||
static CHECKED: AtomicBool = AtomicBool::new(false); | ||
|
||
#[inline] | ||
pub(crate) fn beneath_supported(start: &fs::File) -> bool { | ||
pub(crate) fn beneath_supported() -> bool { | ||
if WORKING.load(Relaxed) { | ||
return true; | ||
} | ||
if CHECKED.load(Relaxed) { | ||
return false; | ||
} | ||
// Unknown O_ flags get ignored but AT_ flags have strict checks, so we use that. | ||
if let Err(rustix::io::Errno::INVAL) = | ||
statat(start, "", AtFlags::EMPTY_PATH | AtFlags::RESOLVE_BENEATH) | ||
{ | ||
CHECKED.store(true, Relaxed); | ||
false | ||
} else { | ||
WORKING.store(true, Relaxed); | ||
true | ||
check_beneath_supported() | ||
} | ||
|
||
#[cold] | ||
fn check_beneath_supported() -> bool { | ||
// `RESOLVE_BENEATH` was introduced in FreeBSD 13, but opening `..` within | ||
// the root directory re-opened the root directory. In FreeBSD 14, it fails | ||
// as cap-std expects. | ||
if let Ok(root) = openat( | ||
CWD, | ||
cstr!("/"), | ||
OFlags::RDONLY | OFlags::CLOEXEC, | ||
Mode::empty(), | ||
) { | ||
// Unknown O_ flags get ignored but AT_ flags have strict checks, so we use that. | ||
if let Err(Errno::NOTCAPABLE) = statat(root, cstr!(".."), AtFlags::RESOLVE_BENEATH) { | ||
WORKING.store(true, Relaxed); | ||
return true; | ||
} | ||
} | ||
|
||
CHECKED.store(true, Relaxed); | ||
false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters