Debian Codegraph @

src/OVAL/probes/public/probe-api.h

raw symbols SCIP
1 /**
2 * @file probe-api.h
3 * @brief Probe API public header
4 * @author "Daniel Kopecek" <[email protected]>
5 * @author "Tomas Heinrich" <[email protected]>
6 *
7 * @addtogroup PROBEAPI
8 * This file contains functions for manipulating with the S-exp representation
9 * of OVAL objects and items. Currently object and items have the same structure
10 * and the API distinction is just formal. However, the structure can diverge in
11 * the future and the API functions for manipulating with items should be used
12 * only with items and vice versa. The most recent description of the object and
13 * item structure can be found in this file and should be used as the main source
14 * of information for implementing new API functions. In the following text, the
15 * term `element' referers to the general structure which is used to represent
16 * the various components of an OVAL document, particularly the OVAL objects,
17 * items and entities.
18 *
19 * \paragraph Element structure
20 * The basic structure of an element looks like this:\n
21 * \n
22 * (foo_object bar)\n
23 * \n
24 * \em foo_object is the element name and \em bar is the value of the element. There
25 * can be 0 to n values. In case the element has some attributes set the structure
26 * changes to:\n
27 * \n
28 * ((foo_object :attr1 val1) bar)\n
29 * \n
30 * where \em attr1 is the name of the attribute and \em val1 is the attribute's value.
31 * The colon in the attribute name signals that the attribute has a value.
32 *
33 * @{
34 */
35 /*
36 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
37 * All Rights Reserved.
38 *
39 * This library is free software; you can redistribute it and/or
40 * modify it under the terms of the GNU Lesser General Public
41 * License as published by the Free Software Foundation; either
42 * version 2.1 of the License, or (at your option) any later version.
43 *
44 * This library is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47 * Lesser General Public License for more details.
48 *
49 * You should have received a copy of the GNU Lesser General Public
50 * License along with this library; if not, write to the Free Software
51 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
52 *
53 * Authors:
54 * Daniel Kopecek <[email protected]>
55 */
56
57 #pragma once
58 #ifndef PROBE_API_H
59 #define PROBE_API_H
60
61 #include <stdarg.h>
62 #include <stdint.h>
63 #include <stdbool.h>
64 #include <pthread.h>
65 #include <oval_definitions.h>
66 #include <oval_system_characteristics.h>
67 #include <oval_results.h>
68 #include <oval_types.h>
69 #include "sexp-types.h"
70 #include "oscap_export.h"
71 #include "list.h"
72
73 /*
74 * items
75 */
76
77 /**
78 * Create a new item consisting of a name, optional attributes argument and an arbitrary number of entities.
79 * Every entity is a triple:
80 * const char *name - name of the new entity
81 * SEXP_t attrs - optional list of entity attributes in a sexp, can be NULL
82 * SEXP_t val - value of the new entity in a sexp
83 * This function increments its SEXP_t arguments' reference count.
84 * @param name mandatory name argument
85 * @param attrs optional item's attributes argument
86 * @param ... arbitrary number of entity arguments
87 */
88 OSCAP_API SEXP_t *probe_item_creat(const char *name, SEXP_t * attrs, ...);
89
90 /**
91 * Create a new item with just a name and optional attributes argument.
92 * @param name item's name
93 * @param attrs optional attributes argument
94 */
95 OSCAP_API SEXP_t *probe_item_new(const char *name, SEXP_t * attrs);
96
97 /**
98 * Add a new attribute to an item.
99 * This function increments its val argument's reference count.
100 * @param item the item to be modified
101 * @param name name of the new attribute
102 * @param val value of the new attribute
103 */
104 OSCAP_API SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val);
105
106 /**
107 * Add a new entity to an item.
108 * This function increments its attrs and val arguments' reference count.
109 * @param item the item to be modified
110 * @param name name of the new entity
111 * @param attrs optional attributes of the new entity
112 * @param val value of the new entity
113 */
114 OSCAP_API SEXP_t *probe_item_ent_add(SEXP_t * item, const char *name, SEXP_t * attrs, SEXP_t * val);
115
116 /**
117 * Set item's status.
118 * @param obj the item to be modified
119 * @param status the new status
120 */
121 OSCAP_API int probe_item_setstatus(SEXP_t * obj, oval_syschar_status_t status);
122
123 /**
124 * Set status of an item's entity.
125 * @param obj the item to be modified
126 * @param name the name of the entity
127 * @param n select the n-th occurence of an entity with the specified name
128 * @param status the new status
129 */
130 OSCAP_API int probe_itement_setstatus(SEXP_t * obj, const char *name, uint32_t n, oval_syschar_status_t status);
131
132 /**
133 *
134 */
135 struct id_desc_t;
136
137 /**
138 * Reset the item id generator.
139 * @param id_desc pointer to a structure holding the global id context
140 */
141 OSCAP_API void probe_item_resetidctr(struct id_desc_t *id_desc);
142
143 #define probe_item_getent(item, name, n) probe_obj_getent (item, name, n)
144
145 /*
146 * attributes
147 */
148
149 /**
150 * Create a new list of attributes.
151 * This function increments its val argument's reference count.
152 * @param name the name of the attribute
153 * @param val the value of the attribute
154 * @param ... there can be an arbitrary number of name - value pairs
155 */
156 OSCAP_API SEXP_t *probe_attr_creat(const char *name, const SEXP_t * val, ...);
157
158 /*
159 * objects
160 */
161
162 /**
163 * Create a new object consisting of a name, optional attributes argument and an arbitrary number of entities.
164 * Every entity is a triple:
165 * const char *name - name of the new entity
166 * SEXP_t attrs - optional list of entity attributes in a sexp, can be NULL
167 * SEXP_t val - value of the new entity in a sexp
168 * This function increments its SEXP_t arguments' reference count.
169 * @param name mandatory name argument
170 * @param attrs optional object's attributes argument
171 * @param ... arbitrary number of entity arguments
172 */
173 OSCAP_API SEXP_t *probe_obj_creat(const char *name, SEXP_t * attrs, ...);
174
175 /**
176 * Create a new object with just a name and optional attributes argument.
177 * This function increments its SEXP_t argument's reference count.
178 * @param name object's name
179 * @param attrs optional attributes argument
180 */
181 OSCAP_API SEXP_t *probe_obj_new(const char *name, SEXP_t * attrs);
182
183 /**
184 * Get an entity from an object.
185 * @param obj the queried object
186 * @param name the name of the entity
187 * @param n select the n-th occurence of an entity with the specified name
188 */
189 OSCAP_API SEXP_t *probe_obj_getent(const SEXP_t * obj, const char *name, uint32_t n);
190
191 /**
192 * Get the value of an object's entity.
193 * The function respects the var_ref attribute and returns the currently selected value.
194 * @param obj the queried object
195 * @param name the name of the entity
196 * @param n select the n-th occurence of an entity with the specified name
197 */
198 OSCAP_API SEXP_t *probe_obj_getentval(const SEXP_t * obj, const char *name, uint32_t n);
199
200 /**
201 * Get the list of values of an object's entity.
202 * If the entity uses var_ref, there can be more than one value.
203 * @param obj the queried object
204 * @param name the name of the entity
205 * @param n select the n-th occurence of an entity with the specified name
206 * @param res the resulting value list is stored in this argument
207 * @return number of values in the list stored in the res argument
208 */
209 OSCAP_API int probe_obj_getentvals(const SEXP_t * obj, const char *name, uint32_t n, SEXP_t ** res);
210
211 /**
212 * Get the value of an object's attribute.
213 * @param obj the queried object
214 * @param name the name of the attribute
215 */
216 OSCAP_API SEXP_t *probe_obj_getattrval(const SEXP_t * obj, const char *name);
217
218 /**
219 * Check whether the specified attribute exists.
220 * @param obj the queried object
221 * @param name the name of the attribute
222 */
223 OSCAP_API bool probe_obj_attrexists(const SEXP_t * obj, const char *name);
224
225 /**
226 * Set objects's status.
227 * @param obj the object to be modified
228 * @param status the new status
229 */
230 OSCAP_API int probe_obj_setstatus(SEXP_t * obj, oval_syschar_status_t status);
231
232 /**
233 * Get the name of an object.
234 * @param obj the queried object
235 */
236 OSCAP_API char *probe_obj_getname(const SEXP_t * obj);
237
238 /**
239 * Get the name of an object.
240 * The name is stored in the provided buffer.
241 * @param obj the queried object
242 * @param buffer the buffer to store the name in
243 * @param buflen the length of the buffer
244 */
245 OSCAP_API size_t probe_obj_getname_r(const SEXP_t * obj, char *buffer, size_t buflen);
246
247 /*
248 * collected objects
249 */
250
251 OSCAP_API SEXP_t *probe_cobj_new(oval_syschar_collection_flag_t flag, SEXP_t *msg_list, SEXP_t *item_list, SEXP_t *mask_list);
252 OSCAP_API int probe_cobj_add_msg(SEXP_t *cobj, const SEXP_t *msg);
253 OSCAP_API SEXP_t *probe_cobj_get_msgs(const SEXP_t *cobj);
254 OSCAP_API SEXP_t *probe_cobj_get_mask(const SEXP_t *cobj);
255 OSCAP_API int probe_cobj_add_item(SEXP_t *cobj, const SEXP_t *item);
256 OSCAP_API SEXP_t *probe_cobj_get_items(const SEXP_t *cobj);
257 OSCAP_API void probe_cobj_set_flag(SEXP_t *cobj, oval_syschar_collection_flag_t flag);
258 OSCAP_API oval_syschar_collection_flag_t probe_cobj_get_flag(const SEXP_t *cobj);
259 oval_syschar_collection_flag_t probe_cobj_combine_flags(oval_syschar_collection_flag_t f1,
260 oval_syschar_collection_flag_t f2,
261 oval_setobject_operation_t op);
262 OSCAP_API oval_syschar_collection_flag_t probe_cobj_compute_flag(SEXP_t *cobj);
263
264 /*
265 * messages
266 */
267
268 /**
269 * Create a new message that can be added to a collected object.
270 * @param level the level associated with the new message
271 * @param message the text of the new message
272 */
273 OSCAP_API SEXP_t *probe_msg_creat(oval_message_level_t level, char *message);
274
275 /**
276 * Create a new message that can be added to a collected object.
277 * @param level the level associated with the new message
278 * @param fmt printf-like format string that produces the text of the new message
279 * @param ... arguments for the format
280 */
281 OSCAP_API SEXP_t *probe_msg_creatf(oval_message_level_t level, const char *fmt, ...) __attribute__((format(printf, 2, 3), nonnull(2)));
282
283 /*
284 * entities
285 */
286
287 /**
288 * Create a new list of entities.
289 * This function increments its SEXP_t arguments' reference count.
290 * @param name the name of the entity
291 * @param attrs optional entity's attributes argument
292 * @param val the value of the entity
293 * @param ... there can be an arbitrary number of name - attributes - value triples
294 */
295 OSCAP_API SEXP_t *probe_ent_creat(const char *name, SEXP_t * attrs, SEXP_t * val, ...);
296
297 /**
298 * Create a new entity.
299 * This function increments its SEXP_t arguments' reference count.
300 * @param name the name of the entity
301 * @param attrs optional entity's attributes argument
302 * @param val the value of the entity
303 */
304 OSCAP_API SEXP_t *probe_ent_creat1(const char *name, SEXP_t * attrs, SEXP_t * val);
305
306 /**
307 * Add a new attribute to an entity.
308 * This function increments its val argument's reference count.
309 * @param ent the entity to be modified
310 * @param name name of the new attribute
311 * @param val value of the new attribute
312 */
313 OSCAP_API SEXP_t *probe_ent_attr_add(SEXP_t * ent, const char *name, SEXP_t * val);
314
315 /**
316 * Get the value of an entity.
317 * The function respects the var_ref attribute and returns the currently selected value.
318 * @param ent the queried entity
319 */
320 OSCAP_API SEXP_t *probe_ent_getval(const SEXP_t * ent);
321
322 /**
323 * Get the list of values of an entity.
324 * If the entity uses var_ref, there can be more than one value.
325 * @param ent the queried entity
326 * @param res the resulting value list is stored in this argument
327 * @return number of values in the list stored in the res argument
328 */
329 OSCAP_API int probe_ent_getvals(const SEXP_t * ent, SEXP_t ** res);
330
331 /**
332 * Get the value of an entity's attribute.
333 * @param ent the queried entity
334 * @param name the name of the attribute
335 */
336 OSCAP_API SEXP_t *probe_ent_getattrval(const SEXP_t * ent, const char *name);
337
338 /**
339 * Check whether the specified attribute exists.
340 * @param ent the queried entity
341 * @param name the name of the attribute
342 */
343 OSCAP_API bool probe_ent_attrexists(const SEXP_t * ent, const char *name);
344
345 /**
346 * Set the OVAL data type of an entity.
347 * @param ent the queried entity
348 * @param type the new data type
349 */
350 OSCAP_API int probe_ent_setdatatype(SEXP_t * ent, oval_datatype_t type);
351
352 /**
353 * Get the OVAL data type of an entity.
354 * @param ent the queried entity
355 */
356 OSCAP_API oval_datatype_t probe_ent_getdatatype(const SEXP_t * ent);
357
358 /**
359 * Set entity's mask.
360 * @param ent the queried entity
361 * @mask the new mask
362 */
363 OSCAP_API int probe_ent_setmask(SEXP_t * ent, bool mask);
364
365 /**
366 * Get entity's mask.
367 * @param ent the queried entity
368 */
369 OSCAP_API bool probe_ent_getmask(const SEXP_t * ent);
370
371 /**
372 * Set entity's status.
373 * @param ent the entity to be modified
374 * @param status the new status
375 */
376 OSCAP_API int probe_ent_setstatus(SEXP_t * ent, oval_syschar_status_t status);
377
378 /**
379 * Get entity status.
380 * @param ent the queried entity
381 */
382 OSCAP_API oval_syschar_status_t probe_ent_getstatus(const SEXP_t * ent);
383
384 /**
385 * Get the name of an entity.
386 * @param ent the queried entity
387 */
388 OSCAP_API char *probe_ent_getname(const SEXP_t * ent);
389
390 /**
391 * Get the name of an entity.
392 * The name is stored in the provided buffer.
393 * @param ent the queried entity
394 * @param buffer the buffer to store the name in
395 * @param buflen the length of the buffer
396 */
397 OSCAP_API size_t probe_ent_getname_r(const SEXP_t * ent, char *buffer, size_t buflen);
398
399 /**
400 * Free the memory allocated by the probe_* functions.
401 * @param obj the object to be freed
402 */
403 OSCAP_API void probe_free(SEXP_t * obj);
404
405 /**
406 * Set all of the missing attributes of the 'behaviors' entity
407 * to default values. If the referenced pointer contains NULL,
408 * a new entity is created and stored in the referenced pointer.
409 * @param behaviors address of the pointer to the 'behaviors' entity, must not be NULL
410 */
411 OSCAP_API void probe_filebehaviors_canonicalize(SEXP_t **behaviors);
412
413 /**
414 * Set all of the missing attributes of the 'behaviors' entity
415 * to default values. If the referenced pointer contains NULL,
416 * a new entity is created and stored in the referenced pointer.
417 * @param behaviors address of the pointer to the 'behaviors' entity, must not be NULL
418 */
419 OSCAP_API void probe_tfc54behaviors_canonicalize(SEXP_t **behaviors);
420
421 #define PROBE_EINVAL 1 /**< Invalid type/value/format */
422 #define PROBE_ENOELM 2 /**< Missing element OBSOLETE: use ENOENT */
423 #define PROBE_ENOVAL 3 /**< Missing value */
424 #define PROBE_ENOATTR 4 /**< Missing attribute */
425 #define PROBE_EINIT 5 /**< Initialization failed */
426 #define PROBE_ENOMEM 6 /**< No memory */
427 #define PROBE_EOPNOTSUPP 7 /**< Not supported */
428 #define PROBE_ERANGE 8 /**< Out of range */
429 #define PROBE_EDOM 9 /**< Out of domain */
430 #define PROBE_EFAULT 10 /**< Memory fault/NULL value */
431 #define PROBE_EACCESS 11 /**< Operation not permitted */
432 #define PROBE_ESETEVAL 12 /**< Set evaluation failed */
433 #define PROBE_ENOENT 13 /**< Missing entity */
434 #define PROBE_ENOOBJ 14 /**< Missing object */
435 #define PROBE_ECONNABORTED 15 /**< Evaluation aborted */
436 #define PROBE_ESYSTEM 253 /**< System call failure */
437 #define PROBE_EFATAL 254 /**< Unrecoverable error */
438 #define PROBE_EUNKNOWN 255 /**< Unknown/Unexpected error */
439
440 #define PROBECMD_STE_FETCH 1 /**< State fetch command code */
441 #define PROBECMD_OBJ_EVAL 2 /**< Object eval command code */
442 #define PROBECMD_RESET 3 /**< Reset command code */
443
444 typedef struct probe_ctx probe_ctx;
445
446 OSCAP_API bool probe_item_filtered(const SEXP_t *item, const SEXP_t *filters);
447
448 /**
449 * Collect generated item (i.e. add it to the collected object)
450 * The function takes ownership of the item reference and takes
451 * care of freeing the item (i.e. don't call SEXP_free(item) after
452 * calling this function). The implementation of this function
453 * is placed in the `probe/icache.c' file.
454 */
455 OSCAP_API int probe_item_collect(probe_ctx *ctx, SEXP_t *item);
456
457 /**
458 * Return reference to the input object. The reference counter
459 * is NOT incremented by this operation (i.e. don't call SEXP_free
460 * on the return value of this function). Implementation of this
461 * function is placed in the `' file.
462 */
463 OSCAP_API SEXP_t *probe_ctx_getobject(probe_ctx *ctx);
464
465 /**
466 * Return reference to the output object (aka collected object).
467 * Reference counter is NOT incremented (see the description of
468 * probe_ctx_getobject above).
469 */
470 OSCAP_API SEXP_t *probe_ctx_getresult(probe_ctx *ctx);
471
472 typedef struct {
473 oval_datatype_t type;
474 void *value;
475 } probe_elmatr_t;
476
477 OSCAP_API SEXP_t *probe_item_create(oval_subtype_t item_subtype, probe_elmatr_t *item_attributes[], ...);
478
479 #define PROBE_ENT_AREF(ent, dst, attr_name, invalid_exp) \
480 do { \
481 if (((dst) = probe_ent_getattrval(ent, attr_name)) == NULL) { \
482 dE("Attribute `%s' is missing!", attr_name); \
483 invalid_exp \
484 } \
485 } while(0)
486
487 #define PROBE_ENT_STRVAL(ent, dst, dstlen, invalid_exp, zerolen_exp) \
488 do { \
489 SEXP_t *___r; \
490 \
491 if ((___r = probe_ent_getval(ent)) == NULL) { \
492 invalid_exp \
493 } else { \
494 if (!SEXP_stringp(___r)) { \
495 SEXP_free(___r); \
496 invalid_exp \
497 } \
498 else if (SEXP_string_length(___r) == 0) { \
499 SEXP_free(___r); \
500 zerolen_exp \
501 } else { \
502 SEXP_string_cstr_r(___r, dst, dstlen); \
503 SEXP_free(___r); \
504 } \
505 } \
506 } while (0)
507
508 #define PROBE_ENT_I32VAL(ent, dst, invalid_exp, nil_exp) \
509 do { \
510 SEXP_t *___r; \
511 \
512 if ((___r = probe_ent_getval(ent)) == NULL) { \
513 nil_exp; \
514 } else { \
515 if (!SEXP_numberp(___r)) { \
516 SEXP_free(___r); \
517 invalid_exp; \
518 } else { \
519 dst = SEXP_number_geti_32(___r); \
520 SEXP_free(___r); \
521 } \
522 } \
523 } while (0)
524
525 #endif /* PROBE_API_H */
526
527 OSCAP_API oval_operation_t probe_ent_getoperation(SEXP_t *entity, oval_operation_t op);
528
529 OSCAP_API int probe_item_add_msg(SEXP_t *item, oval_message_level_t msglvl, char *msgfmt, ...);
530
531 OSCAP_API SEXP_t *probe_entval_from_cstr(oval_datatype_t type, const char *value, size_t vallen);
532 OSCAP_API SEXP_t *probe_ent_from_cstr(const char *name, oval_datatype_t type, const char *value, size_t vallen);
533
534 OSCAP_API oval_schema_version_t probe_obj_get_platform_schema_version(const SEXP_t *obj);
535
536 /**
537 * Get object entity mask
538 * @returns a list of masked entities
539 */
540 OSCAP_API SEXP_t *probe_obj_getmask(SEXP_t *obj);
541
542 /**
543 * Check if the given path matches any of the paths in the blocked paths list
544 * @param path path to be examined
545 * @param blocked_paths list of blocked paths
546 */
547 OSCAP_API bool probe_path_is_blocked(const char *path, struct oscap_list *blocked_paths);
548
549 /// @}