Skip to content

Commit

Permalink
Merge pull request #581 from jjnicola/master-timeout
Browse files Browse the repository at this point in the history
Handle script timeout as script preference
  • Loading branch information
ArnoStiefvater authored Oct 18, 2021
2 parents 07f013d + 40fe289 commit a3ea083
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 82 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add functions for sentry integration. [#502](https://github.com/greenbone/gvm-libs/pull/502) [#506](https://github.com/greenbone/gvm-libs/pull/506)

### Changed
- Handle script timeout as script preference with ID 0 [#581](https://github.com/greenbone/gvm-libs/pull/581)

### Fixed
### Removed

Expand Down
34 changes: 0 additions & 34 deletions base/nvti.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ typedef struct nvti
GSList *prefs; /**< @brief Collection of NVT preferences */

// The following are not settled yet.
gint timeout; /**< @brief Default timeout time for this NVT */
gint category; /**< @brief The category, this NVT belongs to */
gchar *family; /**< @brief Family the NVT belongs to */
} nvti_t;
Expand Down Expand Up @@ -1212,20 +1211,6 @@ nvti_pref (const nvti_t *n, guint p)
return n ? g_slist_nth_data (n->prefs, p) : NULL;
}

/**
* @brief Get the timeout for this NVT.
*
* @param n The NVT Info structure of which the timeout should
* be returned.
*
* @return The timeout integer number. A value <= 0 indicates it is not set.
*/
gint
nvti_timeout (const nvti_t *n)
{
return n ? n->timeout : -1;
}

/**
* @brief Get the category for this NVT.
*
Expand Down Expand Up @@ -1808,25 +1793,6 @@ nvti_set_family (nvti_t *n, const gchar *family)
return 0;
}

/**
* @brief Set the timeout of a NVT Info.
*
* @param n The NVT Info structure.
*
* @param timeout The timeout to set. Values <= 0 will indicate it is not set.
*
* @return 0 for success. Anything else indicates an error.
*/
int
nvti_set_timeout (nvti_t *n, const gint timeout)
{
if (!n)
return -1;

n->timeout = timeout;
return 0;
}

/**
* @brief Set the category type of a NVT Info.
*
Expand Down
2 changes: 2 additions & 0 deletions base/nvti.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <glib.h>

#define NVTPREF_TIMEOUT_ID 0

typedef struct nvtpref nvtpref_t;

nvtpref_t *
Expand Down
20 changes: 0 additions & 20 deletions base/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,3 @@ prefs_dump (void)
}
}
}

/**
* @brief Returns the timeout defined by the client or 0 if none was set.
*
* @param oid OID of NVT to ask timeout value of.
*
* @return 0 if no timeout for the NVT oid was found, timeout in seconds
* otherwise.
*/
int
prefs_nvt_timeout (const char *oid)
{
char *pref_name = g_strdup_printf ("timeout.%s", oid);
const char *val = prefs_get (pref_name);
int timeout = (val ? atoi (val) : 0);

g_free (pref_name);

return timeout;
}
6 changes: 2 additions & 4 deletions util/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,6 @@ redis_get_nvt_all (kb_t kb, const char *oid)
nvti_add_refs (nvti, "bid", rep->element[NVT_BIDS_POS]->str, "");
nvti_add_refs (nvti, NULL, rep->element[NVT_XREFS_POS]->str, "");
nvti_set_category (nvti, atoi (rep->element[NVT_CATEGORY_POS]->str));
nvti_set_timeout (nvti, atoi (rep->element[NVT_TIMEOUT_POS]->str));
nvti_set_family (nvti, rep->element[NVT_FAMILY_POS]->str);
nvti_set_name (nvti, rep->element[NVT_NAME_POS]->str);

Expand Down Expand Up @@ -1563,13 +1562,12 @@ redis_add_nvt (kb_t kb, const nvti_t *nvt, const char *filename)

kbr = redis_kb (kb);
rep = redis_cmd (
kbr, "RPUSH nvt:%s %s %s %s %s %s %s %s %s %s %s %s %d %d %s %s",
kbr, "RPUSH nvt:%s %s %s %s %s %s %s %s %s %s %s %s %d %s %s",
nvti_oid (nvt), filename, nvti_required_keys (nvt) ?: "",
nvti_mandatory_keys (nvt) ?: "", nvti_excluded_keys (nvt) ?: "",
nvti_required_udp_ports (nvt) ?: "", nvti_required_ports (nvt) ?: "",
nvti_dependencies (nvt) ?: "", nvti_tag (nvt) ?: "", cves ?: "", bids ?: "",
xrefs ?: "", nvti_category (nvt), nvti_timeout (nvt), nvti_family (nvt),
nvti_name (nvt));
xrefs ?: "", nvti_category (nvt), nvti_family (nvt), nvti_name (nvt));
g_free (cves);
g_free (bids);
g_free (xrefs);
Expand Down
1 change: 0 additions & 1 deletion util/kb.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ enum kb_nvt_pos
NVT_BIDS_POS,
NVT_XREFS_POS,
NVT_CATEGORY_POS,
NVT_TIMEOUT_POS,
NVT_FAMILY_POS,
NVT_NAME_POS,
NVT_TIMESTAMP_POS,
Expand Down
20 changes: 0 additions & 20 deletions util/nvticache.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,26 +410,6 @@ nvticache_get_category (const char *oid)
return category;
}

/**
* @brief Get the Timeout from a plugin OID.
*
* @param[in] oid OID to match.
*
* @return Timeout matching OID, -1 otherwise.
*/
int
nvticache_get_timeout (const char *oid)
{
int timeout;
char *timeout_s;

assert (cache_kb);
timeout_s = kb_nvt_get (cache_kb, oid, NVT_TIMEOUT_POS);
timeout = atoi (timeout_s);
g_free (timeout_s);
return timeout;
}

/**
* @brief Get the name from a plugin OID.
*
Expand Down
3 changes: 0 additions & 3 deletions util/nvticache.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ nvticache_get_required_udp_ports (const char *);
int
nvticache_get_category (const char *);

int
nvticache_get_timeout (const char *);

char *
nvticache_get_dependencies (const char *);

Expand Down

0 comments on commit a3ea083

Please sign in to comment.