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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! 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()
//! }
//! ```

#![warn(unused_extern_crates)]
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]

#[cfg(all(feature="readline", not(target_os="openbsd")))]
extern crate rustyline;
#[macro_use] extern crate log;
extern crate clap;
extern crate libc;
extern crate errno;
extern crate regex;
#[cfg(unix)]
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(target_os="openbsd")]
extern crate pledge;

#[cfg(feature="archives")]
extern crate tar;
#[cfg(feature="archives")]
extern crate libflate;

#[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 http;
#[cfg(feature="network")]
extern crate url;
#[cfg(feature="network")]
extern crate hyper_rustls;
#[cfg(feature="network")]
extern crate tokio_core;
#[cfg(feature="network")]
extern crate futures;

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

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

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

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

    #[cfg(target_os="openbsd")]
    use pledge;

    error_chain! {
        errors {
            Errno(errno: errno::Errno) {
                description("errno")
                display("errno: {:?}", errno)
            }
        }
        foreign_links {
            Args(clap::Error);
            Io(std::io::Error);
            InvalidNum(std::num::ParseIntError);
            InvalidRegex(regex::Error);
            AddrParseError(std::net::AddrParseError);
            Base64Decode(base64::DecodeError);
            Uri(http::uri::InvalidUri) #[cfg(feature="network")];
            Http(hyper::Error) #[cfg(feature="network")];
            Caps(caps::errors::Error) #[cfg(target_os="linux")];
            Pledge(pledge::Error) #[cfg(target_os="openbsd")];
        }
    }
}
pub use self::error::{Result, Error, ErrorKind};

#[macro_use] mod macros;
pub mod busybox;
#[cfg(all(feature="readline", not(target_os="openbsd")))]
pub mod completer;
#[cfg(feature="network")]
pub mod crypto;
pub mod ctrl;
pub mod ffi;
pub mod shell;

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

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