OpenVAS Scanner  22.7.9
nasl_misc_funcs.c
Go to the documentation of this file.
1 /* SPDX-FileCopyrightText: 2023 Greenbone AG
2  * SPDX-FileCopyrightText: 2002-2004 Tenable Network Security
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
12 #include "nasl_misc_funcs.h"
13 
14 #include "../misc/ftp_funcs.h" /* for ftp_log_in */
15 #include "../misc/heartbeat.h" /* plug_get_host_open_port */
16 #include "../misc/network.h" /* read_stream_connection_min */
17 #include "../misc/plugutils.h" /* plug_get_host_open_port */
18 #include "../misc/vendorversion.h" /* for vendor_version_get */
19 #include "byteorder.h"
20 #include "exec.h"
21 #include "nasl_debug.h"
22 #include "nasl_func.h"
23 #include "nasl_global_ctxt.h"
24 #include "nasl_lex_ctxt.h"
25 #include "nasl_packet_forgery.h"
26 #include "nasl_tree.h"
27 #include "nasl_var.h"
28 
29 #include <errno.h> /* for errno */
30 #include <glib.h>
31 #include <gvm/util/compressutils.h> /* for gvm_uncompress */
32 #include <gvm/util/kb.h> /* for KB_TYPE_STR */
33 #include <stdbool.h> /* for boolean */
34 #include <stdlib.h> /* for lrand48 */
35 #include <string.h> /* for bzero */
36 #include <sys/time.h> /* for gettimeofday */
37 #include <unistd.h> /* for usleep */
38 
39 #define uint32 unsigned int
40 
41 #define NASL_EXIT_DEPRECATED 66
42 #define NASL_EXIT_NOTVULN 99
43 
44 /*---------------------------------------------------------------------*/
45 tree_cell *
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 }
54 
55 /*---------------------------------------------------------------------*/
56 tree_cell *
58 {
59  int slp = get_int_var_by_num (lexic, 0, 0);
60  usleep (slp);
61  return FAKE_CELL;
62 }
63 
64 tree_cell *
66 {
67  int slp = get_int_var_by_num (lexic, 0, 0);
68  sleep (slp);
69  return FAKE_CELL;
70 }
71 
72 /*---------------------------------------------------------------------*/
73 
74 tree_cell *
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 }
101 
102 tree_cell *
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 }
120 
121 /*---------------------------------------------------------------------*/
122 
123 tree_cell *
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 }
195 
196 /*---------------------------------------------------------------------*/
197 
198 tree_cell *
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 }
229 
230 tree_cell *
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 }
288 
289 /*---------------------------------------------------------------------*/
290 
291 tree_cell *
293 {
294  dump_ctxt (lexic->up_ctxt);
295  return FAKE_CELL;
296 }
297 
298 static void
299 simple_register_host_detail (lex_ctxt *lexic, char *name, char *value)
300 {
301  char detail[128];
302  const char *oid = lexic->oid;
303 
304  plug_set_key (lexic->script_infos, "HostDetails", ARG_STRING, name);
305  plug_set_key (lexic->script_infos, "HostDetails/NVT", ARG_STRING,
306  (void *) oid);
307 
308  g_snprintf (detail, sizeof (detail), "HostDetails/NVT/%s/%s", oid, name);
309  plug_set_key (lexic->script_infos, detail, ARG_STRING, value);
310 }
311 
312 tree_cell *
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 }
333 
334 /*---------------------------------------------------------------------*/
335 
336 tree_cell *
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 }
347 
353 tree_cell *
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 }
409 
410 /*
411  * This function takes any _even_ number of arguments and makes
412  * an array from them. In each pair, the 1st argument is the index, the
413  * 2nd the value.
414  * Illegal types are dropped with a warning
415  */
416 
417 tree_cell *
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 }
464 
465 tree_cell *
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 }
511 
512 tree_cell *
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 }
532 
533 tree_cell *
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 }
571 
572 tree_cell *
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 }
591 
592 /* Sorts an array */
593 
594 static lex_ctxt *mylexic = NULL;
595 
596 static int
597 var_cmp (const void *a, const void *b)
598 {
599  anon_nasl_var **pv1 = (anon_nasl_var **) a, **pv2 = (anon_nasl_var **) b;
600  tree_cell *t1, *t2;
601  int ret;
602 
603  t1 = var2cell ((anon_nasl_var *) *pv1);
604  t2 = var2cell ((anon_nasl_var *) *pv2);
605  ret = cell_cmp (mylexic, t1, t2);
606  deref_cell (t1);
607  deref_cell (t2);
608 
609  return ret;
610 }
611 
612 tree_cell *
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 }
636 
637 tree_cell *
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 }
647 
648 tree_cell *
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 }
667 
668 tree_cell *
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 }
733 
734 tree_cell *
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 }
768 
769 tree_cell *
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 }
814 
815 tree_cell *
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 }
839 
840 tree_cell *
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 }
874 
875 tree_cell *
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 }
894 
898 tree_cell *
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 }
nasl_sort_array
tree_cell * nasl_sort_array(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:613
st_a_nasl_var
Definition: nasl_var.h:40
nasl_dec2str
tree_cell * nasl_dec2str(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:876
nasl_misc_funcs.h
nasl_get_byte_order
tree_cell * nasl_get_byte_order(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:899
struct_lex_ctxt::ctx_vars
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:35
nasl_do_exit
tree_cell * nasl_do_exit(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:313
nasl_defined_func
tree_cell * nasl_defined_func(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:573
script_infos
Definition: scanneraux.h:29
nasl_localtime
tree_cell * nasl_localtime(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:669
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
nasl_end_denial
tree_cell * nasl_end_denial(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:231
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
byteorder.h
Unix SMB/CIFS implementation. SMB Byte handling.
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
nasl_start_denial
tree_cell * nasl_start_denial(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:199
iac
#define iac
DYN_ARRAY
@ DYN_ARRAY
Definition: nasl_tree.h:90
nasl_unixtime
tree_cell * nasl_unixtime(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:638
FAKE_CELL
#define FAKE_CELL
Definition: nasl_tree.h:110
nasl_ftp_get_pasv_address
tree_cell * nasl_ftp_get_pasv_address(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:103
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
exec.h
ftp_get_pasv_address
int ftp_get_pasv_address(int soc, struct sockaddr_in *addr)
Definition: ftp_funcs.c:101
nasl_make_array
tree_cell * nasl_make_array(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:418
st_nasl_string::s_siz
int s_siz
Definition: nasl_var.h:27
name
const char * name
Definition: nasl_init.c:411
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
struct_lex_ctxt::up_ctxt
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:24
VAR2_INT
@ VAR2_INT
Definition: nasl_var.h:16
oid
const char * oid
Definition: nasl_builtin_find_service.c:51
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
nasl_debug.h
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
nasl_telnet_init
tree_cell * nasl_telnet_init(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:124
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
nasl_rand
tree_cell * nasl_rand(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:46
read_stream_connection
int read_stream_connection(int fd, void *buf0, int len)
Definition: network.c:1457
nasl_gettimeofday
tree_cell * nasl_gettimeofday(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:649
nasl_typeof
tree_cell * nasl_typeof(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:534
nasl_lex_ctxt.h
var2cell
tree_cell * var2cell(anon_nasl_var *v)
Definition: nasl_var.c:171
nasl_gzip
tree_cell * nasl_gzip(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:841
struct_lex_ctxt::oid
const char * oid
Definition: nasl_lex_ctxt.h:31
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
nasl_dump_ctxt
tree_cell * nasl_dump_ctxt(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:292
VAR2_ARRAY
@ VAR2_ARRAY
Definition: nasl_var.h:19
nasl_func.h
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
nasl_mktime
tree_cell * nasl_mktime(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:735
timeval
static struct timeval timeval(unsigned long val)
Definition: nasl_builtin_synscan.c:94
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:30
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
struct_lex_ctxt
Definition: nasl_lex_ctxt.h:23
nasl_ftp_log_in
tree_cell * nasl_ftp_log_in(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:75
nasl_var.h
nasl_packet_forgery.h
cell_cmp
long int cell_cmp(lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
Definition: exec.c:218
nasl_open_sock_kdc
tree_cell * nasl_open_sock_kdc(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:770
ref_cell
void ref_cell(tree_cell *c)
Definition: nasl_tree.c:167
nasl_sleep
tree_cell * nasl_sleep(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:65
nasl_global_ctxt.h
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
struct_lex_ctxt::recv_timeout
int recv_timeout
Definition: nasl_lex_ctxt.h:32
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
nasl_gunzip
tree_cell * nasl_gunzip(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:816
add_var_to_list
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1245
plug_set_key
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
Definition: plugutils.c:962
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
nasl_isnull
tree_cell * nasl_isnull(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:337
nasl_max_index
tree_cell * nasl_max_index(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:513
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
nasl_keys
tree_cell * nasl_keys(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:466
st_n_nasl_var::u
struct st_a_nasl_var u
Definition: nasl_var.h:56
code
#define code
nasl_tree.h
ARG_STRING
#define ARG_STRING
Definition: plugutils.h:19
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
struct_lex_ctxt::ret_val
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:25
nasl_usleep
tree_cell * nasl_usleep(lex_ctxt *lexic)
Definition: nasl_misc_funcs.c:57
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