[Openvas-commits] r11551 - in trunk/gsa: . src src/html

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 2 18:59:17 CEST 2011


Author: mattm
Date: 2011-09-02 18:59:16 +0200 (Fri, 02 Sep 2011)
New Revision: 11551

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/gsad.c
   trunk/gsa/src/gsad_omp.c
   trunk/gsa/src/gsad_omp.h
   trunk/gsa/src/html/omp.xsl
Log:
	Convert more pages to new param mechanism.

	* src/gsad.c (init_validator): Add rules and new commands.
	(exec_omp_get): Pass single param instead of many.

	* src/gsad_omp.c (export_lsc_credential_omp): New function.  Split from
	get_lsc_credentials.
	(get_lsc_credentials): Replace multiple args with one.  Update caller.
	(get_lsc_credentials_omp, get_agents_omp, get_escalator_omp)
	(get_escalators_omp): Replace multiple args with one.
	(create_agent_omp): Improve size check because new param size can be -1.
	(get_agent_omp): New function.  Split from get_agents.

	* src/gsad_omp.h: Update headers accordingly.

	* src/html/omp.xsl (lsc_credential, agent): Use new command names.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2011-09-02 12:26:14 UTC (rev 11550)
+++ trunk/gsa/ChangeLog	2011-09-02 16:59:16 UTC (rev 11551)
@@ -2,6 +2,25 @@
 
 	Convert more pages to new param mechanism.
 
+	* src/gsad.c (init_validator): Add rules and new commands.
+	(exec_omp_get): Pass single param instead of many.
+
+	* src/gsad_omp.c (export_lsc_credential_omp): New function.  Split from
+	get_lsc_credentials.
+	(get_lsc_credentials): Replace multiple args with one.  Update caller.
+	(get_lsc_credentials_omp, get_agents_omp, get_escalator_omp)
+	(get_escalators_omp): Replace multiple args with one.
+	(create_agent_omp): Improve size check because new param size can be -1.
+	(get_agent_omp): New function.  Split from get_agents.
+
+	* src/gsad_omp.h: Update headers accordingly.
+
+	* src/html/omp.xsl (lsc_credential, agent): Use new command names.
+
+2011-09-01  Matthew Mundell <matthew.mundell at greenbone.net>
+
+	Convert more pages to new param mechanism.
+
 	* src/gsad.c (exec_omp_get): Pass single param instead of many.
 
 	* src/gsad_omp.c (verify_agent_omp, export_config_omp)

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2011-09-02 12:26:14 UTC (rev 11550)
+++ trunk/gsa/src/gsad.c	2011-09-02 16:59:16 UTC (rev 11551)
@@ -476,8 +476,10 @@
                          "|(empty_trashcan)"
                          "|(escalate_report)"
                          "|(export_config)"
+                         "|(export_lsc_credential)"
                          "|(export_preference_file)"
                          "|(export_report_format)"
+                         "|(get_agent)"
                          "|(get_agents)"
                          "|(get_config)"
                          "|(get_config_family)"
@@ -575,6 +577,10 @@
   openvas_validator_add (validator, "hosts_allow", "^0|1|2$");
   openvas_validator_add (validator, "hosts_opt",  "^[[:alnum:], \\./]{0,80}$");
   openvas_validator_add (validator, "hour",        "^((0|1)[0-9]{1,1})|(2(0|1|2|3))$");
+  openvas_validator_add (validator, "howto_use",   "^(\\R|.)*$");
+  openvas_validator_add (validator, "howto_install",  "^(\\R|.)*$");
+  openvas_validator_add (validator, "installer",      "^(\\R|.)*$");
+  openvas_validator_add (validator, "installer_sig",  "^(\\R|.)*$");
   openvas_validator_add (validator, "levels",       "^(h|m|l|g|f){0,5}$");
   openvas_validator_add (validator, "login",      "^[[:alnum:]]{1,10}$");
   openvas_validator_add (validator, "lsc_credential_id", "^[a-z0-9\\-]+$");
@@ -3142,6 +3148,31 @@
     return export_config_omp (credentials, params, content_type,
                               content_disposition, response_size);
 
+  else if (!strcmp (cmd, "export_lsc_credential"))
+    {
+      char *html;
+      gchar *lsc_credential_login;
+
+      if (export_lsc_credential_omp (credentials,
+                                     params,
+                                     response_size,
+                                     &html,
+                                     &lsc_credential_login))
+        return html;
+
+      content_type_from_format_string (content_type, package_format);
+      free (*content_disposition);
+      *content_disposition = g_strdup_printf
+                              ("attachment; filename=openvas-lsc-target-%s.%s",
+                               lsc_credential_login,
+                               (strcmp (package_format, "key") == 0
+                                 ? "pub"
+                                 : package_format));
+      free (lsc_credential_login);
+
+      return html;
+    }
+
   else if (!strcmp (cmd, "export_preference_file"))
     return export_preference_file_omp (credentials, params, content_type,
                                        content_disposition, response_size);
@@ -3150,33 +3181,17 @@
     return export_report_format_omp (credentials, params, content_type,
                                      content_disposition, response_size);
 
-  else if (0 == strcmp (cmd, "get_agents")
-           && ((agent_id == NULL && agent_format == NULL)
-               || (agent_id && agent_format)))
+  ELSE (get_agents)
+
+  else if (!strcmp (cmd, "get_agent"))
     {
       char *html, *filename;
 
-      if (agent_id == NULL)
-        {
-          get_agents_omp (credentials,
-                          agent_id,
-                          agent_format,
-                          response_size,
-                          sort_field,
-                          sort_order,
-                          &html,
-                          NULL);
-          return html;
-        }
-
-      if (get_agents_omp (credentials,
-                          agent_id,
-                          agent_format,
-                          response_size,
-                          NULL,
-                          NULL,
-                          &html,
-                          &filename))
+      if (get_agent_omp (credentials,
+                         params,
+                         response_size,
+                         &html,
+                         &filename))
         return html;
 
       *content_type = GSAD_CONTENT_TYPE_OCTET_STREAM;
@@ -3188,9 +3203,7 @@
       return html;
     }
 
