OpenVAS Scanner 23.32.3
nasl_scanner_glue.h File Reference
#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_scanner_glue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellscript_timeout (lex_ctxt *)
 Add timeout preference to VT preferences.
tree_cellscript_oid (lex_ctxt *)
tree_cellscript_cve_id (lex_ctxt *)
tree_cellscript_xref (lex_ctxt *)
 Add a cross reference to the meta data.
tree_cellscript_tag (lex_ctxt *)
tree_cellscript_name (lex_ctxt *)
tree_cellscript_version (lex_ctxt *)
tree_cellscript_copyright (lex_ctxt *)
tree_cellscript_category (lex_ctxt *)
tree_cellscript_family (lex_ctxt *)
tree_cellscript_dependencies (lex_ctxt *)
tree_cellscript_require_keys (lex_ctxt *)
tree_cellscript_mandatory_keys (lex_ctxt *)
tree_cellscript_exclude_keys (lex_ctxt *)
tree_cellscript_require_ports (lex_ctxt *)
tree_cellscript_require_udp_ports (lex_ctxt *)
tree_cellnasl_get_preference (lex_ctxt *)
tree_cellscript_add_preference (lex_ctxt *)
tree_cellscript_get_preference (lex_ctxt *)
 Get a preferences of the current script.
tree_cellscript_get_preference_file_content (lex_ctxt *)
tree_cellscript_get_preference_file_location (lex_ctxt *)
tree_cellsafe_checks (lex_ctxt *)
tree_cellget_script_oid (lex_ctxt *)
 Return the OID of the current script.
tree_cellget_host_kb_index (lex_ctxt *)
 Get the kb index of the host running the current script.
tree_cellget_kb_item (lex_ctxt *)
tree_cellget_kb_list (lex_ctxt *)
tree_cellset_kb_item (lex_ctxt *)
 Set a kb item.
tree_cellreplace_kb_item (lex_ctxt *)
tree_cellsecurity_message (lex_ctxt *)
 Send a security message to the client.
tree_celllog_message (lex_ctxt *)
tree_cellerror_message2 (lex_ctxt *)
tree_cellnasl_scanner_get_port (lex_ctxt *)
tree_cellnasl_scanner_add_port (lex_ctxt *)
tree_cellnasl_scanner_status (lex_ctxt *)
tree_cellnasl_vendor_version (lex_ctxt *)
tree_cellnasl_update_table_driven_lsc_data (lex_ctxt *)
 Communicate to the parent process that LSC data is ready for use in the host kb.
tree_cellnasl_notus (lex_ctxt *)
 Directly runs a LSC with the given package list and OS release.
tree_cellnasl_notus_error (lex_ctxt *)
 Get the last Notus error as string.
tree_cellsecurity_notus (lex_ctxt *lexic)

Function Documentation

◆ error_message2()

tree_cell * error_message2 ( lex_ctxt * lexic)

Definition at line 1146 of file nasl_scanner_glue.c.

1147{
1149}
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Definition plugutils.c:806
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition plugutils.c:813

References post_error(), proto_post_error(), and security_something().

Here is the call graph for this function:

◆ get_host_kb_index()

tree_cell * get_host_kb_index ( lex_ctxt * lexic)

Get the kb index of the host running the current script.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the host kb index value as positive integer. NULL otherwise

Definition at line 765 of file nasl_scanner_glue.c.

766{
767 struct script_infos *script_infos = lexic->script_infos;
768 int val;
769 tree_cell *retc;
770
771 val = kb_get_kb_index (script_infos->key);
772 if (val >= 0)
773 {
775 retc->x.i_val = val;
776 }
777 else
778 return NULL;
779
780 return retc;
781}
const char * val
Definition nasl_init.c:440
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ CONST_INT
Definition nasl_tree.h:79
struct TC tree_cell
long int i_val
Definition nasl_tree.h:104
union TC::@332262321161220155002104006201360276211317150140 x
struct script_infos * script_infos

References alloc_typed_cell(), CONST_INT, TC::i_val, script_infos::key, struct_lex_ctxt::script_infos, val, and TC::x.

Here is the call graph for this function:

◆ get_kb_item()

tree_cell * get_kb_item ( lex_ctxt * lexic)

Definition at line 713 of file nasl_scanner_glue.c.

714{
715 struct script_infos *script_infos = lexic->script_infos;
716
717 char *kb_entry = get_str_var_by_num (lexic, 0);
718 char *val;
719 tree_cell *retc;
720 int type = -1, single = get_int_var_by_num (lexic, 1, 0);
721 size_t len;
722
723 if (kb_entry == NULL)
724 return NULL;
725
726 val = plug_get_key (script_infos, kb_entry, &type, &len, !!single);
727
728 if (val == NULL && type == -1)
729 return NULL;
730
732 if (type == KB_TYPE_INT)
733 {
734 retc->x.i_val = GPOINTER_TO_SIZE (val);
735 g_free (val);
736 return retc;
737 }
738 else
739 {
740 retc->type = CONST_DATA;
741 if (val != NULL)
742 {
743 retc->size = len;
744 retc->x.str_val = val;
745 }
746 else
747 {
748 retc->size = 0;
749 retc->x.str_val = NULL;
750 }
751 }
752
753 return retc;
754}
char * get_str_var_by_num(lex_ctxt *, int)
Definition nasl_var.c:1108
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition nasl_var.c:1094
uint8_t len
@ CONST_DATA
Definition nasl_tree.h:82
void * plug_get_key(struct script_infos *args, char *name, int *type, size_t *len, int single)
Get values from a kb under the given key name.
Definition plugutils.c:1226
int size
Definition nasl_tree.h:99
char * str_val
Definition nasl_tree.h:103
short type
Definition nasl_tree.h:95

