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

Add nasl function to get the host kb index. #530

Merged
merged 1 commit into from
Jun 16, 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 @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Extend script_get_preference() to get the value by id. [#470](https://github.com/greenbone/openvas/pull/470)
- Add extended environmental variables info to greenbone-nvt-sync help text. [#488](https://github.com/greenbone/openvas/pull/488)
- Extend nasl functions which generate results with optional "uri" parameter [#526](https://github.com/greenbone/openvas/pull/526)
- Add nasl function to get the host kb index. [#530](https://github.com/greenbone/openvas/pull/530)

### Changed
- The logging of the NASL internal regexp functions was extended to include the pattern in case of a failed regcomp(). [#397](https://github.com/greenbone/openvas/pull/397)
Expand Down
1 change: 1 addition & 0 deletions nasl/nasl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static init_func libfuncs[] = {
{"set_kb_item", set_kb_item},
{"get_kb_item", get_kb_item},
{"get_kb_list", get_kb_list},
{"get_host_kb_index", get_host_kb_index},
{"security_message", security_message},
{"log_message", log_message},
{"error_message", error_message},
Expand Down
27 changes: 27 additions & 0 deletions nasl/nasl_scanner_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,33 @@ get_kb_item (lex_ctxt *lexic)
return retc;
}

/**
* @brief Get the kb index of the host running the current script.
*
* @param[in] lexic NASL lexer.
*
* @return lex cell containing the host kb index value as positive integer.
* NULL otherwise
*/
tree_cell *
get_host_kb_index (lex_ctxt *lexic)
{
struct script_infos *script_infos = lexic->script_infos;
int val;
tree_cell *retc;

val = kb_get_kb_index (script_infos->key);
if (val >= 0)
{
retc = alloc_typed_cell (CONST_INT);
retc->x.i_val = val;
}
else
return NULL;

return retc;
}

tree_cell *
replace_kb_item (lex_ctxt *lexic)
{
Expand Down
3 changes: 3 additions & 0 deletions nasl/nasl_scanner_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ safe_checks (lex_ctxt *);
tree_cell *
get_script_oid (lex_ctxt *);

tree_cell *
get_host_kb_index (lex_ctxt *);

tree_cell *
get_kb_item (lex_ctxt *);

Expand Down