OpenVAS Scanner  7.0.0~git
nasl_socket.c
Go to the documentation of this file.
1 /* Portions Copyright (C) 2012-2019 Greenbone Networks GmbH
2  * Based on work Copyright (C) 2002 - 2004 Tenable Network Security
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
30 /*--------------------------------------------------------------------------*/
31 #include "../misc/network.h"
32 #include "../misc/plugutils.h" /* for plug_get_host_ip */
33 #include "exec.h"
34 #include "nasl.h"
35 #include "nasl_debug.h"
36 #include "nasl_func.h"
37 #include "nasl_global_ctxt.h"
38 #include "nasl_lex_ctxt.h"
39 #include "nasl_packet_forgery.h"
40 #include "nasl_tree.h"
41 #include "nasl_var.h"
42 
43 #include <arpa/inet.h> /* for inet_aton */
44 #include <errno.h> /* for errno */
45 #include <fcntl.h> /* for fnctl */
46 #include <gnutls/gnutls.h>
47 #include <gvm/base/logging.h>
48 #include <gvm/base/networking.h> /* for gvm_source_set_socket */
49 #include <gvm/base/prefs.h> /* for prefs_get */
50 #include <netinet/in.h> /* for sockaddr_in */
51 #include <stdlib.h> /* for atoi() */
52 #include <string.h> /* for bzero */
53 #include <sys/time.h>
54 #include <unistd.h> /* for close */
55 
56 #ifndef EADDRNOTAVAIL
57 #define EADDRNOTAVAIL EADDRINUSE
58 #endif
59 
60 #undef G_LOG_DOMAIN
61 
64 #define G_LOG_DOMAIN "lib nasl"
65 
66 /*----------------------- Private functions ---------------------------*/
67 
68 static int
69 unblock_socket (int soc)
70 {
71  int flags = fcntl (soc, F_GETFL, 0);
72  if (flags < 0)
73  {
74  perror ("fcntl(F_GETFL)");
75  return -1;
76  }
77  if (fcntl (soc, F_SETFL, O_NONBLOCK | flags) < 0)
78  {
79  perror ("fcntl(F_SETFL,O_NONBLOCK)");
80  return -1;
81  }
82  return 0;
83 }
84 
85 static int
86 block_socket (int soc)
87 {
88  int flags = fcntl (soc, F_GETFL, 0);
89  if (flags < 0)
90  {
91  perror ("fcntl(F_GETFL)");
92  return -1;
93  }
94  if (fcntl (soc, F_SETFL, (~O_NONBLOCK) & flags) < 0)
95  {
96  perror ("fcntl(F_SETFL,~O_NONBLOCK)");
97  return -1;
98  }
99  return 0;
100 }
101 
102 static void
104 {
105  const char *time_between_request;
106  int minwaittime = 0;
107 
108  time_between_request = prefs_get ("time_between_request");
109  if (time_between_request)
110  minwaittime = atoi (time_between_request);
111 
112  if (minwaittime > 0)
113  {
114  static double lastprobesec = 0;
115  static double lastprobeusec = 0;
116  struct timeval tvnow, tvdiff;
117  double diff_msec;
118  int time2wait = 0;
119 
120  gettimeofday (&tvnow, NULL);
121  if (lastprobesec <= 0)
122  {
123  lastprobesec = tvnow.tv_sec - 10;
124  lastprobeusec = tvnow.tv_usec;
125  }
126 
127  tvdiff.tv_sec = tvnow.tv_sec - lastprobesec;
128  tvdiff.tv_usec = tvnow.tv_usec - lastprobeusec;
129  if (tvdiff.tv_usec <= 0)
130  {
131  tvdiff.tv_sec += 1;
132  tvdiff.tv_usec *= -1;
133  }
134 
135  diff_msec = tvdiff.tv_sec * 1000 + tvdiff.tv_usec / 1000;
136  time2wait = (minwaittime - diff_msec) * 1000;
137  if (time2wait > 0)
138  usleep (time2wait);
139 
140  gettimeofday (&tvnow, NULL);
141  lastprobesec = tvnow.tv_sec;
142  lastprobeusec = tvnow.tv_usec;
143  }
144 }
145 
146 /*
147  * NASL automatically re-send data when a recv() on a UDP packet
148  * fails. The point is to take care of packets lost en route.
149  *
150  * To do this, we store a copy of the data sent by a given socket
151  * each time send() is called, and we re-send() it each time
152  * recv() is called and fails
153  *
154  */
155 
157 {
158  int len;
159  char *data;
160 };
161 
162 /* add udp data in our cache */
163 static int
164 add_udp_data (struct script_infos *script_infos, int soc, char *data, int len)
165 {
166  GHashTable *udp_data = script_infos->udp_data;
167  struct udp_record *data_record = g_malloc0 (sizeof (struct udp_record));
168  int *key = g_memdup (&soc, sizeof (int));
169 
170  data_record->len = len;
171  data_record->data = g_memdup ((gconstpointer) data, (guint) len);
172 
173  if (udp_data == NULL)
174  {
175  udp_data =
176  g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free);
177  script_infos->udp_data = udp_data;
178  }
179 
180  g_hash_table_replace (udp_data, (gpointer) key, (gpointer) data_record);
181 
182  return 0;
183 }
184 
185 /* get the udp data for socket <soc> */
186 static char *
187 get_udp_data (struct script_infos *script_infos, int soc, int *len)
188 {
189  GHashTable *udp_data;
190  struct udp_record *data_record;
191 
192  if ((udp_data = script_infos->udp_data) == NULL)
193  {
194  udp_data =
195  g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free);
196  script_infos->udp_data = udp_data;
197  return NULL;
198  }
199  data_record = g_hash_table_lookup (udp_data, (gconstpointer) &soc);
200 
201  if (!data_record)
202  return NULL;
203 
204  *len = data_record->len;
205  return data_record->data;
206 }
207 
208 /* remove the udp data for socket <soc> */
209 static void
211 {
212  GHashTable *udp_data = script_infos->udp_data;
213 
214  if (udp_data)
215  g_hash_table_remove (udp_data, (gconstpointer) &soc);
216 }
217 
218 /*-------------------------------------------------------------------*/
219 
221 
222 static tree_cell *
224 {
225  struct script_infos *script_infos = lexic->script_infos;
226  int sport, current_sport = -1;
227  int dport;
228  int sock;
229  int e;
230  struct sockaddr_in addr, daddr;
231  struct sockaddr_in6 addr6, daddr6;
232  struct in6_addr *p;
233  int to = get_int_var_by_name (lexic, "timeout", lexic->recv_timeout);
234  tree_cell *retc;
235  struct timeval tv;
236  fd_set rd;
237  int opt;
238  unsigned int opt_sz;
239  int family;
240 
241  sport = get_int_var_by_name (lexic, "sport", -1);
242  dport = get_int_var_by_name (lexic, "dport", -1);
243  if (dport <= 0)
244  {
245  nasl_perror (
246  lexic, "open_private_socket: missing or undefined parameter dport!\n");
247  return NULL;
248  }
249 
250  if (sport < 0)
251  current_sport = 1023;
252 
253 restart:
254  if (proto == IPPROTO_TCP)
257  if (IN6_IS_ADDR_V4MAPPED (p))
258  {
259  family = AF_INET;
260  bzero (&addr, sizeof (addr));
261  if (proto == IPPROTO_TCP)
262  sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
263  else
264  sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
265  }
266  else
267  {
268  family = AF_INET6;
269  bzero (&addr6, sizeof (addr6));
270  if (proto == IPPROTO_TCP)
271  sock = socket (AF_INET6, SOCK_STREAM, IPPROTO_TCP);
272  else
273  sock = socket (AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
274  }
275 
276  /*
277  * We will bind to a privileged port. Let's declare
278  * our socket ready for reuse
279  */
280 
281  if (sock < 0)
282  return NULL;
283 
284 tryagain:
285  if (current_sport < 128 && sport < 0)
286  {
287  close (sock);
288  return NULL;
289  }
290  e = gvm_source_set_socket (sock, sport > 0 ? sport : current_sport--, family);
291 
292  /*
293  * bind() failed - try again on a lower port
294  */
295  if (e < 0)
296  {
297  if (sport > 0)
298  {
299  close (sock);
300  return NULL;
301  }
302  else
303  goto tryagain;
304  }
305 
306  /*
307  * Connect to the other end
308  */
310 
311  if (IN6_IS_ADDR_V4MAPPED (p))
312  {
313  bzero (&daddr, sizeof (daddr));
314  daddr.sin_addr.s_addr = p->s6_addr32[3];
315  daddr.sin_family = AF_INET;
316  daddr.sin_port = htons (dport);
317  unblock_socket (sock);
318  e = connect (sock, (struct sockaddr *) &daddr, sizeof (daddr));
319  }
320  else
321  {
322  bzero (&daddr6, sizeof (daddr6));
323  memcpy (&daddr6.sin6_addr, p, sizeof (struct in6_addr));
324  daddr6.sin6_family = AF_INET6;
325  daddr6.sin6_port = htons (dport);
326  unblock_socket (sock);
327  e = connect (sock, (struct sockaddr *) &daddr6, sizeof (daddr6));
328  }
329 
330  if (e < 0)
331  {
332  if (errno == EADDRINUSE || errno == EADDRNOTAVAIL)
333  {
334  close (sock);
335  if (sport < 0)
336  goto restart;
337  else
338  return NULL;
339  }
340  else if (errno != EINPROGRESS)
341  {
342  close (sock);
343  return NULL;
344  }
345  }
346 
347  do
348  {
349  tv.tv_sec = to;
350  tv.tv_usec = 0;
351  FD_ZERO (&rd);
352  FD_SET (sock, &rd);
353  e = select (sock + 1, NULL, &rd, NULL, to > 0 ? &tv : NULL);
354  }
355  while (e < 0 && errno == EINTR);
356 
357  if (e <= 0)
358  {
359  close (sock);
360  return FAKE_CELL;
361  }
362 
363  block_socket (sock);
364  opt_sz = sizeof (opt);
365 
366  if (getsockopt (sock, SOL_SOCKET, SO_ERROR, &opt, &opt_sz) < 0)
367  {
368  g_message ("[%d] open_priv_sock()->getsockopt() failed : %s", getpid (),
369  strerror (errno));
370  close (sock);
371  return NULL;
372  }
373 
374  switch (opt)
375  {
376  case EADDRINUSE:
377  case EADDRNOTAVAIL:
378  close (sock);
379  if (sport < 0)
380  goto restart;
381  else
382  return FAKE_CELL;
383 
384  case 0:
385  break;
386  default:
387  close (sock);
388  return FAKE_CELL;
389  break;
390  }
391 
392  if (lowest_socket == 0)
393  lowest_socket = sock;
394  if (proto == IPPROTO_TCP)
395  sock = openvas_register_connection (sock, NULL, NULL, OPENVAS_ENCAPS_IP);
396 
397  retc = alloc_typed_cell (CONST_INT);
398  retc->x.i_val = sock < 0 ? 0 : sock;
399  return retc;
400 }
401 
402 tree_cell *
404 {
405  return nasl_open_privileged_socket (lexic, IPPROTO_TCP);
406 }
407 
408 tree_cell *
410 {
411  return nasl_open_privileged_socket (lexic, IPPROTO_UDP);
412 }
413 
414 /*--------------------------------------------------------------------------*/
415 
416 tree_cell *
418 {
419  int soc = -1;
420  struct script_infos *script_infos = lexic->script_infos;
421  int to, port;
422  int transport = -1;
423  const char *priority;
424  tree_cell *retc;
425 
426  to = get_int_var_by_name (lexic, "timeout", lexic->recv_timeout * 2);
427  if (to < 0)
428  to = 10;
429 
430  transport = get_int_var_by_name (lexic, "transport", -1);
431 
432  if (transport == OPENVAS_ENCAPS_TLScustom)
433  {
434  int type;
435  priority = get_str_var_by_name (lexic, "priority");
436  if (!priority)
437  priority = NULL;
438  type = get_var_type_by_name (lexic, "priority");
439  if (type != VAR2_STRING && type != VAR2_DATA)
440  priority = NULL;
441  }
442  else
443  priority = NULL;
444 
445  if (bufsz < 0)
446  bufsz = get_int_var_by_name (lexic, "bufsz", 0);
447 
448  port = get_int_var_by_num (lexic, 0, -1);
449  if (port < 0)
450  return NULL;
451 
453 
454  /* If "transport" has not been given, use auto detection if enabled
455  in the KB. if "transport" has been given with a value of 0 force
456  autodetection reagardless of what the KB tells. */
457  if (transport < 0)
458  soc = open_stream_auto_encaps_ext (script_infos, port, to, 0);
459  else if (transport == 0)
460  soc = open_stream_auto_encaps_ext (script_infos, port, to, 1);
461  else
462  soc =
463  open_stream_connection_ext (script_infos, port, transport, to, priority);
464  if (bufsz > 0 && soc >= 0)
465  {
466  if (stream_set_buffer (soc, bufsz) < 0)
467  nasl_perror (lexic, "stream_set_buffer: soc=%d,bufsz=%d\n", soc, bufsz);
468  }
469 
470  retc = alloc_typed_cell (CONST_INT);
471  retc->x.i_val = soc < 0 ? 0 : soc;
472 
473  return retc;
474 }
475 
516 tree_cell *
518 {
519  return nasl_open_sock_tcp_bufsz (lexic, -1);
520 }
521 
522 /*
523  * Opening a UDP socket is a little more tricky, since
524  * UDP works in a way which is different from TCP...
525  *
526  * Our goal is to hide this difference for the end-user
527  */
528 tree_cell *
530 {
531  int soc;
532  tree_cell *retc;
533  int port;
534  struct sockaddr_in soca;
535  struct sockaddr_in6 soca6;
536  struct script_infos *script_infos = lexic->script_infos;
537  struct in6_addr *ia;
538 
539  port = get_int_var_by_num (lexic, 0, -1);
540  if (port < 0)
541  return NULL;
542 
544  if (ia == NULL)
545  return NULL;
546  if (IN6_IS_ADDR_V4MAPPED (ia))
547  {
548  bzero (&soca, sizeof (soca));
549  soca.sin_addr.s_addr = ia->s6_addr32[3];
550  soca.sin_port = htons (port);
551  soca.sin_family = AF_INET;
552 
553  soc = socket (AF_INET, SOCK_DGRAM, 0);
554  if (soc < 0)
555  return NULL;
556  gvm_source_set_socket (soc, 0, AF_INET);
557  if (connect (soc, (struct sockaddr *) &soca, sizeof (soca)) < 0)
558  {
559  close (soc);
560  return NULL;
561  }
562  }
563  else
564  {
565  bzero (&soca6, sizeof (soca6));
566  memcpy (&soca6.sin6_addr, ia, sizeof (struct in6_addr));
567  soca6.sin6_port = htons (port);
568  soca6.sin6_family = AF_INET6;
569 
570  soc = socket (AF_INET6, SOCK_DGRAM, 0);
571  if (soc < 0)
572  return NULL;
573  gvm_source_set_socket (soc, 0, AF_INET6);
574  if (connect (soc, (struct sockaddr *) &soca6, sizeof (soca6)) < 0)
575  {
576  close (soc);
577  return NULL;
578  }
579  }
580 
581  if (soc > 0 && lowest_socket == 0)
582  lowest_socket = soc;
583 
584  retc = alloc_typed_cell (CONST_INT);
585  retc->x.i_val = soc;
586  return retc;
587 }
588 
589 tree_cell *
591 {
592  int soc, transport, ret;
593  tree_cell *retc;
594 
595  soc = get_int_var_by_name (lexic, "socket", -1);
596  transport =
597  get_int_var_by_name (lexic, "transport", OPENVAS_ENCAPS_TLScustom);
598  if (soc < 0)
599  {
600  nasl_perror (lexic, "socket_ssl_negotiate: Erroneous socket value %d\n",
601  soc);
602  return NULL;
603  }
604  if (transport == -1)
605  transport = OPENVAS_ENCAPS_TLScustom;
606  else if (!IS_ENCAPS_SSL (transport))
607  {
608  nasl_perror (lexic,
609  "socket_ssl_negotiate: Erroneous transport value %d\n",
610  transport);
611  return NULL;
612  }
613  ret = socket_negotiate_ssl (soc, transport, lexic->script_infos);
614  if (ret < 0)
615  return NULL;
616 
617  retc = alloc_typed_cell (CONST_INT);
618  retc->x.i_val = ret;
619  return retc;
620 }
621 
622 tree_cell *
624 {
625  int soc, cert_len = 0;
626  tree_cell *retc;
627  void *cert;
628 
629  soc = get_int_var_by_name (lexic, "socket", -1);
630  if (soc < 0)
631  {
632  nasl_perror (lexic, "socket_get_cert: Erroneous socket value %d\n", soc);
633  return NULL;
634  }
635  socket_get_cert (soc, &cert, &cert_len);
636  if (cert_len <= 0)
637  return NULL;
638  retc = alloc_typed_cell (CONST_DATA);
639  retc->x.str_val = cert;
640  retc->size = cert_len;
641  return retc;
642 }
643 
644 tree_cell *
646 {
647  int soc;
648  size_t sid_len = 0;
649  tree_cell *retc;
650  void *sid;
651 
652  soc = get_int_var_by_name (lexic, "socket", -1);
653  if (soc < 0)
654  {
655  nasl_perror (lexic, "socket_get_cert: Erroneous socket value %d\n", soc);
656  return NULL;
657  }
658  socket_get_ssl_session_id (soc, &sid, &sid_len);
659  if (sid == NULL || sid_len == 0)
660  return NULL;
661  retc = alloc_typed_cell (CONST_DATA);
662  retc->x.str_val = sid;
663  retc->size = sid_len;
664  return retc;
665 }
666 
667 tree_cell *
669 {
670  int soc;
671  int version;
672  tree_cell *retc;
673 
674  soc = get_int_var_by_name (lexic, "socket", -1);
675  version = socket_get_ssl_version (soc);
676  if (version < 0)
677  return NULL;
678  retc = alloc_typed_cell (CONST_INT);
679  retc->x.i_val = version;
680  return retc;
681 }
682 
683 tree_cell *
685 {
686  int soc, result;
687  tree_cell *retc;
688 
689  soc = get_int_var_by_name (lexic, "socket", -1);
690  result = socket_get_ssl_ciphersuite (soc);
691  if (result < 0)
692  return NULL;
693  retc = alloc_typed_cell (CONST_INT);
694  retc->x.i_val = result;
695  return retc;
696 }
697 
698 /*---------------------------------------------------------------------*/
699 
700 tree_cell *
702 {
703  char *data;
704  int len = get_int_var_by_name (lexic, "length", -1);
705  int min_len = get_int_var_by_name (lexic, "min", -1);
706  int soc = get_int_var_by_name (lexic, "socket", 0);
707  int to = get_int_var_by_name (lexic, "timeout", lexic->recv_timeout);
708  fd_set rd;
709  struct timeval tv;
710  int new_len = 0;
711  int type = -1;
712  unsigned int opt_len = sizeof (type);
713  int e;
714 
715  if (len <= 0 || soc <= 0)
716  return NULL;
717 
718  tv.tv_sec = to;
719  tv.tv_usec = 0;
720 
721  data = g_malloc0 (len);
722  if (!fd_is_stream (soc))
723  e = getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &opt_len);
724  else
725  e = -1;
726 
727  if (e == 0 && type == SOCK_DGRAM)
728  {
729  /* As UDP packets may be lost, we retry up to 5 times */
730  int retries = 5;
731  int i;
732 
733  tv.tv_sec = to / retries;
734  tv.tv_usec = (to % retries) * 100000;
735 
736  for (i = 0; i < retries; i++)
737  {
738  FD_ZERO (&rd);
739  FD_SET (soc, &rd);
740 
741  if (select (soc + 1, &rd, NULL, NULL, &tv) > 0)
742  {
743  int e;
744  e = recv (soc, data + new_len, len - new_len, 0);
745 
746  if (e <= 0)
747  {
748  if (!new_len)
749  {
750  g_free (data);
751  return NULL;
752  }
753  }
754  else
755  new_len += e;
756 
757  break; /* UDP data is never fragmented */
758  }
759  else
760  {
761  /* The packet may have been lost en route - we resend it */
762  char *data;
763  int len;
764 
765  data = get_udp_data (lexic->script_infos, soc, &len);
766  if (data != NULL)
767  send (soc, data, len, 0);
768  tv.tv_sec = to / retries;
769  tv.tv_usec = (to % retries) * 100000;
770  }
771  }
772  }
773  else
774  {
775  int old = stream_set_timeout (soc, tv.tv_sec);
776  new_len = read_stream_connection_min (soc, data, min_len, len);
777  stream_set_timeout (soc, old);
778  }
779  if (new_len > 0)
780  {
782  retc->x.str_val = g_memdup (data, new_len);
783  retc->size = new_len;
784  g_free (data);
785  return retc;
786  }
787  else
788  {
789  g_free (data);
790  return NULL;
791  }
792 }
793 
794 tree_cell *
796 {
797  int len = get_int_var_by_name (lexic, "length", -1);
798  int soc = get_int_var_by_name (lexic, "socket", 0);
799  int timeout = get_int_var_by_name (lexic, "timeout", -1);
800  char *data;
801  int new_len = 0;
802  int n = 0;
803  tree_cell *retc;
804  time_t t1 = 0;
805 
806  if (len == -1 || soc <= 0)
807  {
808  nasl_perror (lexic, "recv_line: missing or undefined parameter"
809  " length or socket\n");
810  return NULL;
811  }
812 
813  if (timeout >= 0) /* sycalls are much more expensive than simple tests */
814  t1 = time (NULL);
815 
816  if (fd_is_stream (soc) != 0)
817  {
818  int bufsz = stream_get_buffer_sz (soc);
819  if (bufsz <= 0)
820  stream_set_buffer (soc, len + 1);
821  }
822 
823  data = g_malloc0 (len + 1);
824  for (;;)
825  {
826  int e = read_stream_connection_min (soc, data + n, 1, 1);
827  if (e < 0)
828  break;
829  if (e == 0)
830  {
831  if (timeout >= 0 && time (NULL) - t1 < timeout)
832  continue;
833  else
834  break;
835  }
836  n++;
837  if ((data[n - 1] == '\n') || (n >= len))
838  break;
839  }
840 
841  if (n <= 0)
842  {
843  g_free (data);
844  return NULL;
845  }
846 
847  new_len = n;
848 
849  retc = alloc_typed_cell (CONST_DATA);
850  retc->size = new_len;
851  retc->x.str_val = g_memdup (data, new_len + 1);
852 
853  g_free (data);
854 
855  return retc;
856 }
857 
858 /*---------------------------------------------------------------------*/
859 
860 tree_cell *
862 {
863  int soc = get_int_var_by_name (lexic, "socket", 0);
864  char *data = get_str_var_by_name (lexic, "data");
865  int option = get_int_var_by_name (lexic, "option", 0);
866  int length = get_int_var_by_name (lexic, "length", 0);
867  int data_length = get_var_size_by_name (lexic, "data");
868  int n;
869  tree_cell *retc;
870  int type;
871  unsigned int type_len = sizeof (type);
872 
873  if (soc <= 0 || data == NULL)
874  {
875  nasl_perror (lexic, "Syntax error with the send() function\n");
876  nasl_perror (lexic,
877  "Correct syntax is : send(socket:<soc>, data:<data>\n");
878  return NULL;
879  }
880 
881  if (length <= 0 || length > data_length)
882  length = data_length;
883 
884  if (!fd_is_stream (soc)
885  && getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &type_len) == 0
886  && type == SOCK_DGRAM)
887  {
888  n = send (soc, data, length, option);
889  add_udp_data (lexic->script_infos, soc, data, length);
890  }
891  else
892  {
894  n = nsend (soc, data, length, option);
895  }
896 
897  retc = alloc_typed_cell (CONST_INT);
898  retc->x.i_val = n;
899 
900  return retc;
901 }
902 
903 /*---------------------------------------------------------------------*/
904 tree_cell *
906 {
907  int soc;
908  int type;
909  unsigned int opt_len = sizeof (type);
910  int e;
911 
912  soc = get_int_var_by_num (lexic, 0, -1);
913  if (fd_is_stream (soc))
914  {
916  return close_stream_connection (soc) < 0 ? NULL : FAKE_CELL;
917  }
918  if (lowest_socket == 0 || soc < lowest_socket)
919  {
920  nasl_perror (lexic, "close(%d): Invalid socket value\n", soc);
921  return NULL;
922  }
923 
924  e = getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &opt_len);
925  if (e == 0)
926  {
927  if (type == SOCK_DGRAM)
928  {
929  rm_udp_data (lexic->script_infos, soc);
930  return FAKE_CELL;
931  }
932  close (soc);
933  return FAKE_CELL;
934  }
935  else
936  nasl_perror (lexic, "close(%d): %s\n", soc, strerror (errno));
937 
938  return NULL;
939 }
940 
941 static struct jmg
942 {
943  struct in_addr in;
944  int count;
945  int s;
946 } *jmg_desc = NULL;
947 static int jmg_max = 0;
948 
949 tree_cell *
951 {
952  char *a;
953  int i, j;
954  struct ip_mreq m;
955  tree_cell *retc = NULL;
956 
957  a = get_str_var_by_num (lexic, 0);
958  if (a == NULL)
959  {
960  nasl_perror (lexic, "join_multicast_group: missing parameter\n");
961  return NULL;
962  }
963  if (!inet_aton (a, &m.imr_multiaddr))
964  {
965  nasl_perror (lexic, "join_multicast_group: invalid parameter '%s'\n", a);
966  return NULL;
967  }
968  m.imr_interface.s_addr = INADDR_ANY;
969 
970  j = -1;
971  for (i = 0; i < jmg_max; i++)
972  if (jmg_desc[i].in.s_addr == m.imr_multiaddr.s_addr
973  && jmg_desc[i].count > 0)
974  {
975  jmg_desc[i].count++;
976  break;
977  }
978  else if (jmg_desc[i].count <= 0)
979  j = i;
980 
981  if (i >= jmg_max)
982  {
983  int s = socket (AF_INET, SOCK_DGRAM, 0);
984  if (s < 0)
985  {
986  nasl_perror (lexic, "join_multicast_group: socket: %s\n",
987  strerror (errno));
988  return NULL;
989  }
990 
991  if (setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &m, sizeof (m)) < 0)
992  {
993  nasl_perror (
994  lexic, "join_multicast_group: setsockopt(IP_ADD_MEMBERSHIP): %s\n",
995  strerror (errno));
996  close (s);
997  return NULL;
998  }
999 
1000  if (j < 0)
1001  {
1002  jmg_desc = g_realloc (jmg_desc, sizeof (*jmg_desc) * (jmg_max + 1));
1003  j = jmg_max++;
1004  }
1005  jmg_desc[j].s = s;
1006  jmg_desc[j].in = m.imr_multiaddr;
1007  jmg_desc[j].count = 1;
1008  }
1009 
1010  retc = alloc_typed_cell (CONST_INT);
1011  retc->x.i_val = 1;
1012  return retc;
1013 }
1014 
1015 tree_cell *
1017 {
1018  char *a;
1019  struct in_addr ia;
1020  int i;
1021 
1022  a = get_str_var_by_num (lexic, 0);
1023  if (a == NULL)
1024  {
1025  nasl_perror (lexic, "leave_multicast_group: missing parameter\n");
1026  return NULL;
1027  }
1028  if (!inet_aton (a, &ia))
1029  {
1030  nasl_perror (lexic, "leave_multicast_group: invalid parameter '%s'\n", a);
1031  return NULL;
1032  }
1033 
1034  for (i = 0; i < jmg_max; i++)
1035  if (jmg_desc[i].count > 0 && jmg_desc[i].in.s_addr == ia.s_addr)
1036  {
1037  if (--jmg_desc[i].count <= 0)
1038  close (jmg_desc[i].s);
1039  return FAKE_CELL;
1040  }
1041 
1042  nasl_perror (lexic, "leave_multicast_group: never joined group %s\n", a);
1043  return NULL;
1044 }
1045 
1046 /* Fixme: Merge this into nasl_get_sock_info. */
1047 tree_cell *
1049 {
1050  struct sockaddr_in ia;
1051  int s, fd;
1052  unsigned int l;
1053  tree_cell *retc;
1054  int type;
1055  unsigned int type_len = sizeof (type);
1056 
1057  s = get_int_var_by_num (lexic, 0, -1);
1058  if (s < 0)
1059  {
1060  nasl_perror (lexic, "get_source_port: missing socket parameter\n");
1061  return NULL;
1062  }
1063  if (!fd_is_stream (s)
1064  && getsockopt (s, SOL_SOCKET, SO_TYPE, &type, &type_len) == 0
1065  && type == SOCK_DGRAM)
1066  fd = s;
1067  else
1069 
1070  if (fd < 0)
1071  {
1072  nasl_perror (lexic, "get_source_port: invalid socket parameter %d\n", s);
1073  return NULL;
1074  }
1075  l = sizeof (ia);
1076  if (getsockname (fd, (struct sockaddr *) &ia, &l) < 0)
1077  {
1078  nasl_perror (lexic, "get_source_port: getsockname(%d): %s\n", fd,
1079  strerror (errno));
1080  return NULL;
1081  }
1082  retc = alloc_typed_cell (CONST_INT);
1083  retc->x.i_val = ntohs (ia.sin_port);
1084  return retc;
1085 }
1086 
1087 tree_cell *
1089 {
1090  int soc = get_int_var_by_num (lexic, 0, -1);
1091  tree_cell *retc;
1092  int err;
1093 
1094  if (soc < 0 || !fd_is_stream (soc))
1095  return NULL;
1096 
1097  err = stream_get_err (soc);
1098  retc = alloc_typed_cell (CONST_INT);
1099 
1100  switch (err)
1101  {
1102  case 0:
1103  retc->x.i_val = NASL_ERR_NOERR;
1104  break;
1105  case ETIMEDOUT:
1106  retc->x.i_val = NASL_ERR_ETIMEDOUT;
1107  break;
1108  case EBADF:
1109  case EPIPE:
1110  case ECONNRESET:
1111  case ENOTSOCK:
1112  retc->x.i_val = NASL_ERR_ECONNRESET;
1113  break;
1114 
1115  case ENETUNREACH:
1116  case EHOSTUNREACH:
1117  retc->x.i_val = NASL_ERR_EUNREACH;
1118  break;
1119  case -1:
1120  g_message ("socket_get_error: Erroneous socket value %d", soc);
1121  break;
1122 
1123  default:
1124  g_message ("Unknown error %d %s", err, strerror (err));
1125  }
1126 
1127  return retc;
1128 }
1129 
1189 tree_cell *
1191 {
1192  int sock;
1193  int type;
1194  int err;
1195  const char *keyword, *s;
1196  tree_cell *retc;
1197  int as_string;
1198  int transport;
1199  gnutls_session_t tls_session;
1200  char *strval;
1201  int intval;
1202 
1203  sock = get_int_var_by_num (lexic, 0, -1);
1204  if (sock <= 0)
1205  {
1206  nasl_perror (lexic, "error: socket %d is not valid\n");
1207  return NULL;
1208  }
1209 
1210  keyword = get_str_var_by_num (lexic, 1);
1211  if (!keyword
1212  || !((type = get_var_type_by_num (lexic, 1)) == VAR2_STRING
1213  || type == VAR2_DATA))
1214  {
1215  nasl_perror (lexic, "error: second argument is not of type string\n");
1216  return NULL;
1217  }
1218 
1219  as_string = !!get_int_var_by_name (lexic, "asstring", 0);
1220 
1221  transport = 0;
1222  strval = NULL;
1223  intval = 0;
1224  retc = FAKE_CELL; /* Dummy value to detect retc == NULL. */
1225 
1226  {
1227  void *tmp = NULL;
1228  err = get_sock_infos (sock, &transport, &tmp);
1229  tls_session = tmp;
1230  }
1231  if (err)
1232  {
1233  nasl_perror (lexic, "error retrieving infos for socket %d: %s\n", sock,
1234  strerror (err));
1235  retc = NULL;
1236  }
1237  else if (!strcmp (keyword, "encaps"))
1238  {
1239  if (as_string)
1240  strval = g_strdup (get_encaps_name (transport));
1241  else
1242  intval = transport;
1243  }
1244  else if (!strcmp (keyword, "tls-proto"))
1245  {
1246  if (!tls_session)
1247  s = "n/a";
1248  else
1249  s =
1250  gnutls_protocol_get_name (gnutls_protocol_get_version (tls_session));
1251  strval = g_strdup (s ? s : "[?]");
1252  }
1253  else if (!strcmp (keyword, "tls-kx"))
1254  {
1255  if (!tls_session)
1256  s = "n/a";
1257  else
1258  s = gnutls_kx_get_name (gnutls_kx_get (tls_session));
1259  strval = g_strdup (s ? s : "");
1260  }
1261  else if (!strcmp (keyword, "tls-certtype"))
1262  {
1263  if (!tls_session)
1264  s = "n/a";
1265  else
1266  s = gnutls_certificate_type_get_name (
1267  gnutls_certificate_type_get (tls_session));
1268  strval = g_strdup (s ? s : "");
1269  }
1270  else if (!strcmp (keyword, "tls-cipher"))
1271  {
1272  if (!tls_session)
1273  s = "n/a";
1274  else
1275  s = gnutls_cipher_get_name (gnutls_cipher_get (tls_session));
1276  strval = g_strdup (s ? s : "");
1277  }
1278  else if (!strcmp (keyword, "tls-mac"))
1279  {
1280  if (!tls_session)
1281  s = "n/a";
1282  else
1283  s = gnutls_mac_get_name (gnutls_mac_get (tls_session));
1284  strval = g_strdup (s ? s : "");
1285  }
1286  else if (!strcmp (keyword, "tls-auth"))
1287  {
1288  if (!tls_session)
1289  s = "n/a";
1290  else
1291  {
1292  switch (gnutls_auth_get_type (tls_session))
1293  {
1294  case GNUTLS_CRD_ANON:
1295  s = "ANON";
1296  break;
1297  case GNUTLS_CRD_CERTIFICATE:
1298  s = "CERT";
1299  break;
1300  case GNUTLS_CRD_PSK:
1301  s = "PSK";
1302  break;
1303  case GNUTLS_CRD_SRP:
1304  s = "SRP";
1305  break;
1306  default:
1307  s = "[?]";
1308  break;
1309  }
1310  }
1311  strval = g_strdup (s);
1312  }
1313  else if (!strcmp (keyword, "tls-cert"))
1314  {
1315  /* We only support X.509 for now. GNUTLS also allows for
1316  OpenPGP, but we are not prepared for that. */
1317  if (tls_session
1318  && gnutls_certificate_type_get (tls_session) == GNUTLS_CRT_X509)
1319  {
1320  const gnutls_datum_t *list;
1321  unsigned int nlist = 0;
1322  nasl_array *a;
1323  anon_nasl_var v;
1324 
1325  list = gnutls_certificate_get_peers (tls_session, &nlist);
1326  if (!list)
1327  retc = NULL; /* No certificate or other error. */
1328  else
1329  {
1330  unsigned int i;
1331  retc = alloc_typed_cell (DYN_ARRAY);
1332  retc->x.ref_val = a = g_malloc0 (sizeof *a);
1333 
1334  for (i = 0; i < nlist; i++)
1335  {
1336  memset (&v, 0, sizeof v);
1337  v.var_type = VAR2_DATA;
1338  v.v.v_str.s_val = list[i].data;
1339  v.v.v_str.s_siz = list[i].size;
1340  add_var_to_list (a, i, &v);
1341  }
1342  }
1343  }
1344  }
1345  else
1346  {
1347  nasl_perror (lexic, "unknown keyword '%s'\n", keyword);
1348  retc = NULL;
1349  }
1350 
1351  if (!retc)
1352  ;
1353  else if (retc != FAKE_CELL)
1354  ; /* Already allocated. */
1355  else if (strval)
1356  {
1357  retc = alloc_typed_cell (CONST_STR);
1358  retc->x.str_val = strval;
1359  retc->size = strlen (strval);
1360  }
1361  else
1362  {
1363  retc = alloc_typed_cell (CONST_INT);
1364  retc->x.i_val = intval;
1365  }
1366 
1367  return retc;
1368 }
1369 
1388 tree_cell *
1390 {
1391  int soc, err;
1392  int ret;
1393  tree_cell *retc;
1394  gnutls_x509_crt_t *cert = NULL;
1395  gnutls_x509_trust_list_t ca_list;
1396  unsigned int ca_list_size = 0;
1397  unsigned int i, cert_n = 0;
1398  unsigned int voutput;
1399  const gnutls_datum_t *certs;
1400 
1401  int transport;
1402  gnutls_session_t tls_session;
1403 
1404  soc = get_int_var_by_name (lexic, "socket", -1);
1405  if (soc < 0)
1406  {
1407  nasl_perror (lexic, "socket_get_cert: Erroneous socket value %d\n", soc);
1408  return NULL;
1409  }
1410 
1411  {
1412  void *tmp = NULL;
1413  err = get_sock_infos (soc, &transport, &tmp);
1414  tls_session = tmp;
1415  }
1416  if (err)
1417  {
1418  nasl_perror (lexic, "error retrieving tls_session for socket %d: %s\n",
1419  soc, strerror (err));
1420  return NULL;
1421  }
1422 
1423  /* We only support X.509 for now. GNUTLS also allows for
1424  OpenPGP, but we are not prepared for that. */
1425  if (tls_session
1426  && gnutls_certificate_type_get (tls_session) == GNUTLS_CRT_X509)
1427  {
1428  certs = gnutls_certificate_get_peers (tls_session, &cert_n);
1429  if (!certs)
1430  return NULL; /* No certificate or other error. */
1431  }
1432  else
1433  return NULL;
1434 
1435  cert = g_malloc0 (sizeof (*cert) * cert_n);
1436  for (i = 0; i < cert_n; i++)
1437  {
1438  if (gnutls_x509_crt_init (&cert[i]) != GNUTLS_E_SUCCESS)
1439  return NULL;
1440  if (gnutls_x509_crt_import (cert[i], &certs[i], GNUTLS_X509_FMT_DER)
1441  != GNUTLS_E_SUCCESS)
1442  return NULL;
1443  }
1444 
1445  /* Init ca_list and load system CA trust list */
1446  if ((ret = gnutls_x509_trust_list_init (&ca_list, ca_list_size)) < 0)
1447  return NULL;
1448  ret = gnutls_x509_trust_list_add_system_trust (ca_list, 0, 0);
1449  if (ret < 0)
1450  return NULL;
1451 
1452  /* Certificate verification against a trust list*/
1453  if (gnutls_x509_trust_list_verify_crt (ca_list, cert, cert_n, 0, &voutput,
1454  NULL)
1455  != GNUTLS_E_SUCCESS)
1456  return NULL;
1457 
1458  ret = voutput;
1459 
1460  retc = alloc_typed_cell (CONST_INT);
1461  retc->x.i_val = ret;
1462  return retc;
1463 }
st_a_nasl_var
Definition: nasl_var.h:50
nasl_close_socket
tree_cell * nasl_close_socket(lex_ctxt *lexic)
Definition: nasl_socket.c:905
script_infos
Definition: scanneraux.h:43
get_udp_data
static char * get_udp_data(struct script_infos *script_infos, int soc, int *len)
Definition: nasl_socket.c:187
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
get_var_size_by_name
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
OPENVAS_ENCAPS_IP
@ OPENVAS_ENCAPS_IP
Definition: network.h:45
plug_get_host_ip
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Definition: plugutils.c:285
nasl_recv
tree_cell * nasl_recv(lex_ctxt *lexic)
Definition: nasl_socket.c:701
TC::str_val
char * str_val
Definition: nasl_tree.h:112
nasl_join_multicast_group
tree_cell * nasl_join_multicast_group(lex_ctxt *lexic)
Definition: nasl_socket.c:950
script_infos::udp_data
GHashTable * udp_data
Definition: scanneraux.h:50
nasl_socket_negotiate_ssl
tree_cell * nasl_socket_negotiate_ssl(lex_ctxt *lexic)
Definition: nasl_socket.c:590
CONST_STR
@ CONST_STR
Definition: nasl_tree.h:91
nasl_get_sock_info
tree_cell * nasl_get_sock_info(lex_ctxt *lexic)
Get info pertaining to a socket.
Definition: nasl_socket.c:1190
nasl_socket_get_cert
tree_cell * nasl_socket_get_cert(lex_ctxt *lexic)
Definition: nasl_socket.c:623
openvas_get_socket_from_connection
int openvas_get_socket_from_connection(int fd)
Definition: network.c:367
timeval
struct timeval timeval(unsigned long val)
Definition: nasl_builtin_synscan.c:105
DYN_ARRAY
@ DYN_ARRAY
Definition: nasl_tree.h:101
get_encaps_name
const char * get_encaps_name(openvas_encaps_t code)
Definition: network.c:1546
FAKE_CELL
#define FAKE_CELL
Definition: nasl_tree.h:119
openvas_register_connection
int openvas_register_connection(int soc, void *ssl, gnutls_certificate_credentials_t certcred, openvas_encaps_t encaps)
Definition: network.c:244
TC::x
union TC::@2 x
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
jmg
Definition: nasl_socket.c:941
open_stream_auto_encaps_ext
int open_stream_auto_encaps_ext(struct script_infos *args, unsigned int port, int timeout, int force)
Definition: network.c:1002
socket_get_cert
void socket_get_cert(int fd, void **cert, int *certlen)
Definition: network.c:730
exec.h
nasl_open_sock_udp
tree_cell * nasl_open_sock_udp(lex_ctxt *lexic)
Definition: nasl_socket.c:529
NASL_ERR_NOERR
#define NASL_ERR_NOERR
Definition: nasl.h:63
udp_record
Definition: nasl_socket.c:156
socket_get_ssl_version
int socket_get_ssl_version(int fd)
Definition: network.c:766
st_nasl_string::s_siz
int s_siz
Definition: nasl_var.h:38
NASL_ERR_EUNREACH
#define NASL_ERR_EUNREACH
Definition: nasl.h:66
st_nasl_array
Definition: nasl_var.h:43
OPENVAS_ENCAPS_TLScustom
@ OPENVAS_ENCAPS_TLScustom
Definition: network.h:52
nasl_open_sock_tcp
tree_cell * nasl_open_sock_tcp(lex_ctxt *lexic)
Open a TCP socket to the target host.
Definition: nasl_socket.c:517
stream_set_buffer
int stream_set_buffer(int fd, int sz)
Definition: network.c:1975
nasl_debug.h
nasl_get_source_port
tree_cell * nasl_get_source_port(lex_ctxt *lexic)
Definition: nasl_socket.c:1048
udp_record::data
char * data
Definition: nasl_socket.c:159
nasl_perror
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
get_var_type_by_name
int get_var_type_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1171
rm_udp_data
static void rm_udp_data(struct script_infos *script_infos, int soc)
Definition: nasl_socket.c:210
block_socket
static int block_socket(int soc)
Definition: nasl_socket.c:86
TC::size
int size
Definition: nasl_tree.h:109
stream_get_err
int stream_get_err(int fd)
Definition: network.c:145
nsend
int nsend(int fd, void *data, int length, int i_opt)
Definition: network.c:1402
option
#define option
add_udp_data
static int add_udp_data(struct script_infos *script_infos, int soc, char *data, int len)
Definition: nasl_socket.c:164
IS_ENCAPS_SSL
#define IS_ENCAPS_SSL(x)
Definition: network.h:56
nasl_lex_ctxt.h
nasl_leave_multicast_group
tree_cell * nasl_leave_multicast_group(lex_ctxt *lexic)
Definition: nasl_socket.c:1016
nasl_recv_line
tree_cell * nasl_recv_line(lex_ctxt *lexic)
Definition: nasl_socket.c:795
EADDRNOTAVAIL
#define EADDRNOTAVAIL
Definition: nasl_socket.c:57
jmg::s
int s
Definition: nasl_socket.c:945
NASL_ERR_ECONNRESET
#define NASL_ERR_ECONNRESET
Definition: nasl.h:65
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
socket_get_ssl_ciphersuite
int socket_get_ssl_ciphersuite(int fd)
Definition: network.c:847
VAR2_DATA
@ VAR2_DATA
Definition: nasl_var.h:29
nasl.h
read_stream_connection_min
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
Definition: network.c:1212
nasl_open_sock_tcp_bufsz
tree_cell * nasl_open_sock_tcp_bufsz(lex_ctxt *lexic, int bufsz)
Definition: nasl_socket.c:417
fd_is_stream
int fd_is_stream(int fd)
Definition: network.c:1959
nasl_socket_get_ssl_version
tree_cell * nasl_socket_get_ssl_version(lex_ctxt *lexic)
Definition: nasl_socket.c:668
nasl_func.h
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
nasl_socket_get_ssl_session_id
tree_cell * nasl_socket_get_ssl_session_id(lex_ctxt *lexic)
Definition: nasl_socket.c:645
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:41
nasl_socket_cert_verify
tree_cell * nasl_socket_cert_verify(lex_ctxt *lexic)
Verify a certificate.
Definition: nasl_socket.c:1389
TC
Definition: nasl_tree.h:104
struct_lex_ctxt
Definition: nasl_lex_ctxt.h:33
stream_get_buffer_sz
int stream_get_buffer_sz(int fd)
Definition: network.c:1965
nasl_var.h
nasl_packet_forgery.h
wait_before_next_probe
static void wait_before_next_probe()
Definition: nasl_socket.c:103
nasl_socket_get_error
tree_cell * nasl_socket_get_error(lex_ctxt *lexic)
Definition: nasl_socket.c:1088
udp_record::len
int len
Definition: nasl_socket.c:158
jmg::count
int count
Definition: nasl_socket.c:944
socket_get_ssl_session_id
void socket_get_ssl_session_id(int fd, void **sid, size_t *ssize)
Definition: network.c:807
socket_negotiate_ssl
int socket_negotiate_ssl(int fd, openvas_encaps_t transport, struct script_infos *args)
Definition: network.c:683
nasl_open_privileged_socket
static tree_cell * nasl_open_privileged_socket(lex_ctxt *lexic, int proto)
Definition: nasl_socket.c:223
nasl_global_ctxt.h
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
jmg::in
struct in_addr in
Definition: nasl_socket.c:943
struct_lex_ctxt::recv_timeout
int recv_timeout
Definition: nasl_lex_ctxt.h:43
nasl_send
tree_cell * nasl_send(lex_ctxt *lexic)
Definition: nasl_socket.c:861
unblock_socket
static int unblock_socket(int soc)
Definition: nasl_socket.c:69
jmg_desc
static struct jmg * jmg_desc
nasl_open_priv_sock_tcp
tree_cell * nasl_open_priv_sock_tcp(lex_ctxt *lexic)
Definition: nasl_socket.c:403
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
VAR2_STRING
@ VAR2_STRING
Definition: nasl_var.h:28
jmg_max
static int jmg_max
Definition: nasl_socket.c:947
close_stream_connection
int close_stream_connection(int fd)
Definition: network.c:1518
nasl_socket_get_ssl_ciphersuite
tree_cell * nasl_socket_get_ssl_ciphersuite(lex_ctxt *lexic)
Definition: nasl_socket.c:684
get_sock_infos
int get_sock_infos(int sock, int *r_transport, void **r_tls_session)
Definition: network.c:2063
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
NASL_ERR_ETIMEDOUT
#define NASL_ERR_ETIMEDOUT
Definition: nasl.h:64
lowest_socket
int lowest_socket
Definition: nasl_socket.c:220
nasl_tree.h
list
Definition: nasl_builtin_synscan.c:259
open_stream_connection_ext
int open_stream_connection_ext(struct script_infos *args, unsigned int port, int transport, int timeout, const char *priority)
Definition: network.c:886
st_nasl_string::s_val
unsigned char * s_val
Definition: nasl_var.h:37
nasl_open_priv_sock_udp
tree_cell * nasl_open_priv_sock_udp(lex_ctxt *lexic)
Definition: nasl_socket.c:409
TC::i_val
long int i_val
Definition: nasl_tree.h:113
stream_set_timeout
int stream_set_timeout(int fd, int timeout)
Definition: network.c:1033