[Openvas-commits] r9234 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 19 23:22:16 CEST 2010
Author: mattm
Date: 2010-10-19 23:22:15 +0200 (Tue, 19 Oct 2010)
New Revision: 9234
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/omp.c
Log:
* src/omp.c (check_host_netmasks): New function. From GSA
validate_hosts_parameter.
(omp_xml_handle_end_element): Check host netmasks for CREATE_TARGET,
CREATE_NOTE and CREATE_OVERRIDE.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2010-10-19 20:24:33 UTC (rev 9233)
+++ trunk/openvas-manager/ChangeLog 2010-10-19 21:22:15 UTC (rev 9234)
@@ -1,5 +1,12 @@
2010-10-19 Matthew Mundell <matthew.mundell at greenbone.net>
+ * src/omp.c (check_host_netmasks): New function. From GSA
+ validate_hosts_parameter.
+ (omp_xml_handle_end_element): Check host netmasks for CREATE_TARGET,
+ CREATE_NOTE and CREATE_OVERRIDE.
+
+2010-10-19 Matthew Mundell <matthew.mundell at greenbone.net>
+
* src/omp.c (omp_xml_handle_end_element): In CLIENT_CREATE_TARGET only
allow creation if max_hosts succeeds on the hosts value.
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2010-10-19 20:24:33 UTC (rev 9233)
+++ trunk/openvas-manager/src/omp.c 2010-10-19 21:22:15 UTC (rev 9234)
@@ -361,6 +361,46 @@
return -1;
}
+/**
+ * @brief Check the netmask sizes in a target host string.
+ *
+ * @param hosts String containing hostnames, IPs etc.
+ *
+ * @return 0 valid, 1 CIDR mask out of range.
+ */
+static int
+check_host_netmasks (const char* hosts)
+{
+ char* slashpos;
+ char* copy = g_strdup (hosts);
+ int cidr_mask = 32;
+
+ slashpos = strchr (copy, '/');
+ while (slashpos)
+ {
+ char* commapos;
+
+ commapos = strchr (slashpos, ',');
+ if (commapos != NULL)
+ commapos[0] = '\0';
+ if (slashpos[1] == '\0')
+ {
+ g_free (copy);
+ return 0;
+ }
+ cidr_mask = atoi (slashpos + 1);
+ if (cidr_mask < 20)
+ {
+ g_free (copy);
+ return 1;
+ }
+ slashpos = strchr (slashpos + 1, '/');
+ }
+
+ g_free (copy);
+ return 0;
+}
+
/* Help message. */
@@ -11258,6 +11298,14 @@
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_note",
"CREATE_NOTE requires a TEXT entity"));
+ else if (max_hosts (create_note_data->hosts) == -1)
+ SEND_TO_CLIENT_OR_FAIL
+ (XML_ERROR_SYNTAX ("create_note",
+ "Error in host specification"));
+ else if (check_host_netmasks (create_note_data->hosts))
+ SEND_TO_CLIENT_OR_FAIL
+ (XML_ERROR_SYNTAX ("create_note",
+ "Host netmasks must be at most CIDR /20"));
else if (create_note_data->task_id
&& find_task (create_note_data->task_id, &task))
SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("create_note"));
@@ -11365,6 +11413,14 @@
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_override",
"CREATE_OVERRIDE requires a TEXT entity"));
+ else if (max_hosts (create_override_data->hosts) == -1)
+ SEND_TO_CLIENT_OR_FAIL
+ (XML_ERROR_SYNTAX ("create_override",
+ "Error in host specification"));
+ else if (check_host_netmasks (create_override_data->hosts))
+ SEND_TO_CLIENT_OR_FAIL
+ (XML_ERROR_SYNTAX ("create_override",
+ "Host netmasks must be at most CIDR /20"));
else if (create_override_data->new_threat == NULL)
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_override",
@@ -12043,6 +12099,11 @@
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_target",
"Error in host specification"));
+ else if (create_target_data->target_locator == NULL
+ && check_host_netmasks (create_target_data->hosts))
+ SEND_TO_CLIENT_OR_FAIL
+ (XML_ERROR_SYNTAX ("create_target",
+ "Host netmasks must be at most CIDR /20"));
else if (strlen (create_target_data->hosts) != 0
&& create_target_data->target_locator != NULL)
SEND_TO_CLIENT_OR_FAIL
More information about the Openvas-commits
mailing list