OpenVAS Scanner 23.40.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_type (lex_ctxt *)
 Get the Notus scan type.
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 1179 of file nasl_scanner_glue.c.

1180{
1182}
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:811
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition plugutils.c:818

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 766 of file nasl_scanner_glue.c.

767{
768 struct script_infos *script_infos = lexic->script_infos;
769 int val;
770 tree_cell *retc;
771
772 val = kb_get_kb_index (script_infos->key);
773 if (val >= 0)
774 {
776 retc->x.i_val = val;
777 }
778 else
779 return NULL;
780
781 return retc;
782}
const char * val
Definition nasl_init.c:441
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 714 of file nasl_scanner_glue.c.

715{
716 struct script_infos *script_infos = lexic->script_infos;
717
718 char *kb_entry = get_str_var_by_num (lexic, 0);
719 char *val;
720 tree_cell *retc;
721 int type = -1, single = get_int_var_by_num (lexic, 1, 0);
722 size_t len;
723
724 if (kb_entry == NULL)
725 return NULL;
726
727 val = plug_get_key (script_infos, kb_entry, &type, &len, !!single);
728
729 if (val == NULL && type == -1)
730 return NULL;
731
733 if (type == KB_TYPE_INT)
734 {
735 retc->x.i_val = GPOINTER_TO_SIZE (val);
736 g_free (val);
737 return retc;
738 }
739 else
740 {
741 retc->type = CONST_DATA;
742 if (val != NULL)
743 {
744 retc->size = len;
745 retc->x.str_val = val;
746 }
747 else
748 {
749 retc->size = 0;
750 retc->x.str_val = NULL;
751 }
752 }
753
754 return retc;
755}
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:1231
long 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 653 of file nasl_scanner_glue.c.

654{
655 struct script_infos *script_infos = lexic->script_infos;
656 kb_t kb = plug_get_kb (script_infos);
657 char *kb_mask = get_str_var_by_num (lexic, 0);
658 tree_cell *retc;
659 int num_elems = 0;
660 nasl_array *a;
661 struct kb_item *res, *top;
662
663 if (kb_mask == NULL)
664 {
665 nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
666 return NULL;
667 }
668
669 if (kb == NULL)
670 return NULL;
671
673 retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
674
675 if (strchr (kb_mask, '*'))
676 top = res = kb_item_get_pattern (kb, kb_mask);
677 else
678 top = res = kb_item_get_all (kb, kb_mask);
679
680 while (res != NULL)
681 {
683 bzero (&v, sizeof (v));
684
685 if (res->type == KB_TYPE_INT)
686 {
687 v.var_type = VAR2_INT;
688 v.v.v_int = res->v_int;
689 add_var_to_array (a, res->name, &v);
690 num_elems++;
691 }
692 else if (res->type == KB_TYPE_STR)
693 {
695 v.v.v_str.s_val = (unsigned char *) res->v_str;
696 v.v.v_str.s_siz = strlen (res->v_str);
697 add_var_to_array (a, res->name, &v);
698 num_elems++;
699 }
700 res = res->next;
701 }
702
703 kb_item_free (top);
704
705 if (num_elems == 0)
706 {
707 deref_cell (retc);
708 return FAKE_CELL;
709 }
710 return retc;
711}
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:1157
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
long int s_siz
Definition nasl_var.h:27

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 635 of file nasl_scanner_glue.c.

636{
637 const char *oid = lexic->oid;
638 tree_cell *retc = NULL;
639
640 if (oid)
641 {
643 retc->x.str_val = g_strdup (oid);
644 retc->size = strlen (oid);
645 }
646
647 return retc;
648}
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 1171 of file nasl_scanner_glue.c.

1172{
1174}
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:784
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:804

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 1185 of file nasl_scanner_glue.c.

1186{
1187 tree_cell *retc;
1188 char *name;
1189 const char *value;
1190
1191 name = get_str_var_by_num (lexic, 0);
1192 if (name == NULL)
1193 {
1194 nasl_perror (lexic, "get_preference: no name\n");
1195 return NULL;
1196 }
1197 value = prefs_get (name);
1198 if (value == NULL)
1199 return NULL;
1200
1202 retc->x.str_val = strdup (value);
1203 retc->size = strlen (value);
1204 return retc;
1205}
const char * name
Definition nasl_init.c:440

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. As there are currently 2 types of LSC scanner, with different result formats, the result depends on the used scanner type. In case of Notus it returns a list of 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. In case of Skiron, it returns a dictionary with the OIDs and corresponding result messages.

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 1444 of file nasl_scanner_glue.c.

