lxc_sys2/
attach_options.rs

1use std::os::raw::{c_char, c_int, c_long, c_uint, c_void};
2use std::ptr::null_mut;
3
4/// LXC environment policy
5///
6/// ---
7/// **version:** 1.0.0
8#[repr(C)]
9#[derive(Debug, Copy, Clone)]
10pub enum lxc_attach_env_policy_t {
11    /// Retain the environment
12    ///
13    /// ---
14    /// **version:** 1.0.0
15    LXC_ATTACH_KEEP_ENV,
16    /// Clear the environment
17    ///
18    /// ---
19    /// **version:** 1.0.0
20    LXC_ATTACH_CLEAR_ENV,
21}
22
23// Options on by default
24/// Move to cgroup
25///
26/// ---
27/// **version:** 1.0.0
28pub const LXC_ATTACH_MOVE_TO_CGROUP: u32 = 0x00000001;
29/// Drop capabilities
30///
31/// ---
32/// **version:** 1.0.0
33pub const LXC_ATTACH_DROP_CAPABILITIES: u32 = 0x00000002;
34/// Set personality
35///
36/// ---
37/// **version:** 1.0.0
38pub const LXC_ATTACH_SET_PERSONALITY: u32 = 0x00000004;
39/// Execute under a Linux Security Module
40///
41/// ---
42/// **version:** 1.0.0
43pub const LXC_ATTACH_LSM_EXEC: u32 = 0x00000008;
44
45// Options off by default
46/// Remount /proc filesystem
47///
48/// ---
49/// **version:** 1.0.0
50pub const LXC_ATTACH_REMOUNT_PROC_SYS: u32 = 0x00010000;
51/// FIXME: unknown
52///
53/// ---
54/// **version:** 1.0.0
55pub const LXC_ATTACH_LSM_NOW: u32 = 0x00020000;
56
57/// Mask of flags to apply by default
58///
59/// ---
60/// **version:** 1.0.0
61pub const LXC_ATTACH_DEFAULT: u32 = 0x0000FFFF;
62
63/// All Linux Security Module flags
64///
65/// ---
66/// **version:** 1.0.0
67pub const LXC_ATTACH_LSM: u32 = LXC_ATTACH_LSM_EXEC | LXC_ATTACH_LSM_NOW;
68
69/// LXC attach function type.
70///
71/// Function to run in container
72///
73/// ---
74/// **Parameters**
75///
76/// **payload** [lxc_attach_command_t] to run.
77///
78/// ---
79/// **Returns**
80///
81/// Function should return `0` on success, and any other value to denote
82/// failure.
83///
84/// ---
85/// **version:** 1.0.0
86pub type lxc_attach_exec_t = extern "C" fn(payload: *mut c_void) -> c_int;
87
88#[repr(C)]
89#[derive(Debug, Copy, Clone)]
90/// LXC attach options for \ref lxc_container `attach()`.
91///
92/// ---
93/// **version:** 1.0.0
94pub struct lxc_attach_options_t {
95    /// Any combination of LXC_ATTACH_* flags
96    ///
97    /// ---
98    /// **version:** 1.0.0
99    pub attach_flags: c_uint,
100    /// The namespaces to attach to (CLONE_NEW... flags)
101    ///
102    /// ---
103    /// **version:** 1.0.0
104    pub namespaces: c_int,
105    /// Initial personality (`-1` to autodetect).
106    ///
107    /// ---
108    /// **warning:** This may be ignored if lxc is compiled without personality
109    /// support)
110    ///
111    /// ---
112    /// **version:** 1.0.0
113    pub personality: c_long,
114    /// Inital current directory, use `NULL` to use cwd.
115    /// If the current directory does not exist in the container, the
116    /// root directory will be used instead because of kernel defaults.
117    ///
118    /// ---
119    /// **version:** 1.0.0
120    pub initial_cwd: *mut c_char,
121    /// The user-id to run as.
122    ///
123    /// ---
124    /// **note:** Set to `-1` for default behaviour (init uid for userns
125    /// containers or `0` (super-user) if detection fails).
126    ///
127    /// ---
128    /// **version:** 1.0.0
129    pub uid: c_uint,
130    ///  The group-id to run as.
131    ///
132    /// ---
133    /// **note:** Set to `-1` for default behaviour (init gid for userns
134    /// containers or `0` (super-user) if detection fails).
135    ///
136    /// ---
137    /// **version:** 1.0.0
138    pub gid: c_uint,
139    /// Environment policy
140    ///
141    /// ---
142    /// **version:** 1.0.0
143    pub env_policy: lxc_attach_env_policy_t,
144    /// Extra environment variables to set in the container environment
145    ///
146    /// ---
147    /// **version:** 1.0.0
148    pub extra_env_vars: *mut *mut c_char,
149    /// Names of environment variables in existing environment to retain
150    /// in container environment.
151    ///
152    /// ---
153    /// **version:** 1.0.0
154    pub extra_keep_env: *mut *mut c_char,
155
156    /// stdin file descriptor
157    ///
158    /// ---
159    /// **version:** 1.0.0
160    pub stdin_fd: c_int,
161    /// stdout file descriptor
162    ///
163    /// ---
164    /// **version:** 1.0.0
165    pub stdout_fd: c_int,
166    /// stderr file descriptor
167    ///
168    /// ---
169    /// **version:** 1.0.0
170    pub stderr_fd: c_int,
171}
172
173/// Default attach options to use
174///
175/// ---
176/// **version:** 1.0.0
177impl std::default::Default for lxc_attach_options_t {
178    fn default() -> Self {
179        lxc_attach_options_t {
180            attach_flags: LXC_ATTACH_DEFAULT,
181            namespaces: -1,
182            personality: -1,
183            initial_cwd: null_mut(),
184            uid: c_uint::MAX,
185            gid: c_uint::MAX,
186            env_policy: lxc_attach_env_policy_t::LXC_ATTACH_KEEP_ENV,
187            extra_env_vars: null_mut(),
188            extra_keep_env: null_mut(),
189            stdin_fd: 0,
190            stdout_fd: 1,
191            stderr_fd: 2,
192        }
193    }
194}
195
196#[repr(C)]
197#[derive(Debug, Copy, Clone)]
198/// Representation of a command to run in a container.
199///
200/// ---
201/// **version:** 1.0.0
202pub struct lxc_attach_command_t {
203    /// The program to run (passed to execvp)
204    ///
205    /// ---
206    /// **version:** 1.0.0
207    pub program: *mut c_char,
208    /// The argv pointer of that program, including the program itself in
209    /// argv\[0\]
210    ///
211    /// ---
212    /// **version:** 1.0.0
213    pub argv: *mut *mut c_char,
214}
215
216extern "C" {
217    /// Run a command in the container.
218    ///
219    /// ---
220    /// **Parameters**
221    ///
222    /// **payload** [lxc_attach_command_t] to run.
223    ///
224    /// ---
225    /// **Returns**
226    ///
227    /// `-1` on error, exit code of lxc_attach_command_t program on success.
228    ///
229    /// ---
230    /// **version:** 1.0.0
231    pub fn lxc_attach_run_command(payload: *mut c_void) -> c_int;
232
233    /// Run a shell command in the container.
234    ///
235    /// ---
236    /// **Parameters**
237    ///
238    /// **payload** Not used.
239    ///
240    /// ---
241    /// **Returns**
242    ///
243    /// Exit code of shell.
244    ///
245    /// ---
246    /// **version:** 1.0.0
247    pub fn lxc_attach_run_shell(payload: *mut c_void) -> c_int;
248}