2222 */
2323
2424#include "config.h"
25- #include "expression.h"
26- #include "internal.h"
27- #include "auparse.h"
28- #include "interpret.h"
29- #include "auparse-idata.h"
30- #include "libaudit.h"
3125#include <errno.h>
3226#include <stdlib.h>
3327#include <string.h>
3428#include <unistd.h>
3529#include <fcntl.h>
3630#include <stdio_ext.h>
3731#include <limits.h>
32+ #include "internal.h"
33+ #include "expression.h"
34+ #include "auparse.h"
35+ #include "interpret.h"
36+ #include "auparse-idata.h"
37+ #include "libaudit.h"
3838#include "common.h"
3939
4040//#define LOL_EVENTS_DEBUG01 1 // add debug for list of list event
@@ -46,12 +46,6 @@ static int debug = 0;
4646
4747static time_t eoe_timeout = EOE_TIMEOUT ;
4848
49- static void init_lib (void ) __attribute__ ((constructor ));
50- static void init_lib (void )
51- {
52- init_interpretation_list ();
53- }
54-
5549/* like strchr except string is delimited by length, not null byte */
5650static char * strnchr (const char * s , int c , size_t n )
5751{
@@ -574,6 +568,11 @@ auparse_state_t *auparse_init(ausource_t source, const void *b)
574568 au -> find_field = NULL ;
575569 au -> search_where = AUSEARCH_STOP_EVENT ;
576570 au -> tmp_translation = NULL ;
571+ au -> uid_cache = NULL ;
572+ au -> uid_cache_created = 0 ;
573+ au -> gid_cache = NULL ;
574+ au -> gid_cache_created = 0 ;
575+ init_interpretation_list (au );
577576 init_normalizer (& au -> norm_data );
578577
579578 return au ;
@@ -633,8 +632,8 @@ static void consume_feed(auparse_state_t *au, int flush)
633632 au -> le = l ; // make this current the event of interest
634633 aup_list_first (l );
635634 r = aup_list_get_cur (l );
636- free_interpretation_list ();
637- load_interpretation_list (r -> interp );
635+ free_interpretation_list (au );
636+ load_interpretation_list (au , r -> interp );
638637 aup_list_first_field (l );
639638
640639 if (au -> callback ) {
@@ -722,22 +721,22 @@ void auparse_set_escape_mode(auparse_state_t *au, auparse_esc_t mode)
722721 * buf is a string of name value pairs to be used for interpreting.
723722 * Calling this function automatically releases the previous list.
724723 */
725- void _auparse_load_interpretations (const char * buf )
724+ void _auparse_load_interpretations (auparse_state_t * au , const char * buf )
726725{
727- free_interpretation_list ();
726+ free_interpretation_list (au );
728727
729728 if (buf == NULL )
730729 return ;
731730
732- load_interpretation_list (buf );
731+ load_interpretation_list (au , buf );
733732}
734733
735734/*
736735 * Non-public function. Subject to change.
737736 */
738- void _auparse_free_interpretations (void )
737+ void _auparse_free_interpretations (auparse_state_t * au )
739738{
740- free_interpretation_list ();
739+ free_interpretation_list (au );
741740}
742741
743742int auparse_reset (auparse_state_t * au )
@@ -782,7 +781,7 @@ int auparse_reset(auparse_state_t *au)
782781 default :
783782 return -1 ;
784783 }
785- free_interpretation_list ();
784+ free_interpretation_list (( auparse_state_t * ) au );
786785 return 0 ;
787786}
788787
@@ -791,7 +790,7 @@ char *auparse_metrics(const auparse_state_t *au)
791790 char * metrics ;
792791 unsigned int uid , gid ;
793792
794- aulookup_metrics (& uid , & gid );
793+ aulookup_metrics (au , & uid , & gid );
795794
796795 if (asprintf (& metrics ,
797796 "max lol available: %lu\n"
@@ -1038,7 +1037,7 @@ static void auparse_destroy_common(auparse_state_t *au)
10381037 fclose (au -> in );
10391038 au -> in = NULL ;
10401039 }
1041- free_interpretation_list ();
1040+ free_interpretation_list (au );
10421041 clear_normalizer (& au -> norm_data );
10431042 au_lol_clear (au -> au_lo , 0 );
10441043 free ((void * )au -> tmp_translation );
@@ -1048,8 +1047,8 @@ static void auparse_destroy_common(auparse_state_t *au)
10481047
10491048void auparse_destroy (auparse_state_t * au )
10501049{
1051- _aulookup_destroy_uid_list ();
1052- aulookup_destroy_gid_list ();
1050+ _aulookup_destroy_uid_list (au );
1051+ aulookup_destroy_gid_list (au );
10531052
10541053 auparse_destroy_common (au );
10551054}
@@ -1551,8 +1550,8 @@ static int au_auparse_next_event(auparse_state_t *au)
15511550
15521551 aup_list_first (l );
15531552 r = aup_list_get_cur (l );
1554- free_interpretation_list ();
1555- load_interpretation_list (r -> interp );
1553+ free_interpretation_list (au );
1554+ load_interpretation_list (au , r -> interp );
15561555 aup_list_first_field (l );
15571556 au -> le = l ;
15581557#ifdef LOL_EVENTS_DEBUG01
@@ -1603,8 +1602,8 @@ static int au_auparse_next_event(auparse_state_t *au)
16031602
16041603 aup_list_first (l );
16051604 r = aup_list_get_cur (l );
1606- free_interpretation_list ();
1607- load_interpretation_list (r -> interp );
1605+ free_interpretation_list (au );
1606+ load_interpretation_list (au , r -> interp );
16081607 aup_list_first_field (l );
16091608 au -> le = l ;
16101609#ifdef LOL_EVENTS_DEBUG01
@@ -1707,8 +1706,8 @@ static int au_auparse_next_event(auparse_state_t *au)
17071706
17081707 aup_list_first (l );
17091708 r = aup_list_get_cur (l );
1710- free_interpretation_list ();
1711- load_interpretation_list (r -> interp );
1709+ free_interpretation_list (au );
1710+ load_interpretation_list (au , r -> interp );
17121711 aup_list_first_field (l );
17131712 au -> le = l ;
17141713#ifdef LOL_EVENTS_DEBUG01
@@ -1842,7 +1841,7 @@ int auparse_first_record(auparse_state_t *au)
18421841 return rc ;
18431842 }
18441843 r = aup_list_get_cur (au -> le );
1845- if (r && r -> item == 0 && interpretation_list_cnt ()) {
1844+ if (r && r -> item == 0 && interpretation_list_cnt (au )) {
18461845 // If we are on the first record and the list has previously
18471846 // been loaded, just pull cursor back and avoid loading the
18481847 // interpretation list.
@@ -1851,8 +1850,8 @@ int auparse_first_record(auparse_state_t *au)
18511850 }
18521851 aup_list_first (au -> le );
18531852 r = aup_list_get_cur (au -> le );
1854- free_interpretation_list ();
1855- load_interpretation_list (r -> interp );
1853+ free_interpretation_list (au );
1854+ load_interpretation_list (au , r -> interp );
18561855 aup_list_first_field (au -> le );
18571856
18581857 return 1 ;
@@ -1867,7 +1866,7 @@ int auparse_next_record(auparse_state_t *au)
18671866{
18681867 rnode * r ;
18691868
1870- free_interpretation_list ();
1869+ free_interpretation_list (au );
18711870 // Its OK if au->le == NULL because get_cnt handles it
18721871 if (aup_list_get_cnt (au -> le ) == 0 ) {
18731872 int rc = auparse_first_record (au );
@@ -1876,19 +1875,19 @@ int auparse_next_record(auparse_state_t *au)
18761875 }
18771876 r = aup_list_next (au -> le );
18781877 if (r ) {
1879- load_interpretation_list (r -> interp );
1878+ load_interpretation_list (au , r -> interp );
18801879 return 1 ;
18811880 } else
18821881 return 0 ;
18831882}
18841883
18851884
1886- int auparse_goto_record_num (const auparse_state_t * au , unsigned int num )
1885+ int auparse_goto_record_num (auparse_state_t * au , unsigned int num )
18871886{
18881887 rnode * r ;
18891888
18901889 r = aup_list_get_cur (au -> le );
1891- if (r && r -> item == num && interpretation_list_cnt ()) {
1890+ if (r && r -> item == num && interpretation_list_cnt (au )) {
18921891 // If we are on the first record and the list has previously
18931892 // been loaded, just pull cursor back and avoid loading the
18941893 // interpretation list.
@@ -1897,14 +1896,15 @@ int auparse_goto_record_num(const auparse_state_t *au, unsigned int num)
18971896 }
18981897
18991898 /* Check if a request is out of range */
1900- free_interpretation_list ();
1899+ free_interpretation_list (au );
1900+
19011901 // Its OK if au->le == NULL because get_cnt handles it
19021902 if (num >= aup_list_get_cnt (au -> le ))
19031903 return 0 ;
19041904
19051905 r = aup_list_goto_rec (au -> le , num );
19061906 if (r != NULL ) {
1907- load_interpretation_list (r -> interp );
1907+ load_interpretation_list (au , r -> interp );
19081908 aup_list_first_field (au -> le );
19091909 return 1 ;
19101910 } else
@@ -2065,7 +2065,7 @@ const char *auparse_find_field(auparse_state_t *au, const char *name)
20652065}
20662066
20672067/* Increment 1 location and then scan for next field */
2068- const char * auparse_find_field_next (const auparse_state_t * au )
2068+ const char * auparse_find_field_next (auparse_state_t * au )
20692069{
20702070 if (au -> le == NULL )
20712071 return NULL ;
@@ -2089,8 +2089,8 @@ const char *auparse_find_field_next(const auparse_state_t *au)
20892089 r = aup_list_next (au -> le );
20902090 if (r ) {
20912091 aup_list_first_field (au -> le );
2092- free_interpretation_list ();
2093- load_interpretation_list (r -> interp );
2092+ free_interpretation_list (au );
2093+ load_interpretation_list (au , r -> interp );
20942094 }
20952095 }
20962096 }
@@ -2193,7 +2193,7 @@ const char *auparse_interpret_field(auparse_state_t *au)
21932193 rnode * r = aup_list_get_cur (au -> le );
21942194 if (r ) {
21952195 r -> cwd = NULL ;
2196- return nvlist_interp_cur_val (r , au -> escape_mode );
2196+ return nvlist_interp_cur_val (au , r );
21972197 }
21982198 }
21992199 return NULL ;
@@ -2213,7 +2213,7 @@ const char *auparse_interpret_realpath(const auparse_state_t *au)
22132213
22142214 // Tell it to make a realpath
22152215 r -> cwd = au -> le -> cwd ;
2216- return nvlist_interp_cur_val (r , au -> escape_mode );
2216+ return nvlist_interp_cur_val (( auparse_state_t * ) au , r );
22172217 }
22182218 }
22192219 return NULL ;
@@ -2233,7 +2233,7 @@ static const char *auparse_interpret_sock_parts(auparse_state_t *au,
22332233 if (nvlist_get_cur_type (r ) != AUPARSE_TYPE_SOCKADDR )
22342234 return NULL ;
22352235 // Get interpretation
2236- const char * val = nvlist_interp_cur_val (r , au -> escape_mode );
2236+ const char * val = nvlist_interp_cur_val (( auparse_state_t * ) au , r );
22372237 if (val == NULL )
22382238 return NULL ;
22392239 // make a copy since we modify it
0 commit comments