OpenVAS Libraries  9.0.3
nasl_misc_funcs.c File Reference
#include <glib.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "../misc/ftp_funcs.h"
#include "../base/kb.h"
#include "../misc/network.h"
#include "../misc/plugutils.h"
#include "../base/openvas_compress.h"
#include "nasl_tree.h"
#include "nasl_global_ctxt.h"
#include "nasl_func.h"
#include "nasl_var.h"
#include "nasl_lex_ctxt.h"
#include "exec.h"
#include "nasl_packet_forgery.h"
#include "nasl_debug.h"
#include "nasl_misc_funcs.h"
#include "byteorder.h"
Include dependency graph for nasl_misc_funcs.c:

Go to the source code of this file.

Macros

#define uint32   unsigned int
 
#define NASL_EXIT_DEPRECATED   66
 
#define NASL_EXIT_NOTVULN   99
 
#define iac   buffer[0]
 
#define code   buffer[1]
 
#define option   buffer[2]
 
#define BOGUS   "are you dead ?"
 

Functions

tree_cellnasl_rand (lex_ctxt *lexic)
 
tree_cellnasl_usleep (lex_ctxt *lexic)
 
tree_cellnasl_sleep (lex_ctxt *lexic)
 
tree_cellnasl_ftp_log_in (lex_ctxt *lexic)
 
tree_cellnasl_ftp_get_pasv_address (lex_ctxt *lexic)
 
tree_cellnasl_telnet_init (lex_ctxt *lexic)
 
tree_cellnasl_start_denial (lex_ctxt *lexic)
 
tree_cellnasl_end_denial (lex_ctxt *lexic)
 
tree_cellnasl_dump_ctxt (lex_ctxt *lexic)
 
tree_cellnasl_do_exit (lex_ctxt *lexic)
 
tree_cellnasl_isnull (lex_ctxt *lexic)
 
tree_cellnasl_make_list (lex_ctxt *lexic)
 
tree_cellnasl_make_array (lex_ctxt *lexic)
 
tree_cellnasl_keys (lex_ctxt *lexic)
 
tree_cellnasl_max_index (lex_ctxt *lexic)
 
tree_cellnasl_typeof (lex_ctxt *lexic)
 
tree_cellnasl_defined_func (lex_ctxt *lexic)
 
tree_cellnasl_func_named_args (lex_ctxt *lexic)
 
tree_cellnasl_func_unnamed_args (lex_ctxt *lexic)
 
tree_cellnasl_func_has_arg (lex_ctxt *lexic)
 
tree_cellnasl_sort_array (lex_ctxt *lexic)
 
tree_cellnasl_unixtime (lex_ctxt *lexic)
 
tree_cellnasl_gettimeofday (lex_ctxt *lexic)
 
tree_cellnasl_localtime (lex_ctxt *lexic)
 
tree_cellnasl_mktime (lex_ctxt *lexic)
 
tree_cellnasl_open_sock_kdc (lex_ctxt *lexic)
 
tree_cellnasl_gunzip (lex_ctxt *lexic)
 
tree_cellnasl_gzip (lex_ctxt *lexic)
 
tree_cellnasl_dec2str (lex_ctxt *lexic)
 
tree_cellnasl_get_byte_order (lex_ctxt *lexic)
 

Macro Definition Documentation

◆ BOGUS

#define BOGUS   "are you dead ?"

Referenced by nasl_end_denial().

◆ code

◆ iac

#define iac   buffer[0]

Referenced by nasl_telnet_init().

◆ NASL_EXIT_DEPRECATED

#define NASL_EXIT_DEPRECATED   66

Definition at line 51 of file nasl_misc_funcs.c.

◆ NASL_EXIT_NOTVULN

#define NASL_EXIT_NOTVULN   99

Definition at line 52 of file nasl_misc_funcs.c.

Referenced by nasl_do_exit().

◆ option

#define option   buffer[2]

Referenced by nasl_send(), and nasl_telnet_init().

◆ uint32

#define uint32   unsigned int

Definition at line 49 of file nasl_misc_funcs.c.

Referenced by nasl_dec2str().

Function Documentation

◆ nasl_dec2str()

tree_cell* nasl_dec2str ( lex_ctxt lexic)

Definition at line 1007 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), nasl_perror(), SIVAL, TC::size, TC::str_val, TC::type, uint32, and TC::x.

