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

Check for opts params in osp_get_performance_ext() #268

Merged
merged 5 commits into from
Sep 26, 2019
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- A function to get an osp scan status and a enum type for the different status [#259](https://github.com/greenbone/gvm-libs/pull/259)
- API functions for NVTI to handle timestamps [#261](https://github.com/greenbone/gvm-libs/pull/261)
- API function for NVTI to add a single tag [#263](https://github.com/greenbone/gvm-libs/pull/263)
- Add osp_get_performance() function. [#262](https://github.com/greenbone/gvm-libs/pull/262)
- Add osp_get_performance_ext() function. [#262](https://github.com/greenbone/gvm-libs/pull/262)

### Changed
- Change the default path to the redis socket to /run/redis/redis.sock [#256](https://github.com/greenbone/gvm-libs/pull/256)
- Handle EAI_AGAIN in gvm_host_reverse_lookup() IPv6 case and function refactor. [#229](https://github.com/greenbone/gvm-libs/pull/229)
- Prevent g_strsplit to be called with NULL. [#238](https://github.com/greenbone/gvm-libs/pull/238)
- Timestamps for NVTI modification date and creation date now internally handled as seconds since epoch. [#265](https://github.com/greenbone/gvm-libs/pull/265)
- The tag cvss_base is not added to redis anymore. [#267](https://github.com/greenbone/gvm-libs/pull/267)
- Functions in osp.c with error as argument, will set the error if the connection is missing. [#268](https://github.com/greenbone/gvm-libs/pull/268)

### Fixed
- Prevent g_strsplit to be called with NULL. [#238](https://github.com/greenbone/gvm-libs/pull/238)
Expand Down
75 changes: 64 additions & 11 deletions osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,36 @@ osp_delete_scan (osp_connection_t *connection, const char *scan_id)
* @param[out] graph Graphic base64 encoded.
* @param[out] error Pointer to error, if any.
*
* @return 0 if success, 1 if error.
* @return 0 if success, -1 if error.
*/
int
osp_get_performance_ext (osp_connection_t *connection,
osp_get_performance_opts_t opts,
char **graph, char **error)
osp_get_performance_opts_t opts, char **graph,
char **error)
{
entity_t entity;
int rc;
time_t now;

if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send get_performance command "
"to scanner. Not valid connection");
return -1;
}

time (&now);

if (!opts.titles || !strcmp (opts.titles, "") || opts.start < 0
|| opts.start > now || opts.end < 0 || opts.end > now)
{
if (error)
*error = g_strdup ("Couldn't send get_performance command "
"to scanner. Bad or missing parameters.");
return -1;
}

assert (connection);
rc = osp_send_command (connection, &entity,
"<get_performance start='%d' "
"end='%d' titles='%s'/>",
Expand All @@ -478,11 +497,11 @@ osp_get_performance_ext (osp_connection_t *connection,
{
if (error)
*error = g_strdup ("Couldn't send get_performance command to scanner");
return 1;
return -1;
}

if (graph && entity_text (entity) && strcmp (entity_text (entity), "\0"))
*graph = g_strdup (entity_text (entity));
*graph = g_strdup (entity_text (entity));
else
{
const char *text = entity_attribute (entity, "status_text");
Expand All @@ -491,7 +510,7 @@ osp_get_performance_ext (osp_connection_t *connection,
if (error)
*error = g_strdup (text);
free_entity (entity);
return 1;
return -1;
}

free_entity (entity);
Expand All @@ -515,7 +534,14 @@ osp_get_scan_status_ext (osp_connection_t *connection,
int rc;
osp_scan_status_t status = OSP_SCAN_STATUS_ERROR;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send get_scans command "
"to scanner. Not valid connection");
return status;
}

assert (opts.scan_id);
rc = osp_send_command (connection, &entity,
"<get_scans scan_id='%s'"
Expand Down Expand Up @@ -576,7 +602,13 @@ osp_get_scan_pop (osp_connection_t *connection, const char *scan_id,
int progress;
int rc;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send get_scan command "
"to scanner. Not valid connection");
return -1;
}
assert (scan_id);
rc = osp_send_command (connection, &entity,
"<get_scans scan_id='%s'"
Expand Down Expand Up @@ -649,7 +681,13 @@ osp_stop_scan (osp_connection_t *connection, const char *scan_id, char **error)
entity_t entity;
int rc;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send stop_scan command "
"to scanner. Not valid connection");
return -1;
}
assert (scan_id);
rc = osp_send_command (connection, &entity, "<stop_scan scan_id='%s'/>",
scan_id);
Expand Down Expand Up @@ -726,7 +764,14 @@ osp_start_scan (osp_connection_t *connection, const char *target,
int status;
int rc;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send start_scan command "
"to scanner. Not valid connection");
return -1;
}

assert (target);
/* Construct options string. */
if (options)
Expand Down Expand Up @@ -904,6 +949,14 @@ osp_start_scan_ext (osp_connection_t *connection,
char filename[] = "/tmp/osp-cmd-XXXXXX";
int fd;

if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send start_scan command "
"to scanner. Not valid connection");
return -1;
}

fd = mkstemp (filename);
FILE *file = fdopen (fd, "w");

Expand Down