123 #define _XOPEN_SOURCE 129 #include <glib/gstdio.h> 131 #include <sys/stat.h> 138 #include <openvas/misc/openvas_uuid.h> 139 #include <openvas/base/openvas_file.h> 140 #include <openvas/misc/openvas_logging.h> 146 #define G_LOG_DOMAIN "md main" 154 #define CONFIG_ID_FULL_AND_FAST 1 159 #define CONFIG_ID_FULL_AND_FAST_ULTIMATE 2 164 #define CONFIG_ID_FULL_AND_VERY_DEEP 3 169 #define CONFIG_ID_FULL_AND_VERY_DEEP_ULTIMATE 4 196 create_tables_version_4 ()
198 sql (
"CREATE TABLE IF NOT EXISTS config_preferences" 199 " (id INTEGER PRIMARY KEY, config INTEGER, type, name, value);");
200 sql (
"CREATE TABLE IF NOT EXISTS configs" 201 " (id INTEGER PRIMARY KEY, name UNIQUE, nvt_selector, comment," 202 " family_count INTEGER, nvt_count INTEGER, families_growing INTEGER," 203 " nvts_growing INTEGER);");
204 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials" 205 " (id INTEGER PRIMARY KEY, name, password, comment, public_key TEXT," 206 " private_key TEXT, rpm TEXT, deb TEXT, exe TEXT);");
207 sql (
"CREATE TABLE IF NOT EXISTS meta" 208 " (id INTEGER PRIMARY KEY, name UNIQUE, value);");
209 sql (
"CREATE TABLE IF NOT EXISTS nvt_preferences" 210 " (id INTEGER PRIMARY KEY, name, value);");
212 sql (
"CREATE TABLE IF NOT EXISTS nvt_selectors" 213 " (id INTEGER PRIMARY KEY, name, exclude INTEGER, type INTEGER," 214 " family_or_nvt, family);");
215 sql (
"CREATE TABLE IF NOT EXISTS nvts" 216 " (id INTEGER PRIMARY KEY, oid, version, name, summary, description," 217 " copyright, cve, bid, xref, tag, sign_key_ids, category INTEGER," 219 sql (
"CREATE TABLE IF NOT EXISTS report_hosts" 220 " (id INTEGER PRIMARY KEY, report INTEGER, host, start_time, end_time," 221 " attack_state, current_port, max_port);");
222 sql (
"CREATE INDEX IF NOT EXISTS report_hosts_by_report_and_host" 223 " ON report_hosts (report, host);");
224 sql (
"CREATE TABLE IF NOT EXISTS report_results" 225 " (id INTEGER PRIMARY KEY, report INTEGER, result INTEGER);");
226 sql (
"CREATE TABLE IF NOT EXISTS reports" 227 " (id INTEGER PRIMARY KEY, uuid, hidden INTEGER, task INTEGER," 228 " date INTEGER, start_time, end_time, nbefile, comment," 229 " scan_run_status INTEGER);");
230 sql (
"CREATE TABLE IF NOT EXISTS results" 231 " (id INTEGER PRIMARY KEY, task INTEGER, subnet, host, port, nvt, type," 233 sql (
"CREATE TABLE IF NOT EXISTS targets" 234 " (id INTEGER PRIMARY KEY, name, hosts, comment);");
235 sql (
"CREATE TABLE IF NOT EXISTS task_files" 236 " (id INTEGER PRIMARY KEY, task INTEGER, name, content);");
237 sql (
"CREATE TABLE IF NOT EXISTS tasks" 238 " (id INTEGER PRIMARY KEY, uuid, name, hidden INTEGER, time, comment," 239 " description, owner" ", run_status INTEGER," 240 " start_time, end_time, config, target);");
241 sql (
"CREATE TABLE IF NOT EXISTS users" 242 " (id INTEGER PRIMARY KEY, name UNIQUE, password);");
272 sql (
"ALTER TABLE reports ADD COLUMN scan_run_status INTEGER;");
279 sql (
"UPDATE reports SET scan_run_status = '%u';",
282 sql (
"UPDATE reports SET scan_run_status = '%u'" 283 " WHERE start_time IS NULL OR end_time IS NULL;",
286 sql (
"UPDATE reports SET scan_run_status = '%u'" 287 " WHERE end_time IS NOT NULL;",
329 const char *category_string;
333 category = atoi (category_string);
334 sql (
"UPDATE nvts SET category = %i WHERE ROWID = %llu;",
372 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials (name, comment, rpm, deb, dog);");
381 sql (
"DELETE from lsc_credentials;");
387 sql (
"ALTER TABLE lsc_credentials ADD COLUMN password;");
388 sql (
"ALTER TABLE lsc_credentials ADD COLUMN public_key TEXT;");
389 sql (
"ALTER TABLE lsc_credentials ADD COLUMN private_key TEXT;");
390 sql (
"ALTER TABLE lsc_credentials ADD COLUMN exe TEXT;");
425 sql (
"ALTER TABLE nvt_selectors ADD COLUMN family;");
432 sql (
"UPDATE nvt_selectors SET family =" 433 " (SELECT family FROM nvts where oid = '%s')" 434 " WHERE name = '%s';",
435 quoted_nvt, quoted_name);
436 g_free (quoted_name);
460 "SELECT rowid, config, type, name, value" 461 " FROM config_preferences_4;");
467 sql (
"INSERT into config_preferences (id, config, type, name, value)" 468 " VALUES (%llu, %llu, %s, %s, %s);",
474 g_free (quoted_type);
475 g_free (quoted_name);
476 g_free (quoted_value);
479 sql (
"DROP TABLE config_preferences_4;");
483 "SELECT rowid, name, nvt_selector, comment, family_count," 484 " nvt_count, families_growing, nvts_growing" 491 sql (
"INSERT into configs" 492 " (id, name, nvt_selector, comment, family_count, nvt_count," 493 " families_growing, nvts_growing)" 495 " (%llu, %s, %s, %s, %llu, %llu, %llu, %llu);",
504 g_free (quoted_name);
505 g_free (quoted_nvt_selector);
506 g_free (quoted_comment);
509 sql (
"DROP TABLE configs_4;");
513 "SELECT rowid, name, password, comment, public_key," 514 " private_key, rpm, deb, exe" 515 " FROM lsc_credentials_4;");
526 sql (
"INSERT into lsc_credentials" 527 " (id, name, password, comment, public_key, private_key, rpm, deb," 530 " (%llu, %s, %s, %s, %s, %s, %s, %s, %s);",
540 g_free (quoted_name);
541 g_free (quoted_password);
542 g_free (quoted_comment);
543 g_free (quoted_public_key);
544 g_free (quoted_private_key);
550 sql (
"DROP TABLE lsc_credentials_4;");
553 init_iterator (&rows,
"SELECT rowid, name, value FROM meta_4;");
558 sql (
"INSERT into meta (id, name, value)" 559 " VALUES (%llu, %s, %s);",
563 g_free (quoted_name);
564 g_free (quoted_value);
567 sql (
"DROP TABLE meta_4;");
570 init_iterator (&rows,
"SELECT rowid, name, value FROM nvt_preferences_4;");
575 sql (
"INSERT into nvt_preferences (id, name, value)" 576 " VALUES (%llu, %s, %s);",
580 g_free (quoted_name);
581 g_free (quoted_value);
584 sql (
"DROP TABLE nvt_preferences_4;");
588 "SELECT rowid, name, exclude, type, family_or_nvt, family" 589 " FROM nvt_selectors_4;");
595 sql (
"INSERT into nvt_selectors" 596 " (id, name, exclude, type, family_or_nvt, family)" 598 " (%llu, %s, %llu, %llu, %s, %s);",
603 quoted_family_or_nvt,
605 g_free (quoted_name);
606 g_free (quoted_family_or_nvt);
607 g_free (quoted_family);
610 sql (
"DROP TABLE nvt_selectors_4;");
614 "SELECT rowid, oid, version, name, summary, description," 615 " copyright, cve, bid, xref, tag, sign_key_ids, category," 638 gchar* pos = quoted_description;
639 while ((pos = strchr (pos,
';')))
643 sql (
"INSERT into nvts" 644 " (id, oid, version, name, summary, description, copyright, cve," 645 " bid, xref, tag, sign_key_ids, category, family)" 647 " (%llu, %s, %s, %s, %s, %s, %s, %s, %s, %s," 648 " %s, %s, %llu, %s);",
664 g_free (quoted_version);
665 g_free (quoted_name);
666 g_free (quoted_summary);
667 g_free (quoted_description);
668 g_free (quoted_copyright);
671 g_free (quoted_xref);
673 g_free (quoted_sign_key_ids);
674 g_free (quoted_family);
677 sql (
"DROP TABLE nvts_4;");
681 "SELECT rowid, report, host, start_time, end_time," 682 " attack_state, current_port, max_port" 683 " FROM report_hosts_4;");
692 sql (
"INSERT into report_hosts" 693 " (id, report, host, start_time, end_time, attack_state," 694 " current_port, max_port)" 696 " (%llu, %llu, %s, %s, %s, %s, %s, %s);",
705 g_free (quoted_host);
706 g_free (quoted_start_time);
707 g_free (quoted_end_time);
708 g_free (quoted_attack_state);
709 g_free (quoted_current_port);
710 g_free (quoted_max_port);
713 sql (
"DROP TABLE report_hosts_4;");
716 init_iterator (&rows,
"SELECT rowid, report, result FROM report_results_4;");
719 sql (
"INSERT into report_results (id, report, result)" 720 " VALUES (%llu, %llu, %llu)",
726 sql (
"DROP TABLE report_results_4;");
730 "SELECT rowid, uuid, hidden, task, date, start_time, end_time," 731 " nbefile, comment, scan_run_status" 740 sql (
"INSERT into reports" 741 " (id, uuid, hidden, task, date, start_time, end_time, nbefile," 742 " comment, scan_run_status)" 744 " (%llu, %s, %llu, %llu, %llu, %s, %s, %s, %s, %llu);",
755 g_free (quoted_uuid);
756 g_free (quoted_start_time);
757 g_free (quoted_end_time);
758 g_free (quoted_nbefile);
759 g_free (quoted_comment);
762 sql (
"DROP TABLE reports_4;");
766 "SELECT rowid, task, subnet, host, port, nvt, type," 777 sql (
"INSERT into results" 778 " (id, task, subnet, host, port, nvt, type, description)" 780 " (%llu, %llu, %s, %s, %s, %s, %s, %s);",
789 g_free (quoted_subnet);
790 g_free (quoted_host);
791 g_free (quoted_port);
793 g_free (quoted_type);
794 g_free (quoted_description);
797 sql (
"DROP TABLE results_4;");
800 init_iterator (&rows,
"SELECT rowid, name, hosts, comment FROM targets_4;");
806 sql (
"INSERT into targets (id, name, hosts, comment)" 807 " VALUES (%llu, %s, %s, %s);",
812 g_free (quoted_name);
813 g_free (quoted_hosts);
814 g_free (quoted_comment);
817 sql (
"DROP TABLE targets_4;");
820 init_iterator (&rows,
"SELECT rowid, task, name, content FROM task_files_4;");
825 sql (
"INSERT into task_files (id, task, name, content)" 826 " VALUES (%llu, %llu, %s, %s);",
831 g_free (quoted_name);
832 g_free (quoted_content);
835 sql (
"DROP TABLE task_files_4;");
839 "SELECT rowid, uuid, name, hidden, time, comment, description," 840 " owner, run_status, start_time, end_time, config, target" 853 sql (
"INSERT into tasks" 854 " (id, uuid, name, hidden, time, comment, description, owner," 855 " run_status, start_time, end_time, config, target)" 857 " (%llu, %s, %s, %llu, %s, %s, %s, %llu, %llu, %s," 872 g_free (quoted_uuid);
873 g_free (quoted_name);
874 g_free (quoted_time);
875 g_free (quoted_comment);
876 g_free (quoted_description);
877 g_free (quoted_start_time);
878 g_free (quoted_end_time);
879 g_free (quoted_config);
880 g_free (quoted_target);
883 sql (
"DROP TABLE tasks_4;");
886 init_iterator (&rows,
"SELECT rowid, name, password FROM users_4;");
891 sql (
"INSERT into users (id, name, password)" 892 " VALUES (%llu, %s, %s);",
896 g_free (quoted_name);
897 g_free (quoted_password);
900 sql (
"DROP TABLE users_4;");
935 sql (
"CREATE TABLE IF NOT EXISTS nvt_preferences (name, value);");
936 sql (
"CREATE TABLE IF NOT EXISTS task_files (task INTEGER, name, content);");
940 sql (
"ALTER TABLE config_preferences RENAME TO config_preferences_4;");
941 sql (
"ALTER TABLE configs RENAME TO configs_4;");
942 sql (
"ALTER TABLE lsc_credentials RENAME TO lsc_credentials_4;");
943 sql (
"ALTER TABLE meta RENAME TO meta_4;");
944 sql (
"ALTER TABLE nvt_preferences RENAME TO nvt_preferences_4;");
945 sql (
"ALTER TABLE nvt_selectors RENAME TO nvt_selectors_4;");
946 sql (
"ALTER TABLE nvts RENAME TO nvts_4;");
947 sql (
"ALTER TABLE report_hosts RENAME TO report_hosts_4;");
948 sql (
"ALTER TABLE report_results RENAME TO report_results_4;");
949 sql (
"ALTER TABLE reports RENAME TO reports_4;");
950 sql (
"ALTER TABLE results RENAME TO results_4;");
951 sql (
"ALTER TABLE targets RENAME TO targets_4;");
952 sql (
"ALTER TABLE task_files RENAME TO task_files_4;");
953 sql (
"ALTER TABLE tasks RENAME TO tasks_4;");
954 sql (
"ALTER TABLE users RENAME TO users_4;");
958 create_tables_version_4 ();
987 if (
sql_int (
"SELECT COUNT(*) = 0 FROM configs" 988 " WHERE name = '%s';",
989 predefined_config_name)
990 &&
sql_int (
"SELECT COUNT(*) = 1 FROM configs" 992 predefined_config_id))
998 sql (
"INSERT into configs (nvt_selector, comment, family_count," 999 " nvt_count, nvts_growing, families_growing)" 1000 " SELECT nvt_selector, comment, family_count," 1001 " nvt_count, nvts_growing, families_growing" 1003 " WHERE id = %llu;",
1004 predefined_config_id);
1009 sql (
"UPDATE config_preferences SET config = %llu WHERE config = %llu;",
1011 predefined_config_id);
1012 name =
sql_string (
"SELECT name FROM configs WHERE id = %llu;",
1013 predefined_config_id);
1022 sql (
"DELETE FROM configs WHERE id = %llu;",
1023 predefined_config_id);
1024 sql (
"UPDATE configs SET name = '%s' WHERE id = %llu;",
1027 g_free (quoted_name);
1057 if (
sql_int (
"SELECT COUNT(*) = 0 OR id == 1 FROM configs" 1058 " WHERE name = 'Full and fast';")
1059 &&
sql_int (
"SELECT COUNT(*) = 0 OR id == 2 FROM configs" 1060 " WHERE name = 'Full and fast ultimate';")
1061 &&
sql_int (
"SELECT COUNT(*) = 0 OR id == 3 FROM configs" 1062 " WHERE name = 'Full and very deep';")
1063 &&
sql_int (
"SELECT COUNT(*) = 0 OR id == 4 FROM configs" 1064 " WHERE name = 'Full and very deep ultimate';"))
1078 g_warning (
"%s: a predefined config has moved from the standard location," 1091 update_all_config_caches ();
1124 sql (
"ALTER TABLE targets ADD COLUMN lsc_credential INTEGER;");
1125 sql (
"UPDATE targets SET lsc_credential = 0;");
1158 sql (
"ALTER TABLE lsc_credentials ADD COLUMN login;");
1159 sql (
"UPDATE lsc_credentials SET login = name;");
1195 sql (
"CREATE TABLE IF NOT EXISTS escalators" 1196 " (id INTEGER PRIMARY KEY, name UNIQUE, comment, event INTEGER," 1197 " condition INTEGER, method INTEGER);");
1199 sql (
"CREATE TABLE IF NOT EXISTS agents" 1200 " (id INTEGER PRIMARY KEY, name UNIQUE, comment, installer TEXT," 1201 " howto_install TEXT, howto_use TEXT);");
1205 sql (
"ALTER TABLE targets ADD COLUMN owner INTEGER;");
1206 sql (
"UPDATE targets SET owner = NULL;");
1208 sql (
"ALTER TABLE configs ADD COLUMN owner INTEGER;");
1209 sql (
"UPDATE configs SET owner = NULL;");
1211 sql (
"ALTER TABLE lsc_credentials ADD COLUMN owner INTEGER;");
1212 sql (
"UPDATE lsc_credentials SET owner = NULL;");
1214 sql (
"ALTER TABLE escalators ADD COLUMN owner INTEGER;");
1215 sql (
"UPDATE escalators SET owner = NULL;");
1217 sql (
"ALTER TABLE reports ADD COLUMN owner INTEGER;");
1218 sql (
"UPDATE reports SET owner = NULL;");
1220 sql (
"ALTER TABLE agents ADD COLUMN owner INTEGER;");
1221 sql (
"UPDATE agents SET owner = NULL;");
1227 sql (
"UPDATE tasks SET owner = CAST (owner AS INTEGER);"),
1252 uuid_file = g_build_filename (OPENVAS_STATE_DIR,
"users", name,
"uuid", NULL);
1253 if (g_file_test (uuid_file, G_FILE_TEST_EXISTS))
1258 if (g_file_get_contents (uuid_file, &uuid, &size, NULL))
1260 if (strlen (uuid) < 36)
1302 sql (
"ALTER TABLE users RENAME TO users_9;");
1304 sql (
"CREATE TABLE users" 1305 " (id INTEGER PRIMARY KEY, uuid UNIQUE, name, password);");
1307 init_iterator (&rows,
"SELECT id, name, password FROM users_9;");
1308 while (
next (&rows))
1310 gchar *quoted_name, *quoted_password, *uuid;
1315 uuid = openvas_uuid_make ();
1326 sql (
"INSERT into users (id, uuid, name, password)" 1327 " VALUES (%llu, '%s', %s, %s);",
1333 g_free (quoted_name);
1334 g_free (quoted_password);
1337 sql (
"DROP TABLE users_9;");
1375 sql (
"ALTER TABLE tasks RENAME TO tasks_10;");
1377 sql (
"CREATE TABLE tasks" 1378 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, hidden INTEGER," 1379 " time, comment, description, run_status INTEGER, start_time," 1380 " end_time, config INTEGER, target INTEGER);");
1382 sql (
"INSERT into tasks" 1383 " (id, uuid, owner, name, hidden, time, comment, description," 1384 " run_status, start_time, end_time, config, target)" 1386 " id, uuid, owner, name, hidden, time, comment, description," 1387 " run_status, start_time, end_time," 1388 " (SELECT id FROM configs WHERE configs.name = tasks_10.config)," 1389 " (SELECT id FROM targets WHERE targets.name = tasks_10.target)" 1392 sql (
"DROP TABLE tasks_10;");
1430 sql (
"ALTER TABLE agents RENAME TO agents_11;");
1432 sql (
"CREATE TABLE agents" 1433 " (id INTEGER PRIMARY KEY, owner INTEGER, name, comment," 1434 " installer TEXT, howto_install TEXT, howto_use TEXT);");
1436 sql (
"INSERT into agents" 1437 " (id, owner, name, comment, installer, howto_install, howto_use)" 1439 " id, owner, name, comment, installer, howto_install, howto_use" 1440 " FROM agents_11;");
1442 sql (
"DROP TABLE agents_11;");
1444 sql (
"ALTER TABLE configs RENAME TO configs_11;");
1446 sql (
"CREATE TABLE configs" 1447 " (id INTEGER PRIMARY KEY, owner INTEGER, name, nvt_selector, comment," 1448 " family_count INTEGER, nvt_count INTEGER, families_growing INTEGER," 1449 " nvts_growing INTEGER);");
1451 sql (
"INSERT into configs" 1452 " (id, owner, name, nvt_selector, comment, family_count, nvt_count," 1453 " families_growing, nvts_growing)" 1455 " id, owner, name, nvt_selector, comment, family_count, nvt_count," 1456 " families_growing, nvts_growing" 1457 " FROM configs_11;");
1459 sql (
"DROP TABLE configs_11;");
1461 sql (
"ALTER TABLE escalators RENAME TO escalators_11;");
1463 sql (
"CREATE TABLE escalators" 1464 " (id INTEGER PRIMARY KEY, owner INTEGER, name, comment, event INTEGER," 1465 " condition INTEGER, method INTEGER);");
1467 sql (
"INSERT into escalators" 1468 " (id, owner, name, comment, event, condition, method)" 1470 " id, owner, name, comment, event, condition, method" 1471 " FROM escalators_11;");
1473 sql (
"DROP TABLE escalators_11;");
1513 init_iterator (&rows,
"SELECT distinct name FROM nvt_selectors;");
1514 while (
next (&rows))
1516 gchar *quoted_name, *uuid;
1521 uuid = openvas_uuid_make ();
1531 sql (
"UPDATE nvt_selectors SET name = '%s' WHERE name = %s;",
1535 sql (
"UPDATE configs SET nvt_selector = '%s' WHERE nvt_selector = %s;",
1540 g_free (quoted_name);
1544 if (
sql_int (
"SELECT COUNT(*) FROM nvt_selectors WHERE name = '" 1546 sql (
"DELETE FROM nvt_selectors WHERE name = 'All';");
1548 sql (
"UPDATE nvt_selectors" 1550 " WHERE name = 'All';");
1552 sql (
"UPDATE configs" 1554 " WHERE nvt_selector = 'All';");
1589 sql (
"ALTER TABLE results ADD COLUMN uuid;");
1590 sql (
"UPDATE results SET uuid = make_uuid();");
1625 sql (
"ALTER TABLE tasks ADD COLUMN schedule INTEGER;");
1626 sql (
"ALTER TABLE tasks ADD COLUMN schedule_next_time;");
1627 sql (
"UPDATE tasks SET schedule = 0, schedule_next_time = 0;");
1662 sql (
"CREATE TABLE IF NOT EXISTS schedules" 1663 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment," 1664 " first_time, period, duration);");
1666 sql (
"ALTER TABLE schedules ADD COLUMN period_months;");
1667 sql (
"UPDATE schedules SET period_months = 0;");
1672 sql (
"UPDATE tasks SET comment = '';");
1709 sql (
"ALTER TABLE nvts ADD COLUMN cvss_base;");
1710 sql (
"ALTER TABLE nvts ADD COLUMN risk_factor;");
1715 while (
next (&rows))
1717 gchar *tags, *cvss_base;
1724 sql (
"UPDATE nvts SET cvss_base = '%s', risk_factor = '%s', tag = '%s'" 1725 " WHERE id = %llu;",
1726 cvss_base ? cvss_base :
"",
1753 if (
sql_int (
"SELECT count(*) FROM config_preferences" 1754 " WHERE config = %llu" 1756 " 'Ping Host[checkbox]:Mark unrechable Hosts as dead" 1760 sql (
"INSERT into config_preferences (config, type, name, value)" 1761 " VALUES (%llu, 'PLUGINS_PREFS'," 1762 " 'Ping Host[checkbox]:Mark unrechable Hosts as dead (not scanning)'," 1794 if (
sql_int (
"SELECT count(*) FROM nvt_selectors WHERE name =" 1796 " AND family_or_nvt = '1.3.6.1.4.1.25623.1.0.100315';")
1799 sql (
"INSERT into nvt_selectors" 1800 " (name, exclude, type, family_or_nvt, family)" 1804 " '1.3.6.1.4.1.25623.1.0.100315', 'Port scanners');");
1850 sql (
"ALTER TABLE agents RENAME TO agents_18;");
1852 sql (
"CREATE TABLE agents" 1853 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 1854 " installer TEXT, howto_install TEXT, howto_use TEXT);");
1856 sql (
"INSERT into agents" 1857 " (id, uuid, owner, name, comment, installer, howto_install, howto_use)" 1859 " id, make_uuid (), owner, name, comment, installer, howto_install, howto_use" 1860 " FROM agents_18;");
1862 sql (
"DROP TABLE agents_18;");
1864 sql (
"ALTER TABLE configs RENAME TO configs_18;");
1866 sql (
"CREATE TABLE configs" 1867 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name," 1868 " nvt_selector, comment, family_count INTEGER, nvt_count INTEGER," 1869 " families_growing INTEGER, nvts_growing INTEGER);");
1871 sql (
"INSERT into configs" 1872 " (id, uuid, owner, name, nvt_selector, comment, family_count," 1873 " nvt_count, families_growing, nvts_growing)" 1875 " id, make_uuid (), owner, name, nvt_selector, comment, family_count," 1876 " nvt_count, families_growing, nvts_growing" 1877 " FROM configs_18;");
1879 sql (
"DROP TABLE configs_18;");
1881 sql (
"ALTER TABLE escalators RENAME TO escalators_18;");
1883 sql (
"CREATE TABLE escalators" 1884 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 1885 " event INTEGER, condition INTEGER, method INTEGER);");
1887 sql (
"INSERT into escalators" 1888 " (id, uuid, owner, name, comment, event, condition, method)" 1890 " id, make_uuid (), owner, name, comment, event, condition, method" 1891 " FROM escalators_18;");
1893 sql (
"DROP TABLE escalators_18;");
1895 sql (
"ALTER TABLE lsc_credentials RENAME TO lsc_credentials_18;");
1897 sql (
"CREATE TABLE lsc_credentials" 1898 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, login," 1899 " password, comment, public_key TEXT, private_key TEXT, rpm TEXT," 1900 " deb TEXT, exe TEXT);");
1902 sql (
"INSERT into lsc_credentials" 1903 " (id, uuid, owner, name, login, password, comment, public_key," 1904 " private_key, rpm, deb, exe)" 1906 " id, make_uuid (), owner, name, login, password, comment, public_key," 1907 " private_key, rpm, deb, exe" 1908 " FROM lsc_credentials_18;");
1910 sql (
"DROP TABLE lsc_credentials_18;");
1912 sql (
"ALTER TABLE targets RENAME TO targets_18;");
1914 sql (
"CREATE TABLE targets" 1915 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, hosts," 1916 " comment, lsc_credential INTEGER);");
1918 sql (
"INSERT into targets" 1919 " (id, uuid, owner, name, hosts, comment, lsc_credential)" 1921 " id, make_uuid (), owner, name, hosts, comment, lsc_credential" 1922 " FROM targets_18;");
1924 sql (
"DROP TABLE targets_18;");
1928 sql (
"UPDATE configs" 1932 sql (
"UPDATE configs" 1936 sql (
"UPDATE configs" 1940 sql (
"UPDATE configs" 1945 sql (
"UPDATE configs" 1947 " WHERE name = 'empty';");
1949 sql (
"UPDATE targets" 1950 " SET uuid = 'b493b7a8-7489-11df-a3ec-002264764cea'" 1951 " WHERE name = 'Localhost';");
1990 sql (
"ALTER TABLE agents ADD COLUMN installer_64 TEXT;");
1991 sql (
"ALTER TABLE agents ADD COLUMN installer_signature_64 TEXT;");
1992 sql (
"ALTER TABLE agents ADD COLUMN installer_trust INTEGER;");
1995 while (
next (&rows))
1999 gsize installer_size;
2003 sql (
"UPDATE agents SET" 2004 " installer_trust = %i," 2005 " installer_64 = installer," 2006 " installer_signature_64 = ''" 2011 stmt =
sql_prepare (
"UPDATE agents SET installer = $1" 2012 " WHERE id = %llu;",
2019 g_warning (
"%s: sql_prepare failed\n", __FUNCTION__);
2025 if (strlen (installer_64) > 0)
2026 installer = (gchar*) g_base64_decode (installer_64, &installer_size);
2029 installer = g_strdup (
"");
2037 g_warning (
"%s: sql_bind_text failed\n", __FUNCTION__);
2047 while ((ret =
sql_exec (stmt)) > 0);
2050 g_warning (
"%s: sql_exec failed\n", __FUNCTION__);
2093 sql (
"ALTER TABLE agents ADD COLUMN installer_filename TEXT;");
2133 sql (
"CREATE TABLE IF NOT EXISTS report_formats" 2134 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, extension," 2135 " content_type, summary, description);");
2139 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'CPE';")
2141 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2142 " extension, content_type)" 2143 " VALUES (make_uuid (), NULL, 'CPE'," 2144 " 'Common Product Enumeration CSV table.'," 2145 " 'CPE stands for Common Product Enumeration. It is a structured naming scheme for\n" 2146 "information technology systems, platforms, and packages. In other words: CPE\n" 2147 "provides a unique identifier for virtually any software product that is known for\n" 2148 "a vulnerability.\n" 2150 "The CPE dictionary is maintained by MITRE and NIST. MITRE also maintains CVE\n" 2151 "(Common Vulnerability Enumeration) and other relevant security standards.\n" 2153 "The report selects all CPE tables from the results and forms a single table\n" 2154 "as a comma separated values file.\n'," 2155 " 'csv', 'text/csv');");
2157 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'HTML';")
2159 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2160 " extension, content_type)" 2161 " VALUES (make_uuid (), NULL, 'HTML', 'Single page HTML report.'," 2162 " 'A single HTML page listing results of a scan. Style information is embedded in\n" 2163 "the HTML, so the page is suitable for viewing in a browser as is.\n'," 2164 " 'html', 'text/html');");
2166 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'ITG';")
2168 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2169 " extension, content_type)" 2170 " VALUES (make_uuid (), NULL, 'ITG'," 2171 " 'German \"IT-Grundschutz-Kataloge\" report.'," 2172 " 'Tabular report on the German \"IT-Grundschutz-Kataloge\",\n" 2173 "as published and maintained by the German Federal Agency for IT-Security.\n'," 2174 " 'csv', 'text/csv');");
2176 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'LaTeX';")
2178 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2179 " extension, content_type)" 2180 " VALUES (make_uuid (), NULL, 'LaTeX'," 2181 " 'LaTeX source file.'," 2182 " 'Report as LaTeX source file for further processing.\n'," 2183 " 'tex', 'text/plain');");
2185 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'NBE';")
2187 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2188 " extension, content_type)" 2189 " VALUES (make_uuid (), NULL, 'NBE', 'Legacy OpenVAS report.'," 2190 " 'The traditional OpenVAS Scanner text based format.'," 2191 " 'nbe', 'text/plain');");
2193 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'PDF';")
2195 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2196 " extension, content_type)" 2197 " VALUES (make_uuid (), NULL, 'PDF'," 2198 " 'Portable Document Format report.'," 2199 " 'Scan results in Portable Document Format (PDF).'," 2200 "'pdf', 'application/pdf');");
2202 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'TXT';")
2204 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2205 " extension, content_type)" 2206 " VALUES (make_uuid (), NULL, 'TXT', 'Plain text report.'," 2207 " 'Plain text report, best viewed with fixed font size.'," 2208 " 'txt', 'text/plain');");
2210 if (
sql_int (
"SELECT count(*) FROM report_formats WHERE name = 'XML';")
2212 sql (
"INSERT into report_formats (uuid, owner, name, summary, description," 2213 " extension, content_type)" 2214 " VALUES (make_uuid (), NULL, 'XML'," 2215 " 'Raw XML report.'," 2216 " 'Complete scan report in OpenVAS Manager XML format.'," 2217 " 'xml', 'text/xml');");
2221 sql (
"UPDATE report_formats SET uuid = 'a0704abb-2120-489f-959f-251c9f4ffebd'" 2222 " WHERE name = 'CPE'");
2224 sql (
"UPDATE report_formats SET uuid = 'b993b6f5-f9fb-4e6e-9c94-dd46c00e058d'" 2225 " WHERE name = 'HTML'");
2227 sql (
"UPDATE report_formats SET uuid = '929884c6-c2c4-41e7-befb-2f6aa163b458'" 2228 " WHERE name = 'ITG'");
2230 sql (
"UPDATE report_formats SET uuid = '9f1ab17b-aaaa-411a-8c57-12df446f5588'" 2231 " WHERE name = 'LaTeX'");
2233 sql (
"UPDATE report_formats SET uuid = 'f5c2a364-47d2-4700-b21d-0a7693daddab'" 2234 " WHERE name = 'NBE'");
2236 sql (
"UPDATE report_formats SET uuid = '1a60a67e-97d0-4cbf-bc77-f71b08e7043d'" 2237 " WHERE name = 'PDF'");
2239 sql (
"UPDATE report_formats SET uuid = '19f6f1b3-7128-4433-888c-ccc764fe6ed5'" 2240 " WHERE name = 'TXT'");
2242 sql (
"UPDATE report_formats SET uuid = 'd5da9f67-8551-4e51-807b-b6a873d70e34'" 2243 " WHERE name = 'XML'");
2247 init_iterator (&rows,
"SELECT id, uuid, owner, name FROM report_formats;");
2248 while (
next (&rows))
2250 const char *name, *uuid;
2251 gchar *old_dir, *new_dir;
2252 int user_format = 0;
2257 if (
sql_int (
"SELECT owner is NULL FROM report_formats" 2258 " WHERE id = %llu;",
2262 old_dir = g_build_filename (OPENVAS_SYSCONF_DIR,
2264 "global_report_formats",
2267 new_dir = g_build_filename (OPENVAS_SYSCONF_DIR,
2269 "global_report_formats",
2276 owner_uuid =
sql_string (
"SELECT uuid FROM users" 2277 " WHERE id = %llu;",
2279 if (owner_uuid == NULL)
2281 g_warning (
"%s: owner missing from users table\n", __FUNCTION__);
2286 old_dir = g_build_filename (OPENVAS_SYSCONF_DIR,
2292 new_dir = g_build_filename (OPENVAS_SYSCONF_DIR,
2301 if (g_file_test (new_dir, G_FILE_TEST_EXISTS))
2303 if (g_file_test (old_dir, G_FILE_TEST_EXISTS)
2304 && openvas_file_remove_recurse (old_dir))
2305 g_warning (
"%s: failed to remove %s\n",
2311 else if ((g_file_test (old_dir, G_FILE_TEST_EXISTS)
2313 && rename (old_dir, new_dir))
2315 g_warning (
"%s: renaming %s to %s failed: %s\n",
2363 sql (
"ALTER TABLE report_formats ADD COLUMN signature;");
2364 sql (
"UPDATE report_formats SET signature = '';");
2366 sql (
"ALTER TABLE report_formats ADD COLUMN trust;");
2402 sql (
"UPDATE tasks SET owner = NULL where owner = 0;"),
2438 init_iterator (&rows,
"SELECT id, name, value FROM nvt_preferences;");
2439 while (
next (&rows))
2442 int type_start = -1, type_end = -1, count;
2447 count = sscanf (name,
"%*[^[][%nradio%n]:", &type_start, &type_end);
2448 if (count == 0 && type_start > 0 && type_end > 0)
2451 gchar **split, **point, *quoted_value;
2458 split = g_strsplit (value,
";", 0);
2459 string = g_string_new (
"");
2463 if (strlen (*point))
2468 g_string_append_c (
string,
';');
2469 g_string_append (
string, *point);
2475 quoted_value =
sql_nquote (string->str, string->len);
2476 g_string_free (
string, TRUE);
2477 sql (
"UPDATE nvt_preferences SET value = '%s' WHERE id = %llu",
2480 g_free (quoted_value);
2486 "SELECT id, name, value FROM config_preferences" 2487 " WHERE type = 'PLUGINS_PREFS';");
2488 while (
next (&rows))
2491 int type_start = -1, type_end = -1, count;
2496 count = sscanf (name,
"%*[^[][%nradio%n]:", &type_start, &type_end);
2497 if (count == 0 && type_start > 0 && type_end > 0)
2500 gchar **split, **point, *quoted_value;
2507 split = g_strsplit (value,
";", 0);
2508 string = g_string_new (
"");
2512 if (strlen (*point))
2517 g_string_append_c (
string,
';');
2518 g_string_append (
string, *point);
2524 quoted_value =
sql_nquote (string->str, string->len);
2525 g_string_free (
string, TRUE);
2526 sql (
"UPDATE config_preferences SET value = '%s' WHERE id = %llu",
2529 g_free (quoted_value);
2565 sql (
"ALTER TABLE report_formats ADD column trust_time;");
2566 sql (
"UPDATE report_formats SET trust_time = %i;", time (NULL));
2600 sql (
"ALTER TABLE reports ADD column slave_progress;");
2601 sql (
"UPDATE reports SET slave_progress = 0;");
2603 sql (
"ALTER TABLE tasks ADD column slave;");
2604 sql (
"UPDATE tasks SET slave = 0;");
2637 sql (
"ALTER TABLE report_formats ADD COLUMN flags INTEGER;");
2638 sql (
"UPDATE report_formats SET flags = 1;");
2671 sql (
"ALTER TABLE reports ADD COLUMN slave_task_uuid;");
2672 sql (
"UPDATE reports SET slave_task_uuid = ''");
2705 sql (
"ALTER TABLE agents ADD column installer_trust_time;");
2706 sql (
"UPDATE agents SET installer_trust_time = %i;", time (NULL));
2740 sql (
"UPDATE tasks SET slave = 0;");
2773 sql (
"CREATE TABLE IF NOT EXISTS report_format_params" 2774 " (id INTEGER PRIMARY KEY, report_format, name, value);");
2778 sql (
"ALTER TABLE report_format_params ADD column type INTEGER;");
2779 sql (
"UPDATE report_format_params SET type = 3;");
2812 sql (
"ALTER TABLE report_format_params ADD column type_min;");
2813 sql (
"UPDATE report_format_params SET type_min = %lli;", LLONG_MIN);
2815 sql (
"ALTER TABLE report_format_params ADD column type_max;");
2816 sql (
"UPDATE report_format_params SET type_max = %lli;", LLONG_MAX);
2818 sql (
"ALTER TABLE report_format_params ADD column type_regex;");
2819 sql (
"UPDATE report_format_params SET type_regex = '';");
2821 sql (
"ALTER TABLE report_format_params ADD column fallback;");
2822 sql (
"UPDATE report_format_params SET fallback = value;");
2841 if (
sql_int (
"SELECT count(*) FROM config_preferences" 2842 " WHERE config = %llu" 2844 " 'Login configurations[checkbox]:NTLMSSP';",
2847 sql (
"INSERT into config_preferences (config, type, name, value)" 2848 " VALUES (%llu, 'PLUGINS_PREFS'," 2849 " 'Login configurations[checkbox]:NTLMSSP'," 2917 sql (
"ALTER TABLE targets ADD column smb_lsc_credential;");
2918 sql (
"UPDATE targets SET smb_lsc_credential = lsc_credential;");
2941 sql (
"INSERT INTO targets" 2942 " (uuid, owner, name, hosts, comment, lsc_credential," 2943 " smb_lsc_credential)" 2944 " SELECT make_uuid (), owner, uniquify ('target', '%s', owner, '')," 2945 " hosts, comment, lsc_credential, smb_lsc_credential" 2946 " FROM targets WHERE id = %llu;",
2949 g_free (quoted_name);
2962 char *scanner_range, *quoted_scanner_range;
2980 sql (
"UPDATE tasks SET" 2981 " target = (SELECT id FROM targets WHERE name = 'Localhost')," 2982 " config = (SELECT id FROM configs WHERE name = 'Full and fast')" 2983 " WHERE uuid = '343435d6-91b0-11de-9478-ffd71f4c6f29';");
2989 sql (
"ALTER TABLE targets ADD column port_range;");
2990 sql (
"UPDATE targets SET port_range = NULL;");
2992 scanner_range =
sql_string (
"SELECT value FROM nvt_preferences" 2993 " WHERE name = 'port_range'");
2996 quoted_scanner_range =
sql_quote (scanner_range);
2997 free (scanner_range);
3000 quoted_scanner_range = NULL;
3002 init_iterator (&tasks,
"SELECT id, target, config FROM tasks;");
3003 while (
next (&tasks))
3005 char *config_range, *quoted_config_range;
3010 if (
sql_int (
"SELECT port_range IS NULL FROM targets WHERE id = %llu;",
3018 name =
sql_string (
"SELECT name || ' Migration' FROM targets" 3019 " WHERE id = %llu;",
3025 sql (
"UPDATE tasks SET target = %llu WHERE id = %llu",
3030 config_range =
sql_string (
"SELECT value FROM config_preferences" 3031 " WHERE config = %llu" 3032 " AND name = 'port_range';",
3037 quoted_config_range =
sql_quote (config_range);
3038 free (config_range);
3041 quoted_config_range = NULL;
3043 sql (
"UPDATE targets SET port_range = '%s'" 3044 " WHERE id = %llu;",
3046 ? quoted_config_range
3047 : (quoted_scanner_range ? quoted_scanner_range :
"default"),
3050 free (quoted_config_range);
3054 sql (
"UPDATE targets SET port_range = 'default' WHERE port_range IS NULL;");
3056 sql (
"DELETE FROM config_preferences WHERE name = 'port_range';");
3057 sql (
"DELETE FROM nvt_preferences WHERE name = 'port_range';");
3059 free (quoted_scanner_range);
3094 sql (
"UPDATE tasks SET" 3095 " target = (SELECT id FROM targets WHERE name = 'Localhost')," 3096 " config = (SELECT id FROM configs WHERE name = 'Full and fast')" 3097 " WHERE uuid = '343435d6-91b0-11de-9478-ffd71f4c6f29';");
3116 gchar *old_dir, *new_dir;
3135 old_dir = g_build_filename (OPENVAS_SYSCONF_DIR,
3137 "global_report_formats",
3140 openvas_file_remove_recurse (old_dir);
3145 new_dir = g_build_filename (OPENVAS_STATE_DIR,
3149 if (g_mkdir_with_parents (new_dir, 0755 ))
3151 g_warning (
"%s: failed to create dir %s", __FUNCTION__, new_dir);
3157 old_dir = g_build_filename (OPENVAS_SYSCONF_DIR,
3163 g_mkdir_with_parents (old_dir, 0755 );
3167 gchar *standard_out = NULL;
3168 gchar *standard_err = NULL;
3171 cmd = (gchar **) g_malloc (4 *
sizeof (gchar *));
3172 cmd[0] = g_strdup (
"mv");
3176 g_debug (
"%s: Spawning in .: %s %s %s\n",
3177 __FUNCTION__, cmd[0], cmd[1], cmd[2]);
3178 if ((g_spawn_sync (
".",
3181 G_SPAWN_SEARCH_PATH,
3189 || (WIFEXITED (exit_status) == 0)
3190 || WEXITSTATUS (exit_status))
3192 g_warning (
"%s: failed rename: %d (WIF %i, WEX %i)",
3195 WIFEXITED (exit_status),
3196 WEXITSTATUS (exit_status));
3197 g_debug (
"%s: stdout: %s\n", __FUNCTION__, standard_out);
3198 g_debug (
"%s: stderr: %s\n", __FUNCTION__, standard_err);
3248 sql (
"UPDATE configs SET comment =" 3249 " 'Most NVT''s; optimized by using previously collected information.'" 3252 sql (
"UPDATE configs SET comment =" 3253 " 'Most NVT''s including those that can stop services/hosts;" 3254 " optimized by using previously collected information.'" 3257 sql (
"UPDATE configs SET comment =" 3258 " 'Most NVT''s; don''t trust previously collected information; slow.'" 3261 sql (
"UPDATE configs SET comment =" 3262 " 'Most NVT''s including those that can stop services/hosts;" 3263 " don''t trust previously collected information; slow.'" 3283 sql (
"UPDATE config_preferences SET value = 'yes'" 3284 " WHERE config = %llu" 3285 " AND type = 'SERVER_PREFS'" 3286 " AND name = 'unscanned_closed';",
3355 sql (
"UPDATE report_formats SET signature = NULL" 3356 " WHERE uuid = 'a0704abb-2120-489f-959f-251c9f4ffebd';");
3357 sql (
"UPDATE report_formats SET signature = NULL" 3358 " WHERE uuid = 'b993b6f5-f9fb-4e6e-9c94-dd46c00e058d';");
3359 sql (
"UPDATE report_formats SET signature = NULL" 3360 " WHERE uuid = '929884c6-c2c4-41e7-befb-2f6aa163b458';");
3361 sql (
"UPDATE report_formats SET signature = NULL" 3362 " WHERE uuid = '9f1ab17b-aaaa-411a-8c57-12df446f5588';");
3363 sql (
"UPDATE report_formats SET signature = NULL" 3364 " WHERE uuid = 'f5c2a364-47d2-4700-b21d-0a7693daddab';");
3365 sql (
"UPDATE report_formats SET signature = NULL" 3366 " WHERE uuid = '1a60a67e-97d0-4cbf-bc77-f71b08e7043d';");
3367 sql (
"UPDATE report_formats SET signature = NULL" 3368 " WHERE uuid = '19f6f1b3-7128-4433-888c-ccc764fe6ed5';");
3369 sql (
"UPDATE report_formats SET signature = NULL" 3370 " WHERE uuid = 'd5da9f67-8551-4e51-807b-b6a873d70e34';");
3405 sql (
"ALTER TABLE tasks ADD column config_location INTEGER;");
3406 sql (
"ALTER TABLE tasks ADD column target_location INTEGER;");
3407 sql (
"ALTER TABLE tasks ADD column schedule_location INTEGER;");
3408 sql (
"ALTER TABLE tasks ADD column slave_location INTEGER;");
3410 sql (
"UPDATE tasks SET" 3417 sql (
"CREATE TABLE IF NOT EXISTS task_escalators" 3418 " (id INTEGER PRIMARY KEY, task INTEGER, escalator INTEGER);");
3420 sql (
"ALTER TABLE task_escalators ADD column escalator_location INTEGER;");
3422 sql (
"UPDATE task_escalators" 3459 sql (
"CREATE TABLE IF NOT EXISTS targets_trash" 3460 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, hosts," 3461 " comment, lsc_credential INTEGER, smb_lsc_credential INTEGER," 3462 " port_range, ssh_location INTEGER, smb_location INTEGER);");
3464 sql (
"ALTER TABLE targets ADD column ssh_port;");
3465 sql (
"ALTER TABLE targets_trash ADD column ssh_port;");
3467 sql (
"UPDATE targets SET ssh_port = 22" 3468 " WHERE lsc_credential > 0;");
3469 sql (
"UPDATE targets_trash SET ssh_port = 22" 3470 " WHERE lsc_credential > 0;");
3506 g_warning (
"%s: failed to chmod %s: %s",
3509 : OPENVAS_STATE_DIR
"/mgr/tasks.db",
3546 sql (
"ALTER TABLE tasks ADD column upload_result_count;");
3547 sql (
"UPDATE tasks SET upload_result_count = -1;");
3580 sql (
"UPDATE targets SET hosts = clean_hosts (hosts);");
3581 sql (
"UPDATE targets_trash SET hosts = clean_hosts (hosts);");
3615 sql (
"CREATE TABLE IF NOT EXISTS task_preferences" 3616 " (id INTEGER PRIMARY KEY, task INTEGER, name, value);");
3618 sql (
"INSERT INTO task_preferences (task, name, value)" 3619 " SELECT tasks.id, config_preferences.name, config_preferences.value" 3620 " FROM tasks, config_preferences" 3621 " WHERE tasks.config = config_preferences.config" 3622 " AND (config_preferences.name = 'max_checks'" 3623 " OR config_preferences.name = 'max_hosts')");
3657 sql (
"CREATE TABLE IF NOT EXISTS report_host_details" 3658 " (id INTEGER PRIMARY KEY, report_host INTEGER, source_type," 3659 " source_name, source_description, name, value);");
3661 sql (
"UPDATE report_host_details SET name = 'App' WHERE name = 'app';");
3698 sql (
"UPDATE results SET uuid = 'cb291ec0-1b0d-11df-8aa1-002264764cea'" 3699 " WHERE host = 'localhost';");
3701 sql (
"UPDATE results SET host = '127.0.0.1'" 3702 " WHERE uuid = 'cb291ec0-1b0d-11df-8aa1-002264764cea';");
3704 sql (
"UPDATE report_hosts SET host = '127.0.0.1'" 3705 " WHERE host = 'localhost';");
3740 sql (
"ALTER TABLE task_preferences RENAME TO task_preferences_49;");
3744 sql (
"CREATE TABLE IF NOT EXISTS task_preferences" 3745 " (id INTEGER PRIMARY KEY, task INTEGER, name, value);");
3749 sql (
"INSERT into task_preferences" 3750 " (id, task, name, value)" 3752 " id, task, name, value" 3753 " FROM task_preferences_49;");
3757 sql (
"DROP TABLE task_preferences_49;");
3790 sql (
"ALTER TABLE users ADD column timezone;");
3791 sql (
"UPDATE users SET timezone = NULL;");
3825 g_critical (
"%s: failed to create convert", __FUNCTION__);
3833 sql (
"UPDATE report_hosts SET start_time = convert (start_time);");
3834 sql (
"UPDATE report_hosts SET end_time = convert (end_time);");
3835 sql (
"UPDATE reports SET start_time = convert (start_time);");
3836 sql (
"UPDATE reports SET end_time = convert (end_time);");
3837 sql (
"UPDATE tasks SET start_time = convert (start_time);");
3838 sql (
"UPDATE tasks SET end_time = convert (end_time);");
3872 sql (
"CREATE TABLE IF NOT EXISTS overrides" 3873 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 3874 " creation_time, modification_time, text, hosts, port, threat," 3875 " new_threat, task INTEGER, result INTEGER);");
3877 sql (
"ALTER TABLE overrides ADD column end_time;");
3878 sql (
"UPDATE overrides SET end_time = 0;");
3912 sql (
"CREATE TABLE IF NOT EXISTS notes" 3913 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 3914 " creation_time, modification_time, text, hosts, port, threat," 3915 " task INTEGER, result INTEGER);");
3917 sql (
"ALTER TABLE notes ADD column end_time;");
3918 sql (
"UPDATE notes SET end_time = 0;");
3942 dir = g_build_filename (OPENVAS_DATA_DIR,
3944 "global_report_formats",
3948 if (g_file_test (dir, G_FILE_TEST_EXISTS) && openvas_file_remove_recurse (dir))
3950 g_warning (
"%s: failed to remove dir %s", __FUNCTION__, dir);
3956 sql (
"UPDATE report_formats" 3958 " WHERE uuid = '%s';",
3992 "5ceff8ba-1f62-11e1-ab9f-406186ea4fc5"))
3999 "6c248850-1f62-11e1-b082-406186ea4fc5"))
4006 "77bd6c4a-1f62-11e1-abf0-406186ea4fc5"))
4013 "7fcc3a1a-1f62-11e1-86bf-406186ea4fc5"))
4020 "9ca6fe72-1f62-11e1-9e7c-406186ea4fc5"))
4027 "a0b5bfb2-1f62-11e1-85db-406186ea4fc5"))
4034 "a3810a62-1f62-11e1-9219-406186ea4fc5"))
4041 "a994b278-1f62-11e1-96ac-406186ea4fc5"))
4059 #define MIGRATE_55_TO_56_RANGE(type, start, end) \ 4060 sql ("INSERT INTO port_ranges" \ 4061 " (uuid, port_list, type, start, \"end\", comment, exclude)" \ 4063 " (make_uuid (), %llu, %i," \ 4064 " '" G_STRINGIFY (start) "'," \ 4065 " '" G_STRINGIFY (end) "'," \ 4076 if (
sql_int (
"SELECT count(*) FROM port_lists" 4081 sql (
"INSERT INTO port_lists (uuid, owner, name, comment)" 4754 sql (
"ALTER TABLE targets_trash ADD COLUMN port_list_location;");
4755 sql (
"UPDATE targets_trash" 4760 sql (
"CREATE TABLE IF NOT EXISTS port_lists" 4761 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment);");
4762 sql (
"CREATE TABLE IF NOT EXISTS port_lists_trash" 4763 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment);");
4764 sql (
"CREATE TABLE IF NOT EXISTS port_ranges" 4765 " (id INTEGER PRIMARY KEY, uuid UNIQUE, port_list INTEGER, type," 4766 " start, end, comment, exclude);");
4767 sql (
"CREATE TABLE IF NOT EXISTS port_ranges_trash" 4768 " (id INTEGER PRIMARY KEY, uuid UNIQUE, port_list INTEGER, type," 4769 " start, end, comment, exclude);");
4775 init_iterator (&rows,
"SELECT id, owner, name, port_range FROM targets;");
4776 while (
next (&rows))
4784 if (range && strcmp (range,
"default"))
4797 sql (
"INSERT INTO port_lists (uuid, owner, name, comment)" 4798 " VALUES (make_uuid (), %llu, '%s', %llu)",
4803 g_free (quoted_name);
4810 gchar **split, **point;
4812 while (*range && isblank (*range)) range++;
4814 split = g_strsplit (range,
",", 0);
4821 hyphen = strchr (*point,
'-');
4829 sql (
"INSERT INTO port_ranges" 4830 " (uuid, port_list, type, start, \"end\", comment," 4833 " (make_uuid (), %llu, %i, %s, %s, '', 0)",
4843 sql (
"INSERT INTO port_ranges" 4844 " (uuid, port_list, type, start, \"end\", comment," 4847 " (make_uuid (), %llu, %i, %s, NULL, ''," 4860 sql (
"UPDATE targets SET port_range" 4861 " = (SELECT id FROM port_lists" 4863 " WHERE id = %llu;",
4870 sql (
"UPDATE targets SET" 4871 " port_range = (SELECT id FROM port_lists" 4872 " WHERE comment = targets.id)" 4874 " != (SELECT id FROM port_lists" 4877 sql (
"UPDATE port_lists SET" 4878 " comment = 'Migrated from target '" 4879 " || (SELECT targets.name FROM targets" 4880 " WHERE port_lists.id = targets.port_range)" 4887 "SELECT id, owner, name, port_range FROM targets_trash;");
4888 while (
next (&rows))
4896 if (range && strcmp (range,
"default"))
4909 sql (
"INSERT INTO port_lists_trash (uuid, owner, name, comment)" 4910 " VALUES (make_uuid (), %llu, '%s', %llu)",
4915 g_free (quoted_name);
4922 gchar **split, **point;
4924 while (*range && isblank (*range)) range++;
4926 split = g_strsplit (range,
",", 0);
4933 hyphen = strchr (*point,
'-');
4941 sql (
"INSERT INTO port_ranges_trash" 4942 " (uuid, port_list, type, start, \"end\", comment," 4945 " (make_uuid (), %llu, %i, %s, %s, '', 0)",
4955 sql (
"INSERT INTO port_ranges_trash" 4956 " (uuid, port_list, type, start, \"end\", comment," 4959 " (make_uuid (), %llu, %i, %s, NULL, ''," 4972 sql (
"UPDATE targets_trash SET port_range" 4973 " = (SELECT id FROM port_lists" 4976 " WHERE id = %llu;",
4985 sql (
"UPDATE targets_trash SET" 4986 " port_range = (SELECT id FROM port_lists_trash" 4987 " WHERE comment = targets_trash.id)" 4989 " != (SELECT id FROM port_lists" 4992 sql (
"UPDATE port_lists_trash SET" 4993 " comment = 'Migrated from trashcan target '" 4994 " || (SELECT targets_trash.name FROM targets_trash" 4995 " WHERE port_lists_trash.id = targets_trash.port_range)" 5031 sql (
"CREATE TABLE IF NOT EXISTS escalator_condition_data" 5032 " (id INTEGER PRIMARY KEY, escalator INTEGER, name, data);");
5033 sql (
"CREATE TABLE IF NOT EXISTS escalator_condition_data_trash" 5034 " (id INTEGER PRIMARY KEY, escalator INTEGER, name, data);");
5035 sql (
"CREATE TABLE IF NOT EXISTS escalator_event_data" 5036 " (id INTEGER PRIMARY KEY, escalator INTEGER, name, data);");
5037 sql (
"CREATE TABLE IF NOT EXISTS escalator_event_data_trash" 5038 " (id INTEGER PRIMARY KEY, escalator INTEGER, name, data);");
5039 sql (
"CREATE TABLE IF NOT EXISTS escalator_method_data" 5040 " (id INTEGER PRIMARY KEY, escalator INTEGER, name, data);");
5041 sql (
"CREATE TABLE IF NOT EXISTS escalator_method_data_trash" 5042 " (id INTEGER PRIMARY KEY, escalator INTEGER, name, data);");
5043 sql (
"CREATE TABLE IF NOT EXISTS escalators" 5044 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 5045 " event INTEGER, condition INTEGER, method INTEGER);");
5046 sql (
"CREATE TABLE IF NOT EXISTS escalators_trash" 5047 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 5048 " event INTEGER, condition INTEGER, method INTEGER);");
5049 sql (
"CREATE TABLE IF NOT EXISTS task_escalators" 5050 " (id INTEGER PRIMARY KEY, task INTEGER, escalator INTEGER," 5051 " escalator_location INTEGER);");
5055 sql (
"CREATE TABLE alert_condition_data" 5056 " (id INTEGER PRIMARY KEY, alert INTEGER, name, data);");
5058 "escalator",
"alert");
5059 sql (
"DROP TABLE escalator_condition_data;");
5065 sql (
"CREATE TABLE alert_event_data" 5066 " (id INTEGER PRIMARY KEY, alert INTEGER, name, data);");
5068 "escalator",
"alert");
5069 sql (
"DROP TABLE escalator_event_data;");
5071 sql (
"CREATE TABLE alert_event_data_trash" 5072 " (id INTEGER PRIMARY KEY, alert INTEGER, name, data);");
5074 "escalator",
"alert");
5075 sql (
"DROP TABLE escalator_event_data_trash;");
5077 sql (
"CREATE TABLE alert_method_data" 5078 " (id INTEGER PRIMARY KEY, alert INTEGER, name, data);");
5080 "escalator",
"alert");
5081 sql (
"DROP TABLE escalator_method_data;");
5083 sql (
"CREATE TABLE alert_method_data_trash" 5084 " (id INTEGER PRIMARY KEY, alert INTEGER, name, data);");
5086 "escalator",
"alert");
5087 sql (
"DROP TABLE escalator_method_data_trash;");
5089 sql (
"CREATE TABLE alerts" 5090 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 5091 " event INTEGER, condition INTEGER, method INTEGER);");
5093 "escalator",
"alert");
5094 sql (
"DROP TABLE escalators;");
5096 sql (
"CREATE TABLE alerts_trash" 5097 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 5098 " event INTEGER, condition INTEGER, method INTEGER);");
5100 "escalator",
"alert");
5101 sql (
"DROP TABLE escalators_trash;");
5103 sql (
"CREATE TABLE task_alerts_56" 5104 " (id INTEGER PRIMARY KEY, task INTEGER, alert INTEGER," 5105 " escalator_location INTEGER);");
5107 "escalator",
"alert");
5108 sql (
"DROP TABLE task_escalators;");
5110 sql (
"CREATE TABLE task_alerts" 5111 " (id INTEGER PRIMARY KEY, task INTEGER, alert INTEGER," 5112 " alert_location INTEGER);");
5114 "escalator_location",
"alert_location");
5115 sql (
"DROP TABLE task_alerts_56;");
5150 sql (
"CREATE TABLE IF NOT EXISTS agents_trash" 5151 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 5152 " installer TEXT, installer_64 TEXT, installer_filename," 5153 " installer_signature_64 TEXT, installer_trust INTEGER," 5154 " installer_trust_time, howto_install TEXT, howto_use TEXT);");
5158 sql (
"ALTER TABLE targets ADD COLUMN creation_time;");
5159 sql (
"ALTER TABLE targets ADD COLUMN modification_time;");
5160 sql (
"UPDATE targets SET creation_time = 0, modification_time = 0;");
5162 sql (
"ALTER TABLE targets_trash ADD COLUMN creation_time;");
5163 sql (
"ALTER TABLE targets_trash ADD COLUMN modification_time;");
5164 sql (
"UPDATE targets_trash SET creation_time = 0, modification_time = 0;");
5166 sql (
"ALTER TABLE agents ADD COLUMN creation_time;");
5167 sql (
"ALTER TABLE agents ADD COLUMN modification_time;");
5168 sql (
"UPDATE agents SET creation_time = 0, modification_time = 0;");
5170 sql (
"ALTER TABLE agents_trash ADD COLUMN creation_time;");
5171 sql (
"ALTER TABLE agents_trash ADD COLUMN modification_time;");
5172 sql (
"UPDATE agents_trash SET creation_time = 0, modification_time = 0;");
5208 sql (
"UPDATE alert_method_data" 5209 " SET data = '5ceff8ba-1f62-11e1-ab9f-406186ea4fc5'" 5210 " WHERE data = 'a0704abb-2120-489f-959f-251c9f4ffebd';");
5212 sql (
"UPDATE alert_method_data" 5213 " SET data = '6c248850-1f62-11e1-b082-406186ea4fc5'" 5214 " WHERE data = 'b993b6f5-f9fb-4e6e-9c94-dd46c00e058d';");
5216 sql (
"UPDATE alert_method_data" 5217 " SET data = '77bd6c4a-1f62-11e1-abf0-406186ea4fc5'" 5218 " WHERE data = '929884c6-c2c4-41e7-befb-2f6aa163b458';");
5220 sql (
"UPDATE alert_method_data" 5221 " SET data = '7fcc3a1a-1f62-11e1-86bf-406186ea4fc5'" 5222 " WHERE data = '9f1ab17b-aaaa-411a-8c57-12df446f5588';");
5224 sql (
"UPDATE alert_method_data" 5225 " SET data = '9ca6fe72-1f62-11e1-9e7c-406186ea4fc5'" 5226 " WHERE data = 'f5c2a364-47d2-4700-b21d-0a7693daddab';");
5228 sql (
"UPDATE alert_method_data" 5229 " SET data = 'a0b5bfb2-1f62-11e1-85db-406186ea4fc5'" 5230 " WHERE data = '1a60a67e-97d0-4cbf-bc77-f71b08e7043d';");
5232 sql (
"UPDATE alert_method_data" 5233 " SET data = 'a3810a62-1f62-11e1-9219-406186ea4fc5'" 5234 " WHERE data = '19f6f1b3-7128-4433-888c-ccc764fe6ed5';");
5236 sql (
"UPDATE alert_method_data" 5237 " SET data = 'a994b278-1f62-11e1-96ac-406186ea4fc5'" 5238 " WHERE data = 'd5da9f67-8551-4e51-807b-b6a873d70e34';");
5273 sql (
"INSERT INTO task_preferences (task, name, value)" 5274 " SELECT id, 'in_assets', 'yes' FROM tasks;");
5309 sql (
"ALTER TABLE alerts ADD COLUMN filter INTEGER;");
5310 sql (
"UPDATE alerts SET filter = 0;");
5312 sql (
"ALTER TABLE alerts_trash ADD COLUMN filter INTEGER;");
5313 sql (
"UPDATE alerts_trash SET filter = 0;");
5315 sql (
"ALTER TABLE alerts_trash ADD COLUMN filter_location INTEGER;");
5316 sql (
"UPDATE alerts_trash SET filter_location = 0;");
5351 sql (
"ALTER TABLE reports ADD COLUMN highs;");
5352 sql (
"ALTER TABLE reports ADD COLUMN mediums;");
5353 sql (
"ALTER TABLE reports ADD COLUMN lows;");
5354 sql (
"ALTER TABLE reports ADD COLUMN logs;");
5355 sql (
"ALTER TABLE reports ADD COLUMN fps;");
5356 sql (
"ALTER TABLE reports ADD COLUMN override_highs;");
5357 sql (
"ALTER TABLE reports ADD COLUMN override_mediums;");
5358 sql (
"ALTER TABLE reports ADD COLUMN override_lows;");
5359 sql (
"ALTER TABLE reports ADD COLUMN override_logs;");
5360 sql (
"ALTER TABLE reports ADD COLUMN override_fps;");
5362 sql (
"UPDATE reports SET highs = -1, override_highs = -1;");
5397 sql (
"CREATE TABLE IF NOT EXISTS schedules_trash" 5398 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment," 5399 " first_time, period, period_months, duration);");
5403 sql (
"ALTER TABLE schedules ADD COLUMN timezone;");
5404 sql (
"ALTER TABLE schedules ADD COLUMN initial_offset;");
5406 sql (
"UPDATE schedules" 5407 " SET timezone = (SELECT users.timezone FROM users" 5408 " WHERE id = schedules.owner);");
5410 sql (
"UPDATE schedules SET initial_offset = current_offset (timezone);");
5412 sql (
"ALTER TABLE schedules_trash ADD COLUMN timezone;");
5413 sql (
"ALTER TABLE schedules_trash ADD COLUMN initial_offset;");
5415 sql (
"UPDATE schedules_trash" 5416 " SET timezone = (SELECT users.timezone FROM users" 5417 " WHERE id = schedules_trash.owner);");
5419 sql (
"UPDATE schedules_trash" 5420 " SET initial_offset = current_offset (timezone);");
5455 sql (
"ALTER TABLE results ADD COLUMN report;");
5457 sql (
"UPDATE results SET report = (SELECT report FROM report_results" 5458 " WHERE result = results.id);");
5460 sql (
"CREATE INDEX IF NOT EXISTS results_by_report_host" 5461 " ON results (report, host);");
5496 sql (
"UPDATE results SET report = (SELECT report FROM report_results" 5497 " WHERE result = results.id);");
5499 sql (
"REINDEX results_by_report_host;");
5534 sql (
"ALTER TABLE schedules ADD COLUMN creation_time;");
5535 sql (
"ALTER TABLE schedules ADD COLUMN modification_time;");
5536 sql (
"UPDATE schedules SET creation_time = 0, modification_time = 0;");
5538 sql (
"ALTER TABLE schedules_trash ADD COLUMN creation_time;");
5539 sql (
"ALTER TABLE schedules_trash ADD COLUMN modification_time;");
5540 sql (
"UPDATE schedules_trash SET creation_time = 0, modification_time = 0;");
5575 sql (
"ALTER TABLE tasks ADD COLUMN creation_time;");
5576 sql (
"ALTER TABLE tasks ADD COLUMN modification_time;");
5577 sql (
"UPDATE tasks SET creation_time = 0, modification_time = 0;");
5612 sql (
"CREATE TABLE IF NOT EXISTS slaves_trash" 5613 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment, host," 5614 " port, login, password);");
5618 sql (
"ALTER TABLE slaves ADD COLUMN creation_time;");
5619 sql (
"ALTER TABLE slaves ADD COLUMN modification_time;");
5620 sql (
"UPDATE slaves SET creation_time = 0, modification_time = 0;");
5622 sql (
"ALTER TABLE slaves_trash ADD COLUMN creation_time;");
5623 sql (
"ALTER TABLE slaves_trash ADD COLUMN modification_time;");
5624 sql (
"UPDATE slaves_trash SET creation_time = 0, modification_time = 0;");
5659 sql (
"CREATE TABLE IF NOT EXISTS report_formats_trash" 5660 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, extension," 5661 " content_type, summary, description, signature, trust INTEGER," 5662 " trust_time, flags INTEGER, original_uuid);");
5666 sql (
"ALTER TABLE report_formats ADD COLUMN creation_time;");
5667 sql (
"ALTER TABLE report_formats ADD COLUMN modification_time;");
5668 sql (
"UPDATE report_formats SET creation_time = 0, modification_time = 0;");
5670 sql (
"ALTER TABLE report_formats_trash ADD COLUMN creation_time;");
5671 sql (
"ALTER TABLE report_formats_trash ADD COLUMN modification_time;");
5672 sql (
"UPDATE report_formats_trash SET" 5673 " creation_time = 0, modification_time = 0;");
5708 sql (
"ALTER TABLE port_lists ADD COLUMN creation_time;");
5709 sql (
"ALTER TABLE port_lists ADD COLUMN modification_time;");
5710 sql (
"UPDATE port_lists SET creation_time = 0, modification_time = 0;");
5712 sql (
"ALTER TABLE port_lists_trash ADD COLUMN creation_time;");
5713 sql (
"ALTER TABLE port_lists_trash ADD COLUMN modification_time;");
5714 sql (
"UPDATE port_lists_trash SET" 5715 " creation_time = 0, modification_time = 0;");
5750 sql (
"ALTER TABLE alerts ADD COLUMN creation_time;");
5751 sql (
"ALTER TABLE alerts ADD COLUMN modification_time;");
5752 sql (
"UPDATE alerts SET creation_time = 0, modification_time = 0;");
5754 sql (
"ALTER TABLE alerts_trash ADD COLUMN creation_time;");
5755 sql (
"ALTER TABLE alerts_trash ADD COLUMN modification_time;");
5756 sql (
"UPDATE alerts_trash SET" 5757 " creation_time = 0, modification_time = 0;");
5792 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials_trash" 5793 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, login," 5794 " password, comment, public_key TEXT, private_key TEXT, rpm TEXT," 5795 " deb TEXT, exe TEXT);");
5799 sql (
"ALTER TABLE lsc_credentials ADD COLUMN creation_time;");
5800 sql (
"ALTER TABLE lsc_credentials ADD COLUMN modification_time;");
5801 sql (
"UPDATE lsc_credentials SET creation_time = 0, modification_time = 0;");
5803 sql (
"ALTER TABLE lsc_credentials_trash ADD COLUMN creation_time;");
5804 sql (
"ALTER TABLE lsc_credentials_trash ADD COLUMN modification_time;");
5805 sql (
"UPDATE lsc_credentials_trash SET" 5806 " creation_time = 0, modification_time = 0;");
5841 sql (
"CREATE TABLE IF NOT EXISTS configs_trash" 5842 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name," 5843 " nvt_selector, comment, family_count INTEGER, nvt_count INTEGER," 5844 " families_growing INTEGER, nvts_growing INTEGER);");
5848 sql (
"ALTER TABLE configs ADD COLUMN creation_time;");
5849 sql (
"ALTER TABLE configs ADD COLUMN modification_time;");
5850 sql (
"UPDATE configs SET creation_time = 0, modification_time = 0;");
5852 sql (
"ALTER TABLE configs_trash ADD COLUMN creation_time;");
5853 sql (
"ALTER TABLE configs_trash ADD COLUMN modification_time;");
5854 sql (
"UPDATE configs_trash SET creation_time = 0, modification_time = 0;");
5889 sql (
"ALTER TABLE nvts ADD COLUMN uuid;");
5890 sql (
"UPDATE nvts SET uuid = oid;");
5892 sql (
"ALTER TABLE nvts ADD COLUMN comment;");
5893 sql (
"UPDATE nvts SET comment = '';");
5895 sql (
"ALTER TABLE nvts ADD COLUMN creation_time;");
5896 sql (
"ALTER TABLE nvts ADD COLUMN modification_time;");
5897 sql (
"UPDATE nvts SET" 5898 " creation_time = parse_time (tag (tag, 'creation_date'))," 5899 " modification_time = parse_time (tag (tag, 'last_modification'));");
5932 sql (
"CREATE TABLE IF NOT EXISTS permissions" 5933 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 5934 " resource_type, resource, resource_uuid, resource_location," 5935 " subject_type, subject, creation_time, modification_time);");
5937 sql (
"CREATE TABLE IF NOT EXISTS task_users" 5938 " (id INTEGER PRIMARY KEY, task INTEGER, user INTEGER," 5939 " actions INTEGER);");
5945 sql (
"INSERT INTO permissions" 5946 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 5947 " resource_location, subject_type, subject, creation_time," 5948 " modification_time)" 5949 " SELECT make_uuid ()," 5950 " (SELECT owner FROM tasks WHERE id = task)," 5951 " 'get', '', 'task', task," 5952 " (SELECT uuid FROM tasks WHERE id = task)," 5953 " " G_STRINGIFY (
LOCATION_TABLE)
", 'user', user, m_now (), m_now ()" 5954 " FROM task_users;");
5956 sql (
"DROP TABLE task_users;");
5988 sql (
"DELETE FROM %s.meta WHERE name = \"nvts_checksum\";",
5992 sql (
"UPDATE %s.meta SET name = \"nvts_feed_version\"" 5993 " WHERE name = \"nvts_md5sum\";",
6027 sql (
"ALTER TABLE users ADD COLUMN owner;");
6028 sql (
"ALTER TABLE users ADD COLUMN comment;");
6029 sql (
"ALTER TABLE users ADD COLUMN creation_time;");
6030 sql (
"ALTER TABLE users ADD COLUMN modification_time;");
6031 sql (
"ALTER TABLE users ADD COLUMN role;");
6032 sql (
"ALTER TABLE users ADD COLUMN hosts;");
6033 sql (
"ALTER TABLE users ADD COLUMN hosts_allow;");
6034 sql (
"UPDATE users SET" 6037 " creation_time = 0," 6038 " modification_time = 0," 6042 " hosts_allow = 2;");
6074 sql (
"UPDATE schedules" 6076 " WHERE duration = -1;");
6078 sql (
"UPDATE schedules" 6080 " WHERE period = -1;");
6082 sql (
"UPDATE schedules_trash" 6084 " WHERE duration = -1;");
6086 sql (
"UPDATE schedules_trash" 6088 " WHERE period = -1;");
6121 sql (
"DELETE FROM nvt_selectors WHERE " 6123 " AND family_or_nvt='1.3.6.1.4.1.25623.1.0.80091';");
6126 sql (
"INSERT INTO config_preferences (config, type, name, value)" 6127 " VALUES ((SELECT id FROM configs WHERE uuid = '" 6130 " 'Ping Host[checkbox]:Mark unrechable Hosts as dead (not scanning)'," 6132 sql (
"INSERT INTO config_preferences (config, type, name, value)" 6133 " VALUES ((SELECT id FROM configs WHERE uuid = '" 6136 " 'Ping Host[checkbox]:Report about unrechable Hosts'," 6140 sql (
"INSERT INTO config_preferences (config, type, name, value)" 6141 " VALUES ((SELECT id FROM configs WHERE uuid = '" 6144 " 'Services[radio]:Test SSL based services'," 6145 " 'All;Known SSL ports;None');");
6156 #define MIGRATE_79_to_80_DELETE(table) \ 6157 sql ("DELETE FROM " table \ 6158 " WHERE owner IN (SELECT id FROM users WHERE %s);", \ 6172 sql (
"DELETE FROM config_preferences" 6173 " WHERE config IN (SELECT id FROM configs" 6174 " WHERE owner IN (SELECT id FROM users" 6177 sql (
"DELETE FROM config_preferences_trash" 6178 " WHERE config IN (SELECT id FROM configs" 6179 " WHERE owner IN (SELECT id FROM users" 6182 sql (
"DELETE FROM nvt_selectors" 6183 " WHERE name IN (SELECT nvt_selector FROM configs" 6184 " WHERE owner IN (SELECT id FROM users" 6189 sql (
"DELETE FROM alert_condition_data" 6190 " WHERE alert IN (SELECT id FROM alerts" 6191 " WHERE owner IN (SELECT id FROM users" 6194 sql (
"DELETE FROM alert_condition_data_trash" 6195 " WHERE alert IN (SELECT id FROM alerts_trash" 6196 " WHERE owner IN (SELECT id FROM users" 6199 sql (
"DELETE FROM alert_event_data" 6200 " WHERE alert IN (SELECT id FROM alerts" 6201 " WHERE owner IN (SELECT id FROM users" 6204 sql (
"DELETE FROM alert_event_data_trash" 6205 " WHERE alert IN (SELECT id FROM alerts_trash" 6206 " WHERE owner IN (SELECT id FROM users" 6209 sql (
"DELETE FROM alert_method_data" 6210 " WHERE alert IN (SELECT id FROM alerts" 6211 " WHERE owner IN (SELECT id FROM users" 6214 sql (
"DELETE FROM alert_method_data_trash" 6215 " WHERE alert IN (SELECT id FROM alerts_trash" 6216 " WHERE owner IN (SELECT id FROM users" 6223 sql (
"DELETE FROM group_users" 6224 " WHERE `group` IN (SELECT id FROM groups" 6225 " WHERE owner IN (SELECT id FROM users" 6239 sql (
"DELETE FROM port_ranges" 6240 " WHERE port_list IN (SELECT id FROM port_lists" 6241 " WHERE owner IN (SELECT id FROM users" 6244 sql (
"DELETE FROM port_ranges_trash" 6245 " WHERE port_list IN (SELECT id FROM port_lists_trash" 6246 " WHERE owner IN (SELECT id FROM users" 6249 sql (
"DELETE FROM report_format_param_options" 6250 " WHERE report_format_param" 6251 " IN (SELECT id FROM report_format_params" 6252 " WHERE report_format" 6253 " IN (SELECT id FROM report_formats" 6254 " WHERE owner IN (SELECT id FROM users" 6257 sql (
"DELETE FROM report_format_param_options_trash" 6258 " WHERE report_format_param" 6259 " IN (SELECT id FROM report_format_params_trash" 6260 " WHERE report_format" 6261 " IN (SELECT id FROM report_formats" 6262 " WHERE owner IN (SELECT id FROM users" 6265 sql (
"DELETE FROM report_format_params" 6266 " WHERE report_format IN (SELECT id FROM report_formats" 6267 " WHERE owner IN (SELECT id FROM users" 6270 sql (
"DELETE FROM report_format_params_trash" 6271 " WHERE report_format IN (SELECT id FROM report_formats" 6272 " WHERE owner IN (SELECT id FROM users" 6277 sql (
"DELETE FROM report_host_details" 6278 " WHERE report_host" 6279 " IN (SELECT id FROM report_hosts" 6280 " WHERE report IN (SELECT id FROM reports" 6281 " WHERE owner IN (SELECT id FROM users" 6284 sql (
"DELETE FROM report_results" 6285 " WHERE report IN (SELECT id FROM reports" 6286 " WHERE owner IN (SELECT id FROM users" 6289 sql (
"DELETE FROM results" 6290 " WHERE report IN (SELECT id FROM reports" 6291 " WHERE owner IN (SELECT id FROM users" 6304 sql (
"DELETE FROM task_files" 6305 " WHERE task IN (SELECT id FROM tasks" 6306 " WHERE owner IN (SELECT id FROM users" 6309 sql (
"DELETE FROM task_alerts" 6310 " WHERE task IN (SELECT id FROM tasks" 6311 " WHERE owner IN (SELECT id FROM users" 6314 sql (
"DELETE FROM task_preferences" 6315 " WHERE task IN (SELECT id FROM tasks" 6316 " WHERE owner IN (SELECT id FROM users" 6320 sql (
"DELETE FROM users WHERE %s;",
6324 #define RULES_HEADER "# This file is managed by the OpenVAS Administrator.\n# Any modifications must keep to the format that the Administrator expects.\n" 6339 gchar *rules_file, *rules;
6340 GError *error = NULL;
6342 assert (hosts != NULL);
6343 assert (hosts_allow != NULL);
6345 rules_file = g_build_filename (user_dir,
"auth",
"rules", NULL);
6346 if (g_file_test (rules_file, G_FILE_TEST_EXISTS) == FALSE)
6353 g_file_get_contents (rules_file, &rules, NULL, &error);
6356 g_warning (
"%s", error->message);
6357 g_error_free (error);
6358 g_free (rules_file);
6361 g_free (rules_file);
6369 count = sscanf (rules,
RULES_HEADER "# allow %*[^\n]%n\n", &end);
6370 if (count == 0 && end > 0)
6380 count = sscanf (rules,
RULES_HEADER "# deny %*[^\n]%n\n", &end);
6381 if (count == 0 && end > 0)
6420 struct dirent **names;
6439 sql (
"CREATE TABLE IF NOT EXISTS alert_condition_data_trash" 6440 " (id INTEGER PRIMARY KEY, alert INTEGER, name, data);");
6441 sql (
"CREATE TABLE IF NOT EXISTS config_preferences_trash" 6442 " (id INTEGER PRIMARY KEY, config INTEGER, type, name, value);");
6443 sql (
"CREATE TABLE IF NOT EXISTS groups" 6444 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 6445 " creation_time, modification_time);");
6446 sql (
"CREATE TABLE IF NOT EXISTS group_users" 6447 " (id INTEGER PRIMARY KEY, `group` INTEGER, user INTEGER);");
6448 sql (
"CREATE TABLE IF NOT EXISTS filters" 6449 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 6450 " type, term, creation_time, modification_time);");
6451 sql (
"CREATE TABLE IF NOT EXISTS filters_trash" 6452 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 6453 " type, term, creation_time, modification_time);");
6454 sql (
"CREATE TABLE IF NOT EXISTS notes_trash" 6455 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 6456 " creation_time, modification_time, text, hosts, port, threat," 6457 " task INTEGER, result INTEGER, end_time);");
6458 sql (
"CREATE TABLE IF NOT EXISTS overrides_trash" 6459 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 6460 " creation_time, modification_time, text, hosts, port, threat," 6461 " new_threat, task INTEGER, result INTEGER, end_time);");
6462 sql (
"CREATE TABLE IF NOT EXISTS permissions" 6463 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 6464 " resource_type, resource, resource_uuid, resource_location," 6465 " subject_type, subject, creation_time, modification_time);");
6466 sql (
"CREATE TABLE IF NOT EXISTS permissions_trash" 6467 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 6468 " resource_type, resource, resource_uuid, resource_location," 6469 " subject_type, subject, creation_time, modification_time);");
6470 sql (
"CREATE TABLE IF NOT EXISTS port_names" 6471 " (id INTEGER PRIMARY KEY, number INTEGER, protocol, name," 6472 " UNIQUE (number, protocol) ON CONFLICT REPLACE);");
6473 sql (
"CREATE TABLE IF NOT EXISTS report_format_params_trash" 6474 " (id INTEGER PRIMARY KEY, report_format, name, type INTEGER, value," 6475 " type_min, type_max, type_regex, fallback);");
6476 sql (
"CREATE TABLE IF NOT EXISTS report_format_param_options_trash" 6477 " (id INTEGER PRIMARY KEY, report_format_param, value);");
6478 sql (
"CREATE TABLE IF NOT EXISTS settings" 6479 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment, value);");
6480 sql (
"CREATE TABLE IF NOT EXISTS tags" 6481 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 6482 " creation_time, modification_time, attach_type, attach_id," 6483 " active, value);");
6484 sql (
"CREATE TABLE IF NOT EXISTS tags_trash" 6485 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 6486 " creation_time, modification_time, attach_type, attach_id," 6487 " active, value);");
6491 sql (
"ALTER TABLE users ADD COLUMN method;");
6492 sql (
"UPDATE users SET method = 'file';");
6494 count = scandir (OPENVAS_STATE_DIR
"/users", &names, NULL, alphasort);
6497 g_warning (
"%s: failed to open dir %s/users: %s\n",
6505 dirs = make_array ();
6509 sql (
"UPDATE users SET password = -1;");
6516 for (index = 0; index < count; index++)
6518 gchar *role, *role_file, *uuid, *uuid_file, *classic_dir, *remote_dir;
6519 gchar *hash, *hosts, *quoted_hash, *quoted_hosts, *quoted_method;
6520 gchar *quoted_name, *quoted_uuid, *where, *file, *remote_flag_file;
6521 auth_method_t method;
6526 if ((strcmp (names[index]->d_name,
".") == 0)
6527 || (strcmp (names[index]->d_name,
"..") == 0)
6528 || (strcmp (names[index]->d_name,
"om") == 0))
6530 free (names[index]);
6536 remote_dir = g_build_filename (OPENVAS_STATE_DIR,
6539 names[index]->d_name,
6541 classic_dir = g_build_filename (OPENVAS_STATE_DIR,
"users",
6542 names[index]->d_name,
6544 remote_flag_file = g_build_filename (classic_dir,
6549 g_debug (
" user: %s\n", names[index]->d_name);
6550 g_debug (
" remote dir: %s\n", remote_dir);
6551 g_debug (
" classic dir: %s\n", classic_dir);
6552 g_debug (
" flag file: %s\n", remote_flag_file);
6553 if (g_file_test (remote_dir, G_FILE_TEST_IS_DIR)
6554 && g_file_test (remote_flag_file, G_FILE_TEST_EXISTS))
6555 method = AUTHENTICATION_METHOD_LDAP_CONNECT;
6558 g_free (remote_dir);
6559 method = AUTHENTICATION_METHOD_FILE;
6560 if (g_file_test (classic_dir, G_FILE_TEST_IS_DIR) == FALSE)
6562 free (names[index]);
6563 g_free (classic_dir);
6564 g_free (remote_flag_file);
6567 remote_dir = g_strdup (classic_dir);
6569 g_free (remote_flag_file);
6573 uuid_file = g_build_filename (remote_dir,
"uuid", NULL);
6575 g_file_get_contents (uuid_file,
6581 g_warning (
"%s: Failed to read %s: %s\n",
6585 g_free (classic_dir);
6586 g_free (remote_dir);
6588 g_error_free (error);
6596 if (uuid == NULL || strlen (g_strchomp (uuid)) != 36)
6598 g_warning (
"%s: Error in UUID: %s\n",
6601 g_free (classic_dir);
6602 g_free (remote_dir);
6607 g_debug (
" uuid: %s\n", uuid);
6613 role_file = g_build_filename (remote_dir,
"isobserver", NULL);
6614 if (g_file_test (role_file, G_FILE_TEST_EXISTS))
6618 role_file = g_build_filename (remote_dir,
"isadmin", NULL);
6619 if (g_file_test (role_file, G_FILE_TEST_EXISTS))
6627 "SELECT id FROM users WHERE uuid = '%s';",
6633 quoted_name =
sql_quote (names[index]->d_name);
6634 sql (
"INSERT INTO users" 6635 " (uuid, owner, name, comment, password, timezone, method," 6636 " hosts, hosts_allow)" 6638 " ('%s', NULL, '%s', '', NULL, NULL, 'file', '', 2);",
6641 g_free (quoted_name);
6647 g_warning (
"%s: Error finding user %s\n",
6651 g_free (quoted_uuid);
6652 g_free (classic_dir);
6653 g_free (remote_dir);
6661 file = g_build_filename (classic_dir,
"auth",
"hash", NULL);
6663 if (file && g_file_test (file, G_FILE_TEST_EXISTS))
6665 g_file_get_contents (file,
6671 g_warning (
"%s: Failed to read %s: %s\n",
6675 g_free (classic_dir);
6676 g_free (remote_dir);
6677 g_free (quoted_uuid);
6679 g_error_free (error);
6696 g_warning (
"%s: Failed to get user rules from %s\n",
6699 g_free (classic_dir);
6700 g_free (remote_dir);
6701 g_free (quoted_uuid);
6702 g_error_free (error);
6707 if (hosts_allow == 3)
6713 quoted_method =
sql_quote (auth_method_name (method));
6714 quoted_hash =
sql_quote (hash ? hash :
"");
6715 quoted_hosts =
sql_quote (hosts ? hosts :
"");
6720 " password = %s%s%s," 6723 " WHERE id = %llu;",
6728 hash ? quoted_hash :
"NULL",
6733 g_free (quoted_uuid);
6734 g_free (quoted_method);
6735 g_free (quoted_hash);
6736 g_free (quoted_hosts);
6740 quoted_name =
sql_quote (names[index]->d_name);
6741 where = g_strdup_printf (
"name = '%s' AND id != %llu",
6744 g_free (quoted_name);
6750 array_add (dirs, classic_dir);
6752 free (names[index]);
6764 dir = g_build_filename (OPENVAS_STATE_DIR,
"users-remote", NULL);
6765 if (g_lstat (dir, &state))
6767 if (errno != ENOENT)
6768 g_warning (
"%s: g_lstat (%s) failed: %s\n",
6769 __FUNCTION__, dir, g_strerror (errno));
6772 openvas_file_remove_recurse (dir);
6778 for (index = 0; index < dirs->len; index++)
6779 openvas_file_remove_recurse (g_ptr_array_index (dirs, index));
6812 sql (
"CREATE TABLE IF NOT EXISTS roles" 6813 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 6814 " creation_time, modification_time);");
6815 sql (
"CREATE TABLE IF NOT EXISTS role_users" 6816 " (id INTEGER PRIMARY KEY, role INTEGER, user INTEGER);");
6820 sql (
"INSERT INTO roles" 6821 " (uuid, owner, name, comment, creation_time, modification_time)" 6826 sql (
"INSERT INTO roles" 6827 " (uuid, owner, name, comment, creation_time, modification_time)" 6829 " ('" ROLE_UUID_USER "', NULL, 'User', 'User', m_now (), m_now ());");
6831 sql (
"INSERT INTO roles" 6832 " (uuid, owner, name, comment, creation_time, modification_time)" 6837 sql (
"INSERT INTO role_users (role, user)" 6838 " SELECT (SELECT id FROM roles WHERE roles.name = users.role)," 6845 sql (
"UPDATE users SET role = NULL;");
6909 sql (
"ALTER TABLE nvts RENAME TO nvts_82;");
6913 sql (
"CREATE TABLE IF NOT EXISTS nvts" 6914 " (id INTEGER PRIMARY KEY, uuid, oid, version, name, comment, summary," 6915 " description, copyright, cve, bid, xref, tag, sign_key_ids," 6916 " category INTEGER, family, cvss_base, creation_time," 6917 " modification_time);");
6921 sql (
"INSERT into nvts" 6922 " (id, uuid, oid, version, name, comment, summary, description," 6923 " copyright, cve, bid, xref, tag, sign_key_ids, category, family," 6924 " cvss_base, creation_time, modification_time)" 6926 " id, uuid, oid, version, name, comment, summary, description," 6927 " copyright, cve, bid, xref, tag, sign_key_ids, category, family," 6928 " cvss_base, creation_time, modification_time" 6933 sql (
"DROP TABLE nvts_82;");
6964 sql (
"ALTER TABLE results ADD COLUMN nvt_version;");
6965 sql (
"ALTER TABLE results ADD COLUMN severity REAL;");
6996 sql (
"ALTER TABLE reports ADD COLUMN severity REAL;");
6997 sql (
"ALTER TABLE reports ADD COLUMN override_severity REAL;");
7000 sql (
"UPDATE reports SET highs = -1;");
7001 sql (
"UPDATE reports SET override_highs = -1;");
7032 sql (
"ALTER TABLE overrides ADD COLUMN new_severity REAL;");
7033 sql (
"ALTER TABLE overrides_trash ADD COLUMN new_severity REAL;");
7036 sql (
"UPDATE reports SET override_highs = -1;");
7074 sql (
"UPDATE results" 7075 " SET severity = (CASE type" 7076 " WHEN 'Security Hole' THEN 10.0" 7077 " WHEN 'Security Warning' THEN 5.0" 7078 " WHEN 'Security Note' THEN 2.0" 7079 " WHEN 'Log Message' THEN 0.0" 7081 " WHERE severity IS NULL;");
7083 sql (
"UPDATE results SET type = 'Alarm'" 7084 " WHERE type = 'Security Hole'" 7085 " OR type = 'Security Warning'" 7086 " OR type = 'Security Note';");
7118 sql (
"ALTER TABLE reports RENAME TO reports_87;");
7120 sql (
"CREATE TABLE IF NOT EXISTS reports" 7121 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, hidden INTEGER," 7122 " task INTEGER, date INTEGER, start_time, end_time, nbefile, comment," 7123 " scan_run_status INTEGER, slave_progress, slave_task_uuid);");
7125 sql (
"CREATE TABLE IF NOT EXISTS report_counts" 7126 " (id INTEGER PRIMARY KEY, report INTEGER, user INTEGER," 7127 " severity, override_severity, highs, mediums, lows, logs, fps," 7128 " override_highs, override_mediums, override_lows, override_logs," 7131 sql (
"INSERT INTO reports" 7132 " (id, uuid, owner, hidden, task, date, start_time, end_time," 7133 " nbefile, comment, scan_run_status, slave_progress, slave_task_uuid)" 7134 " SELECT id, uuid, owner, hidden, task, date, start_time, end_time," 7135 " nbefile, comment, scan_run_status, slave_progress, slave_task_uuid" 7136 " FROM reports_87;");
7138 sql (
"DROP TABLE reports_87;");
7170 sql (
"ALTER TABLE overrides RENAME TO overrides_88;");
7171 sql (
"ALTER TABLE overrides_trash RENAME TO overrides_trash_88;");
7174 sql (
"CREATE TABLE IF NOT EXISTS overrides" 7175 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 7176 " creation_time, modification_time, text, hosts, port, severity," 7177 " new_severity, task INTEGER, result INTEGER, end_time);");
7179 sql (
"CREATE TABLE IF NOT EXISTS overrides_trash" 7180 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 7181 " creation_time, modification_time, text, hosts, port, severity," 7182 " new_severity, task INTEGER, result INTEGER, end_time);");
7185 sql (
"INSERT INTO overrides" 7186 " (id, uuid, owner, nvt, creation_time, modification_time, text," 7187 " hosts, port, severity, new_severity, task, result, end_time)" 7188 " SELECT id, uuid, owner, nvt, creation_time, modification_time, text," 7191 " WHEN 'Security Hole' THEN 0.1" 7192 " WHEN 'Security Warning' THEN 0.1" 7193 " WHEN 'Security Note' THEN 0.1" 7194 " WHEN 'Alarm' THEN 0.1" 7195 " WHEN 'Log Message' THEN 0.0" 7196 " WHEN 'False Positive' THEN -1.0" 7197 " WHEN 'Debug Message' THEN -2.0" 7198 " WHEN 'Error Message' THEN -3.0" 7201 " coalesce (new_severity," 7203 " WHEN 'Security Hole' THEN 10.0" 7204 " WHEN 'Security Warning' THEN 5.0" 7205 " WHEN 'Security Note' THEN 2.0" 7206 " WHEN 'Log Message' THEN 0.0" 7207 " WHEN 'False Positive' THEN -1.0" 7208 " WHEN 'Debug Message' THEN -2.0" 7209 " WHEN 'Error Message' THEN -3.0" 7211 " task, result, end_time" 7212 " FROM overrides_88;");
7214 sql (
"INSERT INTO overrides_trash" 7215 " (id, uuid, owner, nvt, creation_time, modification_time, text," 7216 " hosts, port, severity, new_severity, task, result, end_time)" 7217 " SELECT id, uuid, owner, nvt, creation_time, modification_time, text," 7220 " WHEN 'Security Hole' THEN 0.1" 7221 " WHEN 'Security Warning' THEN 0.1" 7222 " WHEN 'Security Note' THEN 0.1" 7223 " WHEN 'Alarm' THEN 0.1" 7224 " WHEN 'Log Message' THEN 0.0" 7225 " WHEN 'False Positive' THEN -1.0" 7226 " WHEN 'Debug Message' THEN -2.0" 7227 " WHEN 'Error Message' THEN -3.0" 7230 " coalesce (new_severity," 7232 " WHEN 'Security Hole' THEN 10.0" 7233 " WHEN 'Security Warning' THEN 5.0" 7234 " WHEN 'Security Note' THEN 2.0" 7235 " WHEN 'Log Message' THEN 0.0" 7236 " WHEN 'False Positive' THEN -1.0" 7237 " WHEN 'Debug Message' THEN -2.0" 7238 " WHEN 'Error Message' THEN -3.0" 7240 " task, result, end_time" 7241 " FROM overrides_trash_88;");
7244 sql (
"DROP TABLE overrides_88;");
7245 sql (
"DROP TABLE overrides_trash_88;");
7248 sql (
"UPDATE report_counts set override_highs = -1;");
7281 sql (
"UPDATE groups SET owner = NULL;");
7282 sql (
"UPDATE roles SET owner = NULL;");
7283 sql (
"UPDATE users SET owner = NULL;");
7315 sql (
"ALTER TABLE notes RENAME TO notes_90;");
7316 sql (
"ALTER TABLE notes_trash RENAME TO notes_trash_90;");
7319 sql (
"CREATE TABLE IF NOT EXISTS notes" 7320 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 7321 " creation_time, modification_time, text, hosts, port, severity," 7322 " task INTEGER, result INTEGER, end_time);");
7323 sql (
"CREATE TABLE IF NOT EXISTS notes_trash" 7324 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, nvt," 7325 " creation_time, modification_time, text, hosts, port, severity," 7326 " task INTEGER, result INTEGER, end_time);");
7329 sql (
"INSERT INTO notes" 7330 " (id, uuid, owner , nvt, creation_time, modification_time, text," 7331 " hosts, port, severity, task, result, end_time)" 7332 " SELECT id, uuid, owner, nvt, creation_time, modification_time, text," 7335 " WHEN 'Security Hole' THEN 0.1" 7336 " WHEN 'Security Warning' THEN 0.1" 7337 " WHEN 'Security Note' THEN 0.1" 7338 " WHEN 'Alarm' THEN 0.1" 7339 " WHEN 'Log Message' THEN 0.0" 7340 " WHEN 'False Positive' THEN -1.0" 7341 " WHEN 'Debug Message' THEN -2.0" 7342 " WHEN 'Error Message' THEN -3.0" 7345 " task, result, end_time" 7348 sql (
"INSERT INTO notes_trash" 7349 " (id, uuid, owner , nvt, creation_time, modification_time, text," 7350 " hosts, port, severity, task, result, end_time)" 7351 " SELECT id, uuid, owner, nvt, creation_time, modification_time, text," 7354 " WHEN 'Security Hole' THEN 0.1" 7355 " WHEN 'Security Warning' THEN 0.1" 7356 " WHEN 'Security Note' THEN 0.1" 7357 " WHEN 'Alarm' THEN 0.1" 7358 " WHEN 'Log Message' THEN 0.0" 7359 " WHEN 'False Positive' THEN -1.0" 7360 " WHEN 'Debug Message' THEN -2.0" 7361 " WHEN 'Error Message' THEN -3.0" 7364 " task, result, end_time" 7365 " FROM notes_trash_90;");
7368 sql (
"DROP TABLE notes_90;");
7369 sql (
"DROP TABLE notes_trash_90;");
7405 sql (
"INSERT INTO settings (uuid, owner, name, comment, value)" 7406 " SELECT '739ab810-163d-11e3-9af6-406186ea4fc5', owner," 7407 " 'Results Filter', comment, value" 7409 " WHERE name = 'Reports Filter';");
7411 sql (
"DELETE FROM settings WHERE name = 'Reports Filter';");
7413 sql (
"UPDATE filters SET type = 'result' WHERE type = 'report';");
7446 sql (
"DELETE FROM config_preferences WHERE name = 'host_expansion';");
7447 sql (
"DELETE FROM config_preferences_trash WHERE name = 'host_expansion';");
7478 sql (
"ALTER TABLE targets ADD COLUMN exclude_hosts;");
7479 sql (
"ALTER TABLE targets_trash ADD COLUMN exclude_hosts;");
7510 sql (
"DROP TABLE report_counts;");
7511 sql (
"CREATE TABLE IF NOT EXISTS report_counts" 7512 " (id INTEGER PRIMARY KEY, report INTEGER, user INTEGER," 7513 " severity, count, override);");
7544 sql (
"ALTER TABLE targets ADD COLUMN reverse_lookup_only;");
7545 sql (
"ALTER TABLE targets ADD COLUMN reverse_lookup_unify;");
7546 sql (
"UPDATE targets SET reverse_lookup_only = 0, reverse_lookup_unify = 0;");
7548 sql (
"ALTER TABLE targets_trash ADD COLUMN reverse_lookup_only;");
7549 sql (
"ALTER TABLE targets_trash ADD COLUMN reverse_lookup_unify;");
7550 sql (
"UPDATE targets_trash SET reverse_lookup_only = 0, " 7551 " reverse_lookup_unify = 0;");
7582 sql (
"ALTER TABLE tasks ADD COLUMN hosts_ordering;");
7583 sql (
"UPDATE tasks SET hosts_ordering = 'sequential';");
7614 sql (
"UPDATE settings SET value = 0" 7615 " WHERE name = 'Dynamic Severity'" 7616 " AND owner IS NULL;");
7649 sql (
"DELETE FROM config_preferences WHERE name = 'reverse_lookup';");
7650 sql (
"DELETE FROM config_preferences" 7651 " WHERE name = 'slice_network_addresses';");
7652 sql (
"DELETE FROM config_preferences_trash WHERE name = 'reverse_lookup';");
7653 sql (
"DELETE FROM config_preferences_trash" 7654 " WHERE name = 'slice_network_addresses';");
7686 sql (
"ALTER TABLE results RENAME TO results_99;");
7689 sql (
"CREATE TABLE IF NOT EXISTS results" 7690 " (id INTEGER PRIMARY KEY, uuid, task INTEGER, host, port, nvt," 7691 " type, description, report, nvt_version, severity REAL)");
7694 sql (
"INSERT INTO results" 7695 " (id, uuid, task, host, port, nvt, type," 7696 " description, report, nvt_version, severity)" 7697 " SELECT id, uuid, task, host, port, nvt, type, description, report," 7698 " nvt_version, severity FROM results_99");
7701 sql (
"DROP TABLE results_99;");
7733 sql (
"UPDATE alert_condition_data SET" 7734 " name = 'severity'," 7736 " WHEN 'High' THEN 5.1" 7737 " WHEN 'Medium' THEN 2.1" 7738 " WHEN 'Meduim' THEN 2.1" 7739 " WHEN 'Low' THEN 0.1" 7740 " WHEN 'Log' THEN 0.0" 7741 " WHEN 'False Positive' THEN -1.0" 7743 " WHERE name = 'level';");
7745 sql (
"UPDATE alert_condition_data_trash SET" 7746 " name = 'severity'," 7748 " WHEN 'High' THEN 5.1" 7749 " WHEN 'Medium' THEN 2.1" 7750 " WHEN 'Meduim' THEN 2.1" 7751 " WHEN 'Low' THEN 0.1" 7752 " WHEN 'Log' THEN 0.0" 7753 " WHEN 'False Positive' THEN -1.0" 7755 " WHERE name = 'level';");
7787 sql (
"ALTER TABLE nvts RENAME TO nvts_101;");
7790 sql (
"CREATE TABLE IF NOT EXISTS nvts" 7791 " (id INTEGER PRIMARY KEY, uuid, oid, version, name, comment, summary," 7792 " copyright, cve, bid, xref, tag, sign_key_ids," 7793 " category INTEGER, family, cvss_base, creation_time," 7794 " modification_time);");
7797 sql (
"INSERT INTO nvts" 7798 " (id, uuid, oid, version, name, comment, summary," 7799 " copyright, cve, bid, xref, tag, sign_key_ids," 7800 " category, family, cvss_base, creation_time, modification_time)" 7801 " SELECT id, uuid, oid, version, name, comment, summary," 7802 " copyright, cve, bid, xref, tag, sign_key_ids," 7803 " category, family, cvss_base, creation_time, modification_time" 7807 sql (
"DROP TABLE nvts_101;");
7839 sql (
"DELETE FROM report_counts WHERE report IN" 7840 " (SELECT report FROM results" 7841 " WHERE severity = 'NULL' OR severity = '' OR severity IS NULL);");
7844 sql (
"UPDATE results SET" 7845 " severity = CASE type" 7846 " WHEN 'Error Message' THEN -3.0" 7847 " WHEN 'Debug Message' THEN -2.0" 7848 " WHEN 'False Positive' THEN -1.0" 7849 " WHEN 'Log Message' THEN 0.0" 7851 " WHERE severity = 'NULL' OR severity = '' OR severity IS NULL;");
7883 sql (
"ALTER TABLE tasks ADD column alterable;");
7884 sql (
"UPDATE tasks SET alterable = 0;");
7916 sql (
"ALTER TABLE report_counts ADD COLUMN end_time INTEGER;");
7919 sql (
"UPDATE report_counts" 7920 " SET end_time = (SELECT coalesce(min(end_time), 0)" 7921 " FROM overrides, results" 7922 " WHERE overrides.nvt = results.nvt" 7923 " AND results.report = report_counts.report" 7924 " AND overrides.end_time > 1)" 7925 " WHERE report_counts.override = 1;");
7927 sql (
"UPDATE report_counts" 7929 " WHERE report_counts.override = 0;");
7932 sql (
"DELETE FROM report_counts" 7933 " WHERE end_time != 0 AND end_time <= m_now ()");
7964 sql (
"ALTER TABLE users ADD COLUMN ifaces;");
7965 sql (
"ALTER TABLE users ADD COLUMN ifaces_allow;");
7966 sql (
"UPDATE users SET ifaces = '', ifaces_allow = 2");
7998 sql (
"UPDATE results" 7999 " SET task = (SELECT task FROM reports WHERE reports.id = report);");
8032 " SET hosts = '', hosts_allow = 0 WHERE hosts_allow = 2;");
8034 " SET ifaces = '', ifaces_allow = 0 WHERE ifaces_allow = 2;");
8067 sql (
"UPDATE permissions SET name = 'create_' || resource_type" 8068 " WHERE name = 'create';");
8069 sql (
"DELETE FROM permissions WHERE name = 'create_';");
8071 sql (
"UPDATE permissions SET name = 'delete_' || resource_type" 8072 " WHERE name = 'delete';");
8073 sql (
"DELETE FROM permissions WHERE name = 'delete_';");
8075 sql (
"UPDATE permissions SET name = 'get_' || resource_type || 's'" 8076 " WHERE name = 'get';");
8077 sql (
"DELETE FROM permissions WHERE name = 'get_';");
8079 sql (
"UPDATE permissions SET name = 'modify_' || resource_type" 8080 " WHERE name = 'modify';");
8081 sql (
"DELETE FROM permissions WHERE name = 'modify_';");
8114 sql (
"ALTER TABLE permissions ADD COLUMN subject_location;");
8115 sql (
"UPDATE permissions SET subject_location = 0;");
8117 sql (
"ALTER TABLE permissions_trash ADD COLUMN subject_location;");
8118 sql (
"UPDATE permissions_trash SET subject_location = 0;");
8151 sql (
"ALTER TABLE targets ADD COLUMN alive_test;");
8152 sql (
"UPDATE targets SET alive_test = 0;");
8154 sql (
"ALTER TABLE targets_trash ADD COLUMN alive_test;");
8155 sql (
"UPDATE targets_trash SET alive_test = 0;");
8189 sql (
"DELETE FROM config_preferences" 8190 " WHERE config = (SELECT id FROM configs" 8192 " AND (name = 'Ping Host[checkbox]:Do a TCP ping'" 8193 " OR name = 'Ping Host[checkbox]:Do an ICMP ping'" 8194 " OR name = 'Ping Host[checkbox]:Use ARP'" 8195 " OR name = 'Ping Host[checkbox]:Use nmap'" 8196 " OR name = 'Ping Host[checkbox]:nmap: try also with only -sP'" 8197 " OR name = 'Ping Host[entry]:nmap additional ports for -PA');");
8231 sql (
"DELETE FROM report_counts;");
8264 sql (
"ALTER TABLE reports ADD COLUMN slave_uuid;");
8265 sql (
"ALTER TABLE reports ADD COLUMN slave_name;");
8266 sql (
"ALTER TABLE reports ADD COLUMN slave_host;");
8267 sql (
"ALTER TABLE reports ADD COLUMN slave_port;");
8268 sql (
"ALTER TABLE reports ADD COLUMN source_iface;");
8298 sql (
"ALTER TABLE nvts RENAME TO nvts_114;");
8301 sql (
"CREATE TABLE IF NOT EXISTS nvts" 8302 " (id INTEGER PRIMARY KEY, uuid, oid, version, name, comment, summary," 8303 " copyright, cve, bid, xref, tag, category INTEGER, family, cvss_base," 8304 " creation_time, modification_time);");
8307 sql (
"INSERT INTO nvts" 8308 " (id, uuid, oid, version, name, comment, summary," 8309 " copyright, cve, bid, xref, tag," 8310 " category, family, cvss_base, creation_time, modification_time)" 8311 " SELECT id, uuid, oid, version, name, comment, summary," 8312 " copyright, cve, bid, xref, tag," 8313 " category, family, cvss_base, creation_time, modification_time" 8317 sql (
"DROP TABLE nvts_114;");
8350 sql (
"DELETE FROM nvt_selectors" 8353 " AND family_or_nvt = '1.3.6.1.4.1.25623.1.0.810002'");
8364 #define ID_WHEN_WITH_TRASH(type) \ 8365 " WHEN '" G_STRINGIFY (type) "' THEN" \ 8366 " COALESCE ((SELECT id FROM " G_STRINGIFY (type) "s" \ 8367 " WHERE uuid = attach_id)," \ 8368 " (SELECT id FROM " G_STRINGIFY (type) "s_trash" \ 8369 " WHERE uuid = attach_id)," \ 8372 #define ID_WHEN_WITHOUT_TRASH(type) \ 8373 " WHEN '" G_STRINGIFY (type) "' THEN" \ 8374 " COALESCE ((SELECT id FROM " G_STRINGIFY (type) "s" \ 8375 " WHERE uuid = attach_id)," \ 8378 #define RESOURCE_TRASH(type) \ 8379 " WHEN '" G_STRINGIFY (type) "' THEN" \ 8380 " (SELECT CASE WHEN " \ 8381 " (EXISTS (SELECT * FROM " G_STRINGIFY (type) "s_trash" \ 8382 " WHERE uuid = attach_id))" \ 8383 " THEN " G_STRINGIFY (LOCATION_TRASH) \ 8384 " ELSE " G_STRINGIFY (LOCATION_TABLE) " END)" 8411 sql (
"ALTER TABLE tags RENAME TO tags_117;");
8412 sql (
"ALTER TABLE tags_trash RENAME TO tags_trash_117;");
8414 sql (
"CREATE TABLE IF NOT EXISTS tags" 8415 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 8416 " creation_time, modification_time, resource_type, resource," 8417 " resource_uuid, resource_location, active, value);");
8419 sql (
"CREATE TABLE IF NOT EXISTS groups_trash" 8420 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 8421 " type, term, creation_time, modification_time);");
8423 sql (
"CREATE TABLE IF NOT EXISTS roles_trash" 8424 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, comment," 8425 " creation_time, modification_time);");
8427 sql (
"INSERT INTO tags" 8428 " (id, uuid, owner, name, comment," 8429 " creation_time, modification_time, resource_type, resource," 8430 " resource_uuid, resource_location, active, value)" 8432 " id, uuid, owner, name, comment, creation_time, modification_time," 8434 " (SELECT CASE attach_type" 8460 " (SELECT CASE attach_type" 8475 " COALESCE ((SELECT CASE WHEN hidden = 2 THEN " 8480 " FROM tasks WHERE uuid = attach_id)," 8482 " WHEN 'report' THEN" 8483 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8488 " FROM (SELECT task FROM reports" 8489 " WHERE reports.uuid = attach_id) AS report_task" 8490 " JOIN tasks ON tasks.id = report_task.task)," 8492 " WHEN 'result' THEN" 8493 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8498 " FROM (SELECT task FROM results" 8499 " WHERE results.uuid = attach_id) AS result_task" 8500 " JOIN tasks ON tasks.id = result_task.task)," 8513 sql (
"DROP TABLE tags_117;");
8517 sql (
"CREATE TABLE IF NOT EXISTS tags_trash" 8518 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner, name, comment," 8519 " creation_time, modification_time, resource_type, resource," 8520 " resource_uuid, resource_location, active, value);");
8522 sql (
"INSERT INTO tags_trash" 8523 " (id, uuid, owner, name, comment," 8524 " creation_time, modification_time, resource_type, resource," 8525 " resource_uuid, resource_location, active, value)" 8527 " id, uuid, owner, name, comment, creation_time, modification_time," 8529 " (SELECT CASE attach_type" 8555 " (SELECT CASE attach_type" 8570 " COALESCE ((SELECT CASE WHEN hidden = 2 THEN " 8575 " FROM tasks WHERE uuid = attach_id)," 8577 " WHEN 'report' THEN" 8578 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8583 " FROM (SELECT task FROM reports" 8584 " WHERE reports.uuid = attach_id) AS report_task" 8585 " JOIN tasks ON tasks.id = report_task.task)," 8587 " WHEN 'result' THEN" 8588 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8593 " FROM (SELECT task FROM results" 8594 " WHERE results.uuid = attach_id) AS result_task" 8595 " JOIN tasks ON tasks.id = result_task.task)," 8599 " FROM tags_trash_117;",
8608 sql (
"DROP TABLE tags_trash_117;");
8618 #undef ID_WHEN_WITH_TRASH 8619 #undef ID_WHEN_WITHOUT_TRASH 8620 #undef RESOURCE_TRASH 8623 #define RESOURCE_TRASH(type) \ 8624 " WHEN '" G_STRINGIFY (type) "' THEN" \ 8625 " (SELECT CASE WHEN " \ 8626 " (EXISTS (SELECT * FROM " G_STRINGIFY (type) "s_trash" \ 8627 " WHERE uuid = resource_uuid))" \ 8628 " THEN " G_STRINGIFY (LOCATION_TRASH) \ 8629 " ELSE " G_STRINGIFY (LOCATION_TABLE) " END)" 8652 sql (
"UPDATE tags SET resource_location = " 8653 " (SELECT CASE resource_type" 8668 " COALESCE ((SELECT CASE WHEN hidden = 2 THEN " 8673 " FROM tasks WHERE uuid = resource_uuid)," 8675 " WHEN 'report' THEN" 8676 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8681 " FROM (SELECT task FROM reports" 8682 " WHERE reports.uuid = resource_uuid) AS report_task" 8683 " JOIN tasks ON tasks.id = report_task.task)," 8685 " WHEN 'result' THEN" 8686 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8691 " FROM (SELECT task FROM results" 8692 " WHERE results.uuid = resource_uuid) AS result_task" 8693 " JOIN tasks ON tasks.id = result_task.task)," 8697 sql (
"UPDATE tags_trash SET resource_location = " 8698 " (SELECT CASE resource_type" 8713 " COALESCE ((SELECT CASE WHEN hidden = 2 THEN " 8718 " FROM tasks WHERE uuid = resource_uuid)," 8720 " WHEN 'report' THEN" 8721 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8726 " FROM (SELECT task FROM reports" 8727 " WHERE reports.uuid = resource_uuid) AS report_task" 8728 " JOIN tasks ON tasks.id = report_task.task)," 8730 " WHEN 'result' THEN" 8731 " COALESCE ((SELECT CASE WHEN tasks.hidden = 2 THEN " 8736 " FROM (SELECT task FROM results" 8737 " WHERE results.uuid = resource_uuid) AS result_task" 8738 " JOIN tasks ON tasks.id = result_task.task)," 8750 #undef RESOURCE_TRASH 8774 sql (
"DELETE FROM results" 8775 " WHERE NOT EXISTS (SELECT * FROM report_results" 8776 " WHERE report_results.result = results.id);");
8779 g_debug (
"%s: Removed %d orphaned result(s).",
8781 sql (
"DELETE FROM report_counts WHERE override = 0;");
8782 sql (
"DELETE FROM report_counts WHERE override = 1;");
8817 sql (
"DELETE FROM permissions" 8820 " AND resource_exists (resource_type, resource, resource_location) == 0;");
8822 sql (
"DELETE FROM permissions" 8825 " AND resource_exists (subject_type, subject, subject_location) == 0;");
8859 sql (
"DELETE FROM permissions WHERE subject_type = 'role'" 8860 " AND subject = (SELECT id FROM roles" 8894 sql (
"DELETE FROM permissions" 8895 " WHERE subject_type = 'role' AND subject IN" 8916 int column_found = 0;
8933 init_iterator (&column_data,
"PRAGMA table_info (targets_trash);");
8934 while (
next (&column_data) && column_found == 0)
8936 const char* column_name;
8939 column_found = (strcmp (column_name,
"alive_test") == 0);
8943 if (column_found == 0)
8945 sql (
"ALTER TABLE targets_trash ADD COLUMN alive_test;");
8946 sql (
"UPDATE targets_trash SET alive_test = 0;");
8979 sql (
"ALTER TABLE lsc_credentials RENAME TO lsc_credentials_123;");
8980 sql (
"ALTER TABLE lsc_credentials_trash RENAME TO lsc_credentials_trash_123;");
8983 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials" 8984 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name," 8985 " login, password, comment, private_key, rpm, deb, exe," 8986 " creation_time, modification_time);");
8987 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials_trash" 8988 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name," 8989 " login, password, comment, private_key, rpm, deb, exe," 8990 " creation_time, modification_time);");
8993 sql (
"INSERT INTO lsc_credentials" 8994 " (id, uuid, owner , name, login, password, comment, private_key, rpm," 8995 " deb, exe, creation_time, modification_time)" 8996 " SELECT id, uuid, owner, name, login, password, comment, private_key," 8997 " rpm, deb, exe, creation_time, modification_time" 8998 " FROM lsc_credentials_123;");
9000 sql (
"INSERT INTO lsc_credentials_trash" 9001 " (id, uuid, owner , name, login, password, comment, private_key, rpm," 9002 " deb, exe, creation_time, modification_time)" 9003 " SELECT id, uuid, owner, name, login, password, comment, private_key," 9004 " rpm, deb, exe, creation_time, modification_time" 9005 " FROM lsc_credentials_123;");
9008 sql (
"DROP TABLE lsc_credentials_123;");
9009 sql (
"DROP TABLE lsc_credentials_trash_123;");
9041 sql (
"ALTER TABLE tasks ADD COLUMN scanner;");
9042 sql (
"ALTER TABLE configs ADD COLUMN type;");
9043 sql (
"ALTER TABLE configs_trash ADD COLUMN type;");
9044 sql (
"UPDATE tasks SET scanner = 0;");
9045 sql (
"UPDATE configs SET type = 0;");
9046 sql (
"UPDATE configs_trash SET type = 0;");
9081 sql (
"ALTER TABLE tasks RENAME TO tasks_125;");
9085 sql (
"CREATE TABLE IF NOT EXISTS tasks" 9086 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, hidden INTEGER," 9087 " time, comment, run_status INTEGER, start_time, end_time," 9088 " config INTEGER, target INTEGER, schedule INTEGER, schedule_next_time," 9089 " slave INTEGER, config_location INTEGER, target_location INTEGER," 9090 " schedule_location INTEGER, slave_location INTEGER," 9091 " upload_result_count INTEGER, hosts_ordering, scanner, alterable," 9092 " creation_time, modification_time);");
9096 sql (
"INSERT into tasks" 9097 " (id, uuid, owner, name, hidden," 9098 " time, comment, run_status, start_time, end_time," 9099 " config, target, schedule, schedule_next_time," 9100 " slave, config_location, target_location," 9101 " schedule_location, slave_location," 9102 " upload_result_count, hosts_ordering, scanner, alterable," 9103 " creation_time, modification_time)" 9105 " id, uuid, owner, name, hidden," 9106 " time, comment, run_status, start_time, end_time," 9107 " config, target, schedule, schedule_next_time," 9108 " slave, config_location, target_location," 9109 " schedule_location, slave_location," 9110 " upload_result_count, hosts_ordering, scanner, alterable," 9111 " creation_time, modification_time" 9112 " FROM tasks_125;");
9116 sql (
"DROP TABLE tasks_125;");
9151 sql (
"UPDATE permissions" 9152 " SET resource_uuid = (SELECT uuid FROM tasks WHERE tasks.id = resource)" 9153 " WHERE resource_type = 'task'" 9154 " AND resource != 0;");
9187 sql (
"ALTER TABLE results ADD COLUMN qod INTEGER;");
9188 sql (
"UPDATE results SET qod = -1;");
9220 sql (
"CREATE TABLE IF NOT EXISTS scanners" 9221 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment," 9222 " host, port, type, creation_time, modification_time);");
9223 sql (
"CREATE TABLE IF NOT EXISTS scanners_trash" 9224 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment," 9225 " host, port, type, creation_time, modification_time);");
9229 if (
sql_int (
"SELECT count(*) FROM scanners WHERE uuid = '%s';",
9231 sql (
"INSERT INTO scanners" 9232 " (uuid, owner, name, host, port, type," 9233 " creation_time, modification_time)" 9238 sql (
"UPDATE tasks SET scanner =" 9240 " WHERE scanner = 0 OR scanner IS NULL;");
9259 char *ca_pub, *key_pub, *key_priv;
9260 char *quoted_ca_pub, *quoted_key_pub, *quoted_key_priv;
9261 GError *error = NULL;
9277 sql (
"ALTER TABLE scanners ADD COLUMN ca_pub;");
9278 sql (
"ALTER TABLE scanners ADD COLUMN key_pub;");
9279 sql (
"ALTER TABLE scanners ADD COLUMN key_priv;");
9280 sql (
"ALTER TABLE scanners_trash ADD COLUMN ca_pub;");
9281 sql (
"ALTER TABLE scanners_trash ADD COLUMN key_pub;");
9282 sql (
"ALTER TABLE scanners_trash ADD COLUMN key_priv;");
9285 if (!g_file_get_contents (
CACERT, &ca_pub, NULL, &error))
9287 g_warning (
"%s: %s\n", __FUNCTION__, error->message);
9288 g_error_free (error);
9291 if (!g_file_get_contents (
CLIENTCERT, &key_pub, NULL, &error))
9293 g_warning (
"%s: %s\n", __FUNCTION__, error->message);
9294 g_error_free (error);
9298 if (!g_file_get_contents (
CLIENTKEY, &key_priv, NULL, &error))
9300 g_warning (
"%s: %s\n", __FUNCTION__, error->message);
9301 g_error_free (error);
9314 sql (
"UPDATE scanners SET ca_pub = '%s', key_pub = '%s', key_priv = '%s';",
9315 quoted_ca_pub, quoted_key_pub, quoted_key_priv);
9316 sql (
"UPDATE scanners_trash SET ca_pub = '%s', key_pub = '%s'," 9317 " key_priv = '%s';",
9318 quoted_ca_pub, quoted_key_pub, quoted_key_priv);
9319 g_free (quoted_ca_pub);
9320 g_free (quoted_key_pub);
9321 g_free (quoted_key_priv);
9353 sql (
"DELETE FROM permissions" 9354 " WHERE name = 'get_target_locators'" 9355 " OR name = 'pause_task'" 9356 " OR name = 'resume_paused_task';");
9358 sql (
"DELETE FROM permissions_trash" 9359 " WHERE name = 'get_target_locators'" 9360 " OR name = 'pause_task'" 9361 " OR name = 'resume_paused_task';");
9397 sql (
"ALTER TABLE lsc_credentials RENAME TO lsc_credentials_131;");
9398 sql (
"ALTER TABLE lsc_credentials_trash RENAME TO lsc_credentials_trash_131;");
9404 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials" 9405 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, login," 9406 " password, comment, private_key TEXT," 9407 " creation_time, modification_time);");
9408 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials_trash" 9409 " (id INTEGER PRIMARY KEY, uuid UNIQUE, owner INTEGER, name, login," 9410 " password, comment, private_key TEXT," 9411 " creation_time, modification_time);");
9415 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials" 9416 " (id SERIAL PRIMARY KEY," 9417 " uuid text UNIQUE NOT NULL," 9418 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 9419 " name text NOT NULL," 9423 " private_key text," 9424 " creation_time integer," 9425 " modification_time integer);");
9427 sql (
"CREATE TABLE IF NOT EXISTS lsc_credentials_trash" 9428 " (id SERIAL PRIMARY KEY," 9429 " uuid text UNIQUE NOT NULL," 9430 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 9431 " name text NOT NULL," 9435 " private_key text," 9436 " creation_time integer," 9437 " modification_time integer);");
9442 sql (
"INSERT into lsc_credentials" 9443 " (id, uuid, owner, name, comment, login, password, private_key," 9444 " creation_time, modification_time)" 9446 " id, uuid, owner, name, comment, login, password, private_key," 9447 " creation_time, modification_time" 9448 " FROM lsc_credentials_131;");
9449 sql (
"INSERT into lsc_credentials_trash" 9450 " (id, uuid, owner, name, comment, login, password, private_key," 9451 " creation_time, modification_time)" 9453 " id, uuid, owner, name, comment, login, password, private_key," 9454 " creation_time, modification_time" 9455 " FROM lsc_credentials_trash_131;");
9459 sql (
"DROP TABLE lsc_credentials_131;");
9460 sql (
"DROP TABLE lsc_credentials_trash_131;");
9493 sql (
"ALTER TABLE results ADD COLUMN owner INTEGER;");
9495 sql (
"ALTER TABLE results ADD COLUMN owner integer" 9496 " REFERENCES users (id) ON DELETE RESTRICT;");
9498 sql (
"ALTER TABLE results ADD COLUMN date integer;");
9501 sql (
"UPDATE results" 9502 " SET owner = (SELECT owner FROM reports" 9503 " WHERE reports.id = results.report)," 9504 " date = (SELECT date FROM reports" 9505 " WHERE reports.id = results.report);");
9539 sql (
"ALTER TABLE targets ADD COLUMN esxi_lsc_credential;");
9540 sql (
"ALTER TABLE targets_trash ADD COLUMN esxi_lsc_credential;");
9541 sql (
"ALTER TABLE targets_trash ADD COLUMN esxi_location INTEGER;");
9545 sql (
"ALTER TABLE targets ADD COLUMN esxi_lsc_credential integer;");
9547 sql (
"ALTER TABLE targets_trash ADD COLUMN esxi_lsc_credential integer;");
9549 sql (
"ALTER TABLE targets_trash ADD COLUMN esxi_location integer;");
9583 sql (
"DROP TABLE report_results;");
9619 " SET end_time = (SELECT reports.end_time FROM reports" 9620 " WHERE task = tasks.id ORDER BY id DESC LIMIT 1)" 9621 " WHERE EXISTS (SELECT id FROM reports WHERE task = tasks.id);");
9624 " SET end_time = NULL" 9625 " WHERE NOT EXISTS (SELECT id FROM reports WHERE task = tasks.id);");
9659 sql (
"DELETE FROM permissions" 9660 " WHERE subject_type = 'role' AND subject IN" 9695 sql (
"INSERT INTO permissions" 9696 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 9697 " resource_location, subject_type, subject, subject_location," 9698 " creation_time, modification_time)" 9700 " (make_uuid (), NULL, 'get_aggregates', '', ''," 9702 " (SELECT id FROM roles WHERE uuid = '%s')," 9706 sql (
"INSERT INTO permissions" 9707 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 9708 " resource_location, subject_type, subject, subject_location," 9709 " creation_time, modification_time)" 9711 " (make_uuid (), NULL, 'get_aggregates', '', ''," 9713 " (SELECT id FROM roles WHERE uuid = '%s')," 9717 sql (
"INSERT INTO permissions" 9718 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 9719 " resource_location, subject_type, subject, subject_location," 9720 " creation_time, modification_time)" 9722 " (make_uuid (), NULL, 'get_aggregates', '', ''," 9724 " (SELECT id FROM roles WHERE uuid = '%s')," 9728 sql (
"INSERT INTO permissions" 9729 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 9730 " resource_location, subject_type, subject, subject_location," 9731 " creation_time, modification_time)" 9733 " (make_uuid (), NULL, 'get_aggregates', '', ''," 9735 " (SELECT id FROM roles WHERE uuid = '%s')," 9770 sql (
"ALTER TABLE nvts ADD COLUMN solution_type text;");
9774 while (
next (&nvts))
9778 gchar *solution_type =
tag_value (tags,
"solution_type");
9779 gchar *quoted_solution_type =
sql_quote (solution_type);
9781 sql (
"UPDATE nvts SET" 9782 " solution_type = '%s'" 9783 " WHERE id = %llu;",
9784 quoted_solution_type,
9787 g_free (solution_type);
9788 g_free (quoted_solution_type);
9820 sql (
"UPDATE permissions SET" 9821 " name = 'resume_task'" 9822 " WHERE name = 'resume_stopped_task';");
9824 sql (
"UPDATE permissions_trash SET" 9825 " name = 'resume_task'" 9826 " WHERE name = 'resume_stopped_task';");
9856 sql (
"ALTER TABLE config_preferences ADD COLUMN default_value text;");
9857 sql (
"ALTER TABLE config_preferences_trash ADD COLUMN default_value text;");
9890 sql (
"DELETE FROM permissions WHERE name = 'resume_or_start_task';");
9892 sql (
"DELETE FROM permissions_trash WHERE name = 'resume_or_start_task';");
9927 " WHERE (qod IS NULL) OR (qod <= 0);");
9960 sql (
"ALTER TABLE nvts ADD COLUMN qod INTEGER;");
9961 sql (
"ALTER TABLE nvts ADD COLUMN qod_type TEXT;");
9962 sql (
"ALTER TABLE results ADD COLUMN qod_type TEXT;");
9966 sql (
"UPDATE results SET qod_type='';");
9968 init_iterator (&nvts,
"SELECT id, tag FROM nvts WHERE tag LIKE '%%|qod%%';");
9969 while (
next (&nvts))
9971 gchar *qod_str, *qod_type, *quoted_qod_type;
9978 if (qod_str == NULL || sscanf (qod_str,
"%d", &qod) != 1)
9981 sql (
"UPDATE nvts SET qod=%d, qod_type='%s' WHERE id=%llu;",
9986 g_free (quoted_qod_type);
10020 sql (
"ALTER TABLE tasks ADD COLUMN schedule_periods INTEGER;");
10021 sql (
"UPDATE tasks SET schedule_periods=0;");
10053 sql (
"DROP VIEW IF EXISTS result_new_severities;");
10054 sql (
"DROP VIEW IF EXISTS result_overrides;");
10055 sql (
"DELETE FROM report_counts;");
10087 sql (
"ALTER TABLE report_counts ADD COLUMN min_qod INTEGER;");
10153 sql (
"ALTER TABLE tasks ADD COLUMN scanner_location INTEGER;");
10186 sql (
"DROP VIEW IF EXISTS result_new_severities;");
10197 #define INSERT_PERMISSION(name, role) \ 10198 sql ("INSERT INTO permissions" \ 10199 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," \ 10200 " resource_location, subject_type, subject, subject_location," \ 10201 " creation_time, modification_time)" \ 10203 " (make_uuid (), NULL, '" G_STRINGIFY (name) "', '', ''," \ 10204 " 0, '', " G_STRINGIFY (LOCATION_TABLE) ", 'role'," \ 10205 " (SELECT id FROM roles WHERE uuid = '%s')," \ 10206 " " G_STRINGIFY (LOCATION_TABLE) ", m_now (), m_now ());", \ 10284 #define DELETE_PERMISSION(name, role) \ 10285 sql ("DELETE FROM permissions" \ 10286 " WHERE subject_type = 'role'" \ 10287 " AND subject_location = " G_STRINGIFY (LOCATION_TABLE) \ 10288 " AND subject = (SELECT id FROM roles WHERE uuid = '%s')" \ 10289 " AND name = '" G_STRINGIFY (name) "';", \ 10341 const char *primary_key_type =
sql_is_sqlite3 () ?
"INTEGER" :
"SERIAL";
10357 sql (
"CREATE TABLE credentials" 10358 " (id %s PRIMARY KEY," 10359 " uuid text UNIQUE NOT NULL," 10360 " owner integer%s," 10361 " name text NOT NULL," 10363 " creation_time integer," 10364 " modification_time integer," 10367 sql_is_sqlite3() ?
"" :
" REFERENCES users (id) ON DELETE RESTRICT");
10369 sql (
"CREATE TABLE credentials_trash" 10370 " (id %s PRIMARY KEY," 10371 " uuid text UNIQUE NOT NULL," 10372 " owner integer%s," 10373 " name text NOT NULL," 10375 " creation_time integer," 10376 " modification_time integer," 10379 sql_is_sqlite3() ?
"" :
" REFERENCES users (id) ON DELETE RESTRICT");
10381 sql (
"CREATE TABLE credentials_data" 10382 " (id %s PRIMARY KEY," 10383 " credential INTEGER%s," 10389 :
" REFERENCES credentials (id) ON DELETE RESTRICT");
10391 sql (
"CREATE TABLE credentials_trash_data" 10392 " (id %s PRIMARY KEY," 10393 " credential INTEGER%s," 10399 :
" REFERENCES credentials_trash (id) ON DELETE RESTRICT");
10402 sql (
"INSERT INTO credentials" 10403 " (id, uuid, owner, name, comment, creation_time, modification_time)" 10405 " id, uuid, owner, name, comment, creation_time, modification_time" 10406 " FROM lsc_credentials;");
10408 sql (
"INSERT INTO credentials_trash" 10409 " (id, uuid, owner, name, comment, creation_time, modification_time)" 10411 " id, uuid, owner, name, comment, creation_time, modification_time" 10412 " FROM lsc_credentials_trash;");
10415 sql (
"INSERT INTO credentials_data (credential, type, value)" 10416 " SELECT id, 'username', login FROM lsc_credentials" 10417 " WHERE login IS NOT NULL;");
10419 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 10420 " SELECT id, 'username', login FROM lsc_credentials_trash" 10421 " WHERE login IS NOT NULL;");
10423 sql (
"INSERT INTO credentials_data (credential, type, value)" 10424 " SELECT id, 'password', password FROM lsc_credentials" 10425 " WHERE password IS NOT NULL AND private_key != ';;encrypted;;';");
10427 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 10428 " SELECT id, 'password', password FROM lsc_credentials_trash" 10429 " WHERE password IS NOT NULL AND private_key != ';;encrypted;;';");
10431 sql (
"INSERT INTO credentials_data (credential, type, value)" 10432 " SELECT id, 'private_key', private_key FROM lsc_credentials" 10433 " WHERE password IS NOT NULL AND private_key != ';;encrypted;;';");
10435 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 10436 " SELECT id, 'private_key', private_key FROM lsc_credentials_trash" 10437 " WHERE password IS NOT NULL AND private_key != ';;encrypted;;';");
10439 sql (
"INSERT INTO credentials_data (credential, type, value)" 10440 " SELECT id, 'secret', password FROM lsc_credentials" 10441 " WHERE password IS NOT NULL AND private_key = ';;encrypted;;';");
10443 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 10444 " SELECT id, 'secret', password FROM lsc_credentials_trash" 10445 " WHERE password IS NOT NULL AND private_key = ';;encrypted;;';");
10451 sql (
"SELECT setval ('credentials_id_seq'," 10452 " (SELECT max (id) + 1 FROM credentials));");
10454 sql (
"SELECT setval ('credentials_trash_id_seq'," 10455 " (SELECT max (id) + 1 FROM credentials_trash));");
10457 sql (
"SELECT setval ('credentials_data_id_seq'," 10458 " (SELECT max (id) + 1 FROM credentials_data));");
10460 sql (
"SELECT setval ('credentials_trash_data_id_seq'," 10461 " (SELECT max (id) + 1" 10462 " FROM credentials_trash_data));");
10467 "SELECT id, password, private_key, 0" 10468 " FROM lsc_credentials" 10470 " SELECT id, password, private_key, 1" 10471 " FROM lsc_credentials_trash;");
10473 while (
next (&credentials))
10477 const char *password, *privkey;
10485 if (privkey == NULL)
10487 else if (strcmp (privkey,
";;encrypted;;"))
10500 sql (
"UPDATE %s SET type = '%s' WHERE id = %llu;",
10501 is_trash ?
"credentials_trash" :
"credentials",
10507 sql (
"DROP TABLE lsc_credentials;");
10508 sql (
"DROP TABLE lsc_credentials_trash;");
10511 sql (
"UPDATE tags SET resource_type = 'credential'" 10512 " WHERE resource_type = 'lsc_credential';");
10513 sql (
"UPDATE tags_trash SET resource_type = 'credential'" 10514 " WHERE resource_type = 'lsc_credential';");
10517 sql (
"UPDATE permissions SET name = 'create_credential'" 10518 " WHERE name = 'create_lsc_credential';");
10519 sql (
"UPDATE permissions SET name = 'delete_credential'" 10520 " WHERE name = 'delete_lsc_credential';");
10521 sql (
"UPDATE permissions SET name = 'get_credentials'" 10522 " WHERE name = 'get_lsc_credentials';");
10523 sql (
"UPDATE permissions SET name = 'modify_credential'" 10524 " WHERE name = 'modify_lsc_credential';");
10526 sql (
"UPDATE permissions_trash SET name = 'create_credential'" 10527 " WHERE name = 'create_lsc_credential';");
10528 sql (
"UPDATE permissions_trash SET name = 'delete_credential'" 10529 " WHERE name = 'delete_lsc_credential';");
10530 sql (
"UPDATE permissions_trash SET name = 'get_credentials'" 10531 " WHERE name = 'get_lsc_credentials';");
10532 sql (
"UPDATE permissions_trash SET name = 'modify_credential'" 10533 " WHERE name = 'modify_lsc_credential';");
10568 sql (
"UPDATE alerts SET method = method + 1 WHERE method >= 4;");
10571 sql (
"ALTER TABLE reports ADD COLUMN flags INTEGER;");
10572 sql (
"UPDATE reports SET flags = 0;");
10607 sql (
"ALTER TABLE targets RENAME TO targets_155;");
10608 sql (
"ALTER TABLE targets_trash RENAME TO targets_trash_155;");
10611 sql (
"CREATE TABLE IF NOT EXISTS targets" 10612 " (id INTEGER PRIMARY KEY," 10613 " uuid text UNIQUE NOT NULL," 10615 " name text NOT NULL," 10617 " exclude_hosts text," 10618 " reverse_lookup_only integer," 10619 " reverse_lookup_unify integer," 10621 " port_list integer," 10622 " alive_test integer," 10623 " creation_time integer," 10624 " modification_time integer);");
10626 sql (
"CREATE TABLE IF NOT EXISTS targets_trash" 10627 " (id INTEGER PRIMARY KEY," 10628 " uuid text UNIQUE NOT NULL," 10630 " name text NOT NULL," 10632 " exclude_hosts text," 10633 " reverse_lookup_only integer," 10634 " reverse_lookup_unify integer," 10636 " port_list integer," 10637 " port_list_location integer," 10638 " alive_test integer," 10639 " creation_time integer," 10640 " modification_time integer);");
10642 sql (
"CREATE TABLE IF NOT EXISTS targets_login_data" 10643 " (id INTEGER PRIMARY KEY," 10646 " credential INTEGER," 10647 " port INTEGER);");
10649 sql (
"CREATE TABLE IF NOT EXISTS targets_trash_login_data" 10650 " (id INTEGER PRIMARY KEY," 10653 " credential INTEGER," 10655 " credential_location INTEGER);");
10658 sql (
"INSERT INTO targets" 10659 " (id, uuid, owner, name, hosts, exclude_hosts," 10660 " reverse_lookup_only, reverse_lookup_unify, comment," 10661 " port_list, alive_test, creation_time, modification_time)" 10662 " SELECT id, uuid, owner, name, hosts, exclude_hosts," 10663 " reverse_lookup_only, reverse_lookup_unify, comment," 10664 " port_range, alive_test, creation_time, modification_time" 10665 " FROM targets_155;");
10667 sql (
"INSERT INTO targets_trash" 10668 " (id, uuid, owner, name, hosts, exclude_hosts," 10669 " reverse_lookup_only, reverse_lookup_unify, comment," 10670 " port_list, alive_test, creation_time, modification_time)" 10671 " SELECT id, uuid, owner, name, hosts, exclude_hosts," 10672 " reverse_lookup_only, reverse_lookup_unify, comment," 10673 " port_range, alive_test, creation_time, modification_time" 10674 " FROM targets_trash_155;");
10677 sql (
"INSERT INTO targets_login_data" 10678 " (target, type, credential, port)" 10679 " SELECT id, 'ssh', lsc_credential, CAST (ssh_port AS integer)" 10680 " FROM targets_155 WHERE lsc_credential != 0;");
10682 sql (
"INSERT INTO targets_login_data" 10683 " (target, type, credential, port)" 10684 " SELECT id, 'smb', smb_lsc_credential, 0" 10685 " FROM targets_155 WHERE smb_lsc_credential != 0;");
10687 sql (
"INSERT INTO targets_login_data" 10688 " (target, type, credential, port)" 10689 " SELECT id, 'esxi', esxi_lsc_credential, 0" 10690 " FROM targets_155 WHERE esxi_lsc_credential != 0;");
10693 sql (
"INSERT INTO targets_trash_login_data" 10694 " (target, type, credential, port, credential_location)" 10695 " SELECT id, 'ssh', lsc_credential, CAST (ssh_port AS integer)," 10697 " FROM targets_trash_155 WHERE lsc_credential != 0;");
10699 sql (
"INSERT INTO targets_trash_login_data" 10700 " (target, type, credential, port, credential_location)" 10701 " SELECT id, 'smb', smb_lsc_credential, 0, smb_location" 10702 " FROM targets_trash_155 WHERE smb_lsc_credential != 0;");
10704 sql (
"INSERT INTO targets_trash_login_data" 10705 " (target, type, credential, port, credential_location)" 10706 " SELECT id, 'esxi', esxi_lsc_credential, 0, esxi_location" 10707 " FROM targets_trash_155 WHERE esxi_lsc_credential != 0;");
10710 sql (
"DROP TABLE targets_155;");
10711 sql (
"DROP TABLE targets_trash_155;");
10717 sql (
"CREATE TABLE IF NOT EXISTS targets_login_data" 10718 " (id SERIAL PRIMARY KEY," 10719 " target INTEGER REFERENCES targets (id)," 10721 " credential INTEGER REFERENCES credentials (id)," 10722 " port INTEGER);");
10724 sql (
"CREATE TABLE IF NOT EXISTS targets_trash_login_data" 10725 " (id SERIAL PRIMARY KEY," 10726 " target INTEGER REFERENCES targets_trash (id)," 10728 " credential INTEGER," 10730 " credential_location INTEGER);");
10733 sql (
"INSERT INTO targets_login_data" 10734 " (target, type, credential, port)" 10735 " SELECT id, 'ssh', lsc_credential, CAST (ssh_port AS integer)" 10736 " FROM targets WHERE lsc_credential != 0;");
10738 sql (
"INSERT INTO targets_login_data" 10739 " (target, type, credential, port)" 10740 " SELECT id, 'smb', smb_lsc_credential, 0" 10741 " FROM targets WHERE smb_lsc_credential != 0;");
10743 sql (
"INSERT INTO targets_login_data" 10744 " (target, type, credential, port)" 10745 " SELECT id, 'esxi', esxi_lsc_credential, 0" 10746 " FROM targets WHERE esxi_lsc_credential != 0;");
10749 sql (
"INSERT INTO targets_trash_login_data" 10750 " (target, type, credential, port, credential_location)" 10751 " SELECT id, 'ssh', lsc_credential, CAST (ssh_port AS integer)," 10753 " FROM targets_trash WHERE lsc_credential != 0;");
10755 sql (
"INSERT INTO targets_trash_login_data" 10756 " (target, type, credential, port, credential_location)" 10757 " SELECT id, 'smb', smb_lsc_credential, 0, smb_location" 10758 " FROM targets_trash WHERE smb_lsc_credential != 0;");
10760 sql (
"INSERT INTO targets_trash_login_data" 10761 " (target, type, credential, port, credential_location)" 10762 " SELECT id, 'esxi', esxi_lsc_credential, 0, esxi_location" 10763 " FROM targets_trash WHERE esxi_lsc_credential != 0;");
10766 sql (
"ALTER TABLE targets DROP COLUMN lsc_credential;");
10767 sql (
"ALTER TABLE targets DROP COLUMN ssh_port;");
10768 sql (
"ALTER TABLE targets DROP COLUMN smb_lsc_credential;");
10769 sql (
"ALTER TABLE targets DROP COLUMN esxi_lsc_credential;");
10770 sql (
"ALTER TABLE targets RENAME COLUMN port_range TO port_list;");
10772 sql (
"ALTER TABLE targets_trash DROP COLUMN lsc_credential;");
10773 sql (
"ALTER TABLE targets_trash DROP COLUMN ssh_location;");
10774 sql (
"ALTER TABLE targets_trash DROP COLUMN ssh_port;");
10775 sql (
"ALTER TABLE targets_trash DROP COLUMN smb_lsc_credential;");
10776 sql (
"ALTER TABLE targets_trash DROP COLUMN smb_location;");
10777 sql (
"ALTER TABLE targets_trash DROP COLUMN esxi_lsc_credential;");
10778 sql (
"ALTER TABLE targets_trash DROP COLUMN esxi_location;");
10779 sql (
"ALTER TABLE targets_trash RENAME COLUMN port_range TO port_list;");
10815 sql (
"ALTER TABLE slaves ADD COLUMN credential INTEGER;");
10819 sql (
"ALTER TABLE slaves ADD COLUMN credential INTEGER" 10820 " REFERENCES credentials (id) ON DELETE RESTRICT;");
10822 sql (
"ALTER TABLE slaves_trash ADD COLUMN credential INTEGER;");
10823 sql (
"ALTER TABLE slaves_trash ADD COLUMN credential_location INTEGER;");
10827 "SELECT id, name, login, password, owner FROM slaves;");
10829 while (
next (&slaves))
10832 const char *name, *login, *password;
10835 gchar *quoted_name, *quoted_login;
10846 if (
sql_int (
"SELECT count(*) FROM credentials" 10847 " WHERE name = 'Credential for Slave %s'" 10848 " AND owner = %llu;",
10849 quoted_name, owner))
10850 sql (
"INSERT INTO credentials" 10851 " (uuid, name, owner, comment, type," 10852 " creation_time, modification_time)" 10855 " uniquify ('credential', 'Credential for Slave %s', %llu, '')," 10856 " %llu, 'Autogenerated by migration', 'up'," 10857 " m_now (), m_now ());",
10858 quoted_name, owner, owner);
10860 sql (
"INSERT INTO credentials" 10861 " (uuid, name, owner, comment, type," 10862 " creation_time, modification_time)" 10864 " (make_uuid (), 'Credential for Slave %s'," 10865 " %llu, 'Autogenerated by migration', 'up'," 10866 " m_now (), m_now ());",
10867 quoted_name, owner);
10871 sql (
"UPDATE slaves SET credential = %llu WHERE id = %llu;",
10872 new_credential, slave);
10874 sql (
"INSERT INTO credentials_data (credential, type, value)" 10875 " VALUES (%llu, 'username', '%s');",
10876 new_credential, quoted_login);
10880 gchar *quoted_password;
10881 quoted_password =
sql_quote (password);
10882 sql (
"INSERT INTO credentials_data (credential, type, value)" 10883 " VALUES (%llu, 'password', '%s');",
10884 new_credential, quoted_password);
10885 g_free (quoted_password);
10890 gchar *quoted_secret;
10896 "password", password, NULL);
10899 g_free (quoted_name);
10900 g_free (quoted_login);
10906 sql (
"INSERT INTO credentials_data (credential, type, value)" 10907 " VALUES (%llu, 'secret', '%s');",
10908 new_credential, quoted_secret);
10909 g_free (quoted_secret);
10913 " permissions (uuid, owner, name," 10914 " comment, resource_type, resource," 10916 " resource_location, subject_type, subject," 10917 " subject_location, creation_time, modification_time)" 10918 " SELECT make_uuid(), owner, 'get_credentials'," 10919 " 'Autogenerated by Slave migration', 'credential', %llu," 10920 " (SELECT uuid FROM credentials WHERE id=%llu)," 10922 " subject_location, m_now (), m_now ()" 10923 " FROM permissions" 10924 " WHERE resource = %llu" 10925 " AND resource_type = 'slave'" 10927 " GROUP BY owner, subject_type, subject, subject_location;",
10928 new_credential, new_credential, slave);
10931 " permissions_trash (uuid, owner, name," 10932 " comment, resource_type, resource," 10934 " resource_location, subject_type, subject," 10935 " subject_location," 10936 " creation_time, modification_time)" 10937 " SELECT make_uuid(), owner, 'get_credentials'," 10938 " 'Autogenerated by Slave migration', 'credential', %llu," 10939 " (SELECT uuid FROM credentials WHERE id=%llu)," 10941 " subject_location, m_now (), m_now ()" 10942 " FROM permissions_trash" 10943 " WHERE resource = %llu" 10944 " AND resource_type = 'slave'" 10946 " GROUP BY owner, subject_type, subject, subject_location;",
10947 new_credential, new_credential, slave);
10949 g_free (quoted_name);
10950 g_free (quoted_login);
10956 "SELECT id, name, login, password, owner" 10957 " FROM slaves_trash;");
10959 while (
next (&slaves))
10962 const char *name, *login, *password;
10965 gchar *quoted_name, *quoted_login;
10976 sql (
"INSERT INTO credentials_trash" 10977 " (uuid, name, owner, comment, type," 10978 " creation_time, modification_time)" 10980 " (make_uuid (), 'Credential for Slave %s'," 10981 " %llu, 'Autogenerated by migration', 'up'," 10982 " m_now (), m_now ());",
10983 quoted_name, owner);
10987 sql (
"UPDATE slaves_trash SET credential = %llu," 10989 " WHERE id = %llu;",
10990 new_credential, slave);
10992 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 10993 " VALUES (%llu, 'username', '%s');",
10994 new_credential, quoted_login);
10998 gchar *quoted_password;
10999 quoted_password =
sql_quote (password);
11000 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 11001 " VALUES (%llu, 'password', '%s');",
11002 new_credential, quoted_password);
11003 g_free (quoted_password);
11008 gchar *quoted_secret;
11014 "password", password, NULL);
11017 g_free (quoted_name);
11018 g_free (quoted_login);
11024 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 11025 " VALUES (%llu, 'secret', '%s');",
11026 new_credential, quoted_secret);
11027 g_free (quoted_secret);
11031 " permissions (uuid, owner, name," 11032 " comment, resource_type, resource," 11034 " resource_location, subject_type, subject," 11035 " subject_location," 11036 " creation_time, modification_time)" 11037 " SELECT make_uuid(), owner, 'get_credentials'," 11038 " 'Autogenerated by Slave migration', 'credential', %llu," 11039 " (SELECT uuid FROM credentials_trash WHERE id=%llu)," 11041 " subject_location," 11042 " m_now (), m_now ()" 11043 " FROM permissions" 11044 " WHERE resource = %llu" 11045 " AND resource_type = 'slave'" 11047 " GROUP BY owner, subject_type, subject, subject_location;",
11048 new_credential, new_credential, slave);
11051 " permissions_trash (uuid, owner, name," 11052 " comment, resource_type, resource," 11054 " resource_location, subject_type, subject," 11055 " subject_location," 11056 " creation_time, modification_time)" 11057 " SELECT make_uuid(), owner, 'get_credentials'," 11058 " 'Autogenerated by Slave migration', 'credential', %llu," 11059 " (SELECT uuid FROM credentials_trash WHERE id=%llu)," 11061 " subject_location," 11062 " m_now (), m_now ()" 11063 " FROM permissions_trash" 11064 " WHERE resource = %llu" 11065 " AND resource_type = 'slave'" 11067 " GROUP BY owner, subject_type, subject, subject_location;",
11068 new_credential, new_credential, slave);
11070 g_free (quoted_name);
11071 g_free (quoted_login);
11078 sql (
"ALTER TABLE slaves RENAME TO slaves_156;");
11079 sql (
"ALTER TABLE slaves_trash RENAME TO slaves_trash_156;");
11081 sql (
"CREATE TABLE IF NOT EXISTS slaves" 11082 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment, host," 11083 " port, creation_time, modification_time, credential INTEGER);");
11084 sql (
"CREATE TABLE IF NOT EXISTS slaves_trash" 11085 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment, host," 11086 " port, creation_time, modification_time, credential INTEGER," 11087 " credential_location INTEGER);");
11089 sql (
"INSERT INTO slaves" 11090 " (id, uuid, owner, name, comment, host, port," 11091 " creation_time, modification_time, credential)" 11092 " SELECT id, uuid, owner, name, comment, host, port," 11093 " creation_time, modification_time, credential" 11094 " FROM slaves_156;");
11095 sql (
"INSERT INTO slaves_trash" 11096 " (id, uuid, owner, name, comment, host, port," 11097 " creation_time, modification_time, credential," 11098 " credential_location)" 11099 " SELECT id, uuid, owner, name, comment, host, port," 11100 " creation_time, modification_time, credential," 11101 " credential_location" 11102 " FROM slaves_trash_156;");
11104 sql (
"DROP TABLE slaves_156;");
11105 sql (
"DROP TABLE slaves_trash_156;");
11109 sql (
"ALTER TABLE slaves DROP COLUMN login;");
11110 sql (
"ALTER TABLE slaves DROP COLUMN password;");
11111 sql (
"ALTER TABLE slaves_trash DROP COLUMN login;");
11112 sql (
"ALTER TABLE slaves_trash DROP COLUMN password;");
11147 sql (
"ALTER TABLE configs ADD COLUMN scanner INTEGER;");
11148 sql (
"ALTER TABLE configs_trash ADD COLUMN scanner INTEGER;");
11152 sql (
"ALTER TABLE configs ADD COLUMN scanner INTEGER" 11153 " REFERENCES scanners (id) ON DELETE RESTRICT;");
11154 sql (
"ALTER TABLE configs_trash ADD COLUMN scanner INTEGER" 11155 " REFERENCES scanners (id) ON DELETE RESTRICT;");
11159 sql (
"UPDATE configs" 11160 " SET scanner = (SELECT id FROM scanners WHERE type = %d LIMIT 1)" 11196 sql (
"ALTER TABLE scanners ADD COLUMN credential INTEGER;");
11200 sql (
"ALTER TABLE scanners ADD COLUMN credential INTEGER" 11201 " REFERENCES credentials (id) ON DELETE RESTRICT;");
11203 sql (
"ALTER TABLE scanners_trash ADD COLUMN credential INTEGER;");
11204 sql (
"ALTER TABLE scanners_trash ADD COLUMN credential_location INTEGER;");
11208 "SELECT id, name, key_pub, key_priv, owner FROM scanners;");
11210 while (
next (&scanners))
11213 const char *name, *key_pub, *key_priv;
11216 gchar *quoted_name, *quoted_key_pub;
11225 if (key_pub == NULL || key_priv == NULL)
11233 if (
sql_int (
"SELECT count(*) FROM credentials" 11234 " WHERE name = 'Credential for Scanner %s'" 11235 " AND owner = %llu;",
11236 quoted_name, owner))
11237 sql (
"INSERT INTO credentials" 11238 " (uuid, name, owner, comment, type," 11239 " creation_time, modification_time)" 11242 " uniquify ('credential'," 11243 " 'Credential for Scanner %s', %llu, '')," 11244 " %llu, 'Autogenerated by migration', 'cc'," 11245 " m_now (), m_now ());",
11246 quoted_name, owner, owner);
11248 sql (
"INSERT INTO credentials" 11249 " (uuid, name, owner, comment, type," 11250 " creation_time, modification_time)" 11252 " (make_uuid (), 'Credential for Scanner %s'," 11253 " %llu, 'Autogenerated by migration', 'cc'," 11254 " m_now (), m_now ());",
11255 quoted_name, owner);
11259 if (
sql_int (
"SELECT count(*) FROM credentials" 11260 " WHERE name = 'Credential for Scanner %s'" 11261 " AND owner = NULL;",
11262 quoted_name, owner))
11263 sql (
"INSERT INTO credentials" 11264 " (uuid, name, owner, comment, type," 11265 " creation_time, modification_time)" 11268 " uniquify ('credential'," 11269 " 'Credential for Scanner %s', NULL, '')," 11270 " NULL, 'Autogenerated by migration', 'cc'," 11271 " m_now (), m_now ());",
11274 sql (
"INSERT INTO credentials" 11275 " (uuid, name, owner, comment, type," 11276 " creation_time, modification_time)" 11278 " (make_uuid (), 'Credential for Scanner %s'," 11279 " NULL, 'Autogenerated by migration', 'cc'," 11280 " m_now (), m_now ());",
11286 sql (
"UPDATE scanners SET credential = %llu WHERE id = %llu;",
11287 new_credential, scanner);
11289 sql (
"INSERT INTO credentials_data (credential, type, value)" 11290 " VALUES (%llu, 'certificate', '%s');",
11291 new_credential, quoted_key_pub);
11295 gchar *quoted_key_priv;
11296 quoted_key_priv =
sql_quote (key_priv);
11297 sql (
"INSERT INTO credentials_data (credential, type, value)" 11298 " VALUES (%llu, 'private_key', '%s');",
11299 new_credential, quoted_key_priv);
11300 g_free (quoted_key_priv);
11305 gchar *quoted_secret;
11311 "private_key", key_priv, NULL);
11314 g_free (quoted_name);
11315 g_free (quoted_key_pub);
11321 sql (
"INSERT INTO credentials_data (credential, type, value)" 11322 " VALUES (%llu, 'secret', '%s');",
11323 new_credential, quoted_secret);
11324 g_free (quoted_secret);
11328 " permissions (uuid, owner, name," 11329 " comment, resource_type, resource," 11331 " resource_location, subject_type, subject," 11332 " subject_location, creation_time, modification_time)" 11333 " SELECT make_uuid(), owner, 'get_credentials'," 11334 " 'Autogenerated by Scanner migration', 'credential', %llu," 11335 " (SELECT uuid FROM credentials WHERE id=%llu)," 11337 " subject_location, m_now (), m_now ()" 11338 " FROM permissions" 11339 " WHERE resource = %llu" 11340 " AND resource_type = 'scanner'" 11342 " GROUP BY owner, subject_type, subject, subject_location;",
11343 new_credential, new_credential, scanner);
11346 " permissions_trash (uuid, owner, name," 11347 " comment, resource_type, resource," 11349 " resource_location, subject_type, subject," 11350 " subject_location," 11351 " creation_time, modification_time)" 11352 " SELECT make_uuid(), owner, 'get_credentials'," 11353 " 'Autogenerated by Scanner migration', 'credential', %llu," 11354 " (SELECT uuid FROM credentials WHERE id=%llu)," 11356 " subject_location, m_now (), m_now ()" 11357 " FROM permissions_trash" 11358 " WHERE resource = %llu" 11359 " AND resource_type = 'scanner'" 11361 " GROUP BY owner, subject_type, subject, subject_location;",
11362 new_credential, new_credential, scanner);
11364 g_free (quoted_name);
11365 g_free (quoted_key_pub);
11371 "SELECT id, name, key_pub, key_priv, owner" 11372 " FROM scanners_trash;");
11374 while (
next (&scanners))
11377 const char *name, *key_pub, *key_priv;
11380 gchar *quoted_name, *quoted_key_pub;
11389 if (key_pub == NULL || key_priv == NULL)
11396 sql (
"INSERT INTO credentials_trash" 11397 " (uuid, name, owner, comment, type," 11398 " creation_time, modification_time)" 11400 " (make_uuid (), 'Credential for Scanner %s'," 11401 " %llu, 'Autogenerated by migration', 'cc'," 11402 " m_now (), m_now ());",
11403 quoted_name, owner);
11405 sql (
"INSERT INTO credentials_trash" 11406 " (uuid, name, owner, comment, type," 11407 " creation_time, modification_time)" 11409 " (make_uuid (), 'Credential for Scanner %s'," 11410 " NULL, 'Autogenerated by migration', 'cc'," 11411 " m_now (), m_now ());",
11416 sql (
"UPDATE scanners_trash SET credential = %llu," 11418 " WHERE id = %llu;",
11419 new_credential, scanner);
11421 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 11422 " VALUES (%llu, 'certificate', '%s');",
11423 new_credential, quoted_key_pub);
11427 gchar *quoted_key_priv;
11428 quoted_key_priv =
sql_quote (key_priv);
11429 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 11430 " VALUES (%llu, 'private_key', '%s');",
11431 new_credential, quoted_key_priv);
11432 g_free (quoted_key_priv);
11437 gchar *quoted_secret;
11443 "private_key", key_priv, NULL);
11446 g_free (quoted_name);
11447 g_free (quoted_key_pub);
11453 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 11454 " VALUES (%llu, 'secret', '%s');",
11455 new_credential, quoted_secret);
11456 g_free (quoted_secret);
11460 " permissions (uuid, owner, name," 11461 " comment, resource_type, resource," 11463 " resource_location, subject_type, subject," 11464 " subject_location," 11465 " creation_time, modification_time)" 11466 " SELECT make_uuid(), owner, 'get_credentials'," 11467 " 'Autogenerated by Scanner migration', 'credential', %llu," 11468 " (SELECT uuid FROM credentials_trash WHERE id=%llu)," 11470 " subject_location," 11471 " m_now (), m_now ()" 11472 " FROM permissions" 11473 " WHERE resource = %llu" 11474 " AND resource_type = 'scanner'" 11476 " GROUP BY owner, subject_type, subject, subject_location;",
11477 new_credential, new_credential, scanner);
11480 " permissions_trash (uuid, owner, name," 11481 " comment, resource_type, resource," 11483 " resource_location, subject_type, subject," 11484 " subject_location," 11485 " creation_time, modification_time)" 11486 " SELECT make_uuid(), owner, 'get_credentials'," 11487 " 'Autogenerated by Scanner migration', 'credential', %llu," 11488 " (SELECT uuid FROM credentials_trash WHERE id=%llu)," 11490 " subject_location," 11491 " m_now (), m_now ()" 11492 " FROM permissions_trash" 11493 " WHERE resource = %llu" 11494 " AND resource_type = 'scanner'" 11496 " GROUP BY owner, subject_type, subject, subject_location;",
11497 new_credential, new_credential, scanner);
11499 g_free (quoted_name);
11500 g_free (quoted_key_pub);
11507 sql (
"ALTER TABLE scanners RENAME TO scanners_158;");
11508 sql (
"ALTER TABLE scanners_trash RENAME TO scanners_trash_158;");
11510 sql (
"CREATE TABLE IF NOT EXISTS scanners" 11511 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment," 11512 " host, port, type, ca_pub, credential INTEGER," 11513 " creation_time, modification_time);");
11514 sql (
"CREATE TABLE IF NOT EXISTS scanners_trash" 11515 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, comment," 11516 " host, port, type, ca_pub, credential INTEGER," 11517 " credential_location INTEGER, creation_time, modification_time);");
11519 sql (
"INSERT INTO scanners" 11520 " (id, uuid, owner, name, comment, host, port, type," 11521 " ca_pub, credential, creation_time, modification_time)" 11522 " SELECT id, uuid, owner, name, comment, host, port, type," 11523 " ca_pub, credential, creation_time, modification_time" 11524 " FROM scanners_158;");
11525 sql (
"INSERT INTO scanners_trash" 11526 " (id, uuid, owner, name, comment, host, port, type," 11527 " ca_pub, credential, credential_location, creation_time," 11528 " modification_time)" 11529 " SELECT id, uuid, owner, name, comment, host, port, type," 11530 " ca_pub, credential, credential_location, creation_time," 11531 " modification_time" 11532 " FROM scanners_trash_158;");
11534 sql (
"DROP TABLE scanners_158;");
11535 sql (
"DROP TABLE scanners_trash_158;");
11539 sql (
"ALTER TABLE scanners DROP COLUMN key_pub;");
11540 sql (
"ALTER TABLE scanners DROP COLUMN key_priv;");
11541 sql (
"ALTER TABLE scanners_trash DROP COLUMN key_pub;");
11542 sql (
"ALTER TABLE scanners_trash DROP COLUMN key_priv;");
11576 sql (
"INSERT INTO report_format_params (report_format, name, type, value," 11577 " type_min, type_max, type_regex, fallback)" 11578 " VALUES ((SELECT id FROM report_formats" 11579 " WHERE uuid = 'c15ad349-bd8d-457a-880a-c7056532ee15')," 11580 " 'Attach HTML report', %i, 1, 0, 1, '', 1);",
11618 "SELECT 0, id, name, owner," 11619 " (SELECT value FROM credentials_data" 11620 " WHERE credential = credentials.id" 11621 " AND type = 'secret')," 11622 " (SELECT value FROM credentials_data" 11623 " WHERE credential = credentials.id" 11624 " AND type = 'password')" 11625 " FROM credentials" 11626 " WHERE type = 'usk'" 11627 " AND (id IN (SELECT credential" 11628 " FROM targets_login_data" 11629 " WHERE type='smb' OR type='esxi')" 11630 " OR id IN (SELECT credential" 11631 " FROM targets_trash_login_data" 11632 " WHERE (type='smb' OR type='esxi')" 11633 " AND credential_location" 11636 " SELECT 1, id, name, owner," 11637 " (SELECT value FROM credentials_trash_data" 11638 " WHERE credential = credentials_trash.id" 11639 " AND type = 'secret')," 11640 " (SELECT value FROM credentials_trash_data" 11641 " WHERE credential = credentials_trash.id" 11642 " AND type = 'password')" 11643 " FROM credentials_trash" 11644 " WHERE type = 'usk'" 11645 " AND id IN (SELECT credential" 11646 " FROM targets_trash_login_data" 11647 " WHERE (type='smb' OR type='esxi')" 11648 " AND credential_location" 11651 while (
next (&iter))
11655 const char *name, *old_secret, *old_password;
11656 gchar* quoted_name;
11669 sql (
"INSERT INTO credentials_trash" 11670 " (uuid, name, owner, comment, type," 11671 " creation_time, modification_time)" 11673 " (make_uuid (), '%s - user and password'," 11674 " %llu, 'Autogenerated by migration', 'up'," 11675 " m_now (), m_now ());",
11676 quoted_name, owner);
11680 if (
sql_int (
"SELECT count(*) FROM credentials" 11681 " WHERE name = '%s - user and password'" 11682 " AND owner = %llu;",
11683 quoted_name, owner))
11684 sql (
"INSERT INTO credentials" 11685 " (uuid, name, owner, comment, type," 11686 " creation_time, modification_time)" 11689 " uniquify ('credential', '%s - user and password', %llu, '')," 11690 " %llu, 'Autogenerated by migration', 'up'," 11691 " m_now (), m_now ());",
11692 quoted_name, owner, owner);
11694 sql (
"INSERT INTO credentials" 11695 " (uuid, name, owner, comment, type," 11696 " creation_time, modification_time)" 11698 " (make_uuid (), '%s - user and password'," 11699 " %llu, 'Autogenerated by migration', 'up'," 11700 " m_now (), m_now ());",
11701 quoted_name, owner);
11707 sql (
"INSERT INTO %s (credential, type, value)" 11708 " SELECT %llu, 'username', value FROM %s" 11709 " WHERE credential = %llu AND type = 'username'",
11710 trash ?
"credentials_trash_data" :
"credentials_data",
11712 trash ?
"credentials_trash_data" :
"credentials_data",
11726 gchar *quoted_password =
sql_quote (old_password ? old_password :
"");
11727 sql (
"INSERT INTO %s (credential, type, value)" 11728 " VALUES (%llu, 'password', '%s');",
11729 trash ?
"credentials_trash_data" :
"credentials_data",
11732 g_free (quoted_password);
11738 "password", old_password,
11740 sql (
"INSERT INTO %s (credential, type, value)" 11741 " VALUES (%llu, 'password', '%s');",
11742 trash ?
"credentials_trash_data" :
"credentials_data",
11746 g_free (new_secret);
11752 sql (
"UPDATE targets_trash_login_data SET credential = %llu" 11753 " WHERE credential = %llu" 11754 " AND (type = 'smb' OR type = 'esxi')" 11756 new_credential, credential);
11760 sql (
"UPDATE targets_login_data SET credential = %llu" 11761 " WHERE credential = %llu" 11762 " AND (type = 'smb' OR type = 'esxi');",
11763 new_credential, credential);
11764 sql (
"UPDATE targets_trash_login_data SET credential = %llu" 11765 " WHERE credential = %llu" 11766 " AND (type = 'smb' OR type = 'esxi')" 11768 new_credential, credential);
11804 sql (
"ALTER TABLE credentials ADD COLUMN allow_insecure INTEGER;");
11805 sql (
"ALTER TABLE credentials_trash ADD COLUMN allow_insecure INTEGER;");
11808 sql (
"UPDATE credentials SET allow_insecure = 0;");
11809 sql (
"UPDATE credentials_trash SET allow_insecure = 0;");
11823 #define MIGRATE_162_TO_163_CONTROL_DESCRIPTION \ 11824 "Dear IS Coordinator,\n" \ 11826 "A new scan has been carried out and the results are now available in Verinice.\n" \ 11827 "If responsible persons are linked to the asset groups, the tasks are already created.\n" \ 11829 "Please check the results in a timely manner.\n" \ 11856 sql (
"INSERT INTO report_format_params (report_format, name, type, value," 11857 " type_min, type_max, type_regex, fallback)" 11858 " VALUES ((SELECT id FROM report_formats" 11859 " WHERE uuid = 'c15ad349-bd8d-457a-880a-c7056532ee15')," 11860 " 'ISM Control Description', %i, '%s', 0, 100000, '', '%s');",
11875 #define UPDATE_CHART_SETTINGS(type, default, left_uuid, right_uuid) \ 11876 sql ("INSERT INTO settings (owner, uuid, name, value)" \ 11877 " SELECT owner, '%s', 'Dummy', 'left-' || '%s' FROM settings" \ 11878 " WHERE uuid = '%s'" \ 11879 " AND NOT EXISTS (SELECT * FROM settings AS old_settings" \ 11880 " WHERE old_settings.uuid = '%s'" \ 11881 " AND old_settings.owner = settings.owner);", \ 11882 left_uuid, default, right_uuid, left_uuid); \ 11883 sql ("UPDATE settings" \ 11884 " SET name = '%s Top Dashboard Components'," \ 11885 " value = coalesce ((SELECT substr (old_settings.value, 6)" \ 11886 " FROM settings AS old_settings" \ 11887 " WHERE old_settings.uuid = '%s'" \ 11888 " AND old_settings.owner = settings.owner)," \ 11889 " '" default "')" \ 11891 " || coalesce ((SELECT substr (old_settings.value, 7)" \ 11892 " FROM settings AS old_settings" \ 11893 " WHERE old_settings.uuid = '%s'" \ 11894 " AND old_settings.owner = settings.owner),"\ 11895 " '" default "')" \ 11896 " WHERE uuid = '%s';", \ 11897 type, left_uuid, right_uuid, left_uuid); \ 11898 sql ("DELETE FROM settings" \ 11899 " WHERE uuid = '%s';", \ 11902 #define UPDATE_DASHBOARD_SETTINGS(type, default, \ 11903 uuid_1, uuid_2, uuid_3, uuid_4, \ 11904 filter_1, filter_2, filter_3, filter_4) \ 11905 sql ("INSERT INTO settings (owner, uuid, name, value)" \ 11906 " SELECT DISTINCT owner, '%s', 'dummy', '%s' FROM settings" \ 11907 " WHERE uuid IN ('%s', '%s', '%s')" \ 11908 " AND NOT EXISTS (SELECT * FROM settings AS old_settings" \ 11909 " WHERE uuid = '%s'" \ 11910 " AND old_settings.owner = settings.owner);", \ 11911 uuid_1, default, uuid_2, uuid_3, uuid_4, uuid_1); \ 11912 sql ("UPDATE settings" \ 11913 " SET name = '%s Dashboard Components'," \ 11914 " value = coalesce ((SELECT substr (old_settings.value," \ 11915 " length ('" type "') + 4)" \ 11916 " FROM settings AS old_settings" \ 11917 " WHERE old_settings.uuid = '%s'" \ 11918 " AND old_settings.owner = settings.owner)," \ 11919 " '" default "')" \ 11921 " || coalesce ((SELECT substr (old_settings.value," \ 11922 " length ('" type "') + 4)" \ 11923 " FROM settings AS old_settings" \ 11924 " WHERE old_settings.uuid = '%s'" \ 11925 " AND old_settings.owner = settings.owner),"\ 11926 " '" default "')" \ 11928 " || coalesce ((SELECT substr (old_settings.value," \ 11929 " length ('" type "') + 4)" \ 11930 " FROM settings AS old_settings" \ 11931 " WHERE old_settings.uuid = '%s'" \ 11932 " AND old_settings.owner = settings.owner),"\ 11933 " '" default "')" \ 11935 " || coalesce ((SELECT substr (old_settings.value," \ 11936 " length ('" type "') + 4)" \ 11937 " FROM settings AS old_settings" \ 11938 " WHERE old_settings.uuid = '%s'" \ 11939 " AND old_settings.owner = settings.owner),"\ 11940 " '" default "')" \ 11941 " WHERE uuid = '%s';", \ 11942 type, uuid_1, uuid_2, uuid_3, uuid_4, uuid_1); \ 11943 sql ("INSERT INTO settings (owner, uuid, name, value)" \ 11944 " SELECT DISTINCT owner, '%s', 'dummy', '' FROM settings" \ 11945 " WHERE uuid IN ('%s', '%s', '%s')" \ 11946 " AND NOT EXISTS (SELECT * FROM settings AS old_settings" \ 11947 " WHERE uuid = '%s'" \ 11948 " AND old_settings.owner = settings.owner);", \ 11949 filter_1, filter_2, filter_3, filter_4, filter_1); \ 11950 sql ("UPDATE settings" \ 11951 " SET name = '%s Dashboard Filters'," \ 11952 " value = coalesce ((SELECT old_settings.value" \ 11953 " FROM settings AS old_settings" \ 11954 " WHERE old_settings.uuid = '%s'" \ 11955 " AND old_settings.owner = settings.owner)," \ 11958 " || coalesce ((SELECT old_settings.value" \ 11959 " FROM settings AS old_settings" \ 11960 " WHERE old_settings.uuid = '%s'" \ 11961 " AND old_settings.owner = settings.owner),"\ 11964 " || coalesce ((SELECT old_settings.value" \ 11965 " FROM settings AS old_settings" \ 11966 " WHERE old_settings.uuid = '%s'" \ 11967 " AND old_settings.owner = settings.owner),"\ 11970 " || coalesce ((SELECT old_settings.value" \ 11971 " FROM settings AS old_settings" \ 11972 " WHERE old_settings.uuid = '%s'" \ 11973 " AND old_settings.owner = settings.owner),"\ 11975 " WHERE uuid = '%s';", \ 11976 type, filter_1, filter_2, filter_3, filter_4, filter_1); \ 11977 sql ("DELETE FROM settings" \ 11978 " WHERE uuid IN ('%s', '%s', '%s', '%s', '%s', '%s');", \ 11979 uuid_2, uuid_3, uuid_4, filter_2, filter_3, filter_4); 12002 sql (
"DELETE FROM settings" 12003 " WHERE id NOT IN (SELECT min(id) FROM settings" 12004 " GROUP BY uuid, owner);");
12008 "3d5db3c7-5208-4b47-8c28-48efc621b1e0",
12009 "ce8608af-7e66-45a8-aa8a-76def4f9f838")
12011 "e599bb6b-b95a-4bb2-a6bb-fe8ac69bc071",
12012 "fc875cd4-16bf-42d1-98ed-c0c9bd6015cd")
12014 "0b8ae70d-d8fc-4418-8a72-e65ac8d2828e",
12015 "cb7db2fe-3fe4-4704-9fa1-efd4b9e522a8")
12018 "f68d9369-1945-477b-968f-121c6029971b",
12019 "af89a84a-d3ec-43a8-97a8-aa688bf093bc")
12021 "815ddd2e-8654-46c7-a05b-d73224102240",
12022 "418a5746-d68a-4a2d-864a-0da993b32220")
12024 "9cff9b4d-b164-43ce-8687-f2360afc7500",
12025 "629fdb73-35fa-4247-9018-338c202f7c03")
12027 "9563efc0-9f4e-4d1f-8f8d-0205e32b90a4",
12028 "fe1610a3-4e87-4b0d-9b7a-f0f66fef586b")
12030 "a6946f44-480f-4f37-8a73-28a4cd5310c4",
12031 "469d50da-880a-4bfc-88ed-22e53764c683")
12033 "9812ea49-682d-4f99-b3cc-eca051d1ce59",
12034 "72014b52-4389-435d-9438-8c13601ecbd2")
12036 "4c7b1ea7-b7e6-4d12-9791-eb9f72b6f864",
12037 "985f38eb-1a30-4a35-abb6-3eec05b5d54a")
12041 "84ab32da-fe69-44d8-8a8f-70034cf28d4e",
12042 "42d48049-3153-43bf-b30d-72ca5ab1eb49",
12043 "76f34fe0-254a-4481-97aa-c6f1da2f842b",
12044 "71106ed7-b677-414e-bf67-2e7716441db3",
12045 "517d0efe-426e-49a9-baa7-eda2832c93e8",
12046 "3c693fb2-4f87-4b1f-a09e-cb9aa66440f4",
12047 "bffa72a5-8110-49f9-aa5e-f431ce834826",
12048 "268079c6-f353-414f-9b7c-43f5419edf2d")
12081 sql (
"ALTER TABLE config_preferences ADD COLUMN hr_name TEXT;");
12082 sql (
"UPDATE config_preferences" 12083 " SET hr_name = name" 12084 " WHERE type != 'SERVER_PREFS' AND type != 'PLUGINS_PREFS';");
12088 sql (
"ALTER TABLE config_preferences_trash ADD COLUMN hr_name TEXT;");
12089 sql (
"UPDATE config_preferences_trash" 12090 " SET hr_name = name" 12091 " WHERE type != 'SERVER_PREFS' AND type != 'PLUGINS_PREFS';");
12126 " (SELECT data FROM alert_method_data" 12127 " WHERE alert = alerts.id" 12128 " AND (name='scp_username'" 12129 " OR name='verinice_server_username'))," 12130 " (SELECT data FROM alert_method_data" 12131 " WHERE alert = alerts.id" 12132 " AND (name='scp_password'" 12133 " OR name='verinice_server_password'))," 12135 " FROM alerts WHERE method = 8 OR method = 6;");
12140 const char *name, *login, *password;
12143 gchar *new_credential_id, *quoted_name, *quoted_login;
12154 if (name == NULL || password == NULL)
12161 if (
sql_int (
"SELECT count(*) FROM credentials" 12162 " WHERE name = 'Credential for Alert %s'" 12163 " AND owner = %llu;",
12164 quoted_name, owner))
12165 sql (
"INSERT INTO credentials" 12166 " (uuid, name, owner, comment, type," 12167 " creation_time, modification_time)" 12170 " uniquify ('credential', 'Credential for Alert %s', %llu, '')," 12171 " %llu, 'Autogenerated by migration', 'up'," 12172 " m_now (), m_now ());",
12173 quoted_name, owner, owner);
12175 sql (
"INSERT INTO credentials" 12176 " (uuid, name, owner, comment, type," 12177 " creation_time, modification_time)" 12179 " (make_uuid (), 'Credential for Alert %s'," 12180 " %llu, 'Autogenerated by migration', 'up'," 12181 " m_now (), m_now ());",
12182 quoted_name, owner);
12186 new_credential_id =
sql_string (
"SELECT uuid FROM credentials" 12187 " WHERE id = %llu;",
12190 sql (
"INSERT INTO credentials_data (credential, type, value)" 12191 " VALUES (%llu, 'username', '%s');",
12197 gchar *quoted_password;
12198 quoted_password =
sql_quote (password);
12199 sql (
"INSERT INTO credentials_data (credential, type, value)" 12200 " VALUES (%llu, 'password', '%s');",
12201 new_credential, quoted_password);
12202 g_free (quoted_password);
12207 gchar *quoted_secret;
12213 "password", password, NULL);
12216 g_free (quoted_name);
12217 g_free (quoted_login);
12223 sql (
"INSERT INTO credentials_data (credential, type, value)" 12224 " VALUES (%llu, 'secret', '%s');",
12225 new_credential, quoted_secret);
12226 g_free (quoted_secret);
12230 sql (
"INSERT INTO alert_method_data (alert, name, data)" 12231 " VALUES (%llu, '%s_credential', '%s');",
12233 method == 8 ?
"scp" :
"verinice_server",
12234 new_credential_id);
12238 " permissions (uuid, owner, name," 12239 " comment, resource_type, resource," 12241 " resource_location, subject_type, subject," 12242 " subject_location, creation_time, modification_time)" 12243 " SELECT make_uuid(), owner, 'get_credentials'," 12244 " 'Autogenerated by Alert migration', 'credential', %llu," 12245 " (SELECT uuid FROM credentials WHERE id=%llu)," 12247 " subject_location, m_now (), m_now ()" 12248 " FROM permissions" 12249 " WHERE resource = %llu" 12250 " AND resource_type = 'alert'" 12252 " GROUP BY owner, subject_type, subject, subject_location;",
12253 new_credential, new_credential, alert);
12256 " permissions_trash (uuid, owner, name," 12257 " comment, resource_type, resource," 12259 " resource_location, subject_type, subject," 12260 " subject_location," 12261 " creation_time, modification_time)" 12262 " SELECT make_uuid(), owner, 'get_credentials'," 12263 " 'Autogenerated by Alert migration', 'credential', %llu," 12264 " (SELECT uuid FROM credentials WHERE id=%llu)," 12266 " subject_location, m_now (), m_now ()" 12267 " FROM permissions_trash" 12268 " WHERE resource = %llu" 12269 " AND resource_type = 'alert'" 12271 " GROUP BY owner, subject_type, subject, subject_location;",
12272 new_credential, new_credential, alert);
12274 g_free (new_credential_id);
12275 g_free (quoted_name);
12276 g_free (quoted_login);
12283 " (SELECT data FROM alert_method_data_trash" 12284 " WHERE alert = alerts_trash.id" 12285 " AND (name='scp_username'" 12286 " OR name='verinice_server_username'))," 12287 " (SELECT data FROM alert_method_data_trash" 12288 " WHERE alert = alerts_trash.id" 12289 " AND (name='scp_password'" 12290 " OR name='verinice_server_password'))," 12292 " FROM alerts_trash WHERE method = 8 OR method = 6;");
12297 const char *name, *login, *password;
12300 gchar *new_credential_id, *quoted_name, *quoted_login;
12311 if (name == NULL || password == NULL)
12319 sql (
"INSERT INTO credentials_trash" 12320 " (uuid, name, owner, comment, type," 12321 " creation_time, modification_time)" 12323 " (make_uuid (), 'Credential for Alert %s'," 12324 " %llu, 'Autogenerated by migration', 'up'," 12325 " m_now (), m_now ());",
12326 quoted_name, owner);
12329 new_credential_id =
sql_string (
"SELECT uuid FROM credentials_trash" 12330 " WHERE id = %llu;",
12334 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 12335 " VALUES (%llu, 'username', '%s');",
12336 new_credential, quoted_login);
12340 gchar *quoted_password;
12341 quoted_password =
sql_quote (password);
12342 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 12343 " VALUES (%llu, 'password', '%s');",
12344 new_credential, quoted_password);
12345 g_free (quoted_password);
12350 gchar *quoted_secret;
12356 "password", password, NULL);
12359 g_free (quoted_name);
12360 g_free (quoted_login);
12366 sql (
"INSERT INTO credentials_trash_data (credential, type, value)" 12367 " VALUES (%llu, 'secret', '%s');",
12368 new_credential, quoted_secret);
12369 g_free (quoted_secret);
12373 sql (
"INSERT INTO alert_method_data_trash (alert, name, data)" 12374 " VALUES (%llu, '%s_credential', '%s');",
12376 method == 8 ?
"scp" :
"verinice_server",
12377 new_credential_id);
12379 sql (
"INSERT INTO alert_method_data_trash (alert, name, data)" 12380 " VALUES (%llu, '%s_credential_location', %d);",
12382 method == 8 ?
"scp" :
"verinice_server",
12387 " permissions (uuid, owner, name," 12388 " comment, resource_type, resource," 12390 " resource_location, subject_type, subject," 12391 " subject_location," 12392 " creation_time, modification_time)" 12393 " SELECT make_uuid(), owner, 'get_credentials'," 12394 " 'Autogenerated by Alert migration', 'credential', %llu," 12395 " (SELECT uuid FROM credentials_trash WHERE id=%llu)," 12397 " subject_location," 12398 " m_now (), m_now ()" 12399 " FROM permissions" 12400 " WHERE resource = %llu" 12401 " AND resource_type = 'alert'" 12403 " GROUP BY owner, subject_type, subject, subject_location;",
12404 new_credential, new_credential, alert);
12407 " permissions_trash (uuid, owner, name," 12408 " comment, resource_type, resource," 12410 " resource_location, subject_type, subject," 12411 " subject_location," 12412 " creation_time, modification_time)" 12413 " SELECT make_uuid(), owner, 'get_credentials'," 12414 " 'Autogenerated by Alert migration', 'credential', %llu," 12415 " (SELECT uuid FROM credentials_trash WHERE id=%llu)," 12417 " subject_location," 12418 " m_now (), m_now ()" 12419 " FROM permissions_trash" 12420 " WHERE resource = %llu" 12421 " AND resource_type = 'alert'" 12423 " GROUP BY owner, subject_type, subject, subject_location;",
12424 new_credential, new_credential, alert);
12426 g_free (new_credential_id);
12427 g_free (quoted_name);
12428 g_free (quoted_login);
12433 sql (
"DELETE FROM alert_method_data" 12434 " WHERE name='scp_username'" 12435 " OR name='verinice_server_username'" 12436 " OR name='scp_password'" 12437 " OR name='verinice_server_password';");
12439 sql (
"DELETE FROM alert_method_data_trash" 12440 " WHERE name='scp_username'" 12441 " OR name='verinice_server_username'" 12442 " OR name='scp_password'" 12443 " OR name='verinice_server_password';");
12458 insert_predefined (
const gchar *uuid)
12460 if (
sql_int (
"SELECT EXISTS (SELECT * FROM report_formats" 12461 " WHERE uuid = '%s');",
12463 sql (
"INSERT INTO resources_predefined (resource_type, resource)" 12464 " VALUES ('report_format'," 12465 " (SELECT id FROM report_formats WHERE uuid = '%s'));",
12492 sql (
"CREATE TABLE IF NOT EXISTS resources_predefined" 12493 " (id INTEGER PRIMARY KEY, resource_type, resource INTEGER)");
12495 sql (
"CREATE TABLE IF NOT EXISTS resources_predefined" 12496 " (id SERIAL PRIMARY KEY, resource_type text, resource INTEGER)");
12500 insert_predefined (
"5057e5cc-b825-11e4-9d0e-28d24461215b");
12501 insert_predefined (
"910200ca-dc05-11e1-954f-406186ea4fc5");
12502 insert_predefined (
"5ceff8ba-1f62-11e1-ab9f-406186ea4fc5");
12503 insert_predefined (
"c1645568-627a-11e3-a660-406186ea4fc5");
12504 insert_predefined (
"9087b18c-626c-11e3-8892-406186ea4fc5");
12505 insert_predefined (
"6c248850-1f62-11e1-b082-406186ea4fc5");
12506 insert_predefined (
"77bd6c4a-1f62-11e1-abf0-406186ea4fc5");
12507 insert_predefined (
"a684c02c-b531-11e1-bdc2-406186ea4fc5");
12508 insert_predefined (
"9ca6fe72-1f62-11e1-9e7c-406186ea4fc5");
12509 insert_predefined (
"c402cc3e-b531-11e1-9163-406186ea4fc5");
12510 insert_predefined (
"a3810a62-1f62-11e1-9219-406186ea4fc5");
12511 insert_predefined (
"a994b278-1f62-11e1-96ac-406186ea4fc5");
12512 insert_predefined (
"9e5e5deb-879e-4ecc-8be6-a71cd0875cdd");
12513 insert_predefined (
"c15ad349-bd8d-457a-880a-c7056532ee15");
12514 insert_predefined (
"50c9950a-f326-11e4-800c-28d24461215b");
12549 uuid =
"343435d6-91b0-11de-9478-ffd71f4c6f29";
12551 sql (
"DELETE FROM report_counts" 12552 " WHERE report IN (SELECT id FROM reports" 12553 " WHERE task = (SELECT id FROM tasks" 12554 " WHERE uuid = '%s'));",
12557 sql (
"DELETE FROM report_hosts" 12558 " WHERE report IN (SELECT id FROM reports" 12559 " WHERE task = (SELECT id FROM tasks" 12560 " WHERE uuid = '%s'));",
12563 sql (
"DELETE FROM results" 12564 " WHERE task = (SELECT id FROM tasks" 12565 " WHERE uuid = '%s');",
12568 sql (
"DELETE FROM reports" 12569 " WHERE task = (SELECT id FROM tasks" 12570 " WHERE uuid = '%s');",
12573 sql (
"DELETE FROM task_preferences" 12574 " WHERE task = (SELECT id FROM tasks" 12575 " WHERE uuid = '%s');",
12578 sql (
"DELETE FROM tasks WHERE uuid = '%s';",
12600 migrate_168_to_169_copy_target (
user_t owner,
const gchar *uuid,
target_t *
new)
12604 sql (
"INSERT INTO targets" 12605 " (uuid, owner, name, comment, creation_time, modification_time," 12606 " hosts, exclude_hosts, port_list, reverse_lookup_only," 12607 " reverse_lookup_unify)" 12608 " SELECT make_uuid (), %llu, name, comment, m_now (), m_now ()," 12609 " hosts, exclude_hosts, port_list, reverse_lookup_only," 12610 " reverse_lookup_unify" 12612 " WHERE uuid = '%s';",
12618 sql (
"INSERT INTO tags" 12619 " (uuid, owner, name, comment, creation_time, modification_time," 12620 " resource_type, resource, resource_uuid, resource_location," 12622 " SELECT make_uuid (), %llu, name, comment, m_now (), m_now ()," 12623 " resource_type, %llu," 12624 " (SELECT uuid FROM targets WHERE id = %llu)," 12625 " resource_location, active, value" 12626 " FROM tags WHERE resource_type = 'target'" 12627 " AND resource = (SELECT id FROM targets WHERE uuid = '%s')" 12660 uuid =
"b493b7a8-7489-11df-a3ec-002264764cea";
12663 while (
next (&users))
12669 if (
sql_int (
"SELECT count (*) FROM tasks" 12670 " WHERE owner = %llu" 12671 " AND target = (SELECT id FROM targets" 12672 " WHERE uuid = '%s');",
12681 " WHERE owner = %llu;",
12684 " WHERE owner = %llu;",
12687 migrate_168_to_169_copy_target (owner, uuid, &
new);
12694 sql (
"UPDATE tasks SET target = %llu" 12695 " WHERE owner = %llu" 12696 " AND target = (SELECT id FROM targets WHERE uuid = '%s');",
12706 sql (
"DELETE FROM targets WHERE uuid = '%s';",
12727 migrate_169_to_170_add_permission (
const gchar *role,
const gchar *permission)
12729 sql (
"INSERT INTO permissions" 12730 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 12731 " resource_location, subject_type, subject, subject_location," 12732 " creation_time, modification_time)" 12734 " (make_uuid (), NULL, lower ('%s'), '', ''," 12736 " (SELECT id FROM roles WHERE uuid = '%s')," 12764 migrate_169_to_170_add_permission (
"8d453140-b74d-11e2-b0be-406186ea4fc5",
12766 migrate_169_to_170_add_permission (
"8d453140-b74d-11e2-b0be-406186ea4fc5",
12768 migrate_169_to_170_add_permission (
"8d453140-b74d-11e2-b0be-406186ea4fc5",
12788 gchar *old_dir, *new_dir;
12805 new_dir = g_build_filename (OPENVAS_STATE_DIR,
12809 if (g_mkdir_with_parents (new_dir, 0755 ))
12811 g_warning (
"%s: failed to create dir %s", __FUNCTION__, new_dir);
12817 old_dir = g_build_filename (OPENVAS_DATA_DIR,
12819 "report_formats_trash",
12822 if (g_lstat (old_dir, &state))
12828 if (errno != ENOENT)
12829 g_warning (
"%s: g_lstat (%s) failed: %s\n",
12830 __FUNCTION__, old_dir, g_strerror (errno));
12832 g_warning (
"%s: trash report formats directory missing (%s)\n",
12833 __FUNCTION__, old_dir);
12834 g_warning (
"%s: any trash report formats will be removed on startup\n",
12840 gchar *standard_out = NULL;
12841 gchar *standard_err = NULL;
12846 g_mkdir_with_parents (old_dir, 0755 );
12848 cmd = (gchar **) g_malloc (4 *
sizeof (gchar *));
12849 cmd[0] = g_strdup (
"mv");
12853 g_debug (
"%s: Spawning in .: %s %s %s\n",
12854 __FUNCTION__, cmd[0], cmd[1], cmd[2]);
12855 if ((g_spawn_sync (
".",
12858 G_SPAWN_SEARCH_PATH,
12866 || (WIFEXITED (exit_status) == 0)
12867 || WEXITSTATUS (exit_status))
12869 g_warning (
"%s: failed rename: %d (WIF %i, WEX %i)",
12872 WIFEXITED (exit_status),
12873 WEXITSTATUS (exit_status));
12874 g_debug (
"%s: stdout: %s\n", __FUNCTION__, standard_out);
12875 g_debug (
"%s: stderr: %s\n", __FUNCTION__, standard_err);
12909 gchar *old_dir_path, *new_dir_path;
12910 const gchar *subdir_name;
12927 new_dir_path = g_build_filename (OPENVAS_STATE_DIR,
12931 if (g_mkdir_with_parents (new_dir_path, 0755 ))
12933 g_warning (
"%s: failed to create dir %s", __FUNCTION__, new_dir_path);
12934 g_free (new_dir_path);
12939 old_dir_path = g_build_filename (OPENVAS_DATA_DIR,
12941 "global_report_formats",
12944 if (g_lstat (old_dir_path, &state))
12950 if (errno != ENOENT)
12951 g_warning (
"%s: g_lstat (%s) failed: %s\n",
12952 __FUNCTION__, old_dir_path, g_strerror (errno));
12954 g_info (
"%s: old global report formats directory missing (%s)\n",
12955 __FUNCTION__, old_dir_path);
12965 old_dir = g_dir_open (old_dir_path, 0, &error);
12966 if (old_dir == NULL)
12968 g_warning (
"%s: Failed to open directory '%s': %s",
12969 __FUNCTION__, old_dir_path, error->message);
12970 g_error_free (error);
12971 g_free (old_dir_path);
12972 g_free (new_dir_path);
12977 subdir_name = g_dir_read_name (old_dir);
12979 while (subdir_name && move_failed == 0)
12981 gchar *old_subdir_path, *new_subdir_path;
12985 old_subdir_path = g_build_filename (old_dir_path, subdir_name, NULL);
12986 new_subdir_path = g_build_filename (new_dir_path, subdir_name, NULL);
12987 new_subdir = g_dir_open (new_subdir_path, 0, &error);
12990 g_debug (
"%s: Skipping '%s', directory already exists",
12991 __FUNCTION__, new_subdir_path);
12992 openvas_file_remove_recurse (old_subdir_path);
12993 g_dir_close (new_subdir);
12995 else if (error->code == G_FILE_ERROR_NOENT)
12998 gchar *standard_out = NULL;
12999 gchar *standard_err = NULL;
13002 cmd = (gchar **) g_malloc (4 *
sizeof (gchar *));
13003 cmd[0] = g_strdup (
"mv");
13004 cmd[1] = old_subdir_path;
13005 cmd[2] = new_subdir_path;
13007 g_debug (
"%s: Spawning in .: %s %s %s\n",
13008 __FUNCTION__, cmd[0], cmd[1], cmd[2]);
13009 if ((g_spawn_sync (
".",
13012 G_SPAWN_SEARCH_PATH,
13020 || (WIFEXITED (exit_status) == 0)
13021 || WEXITSTATUS (exit_status))
13023 g_warning (
"%s: failed rename: %d (WIF %i, WEX %i)",
13026 WIFEXITED (exit_status),
13027 WEXITSTATUS (exit_status));
13028 g_debug (
"%s: stdout: %s\n", __FUNCTION__, standard_out);
13029 g_debug (
"%s: stderr: %s\n", __FUNCTION__, standard_err);
13037 g_warning (
"%s: failed to check directory '%s' : %s",
13038 __FUNCTION__, new_subdir_path, error->message);
13041 g_free (old_subdir_path);
13042 g_free (new_subdir_path);
13044 g_error_free (error);
13045 subdir_name = g_dir_read_name (old_dir);
13048 g_dir_close (old_dir);
13056 g_free (old_dir_path);
13057 g_free (new_dir_path);
13089 sql (
"ALTER TABLE nvts RENAME TO nvts_172;");
13091 sql (
"CREATE TABLE IF NOT EXISTS nvts" 13092 " (id INTEGER PRIMARY KEY, uuid, oid, version, name, comment," 13093 " copyright, cve, bid, xref, tag, category INTEGER, family, cvss_base," 13094 " creation_time, modification_time, solution_type TEXT, qod INTEGER," 13095 " qod_type TEXT);");
13097 sql (
"INSERT INTO nvts" 13098 " (id, uuid, oid, version, name, comment, copyright, cve," 13099 " bid, xref, tag, category, family, cvss_base, creation_time," 13100 " modification_time, solution_type, qod, qod_type)" 13101 " SELECT id, uuid, oid, version, name, comment, copyright, cve," 13102 " bid, xref, tag, category, family, cvss_base, creation_time," 13103 " modification_time, solution_type, qod, qod_type" 13104 " FROM nvts_172;");
13106 sql (
"DROP TABLE nvts_172;");
13109 sql (
"ALTER TABLE nvts DROP COLUMN summary;");
13143 "SELECT id FROM report_formats" 13144 " WHERE uuid='c15ad349-bd8d-457a-880a-c7056532ee15';");
13147 sql (
"UPDATE report_formats" 13148 " SET summary='Greenbone Verinice ISM Report, v3.0.0.'," 13149 " description='Information Security Management Report for Verinice import, version 3.0.0.\n'" 13150 " WHERE id = %llu",
13154 sql (
"DELETE FROM report_format_params" 13155 " WHERE report_format = %llu" 13156 " AND name LIKE 'Attach %%%% report'",
13160 sql (
"INSERT INTO report_format_params (report_format, name, type, value," 13161 " type_min, type_max, type_regex, fallback)" 13162 " VALUES (%lli, 'Attached report formats', %i, '%s', 0, 0, '', 1);",
13165 "6c248850-1f62-11e1-b082-406186ea4fc5");
13186 gchar *old_dir_path, *new_dir_path;
13187 const gchar *subdir_name;
13205 new_dir_path = g_build_filename (OPENVAS_DATA_DIR,
13212 if (g_mkdir_with_parents (new_dir_path, 0755 ))
13214 g_warning (
"%s: failed to create dir %s", __FUNCTION__, new_dir_path);
13215 g_free (new_dir_path);
13220 old_dir_path = g_build_filename (OPENVAS_STATE_DIR,
13222 "global_report_formats",
13227 g_mkdir_with_parents (old_dir_path, 0755 );
13232 old_dir = g_dir_open (old_dir_path, 0, &error);
13233 if (old_dir == NULL)
13235 g_warning (
"%s: Failed to open directory '%s': %s",
13236 __FUNCTION__, old_dir_path, error->message);
13237 g_error_free (error);
13238 g_free (old_dir_path);
13239 g_free (new_dir_path);
13244 subdir_name = g_dir_read_name (old_dir);
13246 while (subdir_name && move_failed == 0)
13248 gchar *old_subdir_path, *new_subdir_path;
13252 old_subdir_path = g_build_filename (old_dir_path, subdir_name, NULL);
13253 new_subdir_path = g_build_filename (new_dir_path, subdir_name, NULL);
13254 new_subdir = g_dir_open (new_subdir_path, 0, &error);
13257 g_debug (
"%s: Skipping '%s', directory already exists",
13258 __FUNCTION__, new_subdir_path);
13259 openvas_file_remove_recurse (old_subdir_path);
13260 g_dir_close (new_subdir);
13262 else if (error->code == G_FILE_ERROR_NOENT)
13265 gchar *standard_out = NULL;
13266 gchar *standard_err = NULL;
13269 cmd = (gchar **) g_malloc (4 *
sizeof (gchar *));
13270 cmd[0] = g_strdup (
"mv");
13271 cmd[1] = old_subdir_path;
13272 cmd[2] = new_subdir_path;
13274 g_debug (
"%s: Spawning in .: %s %s %s\n",
13275 __FUNCTION__, cmd[0], cmd[1], cmd[2]);
13276 if ((g_spawn_sync (
".",
13279 G_SPAWN_SEARCH_PATH,
13287 || (WIFEXITED (exit_status) == 0)
13288 || WEXITSTATUS (exit_status))
13290 g_warning (
"%s: failed rename: %d (WIF %i, WEX %i)",
13293 WIFEXITED (exit_status),
13294 WEXITSTATUS (exit_status));
13295 g_debug (
"%s: stdout: %s\n", __FUNCTION__, standard_out);
13296 g_debug (
"%s: stderr: %s\n", __FUNCTION__, standard_err);
13304 g_warning (
"%s: failed to check directory '%s' : %s",
13305 __FUNCTION__, new_subdir_path, error->message);
13308 g_free (old_subdir_path);
13309 g_free (new_subdir_path);
13311 g_error_free (error);
13312 subdir_name = g_dir_read_name (old_dir);
13314 g_free (new_dir_path);
13315 g_dir_close (old_dir);
13319 g_free (old_dir_path);
13324 openvas_file_remove_recurse (old_dir_path);
13325 g_free (old_dir_path);
13358 sql (
"UPDATE scanners SET host = '" OPENVAS_RUN_DIR
"/openvassd.sock'" 13396 sql (
"INSERT INTO permissions" 13397 " (uuid, owner, name, comment, resource_type, resource, resource_uuid," 13398 " resource_location, subject_type, subject, subject_location," 13399 " creation_time, modification_time)" 13400 " SELECT make_uuid (), *, %i, %i" 13401 " FROM (SELECT DISTINCT owner, 'get_feeds', comment, resource_type," 13402 " resource, resource_uuid, resource_location," 13403 " subject_type, subject, subject_location" 13404 " FROM permissions" 13405 " WHERE (name = 'describe_feed'" 13406 " OR name = 'describe_scap'" 13407 " OR name = 'describe_cert'))" 13412 sql (
"DELETE FROM permissions" 13413 " WHERE (name = 'describe_feed'" 13414 " OR name = 'describe_scap'" 13415 " OR name = 'describe_cert');");
13448 sql (
"UPDATE scanners SET ca_pub = NULL" 13453 "SELECT credential FROM scanners" 13457 sql (
"UPDATE scanners SET credential = NULL" 13461 if ((
sql_int (
"SELECT count(*) FROM scanners" 13462 " WHERE credential = %llu" 13465 && (
sql_int (
"SELECT count(*) FROM scanners_trash" 13466 " WHERE credential = %llu" 13467 " AND credential_location = %d;",
13469 && (
sql_int (
"SELECT count(*) FROM targets_login_data" 13470 " WHERE credential = %llu;",
13472 && (
sql_int (
"SELECT count(*) FROM targets_trash_login_data" 13473 " WHERE credential = %llu" 13474 " AND credential_location = %d;",
13476 && (
sql_int (
"SELECT count(*) FROM slaves" 13477 " WHERE credential = %llu;",
13479 && (
sql_int (
"SELECT count(*) FROM slaves_trash" 13480 " WHERE credential = %llu" 13481 " AND credential_location = %d;",
13484 sql (
"DELETE FROM credentials_data WHERE credential = %llu",
13486 sql (
"DELETE FROM credentials WHERE id = %llu",
13521 sql (
"ALTER TABLE reports ADD COLUMN slave_username TEXT;");
13522 sql (
"ALTER TABLE reports ADD COLUMN slave_password TEXT;");
13524 sql (
"UPDATE reports" 13525 " SET slave_username = (SELECT credentials_data.value" 13526 " FROM slaves, credentials_data" 13527 " WHERE slaves.id = (SELECT id FROM slaves" 13528 " WHERE uuid = slave_uuid)" 13529 " AND credentials_data.credential" 13530 " = slaves.credential" 13531 " AND credentials_data.type = 'username');");
13533 sql (
"UPDATE reports" 13534 " SET slave_password = (SELECT credentials_data.value" 13535 " FROM slaves, credentials_data" 13536 " WHERE slaves.id = (SELECT id FROM slaves" 13537 " WHERE uuid = slave_uuid)" 13538 " AND credentials_data.credential" 13539 " = slaves.credential" 13540 " AND credentials_data.type = 'username');");
13563 " SET resource_type = 'scanner'," 13564 " resource = (SELECT id FROM scanners%s" 13565 " WHERE uuid = resource_uuid)" 13566 " WHERE resource_type = 'slave'" 13567 " AND resource_location = %i;",
13569 trash ?
"_trash" :
"",
13595 sql (
"DELETE FROM settings" 13596 " WHERE uuid = 'aec201fa-8a82-4b61-bebe-a44ea93b2909'" 13597 " OR uuid = '2681c32a-8dfd-40c9-a9c6-8d4e2c7799eb';");
13599 sql (
"UPDATE filters" 13600 " SET type = replace (type, 'slave', 'scanner');");
13602 sql (
"UPDATE filters_trash" 13603 " SET type = replace (type, 'slave', 'scanner');");
13605 sql (
"INSERT INTO scanners (uuid, owner, name, comment, host, port," 13606 " creation_time, modification_time, credential," 13608 " SELECT uuid, owner, name, comment, host, CAST (port AS INTEGER)," 13609 " creation_time, modification_time, credential, %i, NULL" 13618 sql (
"UPDATE tasks" 13619 " SET scanner = (SELECT id FROM scanners" 13620 " WHERE uuid = (SELECT uuid FROM slaves" 13621 " WHERE id = tasks.slave))," 13623 " WHERE slave != 0" 13626 sql (
"INSERT INTO scanners_trash (uuid, owner, name, comment, host, port," 13627 " creation_time, modification_time," 13628 " credential, type, ca_pub)" 13629 " SELECT uuid, owner, name, comment, host, CAST (port AS INTEGER)," 13630 " creation_time, modification_time, credential, %i, NULL" 13631 " FROM slaves_trash;",
13639 sql (
"UPDATE permissions" 13640 " SET name = replace (name, 'slave', 'scanner');");
13642 sql (
"UPDATE permissions_trash" 13643 " SET name = replace (name, 'slave', 'scanner');");
13645 sql (
"UPDATE tasks" 13646 " SET scanner = (SELECT id FROM scanners_trash" 13647 " WHERE uuid = (SELECT uuid FROM slaves_trash" 13648 " WHERE id = tasks.slave))," 13650 " WHERE slave != 0" 13653 sql (
"DROP TABLE slaves;");
13654 sql (
"DROP TABLE slaves_trash;");
13691 sql (
"ALTER TABLE tasks RENAME TO tasks_180;");
13693 sql (
"CREATE TABLE IF NOT EXISTS tasks" 13694 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, hidden INTEGER," 13695 " comment, run_status INTEGER, start_time, end_time," 13696 " config INTEGER, target INTEGER, schedule INTEGER, schedule_next_time," 13697 " schedule_periods INTEGER, config_location INTEGER," 13698 " target_location INTEGER, schedule_location INTEGER," 13699 " scanner_location INTEGER, upload_result_count INTEGER," 13700 " hosts_ordering, scanner, alterable, creation_time," 13701 " modification_time);");
13703 sql (
"INSERT INTO tasks" 13704 " (id, uuid, owner, name, hidden, comment, run_status, start_time," 13705 " end_time, config, target, schedule, schedule_next_time," 13706 " schedule_periods, config_location, target_location," 13707 " schedule_location, scanner_location, upload_result_count," 13708 " hosts_ordering, scanner, alterable, creation_time," 13709 " modification_time)" 13710 " SELECT id, uuid, owner, name, hidden, comment, run_status," 13711 " start_time, end_time, config, target, schedule," 13712 " schedule_next_time, schedule_periods, config_location," 13713 " target_location, schedule_location, scanner_location," 13714 " upload_result_count, hosts_ordering, scanner, alterable," 13715 " creation_time, modification_time" 13716 " FROM tasks_180;");
13718 sql (
"DROP TABLE tasks_180;");
13722 sql (
"ALTER TABLE tasks DROP COLUMN slave;");
13723 sql (
"ALTER TABLE tasks DROP COLUMN slave_location;");
13745 gchar *new_dir_path, *old_dir_path;
13748 const gchar *asc_name;
13751 new_dir_path = g_build_filename (OPENVAS_STATE_DIR,
13757 if (g_mkdir_with_parents (new_dir_path, 0755 ))
13759 g_warning (
"%s: failed to create dir %s", __FUNCTION__, new_dir_path);
13760 g_free (new_dir_path);
13764 old_dir_path = g_build_filename (OPENVAS_NVT_DIR,
13770 old_dir = g_dir_open (old_dir_path, 0, &error);
13771 if (old_dir == NULL)
13773 if (error->code == G_FILE_ERROR_NOENT)
13776 g_warning (
"%s: Failed to open directory '%s': %s",
13777 __FUNCTION__, old_dir_path, error->message);
13778 g_error_free (error);
13779 g_free (old_dir_path);
13780 g_free (new_dir_path);
13784 asc_name = g_dir_read_name (old_dir);
13786 while (asc_name && move_failed == 0)
13788 gchar *old_asc_path, *new_asc_path;
13791 gchar *standard_out = NULL;
13792 gchar *standard_err = NULL;
13796 old_asc_path = g_build_filename (old_dir_path, asc_name, NULL);
13797 new_asc_path = g_build_filename (new_dir_path, asc_name, NULL);
13799 cmd = (gchar **) g_malloc (4 *
sizeof (gchar *));
13800 cmd[0] = g_strdup (
"mv");
13801 cmd[1] = old_asc_path;
13802 cmd[2] = new_asc_path;
13804 g_debug (
"%s: Spawning in .: %s %s %s\n",
13805 __FUNCTION__, cmd[0], cmd[1], cmd[2]);
13806 if ((g_spawn_sync (
".",
13809 G_SPAWN_SEARCH_PATH,
13817 || (WIFEXITED (exit_status) == 0)
13818 || WEXITSTATUS (exit_status))
13820 g_warning (
"%s: failed rename: %d (WIF %i, WEX %i)",
13823 WIFEXITED (exit_status),
13824 WEXITSTATUS (exit_status));
13825 g_debug (
"%s: stdout: %s\n", __FUNCTION__, standard_out);
13826 g_debug (
"%s: stderr: %s\n", __FUNCTION__, standard_err);
13831 g_free (old_asc_path);
13832 g_free (new_asc_path);
13834 g_error_free (error);
13835 asc_name = g_dir_read_name (old_dir);
13837 g_free (new_dir_path);
13838 g_dir_close (old_dir);
13842 g_free (old_dir_path);
13846 openvas_file_remove_recurse (old_dir_path);
13848 g_free (old_dir_path);
13917 sql (
"ALTER TABLE reports RENAME TO reports_182;");
13919 sql (
"CREATE TABLE reports" 13920 " (id INTEGER PRIMARY KEY, uuid, owner INTEGER, hidden INTEGER," 13921 " task INTEGER, date INTEGER, start_time, end_time, nbefile, comment," 13922 " scan_run_status INTEGER, slave_progress, slave_task_uuid," 13923 " slave_uuid, slave_name, slave_host, slave_port, source_iface," 13924 " flags INTEGER);");
13926 sql (
"INSERT INTO reports" 13927 " (id, uuid, owner, hidden, task, date, start_time, end_time," 13928 " nbefile, comment, scan_run_status, slave_progress," 13929 " slave_task_uuid, slave_uuid, slave_name, slave_host," 13930 " slave_port, source_iface, flags)" 13931 " SELECT id, uuid, owner, hidden, task, date, start_time, end_time," 13932 " nbefile, comment, scan_run_status, slave_progress," 13933 " slave_task_uuid, slave_uuid, slave_name, slave_host," 13934 " slave_port, source_iface, flags" 13935 " FROM reports_182;");
13937 sql (
"DROP TABLE reports_182;");
13941 sql (
"ALTER TABLE reports DROP COLUMN slave_username;");
13942 sql (
"ALTER TABLE reports DROP COLUMN slave_password;");
13976 sql (
"DELETE FROM permissions WHERE name = 'get_nvt_feed_version';");
13978 sql (
"DELETE FROM permissions_trash WHERE name = 'get_nvt_feed_version';");
13983 sql (
"UPDATE report_formats SET flags = (flags & ~1) WHERE id NOT IN" 13984 " (SELECT resource FROM resources_predefined" 13985 " WHERE resource_type='report_format');");
13996 #undef UPDATE_CHART_SETTINGS 13997 #undef UPDATE_DASHBOARD_SETTINGS 13999 #ifdef SQL_IS_SQLITE 14000 #define SQLITE_OR_NULL(function) function 14002 #define SQLITE_OR_NULL(function) NULL 14211 (GLogFunc) openvas_log_func,
14216 return db_version > 0 && db_version < 52;
14232 migrators = database_migrators + old_version + 1;
14234 while ((migrators->
version >= 0) && (migrators->
version <= new_version))
14236 if (migrators->
function == NULL)
return 0;
14237 if (migrators->
version == new_version)
return 1;
14259 int old_version, old_scap_version, old_cert_version;
14261 int new_version, new_scap_version, new_cert_version;
14262 int version_current = 0, scap_version_current = 0, cert_version_current = 0;
14266 (GLogFunc) openvas_log_func,
14274 if (old_version == -1)
14280 if (old_version == -2)
14282 g_warning (
"%s: no task tables yet, run a --rebuild to create them.\n",
14284 version_current = 1;
14286 else if (old_version == new_version)
14288 version_current = 1;
14304 migrators = database_migrators + old_version + 1;
14306 while ((migrators->
version >= 0) && (migrators->
version <= new_version))
14331 if (old_scap_version == new_scap_version)
14333 g_debug (
"SCAP database already at current version");
14334 scap_version_current = 1;
14336 else if (old_scap_version == -1)
14338 g_message (
"No SCAP database found for migration");
14339 scap_version_current = 1;
14341 else if (old_scap_version > new_scap_version)
14343 g_warning (
"SCAP database version too new: %d", old_scap_version);
14348 g_message (
"Migrating SCAP database");
14353 g_message (
"SCAP database migrated successfully");
14356 g_warning (
"SCAP sync already running");
14369 if (old_cert_version == new_cert_version)
14371 g_debug (
"CERT database already at current version");
14372 cert_version_current = 1;
14374 else if (old_cert_version == -1)
14376 g_message (
"No CERT database found for migration");
14377 cert_version_current = 1;
14379 else if (old_cert_version > new_cert_version)
14381 g_warning (
"CERT database version too new: %d", old_cert_version);
14386 g_message (
"Migrating CERT database");
14391 g_message (
"CERT database migrated successfully");
14394 g_warning (
"CERT sync already running");
14407 if (version_current && scap_version_current && cert_version_current)
int sql_is_sqlite3()
Get whether backend is SQLite3.
int migrate_58_to_59()
Migrate the database from version 58 to version 59.
void init_manage_process(int, const gchar *)
Initialize the manage library for a process.
char * alert_data(alert_t alert, const char *type, const char *name)
Return data associated with an alert.
GSList * log_config
Logging parameters, as passed to setup_log_handlers.
void migrate_179_to_180_update_ref(const gchar *table, int trash)
Update a reference for migrate_179_to_180.
void migrate_17_to_18_set_pref(config_t config)
Set the pref for migrate_17_to_18.
int migrate_174_to_175()
Migrate the database from version 174 to version 175.
int migrate_150_to_151()
Migrate the database from version 150 to version 151.
int migrate_148_to_149()
Migrate the database from version 148 to version 149.
long long int credential_t
int migrate_27_to_28()
Migrate the database from version 27 to version 28.
#define INSERT_PERMISSION(name, role)
int migrate_32_to_33()
Migrate the database from version 32 to version 33.
#define MIN_QOD_DEFAULT
Default min quality of detection percentage for filters.
int migrate_88_to_89()
Migrate the database from version 88 to version 89.
int migrate_54_to_55_format(const char *old_uuid, const char *new_uuid)
Migrate a report format from version 54 to version 55.
int migrate_160_to_161()
Migrate the database from version 160 to version 161.
int migrate_113_to_114()
Migrate the database from version 113 to version 114.
lsc_crypt_ctx_t lsc_crypt_new()
Return a new context for LSC encryption.
void migrate_33_to_34_set_pref(config_t config)
Set the pref for migrate_33_to_34.
void parse_tags(const char *scanner_tags, gchar **tags, gchar **cvss_base)
Split up the tags received from the scanner.
int migrate_138_to_139()
Migrate the database from version 138 to version 139.
int migrate_60_to_61()
Migrate the database from version 60 to version 61.
int migrate_36_to_37()
Migrate the database from version 36 to version 37.
const char * sql_schema()
Get main schema name.
int migrate_97_to_98()
Migrate the database from version 97 to version 98.
void migrate_55_to_56_ensure_predefined_port_lists_exist()
Ensure that the predefined port lists exist.
int migrate_139_to_140()
Migrate the database from version 139 to version 140.
int manage_scap_db_supported_version()
Return the database version supported by this manager.
#define LOCATION_TRASH
Location of a constituent of a trashcan resource.
int migrate_17_to_18()
Migrate the database from version 17 to version 18.
int migrate_66_to_67()
Migrate the database from version 66 to version 67.
int manage_scap_loaded()
Check whether SCAP is available.
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
int migrate_19_to_20()
Migrate the database from version 19 to version 20.
int migrate_159_to_160()
Migrate the database from version 159 to version 160.
#define CONFIG_UUID_FULL_AND_FAST
UUID of 'Full and fast' config.
int migrate_35_to_36()
Migrate the database from version 35 to version 36.
int migrate_38_to_39()
Migrate the database from version 38 to version 39.
int migrate_176_to_177()
Migrate the database from version 176 to version 177.
int version
Version that the migrator produces.
int migrate_20_to_21()
Migrate the database from version 20 to version 21.
#define CONFIG_UUID_FULL_AND_FAST_ULTIMATE
UUID of 'Full and fast ultimate' config.
int iterator_int(iterator_t *iterator, int col)
Get a int column from an iterator.
int migrate_98_to_99()
Migrate the database from version 98 to version 99.
int migrate_100_to_101()
Migrate the database from version 100 to version 101.
int migrate_22_to_23()
Migrate the report formats from version 22 to version 23.
int migrate_2_to_3()
Migrate the database from version 2 to version 3.
int migrate_12_to_13()
Migrate the database from version 12 to version 13.
int migrate_80_to_81()
Migrate the database from version 80 to version 81.
void sql_begin_exclusive()
Begin an exclusive transaction.
resource_t sql_last_insert_id()
Get the ID of the last inserted row.
int migrate_50_to_51()
Migrate the database from version 50 to version 51.
int migrate_155_to_156()
Migrate the database from version 155 to version 156.
int migrate_128_to_129()
Migrate the database from version 128 to version 129.
int migrate_43_to_44()
Migrate the database from version 43 to version 44.
void cleanup_manage_process(gboolean)
Cleanup the manage library.
int migrate_86_to_87()
Migrate the database from version 86 to version 87.
int migrate_182_to_183()
Migrate the database from version 182 to version 183.
int migrate_178_to_179()
Migrate the database from version 178 to version 179.
int migrate_129_to_130()
Migrate the database from version 129 to version 130.
int migrate_127_to_128()
Migrate the database from version 127 to version 128.
int migrate_156_to_157()
Migrate the database from version 156 to version 157.
int migrate_122_to_123()
Migrate the database from version 122 to version 123.
target_t migrate_35_to_36_duplicate_target(target_t target, const char *name)
Make a copy of a target.
void sql_rollback()
Roll a transaction back.
int migrate_5_to_6()
Migrate the database from version 5 to version 6.
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
#define QOD_DEFAULT
Default quality of detection percentage.
int manage_cert_loaded()
Check whether CERT is available.
int migrate_137_to_138()
Migrate the database from version 137 to version 138.
lsc_crypt_ctx_t crypt_ctx
Encryption context.
int migrate_163_to_164()
Migrate the database from version 163 to version 164.
int migrate_57_to_58()
Migrate the database from version 57 to version 58.
int migrate_134_to_135()
Migrate the database from version 134 to version 135.
int migrate_145_to_146()
Migrate the database from version 145 to version 146.
int migrate_71_to_72()
Migrate the database from version 71 to version 72.
int migrate_85_to_86()
Migrate the database from version 85 to version 86.
int migrate_104_to_105()
Migrate the database from version 104 to version 105.
#define CONFIG_ID_FULL_AND_VERY_DEEP
Database ROWID of 'Full and very deep' config.
#define MIGRATE_162_TO_163_CONTROL_DESCRIPTION
Description for Verinice ISM report format.
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
int migrate_10_to_11()
Migrate the database from version 10 to version 11.
int migrate_147_to_148()
Migrate the database from version 147 to version 148.
int migrate_154_to_155()
Migrate the database from version 154 to version 155.
int migrate_169_to_170()
Migrate the database from version 169 to version 170.
int migrate_52_to_53()
Migrate the database from version 52 to version 53.
int migrate_7_to_8()
Migrate the database from version 7 to version 8.
int migrate_55_to_56()
Migrate the database from version 55 to version 56.
int migrate_105_to_106()
Migrate the database from version 105 to version 106.
int migrate_119_to_120()
Migrate the database from version 119 to version 120.
int migrate_103_to_104()
Migrate the database from version 103 to version 104.
#define CONFIG_UUID_DISCOVERY
UUID of 'Discovery' config.
int migrate_79_to_80()
Migrate the database from version 79 to version 80.
int migrate_110_to_111()
Migrate the database from version 110 to version 111.
int sql_exec(sql_stmt_t *stmt)
Execute a prepared statement.
#define ROLE_UUID_USER
Predefined role UUID.
int migrate_158_to_159()
Migrate the database from version 158 to version 159.
int migrate_4_to_5()
Migrate the database from version 4 to version 5.
#define ROLE_UUID_SUPER_ADMIN
Predefined role UUID.
int migrate_14_to_15()
Migrate the database from version 14 to version 15.
int migrate_132_to_133()
Migrate the database from version 132 to version 133.
int migrate_101_to_102()
Migrate the database from version 101 to version 102.
const char * lsc_crypt_get_private_key(lsc_crypt_ctx_t ctx, const char *ciphertext)
Return an encrypted private key in the clear.
int migrate_125_to_126()
Migrate the database from version 125 to version 126.
int migrate_45_to_46()
Migrate the database from version 45 to version 46.
int migrate_114_to_115()
Migrate the database from version 114 to version 115.
int migrate_181_to_182()
Migrate the database from version 181 to version 182.
int migrate_124_to_125()
Migrate the database from version 124 to version 125.
int migrate_89_to_90()
Migrate the database from version 89 to version 90.
int migrate_29_to_30()
Migrate the database from version 29 to version 30.
int migrate_133_to_134()
Migrate the database from version 133 to version 134.
int migrate_64_to_65()
Migrate the database from version 64 to version 65.
#define NVT_SELECTOR_TYPE_NVT
NVT selector type for "NVT" rule.
const char * nvt_selector_iterator_nvt(iterator_t *)
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
int modify_asset(const char *, const char *)
#define ID_WHEN_WITH_TRASH(type)
int sql_changes()
Return 0.
int disable_encrypted_credentials
Flag indicating that encrypted credentials are disabled.
#define ID_WHEN_WITHOUT_TRASH(type)
int migrate_90_to_91()
Migrate the database from version 90 to version 91.
int migrate_170_to_171()
Migrate the database from version 170 to version 171.
int migrate_99_to_100()
Migrate the database from version 99 to version 100.
#define ROLE_UUID_OBSERVER
Predefined role UUID.
#define MIGRATE_55_TO_56_RANGE(type, start, end)
Insert a port range.
int migrate_84_to_85()
Migrate the database from version 84 to version 85.
#define MIGRATE_79_to_80_DELETE(table)
int migrate_106_to_107()
Migrate the database from version 106 to version 107.
int migrate_177_to_178()
Migrate the database from version 177 to version 178.
int migrate_180_to_181()
Migrate the database from version 180 to version 181.
#define ROLE_UUID_GUEST
Predefined role UUID.
#define CONFIG_UUID_FULL_AND_VERY_DEEP
UUID of 'Full and very deep' config.
gchar * task_db_name
Name of the database file.
#define DELETE_PERMISSION(name, role)
int migrate_9_to_10()
Migrate the database from version 9 to version 10.
int migrate_123_to_124()
Migrate the database from version 123 to version 124.
int migrate_161_to_162()
Migrate the database from version 161 to version 162.
int migrate_126_to_127()
Migrate the database from version 126 to version 127.
int migrate_181_to_182_move(const char *dest)
Move signatures.
int migrate_54_to_55()
Migrate the database from version 54 to version 55.
int migrate_72_to_73()
Migrate the database from version 72 to version 73.
int migrate_79_to_80_user_access(const gchar *user_dir, gchar **hosts, int *hosts_allow)
Get access information for a user.
int migrate_48_to_49()
Migrate the database from version 48 to version 49.
#define CONFIG_UUID_EMPTY
UUID of 'Empty' config.
int migrate_59_to_60()
Migrate the database from version 59 to version 60.
const char * lsc_crypt_get_password(lsc_crypt_ctx_t ctx, const char *ciphertext)
Return an encrypted password in the clear.
int migrate_135_to_136()
Migrate the database from version 135 to version 136.
void migrate_5_to_6_move_other_config(const char *predefined_config_name, config_t predefined_config_id)
Move a config that is using a predefined ID.
The context object for encryption operations.
int migrate_116_to_117()
Migrate the database from version 116 to version 117.
#define CONFIG_ID_FULL_AND_FAST_ULTIMATE
Database ROWID of 'Full and fast ultimate' config.
#define SCANNER_UUID_DEFAULT
UUID of 'OpenVAS Default' scanner.
int migrate_69_to_70()
Migrate the database from version 69 to version 70.
int migrate_39_to_40()
Migrate the database from version 39 to version 40.
int migrate_83_to_84()
Migrate the database from version 83 to version 84.
#define RESOURCE_TRASH(type)
#define CONFIG_ID_FULL_AND_FAST
Database ROWID of 'Full and fast' config.
#define CLIENTCERT
Location of client certificate.
int migrate_15_to_16()
Migrate the database from version 15 to version 16.
int migrate_33_to_34()
Migrate the database from version 33 to version 34.
int migrate_95_to_96()
Migrate the database from version 95 to version 96.
int migrate_94_to_95()
Migrate the database from version 94 to version 95.
int migrate_146_to_147()
Migrate the database from version 146 to version 147.
int migrate_167_to_168()
Migrate the database from version 167 to version 168.
int migrate_96_to_97()
Migrate the database from version 96 to version 97.
int migrate_75_to_76()
Migrate the database from version 75 to version 76.
#define UPDATE_CHART_SETTINGS(type, default, left_uuid, right_uuid)
#define MANAGE_NVT_SELECTOR_UUID_DISCOVERY
UUID of 'Discovery' NVT selector.
int migrate_111_to_112()
Migrate the database from version 111 to version 112.
int delete_asset(const char *, const char *, int)
int migrate_37_to_38()
Migrate the database from version 37 to version 38.
int migrate_74_to_75()
Migrate the database from version 74 to version 75.
int migrate_140_to_141()
Migrate the database from version 140 to version 141.
int migrate_6_to_7()
Migrate the database from version 6 to version 7.
int migrate_81_to_82()
Migrate the database from version 81 to version 82.
int migrate_91_to_92()
Migrate the database from version 91 to version 92.
int migrate_47_to_48()
Migrate the database from version 47 to version 48.
int migrate_152_to_153()
Migrate the database from version 152 to version 153.
int migrate_164_to_165()
Migrate the database from version 163 to version 164.
int migrate_76_to_77()
Migrate the database from version 76 to version 77.
int migrate_62_to_63()
Migrate the database from version 62 to version 63.
int migrate_56_to_57()
Migrate the database from version 56 to version 57.
int migrate_30_to_31()
Migrate the database from version 30 to version 31.
gchar * migrate_9_to_10_user_uuid(const char *name)
Return the UUID of a user from the OpenVAS user UUID file.
#define TRUST_UNKNOWN
Trust constant for unknown.
int openvas_migrate_secinfo(const gchar *, int)
int migrate_34_to_35()
Migrate the database from version 34 to version 35.
int migrate_67_to_68()
Migrate the database from version 67 to version 68.
int migrate_92_to_93()
Migrate the database from version 92 to version 93.
int qod_from_type(const char *)
int migrate_23_to_24()
Migrate the database from version 23 to version 24.
int migrate_118_to_119()
Migrate the database from version 118 to version 119.
int migrate_142_to_143()
Migrate the database from version 142 to version 143.
void init_nvt_selector_iterator(iterator_t *, const char *, config_t, int)
int migrate_16_to_17()
Migrate the database from version 16 to version 17.
int migrate_82_to_83()
Migrate the database from version 82 to version 83.
int migrate_31_to_32()
Migrate the database from version 31 to version 32.
int migrate_171_to_172()
Migrate the database from version 171 to version 172.
int migrate_21_to_22()
Migrate the report formats from version 21 to version 22.
void migrate_39_to_40_set_pref(config_t config)
Set the pref for migrate_39_to_40.
#define ALL_LOG_LEVELS
Flag with all Glib log levels.
#define UPDATE_DASHBOARD_SETTINGS(type, default, uuid_1, uuid_2, uuid_3, uuid_4, filter_1, filter_2, filter_3, filter_4)
void migrate_4_to_5_copy_data()
Move all the data to the new tables for the 4 to 5 migrator.
int migrate_13_to_14()
Migrate the database from version 13 to version 14.
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
int migrate_18_to_19()
Migrate the database from version 18 to version 19.
int migrate_144_to_145()
Migrate the database from version 144 to version 145.
gchar * tag_value(const gchar *tags, const gchar *tag)
Extract a tag from an OTP tag list.
int migrate_168_to_169()
Migrate the database from version 168 to version 169.
int migrate_78_to_79()
Migrate the database from version 78 to version 79.
char * lsc_crypt_encrypt(lsc_crypt_ctx_t ctx, const char *first_name,...)
Encrypt a list of name/value pairs.
int migrate_153_to_154()
Migrate the database from version 152 to version 153.
int migrate_131_to_132()
Migrate the database from version 131 to version 132.
int migrate_166_to_167()
Migrate the database from version 166 to version 167.
int migrate_117_to_118()
Migrate the database from version 117 to version 118.
int manage_migrate(GSList *log_config, const gchar *database)
Migrate database to version supported by this manager.
int manage_db_supported_version()
Return the database version supported by this manager.
int migrate_11_to_12()
Migrate the database from version 11 to version 12.
credentials_t current_credentials
Current credentials during any OMP command.
#define g_info(...)
Defines g_info for glib versions older than 2.40.
#define G_LOG_DOMAIN
GLib log domain.
int manage_cert_db_version()
Return the database version of the actual database.
#define CONFIG_ID_FULL_AND_VERY_DEEP_ULTIMATE
Database ROWID of 'Full and very deep ultimate' config.
int migrate_136_to_137()
Migrate the database from version 136 to version 137.
int migrate_26_to_27()
Migrate the database from version 26 to version 27.
int migrate_8_to_9()
Migrate the database from version 8 to version 9.
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
#define CLIENTKEY
Location of client certificate private key.
int manage_create_migrate_51_to_52_convert()
Dummy for SQLite3 compatibility.
int migrate_46_to_47()
Migrate the database from version 46 to version 47.
#define CACERT
Location of Certificate Authority certificate.
int migrate_63_to_64()
Migrate the database from version 63 to version 64.
int migrate_70_to_71()
Migrate the database from version 70 to version 71.
int migrate_109_to_110()
Migrate the database from version 109 to version 110.
#define CONFIG_UUID_HOST_DISCOVERY
UUID of 'Host Discovery' config.
int migrate_49_to_50()
Migrate the database from version 49 to version 50.
#define CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE
UUID of 'Full and very deep ultimate' config.
sql_stmt_t * sql_prepare(const char *sql,...)
Prepare a statement.
#define ROLE_UUID_ADMIN
Predefined role UUID.
int migrate_141_to_142()
Migrate the database from version 141 to version 142.
int migrate_173_to_174()
Migrate the database from version 173 to version 174.
int migrate_44_to_45()
Migrate the database from version 44 to version 45.
int migrate_61_to_62()
Migrate the database from version 61 to version 62.
int migrate_162_to_163()
Migrate the database from version 158 to version 162.
int migrate_115_to_116()
Migrate the database from version 115 to version 116.
int manage_db_version()
Return the database version of the actual database.
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
int migrate_183_to_184()
Migrate the database from version 183 to version 184.
int migrate_179_to_180()
Migrate the database from version 179 to version 180.
void sql_commit()
Commit a transaction.
int migrate_24_to_25()
Migrate the database from version 24 to version 25.
int migrate_165_to_166()
Migrate the database from version 165 to version 166.
int migrate_53_to_54()
Migrate the database from version 53 to version 54.
int migrate_112_to_113()
Migrate the database from version 112 to version 113.
int migrate_151_to_152()
Migrate the database from version 151 to version 152.
int manage_cert_db_supported_version()
Return the database version supported by this manager.
gchar * sql_insert(const char *string)
Get the SQL insert expression for a string.
int migrate_121_to_122()
Migrate the database from version 121 to version 122.
int migrate_3_to_4()
Migrate the database from version 3 to version 4.
int migrate_172_to_173()
Migrate the database from version 172 to version 173.
int migrate_1_to_2()
Migrate the database from version 1 to version 2.
void migrate_79_to_80_remove_users(const char *where)
Delete users according to a condition.
void sql_rename_column(const char *old_table, const char *new_table, const char *old_name, const char *new_name)
Move data from a table to a new table, heeding column rename.
gboolean next(iterator_t *)
Increment an iterator.
int migrate_25_to_26()
Migrate the database from version 25 to version 26.
int migrate_65_to_66()
Migrate the database from version 65 to version 66.
int migrate_77_to_78()
Migrate the database from version 77 to version 78.
int migrate_143_to_144()
Migrate the database from version 143 to version 144.
int migrate_149_to_150()
Migrate the database from version 149 to version 150.
int migrate_42_to_43()
Migrate the database from version 42 to version 43.
void lsc_crypt_release(lsc_crypt_ctx_t ctx)
Release an LSC encryption context.
#define LOCATION_TABLE
Location of a constituent of a trashcan resource.
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
int migrate_40_to_41()
Migrate the database from version 40 to version 41.
void check_generate_scripts()
Ensure the generate scripts are all executable.
#define PORT_LIST_UUID_DEFAULT
UUID of 'OpenVAS Default' port list.
gchar * sql_nquote(const char *string, size_t length)
Quotes a string of a known length to be passed to sql statements.
int migrate_0_to_1()
Migrate the database from version 0 to version 1.
int migrate_51_to_52()
Migrate the database from version 51 to version 52.
int migrate_28_to_29()
Migrate the database from version 27 to version 28.
int migrate_93_to_94()
Migrate the database from version 93 to version 94.
int migrate_120_to_121()
Migrate the database from version 120 to version 121.
int(* function)()
Function that does the migration. NULL if too hard.
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
int migrate_is_available(int old_version, int new_version)
Check whether a migration is available.
int sql_bind_text(sql_stmt_t *, int, const gchar *, gsize)
Bind a text value to a statement.
#define SQLITE_OR_NULL(function)
int manage_scap_db_version()
Return the database version of the actual database.
#define MANAGE_NVT_SELECTOR_UUID_ALL
UUID of 'All' NVT selector.
int migrate_107_to_108()
Migrate the database from version 107 to version 108.
#define ROLE_UUID_INFO
Predefined role UUID.
int migrate_73_to_74()
Migrate the database from version 73 to version 74.
int migrate_108_to_109()
Migrate the database from version 108 to version 109.
int migrate_157_to_158()
Migrate the database from version 157 to version 158.
int migrate_175_to_176()
Migrate the database from version 175 to version 176.
const char * nvt_selector_iterator_name(iterator_t *)
gboolean manage_migrate_needs_timezone(GSList *log_config, const gchar *database)
Check whether the migration needs the real timezone.
int migrate_87_to_88()
Migrate the database from version 87 to version 88.
void sql_finalize(sql_stmt_t *)
Free a prepared statement.
int migrate_102_to_103()
Migrate the database from version 102 to version 103.
int migrate_41_to_42()
Migrate the database from version 41 to version 42.
long long int resource_t
A resource, like a task or target.
int migrate_68_to_69()
Migrate the database from version 68 to version 69.
long long int report_format_t
int migrate_130_to_131()
Migrate the database from version 130 to version 131.
void set_db_version(int version)
Set the database version of the actual database.