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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 16 13:38:34 CET 2009


Author: mattm
Date: 2009-12-16 13:38:32 +0100 (Wed, 16 Dec 2009)
New Revision: 6147

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.c
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	Separate credential name and login name for LSC credentials.

	* src/tasks_sql.h (DATABASE_VERSION): Increase to 8, for changes to table
	lsc_credentials.
	(create_tables): Add login column to lsc_credentials.
	(create_lsc_credential): Add login param.
	(init_lsc_credential_iterator): Include login.
	(lsc_credential_iterator_login): New function.  Adjust positions of other
	accessors accordingly.

	* src/manage.h: Add headers.

	* src/manage.c (start_task): Send login to scanner instead of name.

	* src/omp.c (client_state_t): Add CLIENT_CREATE_LSC_CREDENTIAL_LOGIN.
	(omp_xml_handle_start_element, omp_xml_handle_start_element)
	(omp_xml_handle_text): Add login to LSC credential handling.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-12-16 11:39:06 UTC (rev 6146)
+++ trunk/openvas-manager/ChangeLog	2009-12-16 12:38:32 UTC (rev 6147)
@@ -1,3 +1,23 @@
+2009-12-16  Matthew Mundell <matthew.mundell at intevation.de>
+
+	Separate credential name and login name for LSC credentials.
+
+	* src/tasks_sql.h (DATABASE_VERSION): Increase to 8, for changes to table
+	lsc_credentials.
+	(create_tables): Add login column to lsc_credentials.
+	(create_lsc_credential): Add login param.
+	(init_lsc_credential_iterator): Include login.
+	(lsc_credential_iterator_login): New function.  Adjust positions of other
+	accessors accordingly.
+
+	* src/manage.h: Add headers.
+
+	* src/manage.c (start_task): Send login to scanner instead of name.
+
+	* src/omp.c (client_state_t): Add CLIENT_CREATE_LSC_CREDENTIAL_LOGIN.
+	(omp_xml_handle_start_element, omp_xml_handle_start_element)
+	(omp_xml_handle_text): Add login to LSC credential handling.
+
 2009-12-15  Matthew Mundell <matthew.mundell at intevation.de>
 
 	* CMakeLists.txt: Add fullstop to Description.

Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c	2009-12-16 11:39:06 UTC (rev 6146)
+++ trunk/openvas-manager/src/manage.c	2009-12-16 12:38:32 UTC (rev 6147)
@@ -834,7 +834,7 @@
         init_lsc_credential_iterator (&credentials, credential, 1, NULL);
         if (next (&credentials))
           {
-            const char *user = lsc_credential_iterator_name (&credentials);
+            const char *user = lsc_credential_iterator_login (&credentials);
             const char *password = lsc_credential_iterator_password (&credentials);
 
             if (sendf_to_server ("SMB Authorization[entry]:SMB login: <|> %s\n",

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-12-16 11:39:06 UTC (rev 6146)
+++ trunk/openvas-manager/src/manage.h	2009-12-16 12:38:32 UTC (rev 6147)
@@ -758,7 +758,7 @@
 /* LSC credentials. */
 
 int
-create_lsc_credential (const char*, const char*, const char*);
+create_lsc_credential (const char*, const char*, const char*, const char*);
 
 int
 delete_lsc_credential (const char*);
@@ -770,6 +770,9 @@
 lsc_credential_iterator_name (iterator_t*);
 
 const char*
+lsc_credential_iterator_login (iterator_t*);
+
+const char*
 lsc_credential_iterator_comment (iterator_t*);
 
 const char*

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-12-16 11:39:06 UTC (rev 6146)
+++ trunk/openvas-manager/src/omp.c	2009-12-16 12:38:32 UTC (rev 6147)
@@ -511,6 +511,7 @@
   CLIENT_CREATE_LSC_CREDENTIAL_COMMENT,
   CLIENT_CREATE_LSC_CREDENTIAL_NAME,
   CLIENT_CREATE_LSC_CREDENTIAL_PASSWORD,
+  CLIENT_CREATE_LSC_CREDENTIAL_LOGIN,
   CLIENT_CREATE_TARGET,
   CLIENT_CREATE_TARGET_COMMENT,
   CLIENT_CREATE_TARGET_HOSTS,
@@ -1239,6 +1240,7 @@
             assert (modify_task_name == NULL);
             openvas_append_string (&modify_task_comment, "");
             openvas_append_string (&modify_task_name, "");
+            openvas_append_string (&current_name, "");
             set_client_state (CLIENT_CREATE_LSC_CREDENTIAL);
           }
         else if (strcasecmp ("CREATE_TASK", element_name) == 0)
@@ -1879,6 +1881,8 @@
       case CLIENT_CREATE_LSC_CREDENTIAL:
         if (strcasecmp ("COMMENT", element_name) == 0)
           set_client_state (CLIENT_CREATE_LSC_CREDENTIAL_COMMENT);
+        else if (strcasecmp ("LOGIN", element_name) == 0)
+          set_client_state (CLIENT_CREATE_LSC_CREDENTIAL_LOGIN);
         else if (strcasecmp ("NAME", element_name) == 0)
           set_client_state (CLIENT_CREATE_LSC_CREDENTIAL_NAME);
         else if (strcasecmp ("PASSWORD", element_name) == 0)
@@ -5200,6 +5204,7 @@
         {
           assert (strcasecmp ("CREATE_LSC_CREDENTIAL", element_name) == 0);
           assert (modify_task_name != NULL);
+          assert (current_name != NULL);
 
           if (strlen (modify_task_name) == 0)
             {
@@ -5208,8 +5213,16 @@
                                   "CREATE_LSC_CREDENTIAL name must both be at"
                                   " least one character long"));
             }
+          else if (strlen (current_name) == 0)
+            {
+              SEND_TO_CLIENT_OR_FAIL
+               (XML_ERROR_SYNTAX ("create_lsc_credential",
+                                  "CREATE_LSC_CREDENTIAL user must both be at"
+                                  " least one character long"));
+            }
           else switch (create_lsc_credential (modify_task_name,
                                               modify_task_comment,
+                                              current_name,
                                               modify_task_parameter))
             {
               case 0:
@@ -5234,6 +5247,7 @@
                 break;
             }
           openvas_free_string_var (&modify_task_comment);
+          openvas_free_string_var (&current_name);
           openvas_free_string_var (&modify_task_name);
           openvas_free_string_var (&modify_task_parameter);
           set_client_state (CLIENT_AUTHENTIC);
@@ -5243,6 +5257,10 @@
         assert (strcasecmp ("COMMENT", element_name) == 0);
         set_client_state (CLIENT_CREATE_LSC_CREDENTIAL);
         break;
+      case CLIENT_CREATE_LSC_CREDENTIAL_LOGIN:
+        assert (strcasecmp ("LOGIN", element_name) == 0);
+        set_client_state (CLIENT_CREATE_LSC_CREDENTIAL);
+        break;
       case CLIENT_CREATE_LSC_CREDENTIAL_NAME:
         assert (strcasecmp ("NAME", element_name) == 0);
         set_client_state (CLIENT_CREATE_LSC_CREDENTIAL);
@@ -6515,12 +6533,14 @@
                         SENDF_TO_CLIENT_OR_FAIL
                          ("<lsc_credential>"
                           "<name>%s</name>"
+                          "<login>%s</login>"
                           "<comment>%s</comment>"
                           "<in_use>%i</in_use>"
                           "<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)
@@ -6531,12 +6551,14 @@
                         SENDF_TO_CLIENT_OR_FAIL
                          ("<lsc_credential>"
                           "<name>%s</name>"
+                          "<login>%s</login>"
                           "<comment>%s</comment>"
                           "<in_use>%i</in_use>"
                           "<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)
@@ -6547,12 +6569,14 @@
                         SENDF_TO_CLIENT_OR_FAIL
                          ("<lsc_credential>"
                           "<name>%s</name>"
+                          "<login>%s</login>"
                           "<comment>%s</comment>"
                           "<in_use>%i</in_use>"
                           "<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)
@@ -6563,12 +6587,14 @@
                         SENDF_TO_CLIENT_OR_FAIL
                          ("<lsc_credential>"
                           "<name>%s</name>"
+                          "<login>%s</login>"
                           "<comment>%s</comment>"
                           "<in_use>%i</in_use>"
                           "<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)
@@ -6579,11 +6605,13 @@
                         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)
@@ -6745,6 +6773,9 @@
       case CLIENT_CREATE_LSC_CREDENTIAL_COMMENT:
         openvas_append_text (&modify_task_comment, text, text_len);
         break;
+      case CLIENT_CREATE_LSC_CREDENTIAL_LOGIN:
+        openvas_append_text (&current_name, text, text_len);
+        break;
       case CLIENT_CREATE_LSC_CREDENTIAL_NAME:
         openvas_append_text (&modify_task_name, text, text_len);
         break;

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-12-16 11:39:06 UTC (rev 6146)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-12-16 12:38:32 UTC (rev 6147)
@@ -36,7 +36,7 @@
 /**
  * @brief Version of the database schema.
  */
-#define DATABASE_VERSION 7
+#define DATABASE_VERSION 8
 
 /**
  * @brief NVT selector type for "all" rule.
@@ -456,7 +456,7 @@
 {
   sql ("CREATE TABLE IF NOT EXISTS config_preferences (id INTEGER PRIMARY KEY, config INTEGER, type, name, value);");
   sql ("CREATE TABLE IF NOT EXISTS configs (id INTEGER PRIMARY KEY, name UNIQUE, nvt_selector, comment, family_count INTEGER, nvt_count INTEGER, families_growing INTEGER, nvts_growing INTEGER);");
-  sql ("CREATE TABLE IF NOT EXISTS lsc_credentials (id INTEGER PRIMARY KEY, name, password, comment, public_key TEXT, private_key TEXT, rpm TEXT, deb TEXT, exe TEXT);");
+  sql ("CREATE TABLE IF NOT EXISTS lsc_credentials (id INTEGER PRIMARY KEY, name, login, password, comment, public_key TEXT, private_key TEXT, rpm TEXT, deb TEXT, exe TEXT);");
   sql ("CREATE TABLE IF NOT EXISTS meta    (id INTEGER PRIMARY KEY, name UNIQUE, value);");
   sql ("CREATE TABLE IF NOT EXISTS nvt_preferences (id INTEGER PRIMARY KEY, name, value);");
   /* nvt_selectors types: 0 all, 1 family, 2 NVT (NVT_SELECTOR_TYPE_* above). */
@@ -7973,6 +7973,8 @@
  * @param[in]  name      Name of LSC credential.  Must be at least one
  *                       character long.
  * @param[in]  comment   Comment on LSC credential.
+ * @param[in]  login     Name of LSC credential user.  Must be at least one
+ *                       character long.
  * @param[in]  password  Password for password-only credential, NULL to
  *                       generate credentials.
  *
@@ -7981,19 +7983,20 @@
  */
 int
 create_lsc_credential (const char* name, const char* comment,
-                       const char* given_password)
+                       const char* login, const char* given_password)
 {
   gchar *quoted_name = sql_nquote (name, strlen (name));
-  gchar *quoted_comment, *public_key, *private_key, *base64;
+  gchar *quoted_comment, *quoted_login, *public_key, *private_key, *base64;
   void *rpm, *deb, *exe;
   gsize rpm_size, deb_size, exe_size;
   int i;
   GRand *rand;
 #define PASSWORD_LENGTH 10
   gchar password[PASSWORD_LENGTH];
-  const char *s = name;
+  const char *s = login;
 
-  assert (strlen (name) > 0);
+  assert (name && strlen (name) > 0);
+  assert (login && strlen (login) > 0);
 
   while (*s) if (!isalnum (*s++)) return 2;
 
@@ -8009,20 +8012,24 @@
 
   if (given_password)
     {
+      gchar *quoted_login = sql_quote (login);
       gchar *quoted_password = sql_quote (given_password);
       gchar *quoted_comment = sql_quote (comment);
 
       /* Password-only credential. */
 
       sql ("INSERT INTO lsc_credentials"
-           " (name, password, comment, public_key, private_key, rpm, deb, exe)"
+           " (name, login, password, comment, public_key, private_key, rpm,"
+           "  deb, exe)"
            " VALUES"
-           " ('%s', '%s', '%s', NULL, NULL, NULL, NULL, NULL)",
+           " ('%s', '%s', '%s', '%s', NULL, NULL, NULL, NULL, NULL)",
            quoted_name,
+           quoted_login,
            quoted_password,
            quoted_comment);
 
       g_free (quoted_name);
+      g_free (quoted_login);
       g_free (quoted_password);
       g_free (quoted_comment);
 
@@ -8038,7 +8045,7 @@
   password[PASSWORD_LENGTH - 1] = '\0';
   g_rand_free (rand);
 
-  if (lsc_user_all_create (name,
+  if (lsc_user_all_create (login,
                            password,
                            &public_key,
                            &private_key,
@@ -8059,18 +8066,20 @@
     sqlite3_stmt* stmt;
     gchar* formatted, *quoted_password;
 
+    quoted_login = sql_quote (login);
     quoted_password = sql_nquote (password, strlen (password));
     if (comment)
       {
         quoted_comment = sql_nquote (comment, strlen (comment));
         formatted = g_strdup_printf ("INSERT INTO lsc_credentials"
-                                     " (name, password, comment,"
+                                     " (name, login, password, comment,"
                                      "  public_key, private_key, rpm, deb, exe)"
                                      " VALUES"
-                                     " ('%s', '%s', '%s',"
+                                     " ('%s', '%s', '%s', '%s',"
                                      "  $public_key, $private_key,"
                                      "  $rpm, $deb, $exe);",
                                      quoted_name,
+                                     quoted_login,
                                      quoted_password,
                                      quoted_comment);
         g_free (quoted_comment);
@@ -8078,17 +8087,19 @@
     else
       {
         formatted = g_strdup_printf ("INSERT INTO lsc_credentials"
-                                     " (name, password, comment,"
+                                     " (name, login, password, comment,"
                                      "  public_key, private_key, rpm, deb, exe)"
                                      " VALUES"
-                                     " ('%s', '%s', '',"
+                                     " ('%s', '%s', '%s', '',"
                                      "  $public_key, $private_key,"
                                      "  $rpm, $deb, $exe);",
                                      quoted_name,
+                                     quoted_login,
                                      quoted_password);
       }
 
     g_free (quoted_name);
+    g_free (quoted_login);
     g_free (quoted_password);
 
     tracef ("   sql: %s\n", formatted);
@@ -8316,7 +8327,7 @@
     {
       gchar *quoted_name = sql_quote (name);
       init_iterator (iterator,
-                     "SELECT name, password, comment, public_key,"
+                     "SELECT name, login, password, comment, public_key,"
                      " private_key, rpm, deb, exe,"
                      " (SELECT count(*) > 0 FROM targets"
                      "  WHERE lsc_credential = lsc_credentials.ROWID)"
@@ -8330,7 +8341,7 @@
     }
   else
     init_iterator (iterator,
-                   "SELECT name, password, comment, public_key,"
+                   "SELECT name, login, password, comment, public_key,"
                    " private_key, rpm, deb, exe,"
                    " (SELECT count(*) > 0 FROM targets"
                    "  WHERE lsc_credential = lsc_credentials.ROWID)"
@@ -8341,22 +8352,23 @@
 }
 
 DEF_ACCESS (lsc_credential_iterator_name, 0);
-DEF_ACCESS (lsc_credential_iterator_password, 1);
+DEF_ACCESS (lsc_credential_iterator_login, 1);
+DEF_ACCESS (lsc_credential_iterator_password, 2);
 
 const char*
 lsc_credential_iterator_comment (iterator_t* iterator)
 {
   const char *ret;
   if (iterator->done) return "";
-  ret = (const char*) sqlite3_column_text (iterator->stmt, 2);
+  ret = (const char*) sqlite3_column_text (iterator->stmt, 3);
   return ret ? ret : "";
 }
 
-DEF_ACCESS (lsc_credential_iterator_public_key, 3);
-DEF_ACCESS (lsc_credential_iterator_private_key, 4);
-DEF_ACCESS (lsc_credential_iterator_rpm, 5);
-DEF_ACCESS (lsc_credential_iterator_deb, 6);
-DEF_ACCESS (lsc_credential_iterator_exe, 7);
+DEF_ACCESS (lsc_credential_iterator_public_key, 4);
+DEF_ACCESS (lsc_credential_iterator_private_key, 5);
+DEF_ACCESS (lsc_credential_iterator_rpm, 6);
+DEF_ACCESS (lsc_credential_iterator_deb, 7);
+DEF_ACCESS (lsc_credential_iterator_exe, 8);
 
 int
 lsc_credential_iterator_in_use (iterator_t* iterator)



More information about the Openvas-commits mailing list