-  else if ((!strcmp (cmd, "get_escalator")) && (escalator_id != NULL))
-    return get_escalator_omp (credentials, escalator_id, sort_field,
-                              sort_order);
+  ELSE (get_escalator)
 
   else if ((!strcmp (cmd, "get_result")) && (result_id != NULL)
            && (task_id != NULL))
@@ -3200,53 +3213,21 @@
                            min_cvss_base, result_hosts_only, sort_field,
                            sort_order, delta_report_id, delta_states);
 
-  else if (!strcmp (cmd, "get_escalators"))
-    return get_escalators_omp (credentials, sort_field, sort_order);
-
+  ELSE (get_escalators)
   ELSE (get_lsc_credential)
+  ELSE (get_lsc_credentials)
+  ELSE (get_note)
 
-  else if (!strcmp (cmd, "get_lsc_credentials")
-           && ((lsc_credential_id == NULL && package_format == NULL)
-               || (lsc_credential_id && package_format)))
-    {
-      char *html, *lsc_credential_login;
+  else if (!strcmp (cmd, "get_notes"))
+    return get_notes_omp (credentials);
 
-      if (lsc_credential_id == NULL)
-        {
-          get_lsc_credentials_omp (credentials,
-                                   lsc_credential_id,
-                                   package_format,
-                                   response_size,
-                                   sort_field,
-                                   sort_order,
-                                   &html,
-                                   NULL);
-          return html;
-        }
+  else if ((!strcmp (cmd, "get_override"))
+           && (override_id != NULL))
+    return get_override_omp (credentials, override_id);
 
-      if (get_lsc_credentials_omp (credentials,
-                                   lsc_credential_id,
-                                   package_format,
-                                   response_size,
-                                   NULL,
-                                   NULL,
-                                   &html,
-                                   &lsc_credential_login))
-        return html;
+  else if (!strcmp (cmd, "get_overrides"))
+    return get_overrides_omp (credentials);
 
-      content_type_from_format_string (content_type, package_format);
-      free (*content_disposition);
-      *content_disposition = g_strdup_printf
-                              ("attachment; filename=openvas-lsc-target-%s.%s",
-                               lsc_credential_login,
-                               (strcmp (package_format, "key") == 0
-                                 ? "pub"
-                                 : package_format));
-      free (lsc_credential_login);
-
-      return html;
-    }
-
   else if (!strcmp (cmd, "get_report"))
     {
       char *ret;
@@ -3266,18 +3247,6 @@
       return ret;
     }
 
-  ELSE (get_note)
-
-  else if ((!strcmp (cmd, "get_notes")))
-    return get_notes_omp (credentials);
-
-  else if ((!strcmp (cmd, "get_override"))
-           && (override_id != NULL))
-    return get_override_omp (credentials, override_id);
-
-  else if ((!strcmp (cmd, "get_overrides")))
-    return get_overrides_omp (credentials);
-
   else if ((!strcmp (cmd, "get_report_format")) && (report_format_id != NULL))
     return get_report_format_omp (credentials, report_format_id, sort_field,
                                   sort_order);

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2011-09-02 12:26:14 UTC (rev 11550)
+++ trunk/gsa/src/gsad_omp.c	2011-09-02 16:59:16 UTC (rev 11551)
@@ -2074,39 +2074,30 @@
   return get_lsc_credential (credentials, params, NULL);
 }
 
-/** @todo Do package download somewhere else. */
 /**
  * @brief Get one or all LSC credentials, XSL transform the result.
  *
- * @param[in]   credentials        Username and password for authentication.
- * @param[in]   lsc_credential_id  UUID of LSC credential.
- * @param[in]   format             Format of result
- * @param[out]  result_len         Length of result.
- * @param[in]   sort_field         Field to sort on, or NULL.
- * @param[in]   sort_order         "ascending", "descending", or NULL.
- * @param[out]  html               Result of XSL transformation.  Required.
- * @param[out]  login              Login name return.  NULL to skip.  Only set
- *                                 on success with lsc_credential_id.
- * @param[in]   commands           Extra commands to run before the others when
- *                                 lsc_credential_id is NULL.
+ * @param[in]   credentials  Username and password for authentication.
+ * @param[in]   params       Request parameters.
+ * @param[out]  result_len   Length of result.
+ * @param[out]  html         Result of XSL transformation.  Required.
+ * @param[out]  login        Login name return.  NULL to skip.  Only set on
+ *                           success with lsc_credential_id.
  *
  * @return 0 success, 1 failure.
  */
-static int
-get_lsc_credentials (credentials_t * credentials,
-                     const char * lsc_credential_id,
-                     const char * format,
-                     gsize *result_len,
-                     const char * sort_field,
-                     const char * sort_order,
-                     char ** html,
-                     char ** login,
-                     const char *commands)
+int
+export_lsc_credential_omp (credentials_t * credentials,
+                           params_t *params,
+                           gsize *result_len,
+                           char ** html,
+                           char ** login)
 {
   entity_t entity;
   gnutls_session_t session;
   int socket;
   gchar *connect_html;
+  const char *lsc_credential_id, *format;
 
   assert (html);
 
@@ -2126,237 +2117,259 @@
       default:
         *html = gsad_message (credentials,
                               "Internal error", __FUNCTION__, __LINE__,
-                              "An internal error occurred while getting the credential list. "
-                              "The current list of credentials is not available. "
+                              "An internal error occurred while getting a credential. "
                               "Diagnostics: Failure to connect to manager daemon.",
-                              "/omp?cmd=get_targets");
+                              "/omp?cmd=get_lsc_credentials");
         return 1;
     }
 
   /* Send the request. */
 
