[Openvas-commits] r6267 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Dec 28 15:33:20 CET 2009


Author: mattm
Date: 2009-12-28 15:33:17 +0100 (Mon, 28 Dec 2009)
New Revision: 6267

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	* src/tasks_sql.h (lsc_credential_iterator_in_use): Correct column.
	(init_lsc_credential_target_iterator)
	(lsc_credential_target_iterator_name): New functions.

	* src/manage.h: Add headers accordingly.

	* src/omp.c (omp_xml_handle_end_element): Rename variable targets to
	credentials.  Send targets using the credential with each credential in
	list version.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-12-28 13:59:45 UTC (rev 6266)
+++ trunk/openvas-manager/ChangeLog	2009-12-28 14:33:17 UTC (rev 6267)
@@ -1,5 +1,17 @@
 2009-12-28  Matthew Mundell <matthew.mundell at intevation.de>
 
+	* src/tasks_sql.h (lsc_credential_iterator_in_use): Correct column.
+	(init_lsc_credential_target_iterator)
+	(lsc_credential_target_iterator_name): New functions.
+
+	* src/manage.h: Add headers accordingly.
+
+	* src/omp.c (omp_xml_handle_end_element): Rename variable targets to
+	credentials.  Send targets using the credential with each credential in
+	list version.
+
+2009-12-28  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/tasks_sql.h (collate_ip_compare, collate_ip): New functions.
 	(init_manage_process): Add SQL collation function collate_ip.
 	(init_host_iterator): Order by hosts with IP collation.

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-12-28 13:59:45 UTC (rev 6266)
+++ trunk/openvas-manager/src/manage.h	2009-12-28 14:33:17 UTC (rev 6267)
@@ -926,6 +926,12 @@
 char*
 lsc_credential_name (lsc_credential_t);
 
+void
+init_lsc_credential_target_iterator (iterator_t*, const char *, int);
+
+const char*
+lsc_credential_target_iterator_name (iterator_t*);
+
 
 /* Agents. */
 

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-12-28 13:59:45 UTC (rev 6266)
+++ trunk/openvas-manager/src/omp.c	2009-12-28 14:33:17 UTC (rev 6267)
@@ -7508,7 +7508,7 @@
 
       case CLIENT_GET_LSC_CREDENTIALS:
         {
-          iterator_t targets;
+          iterator_t credentials;
           int format;
           assert (strcasecmp ("GET_LSC_CREDENTIALS", element_name) == 0);
 
@@ -7543,13 +7543,13 @@
               SEND_TO_CLIENT_OR_FAIL ("<get_lsc_credentials_response"
                                       " status=\"" STATUS_OK "\""
                                       " status_text=\"" STATUS_OK_TEXT "\">");
-              init_lsc_credential_iterator (&targets,
+              init_lsc_credential_iterator (&credentials,
                                             current_uuid,
                                             /* Attribute sort_order. */
                                             current_int_2,
                                             /* Attribute sort_field. */
                                             current_name);
-              while (next (&targets))
+              while (next (&credentials))
                 {
                   switch (format)
                     {
@@ -7563,13 +7563,13 @@
                           "<type>%s</type>"
                           "<public_key>%s</public_key>"
                           "</lsc_credential>",
-                          lsc_credential_iterator_name (&targets),
-                          lsc_credential_iterator_login (&targets),
-                          lsc_credential_iterator_comment (&targets),
-                          lsc_credential_iterator_in_use (&targets),
-                          lsc_credential_iterator_public_key (&targets)
+                          lsc_credential_iterator_name (&credentials),
+                          lsc_credential_iterator_login (&credentials),
+                          lsc_credential_iterator_comment (&credentials),
+                          lsc_credential_iterator_in_use (&credentials),
+                          lsc_credential_iterator_public_key (&credentials)
                             ? "gen" : "pass",
-                          lsc_credential_iterator_public_key (&targets));
+                          lsc_credential_iterator_public_key (&credentials));
                         break;
                       case 2: /* rpm */
                         SENDF_TO_CLIENT_OR_FAIL
@@ -7581,13 +7581,13 @@
                           "<type>%s</type>"
                           "<package format=\"rpm\">%s</package>"
                           "</lsc_credential>",
-                          lsc_credential_iterator_name (&targets),
-                          lsc_credential_iterator_login (&targets),
-                          lsc_credential_iterator_comment (&targets),
-                          lsc_credential_iterator_in_use (&targets),
-                          lsc_credential_iterator_public_key (&targets)
+                          lsc_credential_iterator_name (&credentials),
+                          lsc_credential_iterator_login (&credentials),
+                          lsc_credential_iterator_comment (&credentials),
+                          lsc_credential_iterator_in_use (&credentials),
+                          lsc_credential_iterator_public_key (&credentials)
                             ? "gen" : "pass",
-                          lsc_credential_iterator_rpm (&targets));
+                          lsc_credential_iterator_rpm (&credentials));
                         break;
                       case 3: /* deb */
                         SENDF_TO_CLIENT_OR_FAIL
@@ -7599,13 +7599,13 @@
                           "<type>%s</type>"
                           "<package format=\"deb\">%s</package>"
                           "</lsc_credential>",
