#openbsd #security

unveil

Rust binding for OpenBSD’s unveil(2)

5 unstable releases

Uses old Rust 2015

0.3.1 Jun 6, 2021
0.3.0 Jan 10, 2021
0.2.1 Feb 16, 2020
0.2.0 Nov 3, 2018
0.1.0 Oct 20, 2018

#2 in #openbsd

Download history 22/week @ 2021-05-30 40/week @ 2021-06-06 19/week @ 2021-06-13 34/week @ 2021-06-20 32/week @ 2021-06-27 197/week @ 2021-07-04 105/week @ 2021-07-11 30/week @ 2021-07-18 42/week @ 2021-07-25 48/week @ 2021-08-01 34/week @ 2021-08-08 31/week @ 2021-08-15 44/week @ 2021-08-22 13/week @ 2021-08-29 41/week @ 2021-09-05 20/week @ 2021-09-12

166 downloads per month
Used in 5 crates

MIT/Apache

8KB
112 lines

unveil-rs

Crate Documentation

Rust binding for OpenBSD's unveil(2).

Requirements

  • OpenBSD 6.4 or later

Usage

extern crate unveil;

use std::fs::File;
use std::io::prelude::*;
use unveil::unveil;

fn main() {
    let path = "public.txt";
    let contents = b"Hello world!";
    File::create(path).unwrap().write_all(contents).unwrap();

    // Restrict filesystem view by only allowing read operations on the specified path
    unveil(path, "r").unwrap();

    // Reading from unveiled paths will succeed
    let mut file = File::open(path).unwrap();
    let mut buffer = Vec::new();
    file.read_to_end(&mut buffer).unwrap();
    assert_eq!(contents, &buffer[..]);

    // Reading from paths which have not been unveiled will fail
    assert!(File::open("/etc/passwd").is_err());

    // Disable further calls to unveil
    unveil("", "").unwrap();

    // All calls to unveil will now fail
    assert!(unveil(path, "rw").is_err());
}

Related projects

  • pledge-rs - Rust binding for OpenBSD's pledge(2).

Dependencies

~30KB