1445{
1446 char *response;
1447 advisories_t *advisories = NULL;
1448 char *pkg_list = get_str_var_by_name (lexic, "pkg_list");
1449 char *product = get_str_var_by_name (lexic, "product");
1450
1451 notus_err = 0;
1452
1453 if (product == NULL || pkg_list == NULL)
1454 {
1455 g_warning ("%s: Missing data for running LSC", __func__);
1456 notus_err = -1;
1457 return NULL;
1458 }
1459
1460 response = lsc_get_response (pkg_list, product);
1461
1462 if (!response)
1463 {
1464 g_warning ("%s: Unable to get the response", __func__);
1465 notus_err = -2;
1466
1467 return NULL;
1468 }
1469
1470 advisories = lsc_process_response (response, strlen (response));
1471 g_free (response);
1472
1473 if (!advisories)
1474 {
1475 g_warning ("%s: Unable to process the response", __func__);
1476 notus_err = -4;
1477
1478 return NULL;
1479 }
1480
1482
1483 if (notus_type == NOTUS)
1484 // TODO: Remove notus, when it is deprecated
1485 return parse_notus (advisories);
1486 else
1487 return parse_skiron (advisories);
1488}
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1118
static int notus_err
Error code for Notus.
static tree_cell * parse_skiron(advisories_t *adv)
static tree_cell * parse_notus(advisories_t *advisories)
static int notus_type
Type of Notus scan. This is either Notus or Skiron.
advisory_type_t type
char * lsc_get_response(const char *pkg_list, const char *os)
Sent the installed package list and OS to notus.
advisories_t * lsc_process_response(const gchar *resp, const size_t len)
Process a json object which contains advisories and vulnerable packages.
struct advisories advisories_t
@ NOTUS

References get_str_var_by_name(), lsc_get_response(), lsc_process_response(), NOTUS, notus_err, notus_type, parse_notus(), parse_skiron(), and advisories::type.

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 1523 of file nasl_scanner_glue.c.

1524{
1525 tree_cell *retc;
1526 char *notus_err_str;
1527 (void) lexic;
1528
1529 switch (notus_err)
1530 {
1531 case -1:
1532 notus_err_str = strdup ("Missing data for running LSC");
1533 break;
1534 case -2:
1535 notus_err_str = strdup ("Unable to get the response");
1536 break;
1537 case -3:
1538 notus_err_str = strdup ("Unknown fixed version type for advisory");
1539 break;
1540 case -4:
1541 notus_err_str = strdup ("Unable to process the response");
1542 break;
1543 default:
1544 return NULL;
1545 }
1546
1547 retc = alloc_typed_cell (CONST_STR);
1548 retc->x.str_val = notus_err_str;
1549 retc->size = strlen (notus_err_str);
1550
1551 return retc;
1552}
@ 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_notus_type()

tree_cell * nasl_notus_type ( lex_ctxt * lexic)

Get the Notus scan type.

0 for Notus, 1 for Skiron.

NASL Function: notus_type\n
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
Scan type as integer.

Definition at line 1502 of file nasl_scanner_glue.c.

1503{
1504 tree_cell *retc;
1505 (void) lexic;
1506
1507 retc = alloc_typed_cell (CONST_INT);
1508 retc->x.i_val = (int) notus_type;
1509 return retc;
1510}

References alloc_typed_cell(), CONST_INT, TC::i_val, notus_type, 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 1601 of file nasl_scanner_glue.c.

1602{
1603 struct script_infos *script_infos = lexic->script_infos;
1604
1605 int port = get_int_var_by_name (lexic, "port", -1);
1606 char *proto = get_str_var_by_name (lexic, "proto");
1607
1608 if (port >= 0)
1609 {
1610 scanner_add_port (script_infos, port, proto ? proto : "tcp");
1611 }
1612
1613 return FAKE_CELL;
1614}
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:1151

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 1561 of file nasl_scanner_glue.c.

