1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! This crate provides an interactive shell that can be used to provide a
//! basic debugger for sandboxes. It features a couple of builtin commands to
//! test eg. file access when external programs can't be used (chroots or
//! seccomp).
//!
//! It also accepts custom functions that can be included to step through
//! various stages of your sandbox.
//!
//! # Example
//!
//! ```
//! #[macro_use] extern crate boxxy;
//! extern crate env_logger;
//!
//! fn stage1(sh: &mut boxxy::Shell, args: Vec<String>) -> Result<(), boxxy::Error> {
//!     shprintln!(sh, "init stage 1! {:?}", args);
//!     // your code here
//!     Ok(())
//! }
//!
//! fn stage2(sh: &mut boxxy::Shell, args: Vec<String>) -> Result<(), boxxy::Error> {
//!     shprintln!(sh, "init stage 2! {:?}", args);
//!     // your code here
//!     Ok(())
//! }
//!
//! fn main() {
//!     env_logger::init();
//!
//!     let toolbox = boxxy::Toolbox::new().with(vec![
//!             ("stage1", stage1),
//!             ("stage2", stage2),
//!         ]);
//!     boxxy::Shell::new(toolbox).run()
//! }
//! ```
extern crate rustyline;
#[macro_use] extern crate log;
extern crate clap;
extern crate libc;
extern crate errno;
extern crate regex;
extern crate nix;
extern crate base64;
extern crate bufstream;
#[macro_use] extern crate error_chain;
#[macro_use] extern crate cfg_if;

#[cfg(target_os="linux")]
extern crate caps;

#[cfg(feature="network")]
extern crate rustls;
#[cfg(feature="network")]
extern crate webpki;
#[cfg(feature="network")]
extern crate crypto as rust_crypto;

#[cfg(feature="network")]
extern crate hyper;
#[cfg(feature="network")]
extern crate hyper_rustls;
#[cfg(feature="network")]
extern crate tokio_core;
#[cfg(feature="network")]
extern crate futures;

mod error {
    use clap;
    use regex;
    use errno;

    #[cfg(feature="network")]
    use hyper;

    #[cfg(target_os="linux")]
    use caps;

    use std::io;
    use std::num;

    error_chain! {
        errors {
            Errno(errno: errno::Errno) {
                description("errno")
                display("errno: {:?}", errno)
            }
        }
        foreign_links {
            Args(clap::Error);
            Io(io::Error);
            InvalidNum(num::ParseIntError);
            InvalidRegex(regex::Error);
            Uri(hyper::error::UriError) #[cfg(feature="network")];
            Http(hyper::Error) #[cfg(feature="network")];
            Caps(caps::errors::Error) #[cfg(target_os="linux")];
        }
    }
}
pub use self::error::{Result, Error, ErrorKind};

#[macro_use] mod macros;
pub mod busybox;
#[cfg(feature="network")]
pub mod crypto;
pub mod ctrl;
pub mod ffi;
pub mod shell;

pub use shell::{Shell, Toolbox};
pub use shell::{Command, NativeCommand, ForeignCommand};

/// Arguments passed to builtin commands
pub type Arguments = Vec<String>;