References alloc_typed_cell(), CONST_DATA, CONST_INT, get_int_var_by_num(), get_str_var_by_num(), TC::i_val, len, plug_get_key(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, TC::type, val, and TC::x.

Here is the call graph for this function:

◆ get_kb_list()

tree_cell * get_kb_list ( lex_ctxt * lexic)

Definition at line 652 of file nasl_scanner_glue.c.

653{
654 struct script_infos *script_infos = lexic->script_infos;
655 kb_t kb = plug_get_kb (script_infos);
656 char *kb_mask = get_str_var_by_num (lexic, 0);
657 tree_cell *retc;
658 int num_elems = 0;
659 nasl_array *a;
660 struct kb_item *res, *top;
661
662 if (kb_mask == NULL)
663 {
664 nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
665 return NULL;
666 }
667
668 if (kb == NULL)
669 return NULL;
670
672 retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
673
674 if (strchr (kb_mask, '*'))
675 top = res = kb_item_get_pattern (kb, kb_mask);
676 else
677 top = res = kb_item_get_all (kb, kb_mask);
678
679 while (res != NULL)
680 {
682 bzero (&v, sizeof (v));
683
684 if (res->type == KB_TYPE_INT)
685 {
686 v.var_type = VAR2_INT;
687 v.v.v_int = res->v_int;
688 add_var_to_array (a, res->name, &v);
689 num_elems++;
690 }
691 else if (res->type == KB_TYPE_STR)
692 {
694 v.v.v_str.s_val = (unsigned char *) res->v_str;
695 v.v.v_str.s_siz = strlen (res->v_str);
696 add_var_to_array (a, res->name, &v);
697 num_elems++;
698 }
699 res = res->next;
700 }
701
702 kb_item_free (top);
703
704 if (num_elems == 0)
705 {
706 deref_cell (retc);
707 return FAKE_CELL;
708 }
709 return retc;
710}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
void deref_cell(tree_cell *c)
Definition nasl_tree.c:178
@ DYN_ARRAY
Definition nasl_tree.h:90
#define FAKE_CELL
Definition nasl_tree.h:110
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition nasl_var.c:1277
struct st_a_nasl_var anon_nasl_var
struct st_nasl_array nasl_array
@ VAR2_DATA
Definition nasl_var.h:18
@ VAR2_INT
Definition nasl_var.h:16
kb_t plug_get_kb(struct script_infos *args)
Definition plugutils.c:1152
void * ref_val
Definition nasl_tree.h:105
nasl_string_t v_str
Definition nasl_var.h:47
union st_a_nasl_var::@154137074032032170165360023270032033276061363156 v
long int v_int
Definition nasl_var.h:48
unsigned char * s_val
Definition nasl_var.h:26

References add_var_to_array(), alloc_typed_cell(), deref_cell(), DYN_ARRAY, FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_get_kb(), TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, struct_lex_ctxt::script_infos, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function:

◆ get_script_oid()

tree_cell * get_script_oid ( lex_ctxt * lexic)

Return the OID of the current script.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the OID as a string.

Definition at line 634 of file nasl_scanner_glue.c.

635{
636 const char *oid = lexic->oid;
637 tree_cell *retc = NULL;
638
639 if (oid)
640 {
642 retc->x.str_val = g_strdup (oid);
643 retc->size = strlen (oid);
644 }
645
646 return retc;
647}
const char * oid
const char * oid

References alloc_typed_cell(), CONST_DATA, oid, struct_lex_ctxt::oid, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ log_message()

tree_cell * log_message ( lex_ctxt * lexic)

Definition at line 1138 of file nasl_scanner_glue.c.

1139{
1141}
void proto_post_log(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Post a log message.
Definition plugutils.c:779
void post_log_with_uri(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Post a log message about a tcp port with a uri.
Definition plugutils.c:799

References post_log_with_uri(), proto_post_log(), and security_something().

Here is the call graph for this function:

◆ nasl_get_preference()

tree_cell * nasl_get_preference ( lex_ctxt * lexic)

Definition at line 1152 of file nasl_scanner_glue.c.

1153{
1154 tree_cell *retc;
1155 char *name;
1156 const char *value;
1157
1158 name = get_str_var_by_num (lexic, 0);
1159 if (name == NULL)
1160 {
1161 nasl_perror (lexic, "get_preference: no name\n");
1162 return NULL;
1163 }
1164 value = prefs_get (name);
1165 if (value == NULL)
1166 return NULL;
1167
1169 retc->x.str_val = strdup (value);
1170 retc->size = strlen (value);
1171 return retc;
1172}
const char * name
Definition nasl_init.c:439

References alloc_typed_cell(), CONST_DATA, get_str_var_by_num(), name, nasl_perror(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_notus()

tree_cell * nasl_notus ( lex_ctxt * lexic)

Directly runs a LSC with the given package list and OS release.

This function runs a Notus scan using the provided package list and OS release. In case of success, it returns a list of Notus results in a JSON-like format. If an error occurs, it returns NULL and sets the notus_err variable to the appropriate error code. The error can be gathered using the notus_error function.

NASL Function: notus\n
NASL Named Parameters:\n
  • pkg_list String containing the gathered package list.
  • product The OS release.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
List of Notus results in a JSON-like format, NULL on error.

Definition at line 1263 of file nasl_scanner_glue.c.

1264{
1265 tree_cell *retc;
1266 char *response;
1267 advisories_t *advisories = NULL;
1268 anon_nasl_var element;
1269 char *pkg_list = get_str_var_by_name (lexic, "pkg_list");
1270 char *product = get_str_var_by_name (lexic, "product");
1271
1272 if (product == NULL || pkg_list == NULL)
1273 {
1274 g_warning ("%s: Missing data for running LSC", __func__);
1275 notus_err = -1;
1276 return NULL;
1277 }
1278
1279 response = notus_get_response (pkg_list, product);
1280
1281 if (!response)
1282 {
1283 g_warning ("%s: Unable to get the response", __func__);
1284 notus_err = -2;
1285
1286 return NULL;
1287 }
1288
1289 advisories = process_notus_response (response, strlen (response));
1290 g_free (response);
1291
1292 retc = alloc_typed_cell (DYN_ARRAY);
1293 retc->x.ref_val = g_malloc0 (sizeof (nasl_array));
1294
1295 // Process the advisories, generate results and store them in the kb
1296 for (size_t i = 0; i < advisories->count; i++)
1297 {
1299 anon_nasl_var vulnerable_pkgs, oid;
1300
1301 memset (&element, 0, sizeof (element));
1302 element.var_type = VAR2_ARRAY;
1303
1304 memset (&vulnerable_pkgs, 0, sizeof (vulnerable_pkgs));
1305 vulnerable_pkgs.var_type = VAR2_ARRAY;
1306
1307 memset (&oid, 0, sizeof (oid));
1308 oid.var_type = VAR2_STRING;
1309 oid.v.v_str.s_val = (unsigned char *) advisory->oid;
1310 oid.v.v_str.s_siz = strlen (advisory->oid);
1311
1312 for (size_t j = 0; j < advisory->count; j++)
1313 {
1314 vuln_pkg_t *pkg = advisory->pkgs[j];
1315 anon_nasl_var name, installed, vul_pkg;
1316 memset (&name, 0, sizeof (name));
1317 memset (&installed, 0, sizeof (installed));
1318 memset (&vul_pkg, 0, sizeof (vul_pkg));
1319 name.var_type = VAR2_STRING;
1320 installed.var_type = VAR2_STRING;
1321 vul_pkg.var_type = VAR2_ARRAY;
1322 name.v.v_str.s_val = (unsigned char *) pkg->pkg_name;
1323 name.v.v_str.s_siz = strlen (pkg->pkg_name);
1324 installed.v.v_str.s_val = (unsigned char *) pkg->install_version;
1325 installed.v.v_str.s_siz = strlen (pkg->install_version);
1326
1327 if (pkg->type == RANGE)
1328 {
1329 anon_nasl_var range, start, end;
1330 memset (&range, 0, sizeof (range));
1331 range.var_type = VAR2_ARRAY;
1332
1333 memset (&start, 0, sizeof (start));
1334 start.var_type = VAR2_STRING;
1335 start.v.v_str.s_val = (unsigned char *) pkg->range->start;
1336 start.v.v_str.s_siz = strlen (pkg->range->start);
1337 add_var_to_array (&range.v.v_arr, "start", &start);
1338
1339 memset (&end, 0, sizeof (end));
1340 end.var_type = VAR2_STRING;
1341 end.v.v_str.s_val = (unsigned char *) pkg->range->stop;
1342 end.v.v_str.s_siz = strlen (pkg->range->stop);
1343 add_var_to_array (&range.v.v_arr, "end", &end);
1344 add_var_to_array (&vul_pkg.v.v_arr, "fixed", &range);
1345 }
1346 else if (pkg->type == SINGLE)
1347 {
1348 anon_nasl_var single, version, specifier;
1349
1350 memset (&single, 0, sizeof (single));
1351 single.var_type = VAR2_ARRAY;
1352
1353 memset (&version, 0, sizeof (version));
1354 version.var_type = VAR2_STRING;
1355 version.v.v_str.s_val = (unsigned char *) pkg->version->version;
1356 version.v.v_str.s_siz = strlen (pkg->version->version);
1357 add_var_to_array (&single.v.v_arr, "version", &version);
1358
1359 memset (&specifier, 0, sizeof (specifier));
1360 specifier.var_type = VAR2_STRING;
1361 specifier.v.v_str.s_val =
1362 (unsigned char *) pkg->version->specifier;
1363 specifier.v.v_str.s_siz = strlen (pkg->version->specifier);
1364 add_var_to_array (&single.v.v_arr, "specifier", &specifier);
1365
1366 add_var_to_array (&vul_pkg.v.v_arr, "fixed", &single);
1367 }
1368 else
1369 {
1370 g_warning ("%s: Unknown fixed version type for advisory %s",
1371 __func__, advisory->oid);
1373 notus_err = -3;
1374 deref_cell (retc);
1375
1376 return NULL;
1377 }
1378 add_var_to_array (&vul_pkg.v.v_arr, "name", &name);
1379 add_var_to_array (&vul_pkg.v.v_arr, "installed", &installed);
1380 add_var_to_list (&vulnerable_pkgs.v.v_arr, j, &vul_pkg);
1381 }
1382
1383 add_var_to_array (&element.v.v_arr, "oid", &oid);
1384 add_var_to_array (&element.v.v_arr, "vulnerable_packages",
1385 &vulnerable_pkgs);
1386 add_var_to_list (retc->x.ref_val, i, &element);
1387 }
1388
1390
1391 return retc;
1392}
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1118
static int notus_err
Error code for Notus.
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition nasl_var.c:1245
@ VAR2_STRING
Definition nasl_var.h:17
@ VAR2_ARRAY
Definition nasl_var.h:19
advisory_t ** advisories
vuln_pkg_t * pkgs[100]
nasl_array v_arr
Definition nasl_var.h:49
fixed_version_t * version
enum fixed_type type
version_range_t * range
char * notus_get_response(const char *pkg_list, const char *os)
Sent the installed package list and OS to notus.
advisories_t * process_notus_response(const gchar *resp, const size_t len)
Process a json object which contains advisories and vulnerable packages.
void advisories_free(advisories_t *advisories)
Free()'s an advisories.
struct advisories advisories_t
@ SINGLE
@ RANGE
struct advisory advisory_t
struct vulnerable_pkg vuln_pkg_t

References add_var_to_array(), add_var_to_list(), advisories::advisories, advisories_free(), alloc_typed_cell(), advisories::count, advisory::count, deref_cell(), DYN_ARRAY, get_str_var_by_name(), vulnerable_pkg::install_version, name, notus_err, notus_get_response(), advisory::oid, oid, vulnerable_pkg::pkg_name, advisory::pkgs, process_notus_response(), RANGE, vulnerable_pkg::range, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, SINGLE, fixed_version::specifier, version_range::start, version_range::stop, vulnerable_pkg::type, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_STRING, st_a_nasl_var::var_type, fixed_version::version, vulnerable_pkg::version, and TC::x.

Here is the call graph for this function:

◆ nasl_notus_error()

tree_cell * nasl_notus_error ( lex_ctxt * lexic)

Get the last Notus error as string.

NASL Function: notus_error\n
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
Error message as a string.

Definition at line 1404 of file nasl_scanner_glue.c.

1405{
1406 tree_cell *retc;
1407 char *notus_err_str;
1408 (void) lexic;
1409
1410 switch (notus_err)
1411 {
1412 case -1:
1413 notus_err_str = strdup ("Missing data for running LSC");
1414 break;
1415 case -2:
1416 notus_err_str = strdup ("Unable to get the response");
1417 break;
1418 case -3:
1419 notus_err_str = strdup ("Unknown fixed version type for advisory");
1420 break;
1421 default:
1422 return NULL;
1423 }
1424
1425 retc = alloc_typed_cell (CONST_STR);
1426 retc->x.str_val = notus_err_str;
1427 retc->size = strlen (notus_err_str);
1428
1429 return retc;
1430}
@ CONST_STR
Definition nasl_tree.h:80

References alloc_typed_cell(), CONST_STR, notus_err, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_scanner_add_port()

tree_cell * nasl_scanner_add_port ( lex_ctxt * lexic)

Definition at line 1479 of file nasl_scanner_glue.c.

1480{
1481 struct script_infos *script_infos = lexic->script_infos;
1482
1483 int port = get_int_var_by_name (lexic, "port", -1);
1484 char *proto = get_str_var_by_name (lexic, "proto");
1485
1486 if (port >= 0)
1487 {
1488 scanner_add_port (script_infos, port, proto ? proto : "tcp");
1489 }
1490
1491 return FAKE_CELL;
1492}
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition nasl_var.c:1101
void scanner_add_port(struct script_infos *args, int port, char *proto)
Definition plugutils.c:1146

References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), scanner_add_port(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ nasl_scanner_get_port()

tree_cell * nasl_scanner_get_port ( lex_ctxt * lexic)

If the plugin is a port scanner, it needs to report the list of open ports back to openvas scanner, and it also needs to know which ports are to be scanned.

Definition at line 1439 of file nasl_scanner_glue.c.

1440{
1441 tree_cell *retc;
1442 int idx = get_int_var_by_num (lexic, 0, -1);
1443 const char *prange = prefs_get ("port_range");
1444 static int num = 0;
1445 static u_short *ports = NULL;
1446
1447 if (prange == NULL)
1448 return NULL;
1449
1450 if (idx < 0)
1451 {
1452 nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1453 nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1454 nasl_perror (lexic,
1455 "Where <num> should be 0 the first time you call it\n");
1456 return NULL;
1457 }
1458
1459 if (ports == NULL)
1460 {
1461 ports = (u_short *) getpts ((char *) prange, &num);
1462 if (ports == NULL)
1463 {
1464 return NULL;
1465 }
1466 }
1467
1468 if (idx >= num)
1469 {
1470 return NULL;
1471 }
1472
1473 retc = alloc_typed_cell (CONST_INT);
1474 retc->x.i_val = ports[idx];
1475 return retc;
1476}
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Definition network.c:2296

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), getpts(), TC::i_val, nasl_perror(), and TC::x.

Here is the call graph for this function:

◆ nasl_scanner_status()

tree_cell * nasl_scanner_status ( lex_ctxt * lexic)

Definition at line 1495 of file nasl_scanner_glue.c.

1496{
1497 /* Kept for backward compatibility. */
1498 (void) lexic;
1499 return FAKE_CELL;
1500}

References FAKE_CELL.

◆ nasl_update_table_driven_lsc_data()

tree_cell * nasl_update_table_driven_lsc_data ( lex_ctxt * lexic)

Communicate to the parent process that LSC data is ready for use in the host kb.

NASL Function: update_table_driven_lsc_data\n
NASL Named Parameters:\n
  • pkg_list String containing the gathered package list.
  • os_release The OS release.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
NULL

Definition at line 1203 of file nasl_scanner_glue.c.

1204{
1205 struct script_infos *script_infos = lexic->script_infos;
1206 ipc_data_t *lsc = NULL;
1207 const char *json = NULL;
1208 gchar *pkg_list = get_str_var_by_name (lexic, "pkg_list");
1209 gchar *os_version = get_str_var_by_name (lexic, "os_release");
1210
1211 if (os_version == NULL || pkg_list == NULL)
1212 {
1213 g_warning ("%s: Missing data for running LSC", __func__);
1214 return NULL;
1215 }
1216
1217 plug_set_key (script_infos, "ssh/login/package_list_notus", ARG_STRING,
1218 pkg_list);
1219 plug_set_key (script_infos, "ssh/login/release_notus", ARG_STRING,
1220 os_version);
1221
1222 lsc = ipc_data_type_from_lsc (TRUE);
1223 if (!lsc)
1224 return NULL;
1225
1226 json = ipc_data_to_json (lsc);
1227 ipc_data_destroy (&lsc);
1228 if (ipc_send (lexic->script_infos->ipc_context, IPC_MAIN, json, strlen (json))
1229 < 0)
1230 g_warning ("Unable to send the package list for LSC to the host process");
1231
1232 g_free ((void *) json);
1233 return NULL;
1234}
int ipc_send(struct ipc_context *context, enum ipc_relation to, const char *msg, size_t len)
sends given msg to the target based on the given context
Definition ipc.c:46
@ IPC_MAIN
Definition ipc.h:18
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
ipc_data_t * ipc_data_type_from_lsc(gboolean data_ready)
initializes ipc_data for the table driven LSC.
const char * ipc_data_to_json(ipc_data_t *data)
transforms ipc_data to a json string
struct ipc_data ipc_data_t
Definition ipc_openvas.h:23
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
Definition plugutils.c:1055
#define ARG_STRING
Definition plugutils.h:19
struct ipc_context * ipc_context
Definition scanneraux.h:31

References ARG_STRING, get_str_var_by_name(), script_infos::ipc_context, ipc_data_destroy(), ipc_data_to_json(), ipc_data_type_from_lsc(), IPC_MAIN, ipc_send(), plug_set_key(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ nasl_vendor_version()

tree_cell * nasl_vendor_version ( lex_ctxt * lexic)

Definition at line 1175 of file nasl_scanner_glue.c.

1176{
1177 tree_cell *retc;
1178 gchar *version = g_strdup (vendor_version_get ());
1179 (void) lexic;
1181 retc->x.str_val = strdup (version);
1182 retc->size = strlen (version);
1183 g_free (version);
1184
1185 return retc;
1186}
const gchar * vendor_version_get()
Get vendor version.

References alloc_typed_cell(), CONST_DATA, TC::size, TC::str_val, vendor_version_get(), and TC::x.

Here is the call graph for this function:

◆ replace_kb_item()

tree_cell * replace_kb_item ( lex_ctxt * lexic)

Definition at line 784 of file nasl_scanner_glue.c.

785{
786 struct script_infos *script_infos = lexic->script_infos;
787 char *name = get_str_var_by_name (lexic, "name");
788 int type = get_var_type_by_name (lexic, "value");
789
790 if (name == NULL)
791 {
792 nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
793 name);
794 return FAKE_CELL;
795 }
796
797 if (type == VAR2_INT)
798 {
799 int value = get_int_var_by_name (lexic, "value", -1);
800 if (value != -1)
802 GSIZE_TO_POINTER (value));
803 else
805 lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
806 }
807 else
808 {
809 char *value = get_str_var_by_name (lexic, "value");
810 int len = get_var_size_by_name (lexic, "value");
811
812 if (value == NULL)
813 {
814 nasl_perror (lexic,
815 "Syntax error with replace_kb_item(%s) [null value]\n",
816 name);
817 return FAKE_CELL;
818 }
820 }
821
822 return FAKE_CELL;
823}
int get_var_size_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1138
int get_var_type_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1162
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
Definition plugutils.c:1113
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
Definition plugutils.c:1140
#define ARG_INT
Definition plugutils.h:20

References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), len, name, nasl_perror(), plug_replace_key(), plug_replace_key_len(), struct_lex_ctxt::script_infos, and VAR2_INT.

Here is the call graph for this function:

◆ safe_checks()

tree_cell * safe_checks ( lex_ctxt * lexic)

Definition at line 616 of file nasl_scanner_glue.c.

617{
618 (void) lexic;
620
621 retc->x.i_val = prefs_get_bool ("safe_checks");
622
623 return retc;
624}

References alloc_typed_cell(), CONST_INT, TC::i_val, and TC::x.

Referenced by plugin_run_openvas_tcp_scanner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script_add_preference()

tree_cell * script_add_preference ( lex_ctxt * lexic)

Definition at line 439 of file nasl_scanner_glue.c.

440{
441 int id = get_int_var_by_name (lexic, "id", -1);
442 char *name = get_str_var_by_name (lexic, "name");
443 char *type = get_str_var_by_name (lexic, "type");
444 char *value = get_str_var_by_name (lexic, "value");
445 struct script_infos *script_infos = lexic->script_infos;
446 nvtpref_t *np;
447 unsigned int i;
448
449 if (!script_infos->nvti)
450 return FAKE_CELL;
451 if (id < 0)
452 id = nvti_pref_len (script_infos->nvti) + 1;
453 if (id == 0)
454 {
455 nasl_perror (lexic,
456 "Invalid id or not allowed id value in the call to %s()\n",
457 __func__);
458 return FAKE_CELL;
459 }
460 if (!name || !type || !value)
461 {
462 nasl_perror (lexic,
463 "Argument error in the call to script_add_preference()\n");
464 return FAKE_CELL;
465 }
466 for (i = 0; i < nvti_pref_len (script_infos->nvti); i++)
467 {
468 if (!strcmp (name, nvtpref_name (nvti_pref (script_infos->nvti, i))))
469 {
470 nasl_perror (lexic, "Preference '%s' already exists\n", name);
471 return FAKE_CELL;
472 }
473 if (id == nvtpref_id (nvti_pref (script_infos->nvti, i)))
474 {
475 nasl_perror (lexic, "Invalid or already existent preference id\n");
476 return FAKE_CELL;
477 }
478 }
479
480 np = nvtpref_new (id, name, type, value);
481 nvti_add_pref (script_infos->nvti, np);
482 return FAKE_CELL;
483}
nvti_t * nvti
Definition scanneraux.h:33

References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_category()

tree_cell * script_category ( lex_ctxt * lexic)

Definition at line 259 of file nasl_scanner_glue.c.

260{
261 struct script_infos *script_infos = lexic->script_infos;
262
263 int category = get_int_var_by_num (lexic, 0, -1);
264
265 if (category < 0)
266 {
267 nasl_perror (lexic, "Argument error in function script_category()\n");
268 nasl_perror (lexic, "Function usage is : script_category(<category>)\n");
269 return FAKE_CELL;
270 }
271 nvti_set_category (script_infos->nvti, category);
272 return FAKE_CELL;
273}

References FAKE_CELL, get_int_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_copyright()

tree_cell * script_copyright ( lex_ctxt * lexic)

Definition at line 252 of file nasl_scanner_glue.c.

253{
254 (void) lexic;
255 return FAKE_CELL;
256}

References FAKE_CELL.

◆ script_cve_id()

tree_cell * script_cve_id ( lex_ctxt * lexic)

Definition at line 116 of file nasl_scanner_glue.c.

117{
118 struct script_infos *script_infos = lexic->script_infos;
119 char *cve = get_str_var_by_num (lexic, 0);
120 int i;
121
122 for (i = 0; cve != NULL; i++)
123 {
124 nvti_add_vtref (script_infos->nvti, vtref_new ("cve", cve, ""));
125 cve = get_str_var_by_num (lexic, i + 1);
126 }
127
128 return FAKE_CELL;
129}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_dependencies()

tree_cell * script_dependencies ( lex_ctxt * lexic)

Definition at line 283 of file nasl_scanner_glue.c.

284{
285 struct script_infos *script_infos = lexic->script_infos;
286 char *dep = get_str_var_by_num (lexic, 0);
287 int i;
288
289 if (dep == NULL)
290 {
291 nasl_perror (lexic, "Argument error in function script_dependencies()\n");
292 nasl_perror (lexic, "Function usage is : script_dependencies(<name>)\n");
293 nasl_perror (lexic, "Where <name> is the name of another script\n");
294
295 return FAKE_CELL;
296 }
297
298 for (i = 0; dep != NULL; i++)
299 {
300 dep = get_str_var_by_num (lexic, i);
301 if (dep != NULL)
303 }
304
305 return FAKE_CELL;
306}
void plug_set_dep(struct script_infos *args, const char *depname)
Definition plugutils.c:104

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_set_dep(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_exclude_keys()

tree_cell * script_exclude_keys ( lex_ctxt * lexic)

Definition at line 380 of file nasl_scanner_glue.c.

381{
382 char *keys = get_str_var_by_num (lexic, 0);
383 int i;
384
385 if (keys == NULL)
386 {
387 nasl_perror (lexic, "Argument error in function script_exclude_keys()\n");
388 nasl_perror (lexic, "Function usage is : script_exclude_keys(<name>)\n");
389 nasl_perror (lexic, "Where <name> is the name of a key\n");
390 return FAKE_CELL;
391 }
392
393 for (i = 0; keys != NULL; i++)
394 {
395 keys = get_str_var_by_num (lexic, i);
396 nvti_add_excluded_keys (lexic->script_infos->nvti, keys);
397 }
398
399 return FAKE_CELL;
400}

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_family()

tree_cell * script_family ( lex_ctxt * lexic)

Definition at line 276 of file nasl_scanner_glue.c.

277{
278 nvti_set_family (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
279 return FAKE_CELL;
280}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_get_preference()

tree_cell * script_get_preference ( lex_ctxt * lexic)

Get a preferences of the current script.

Search the preference by preference name or by preferences id.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the preferences value as a string. Fake cell otherwise

Definition at line 496 of file nasl_scanner_glue.c.

497{
498 tree_cell *retc;
499 int id = get_int_var_by_name (lexic, "id", -1);
500 char *pref = get_str_var_by_num (lexic, 0);
501 char *value;
502
503 if (pref == NULL && id == -1)
504 {
505 nasl_perror (lexic,
506 "Argument error in the function script_get_preference()\n");
507 nasl_perror (lexic,
508 "Function usage is : pref = script_get_preference(<name>, "
509 "id:<id>)\n");
510 return FAKE_CELL;
511 }
512
513 value = get_plugin_preference (lexic->oid, pref, id);
514 if (value != NULL)
515 {
517 if (isalldigit (value, strlen (value)))
518 retc->x.i_val = atoi (value);
519 else
520 {
521 retc->type = CONST_DATA;
522 retc->size = strlen (value);
523 retc->x.str_val = g_strdup (value);
524 }
525 g_free (value);
526 return retc;
527 }
528 else
529 return FAKE_CELL;
530}
static int isalldigit(char *str, int len)
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition plugutils.c:832

References alloc_typed_cell(), CONST_DATA, CONST_INT, FAKE_CELL, get_int_var_by_name(), get_plugin_preference(), get_str_var_by_num(), TC::i_val, isalldigit(), nasl_perror(), struct_lex_ctxt::oid, TC::size, TC::str_val, TC::type, and TC::x.

Here is the call graph for this function:

◆ script_get_preference_file_content()

tree_cell * script_get_preference_file_content ( lex_ctxt * lexic)

Definition at line 533 of file nasl_scanner_glue.c.

534{
535 struct script_infos *script_infos = lexic->script_infos;
536 tree_cell *retc;
537 char *pref = get_str_var_by_num (lexic, 0);
538 char *value;
539 char *content;
540 int contentsize = 0;
541
542 if (pref == NULL)
543 {
544 nasl_perror (lexic,
545 "Argument error in the function script_get_preference()\n");
546 nasl_perror (lexic, "Function usage is : pref = "
547 "script_get_preference_file_content(<name>)\n");
548 return NULL;
549 }
550
551 value = get_plugin_preference (lexic->oid, pref, -1);
552 if (value == NULL)
553 return NULL;
554
556 contentsize = get_plugin_preference_file_size (script_infos, value);
557 g_free (value);
558 if (content == NULL)
559 return FAKE_CELL;
560 if (contentsize <= 0)
561 {
562 nasl_perror (lexic,
563 "script_get_preference_file_content: could not get "
564 " size of file from preference %s\n",
565 pref);
566 return NULL;
567 }
568
570 retc->size = contentsize;
571 retc->x.str_val = content;
572
573 return retc;
574}
char * get_plugin_preference_file_content(struct script_infos *desc, const char *identifier)
Get the file contents of a plugins preference that is of type "file".
Definition plugutils.c:975
long get_plugin_preference_file_size(struct script_infos *desc, const char *identifier)
Get the file size of a plugins preference that is of type "file".
Definition plugutils.c:1006

References alloc_typed_cell(), CONST_DATA, FAKE_CELL, get_plugin_preference(), get_plugin_preference_file_content(), get_plugin_preference_file_size(), get_str_var_by_num(), nasl_perror(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ script_get_preference_file_location()

tree_cell * script_get_preference_file_location ( lex_ctxt * lexic)

Definition at line 577 of file nasl_scanner_glue.c.

578{
579 struct script_infos *script_infos = lexic->script_infos;
580 tree_cell *retc;
581 char *pref = get_str_var_by_num (lexic, 0);
582 const char *value, *local;
583 int len;
584
585 if (pref == NULL)
586 {
588 lexic, "script_get_preference_file_location: no preference name!\n");
589 return NULL;
590 }
591
592 value = get_plugin_preference (lexic->oid, pref, -1);
593 if (value == NULL)
594 {
596 lexic,
597 "script_get_preference_file_location: could not get preference %s\n",
598 pref);
599 return NULL;
600 }
602 if (local == NULL)
603 return NULL;
604
605 len = strlen (local);
607 retc->size = len;
608 retc->x.str_val = g_malloc0 (len + 1);
609 memcpy (retc->x.str_val, local, len + 1);
610
611 return retc;
612}
const char * get_plugin_preference_fname(struct script_infos *desc, const char *filename)
Get the file name of a plugins preference that is of type "file".
Definition plugutils.c:920

References alloc_typed_cell(), CONST_DATA, get_plugin_preference(), get_plugin_preference_fname(), get_str_var_by_num(), len, nasl_perror(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ script_mandatory_keys()

tree_cell * script_mandatory_keys ( lex_ctxt * lexic)

Definition at line 333 of file nasl_scanner_glue.c.

334{
335 char *keys = get_str_var_by_num (lexic, 0);
336 char **splits = NULL, *re = get_str_var_by_name (lexic, "re");
337 int i;
338
339 if (keys == NULL)
340 {
341 nasl_perror (lexic,
342 "Argument error in function script_mandatory_keys()\n");
343 nasl_perror (lexic, "Function usage is: script_mandatory_keys(<name>... "
344 "[, re: '<name>=<regex>'])\n");
345 nasl_perror (lexic, "Where <name> is the name of a key and <regex> is a "
346 "regular expression for a value of a key.\n");
347 return FAKE_CELL;
348 }
349
350 if (re)
351 {
352 splits = g_strsplit (re, "=", 0);
353
354 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
355 {
356 nasl_perror (lexic, "Erroneous re argument");
357 return FAKE_CELL;
358 }
359 }
360 for (i = 0; keys != NULL; i++)
361 {
362 keys = get_str_var_by_num (lexic, i);
363
364 if (splits && keys && !strcmp (keys, splits[0]))
365 {
366 nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
367 re = NULL;
368 }
369 else
370 nvti_add_mandatory_keys (lexic->script_infos->nvti, keys);
371 }
372 if (re)
373 nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
374
375 g_strfreev (splits);
376 return FAKE_CELL;
377}

References FAKE_CELL, get_str_var_by_name(), get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_name()

tree_cell * script_name ( lex_ctxt * lexic)

Definition at line 238 of file nasl_scanner_glue.c.

239{
240 nvti_set_name (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
241 return FAKE_CELL;
242}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Referenced by nasl_perror(), and nasl_trace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script_oid()

tree_cell * script_oid ( lex_ctxt * lexic)

Definition at line 109 of file nasl_scanner_glue.c.

110{
111 nvti_set_oid (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
112 return FAKE_CELL;
113}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_keys()

tree_cell * script_require_keys ( lex_ctxt * lexic)

Definition at line 309 of file nasl_scanner_glue.c.

310{
311 char *keys = get_str_var_by_num (lexic, 0);
312 int i;
313
314 if (keys == NULL)
315 {
316 nasl_perror (lexic, "Argument error in function script_require_keys()\n");
317 nasl_perror (lexic,
318 "Function usage is : script_require_keys(<name>...)\n");
319 nasl_perror (lexic, "Where <name> is the name of a key\n");
320 return FAKE_CELL;
321 }
322
323 for (i = 0; keys != NULL; i++)
324 {
325 keys = get_str_var_by_num (lexic, i);
326 nvti_add_required_keys (lexic->script_infos->nvti, keys);
327 }
328
329 return FAKE_CELL;
330}

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_ports()

tree_cell * script_require_ports ( lex_ctxt * lexic)

Definition at line 403 of file nasl_scanner_glue.c.

404{
405 char *port;
406 int i;
407
408 for (i = 0;; i++)
409 {
410 port = get_str_var_by_num (lexic, i);
411 if (port != NULL)
412 nvti_add_required_ports (lexic->script_infos->nvti, port);
413 else
414 break;
415 }
416
417 return FAKE_CELL;
418}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_udp_ports()

tree_cell * script_require_udp_ports ( lex_ctxt * lexic)

Definition at line 421 of file nasl_scanner_glue.c.

422{
423 int i;
424 char *port;
425
426 for (i = 0;; i++)
427 {
428 port = get_str_var_by_num (lexic, i);
429 if (port != NULL)
430 nvti_add_required_udp_ports (lexic->script_infos->nvti, port);
431 else
432 break;
433 }
434
435 return FAKE_CELL;
436}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_tag()

tree_cell * script_tag ( lex_ctxt * lexic)

Definition at line 198 of file nasl_scanner_glue.c.

199{
200 struct script_infos *script_infos = lexic->script_infos;
201 char *name = get_str_var_by_name (lexic, "name");
202 char *value = get_str_var_by_name (lexic, "value");
203
204 if (value == NULL || name == NULL)
205 {
206 nasl_perror (lexic, "script_tag() syntax error - should be"
207 " script_tag(name:<name>, value:<value>)\n");
208 if (name == NULL)
209 {
210 nasl_perror (lexic, " <name> is empty\n");
211 }
212 else
213 {
214 nasl_perror (lexic, " <name> is %s\n", name);
215 }
216 if (value == NULL)
217 {
218 nasl_perror (lexic, " <value> is empty)\n");
219 }
220 else
221 {
222 nasl_perror (lexic, " <value> is %s\n)", value);
223 }
224 return FAKE_CELL;
225 }
226
227 if (strchr (value, '|'))
228 {
229 nasl_perror (lexic, "%s tag contains | separator", name);
230 return FAKE_CELL;
231 }
232 nvti_add_tag (script_infos->nvti, name, value);
233
234 return FAKE_CELL;
235}

References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_timeout()

tree_cell * script_timeout ( lex_ctxt * lexic)

Add timeout preference to VT preferences.

VT timeout is handled as normal VT preference. Because of backward compatibility issues the timeout preference is always located at the VT pref location with id NVTPREF_TIMEOUT_ID.

Parameters
[in]lexiclexic
[in]toscript timeout
Returns
FAKE_CELL

Definition at line 91 of file nasl_scanner_glue.c.

92{
93 nvti_t *nvti = lexic->script_infos->nvti;
94 int to = get_int_var_by_num (lexic, 0, -65535);
95 nvtpref_t *np;
96 gchar *timeout;
97
98 if (to == -65535)
99 return FAKE_CELL;
100
101 timeout = g_strdup_printf ("%d", to);
102
103 np = nvtpref_new (NVTPREF_TIMEOUT_ID, "timeout", "entry", timeout);
104 nvti_add_pref (nvti, np);
105 return FAKE_CELL;
106}

References FAKE_CELL, get_int_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_version()

tree_cell * script_version ( lex_ctxt * lexic)

Definition at line 245 of file nasl_scanner_glue.c.

246{
247 (void) lexic;
248 return FAKE_CELL;
249}

References FAKE_CELL.

◆ script_xref()

tree_cell * script_xref ( lex_ctxt * lexic)

Add a cross reference to the meta data.

The parameter "name" of the command defines actually the type, for example "URL" or "OSVDB". The parameter "value" is the actual reference. Alternative to "value", "csv" can be used with a list of comma-separated values.

In fact, if name is "cve", it is equivalent to call script_cve_id(), for example script_cve_id ("CVE-2019-12345"); is identical to script_xref (name: "cve", value: "CVE-2019-12345");

This even works with multiple comma-separated elements like script_xref (name: "cve", csv: "CVE-2019-12345,CVE-2019-54321");

Parameters
lexicThe parser context.
Returns
Always FAKE_CELL.

Definition at line 154 of file nasl_scanner_glue.c.

155{
156 struct script_infos *script_infos = lexic->script_infos;
157 char *name = get_str_var_by_name (lexic, "name");
158 char *value = get_str_var_by_name (lexic, "value");
159 char *csv = get_str_var_by_name (lexic, "csv");
160
161 if (((value == NULL) && (csv == NULL)) || name == NULL)
162 {
163 nasl_perror (lexic,
164 "script_xref() syntax error - should be"
165 " script_xref(name:<name>, value:<value>) or"
166 " script_xref(name:<name>, value:<value>, csv:<CSVs>) or"
167 " script_xref(name:<name>, csv:<CSVs>)\n");
168 if (name == NULL)
169 {
170 nasl_perror (lexic, " <name> is empty\n");
171 }
172 else
173 {
174 nasl_perror (lexic, " <name> is %s\n", name);
175 }
176 if ((value == NULL) && (csv == NULL))
177 {
178 nasl_perror (lexic, " <value> and <csv> is empty)\n");
179 }
180 else
181 {
182 nasl_perror (lexic, " <value> is %s\n)", value);
183 nasl_perror (lexic, " <csv> is %s\n)", csv);
184 }
185 return FAKE_CELL;
186 }
187
188 if (csv)
189 nvti_add_refs (script_infos->nvti, name, csv, "");
190
191 if (value)
192 nvti_add_vtref (script_infos->nvti, vtref_new (name, value, ""));
193
194 return FAKE_CELL;
195}

References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ security_message()

tree_cell * security_message ( lex_ctxt * lexic)

Send a security message to the client.

Parameters
[in]lexicNASL lexer.
Returns
FAKE_CELL.

Definition at line 1132 of file nasl_scanner_glue.c.

1133{
1135}
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition plugutils.c:769
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Definition plugutils.c:762

References post_alarm(), proto_post_alarm(), and security_something().

Here is the call graph for this function:

◆ security_notus()

tree_cell * security_notus ( lex_ctxt * lexic)

Definition at line 1012 of file nasl_scanner_glue.c.

1013{
1014 tree_cell *result;
1015 named_nasl_var *oid_var, *var, *vul_packages, *name, *version, *fixed,
1016 *fixed_version, *specifier, *start, *end;
1017 anon_nasl_var *pkg;
1018 unsigned char *oid;
1019 int i;
1020 GString *result_buf, *buf;
1021 gchar *kb_result;
1022
1023 result = get_variable_by_name (lexic, "result");
1024 if (result == NULL)
1025 {
1026 nasl_perror (lexic, "security_lsc: oid or result is NULL\n");
1027 return FAKE_CELL;
1028 }
1029
1030 var = (named_nasl_var *) result->x.ref_val;
1031
1032 oid_var = get_var_by_name (&var->u.v.v_arr, "oid");
1033 if (oid_var == NULL)
1034 {
1035 nasl_perror (lexic, "security_lsc: oid not found\n");
1036 return FAKE_CELL;
1037 }
1038
1039 oid = oid_var->u.v.v_str.s_val;
1040
1041 vul_packages = get_var_by_name (&var->u.v.v_arr, "vulnerable_packages");
1042 if (vul_packages == NULL || vul_packages->u.var_type != VAR2_ARRAY)
1043 {
1044 nasl_perror (lexic, "security_lsc: vul_packages is not an array\n");
1045 return FAKE_CELL;
1046 }
1047 result_buf = g_string_new (NULL);
1048 for (i = 0; i < vul_packages->u.v.v_arr.max_idx; i++)
1049 {
1050 pkg = nasl_get_var_by_num (lexic, &vul_packages->u.v.v_arr, i, 0);
1051 if (pkg == NULL)
1052 continue;
1053
1054 name = get_var_by_name (&pkg->v.v_arr, "name");
1055 version = get_var_by_name (&pkg->v.v_arr, "installed");
1056 fixed = get_var_by_name (&pkg->v.v_arr, "fixed");
1057 if (fixed == NULL)
1058 continue;
1059 fixed_version = get_var_by_name (&fixed->u.v.v_arr, "version");
1060 specifier = get_var_by_name (&fixed->u.v.v_arr, "specifier");
1061 start = get_var_by_name (&fixed->u.v.v_arr, "start");
1062 end = get_var_by_name (&fixed->u.v.v_arr, "end");
1063
1064 if (name == NULL || version == NULL)
1065 {
1066 continue;
1067 }
1068
1069 if (fixed_version != NULL && specifier != NULL)
1070 {
1071 buf = g_string_new (NULL);
1072 g_string_printf (buf,
1073 "\n"
1074 "Vulnerable package: %s\n"
1075 "Installed version: %s-%s\n"
1076 "Fixed version: %2s%s-%s\n",
1077 name->u.v.v_str.s_val, name->u.v.v_str.s_val,
1078 version->u.v.v_str.s_val, specifier->u.v.v_str.s_val,
1079 name->u.v.v_str.s_val,
1080 fixed_version->u.v.v_str.s_val);
1081 }
1082 else if (start != NULL && end != NULL)
1083 {
1084 buf = g_string_new (NULL);
1085 g_string_printf (buf,
1086 "\n"
1087 "Vulnerable package: %s\n"
1088 "Installed version: %s-%s\n"
1089 "Fixed version: < %s-%s\n"
1090 "Fixed version: >=%s-%s\n",
1091 name->u.v.v_str.s_val, name->u.v.v_str.s_val,
1092 version->u.v.v_str.s_val, name->u.v.v_str.s_val,
1093 start->u.v.v_str.s_val, name->u.v.v_str.s_val,
1094 end->u.v.v_str.s_val);
1095 }
1096 else
1097 {
1098 continue;
1099 }
1100 g_string_append (result_buf, buf->str);
1101 g_string_free (buf, TRUE);
1102 }
1103
1104 if (result_buf == NULL)
1105 {
1106 nasl_perror (lexic, "security_lsc: No results to publish\n");
1107 return FAKE_CELL;
1108 }
1109
1110 gchar ip_str[INET6_ADDRSTRLEN];
1111 addr6_to_str (lexic->script_infos->ip, ip_str);
1112 // type|||IP|||HOSTNAME|||package|||OID|||the result message|||URI
1113 kb_result =
1114 g_strdup_printf ("%s|||%s|||%s|||%s|||%s|||%s|||%s", "ALARM", ip_str, " ",
1115 "package", oid, result_buf->str, "");
1116 g_string_free (result_buf, TRUE);
1117 kb_item_push_str_with_main_kb_check (get_main_kb (), "internal/results",
1118 kb_result);
1119 g_free (kb_result);
1120
1121 return NULL;
1122}
kb_t get_main_kb(void)
gets the main_kb. @description returns the previously set main_kb; when asserts are enabled it will a...
Definition kb_cache.c:41
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:176
named_nasl_var * get_var_by_name(nasl_array *a, const char *s)
Definition nasl_var.c:75
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition nasl_var.c:43
struct st_n_nasl_var named_nasl_var
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
Definition plugutils.c:533
Fixed version.
struct in6_addr * ip
Definition scanneraux.h:37
struct st_a_nasl_var u
Definition nasl_var.h:56

References FAKE_CELL, get_main_kb(), get_var_by_name(), get_variable_by_name(), script_infos::ip, kb_item_push_str_with_main_kb_check(), st_nasl_array::max_idx, name, nasl_get_var_by_num(), nasl_perror(), oid, TC::ref_val, st_nasl_string::s_val, struct_lex_ctxt::script_infos, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function:

◆ set_kb_item()

tree_cell * set_kb_item ( lex_ctxt * lexic)

Set a kb item.

If expire is set the key will be removed after it expired.

Parameters
[in]lexicNASL lexer.
[in]nameName of Item.
[in]valueValue of Item.
[in]expireOptional expire for item in seconds.
Returns
FAKE_CELL

Definition at line 894 of file nasl_scanner_glue.c.

895{
896 struct script_infos *script_infos = lexic->script_infos;
897 char *name = get_str_var_by_name (lexic, "name");
898 int type = get_var_type_by_name (lexic, "value");
899 int expire = get_int_var_by_name (lexic, "expire", -1);
900
901 if (expire != -1)
902 return set_kb_item_volatile (lexic);
903
904 if (name == NULL)
905 {
906 nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
907 name);
908 return FAKE_CELL;
909 }
910
911 if (type == VAR2_INT)
912 {
913 int value = get_int_var_by_name (lexic, "value", -1);
914 if (value != -1)
915 plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
916 else
918 lexic, "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
919 name);
920 }
921 else
922 {
923 char *value = get_str_var_by_name (lexic, "value");
924 int len = get_var_size_by_name (lexic, "value");
925 if (value == NULL)
926 {
928 lexic,
929 "Syntax error with set_kb_item() [null value for name '%s']\n",
930 name);
931 return FAKE_CELL;
932 }
934 }
935
936 return FAKE_CELL;
937}
static tree_cell * set_kb_item_volatile(lex_ctxt *lexic)
Set a volatile kb item.
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
Definition plugutils.c:1028

References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), len, name, nasl_perror(), plug_set_key(), plug_set_key_len(), struct_lex_ctxt::script_infos, set_kb_item_volatile(), and VAR2_INT.

Here is the call graph for this function: