Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify osp_get_vts_version() #357

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
- Improve validation in is_hostname [#353](https://github.com/greenbone/gvm-libs/pull/353)
- Use get_vts instead of get_version to get the feed version is osp_get_vts_version(). [#357](https://github.com/greenbone/gvm-libs/pull/357)

### Fixed
- Fix is_cidr_block(). [#322](https://github.com/greenbone/gvm-libs/pull/322)
Expand Down
40 changes: 30 additions & 10 deletions osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,38 +331,51 @@ osp_get_version (osp_connection_t *connection, char **s_name, char **s_version,
*
* @param[in] connection Connection to an OSP server.
* @param[out] vts_version Parsed scanner version.
* @param[out] error Pointer to error, if any.
*
* @return 0 if success, 1 if error.
*/
int
osp_get_vts_version (osp_connection_t *connection, char **vts_version)
osp_get_vts_version (osp_connection_t *connection, char **vts_version,
char **error)
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
{
entity_t entity, vts, version;
entity_t entity, vts;
const char *version;
const char *status, *status_text;
osp_get_vts_opts_t get_vts_opts;

if (!connection)
return 1;

if (osp_send_command (connection, &entity, "<get_version/>"))
get_vts_opts.filter = NULL;
get_vts_opts.version_only = 1;
if (osp_get_vts_ext (connection, get_vts_opts, &entity))
return 1;

vts = entity_child (entity, "vts");
if (!vts)
status = entity_attribute (entity, "status");

if (status != NULL && !strcmp (status, "400"))
{
g_warning ("%s: element VTS missing.", __func__);
status_text = entity_attribute (entity, "status_text");
g_debug ("%s: %s - %s.", __func__, status, status_text);
if (error)
*error = g_strdup (status_text);
free_entity (entity);
return 1;
}

version = entity_child (vts, "version");
if (!version)
vts = entity_child (entity, "vts");
if (!vts)
{
g_warning ("%s: element VERSION missing.", __func__);
g_warning ("%s: element VTS missing.", __func__);
free_entity (entity);
return 1;
}

version = entity_attribute (vts, "vts_version");

if (vts_version)
*vts_version = g_strdup (entity_text (version));
*vts_version = g_strdup (version);

free_entity (entity);
return 0;
Expand Down Expand Up @@ -410,6 +423,13 @@ osp_get_vts_ext (osp_connection_t *connection, osp_get_vts_opts_t opts,
if (vts == NULL)
return 1;

if (opts.version_only == 1)
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
{
if (osp_send_command (connection, vts, "<get_vts version_only='1'/>"))
return 1;
return 0;
}

if (opts.filter)
{
if (osp_send_command (connection, vts, "<get_vts filter='%s'/>",
Expand Down
5 changes: 3 additions & 2 deletions osp/osp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ osp_get_version (osp_connection_t *, char **, char **, char **, char **,
char **, char **);

int
osp_get_vts_version (osp_connection_t *, char **);
osp_get_vts_version (osp_connection_t *, char **, char **error);

int
osp_get_vts (osp_connection_t *, entity_t *);

typedef struct
{
char *filter; ///< the filter to apply for a vt sub-selection.
char *filter; ///< the filter to apply for a vt sub-selection.
int version_only; ///< if get only feed info or the vt collection
} osp_get_vts_opts_t;

int
Expand Down