OpenVAS Scanner
7.0.0~git
|
Go to the documentation of this file.
30 #include "../misc/network.h"
31 #include "../misc/plugutils.h"
32 #include "../misc/vendorversion.h"
44 #include <gvm/base/logging.h>
45 #include <gvm/base/prefs.h>
46 #include <gvm/util/kb.h>
56 #define G_LOG_DOMAIN "lib nasl"
65 for (i = 0; i < len; i++)
67 if (!isdigit (str[i]))
71 snprintf (buf,
sizeof (buf),
"%d", atoi (str));
72 if (strcmp (buf, str) != 0)
94 nvti_set_timeout (nvti, to ? to : -1);
112 for (i = 0; cve != NULL; i++)
128 for (i = 0; bid != NULL; i++)
173 if (((value == NULL) && (csv == NULL)) ||
name == NULL)
176 "script_xref() syntax error - should be"
177 " script_xref(name:<name>, value:<value>) or"
178 " script_xref(name:<name>, value:<value>, csv:<CSVs>) or"
179 " script_xref(name:<name>, csv:<CSVs>)\n");
188 if ((value == NULL) && (csv == NULL))
190 nasl_perror (lexic,
" <value> and <csv> is empty)\n");
216 if (value == NULL ||
name == NULL)
218 nasl_perror (lexic,
"script_tag() syntax error - should be"
219 " script_tag(name:<name>, value:<value>)\n");
239 if (strchr (value,
'|'))
279 nasl_perror (lexic,
"Argument error in function script_category()\n");
280 nasl_perror (lexic,
"Function usage is : script_category(<category>)\n");
303 nasl_perror (lexic,
"Argument error in function script_dependencies()\n");
304 nasl_perror (lexic,
"Function usage is : script_dependencies(<name>)\n");
305 nasl_perror (lexic,
"Where <name> is the name of another script\n");
310 for (i = 0; dep != NULL; i++)
328 nasl_perror (lexic,
"Argument error in function script_require_keys()\n");
329 nasl_perror (lexic,
"Function usage is : script_require_keys(<name>)\n");
330 nasl_perror (lexic,
"Where <name> is the name of a key\n");
334 for (i = 0; keys != NULL; i++)
353 "Argument error in function script_mandatory_keys()\n");
355 "Function usage is : script_mandatory_keys(<name>)\n");
356 nasl_perror (lexic,
"Where <name> is the name of a key\n");
362 splits = g_strsplit (re,
"=", 0);
364 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
370 for (i = 0; keys != NULL; i++)
374 if (splits && keys && !strcmp (keys, splits[0]))
397 nasl_perror (lexic,
"Argument error in function script_exclude_keys()\n");
398 nasl_perror (lexic,
"Function usage is : script_exclude_keys(<name>)\n");
399 nasl_perror (lexic,
"Where <name> is the name of a key\n");
403 for (i = 0; keys != NULL; i++)
463 if (!
name || !type || !value)
466 "Argument error in the call to script_add_preference()\n");
478 np = nvtpref_new (
id,
name, type, value);
493 "Argument error in the function script_get_preference()\n");
495 lexic,
"Function usage is : pref = script_get_preference(<name>)\n");
504 retc->
x.
i_val = atoi (value);
508 retc->
size = strlen (value);
531 "Argument error in the function script_get_preference()\n");
533 "script_get_preference_file_content(<name>)\n");
546 if (contentsize <= 0)
549 "script_get_preference_file_content: could not get "
550 " size of file from preference %s\n",
556 retc->
size = contentsize;
568 const char *value, *local;
574 lexic,
"script_get_preference_file_location: no preference name!\n");
583 "script_get_preference_file_location: could not get preference %s\n",
591 len = strlen (local);
594 retc->
x.
str_val = g_malloc0 (len + 1);
595 memcpy (retc->
x.
str_val, local, len + 1);
607 retc->
x.
i_val = prefs_get_bool (
"safe_checks");
623 if (strcmp (value,
"busy") == 0)
647 retc->
size = strlen (value);
665 const char *
oid = lexic->
oid;
689 struct kb_item *res, *top;
693 nasl_perror (lexic,
"get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
703 if (strchr (kb_mask,
'*'))
704 top = res = kb_item_get_pattern (kb, kb_mask);
706 top = res = kb_item_get_all (kb, kb_mask);
711 bzero (&v,
sizeof (v));
713 if (res->type == KB_TYPE_INT)
720 else if (res->type == KB_TYPE_STR)
752 if (kb_entry == NULL)
757 if (
val == NULL && type == -1)
761 if (type == KB_TYPE_INT)
794 nasl_perror (lexic,
"Syntax error with replace_kb_item() [null name]\n",
804 GSIZE_TO_POINTER (value));
807 lexic,
"Syntax error with replace_kb_item(%s) [value=-1]\n",
name);
817 "Syntax error with replace_kb_item(%s) [null value]\n",
836 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
848 lexic,
"Syntax error with set_kb_item() [value=-1 for name '%s']\n",
859 "Syntax error with set_kb_item() [null value for name '%s']\n",
875 int,
const char *,
const char *);
898 dup = g_memdup (data, len + 1);
899 for (i = 0; i < len; i++)
907 fprintf (stdout,
"%s\n", dup);
909 fprintf (stdout,
"Success\n");
975 value = prefs_get (
name);
981 retc->
size = strlen (value);
993 retc->
size = strlen (version);
1011 const char *prange = prefs_get (
"port_range");
1013 static u_short *ports = NULL;
1020 nasl_perror (lexic,
"Argument error in scanner_get_port()\n");
1021 nasl_perror (lexic,
"Correct usage is : num = scanner_get_port(<num>)\n");
1023 "Where <num> should be 0 the first time you call it\n");
1029 ports = (u_short *)
getpts ((
char *) prange, &num);
1042 retc->
x.
i_val = ports[idx];
tree_cell * security_message(lex_ctxt *lexic)
Send a security message to the client.
tree_cell * script_copyright(lex_ctxt *lexic)
void plug_set_dep(struct script_infos *args, const char *depname)
tree_cell * script_require_ports(lex_ctxt *lexic)
tree_cell * script_require_udp_ports(lex_ctxt *lexic)
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
const gchar * vendor_version_get()
Get vendor version.
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action)
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.
int get_var_size_by_name(lex_ctxt *, const char *)
kb_t plug_get_kb(struct script_infos *args)
tree_cell * get_kb_item(lex_ctxt *lexic)
tree_cell * scan_phase(lex_ctxt *lexic)
static int isalldigit(char *str, int len)
tree_cell * nasl_scanner_get_port(lex_ctxt *lexic)
tree_cell * script_exclude_keys(lex_ctxt *lexic)
tree_cell * script_cve_id(lex_ctxt *lexic)
tree_cell * script_family(lex_ctxt *lexic)
void post_error(const char *oid, struct script_infos *desc, int port, const char *action)
char * get_str_var_by_name(lex_ctxt *, const char *)
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action)
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".
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
void post_log(const char *oid, struct script_infos *desc, int port, const char *action)
Post a log message about a tcp port.
tree_cell * nasl_scanner_add_port(lex_ctxt *lexic)
tree_cell * script_dependencies(lex_ctxt *lexic)
tree_cell * set_kb_item(lex_ctxt *lexic)
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
tree_cell * log_message(lex_ctxt *lexic)
tree_cell * script_bugtraq_id(lex_ctxt *lexic)
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
tree_cell * script_add_preference(lex_ctxt *lexic)
tree_cell * nasl_scanner_status(lex_ctxt *lexic)
struct scan_globals * globals
void nasl_perror(lex_ctxt *lexic, char *msg,...)
int get_var_type_by_name(lex_ctxt *, const char *)
tree_cell * script_version(lex_ctxt *lexic)
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
tree_cell * script_require_keys(lex_ctxt *lexic)
tree_cell * script_tag(lex_ctxt *lexic)
void(* post_something_t)(const char *, struct script_infos *, int, const char *)
tree_cell * script_timeout(lex_ctxt *lexic)
long int get_int_var_by_name(lex_ctxt *, const char *, int)
void scanner_add_port(struct script_infos *args, int port, char *proto)
long int get_int_var_by_num(lex_ctxt *, int, int)
char * get_str_var_by_num(lex_ctxt *, int)
tree_cell * script_name(lex_ctxt *lexic)
tree_cell * get_kb_list(lex_ctxt *lexic)
struct script_infos * script_infos
tree_cell * safe_checks(lex_ctxt *lexic)
char * network_scan_status
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".
tree_cell * script_mandatory_keys(lex_ctxt *lexic)
tree_cell * nasl_get_preference(lex_ctxt *lexic)
tree_cell * replace_kb_item(lex_ctxt *lexic)
tree_cell * script_get_preference_file_location(lex_ctxt *lexic)
union st_a_nasl_var::@4 v
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
char * get_plugin_preference(const char *oid, const char *name)
tree_cell * script_xref(lex_ctxt *lexic)
Add a cross reference to the meta data.
tree_cell * script_get_preference_file_content(lex_ctxt *lexic)
tree_cell * nasl_vendor_version(lex_ctxt *lexic)
tree_cell * error_message(lex_ctxt *lexic)
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".
void deref_cell(tree_cell *c)
tree_cell * alloc_typed_cell(int typ)
void(* proto_post_something_t)(const char *, struct script_infos *, int, const char *, const char *)
tree_cell * script_oid(lex_ctxt *lexic)
tree_cell * network_targets(lex_ctxt *lexic)
tree_cell * script_category(lex_ctxt *lexic)
tree_cell * script_get_preference(lex_ctxt *lexic)
void proto_post_log(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action)
Post a log message.
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action)
tree_cell * get_script_oid(lex_ctxt *lexic)
Return the OID of the current script.