static int _oval_test_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *user) { struct oval_test *test = (struct oval_test *)user; char *tagname = (char *)xmlTextReaderLocalName(reader); int return_code = 0; if ((strcmp(tagname, "notes") == 0)) { return_code = oval_parser_parse_tag(reader, context, &_oval_test_parse_notes, test); } else if ((strcmp(tagname, "object") == 0)) { char *object_ref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "object_ref"); if (object_ref != NULL) { struct oval_definition_model *model = context->definition_model; struct oval_object *object = oval_definition_model_get_new_object(model, object_ref); oscap_free(object_ref); object_ref = NULL; oval_test_set_object(test, object); } } else if ((strcmp(tagname, "state") == 0)) { char *state_ref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "state_ref"); if (state_ref != NULL) { struct oval_definition_model *model = context->definition_model; struct oval_state *state = oval_definition_model_get_new_state(model, state_ref); oval_test_add_state(test, state); oscap_free(state_ref); state_ref = NULL; } } else { oscap_dlprintf(DBG_W, "Skipping tag <%s>.\n", tagname); return_code = oval_parser_skip_tag(reader, context); } oscap_free(tagname); return return_code; }
static inline int ds_sds_compose_component_add_script_content(xmlNode *component, const char *filepath) { FILE* f = fopen(filepath, "r"); if (!f) { oscap_seterr(OSCAP_EFAMILY_GLIBC, "Can't read plain text from file '%s'.", filepath); return -1; } fseek(f, 0, SEEK_END); long int length = ftell(f); fseek(f, 0, SEEK_SET); if (length >= 0) { char* buffer = oscap_alloc((length + 1) * sizeof(char)); if (fread(buffer, length, 1, f) != 1) { oscap_seterr(OSCAP_EFAMILY_GLIBC, "Error while reading from file '%s'.", filepath); fclose(f); oscap_free(buffer); return -1; } fclose(f); buffer[length] = '\0'; xmlNsPtr local_ns = xmlNewNs(component, BAD_CAST sce_xccdf_ns_uri, BAD_CAST "oscap-sce-xccdf-stream"); xmlNewTextChild(component, local_ns, BAD_CAST "script", BAD_CAST buffer); oscap_free(buffer); return 0; } else { oscap_seterr(OSCAP_EFAMILY_GLIBC, "No data read from file '%s'.", filepath); fclose(f); return -1; } }
int probe_main (probe_ctx *ctx, void *arg) { SEXP_t *object; struct runlevel_req request_st; struct runlevel_rep *reply_st = NULL; object = probe_ctx_getobject(ctx); request_st.service_name_ent = probe_obj_getent(object, "service_name", 1); if (request_st.service_name_ent == NULL) { dI("%s: element not found", "service_name"); return PROBE_ENOELM; } request_st.runlevel_ent = probe_obj_getent(object, "runlevel", 1); if (request_st.runlevel_ent == NULL) { SEXP_free(request_st.service_name_ent); dI("%s: element not found", "runlevel"); return PROBE_ENOELM; } if (get_runlevel(&request_st, &reply_st) == -1) { SEXP_t *msg; msg = probe_msg_creat(OVAL_MESSAGE_LEVEL_ERROR, "get_runlevel failed."); probe_cobj_add_msg(probe_ctx_getresult(ctx), msg); SEXP_free(msg); probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR); } else { struct runlevel_rep *next_rep; SEXP_t *item; while (reply_st != NULL) { dI("get_runlevel: [0]=\"%s\", [1]=\"%s\", [2]=\"%d\", [3]=\"%d\"", reply_st->service_name, reply_st->runlevel, reply_st->start, reply_st->kill); item = probe_item_create(OVAL_UNIX_RUNLEVEL, NULL, "service_name", OVAL_DATATYPE_STRING, reply_st->service_name, "runlevel", OVAL_DATATYPE_STRING, reply_st->runlevel, "start", OVAL_DATATYPE_BOOLEAN, reply_st->start, "kill", OVAL_DATATYPE_BOOLEAN, reply_st->kill, NULL); probe_item_collect(ctx, item); next_rep = reply_st->next; oscap_free(reply_st->service_name); oscap_free(reply_st->runlevel); oscap_free(reply_st); reply_st = next_rep; } } SEXP_free(request_st.runlevel_ent); SEXP_free(request_st.service_name_ent); return 0; }
void oval_definition_model_free(struct oval_definition_model *model) { __attribute__nonnull__(model); oval_string_map_free(model->definition_map, (oscap_destruct_func) oval_definition_free); oval_string_map_free(model->object_map, (oscap_destruct_func) oval_object_free); oval_string_map_free(model->state_map, (oscap_destruct_func) oval_state_free); oval_string_map_free(model->test_map, (oscap_destruct_func) oval_test_free); oval_string_map_free(model->variable_map, (oscap_destruct_func) oval_variable_free); if (model->vardef_map != NULL) oval_string_map_free(model->vardef_map, (oscap_destruct_func) oval_string_map_free0); if (model->bound_variable_models) oval_collection_free_items(model->bound_variable_models, (oscap_destruct_func) oval_variable_model_free); if (model->schema != NULL) oscap_free(model->schema); model->definition_map = NULL; model->object_map = NULL; model->state_map = NULL; model->test_map = NULL; model->variable_map = NULL; model->schema = NULL; oval_generator_free(model->generator); oscap_free(model); }
static int _oval_affected_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *user) { struct oval_affected *affected = (struct oval_affected *)user; int return_code; xmlChar *tagname = xmlTextReaderLocalName(reader); //xmlChar *namespace = xmlTextReaderNamespaceUri(reader); if (strcmp((char *)tagname, "platform") == 0) { char *platform = NULL; return_code = oscap_parser_text_value(reader, &oscap_text_consumer, &platform); if (platform != NULL) { oval_affected_add_platform(affected, platform); oscap_free(platform); } } else if (strcmp((char *)tagname, "product") == 0) { char *product = NULL; return_code = oscap_parser_text_value(reader, &oscap_text_consumer, &product); if (product != NULL) { oval_affected_add_product(affected, product); oscap_free(product); } } else { dI("Skipping tag: %s", tagname); return_code = oval_parser_skip_tag(reader, context); } oscap_free(tagname); return return_code; }
void xccdf_ident_free(struct xccdf_ident *ident) { if (ident) { oscap_free(ident->id); oscap_free(ident->system); oscap_free(ident); } }
void xccdf_profile_note_free(struct xccdf_profile_note *note) { if (note) { oscap_free(note->reftag); oscap_text_free(note->text); oscap_free(note); } }
void xccdf_check_content_ref_free(struct xccdf_check_content_ref *ref) { if (ref) { oscap_free(ref->name); oscap_free(ref->href); oscap_free(ref); } }
void rds_asset_index_free(struct rds_asset_index *s) { if (s != NULL) { oscap_list_free0(s->reports); oscap_free(s->id); oscap_free(s); } }
void oval_value_free(struct oval_value *value) { if (value) { oscap_free(value->text); value->text = NULL; oscap_free(value); } }
void xccdf_fixtext_free(struct xccdf_fixtext *item) { if (item) { oscap_text_free(item->text); oscap_free(item->fixref); oscap_free(item); } }
void xccdf_check_export_free(struct xccdf_check_export *item) { if (item) { oscap_free(item->name); oscap_free(item->value); oscap_free(item); } }
void xccdf_check_import_free(struct xccdf_check_import *item) { if (item) { oscap_free(item->name); oscap_free(item->xpath); oscap_free(item->content); oscap_free(item); } }
static SEXP_t *oval_probe_cmd_obj_eval(SEXP_t *sexp, void *arg) { char *id_str; struct oval_definition_model *defs; struct oval_object *obj; struct oval_syschar *res; oval_pext_t *pext = (oval_pext_t *) arg; SEXP_t *ret, *ret_code; int r; assume_d (sexp != NULL, NULL); assume_d (arg != NULL, NULL); if (!SEXP_stringp(sexp)) { oscap_dlprintf(DBG_E, "Invalid argument: type=%s.\n", SEXP_strtype(sexp)); return (NULL); } id_str = SEXP_string_cstr(sexp); defs = oval_syschar_model_get_definition_model(*(pext->model)); obj = oval_definition_model_get_object(defs, id_str); ret = SEXP_list_new (sexp, NULL); oscap_dlprintf(DBG_I, "Get_object: %s.\n", id_str); if (obj == NULL) { oscap_dlprintf(DBG_E, "Can't find obj: id=%s.\n", id_str); oscap_free(id_str); SEXP_free(ret); return (NULL); } oscap_clearerr(); r = oval_probe_query_object(pext->sess_ptr, obj, OVAL_PDFLAG_NOREPLY|OVAL_PDFLAG_SLAVE, &res); if (r < 0) ret_code = SEXP_number_newu((unsigned int) SYSCHAR_FLAG_COMPLETE); else ret_code = SEXP_number_newu((unsigned int) oval_syschar_get_flag(res)); SEXP_list_add(ret, ret_code); SEXP_free(ret_code); if (oscap_err()) { oscap_dlprintf(DBG_E, "Failed: id: %s, err: %d, %s.\n", id_str, oscap_err_family(), oscap_err_desc()); oscap_clearerr(); oscap_free(id_str); SEXP_free(ret); return (NULL); } oscap_free(id_str); return (ret); }
void oval_message_free(struct oval_message *message) { __attribute__nonnull__(message); if (message->text != NULL) oscap_free(message->text); message->text = NULL; oscap_free(message); }
void xccdf_fix_free(struct xccdf_fix *item) { if (item) { oscap_free(item->id); oscap_free(item->system); oscap_free(item->platform); oscap_free(item->content); oscap_free(item); } }
int oval_test_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *usr) { int ret = 0; char *comm = NULL; char *version = NULL; struct oval_definition_model *model = context->definition_model; char *id = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "id"); struct oval_test *test = oval_definition_model_get_new_test(model, id); oval_subtype_t subtype = oval_subtype_parse(reader); if ( subtype == OVAL_SUBTYPE_UNKNOWN) { oscap_seterr(OSCAP_EFAMILY_OVAL, "Unknown test type %s.", id); ret = -1; goto cleanup; } oval_test_set_subtype(test, subtype); oval_operator_t ste_operator = oval_operator_parse(reader, "state_operator", OVAL_OPERATOR_AND); oval_test_set_state_operator(test, ste_operator); oval_check_t check = oval_check_parse(reader, "check", OVAL_CHECK_UNKNOWN); if (check == OVAL_CHECK_NONE_EXIST) { dW("The 'none exist' CheckEnumeration value has been deprecated. " "Converted to check='none satisfy' and check_existence='none exist'.\n"); oval_test_set_check(test, OVAL_CHECK_NONE_SATISFY); oval_test_set_existence(test, OVAL_NONE_EXIST); } else { oval_existence_t existence; oval_test_set_check(test, check); existence = oval_existence_parse(reader, "check_existence", OVAL_AT_LEAST_ONE_EXISTS); oval_test_set_existence(test, existence); } comm = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "comment"); if (comm != NULL) { oval_test_set_comment(test, comm); } int deprecated = oval_parser_boolean_attribute(reader, "deprecated", 0); oval_test_set_deprecated(test, deprecated); version = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "version"); oval_test_set_version(test, atoi(version)); ret = oval_parser_parse_tag(reader, context, &_oval_test_parse_tag, test); cleanup: oscap_free(version); oscap_free(comm); oscap_free(id); return ret; }
oval_result_t probe_ent_cmp_version(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) { const char *state_version = SEXP_string_cstr(val1); const char *sys_version = SEXP_string_cstr(val2); oval_result_t result = oval_versiontype_cmp(state_version, sys_version, op); oscap_free(state_version); oscap_free(sys_version); return result; }
void oval_agent_destroy_session(oval_agent_session_t * ag_sess) { if (ag_sess != NULL) { oscap_free(ag_sess->product_name); #if defined(OVAL_PROBES_ENABLED) oval_probe_session_destroy(ag_sess->psess); oval_results_model_free(ag_sess->res_model); #endif oval_syschar_model_free(ag_sess->sys_model); oscap_free(ag_sess->filename); oscap_free(ag_sess); } }
oval_result_t probe_ent_cmp_evr(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) { oval_result_t result = OVAL_RESULT_ERROR; char *s1 = SEXP_string_cstr(val1); char *s2 = SEXP_string_cstr(val2); result = oval_evr_string_cmp(s1, s2, op); oscap_free(s1); oscap_free(s2); return result; }
void oval_behavior_free(struct oval_behavior *behavior) { __attribute__nonnull__(behavior); if (behavior->value) oscap_free(behavior->value); if (behavior->key) oscap_free(behavior->key); behavior->key = NULL; behavior->value = NULL; oscap_free(behavior); }
static oval_result_t probe_ent_cmp_ipaddr(int af, SEXP_t *val1, SEXP_t *val2, oval_operation_t op) { oval_result_t result = OVAL_RESULT_ERROR; char *addr1 = SEXP_string_cstr(val1); char *addr2 = SEXP_string_cstr(val2); result = oval_ipaddr_cmp(af, addr1, addr2, op); oscap_free(addr1); oscap_free(addr2); return result; }
static void probe_icache_free_node(struct rbt_i64_node *n) { probe_citem_t *ci = (probe_citem_t *)n->data; while (ci->count > 0) { SEXP_free(ci->item[ci->count - 1]); --ci->count; } oscap_free(ci->item); oscap_free(ci); return; }
void oval_record_field_free(struct oval_record_field *rf) { if (rf == NULL) return; if (rf->name != NULL) oscap_free(rf->name); if (rf->value != NULL) oscap_free(rf->value); rf->name = rf->value = NULL; oscap_free(rf); }
void oval_pext_free(oval_pext_t *pext) { if (!pext->do_init) { /* free structs */ oscap_free(pext->pdsc); pext->pdsc = NULL; pext->pdsc_cnt = 0; oval_pdtbl_free(pext->pdtbl); } pthread_mutex_destroy(&pext->lock); oscap_free(pext); }
void oval_entity_free(struct oval_entity *entity) { __attribute__nonnull__(entity); if (entity->value != NULL) oval_value_free(entity->value); if (entity->name != NULL) oscap_free(entity->name); entity->name = NULL; entity->value = NULL; entity->variable = NULL; oscap_free(entity); }
void xccdf_check_free(struct xccdf_check *check) { if (check) { oscap_list_free(check->content_refs, (oscap_destruct_func) xccdf_check_content_ref_free); oscap_list_free(check->imports, (oscap_destruct_func) xccdf_check_import_free); oscap_list_free(check->exports, (oscap_destruct_func) xccdf_check_export_free); oscap_list_free(check->children, (oscap_destruct_func) xccdf_check_free); oscap_free(check->id); oscap_free(check->system); oscap_free(check->selector); oscap_free(check->content); oscap_free(check); } }
static SEXP_t *oval_probe_cmd_ste_fetch(SEXP_t *sexp, void *arg) { SEXP_t *id, *ste_list, *ste_sexp; char *id_str; struct oval_state *ste; struct oval_definition_model *definition_model; oval_pext_t *pext = (oval_pext_t *)arg; int ret; assume_d (sexp != NULL, NULL); assume_d (arg != NULL, NULL); ste_list = SEXP_list_new(NULL); SEXP_list_foreach(id, sexp) { if (SEXP_stringp(id)) { id_str = SEXP_string_cstr(id); definition_model = oval_syschar_model_get_definition_model(*(pext->model)); ste = oval_definition_model_get_state(definition_model, id_str); if (ste == NULL) { oscap_dlprintf(DBG_E, "Can't find ste: id: %s.\n", id_str); SEXP_list_free(ste_list); oscap_free(id_str); SEXP_free(id); return (NULL); } ret = oval_state_to_sexp(pext->sess_ptr, ste, &ste_sexp); if (ret !=0) { oscap_dlprintf(DBG_E, "Failed to convert OVAL state to SEXP, id: %s.\n", id_str); SEXP_list_free(ste_list); oscap_free(id_str); SEXP_free(id); return (NULL); } SEXP_list_add(ste_list, ste_sexp); SEXP_free(ste_sexp); oscap_free(id_str); } } return (ste_list); }
void oval_string_map_put_string(struct oval_string_map *map, const char *key, const char *val) { char *str = strdup(val), *key_copy; assume_d(map != NULL, /* void */); assume_d(key != NULL, /* void */); if (rbt_str_add((rbt_t *)map, key_copy = strdup(key), str) == 0) return; else { oscap_free(str); oscap_free(key_copy); } return; }
void oval_sysent_set_value(struct oval_sysent *sysent, char *value) { __attribute__nonnull__(sysent); if (sysent->value != NULL) oscap_free(sysent->value); sysent->value = oscap_strdup(value); }