OpenVAS Scanner  7.0.0~git
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 859 of file nasl_misc_funcs.c.

860 {
861  /*converts integer to 4 byte buffer */
862  (void) lexic;
863  int num = get_int_var_by_name (lexic, "num", -1);
864  if (num == -1)
865  {
866  nasl_perror (lexic, "Syntax : dec2str(num:<n>)\n");
867  return NULL;
868  }
869  char *ret = g_malloc0 (sizeof (num));
870  SIVAL (ret, 0, num);
871  tree_cell *retc;
872  retc = alloc_typed_cell (CONST_DATA);
873  retc->size = sizeof (num);
874  retc->x.str_val = ret;
875  return retc;
876 }

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

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

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

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

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

291 {
292  dump_ctxt (lexic->up_ctxt);
293  return FAKE_CELL;
294 }

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

240 {
241  int port = lexic->script_infos->denial_port;
242  int soc;
243  int to = lexic->recv_timeout;
244  struct script_infos *script_infos = lexic->script_infos;
245  tree_cell *retc = NULL;
246 
247  /*
248  * We must wait the time the DoS does its effect
249  */
250  sleep (10);
251 
252  if (!port)
253  {
254  int ping = script_infos->alive;
255 
256  if (ping)
257  return nasl_tcp_ping (lexic);
258  else
259  {
260  retc = alloc_typed_cell (CONST_INT);
261  retc->x.i_val = 1;
262  return retc;
263  }
264  }
265  else
266  {
267  retc = alloc_typed_cell (CONST_INT);
268 
270  if (soc > 0)
271  {
272  /* Send some data */
273 #define BOGUS "are you dead ?"
274  if ((nsend (soc, BOGUS, sizeof (BOGUS) - 1, 0)) >= 0)
275  {
276  retc->x.i_val = 1;
278  return retc;
279  }
280  }
281  }
282 
283  retc->x.i_val = 0;
284  return retc;
285 }

References script_infos::alive, alloc_typed_cell(), BOGUS, close_stream_connection(), CONST_INT, script_infos::denial_port, TC::i_val, nasl_tcp_ping(), nsend(), open_stream_connection(), OPENVAS_ENCAPS_IP, struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, 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 112 of file nasl_misc_funcs.c.

113 {
114  int soc;
115  struct sockaddr_in addr;
116  tree_cell *retc;
117 
118  soc = get_int_var_by_name (lexic, "socket", 0);
119  if (soc <= 0)
120  return NULL;
121 
122  bzero (&addr, sizeof (addr));
123  ftp_get_pasv_address (soc, &addr);
124 
125  retc = alloc_typed_cell (CONST_INT);
126  retc->x.i_val = ntohs (addr.sin_port);
127  return retc;
128 }

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

85 {
86  char *u, *p;
87  int soc;
88  tree_cell *retc;
89  int res;
90 
91  soc = get_int_var_by_name (lexic, "socket", 0);
92  if (soc <= 0)
93  return NULL;
94 
95  u = get_str_var_by_name (lexic, "user");
96  if (u == NULL)
97  u = "";
98 
99  p = get_str_var_by_name (lexic, "pass");
100  if (p == NULL)
101  p = "";
102 
103  res = ftp_log_in (soc, u, p) == 0;
104 
105  retc = alloc_typed_cell (CONST_INT);
106  retc->x.i_val = res;
107 
108  return retc;
109 }

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

883 {
884  (void) lexic;
885  tree_cell *retc;
886  short w = 0x0001;
887  char *p = (char *) &w;
888  int val;
889 
890  val = (*p == 1);
891 
892  retc = alloc_typed_cell (CONST_INT);
893  retc->x.i_val = val;
894  return retc;
895 }

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

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

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

800 {
801  tree_cell *retc;
802  void *data, *uncompressed;
803  unsigned long datalen, uncomplen;
804 
805  data = get_str_var_by_name (lexic, "data");
806  if (data == NULL)
807  return NULL;
808  datalen = get_var_size_by_name (lexic, "data");
809  if (datalen <= 0)
810  return NULL;
811 
812  uncompressed = gvm_uncompress (data, datalen, &uncomplen);
813  if (uncompressed == NULL)
814  return NULL;
815 
816  retc = alloc_typed_cell (CONST_DATA);
817  retc->size = uncomplen;
818  retc->x.str_val = uncompressed;
819 
820  return retc;
821 }

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

825 {
826  tree_cell *retc;
827  void *data, *compressed, *headerformat;
828  unsigned long datalen, complen;
829 
830  data = get_str_var_by_name (lexic, "data");
831  if (data == NULL)
832  return NULL;
833  datalen = get_var_size_by_name (lexic, "data");
834  if (datalen <= 0)
835  return NULL;
836 
837  headerformat = get_str_var_by_name (lexic, "headformat");
838  if (!g_strcmp0 (headerformat, "gzip"))
839  {
840  compressed = gvm_compress_gzipheader (data, datalen, &complen);
841  if (compressed == NULL)
842  return NULL;
843  }
844  else
845  {
846  compressed = gvm_compress (data, datalen, &complen);
847  if (compressed == NULL)
848  return NULL;
849  }
850 
851  retc = alloc_typed_cell (CONST_DATA);
852  retc->size = complen;
853  retc->x.str_val = compressed;
854 
855  return retc;
856 }

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

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

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

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

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

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

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

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

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

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

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

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

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

719 {
720  struct tm tm;
721  tree_cell *retc;
722  time_t tictac;
723 
724  tm.tm_sec = get_int_var_by_name (lexic, "sec", 0); /* seconds */
725  tm.tm_min = get_int_var_by_name (lexic, "min", 0); /* minutes */
726  tm.tm_hour = get_int_var_by_name (lexic, "hour", 0); /* hours */
727  tm.tm_mday = get_int_var_by_name (lexic, "mday", 0); /* day of the month */
728  tm.tm_mon = get_int_var_by_name (lexic, "mon", 1); /* month */
729  tm.tm_mon -= 1;
730  tm.tm_year = get_int_var_by_name (lexic, "year", 0); /* year */
731  if (tm.tm_year >= 1900)
732  tm.tm_year -= 1900;
733  tm.tm_isdst =
734  get_int_var_by_name (lexic, "isdst", -1); /* daylight saving time */
735  errno = 0;
736  tictac = mktime (&tm);
737  if (tictac == (time_t) (-1))
738  {
739  nasl_perror (lexic,
740  "mktime(sec=%02d min=%02d hour=%02d mday=%02d mon=%02d "
741  "year=%04d isdst=%d): %s\n",
742  tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon + 1,
743  tm.tm_year + 1900, tm.tm_isdst,
744  errno ? strerror (errno) : "invalid value?");
745  return NULL;
746  }
747  retc = alloc_typed_cell (CONST_INT);
748  retc->x.i_val = tictac;
749  return retc;
750 }

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

754 {
755  tree_cell *retc;
756  int ret, type, forced_type = KB_TYPE_INT;
757  int timeout = 30, tcp = 0;
758  unsigned short port = 88, *port_aux = NULL;
759  char *hostname = NULL, *tcp_str; /* Domain name for windows */
760  struct script_infos *script_infos;
761 
762  script_infos = lexic->script_infos;
763 
764  hostname = plug_get_key (script_infos, "Secret/kdc_hostname", &type, NULL, 0);
765  if (!hostname || type != KB_TYPE_STR)
766  return NULL;
767 
768  port_aux = (unsigned short *) plug_get_key (script_infos, "Secret/kdc_port",
769  &forced_type, NULL, 0);
770  if (port_aux)
771  {
772  port = *port_aux;
773  g_free (port_aux);
774  }
775  if (port <= 0 || forced_type != KB_TYPE_INT)
776  return NULL;
777 
778  tcp_str = plug_get_key (script_infos, "Secret/kdc_use_tcp", &type, NULL, 0);
779  tcp = GPOINTER_TO_SIZE (tcp_str);
780  g_free (tcp_str);
781  if (tcp < 0 || type != KB_TYPE_INT)
782  tcp = 0;
783 
784  if (tcp == 0)
785  ret = open_sock_opt_hn (hostname, port, SOCK_DGRAM, IPPROTO_UDP, timeout);
786  else
787  ret = open_sock_opt_hn (hostname, port, SOCK_STREAM, IPPROTO_TCP, timeout);
788  g_free (hostname);
789 
790  if (ret < 0)
791  return NULL;
792 
793  retc = alloc_typed_cell (CONST_INT);
794  retc->x.i_val = ret;
795  return retc;
796 }

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

56 {
57  (void) lexic;
58  tree_cell *retc;
59  retc = alloc_typed_cell (CONST_INT);
60  retc->x.i_val = lrand48 ();
61  return retc;
62 }

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

75 {
76  int slp = get_int_var_by_num (lexic, 0, 0);
77  sleep (slp);
78  return FAKE_CELL;
79 }

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

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

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

208 {
209  struct script_infos *script_infos = lexic->script_infos;
210  int to = lexic->recv_timeout;
212  int soc;
213  int alive = 0;
214  tree_cell *p;
215 
216  if (port)
217  {
219  if (soc >= 0)
220  {
221  script_infos->denial_port = port;
223 
224  return FAKE_CELL;
225  }
226  }
227 
228  p = nasl_tcp_ping (lexic);
229  if (p != NULL)
230  alive = p->x.i_val;
231 
233  deref_cell (p);
234 
235  return FAKE_CELL;
236 }

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

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

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

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

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

634 {
635  tree_cell *retc;
636 
637  (void) lexic;
638  retc = alloc_typed_cell (CONST_INT);
639  retc->x.i_val = time (NULL);
640  return retc;
641 }

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

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

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:50
VAR2_ARRAY
@ VAR2_ARRAY
Definition: nasl_var.h:30
struct_lex_ctxt::ctx_vars
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:46
script_infos
Definition: scanneraux.h:43
simple_register_host_detail
static void simple_register_host_detail(lex_ctxt *lexic, char *name, char *value)
Definition: nasl_misc_funcs.c:297
get_func_ref_by_name
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:94
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
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:699
get_var_size_by_name
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
nasl_tcp_ping
tree_cell * nasl_tcp_ping(lex_ctxt *lexic)
Definition: nasl_packet_forgery.c:1254
OPENVAS_ENCAPS_IP
@ OPENVAS_ENCAPS_IP
Definition: network.h:45
TC::str_val
char * str_val
Definition: nasl_tree.h:112
NASL_EXIT_NOTVULN
#define NASL_EXIT_NOTVULN
Definition: nasl_misc_funcs.c:51
open_stream_connection
int open_stream_connection(struct script_infos *args, unsigned int port, int transport, int timeout)
Definition: network.c:992
st_n_nasl_var
Definition: nasl_var.h:65
var2str
const char * var2str(anon_nasl_var *v)
Definition: nasl_var.c:1076
st_nasl_array::max_idx
int max_idx
Definition: nasl_var.h:45
script_infos::denial_port
int denial_port
Definition: scanneraux.h:54
st_a_nasl_var::v_arr
nasl_array v_arr
Definition: nasl_var.h:60
st_nasl_array::hash_elt
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:47
timeval
struct timeval timeval(unsigned long val)
Definition: nasl_builtin_synscan.c:105
iac
#define iac
DYN_ARRAY
@ DYN_ARRAY
Definition: nasl_tree.h:101
FAKE_CELL
#define FAKE_CELL
Definition: nasl_tree.h:119
TC::x
union TC::@2 x
st_n_nasl_var::var_name
char * var_name
Definition: nasl_var.h:69
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
st_a_nasl_var::v_str
nasl_string_t v_str
Definition: nasl_var.h:58
SIVAL
#define SIVAL(buf, pos, val)
Definition: byteorder.h:130
ftp_get_pasv_address
int ftp_get_pasv_address(int soc, struct sockaddr_in *addr)
Definition: ftp_funcs.c:113
st_nasl_string::s_siz
int s_siz
Definition: nasl_var.h:38
st_nasl_array
Definition: nasl_var.h:43
script_infos::alive
int alive
Definition: scanneraux.h:55
dump_ctxt
void dump_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:64
plug_get_host_open_port
unsigned int plug_get_host_open_port(struct script_infos *desc)
Definition: plugutils.c:786
st_n_nasl_var::next_var
struct st_n_nasl_var * next_var
Definition: nasl_var.h:73
nasl_perror
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
add_var_to_array
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1286
VAR2_UNDEF
@ VAR2_UNDEF
Definition: nasl_var.h:26
TC::size
int size
Definition: nasl_tree.h:109
nsend
int nsend(int fd, void *data, int length, int i_opt)
Definition: network.c:1402
option
#define option
read_stream_connection
int read_stream_connection(int fd, void *buf0, int len)
Definition: network.c:1272
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
ftp_log_in
int ftp_log_in(int soc, char *username, char *passwd)
Definition: ftp_funcs.c:29
VAR2_DATA
@ VAR2_DATA
Definition: nasl_var.h:29
read_stream_connection_min
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
Definition: network.c:1212
TC::ref_val
void * ref_val
Definition: nasl_tree.h:114
get_int_var_by_num
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1106
get_str_var_by_num
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1120
st_a_nasl_var::var_type
int var_type
Definition: nasl_var.h:52
open_sock_opt_hn
int open_sock_opt_hn(const char *hostname, unsigned int port, int type, int protocol, int timeout)
Definition: network.c:1700
TC
Definition: nasl_tree.h:104
mylexic
static lex_ctxt * mylexic
Definition: nasl_misc_funcs.c:592
ref_cell
void ref_cell(tree_cell *c)
Definition: nasl_tree.c:178
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
hostname
const char * hostname
Definition: pluginlaunch.c:76
BOGUS
#define BOGUS
val
const char * val
Definition: nasl_init.c:378
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:1164
add_var_to_list
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1254
st_a_nasl_var::v
union st_a_nasl_var::@4 v
write_stream_connection
int write_stream_connection(int fd, void *buf0, int n)
Definition: network.c:1396
VAR2_STRING
@ VAR2_STRING
Definition: nasl_var.h:28
st_a_nasl_var::v_int
long int v_int
Definition: nasl_var.h:59
close_stream_connection
int close_stream_connection(int fd)
Definition: network.c:1518
deref_cell
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:192
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
var_cmp
static int var_cmp(const void *a, const void *b)
Definition: nasl_misc_funcs.c:595
nasl_make_list
tree_cell * nasl_make_list(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:352
st_n_nasl_var::u
struct st_a_nasl_var u
Definition: nasl_var.h:67
VAR2_INT
@ VAR2_INT
Definition: nasl_var.h:27
code
#define code
VAR_NAME_HASH
#define VAR_NAME_HASH
Definition: nasl_var.h:33
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:58
st_nasl_string::s_val
unsigned char * s_val
Definition: nasl_var.h:37
TC::i_val
long int i_val
Definition: nasl_tree.h:113
array_max_index
int array_max_index(nasl_array *a)
Definition: nasl_var.c:1311
st_nasl_array::num_elt
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:46