-  if (lsc_credential_id && format)
+  lsc_credential_id = params_value (params, "lsc_credential_id");
+  format = params_value (params, "package_format");
+
+  if ((lsc_credential_id == NULL) || (format == NULL))
     {
-      if (openvas_server_sendf (&session,
-                                "<get_lsc_credentials"
-                                " lsc_credential_id=\"%s\""
-                                " format=\"%s\"/>",
-                                lsc_credential_id,
-                                format)
-          == -1)
-        {
-          openvas_server_close (socket, session);
-          *html = gsad_message (credentials,
-                                "Internal error", __FUNCTION__, __LINE__,
-                                "An internal error occurred while getting credential list. "
-                                "The current list of credentials is not available. "
-                                "Diagnostics: Failure to send command to manager daemon.",
-                                "/omp?cmd=get_targets");
-          return 1;
-        }
+      openvas_server_close (socket, session);
+      *html = gsad_message (credentials,
+                            "Internal error", __FUNCTION__, __LINE__,
+                            "An internal error occurred while getting a credential. "
+                            "Diagnostics: Required parameter was NULL.",
+                            "/omp?cmd=get_lsc_credentials");
+      return 1;
     }
-  else
+
+  if (openvas_server_sendf (&session,
+                            "<get_lsc_credentials"
+                            " lsc_credential_id=\"%s\""
+                            " format=\"%s\"/>",
+                            lsc_credential_id,
+                            format)
+      == -1)
     {
-      if (openvas_server_sendf (&session,
-                                "<commands>"
-                                "%s"
-                                "<get_lsc_credentials"
-                                " sort_field=\"%s\" sort_order=\"%s\"/>"
-                                "</commands>",
-                                commands ? commands : "",
-                                sort_field ? sort_field : "name",
-                                sort_order ? sort_order : "ascending")
-          == -1)
+      openvas_server_close (socket, session);
+      *html = gsad_message (credentials,
+                            "Internal error", __FUNCTION__, __LINE__,
+                            "An internal error occurred while getting a credential. "
+                            "Diagnostics: Failure to send command to manager daemon.",
+                            "/omp?cmd=get_lsc_credentials");
+      return 1;
+    }
+
+  /* Read and handle the response. */
+
+  if (strcmp (format, "rpm") == 0
+      || strcmp (format, "deb") == 0
+      || strcmp (format, "exe") == 0)
+    {
+      char *package_encoded = NULL;
+      gchar *package_decoded = NULL;
+      entity_t package_entity = NULL, credential_entity;
+
+      /* A base64 encoded package. */
+
+      entity = NULL;
+      if (read_entity (&session, &entity))
         {
           openvas_server_close (socket, session);
           *html = gsad_message (credentials,
                                 "Internal error", __FUNCTION__, __LINE__,
-                                "An internal error occurred while getting credential list. "
-                                "The current list of credentials is not available. "
-                                "Diagnostics: Failure to send command to manager daemon.",
-                                "/omp?cmd=get_targets");
+                                "An internal error occurred while getting a credential. "
+                                "The credential is not available. "
+                                "Diagnostics: Failure to receive response from manager daemon.",
+                                "/omp?cmd=get_lsc_credentials");
           return 1;
         }
-    }
 
