OpenVAS Scanner 22.7.9
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_message (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 *)
 

Function Documentation

◆ error_message()

tree_cell * error_message ( lex_ctxt lexic)

Definition at line 1027 of file nasl_scanner_glue.c.

1028{
1030}
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:717
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition: plugutils.c:724

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

762{
763 struct script_infos *script_infos = lexic->script_infos;
764 int val;
765 tree_cell *retc;
766
767 val = kb_get_kb_index (script_infos->key);
768 if (val >= 0)
769 {
771 retc->x.i_val = val;
772 }
773 else
774 return NULL;
775
776 return retc;
777}
const char * val
Definition: nasl_init.c:412
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:28
@ CONST_INT
Definition: nasl_tree.h:79
Definition: nasl_tree.h:94
union TC::@5 x
long int i_val
Definition: nasl_tree.h:104
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:30

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

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

649{
650 struct script_infos *script_infos = lexic->script_infos;
651 kb_t kb = plug_get_kb (script_infos);
652 char *kb_mask = get_str_var_by_num (lexic, 0);
653 tree_cell *retc;
654 int num_elems = 0;
655 nasl_array *a;
656 struct kb_item *res, *top;
657
658 if (kb_mask == NULL)
659 {
660 nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
661 return NULL;
662 }
663
664 if (kb == NULL)
665 return NULL;
666
668 retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
669
670 if (strchr (kb_mask, '*'))
671 top = res = kb_item_get_pattern (kb, kb_mask);
672 else
673 top = res = kb_item_get_all (kb, kb_mask);
674
675 while (res != NULL)
676 {
678 bzero (&v, sizeof (v));
679
680 if (res->type == KB_TYPE_INT)
681 {
682 v.var_type = VAR2_INT;
683 v.v.v_int = res->v_int;
684 add_var_to_array (a, res->name, &v);
685 num_elems++;
686 }
687 else if (res->type == KB_TYPE_STR)
688 {
690 v.v.v_str.s_val = (unsigned char *) res->v_str;
691 v.v.v_str.s_siz = strlen (res->v_str);
692 add_var_to_array (a, res->name, &v);
693 num_elems++;
694 }
695 res = res->next;
696 }
697
698 kb_item_free (top);
699
700 if (num_elems == 0)
701 {
702 deref_cell (retc);
703 return FAKE_CELL;
704 }
705 return retc;
706}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:111
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:181
@ 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
@ 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:1055
void * ref_val
Definition: nasl_tree.h:105
nasl_string_t v_str
Definition: nasl_var.h:47
int var_type
Definition: nasl_var.h:41
union st_a_nasl_var::@7 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 630 of file nasl_scanner_glue.c.

631{
632 const char *oid = lexic->oid;
633 tree_cell *retc = NULL;
634
635 if (oid)
636 {
638 retc->x.str_val = g_strdup (oid);
639 retc->size = strlen (oid);
640 }
641
642 return retc;
643}
const char * oid
const char * oid
Definition: nasl_lex_ctxt.h:31

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

1022{
1024}
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:690
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:710

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

1034{
1035 tree_cell *retc;
1036 char *name;
1037 const char *value;
1038
1039 name = get_str_var_by_num (lexic, 0);
1040 if (name == NULL)
1041 {
1042 nasl_perror (lexic, "get_preference: no name\n");
1043 return NULL;
1044 }
1045 value = prefs_get (name);
1046 if (value == NULL)
1047 return NULL;
1048
1050 retc->x.str_val = strdup (value);
1051 retc->size = strlen (value);
1052 return retc;
1053}
const char * name
Definition: nasl_init.c:411

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_scanner_add_port()

tree_cell * nasl_scanner_add_port ( lex_ctxt lexic)

Definition at line 1117 of file nasl_scanner_glue.c.