1562{
1563 tree_cell *retc;
1564 int idx = get_int_var_by_num (lexic, 0, -1);
1565 const char *prange = prefs_get ("port_range");
1566 static int num = 0;
1567 static u_short *ports = NULL;
1568
1569 if (prange == NULL)
1570 return NULL;
1571
1572 if (idx < 0)
1573 {
1574 nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1575 nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1576 nasl_perror (lexic,
1577 "Where <num> should be 0 the first time you call it\n");
1578 return NULL;
1579 }
1580
1581 if (ports == NULL)
1582 {
1583 ports = (u_short *) getpts ((char *) prange, &num);
1584 if (ports == NULL)
1585 {
1586 return NULL;
1587 }
1588 }
1589
1590 if (idx >= num)
1591 {
1592 return NULL;
1593 }
1594
1595 retc = alloc_typed_cell (CONST_INT);
1596 retc->x.i_val = ports[idx];
1597 return retc;
1598}
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 1617 of file nasl_scanner_glue.c.

1618{
1619 /* Kept for backward compatibility. */
1620 (void) lexic;
1621 return FAKE_CELL;
1622}

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 1236 of file nasl_scanner_glue.c.

1237{
1238 struct script_infos *script_infos = lexic->script_infos;
1239 ipc_data_t *lsc = NULL;
1240 const char *json = NULL;
1241 gchar *pkg_list = get_str_var_by_name (lexic, "pkg_list");
1242 gchar *os_version = get_str_var_by_name (lexic, "os_release");
1243
1244 if (os_version == NULL || pkg_list == NULL)
1245 {
1246 g_warning ("%s: Missing data for running LSC", __func__);
1247 return NULL;
1248 }
1249
1250 plug_set_key (script_infos, "ssh/login/package_list_notus", ARG_STRING,
1251 pkg_list);
1252 plug_set_key (script_infos, "ssh/login/release_notus", ARG_STRING,
1253 os_version);
1254
1255 lsc = ipc_data_type_from_lsc (TRUE);
1256 if (!lsc)
1257 return NULL;
1258
1259 json = ipc_data_to_json (lsc);
1260 ipc_data_destroy (&lsc);
1261 if (ipc_send (lexic->script_infos->ipc_context, IPC_MAIN, json, strlen (json))
1262 < 0)
1263 g_warning ("Unable to send the package list for LSC to the host process");
1264
1265 g_free ((void *) json);
1266 return NULL;
1267}
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:1060
#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 1208 of file nasl_scanner_glue.c.

1209{
1210 tree_cell *retc;
1211 gchar *version = g_strdup (vendor_version_get ());
1212 (void) lexic;
1214 retc->x.str_val = strdup (version);
1215 retc->size = strlen (version);
1216 g_free (version);
1217
1218 return retc;
1219}
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 785 of file nasl_scanner_glue.c.

786{
787 struct script_infos *script_infos = lexic->script_infos;
788 char *name = get_str_var_by_name (lexic, "name");
789 int type = get_var_type_by_name (lexic, "value");
790
791 if (name == NULL)
792 {
793 nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
794 name);
795 return FAKE_CELL;
796 }
797
798 if (type == VAR2_INT)
799 {
800 int value = get_int_var_by_name (lexic, "value", -1);
801 if (value != -1)
803 GSIZE_TO_POINTER (value));
804 else
806 lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
807 }
808 else
809 {
810 char *value = get_str_var_by_name (lexic, "value");
811 size_t len = get_var_size_by_name (lexic, "value");
812
813 if (value == NULL)
814 {
815 nasl_perror (lexic,
816 "Syntax error with replace_kb_item(%s) [null value]\n",
817 name);
818 return FAKE_CELL;
819 }
821 }
822
823 return FAKE_CELL;
824}
int get_var_type_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1162
long int get_var_size_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1138
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
Definition plugutils.c:1118
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
Definition plugutils.c:1145
#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 617 of file nasl_scanner_glue.c.

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

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 440 of file nasl_scanner_glue.c.

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

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

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 253 of file nasl_scanner_glue.c.

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

References FAKE_CELL.

◆ script_cve_id()

tree_cell * script_cve_id ( lex_ctxt * lexic)

Definition at line 117 of file nasl_scanner_glue.c.

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

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 284 of file nasl_scanner_glue.c.

