OpenVAS Scanner  5.1.3
openvassd.c File Reference
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <netdb.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <openvas/misc/openvas_proctitle.h>
#include <openvas/misc/openvas_logging.h>
#include <openvas/base/pidfile.h>
#include <openvas/base/nvticache.h>
#include <openvas/base/kb.h>
#include <openvas/base/gpgme_util.h>
#include <openvas/misc/prefs.h>
#include <openvas/misc/vendorversion.h>
#include <gcrypt.h>
#include "comm.h"
#include "attack.h"
#include "sighand.h"
#include "log.h"
#include "processes.h"
#include "ntp.h"
#include "utils.h"
#include "pluginlaunch.h"
#include <openvas/misc/network.h>
Include dependency graph for openvassd.c:

Go to the source code of this file.

Data Structures

struct  openvassd_option
 

Functions

void loading_handler_stop (pid_t handler_pid)
 
void check_kb_status ()
 Check if Redis Server is up and if the KB exists. If KB does not exist,force a reload and stop all the running scans. More...
 
int main (int argc, char *argv[])
 openvassd. More...
 

Variables

int global_max_hosts = 15
 
int global_max_checks = 10
 
gchar * unix_socket_path = NULL
 

Detailed Description

OpenVAS Scanner main module, runs the scanner.

Definition in file openvassd.c.

Function Documentation

◆ check_kb_status()

void check_kb_status ( )

Check if Redis Server is up and if the KB exists. If KB does not exist,force a reload and stop all the running scans.

Definition at line 570 of file openvassd.c.

References log_write().

