OpenVAS Manager  7.0.3~git
ompd.c
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: Module for OpenVAS Manager: the OMP daemon.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  *
8  * Copyright:
9  * Copyright (C) 2009, 2013 Greenbone Networks GmbH
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
40 #include "ompd.h"
41 #include "scanner.h"
42 #include "logf.h"
43 #include "omp.h"
45 #include "otp.h"
46 #include "ovas-mngr-comm.h"
47 
48 #include <assert.h>
49 #include <dirent.h>
50 #include <errno.h>
51 #include <string.h>
52 #include <sys/select.h>
53 #include <sys/socket.h>
54 #include <sys/time.h>
55 #include <sys/types.h>
56 #include <sys/stat.h>
57 #include <unistd.h>
58 
59 #include <openvas/misc/openvas_server.h>
60 
61 #if FROM_BUFFER_SIZE > SSIZE_MAX
62 #error FROM_BUFFER_SIZE too big for "read"
63 #endif
64 
65 #undef G_LOG_DOMAIN
66 
69 #define G_LOG_DOMAIN "md main"
70 
75 
80 
85 
90 
94 static int ompd_nvt_cache_mode = 0;
95 
116 int
117 init_ompd (GSList *log_config, int nvt_cache_mode, const gchar *database,
118  int max_ips_per_target, int max_email_attachment_size,
119  int max_email_include_size, int max_email_message_size,
120  void (*progress) (),
121  int (*fork_connection) (openvas_connection_t *, gchar*),
122  int skip_db_check)
123 {
124  return init_omp (log_config, nvt_cache_mode, database, max_ips_per_target,
125  max_email_attachment_size, max_email_include_size,
126  max_email_message_size,
127  progress, fork_connection, skip_db_check);
128 }
129 
136 void
137 init_ompd_process (const gchar *database, gchar **disable)
138 {
140  from_client_start = 0;
141  from_client_end = 0;
142  init_omp_process (0, database, NULL, NULL, disable);
143 }
144 
153 static int
154 read_from_client_unix (int client_socket)
155 {
157  {
158  int count;
159  count = read (client_socket,
162  if (count < 0)
163  {
164  if (errno == EAGAIN)
165  /* Got everything available, return to `select'. */
166  return 0;
167  if (errno == EINTR)
168  /* Interrupted, try read again. */
169  continue;
170  g_warning ("%s: failed to read from client: %s\n",
171  __FUNCTION__, strerror (errno));
172  return -1;
173  }
174  if (count == 0)
175  {
176  /* End of file. */
177 
178  if (from_client_end)
179  /* There's still client input to process, so pretend we read
180  * something, to prevent serve_omp from exiting.
181  *
182  * This should instead be dealt with in serve_omp, but that function
183  * has got quite complex. */
184  return 0;
185 
186  return -3;
187  }
188  from_client_end += count;
189  }
190 
191  /* Buffer full. */
192  return -2;
193 }
194 
203 static int
204 read_from_client_tls (gnutls_session_t* client_session)
205 {
207  {
208  ssize_t count;
209  count = gnutls_record_recv (*client_session,
212  if (count < 0)
213  {
214  if (count == GNUTLS_E_AGAIN)
215  /* Got everything available, return to `select'. */
216  return 0;
217  if (count == GNUTLS_E_INTERRUPTED)
218  /* Interrupted, try read again. */
219  continue;
220  if (count == GNUTLS_E_REHANDSHAKE)
221  {
223  g_debug (" should rehandshake\n");
224  continue;
225  }
226  if (gnutls_error_is_fatal ((int) count) == 0
227  && (count == GNUTLS_E_WARNING_ALERT_RECEIVED
228  || count == GNUTLS_E_FATAL_ALERT_RECEIVED))
229  {
230  int alert = gnutls_alert_get (*client_session);
231  const char* alert_name = gnutls_alert_get_name (alert);
232  g_warning ("%s: TLS Alert %d: %s\n",
233  __FUNCTION__, alert, alert_name);
234  }
235  g_warning ("%s: failed to read from client: %s\n",
236  __FUNCTION__, gnutls_strerror ((int) count));
237  return -1;
238  }
239  if (count == 0)
240  {
241  /* End of file. */
242 
243  if (from_client_end)
244  /* There's still client input to process, so pretend we read
245  * something, to prevent serve_omp from exiting.
246  *
247  * This should instead be dealt with in serve_omp, but that function
248  * has got quite complex. */
249  return 0;
250 
251  return -3;
252  }
253  from_client_end += count;
254  }
255 
256  /* Buffer full. */
257  return -2;
258 }
259 
268 static int
269 read_from_client (openvas_connection_t *client_connection)
270 {
271  if (client_connection->tls)
272  return read_from_client_tls (&client_connection->session);
273  return read_from_client_unix (client_connection->socket);
274 }
275 
284 static int
285 write_to_client_tls (gnutls_session_t* client_session)
286 {
288  {
289  ssize_t count;
290  count = gnutls_record_send (*client_session,
293  if (count < 0)
294  {
295  if (count == GNUTLS_E_AGAIN)
296  /* Wrote as much as client would accept. */
297  return -2;
298  if (count == GNUTLS_E_INTERRUPTED)
299  /* Interrupted, try write again. */
300  continue;
301  if (count == GNUTLS_E_REHANDSHAKE)
303  continue;
304  g_warning ("%s: failed to write to client: %s\n",
305  __FUNCTION__,
306  gnutls_strerror ((int) count));
307  return -1;
308  }
309  logf ("=> client %.*s\n",
312  to_client_start += count;
313  g_debug ("=> client %u bytes\n", (unsigned int) count);
314  }
315  g_debug ("=> client done\n");
317 
318  /* Wrote everything. */
319  return 0;
320 }
321 
329 static int
330 write_to_client_unix (int client_socket)
331 {
333  {
334  ssize_t count;
335  count = write (client_socket,
338  if (count < 0)
339  {
340  if (errno == EAGAIN)
341  /* Wrote as much as client would accept. */
342  return -2;
343  if (errno == EINTR)
344  /* Interrupted, try write again. */
345  continue;
346  g_warning ("%s: failed to write to client: %s\n",
347  __FUNCTION__,
348  strerror (errno));
349  return -1;
350  }
351  logf ("=> client %.*s\n",
354  to_client_start += count;
355  g_debug ("=> client %u bytes\n", (unsigned int) count);
356  }
357  g_debug ("=> client done\n");
359 
360  /* Wrote everything. */
361  return 0;
362 }
363 
371 static int
372 write_to_client (openvas_connection_t *client_connection)
373 {
374  if (client_connection->tls)
375  return write_to_client_tls (&client_connection->session);
376  return write_to_client_unix (client_connection->socket);
377 }
378 
389 gboolean
390 ompd_send_to_client (const char* msg, void* write_to_client_data)
391 {
393  assert (msg);
394 
396  < strlen (msg))
397  {
398  buffer_size_t length;
399 
400  /* Too little space in to_client buffer for message. */
401 
402  switch (write_to_client (write_to_client_data))
403  {
404  case 0: /* Wrote everything in to_client. */
405  break;
406  case -1: /* Error. */
407  g_debug (" %s full (%i < %zu); client write failed\n",
408  __FUNCTION__,
409  ((buffer_size_t) TO_CLIENT_BUFFER_SIZE) - to_client_end,
410  strlen (msg));
411  return TRUE;
412  case -2: /* Wrote as much as client was willing to accept. */
413  break;
414  default: /* Programming error. */
415  assert (0);
416  }
417 
418  length = ((buffer_size_t) TO_CLIENT_BUFFER_SIZE) - to_client_end;
419 
420  if (length > strlen (msg))
421  break;
422 
423  memmove (to_client + to_client_end, msg, length);
424  g_debug ("-> client: %.*s\n", (int) length, msg);
425  to_client_end += length;
426  msg += length;
427  }
428 
429  if (strlen (msg))
430  {
431  assert (strlen (msg)
432  <= (((buffer_size_t) TO_CLIENT_BUFFER_SIZE) - to_client_end));
433  memmove (to_client + to_client_end, msg, strlen (msg));
434  g_debug ("-> client: %s\n", msg);
435  to_client_end += strlen (msg);
436  }
437 
438  return FALSE;
439 }
440 
446 static void
447 session_clean (openvas_connection_t *client_connection)
448 {
449  if (client_connection->session)
450  {
451  gnutls_deinit (client_connection->session);
452  client_connection->session = NULL;
453  }
454  if (client_connection->credentials)
455  {
456  gnutls_certificate_free_credentials (client_connection->credentials);
457  client_connection->credentials = NULL;
458  }
459 }
460 
492 int
493 serve_omp (openvas_connection_t *client_connection, const gchar *database,
494  gchar **disable, void (*progress) ())
495 {
496  int nfds, scan_handler = 0, rc = 0;
497  /* True if processing of the client input is waiting for space in the
498  * to_scanner or to_client buffer. */
499  short client_input_stalled;
500  /* Client status flag. Set to 0 when the client closes the connection
501  * while the scanner is active. */
502  short client_active = client_connection->socket > 0;
503 
504  if (client_connection->socket < 0)
505  ompd_nvt_cache_mode = client_connection->socket;
506 
507  if (ompd_nvt_cache_mode)
508  g_info (" Updating NVT cache.\n");
509  else
510  g_debug (" Serving OMP.\n");
511 
512  /* Initialise the XML parser and the manage library. */
513  init_omp_process (ompd_nvt_cache_mode,
514  database,
515  (int (*) (const char*, void*)) ompd_send_to_client,
516  (void*) client_connection,
517  disable);
518 #if 0
519 
520  if (tasks) free_tasks ();
521  if (current_scanner_preference) free (current_scanner_preference);
522  free_credentials (&current_credentials);
523  maybe_free_scanner_preferences (); // old
524 #endif
525 
526  /* Setup the scanner address and try to connect. */
527  if (ompd_nvt_cache_mode && !openvas_scanner_connected ())
528  {
529  int ret;
530 
531  /* Is here because it queries the DB and needs it initialized.
532  * XXX: Move outside serve_omp ().
533  */
534 
536  if (ret)
537  return ret;
539  {
541  return -1;
542  }
543  }
544 
545  client_input_stalled = 0;
546 
548  /* Loop handling input from the sockets.
549  *
550  * That is, select on all the socket fds and then, as necessary
551  * - read from the client into buffer from_client
552  * - write to the scanner from buffer to_scanner
553  * - read from the scanner into buffer from_scanner
554  * - write to the client from buffer to_client.
555  *
556  * On reading from an fd, immediately try react to the input. On reading
557  * from the client call process_omp_client_input, which parses OMP
558  * commands and may write to to_scanner and to_client. On reading from
559  * the scanner call process_otp_scanner_input, which updates information
560  * kept about the scanner.
561  *
562  * There are a few complications here
563  * - the program must read from or write to an fd returned by select
564  * before selecting on the fd again,
565  * - the program need only select on the fds for writing if there is
566  * something to write,
567  * - similarly, the program need only select on the fds for reading
568  * if there is buffer space available,
569  * - the buffers from_client and from_scanner can become full during
570  * reading
571  * - a read from the client can be stalled by the to_scanner buffer
572  * filling up, or the to_client buffer filling up (in which case
573  * process_omp_client_input will try to write the to_client buffer
574  * itself),
575  * - a read from the scanner can, theoretically, be stalled by the
576  * to_scanner buffer filling up (during initialisation).
577  */
578 
579  nfds = openvas_scanner_get_nfds (client_connection->socket);
580  while (1)
581  {
582  int ret;
583  fd_set readfds, writefds;
585 
586  if (termination_signal)
587  {
588  g_debug ("%s: Received %s signal.",
589  __FUNCTION__,
590  sys_siglist[get_termination_signal()]);
591 
593  {
595  }
596 
597  goto client_free;
598  }
599 
600  /* Setup for select. */
601 
604  FD_ZERO (&readfds);
605  FD_ZERO (&writefds);
606 
609  if (client_active)
610  {
611  /* See whether to read from the client. */
613  FD_SET (client_connection->socket, &readfds);
614  /* See whether to write to the client. */
616  FD_SET (client_connection->socket, &writefds);
617  }
618 
619  /* See whether we need to read from the scannner. */
627  && !openvas_scanner_full ())
628  openvas_scanner_fd_set (&readfds);
629 
630  /* See whether we need to write to the scanner. */
636  && to_server_buffer_space () > 0)
640  openvas_scanner_fd_set (&writefds);
641 
642  /* Select, then handle result. Due to GNUTLS internal buffering
643  * we test for pending records first and emulate a select call
644  * in that case. Note, that GNUTLS guarantees that writes are
645  * not buffered. Note also that GNUTLS versions < 3 did not
646  * exhibit a problem in OpenVAS due to a different buffering
647  * strategy. */
648  ret = 0;
649  if (client_connection->socket > 0
650  && client_connection->tls
651  && FD_ISSET (client_connection->socket, &readfds)
652  && gnutls_record_check_pending (client_connection->session))
653  {
654  FD_ZERO (&readfds);
655  FD_ZERO (&writefds);
656  ret++;
657  FD_SET (client_connection->socket, &readfds);
658  }
659  if (openvas_scanner_fd_isset (&readfds))
660  {
662  {
663  if (!ret)
664  {
665  FD_ZERO (&readfds);
666  FD_ZERO (&writefds);
667  }
668  ret++;
669  openvas_scanner_fd_set (&readfds);
670  }
671  else if (openvas_scanner_peek () == 0)
672  {
673  /* Scanner has gone down. Exit. */
674  rc = -1;
675  goto client_free;
676  }
677  }
678 
679  if (!ret)
680  {
681  /* Timeout periodically, so that process_omp_change runs
682  * periodically. */
683  struct timeval timeout;
684 
685  timeout.tv_usec = 0;
686  timeout.tv_sec = 1;
687  ret = select (nfds, &readfds, &writefds, NULL, &timeout);
688  }
689  if ((ret < 0 && errno == EINTR) || ret == 0)
690  {
691  if (process_omp_change () == -1)
692  {
693  rc = -1;
694  goto client_free;
695  }
696  if (!scan_handler && !ompd_nvt_cache_mode)
697  continue;
698  }
699  else if (ret < 0)
700  {
701  g_warning ("%s: child select failed: %s\n", __FUNCTION__,
702  strerror (errno));
703  rc = -1;
704  goto client_free;
705  }
706 
707  /* Read any data from the client. */
708  if (client_connection->socket > 0
709  && FD_ISSET (client_connection->socket, &readfds))
710  {
711  buffer_size_t initial_start = from_client_end;
712 
713  switch (read_from_client (client_connection))
714  {
715  case 0: /* Read everything. */
716  break;
717  case -1: /* Error. */
718  rc = -1;
719  goto client_free;
720  case -2: /* from_client buffer full. */
721  /* There may be more to read. */
722  break;
723  case -3: /* End of file. */
724  g_debug (" EOF reading from client.\n");
725  if (client_connection->socket > 0
726  && FD_ISSET (client_connection->socket, &writefds))
727  /* Write rest of to_client to client, so that the client gets
728  * any buffered output and the response to the error. */
729  write_to_client (client_connection);
730  rc = 0;
731  goto client_free;
732  default: /* Programming error. */
733  assert (0);
734  }
735 
736  /* This check prevents output in the "asynchronous network
737  * error" case. */
738  if (from_client_end > initial_start)
739  {
740  logf ("<= client %.*s\n",
741  from_client_end - initial_start,
742  from_client + initial_start);
743  if (g_strstr_len (from_client + initial_start,
744  from_client_end - initial_start,
745  "<password>"))
746  g_debug ("<= client Input may contain password, suppressed.\n");
747  else
748  g_debug ("<= client \"%.*s\"\n",
749  from_client_end - initial_start,
750  from_client + initial_start);
751  }
752 
753  ret = process_omp_client_input ();
754  if (ret == 0)
755  /* Processed all input. */
756  client_input_stalled = 0;
757  else if (ret == 3)
758  {
759  /* In the parent after a start_task fork. Free the scanner session
760  * without closing it, for usage by the child process. */
763  nfds = openvas_scanner_get_nfds (client_connection->socket);
764  client_input_stalled = 0;
765  /* Skip the rest of the loop because the scanner socket is
766  * a new socket. This is asking for select trouble, really. */
767  continue;
768  }
769  else if (ret == 2)
770  {
771  /* Now in a process forked to run a task, which has
772  * successfully started the task. Close the client
773  * connection, as the parent process has continued the
774  * session with the client. */
775  session_clean (client_connection);
776  client_active = 0;
777  client_input_stalled = 0;
778  scan_handler = 1;
779  }
780  else if (ret == 4)
781  {
782  /* Now in a process forked for some operation which has
783  * successfully completed. Close the client connection,
784  * and exit, as the parent process has continued the
785  * session with the client. */
786  session_clean (client_connection);
787  return 0;
788  }
789  else if (ret == -10)
790  {
791  /* Now in a process forked to run a task, which has
792  * failed in starting the task. */
793  session_clean (client_connection);
794  return -1;
795  }
796  else if (ret == -1 || ret == -4)
797  {
798  /* Error. Write rest of to_client to client, so that the
799  * client gets any buffered output and the response to the
800  * error. */
801  write_to_client (client_connection);
802  rc = -1;
803  goto client_free;
804  }
805  else if (ret == -2)
806  {
807  /* to_scanner buffer full. */
808  g_debug (" client input stalled 1\n");
809  client_input_stalled = 1;
810  /* Carry on to write to_scanner. */
811  }
812  else if (ret == -3)
813  {
814  /* to_client buffer full. */
815  g_debug (" client input stalled 2\n");
816  client_input_stalled = 2;
817  /* Carry on to write to_client. */
818  }
819  else
820  {
821  /* Programming error. */
822  assert (0);
823  client_input_stalled = 0;
824  }
825  }
826 
827  /* Read any data from the scanner. */
829  && (openvas_scanner_fd_isset (&readfds) || scan_handler))
830  {
831  switch (openvas_scanner_read ())
832  {
833  case 0: /* Read everything. */
834  break;
835  case -1: /* Error. */
836  /* This may be because the scanner closed the connection
837  * at the end of a command. */
840  rc = -1;
841  goto client_free;
842  case -2: /* from_scanner buffer full. */
843  /* There may be more to read. */
844  break;
845  case -3: /* End of file. */
847  if (client_active == 0)
848  /* The client has closed the connection, so exit. */
849  return 0;
850  /* Scanner went down, exit. */
851  rc = -1;
852  goto client_free;
853  default: /* Programming error. */
854  assert (0);
855  }
856  }
857 
858  /* Write any data to the scanner. */
860  && (openvas_scanner_fd_isset (&writefds) || scan_handler))
861  {
862  /* Write as much as possible to the scanner. */
863 
864  switch (openvas_scanner_write (ompd_nvt_cache_mode))
865  {
866  case 0: /* Wrote everything in to_scanner. */
867  break;
868  case -1: /* Error. */
871  rc = -1;
872  goto client_free;
873  case -2: /* Wrote as much as scanner was willing to accept. */
874  break;
875  case -3: /* Did an initialisation step. */
876  break;
877  default: /* Programming error. */
878  assert (0);
879  }
880  }
881 
882  /* Write any data to the client. */
883  if (client_connection->socket > 0
884  && FD_ISSET (client_connection->socket, &writefds))
885  {
886  /* Write as much as possible to the client. */
887 
888  switch (write_to_client (client_connection))
889  {
890  case 0: /* Wrote everything in to_client. */
891  break;
892  case -1: /* Error. */
893  rc = -1;
894  goto client_free;
895  case -2: /* Wrote as much as client was willing to accept. */
896  break;
897  default: /* Programming error. */
898  assert (0);
899  }
900  }
901 
902  if (client_input_stalled)
903  {
904  /* Try process the client input, in case writing to the scanner
905  * or client has freed some space in to_scanner or to_client. */
906 
907  ret = process_omp_client_input ();
908  if (ret == 0)
909  /* Processed all input. */
910  client_input_stalled = 0;
911  else if (ret == 3)
912  {
913  /* In the parent after a start_task fork. Free the scanner session
914  * without closing it, for usage by the child process. */
917  nfds = openvas_scanner_get_nfds (client_connection->socket);
918  /* Skip the rest of the loop because the scanner socket is
919  * a new socket. This is asking for select trouble, really. */
920  continue;
921  }
922  else if (ret == 2)
923  {
924  /* Now in a process forked to run a task, which has
925  * successfully started the task. Close the client
926  * connection, as the parent process has continued the
927  * session with the client. */
928  session_clean (client_connection);
929  scan_handler = 1;
930  client_active = 0;
931  }
932  else if (ret == 4)
933  {
934  /* Now in a process forked for some operation which has
935  * successfully completed. Close the client connection,
936  * and exit, as the parent process has continued the
937  * session with the client. */
938  session_clean (client_connection);
939  return 0;
940  }
941  else if (ret == -10)
942  {
943  /* Now in a process forked to run a task, which has
944  * failed in starting the task. */
945  session_clean (client_connection);
946  return -1;
947  }
948  else if (ret == -1)
949  {
950  /* Error. Write rest of to_client to client, so that the
951  * client gets any buffered output and the response to the
952  * error. */
953  write_to_client (client_connection);
954  rc = -1;
955  goto client_free;
956  }
957  else if (ret == -2)
958  {
959  /* to_scanner buffer full. */
960  g_debug (" client input still stalled (1)\n");
961  client_input_stalled = 1;
962  }
963  else if (ret == -3)
964  {
965  /* to_client buffer full. */
966  g_debug (" client input still stalled (2)\n");
967  client_input_stalled = 2;
968  }
969  else
970  {
971  /* Programming error. */
972  assert (0);
973  client_input_stalled = 0;
974  }
975  }
976 
978  {
979  /* Try process the scanner input, in case writing to the scanner
980  * has freed some space in to_scanner. */
981 
983  if (ret == 1)
984  {
985  /* Received scanner BYE. Write out the rest of to_scanner (the
986  * BYE ACK).
987  */
988  openvas_scanner_write (ompd_nvt_cache_mode);
990  if (client_active == 0)
991  return 0;
993  nfds = openvas_scanner_get_nfds (client_connection->socket);
994  }
995  else if (ret == 2)
996  {
997  /* Bad login to scanner. */
998  if (client_active == 0)
999  return 0;
1000  rc = -1;
1001  goto client_free;
1002  }
1003  else if (ret == 3)
1004  {
1005  /* Calls via serve_client() should continue. */
1006  if (ompd_nvt_cache_mode)
1007  return 1;
1009  }
1010  else if (ret == -1)
1011  {
1012  /* Error. */
1013  rc = -1;
1014  goto client_free;
1015  }
1016  else if (ret == -3)
1017  /* to_scanner buffer still full. */
1018  g_debug (" scanner input stalled\n");
1019  else
1020  {
1021  /* Programming error. */
1022  assert (ret == 0 || ret == 5);
1023  }
1024  }
1025 
1026  if (process_omp_change () == -1)
1027  {
1028  rc = -1;
1029  goto client_free;
1030  }
1031 
1032  } /* while (1) */
1033 
1034 client_free:
1035  if (client_active)
1036  openvas_connection_free (client_connection);
1037  return rc;
1038 }
int init_omp(GSList *log_config, int nvt_cache_mode, const gchar *database, int max_ips_per_target, int max_email_attachment_size, int max_email_include_size, int max_email_message_size, void(*progress)(), int(*fork_connection)(openvas_connection_t *, gchar *), int skip_db_check)
Initialise OMP library.
Definition: omp.c:30814
Protos for communication between openvas-manager and openvas-server.
void init_omp_process(int update_nvt_cache, const gchar *database, int(*write_to_client)(const char *, void *), void *write_to_client_data, gchar **disable)
Initialise OMP library data for a process.
Definition: omp.c:30846
buffer_size_t from_client_start
The start of the data in the from_client buffer.
Definition: ompd.c:84
#define TO_CLIENT_BUFFER_SIZE
The size of the to_client data buffer, in bytes.
Definition: omp.h:38
int openvas_scanner_read()
Read as much from the server as the from_scanner buffer will.
Definition: scanner.c:233
GSList * log_config
Logging parameters, as passed to setup_log_handlers.
Definition: openvasmd.c:310
void openvas_scanner_free()
Free the scanner allocated data. Doesn&#39;t close socket and terminate the session.
Definition: scanner.c:659
int process_omp_change()
Deal with any changes caused by other processes.
Definition: omp.c:31098
scanner_init_state_t scanner_init_state
The initialisation state of the scanner.
Definition: otp.c:411
#define logf(format, args...)
Dummy macro, enabled with LOG.
Definition: logf.h:81
int openvas_scanner_peek()
Check if there is any data to receive from connected Scanner socket.
Definition: scanner.c:715
buffer_size_t from_client_end
The end of the data in the from_client buffer.
Definition: ompd.c:89
gboolean ompd_send_to_client(const char *msg, void *write_to_client_data)
Send a response message to the client.
Definition: ompd.c:390
buffer_size_t from_buffer_size
Size of from_client data buffer, in bytes.
Definition: ompd.c:79
gnutls_session_t client_session
The client session.
Definition: openvasmd.c:236
buffer_size_t to_client_start
The start of the data in the to_client buffer.
Definition: omp.c:4984
unsigned int to_server_buffer_space()
Get the number of characters free in the server output buffer.
void openvas_scanner_fd_set(fd_set *fd)
Add connected to Scanner&#39;s socket to an fd_set.
Definition: scanner.c:701
int openvas_scanner_connected()
Whether we have started a connection to the Scanner using openvas_scanner_connect().
Definition: scanner.c:764
int process_omp_client_input()
Process any XML available in from_client.
Definition: omp.c:30895
int openvas_scanner_full()
Check whether the buffer for data from Scanner is full.
Definition: scanner.c:310
void(* progress)()
Function to mark progress.
Definition: manage_sql.c:352
volatile int termination_signal
Flag for signal handlers.
Definition: openvasmd.c:256
int serve_omp(openvas_connection_t *client_connection, const gchar *database, gchar **disable, void(*progress)())
Serve the OpenVAS Management Protocol (OMP).
Definition: ompd.c:493
void openvas_scanner_fork()
Reset Scanner variables after a fork.
Definition: scanner.c:575
int openvas_scanner_write(int nvt_cache_mode)
Write as much as possible from the to_scanner buffer to the scanner.
Definition: scanner.c:338
char * alert_name(alert_t alert)
Return the name of an alert.
Definition: manage_sql.c:8362
void set_scanner_init_state(scanner_init_state_t state)
Set the scanner initialisation state, scanner_init_state.
Definition: otp.c:432
void init_ompd_process(const gchar *database, gchar **disable)
Initialise a process forked within the OMP daemon.
Definition: ompd.c:137
#define FROM_BUFFER_SIZE
Size of from_client and from_scanner data buffers, in bytes.
Definition: ompd.h:45
int openvas_scanner_connect()
Create a new connection to the scanner and set it as current scanner.
Definition: scanner.c:619
int get_termination_signal()
Gets the last termination signal or 0.
Definition: manage.c:9582
int init_ompd(GSList *log_config, int nvt_cache_mode, const gchar *database, int max_ips_per_target, int max_email_attachment_size, int max_email_include_size, int max_email_message_size, void(*progress)(), int(*fork_connection)(openvas_connection_t *, gchar *), int skip_db_check)
Initialise the OMP library for the OMP daemon.
Definition: ompd.c:117
int openvas_scanner_get_nfds(int socket)
Get the nfds value to use for a select() call.
Definition: scanner.c:732
char to_client[TO_CLIENT_BUFFER_SIZE]
Buffer of output to the client.
Definition: omp.c:4979
A printf like macro for logging communication.
char from_client[FROM_BUFFER_SIZE]
Buffer of input from the client.
Definition: ompd.c:74
int openvas_scanner_init(int cache_mode)
Initializes the already setup connection with the Scanner.
Definition: scanner.c:778
int openvas_scanner_session_peek()
Check if there is any data to receive from connected Scanner session.
Definition: scanner.c:747
credentials_t current_credentials
Current credentials during any OMP command.
Definition: manage.c:717
#define g_info(...)
Defines g_info for glib versions older than 2.40.
Definition: manage.h:55
void free_tasks()
Dummy function.
Definition: manage_sql.c:31878
buffer_size_t to_client_end
The end of the data in the to_client buffer.
Definition: omp.c:4988
int manage_scanner_set_default()
Set the default scanner as the scanner to connect to.
Definition: manage_sql.c:17440
int process_otp_scanner_input(void(*progress)())
Process any lines available in from_scanner.
Definition: otp.c:781
unsigned int buffer_size_t
Definition: types.h:31
int openvas_scanner_fd_isset(fd_set *fd)
Check if connected to Scanner is set in an fd_set.
Definition: scanner.c:688
int openvas_scanner_close()
Finish the connection to the Scanner and free internal buffers.
Definition: scanner.c:551