-  /* Read and handle the response. */
-
-  if (lsc_credential_id && format)
-    {
-      if (strcmp (format, "rpm") == 0
-          || strcmp (format, "deb") == 0
-          || strcmp (format, "exe") == 0)
+      credential_entity = entity_child (entity, "lsc_credential");
+      if (credential_entity)
+        package_entity = entity_child (credential_entity, "package");
+      if (package_entity != NULL)
         {
-          char *package_encoded = NULL;
-          gchar *package_decoded = NULL;
-          entity_t package_entity = NULL, credential_entity;
-
-          /* A base64 encoded package. */
-
-          entity = NULL;
-          if (read_entity (&session, &entity))
+          gsize len;
+          package_encoded = entity_text (package_entity);
+          if (strlen (package_encoded))
             {
-              openvas_server_close (socket, session);
-              *html = gsad_message (credentials,
-                                    "Internal error", __FUNCTION__, __LINE__,
-                                    "An internal error occurred while getting a credential. "
-                                    "The credential is not available. "
-                                    "Diagnostics: Failure to receive response from manager daemon.",
-                                    "/omp?cmd=get_targets");
-              return 1;
-            }
-
-          credential_entity = entity_child (entity, "lsc_credential");
-          if (credential_entity)
-            package_entity = entity_child (credential_entity, "package");
-          if (package_entity != NULL)
-            {
-              gsize len;
-              package_encoded = entity_text (package_entity);
-              if (strlen (package_encoded))
+              package_decoded = (gchar *) g_base64_decode (package_encoded,
+                                                           &len);
+              if (package_decoded == NULL)
                 {
-                  package_decoded = (gchar *) g_base64_decode (package_encoded,
-                                                               &len);
-                  if (package_decoded == NULL)
-                    {
-                      package_decoded = (gchar *) g_strdup ("");
-                      len = 0;
-                    }
-                }
-              else
-                {
                   package_decoded = (gchar *) g_strdup ("");
                   len = 0;
                 }
-              if (result_len) *result_len = len;
-              openvas_server_close (socket, session);
-              *html = package_decoded;
-              if (login)
-                {
-                  entity_t login_entity;
-                  login_entity = entity_child (credential_entity, "login");
-                  if (login_entity)
-                    *login = g_strdup (entity_text (login_entity));
-                  else
-                    *login = NULL;
-                }
-              free_entity (entity);
-              return 0;
             }
           else
             {
-              free_entity (entity);
-              openvas_server_close (socket, session);
-              *html = gsad_message (credentials,
-                                    "Internal error", __FUNCTION__, __LINE__,
-                                    "An internal error occurred while getting a credential. "
-                                    "The credential could not be delivered. "
-                                    "Diagnostics: Failure to receive credential from manager daemon.",
-                                    "/omp?cmd=get_tasks");
-              return 1;
+              package_decoded = (gchar *) g_strdup ("");
+              len = 0;
             }
+          if (result_len) *result_len = len;
+          openvas_server_close (socket, session);
+          *html = package_decoded;
+          if (login)
+            {
+              entity_t login_entity;
+              login_entity = entity_child (credential_entity, "login");
+              if (login_entity)
+                *login = g_strdup (entity_text (login_entity));
+              else
+                *login = NULL;
+            }
+          free_entity (entity);
+          return 0;
         }
       else
         {
-          entity_t credential_entity, key_entity = NULL;
-
-          /* A key. */
-
-          entity = NULL;
-          if (read_entity (&session, &entity))
-            {
-              openvas_server_close (socket, session);
-              *html = gsad_message (credentials,
-                                    "Internal error", __FUNCTION__, __LINE__,
-                                    "An internal error occurred while getting a credential. "
-                                    "The credential could not be delivered. "
-                                    "Diagnostics: Failure to receive credential from manager daemon.",
-                                    "/omp?cmd=get_tasks");
-              return 1;
-            }
+          free_entity (entity);
           openvas_server_close (socket, session);
-
-          credential_entity = entity_child (entity, "lsc_credential");
-          if (credential_entity)
-            key_entity = entity_child (credential_entity, "public_key");
-          if (key_entity != NULL)
-            {
-              *html = g_strdup (entity_text (key_entity));
-              if (login)
-                {
-                  entity_t login_entity = entity_child (credential_entity, "login");
-                  if (login_entity)
-                    *login = g_strdup (entity_text (login_entity));
-                  else
-                    *login = NULL;
-                }
-              free_entity (entity);
-              return 0;
-            }
           *html = gsad_message (credentials,
                                 "Internal error", __FUNCTION__, __LINE__,
                                 "An internal error occurred while getting a credential. "
                                 "The credential could not be delivered. "
-                                "Diagnostics: Failure to parse credential from manager daemon.",
-                                "/omp?cmd=get_tasks");
-          free_entity (entity);
+                                "Diagnostics: Failure to receive credential from manager daemon.",
+                                "/omp?cmd=get_lsc_credentials");
           return 1;
         }
     }
   else
     {
-      char *text = NULL;
+      entity_t credential_entity, key_entity = NULL;
 
-      /* The list of credentials. */
+      /* A key. */
 
       entity = NULL;
-      if (read_entity_and_text (&session, &entity, &text))
+      if (read_entity (&session, &entity))
         {
           openvas_server_close (socket, session);
           *html = gsad_message (credentials,
                                 "Internal error", __FUNCTION__, __LINE__,
-                                "An internal error occurred while getting credential list. "
-                                "The current list of credentials is not available. "
-                                "Diagnostics: Failure to receive response from manager daemon.",
-                                "/omp?cmd=get_targets");
+                                "An internal error occurred while getting a credential. "
+                                "The credential could not be delivered. "
+                                "Diagnostics: Failure to receive credential from manager daemon.",
+                                "/omp?cmd=get_lsc_credentials");
           return 1;
         }
+      openvas_server_close (socket, session);
+
+      credential_entity = entity_child (entity, "lsc_credential");
+      if (credential_entity)
+        key_entity = entity_child (credential_entity, "public_key");
+      if (key_entity != NULL)
+        {
+          *html = g_strdup (entity_text (key_entity));
+          if (login)
+            {
+              entity_t login_entity = entity_child (credential_entity, "login");
+              if (login_entity)
+                *login = g_strdup (entity_text (login_entity));
+              else
+                *login = NULL;
+            }
+          free_entity (entity);
+          return 0;
+        }
+      *html = gsad_message (credentials,
+                            "Internal error", __FUNCTION__, __LINE__,
+                            "An internal error occurred while getting a credential. "
+                            "The credential could not be delivered. "
+                            "Diagnostics: Failure to parse credential from manager daemon.",
+                            "/omp?cmd=get_lsc_credentials");
       free_entity (entity);
+      return 1;
+    }
+}
 
+/**
+ * @brief Get an LSC credentials, XSL transform the result.
+ *
+ * @param[in]  credentials  Username and password for authentication.
+ * @param[in]  params       Request parameters.
+ * @param[in]  commands     Extra commands to run before the others when
+ *                          lsc_credential_id is NULL.
+ *
+ * @return 0 success, 1 failure.
+ */
+static char *
+get_lsc_credentials (credentials_t * credentials, params_t *params,
+                     const char *commands)
+{
+  entity_t entity;
+  gnutls_session_t session;
+  int socket;
+  gchar *connect_html;
+  char *text = NULL;
+  const char *sort_order, *sort_field;
+
+  switch (manager_connect (credentials, &socket, &session, &connect_html))
+    {
+      case 0:
+        break;
+      case -1:
+        if (connect_html)
+          return (connect_html);
+        /* Fall through. */
+      default:
+        return gsad_message (credentials,
+                             "Internal error", __FUNCTION__, __LINE__,
+                             "An internal error occurred while getting the credential list. "
+                             "The current list of credentials is not available. "
+                             "Diagnostics: Failure to connect to manager daemon.",
+                             "/omp?cmd=get_targets");
+    }
+
+  /* Send the request. */
+
+  if (openvas_server_sendf (&session,
+                            "<commands>"
+                            "%s"
+                            "<get_lsc_credentials"
+                            " sort_field=\"%s\" sort_order=\"%s\"/>"
+                            "</commands>",
+                            commands ? commands : "",
+                            sort_field ? sort_field : "name",
+                            sort_order ? sort_order : "ascending")
+      == -1)
+    {
       openvas_server_close (socket, session);
-      *html = xsl_transform_omp (credentials, text);
-      return 0;
+      return gsad_message (credentials,
+                           "Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while getting credential list. "
+                           "The current list of credentials is not available. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_targets");
     }
+
+  /* Read and handle the response. */
+
+  entity = NULL;
+  if (read_entity_and_text (&session, &entity, &text))
+    {
+      openvas_server_close (socket, session);
+      return gsad_message (credentials,
+                           "Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while getting credential list. "
+                           "The current list of credentials is not available. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_targets");
+    }
+  free_entity (entity);
+
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, text);
 }
 
 /**
  * @brief Get one or all LSC credentials, XSL transform the result.
  *
- * @param[in]   credentials        Username and password for authentication.
- * @param[in]   lsc_credential_id  UUID of LSC credential.
- * @param[in]   format             Format of result
- * @param[out]  result_len         Length of result.
- * @param[in]   sort_field         Field to sort on, or NULL.
- * @param[in]   sort_order         "ascending", "descending", or NULL.
- * @param[out]  html               Result of XSL transformation.  Required.
- * @param[out]  login              Login name return.  NULL to skip.  Only set
- *                                 on success with lsc_credential_id.
+ * @param[in]  credentials  Username and password for authentication.
+ * @param[in]  params       Request parameters.
  *
  * @return 0 success, 1 failure.
  */
-int
-get_lsc_credentials_omp (credentials_t * credentials,
-                         const char * lsc_credential_id,
-                         const char * format,
-                         gsize *result_len,
-                         const char * sort_field,
-                         const char * sort_order,
-                         char ** html,
-                         char ** login)
+char *
+get_lsc_credentials_omp (credentials_t * credentials, params_t *params)
 {
-  return get_lsc_credentials (credentials, lsc_credential_id, format,
-                              result_len, sort_field, sort_order, html,
-                              login, NULL);
+  return get_lsc_credentials (credentials, params, NULL);
 }
 
 /**
@@ -2578,10 +2591,7 @@
   if (strcmp (params_value (params, "next"), "get_lsc_credentials") == 0)
     {
       char *ret;
-      get_lsc_credentials (credentials, NULL, NULL, NULL,
-                           params_value (params, "sort_field"),
-                           params_value (params, "sort_order"),
-                           &ret, NULL, modify);
+      ret = get_lsc_credentials (credentials, params, modify);
       g_free (modify);
       return ret;
     }
@@ -2661,22 +2671,22 @@
 
       /* Create the agent. */
 
-      installer_64 = installer_size
+      installer_64 = (installer_size > 0)
                      ? g_base64_encode ((guchar *) installer,
                                         installer_size)
                      : g_strdup ("");
 
-      installer_sig_64 = installer_sig_size
+      installer_sig_64 = (installer_sig_size > 0)
                          ? g_base64_encode ((guchar *) installer_sig,
                                             installer_sig_size)
                          : g_strdup ("");
 
-      howto_install_64 = howto_install_size
+      howto_install_64 = (howto_install_size > 0)
                          ? g_base64_encode ((guchar *) howto_install,
                                             howto_install_size)
                          : g_strdup ("");
 
-      howto_use_64 = howto_use_size
+      howto_use_64 = (howto_use_size > 0)
                      ? g_base64_encode ((guchar *) howto_use,
                                         howto_use_size)
                      : g_strdup ("");
@@ -2845,16 +2855,13 @@
   return xsl_transform_omp (credentials, text);
 }
 
-/** @todo Split into get_agents_omp and get_agent_omp. */
 /**
- * @brief Get one or all agents, XSL transform the result.
+ * @brief Get an agent, XSL transform the result.
  *
  * @param[in]   credentials  Username and password for authentication.
- * @param[in]   agent_id     UUID of agent.
+ * @param[in]   params       Request parameters.
  * @param[in]   format       Format of result
  * @param[out]  result_len   Length of result.
- * @param[in]   sort_field   Field to sort on, or NULL.
- * @param[in]   sort_order   "ascending", "descending", or NULL.
  * @param[out]  html         Result of XSL transformation.  Required.
  * @param[out]  filename     Agent filename return.  NULL to skip.  Only set
  *                           on success with agent_id.
@@ -2862,20 +2869,32 @@
  * @return 0 success, 1 failure.
  */
 int
-get_agents_omp (credentials_t * credentials,
-                const char * agent_id,
-                const char * format,
-                gsize *result_len,
-                const char * sort_field,
-                const char * sort_order,
-                char ** html,
-                char ** filename)
+get_agent_omp (credentials_t * credentials,
+               params_t *params,
+               gsize *result_len,
+               char ** html,
+               char ** filename)
 {
   entity_t entity;
   gnutls_session_t session;
   int socket;
   gchar *connect_html;
+  const char *agent_id, *format;
 
+  agent_id = params_value (params, "agent_id");
+  format = params_value (params, "agent_format");
+
+  if ((agent_id == NULL) || (format == NULL))
+    {
+      *html = gsad_message (credentials,
+                            "Internal error", __FUNCTION__, __LINE__,
+                            "An internal error occurred while deleting an agent. "
+                            "The agent was not deleted. "
+                            "Diagnostics: Required parameter was NULL.",
+                            "/omp?cmd=get_agents");
+      return 1;
+    }
+
   *result_len = 0;
 
   switch (manager_connect (credentials, &socket, &session, &connect_html))
@@ -2903,174 +2922,204 @@
 
   /* Send the request. */
 
-  if (agent_id && format)
+  if (openvas_server_sendf (&session,
+                            "<get_agents agent_id=\"%s\" format=\"%s\"/>",
+                            agent_id,
+                            format)
+      == -1)
     {
-      if (openvas_server_sendf (&session,
-                                "<get_agents agent_id=\"%s\" format=\"%s\"/>",
-                                agent_id,
-                                format)
-          == -1)
-        {
-          openvas_server_close (socket, session);
-          *html = gsad_message (credentials,
-                                "Internal error", __FUNCTION__, __LINE__,
-                                "An internal error occurred while getting agent list. "
-                                "The current list of agents is not available. "
-                                "Diagnostics: Failure to send command to manager daemon.",
-                                "/omp?cmd=get_agents");
-          return 1;
-        }
+      openvas_server_close (socket, session);
+      *html = gsad_message (credentials,
+                            "Internal error", __FUNCTION__, __LINE__,
+                            "An internal error occurred while getting agent list. "
+                            "The current list of agents is not available. "
+                            "Diagnostics: Failure to send command to manager daemon.",
+                            "/omp?cmd=get_agents");
+      return 1;
     }
-  else
+
+  /* Read and handle the response. */
+
+  if (strcmp (format, "installer") == 0
+      || strcmp (format, "howto_install") == 0
+      || strcmp (format, "howto_use") == 0)
     {
-      if (openvas_server_sendf (&session,
-                                "<commands>"
-                                "<get_agents"
-                                " sort_field=\"%s\" sort_order=\"%s\"/>"
-                                "</commands>",
-                                sort_field ? sort_field : "name",
-                                sort_order ? sort_order : "ascending")
-          == -1)
+      char *package_encoded = NULL;
+      gchar *package_decoded = NULL;
+      entity_t package_entity = NULL, agent_entity;
+
+      /* A base64 encoded package. */
+
+      entity = NULL;
+      if (read_entity (&session, &entity))
         {
           openvas_server_close (socket, session);
           *html = gsad_message (credentials,
                                 "Internal error", __FUNCTION__, __LINE__,
-                                "An internal error occurred while getting agent list. "
-                                "The current list of agents is not available. "
-                                "Diagnostics: Failure to send command to manager daemon.",
+                                "An internal error occurred while getting a agent. "
+                                "The agent is not available. "
+                                "Diagnostics: Failure to receive response from manager daemon.",
                                 "/omp?cmd=get_agents");
           return 1;
         }
-    }
 
-  /* Read and handle the response. */
-
-  if (agent_id && format)
-    {
-      if (strcmp (format, "installer") == 0
-          || strcmp (format, "howto_install") == 0
-          || strcmp (format, "howto_use") == 0)
+      agent_entity = entity_child (entity, "agent");
+      if (agent_entity)
+        package_entity = entity_child (agent_entity, "package");
+      if (package_entity != NULL)
         {
-          char *package_encoded = NULL;
-          gchar *package_decoded = NULL;
-          entity_t package_entity = NULL, agent_entity;
-
-          /* A base64 encoded package. */
-
-          entity = NULL;
-          if (read_entity (&session, &entity))
+          package_encoded = entity_text (package_entity);
+          if (strlen (package_encoded))
             {
-              openvas_server_close (socket, session);
-              *html = gsad_message (credentials,
-                                    "Internal error", __FUNCTION__, __LINE__,
-                                    "An internal error occurred while getting a agent. "
-                                    "The agent is not available. "
-                                    "Diagnostics: Failure to receive response from manager daemon.",
-                                    "/omp?cmd=get_agents");
-              return 1;
-            }
-
-          agent_entity = entity_child (entity, "agent");
-          if (agent_entity)
-            package_entity = entity_child (agent_entity, "package");
-          if (package_entity != NULL)
-            {
-              package_encoded = entity_text (package_entity);
-              if (strlen (package_encoded))
+              package_decoded = (gchar *) g_base64_decode (package_encoded,
+                                                           result_len);
+              if (package_decoded == NULL)
                 {
-                  package_decoded = (gchar *) g_base64_decode (package_encoded,
-                                                               result_len);
-                  if (package_decoded == NULL)
-                    {
-                      package_decoded = (gchar *) g_strdup ("");
-                      *result_len = 0;
-                    }
-                }
-              else
-                {
                   package_decoded = (gchar *) g_strdup ("");
                   *result_len = 0;
                 }
-              openvas_server_close (socket, session);
-              *html = package_decoded;
-              if (filename)
-                {
-                  entity_t filename_entity;
-                  filename_entity = entity_child (package_entity,
-                                                  "filename");
-                  if (filename_entity)
-                    *filename = g_strdup (entity_text (filename_entity));
-                  else
-                    *filename = NULL;
-                }
-              free_entity (entity);
-              return 0;
             }
           else
             {
-              free_entity (entity);
-              openvas_server_close (socket, session);
-              *html = gsad_message (credentials,
-                                    "Internal error", __FUNCTION__, __LINE__,
-                                    "An internal error occurred while getting a agent. "
-                                    "The agent could not be delivered. "
-                                    "Diagnostics: Failure to receive agent from manager daemon.",
-                                    "/omp?cmd=get_tasks");
-              return 1;
+              package_decoded = (gchar *) g_strdup ("");
+              *result_len = 0;
             }
+          openvas_server_close (socket, session);
+          *html = package_decoded;
+          if (filename)
+            {
+              entity_t filename_entity;
+              filename_entity = entity_child (package_entity,
+                                              "filename");
+              if (filename_entity)
+                *filename = g_strdup (entity_text (filename_entity));
+              else
+                *filename = NULL;
+            }
+          free_entity (entity);
+          return 0;
         }
       else
         {
-          /* An error. */
-
-          entity = NULL;
-          if (read_entity (&session, &entity))
-            {
-              openvas_server_close (socket, session);
-              *html = gsad_message (credentials,
-                                    "Internal error", __FUNCTION__, __LINE__,
-                                    "An internal error occurred while getting a agent. "
-                                    "The agent could not be delivered. "
-                                    "Diagnostics: Failure to receive agent from manager daemon.",
-                                    "/omp?cmd=get_tasks");
-              return 1;
-            }
+          free_entity (entity);
           openvas_server_close (socket, session);
-
-          free_entity (entity);
           *html = gsad_message (credentials,
                                 "Internal error", __FUNCTION__, __LINE__,
                                 "An internal error occurred while getting a agent. "
                                 "The agent could not be delivered. "
-                                "Diagnostics: Failure to parse agent from manager daemon.",
+                                "Diagnostics: Failure to receive agent from manager daemon.",
                                 "/omp?cmd=get_tasks");
           return 1;
         }
     }
   else
     {
-      char *text = NULL;
+      /* An error. */
 
-      /* The list of agents. */
-
       entity = NULL;
-      if (read_entity_and_text (&session, &entity, &text))
+      if (read_entity (&session, &entity))
         {
           openvas_server_close (socket, session);
           *html = gsad_message (credentials,
                                 "Internal error", __FUNCTION__, __LINE__,
-                                "An internal error occurred while getting agent list. "
-                                "The current list of agents is not available. "
-                                "Diagnostics: Failure to receive response from manager daemon.",
+                                "An internal error occurred while getting a agent. "
+                                "The agent could not be delivered. "
+                                "Diagnostics: Failure to receive agent from manager daemon.",
                                 "/omp?cmd=get_tasks");
           return 1;
         }
+      openvas_server_close (socket, session);
+
       free_entity (entity);
+      *html = gsad_message (credentials,
+                            "Internal error", __FUNCTION__, __LINE__,
+                            "An internal error occurred while getting a agent. "
+                            "The agent could not be delivered. "
+                            "Diagnostics: Failure to parse agent from manager daemon.",
+                            "/omp?cmd=get_tasks");
+      return 1;
+    }
+}
 
+/**
+ * @brief Get one or all agents, XSL transform the result.
+ *
+ * @param[in]   credentials  Username and password for authentication.
+ * @param[in]   params       Request parameters.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+get_agents_omp (credentials_t * credentials, params_t *params)
+{
+  entity_t entity;
+  gnutls_session_t session;
+  int socket;
+  gchar *connect_html;
+  char *text = NULL;
+  const char *sort_field, *sort_order;
+
+  switch (manager_connect (credentials, &socket, &session, &connect_html))
+    {
+      case 0:
+        break;
+      case -1:
+        if (connect_html)
+          {
+            return connect_html;
+          }
+        /* Fall through. */
+      default:
+        {
+          return gsad_message (credentials,
+                               "Internal error", __FUNCTION__, __LINE__,
+                               "An internal error occurred while getting the agent list. "
+                               "The current list of agents is not available. "
+                               "Diagnostics: Failure to connect to manager daemon.",
+                               "/omp?cmd=get_agents");
+        }
+    }
+
+  /* Send the request. */
+
+  sort_field = params_value (params, "sort_field");
+  sort_order = params_value (params, "sort_order");
+
+  if (openvas_server_sendf (&session,
+                            "<commands>"
+                            "<get_agents"
+                            " sort_field=\"%s\" sort_order=\"%s\"/>"
+                            "</commands>",
+                            sort_field ? sort_field : "name",
+                            sort_order ? sort_order : "ascending")
+      == -1)
+    {
       openvas_server_close (socket, session);
-      *html = xsl_transform_omp (credentials, text);
-      return 0;
+      return gsad_message (credentials,
+                           "Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while getting agent list. "
+                           "The current list of agents is not available. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_agents");
     }
+
+  /* Read and handle the response. */
+
+  entity = NULL;
+  if (read_entity_and_text (&session, &entity, &text))
+    {
+      openvas_server_close (socket, session);
+      return gsad_message (credentials,
+                           "Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while getting agent list. "
+                           "The current list of agents is not available. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_tasks");
+    }
+  free_entity (entity);
+
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, text);
 }
 
 /**
@@ -3515,21 +3564,30 @@
  * @brief Get one escalator, XSL transform the result.
  *
  * @param[in]  credentials   Username and password for authentication.
- * @param[in]  escalator_id  Name of escalator.
- * @param[in]  sort_field    Field to sort on, or NULL.
- * @param[in]  sort_order    "ascending", "descending", or NULL.
+ * @param[in]  params       Request parameters.
  *
  * @return Result of XSL transformation.
  */
 char *
-get_escalator_omp (credentials_t * credentials, const char * escalator_id,
-                   const char * sort_field, const char * sort_order)
+get_escalator_omp (credentials_t * credentials, params_t *params)
 {
   GString *xml;
   gnutls_session_t session;
   int socket;
   gchar *html;
+  const char *escalator_id, *sort_field, *sort_order;
 
+  escalator_id = params_value (params, "escalator_id");
+  sort_field = params_value (params, "sort_field");
+  sort_order = params_value (params, "sort_order");
+
+  if (escalator_id == NULL)
+    return gsad_message (credentials,
+                         "Internal error", __FUNCTION__, __LINE__,
+                         "An internal error occurred while getting an escalator. "
+                         "Diagnostics: Required parameter was NULL.",
+                         "/omp?cmd=get_escalators");
+
   switch (manager_connect (credentials, &socket, &session, &html))
     {
       case 0:
@@ -3658,14 +3716,12 @@
  * @brief Get all escalators, XSL transform the result.
  *
  * @param[in]  credentials  Username and password for authentication.
- * @param[in]  sort_field   Field to sort on, or NULL.
- * @param[in]  sort_order   "ascending", "descending", or NULL.
+ * @param[in]  params       Request parameters.
  *
  * @return Result of XSL transformation.
  */
 char *
-get_escalators_omp (credentials_t * credentials, const char * sort_field,
-                    const char * sort_order)
+get_escalators_omp (credentials_t * credentials, params_t *params)
 {
   GString *xml;
   gnutls_session_t session;
@@ -3692,7 +3748,9 @@
 
   xml = g_string_new ("<get_escalators>");
 
-  ret = get_escalators_xml (credentials, &session, xml, sort_field, sort_order);
+  ret = get_escalators_xml (credentials, &session, xml,
+                            params_value (params, "sort_field"),
+                            params_value (params, "sort_order"));
   if (ret)
     {
       g_string_free (xml, TRUE);

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2011-09-02 12:26:14 UTC (rev 11550)
+++ trunk/gsa/src/gsad_omp.h	2011-09-02 16:59:16 UTC (rev 11551)
@@ -70,22 +70,21 @@
 char * delete_escalator_omp (credentials_t *, params_t *);
 char * delete_trash_escalator_omp (credentials_t *, params_t *);
 char * test_escalator_omp (credentials_t *, params_t *);
-char * get_escalator_omp (credentials_t *, const char *, const char *,
-                          const char *);
-char * get_escalators_omp (credentials_t *, const char *, const char *);
+char * get_escalator_omp (credentials_t *, params_t *);
+char * get_escalators_omp (credentials_t *, params_t *);
 
+int export_lsc_credential_omp (credentials_t *, params_t *, gsize *, char **,
+                               char **);
 char * get_lsc_credential_omp (credentials_t *, params_t *);
-int get_lsc_credentials_omp (credentials_t *, const char *, const char *,
-                             gsize *, const char *, const char *, char **,
-                             char **);
+char * get_lsc_credentials_omp (credentials_t *, params_t *);
 char * create_lsc_credential_omp (credentials_t *, params_t *);
 char * delete_lsc_credential_omp (credentials_t *, params_t *);
 char * delete_trash_lsc_credential_omp (credentials_t *, params_t *);
 char * edit_lsc_credential_omp (credentials_t *, params_t *);
 char * save_lsc_credential_omp (credentials_t *, params_t *);
 
-int get_agents_omp (credentials_t *, const char *, const char *,
-                    gsize *, const char *, const char *, char **, char **);
+char * get_agents_omp (credentials_t *, params_t *);
+int get_agent_omp (credentials_t *, params_t *, gsize *, char **, char **);
 char * create_agent_omp (credentials_t *, params_t *);
 char * delete_agent_omp (credentials_t *, params_t *);
 char * delete_trash_agent_omp (credentials_t *, params_t *);

Modified: trunk/gsa/src/html/omp.xsl
===================================================================
--- trunk/gsa/src/html/omp.xsl	2011-09-02 12:26:14 UTC (rev 11550)
+++ trunk/gsa/src/html/omp.xsl	2011-09-02 16:59:16 UTC (rev 11551)
@@ -3652,19 +3652,19 @@
         <img src="/img/edit.png" border="0" alt="Edit"/>
       </a>
       <xsl:if test="type='gen'">
-        <a href="/omp?cmd=get_lsc_credentials&amp;lsc_credential_id={@id}&amp;package_format=rpm&amp;token={/envelope/token}"
+        <a href="/omp?cmd=export_lsc_credential&amp;lsc_credential_id={@id}&amp;package_format=rpm&amp;token={/envelope/token}"
            title="Download RPM package" style="margin-left:3px;">
           <img src="/img/rpm.png" border="0" alt="Download RPM"/>
         </a>
-        <a href="/omp?cmd=get_lsc_credentials&amp;lsc_credential_id={@id}&amp;package_format=deb&amp;token={/envelope/token}"
+        <a href="/omp?cmd=export_lsc_credential&amp;lsc_credential_id={@id}&amp;package_format=deb&amp;token={/envelope/token}"
            title="Download Debian package" style="margin-left:3px;">
           <img src="/img/deb.png" border="0" alt="Download Deb"/>
         </a>
-        <a href="/omp?cmd=get_lsc_credentials&amp;lsc_credential_id={@id}&amp;package_format=exe&amp;token={/envelope/token}"
+        <a href="/omp?cmd=export_lsc_credential&amp;lsc_credential_id={@id}&amp;package_format=exe&amp;token={/envelope/token}"
            title="Download Exe package" style="margin-left:3px;">
           <img src="/img/exe.png" border="0" alt="Download Exe"/>
         </a>
-        <a href="/omp?cmd=get_lsc_credentials&amp;lsc_credential_id={@id}&amp;package_format=key&amp;token={/envelope/token}"
+        <a href="/omp?cmd=export_lsc_credential&amp;lsc_credential_id={@id}&amp;package_format=key&amp;token={/envelope/token}"
            title="Download Public Key" style="margin-left:3px;">
           <img src="/img/key.png" border="0" alt="Download Public Key"/>
         </a>
@@ -3969,7 +3969,7 @@
                style="margin-left:3px;"/>
         </xsl:otherwise>
       </xsl:choose>
-      <a href="/omp?cmd=get_agents&amp;agent_id={@id}&amp;agent_format=installer&amp;token={/envelope/token}"
+      <a href="/omp?cmd=get_agent&amp;agent_id={@id}&amp;agent_format=installer&amp;token={/envelope/token}"
          title="Download installer package" style="margin-left:3px;">
         <img src="/img/agent.png" border="0" alt="Download Installer"/>
       </a>



More information about the Openvas-commits mailing list