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 
71 /*
72  * items
73  */
74 
79 SEXP_t *probe_item_build(const char *fmt, ...);
80 
81 /* SEXP_t *probe_item_creat (const char *name, SEXP_t *attrs, ...); */
93 SEXP_t *probe_item_creat(const char *name, SEXP_t * attrs, ...);
94 
100 SEXP_t *probe_item_new(const char *name, SEXP_t * attrs);
101 
109 SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val);
110 
119 SEXP_t *probe_item_ent_add(SEXP_t * item, const char *name, SEXP_t * attrs, SEXP_t * val);
120 
127 
135 int probe_itement_setstatus(SEXP_t * obj, const char *name, uint32_t n, oval_syschar_status_t status);
136 
140 struct id_desc_t;
141 
147 SEXP_t *probe_item_newid(struct id_desc_t *id_desc);
148 
153 void probe_item_resetidctr(struct id_desc_t *id_desc);
154 
155 #define probe_item_getent(item, name, n) probe_obj_getent (item, name, n)
156 
157 /*
158  * attributes
159  */
160 
168 SEXP_t *probe_attr_creat(const char *name, const SEXP_t * val, ...);
169 
170 /*
171  * objects
172  */
173 
178 SEXP_t *probe_obj_build(const char *fmt, ...);
179 
191 SEXP_t *probe_obj_creat(const char *name, SEXP_t * attrs, ...);
192 
199 SEXP_t *probe_obj_new(const char *name, SEXP_t * attrs);
200 
207 SEXP_t *probe_obj_getent(const SEXP_t * obj, const char *name, uint32_t n);
208 
216 SEXP_t *probe_obj_getentval(const SEXP_t * obj, const char *name, uint32_t n);
217 
227 int probe_obj_getentvals(const SEXP_t * obj, const char *name, uint32_t n, SEXP_t ** res);
228 
234 SEXP_t *probe_obj_getattrval(const SEXP_t * obj, const char *name);
235 
241 bool probe_obj_attrexists(const SEXP_t * obj, const char *name);
242 
249 
257 int probe_objent_setstatus(SEXP_t * obj, const char *name, uint32_t n, oval_syschar_status_t status);
258 
263 char *probe_obj_getname(const SEXP_t * obj);
264 
272 size_t probe_obj_getname_r(const SEXP_t * obj, char *buffer, size_t buflen);
273 
274 /*
275  * collected objects
276  */
277 
278 SEXP_t *probe_cobj_new(oval_syschar_collection_flag_t flag, SEXP_t *msg_list, SEXP_t *item_list);
279 int probe_cobj_add_msg(SEXP_t *cobj, const SEXP_t *msg);
280 SEXP_t *probe_cobj_get_msgs(const SEXP_t *cobj);
281 int probe_cobj_add_item(SEXP_t *cobj, const SEXP_t *item);
282 SEXP_t *probe_cobj_get_items(const SEXP_t *cobj);
283 void probe_cobj_set_flag(SEXP_t *cobj, oval_syschar_collection_flag_t flag);
284 oval_syschar_collection_flag_t probe_cobj_get_flag(const SEXP_t *cobj);
288 oval_syschar_collection_flag_t probe_cobj_compute_flag(SEXP_t *cobj);
289 
290 /*
291  * messages
292  */
293 
299 SEXP_t *probe_msg_creat(oval_message_level_t level, char *message);
300 
307 SEXP_t *probe_msg_creatf(oval_message_level_t level, const char *fmt, ...) __attribute__((format(printf, 2, 3), nonnull(2)));
308 
309 /*
310  * entities
311  */
312 
321 SEXP_t *probe_ent_creat(const char *name, SEXP_t * attrs, SEXP_t * val, ...);
322 
330 SEXP_t *probe_ent_creat1(const char *name, SEXP_t * attrs, SEXP_t * val);
331 
339 SEXP_t *probe_ent_attr_add(SEXP_t * ent, const char *name, SEXP_t * val);
340 
346 SEXP_t *probe_ent_getval(const SEXP_t * ent);
347 
355 int probe_ent_getvals(const SEXP_t * ent, SEXP_t ** res);
356 
362 SEXP_t *probe_ent_getattrval(const SEXP_t * ent, const char *name);
363 
369 bool probe_ent_attrexists(const SEXP_t * ent, const char *name);
370 
377 
383 
389 int probe_ent_setmask(SEXP_t * ent, bool mask);
390 
395 bool probe_ent_getmask(const SEXP_t * ent);
396 
403 
409 
414 char *probe_ent_getname(const SEXP_t * ent);
415 
423 size_t probe_ent_getname_r(const SEXP_t * ent, char *buffer, size_t buflen);
424 
429 void probe_free(SEXP_t * obj);
430 
437 void probe_filebehaviors_canonicalize(SEXP_t **behaviors);
438 
445 void probe_tfc54behaviors_canonicalize(SEXP_t **behaviors);
446 
447 #define PROBE_EINVAL 1
448 #define PROBE_ENOELM 2
449 #define PROBE_ENOVAL 3
450 #define PROBE_ENOATTR 4
451 #define PROBE_EINIT 5
452 #define PROBE_ENOMEM 6
453 #define PROBE_EOPNOTSUPP 7
454 #define PROBE_ERANGE 8
455 #define PROBE_EDOM 9
456 #define PROBE_EFAULT 10
457 #define PROBE_EACCESS 11
458 #define PROBE_ESETEVAL 12
459 #define PROBE_ENOENT 13
460 #define PROBE_ENOOBJ 14
461 #define PROBE_ECONNABORTED 15
462 #define PROBE_ESYSTEM 253
463 #define PROBE_EFATAL 254
464 #define PROBE_EUNKNOWN 255
466 #define PROBECMD_STE_FETCH 1
467 #define PROBECMD_OBJ_EVAL 2
468 #define PROBECMD_RESET 3
470 void *probe_init(void) __attribute__ ((unused));
471 void probe_fini(void *) __attribute__ ((unused));
472 
473 typedef struct probe_ctx probe_ctx;
474 
475 int probe_main(probe_ctx *, void *) __attribute__ ((nonnull(1)));
476 
477 #define PROBE_VARREF_HANDLING 0
478 #define PROBE_RESULT_CACHING 1
479 
480 int probe_setoption(int option, ...);
481 
482 bool probe_item_filtered(const SEXP_t *item, const SEXP_t *filters);
483 
484 int probe_result_additem(SEXP_t *result, SEXP_t *item);
485 
493 int probe_item_collect(probe_ctx *ctx, SEXP_t *item);
494 
501 SEXP_t *probe_ctx_getobject(probe_ctx *ctx);
502 
508 SEXP_t *probe_ctx_getresult(probe_ctx *ctx);
509 
510 typedef struct {
511  oval_datatype_t type;
512  void *value;
514 
515 SEXP_t *probe_item_create(oval_subtype_t item_subtype, probe_elmatr_t *item_attributes[], ...);
516 
517 #define PROBE_ENT_AREF(ent, dst, attr_name, invalid_exp) \
518  do { \
519  if (((dst) = probe_ent_getattrval(ent, attr_name)) == NULL) { \
520  dE("Attribute `%s' is missing!\n", attr_name); \
521  invalid_exp \
522  } \
523  } while(0)
524 
525 #define PROBE_ENT_STRVAL(ent, dst, dstlen, invalid_exp, zerolen_exp) \
526  do { \
527  SEXP_t *___r; \
528  \
529  if ((___r = probe_ent_getval(ent)) == NULL) { \
530  dW("Entity has no value!\n"); \
531  invalid_exp \
532  } else { \
533  if (!SEXP_stringp(___r)) { \
534  dE("Invalid type\n"); \
535  SEXP_free(___r); \
536  invalid_exp \
537  } \
538  if (SEXP_string_length(___r) == 0) { \
539  SEXP_free(___r); \
540  zerolen_exp \
541  } else { \
542  SEXP_string_cstr_r(___r, dst, dstlen); \
543  SEXP_free(___r); \
544  } \
545  } \
546  } while (0)
547 
548 #define PROBE_ENT_I32VAL(ent, dst, invalid_exp, nil_exp) \
549  do { \
550  SEXP_t *___r; \
551  \
552  if ((___r = probe_ent_getval(ent)) == NULL) { \
553  dW("Entity has no value!\n"); \
554  nil_exp; \
555  } else { \
556  if (!SEXP_numberp(___r)) { \
557  dE("Invalid type\n"); \
558  SEXP_free(___r); \
559  invalid_exp; \
560  } else { \
561  dst = SEXP_number_geti_32(___r); \
562  SEXP_free(___r); \
563  } \
564  } \
565  } while (0)
566 
567 #endif /* PROBE_API_H */
568 
569 oval_operation_t probe_ent_getoperation(SEXP_t *entity, oval_operation_t op);
570 
571 int probe_item_add_msg(SEXP_t *item, oval_message_level_t msglvl, char *msgfmt, ...);
572 
573 SEXP_t *probe_entval_from_cstr(oval_datatype_t type, const char *value, size_t vallen);
574 SEXP_t *probe_ent_from_cstr(const char *name, oval_datatype_t type, const char *value, size_t vallen);
575 
576 oval_version_t probe_obj_get_schema_version(const SEXP_t *obj);