| 1 | // SPDX-License-Identifier: Apache-2.0 or MIT |
| 2 | // |
| 3 | // Copyright 2021 Sony Group Corporation |
| 4 | // |
| 5 | |
| 6 | //! Rust Language Bindings for the libseccomp Library |
| 7 | //! |
| 8 | //! The libseccomp library provides an easy to use, platform independent, interface to |
| 9 | //! the Linux Kernel's syscall filtering mechanism. The libseccomp API is designed to |
| 10 | //! abstract away the underlying BPF based syscall filter language and present a more |
| 11 | //! conventional function-call based filtering interface that should be familiar to, and |
| 12 | //! easily adopted by, application developers. |
| 13 | //! |
| 14 | //! The libseccomp crate is a high-level safe API for the libseccomp library. |
| 15 | //! |
| 16 | //! # Examples |
| 17 | //! |
| 18 | //! ```rust |
| 19 | //! use libseccomp::*; |
| 20 | //! |
| 21 | //! fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 22 | //! let mut filter = ScmpFilterContext::new(ScmpAction::Allow)?; |
| 23 | //! let syscall = ScmpSyscall::from_name("getuid")?; |
| 24 | //! |
| 25 | //! filter.add_arch(ScmpArch::X8664)?; |
| 26 | //! filter.add_rule(ScmpAction::Errno(1), syscall)?; |
| 27 | //! filter.set_ctl_log(true)?; |
| 28 | //! filter.set_syscall_priority(syscall, 100)?; |
| 29 | //! filter.load()?; |
| 30 | //! |
| 31 | //! Ok(()) |
| 32 | //! } |
| 33 | //! ``` |
| 34 | //! |
| 35 | //! The above example can be replaced with builder pattern. |
| 36 | //! |
| 37 | //! ```rust |
| 38 | //! use libseccomp::*; |
| 39 | //! |
| 40 | //! fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 41 | //! let syscall = ScmpSyscall::from_name("getuid")?; |
| 42 | //! |
| 43 | //! ScmpFilterContext::new(ScmpAction::Allow)? |
| 44 | //! .add_arch(ScmpArch::X8664)? |
| 45 | //! .add_rule(ScmpAction::Errno(1), syscall)? |
| 46 | //! .set_ctl_log(true)? |
| 47 | //! .set_syscall_priority(syscall, 100)? |
| 48 | //! .load()?; |
| 49 | //! |
| 50 | //! Ok(()) |
| 51 | //! } |
| 52 | //! ``` |
| 53 | //! |
| 54 | //! # Features |
| 55 | //! |
| 56 | //! - `const-syscall`: Allow creating of `ScmpSyscall` in a `const`-context. |
| 57 | |
| 58 | #![warn(rust_2018_idioms)] |
| 59 | #![deny(missing_debug_implementations)] |
| 60 | #![deny(missing_docs)] |
| 61 | #![deny(unsafe_op_in_unsafe_fn)] |
| 62 | #![warn(clippy::inefficient_to_string)] |
| 63 | #![warn(clippy::string_to_string)] |
| 64 | #![warn(clippy::semicolon_if_nothing_returned)] |
| 65 | #![warn(clippy::clone_on_ref_ptr)] |
| 66 | #![warn(clippy::unwrap_in_result)] |
| 67 | #![cfg_attr(docsrs, feature(doc_cfg))] |
| 68 | |
| 69 | /// Errors |
| 70 | pub mod errorrust-analyzer cargo libseccomp 0.4.0 error/; |
| 71 | |
| 72 | mod actionrust-analyzer cargo libseccomp 0.4.0 action/; |
| 73 | mod apirust-analyzer cargo libseccomp 0.4.0 api/; |
| 74 | mod archrust-analyzer cargo libseccomp 0.4.0 arch/; |
| 75 | mod arg_comparerust-analyzer cargo libseccomp 0.4.0 arg_compare/; |
| 76 | mod compare_oprust-analyzer cargo libseccomp 0.4.0 compare_op/; |
| 77 | mod filter_attrrust-analyzer cargo libseccomp 0.4.0 filter_attr/; |
| 78 | mod filter_contextrust-analyzer cargo libseccomp 0.4.0 filter_context/; |
| 79 | mod functionsrust-analyzer cargo libseccomp 0.4.0 functions/; |
| 80 | mod notifyrust-analyzer cargo libseccomp 0.4.0 notify/; |
| 81 | mod syscallrust-analyzer cargo libseccomp 0.4.0 syscall/; |
| 82 | mod versionrust-analyzer cargo libseccomp 0.4.0 version/; |
| 83 | |
| 84 | use errorrust-analyzer cargo libseccomp 0.4.0 error/::{Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#, SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#}; |
| 85 | |
| 86 | pub use actionrust-analyzer cargo libseccomp 0.4.0 action/::ScmpActionrust-analyzer cargo libseccomp 0.4.0 action/ScmpAction#; |
| 87 | pub use apirust-analyzer cargo libseccomp 0.4.0 api/::{check_apirust-analyzer cargo libseccomp 0.4.0 api/check_api()., get_apirust-analyzer cargo libseccomp 0.4.0 api/get_api()., set_apirust-analyzer cargo libseccomp 0.4.0 api/set_api().}; |
| 88 | pub use archrust-analyzer cargo libseccomp 0.4.0 arch/::ScmpArchrust-analyzer cargo libseccomp 0.4.0 arch/ScmpArch#; |
| 89 | pub use arg_comparerust-analyzer cargo libseccomp 0.4.0 arg_compare/::ScmpArgComparerust-analyzer cargo libseccomp 0.4.0 arg_compare/ScmpArgCompare#; |
| 90 | pub use compare_oprust-analyzer cargo libseccomp 0.4.0 compare_op/::ScmpCompareOprust-analyzer cargo libseccomp 0.4.0 compare_op/ScmpCompareOp#; |
| 91 | pub use filter_attrrust-analyzer cargo libseccomp 0.4.0 filter_attr/::ScmpFilterAttrrust-analyzer cargo libseccomp 0.4.0 filter_attr/ScmpFilterAttr#; |
| 92 | pub use filter_contextrust-analyzer cargo libseccomp 0.4.0 filter_context/::ScmpFilterContextrust-analyzer cargo libseccomp 0.4.0 filter_context/ScmpFilterContext#; |
| 93 | pub use functionsrust-analyzer cargo libseccomp 0.4.0 functions/::*; |
| 94 | pub use notifyrust-analyzer cargo libseccomp 0.4.0 notify/::*; |
| 95 | pub use syscallrust-analyzer cargo libseccomp 0.4.0 syscall/::{RawSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/RawSyscall#, ScmpSyscallrust-analyzer cargo libseccomp 0.4.0 syscall/ScmpSyscall#}; |
| 96 | pub use versionrust-analyzer cargo libseccomp 0.4.0 version/::{check_versionrust-analyzer cargo libseccomp 0.4.0 version/check_version()., ScmpVersionrust-analyzer cargo libseccomp 0.4.0 version/ScmpVersion#}; |
| 97 | |
| 98 | fn cvtrust-analyzer cargo libseccomp 0.4.0 cvt().(ret: i32) -> Resultrust-analyzer cargo libseccomp 0.4.0 error/Result#<()> { |
| 99 | if ret rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 100 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 101 | } else { |
| 102 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(SeccompErrorrust-analyzer cargo libseccomp 0.4.0 error/SeccompError#::from_errnorust-analyzer cargo libseccomp 0.4.0 error/impl#[SeccompError]from_errno().(ret)) |
| 103 | } |
| 104 | } |