#openbsd #security

unveil

Rust binding for OpenBSD’s unveil(2)

3 unstable releases

Uses old Rust 2015

0.2.1 Feb 16, 2020
0.2.0 Nov 3, 2018
0.1.0 Oct 20, 2018

#147 in Cryptography

Download history 14/week @ 2020-04-22 11/week @ 2020-04-29 15/week @ 2020-05-06 16/week @ 2020-05-13 15/week @ 2020-05-20 13/week @ 2020-05-27 21/week @ 2020-06-03 7/week @ 2020-06-10 14/week @ 2020-06-17 10/week @ 2020-06-24 17/week @ 2020-07-01 12/week @ 2020-07-08 9/week @ 2020-07-15 6/week @ 2020-07-22 11/week @ 2020-07-29 9/week @ 2020-08-05

82 downloads per month
Used in 3 crates

MIT/Apache

7KB
66 lines

unveil-rs

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

~27KB