571 {
572  int waitredis = 5, waitkb = 5, ret = 0;
573  kb_t kb_access_aux;
574 
575  while (waitredis != 0)
576  {
577  ret = kb_new (&kb_access_aux, prefs_get ("kb_location"));
578  if (ret)
579  {
580  log_write ("Redis connection lost. Trying to reconnect.");
581  waitredis--;
582  sleep (5);
583  continue;
584  }
585  else
586  {
587  kb_delete (kb_access_aux);
588  break;
589  }
590  }
591 
592  if (waitredis == 0)
593  {
594  log_write ("Critical Redis connection error.");
595  exit (1);
596  }
597 
598  while (waitkb != 0)
599  {
600  kb_access_aux = kb_find (prefs_get ("kb_location"), "nvticache");
601  if (!kb_access_aux)
602  {
603  log_write ("Redis kb not found. Trying again in 2 seconds.");
604  waitkb--;
605  sleep (2);
606  continue;
607  }
608  else
609  {
610  kb_lnk_reset (kb_access_aux);
611  g_free (kb_access_aux);
612  break;
613  }
614  }
615 
616  if (waitredis != 5 || waitkb == 0)
617  {
618  log_write ("Redis connection error. Stopping all the running scans.");
619  stop_all_scans ();
620  reload_openvassd ();
621  }
622 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
Here is the call graph for this function:

◆ loading_handler_stop()

void loading_handler_stop ( pid_t  handler_pid)

Definition at line 343 of file openvassd.c.

References destroy_loading_shm(), and terminate_process().

344 {
345  terminate_process (handler_pid);
347 }
void destroy_loading_shm(void)
Definition: pluginload.c:165
int terminate_process(pid_t pid)
Definition: processes.c:43
Here is the call graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

openvassd.

Parameters
argcArgument count.
argvArgument vector.

Definition at line 874 of file openvassd.c.

875 {
876  int ret;
877  pid_t handler_pid;
878 
879  proctitle_init (argc, argv);
880  gcrypt_init ();
881 
882  static gboolean display_version = FALSE;
883  static gboolean dont_fork = FALSE;
884  static gchar *config_file = NULL;
885  static gchar *vendor_version_string = NULL;
886  static gchar *listen_owner = NULL;
887  static gchar *listen_group = NULL;
888  static gchar *listen_mode = NULL;
889  static gchar *gnupg_dir = NULL;
890  static gboolean print_specs = FALSE;
891  static gboolean print_sysconfdir = FALSE;
892  static gboolean only_cache = FALSE;
893  GError *error = NULL;
894  GOptionContext *option_context;
895  static GOptionEntry entries[] = {
896  {"version", 'V', 0, G_OPTION_ARG_NONE, &display_version,
897  "Display version information", NULL},
898  {"foreground", 'f', 0, G_OPTION_ARG_NONE, &dont_fork,
899  "Do not run in daemon mode but stay in foreground", NULL},
900  {"config-file", 'c', 0, G_OPTION_ARG_FILENAME, &config_file,
901  "Configuration file", "<filename>"},
902  {"vendor-version", '\0', 0, G_OPTION_ARG_STRING, &vendor_version_string,
903  "Use <string> as vendor version.", "<string>"},
904  {"cfg-specs", 's', 0, G_OPTION_ARG_NONE, &print_specs,
905  "Print configuration settings", NULL},
906  {"sysconfdir", 'y', 0, G_OPTION_ARG_NONE, &print_sysconfdir,
907  "Print system configuration directory (set at compile time)", NULL},
908  {"only-cache", 'C', 0, G_OPTION_ARG_NONE, &only_cache,
909  "Exit once the NVT cache has been initialized or updated", NULL},
910  {"unix-socket", 'c', 0, G_OPTION_ARG_FILENAME, &unix_socket_path,
911  "Path of unix socket to listen on", "<filename>"},
912  {"listen-owner", '\0', 0, G_OPTION_ARG_STRING, &listen_owner,
913  "Owner of the unix socket", "<string>"},
914  {"listen-group", '\0', 0, G_OPTION_ARG_STRING, &listen_group,
915  "Group of the unix socket", "<string>"},
916  {"listen-mode", '\0', 0, G_OPTION_ARG_STRING, &listen_mode,
917  "File mode of the unix socket", "<string>"},
918  {"gnupg-home", 'c', 0, G_OPTION_ARG_STRING, &gnupg_dir,
919  "Gnupg home directory", "<directory>"},
920  {NULL, 0, 0, 0, NULL, NULL, NULL}
921  };
922 
923  option_context =
924  g_option_context_new ("- Scanner of the Open Vulnerability Assessment System");
925  g_option_context_add_main_entries (option_context, entries, NULL);
926  if (!g_option_context_parse (option_context, &argc, &argv, &error))
927  {
928  g_print ("%s\n\n", error->message);
929  exit (0);
930  }
931  g_option_context_free (option_context);
932 
933  if (print_sysconfdir)
934  {
935  g_print ("%s\n", SYSCONFDIR);
936  exit (0);
937  }
938 
939  /* Switch to UTC so that OTP times are always in UTC. */
940  if (setenv ("TZ", "utc 0", 1) == -1)
941  {
942  g_print ("%s\n\n", strerror (errno));
943  exit (0);
944  }
945  tzset ();
946 
947  if (!unix_socket_path)
948  unix_socket_path = g_build_filename (OPENVAS_RUN_DIR, "openvassd.sock", NULL);
949 
950  if (display_version)
951  {
952  printf ("OpenVAS Scanner %s\n", OPENVASSD_VERSION);
953 #ifdef OPENVASSD_SVN_REVISION
954  printf ("SVN revision %i\n", OPENVASSD_SVN_REVISION);
955 #endif
956  printf
957  ("Most new code since 2005: (C) 2016 Greenbone Networks GmbH\n");
958  printf
959  ("Nessus origin: (C) 2004 Renaud Deraison <deraison@nessus.org>\n");
960  printf ("License GPLv2: GNU GPL version 2\n");
961  printf
962  ("This is free software: you are free to change and redistribute it.\n"
963  "There is NO WARRANTY, to the extent permitted by law.\n\n");
964  exit (0);
965  }
966 
967  if (gnupg_dir)
968  set_gpghome (gnupg_dir);
969 
970  if (vendor_version_string)
971  vendor_version_set (vendor_version_string);
972 
973  if (!config_file)
974  config_file = OPENVASSD_CONF;
975  if (only_cache)
976  {
977  if (init_openvassd (dont_fork, config_file))
978  return 1;
979  if (plugins_init ())
980  return 1;
981  return 0;
982  }
983 
984  if (init_openvassd (dont_fork, config_file))
985  return 1;
986  if (!print_specs)
987  {
988  if (init_unix_network (&global_iana_socket, listen_owner, listen_group,
989  listen_mode))
990  return 1;
991  }
992 
993  /* special treatment */
994  if (print_specs)
995  {
996  prefs_dump ();
997  exit (0);
998  }
999  flush_all_kbs ();
1000 
1001 #if GNUTLS_VERSION_NUMBER < 0x030300
1002  if (openvas_SSL_init () < 0)
1003  log_write ("Could not initialize openvas SSL!");
1004 #endif
1005 
1006  // Daemon mode:
1007  if (dont_fork == FALSE)
1008  set_daemon_mode ();
1009  pidfile_create ("openvassd");
1010 
1011  /* Ignore SIGHUP while reloading. */
1012  openvas_signal (SIGHUP, SIG_IGN);
1013  handler_pid = loading_handler_start ();
1014  if (handler_pid < 0)
1015  return 1;
1016  ret = plugins_init ();
1017  loading_handler_stop (handler_pid);
1018  if (ret)
1019  return 1;
1020  init_signal_handlers ();
1021  main_loop ();
1022  exit (0);
1023 }
void(*)(int) openvas_signal(int signum, void(*handler)(int))
Definition: sighand.c:92
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
int plugins_init(void)
Definition: pluginload.c:358
gchar * unix_socket_path
Definition: openvassd.c:139
void loading_handler_stop(pid_t handler_pid)
Definition: openvassd.c:343

Variable Documentation

◆ global_max_checks

int global_max_checks = 10

Definition at line 87 of file openvassd.c.

Referenced by get_max_checks_number().

◆ global_max_hosts

int global_max_hosts = 15

Globals that should not be touched (used in utils module).

Definition at line 86 of file openvassd.c.

Referenced by get_max_hosts_number().

◆ unix_socket_path

gchar* unix_socket_path = NULL

Definition at line 139 of file openvassd.c.