Code Monkey home page Code Monkey logo

pledge-rs's Introduction

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. MCast β†’ Mcast)
  • consider making execpromises to restrict processes after execve(2)
  • consider using unveil(2) and the unveil crate (OpenBSD 6.4+)

pledge-rs's People

Contributors

delan avatar i80and avatar semarie avatar wezm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pledge-rs's Issues

unrespected pledge API: paths argument

pledge(2) allows defining a whitelist of permitted paths. The current implementation doesn't provide it.

Even if paths argument currently returns EINVAL, I think the API should be provisionned.

unrespected API: promises type

pledge(2) promises are a string of space separated keywords. The current implementation use sort of flags instead of.

I wonder if it would be possible to provide a way to use the low level form: it would permit to use the others promises not implemented by the crate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.