예제 #1
0
void oval_agent_destroy_session(oval_agent_session_t * ag_sess) {
	if (ag_sess != NULL) {
		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
	        free(ag_sess->filename);
		free(ag_sess);
	}
}
예제 #2
0
oval_agent_session_t * oval_agent_new_session(struct oval_definition_model *model, const char * name) {
	oval_agent_session_t *ag_sess;
	struct oval_sysinfo *sysinfo;
	struct oval_generator *generator;
	int ret;

	dI("Started new OVAL agent.", name);

        /* Optimalization */
        oval_definition_model_optimize_by_filter_propagation(model);

	ag_sess = oscap_talloc(oval_agent_session_t);
        ag_sess->filename = oscap_strdup(name);
	ag_sess->def_model = model;
	ag_sess->cur_var_model = NULL;
	ag_sess->sys_model = oval_syschar_model_new(model);
#if defined(OVAL_PROBES_ENABLED)
	ag_sess->psess     = oval_probe_session_new(ag_sess->sys_model);
#endif

#if defined(OVAL_PROBES_ENABLED)
	/* probe sysinfo */
	ret = oval_probe_query_sysinfo(ag_sess->psess, &sysinfo);
	if (ret != 0) {
		oval_probe_session_destroy(ag_sess->psess);
		oval_syschar_model_free(ag_sess->sys_model);
		oscap_free(ag_sess);
		return NULL;
	}
#else
	/* TODO */
	sysinfo = oval_sysinfo_new(ag_sess->sys_model);
#endif /* OVAL_PROBES_ENABLED */
	oval_syschar_model_set_sysinfo(ag_sess->sys_model, sysinfo);
	oval_sysinfo_free(sysinfo);

	/* one system only */
	ag_sess->sys_models[0] = ag_sess->sys_model;
	ag_sess->sys_models[1] = NULL;
#if defined(OVAL_PROBES_ENABLED)
	ag_sess->res_model = oval_results_model_new_with_probe_session(
			model, ag_sess->sys_models, ag_sess->psess);
	generator = oval_results_model_get_generator(ag_sess->res_model);
	oval_generator_set_product_version(generator, oscap_get_version());
#endif

	ag_sess->product_name = NULL;

	return ag_sess;
}
예제 #3
0
int app_collect_oval(const struct oscap_action *action)
{
	struct oval_definition_model	*def_model = NULL;
	struct oval_variable_model	*var_model = NULL;
	struct oval_syschar_model	*sys_model = NULL;
	struct oval_sysinfo		*sysinfo   = NULL;
	struct oval_probe_session	*pb_sess   = NULL;
	struct oval_generator		*generator = NULL;
	int ret = OSCAP_ERROR;

	/* Turn on verbosity */
	if (!oscap_set_verbose(action->verbosity_level, action->f_verbose_log, false)) {
		goto cleanup;
	}

	/* validate inputs */
	if (action->validate) {
		if (!valid_inputs(action)) {
			goto cleanup;
		}
	}

	/* import definitions */
	struct oscap_source *source = oscap_source_new_from_file(action->f_oval);
	def_model = oval_definition_model_import_source(source);
	oscap_source_free(source);
	if (def_model == NULL) {
		fprintf(stderr, "Failed to import the OVAL Definitions from '%s'.\n", action->f_oval);
		goto cleanup;
	}

	/* bind external variables */
	if(action->f_variables) {
		struct oscap_source *var_source = oscap_source_new_from_file(action->f_variables);
		var_model = oval_variable_model_import_source(var_source);
		oscap_source_free(var_source);
		if (var_model == NULL) {
			fprintf(stderr, "Failed to import the OVAL Variables from '%s'.\n", action->f_variables);
			goto cleanup;
		}

		if (oval_definition_model_bind_variable_model(def_model, var_model)) {
			fprintf(stderr, "Failed to bind Variables to Definitions\n");
			goto cleanup;
		}
	}

	/* create empty syschar model */
	sys_model = oval_syschar_model_new(def_model);

	/* set product name */
	generator = oval_syschar_model_get_generator(sys_model);
	oval_generator_set_product_name(generator, OSCAP_PRODUCTNAME);

	/* create probe session */
	pb_sess = oval_probe_session_new(sys_model);

	/* query sysinfo */
	ret = oval_probe_query_sysinfo(pb_sess, &sysinfo);
	if (ret != 0) {
		fprintf(stderr, "Failed to query sysinfo\n");
		goto cleanup;
	}
	oval_syschar_model_set_sysinfo(sys_model, sysinfo);

	/* query objects */
	struct oval_object *object;
	struct oval_syschar *syschar;
	oval_syschar_collection_flag_t sc_flg;
	if (action->id) {
		object = oval_definition_model_get_object(def_model, action->id);
		if (!object) {
			fprintf(stderr, "Object ID(%s) does not exist in '%s'.\n", action->id, action->f_oval);
			goto cleanup;
		}
		printf("Collected: \"%s\" : ", oval_object_get_id(object));
		oval_probe_query_object(pb_sess, object, 0, &syschar);
		sc_flg = oval_syschar_get_flag(syschar);
		printf("%s\n", oval_syschar_collection_flag_get_text(sc_flg));
	}
	else {
	        struct oval_object_iterator *objects = oval_definition_model_get_objects(def_model);
		while (oval_object_iterator_has_more(objects)) {
			object = oval_object_iterator_next(objects);
			printf("Collected: \"%s\" : ", oval_object_get_id(object));
			oval_probe_query_object(pb_sess, object, 0, &syschar);
			sc_flg = oval_syschar_get_flag(syschar);
			printf("%s\n", oval_syschar_collection_flag_get_text(sc_flg));
		}
		oval_object_iterator_free(objects);
	}

	const char* full_validation = getenv("OSCAP_FULL_VALIDATION");

	/* output */
	if (action->f_syschar != NULL) {
		/* export OVAL System Characteristics */
		oval_syschar_model_export(sys_model, action->f_syschar);

		/* validate OVAL System Characteristics */
		if (action->validate && full_validation) {
			struct oscap_source *syschar_source = oscap_source_new_from_file(action->f_syschar);
			if (oscap_source_validate(syschar_source, reporter, (void *)action)) {
				oscap_source_free(syschar_source);
				goto cleanup;
			}
			fprintf(stdout, "OVAL System Characteristics are exported correctly.\n");
			oscap_source_free(syschar_source);
		}
	}

	ret = OSCAP_OK;

cleanup:
	if(oscap_err())
		fprintf(stderr, "%s %s\n", OSCAP_ERR_MSG, oscap_err_desc());

	if (sysinfo) oval_sysinfo_free(sysinfo);
	if (pb_sess) oval_probe_session_destroy(pb_sess);
	if (sys_model) oval_syschar_model_free(sys_model);
	if (def_model) oval_definition_model_free(def_model);

	return ret;
}
예제 #4
0
int main (void)
{
  struct oval_sysinfo *info;

  /*
   *  Create empty models
   */
  struct oval_definition_model *def_model = oval_definition_model_new();
	oscap_assert(def_model != NULL);

  struct oval_syschar_model *sys_model = oval_syschar_model_new(def_model);
	oscap_assert(sys_model != NULL);

  /*
   *  Create probe session
   */
  oval_probe_session_t *sess = oval_probe_session_new(sys_model);
	oscap_assert(sess != NULL);

  /*
   *  Call the sysinfo probe.
   */
	oscap_assert(oval_probe_query_sysinfo(sess, &info) == 0);
	oscap_assert(info != NULL);

  if (info != NULL) {
    char *a, *b, *c, *d;

    printf ("          os_name: %s\n"
	    "       os_version: %s\n"
	    "  os_architecture: %s\n"
	    "primary_host_name: %s\n",

	    a = oval_sysinfo_get_os_name (info),
	    b = oval_sysinfo_get_os_version (info),
	    c = oval_sysinfo_get_os_architecture (info),
	    d = oval_sysinfo_get_primary_host_name (info));

		oscap_assert(a != NULL);
		oscap_assert(b != NULL);
		oscap_assert(c != NULL);
		oscap_assert(d != NULL);

    struct oval_sysint_iterator *ifit = oval_sysinfo_get_interfaces (info);

    if (ifit != NULL) {
      printf ("Interfaces:\n");

      while (oval_sysint_iterator_has_more (ifit)) {
	struct oval_sysint *ife = oval_sysint_iterator_next (ifit);
				oscap_assert(ife != NULL);

	printf ("%s %s %s\n",
		oval_sysint_get_name (ife),
		oval_sysint_get_ip_address (ife),
		oval_sysint_get_mac_address (ife));

	/* oval_sysint_free (ife); */
      }

      oval_sysint_iterator_free (ifit);
    }

    oval_sysinfo_free (info);
    oval_probe_session_destroy(sess);

    return (0);
  }

  /*
   *  Free the probe context. This also terminates
   *  all running probes executed under this context.
   */
  oval_probe_session_destroy(sess);

  return (1);
}