Struct unix_fd::chroot::Chroot[][src]

pub struct Chroot { /* fields omitted */ }

Userspace chroot environment

All symlinks below a root directory are resolved relative this directory. E.g. when having a directory tree like

/
|-- etc/
|   `-- passwd
`-- srv/
    `-- www/
        |-- etc/
        |   `-- passwd
        |-- tmp -> /etc/
        |-- passwd -> /etc/passwd
        `-- test -> ../../../etc/passwd

All the open() statements in code like

let chroot = Chroot::new(&OsString::from("/srv/www"));

let fd = chroot.open(&Path::new("/etc/passwd"), libc::O_RDONLY);
let fd = chroot.open(&Path::new("/tmp/passwd"), libc::O_RDONLY);
let fd = chroot.open(&Path::new("/test"), libc::O_RDONLY);
let fd = chroot.open(&Path::new("/passwd"), libc::O_RDONLY);

will access /srv/www/etc/passwd instead of /etc/passwd.

Implementations

impl Chroot[src]

pub fn new<T: AsRef<Path>>(root: &T) -> Self[src]

pub fn root_fdraw(&self) -> Result<FdRaw>[src]

Opens the top level directory of the chroot directory and returns the filedescriptor.

The directory will be opened with O_CLOEXEC flag being set.

pub fn root_fd(&self) -> Result<Fd>[src]

pub fn chdir<T>(&self, path: &T) -> Result<Fd> where
    T: AsRef<Path>, 
[src]

Opens the directory at path within the chroot.

Every intermediate symlinks will be resolved relative to to the chroot.

Restrictions: path must be absolute.

pub fn chdirat<T>(&self, dir_fd: &Fd, path: &T) -> Result<Fd> where
    T: AsRef<Path>, 
[src]

Opens a directory path in the chroot environment relative to fd.

Behaviour is unspecified if fd lies outside the chroot. path can be relative.

pub fn openat<T>(&self, dir_fd: &Fd, path: &T, flags: c_int) -> Result<Fd> where
    T: AsRef<Path>, 
[src]

Opens a file in the chroot relative to an open directory fd.

Method first opens the directory containing path as described by Self::chdirat() and calls openat() with `O_NOFOLLOW being set there.

pub fn open<T>(&self, path: &T, flags: c_int) -> Result<Fd> where
    T: AsRef<Path>, 
[src]

Opens a file in the chroot environment.

Method first opens the directory containing path as described by Self::chdir() and calls openat() with `O_NOFOLLOW being set there.

pub fn is_lnkat<T>(&self, dir_fd: &Fd, path: &T) -> bool where
    T: AsRef<Path>, 
[src]

Checks whether path is a symlink

Method returns when errors occurred while performing the lookup.

pub fn is_dirat<T>(&self, dir_fd: &Fd, path: &T) -> bool where
    T: AsRef<Path>, 
[src]

Checks whether path is a directory

Method returns when errors occurred while performing the lookup.

pub fn is_regat<T>(&self, dir_fd: &Fd, path: &T) -> bool where
    T: AsRef<Path>, 
[src]

Checks whether path is a regular file

Method returns when errors occurred while performing the lookup.

pub fn fstatat<T>(&self, dir_fd: &Fd, fname: &T) -> Result<stat> where
    T: AsRef<Path>, 
[src]

Returns fstat information

pub fn full_path<T>(&self, dir_fd: &Fd, fname: Option<&T>) -> Result<OsString> where
    T: AsRef<Path>, 
[src]

Transforms fd into an absolute path relative to the chroot and appends fname optionally.

Note: this operation is expensive because it recurses into the parent directories of fd and iterates over their contents to look for a matching subdirectory.

Trait Implementations

impl Debug for Chroot[src]

Auto Trait Implementations

impl RefUnwindSafe for Chroot

impl Send for Chroot

impl Sync for Chroot

impl Unpin for Chroot

impl UnwindSafe for Chroot

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.