Debian Codegraph @

src/DS/public/scap_ds.h

raw symbols SCIP
1 /**
2 * @addtogroup DS
3 * @{
4 *
5 * @file scap_ds.h
6 * Open-scap Data Stream interface.
7 * @author Martin Preisler <[email protected]>
8 */
9
10 /*
11 * Copyright 2012--2014 Red Hat Inc., Durham, North Carolina.
12 * All Rights Reserved.
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 *
28 * Authors:
29 * Martin Preisler <[email protected]>
30 */
31
32 #ifndef OPENSCAP_DS_H
33 #define OPENSCAP_DS_H
34
35 #include "oscap.h"
36 #include "oscap_export.h"
37
38 /**
39 * @brief takes given xccdf file and constructs a source datastream
40 *
41 * @param xccdf_file
42 * Path to the XCCDF file that should be included in the datastream
43 * (including its dependencies).
44 *
45 * @param target_datastream
46 * ID of the datastream that should contain the XCCDF file. It will be
47 * the only datastream in the resulting data-stream-collection.
48 *
49 * @returns
50 * 0 if no errors were encountered
51 * -1 in case of errors
52 */
53 OSCAP_API int ds_sds_compose_from_xccdf(const char* xccdf_file, const char* target_datastream);
54
55 /**
56 * @brief append a new given component to the existing source datastream
57 *
58 * @param target_datastream
59 * Path of the existing source datastream into which the new component
60 * shall be added.
61 *
62 * @param datastream_id
63 * ID of the datastream into which the component shall be added.
64 * Null value indicates the very first datastream in the collection.
65 *
66 * @param new_component
67 * Path to the new component file (XCCDF, OVAL, or CPE Dictionary).
68 *
69 * @returns 0 in case of success
70 */
71 OSCAP_API int ds_sds_compose_add_component(const char *target_datastream, const char *datastream_id, const char *new_component, bool extended);
72
73 /**
74 * @brief takes given source data stream and XCCDF result file and makes a result data stream
75 *
76 * @param sds_file
77 * Path to the source data stream file that was used to generate the result XCCDF
78 *
79 * @param xccdf_result_file
80 * Contains xccdf:TestResult(s) and the embedded Benchmark (optionally).
81 * The embedded Benchmark (source data) will not be included in the result
82 * data stream, we will instead bundle the source data stream.
83 *
84 * @param oval_result_files
85 * NULL terminated list of paths to OVAL result files that should be bundled
86 * in the result data stream.
87 *
88 * @param target_file
89 * Path to the file where the result data stream will be stored
90 *
91 * @returns
92 * 0 if no errors were encountered
93 * -1 in case of errors
94 */
95 OSCAP_API int ds_rds_create(const char* sds_file, const char* xccdf_result_file,
96 const char** oval_result_files, const char* target_file);
97
98 /**
99 * @struct ds_stream_index
100 *
101 * Contains information about one particular "<data-stream>" element in
102 * the datastream collection (also called SDS = source datastream). Is
103 * contained inside ds_sds_index which indexes the entire datastream collection.
104 *
105 * Only contains IDs, does not contain the data of components themselves!
106 * See ds_sds_decompose for that.
107 *
108 * Inside it are components divided into categories called "containers".
109 * These are "checks", "checklists", "dictionaries" and "extended-components".
110 * See the specification for more details about their meaning.
111 *
112 * @see ds_sds_index
113 */
114 struct ds_stream_index;
115
116 /// @memberof ds_stream_index
117 OSCAP_API struct ds_stream_index* ds_stream_index_new(void);
118 /// @memberof ds_stream_index
119 OSCAP_API void ds_stream_index_free(struct ds_stream_index* s);
120
121 /**
122 * @brief Gets ID of the <data-stream> element the index represents.
123 *
124 * @memberof ds_stream_index
125 */
126 OSCAP_API const char* ds_stream_index_get_id(struct ds_stream_index* s);
127
128 /**
129 * @brief Timestamp of creation OR modification of the <data-stream> element the index represents.
130 *
131 * @memberof ds_stream_index
132 */
133 OSCAP_API const char* ds_stream_index_get_timestamp(struct ds_stream_index* s);
134
135 /**
136 * @brief scap-version of the the <data-stream> element the index represents.
137 *
138 * @memberof ds_stream_index
139 */
140 OSCAP_API const char* ds_stream_index_get_version(struct ds_stream_index* s);
141
142 /**
143 * @brief Retrieves iterator over all components inside the <checks> element.
144 *
145 * @memberof ds_stream_index
146 */
147 OSCAP_API struct oscap_string_iterator* ds_stream_index_get_checks(struct ds_stream_index* s);
148
149 /**
150 * @brief Retrieves iterator over all components inside the <checklists> element.
151 *
152 * @memberof ds_stream_index
153 */
154 OSCAP_API struct oscap_string_iterator* ds_stream_index_get_checklists(struct ds_stream_index* s);
155
156 /**
157 * @brief Retrieves iterator over all components inside the <dictionaries> element.
158 *
159 * @memberof ds_stream_index
160 */
161 OSCAP_API struct oscap_string_iterator* ds_stream_index_get_dictionaries(struct ds_stream_index* s);
162
163 /**
164 * @brief Retrieves iterator over all components inside the <extended-components> element.
165 *
166 * @memberof ds_stream_index
167 */
168
169 /**
170 * @struct ds_sds_index
171 *
172 * Represents <data-stream-collection> element - the root element of each
173 * source datastream. Its purpose is to provide IDs and other metadata.
174 *
175 * Contains a list of ds_stream_index structures, each representing one
176 * data-stream inside the collection.
177 *
178 * @see ds_stream_index
179 */
180 struct ds_sds_index;
181
182 /// @memberof ds_sds_index
183 OSCAP_API struct ds_sds_index* ds_sds_index_new(void);
184 /// @memberof ds_sds_index
185 OSCAP_API void ds_sds_index_free(struct ds_sds_index* s);
186
187 /**
188 * @brief retrieves a stream index by data-stream ID
189 *
190 * @memberof ds_sds_index
191 */
192 OSCAP_API struct ds_stream_index* ds_sds_index_get_stream(struct ds_sds_index* s, const char* stream_id);
193
194 /**
195 * @brief retrieves all streams indexed inside this structure
196 *
197 * @memberof ds_sds_index
198 */
199 OSCAP_API struct ds_stream_index_iterator* ds_sds_index_get_streams(struct ds_sds_index* s);
200
201 /**
202 * @brief chooses datastream and checklist id combination given the IDs
203 *
204 * @param datastream_id has to point to an allocated char*, selected datastream ID will be filled into it
205 * @param component_id has to point to an allocated char*, selected xccdf ID will be filled into it
206 *
207 * datastream_id and component_id must not point to the same memory! However,
208 * the pointers pointed to may be NULL (which means any ID will do).
209 *
210 * component_id is actually a component-ref ID, the reason is that we need the component-ref
211 * to know which other components are in the catalog and thus needed when splitting.
212 */
213 OSCAP_API int ds_sds_index_select_checklist(struct ds_sds_index* s,
214 const char** datastream_id, const char** component_id);
215
216 /**
217 * @brief chooses datastream and checklist component ref ID combination, given benchmark ID
218 *
219 * @param benchmark_id Which XCCDF Benchmark ID are we looking for?
220 * Parameters are similar to ds_sds_index_select_checklist, except for benchmark_id.
221 * @see ds_sds_index_select_checklist
222 *
223 * This function looks through to datastream index to find the first component-ref (top-down)
224 * which satisfies the following condition:
225 * "it does point to a component which contains XCCDF Benchmark with id
226 * exactly the same as given benchmark_id".
227 *
228 * Please note that datastream_id AND component_ref_id are pointers to pointers and they
229 * will be overwritten if 0 is returned. The values are never used, unlike with
230 * ds_sds_index_select_checklist.
231 */
232 OSCAP_API int ds_sds_index_select_checklist_by_benchmark_id(struct ds_sds_index* s,
233 const char *benchmark_id, const char **datastream_id, const char **component_ref_id);
234
235 /**
236 * @struct ds_stream_index_iterator
237 * @see oscap_iterator
238 */
239 struct ds_stream_index_iterator;
240
241 /// @memberof ds_stream_index_iterator
242 OSCAP_API struct ds_stream_index *ds_stream_index_iterator_next(struct ds_stream_index_iterator *it);
243 /// @memberof ds_stream_index_iterator
244 OSCAP_API bool ds_stream_index_iterator_has_more(struct ds_stream_index_iterator *it);
245 /// @memberof ds_stream_index_iterator
246 OSCAP_API void ds_stream_index_iterator_free(struct ds_stream_index_iterator *it);
247
248 /**
249 * @struct rds_report_request_index
250 */
251 struct rds_report_request_index;
252
253 OSCAP_API struct rds_report_request_index* rds_report_request_index_new(void);
254 OSCAP_API void rds_report_request_index_free(struct rds_report_request_index* s);
255 OSCAP_API const char* rds_report_request_index_get_id(struct rds_report_request_index* s);
256
257 /**
258 * @struct rds_asset_index
259 */
260 struct rds_asset_index;
261
262 /**
263 * @struct rds_report_index
264 */
265 struct rds_report_index;
266
267 OSCAP_API struct rds_asset_index* rds_asset_index_new(void);
268 OSCAP_API void rds_asset_index_free(struct rds_asset_index* s);
269 OSCAP_API const char* rds_asset_index_get_id(struct rds_asset_index* s);
270 OSCAP_API void rds_asset_index_add_report_ref(struct rds_asset_index* s, struct rds_report_index* report);
271 OSCAP_API struct rds_report_index_iterator* rds_asset_index_get_reports(struct rds_asset_index* s);
272
273 OSCAP_API struct rds_report_index* rds_report_index_new(void);
274 OSCAP_API void rds_report_index_free(struct rds_report_index* s);
275 OSCAP_API const char* rds_report_index_get_id(struct rds_report_index* s);
276 OSCAP_API void rds_report_index_set_request(struct rds_report_index* s, struct rds_report_request_index *request);
277 OSCAP_API struct rds_report_request_index *rds_report_index_get_request(struct rds_report_index* s);
278
279 /**
280 * @struct rds_report_request_index_iterator
281 * @see oscap_iterator
282 */
283 struct rds_report_request_index_iterator;
284
285 /// @memberof rds_report_request_index_iterator
286 OSCAP_API struct rds_report_request_index *rds_report_request_index_iterator_next(struct rds_report_request_index_iterator *it);
287 /// @memberof rds_report_request_index_iterator
288 OSCAP_API bool rds_report_request_index_iterator_has_more(struct rds_report_request_index_iterator *it);
289 /// @memberof rds_report_request_index_iterator
290 OSCAP_API void rds_report_request_index_iterator_free(struct rds_report_request_index_iterator *it);
291
292 /**
293 * @struct rds_asset_index_iterator
294 * @see oscap_iterator
295 */
296 struct rds_asset_index_iterator;
297
298 /// @memberof rds_asset_index_iterator
299 OSCAP_API struct rds_asset_index *rds_asset_index_iterator_next(struct rds_asset_index_iterator *it);
300 /// @memberof rds_asset_index_iterator
301 OSCAP_API bool rds_asset_index_iterator_has_more(struct rds_asset_index_iterator *it);
302 /// @memberof rds_asset_index_iterator
303 OSCAP_API void rds_asset_index_iterator_free(struct rds_asset_index_iterator *it);
304
305 /**
306 * @struct rds_report_index_iterator
307 * @see oscap_iterator
308 */
309 struct rds_report_index_iterator;
310
311 /// @memberof rds_report_index_iterator
312 OSCAP_API struct rds_report_index *rds_report_index_iterator_next(struct rds_report_index_iterator *it);
313 /// @memberof rds_report_index_iterator
314 OSCAP_API bool rds_report_index_iterator_has_more(struct rds_report_index_iterator *it);
315 /// @memberof rds_report_index_iterator
316 OSCAP_API void rds_report_index_iterator_free(struct rds_report_index_iterator *it);
317
318 /**
319 * @struct rds_index
320 *
321 * Represents <asset-report-collection> element - the root element of each
322 * result datastream in Asset Reporting Format = ARF.
323 *
324 * Indexes assets and report-requests.
325 */
326 struct rds_index;
327
328 /// @memberof rds_index
329 OSCAP_API struct rds_index* rds_index_new(void);
330 /// @memberof rds_index
331 OSCAP_API void rds_index_free(struct rds_index *s);
332
333 /// @memberof rds_index
334 OSCAP_API struct rds_report_request_index_iterator *rds_index_get_report_requests(struct rds_index *s);
335 /// @memberof rds_index
336 OSCAP_API struct rds_asset_index_iterator *rds_index_get_assets(struct rds_index *s);
337 /// @memberof rds_index
338 OSCAP_API struct rds_report_index_iterator *rds_index_get_reports(struct rds_index *s);
339
340 /// @memberof rds_index
341 OSCAP_API struct rds_report_request_index *rds_index_get_report_request(struct rds_index *rds, const char *id);
342 /// @memberof rds_index
343 OSCAP_API struct rds_asset_index *rds_index_get_asset(struct rds_index *rds, const char *id);
344 /// @memberof rds_index
345 OSCAP_API struct rds_report_index *rds_index_get_report(struct rds_index *rds, const char *id);
346 /// @memberof rds_index
347 OSCAP_API int rds_index_select_report(struct rds_index *s, const char **report_id);
348
349 /************************************************************/
350 /** @} End of DS group */
351
352 #endif