-                          lsc_credential_iterator_name (&targets),
-                          lsc_credential_iterator_login (&targets),
-                          lsc_credential_iterator_comment (&targets),
-                          lsc_credential_iterator_in_use (&targets),
-                          lsc_credential_iterator_public_key (&targets)
+                          lsc_credential_iterator_name (&credentials),
+                          lsc_credential_iterator_login (&credentials),
+                          lsc_credential_iterator_comment (&credentials),
+                          lsc_credential_iterator_in_use (&credentials),
+                          lsc_credential_iterator_public_key (&credentials)
                             ? "gen" : "pass",
-                          lsc_credential_iterator_deb (&targets));
+                          lsc_credential_iterator_deb (&credentials));
                         break;
                       case 4: /* exe */
                         SENDF_TO_CLIENT_OR_FAIL
@@ -7617,33 +7617,54 @@
                           "<type>%s</type>"
                           "<package format=\"exe\">%s</package>"
                           "</lsc_credential>",
-                          lsc_credential_iterator_name (&targets),
-                          lsc_credential_iterator_login (&targets),
-                          lsc_credential_iterator_comment (&targets),
-                          lsc_credential_iterator_in_use (&targets),
-                          lsc_credential_iterator_public_key (&targets)
+                          lsc_credential_iterator_name (&credentials),
+                          lsc_credential_iterator_login (&credentials),
+                          lsc_credential_iterator_comment (&credentials),
+                          lsc_credential_iterator_in_use (&credentials),
+                          lsc_credential_iterator_public_key (&credentials)
                             ? "gen" : "pass",
-                          lsc_credential_iterator_exe (&targets));
+                          lsc_credential_iterator_exe (&credentials));
                         break;
                       default:
-                        SENDF_TO_CLIENT_OR_FAIL
-                         ("<lsc_credential>"
-                          "<name>%s</name>"
-                          "<login>%s</login>"
-                          "<comment>%s</comment>"
-                          "<in_use>%i</in_use>"
-                          "<type>%s</type>"
-                          "</lsc_credential>",
-                          lsc_credential_iterator_name (&targets),
-                          lsc_credential_iterator_login (&targets),
-                          lsc_credential_iterator_comment (&targets),
-                          lsc_credential_iterator_in_use (&targets),
-                          lsc_credential_iterator_public_key (&targets)
-                            ? "gen" : "pass");
-                        break;
+                        {
+                          const char *name;
+                          iterator_t targets;
+
+                          name = lsc_credential_iterator_name (&credentials);
+                          SENDF_TO_CLIENT_OR_FAIL
+                           ("<lsc_credential>"
+                            "<name>%s</name>"
+                            "<login>%s</login>"
+                            "<comment>%s</comment>"
+                            "<in_use>%i</in_use>"
+                            "<type>%s</type>"
+                            "<targets>",
+                            name,
+                            lsc_credential_iterator_login (&credentials),
+                            lsc_credential_iterator_comment (&credentials),
+                            lsc_credential_iterator_in_use (&credentials),
+                            lsc_credential_iterator_public_key (&credentials)
+                              ? "gen" : "pass");
+
+                          init_lsc_credential_target_iterator (&targets,
+                                                               name,
+                                                               /* sort_order. */
+                                                               current_int_2);
+                          while (next (&targets))
+                            SENDF_TO_CLIENT_OR_FAIL
+                             ("<target>"
+                              "<name>%s</name>"
+                              "</target>",
+                              lsc_credential_target_iterator_name (&targets));
+                          cleanup_iterator (&targets);
+
+                          SEND_TO_CLIENT_OR_FAIL ("</targets>"
+                                                  "</lsc_credential>");
+                          break;
+                        }
                     }
                 }
-              cleanup_iterator (&targets);
+              cleanup_iterator (&credentials);
               SEND_TO_CLIENT_OR_FAIL ("</get_lsc_credentials_response>");
             }
           openvas_free_string_var (&current_name);

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-12-28 13:59:45 UTC (rev 6266)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-12-28 14:33:17 UTC (rev 6267)
@@ -9409,7 +9409,7 @@
 {
   int ret;
   if (iterator->done) return -1;
-  ret = (int) sqlite3_column_int (iterator->stmt, 8);
+  ret = (int) sqlite3_column_int (iterator->stmt, 9);
   return ret;
 }
 
@@ -9422,6 +9422,34 @@
 }
 
 /**
+ * @brief Initialise an LSC credential target iterator.
+ *
+ * Iterates over all targets that use the credential.
+ *
+ * @param[in]  iterator   Iterator.
+ * @param[in]  name       Name of credential.
+ * @param[in]  ascending  Whether to sort ascending or descending.
+ */
+void
+init_lsc_credential_target_iterator (iterator_t* iterator, const char *name,
+                                     int ascending)
+{
+  gchar *quoted_name = sql_quote (name);
+  init_iterator (iterator,
+                 "SELECT name FROM targets WHERE lsc_credential ="
+                 " (SELECT ROWID FROM lsc_credentials WHERE name = '%s')"
+                 " ORDER BY name %s;",
+                 quoted_name,
+                 ascending ? "ASC" : "DESC");
+  g_free (quoted_name);
+}
+
+DEF_ACCESS (lsc_credential_target_iterator_name, 0);
+
+
+/* Agents. */
+
+/**
  * @brief Create an agent entry.
  *
  * @param[in]  name           Name of agent.  Must be at least one character long.



More information about the Openvas-commits mailing list