285{
286 struct script_infos *script_infos = lexic->script_infos;
287 char *dep = get_str_var_by_num (lexic, 0);
288 int i;
289
290 if (dep == NULL)
291 {
292 nasl_perror (lexic, "Argument error in function script_dependencies()\n");
293 nasl_perror (lexic, "Function usage is : script_dependencies(<name>)\n");
294 nasl_perror (lexic, "Where <name> is the name of another script\n");
295
296 return FAKE_CELL;
297 }
298
299 for (i = 0; dep != NULL; i++)
300 {
301 dep = get_str_var_by_num (lexic, i);
302 if (dep != NULL)
304 }
305
306 return FAKE_CELL;
307}
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 381 of file nasl_scanner_glue.c.

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

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 277 of file nasl_scanner_glue.c.

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

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 497 of file nasl_scanner_glue.c.

498{
499 tree_cell *retc;
500 int id = get_int_var_by_name (lexic, "id", -1);
501 char *pref = get_str_var_by_num (lexic, 0);
502 char *value;
503
504 if (pref == NULL && id == -1)
505 {
506 nasl_perror (lexic,
507 "Argument error in the function script_get_preference()\n");
508 nasl_perror (lexic,
509 "Function usage is : pref = script_get_preference(<name>, "
510 "id:<id>)\n");
511 return FAKE_CELL;
512 }
513
514 value = get_plugin_preference (lexic->oid, pref, id);
515 if (value != NULL)
516 {
518 if (isalldigit (value, strlen (value)))
519 retc->x.i_val = atoi (value);
520 else
521 {
522 retc->type = CONST_DATA;
523 retc->size = strlen (value);
524 retc->x.str_val = g_strdup (value);
525 }
526 g_free (value);
527 return retc;
528 }
529 else
530 return FAKE_CELL;
531}
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:837

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 534 of file nasl_scanner_glue.c.

535{
536 struct script_infos *script_infos = lexic->script_infos;
537 tree_cell *retc;
538 char *pref = get_str_var_by_num (lexic, 0);
539 char *value;
540 char *content;
541 int contentsize = 0;
542
543 if (pref == NULL)
544 {
545 nasl_perror (lexic,
546 "Argument error in the function script_get_preference()\n");
547 nasl_perror (lexic, "Function usage is : pref = "
548 "script_get_preference_file_content(<name>)\n");
549 return NULL;
550 }
551
552 value = get_plugin_preference (lexic->oid, pref, -1);
553 if (value == NULL)
554 return NULL;
555
557 contentsize = get_plugin_preference_file_size (script_infos, value);
558 g_free (value);
559 if (content == NULL)
560 return FAKE_CELL;
561 if (contentsize <= 0)
562 {
563 nasl_perror (lexic,
564 "script_get_preference_file_content: could not get "
565 " size of file from preference %s\n",
566 pref);
567 return NULL;
568 }
569
571 retc->size = contentsize;
572 retc->x.str_val = content;
573
574 return retc;
575}
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:980
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:1011

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 578 of file nasl_scanner_glue.c.

579{
580 struct script_infos *script_infos = lexic->script_infos;
581 tree_cell *retc;
582 char *pref = get_str_var_by_num (lexic, 0);
583 const char *value, *local;
584 int len;
585
586 if (pref == NULL)
587 {
589 lexic, "script_get_preference_file_location: no preference name!\n");
590 return NULL;
591 }
592
593 value = get_plugin_preference (lexic->oid, pref, -1);
594 if (value == NULL)
595 {
597 lexic,
598 "script_get_preference_file_location: could not get preference %s\n",
599 pref);
600 return NULL;
601 }
603 if (local == NULL)
604 return NULL;
605
606 len = strlen (local);
608 retc->size = len;
609 retc->x.str_val = g_malloc0 (len + 1);
610 memcpy (retc->x.str_val, local, len + 1);
611
612 return retc;
613}
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:925

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 334 of file nasl_scanner_glue.c.

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

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 239 of file nasl_scanner_glue.c.

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

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 110 of file nasl_scanner_glue.c.

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

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 310 of file nasl_scanner_glue.c.

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

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 404 of file nasl_scanner_glue.c.

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

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 422 of file nasl_scanner_glue.c.

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

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 199 of file nasl_scanner_glue.c.

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

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 92 of file nasl_scanner_glue.c.

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

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 246 of file nasl_scanner_glue.c.

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

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 155 of file nasl_scanner_glue.c.

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

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 1165 of file nasl_scanner_glue.c.