1008 {
1009  /*converts integer to 4 byte buffer */
1010  uint32 num = get_int_local_var_by_name (lexic, "num", -1);
1011  if (num == -1)
1012  {
1013  nasl_perror (lexic, "Syntax : dec2str(num:<n>)\n");
1014  return NULL;
1015  }
1016  char *ret = g_malloc0 (sizeof (num));
1017  SIVAL (ret, 0, num);
1018  tree_cell *retc;
1019  retc = alloc_tree_cell (0, NULL);
1020  retc->type = CONST_DATA;
1021  retc->size = sizeof (num);
1022  retc->x.str_val = ret;
1023  return retc;
1024 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
#define SIVAL(buf, pos, val)
Definition: byteorder.h:123
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
#define uint32
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_defined_func()

tree_cell* nasl_defined_func ( lex_ctxt lexic)

Definition at line 608 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_INT, get_func_ref_by_name(), get_str_var_by_num(), TC::i_val, nasl_perror(), TC::type, and TC::x.

609 {
610  void *f;
611  char *s;
612  tree_cell *retc;
613 
614  s = get_str_var_by_num (lexic, 0);
615  if (s == NULL)
616  {
617  nasl_perror (lexic, "defined_func: missing parameter\n");
618  return NULL;
619  }
620 
621  f = get_func_ref_by_name (lexic, s);
622  retc = alloc_tree_cell (0, NULL);
623  retc->type = CONST_INT;
624  retc->x.i_val = (f != NULL);
625  return retc;
626 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:126
Here is the call graph for this function:

◆ nasl_do_exit()

tree_cell* nasl_do_exit ( lex_ctxt lexic)

Definition at line 331 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_INT, get_int_var_by_num(), TC::i_val, NASL_EXIT_NOTVULN, TC::type, and TC::x.

332 {
333  int retcode = get_int_var_by_num (lexic, 0, 0);
334  tree_cell *retc = alloc_tree_cell (0, NULL);
335 
336  retc->type = CONST_INT;
337  retc->x.i_val = retcode;
338 
339  if (retcode == NASL_EXIT_NOTVULN)
340  simple_register_host_detail(lexic, "EXIT_CODE", "EXIT_NOTVULN");
341 
342 // if (retcode == NASL_EXIT_DEPRECATED)
343  // This return code is reserved for future handling.
344 
345  while (lexic != NULL)
346  {
347  lexic->ret_val = retc;
348  ref_cell (retc);
349  lexic = lexic->up_ctxt;
350  }
351  return retc;
352 }
void ref_cell(tree_cell *c)
Definition: nasl_tree.c:188
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
long int i_val
Definition: nasl_tree.h:114
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:34
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
#define NASL_EXIT_NOTVULN
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:33
Here is the call graph for this function:

◆ nasl_dump_ctxt()

tree_cell* nasl_dump_ctxt ( lex_ctxt lexic)

Definition at line 309 of file nasl_misc_funcs.c.

References dump_ctxt(), FAKE_CELL, and struct_lex_ctxt::up_ctxt.

310 {
311  dump_ctxt (lexic->up_ctxt);
312  return FAKE_CELL;
313 }
#define FAKE_CELL
Definition: nasl_tree.h:120
void dump_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:64
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:33
Here is the call graph for this function:

◆ nasl_end_denial()

tree_cell* nasl_end_denial ( lex_ctxt lexic)

Definition at line 255 of file nasl_misc_funcs.c.

References alloc_tree_cell(), arg_get_value_int(), BOGUS, close_stream_connection(), CONST_INT, TC::i_val, nasl_tcp_ping(), nsend(), open_stream_connection(), OPENVAS_ENCAPS_IP, struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, TC::type, and TC::x.

256 {
257  int port = arg_get_value_int (lexic->script_infos, "denial_port");
258  int soc;
259  int to = lexic->recv_timeout;
260  struct arglist *script_infos = lexic->script_infos;
261  tree_cell *retc = NULL;
262 
263  /*
264  * We must wait the time the DoS does its effect
265  */
266  sleep (10);
267 
268  if (!port)
269  {
270  int ping = arg_get_value_int (script_infos, "tcp_ping_result");
271 
272  if (ping)
273  return nasl_tcp_ping (lexic);
274  else
275  {
276  retc = alloc_tree_cell (0, NULL);
277  retc->type = CONST_INT;
278  retc->x.i_val = 1;
279  return retc;
280  }
281  }
282  else
283  {
284  retc = alloc_tree_cell (0, NULL);
285  retc->type = CONST_INT;
286 
287  soc = open_stream_connection (script_infos, port, OPENVAS_ENCAPS_IP, to);
288  if (soc > 0)
289  {
290  /* Send some data */
291 #define BOGUS "are you dead ?"
292  if ((nsend (soc, BOGUS, sizeof (BOGUS) - 1, 0)) >= 0)
293  {
294  retc->x.i_val = 1;
296  return retc;
297  }
298  }
299  }
300 
301  retc->x.i_val = 0;
302  return retc;
303 }
short type
Definition: nasl_tree.h:107
int open_stream_connection(struct arglist *args, unsigned int port, int transport, int timeout)
Definition: network.c:1117
union TC::@7 x
int nsend(int fd, void *data, int length, int i_opt)
Definition: network.c:1577
Definition: nasl_tree.h:105
#define BOGUS
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int arg_get_value_int(struct arglist *args, const char *name)
Definition: arglists.c:246
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
tree_cell * nasl_tcp_ping(lex_ctxt *lexic)
int close_stream_connection(int fd)
Definition: network.c:1699
Here is the call graph for this function:

◆ nasl_ftp_get_pasv_address()

tree_cell* nasl_ftp_get_pasv_address ( lex_ctxt lexic)

Definition at line 115 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_INT, ftp_get_pasv_address(), and get_int_local_var_by_name().

116 {
117  int soc;
118  struct sockaddr_in addr;
119  tree_cell *retc;
120 
121  soc = get_int_local_var_by_name (lexic, "socket", 0);
122  if (soc <= 0)
123  return NULL;
124 
125  bzero (&addr, sizeof (addr));
126  ftp_get_pasv_address (soc, &addr);
127 
128  retc = alloc_tree_cell (0, NULL);
129  retc->type = CONST_INT;
130  retc->x.i_val = ntohs (addr.sin_port);
131  return retc;
132 }
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
Definition: nasl_tree.h:105
int ftp_get_pasv_address(int soc, struct sockaddr_in *addr)
Definition: ftp_funcs.c:124
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_ftp_log_in()

tree_cell* nasl_ftp_log_in ( lex_ctxt lexic)

Definition at line 86 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_INT, ftp_log_in(), get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, TC::type, and TC::x.

87 {
88  char *u, *p;
89  int soc;
90  tree_cell *retc;
91  int res;
92 
93  soc = get_int_local_var_by_name (lexic, "socket", 0);
94  if (soc <= 0)
95  return NULL;
96 
97  u = get_str_local_var_by_name (lexic, "user");
98  if (u == NULL)
99  u = "";
100 
101  p = get_str_local_var_by_name (lexic, "pass");
102  if (p == NULL)
103  p = "";
104 
105  res = ftp_log_in (soc, u, p) == 0;
106 
107  retc = alloc_tree_cell (0, NULL);
108  retc->type = CONST_INT;
109  retc->x.i_val = res;
110 
111  return retc;
112 }
short type
Definition: nasl_tree.h:107
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
int ftp_log_in(int soc, char *username, char *passwd)
Definition: ftp_funcs.c:37
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_func_has_arg()

tree_cell* nasl_func_has_arg ( lex_ctxt lexic)

Definition at line 698 of file nasl_misc_funcs.c.

References alloc_typed_cell(), st_nasl_func::args_names, CONST_INT, get_func_ref_by_name(), get_int_var_by_num(), get_str_var_by_num(), get_var_type_by_num(), TC::i_val, nasl_perror(), st_nasl_func::nb_named_args, VAR2_DATA, VAR2_INT, VAR2_STRING, and TC::x.

699 {
700  nasl_func *f;
701  char *s;
702  int vt, i, flag = 0;
703  tree_cell *retc;
704 
705 
706  s = get_str_var_by_num (lexic, 0);
707  if (s == NULL)
708  {
709  nasl_perror (lexic, "func_has_arg: missing parameter\n");
710  return NULL;
711  }
712 
713  f = get_func_ref_by_name (lexic, s);
714  if (f == NULL)
715  {
716  nasl_perror (lexic, "func_args: unknown function \"%s\"\n", s);
717  return NULL;
718  }
719 
720  vt = get_var_type_by_num (lexic, 1);
721  switch (vt)
722  {
723  case VAR2_INT:
724  i = get_int_var_by_num (lexic, 1, -1);
725  if (i >= 0 && i < f->nb_unnamed_args)
726  flag = 1;
727  break;
728 
729  case VAR2_STRING:
730  case VAR2_DATA:
731  s = get_str_var_by_num (lexic, 1);
732  for (i = 0; i < f->nb_named_args && !flag; i++)
733  if (strcmp (s, f->args_names[i]) == 0)
734  flag = 1;
735  break;
736 
737  default:
738  nasl_perror (lexic,
739  "func_has_arg: string or integer expected as 2nd parameter\n");
740  return NULL;
741  }
742 
743  retc = alloc_typed_cell (CONST_INT);
744  retc->x.i_val = flag;
745  return retc;
746 }
char ** args_names
Definition: nasl_func.h:35
int nb_named_args
Definition: nasl_func.h:34
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
long int i_val
Definition: nasl_tree.h:114
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:126
int get_var_type_by_num(lex_ctxt *, int)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
Definition: nasl_var.c:1315
Here is the call graph for this function:

◆ nasl_func_named_args()

tree_cell* nasl_func_named_args ( lex_ctxt lexic)

Definition at line 629 of file nasl_misc_funcs.c.

References add_var_to_list(), alloc_typed_cell(), st_nasl_func::args_names, DYN_ARRAY, get_func_ref_by_name(), get_str_var_by_num(), nasl_perror(), st_nasl_func::nb_named_args, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, st_a_nasl_var::v, st_a_nasl_var::v_str, VAR2_STRING, st_a_nasl_var::var_type, and TC::x.

630 {
631  nasl_func *f;
632  char *s;
633  int i;
634  tree_cell *retc;
635  nasl_array *a;
636  anon_nasl_var v;
637 
638  s = get_str_var_by_num (lexic, 0);
639  if (s == NULL)
640  {
641  nasl_perror (lexic, "func_named_args: missing parameter\n");
642  return NULL;
643  }
644 
645  f = get_func_ref_by_name (lexic, s);
646  if (f == NULL)
647  {
648  nasl_perror (lexic, "func_named_args: unknown function \"%s\"\n", s);
649  return NULL;
650  }
651 
652  retc = alloc_typed_cell (DYN_ARRAY);
653  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
654 
655  memset (&v, 0, sizeof (v));
656  v.var_type = VAR2_STRING;
657 
658  for (i = 0; i < f->nb_named_args; i++)
659  {
660  v.v.v_str.s_val = (unsigned char *) f->args_names[i];
661  v.v.v_str.s_siz = strlen (f->args_names[i]);
662  if (add_var_to_list (a, i, &v) < 0)
663  nasl_perror (lexic,
664  "func_named_args: add_var_to_list failed (internal error)\n");
665  }
666 
667  return retc;
668 }
union st_a_nasl_var::@9 v
void * ref_val
Definition: nasl_tree.h:115
nasl_string_t v_str
Definition: nasl_var.h:60
char ** args_names
Definition: nasl_func.h:35
int nb_named_args
Definition: nasl_func.h:34
union TC::@7 x
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1403
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
unsigned char * s_val
Definition: nasl_var.h:35
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:126
Here is the call graph for this function:

◆ nasl_func_unnamed_args()

tree_cell* nasl_func_unnamed_args ( lex_ctxt lexic)

Definition at line 671 of file nasl_misc_funcs.c.

References alloc_typed_cell(), CONST_INT, get_func_ref_by_name(), get_str_var_by_num(), TC::i_val, nasl_perror(), st_nasl_func::nb_unnamed_args, and TC::x.

672 {
673  nasl_func *f;
674  char *s;
675  tree_cell *retc;
676 
677  s = get_str_var_by_num (lexic, 0);
678  if (s == NULL)
679  {
680  nasl_perror (lexic, "func_unnamed_args: missing parameter\n");
681  return NULL;
682  }
683 
684  f = get_func_ref_by_name (lexic, s);
685  if (f == NULL)
686  {
687  nasl_perror (lexic, "func_unnamed_args: unknown function \"%s\"\n", s);
688  return NULL;
689  }
690 
691  retc = alloc_typed_cell (CONST_INT);
692  retc->x.i_val = f->nb_unnamed_args;
693  return retc;
694 }
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
int nb_unnamed_args
Definition: nasl_func.h:34
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
long int i_val
Definition: nasl_tree.h:114
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:126
Here is the call graph for this function:

◆ nasl_get_byte_order()

tree_cell* nasl_get_byte_order ( lex_ctxt lexic)

This function returns 1 on little-endian systems, 0 otherwise

Definition at line 1030 of file nasl_misc_funcs.c.

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

1031 {
1032  tree_cell *retc;
1033  short w = 0x0001;
1034  char *p = (char *) &w;
1035  int val;
1036 
1037  val = (*p == 1);
1038 
1039  retc = alloc_typed_cell (CONST_INT);
1040  retc->x.i_val = val;
1041  return retc;
1042 }
const char * val
Definition: nasl_init.c:525
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
Here is the call graph for this function:

◆ nasl_gettimeofday()

tree_cell* nasl_gettimeofday ( lex_ctxt lexic)

Definition at line 802 of file nasl_misc_funcs.c.

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

803 {
804  tree_cell *retc;
805  struct timeval t;
806  char str[64];
807 
808  if (gettimeofday (&t, NULL) < 0)
809  {
810  nasl_perror (lexic, "gettimeofday: %s\n", strerror (errno));
811  return NULL;
812  }
813  sprintf (str, "%u.%06u", (unsigned int) t.tv_sec, (unsigned int) t.tv_usec);
814  retc = alloc_typed_cell (CONST_DATA);
815  retc->size = strlen (str);
816  retc->x.str_val = g_malloc0 (retc->size);
817  strcpy (retc->x.str_val, str);
818  return retc;
819 }
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
struct timeval timeval(unsigned long val)
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_gunzip()

tree_cell* nasl_gunzip ( lex_ctxt lexic)

Definition at line 954 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_DATA, get_str_local_var_by_name(), get_var_size_by_name(), openvas_uncompress(), TC::size, TC::str_val, TC::type, and TC::x.

955 {
956  tree_cell *retc;
957  void *data, *uncompressed;
958  unsigned long datalen, uncomplen;
959 
960  data = get_str_local_var_by_name (lexic, "data");
961  if (data == NULL)
962  return NULL;
963  datalen = get_var_size_by_name (lexic, "data");
964  if (datalen <= 0)
965  return NULL;
966 
967  uncompressed = openvas_uncompress (data, datalen, &uncomplen);
968  if (uncompressed == NULL)
969  return NULL;
970 
971  retc = alloc_tree_cell (0, NULL);
972  retc->type = CONST_DATA;
973  retc->size = uncomplen;
974  retc->x.str_val = uncompressed;
975 
976  return retc;
977 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void * openvas_uncompress(const void *src, unsigned long srclen, unsigned long *dstlen)
Uncompresses data in src buffer.
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_gzip()

tree_cell* nasl_gzip ( lex_ctxt lexic)

Definition at line 980 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_DATA, get_str_local_var_by_name(), get_var_size_by_name(), openvas_compress(), TC::size, TC::str_val, TC::type, and TC::x.

981 {
982  tree_cell *retc;
983  void *data, *compressed;
984  unsigned long datalen, complen;
985 
986  data = get_str_local_var_by_name (lexic, "data");
987  if (data == NULL)
988  return NULL;
989  datalen = get_var_size_by_name (lexic, "data");
990  if (datalen <= 0)
991  return NULL;
992 
993  compressed = openvas_compress (data, datalen, &complen);
994  if (compressed == NULL)
995  return NULL;
996 
997  retc = alloc_tree_cell (0, NULL);
998  retc->type = CONST_DATA;
999  retc->size = complen;
1000  retc->x.str_val = compressed;
1001 
1002  return retc;
1003 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * openvas_compress(const void *src, unsigned long srclen, unsigned long *dstlen)
Compresses data in src buffer.
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_isnull()

tree_cell* nasl_isnull ( lex_ctxt lexic)

Definition at line 359 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_INT, get_var_type_by_num(), TC::i_val, TC::type, VAR2_UNDEF, and TC::x.

360 {
361  int t;
362  tree_cell *retc;
363 
364  t = get_var_type_by_num (lexic, 0);
365  retc = alloc_tree_cell (0, NULL);
366  retc->type = CONST_INT;
367  retc->x.i_val = (t == VAR2_UNDEF);
368  return retc;
369 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_type_by_num(lex_ctxt *, int)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
Definition: nasl_var.c:1315
Here is the call graph for this function:

◆ nasl_keys()

tree_cell* nasl_keys ( lex_ctxt lexic)

Definition at line 498 of file nasl_misc_funcs.c.

References add_var_to_list(), alloc_tree_cell(), struct_lex_ctxt::ctx_vars, DYN_ARRAY, st_nasl_array::hash_elt, st_nasl_array::max_idx, nasl_get_var_by_num(), nasl_perror(), st_n_nasl_var::next_var, st_nasl_array::num_elt, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, TC::type, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_INT, VAR2_STRING, VAR2_UNDEF, st_n_nasl_var::var_name, VAR_NAME_HASH, st_a_nasl_var::var_type, and TC::x.

499 {
500  tree_cell *retc = NULL;
501  anon_nasl_var *v, myvar;
502  named_nasl_var *vn;
503  nasl_array *a, *a2;
504  int i, j, vi;
505 
506  retc = alloc_tree_cell (0, NULL);
507  retc->type = DYN_ARRAY;
508  retc->x.ref_val = a2 = g_malloc0 (sizeof (nasl_array));
509 
510  bzero (&myvar, sizeof (myvar));
511 
512  for (i = vi = 0; (v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi, 0)) != NULL;
513  vi++)
514  {
515  if (v->var_type == VAR2_ARRAY)
516  {
517  a = &v->v.v_arr;
518  /* First the numerical index */
519  for (j = 0; j < a->max_idx; j++)
520  if (a->num_elt[j] != NULL && a->num_elt[j]->var_type != VAR2_UNDEF)
521  {
522  myvar.var_type = VAR2_INT;
523  myvar.v.v_int = j;
524  add_var_to_list (a2, i++, &myvar);
525  }
526  /* Then the string index */
527  if (a->hash_elt != NULL)
528  for (j = 0; j < VAR_NAME_HASH; j++)
529  for (vn = a->hash_elt[j]; vn != NULL; vn = vn->next_var)
530  if (vn->u.var_type != VAR2_UNDEF)
531  {
532  myvar.var_type = VAR2_STRING;
533  myvar.v.v_str.s_val = (unsigned char *) vn->var_name;
534  myvar.v.v_str.s_siz = strlen (vn->var_name);
535  add_var_to_list (a2, i++, &myvar);
536  }
537  }
538  else
539  nasl_perror (lexic, "nasl_keys: bad variable #%d skipped\n", vi);
540  }
541 
542  return retc;
543 }
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition: nasl_var.c:71
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
struct st_n_nasl_var * next_var
Definition: nasl_var.h:74
char * var_name
Definition: nasl_var.h:70
short type
Definition: nasl_tree.h:107
union st_a_nasl_var::@9 v
struct st_a_nasl_var u
Definition: nasl_var.h:68
void * ref_val
Definition: nasl_tree.h:115
nasl_string_t v_str
Definition: nasl_var.h:60
nasl_array v_arr
Definition: nasl_var.h:62
union TC::@7 x
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1403
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
#define VAR_NAME_HASH
Definition: nasl_var.h:31
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
unsigned char * s_val
Definition: nasl_var.h:35
long int v_int
Definition: nasl_var.h:61
Here is the call graph for this function:

◆ nasl_localtime()

tree_cell* nasl_localtime ( lex_ctxt lexic)

Definition at line 822 of file nasl_misc_funcs.c.

References add_var_to_array(), alloc_typed_cell(), DYN_ARRAY, get_int_local_var_by_name(), get_int_var_by_num(), nasl_perror(), TC::ref_val, st_a_nasl_var::v, st_a_nasl_var::v_int, VAR2_INT, st_a_nasl_var::var_type, and TC::x.

823 {
824  tree_cell *retc;
825  struct tm *ptm;
826  time_t tictac;
827  int utc;
828  nasl_array *a;
829  anon_nasl_var v;
830 
831 
832  tictac = get_int_var_by_num (lexic, 0, 0);
833  if (tictac == 0)
834  tictac = time (NULL);
835  utc = get_int_local_var_by_name (lexic, "utc", 0);
836 
837  if (utc)
838  ptm = gmtime (&tictac);
839  else
840  ptm = localtime (&tictac);
841 
842  if (ptm == NULL)
843  {
844  nasl_perror (lexic, "localtime(%d,utc=%d): %s\n", tictac, utc,
845  strerror (errno));
846  return NULL;
847  }
848 
849  retc = alloc_typed_cell (DYN_ARRAY);
850  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
851  memset (&v, 0, sizeof (v));
852  v.var_type = VAR2_INT;
853 
854  v.v.v_int = ptm->tm_sec;
855  add_var_to_array (a, "sec", &v); /* seconds */
856  v.v.v_int = ptm->tm_min;
857  add_var_to_array (a, "min", &v); /* minutes */
858  v.v.v_int = ptm->tm_hour;
859  add_var_to_array (a, "hour", &v); /* hours */
860  v.v.v_int = ptm->tm_mday;
861  add_var_to_array (a, "mday", &v); /* day of the month */
862  v.v.v_int = ptm->tm_mon + 1;
863  add_var_to_array (a, "mon", &v); /* month */
864  v.v.v_int = ptm->tm_year + 1900;
865  add_var_to_array (a, "year", &v); /* year */
866  v.v.v_int = ptm->tm_wday;
867  add_var_to_array (a, "wday", &v); /* day of the week */
868  v.v.v_int = ptm->tm_yday + 1;
869  add_var_to_array (a, "yday", &v); /* day in the year */
870  v.v.v_int = ptm->tm_isdst;
871  add_var_to_array (a, "isdst", &v); /* daylight saving time */
872 
873  return retc;
874 }
union st_a_nasl_var::@9 v
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1432
void * ref_val
Definition: nasl_tree.h:115
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int v_int
Definition: nasl_var.h:61
Here is the call graph for this function:

◆ nasl_make_array()

tree_cell* nasl_make_array ( lex_ctxt lexic)

Definition at line 447 of file nasl_misc_funcs.c.

References add_var_to_array(), add_var_to_list(), alloc_tree_cell(), struct_lex_ctxt::ctx_vars, DYN_ARRAY, nasl_get_var_by_num(), nasl_perror(), TC::ref_val, TC::type, st_a_nasl_var::v, st_a_nasl_var::v_int, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, var2str(), st_a_nasl_var::var_type, and TC::x.

448 {
449  tree_cell *retc = NULL;
450  int vi;
451  anon_nasl_var *v, *v2;
452  nasl_array *a;
453 
454 
455  retc = alloc_tree_cell (0, NULL);
456  retc->type = DYN_ARRAY;
457  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
458 
459  vi = 0;
460  while ((v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi++, 0)) != NULL)
461  {
462  v2 = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi++, 0);
463  if (v2 == NULL)
464  {
465  nasl_perror (lexic, "make_array: odd number (%d) of argument?\n", vi);
466  break;
467  }
468 
469  switch (v2->var_type)
470  {
471  case VAR2_INT:
472  case VAR2_STRING:
473  case VAR2_DATA:
474  switch (v->var_type)
475  {
476  case VAR2_INT:
477  add_var_to_list (a, v->v.v_int, v2);
478  break;
479  case VAR2_STRING:
480  case VAR2_DATA:
481  add_var_to_array (a, (char *) var2str (v), v2);
482  break;
483  }
484  break;
485  case VAR2_UNDEF:
486  default:
487  nasl_perror (lexic, "make_array: bad value type %d for arg #%d\n",
488  v2->var_type, vi);
489  break;
490  }
491  }
492 
493  return retc;
494 }
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition: nasl_var.c:71
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
short type
Definition: nasl_tree.h:107
union st_a_nasl_var::@9 v
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1432
void * ref_val
Definition: nasl_tree.h:115
union TC::@7 x
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1403
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
const char * var2str(const anon_nasl_var *v)
Definition: nasl_var.c:1189
long int v_int
Definition: nasl_var.h:61
Here is the call graph for this function:

◆ nasl_make_list()

tree_cell* nasl_make_list ( lex_ctxt lexic)

This function takes any kind & any number of arguments and makes an array from them. If an argument is an array, its index are lost

Definition at line 377 of file nasl_misc_funcs.c.

References add_var_to_list(), alloc_tree_cell(), struct_lex_ctxt::ctx_vars, DYN_ARRAY, st_nasl_array::hash_elt, st_nasl_array::max_idx, nasl_get_var_by_num(), nasl_perror(), st_n_nasl_var::next_var, st_nasl_array::num_elt, TC::ref_val, TC::type, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_arr, VAR2_ARRAY, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, VAR_NAME_HASH, st_a_nasl_var::var_type, and TC::x.

378 {
379  tree_cell *retc = NULL;
380  int i, j, vi;
381  anon_nasl_var *v;
382  named_nasl_var *vn;
383  nasl_array *a, *a2;
384 
385 
386  retc = alloc_tree_cell (0, NULL);
387  retc->type = DYN_ARRAY;
388  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
389 
390  for (i = vi = 0; (v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi, 0)) != NULL;
391  vi++)
392  {
393  switch (v->var_type)
394  {
395  case VAR2_INT:
396  case VAR2_STRING:
397  case VAR2_DATA:
398  add_var_to_list (a, i++, v);
399  break;
400 
401  case VAR2_ARRAY:
402  a2 = &v->v.v_arr;
403 
404  for (j = 0; j < a2->max_idx; j++)
405  if (add_var_to_list (a, i, a2->num_elt[j]) >= 1)
406  i++;
407 
408  if (a2->hash_elt != NULL)
409  {
410 #if NASL_DEBUG > 1
411  nasl_perror (lexic,
412  "make_list: named arguments in array have no order\n");
413 #endif
414  for (j = 0; j < VAR_NAME_HASH; j++)
415  for (vn = a2->hash_elt[j]; vn != NULL; vn = vn->next_var)
416  if (vn->u.var_type != VAR2_UNDEF)
417  if (add_var_to_list (a, i, &vn->u) >= 1)
418  i++;
419  }
420 
421  break;
422 
423  case VAR2_UNDEF:
424  nasl_perror (lexic,
425  "nasl_make_list: undefined variable #%d skipped\n", i);
426  continue;
427 
428  default:
429  nasl_perror (lexic,
430  "nasl_make_list: unhandled variable type 0x%x - skipped\n",
431  v->var_type);
432  continue;
433  }
434  }
435 
436  return retc;
437 }
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition: nasl_var.c:71
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
struct st_n_nasl_var * next_var
Definition: nasl_var.h:74
short type
Definition: nasl_tree.h:107
union st_a_nasl_var::@9 v
struct st_a_nasl_var u
Definition: nasl_var.h:68
void * ref_val
Definition: nasl_tree.h:115
nasl_array v_arr
Definition: nasl_var.h:62
union TC::@7 x
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1403
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
#define VAR_NAME_HASH
Definition: nasl_var.h:31
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_max_index()

tree_cell* nasl_max_index ( lex_ctxt lexic)

Definition at line 546 of file nasl_misc_funcs.c.

References alloc_tree_cell(), array_max_index(), CONST_INT, struct_lex_ctxt::ctx_vars, TC::i_val, nasl_get_var_by_num(), TC::type, st_a_nasl_var::v, st_a_nasl_var::v_arr, VAR2_ARRAY, st_a_nasl_var::var_type, and TC::x.

547 {
548  tree_cell *retc;
549  anon_nasl_var *v;
550  nasl_array *a;
551 
552  v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, 0, 0);
553  if (v == NULL)
554  return NULL;
555  if (v->var_type != VAR2_ARRAY)
556  return NULL;
557 
558  a = &v->v.v_arr;
559 
560  retc = alloc_tree_cell (0, NULL);
561  retc->type = CONST_INT;
562  retc->x.i_val = array_max_index (a);
563 
564  return retc;
565 }
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition: nasl_var.c:71
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
short type
Definition: nasl_tree.h:107
union st_a_nasl_var::@9 v
nasl_array v_arr
Definition: nasl_var.h:62
union TC::@7 x
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int array_max_index(nasl_array *a)
Definition: nasl_var.c:1457
Here is the call graph for this function:

◆ nasl_mktime()

tree_cell* nasl_mktime ( lex_ctxt lexic)

Definition at line 878 of file nasl_misc_funcs.c.

References alloc_typed_cell(), CONST_INT, get_int_local_var_by_name(), and nasl_perror().

879 {
880  struct tm tm;
881  tree_cell *retc;
882  time_t tictac;
883 
884  tm.tm_sec = get_int_local_var_by_name (lexic, "sec", 0); /* seconds */
885  tm.tm_min = get_int_local_var_by_name (lexic, "min", 0); /* minutes */
886  tm.tm_hour = get_int_local_var_by_name (lexic, "hour", 0); /* hours */
887  tm.tm_mday = get_int_local_var_by_name (lexic, "mday", 0); /* day of the month */
888  tm.tm_mon = get_int_local_var_by_name (lexic, "mon", 1); /* month */
889  tm.tm_mon -= 1;
890  tm.tm_year = get_int_local_var_by_name (lexic, "year", 0); /* year */
891  if (tm.tm_year >= 1900)
892  tm.tm_year -= 1900;
893  tm.tm_isdst = get_int_local_var_by_name (lexic, "isdst", -1); /* daylight saving time */
894  errno = 0;
895  tictac = mktime (&tm);
896  if (tictac == (time_t) (-1))
897  {
898  nasl_perror (lexic,
899  "mktime(sec=%02d min=%02d hour=%02d mday=%02d mon=%02d year=%04d isdst=%d): %s\n",
900  tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon + 1,
901  tm.tm_year + 1900, tm.tm_isdst,
902  errno ? strerror (errno) : "invalid value?");
903  return NULL;
904  }
905  retc = alloc_typed_cell (CONST_INT);
906  retc->x.i_val = tictac;
907  return retc;
908 }
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
Here is the call graph for this function:

◆ nasl_open_sock_kdc()

tree_cell* nasl_open_sock_kdc ( lex_ctxt lexic)

Definition at line 912 of file nasl_misc_funcs.c.

References alloc_typed_cell(), CONST_INT, TC::i_val, KB_TYPE_INT, KB_TYPE_STR, open_sock_opt_hn(), plug_get_key(), struct_lex_ctxt::script_infos, arglist::type, and TC::x.

913 {
914  tree_cell *retc;
915  int ret, type;
916  int timeout = 30, port = 88, tcp = 0;
917  char *hostname = NULL, *port_str, *tcp_str; /* Domain name for windows */
918  struct arglist *script_infos;
919 
920  script_infos = lexic->script_infos;
921 
922  hostname = plug_get_key (script_infos, "Secret/kdc_hostname", &type, 0);
923  if (!hostname || type != KB_TYPE_STR)
924  return NULL;
925 
926  port_str = plug_get_key (script_infos, "Secret/kdc_port", &type, 0);
927  port = GPOINTER_TO_SIZE (port_str);
928  g_free (port_str);
929  if (port <= 0 || type != KB_TYPE_INT)
930  return NULL;
931 
932 
933  tcp_str = plug_get_key (script_infos, "Secret/kdc_use_tcp", &type, 0);
934  tcp = GPOINTER_TO_SIZE (tcp_str);
935  g_free (tcp_str);
936  if (tcp < 0 || type != KB_TYPE_INT)
937  tcp = 0;
938 
939  if (tcp == 0)
940  ret = open_sock_opt_hn (hostname, port, SOCK_DGRAM, IPPROTO_UDP, timeout);
941  else
942  ret = open_sock_opt_hn (hostname, port, SOCK_STREAM, IPPROTO_TCP, timeout);
943  g_free (hostname);
944 
945  if (ret < 0)
946  return NULL;
947 
948  retc = alloc_typed_cell (CONST_INT);
949  retc->x.i_val = ret;
950  return retc;
951 }
Definition: kb.h:49
void * plug_get_key(struct arglist *args, char *name, int *type, int single)
Definition: plugutils.c:767
union TC::@7 x
int type
Definition: arglists.h:34
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: kb.h:48
Definition: nasl_tree.h:105
int open_sock_opt_hn(const char *hostname, unsigned int port, int type, int protocol, int timeout)
Definition: network.c:1888
long int i_val
Definition: nasl_tree.h:114
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
Here is the call graph for this function:

◆ nasl_rand()

tree_cell* nasl_rand ( lex_ctxt lexic)

Definition at line 56 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_INT, TC::i_val, TC::type, and TC::x.

57 {
58  tree_cell *retc;
59  retc = alloc_tree_cell (0, NULL);
60  retc->type = CONST_INT;
61  retc->x.i_val = lrand48 ();
62  return retc;
63 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_sleep()

tree_cell* nasl_sleep ( lex_ctxt lexic)

Definition at line 75 of file nasl_misc_funcs.c.

References FAKE_CELL, and get_int_var_by_num().

76 {
77  int slp = get_int_var_by_num (lexic, 0, 0);
78  sleep (slp);
79  return FAKE_CELL;
80 }
#define FAKE_CELL
Definition: nasl_tree.h:120
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
Here is the call graph for this function:

◆ nasl_sort_array()

tree_cell* nasl_sort_array ( lex_ctxt lexic)

Definition at line 770 of file nasl_misc_funcs.c.

771 {
772  tree_cell *retc = NULL;
773  nasl_array *a;
774 
775  if (mylexic != NULL)
776  {
777  nasl_perror (lexic, "sort: this function is not reentrant!\n");
778  return NULL;
779  }
780  mylexic = lexic;
781  retc = nasl_make_list (lexic);
782  if (retc != NULL)
783  {
784  a = retc->x.ref_val;
785  qsort (a->num_elt, a->max_idx, sizeof (a->num_elt[0]), var_cmp);
786  }
787  mylexic = NULL;
788  return retc;
789 }
tree_cell * nasl_make_list(lex_ctxt *lexic)
void * ref_val
Definition: nasl_tree.h:115
union TC::@7 x
Definition: nasl_tree.h:105
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94

◆ nasl_start_denial()

tree_cell* nasl_start_denial ( lex_ctxt lexic)

Definition at line 211 of file nasl_misc_funcs.c.

References arg_add_value(), arg_get_value(), ARG_INT, arg_set_value(), close_stream_connection(), deref_cell(), FAKE_CELL, TC::i_val, nasl_tcp_ping(), open_stream_connection(), OPENVAS_ENCAPS_IP, plug_get_host_open_port(), struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, and TC::x.

212 {
213  struct arglist *script_infos = lexic->script_infos;
214  int to = lexic->recv_timeout;
215  int port = plug_get_host_open_port (script_infos);
216  int soc;
217  int alive = 0;
218  tree_cell *p;
219 
220  if (port)
221  {
222  soc = open_stream_connection (script_infos, port, OPENVAS_ENCAPS_IP, to);
223  if (soc >= 0)
224  {
225  if (arg_get_value (script_infos, "denial_port") != 0)
226  arg_set_value (script_infos, "denial_port",
227  GSIZE_TO_POINTER (port));
228  else
229  arg_add_value (script_infos, "denial_port", ARG_INT,
230  GSIZE_TO_POINTER (port));
231 
233 
234  return FAKE_CELL;
235  }
236  }
237 
238  p = nasl_tcp_ping (lexic);
239  if (p != NULL)
240  alive = p->x.i_val;
241 
242  if (arg_get_value (script_infos, "tcp_ping_result") != 0)
243  arg_set_value (script_infos, "tcp_ping_result",
244  GSIZE_TO_POINTER (alive));
245  else
246  arg_add_value (script_infos, "tcp_ping_result", ARG_INT,
247  GSIZE_TO_POINTER (alive));
248 
249  deref_cell (p);
250 
251  return FAKE_CELL;
252 }
#define FAKE_CELL
Definition: nasl_tree.h:120
#define ARG_INT
Definition: arglists.h:40
int arg_set_value(struct arglist *arglst, const char *name, void *value)
Definition: arglists.c:225
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:202
int open_stream_connection(struct arglist *args, unsigned int port, int transport, int timeout)
Definition: network.c:1117
union TC::@7 x
void arg_add_value(struct arglist *arglst, const char *name, int type, void *value)
Definition: arglists.c:170
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
unsigned int plug_get_host_open_port(struct arglist *desc)
Definition: plugutils.c:917
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
tree_cell * nasl_tcp_ping(lex_ctxt *lexic)
int close_stream_connection(int fd)
Definition: network.c:1699
Here is the call graph for this function:

◆ nasl_telnet_init()

tree_cell* nasl_telnet_init ( lex_ctxt lexic)

Definition at line 137 of file nasl_misc_funcs.c.

References alloc_typed_cell(), code, CONST_DATA, get_int_var_by_num(), iac, nasl_perror(), option, read_stream_connection(), read_stream_connection_min(), TC::size, TC::str_val, write_stream_connection(), and TC::x.

138 {
139  int soc = get_int_var_by_num (lexic, 0, -1);
140  int opts; /* number of options recorded */
141  unsigned char buffer[1024];
142 #define iac buffer[0]
143 #define code buffer[1]
144 #define option buffer[2]
145  tree_cell *retc;
146  int n = 0, n2;
147  int lm = 0;
148 
149  if (soc <= 0)
150  {
151  nasl_perror (lexic, "Syntax error in the telnet_init() function\n");
152  nasl_perror (lexic,
153  "Correct syntax is : output = telnet_init(<socket>)\n");
154  return NULL;
155  }
156 
157  iac = 255;
158  opts = 0;
159  while (iac == 255)
160  {
161  n = read_stream_connection_min (soc, buffer, 3, 3);
162  if ((iac != 255) || (n <= 0) || (n != 3))
163  break;
164  if ((code == 251) || (code == 252))
165  code = 254; /* WILL , WONT -> DON'T */
166  else if ((code == 253) || (code == 254))
167  code = 252; /* DO,DONT -> WONT */
168  write_stream_connection (soc, buffer, 3);
169  if (lm == 0)
170  {
171  code = 253;
172  option = 0x22;
173  write_stream_connection (soc, buffer, 3);
174  lm++;
175  }
176  opts++;
177  if (opts > 100)
178  break;
179  }
180  if (n <= 0)
181  {
182  if (opts == 0)
183  return NULL;
184  else
185  n = 0;
186  }
187 
188  if (opts > 100) /* remote telnet server is crazy */
189  {
190  nasl_perror (lexic,
191  "More than 100 options received by telnet_init() function! exiting telnet_init.\n");
192  return NULL;
193  }
194 
195  n2 = read_stream_connection (soc, buffer + n, sizeof (buffer) - n);
196  if (n2 > 0)
197  n += n2;
198  retc = alloc_typed_cell (CONST_DATA);
199  retc->size = n;
200  retc->x.str_val = g_memdup (buffer, n + 1);
201 #undef iac
202 #undef data
203 #undef option
204 
205  return retc;
206 }
char * str_val
Definition: nasl_tree.h:113
#define option
union TC::@7 x
int read_stream_connection(int fd, void *buf0, int len)
Definition: network.c:1421
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
Definition: network.c:1360
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
int write_stream_connection(int fd, void *buf0, int n)
Definition: network.c:1571
#define iac
#define code
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_typeof()

tree_cell* nasl_typeof ( lex_ctxt lexic)

Definition at line 568 of file nasl_misc_funcs.c.

References alloc_tree_cell(), CONST_DATA, struct_lex_ctxt::ctx_vars, nasl_get_var_by_num(), TC::size, TC::str_val, TC::type, VAR2_ARRAY, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, st_a_nasl_var::var_type, and TC::x.

569 {
570  tree_cell *retc;
571  anon_nasl_var *u;
572  const char *s;
573 
574  retc = alloc_tree_cell (0, NULL);
575  retc->type = CONST_DATA;
576  u = nasl_get_var_by_num (lexic, &lexic->ctx_vars, 0, 0);
577 
578  if (u == NULL)
579  s = "null";
580  else
581  switch (u->var_type)
582  {
583  case VAR2_UNDEF:
584  s = "undef";
585  break;
586  case VAR2_INT:
587  s = "int";
588  break;
589  case VAR2_STRING:
590  s = "string";
591  break;
592  case VAR2_DATA:
593  s = "data";
594  break;
595  case VAR2_ARRAY:
596  s = "array";
597  break;
598  default:
599  s = "unknown";
600  break;
601  }
602  retc->size = strlen (s);
603  retc->x.str_val = g_strdup (s);
604  return retc;
605 }
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition: nasl_var.c:71
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_unixtime()

tree_cell* nasl_unixtime ( lex_ctxt lexic)

Definition at line 792 of file nasl_misc_funcs.c.

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

793 {
794  tree_cell *retc;
795 
796  retc = alloc_typed_cell (CONST_INT);
797  retc->x.i_val = time (NULL);
798  return retc;
799 }
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
Here is the call graph for this function:

◆ nasl_usleep()

tree_cell* nasl_usleep ( lex_ctxt lexic)

Definition at line 67 of file nasl_misc_funcs.c.

References FAKE_CELL, and get_int_var_by_num().

68 {
69  int slp = get_int_var_by_num (lexic, 0, 0);
70  usleep (slp);
71  return FAKE_CELL;
72 }
#define FAKE_CELL
Definition: nasl_tree.h:120
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
Here is the call graph for this function: