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
//! 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
//!
//! ```
//! extern crate boxxy;
//! extern crate env_logger;
//!
//! fn stage1(args: Vec<String>) -> Result<(), boxxy::Error> {
//!     println!("init stage 1! {:?}", args);
//!     // your code here
//!     Ok(())
//! }
//!
//! fn stage2(args: Vec<String>) -> Result<(), boxxy::Error> {
//!     println!("init stage 2! {:?}", args);
//!     // your code here
//!     Ok(())
//! }
//!
//! fn main() {
//!     env_logger::init().unwrap();
//!
//!     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;

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

pub mod busybox;
pub mod ffi;
pub mod shell;

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

/// Result of builtin commands
pub type Result = std::result::Result<(), Error>;
/// Arguments passed to builtin commands
pub type Arguments = Vec<String>;

/// Possible errors during builtin commands
#[derive(Debug)]
pub enum Error {
    Args(clap::Error),
    Io(io::Error),
    Errno(errno::Errno),
    InvalidNum(std::num::ParseIntError),
    InvalidRegex(regex::Error),
}

impl From<clap::Error> for Error {
    fn from(err: clap::Error) -> Error {
        Error::Args(err)
    }
}

impl From<io::Error> for Error {
    fn from(err: io::Error) -> Error {
        Error::Io(err)
    }
}

impl From<num::ParseIntError> for Error {
    fn from(err: num::ParseIntError) -> Error {
        Error::InvalidNum(err)
    }
}

impl From<regex::Error> for Error {
    fn from(err: regex::Error) -> Error {
        Error::InvalidRegex(err)
    }
}