Skip to content

Commit

Permalink
handle scanner parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Aug 5, 2024
1 parent 4b77d34 commit c4569ea
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 17 deletions.
27 changes: 15 additions & 12 deletions openvasd/jsonutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,22 @@ gvm_jnode_parse_vt (jreader_t reader)
{
nvti_set_solution (nvt, json_reader_get_string_value (reader));
json_reader_end_member (reader);
}
else
{
g_warning ("%s: Missing OID", __func__);

if (json_reader_read_member (reader, "solution_type"))
{
nvti_set_solution_type (nvt, json_reader_get_string_value (reader));
json_reader_end_member (reader);
}
else
{
g_debug ("%s: SOLUTION: missing type for OID: %s", __func__,
nvti_oid (nvt));
json_reader_end_member (reader);
}
json_reader_read_member (reader, "solution_method");
nvti_set_solution_method (nvt, json_reader_get_string_value (reader));
json_reader_end_member (reader);
}
json_reader_read_member (reader, "solution_type");
nvti_set_solution_type (nvt, json_reader_get_string_value (reader));
json_reader_end_member (reader);

json_reader_read_member (reader, "solution_method");
nvti_set_solution_method (nvt, json_reader_get_string_value (reader));
json_reader_end_member (reader);

json_reader_read_member (reader, "summary");
nvti_set_summary (nvt, json_reader_get_string_value (reader));
Expand Down Expand Up @@ -365,7 +368,7 @@ gvm_jnode_parse_vt (jreader_t reader)
json_reader_end_member (reader); // End references

// Parse preferences
if (json_reader_read_member (reader, "references"))
if (json_reader_read_member (reader, "preferences"))
{
if (!json_reader_is_array (reader))
{
Expand Down
106 changes: 101 additions & 5 deletions openvasd/openvasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct openvasd_param
char *name; /**< Parameter name. */
char *defval; /**< Default value. */
char *description; /**< Description. */
char *type; /**< Parameter type. */
int mandatory; /**< If mandatory. */
};

/**
Expand Down Expand Up @@ -1159,14 +1161,17 @@ openvasd_get_scan_preferences (openvasd_connector_t *conn)
* @return New Openvasd parameter.
*/
static openvasd_param_t *
openvasd_param_new (char *id, char *name, char *defval, char *description)
openvasd_param_new (char *id, char *name, char *defval, char *description,
char *type, int mandatory)
{
openvasd_param_t *param = g_malloc0 (sizeof (openvasd_param_t));

param->id = id;
param->defval = defval;
param->description = description;
param->name = name;
param->mandatory = mandatory;
param->type = type;
return param;
}

Expand All @@ -1184,6 +1189,91 @@ openvasd_param_free (openvasd_param_t *param)
g_free (param->name);
g_free (param->defval);
g_free (param->description);
g_free (param->type);
}

/**
* @brief Get the parameter id
*
* @param[in] param Openvasd parameter
*/
char *
openvasd_param_id (openvasd_param_t *param)
{
if (!param)
return NULL;

return param->id;
}

/**
* @brief Get the parameter default
*
* @param[in] param Openvasd parameter
*/
char *
openvasd_param_name (openvasd_param_t *param)
{
if (!param)
return NULL;

return param->defval;
}

/**
* @brief Get the parameter description
*
* @param[in] param Openvasd parameter
*/
char *
openvasd_param_desc (openvasd_param_t *param)
{
if (!param)
return NULL;

return param->description;
}

/**
* @brief Get the parameter type
*
* @param[in] param Openvasd parameter
*/
char *
openvasd_param_type (openvasd_param_t *param)
{
if (!param)
return NULL;

return param->type;
}

/**
* @brief Get the parameter default
*
* @param[in] param Openvasd parameter
*/
char *
openvasd_param_default (openvasd_param_t *param)
{
if (!param)
return NULL;

return param->defval;
}

/**
* @brief If the parameter is mandatory
*
* @param[in] param Openvasd parameter
*/
int
openvasd_param_mandatory (openvasd_param_t *param)
{
if (!param)
return 0;

return param->mandatory;
}

int
Expand Down Expand Up @@ -1215,12 +1305,12 @@ openvasd_parsed_scans_preferences (openvasd_connector_t *conn, GSList **params)
for (int i = 0; i < results_count; i++)
{
const char *id, *name, *desc;
char *defval = NULL;
char *defval = NULL, *param_type = NULL;
openvasd_param_t *param = NULL;
GType t;
JsonNode *node = NULL;
gboolean bool;
int val;
int val, mandatory = 0;
char buf[6];

json_reader_read_element (reader, i);
Expand Down Expand Up @@ -1254,30 +1344,36 @@ openvasd_parsed_scans_preferences (openvasd_connector_t *conn, GSList **params)
val = json_reader_get_int_value (reader);
g_snprintf (buf, sizeof (buf), "%d", val);
defval = g_strdup (buf);
param_type = g_strdup ("integer");
break;
case G_TYPE_STRING:
defval = g_strdup (json_reader_get_string_value (reader));
param_type = g_strdup ("string");
break;
case G_TYPE_BOOLEAN:
bool = json_reader_get_boolean_value (reader);
if (bool)
defval = g_strdup ("yes");
else
defval = g_strdup ("no");
param_type = g_strdup ("boolean");
break;
default:
g_warning ("%s: Unable to parse scan preferences.", __func__);
g_free (defval);
g_free (param_type);
json_reader_end_member (reader);
json_reader_end_element (reader);
continue;
}
json_reader_end_member (reader);
json_reader_end_element (reader);

param = openvasd_param_new (g_strdup (id), g_strdup (name),
g_strdup (defval), g_strdup (desc));
param =
openvasd_param_new (g_strdup (id), g_strdup (name), g_strdup (defval),
g_strdup (desc), g_strdup (param_type), mandatory);
g_free (defval);
g_free (param_type);
*params = g_slist_append (*params, param);
}

Expand Down
18 changes: 18 additions & 0 deletions openvasd/openvasd.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ openvasd_parsed_scans_preferences (openvasd_connector_t *, GSList **);
void
openvasd_param_free (openvasd_param_t *);

char *
openvasd_param_id (openvasd_param_t *);

char *
openvasd_param_name (openvasd_param_t *);

char *
openvasd_param_desc (openvasd_param_t *);

int
openvasd_param_mandatory (openvasd_param_t *);

char *
openvasd_param_type (openvasd_param_t *);

char *
openvasd_param_default (openvasd_param_t *);

/* Target builder */

typedef struct openvasd_target openvasd_target_t;
Expand Down

0 comments on commit c4569ea

Please sign in to comment.