1118{
1119 struct script_infos *script_infos = lexic->script_infos;
1120
1121 int port = get_int_var_by_name (lexic, "port", -1);
1122 char *proto = get_str_var_by_name (lexic, "proto");
1123
1124 if (port >= 0)
1125 {
1126 scanner_add_port (script_infos, port, proto ? proto : "tcp");
1127 }
1128
1129 return FAKE_CELL;
1130}
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1118
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1104
void scanner_add_port(struct script_infos *args, int port, char *proto)
Definition: plugutils.c:1049

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

1078{
1079 tree_cell *retc;
1080 int idx = get_int_var_by_num (lexic, 0, -1);
1081 const char *prange = prefs_get ("port_range");
1082 static int num = 0;
1083 static u_short *ports = NULL;
1084
1085 if (prange == NULL)
1086 return NULL;
1087
1088 if (idx < 0)
1089 {
1090 nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1091 nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1092 nasl_perror (lexic,
1093 "Where <num> should be 0 the first time you call it\n");
1094 return NULL;
1095 }
1096
1097 if (ports == NULL)
1098 {
1099 ports = (u_short *) getpts ((char *) prange, &num);
1100 if (ports == NULL)
1101 {
1102 return NULL;
1103 }
1104 }
1105
1106 if (idx >= num)
1107 {
1108 return NULL;
1109 }
1110
1111 retc = alloc_typed_cell (CONST_INT);
1112 retc->x.i_val = ports[idx];
1113 return retc;
1114}
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 1133 of file nasl_scanner_glue.c.

1134{
1135 /* Kept for backward compatibility. */
1136 (void) lexic;
1137 return FAKE_CELL;
1138}

References FAKE_CELL.

◆ nasl_vendor_version()

tree_cell * nasl_vendor_version ( lex_ctxt lexic)

Definition at line 1056 of file nasl_scanner_glue.c.

1057{
1058 tree_cell *retc;
1059 gchar *version = g_strdup (vendor_version_get ());
1060 (void) lexic;
1062 retc->x.str_val = strdup (version);
1063 retc->size = strlen (version);
1064 g_free (version);
1065
1066 return retc;
1067}
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:38

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

781{
782 struct script_infos *script_infos = lexic->script_infos;
783 char *name = get_str_var_by_name (lexic, "name");
784 int type = get_var_type_by_name (lexic, "value");
785
786 if (name == NULL)
787 {
788 nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
789 name);
790 return FAKE_CELL;
791 }
792
793 if (type == VAR2_INT)
794 {
795 int value = get_int_var_by_name (lexic, "value", -1);
796 if (value != -1)
798 GSIZE_TO_POINTER (value));
799 else
801 lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
802 }
803 else
804 {
805 char *value = get_str_var_by_name (lexic, "value");
806 int len = get_var_size_by_name (lexic, "value");
807
808 if (value == NULL)
809 {
810 nasl_perror (lexic,
811 "Syntax error with replace_kb_item(%s) [null value]\n",
812 name);
813 return FAKE_CELL;
814 }
816 }
817
818 return FAKE_CELL;
819}
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:1020
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
Definition: plugutils.c:1043
#define ARG_STRING
Definition: plugutils.h:19
#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 612 of file nasl_scanner_glue.c.

613{
614 (void) lexic;
616
617 retc->x.i_val = prefs_get_bool ("safe_checks");
618
619 return retc;
620}

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

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

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

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

249{
250 (void) lexic;
251 return FAKE_CELL;
252}

References FAKE_CELL.

◆ script_cve_id()

tree_cell * script_cve_id ( lex_ctxt lexic)

Definition at line 112 of file nasl_scanner_glue.c.

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

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

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

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

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

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

273{
274 nvti_set_family (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
275 return FAKE_CELL;
276}

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

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

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

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

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

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

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

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

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

235{
236 nvti_set_name (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
237 return FAKE_CELL;
238}

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

106{
107 nvti_set_oid (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
108 return FAKE_CELL;
109}

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

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

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

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

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

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

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

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

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

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

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

242{
243 (void) lexic;
244 return FAKE_CELL;
245}

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

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

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

1016{
1018}
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition: plugutils.c:680
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:673

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

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

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

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: