[Openvas-commits] r13022 - in trunk/openvas-libraries: . misc
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Tue Mar 13 15:51:16 CET 2012
Author: mwiegand
Date: 2012-03-13 15:51:16 +0100 (Tue, 13 Mar 2012)
New Revision: 13022
Modified:
trunk/openvas-libraries/ChangeLog
trunk/openvas-libraries/misc/plugutils.c
Log:
* misc/plugutils.c (proto_post_wrapped): Add support for using the
scanner preferences result_prepend_tags and result_append_tags to
prepend or append tag contents to the description of a result. This is
convenience functionality in preparation for the breaking up of the
NVT description block and adding proper handling of refined meta
information all over the OpenVAS Framework.
Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog 2012-03-13 13:59:37 UTC (rev 13021)
+++ trunk/openvas-libraries/ChangeLog 2012-03-13 14:51:16 UTC (rev 13022)
@@ -1,3 +1,12 @@
+2012-03-13 Michael Wiegand <michael.wiegand at greenbone.net>
+
+ * misc/plugutils.c (proto_post_wrapped): Add support for using the
+ scanner preferences result_prepend_tags and result_append_tags to
+ prepend or append tag contents to the description of a result. This is
+ convenience functionality in preparation for the breaking up of the
+ NVT description block and adding proper handling of refined meta
+ information all over the OpenVAS Framework.
+
2012-03-12 Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
* nasl/nasl_misc_funcs.c: Added NASL_EXIT_DEPRECATED.
Modified: trunk/openvas-libraries/misc/plugutils.c
===================================================================
--- trunk/openvas-libraries/misc/plugutils.c 2012-03-13 13:59:37 UTC (rev 13021)
+++ trunk/openvas-libraries/misc/plugutils.c 2012-03-13 14:51:16 UTC (rev 13022)
@@ -529,9 +529,14 @@
{
char *buffer;
int soc;
- char *naction;
int len;
+ char *prepend_tags;
+ char *append_tags;
+ GString *action_str;
+ gchar *action_escaped;
+ GString *action_str_escaped;
nvti_t * nvti = arg_get_value (desc, "NVTI");
+ gchar **nvti_tags = NULL;
if (action == NULL)
action = nvti_description (nvti);
@@ -539,20 +544,104 @@
if (action == NULL)
return;
- len = strlen (action) + 1;
+ action_str = g_string_new (action);
- naction = emalloc (len + 1);
- strncpy (naction, action, strlen (action));
- strcat (naction, "\n");
+ prepend_tags = get_preference (desc, "result_prepend_tags");
+ append_tags = get_preference (desc, "result_append_tags");
- {
- char *old = naction;
- len -= strlen (naction);
- naction = addslashes (naction);
- len += strlen (naction);
- efree (&old);
- }
+ if (prepend_tags || append_tags)
+ {
+ nvti_tags = g_strsplit (nvti_tag (nvti), "|", 0);
+ }
+ /* This is convenience functionality in preparation for the breaking up of the
+ * NVT description block and adding proper handling of refined meta
+ * information all over the OpenVAS Framework.
+ */
+ if (nvti_tags != NULL)
+ {
+ if (prepend_tags != NULL)
+ {
+ gchar **tags = g_strsplit (prepend_tags, ",", 0);
+ int i = 0;
+ gchar *tag_prefix;
+ gchar *tag_value;
+ while (tags[i] != NULL)
+ {
+ int j = 0;
+ tag_value = NULL;
+ tag_prefix = g_strconcat (tags[i], "=", NULL);
+ while (nvti_tags[j] != NULL && tag_value == NULL)
+ {
+ if (g_str_has_prefix (nvti_tags[j], tag_prefix))
+ {
+ tag_value = g_strstr_len (nvti_tags[j], -1, "=");
+ }
+ j++;
+ }
+ g_free (tag_prefix);
+
+ if (tag_value != NULL)
+ {
+ tag_value = tag_value + 1;
+ gchar *tag_line = g_strdup_printf ("%s:\n%s\n\n", tags[i],
+ tag_value);
+ g_string_prepend (action_str, tag_line);
+
+ g_free (tag_line);
+ }
+ i++;
+ }
+ g_strfreev (tags);
+ }
+
+ if (append_tags != NULL)
+ {
+ gchar **tags = g_strsplit (append_tags, ",", 0);
+ int i = 0;
+ gchar *tag_prefix;
+ gchar *tag_value;
+
+ g_string_append (action_str, "\n");
+ while (tags[i] != NULL)
+ {
+ int j = 0;
+ tag_value = NULL;
+ tag_prefix = g_strconcat (tags[i], "=", NULL);
+ while (nvti_tags[j] != NULL && tag_value == NULL)
+ {
+ if (g_str_has_prefix (nvti_tags[j], tag_prefix))
+ {
+ tag_value = g_strstr_len (nvti_tags[j], -1, "=");
+ }
+ j++;
+ }
+ g_free (tag_prefix);
+
+ if (tag_value != NULL)
+ {
+ tag_value = tag_value + 1;
+ gchar *tag_line = g_strdup_printf ("%s:\n%s\n\n", tags[i],
+ tag_value);
+ g_string_append (action_str, tag_line);
+
+ g_free (tag_line);
+ }
+ i++;
+ }
+ g_strfreev (tags);
+ }
+ }
+
+ action_escaped = g_strescape (action_str->str, NULL);
+
+ action_str_escaped = g_string_new (action_escaped);
+
+ g_free (action_escaped);
+ g_string_free (action_str, TRUE);
+
+ len = action_str_escaped->len;
+
buffer = emalloc (1024 + len);
char idbuffer[105];
const char *svc_name = openvas_get_svc_name (port, proto);
@@ -569,13 +658,14 @@
{
snprintf (buffer, 1024 + len,
"SERVER <|> %s <|> %s <|> %s (%d/%s) <|> %s %s<|> SERVER\n",
- what, plug_get_hostname (desc), svc_name, port, proto, naction,
- idbuffer);
+ what, plug_get_hostname (desc), svc_name, port, proto,
+ action_str_escaped->str, idbuffer);
}
else
snprintf (buffer, 1024 + len,
"SERVER <|> %s <|> %s <|> general/%s <|> %s %s<|> SERVER\n", what,
- plug_get_hostname (desc), proto, naction, idbuffer);
+ plug_get_hostname (desc), proto, action_str_escaped->str,
+ idbuffer);
mark_post (desc, what, action);
soc = GPOINTER_TO_SIZE (arg_get_value (desc, "SOCKET"));
@@ -584,7 +674,7 @@
/* Mark in the KB that the plugin was successful */
mark_successful_plugin (desc);
efree (&buffer);
- efree (&naction);
+ g_string_free (action_str_escaped, TRUE);
}
void
More information about the Openvas-commits
mailing list