| 1 | #[cfg(feature = "serde")] |
| 2 | use serde_withrust-analyzer cargo serde_with 3.21.0 crate/::{DeserializeFromStrrust-analyzer cargo serde_with_macros 3.21.0 DeserializeFromStr:, SerializeDisplayrust-analyzer cargo serde_with_macros 3.21.0 SerializeDisplay:}; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#}; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/, FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#}; |
| 5 | |
| 6 | use thiserrorrust-analyzer cargo thiserror 2.0.18 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:; |
| 7 | |
| 8 | use craterust-analyzer cargo linux-audit-parser 0.2.8 crate/::constantsrust-analyzer cargo linux-audit-parser 0.2.8 constants/::*; |
| 9 | |
| 10 | /// Type of an audit message, corresponding to the `type=…` part of |
| 11 | /// every Linux Audit log line. |
| 12 | /// |
| 13 | /// The implementation uses the same 32bit unsigned integer values |
| 14 | /// that are used by the Linux Audit API. Mappings between numeric and |
| 15 | /// symbolic values is generated using CSV retrieved from the [`Linux |
| 16 | /// Audit Project`]'s documentation. |
| 17 | /// |
| 18 | /// [`Linux Audit Project`]: https://github.com/linux-audit/audit-documentation |
| 19 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 20 | #[cfg_attr(feature = "serde", derive(DeserializeFromStrrust-analyzer cargo serde_with_macros 3.21.0 DeserializeFromStr:, SerializeDisplayrust-analyzer cargo serde_with_macros 3.21.0 SerializeDisplay:))] |
| 21 | pub struct MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#(pub u32); |
| 22 | |
| 23 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType# { |
| 24 | fn fmtrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 25 | match EVENT_NAMESrust-analyzer cargo linux-audit-parser 0.2.8 constants/EVENT_NAMES..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&(self.0rust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#0.)) { |
| 26 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{name}"), |
| 27 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "UNKNOWN[{}]", self.0rust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#0.), |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType# { |
| 33 | fn fmtrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 34 | match EVENT_NAMESrust-analyzer cargo linux-audit-parser 0.2.8 constants/EVENT_NAMES..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&(self.0rust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#0.)) { |
| 35 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "MessageType({name})"), |
| 36 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "MessageType({})", self.0rust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#0.), |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /// The error type returned by [MessageType::from_str] |
| 42 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:)] |
| 43 | pub enum ParseMessageTypeErrorrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError# { |
| 44 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("unknown identifier ({0})")] |
| 45 | Unknownrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#Unknown#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 46 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("malformed UNKNOWN[…] string")] |
| 47 | MalformedUnknownrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#MalformedUnknown#, |
| 48 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("cannot parse number ({0}): {1}")] |
| 49 | Numberrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#Number#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#), |
| 50 | } |
| 51 | |
| 52 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType# { |
| 53 | type Errrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType][FromStr]Err# = ParseMessageTypeErrorrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#; |
| 54 | fn from_strrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType][FromStr], Selfrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 55 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = EVENT_IDSrust-analyzer cargo linux-audit-parser 0.2.8 constants/EVENT_IDS..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) { |
| 56 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().id)) |
| 57 | } else { |
| 58 | let number = s |
| 59 | .strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("UNKNOWN[") |
| 60 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| ParseMessageTypeErrorrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#::Unknownrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#Unknown#(s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 61 | .strip_suffixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_suffix().(']') |
| 62 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(ParseMessageTypeErrorrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#::MalformedUnknownrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#MalformedUnknown#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 63 | let id = u32::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32][FromStr]from_str().(number) |
| 64 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| ParseMessageTypeErrorrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#::Numberrust-analyzer cargo linux-audit-parser 0.2.8 message_type/ParseMessageTypeError#Number#(number.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 65 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#(id)) |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | includerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include!!(concatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/concat!!(envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/env!!("OUT_DIR"), "/message_type_impl.rs")); |
| 71 | |
| 72 | impl MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType# { |
| 73 | /// True for messages that are part of multi-part events from |
| 74 | /// kernel-space. |
| 75 | /// |
| 76 | /// This mimics auparse logic as of version 3.0.6 |
| 77 | pub fn is_multipartrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType]is_multipart().(&self) -> bool { |
| 78 | (1300..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2100).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`]contains().(&self.0rust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#0.) || self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&MessageTyperust-analyzer cargo linux-audit-parser 0.2.8 message_type/MessageType#::LOGINrust-analyzer cargo linux-audit-parser 0.2.8 message_type/impl#[MessageType]LOGIN. |
| 79 | } |
| 80 | } |