[Openvas-commits] r2698 - in trunk/openvas-client: . src/gui src/util
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Mar 6 16:46:39 CET 2009
Author: jan
Date: 2009-03-06 16:46:37 +0100 (Fri, 06 Mar 2009)
New Revision: 2698
Modified:
trunk/openvas-client/ChangeLog
trunk/openvas-client/src/gui/priofiltermngr_dlg.c
trunk/openvas-client/src/util/priority_filter.c
trunk/openvas-client/src/util/priority_filter.h
Log:
* src/util/priority_filter.c: Added file doc string and various macros for
XML keywords.
(priority_override_new): Added parameter for directly setting the active
flag.
(write_override_xml_elem): New. Write a override object in xml format.
(priority_filter_to_xml): Added implementation.
* src/util/priority_filter.h: Updated proto for priority_override_new.
* src/gui/priofiltermngr_dlg.c (priorityfiltermanager_dialog): Use
priority_override_new with additional parameter. For testing
purposes create and read a filter xml file.
Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog 2009-03-06 14:57:45 UTC (rev 2697)
+++ trunk/openvas-client/ChangeLog 2009-03-06 15:46:37 UTC (rev 2698)
@@ -1,3 +1,18 @@
+2009-03-06 Jan-Oliver Wagner <jan-oliver.wagner at intevation.de>
+
+ * src/util/priority_filter.c: Added file doc string and various macros for
+ XML keywords.
+ (priority_override_new): Added parameter for directly setting the active
+ flag.
+ (write_override_xml_elem): New. Write a override object in xml format.
+ (priority_filter_to_xml): Added implementation.
+
+ * src/util/priority_filter.h: Updated proto for priority_override_new.
+
+ * src/gui/priofiltermngr_dlg.c (priorityfiltermanager_dialog): Use
+ priority_override_new with additional parameter. For testing
+ purposes create and read a filter xml file.
+
2009-03-06 Felix Wolfsteller <felix.wolfsteller at intevation.de>
Fixed bug: Client always attempted to send 'login to host' mapping file,
Modified: trunk/openvas-client/src/gui/priofiltermngr_dlg.c
===================================================================
--- trunk/openvas-client/src/gui/priofiltermngr_dlg.c 2009-03-06 14:57:45 UTC (rev 2697)
+++ trunk/openvas-client/src/gui/priofiltermngr_dlg.c 2009-03-06 15:46:37 UTC (rev 2698)
@@ -63,11 +63,11 @@
priority_filter_add(global_filter,
priority_override_new("PriorityOverride1",
"localhost",
- "general/tcp",
- "1.3.6.1.4.1.25623.1.0.19506",
+ "http (80/tcp)",
+ "1.3.6.1.4.1.25623.1.0.10056",
"This is just a test-override",
- "INFO",
- "FALSE"));
+ "NOTE",
+ "FALSE", FALSE));
priority_filter_add(global_filter,
priority_override_new("PriorityOverride2",
"192.168.11.35",
@@ -75,7 +75,12 @@
"1.3.6.1.4.1.25623.1.0.900505",
"This is just a test-override",
"NOTE",
- "FALSE"));
+ "FALSE", TRUE));
+
+ char * filter_file = g_build_filename (prefs_get_nessushome(), ".openvasrc", "priofilter.xml", NULL);
+ priority_filter_to_xml (global_filter, filter_file);
+ priority_filter_from_xml (filter_file);
+ g_free(filter_file);
} else {
priority_filter_free(global_filter);
global_filter = NULL;
Modified: trunk/openvas-client/src/util/priority_filter.c
===================================================================
--- trunk/openvas-client/src/util/priority_filter.c 2009-03-06 14:57:45 UTC (rev 2697)
+++ trunk/openvas-client/src/util/priority_filter.c 2009-03-06 15:46:37 UTC (rev 2698)
@@ -34,14 +34,66 @@
* wish to do so, delete this exception statement from your version.
*/
+
+/** @file
+ *
+ * Implementaiton of Priority Filters.
+ *
+ * Priority filters consist of a set of priority overrides.
+ * The data is stored in a xml file, here is a sample:
+ *
+ * @verbatim
+<priority_filter name="My priority Filter">
+ <priority_override name="PriorityOverride1"
+ host="localhost"
+ port="general/tcp"
+ OID="1.3.6.1.4.1.25623.1.0.19506"
+ prio_from="warning"
+ prio_to="FP"
+ active="true">
+ <reason>
+ This is just a test-override.
+ </reason>
+ </priority_override>
+ <priority_override name="PriorityOverride2"
+ host="localhost"
+ port="general/tcp"
+ OID="1.3.6.1.4.1.25623.1.0.19507"
+ prio_from="warning"
+ prio_to="FP"
+ active="true">
+ <reason>
+ This is just another test-override.
+ With some more reasons.
+ </reason>
+ </priority_override>
+</priority_filter>
+ at endverbatim
+*/
+
#include "priority_filter.h"
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <fcntl.h>
+#define XML_ELEM_PRIORITY_FILTER "priority_filter"
+#define XML_ELEM_PRIORITY_OVERRIDE "priority_override"
+#define XML_ELEM_REASON "reason"
+#define XML_ATTR_NAME "name"
+#define XML_ATTR_HOST "host"
+#define XML_ATTR_PORT "port"
+#define XML_ATTR_OID "OID"
+#define XML_ATTR_PRIO_FROM "prio_from"
+#define XML_ATTR_PRIO_TO "prio_to"
+#define XML_ATTR_ACTIVE "active"
+#define XML_ATTR_ACTIVE_TRUE "true"
+
/* temporary, should be part of the global context */
priority_filter_t * global_filter = NULL;
+
/**
* @brief Creates a new priority override.
*
@@ -55,7 +107,7 @@
priority_override_new (const gchar * name, const gchar * host,
const gchar * port, const gchar * oid,
const gchar * reason, const gchar * prio_from,
- const gchar * prio_to)
+ const gchar * prio_to, gboolean active)
{
if (name == NULL || host == NULL || port == NULL || oid == NULL
|| reason == NULL || prio_from == NULL || prio_to == NULL)
@@ -69,8 +121,8 @@
prio_override->reason = g_strdup(reason);
prio_override->prio_from = g_strdup(prio_from);
prio_override->prio_to = g_strdup(prio_to);
- prio_override->active = TRUE;
-
+ prio_override->active = active;
+
return prio_override;
}
@@ -93,6 +145,7 @@
g_free (override);
}
+
/**
* @brief Creates a new empty priority_filter with a name.
*
@@ -123,6 +176,7 @@
g_free(filter);
}
+
/**
* @brief Applies the global filter to the given alert.
*
@@ -140,7 +194,7 @@
* Else a string with the new priority is returned.
*/
const gchar *
-priority_filter_apply(const gchar * host, const gchar * port,
+priority_filter_apply (const gchar * host, const gchar * port,
const gchar * oid, const gchar * prio_from)
{
if (global_filter) {
@@ -154,10 +208,11 @@
o = g_slist_next(o);
}
}
-
+
return NULL;
}
+
/**
* @brief Adds a priority_override to a priority_filter.
*
@@ -175,31 +230,79 @@
{
if (filter == NULL || override == NULL) return FALSE;
- filter->overrides = g_slist_prepend(filter->overrides, (void *)override);
+ filter->overrides = g_slist_prepend (filter->overrides, (void*) override);
return TRUE;
}
+
/**
+ * @brief In a list- callback write a priority override xml-element to file.
+ *
+ * @param override The override to write an xml-element for.
+ * @param fd The file descriptor to write to.
+ */
+static void
+write_override_xml_elem (priority_override_t* override, FILE* fd)
+{
+ if (!fd) return;
+
+ fprintf (fd, "\t<priority_override name=\"%s\"\n"
+ "\t\thost=\"%s\"\n"
+ "\t\tport=\"%s\"\n"
+ "\t\tOID=\"%s\"\n"
+ "\t\tprio_from=\"%s\"\n"
+ "\t\tprio_to=\"%s\"\n"
+ "\t\tactive=\"%s\">\n",
+ override->name, override->host, override->port, override->OID,
+ override->prio_from, override->prio_to,
+ (override->active == TRUE)? "true" : "false");
+ fprintf (fd, "\t\t<reason>\n\t\t%s\n\t\t</reason>\n", override->reason);
+ fprintf (fd, "\t</priority_override>\n");
+}
+
+
+/**
* @brief Export a priority_filter to xml, so that it can be read in with
* @brief priority_filter_from_xml.
*
+ * An examplary file is included in the documentation for this file.
+ *
* @param prio_filter The priority_fiter to export.
* @param filename Filename to which to export to.
*
* @return TRUE in case the filte was successfully created, else FALSE.
*/
gboolean
-priority_filter_to_xml (const priority_filter_t * prio_filter,
+priority_filter_to_xml (const priority_filter_t * filter,
const gchar * filename)
{
- return FALSE;
+ FILE* fd;
+
+ if (filter == NULL) return FALSE;
+
+ fd = fopen (filename, "w");
+ if (fd <= 0) return FALSE;
+
+ fprintf (fd, "<priority_filter name=\"%s\">\n", filter->name);
+ g_slist_foreach (filter->overrides, (GFunc) write_override_xml_elem , fd);
+ fprintf (fd, "</priority_filter>");
+ fclose (fd);
+
+ return TRUE;
}
/**
* @brief Imports a priority_filter from an xml file that has been written by
* @brief priority_filter_to_xml.
+ *
+ * An examplary xml file is included in the documentation for this file.
+ *
+ * @param filename Path of file to parse.
+ *
+ * @return If the file exists and error while parsing occured, a fresh
+ * priority_filter as described in the file (parameter), NULL otherwise.
*/
const priority_filter_t *
priority_filter_from_xml (const gchar * filename)
Modified: trunk/openvas-client/src/util/priority_filter.h
===================================================================
--- trunk/openvas-client/src/util/priority_filter.h 2009-03-06 14:57:45 UTC (rev 2697)
+++ trunk/openvas-client/src/util/priority_filter.h 2009-03-06 15:46:37 UTC (rev 2698)
@@ -84,7 +84,7 @@
const priority_override_t * priority_override_new (const gchar *, const gchar *,
const gchar *, const gchar *, const gchar *, const gchar *,
- const gchar *);
+ const gchar *, gboolean);
void priority_override_free(priority_override_t * );
gboolean priority_filter_to_xml(const priority_filter_t *, const gchar *);
More information about the Openvas-commits
mailing list