AUSEARCH-EXPRESSION(5)

๐Ÿ’– NAME ๐Ÿ’–

ausearch-expression โ€” it's the audit search expression format, bestie. that's the whole thing. this page is section 5 of the manual and it's giving format spec, and we're obsessed. ๐Ÿ’…


โœจ OVERVIEW โœจ

okay so real talk: this page describes the format of "ausearch expressions". the parsing AND the evaluation of these expressions? that's all provided by libauparse, and it's common to every application that uses this library. so like, learn it once, use it everywhere. no cap. ๐Ÿฆ‹


๐Ÿ”ค LEXICAL STRUCTURE ๐Ÿ”ค

white space between tokens is ignored โ€” and when we say white space we mean ASCII space, tab, and new-line characters. the tokens you're gonna see are these:

  • Punctuation โ€” literally just these three: (, ), \
  • Logical operators โ€” !, &&, ||
  • Comparison operators โ€” <, <=, ==, >, >=, !==, i=, i!=, r=, r!=
  • Unquoted strings โ€” any non-empty sequence of ASCII letters, digits, and the _ symbol. simple. cute. effective. ๐ŸŽ€
  • Quoted strings โ€” a sequence of characters surrounded by the " quotes. the \ character starts an escape sequence. the only defined escape sequences are \\ and \". the semantics of other escape sequences is undefined โ€” so like, don't, bestie. ๐Ÿ™ˆ
  • Regexps โ€” a sequence of characters surrounded by the / characters. the \ character starts an escape sequence here too. the only defined escape sequences are \\ and \/. and yeah, the semantics of other escape sequences is undefined again. ๐Ÿ’€

and here's the iconic part: anywhere an unquoted string is valid, a quoted string is valid as well, and vice versa. in particular, field names may be specified using quoted strings, and field values may be specified using unquoted strings. mix and match, it's your world. ๐ŸŒˆ


๐Ÿง  EXPRESSION SYNTAX ๐Ÿง 

so the primary expression has one of these two forms, periodt:

field comparison-operator value

\regexp string-or-regexp

now let's break it down, because the way that this works is lowkey elegant:

field is either a string, which specifies the first field with that name within the current audit record, OR it's the \ escape character followed by a string, which specifies a virtual field with the specified name (virtual fields get defined in a later section, stay tuned โœจ).

field is a string. operator specifies the comparison to perform. okay? okay. ๐Ÿซถ

now the operators, one by one:

  • r=, r!= โ€” get the "raw" string of field, and compare it to value. for fields in audit records, the "raw" string is the exact string stored in the audit record (with all escaping and unprintable character encoding left alone); applications can read the "raw" string using auparse_get_field_str(3). each virtual field may define a "raw" string. and if field is not present or does not define a "raw" string, the result of the comparison is false โ€” regardless of the operator. so like, false no matter what, even for r!=. noted. ๐Ÿ’…
  • i=, i!= โ€” get the "interpreted" string of field, and compare it to value. for fields in audit records, the "interpreted" string is a "user-readable" interpretation of the field value; applications can read the "interpreted" string using auparse_interpret_field(3). each virtual field may define an "interpreted" string. if field is not present or does not define an "interpreted" string, the result of the comparison is false โ€” regardless of the operator. same energy as above, different string. ๐Ÿฆ‹
  • <, <=, ==, >, >=, !== โ€” evaluate the "value" of field, and compare it to value. a "value" may be defined for any field or virtual field, but no "value" is currently defined for any audit record field. the rules of parsing value for comparing it with the "value" of field are specific for each field. if field is not present, the result of the comparison is false โ€” regardless of the operator. and if field does not define a "value", an error is reported when parsing the expression. so that's a hard no, not a quiet false. ๐Ÿ˜ญ

now for the special case of \regexp regexp-or-string: the current audit record is taken as a string (without interpreting field values), and matched against regexp-or-string. and regexp-or-string is an extended regular expression, using a string or regexp token โ€” in other words, delimited by " or /. ๐ŸŒธ

and if E1 and E2 are valid expressions, then ! E1, E1 && E2, and E1 || E2 are valid expressions as well, with the usual C semantics and evaluation priorities. one thing though, don't get it twisted: ! field op value is interpreted as !(field op value), not as (!field) op value. ๐Ÿซถ


๐Ÿฆ‹ VIRTUAL FIELDS ๐Ÿฆ‹

here's the roster of virtual fields, and honestly, they ate:

  • \timestamp โ€” the value is the timestamp of the current event. value must be formatted as:
ts:seconds.milli

where seconds and milli are decimal numbers specifying the seconds and milliseconds part of the timestamp, respectively. โญ

  • \timestamp_ex โ€” this is similar to \timestamp but also includes the event's serial number. value must be formatted as:
ts:seconds.milli:serial

where serial is a decimal number specifying the event's serial number. ๐Ÿ‘‘

  • \record_type โ€” the value is the type of the current record. value is either the record type name, or a decimal number specifying the type. ๐ŸŒˆ

๐Ÿ’… SEMANTICS ๐Ÿ’…

the expression as a whole applies to a single record. and the expression is true for a specified event if it is true for any record associated with the event. so like, one match and the whole event is a yes. main character energy, fr fr. ๐Ÿ”ฅ


๐ŸŒˆ EXAMPLES ๐ŸŒˆ

as a demonstration of the semantics of handling missing fields โ€” which, lowkey, is the whole point โ€” the following expression is true if field is present:

(field r= "") || (field r!= "")

and the same expression surrounded by !( and ) is true if field is not present. ๐Ÿ˜Œ


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

some things may change, so keep your eyes open, bestie:

  • new escape sequences for quoted strings may be defined.
  • for currently defined virtual fields that do not define a "raw" or "interpreted" string, the definition may be added. therefore, don't rely on the fact that comparing the "raw" or "interpreted" string of the field with any value is false. seriously. that's a trap. ๐Ÿ’€
  • new formats of value constants for the \timestamp virtual field may be added.

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Miloslav Trmac ๐Ÿ’–


so that's the whole page, bestie โ€” authored by Miloslav Trmac, brought to you by Red Hat, dated Feb 2008. this was AUSEARCH-EXPRESSION(5) and honestly? iconic. go write some expressions. slay. ๐Ÿ’…โœจ๐ŸŽ€
๐Ÿ“ฆ where this page comes from