1166{
1168}
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition plugutils.c:774
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:767

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 1092 of file nasl_scanner_glue.c.

1093{
1094 tree_cell *result;
1095 gchar *kb_result;
1096 named_nasl_var *oid_var, *var;
1097 unsigned char *oid, *result_string;
1098
1099 result = get_variable_by_name (lexic, "result");
1100 if (result == NULL)
1101 {
1102 nasl_perror (lexic, "security_lsc: oid or result is NULL\n");
1103 return FAKE_CELL;
1104 }
1105
1106 var = (named_nasl_var *) result->x.ref_val;
1107
1108 oid_var = get_var_by_name (&var->u.v.v_arr, "oid");
1109 if (oid_var == NULL)
1110 {
1111 nasl_perror (lexic, "security_lsc: oid not found\n");
1112 return NULL;
1113 }
1114
1115 oid = (unsigned char *) oid_var->u.v.v_str.s_val;
1116
1117 if (notus_type == NOTUS)
1118 {
1119 result_string = get_notus_result_message (lexic, var);
1120 }
1121 else
1122 {
1123 named_nasl_var *message;
1124 message = get_var_by_name (&var->u.v.v_arr, "message");
1125 if (message == NULL)
1126 {
1127 nasl_perror (lexic, "security_lsc: message not found\n");
1128 return NULL;
1129 }
1130 result_string = message->u.v.v_str.s_val;
1131 }
1132
1133 if (result_string == NULL)
1134 {
1135 nasl_perror (lexic, "security_lsc: No results to publish\n");
1136 return FAKE_CELL;
1137 }
1138
1139 gchar ip_str[INET6_ADDRSTRLEN];
1140 addr6_to_str (lexic->script_infos->ip, ip_str);
1141 // type|||IP|||HOSTNAME|||package|||OID|||the result message|||URI
1142 kb_result = g_strdup_printf ("%s|||%s|||%s|||%s|||%s|||%s|||%s", "ALARM",
1143 ip_str, " ", "package", oid, result_string, "");
1144
1145 // Only free result_string for notus type, as skiron uses a reference to a
1146 // nasl var
1147 if (notus_type == NOTUS)
1148 g_free (result_string);
1149
1150 kb_item_push_str_with_main_kb_check (get_main_kb (), "internal/results",
1151 kb_result);
1152 g_free (kb_result);
1153
1154 return FAKE_CELL;
1155}
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
static unsigned char * get_notus_result_message(lex_ctxt *lexic, named_nasl_var *var)
named_nasl_var * get_var_by_name(nasl_array *a, const char *s)
Definition nasl_var.c:75
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
struct in6_addr * ip
Definition scanneraux.h:37
nasl_array v_arr
Definition nasl_var.h:49
struct st_a_nasl_var u
Definition nasl_var.h:56

References FAKE_CELL, get_main_kb(), get_notus_result_message(), get_var_by_name(), get_variable_by_name(), script_infos::ip, kb_item_push_str_with_main_kb_check(), nasl_perror(), NOTUS, notus_type, 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, 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 895 of file nasl_scanner_glue.c.

896{
897 struct script_infos *script_infos = lexic->script_infos;
898 char *name = get_str_var_by_name (lexic, "name");
899 int type = get_var_type_by_name (lexic, "value");
900 int expire = get_int_var_by_name (lexic, "expire", -1);
901
902 if (expire != -1)
903 return set_kb_item_volatile (lexic);
904
905 if (name == NULL)
906 {
907 nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
908 name);
909 return FAKE_CELL;
910 }
911
912 if (type == VAR2_INT)
913 {
914 int value = get_int_var_by_name (lexic, "value", -1);
915 if (value != -1)
916 plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
917 else
919 lexic, "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
920 name);
921 }
922 else
923 {
924 char *value = get_str_var_by_name (lexic, "value");
925 size_t len = get_var_size_by_name (lexic, "value");
926 if (value == NULL)
927 {
929 lexic,
930 "Syntax error with set_kb_item() [null value for name '%s']\n",
931 name);
932 return FAKE_CELL;
933 }
935 }
936
937 return FAKE_CELL;
938}
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:1033

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: