OpenVAS Scanner  22.7.9
nasl_misc_funcs.h File Reference
#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_misc_funcs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

Function Documentation

◆ nasl_dec2str()

tree_cell* nasl_dec2str ( lex_ctxt )

Definition at line 876 of file nasl_misc_funcs.c.

877 {
878  /*converts integer to 4 byte buffer */
879  (void) lexic;
880  int num = get_int_var_by_name (lexic, "num", -1);
881  if (num == -1)
882  {
883  nasl_perror (lexic, "Syntax : dec2str(num:<n>)\n");
884  return NULL;
885  }
886  char *ret = g_malloc0 (sizeof (num));
887  SIVAL (ret, 0, num);
888  tree_cell *retc;
889  retc = alloc_typed_cell (CONST_DATA);
890  retc->size = sizeof (num);
891  retc->x.str_val = ret;
892  return retc;
893 }

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

Here is the call graph for this function:

◆ nasl_defined_func()

tree_cell* nasl_defined_func ( lex_ctxt )

Definition at line 573 of file nasl_misc_funcs.c.

574 {
575  void *f;
576  char *s;
577  tree_cell *retc;
578 
579  s = get_str_var_by_num (lexic, 0);
580  if (s == NULL)
581  {
582  nasl_perror (lexic, "defined_func: missing parameter\n");
583  return NULL;
584  }
585 
586  f = get_func_ref_by_name (lexic, s);
587  retc = alloc_typed_cell (CONST_INT);
588  retc->x.i_val = (f != NULL);
589  return retc;
590 }

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

Here is the call graph for this function:

◆ nasl_do_exit()

tree_cell* nasl_do_exit ( lex_ctxt )

Definition at line 313 of file nasl_misc_funcs.c.

314 {
315  int retcode = get_int_var_by_num (lexic, 0, 0);
317  retc->x.i_val = retcode;
318 
319  if (retcode == NASL_EXIT_NOTVULN)
320  simple_register_host_detail (lexic, "EXIT_CODE", "EXIT_NOTVULN");
321 
322  // if (retcode == NASL_EXIT_DEPRECATED)
323  // This return code is reserved for future handling.
324 
325  while (lexic != NULL)
326  {
327  lexic->ret_val = retc;
328  ref_cell (retc);
329  lexic = lexic->up_ctxt;
330  }
331  return retc;
332 }

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), TC::i_val, NASL_EXIT_NOTVULN, ref_cell(), struct_lex_ctxt::ret_val, simple_register_host_detail(), struct_lex_ctxt::up_ctxt, and TC::x.

Here is the call graph for this function:

◆ nasl_dump_ctxt()

tree_cell* nasl_dump_ctxt ( lex_ctxt )

Definition at line 292 of file nasl_misc_funcs.c.

293 {
294  dump_ctxt (lexic->up_ctxt);
295  return FAKE_CELL;
296 }

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

Here is the call graph for this function:

◆ nasl_end_denial()

tree_cell* nasl_end_denial ( lex_ctxt )

Definition at line 231 of file nasl_misc_funcs.c.

232 {
233  int port = lexic->script_infos->denial_port;
234  int soc;
235  int to = lexic->recv_timeout;
236  struct script_infos *script_infos = lexic->script_infos;
237  kb_t kb = plug_get_kb (script_infos);
238  tree_cell *retc = NULL;
239  char *bogus_data;
240 
241  /*
242  * We must wait the time the DoS does its effect
243  */
244  sleep (10);
245 
246  if (!port)
247  {
248  int ping = script_infos->alive;
249 
250  if (ping)
251  return nasl_tcp_ping (lexic);
252  else
253  {
254  retc = alloc_typed_cell (CONST_INT);
255  retc->x.i_val = 1;
256  return retc;
257  }
258  }
259  else
260  {
261  retc = alloc_typed_cell (CONST_INT);
262 
264  if (soc > 0)
265  {
266  /* Send some data */
267  bogus_data = g_strdup_printf (
268  "Network Security Scan by %s in progress", vendor_version_get ());
269  if ((nsend (soc, bogus_data, strlen (bogus_data), 0)) >= 0)
270  {
271  g_free (bogus_data);
272  retc->x.i_val = 1;
274  return retc;
275  }
276  g_free (bogus_data);
277  }
278  }
279 
280  // Services seem to not respond.
281  // Last test with boreas
282  if (check_host_still_alive (kb, plug_current_vhost ()) == 1)
283  retc->x.i_val = 1;
284  else
285  retc->x.i_val = 0;
286  return retc;
287 }

References script_infos::alive, alloc_typed_cell(), check_host_still_alive(), close_stream_connection(), CONST_INT, script_infos::denial_port, TC::i_val, nasl_tcp_ping(), nsend(), open_stream_connection(), OPENVAS_ENCAPS_IP, plug_current_vhost(), plug_get_kb(), struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, vendor_version_get(), and TC::x.

Here is the call graph for this function:

◆ nasl_ftp_get_pasv_address()

tree_cell* nasl_ftp_get_pasv_address ( lex_ctxt )

Definition at line 103 of file nasl_misc_funcs.c.

104 {
105  int soc;
106  struct sockaddr_in addr;
107  tree_cell *retc;
108 
109  soc = get_int_var_by_name (lexic, "socket", 0);
110  if (soc <= 0)
111  return NULL;
112 
113  bzero (&addr, sizeof (addr));
114  ftp_get_pasv_address (soc, &addr);
115 
116  retc = alloc_typed_cell (CONST_INT);
117  retc->x.i_val = ntohs (addr.sin_port);
118  return retc;
119 }

References alloc_typed_cell(), CONST_INT, ftp_get_pasv_address(), and get_int_var_by_name().

Here is the call graph for this function:

◆ nasl_ftp_log_in()

tree_cell* nasl_ftp_log_in ( lex_ctxt )

Definition at line 75 of file nasl_misc_funcs.c.

76 {
77  char *u, *p;
78  int soc;
79  tree_cell *retc;
80  int res;
81 
82  soc = get_int_var_by_name (lexic, "socket", 0);
83  if (soc <= 0)
84  return NULL;
85 
86  u = get_str_var_by_name (lexic, "user");
87  if (u == NULL)
88  u = "";
89 
90  p = get_str_var_by_name (lexic, "pass");
91  if (p == NULL)
92  p = "";
93 
94  res = ftp_log_in (soc, u, p) == 0;
95 
96  retc = alloc_typed_cell (CONST_INT);
97  retc->x.i_val = res;
98 
99  return retc;
100 }

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

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 899 of file nasl_misc_funcs.c.

900 {
901  (void) lexic;
902  tree_cell *retc;
903  short w = 0x0001;
904  char *p = (char *) &w;
905  int val;
906 
907  val = (*p == 1);
908 
909  retc = alloc_typed_cell (CONST_INT);
910  retc->x.i_val = val;
911  return retc;
912 }

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

Here is the call graph for this function:

◆ nasl_gettimeofday()

tree_cell* nasl_gettimeofday ( lex_ctxt )

Definition at line 649 of file nasl_misc_funcs.c.

650 {
651  tree_cell *retc;
652  struct timeval t;
653  char str[64];
654 
655  if (gettimeofday (&t, NULL) < 0)
656  {
657  nasl_perror (lexic, "gettimeofday: %s\n", strerror (errno));
658  return NULL;
659  }
660  sprintf (str, "%u.%06u", (unsigned int) t.tv_sec, (unsigned int) t.tv_usec);
661  retc = alloc_typed_cell (CONST_DATA);
662  retc->size = strlen (str);
663  retc->x.str_val = g_malloc0 (retc->size);
664  strcpy (retc->x.str_val, str);
665  return retc;
666 }

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

Here is the call graph for this function:

◆ nasl_gunzip()

tree_cell* nasl_gunzip ( lex_ctxt )

Definition at line 816 of file nasl_misc_funcs.c.

817 {
818  tree_cell *retc;
819  void *data, *uncompressed;
820  unsigned long datalen, uncomplen;
821 
822  data = get_str_var_by_name (lexic, "data");
823  if (data == NULL)
824  return NULL;
825  datalen = get_var_size_by_name (lexic, "data");
826  if (datalen <= 0)
827  return NULL;
828 
829  uncompressed = gvm_uncompress (data, datalen, &uncomplen);
830  if (uncompressed == NULL)
831  return NULL;
832 
833  retc = alloc_typed_cell (CONST_DATA);
834  retc->size = uncomplen;
835  retc->x.str_val = uncompressed;
836 
837  return retc;
838 }

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_gzip()

tree_cell* nasl_gzip ( lex_ctxt )

Definition at line 841 of file nasl_misc_funcs.c.

842 {
843  tree_cell *retc;
844  void *data, *compressed, *headerformat;
845  unsigned long datalen, complen;
846 
847  data = get_str_var_by_name (lexic, "data");
848  if (data == NULL)
849  return NULL;
850  datalen = get_var_size_by_name (lexic, "data");
851  if (datalen <= 0)
852  return NULL;
853 
854  headerformat = get_str_var_by_name (lexic, "headformat");
855  if (!g_strcmp0 (headerformat, "gzip"))
856  {
857  compressed = gvm_compress_gzipheader (data, datalen, &complen);
858  if (compressed == NULL)
859  return NULL;
860  }
861  else
862  {
863  compressed = gvm_compress (data, datalen, &complen);
864  if (compressed == NULL)
865  return NULL;
866  }
867 
868  retc = alloc_typed_cell (CONST_DATA);
869  retc->size = complen;
870  retc->x.str_val = compressed;
871 
872  return retc;
873 }

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_isnull()

tree_cell* nasl_isnull ( lex_ctxt )

Definition at line 337 of file nasl_misc_funcs.c.

338 {
339  int t;
340  tree_cell *retc;
341 
342  t = get_var_type_by_num (lexic, 0);
343  retc = alloc_typed_cell (CONST_INT);
344  retc->x.i_val = (t == VAR2_UNDEF);
345  return retc;
346 }

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

Here is the call graph for this function:

◆ nasl_keys()

tree_cell* nasl_keys ( lex_ctxt )

Definition at line 466 of file nasl_misc_funcs.c.

467 {
468  tree_cell *retc = NULL;
469  anon_nasl_var *v, myvar;
470  named_nasl_var *vn;
471  nasl_array *a, *a2;
472  int i, j, vi;
473 
474  retc = alloc_typed_cell (DYN_ARRAY);
475  retc->x.ref_val = a2 = g_malloc0 (sizeof (nasl_array));
476 
477  bzero (&myvar, sizeof (myvar));
478 
479  for (i = vi = 0;
480  (v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi, 0)) != NULL; vi++)
481  {
482  if (v->var_type == VAR2_ARRAY)
483  {
484  a = &v->v.v_arr;
485  /* First the numerical index */
486  for (j = 0; j < a->max_idx; j++)
487  if (a->num_elt[j] != NULL && a->num_elt[j]->var_type != VAR2_UNDEF)
488  {
489  myvar.var_type = VAR2_INT;
490  myvar.v.v_int = j;
491  add_var_to_list (a2, i++, &myvar);
492  }
493  /* Then the string index */
494  if (a->hash_elt != NULL)
495  for (j = 0; j < VAR_NAME_HASH; j++)
496  for (vn = a->hash_elt[j]; vn != NULL; vn = vn->next_var)
497  if (vn->u.var_type != VAR2_UNDEF)
498  {
499  myvar.var_type = VAR2_STRING;
500  myvar.v.v_str.s_val = (unsigned char *) vn->var_name;
501  myvar.v.v_str.s_siz = strlen (vn->var_name);
502  add_var_to_list (a2, i++, &myvar);
503  }
504  }
505  else
506  nasl_perror (lexic, "nasl_keys: bad variable #%d skipped\n", vi);
507  }
508 
509  return retc;
510 }

References add_var_to_list(), alloc_typed_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, 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.

Here is the call graph for this function:

◆ nasl_localtime()

tree_cell* nasl_localtime ( lex_ctxt )

Definition at line 669 of file nasl_misc_funcs.c.

670 {
671  tree_cell *retc;
672  struct tm ptm;
673  time_t tictac;
674  int utc;
675  nasl_array *a;
676  anon_nasl_var v;
677  bool success;
678 
679  tictac = get_int_var_by_num (lexic, 0, 0);
680  if (tictac == 0)
681  tictac = time (NULL);
682  utc = get_int_var_by_name (lexic, "utc", 0);
683 
684  success = true;
685  if (utc)
686  {
687  if (gmtime_r (&tictac, &ptm) == NULL)
688  {
689  success = false;
690  }
691  }
692  else
693  {
694  if (localtime_r (&tictac, &ptm) == NULL)
695  {
696  success = false;
697  }
698  }
699 
700  if (!success)
701  {
702  nasl_perror (lexic, "localtime(%d,utc=%d): %s\n", tictac, utc,
703  strerror (errno));
704  return NULL;
705  }
706 
707  retc = alloc_typed_cell (DYN_ARRAY);
708  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
709  memset (&v, 0, sizeof (v));
710  v.var_type = VAR2_INT;
711 
712  v.v.v_int = ptm.tm_sec;
713  add_var_to_array (a, "sec", &v); /* seconds */
714  v.v.v_int = ptm.tm_min;
715  add_var_to_array (a, "min", &v); /* minutes */
716  v.v.v_int = ptm.tm_hour;
717  add_var_to_array (a, "hour", &v); /* hours */
718  v.v.v_int = ptm.tm_mday;
719  add_var_to_array (a, "mday", &v); /* day of the month */
720  v.v.v_int = ptm.tm_mon + 1;
721  add_var_to_array (a, "mon", &v); /* month */
722  v.v.v_int = ptm.tm_year + 1900;
723  add_var_to_array (a, "year", &v); /* year */
724  v.v.v_int = ptm.tm_wday;
725  add_var_to_array (a, "wday", &v); /* day of the week */
726  v.v.v_int = ptm.tm_yday + 1;
727  add_var_to_array (a, "yday", &v); /* day in the year */
728  v.v.v_int = ptm.tm_isdst;
729  add_var_to_array (a, "isdst", &v); /* daylight saving time */
730 
731  return retc;
732 }

References add_var_to_array(), alloc_typed_cell(), DYN_ARRAY, get_int_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.

Here is the call graph for this function:

◆ nasl_make_array()

tree_cell* nasl_make_array ( lex_ctxt )

Definition at line 418 of file nasl_misc_funcs.c.

419 {
420  tree_cell *retc = NULL;
421  int vi;
422  anon_nasl_var *v, *v2;
423  nasl_array *a;
424 
425  retc = alloc_typed_cell (DYN_ARRAY);
426  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
427 
428  vi = 0;
429  while ((v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi++, 0)) != NULL)
430  {
431  v2 = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi++, 0);
432  if (v2 == NULL)
433  {
434  nasl_perror (lexic, "make_array: odd number (%d) of argument?\n", vi);
435  break;
436  }
437 
438  switch (v2->var_type)
439  {
440  case VAR2_INT:
441  case VAR2_STRING:
442  case VAR2_DATA:
443  switch (v->var_type)
444  {
445  case VAR2_INT:
446  add_var_to_list (a, v->v.v_int, v2);
447  break;
448  case VAR2_STRING:
449  case VAR2_DATA:
450  add_var_to_array (a, (char *) var2str (v), v2);
451  break;
452  }
453  break;
454  case VAR2_UNDEF:
455  default:
456  nasl_perror (lexic, "make_array: bad value type %d for arg #%d\n",
457  v2->var_type, vi);
458  break;
459  }
460  }
461 
462  return retc;
463 }

References add_var_to_array(), add_var_to_list(), alloc_typed_cell(), struct_lex_ctxt::ctx_vars, DYN_ARRAY, nasl_get_var_by_num(), nasl_perror(), TC::ref_val, 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.

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 354 of file nasl_misc_funcs.c.

355 {
356  tree_cell *retc = NULL;
357  int i, j, vi;
358  anon_nasl_var *v;
359  named_nasl_var *vn;
360  nasl_array *a, *a2;
361 
362  retc = alloc_typed_cell (DYN_ARRAY);
363  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
364 
365  for (i = vi = 0;
366  (v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, vi, 0)) != NULL; vi++)
367  {
368  switch (v->var_type)
369  {
370  case VAR2_INT:
371  case VAR2_STRING:
372  case VAR2_DATA:
373  add_var_to_list (a, i++, v);
374  break;
375 
376  case VAR2_ARRAY:
377  a2 = &v->v.v_arr;
378 
379  for (j = 0; j < a2->max_idx; j++)
380  if (add_var_to_list (a, i, a2->num_elt[j]) >= 1)
381  i++;
382 
383  if (a2->hash_elt != NULL)
384  {
385  for (j = 0; j < VAR_NAME_HASH; j++)
386  for (vn = a2->hash_elt[j]; vn != NULL; vn = vn->next_var)
387  if (vn->u.var_type != VAR2_UNDEF)
388  if (add_var_to_list (a, i, &vn->u) >= 1)
389  i++;
390  }
391 
392  break;
393 
394  case VAR2_UNDEF:
395  nasl_perror (lexic,
396  "nasl_make_list: undefined variable #%d skipped\n", i);
397  continue;
398 
399  default:
400  nasl_perror (
401  lexic, "nasl_make_list: unhandled variable type 0x%x - skipped\n",
402  v->var_type);
403  continue;
404  }
405  }
406 
407  return retc;
408 }

References add_var_to_list(), alloc_typed_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_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.

Referenced by nasl_sort_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_max_index()

tree_cell* nasl_max_index ( lex_ctxt )

Definition at line 513 of file nasl_misc_funcs.c.

514 {
515  tree_cell *retc;
516  anon_nasl_var *v;
517  nasl_array *a;
518 
519  v = nasl_get_var_by_num (lexic, &lexic->ctx_vars, 0, 0);
520  if (v == NULL)
521  return NULL;
522  if (v->var_type != VAR2_ARRAY)
523  return NULL;
524 
525  a = &v->v.v_arr;
526 
527  retc = alloc_typed_cell (CONST_INT);
528  retc->x.i_val = array_max_index (a);
529 
530  return retc;
531 }

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

Here is the call graph for this function:

◆ nasl_mktime()

tree_cell* nasl_mktime ( lex_ctxt )

Definition at line 735 of file nasl_misc_funcs.c.

736 {
737  struct tm tm;
738  tree_cell *retc;
739  time_t tictac;
740 
741  tm.tm_sec = get_int_var_by_name (lexic, "sec", 0); /* seconds */
742  tm.tm_min = get_int_var_by_name (lexic, "min", 0); /* minutes */
743  tm.tm_hour = get_int_var_by_name (lexic, "hour", 0); /* hours */
744  tm.tm_mday = get_int_var_by_name (lexic, "mday", 0); /* day of the month */
745  tm.tm_mon = get_int_var_by_name (lexic, "mon", 1); /* month */
746  tm.tm_mon -= 1;
747  tm.tm_year = get_int_var_by_name (lexic, "year", 0); /* year */
748  if (tm.tm_year >= 1900)
749  tm.tm_year -= 1900;
750  tm.tm_isdst =
751  get_int_var_by_name (lexic, "isdst", -1); /* daylight saving time */
752  errno = 0;
753  tictac = mktime (&tm);
754  if (tictac == (time_t) (-1))
755  {
756  nasl_perror (lexic,
757  "mktime(sec=%02d min=%02d hour=%02d mday=%02d mon=%02d "
758  "year=%04d isdst=%d): %s\n",
759  tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon + 1,
760  tm.tm_year + 1900, tm.tm_isdst,
761  errno ? strerror (errno) : "invalid value?");
762  return NULL;
763  }
764  retc = alloc_typed_cell (CONST_INT);
765  retc->x.i_val = tictac;
766  return retc;
767 }

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

Here is the call graph for this function:

◆ nasl_open_sock_kdc()

tree_cell* nasl_open_sock_kdc ( lex_ctxt )

Definition at line 770 of file nasl_misc_funcs.c.

771 {
772  tree_cell *retc;
773  int ret, type, forced_type = KB_TYPE_INT;
774  int timeout = 30, tcp = 0;
775  unsigned short port = 88, *port_aux = NULL;
776  char *hostname = NULL, *tcp_str; /* Domain name for windows */
777  struct script_infos *script_infos;
778 
779  script_infos = lexic->script_infos;
780 
781  hostname = plug_get_key (script_infos, "Secret/kdc_hostname", &type, NULL, 0);
782  if (!hostname || type != KB_TYPE_STR)
783  return NULL;
784 
785  port_aux = (unsigned short *) plug_get_key (script_infos, "Secret/kdc_port",
786  &forced_type, NULL, 0);
787  if (port_aux)
788  {
789  port = *port_aux;
790  g_free (port_aux);
791  }
792  if (port <= 0 || forced_type != KB_TYPE_INT)
793  return NULL;
794 
795  tcp_str = plug_get_key (script_infos, "Secret/kdc_use_tcp", &type, NULL, 0);
796  tcp = GPOINTER_TO_SIZE (tcp_str);
797  g_free (tcp_str);
798  if (tcp < 0 || type != KB_TYPE_INT)
799  tcp = 0;
800 
801  if (tcp == 0)
802  ret = open_sock_opt_hn (hostname, port, SOCK_DGRAM, IPPROTO_UDP, timeout);
803  else
804  ret = open_sock_opt_hn (hostname, port, SOCK_STREAM, IPPROTO_TCP, timeout);
805  g_free (hostname);
806 
807  if (ret < 0)
808  return NULL;
809 
810  retc = alloc_typed_cell (CONST_INT);
811  retc->x.i_val = ret;
812  return retc;
813 }

References alloc_typed_cell(), CONST_INT, hostname, TC::i_val, open_sock_opt_hn(), plug_get_key(), struct_lex_ctxt::script_infos, and TC::x.

Here is the call graph for this function:

◆ nasl_rand()

tree_cell* nasl_rand ( lex_ctxt )

Definition at line 46 of file nasl_misc_funcs.c.

47 {
48  (void) lexic;
49  tree_cell *retc;
50  retc = alloc_typed_cell (CONST_INT);
51  retc->x.i_val = lrand48 ();
52  return retc;
53 }

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

Here is the call graph for this function:

◆ nasl_sleep()

tree_cell* nasl_sleep ( lex_ctxt )

Definition at line 65 of file nasl_misc_funcs.c.

66 {
67  int slp = get_int_var_by_num (lexic, 0, 0);
68  sleep (slp);
69  return FAKE_CELL;
70 }

References FAKE_CELL, and get_int_var_by_num().

Here is the call graph for this function:

◆ nasl_sort_array()

tree_cell* nasl_sort_array ( lex_ctxt )

Definition at line 613 of file nasl_misc_funcs.c.

614 {
615  tree_cell *retc = NULL;
616  nasl_array *a;
617 
618  if (mylexic != NULL)
619  {
620  nasl_perror (lexic, "sort: this function is not reentrant!\n");
621  return NULL;
622  }
623  mylexic = lexic;
624  retc = nasl_make_list (lexic);
625  if (retc != NULL)
626  {
627  a = retc->x.ref_val;
628  if (a->num_elt != NULL)
629  {
630  qsort (a->num_elt, a->max_idx, sizeof (a->num_elt[0]), var_cmp);
631  }
632  }
633  mylexic = NULL;
634  return retc;
635 }

References st_nasl_array::max_idx, mylexic, nasl_make_list(), nasl_perror(), st_nasl_array::num_elt, TC::ref_val, var_cmp(), and TC::x.

Here is the call graph for this function:

◆ nasl_start_denial()

tree_cell* nasl_start_denial ( lex_ctxt )

Definition at line 199 of file nasl_misc_funcs.c.

200 {
201  struct script_infos *script_infos = lexic->script_infos;
202  int to = lexic->recv_timeout;
204  int soc;
205  int alive = 0;
206  tree_cell *p;
207 
208  if (port)
209  {
211  if (soc >= 0)
212  {
213  script_infos->denial_port = port;
215 
216  return FAKE_CELL;
217  }
218  }
219 
220  p = nasl_tcp_ping (lexic);
221  if (p != NULL)
222  alive = p->x.i_val;
223 
225  deref_cell (p);
226 
227  return FAKE_CELL;
228 }

References script_infos::alive, close_stream_connection(), script_infos::denial_port, 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.

Here is the call graph for this function:

◆ nasl_telnet_init()

tree_cell* nasl_telnet_init ( lex_ctxt )

Definition at line 124 of file nasl_misc_funcs.c.

125 {
126  int soc = get_int_var_by_num (lexic, 0, -1);
127  int opts; /* number of options recorded */
128  unsigned char buffer[1024];
129 #define iac buffer[0]
130 #define code buffer[1]
131 #define option buffer[2]
132  tree_cell *retc;
133  int n = 0, n2;
134  int lm = 0;
135 
136  if (soc <= 0)
137  {
138  nasl_perror (lexic, "Syntax error in the telnet_init() function\n");
139  nasl_perror (lexic,
140  "Correct syntax is : output = telnet_init(<socket>)\n");
141  return NULL;
142  }
143 
144  iac = 255;
145  opts = 0;
146  while (iac == 255)
147  {
148  n = read_stream_connection_min (soc, buffer, 3, 3);
149  if ((iac != 255) || (n <= 0) || (n != 3))
150  break;
151  if ((code == 251) || (code == 252))
152  code = 254; /* WILL , WONT -> DON'T */
153  else if ((code == 253) || (code == 254))
154  code = 252; /* DO,DONT -> WONT */
155  write_stream_connection (soc, buffer, 3);
156  if (lm == 0)
157  {
158  code = 253;
159  option = 0x22;
160  write_stream_connection (soc, buffer, 3);
161  lm++;
162  }
163  opts++;
164  if (opts > 100)
165  break;
166  }
167  if (n <= 0)
168  {
169  if (opts == 0)
170  return NULL;
171  else
172  n = 0;
173  }
174 
175  if (opts > 100) /* remote telnet server is crazy */
176  {
177  nasl_perror (lexic, "More than 100 options received by telnet_init() "
178  "function! exiting telnet_init.\n");
179  return NULL;
180  }
181 
182  n2 = read_stream_connection (soc, buffer + n, sizeof (buffer) - n);
183  if (n2 > 0)
184  n += n2;
185  retc = alloc_typed_cell (CONST_DATA);
186  retc->size = n;
187  retc->x.str_val = g_malloc0 (n + 1);
188  memcpy (retc->x.str_val, buffer, n + 1);
189 #undef iac
190 #undef data
191 #undef option
192 
193  return retc;
194 }

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.

Here is the call graph for this function:

◆ nasl_typeof()

tree_cell* nasl_typeof ( lex_ctxt )

Definition at line 534 of file nasl_misc_funcs.c.

535 {
536  tree_cell *retc;
537  anon_nasl_var *u;
538  const char *s;
539 
540  retc = alloc_typed_cell (CONST_DATA);
541  u = nasl_get_var_by_num (lexic, &lexic->ctx_vars, 0, 0);
542 
543  if (u == NULL)
544  s = "null";
545  else
546  switch (u->var_type)
547  {
548  case VAR2_UNDEF:
549  s = "undef";
550  break;
551  case VAR2_INT:
552  s = "int";
553  break;
554  case VAR2_STRING:
555  s = "string";
556  break;
557  case VAR2_DATA:
558  s = "data";
559  break;
560  case VAR2_ARRAY:
561  s = "array";
562  break;
563  default:
564  s = "unknown";
565  break;
566  }
567  retc->size = strlen (s);
568  retc->x.str_val = g_strdup (s);
569  return retc;
570 }

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

Here is the call graph for this function:

◆ nasl_unixtime()

tree_cell* nasl_unixtime ( lex_ctxt )

Definition at line 638 of file nasl_misc_funcs.c.

639 {
640  tree_cell *retc;
641 
642  (void) lexic;
643  retc = alloc_typed_cell (CONST_INT);
644  retc->x.i_val = time (NULL);
645  return retc;
646 }

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

Here is the call graph for this function:

◆ nasl_usleep()

tree_cell* nasl_usleep ( lex_ctxt )

Definition at line 57 of file nasl_misc_funcs.c.

58 {
59  int slp = get_int_var_by_num (lexic, 0, 0);
60  usleep (slp);
61  return FAKE_CELL;
62 }

References FAKE_CELL, and get_int_var_by_num().

Here is the call graph for this function:
st_a_nasl_var
Definition: nasl_var.h:40
struct_lex_ctxt::ctx_vars
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:35
script_infos
Definition: scanneraux.h:29
simple_register_host_detail
static void simple_register_host_detail(lex_ctxt *lexic, char *name, char *value)
Definition: nasl_misc_funcs.c:299
get_func_ref_by_name
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:82
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:82
vendor_version_get
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:38
plug_get_key
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
get_var_size_by_name
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1138
nasl_tcp_ping
tree_cell * nasl_tcp_ping(lex_ctxt *lexic)
Launches a “TCP ping” against the target host.
Definition: nasl_packet_forgery.c:2048
OPENVAS_ENCAPS_IP
@ OPENVAS_ENCAPS_IP
Definition: network.h:31
plug_get_kb
kb_t plug_get_kb(struct script_infos *args)
Definition: plugutils.c:1055
VAR2_UNDEF
@ VAR2_UNDEF
Definition: nasl_var.h:15
TC::str_val
char * str_val
Definition: nasl_tree.h:103
NASL_EXIT_NOTVULN
#define NASL_EXIT_NOTVULN
Definition: nasl_misc_funcs.c:42
open_stream_connection
int open_stream_connection(struct script_infos *args, unsigned int port, int transport, int timeout)
Definition: network.c:1175
st_n_nasl_var
Definition: nasl_var.h:55
var2str
const char * var2str(anon_nasl_var *v)
Definition: nasl_var.c:1065
st_nasl_array::max_idx
int max_idx
Definition: nasl_var.h:34
script_infos::denial_port
int denial_port
Definition: scanneraux.h:40
check_host_still_alive
int check_host_still_alive(kb_t, const char *)
Check if the hosts is still alive and set it as dead if not.
Definition: heartbeat.c:33
st_a_nasl_var::v_arr
nasl_array v_arr
Definition: nasl_var.h:49
TC::x
union TC::@5 x
st_nasl_array::hash_elt
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:36
iac
#define iac
DYN_ARRAY
@ DYN_ARRAY
Definition: nasl_tree.h:90
FAKE_CELL
#define FAKE_CELL
Definition: nasl_tree.h:110
st_n_nasl_var::var_name
char * var_name
Definition: nasl_var.h:58
st_a_nasl_var::v
union st_a_nasl_var::@7 v
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1118
st_a_nasl_var::v_str
nasl_string_t v_str
Definition: nasl_var.h:47
SIVAL
#define SIVAL(buf, pos, val)
Definition: byteorder.h:117
VAR2_STRING
@ VAR2_STRING
Definition: nasl_var.h:17
ftp_get_pasv_address
int ftp_get_pasv_address(int soc, struct sockaddr_in *addr)
Definition: ftp_funcs.c:101
st_nasl_string::s_siz
int s_siz
Definition: nasl_var.h:27
VAR2_DATA
@ VAR2_DATA
Definition: nasl_var.h:18
st_nasl_array
Definition: nasl_var.h:33
script_infos::alive
int alive
Definition: scanneraux.h:41
plug_current_vhost
const char * plug_current_vhost(void)
Definition: plugutils.c:47
VAR2_INT
@ VAR2_INT
Definition: nasl_var.h:16
dump_ctxt
void dump_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:52
plug_get_host_open_port
unsigned int plug_get_host_open_port(struct script_infos *desc)
Definition: plugutils.c:1220
st_n_nasl_var::next_var
struct st_n_nasl_var * next_var
Definition: nasl_var.h:62
nasl_perror
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:111
add_var_to_array
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1277
TC::size
int size
Definition: nasl_tree.h:99
nsend
int nsend(int fd, void *data, int length, int i_opt)
Definition: network.c:1589
option
#define option
read_stream_connection
int read_stream_connection(int fd, void *buf0, int len)
Definition: network.c:1457
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1104
ftp_log_in
int ftp_log_in(int soc, char *username, char *passwd)
Definition: ftp_funcs.c:17
read_stream_connection_min
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
Definition: network.c:1397
VAR2_ARRAY
@ VAR2_ARRAY
Definition: nasl_var.h:19
TC::ref_val
void * ref_val
Definition: nasl_tree.h:105
get_int_var_by_num
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1097
get_str_var_by_num
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1111
st_a_nasl_var::var_type
int var_type
Definition: nasl_var.h:41
timeval
static struct timeval timeval(unsigned long val)
Definition: nasl_builtin_synscan.c:94
open_sock_opt_hn
int open_sock_opt_hn(const char *hostname, unsigned int port, int type, int protocol, int timeout)
Definition: network.c:1890
TC
Definition: nasl_tree.h:94
mylexic
static lex_ctxt * mylexic
Definition: nasl_misc_funcs.c:594
ref_cell
void ref_cell(tree_cell *c)
Definition: nasl_tree.c:167
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:79
hostname
const char * hostname
Definition: pluginlaunch.c:68
val
const char * val
Definition: nasl_init.c:412
get_var_type_by_num
int get_var_type_by_num(lex_ctxt *, int)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
Definition: nasl_var.c:1155
add_var_to_list
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1245
write_stream_connection
int write_stream_connection(int fd, void *buf0, int n)
Definition: network.c:1583
st_a_nasl_var::v_int
long int v_int
Definition: nasl_var.h:48
close_stream_connection
int close_stream_connection(int fd)
Definition: network.c:1705
deref_cell
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:181
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:28
var_cmp
static int var_cmp(const void *a, const void *b)
Definition: nasl_misc_funcs.c:597
nasl_make_list
tree_cell * nasl_make_list(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:354
st_n_nasl_var::u
struct st_a_nasl_var u
Definition: nasl_var.h:56
code
#define code
VAR_NAME_HASH
#define VAR_NAME_HASH
Definition: nasl_var.h:22
nasl_get_var_by_num
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition: nasl_var.c:46
st_nasl_string::s_val
unsigned char * s_val
Definition: nasl_var.h:26
TC::i_val
long int i_val
Definition: nasl_tree.h:104
array_max_index
int array_max_index(nasl_array *a)
Definition: nasl_var.c:1302
st_nasl_array::num_elt
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:35