18#include "../misc/network.h"
19#include "../misc/plugutils.h"
20#include "../misc/support.h"
21#include "../misc/vendorversion.h"
33#include <gvm/base/logging.h>
34#include <gvm/base/prefs.h>
35#include <gvm/util/kb.h>
45#define G_LOG_DOMAIN "lib nasl"
54 for (i = 0; i <
len; i++)
56 if (!isdigit (str[i]))
60 snprintf (buf,
sizeof (buf),
"%d", atoi (str));
61 if (strcmp (buf, str) != 0)
97 timeout = g_strdup_printf (
"%d", to);
99 np = nvtpref_new (NVTPREF_TIMEOUT_ID,
"timeout",
"entry", timeout);
100 nvti_add_pref (nvti, np);
118 for (i = 0; cve != NULL; i++)
157 if (((value == NULL) && (csv == NULL)) ||
name == NULL)
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");
172 if ((value == NULL) && (csv == NULL))
174 nasl_perror (lexic,
" <value> and <csv> is empty)\n");
200 if (value == NULL ||
name == NULL)
202 nasl_perror (lexic,
"script_tag() syntax error - should be"
203 " script_tag(name:<name>, value:<value>)\n");
223 if (strchr (value,
'|'))
263 nasl_perror (lexic,
"Argument error in function script_category()\n");
264 nasl_perror (lexic,
"Function usage is : script_category(<category>)\n");
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");
294 for (i = 0; dep != NULL; i++)
312 nasl_perror (lexic,
"Argument error in function script_require_keys()\n");
314 "Function usage is : script_require_keys(<name>...)\n");
315 nasl_perror (lexic,
"Where <name> is the name of a key\n");
319 for (i = 0; keys != NULL; i++)
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");
348 splits = g_strsplit (re,
"=", 0);
350 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
356 for (i = 0; keys != NULL; i++)
360 if (splits && keys && !strcmp (keys, splits[0]))
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");
389 for (i = 0; keys != NULL; i++)
452 "Invalid id or not allowed id value in the call to %s()\n",
456 if (!
name || !type || !value)
459 "Argument error in the call to script_add_preference()\n");
471 nasl_perror (lexic,
"Invalid or already existent preference id\n");
476 np = nvtpref_new (
id,
name, type, value);
499 if (pref == NULL &&
id == -1)
502 "Argument error in the function script_get_preference()\n");
504 "Function usage is : pref = script_get_preference(<name>, "
514 retc->
x.
i_val = atoi (value);
518 retc->
size = strlen (value);
541 "Argument error in the function script_get_preference()\n");
543 "script_get_preference_file_content(<name>)\n");
556 if (contentsize <= 0)
559 "script_get_preference_file_content: could not get "
560 " size of file from preference %s\n",
566 retc->
size = contentsize;
578 const char *value, *local;
584 lexic,
"script_get_preference_file_location: no preference name!\n");
593 "script_get_preference_file_location: could not get preference %s\n",
601 len = strlen (local);
617 retc->
x.
i_val = prefs_get_bool (
"safe_checks");
632 const char *
oid = lexic->
oid;
656 struct kb_item *res, *top;
660 nasl_perror (lexic,
"get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
670 if (strchr (kb_mask,
'*'))
671 top = res = kb_item_get_pattern (kb, kb_mask);
673 top = res = kb_item_get_all (kb, kb_mask);
678 bzero (&v,
sizeof (v));
680 if (res->type == KB_TYPE_INT)
687 else if (res->type == KB_TYPE_STR)
719 if (kb_entry == NULL)
724 if (
val == NULL && type == -1)
728 if (type == KB_TYPE_INT)
788 nasl_perror (lexic,
"Syntax error with replace_kb_item() [null name]\n",
798 GSIZE_TO_POINTER (value));
801 lexic,
"Syntax error with replace_kb_item(%s) [value=-1]\n",
name);
811 "Syntax error with replace_kb_item(%s) [null value]\n",
841 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
849 if (value != -1 && expire != -1)
851 GSIZE_TO_POINTER (value), expire);
854 "Syntax error with set_kb_item() [value=-1 or expire=-1 "
862 if (value == NULL || expire == -1)
865 "Syntax error with set_kb_item() [null value or "
866 "expire=-1 for name '%s']\n",
902 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
914 lexic,
"Syntax error with set_kb_item() [value=-1 for name '%s']\n",
925 "Syntax error with set_kb_item() [null value for name '%s']\n",
941 int,
const char *,
const char *,
947 const char *,
const char *);
966 dup = g_malloc0 ((
len + 1) *
sizeof (
char *));
967 memcpy (dup, data,
len + 1);
969 for (i = 0; i <
len; i++)
977 fprintf (stdout,
"%s\n", dup);
979 fprintf (stdout,
"Success\n");
1045 value = prefs_get (
name);
1051 retc->
size = strlen (value);
1062 retc->
x.
str_val = strdup (version);
1063 retc->
size = strlen (version);
1081 const char *prange = prefs_get (
"port_range");
1083 static u_short *ports = NULL;
1090 nasl_perror (lexic,
"Argument error in scanner_get_port()\n");
1091 nasl_perror (lexic,
"Correct usage is : num = scanner_get_port(<num>)\n");
1093 "Where <num> should be 0 the first time you call it\n");
1099 ports = (u_short *)
getpts ((
char *) prange, &num);
1112 retc->
x.
i_val = ports[idx];
void nasl_perror(lex_ctxt *lexic, char *msg,...)
int get_var_size_by_name(lex_ctxt *, const char *)
char * get_str_var_by_name(lex_ctxt *, const char *)
char * get_str_var_by_num(lex_ctxt *, int)
long int get_int_var_by_num(lex_ctxt *, int, int)
long int get_int_var_by_name(lex_ctxt *, const char *, int)
int get_var_type_by_name(lex_ctxt *, const char *)
tree_cell * script_tag(lex_ctxt *lexic)
tree_cell * log_message(lex_ctxt *lexic)
tree_cell * nasl_scanner_status(lex_ctxt *lexic)
static tree_cell * set_kb_item_volatile(lex_ctxt *lexic)
Set a volate kb item.
void(* post_something_t)(const char *, struct script_infos *, int, const char *, const char *)
tree_cell * script_family(lex_ctxt *lexic)
tree_cell * script_get_preference(lex_ctxt *lexic)
Get a preferences of the current script.
tree_cell * script_get_preference_file_content(lex_ctxt *lexic)
void(* proto_post_something_t)(const char *, struct script_infos *, int, const char *, const char *, const char *)
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
tree_cell * script_get_preference_file_location(lex_ctxt *lexic)
tree_cell * script_xref(lex_ctxt *lexic)
Add a cross reference to the meta data.
tree_cell * security_message(lex_ctxt *lexic)
Send a security message to the client.
tree_cell * nasl_scanner_add_port(lex_ctxt *lexic)
tree_cell * get_host_kb_index(lex_ctxt *lexic)
Get the kb index of the host running the current script.
tree_cell * safe_checks(lex_ctxt *lexic)
tree_cell * script_name(lex_ctxt *lexic)
tree_cell * script_copyright(lex_ctxt *lexic)
tree_cell * script_add_preference(lex_ctxt *lexic)
tree_cell * nasl_scanner_get_port(lex_ctxt *lexic)
tree_cell * get_script_oid(lex_ctxt *lexic)
Return the OID of the current script.
tree_cell * script_oid(lex_ctxt *lexic)
tree_cell * nasl_vendor_version(lex_ctxt *lexic)
tree_cell * script_category(lex_ctxt *lexic)
tree_cell * get_kb_list(lex_ctxt *lexic)
tree_cell * error_message(lex_ctxt *lexic)
tree_cell * script_timeout(lex_ctxt *lexic)
Add timeout preference to VT preferences.
tree_cell * script_require_udp_ports(lex_ctxt *lexic)
tree_cell * get_kb_item(lex_ctxt *lexic)
static int isalldigit(char *str, int len)
tree_cell * script_mandatory_keys(lex_ctxt *lexic)
tree_cell * script_dependencies(lex_ctxt *lexic)
tree_cell * script_exclude_keys(lex_ctxt *lexic)
tree_cell * set_kb_item(lex_ctxt *lexic)
Set a kb item.
tree_cell * replace_kb_item(lex_ctxt *lexic)
tree_cell * script_require_ports(lex_ctxt *lexic)
tree_cell * script_require_keys(lex_ctxt *lexic)
tree_cell * script_cve_id(lex_ctxt *lexic)
tree_cell * script_version(lex_ctxt *lexic)
tree_cell * nasl_get_preference(lex_ctxt *lexic)
tree_cell * alloc_typed_cell(int typ)
void deref_cell(tree_cell *c)
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
void plug_set_key_volatile(struct script_infos *args, char *name, int type, const void *value, int expire)
Set volatile key with expire.
void scanner_add_port(struct script_infos *args, int port, char *proto)
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
void plug_set_dep(struct script_infos *args, const char *depname)
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
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.
void plug_set_key_len_volatile(struct script_infos *args, char *name, int type, const void *value, int expire, size_t len)
Set volatile key with expire.
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
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.
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".
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.
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".
kb_t plug_get_kb(struct script_infos *args)
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".
union st_a_nasl_var::@7 v
struct script_infos * script_infos
const gchar * vendor_version_get()
Get vendor version.