Open SCAP Library
probe-api.h
Go to the documentation of this file.
1 
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
52  *
53  * Authors:
54  * Daniel Kopecek <dkopecek@redhat.com>
55  */
56 
57 #pragma once
58 #ifndef PROBE_API_H
59 #define PROBE_API_H
60 
61 #include <seap.h>
62 #include <stdarg.h>
63 #include <stdint.h>
64 #include <stdbool.h>
65 #include <pthread.h>
66 #include <oval_definitions.h>
68 #include <oval_results.h>
69 #include <oval_types.h>
70 #include "oscap_export.h"
71 
72 /*
73  * items
74  */
75 
80 OSCAP_API SEXP_t *probe_item_build(const char *fmt, ...);
81 
82 /* SEXP_t *probe_item_creat (const char *name, SEXP_t *attrs, ...); */
94 OSCAP_API SEXP_t *probe_item_creat(const char *name, SEXP_t * attrs, ...);
95 
101 OSCAP_API SEXP_t *probe_item_new(const char *name, SEXP_t * attrs);
102 
110 OSCAP_API SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val);
111 
120 OSCAP_API SEXP_t *probe_item_ent_add(SEXP_t * item, const char *name, SEXP_t * attrs, SEXP_t * val);
121 
127 OSCAP_API int probe_item_setstatus(SEXP_t * obj, oval_syschar_status_t status);
128 
136 OSCAP_API int probe_itement_setstatus(SEXP_t * obj, const char *name, uint32_t n, oval_syschar_status_t status);
137 
141 struct id_desc_t;
142 
148 OSCAP_API SEXP_t *probe_item_newid(struct id_desc_t *id_desc);
149 
154 OSCAP_API void probe_item_resetidctr(struct id_desc_t *id_desc);
155 
156 #define probe_item_getent(item, name, n) probe_obj_getent (item, name, n)
157 
158 /*
159  * attributes
160  */
161 
169 OSCAP_API SEXP_t *probe_attr_creat(const char *name, const SEXP_t * val, ...);
170 
171 /*
172  * objects
173  */
174 
179 OSCAP_API SEXP_t *probe_obj_build(const char *fmt, ...);
180 
192 OSCAP_API SEXP_t *probe_obj_creat(const char *name, SEXP_t * attrs, ...);
193 
200 OSCAP_API SEXP_t *probe_obj_new(const char *name, SEXP_t * attrs);
201 
208 OSCAP_API SEXP_t *probe_obj_getent(const SEXP_t * obj, const char *name, uint32_t n);
209 
217 OSCAP_API SEXP_t *probe_obj_getentval(const SEXP_t * obj, const char *name, uint32_t n);
218 
228 OSCAP_API int probe_obj_getentvals(const SEXP_t * obj, const char *name, uint32_t n, SEXP_t ** res);
229 
235 OSCAP_API SEXP_t *probe_obj_getattrval(const SEXP_t * obj, const char *name);
236 
242 OSCAP_API bool probe_obj_attrexists(const SEXP_t * obj, const char *name);
243 
249 OSCAP_API int probe_obj_setstatus(SEXP_t * obj, oval_syschar_status_t status);
250 
258 OSCAP_API int probe_objent_setstatus(SEXP_t * obj, const char *name, uint32_t n, oval_syschar_status_t status);
259 
264 OSCAP_API char *probe_obj_getname(const SEXP_t * obj);
265 
273 OSCAP_API size_t probe_obj_getname_r(const SEXP_t * obj, char *buffer, size_t buflen);
274 
275 /*
276  * collected objects
277  */
278 
279 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);
280 OSCAP_API int probe_cobj_add_msg(SEXP_t *cobj, const SEXP_t *msg);
281 OSCAP_API SEXP_t *probe_cobj_get_msgs(const SEXP_t *cobj);
282 OSCAP_API SEXP_t *probe_cobj_get_mask(const SEXP_t *cobj);
283 OSCAP_API int probe_cobj_add_item(SEXP_t *cobj, const SEXP_t *item);
284 OSCAP_API SEXP_t *probe_cobj_get_items(const SEXP_t *cobj);
285 OSCAP_API void probe_cobj_set_flag(SEXP_t *cobj, oval_syschar_collection_flag_t flag);
286 OSCAP_API oval_syschar_collection_flag_t probe_cobj_get_flag(const SEXP_t *cobj);
290 OSCAP_API oval_syschar_collection_flag_t probe_cobj_compute_flag(SEXP_t *cobj);
291 
292 /*
293  * messages
294  */
295 
301 OSCAP_API SEXP_t *probe_msg_creat(oval_message_level_t level, char *message);
302 
309 OSCAP_API SEXP_t *probe_msg_creatf(oval_message_level_t level, const char *fmt, ...) __attribute__((format(printf, 2, 3), nonnull(2)));
310 
311 /*
312  * entities
313  */
314 
323 OSCAP_API SEXP_t *probe_ent_creat(const char *name, SEXP_t * attrs, SEXP_t * val, ...);
324 
332 OSCAP_API SEXP_t *probe_ent_creat1(const char *name, SEXP_t * attrs, SEXP_t * val);
333 
341 OSCAP_API SEXP_t *probe_ent_attr_add(SEXP_t * ent, const char *name, SEXP_t * val);
342 
348 OSCAP_API SEXP_t *probe_ent_getval(const SEXP_t * ent);
349 
357 OSCAP_API int probe_ent_getvals(const SEXP_t * ent, SEXP_t ** res);
358 
364 OSCAP_API SEXP_t *probe_ent_getattrval(const SEXP_t * ent, const char *name);
365 
371 OSCAP_API bool probe_ent_attrexists(const SEXP_t * ent, const char *name);
372 
378 OSCAP_API int probe_ent_setdatatype(SEXP_t * ent, oval_datatype_t type);
379 
384 OSCAP_API oval_datatype_t probe_ent_getdatatype(const SEXP_t * ent);
385 
391 OSCAP_API int probe_ent_setmask(SEXP_t * ent, bool mask);
392 
397 OSCAP_API bool probe_ent_getmask(const SEXP_t * ent);
398 
404 OSCAP_API int probe_ent_setstatus(SEXP_t * ent, oval_syschar_status_t status);
405 
410 OSCAP_API oval_syschar_status_t probe_ent_getstatus(const SEXP_t * ent);
411 
416 OSCAP_API char *probe_ent_getname(const SEXP_t * ent);
417 
425 OSCAP_API size_t probe_ent_getname_r(const SEXP_t * ent, char *buffer, size_t buflen);
426 
431 OSCAP_API void probe_free(SEXP_t * obj);
432 
439 OSCAP_API void probe_filebehaviors_canonicalize(SEXP_t **behaviors);
440 
447 OSCAP_API void probe_tfc54behaviors_canonicalize(SEXP_t **behaviors);
448 
449 #define PROBE_EINVAL 1
450 #define PROBE_ENOELM 2
451 #define PROBE_ENOVAL 3
452 #define PROBE_ENOATTR 4
453 #define PROBE_EINIT 5
454 #define PROBE_ENOMEM 6
455 #define PROBE_EOPNOTSUPP 7
456 #define PROBE_ERANGE 8
457 #define PROBE_EDOM 9
458 #define PROBE_EFAULT 10
459 #define PROBE_EACCESS 11
460 #define PROBE_ESETEVAL 12
461 #define PROBE_ENOENT 13
462 #define PROBE_ENOOBJ 14
463 #define PROBE_ECONNABORTED 15
464 #define PROBE_ESYSTEM 253
465 #define PROBE_EFATAL 254
466 #define PROBE_EUNKNOWN 255
468 #define PROBECMD_STE_FETCH 1
469 #define PROBECMD_OBJ_EVAL 2
470 #define PROBECMD_RESET 3
473 OSCAP_API int probe_offline_mode_supported(void);
474 OSCAP_API void probe_preload(void);
475 OSCAP_API void *probe_init(void) __attribute__ ((unused));
476 OSCAP_API void probe_fini(void *) __attribute__ ((unused));
477 
478 typedef struct probe_ctx probe_ctx;
479 
480 OSCAP_API bool probe_item_filtered(const SEXP_t *item, const SEXP_t *filters);
481 
482 OSCAP_API int probe_result_additem(SEXP_t *result, SEXP_t *item);
483 
491 OSCAP_API int probe_item_collect(probe_ctx *ctx, SEXP_t *item);
492 
499 OSCAP_API SEXP_t *probe_ctx_getobject(probe_ctx *ctx);
500 
506 OSCAP_API SEXP_t *probe_ctx_getresult(probe_ctx *ctx);
507 
508 typedef struct {
509  oval_datatype_t type;
510  void *value;
512 
513 OSCAP_API SEXP_t *probe_item_create(oval_subtype_t item_subtype, probe_elmatr_t *item_attributes[], ...);
514 
515 #define PROBE_ENT_AREF(ent, dst, attr_name, invalid_exp) \
516  do { \
517  if (((dst) = probe_ent_getattrval(ent, attr_name)) == NULL) { \
518  dE("Attribute `%s' is missing!", attr_name); \
519  invalid_exp \
520  } \
521  } while(0)
522 
523 #define PROBE_ENT_STRVAL(ent, dst, dstlen, invalid_exp, zerolen_exp) \
524  do { \
525  SEXP_t *___r; \
526  \
527  if ((___r = probe_ent_getval(ent)) == NULL) { \
528  dW("Entity has no value!"); \
529  invalid_exp \
530  } else { \
531  if (!SEXP_stringp(___r)) { \
532  dE("Invalid type"); \
533  SEXP_free(___r); \
534  invalid_exp \
535  } \
536  else if (SEXP_string_length(___r) == 0) { \
537  SEXP_free(___r); \
538  zerolen_exp \
539  } else { \
540  SEXP_string_cstr_r(___r, dst, dstlen); \
541  SEXP_free(___r); \
542  } \
543  } \
544  } while (0)
545 
546 #define PROBE_ENT_I32VAL(ent, dst, invalid_exp, nil_exp) \
547  do { \
548  SEXP_t *___r; \
549  \
550  if ((___r = probe_ent_getval(ent)) == NULL) { \
551  dW("Entity has no value!"); \
552  nil_exp; \
553  } else { \
554  if (!SEXP_numberp(___r)) { \
555  dE("Invalid type"); \
556  SEXP_free(___r); \
557  invalid_exp; \
558  } else { \
559  dst = SEXP_number_geti_32(___r); \
560  SEXP_free(___r); \
561  } \
562  } \
563  } while (0)
564 
565 #endif /* PROBE_API_H */
566 
567 OSCAP_API oval_operation_t probe_ent_getoperation(SEXP_t *entity, oval_operation_t op);
568 
569 OSCAP_API int probe_item_add_msg(SEXP_t *item, oval_message_level_t msglvl, char *msgfmt, ...);
570 
571 OSCAP_API SEXP_t *probe_entval_from_cstr(oval_datatype_t type, const char *value, size_t vallen);
572 OSCAP_API SEXP_t *probe_ent_from_cstr(const char *name, oval_datatype_t type, const char *value, size_t vallen);
573 
574 OSCAP_API oval_schema_version_t probe_obj_get_platform_schema_version(const SEXP_t *obj);
575 
580 OSCAP_API SEXP_t *probe_obj_getmask(SEXP_t *obj);
581 
char * probe_ent_getname(const SEXP_t *ent)
Get the name of an entity.
Definition: probe-api.c:1240
SEXP_t * probe_ent_getval(const SEXP_t *ent)
Get the value of an entity.
Definition: probe-api.c:1054
bool probe_ent_attrexists(const SEXP_t *ent, const char *name)
Check whether the specified attribute exists.
Definition: probe-api.c:1124
oval_operation_t
Operations.
Definition: oval_definitions.h:84
void probe_item_resetidctr(struct id_desc_t *id_desc)
Reset the item id generator.
Definition: probe-api.c:224
SEXP_t * probe_ent_getattrval(const SEXP_t *ent, const char *name)
Get the value of an entity&#39;s attribute.
Definition: probe-api.c:1079
int probe_itement_setstatus(SEXP_t *obj, const char *name, uint32_t n, oval_syschar_status_t status)
Set status of an item&#39;s entity.
Definition: probe-api.c:208
SEXP_t * probe_ent_creat1(const char *name, SEXP_t *attrs, SEXP_t *val)
Create a new entity.
Definition: probe-api.c:1002
oval_subtype_t
Unknown subtypes.
Definition: oval_types.h:120
OSCAP_API int probe_objent_setstatus(SEXP_t *obj, const char *name, uint32_t n, oval_syschar_status_t status)
Set status of an object&#39;s entity.
size_t probe_ent_getname_r(const SEXP_t *ent, char *buffer, size_t buflen)
Get the name of an entity.
Definition: probe-api.c:1283
bool probe_obj_attrexists(const SEXP_t *obj, const char *name)
Check whether the specified attribute exists.
Definition: probe-api.c:550
SEXP_t * probe_msg_creat(oval_message_level_t level, char *message)
Create a new message that can be added to a collected object.
Definition: probe-api.c:923
oval_syschar_status_t
System characteristics status.
Definition: oval_system_characteristics.h:61
int probe_ent_setmask(SEXP_t *ent, bool mask)
Set entity&#39;s mask.
Definition: probe-api.c:1201
bool probe_ent_getmask(const SEXP_t *ent)
Get entity&#39;s mask.
Definition: probe-api.c:1207
SEXP_t * probe_item_new(const char *name, SEXP_t *attrs)
Create a new item with just a name and optional attributes argument.
Definition: probe-api.c:110
SEXP_t * probe_item_attr_add(SEXP_t *item, const char *name, SEXP_t *val)
Add a new attribute to an item.
Definition: probe-api.c:136
SEXP_t * probe_attr_creat(const char *name, const SEXP_t *val,...)
Create a new list of attributes.
Definition: probe-api.c:314
int probe_obj_setstatus(SEXP_t *obj, oval_syschar_status_t status)
Set objects&#39;s status.
Definition: probe-api.c:597
OSCAP_API void * probe_init(void) __attribute__((unused))
Dummy probe_fini function.
Definition: filemd5_probe.c:164
SEXP_t * probe_obj_new(const char *name, SEXP_t *attrs)
Create a new object with just a name and optional attributes argument.
Definition: probe-api.c:390
OSCAP_API SEXP_t * probe_item_build(const char *fmt,...)
Build a new item according to the specified format.
SEXP_t * filters
object filters (OVAL 5.8 and higher)
Definition: probe.h:82
Definition: _sexp-value.h:41
oval_datatype_t
Datatypes.
Definition: oval_definitions.h:149
OSCAP_API void probe_fini(void *) __attribute__((unused))
Dummy probe_fini function.
Definition: filemd5_probe.c:185
Definition: probe.h:79
int probe_obj_getentvals(const SEXP_t *obj, const char *name, uint32_t n, SEXP_t **res)
Get the list of values of an object&#39;s entity.
Definition: probe-api.c:469
oval_datatype_t probe_ent_getdatatype(const SEXP_t *ent)
Get the OVAL data type of an entity.
Definition: probe-api.c:1175
OSCAP_API SEXP_t * probe_obj_build(const char *fmt,...)
Build a new object according to the specified format.
SEXP_t * probe_obj_getentval(const SEXP_t *obj, const char *name, uint32_t n)
Get the value of an object&#39;s entity.
Definition: probe-api.c:457
char * probe_obj_getname(const SEXP_t *obj)
Get the name of an object.
Definition: probe-api.c:607
SEXP_t * probe_obj_getent(const SEXP_t *obj, const char *name, uint32_t n)
Get an entity from an object.
Definition: probe-api.c:414
size_t probe_obj_getname_r(const SEXP_t *obj, char *buffer, size_t buflen)
Get the name of an object.
Definition: probe-api.c:612
SEXP_t * probe_obj_getmask(SEXP_t *obj)
Get object entity mask.
Definition: probe-api.c:1763
void probe_tfc54behaviors_canonicalize(SEXP_t **behaviors)
Set all of the missing attributes of the &#39;behaviors&#39; entity to default values.
Definition: probe-api.c:1367
OSCAP_API SEXP_t * probe_item_newid(struct id_desc_t *id_desc)
Get a new unique id (within a probe) for an item.
OSCAP_API SEXP_t * probe_ctx_getresult(probe_ctx *ctx)
Return reference to the output object (aka collected object).
Definition: probe.c:36
oval_setobject_operation_t
Set operations.
Definition: oval_definitions.h:184
int probe_ent_setstatus(SEXP_t *ent, oval_syschar_status_t status)
Set entity&#39;s status.
Definition: probe-api.c:1213
SEXP_t * probe_ent_attr_add(SEXP_t *ent, const char *name, SEXP_t *val)
Add a new attribute to an entity.
Definition: probe-api.c:1030
OSCAP_API int probe_item_collect(probe_ctx *ctx, SEXP_t *item)
Collect generated item (i.e.
Definition: icache.c:534
SEXP_t * probe_item_creat(const char *name, SEXP_t *attrs,...)
Create a new item consisting of a name, optional attributes argument and an arbitrary number of entit...
Definition: probe-api.c:66
oval_syschar_collection_flag_t
System characteristics result flag.
Definition: oval_system_characteristics.h:50
int probe_item_setstatus(SEXP_t *obj, oval_syschar_status_t status)
Set item&#39;s status.
Definition: probe-api.c:196
Definition: sexp-types.h:82
Definition: oval_schema_version.h:41
SEXP_t * probe_msg_creatf(oval_message_level_t level, const char *fmt,...)
Create a new message that can be added to a collected object.
Definition: probe-api.c:937
SEXP_t * probe_item_ent_add(SEXP_t *item, const char *name, SEXP_t *attrs, SEXP_t *val)
Add a new entity to an item.
Definition: probe-api.c:185
oval_message_level_t
Message level.
Definition: oval_system_characteristics.h:70
Holds information for item ids generation.
Definition: _probe-api.h:44
Definition: probe-api.h:508
SEXP_t * probe_obj_creat(const char *name, SEXP_t *attrs,...)
Create a new object consisting of a name, optional attributes argument and an arbitrary number of ent...
Definition: probe-api.c:347
OSCAP_API SEXP_t * probe_ctx_getobject(probe_ctx *ctx)
Return reference to the input object.
Definition: probe.c:31
int probe_ent_getvals(const SEXP_t *ent, SEXP_t **res)
Get the list of values of an entity.
Definition: probe-api.c:1035
int probe_ent_setdatatype(SEXP_t *ent, oval_datatype_t type)
Set the OVAL data type of an entity.
Definition: probe-api.c:1129
void probe_filebehaviors_canonicalize(SEXP_t **behaviors)
Set all of the missing attributes of the &#39;behaviors&#39; entity to default values.
Definition: probe-api.c:1331
SEXP_t * probe_obj_getattrval(const SEXP_t *obj, const char *name)
Get the value of an object&#39;s attribute.
Definition: probe-api.c:504
OSCAP_API void probe_preload(void)
Dummy probe_preload function.
Definition: preload.c:38
oval_syschar_status_t probe_ent_getstatus(const SEXP_t *ent)
Get entity status.
Definition: probe-api.c:1223
void probe_free(SEXP_t *obj)
Free the memory allocated by the probe_* functions.
Definition: probe-api.c:1326
SEXP_t * probe_ent_creat(const char *name, SEXP_t *attrs, SEXP_t *val,...)
Create a new list of entities.
Definition: probe-api.c:978