35 #define G_LOG_DOMAIN "md manage" 48 sql (
"CREATE TEMPORARY TABLE IF NOT EXISTS current_credentials" 49 " (id SERIAL PRIMARY KEY," 50 " uuid text UNIQUE NOT NULL," 51 " tz_override text);");
52 sql (
"DELETE FROM current_credentials;");
54 sql (
"INSERT INTO current_credentials (uuid) VALUES ('%s');", uuid);
65 sql (
"SET SESSION TIME ZONE '%s';", timezone);
80 return sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 81 " WHERE table_catalog = '%s'" 82 " AND table_schema = 'public'" 83 " AND table_name = 'meta')" 102 const char *old_name,
const char *new_name)
115 static int created = 0;
121 if (
sql_int (
"SELECT count (*) FROM pg_available_extensions" 122 " WHERE name = 'uuid-ossp' AND installed_version IS NOT NULL;")
125 g_warning (
"%s: PostgreSQL extension uuid-ossp required", __FUNCTION__);
131 sql (
"SET role dba;");
133 sql (
"CREATE OR REPLACE FUNCTION max_hosts (text, text)" 135 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_max_hosts'" 137 OPENVAS_LIB_INSTALL_DIR);
139 sql (
"CREATE OR REPLACE FUNCTION level_max_severity (text, text)" 140 " RETURNS double precision" 141 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_level_max_severity'" 143 OPENVAS_LIB_INSTALL_DIR);
145 sql (
"CREATE OR REPLACE FUNCTION level_min_severity (text, text)" 146 " RETURNS double precision" 147 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_level_min_severity'" 149 OPENVAS_LIB_INSTALL_DIR);
151 sql (
"CREATE OR REPLACE FUNCTION next_time (integer, integer, integer)" 153 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_next_time'" 155 OPENVAS_LIB_INSTALL_DIR);
157 sql (
"CREATE OR REPLACE FUNCTION next_time (integer, integer, integer, text)" 159 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_next_time'" 161 OPENVAS_LIB_INSTALL_DIR);
163 sql (
"CREATE OR REPLACE FUNCTION next_time (integer, integer, integer, text, integer)" 165 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_next_time'" 167 OPENVAS_LIB_INSTALL_DIR);
169 sql (
"CREATE OR REPLACE FUNCTION severity_matches_ov (double precision," 172 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_severity_matches_ov'" 175 OPENVAS_LIB_INSTALL_DIR);
177 sql (
"CREATE OR REPLACE FUNCTION valid_db_resource_type (text)" 179 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_valid_db_resource_type'" 181 OPENVAS_LIB_INSTALL_DIR);
183 sql (
"CREATE OR REPLACE FUNCTION regexp (text, text)" 185 " AS '%s/openvasmd/pg/libmanage-pg-server', 'sql_regexp'" 187 OPENVAS_LIB_INSTALL_DIR);
189 if (
sql_int (
"SELECT count(*) FROM pg_operator" 190 " WHERE oprname = '?~#';")
193 sql (
"CREATE OPERATOR ?~#" 194 " (PROCEDURE = regexp, LEFTARG = text, RIGHTARG = text);");
201 if (
sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 202 " WHERE table_catalog = '%s'" 203 " AND table_schema = 'public'" 204 " AND table_name = 'meta')" 208 sql (
"CREATE OR REPLACE FUNCTION resource_name (text, text, integer)" 209 " RETURNS text AS $$" 212 " execute_name text;" 215 " WHEN NOT valid_db_resource_type ($1)" 216 " THEN RAISE EXCEPTION 'Invalid resource type argument: %', $1;" 219 " THEN RETURN (SELECT 'Note for: '" 222 " WHERE nvts.uuid = notes.nvt)" 226 " THEN RETURN (SELECT 'Note for: '" 229 " WHERE nvts.uuid = notes_trash.nvt)" 232 " WHEN $1 = 'override'" 234 " THEN RETURN (SELECT 'Override for: '" 237 " WHERE nvts.uuid = overrides.nvt)" 240 " WHEN $1 = 'override'" 241 " THEN RETURN (SELECT 'Override for: '" 244 " WHERE nvts.uuid = overrides_trash.nvt)" 245 " FROM overrides_trash" 247 " WHEN $1 = 'report'" 248 " THEN RETURN (SELECT (SELECT name FROM tasks WHERE id = task)" 251 " CASE (SELECT end_time FROM tasks" 254 " ELSE (SELECT end_time::text" 255 " FROM tasks WHERE id = task)" 259 " WHEN $1 = 'result'" 260 " THEN RETURN (SELECT (SELECT name FROM tasks WHERE id = task)" 262 " || (SELECT name FROM nvts WHERE oid = nvt)" 265 " CASE (SELECT end_time FROM tasks" 268 " ELSE (SELECT end_time::text" 269 " FROM tasks WHERE id = task)" 274 " THEN RETURN (SELECT name FROM tasks WHERE uuid = $2);" 276 " THEN EXECUTE 'SELECT name FROM ' || $1 || 's" 280 " RETURN execute_name;" 281 " WHEN $1 NOT IN ('nvt', 'cpe', 'cve', 'ovaldef', 'cert_bund_adv'," 282 " 'dfn_cert_adv', 'report', 'result', 'user')" 283 " THEN EXECUTE 'SELECT name FROM ' || $1 || 's_trash" 287 " RETURN execute_name;" 291 "$$ LANGUAGE plpgsql;");
296 sql (
"CREATE OR REPLACE FUNCTION report_progress_active (integer)" 297 " RETURNS integer AS $$" 300 " report_task integer;" 301 " task_target integer;" 302 " target_hosts text;" 303 " target_exclude_hosts text;" 306 " maximum_hosts integer;" 307 " total_progress integer;" 308 " report_host record;" 309 " dead_hosts integer;" 313 " report_task := (SELECT task FROM reports WHERE id = $1);" 314 " task_target := (SELECT target FROM tasks WHERE id = report_task);" 315 " IF task_target IS NULL THEN" 316 " target_hosts := NULL;" 317 " target_exclude_hosts := NULL;" 319 " FROM tasks WHERE id = report_task)" 321 " target_hosts := (SELECT hosts FROM targets_trash" 322 " WHERE id = task_target);" 323 " target_exclude_hosts := (SELECT exclude_hosts FROM targets_trash" 324 " WHERE id = task_target);" 326 " target_hosts := (SELECT hosts FROM targets" 327 " WHERE id = task_target);" 328 " target_exclude_hosts := (SELECT exclude_hosts FROM targets" 329 " WHERE id = task_target);" 331 " IF target_hosts IS NULL THEN" 334 " maximum_hosts := max_hosts (target_hosts, target_exclude_hosts);" 335 " IF maximum_hosts = 0 THEN" 338 " FOR report_host IN SELECT current_port, max_port" 339 " FROM report_hosts WHERE report = $1" 341 " IF report_host.max_port = -1 THEN" 343 " dead_hosts := dead_hosts + 1;" 344 " ELSEIF report_host.max_port IS NOT NULL" 345 " AND report_host.max_port != 0" 347 " progress := (report_host.current_port * 100)" 348 " / report_host.max_port;" 349 " ELSIF report_host.current_port IS NULL" 350 " OR report_host.current_port = 0" 356 " total := total + progress;" 358 " IF (maximum_hosts - dead_hosts) > 0 THEN" 359 " total_progress := total / (maximum_hosts - dead_hosts);" 361 " total_progress := 0;" 363 " IF total_progress = 0 THEN" 365 " ELSIF total_progress = 100 THEN" 368 " RETURN total_progress;" 370 "$$ LANGUAGE plpgsql;");
372 sql (
"CREATE OR REPLACE FUNCTION order_inet (text)" 373 " RETURNS text AS $$" 375 " IF $1 ~ '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$' THEN" 377 " || to_char (split_part ($1, '.', 1)::integer, 'fm000')" 379 " || to_char (split_part ($1, '.', 2)::integer, 'fm000')" 381 " || to_char (split_part ($1, '.', 3)::integer, 'fm000')" 383 " || to_char (split_part ($1, '.', 4)::integer, 'fm000');" 388 "$$ LANGUAGE plpgsql" 391 sql (
"CREATE OR REPLACE FUNCTION order_message_type (text)" 392 " RETURNS integer AS $$" 394 " IF $1 = 'Security Hole' THEN" 396 " ELSIF $1 = 'Security Warning' THEN" 398 " ELSIF $1 = 'Security Note' THEN" 400 " ELSIF $1 = 'Log Message' THEN" 402 " ELSIF $1 = 'Debug Message' THEN" 404 " ELSIF $1 = 'Error Message' THEN" 410 "$$ LANGUAGE plpgsql" 413 sql (
"CREATE OR REPLACE FUNCTION order_port (text)" 414 " RETURNS integer AS $$" 416 " IF $1 ~ '^[0-9]+' THEN" 417 " RETURN CAST (substring ($1, '^[0-9]+') as integer);" 418 " ELSIF $1 ~ '^[^0-9]* \\([0-9]+/' THEN" 419 " RETURN CAST (substring ($1, '^[^0-9]* \\(([0-9]+)/') as integer);" 424 "$$ LANGUAGE plpgsql" 427 sql (
"CREATE OR REPLACE FUNCTION order_role (text)" 428 " RETURNS text AS $$" 430 " IF $1 = 'Admin' THEN" 436 "$$ LANGUAGE plpgsql" 439 sql (
"CREATE OR REPLACE FUNCTION order_threat (text)" 440 " RETURNS integer AS $$" 442 " IF $1 = 'High' THEN" 444 " ELSIF $1 = 'Medium' THEN" 446 " ELSIF $1 = 'Low' THEN" 448 " ELSIF $1 = 'Log' THEN" 450 " ELSIF $1 = 'Debug' THEN" 452 " ELSIF $1 = 'False Positive' THEN" 454 " ELSIF $1 = 'None' THEN" 460 "$$ LANGUAGE plpgsql" 463 sql (
"CREATE OR REPLACE FUNCTION severity_to_type (double precision)" 464 " RETURNS text AS $$" 466 " IF $1 IS NULL THEN" 469 " RETURN 'Log Message';" 471 " RETURN 'False Positive';" 473 " RETURN 'Debug Message';" 475 " RETURN 'Error Message';" 476 " ELSIF $1 > 0.0 AND $1 <= 10.0 THEN" 479 " RAISE EXCEPTION 'Invalid severity score given: %', $1;" 482 "$$ LANGUAGE plpgsql" 485 sql (
"CREATE OR REPLACE FUNCTION iso_time (seconds integer)" 486 " RETURNS text AS $$" 489 " user_offset interval;" 492 " coalesce ((SELECT tz_override FROM current_credentials)," 493 " (SELECT timezone FROM users" 494 " WHERE uuid = (SELECT uuid" 495 " FROM current_credentials)));" 497 " user_offset := age (now () AT TIME ZONE user_zone," 498 " now () AT TIME ZONE 'UTC');" 499 " EXCEPTION WHEN invalid_parameter_value THEN" 500 " user_zone = 'UTC';" 506 " WHEN user_zone IS NULL" 507 " OR EXTRACT (EPOCH FROM user_offset) = 0" 508 " THEN to_char (to_timestamp ($1) AT TIME ZONE 'UTC'," 510 " || to_char (to_timestamp ($1) AT TIME ZONE 'UTC'," 512 " ELSE to_char (to_timestamp ($1) AT TIME ZONE user_zone," 514 " || to_char (to_timestamp ($1) AT TIME ZONE user_zone," 516 " || CASE WHEN (extract (epoch FROM user_offset) > 0)" 517 " THEN '+' ELSE '' END" 518 " || to_char (extract (hours FROM user_offset)::integer," 521 " || to_char (abs (extract (minutes FROM user_offset)" 526 "$$ LANGUAGE plpgsql;");
528 sql (
"CREATE OR REPLACE FUNCTION days_from_now (seconds integer)" 529 " RETURNS integer AS $$" 533 " diff := age ( to_timestamp( seconds ), now() );" 537 " WHEN diff < interval '0 seconds'" 539 " ELSE date_part( 'day', diff )" 542 "$$ LANGUAGE plpgsql" 545 sql (
"CREATE OR REPLACE FUNCTION uniquify (type text, proposed_name text," 546 " owner integer, suffix text)" 547 " RETURNS text AS $$" 549 " number integer := 1;" 550 " candidate text := '';" 551 " separator text := ' ';" 552 " unique_candidate boolean;" 554 " IF type = 'user' THEN separator := '_'; END IF;" 555 " candidate := proposed_name || suffix || separator || number::text;" 557 " EXECUTE 'SELECT count (*) = 0 FROM ' || type || 's" 559 " AND ((owner IS NULL) OR (owner = $2))'" 560 " INTO unique_candidate" 561 " USING candidate, owner;" 562 " EXIT WHEN unique_candidate;" 563 " number := number + 1;" 564 " candidate := proposed_name || suffix || separator || number::text;" 568 "$$ LANGUAGE plpgsql;");
570 sql (
"CREATE OR REPLACE FUNCTION create_index (schema_name text," 574 " RETURNS void AS $$" 576 " IF (SELECT count(*) = 0 FROM pg_indexes" 577 " WHERE schemaname = lower (schema_name)" 578 " AND tablename = lower (table_name)" 579 " AND indexname = lower (index_name))" 581 " EXECUTE 'CREATE INDEX ' || index_name" 582 " || ' ON ' || table_name || ' (' || columns || ');';" 585 "$$ LANGUAGE plpgsql;");
587 sql (
"CREATE OR REPLACE FUNCTION create_index (index_name text," 590 " RETURNS void AS $$" 592 " PERFORM create_index ('public', index_name, table_name, columns);" 594 "$$ LANGUAGE plpgsql;");
596 sql (
"CREATE OR REPLACE FUNCTION user_has_super_on_resource (arg_type text, arg_id integer)" 597 " RETURNS boolean AS $$" 606 " EXISTS (SELECT * FROM permissions" 607 " WHERE name = ''Super''" 609 " AND ((resource = 0)" 611 " OR ((resource_type = ''user'')" 612 " AND (resource = (SELECT ' || $1 || 's.owner" 613 " FROM ' || $1 || 's" 616 " OR ((resource_type = ''role'')" 618 " IN (SELECT DISTINCT role" 621 " = (SELECT ' || $1 || 's.owner" 622 " FROM ' || $1 || 's" 625 " OR ((resource_type = ''group'')" 627 " IN (SELECT DISTINCT \"group\"" 630 " = (SELECT ' || $1 || 's.owner" 631 " FROM ' || $1 || 's" 632 " WHERE id = $2)))))" 634 " AND ((subject_type = ''user''" 636 " = (SELECT id FROM users" 639 " FROM current_credentials)))" 640 " OR (subject_type = ''group''" 642 " IN (SELECT DISTINCT \"group\"" 650 " FROM current_credentials))))" 651 " OR (subject_type = ''role''" 653 " IN (SELECT DISTINCT role" 661 " FROM current_credentials))))))'" 662 " USING arg_type, arg_id" 666 "$$ LANGUAGE plpgsql;");
668 sql (
"CREATE OR REPLACE FUNCTION user_owns (arg_type text, arg_id integer)" 669 " RETURNS boolean AS $$" 677 " WHEN arg_type = 'nvt'" 678 " OR arg_type = 'cve'" 679 " OR arg_type = 'cpe'" 680 " OR arg_type = 'ovaldef'" 681 " OR arg_type = 'cert_bund_adv'" 682 " OR arg_type = 'dfn_cert_adv'" 684 " WHEN user_has_super_on_resource (arg_type, arg_id)" 686 " WHEN arg_type = 'result'" 688 " WHEN EXISTS (SELECT * FROM results, reports" 689 " WHERE results.id = arg_id" 690 " AND results.report = reports.id" 691 " AND ((reports.owner IS NULL)" 693 " = (SELECT id FROM users" 696 " FROM current_credentials)))))" 698 " ELSE RETURN false;" 700 " WHEN arg_type = 'task'" 702 " WHEN EXISTS (SELECT * FROM tasks" 705 " AND ((owner IS NULL)" 707 " = (SELECT id FROM users" 710 " FROM current_credentials)))))" 712 " ELSE RETURN false;" 716 " 'SELECT EXISTS (SELECT * FROM ' || $1 || 's" 718 " AND ((owner IS NULL)" 719 " OR (owner = (SELECT id FROM users" 720 " WHERE users.uuid = (SELECT uuid" 721 " FROM current_credentials))))'" 722 " USING arg_type, arg_id" 727 "$$ LANGUAGE plpgsql;");
731 sql (
"CREATE OR REPLACE FUNCTION t () RETURNS boolean AS $$" 736 sql (
"CREATE OR REPLACE FUNCTION m_now () RETURNS integer AS $$" 737 " SELECT extract (epoch FROM now ())::integer;" 741 sql (
"CREATE OR REPLACE FUNCTION common_cve (text, text)" 742 " RETURNS boolean AS $$" 744 " SELECT EXISTS (SELECT trim (unnest (string_to_array ($1, ',')))" 746 " SELECT trim (unnest (string_to_array ($2, ','))));" 751 sql (
"CREATE OR REPLACE FUNCTION cpe_title (text)" 752 " RETURNS text AS $$" 753 " SELECT title FROM scap.cpes WHERE uuid = $1;" 758 sql (
"CREATE OR REPLACE FUNCTION cpe_title (text)" 759 " RETURNS text AS $$" 760 " SELECT null::text;" 764 sql (
"CREATE OR REPLACE FUNCTION hosts_contains (text, text)" 765 " RETURNS boolean AS $$" 768 " IN (SELECT trim (unnest (string_to_array ($1, ','))));" 772 sql (
"CREATE OR REPLACE FUNCTION make_uuid () RETURNS text AS $$" 773 " SELECT uuid_generate_v4 ()::text AS result;" 776 sql (
"CREATE OR REPLACE FUNCTION tag (text, text) RETURNS text AS $$" 778 " SELECT split_part (unnest, '=', 2)" 779 " FROM unnest (string_to_array ($1, '|'))" 780 " WHERE split_part (unnest, '=', 1) = $2;" 783 if (
sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 784 " WHERE table_catalog = '%s'" 785 " AND table_schema = 'public'" 786 " AND table_name = 'meta')" 790 sql (
"CREATE OR REPLACE FUNCTION report_active (integer)" 791 " RETURNS boolean AS $$" 794 " WHEN (SELECT scan_run_status FROM reports" 795 " WHERE reports.id = $1)" 796 " IN (SELECT unnest (ARRAY [%i, %i, %i, %i, %i, %i," 810 sql (
"CREATE OR REPLACE FUNCTION report_progress (integer)" 811 " RETURNS integer AS $$" 816 " WHEN (SELECT slave_task_uuid FROM reports WHERE id = $1)" 818 " THEN (SELECT slave_progress FROM reports WHERE id = $1)" 819 " WHEN report_active ($1)" 820 " THEN report_progress_active ($1)" 825 sql (
"CREATE OR REPLACE FUNCTION dynamic_severity ()" 826 " RETURNS boolean AS $$" 828 " SELECT CAST (value AS integer) = 1 FROM settings" 829 " WHERE name = 'Dynamic Severity'" 830 " AND ((owner IS NULL)" 831 " OR (owner = (SELECT id FROM users" 834 " FROM current_credentials))))" 835 " ORDER BY coalesce (owner, 0) DESC LIMIT 1;" 838 sql (
"CREATE OR REPLACE FUNCTION current_severity (real, text)" 839 " RETURNS double precision AS $$" 840 " SELECT coalesce ((CASE WHEN $1 > " G_STRINGIFY (
SEVERITY_LOG)
841 " THEN (SELECT CAST (cvss_base" 842 " AS double precision)" 844 " WHERE nvts.oid = $2)" 850 #define OVERRIDES_SQL(severity_sql) \ 852 " ((SELECT overrides.new_severity" \ 854 " WHERE overrides.nvt = results.nvt" \ 855 " AND ((overrides.owner IS NULL)" \ 856 " OR (overrides.owner =" \ 857 " (SELECT id FROM users" \ 858 " WHERE users.uuid" \ 860 " FROM current_credentials))))" \ 861 " AND ((overrides.end_time = 0)" \ 862 " OR (overrides.end_time >= m_now ()))" \ 863 " AND (overrides.task = results.task" \ 864 " OR overrides.task = 0)" \ 865 " AND (overrides.result = results.id" \ 866 " OR overrides.result = 0)" \ 867 " AND (overrides.hosts is NULL" \ 868 " OR overrides.hosts = ''" \ 869 " OR hosts_contains (overrides.hosts," \ 871 " AND (overrides.port is NULL" \ 872 " OR overrides.port = ''" \ 873 " OR overrides.port = results.port)" \ 874 " AND severity_matches_ov" \ 875 " (" severity_sql ", overrides.severity)" \ 876 " ORDER BY overrides.result DESC," \ 877 " overrides.task DESC," \ 878 " overrides.port DESC," \ 879 " overrides.severity ASC," \ 880 " overrides.creation_time DESC" \ 885 if (current_db_version >= 147)
886 sql (
"CREATE OR REPLACE FUNCTION report_severity (report integer," 887 " overrides integer," 889 " RETURNS double precision AS $$" 891 " WITH max_severity AS (SELECT max(severity) AS max" 892 " FROM report_counts" 897 " AND (end_time = 0 or end_time >= m_now ()))" 899 " WHEN EXISTS (SELECT max FROM max_severity)" 900 " AND (SELECT max FROM max_severity) IS NOT NULL" 901 " THEN (SELECT max::double precision FROM max_severity)" 902 " WHEN dynamic_severity () AND $2::boolean" 906 (
"current_severity (results.severity," 909 " WHERE results.report = $1" 910 " AND results.qod >= $3)" 911 " WHEN dynamic_severity ()" 913 " THEN (SELECT max (CASE" 914 " WHEN results.type IS NULL" 916 " ELSE current_severity" 917 " (results.severity, results.nvt)" 920 " WHERE results.report = $1" 921 " AND results.qod >= $3)" 926 " WHERE results.report = $1" 927 " AND results.qod >= $3)" 929 " ELSE (SELECT max (CASE" 930 " WHEN results.type IS NULL" 932 " ELSE results.severity" 935 " WHERE results.report = $1" 936 " AND results.qod >= $3)" 940 sql (
"CREATE OR REPLACE FUNCTION report_host_count (report integer)" 941 " RETURNS bigint AS $$" 942 " SELECT count (DISTINCT id) FROM report_hosts" 943 " WHERE report_hosts.report = $1;" 946 sql (
"CREATE OR REPLACE FUNCTION report_result_host_count (report integer," 948 " RETURNS bigint AS $$" 949 " SELECT count (DISTINCT id) FROM report_hosts" 950 " WHERE report_hosts.report = $1" 951 " AND EXISTS (SELECT * FROM results" 952 " WHERE results.host = report_hosts.host" 953 " AND results.qod >= $2)" 956 sql (
"CREATE OR REPLACE FUNCTION severity_class ()" 957 " RETURNS text AS $$" 959 " SELECT value FROM settings" 960 " WHERE name = 'Severity Class'" 961 " AND ((owner IS NULL)" 962 " OR (owner = (SELECT id FROM users" 963 " WHERE users.uuid = (SELECT uuid" 964 " FROM current_credentials))))" 965 " ORDER BY coalesce (owner, 0) DESC LIMIT 1;" 969 if (current_db_version >= 147)
970 sql (
"CREATE OR REPLACE FUNCTION" 971 " report_severity_count (report integer, overrides integer," 972 " min_qod integer, level text)" 973 " RETURNS bigint AS $$" 975 " WITH severity_count AS (SELECT sum (count) AS total" 976 " FROM report_counts" 981 " or end_time >= m_now ())" 983 " BETWEEN level_min_severity" 984 " ($4, severity_class ())" 985 " AND level_max_severity" 986 " ($4, severity_class ())))" 988 " WHEN EXISTS (SELECT total FROM severity_count)" 989 " AND (SELECT total FROM severity_count) IS NOT NULL" 990 " THEN (SELECT total FROM severity_count)" 991 " WHEN dynamic_severity () AND $2::boolean" 993 " THEN (SELECT count (*)" 995 " WHERE results.report = $1" 996 " AND results.qod >= $3" 998 (
"current_severity (results.severity," 1000 " BETWEEN level_min_severity" 1001 " ($4, severity_class ())" 1002 " AND level_max_severity" 1003 " ($4, severity_class ())))" 1004 " WHEN dynamic_severity ()" 1006 " THEN (SELECT count (*)" 1008 " WHERE results.report = $1" 1009 " AND results.qod >= $3" 1011 " WHEN results.type IS NULL" 1013 " ELSE current_severity (results.severity," 1016 " BETWEEN level_min_severity ($4, severity_class ())" 1017 " AND level_max_severity" 1018 " ($4, severity_class ())))" 1021 " THEN (SELECT count (*)" 1023 " WHERE results.report = $1" 1024 " AND results.qod >= $3" 1026 " BETWEEN level_min_severity ($4, severity_class ())" 1027 " AND level_max_severity" 1028 " ($4, severity_class ())))" 1030 " ELSE (SELECT count (*)" 1032 " WHERE results.report = $1" 1033 " AND results.qod >= $3" 1035 " WHEN results.type IS NULL" 1037 " ELSE results.severity" 1039 " BETWEEN level_min_severity ($4, severity_class ())" 1040 " AND level_max_severity" 1041 " ($4, severity_class ())))" 1043 "$$ LANGUAGE SQL;");
1045 sql (
"CREATE OR REPLACE FUNCTION task_last_report (integer)" 1046 " RETURNS integer AS $$" 1048 " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" 1049 " ORDER BY date DESC LIMIT 1;" 1053 sql (
"CREATE OR REPLACE FUNCTION task_second_last_report (integer)" 1054 " RETURNS integer AS $$" 1056 " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" 1057 " ORDER BY date DESC LIMIT 1 OFFSET 1;" 1061 if (current_db_version >= 147)
1063 sql (
"CREATE OR REPLACE FUNCTION task_severity (integer, integer," 1065 " RETURNS double precision AS $$" 1068 " WHEN (SELECT target IS NULL OR target = 0" 1069 " FROM tasks WHERE id = $1)" 1070 " THEN CAST (NULL AS double precision)" 1072 " (SELECT report_severity ((SELECT id FROM reports" 1074 " AND scan_run_status = %u" 1075 " ORDER BY date DESC" 1076 " LIMIT 1 OFFSET 0), $2, $3))" 1081 sql (
"CREATE OR REPLACE FUNCTION task_trend (integer, integer, integer)" 1082 " RETURNS text AS $$" 1085 " last_report integer;" 1086 " second_last_report integer;" 1087 " severity_a double precision;" 1088 " severity_b double precision;" 1095 " threat_a integer;" 1096 " threat_b integer;" 1100 " WHEN (SELECT count(*) <= 1 FROM reports" 1102 " AND scan_run_status = %u)" 1103 " THEN RETURN ''::text;" 1105 " WHEN NOT EXISTS (SELECT uuid FROM current_credentials)" 1106 " OR (SELECT uuid = '' FROM current_credentials)" 1107 " THEN RETURN ''::text;" 1109 " WHEN (SELECT run_status = %u OR target = 0" 1110 " FROM tasks WHERE id = $1)" 1111 " THEN RETURN ''::text;" 1115 " last_report := task_last_report ($1);" 1116 " second_last_report := task_second_last_report ($1);" 1117 " severity_a := report_severity (last_report, $2, $3);" 1118 " severity_b := report_severity (second_last_report, $2, $3);" 1119 " IF severity_a > severity_b THEN" 1120 " RETURN 'up'::text;" 1121 " ELSIF severity_b > severity_a THEN" 1122 " RETURN 'down'::text;" 1125 " high_a := report_severity_count (last_report, $2, $3," 1127 " high_b := report_severity_count (second_last_report, $2, $3," 1129 " medium_a := report_severity_count (last_report, $2, $3," 1131 " medium_b := report_severity_count (second_last_report, $2, $3," 1133 " low_a := report_severity_count (last_report, $2, $3," 1135 " low_b := report_severity_count (second_last_report, $2, $3," 1137 " IF high_a > 0 THEN" 1139 " ELSIF medium_a > 0 THEN" 1141 " ELSIF low_a > 0 THEN" 1146 " IF high_b > 0 THEN" 1148 " ELSIF medium_b > 0 THEN" 1150 " ELSIF low_b > 0 THEN" 1156 " IF threat_a > threat_b THEN" 1157 " RETURN 'up'::text;" 1158 " ELSIF threat_b > threat_a THEN" 1159 " RETURN 'down'::text;" 1162 " IF high_a > 0 THEN" 1163 " IF high_a > high_b THEN" 1164 " RETURN 'more'::text;" 1165 " ELSIF high_a < high_b THEN" 1166 " RETURN 'less'::text;" 1168 " RETURN 'same'::text;" 1170 " IF medium_a > 0 THEN" 1171 " IF medium_a > medium_b THEN" 1172 " RETURN 'more'::text;" 1173 " ELSIF medium_a < medium_b THEN" 1174 " RETURN 'less'::text;" 1176 " RETURN 'same'::text;" 1178 " IF low_a > 0 THEN" 1179 " IF low_a > low_b THEN" 1180 " RETURN 'more'::text;" 1181 " ELSIF low_a < low_b THEN" 1182 " RETURN 'less'::text;" 1184 " RETURN 'same'::text;" 1186 " RETURN 'same'::text;" 1188 "$$ LANGUAGE plpgsql;",
1194 sql (
"CREATE OR REPLACE FUNCTION run_status_name (integer)" 1195 " RETURNS text AS $$" 1200 " THEN 'Delete Requested'" 1201 " WHEN $1 = %i OR $1 = %i" 1202 " THEN 'Ultimate Delete Requested'" 1211 " WHEN $1 = %i OR $1 = %i OR $1 = %i" 1212 " THEN 'Stop Requested'" 1215 " ELSE 'Internal Error'" 1232 if (
sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 1233 " WHERE table_catalog = '%s'" 1234 " AND table_schema = 'public'" 1235 " AND table_name = 'permissions')" 1238 sql (
"CREATE OR REPLACE FUNCTION user_can_everything (text)" 1239 " RETURNS boolean AS $$" 1243 " SELECT count(*) > 0 FROM permissions" 1244 " WHERE resource = 0" 1245 " AND ((subject_type = 'user'" 1247 " = (SELECT id FROM users" 1248 " WHERE users.uuid = $1))" 1249 " OR (subject_type = 'group'" 1251 " IN (SELECT DISTINCT \"group\"" 1253 " WHERE \"user\" = (SELECT id" 1257 " OR (subject_type = 'role'" 1259 " IN (SELECT DISTINCT role" 1261 " WHERE \"user\" = (SELECT id" 1265 " AND name = 'Everything';" 1266 "$$ LANGUAGE SQL;");
1268 sql (
"CREATE OR REPLACE FUNCTION group_concat_pair (text, text, text)" 1269 " RETURNS text AS $$" 1271 " WHEN $1 IS NULL OR $1 = ''" 1273 " ELSE $1 || $3 || $2" 1278 sql (
"DROP AGGREGATE IF EXISTS group_concat (text, text);");
1280 sql (
"CREATE AGGREGATE group_concat (text, text)" 1281 " (sfunc = group_concat_pair," 1283 " initcond = '');");
1285 if (
sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 1286 " WHERE table_catalog = '%s'" 1287 " AND table_schema = 'public'" 1288 " AND table_name = 'meta')" 1292 sql (
"CREATE OR REPLACE FUNCTION severity_in_level (double precision," 1294 " RETURNS boolean AS $$" 1295 " SELECT CASE (SELECT value FROM settings" 1296 " WHERE name = 'Severity Class'" 1297 " AND ((owner IS NULL)" 1298 " OR (owner = (SELECT id FROM users" 1301 " FROM current_credentials))))" 1302 " ORDER BY coalesce (owner, 0) DESC LIMIT 1)" 1304 " THEN (CASE lower ($2)" 1321 " THEN (CASE lower ($2)" 1325 " THEN $1 >= 0.0 AND $1 < 4.0" 1327 " THEN $1 >= 0.0 AND $1 < 4.0" 1348 "$$ LANGUAGE SQL;");
1350 sql (
"CREATE OR REPLACE FUNCTION severity_to_level (text, integer)" 1351 " RETURNS text AS $$" 1353 " WHEN $1::double precision = " G_STRINGIFY (
SEVERITY_LOG)
1355 " WHEN $1::double precision = " G_STRINGIFY (
SEVERITY_FP)
1356 " THEN 'False Positive'" 1361 " WHEN $1::double precision > 0.0" 1362 " AND $1::double precision <= 10.0" 1363 " THEN (SELECT CASE" 1366 " WHEN severity_in_level ($1::double precision," 1369 " WHEN severity_in_level ($1::double precision," 1372 " WHEN severity_in_level ($1::double precision," 1377 " ELSE 'Internal Error'" 1382 sql (
"CREATE OR REPLACE FUNCTION severity_to_level (double precision," 1384 " RETURNS text AS $$" 1389 " THEN 'False Positive'" 1394 " WHEN $1 > 0.0 AND $1 <= 10.0" 1395 " THEN (SELECT CASE" 1398 " WHEN severity_in_level ($1, 'high')" 1400 " WHEN severity_in_level ($1, 'medium')" 1402 " WHEN severity_in_level ($1, 'low')" 1406 " ELSE 'Internal Error'" 1411 if (current_db_version >= 147)
1412 sql (
"CREATE OR REPLACE FUNCTION task_threat_level (integer, integer," 1414 " RETURNS text AS $$" 1416 " SELECT severity_to_level (task_severity ($1, $2, $3), 0);" 1421 if (
sql_int (
"SELECT (EXISTS (SELECT * FROM information_schema.tables" 1422 " WHERE table_catalog = '%s'" 1423 " AND table_schema = 'public'" 1424 " AND table_name = 'credentials_data')" 1425 " AND EXISTS (SELECT * FROM information_schema.tables" 1426 " WHERE table_catalog = '%s'" 1427 " AND table_schema = 'public'" 1428 " AND table_name = 'credentials_trash_data'))" 1432 sql (
"CREATE OR REPLACE FUNCTION credential_value (integer, integer, text)" 1433 " RETURNS text AS $$" 1437 " (SELECT value FROM credentials_trash_data" 1438 " WHERE credential = $1 AND type = $3)" 1440 " (SELECT value FROM credentials_data" 1441 " WHERE credential = $1 AND type = $3)" 1443 "$$ LANGUAGE SQL;");
1446 if (
sql_int (
"SELECT (EXISTS (SELECT * FROM information_schema.tables" 1447 " WHERE table_catalog = '%s'" 1448 " AND table_schema = 'public'" 1449 " AND table_name = 'targets_login_data')" 1450 " AND EXISTS (SELECT * FROM information_schema.tables" 1451 " WHERE table_catalog = '%s'" 1452 " AND table_schema = 'public'" 1453 " AND table_name = 'targets_trash_login_data'))" 1457 sql (
"CREATE OR REPLACE FUNCTION target_credential (integer, integer, text)" 1458 " RETURNS integer AS $$" 1462 " (SELECT credential FROM targets_trash_login_data" 1463 " WHERE target = $1 AND type = $3)" 1465 " (SELECT credential FROM targets_login_data" 1466 " WHERE target = $1 AND type = $3)" 1468 "$$ LANGUAGE SQL;");
1470 sql (
"CREATE OR REPLACE FUNCTION trash_target_credential_location (integer, text)" 1471 " RETURNS integer AS $$" 1472 " SELECT credential_location FROM targets_trash_login_data" 1473 " WHERE target = $1 AND type = $2" 1474 "$$ LANGUAGE SQL;");
1476 sql (
"CREATE OR REPLACE FUNCTION target_login_port (integer, integer, text)" 1477 " RETURNS integer AS $$" 1481 " (SELECT port FROM targets_trash_login_data" 1482 " WHERE target = $1 AND type = $3)" 1484 " (SELECT port FROM targets_login_data" 1485 " WHERE target = $1 AND type = $3)" 1487 "$$ LANGUAGE SQL;");
1490 sql (
"CREATE OR REPLACE FUNCTION lower (integer)" 1491 " RETURNS integer AS $$" 1508 gchar *owned_clause;
1510 sql (
"DROP TABLE IF EXISTS current_credentials");
1511 sql (
"CREATE TABLE IF NOT EXISTS current_credentials" 1512 " (id SERIAL PRIMARY KEY," 1513 " uuid text UNIQUE NOT NULL," 1514 " tz_override text);");
1516 sql (
"CREATE TABLE IF NOT EXISTS meta" 1517 " (id SERIAL PRIMARY KEY," 1518 " name text UNIQUE NOT NULL," 1521 sql (
"CREATE TABLE IF NOT EXISTS users" 1522 " (id SERIAL PRIMARY KEY," 1523 " uuid text UNIQUE NOT NULL," 1524 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1525 " name text NOT NULL," 1530 " hosts_allow integer," 1532 " ifaces_allow integer," 1534 " creation_time integer," 1535 " modification_time integer);");
1537 sql (
"CREATE TABLE IF NOT EXISTS auth_cache" 1538 " (id SERIAL PRIMARY KEY," 1539 " username text NOT NULL," 1542 " creation_time integer);");
1544 sql (
"CREATE TABLE IF NOT EXISTS agents" 1545 " (id SERIAL PRIMARY KEY," 1546 " uuid text UNIQUE NOT NULL," 1547 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1548 " name text NOT NULL," 1551 " installer_64 text," 1552 " installer_filename text," 1553 " installer_signature_64 text," 1554 " installer_trust integer," 1555 " installer_trust_time integer," 1556 " howto_install text," 1558 " creation_time integer," 1559 " modification_time integer);");
1561 sql (
"CREATE TABLE IF NOT EXISTS agents_trash" 1562 " (id SERIAL PRIMARY KEY," 1563 " uuid text UNIQUE NOT NULL," 1564 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1565 " name text NOT NULL," 1568 " installer_64 text," 1569 " installer_filename text," 1570 " installer_signature_64 text," 1571 " installer_trust integer," 1572 " installer_trust_time integer," 1573 " howto_install text," 1575 " creation_time integer," 1576 " modification_time integer);");
1578 sql (
"CREATE TABLE IF NOT EXISTS alerts" 1579 " (id SERIAL PRIMARY KEY," 1580 " uuid text UNIQUE NOT NULL," 1581 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1582 " name text NOT NULL," 1585 " condition integer," 1588 " creation_time integer," 1589 " modification_time integer);");
1591 sql (
"CREATE TABLE IF NOT EXISTS alerts_trash" 1592 " (id SERIAL PRIMARY KEY," 1593 " uuid text UNIQUE NOT NULL," 1594 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1595 " name text NOT NULL," 1598 " condition integer," 1601 " filter_location integer," 1602 " creation_time integer," 1603 " modification_time integer);");
1605 sql (
"CREATE TABLE IF NOT EXISTS alert_condition_data" 1606 " (id SERIAL PRIMARY KEY," 1607 " alert integer REFERENCES alerts (id) ON DELETE RESTRICT," 1611 sql (
"CREATE TABLE IF NOT EXISTS alert_condition_data_trash" 1612 " (id SERIAL PRIMARY KEY," 1613 " alert integer REFERENCES alerts_trash (id) ON DELETE RESTRICT," 1617 sql (
"CREATE TABLE IF NOT EXISTS alert_event_data" 1618 " (id SERIAL PRIMARY KEY," 1619 " alert integer REFERENCES alerts (id) ON DELETE RESTRICT," 1623 sql (
"CREATE TABLE IF NOT EXISTS alert_event_data_trash" 1624 " (id SERIAL PRIMARY KEY," 1625 " alert integer REFERENCES alerts_trash (id) ON DELETE RESTRICT," 1629 sql (
"CREATE TABLE IF NOT EXISTS alert_method_data" 1630 " (id SERIAL PRIMARY KEY," 1631 " alert integer REFERENCES alerts (id) ON DELETE RESTRICT," 1635 sql (
"CREATE TABLE IF NOT EXISTS alert_method_data_trash" 1636 " (id SERIAL PRIMARY KEY," 1637 " alert integer REFERENCES alerts_trash (id) ON DELETE RESTRICT," 1641 sql (
"CREATE TABLE IF NOT EXISTS credentials" 1642 " (id SERIAL PRIMARY KEY," 1643 " uuid text UNIQUE NOT NULL," 1644 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1645 " name text NOT NULL," 1647 " creation_time integer," 1648 " modification_time integer," 1650 " allow_insecure integer);");
1652 sql (
"CREATE TABLE IF NOT EXISTS credentials_trash" 1653 " (id SERIAL PRIMARY KEY," 1654 " uuid text UNIQUE NOT NULL," 1655 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1656 " name text NOT NULL," 1658 " creation_time integer," 1659 " modification_time integer," 1661 " allow_insecure integer);");
1663 sql (
"CREATE TABLE IF NOT EXISTS credentials_data" 1664 " (id SERIAL PRIMARY KEY," 1665 " credential INTEGER REFERENCES credentials (id) ON DELETE RESTRICT," 1669 sql (
"CREATE TABLE IF NOT EXISTS credentials_trash_data" 1670 " (id SERIAL PRIMARY KEY," 1671 " credential INTEGER REFERENCES credentials_trash (id) ON DELETE RESTRICT," 1675 sql (
"CREATE TABLE IF NOT EXISTS filters" 1676 " (id SERIAL PRIMARY KEY," 1677 " uuid text UNIQUE NOT NULL," 1678 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1679 " name text NOT NULL," 1683 " creation_time integer," 1684 " modification_time integer);");
1686 sql (
"CREATE TABLE IF NOT EXISTS filters_trash" 1687 " (id SERIAL PRIMARY KEY," 1688 " uuid text UNIQUE NOT NULL," 1689 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1690 " name text NOT NULL," 1694 " creation_time integer," 1695 " modification_time integer);");
1697 sql (
"CREATE TABLE IF NOT EXISTS groups" 1698 " (id SERIAL PRIMARY KEY," 1699 " uuid text UNIQUE NOT NULL," 1700 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1701 " name text NOT NULL," 1703 " creation_time integer," 1704 " modification_time integer);");
1706 sql (
"CREATE TABLE IF NOT EXISTS groups_trash" 1707 " (id SERIAL PRIMARY KEY," 1708 " uuid text UNIQUE NOT NULL," 1709 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1710 " name text NOT NULL," 1712 " creation_time integer," 1713 " modification_time integer);");
1715 sql (
"CREATE TABLE IF NOT EXISTS group_users" 1716 " (id SERIAL PRIMARY KEY," 1717 " \"group\" integer REFERENCES groups (id) ON DELETE RESTRICT," 1718 " \"user\" integer REFERENCES users (id) ON DELETE RESTRICT);");
1720 sql (
"CREATE TABLE IF NOT EXISTS group_users_trash" 1721 " (id SERIAL PRIMARY KEY," 1722 " \"group\" integer REFERENCES groups_trash (id) ON DELETE RESTRICT," 1723 " \"user\" integer REFERENCES users (id) ON DELETE RESTRICT);");
1725 sql (
"CREATE TABLE IF NOT EXISTS hosts" 1726 " (id SERIAL PRIMARY KEY," 1727 " uuid text UNIQUE NOT NULL," 1728 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1729 " name text NOT NULL," 1731 " creation_time integer," 1732 " modification_time integer);");
1734 sql (
"CREATE TABLE IF NOT EXISTS host_identifiers" 1735 " (id SERIAL PRIMARY KEY," 1736 " uuid text UNIQUE NOT NULL," 1737 " host integer REFERENCES hosts (id) ON DELETE RESTRICT," 1738 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1739 " name text NOT NULL," 1741 " value text NOT NULL," 1742 " source_type text NOT NULL," 1743 " source_id text NOT NULL," 1744 " source_data text NOT NULL," 1745 " creation_time integer," 1746 " modification_time integer);");
1748 sql (
"CREATE TABLE IF NOT EXISTS oss" 1749 " (id SERIAL PRIMARY KEY," 1750 " uuid text UNIQUE NOT NULL," 1751 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1752 " name text NOT NULL," 1754 " creation_time integer," 1755 " modification_time integer);");
1757 sql (
"CREATE TABLE IF NOT EXISTS host_oss" 1758 " (id SERIAL PRIMARY KEY," 1759 " uuid text UNIQUE NOT NULL," 1760 " host integer REFERENCES hosts (id) ON DELETE RESTRICT," 1761 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1762 " name text NOT NULL," 1764 " os integer REFERENCES oss (id) ON DELETE RESTRICT," 1765 " source_type text NOT NULL," 1766 " source_id text NOT NULL," 1767 " source_data text NOT NULL," 1768 " creation_time integer," 1769 " modification_time integer);");
1771 sql (
"CREATE TABLE IF NOT EXISTS host_max_severities" 1772 " (id SERIAL PRIMARY KEY," 1773 " host integer REFERENCES hosts (id) ON DELETE RESTRICT," 1775 " source_type text NOT NULL," 1776 " source_id text NOT NULL," 1777 " creation_time integer);");
1779 sql (
"CREATE TABLE IF NOT EXISTS host_details" 1780 " (id SERIAL PRIMARY KEY," 1781 " host integer REFERENCES hosts (id) ON DELETE RESTRICT," 1783 " source_type text NOT NULL," 1784 " source_id text NOT NULL," 1786 " detail_source_type text," 1787 " detail_source_name text," 1788 " detail_source_description text," 1792 sql (
"CREATE TABLE IF NOT EXISTS roles" 1793 " (id SERIAL PRIMARY KEY," 1794 " uuid text UNIQUE NOT NULL," 1795 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1796 " name text NOT NULL," 1798 " creation_time integer," 1799 " modification_time integer);");
1801 sql (
"CREATE TABLE IF NOT EXISTS roles_trash" 1802 " (id SERIAL PRIMARY KEY," 1803 " uuid text UNIQUE NOT NULL," 1804 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1805 " name text NOT NULL," 1807 " creation_time integer," 1808 " modification_time integer);");
1810 sql (
"CREATE TABLE IF NOT EXISTS role_users" 1811 " (id SERIAL PRIMARY KEY," 1812 " role integer REFERENCES roles (id) ON DELETE RESTRICT," 1813 " \"user\" integer REFERENCES users (id) ON DELETE RESTRICT);");
1815 sql (
"CREATE TABLE IF NOT EXISTS role_users_trash" 1816 " (id SERIAL PRIMARY KEY," 1817 " role integer REFERENCES roles_trash (id) ON DELETE RESTRICT," 1818 " \"user\" integer REFERENCES users (id) ON DELETE RESTRICT);");
1820 sql (
"CREATE TABLE IF NOT EXISTS nvt_selectors" 1821 " (id SERIAL PRIMARY KEY," 1825 " family_or_nvt text," 1828 sql (
"CREATE TABLE IF NOT EXISTS port_lists" 1829 " (id SERIAL PRIMARY KEY," 1830 " uuid text UNIQUE NOT NULL," 1831 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1832 " name text NOT NULL," 1834 " creation_time integer," 1835 " modification_time integer);");
1837 sql (
"CREATE TABLE IF NOT EXISTS port_lists_trash" 1838 " (id SERIAL PRIMARY KEY," 1839 " uuid text UNIQUE NOT NULL," 1840 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1841 " name text NOT NULL," 1843 " creation_time integer," 1844 " modification_time integer);");
1846 sql (
"CREATE TABLE IF NOT EXISTS port_ranges" 1847 " (id SERIAL PRIMARY KEY," 1848 " uuid text UNIQUE NOT NULL," 1849 " port_list integer REFERENCES port_lists (id) ON DELETE RESTRICT," 1854 " exclude integer);");
1856 sql (
"CREATE TABLE IF NOT EXISTS port_ranges_trash" 1857 " (id SERIAL PRIMARY KEY," 1858 " uuid text UNIQUE NOT NULL," 1859 " port_list integer REFERENCES port_lists_trash (id) ON DELETE RESTRICT," 1864 " exclude integer);");
1866 sql (
"CREATE TABLE IF NOT EXISTS port_names" 1867 " (id SERIAL PRIMARY KEY," 1871 " UNIQUE (number, protocol));");
1873 sql (
"CREATE TABLE IF NOT EXISTS targets" 1874 " (id SERIAL PRIMARY KEY," 1875 " uuid text UNIQUE NOT NULL," 1876 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1877 " name text NOT NULL," 1879 " exclude_hosts text," 1880 " reverse_lookup_only integer," 1881 " reverse_lookup_unify integer," 1883 " port_list integer REFERENCES port_lists (id) ON DELETE RESTRICT," 1884 " alive_test integer," 1885 " creation_time integer," 1886 " modification_time integer);");
1888 sql (
"CREATE TABLE IF NOT EXISTS targets_trash" 1889 " (id SERIAL PRIMARY KEY," 1890 " uuid text UNIQUE NOT NULL," 1891 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1892 " name text NOT NULL," 1894 " exclude_hosts text," 1895 " reverse_lookup_only integer," 1896 " reverse_lookup_unify integer," 1898 " port_list integer," 1899 " port_list_location integer," 1900 " alive_test integer," 1901 " creation_time integer," 1902 " modification_time integer);");
1904 sql (
"CREATE TABLE IF NOT EXISTS targets_login_data" 1905 " (id SERIAL PRIMARY KEY," 1906 " target INTEGER REFERENCES targets (id) ON DELETE RESTRICT," 1908 " credential INTEGER REFERENCES credentials (id) ON DELETE RESTRICT," 1911 sql (
"CREATE TABLE IF NOT EXISTS targets_trash_login_data" 1912 " (id SERIAL PRIMARY KEY," 1913 " target INTEGER REFERENCES targets_trash (id) ON DELETE RESTRICT," 1915 " credential INTEGER," 1917 " credential_location INTEGER);");
1919 sql (
"CREATE TABLE IF NOT EXISTS scanners" 1920 " (id SERIAL PRIMARY KEY," 1921 " uuid text UNIQUE NOT NULL," 1922 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1929 " credential integer REFERENCES credentials (id) ON DELETE RESTRICT," 1930 " creation_time integer," 1931 " modification_time integer);");
1933 sql (
"CREATE TABLE IF NOT EXISTS configs" 1934 " (id SERIAL PRIMARY KEY," 1935 " uuid text UNIQUE NOT NULL," 1936 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1937 " name text NOT NULL," 1938 " nvt_selector text," 1940 " family_count integer," 1941 " nvt_count integer," 1942 " families_growing integer," 1943 " nvts_growing integer," 1945 " scanner integer REFERENCES scanners (id) ON DELETE RESTRICT," 1946 " creation_time integer," 1947 " modification_time integer);");
1949 sql (
"CREATE TABLE IF NOT EXISTS configs_trash" 1950 " (id SERIAL PRIMARY KEY," 1951 " uuid text UNIQUE NOT NULL," 1952 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1953 " name text NOT NULL," 1954 " nvt_selector text," 1956 " family_count integer," 1957 " nvt_count integer," 1958 " families_growing integer," 1959 " nvts_growing integer," 1961 " scanner integer REFERENCES scanners (id) ON DELETE RESTRICT," 1962 " creation_time integer," 1963 " modification_time integer);");
1965 sql (
"CREATE TABLE IF NOT EXISTS config_preferences" 1966 " (id SERIAL PRIMARY KEY," 1967 " config integer REFERENCES configs (id) ON DELETE RESTRICT," 1971 " default_value text," 1974 sql (
"CREATE TABLE IF NOT EXISTS config_preferences_trash" 1975 " (id SERIAL PRIMARY KEY," 1976 " config integer REFERENCES configs_trash (id) ON DELETE RESTRICT," 1980 " default_value text," 1983 sql (
"CREATE TABLE IF NOT EXISTS schedules" 1984 " (id SERIAL PRIMARY KEY," 1985 " uuid text UNIQUE NOT NULL," 1986 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 1987 " name text NOT NULL," 1989 " first_time integer," 1991 " period_months integer," 1992 " duration integer," 1994 " initial_offset integer," 1995 " creation_time integer," 1996 " modification_time integer);");
1998 sql (
"CREATE TABLE IF NOT EXISTS schedules_trash" 1999 " (id SERIAL PRIMARY KEY," 2000 " uuid text UNIQUE NOT NULL," 2001 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2002 " name text NOT NULL," 2004 " first_time integer," 2006 " period_months integer," 2007 " duration integer," 2009 " initial_offset integer," 2010 " creation_time integer," 2011 " modification_time integer);");
2013 sql (
"CREATE TABLE IF NOT EXISTS scanners_trash" 2014 " (id SERIAL PRIMARY KEY," 2015 " uuid text UNIQUE NOT NULL," 2016 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2023 " credential integer," 2024 " credential_location integer," 2025 " creation_time integer," 2026 " modification_time integer);");
2028 sql (
"CREATE TABLE IF NOT EXISTS tasks" 2029 " (id SERIAL PRIMARY KEY," 2030 " uuid text UNIQUE NOT NULL," 2031 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2035 " run_status integer," 2036 " start_time integer," 2037 " end_time integer," 2040 " schedule integer," 2041 " schedule_next_time integer," 2042 " schedule_periods integer," 2044 " config_location integer," 2045 " target_location integer," 2046 " schedule_location integer," 2047 " scanner_location integer," 2048 " upload_result_count integer," 2049 " hosts_ordering text," 2050 " alterable integer," 2051 " creation_time integer," 2052 " modification_time integer);");
2054 sql (
"CREATE TABLE IF NOT EXISTS task_files" 2055 " (id SERIAL PRIMARY KEY," 2056 " task integer REFERENCES tasks (id) ON DELETE RESTRICT," 2060 sql (
"CREATE TABLE IF NOT EXISTS task_alerts" 2061 " (id SERIAL PRIMARY KEY," 2062 " task integer REFERENCES tasks (id) ON DELETE RESTRICT," 2064 " alert_location integer);");
2066 sql (
"CREATE TABLE IF NOT EXISTS task_preferences" 2067 " (id SERIAL PRIMARY KEY," 2068 " task integer REFERENCES tasks (id) ON DELETE RESTRICT," 2072 sql (
"CREATE TABLE IF NOT EXISTS reports" 2073 " (id SERIAL PRIMARY KEY," 2074 " uuid text UNIQUE NOT NULL," 2075 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2077 " task integer REFERENCES tasks (id) ON DELETE RESTRICT," 2079 " start_time integer," 2080 " end_time integer," 2083 " scan_run_status integer," 2084 " slave_progress integer," 2085 " slave_task_uuid text," 2089 " slave_port integer," 2090 " source_iface text," 2091 " flags integer);");
2093 sql (
"CREATE TABLE IF NOT EXISTS report_counts" 2094 " (id SERIAL PRIMARY KEY," 2095 " report integer REFERENCES reports (id) ON DELETE RESTRICT," 2096 " \"user\" integer REFERENCES users (id) ON DELETE RESTRICT," 2097 " severity decimal," 2099 " override integer," 2100 " end_time integer," 2101 " min_qod integer);");
2103 sql (
"CREATE TABLE IF NOT EXISTS resources_predefined" 2104 " (id SERIAL PRIMARY KEY," 2105 " resource_type text," 2106 " resource integer);");
2108 sql (
"CREATE TABLE IF NOT EXISTS results" 2109 " (id SERIAL PRIMARY KEY," 2110 " uuid text UNIQUE NOT NULL," 2111 " task integer REFERENCES tasks (id) ON DELETE RESTRICT," 2116 " description text," 2117 " report integer REFERENCES reports (id) ON DELETE RESTRICT," 2118 " nvt_version text," 2122 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2125 sql (
"CREATE TABLE IF NOT EXISTS report_formats" 2126 " (id SERIAL PRIMARY KEY," 2127 " uuid text UNIQUE NOT NULL," 2128 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2129 " name text NOT NULL," 2131 " content_type text," 2133 " description text," 2136 " trust_time integer," 2138 " creation_time integer," 2139 " modification_time integer);");
2141 sql (
"CREATE TABLE IF NOT EXISTS report_formats_trash" 2142 " (id SERIAL PRIMARY KEY," 2143 " uuid text UNIQUE NOT NULL," 2144 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2145 " name text NOT NULL," 2147 " content_type text," 2149 " description text," 2152 " trust_time integer," 2154 " original_uuid text," 2155 " creation_time integer," 2156 " modification_time integer);");
2158 sql (
"CREATE TABLE IF NOT EXISTS report_format_params" 2159 " (id SERIAL PRIMARY KEY," 2160 " report_format integer REFERENCES report_formats (id) ON DELETE RESTRICT," 2167 " fallback text);");
2169 sql (
"CREATE TABLE IF NOT EXISTS report_format_params_trash" 2170 " (id SERIAL PRIMARY KEY," 2171 " report_format integer REFERENCES report_formats_trash (id) ON DELETE RESTRICT," 2178 " fallback text);");
2180 sql (
"CREATE TABLE IF NOT EXISTS report_format_param_options" 2181 " (id SERIAL PRIMARY KEY," 2182 " report_format_param integer REFERENCES report_format_params (id) ON DELETE RESTRICT," 2185 sql (
"CREATE TABLE IF NOT EXISTS report_format_param_options_trash" 2186 " (id SERIAL PRIMARY KEY," 2187 " report_format_param integer REFERENCES report_format_params_trash (id) ON DELETE RESTRICT," 2190 sql (
"CREATE TABLE IF NOT EXISTS report_hosts" 2191 " (id SERIAL PRIMARY KEY," 2192 " report integer REFERENCES reports (id) ON DELETE RESTRICT," 2194 " start_time integer," 2195 " end_time integer," 2196 " current_port integer," 2197 " max_port integer);");
2199 sql (
"CREATE TABLE IF NOT EXISTS report_host_details" 2200 " (id SERIAL PRIMARY KEY," 2201 " report_host integer REFERENCES report_hosts (id) ON DELETE RESTRICT," 2202 " source_type text," 2203 " source_name text," 2204 " source_description text," 2208 sql (
"CREATE TABLE IF NOT EXISTS nvt_preferences" 2209 " (id SERIAL PRIMARY KEY," 2210 " name text UNIQUE NOT NULL," 2213 sql (
"CREATE TABLE IF NOT EXISTS nvts" 2214 " (id SERIAL PRIMARY KEY," 2215 " uuid text UNIQUE NOT NULL," 2216 " oid text UNIQUE NOT NULL," 2228 " creation_time integer," 2229 " modification_time integer," 2230 " solution_type text," 2232 " qod_type text);");
2234 sql (
"CREATE TABLE IF NOT EXISTS nvt_cves" 2235 " (id SERIAL PRIMARY KEY," 2236 " nvt integer REFERENCES nvts (id) ON DELETE RESTRICT," 2238 " cve_name text);");
2240 sql (
"CREATE TABLE IF NOT EXISTS notes" 2241 " (id SERIAL PRIMARY KEY," 2242 " uuid text UNIQUE NOT NULL," 2243 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2244 " nvt text NOT NULL," 2245 " creation_time integer," 2246 " modification_time integer," 2250 " severity double precision," 2253 " end_time integer);");
2255 sql (
"CREATE TABLE IF NOT EXISTS notes_trash" 2256 " (id SERIAL PRIMARY KEY," 2257 " uuid text UNIQUE NOT NULL," 2258 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2259 " nvt text NOT NULL," 2260 " creation_time integer," 2261 " modification_time integer," 2265 " severity double precision," 2268 " end_time integer);");
2270 sql (
"CREATE TABLE IF NOT EXISTS overrides" 2271 " (id SERIAL PRIMARY KEY," 2272 " uuid text UNIQUE NOT NULL," 2273 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2274 " nvt text NOT NULL," 2275 " creation_time integer," 2276 " modification_time integer," 2279 " new_severity double precision," 2281 " severity double precision," 2284 " end_time integer);");
2286 sql (
"CREATE TABLE IF NOT EXISTS overrides_trash" 2287 " (id SERIAL PRIMARY KEY," 2288 " uuid text UNIQUE NOT NULL," 2289 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2290 " nvt text NOT NULL," 2291 " creation_time integer," 2292 " modification_time integer," 2295 " new_severity double precision," 2297 " severity double precision," 2300 " end_time integer);");
2302 sql (
"CREATE TABLE IF NOT EXISTS permissions" 2303 " (id SERIAL PRIMARY KEY," 2304 " uuid text UNIQUE NOT NULL," 2305 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2306 " name text NOT NULL," 2308 " resource_type text," 2309 " resource integer," 2310 " resource_uuid text," 2311 " resource_location integer," 2312 " subject_type text," 2314 " subject_location integer," 2315 " creation_time integer," 2316 " modification_time integer);");
2318 sql (
"CREATE TABLE IF NOT EXISTS permissions_trash" 2319 " (id SERIAL PRIMARY KEY," 2320 " uuid text UNIQUE NOT NULL," 2321 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2322 " name text NOT NULL," 2324 " resource_type text," 2325 " resource integer," 2326 " resource_uuid text," 2327 " resource_location integer," 2328 " subject_type text," 2330 " subject_location integer," 2331 " creation_time integer," 2332 " modification_time integer);");
2334 sql (
"CREATE TABLE IF NOT EXISTS settings" 2335 " (id SERIAL PRIMARY KEY," 2336 " uuid text NOT NULL," 2337 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2338 " name text NOT NULL," 2342 sql (
"CREATE TABLE IF NOT EXISTS tags" 2343 " (id SERIAL PRIMARY KEY," 2344 " uuid text UNIQUE NOT NULL," 2345 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2346 " name text NOT NULL," 2348 " resource_type text," 2349 " resource integer," 2350 " resource_uuid text," 2351 " resource_location integer," 2354 " creation_time integer," 2355 " modification_time integer);");
2357 sql (
"CREATE TABLE IF NOT EXISTS tags_trash" 2358 " (id SERIAL PRIMARY KEY," 2359 " uuid text UNIQUE NOT NULL," 2360 " owner integer REFERENCES users (id) ON DELETE RESTRICT," 2361 " name text NOT NULL," 2363 " resource_type text," 2364 " resource integer," 2365 " resource_uuid text," 2366 " resource_location integer," 2369 " creation_time integer," 2370 " modification_time integer);");
2380 sql (
"CREATE OR REPLACE VIEW result_overrides AS" 2381 " SELECT users.id AS user," 2382 " results.id as result," 2383 " overrides.id AS override," 2384 " overrides.severity AS ov_old_severity," 2385 " overrides.new_severity AS ov_new_severity" 2386 " FROM users, results, overrides" 2387 " WHERE overrides.nvt = results.nvt" 2388 " AND (overrides.result = 0 OR overrides.result = results.id)" 2390 " AND ((overrides.end_time = 0)" 2391 " OR (overrides.end_time >= m_now ()))" 2392 " AND (overrides.task =" 2393 " (SELECT reports.task FROM reports" 2394 " WHERE results.report = reports.id)" 2395 " OR overrides.task = 0)" 2396 " AND (overrides.result = results.id" 2397 " OR overrides.result = 0)" 2398 " AND (overrides.hosts is NULL" 2399 " OR overrides.hosts = ''" 2400 " OR hosts_contains (overrides.hosts, results.host))" 2401 " AND (overrides.port is NULL" 2402 " OR overrides.port = ''" 2403 " OR overrides.port = results.port)" 2404 " ORDER BY overrides.result DESC, overrides.task DESC," 2405 " overrides.port DESC, overrides.severity ASC," 2406 " overrides.creation_time DESC",
2409 g_free (owned_clause);
2411 sql (
"CREATE OR REPLACE VIEW result_new_severities AS" 2412 " SELECT results.id as result, users.id as user, dynamic, override," 2413 " CASE WHEN dynamic != 0 THEN" 2414 " CASE WHEN override != 0 THEN" 2415 " coalesce ((SELECT ov_new_severity FROM result_overrides" 2416 " WHERE result = results.id" 2417 " AND result_overrides.user = users.id" 2418 " AND severity_matches_ov" 2419 " (current_severity (results.severity," 2423 " current_severity (results.severity, results.nvt))" 2425 " current_severity (results.severity, results.nvt)" 2428 " CASE WHEN override != 0 THEN" 2429 " coalesce ((SELECT ov_new_severity FROM result_overrides" 2430 " WHERE result = results.id" 2431 " AND result_overrides.user = users.id" 2432 " AND severity_matches_ov" 2433 " (results.severity," 2436 " results.severity)" 2440 " END AS new_severity" 2441 " FROM results, users," 2442 " (SELECT 0 AS override UNION SELECT 1 AS override) AS override_opts," 2443 " (SELECT 0 AS dynamic UNION SELECT 1 AS dynamic) AS dynamic_opts;");
2445 sql (
"CREATE OR REPLACE VIEW results_autofp AS" 2446 " SELECT results.id as result, autofp_selection," 2447 " (CASE autofp_selection" 2450 " (((SELECT family FROM nvts WHERE oid = results.nvt)" 2452 " OR results.nvt = '0'" 2454 " (SELECT id FROM nvts" 2455 " WHERE oid = results.nvt" 2458 " OR cve NOT IN (SELECT cve FROM nvts" 2460 " IN (SELECT source_name" 2461 " FROM report_host_details" 2462 " WHERE report_host" 2464 " FROM report_hosts" 2465 " WHERE report = %llu" 2468 " AND name = 'EXIT_CODE'" 2469 " AND value = 'EXIT_NOTVULN')" 2476 " (((SELECT family FROM nvts WHERE oid = results.nvt)" 2478 " OR results.nvt = '0'" 2480 " (SELECT id FROM nvts AS outer_nvts" 2481 " WHERE oid = results.nvt" 2485 " (SELECT cve FROM nvts" 2486 " WHERE oid IN (SELECT source_name" 2487 " FROM report_host_details" 2488 " WHERE report_host" 2490 " FROM report_hosts" 2491 " WHERE report = results.report" 2492 " AND host = results.host)" 2493 " AND name = 'EXIT_CODE'" 2494 " AND value = 'EXIT_NOTVULN')" 2499 " AND common_cve (nvts.cve, outer_nvts.cve)))))" 2503 " ELSE 0 END) AS autofp" 2505 " (SELECT 0 AS autofp_selection" 2506 " UNION SELECT 1 AS autofp_selection" 2507 " UNION SELECT 2 AS autofp_selection) AS autofp_opts;");
2511 sql (
"SELECT create_index ('host_details_by_host'," 2512 " 'host_details', 'host');");
2514 sql (
"SELECT create_index ('host_identifiers_by_host'," 2515 " 'host_identifiers', 'host');");
2516 sql (
"SELECT create_index ('host_identifiers_by_value'," 2517 " 'host_identifiers', 'value');");
2519 sql (
"SELECT create_index ('host_max_severities_by_host'," 2520 " 'host_max_severities', 'host');");
2521 sql (
"SELECT create_index ('host_oss_by_host'," 2522 " 'host_oss', 'host');");
2524 sql (
"SELECT create_index ('nvt_cves_by_oid', 'nvt_cves', 'oid');");
2525 sql (
"SELECT create_index ('nvt_selectors_by_family_or_nvt'," 2527 " 'type, family_or_nvt');");
2528 sql (
"SELECT create_index ('nvt_selectors_by_name'," 2531 sql (
"SELECT create_index ('nvts_by_creation_time'," 2533 " 'creation_time');");
2534 sql (
"SELECT create_index ('nvts_by_family', 'nvts', 'family');");
2535 sql (
"SELECT create_index ('nvts_by_name', 'nvts', 'name');");
2536 sql (
"SELECT create_index ('nvts_by_modification_time'," 2537 " 'nvts', 'modification_time');");
2538 sql (
"SELECT create_index ('nvts_by_cvss_base'," 2539 " 'nvts', 'cvss_base');");
2540 sql (
"SELECT create_index ('nvts_by_solution_type'," 2541 " 'nvts', 'solution_type');");
2543 sql (
"SELECT create_index ('permissions_by_name'," 2544 " 'permissions', 'name');");
2545 sql (
"SELECT create_index ('permissions_by_resource'," 2546 " 'permissions', 'resource');");
2548 sql (
"SELECT create_index ('report_counts_by_report_and_override'," 2549 " 'report_counts', 'report, override');");
2557 sql (
"SELECT create_index" 2558 " ('report_host_details_by_report_host_and_name_and_value'," 2559 " 'report_host_details'," 2560 " 'report_host, name, value');");
2562 sql (
"SELECT create_index" 2563 " ('report_host_details_by_report_host_and_name'," 2564 " 'report_host_details'," 2565 " 'report_host, name');");
2567 sql (
"SELECT create_index" 2568 " ('report_hosts_by_report_and_host'," 2570 " 'report, host');");
2571 sql (
"SELECT create_index ('results_by_host_and_qod', 'results'," 2573 sql (
"SELECT create_index ('results_by_report', 'results', 'report');");
2574 sql (
"SELECT create_index ('results_by_task', 'results', 'task');");
2575 sql (
"SELECT create_index ('results_by_date', 'results', 'date');");
2588 "SELECT table_name, column_name," 2589 " pg_get_serial_sequence (table_name, column_name)" 2590 " FROM information_schema.columns" 2591 " WHERE table_schema = 'public'" 2592 " AND pg_get_serial_sequence (table_name, column_name)" 2595 while (
next (&sequence_tables))
2603 "SELECT last_value + 1 FROM %s;",
2607 "SELECT coalesce (max (%s), 0) + 1 FROM %s;",
2610 if (old_start < new_start)
2611 sql (
"ALTER SEQUENCE %s RESTART WITH %llu;", sequence, new_start);
2627 sql (
"SELECT set_config ('search_path'," 2628 " current_setting ('search_path') || ',scap'," 2632 sql (
"SELECT set_config ('search_path'," 2633 " current_setting ('search_path') || ',cert'," 2645 return !!
sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 2646 " WHERE table_catalog = '%s'" 2647 " AND table_schema = 'cert'" 2648 " AND table_name = 'dfn_cert_advs')" 2661 return !!
sql_int (
"SELECT EXISTS (SELECT * FROM information_schema.tables" 2662 " WHERE table_catalog = '%s'" 2663 " AND table_schema = 'scap'" 2664 " AND table_name = 'cves')" 2682 g_warning (
"%s: database backup not supported for Postgres", __FUNCTION__);
int manage_cert_loaded()
Check whether CERT is available.
#define LOCATION_TRASH
Location of a constituent of a trashcan resource.
int manage_db_empty()
Check whether database is empty.
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
#define LSC_FAMILY_LIST
SQL list of LSC families.
void manage_session_set_timezone(const char *timezone)
Setup session timezone.
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
gchar * acl_where_owned_for_get(const char *type, const char *user_sql)
Generate ownership part of WHERE, for getting a type of resource.
int manage_create_migrate_51_to_52_convert()
Dummy for SQLite3 compatibility.
int manage_create_sql_functions()
Create functions.
#define OVERRIDES_SQL(severity_sql)
void manage_session_init(const char *uuid)
Setup session.
void check_db_sequences()
Ensure sequences for automatic ids are in a consistent state.
int manage_backup_db(const gchar *database)
Backup the database to a file.
void create_tables()
Create all tables.
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
int manage_db_version()
Return the database version of the actual database.
const char * sql_database()
Return name of current database.
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.
#define LOCATION_TABLE
Location of a constituent of a trashcan resource.
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
void manage_attach_databases()
Attach external databases.
int manage_scap_loaded()
Check whether SCAP is available.
long long int resource_t
A resource, like a task or target.