All Projects → i80and → pledge-rs

i80and / pledge-rs

Licence: MIT license
A Rust binding to OpenBSD's pledge(2) interface

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to pledge-rs

Rust Onig
Rust bindings for the Oniguruma regex library
Stars: ✭ 81 (+285.71%)
Mutual labels:  rust-bindings
Zstd Rs
A rust binding for the zstd compression library.
Stars: ✭ 159 (+657.14%)
Mutual labels:  rust-bindings
ctp-rs
A Rust wrapper of CTP API
Stars: ✭ 74 (+252.38%)
Mutual labels:  rust-bindings
Rustkit
Fast and ergonomic Rust bindings for ObjC APIs
Stars: ✭ 89 (+323.81%)
Mutual labels:  rust-bindings
Rust Jack
Decent jack bindings for rust
Stars: ✭ 128 (+509.52%)
Mutual labels:  rust-bindings
Midir
Cross-platform realtime MIDI processing in Rust.
Stars: ✭ 221 (+952.38%)
Mutual labels:  rust-bindings
Rusted Switch
Nintendo Switch Homebrew with Rust 🦀
Stars: ✭ 75 (+257.14%)
Mutual labels:  rust-bindings
libsmt.rs
Rust Bindings to interact with SMTLIB2 compliant solvers
Stars: ✭ 14 (-33.33%)
Mutual labels:  rust-bindings
Shaderc Rs
Rust bindings for the shaderc library.
Stars: ✭ 143 (+580.95%)
Mutual labels:  rust-bindings
liboqs-rust
Rust bindings for liboqs
Stars: ✭ 46 (+119.05%)
Mutual labels:  rust-bindings
Llvm Sys.rs
Rust bindings to LLVM. (Mirror of https://gitlab.com/taricorp/llvm-sys.rs/)
Stars: ✭ 93 (+342.86%)
Mutual labels:  rust-bindings
Nix
Rust friendly bindings to *nix APIs
Stars: ✭ 1,660 (+7804.76%)
Mutual labels:  rust-bindings
mongo-rust-driver
Mongo Rust driver built on top of the Mongo C driver
Stars: ✭ 89 (+323.81%)
Mutual labels:  rust-bindings
Napi
High-level Node.js N-API bindings for Rust [WIP] ✨🦀🚀✨
Stars: ✭ 85 (+304.76%)
Mutual labels:  rust-bindings
blend2d-rs
Blend2D Bindings for Rust
Stars: ✭ 20 (-4.76%)
Mutual labels:  rust-bindings
Lodepng Rust
All-in-one PNG image encoder/decoder in pure Rust
Stars: ✭ 78 (+271.43%)
Mutual labels:  rust-bindings
Mlua
High level Lua 5.4/5.3/5.2/5.1 (including LuaJIT) bindings to Rust with async/await support
Stars: ✭ 176 (+738.1%)
Mutual labels:  rust-bindings
yara-rust
Rust bindings for VirusTotal/Yara
Stars: ✭ 35 (+66.67%)
Mutual labels:  rust-bindings
mozjpeg-rust
Safe Rust wrapper for the MozJPEG library
Stars: ✭ 53 (+152.38%)
Mutual labels:  rust-bindings
voikko-rs
Rust bindings for the Voikko library
Stars: ✭ 16 (-23.81%)
Mutual labels:  rust-bindings

pledge-rs

MIT licensed crates.io

A Rust binding to OpenBSD's pledge(2) interface.

Usage

/* Rust 2015 only */ #[macro_use] extern crate pledge;
/* Rust 2018 only */ use pledge::{pledge, pledge_promises, pledge_execpromises};

fn foo() {
    // make both promises and execpromises
    pledge![Stdio Proc Exec, Stdio Tty].unwrap();

    // make promises only
    pledge_promises![Stdio Exec].unwrap();

    // make execpromises only
    pledge_execpromises![Stdio].unwrap();
}

This is roughly equivalent to:

/* Rust 2015 only */ extern crate pledge;
use pledge::{pledge, Promise, ToPromiseString};

fn foo() {
    // make both promises and execpromises
    let promises = vec![Promise::Stdio, Promise::Proc, Promise::Exec];
    let execpromises = vec![Promise::Stdio, Promise::Tty];
    pledge(&*promises.to_promise_string(), &*execpromises.to_promise_string()).unwrap();

    // make promises only
    let promises = vec![Promise::Stdio, Promise::Exec];
    pledge(&*promises.to_promise_string(), None).unwrap();

    // make execpromises only
    let execpromises = vec![Promise::Stdio];
    pledge(None, &*execpromises.to_promise_string()).unwrap();
}

You may also provide promises directly as a string:

/* Rust 2015 only */ extern crate pledge;
use pledge::pledge;

fn foo() {
    // make both promises and execpromises
    pledge("stdio proc exec", "stdio tty").unwrap();

    // make promises only
    pledge("stdio exec", None).unwrap();

    // make execpromises only
    pledge(None, "stdio").unwrap();
}

All of these will yield pledge::Error::UnsupportedPlatform on platforms that don’t support pledge(2). You can use pledge::Error::ignore_platform to ignore that variant and make your program portable to those platforms:

/* Rust 2015 only */ extern crate pledge;
/* Rust 2018 only */ use pledge::pledge_promises;

fn foo() {
    ...

    pledge_promises![Stdio Exec]
        .or_else(pledge::Error::ignore_platform)
        .unwrap();

    ...
}

Compatibility

This version of the crate is compatible with the OpenBSD 6.3+ interface, where the second parameter restricts the privileges of the process after execve(2), and guaranteed to be compatible with Rust 1.24.0+ (as shipped by OpenBSD 6.3).

Use version ^0.3 for the OpenBSD 5.9+ interface last supported by Bitrig, where the second parameter sets a whitelist of permitted paths.

To migrate your code from older versions:

  • change pledge![P, Q, R] call sites to pledge_promises![P Q R]
  • change pledge("p q r") call sites to pledge("p q r", None)
  • change pledge_with_paths(promises, paths) to pledge(promises)
  • update usage of renamed Promise variants (e.g. MCastMcast)
  • consider making execpromises to restrict processes after execve(2)
  • consider using unveil(2) and the unveil crate (OpenBSD 6.4+)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].