32
32
#include "sexp-manip.h"
33
33
#include "debug_priv.h"
34
34
#include "oval_fts.h"
35
+ #include "list.h"
35
36
36
37
37
- static int yaml_path_query (const char * filepath , const char * yaml_path_cstr , unsigned char * output_buffer , size_t output_buffer_size , probe_ctx * ctx )
38
+ static int yaml_path_query (const char * filepath , const char * yaml_path_cstr , struct oscap_list * values , probe_ctx * ctx )
38
39
{
39
40
int ret = 0 ;
40
41
FILE * yaml_file = fopen (filepath , "r" );
@@ -63,17 +64,9 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, uns
63
64
yaml_parser_initialize (& parser );
64
65
yaml_parser_set_input_file (& parser , yaml_file );
65
66
66
- yaml_emitter_t emitter ;
67
- yaml_emitter_initialize (& emitter );
68
- size_t size_written ;
69
- yaml_emitter_set_output_string (& emitter ,
70
- output_buffer , output_buffer_size , & size_written );
71
- yaml_emitter_set_width (& emitter , -1 );
72
-
73
67
yaml_event_t event ;
74
- bool done = false;
75
-
76
68
bool sequence = false;
69
+
77
70
do {
78
71
if (!yaml_parser_parse (& parser , & event )) {
79
72
SEXP_t * msg = probe_msg_creatf (OVAL_MESSAGE_LEVEL_ERROR ,
@@ -85,7 +78,6 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, uns
85
78
ret = -1 ;
86
79
goto cleanup ;
87
80
}
88
- done = (event .type == YAML_STREAM_END_EVENT );
89
81
if (!yaml_path_filter_event (yaml_path , & parser , & event ,
90
82
YAML_PATH_FILTER_RETURN_ALL )) {
91
83
yaml_event_delete (& event );
@@ -120,27 +112,13 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, uns
120
112
goto cleanup ;
121
113
}
122
114
}
123
-
124
- if (!yaml_emitter_emit (& emitter , & event )) {
125
- SEXP_t * msg = probe_msg_creatf (OVAL_MESSAGE_LEVEL_ERROR ,
126
- "YAML emitter error: yaml_emitter_emit returned 0: %s" ,
127
- emitter .problem );
128
- probe_cobj_add_msg (probe_ctx_getresult (ctx ), msg );
129
- SEXP_free (msg );
130
- probe_cobj_set_flag (probe_ctx_getresult (ctx ), SYSCHAR_FLAG_ERROR );
131
- ret = -1 ;
132
- goto cleanup ;
133
- }
134
-
135
- } while (!done );
136
-
137
- /* string output_buffer contains '\n' at the end */
138
- output_buffer [size_written - 1 ] = '\0' ;
115
+ if (event .type == YAML_SCALAR_EVENT ) {
116
+ oscap_list_add (values , (void * ) strdup ((const char * ) event .data .scalar .value ));
117
+ }
118
+ } while (event .type != YAML_STREAM_END_EVENT );
139
119
140
120
cleanup :
141
121
yaml_parser_delete (& parser );
142
- yaml_emitter_delete (& emitter );
143
-
144
122
yaml_path_destroy (yaml_path );
145
123
fclose (yaml_file );
146
124
@@ -151,34 +129,37 @@ static int process_yaml_file(const char *path, const char *filename, const char
151
129
{
152
130
int ret = 0 ;
153
131
char * filepath = oscap_path_join (path , filename );
132
+ struct oscap_list * values = oscap_list_new ();
154
133
155
- size_t output_buffer_size = 1024 ;
156
- unsigned char * output_buffer = calloc (output_buffer_size , sizeof (unsigned char ));
157
-
158
- if (yaml_path_query (filepath , yamlpath , output_buffer , output_buffer_size , ctx )) {
134
+ if (yaml_path_query (filepath , yamlpath , values , ctx )) {
159
135
ret = -1 ;
160
136
goto cleanup ;
161
137
}
162
138
163
- /* TODO: type conversion of output_buffer data */
164
-
165
- SEXP_t * item = probe_item_create (
166
- OVAL_INDEPENDENT_YAML_FILE_CONTENT ,
167
- NULL ,
168
- "filepath" , OVAL_DATATYPE_STRING , filepath ,
169
- "path" , OVAL_DATATYPE_STRING , path ,
170
- "filename" , OVAL_DATATYPE_STRING , filename ,
171
- "yamlpath" , OVAL_DATATYPE_STRING , yamlpath ,
172
- "value_of" , OVAL_DATATYPE_STRING , output_buffer ,
173
- /*
174
- "windows_view",
175
- */
176
- NULL
177
- );
178
- probe_item_collect (ctx , item );
139
+ struct oscap_iterator * values_it = oscap_iterator_new (values );
140
+ while (oscap_iterator_has_more (values_it )) {
141
+ char * value = oscap_iterator_next (values_it );
142
+ /* TODO: type conversion of 'value' data */
143
+
144
+ SEXP_t * item = probe_item_create (
145
+ OVAL_INDEPENDENT_YAML_FILE_CONTENT ,
146
+ NULL ,
147
+ "filepath" , OVAL_DATATYPE_STRING , filepath ,
148
+ "path" , OVAL_DATATYPE_STRING , path ,
149
+ "filename" , OVAL_DATATYPE_STRING , filename ,
150
+ "yamlpath" , OVAL_DATATYPE_STRING , yamlpath ,
151
+ "value_of" , OVAL_DATATYPE_STRING , value ,
152
+ /*
153
+ "windows_view",
154
+ */
155
+ NULL
156
+ );
157
+ probe_item_collect (ctx , item );
158
+ }
159
+ oscap_iterator_free (values_it );
179
160
180
161
cleanup :
181
- free ( output_buffer );
162
+ oscap_list_free ( values , free );
182
163
free (filepath );
183
164
return ret ;
184
165
}
0 commit comments