OpenVAS CLI  1.4.5
check_omp.c
Go to the documentation of this file.
1 /* OMP Nagios Command Plugin
2  * $Id$
3  * Description: A nagios command plugin for the OpenVAS Management Protocol
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  * Michael Wiegand <michael.wiegand@greenbone.net>
8  * Marcus Brinkmann <mb@g10code.com>
9  * Werner Koch <wk@gnupg.org>
10  *
11  * Copyright:
12  * Copyright (C) 2009-2016 Greenbone Networks GmbH
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27  */
28 
49 #define _GNU_SOURCE
50 
51 #include <assert.h>
52 #include <glib.h>
53 #include <locale.h>
54 #include <stdio.h>
55 #include <stdlib.h> /* for exit() */
56 #include <string.h>
57 #include <stdarg.h>
58 
59 #include <openvas/misc/openvas_server.h>
60 #ifdef _WIN32
61 #include <winsock2.h>
62 #endif
63 #ifndef _WIN32
64 #include <openvas/misc/openvas_logging.h>
65 #endif
66 #include <openvas/omp/omp.h>
67 
71 #define OMP_PROGNAME "check_omp"
72 
76 #define OPENVASMD_ADDRESS "127.0.0.1"
77 
81 #define OPENVASMD_PORT 9390
82 
83 
84 #define DEFAULT_SOCKET_TIMEOUT 10
85 
86 /* See http://nagiosplug.sourceforge.net/developer-guidelines.html for the
87  * official documentiation of the exit codes.
88  * Note that we handle the conditions for the exit codes somewhat differently
89  * since we are not directly monitoring a service, rather we are using a service
90  * (OpenVAS Manager) to monitor another system.
91  */
96 #define NAGIOS_OK 0
97 
102 #define NAGIOS_WARNING 1
103 
108 #define NAGIOS_CRITICAL 2
109 
115 #define NAGIOS_UNKNOWN 3
116 
117 #define NAGIOS_DEPENDENT 4
118 
119 
120 /* Type definitions. */
121 
125 typedef struct
126 {
127  gnutls_session_t session;
128  int socket;
129  gchar *username;
130  gchar *password;
131  gchar *host_string;
132  gint port;
133  gint timeout;
135 
139 typedef struct
140 {
141  gboolean report_link;
142  gboolean dfn_ids;
143  gboolean oids;
144  gboolean descr;
145  gpointer manager_host;
146  gboolean log_messages;
147  gboolean scan_end;
148  guint autofp;
149  gint timeout;
150  gboolean empty_as_unknown;
152 
153 /* Prototypes. */
154 static void
155 do_exit (int rc)
156 #if __GNUC__ >= 3
157  __attribute__ ((__noreturn__));
158 #endif
159 ;
160 
161 
162 /* Global options. */
163 
164 /* If this flag is set, UNKNOWN status codes are mapped to CRITICAL. */
165 static int warnings_are_errors;
166 
167 /* The value of the --overrides option. */
168 static gint overrides_flag;
169 
170 /* This flag is set if in any output a pipe symbol has been replaced
171  by a broken bar (U+00A6). Nagios uses the pipe symbol to separate
172  performance data from the status. */
173 static int pipe_symbol_substituted;
174 
175 
176 /* Helper functions and macros. */
177 
178 static void
179 print_respond_string (const char *string)
180 {
181  const char *s;
182 
183  for (s = string; *s; s++)
184  {
185  if (*s == '|')
186  {
187  fputs ("¦", stdout);
188  pipe_symbol_substituted = 1;
189  }
190  else
191  putchar (*s);
192  }
193 }
194 
195 
196 /* Print the first respond line. The return value is CODE, which is
197  the Nagios plugin status code. */
198 static int
199 respond (int code, const char *format, ...)
200 {
201  va_list arg_ptr;
202  char *buf;
203  const char *status;
204 
205  switch (code)
206  {
207  case NAGIOS_OK:
208  status = "OK";
209  break;
210  case NAGIOS_WARNING:
211  status = "WARNING";
212  break;
213  case NAGIOS_CRITICAL:
214  status = "CRITICAL";
215  break;
216  case NAGIOS_UNKNOWN:
217  status = warnings_are_errors ? "CRITICAL" : "UNKNOWN";
218  break;
219  case NAGIOS_DEPENDENT:
220  status = "DEPENDENT";
221  break;
222  default:
223  fputs ("OMP UNKNOWN: Internal plugin error\n", stdout);
224  return code;
225  }
226 
227  va_start (arg_ptr, format);
228  buf = g_strdup_vprintf (format, arg_ptr);
229  va_end (arg_ptr);
230  printf ("OMP %s: ", status);
231  print_respond_string (buf);
232  if (!*buf || buf[strlen (buf) - 1] != '\n')
233  putchar ('\n');
234  g_free (buf);
235  return code;
236 }
237 
238 
239 /* Print more response lines. This function does not allow to print
240  performance data. */
241 static void
242 respond_data (const char *format, ...)
243 {
244  va_list arg_ptr;
245  char *buf;
246 
247  va_start (arg_ptr, format);
248  buf = g_strdup_vprintf (format, arg_ptr);
249  va_end (arg_ptr);
250  print_respond_string (buf);
251  if (!*buf || buf[strlen (buf) - 1] != '\n')
252  putchar ('\n');
253  g_free (buf);
254 }
255 
256 /* Print performance data. */
257 static void
258 respond_perf_data (const char *format, ...)
259 {
260  va_list arg_ptr;
261  char *buf;
262 
263  if (pipe_symbol_substituted)
264  fputs ("Note: pipe symbol(s) (U+007C) substituted"
265  " by broken bar (U+00A6).\n", stdout);
266 
267  va_start (arg_ptr, format);
268  buf = g_strdup_vprintf (format, arg_ptr);
269  va_end (arg_ptr);
270  g_print ("%s", buf);
271  if (!*buf || buf[strlen (buf) - 1] != '\n')
272  putchar ('\n');
273  g_free (buf);
274 }
275 
276 static void
277 do_exit (int rc)
278 {
279  if (warnings_are_errors && rc == NAGIOS_UNKNOWN)
280  rc = NAGIOS_CRITICAL;
281  exit (rc);
282 }
283 
284 
285 
286 
287 
288 /* Connection handling. */
289 
302 static gboolean
303 manager_open (server_connection_t * connection)
304 {
305  connection->socket =
306  openvas_server_open (&connection->session, connection->host_string,
307  connection->port);
308 
309  if (connection->socket == -1)
310  {
311  do_exit (respond (NAGIOS_UNKNOWN, "Failed to acquire socket.\n"));
312  }
313 
314  if (connection->username && connection->password)
315  {
316  omp_authenticate_info_opts_t authenticate_opts;
317  gchar *timezone, *role, *severity, *pw_warning;
318 
319  authenticate_opts = omp_authenticate_info_opts_defaults;
320 
321  authenticate_opts.timeout = connection->timeout;
322  authenticate_opts.username = connection->username;
323  authenticate_opts.password = connection->password;
324  authenticate_opts.timezone = &timezone;
325  authenticate_opts.role = &role;
326  authenticate_opts.severity = &severity;
327  authenticate_opts.pw_warning = &pw_warning;
328 
329  switch (omp_authenticate_info_ext (&connection->session,
330  authenticate_opts))
331  {
332  case 0:
333  break;
334  case 3:
335  openvas_server_close (connection->socket, connection->session);
336  do_exit (respond (NAGIOS_UNKNOWN,
337  "Timeout while trying to authenticate.\n"));
338  break;
339  default:
340  openvas_server_close (connection->socket, connection->session);
341  do_exit (respond (NAGIOS_UNKNOWN, "Failed to authenticate.\n"));
342  break;
343  }
344 
345  /* We currently have no need for the extra info, so free it. */
346  g_free (*authenticate_opts.timezone);
347  g_free (*authenticate_opts.role);
348  g_free (*authenticate_opts.severity);
349  g_free (*authenticate_opts.pw_warning);
350  }
351 
352  return TRUE;
353 }
354 
360 static int
361 manager_close (server_connection_t * server)
362 {
363  return openvas_server_close (server->socket, server->session);
364 }
365 
366 
367 #define STATUS_BY_TREND 1
368 #define STATUS_BY_LAST_REPORT 2
369 
370 static int
371 filter_report (entity_t report, const char *host_filter,
372  cmd_status_opts_t status_opts)
373 {
374  entity_t results;
375  entities_t elems;
376  entity_t elem;
377  entity_t errors;
378  int any_found = 0;
379  int high_count = 0;
380  int medium_count = 0;
381  int low_count = 0;
382  int log_count = 0;
383  int error_count = 0;
384  int response_code = NAGIOS_OK;
385  GPtrArray *high_oids = NULL;
386  GPtrArray *medium_oids = NULL;
387  GPtrArray *low_oids = NULL;
388  GPtrArray *log_oids = NULL;
389  GPtrArray *high_names = NULL;
390  GPtrArray *medium_names = NULL;
391  GPtrArray *low_names = NULL;
392  GPtrArray *log_names = NULL;
393  GPtrArray *high_descriptions = NULL;
394  GPtrArray *medium_descriptions = NULL;
395  GPtrArray *low_descriptions = NULL;
396  GPtrArray *log_descriptions = NULL;
397  GPtrArray *high_dfn_ids_array = NULL;
398  GPtrArray *medium_dfn_ids_array = NULL;
399  GPtrArray *low_dfn_ids_array = NULL;
400  GPtrArray *log_dfn_ids_array = NULL;
401  GPtrArray *high_dfn_ids = NULL;
402  GPtrArray *medium_dfn_ids = NULL;
403  GPtrArray *low_dfn_ids = NULL;
404  GPtrArray *log_dfn_ids = NULL;
405 
406  results = entity_child (report, "results");
407  if (results == NULL)
408  {
409  return respond (NAGIOS_UNKNOWN, "Failed to get results list.\n");
410  }
411 
412  if (status_opts.oids)
413  {
414  high_oids = g_ptr_array_new ();
415  medium_oids = g_ptr_array_new ();
416  low_oids = g_ptr_array_new ();
417  log_oids = g_ptr_array_new ();
418  high_names = g_ptr_array_new ();
419  medium_names = g_ptr_array_new ();
420  low_names = g_ptr_array_new ();
421  log_names = g_ptr_array_new ();
422  high_descriptions = g_ptr_array_new ();
423  medium_descriptions = g_ptr_array_new ();
424  low_descriptions = g_ptr_array_new ();
425  log_descriptions = g_ptr_array_new ();
426  high_dfn_ids = g_ptr_array_new ();
427  medium_dfn_ids = g_ptr_array_new ();
428  low_dfn_ids = g_ptr_array_new ();
429  log_dfn_ids = g_ptr_array_new ();
430  }
431  else
432  {
433  /* Init to quiet compiler. */
434  high_oids = medium_oids = low_oids = log_oids = NULL;
435  high_names = medium_names = low_names = log_names = NULL;
436  high_descriptions = medium_descriptions = NULL;
437  low_descriptions = log_descriptions = NULL;
438  }
439 
440  elems = results->entities;
441  while ((elem = first_entity (elems)))
442  {
443  if (strcmp (entity_name (elem), "result") == 0)
444  {
445  entity_t entity;
446  const char *host, *threat;
447 
448  entity = entity_child (elem, "host");
449  if (entity == NULL)
450  {
451  return respond (NAGIOS_UNKNOWN,
452  "Failed to parse result host.\n");
453  }
454  host = entity_text (entity);
455 
456  /* Seeking to the right task... */
457  if (host_filter != NULL)
458  if (strcmp (host, host_filter))
459  goto skip_one_filter_report;
460  any_found = 1;
461 
462  entity = entity_child (elem, "threat");
463  if (entity == NULL)
464  {
465  return respond (NAGIOS_UNKNOWN,
466  "Failed to parse result threat.\n");
467  }
468  threat = entity_text (entity);
469  if (!strcmp (threat, "High"))
470  {
471  high_count += 1;
472  if (status_opts.oids)
473  {
474  g_ptr_array_add (high_oids,
475  (gpointer)
476  entity_attribute (entity_child (elem, "nvt"),
477  "oid"));
478  g_ptr_array_add (high_names,
479  (gpointer)
480  entity_text (entity_child (entity_child (elem, "nvt"), "name")));
481  g_ptr_array_add (high_descriptions,
482  (gpointer)
483  entity_text (entity_child (elem, "description")));
484  if (status_opts.dfn_ids) {
485  high_dfn_ids_array = NULL;
486  entity_t cert_entity = entity_child (entity_child (elem, "nvt"), "cert");
487  entities_t cert_refs = cert_entity->entities;
488  if (cert_refs != NULL)
489  {
490  entity_t cert_ref;
491  while ((cert_ref = first_entity(cert_refs))) {
492  if (strcmp (entity_attribute (cert_ref, "type"), "DFN-CERT") == 0)
493  {
494  if (high_dfn_ids_array == NULL)
495  high_dfn_ids_array = g_ptr_array_new ();
496  g_ptr_array_add (high_dfn_ids_array,
497  (gpointer)
498  entity_attribute (cert_ref, "id"));
499  }
500  cert_refs = next_entities (cert_refs);
501  }
502  g_ptr_array_add (high_dfn_ids,
503  (gpointer)
504  high_dfn_ids_array);
505  }
506  else
507  {
508  g_ptr_array_add (high_dfn_ids, NULL);
509  }
510  }
511  }
512  }
513  else if (!strcmp (threat, "Medium"))
514  {
515  medium_count += 1;
516  if (status_opts.oids)
517  {
518  g_ptr_array_add (medium_oids,
519  (gpointer)
520  entity_attribute (entity_child (elem, "nvt"),
521  "oid"));
522  g_ptr_array_add (medium_names,
523  (gpointer)
524  entity_text (entity_child (entity_child (elem, "nvt"), "name")));
525  g_ptr_array_add (medium_descriptions,
526  (gpointer)
527  entity_text (entity_child (elem, "description")));
528  if (status_opts.dfn_ids) {
529  medium_dfn_ids_array = NULL;
530  entity_t cert_entity = entity_child (entity_child (elem, "nvt"), "cert");
531  entities_t cert_refs = cert_entity->entities;
532  if (cert_refs != NULL)
533  {
534  entity_t cert_ref;
535  while ((cert_ref = first_entity(cert_refs))) {
536  if (strcmp (entity_attribute (cert_ref, "type"), "DFN-CERT") == 0)
537  {
538  if (medium_dfn_ids_array == NULL)
539  medium_dfn_ids_array = g_ptr_array_new ();
540  g_ptr_array_add (medium_dfn_ids_array,
541  (gpointer)
542  entity_attribute (cert_ref, "id"));
543  }
544  cert_refs = next_entities (cert_refs);
545  }
546  g_ptr_array_add (medium_dfn_ids,
547  (gpointer)
548  medium_dfn_ids_array);
549  }
550  else
551  {
552  g_ptr_array_add (medium_dfn_ids, NULL);
553  }
554  }
555  }
556  }
557  else if (!strcmp (threat, "Low"))
558  {
559  low_count += 1;
560  if (status_opts.oids)
561  {
562  g_ptr_array_add (low_oids,
563  (gpointer)
564  entity_attribute (entity_child (elem, "nvt"),
565  "oid"));
566  g_ptr_array_add (low_names,
567  (gpointer)
568  entity_text (entity_child (entity_child (elem, "nvt"), "name")));
569  g_ptr_array_add (low_descriptions,
570  (gpointer)
571  entity_text (entity_child (elem, "description")));
572  if (status_opts.dfn_ids) {
573  low_dfn_ids_array = NULL;
574  entity_t cert_entity = entity_child (entity_child (elem, "nvt"), "cert");
575  entities_t cert_refs = cert_entity->entities;
576  if (cert_refs != NULL)
577  {
578  entity_t cert_ref;
579  while ((cert_ref = first_entity(cert_refs))) {
580  if (strcmp (entity_attribute (cert_ref, "type"), "DFN-CERT") == 0)
581  {
582  if (low_dfn_ids_array == NULL)
583  low_dfn_ids_array = g_ptr_array_new ();
584  g_ptr_array_add (low_dfn_ids_array,
585  (gpointer)
586  entity_attribute (cert_ref, "id"));
587  }
588  cert_refs = next_entities (cert_refs);
589  }
590  g_ptr_array_add (low_dfn_ids,
591  (gpointer)
592  low_dfn_ids_array);
593  }
594  else
595  {
596  g_ptr_array_add (low_dfn_ids, NULL);
597  }
598  }
599  }
600  }
601  else if (!strcmp (threat, "Log"))
602  {
603  log_count += 1;
604  if (status_opts.oids)
605  {
606  g_ptr_array_add (log_oids,
607  (gpointer)
608  entity_attribute (entity_child (elem, "nvt"),
609  "oid"));
610  g_ptr_array_add (log_names,
611  (gpointer)
612  entity_text (entity_child (entity_child (elem, "nvt"), "name")));
613  g_ptr_array_add (log_descriptions,
614  (gpointer)
615  entity_text (entity_child (elem, "description")));
616  if (status_opts.dfn_ids) {
617  log_dfn_ids_array = NULL;
618  entity_t cert_entity = entity_child (entity_child (elem, "nvt"), "cert");
619  entities_t cert_refs = cert_entity->entities;
620  if (cert_refs != NULL)
621  {
622  entity_t cert_ref;
623  while ((cert_ref = first_entity(cert_refs))) {
624  if (strcmp (entity_attribute (cert_ref, "type"), "DFN-CERT") == 0)
625  {
626  if (log_dfn_ids_array == NULL)
627  log_dfn_ids_array = g_ptr_array_new ();
628  g_ptr_array_add (log_dfn_ids_array,
629  (gpointer)
630  entity_attribute (cert_ref, "id"));
631  }
632  cert_refs = next_entities (cert_refs);
633  }
634  g_ptr_array_add (log_dfn_ids,
635  (gpointer)
636  log_dfn_ids_array);
637  }
638  else
639  {
640  g_ptr_array_add (log_dfn_ids, NULL);
641  }
642  }
643  }
644  }
645  else
646  {
647  return respond (NAGIOS_UNKNOWN, "Unknown result threat: %s.\n",
648  threat);
649  }
650  }
651  skip_one_filter_report:
652  elems = next_entities (elems);
653  }
654 
655  errors = entity_child (report, "errors");
656  if (errors != NULL)
657  {
658  if (host_filter)
659  {
660  entities_t error_elements;
661  entity_t error_element;
662 
663  error_elements = errors->entities;
664  while ((error_element = first_entity (error_elements)))
665  {
666  if (strcmp (entity_name (error_element), "error") == 0)
667  {
668  entity_t error_host;
669 
670  error_host = entity_child (error_element, "host");
671  if (strcmp (entity_text (error_host), host_filter) == 0)
672  error_count++;
673  }
674  error_elements = next_entities (error_elements);
675  }
676  }
677  else
678  {
679  entity_t count_child;
680  const char *error_text;
681 
682  count_child = entity_child (errors, "count");
683  error_text = entity_text (count_child);
684  error_count = atoi (error_text);
685  }
686  }
687 
688  if (high_count > 0)
689  {
690  response_code = NAGIOS_CRITICAL;
691  }
692  else if (medium_count > 0)
693  {
694  response_code = NAGIOS_WARNING;
695  }
696 
697  if ((results->entities == NULL) || (!any_found && host_filter))
698  {
699  if (status_opts.empty_as_unknown)
700  response_code = NAGIOS_UNKNOWN;
701  }
702 
703  if ((error_count > 0) && (response_code == NAGIOS_OK))
704  {
705  response_code = NAGIOS_UNKNOWN;
706  }
707 
708  respond (response_code, "%i vulnerabilities found - High: %i Medium: %i Low: %i\n",
709  (high_count + medium_count + low_count), high_count, medium_count, low_count);
710 
711  if (results->entities == NULL)
712  respond_data ("Report did not contain any vulnerabilities");
713  else if (!any_found && host_filter)
714  respond_data ("Report did not contain vulnerabilities for IP %s\n", host_filter);
715 
716  if (error_count > 0)
717  {
718  if (host_filter)
719  {
720  respond_data ("Report did contain %i errors for IP %s\n", error_count, host_filter);
721  }
722  else
723  {
724  respond_data ("Report did contain %i errors\n", error_count);
725  }
726  }
727 
728  if (status_opts.report_link)
729  respond_data ("https://%s/omp?cmd=get_report&report_id=%s\n",
730  (gchar *) status_opts.manager_host, entity_attribute (report,
731  "id"));
732 
733  if (status_opts.oids)
734  {
735  int i;
736  unsigned int j;
737  for (i = 0; i < high_count; i++)
738  {
739  respond_data ("NVT: %s (High) (%s)\n",
740  (char *) g_ptr_array_index (high_oids, i),
741  (char *) g_ptr_array_index (high_names, i));
742  if (status_opts.descr)
743  respond_data ("DESCR: %s\n",
744  (char *) g_ptr_array_index (high_descriptions, i));
745  if (status_opts.dfn_ids && (g_ptr_array_index (high_dfn_ids, i) != NULL))
746  {
747  GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (high_dfn_ids, i);
748  GString *dfn_ids_string = NULL;
749  for (j = 0; j < dfn_ids_array->len; j++)
750  {
751  if (dfn_ids_string == NULL)
752  {
753  dfn_ids_string = g_string_new ((char *) g_ptr_array_index (dfn_ids_array, j));
754  }
755  else
756  {
757  g_string_append (dfn_ids_string, (char *) g_ptr_array_index (dfn_ids_array, j));
758  }
759  if (j < dfn_ids_array->len - 1)
760  {
761  g_string_append (dfn_ids_string, ", ");
762  }
763  }
764  respond_data ("DFN-CERT: %s\n", dfn_ids_string->str);
765  g_string_free (dfn_ids_string, FALSE);
766  }
767  }
768 
769  for (i = 0; i < medium_count; i++)
770  {
771  respond_data ("NVT: %s (Medium) (%s)\n",
772  (char *) g_ptr_array_index (medium_oids, i),
773  (char *) g_ptr_array_index (medium_names, i));
774  if (status_opts.descr)
775  respond_data ("DESCR: %s\n",
776  (char *) g_ptr_array_index (medium_descriptions, i));
777  if (status_opts.dfn_ids && (g_ptr_array_index (medium_dfn_ids, i) != NULL))
778  {
779  GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (medium_dfn_ids, i);
780  GString *dfn_ids_string = NULL;
781  for (j = 0; j < dfn_ids_array->len; j++)
782  {
783  if (dfn_ids_string == NULL)
784  {
785  dfn_ids_string = g_string_new ((char *) g_ptr_array_index (dfn_ids_array, j));
786  }
787  else
788  {
789  g_string_append (dfn_ids_string, (char *) g_ptr_array_index (dfn_ids_array, j));
790  }
791  if (j < dfn_ids_array->len - 1)
792  {
793  g_string_append (dfn_ids_string, ", ");
794  }
795  }
796  respond_data ("DFN-CERT: %s\n", dfn_ids_string->str);
797  g_string_free (dfn_ids_string, FALSE);
798  }
799  }
800 
801  for (i = 0; i < low_count; i++)
802  {
803  respond_data ("NVT: %s (Low) (%s)\n",
804  (char *) g_ptr_array_index (low_oids, i),
805  (char *) g_ptr_array_index (low_names, i));
806  if (status_opts.descr)
807  respond_data ("DESCR: %s\n",
808  (char *) g_ptr_array_index (low_descriptions, i));
809  if (status_opts.dfn_ids && (g_ptr_array_index (low_dfn_ids, i) != NULL))
810  {
811  GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (low_dfn_ids, i);
812  GString *dfn_ids_string = NULL;
813  for (j = 0; j < dfn_ids_array->len; j++)
814  {
815  if (dfn_ids_string == NULL)
816  {
817  dfn_ids_string = g_string_new ((char *) g_ptr_array_index (dfn_ids_array, j));
818  }
819  else
820  {
821  g_string_append (dfn_ids_string, (char *) g_ptr_array_index (dfn_ids_array, j));
822  }
823  if (j < dfn_ids_array->len - 1)
824  {
825  g_string_append (dfn_ids_string, ", ");
826  }
827  }
828  respond_data ("DFN-CERT: %s\n", dfn_ids_string->str);
829  g_string_free (dfn_ids_string, FALSE);
830  }
831  }
832 
833  if (status_opts.log_messages)
834  for (i = 0; i < log_count; i++)
835  {
836  respond_data ("NVT: %s (Log) (%s)\n",
837  (char *) g_ptr_array_index (log_oids, i),
838  (char *) g_ptr_array_index (log_names, i));
839  if (status_opts.descr)
840  respond_data ("DESCR: %s\n",
841  (char *) g_ptr_array_index (log_descriptions, i));
842  if (status_opts.dfn_ids && (g_ptr_array_index (log_dfn_ids, i) != NULL))
843  {
844  GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (log_dfn_ids, i);
845  GString *dfn_ids_string = NULL;
846  for (j = 0; j < dfn_ids_array->len; j++)
847  {
848  if (dfn_ids_string == NULL)
849  {
850  dfn_ids_string = g_string_new ((char *) g_ptr_array_index (dfn_ids_array, j));
851  }
852  else
853  {
854  g_string_append (dfn_ids_string, (char *) g_ptr_array_index (dfn_ids_array, j));
855  }
856  if (j < dfn_ids_array->len - 1)
857  {
858  g_string_append (dfn_ids_string, ", ");
859  }
860  }
861  respond_data ("DFN-CERT: %s\n", dfn_ids_string->str);
862  g_string_free (dfn_ids_string, FALSE);
863  }
864  }
865 
866  g_ptr_array_free (high_oids, TRUE);
867  g_ptr_array_free (medium_oids, TRUE);
868  g_ptr_array_free (low_oids, TRUE);
869  g_ptr_array_free (log_oids, TRUE);
870  g_ptr_array_free (high_names, TRUE);
871  g_ptr_array_free (medium_names, TRUE);
872  g_ptr_array_free (low_names, TRUE);
873  g_ptr_array_free (log_names, TRUE);
874  g_ptr_array_free (high_descriptions, TRUE);
875  g_ptr_array_free (medium_descriptions, TRUE);
876  g_ptr_array_free (low_descriptions, TRUE);
877  g_ptr_array_free (log_descriptions, TRUE);
878  g_ptr_array_free (high_dfn_ids, TRUE);
879  g_ptr_array_free (medium_dfn_ids, TRUE);
880  g_ptr_array_free (low_dfn_ids, TRUE);
881  g_ptr_array_free (log_dfn_ids, TRUE);
882  }
883 
884  if (status_opts.scan_end)
885  respond_data ("SCAN_END: %s\n", entity_text (entity_child (report, "scan_end")));
886 
887  respond_perf_data ("|High=%i Medium=%i Low=%i\n",
888  high_count, medium_count, low_count);
889  return response_code;
890 }
891 
892 /* If host_filter is not NULL, mode must be STATUS_BY_LAST_REPORT and
893  host_filter is a string specifying for which IP the last results
894  are returned.
895  It is assumed that the "tasks" only contains a single task with the
896  name "task_filter" or no task at all.
897 */
898 static int
899 cmd_status_impl (server_connection_t * connection, const char *task_filter,
900  entities_t tasks, int mode, char *host_filter,
901  cmd_status_opts_t status_opts)
902 {
903  entity_t task;
904  while ((task = first_entity (tasks)))
905  {
906  if (strcmp (entity_name (task), "task") == 0)
907  {
908  entity_t entity, report;
909 
910  /* FIXME: Check status (Done vs Requested) */
911 
912  if (mode == STATUS_BY_TREND)
913  {
914  const char *trend;
915  entity = entity_child (task, "trend");
916  if (entity == NULL)
917  return respond (NAGIOS_UNKNOWN,
918  "Failed to parse task trend.\n");
919 
920  trend = entity_text (entity);
921 
922  if (!strcmp (trend, "up") || !strcmp (trend, "more"))
923  {
924  return respond (NAGIOS_CRITICAL, "Trend is %s\n", trend);
925  }
926  else if (!strcmp (trend, "down") || !strcmp (trend, "same")
927  || !strcmp (trend, "less"))
928  {
929  return respond (NAGIOS_OK, "Trend is %s\n", trend);
930  }
931  else if (!strcmp (trend, ""))
932  {
933  return respond (NAGIOS_UNKNOWN, "Trend is not available\n");
934  }
935  else
936  {
937  return (respond (NAGIOS_UNKNOWN, "Trend is unknown: %s\n", trend));
938  }
939  }
940  else
941  {
942  /* STATUS_BY_LAST_REPORT */
943  entity_t full_report;
944  omp_get_report_opts_t opts = omp_get_report_opts_defaults;
945 
946  report = entity_child (task, "last_report");
947  if (report == NULL)
948  return respond (NAGIOS_UNKNOWN, "Report is not available\n");
949 
950  report = entity_child (report, "report");
951  if (report == NULL)
952  return respond (NAGIOS_UNKNOWN,
953  "Failed to parse last_report\n");
954 
955  opts.report_id = entity_attribute (report, "id");
956  if (opts.report_id == NULL)
957  {
958  return respond (NAGIOS_UNKNOWN,
959  "Failed to parse last_report's "
960  "report ID.\n");
961  }
962 
963  opts.apply_overrides = overrides_flag;
964  opts.autofp = status_opts.autofp;
965  opts.timeout = status_opts.timeout;
966 
967  switch (omp_get_report_ext (&(connection->session), opts, &full_report))
968  {
969  case 0:
970  break;
971  case 2:
972  return respond (NAGIOS_UNKNOWN,
973  "Timeout while getting full report.\n");
974  default:
975  return respond (NAGIOS_UNKNOWN,
976  "Failed to get full report.\n");
977  }
978 
979  full_report = entity_child (full_report, "report");
980  if (full_report == NULL)
981  return respond (NAGIOS_UNKNOWN,
982  "Failed to get first full report wrapper\n");
983 
984  full_report = entity_child (full_report, "report");
985  if (full_report == NULL)
986  return respond (NAGIOS_UNKNOWN,
987  "Failed to get first full report\n");
988 
989  return filter_report (full_report, host_filter, status_opts);
990 
991  /* FIXME: Maybe add check here if the report is too
992  old? */
993  }
994 
995  /* Never reached. */
996  return respond (NAGIOS_UNKNOWN, "Internal error\n");
997  }
998  tasks = next_entities (tasks);
999  }
1000 
1001  return respond (NAGIOS_UNKNOWN, "Unknown task: %s\n", task_filter);
1002 }
1003 
1004 
1005 /* Entry point. */
1006 
1007 int
1008 main (int argc, char **argv)
1009 {
1010  server_connection_t *connection = NULL;
1011  /* The return status of the command. */
1012  int exit_status = -1;
1013 
1014  /* Global options. */
1015  static gboolean print_version = FALSE;
1016  static gboolean be_verbose = FALSE;
1017  static gchar *manager_host_string = NULL;
1018  static gint manager_port = OPENVASMD_PORT;
1019  static gchar *omp_username = NULL;
1020  static gchar *omp_password = NULL;
1021  /* Command get-omp-version. */
1022  static gboolean cmd_ping = FALSE;
1023  static gint timeout = DEFAULT_SOCKET_TIMEOUT;
1024  static gboolean cmd_status = FALSE;
1025  static gboolean status_trend = FALSE;
1026  static gboolean status_last_report = FALSE;
1027  static gchar *task_string = NULL;
1028  static gchar *host_filter = NULL;
1029  static gboolean connection_details = FALSE;
1030  static gboolean report_link = FALSE;
1031  static gboolean display_dfn_ids = FALSE;
1032  static gboolean display_oids = FALSE;
1033  static gboolean display_descriptions = FALSE;
1034  static gboolean display_log_messages = FALSE;
1035  static gboolean display_scan_end = FALSE;
1036  static guint autofp = 0;
1037  static gboolean empty_as_unknown = FALSE;
1038  static gboolean use_asset_management = FALSE;
1039  /* The rest of the args. */
1040  static gchar **rest = NULL;
1041 
1042  GError *error = NULL;
1043 
1044  GOptionContext *option_context;
1045  static GOptionEntry option_entries[] = {
1046  /* Global options. */
1047  {"host", 'H', 0, G_OPTION_ARG_STRING, &manager_host_string,
1048  "Connect to manager on host <host>", "<host>"},
1049  {"port", 'p', 0, G_OPTION_ARG_INT, &manager_port,
1050  "Use port number <number>", "<number>"},
1051  {"version", 'V', 0, G_OPTION_ARG_NONE, &print_version,
1052  "Print version.", NULL},
1053  {"verbose", 'v', 0, G_OPTION_ARG_NONE, &be_verbose,
1054  "Verbose messages (WARNING: may reveal passwords).", NULL},
1055  {"Werror", 0, 0, G_OPTION_ARG_NONE, &warnings_are_errors,
1056  "Turn status UNKNOWN into status CRITICIAL.", NULL},
1057  {"username", 'u', 0, G_OPTION_ARG_STRING, &omp_username,
1058  "OMP username", "<username>"},
1059  {"password", 'w', 0, G_OPTION_ARG_STRING, &omp_password,
1060  "OMP password", "<password>"},
1061  {"ping", 'O', 0, G_OPTION_ARG_NONE, &cmd_ping,
1062  "Ping the manager", NULL},
1063  {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout,
1064  "Wait <seconds> for response (0 disables timeout)", "<seconds>"},
1065  /* @todo "ping-timeout" remains a hidden synonym for "timout" for backward
1066  * compatibility. Can be removed for version >= 1.5.
1067  */
1068  {"ping-timeout", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &timeout,
1069  NULL, NULL},
1070  {"status", 0, 0, G_OPTION_ARG_NONE, &cmd_status,
1071  "Report status of task", NULL},
1072  {"trend", 0, 0, G_OPTION_ARG_NONE, &status_trend,
1073  "Report status by trend (default)", NULL},
1074  {"last-report", 0, 0, G_OPTION_ARG_NONE, &status_last_report,
1075  "Report status by last report", NULL},
1076  {"task", 'T', 0, G_OPTION_ARG_STRING, &task_string,
1077  "Report status of task <task>", "<task>"},
1078  {"host-filter", 'F', 0, G_OPTION_ARG_STRING, &host_filter,
1079  "Report last report status of host <ip>", "<ip>"},
1080  {"overrides", 0, 0, G_OPTION_ARG_INT, &overrides_flag,
1081  "Include overrides (N: 0=no, 1=yes)", "N"},
1082  {"details", 'd', 0, G_OPTION_ARG_NONE, &connection_details,
1083  "Include connection details in output", NULL},
1084  {"report-link", 'l', 0, G_OPTION_ARG_NONE, &report_link,
1085  "Include URL of report in output", NULL},
1086  {"dfn", 0, 0, G_OPTION_ARG_NONE, &display_dfn_ids,
1087  "Include DFN-CERT IDs on vulnerabilities in output", NULL},
1088  {"oid", 0, 0, G_OPTION_ARG_NONE, &display_oids,
1089  "Include OIDs of NVTs finding vulnerabilities in output", NULL},
1090  {"descr", 0, 0, G_OPTION_ARG_NONE, &display_descriptions,
1091  "Include descriptions of NVTs finding vulnerabilities in output", NULL},
1092  {"showlog", 0, 0, G_OPTION_ARG_NONE, &display_log_messages,
1093  "Include log messages in output", NULL},
1094  {"scanend", 0, 0, G_OPTION_ARG_NONE, &display_scan_end,
1095  "Include timestamp of scan end in output", NULL},
1096  {"autofp", 0, 0, G_OPTION_ARG_INT, &autofp,
1097  "Trust vendor security updates for automatic false positive filtering (0=No, 1=full match, 2=partial).", "<n>"},
1098  {"empty-as-unknown", 'e', 0, G_OPTION_ARG_NONE, &empty_as_unknown,
1099  "Respond with UNKNOWN on empty results", NULL},
1100  {"use-asset-management", 'A', 0, G_OPTION_ARG_NONE, &use_asset_management,
1101  "Request host status via Asset Management", NULL},
1102  {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &rest,
1103  NULL, NULL},
1104  {NULL, 0, 0, 0, NULL, NULL, NULL}
1105  };
1106 
1107  if (setlocale (LC_ALL, "") == NULL)
1108  {
1109  do_exit (respond (NAGIOS_UNKNOWN, "Failed to setlocale\n\n"));
1110  }
1111 
1112  option_context =
1113  g_option_context_new ("- OpenVAS OMP Command Line Interface");
1114  g_option_context_add_main_entries (option_context, option_entries, NULL);
1115  if (!g_option_context_parse (option_context, &argc, &argv, &error))
1116  {
1117  printf ("%s\n\n", error->message);
1118  do_exit (NAGIOS_UNKNOWN);
1119  }
1120  g_option_context_free (option_context);
1121 
1122  if (print_version)
1123  {
1124  printf ("Check-OMP Nagios Command Plugin %s\n", OPENVASCLI_VERSION);
1125  printf ("Copyright (C) 2016 Greenbone Networks GmbH\n");
1126  printf ("License GPLv2+: GNU GPL version 2 or later\n");
1127  printf
1128  ("This is free software: you are free to change and redistribute it.\n"
1129  "There is NO WARRANTY, to the extent permitted by law.\n\n");
1130  do_exit (EXIT_SUCCESS);
1131  }
1132 
1133  /* Check that one and at most one command option is present. */
1134  {
1135  int commands;
1136  commands = (int) cmd_ping + (int) cmd_status;
1137  if (commands == 0)
1138  {
1139  respond (NAGIOS_UNKNOWN, "One command option must be present.\n");
1140  do_exit (NAGIOS_UNKNOWN);
1141  }
1142  if (commands > 1)
1143  {
1144  respond (NAGIOS_UNKNOWN, "Only one command option must be present.\n");
1145  do_exit (NAGIOS_UNKNOWN);
1146  }
1147  }
1148 
1149  /* Set defaults. */
1150  if (!status_trend && !status_last_report)
1151  status_trend = TRUE;
1152  if (status_trend && status_last_report)
1153  {
1154  respond (NAGIOS_UNKNOWN, "--trend and --last-report are exclusive.\n");
1155  do_exit (NAGIOS_UNKNOWN);
1156  }
1157 
1158 
1159  /* Setup the connection structure. */
1160  connection = g_malloc0 (sizeof (*connection));
1161 
1162  if (manager_host_string != NULL)
1163  connection->host_string = manager_host_string;
1164  else
1165  connection->host_string = OPENVASMD_ADDRESS;
1166 
1167  if (manager_port <= 0 || manager_port >= 65536)
1168  {
1169  respond (NAGIOS_UNKNOWN,
1170  "Manager port must be a number between 0 and 65536.\n");
1171  do_exit (NAGIOS_UNKNOWN);
1172  }
1173 
1174  connection->port = manager_port;
1175 
1176  if (omp_username != NULL)
1177  connection->username = omp_username;
1178  if (omp_password != NULL)
1179  connection->password = omp_password;
1180 
1181  if (timeout < 0)
1182  {
1183  respond (NAGIOS_UNKNOWN,
1184  "Timeout must be a non-negative number.\n");
1185  do_exit (NAGIOS_UNKNOWN);
1186  }
1187 
1188  connection->timeout = timeout;
1189 
1190  if (be_verbose)
1191  {
1193  fprintf (stderr, "Will try to connect to host %s, port %d...\n",
1194  connection->host_string, connection->port);
1195  }
1196  else
1197  {
1198 #ifndef _WIN32
1199  g_log_set_default_handler (openvas_log_silent, NULL);
1200 #endif
1201  }
1202 
1203  /* Run the single command. */
1204 
1205  if (cmd_ping)
1206  {
1207  int res;
1208  manager_open (connection);
1209  /* Returns 0 on success, 1 if manager closed connection, 2 on
1210  timeout, -1 on error */
1211  res = omp_ping (&(connection->session), connection->timeout);
1212  if (res == 0)
1213  {
1214  exit_status = respond (NAGIOS_OK, "Alive and kicking!\n");
1215  }
1216  else if (res == 1)
1217  {
1218  exit_status = respond (NAGIOS_CRITICAL, "Connection closed\n");
1219  }
1220  else if (res == 2)
1221  {
1222  exit_status = respond (NAGIOS_CRITICAL, "Connection timed out\n");
1223  }
1224  else
1225  {
1226  exit_status = respond (NAGIOS_CRITICAL, "Unknown error\n");
1227  }
1228  manager_close (connection);
1229  }
1230  else if (cmd_status)
1231  {
1232  entity_t status;
1233 
1234  if (use_asset_management)
1235  {
1236  if (host_filter == NULL)
1237  {
1238  exit_status =
1239  respond (NAGIOS_UNKNOWN, "Status request via Asset Management requires host filter\n");
1240  }
1241  else
1242  {
1243  entity_t asset_report;
1244  entity_t host_detail;
1245  entities_t host_details;
1246  gchar *report_id = NULL;
1247  entity_t full_report;
1248  cmd_status_opts_t status_opts;
1249 
1250  int res;
1251  int high_count = 0;
1252  int medium_count = 0;
1253  int low_count = 0;
1254 
1255  omp_get_report_opts_t asset_opts = omp_get_report_opts_defaults;
1256  omp_get_report_opts_t report_opts = omp_get_report_opts_defaults;
1257 
1258  asset_opts.overrides = overrides_flag;
1259  asset_opts.autofp = autofp;
1260  asset_opts.timeout = timeout;
1261  asset_opts.type = "assets";
1262  asset_opts.host = host_filter;
1263 
1264  manager_open (connection);
1265  res = omp_get_report_ext (&(connection->session), asset_opts, &asset_report);
1266  if (res == 0)
1267  {
1268  asset_report = entity_child (asset_report, "report");
1269  if (asset_report == NULL)
1270  {
1271  exit_status = respond (NAGIOS_UNKNOWN, "Failed to get first asset report wrapper\n");
1272  }
1273  else
1274  {
1275  asset_report = entity_child (asset_report, "report");
1276  if (asset_report == NULL)
1277  {
1278  exit_status = respond (NAGIOS_UNKNOWN, "Failed to get first asset report\n");
1279  }
1280  else
1281  {
1282  asset_report = entity_child (asset_report, "host");
1283  if (asset_report == NULL)
1284  {
1285  exit_status = respond (NAGIOS_UNKNOWN, "Failed to get asset host element\n");
1286  }
1287  else
1288  {
1289  host_details = asset_report->entities;
1290  while ((host_detail = first_entity (host_details)))
1291  {
1292  if (strcmp (entity_name (host_detail), "detail") == 0)
1293  {
1294  entity_t name;
1295  entity_t value;
1296 
1297  name = entity_child (host_detail, "name");
1298  value = entity_child (host_detail, "value");
1299 
1300  if (strcmp (entity_text (name), "report/@id") == 0)
1301  report_id = g_strdup (entity_text (value));
1302  if (strcmp (entity_text (name), "report/result_count/high") == 0)
1303  high_count = atoi (entity_text (value));
1304  if (strcmp (entity_text (name), "report/result_count/medium") == 0)
1305  medium_count = atoi (entity_text (value));
1306  if (strcmp (entity_text (name), "report/result_count/low") == 0)
1307  low_count = atoi (entity_text (value));
1308  }
1309  host_details = next_entities (host_details);
1310  }
1311 
1312  if (report_id == NULL)
1313  {
1314  exit_status = respond (NAGIOS_UNKNOWN, "Failed to get report_id via Asset Management\n");
1315  }
1316  else
1317  {
1318  if ((high_count + medium_count) == 0)
1319  {
1320  int response_code = NAGIOS_OK;
1321  exit_status = respond (response_code,
1322  "%i vulnerabilities found - High: 0 Medium: 0 Low: %i\n",
1323  low_count, low_count);
1324 
1325  if (report_link)
1326  respond_data ("https://%s/omp?cmd=get_report&report_id=%s\n",
1327  (gchar *) (gpointer) connection->host_string, report_id);
1328 
1329  if (display_scan_end)
1330  respond_data ("SCAN_END: %s\n", entity_text (entity_child (asset_report, "end")));
1331 
1332  respond_perf_data ("|High=%i Medium=%i Low=%i\n",
1333  high_count, medium_count, low_count);
1334  }
1335  else
1336  {
1337  report_opts.report_id = report_id;
1338 
1339  status_opts.report_link = report_link;
1340  status_opts.dfn_ids = display_dfn_ids;
1341  status_opts.oids = display_oids;
1342  status_opts.manager_host = (gpointer) connection->host_string;
1343  status_opts.descr = display_descriptions;
1344  status_opts.log_messages = display_log_messages;
1345  status_opts.scan_end = display_scan_end;
1346  status_opts.autofp = autofp;
1347  status_opts.timeout = timeout;
1348  status_opts.empty_as_unknown = empty_as_unknown;
1349 
1350  report_opts.apply_overrides = overrides_flag;
1351  report_opts.autofp = status_opts.autofp;
1352  report_opts.timeout = status_opts.timeout;
1353 
1354  if (!display_log_messages)
1355  report_opts.levels = "hml";
1356 
1357  res = omp_get_report_ext (&(connection->session), report_opts, &full_report);
1358  if (res == 0)
1359  {
1360  full_report = entity_child (full_report, "report");
1361  if (full_report == NULL)
1362  {
1363  exit_status = respond (NAGIOS_UNKNOWN,
1364  "Failed to get first full report wrapper\n");
1365  }
1366  else
1367  {
1368  full_report = entity_child (full_report, "report");
1369  if (full_report == NULL)
1370  {
1371  exit_status = respond (NAGIOS_UNKNOWN,
1372  "Failed to get first full report\n");
1373  }
1374  else
1375  {
1376 
1377  exit_status = filter_report (full_report, host_filter, status_opts);
1378  }
1379  }
1380  }
1381  else if (res == 2)
1382  {
1383  exit_status = respond (NAGIOS_UNKNOWN,
1384  "Timeout while getting full report.\n");
1385  }
1386  else
1387  {
1388  exit_status = respond (NAGIOS_UNKNOWN,
1389  "Failed to get full report.\n");
1390  }
1391  }
1392  }
1393  }
1394  }
1395  }
1396  }
1397  else if (res == 2)
1398  {
1399  exit_status = respond (NAGIOS_UNKNOWN, "Timeout while getting asset report.\n");
1400  }
1401  else
1402  {
1403  exit_status = respond (NAGIOS_UNKNOWN, "Failed to get asset report.\n");
1404  }
1405  }
1406  }
1407  else if (task_string == NULL)
1408  {
1409  exit_status =
1410  respond (NAGIOS_UNKNOWN, "Status request requires task name\n");
1411  }
1412  else
1413  {
1414  manager_open (connection);
1415  omp_get_tasks_opts_t opts;
1416  cmd_status_opts_t status_opts;
1417 
1418  opts = omp_get_tasks_opts_defaults;
1419  opts.details = 1;
1420  /* TODO: Needs to be free'd at some point */
1421  opts.filter = g_strdup_printf ("permission=any owner=any rows=1 name=\"%s\"", task_string);
1422  opts.timeout = timeout;
1423 
1424  if (display_descriptions)
1425  display_oids = TRUE;
1426 
1427  if (display_dfn_ids)
1428  display_oids = TRUE;
1429 
1430  status_opts.report_link = report_link;
1431  status_opts.dfn_ids = display_dfn_ids;
1432  status_opts.oids = display_oids;
1433  status_opts.manager_host = (gpointer) connection->host_string;
1434  status_opts.descr = display_descriptions;
1435  status_opts.log_messages = display_log_messages;
1436  status_opts.scan_end = display_scan_end;
1437  status_opts.autofp = autofp;
1438  status_opts.timeout = timeout;
1439  status_opts.empty_as_unknown = empty_as_unknown;
1440 
1441  /* Returns 0 on success, 2 on timeout, -1 or OMP code on error. */
1442  switch (omp_get_tasks_ext (&(connection->session), opts, &status))
1443  {
1444  case 0:
1445  exit_status =
1446  cmd_status_impl (connection, task_string, status->entities,
1447  status_trend ? STATUS_BY_TREND :
1448  STATUS_BY_LAST_REPORT, host_filter,
1449  status_opts);
1450  break;
1451  case 2:
1452  exit_status = respond (NAGIOS_UNKNOWN, "Timeout while getting tasks\n");
1453  break;
1454  default:
1455  exit_status = respond (NAGIOS_UNKNOWN, "Get tasks failed\n");
1456  break;
1457  }
1458 
1459  manager_close (connection);
1460  }
1461  }
1462  else
1463  /* The option processing ensures that at least one command is present. */
1464  assert (0);
1465 
1466  /* Exit. */
1467 
1468  if (connection_details)
1469  {
1470  if (connection->host_string)
1471  respond_data ("GSM_Host: %s:%d\n", connection->host_string,
1472  (int) connection->port);
1473  if (connection->username)
1474  respond_data ("OMP_User: %s\n", connection->username);
1475  if (task_string && cmd_status)
1476  respond_data ("Task: %s\n", task_string);
1477  }
1478 
1479  if (be_verbose)
1480  {
1481  if (exit_status != NAGIOS_OK)
1482  respond_data ("Command failed.\n");
1483  else
1484  respond_data ("Command completed successfully.\n");
1485  }
1486 
1487  do_exit (exit_status);
1488 }
gpointer manager_host
Pointer to name of the manager host for use in the report link.
Definition: check_omp.c:145
#define NAGIOS_WARNING
The plugin was able to contact the OpenVAS Manager. The returned results did indicate a medium threat...
Definition: check_omp.c:102
gchar * password
Password for user with which to connect.
Definition: omp.c:110
#define STATUS_BY_LAST_REPORT
Definition: check_omp.c:368
#define NAGIOS_OK
The plugin was able to contact the OpenVAS Manager. The returned results did not indicate a medium or...
Definition: check_omp.c:96
#define OPENVASMD_PORT
Default Manager port.
Definition: check_omp.c:81
gboolean log_messages
TRUE if log messages should be included.
Definition: check_omp.c:146
Information needed to handle a connection to a server.
Definition: omp.c:105
gboolean report_link
TRUE if the report URL should be included.
Definition: check_omp.c:141
#define OPENVASMD_ADDRESS
Default Manager (openvasmd) address.
Definition: check_omp.c:76
Options for status display.
Definition: check_omp.c:139
gint timeout
Timeout of request.
Definition: check_omp.c:149
int socket
Socket to server.
Definition: omp.c:108
int main(int argc, char **argv)
Definition: check_omp.c:1008
gboolean descr
TRUE if NVT descriptions should be included.
Definition: check_omp.c:144
#define NAGIOS_DEPENDENT
Definition: check_omp.c:117
guint autofp
Whether to trust vendor security updates. 0 No, 1 full match, 2 partial.
Definition: check_omp.c:148
#define NAGIOS_UNKNOWN
The plugin was not able to contact the OpenVAS Manager or was unable to parse the returned results...
Definition: check_omp.c:115
gboolean oids
TRUE if NVT OIDs should be included.
Definition: check_omp.c:143
gchar * username
Username with which to connect.
Definition: omp.c:109
gnutls_session_t session
GnuTLS Session to use.
Definition: omp.c:107
gint port
Port of server.
Definition: omp.c:113
gchar * host_string
Server host string.
Definition: omp.c:111
#define DEFAULT_SOCKET_TIMEOUT
Definition: check_omp.c:84
#define STATUS_BY_TREND
Definition: check_omp.c:367
gint timeout
Timeout of request.
Definition: omp.c:118
gboolean dfn_ids
TRUE if DFN-CERT-IDs should be included.
Definition: check_omp.c:142
#define NAGIOS_CRITICAL
The plugin was able to contact the OpenVAS Manager. The returned results did indicate a high threat o...
Definition: check_omp.c:108
gboolean empty_as_unknown
TRUE if empty results should produce an UNKNOWN response instead of OK.
Definition: check_omp.c:150
gboolean scan_end
TRUE if the time the scan finished should be included.
Definition: check_omp.c:147