Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round 5 of OTP cleanout #749

Merged
merged 21 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9b71f10
Remove comment about OTP update
mattmundell Sep 11, 2019
9a55224
Change process name of GMP slave tasks
mattmundell Sep 11, 2019
9114397
Correct doc
mattmundell Sep 11, 2019
cec408d
Update comment that referred to otp.c
mattmundell Sep 11, 2019
36f8274
Remove unused SQL function 'tag'
mattmundell Sep 11, 2019
6d24dda
Remove outdated suggestion from comment
mattmundell Sep 11, 2019
5c831cc
Correct comments about ports
mattmundell Sep 11, 2019
0065ea7
Merge branch 'master' into otp-cleanup-5
mattmundell Sep 12, 2019
6843fce
Merge branch 'master' into otp-cleanup-5
mattmundell Sep 12, 2019
9c9f995
Rename parse_otp_time to parse_utc_ctime
mattmundell Sep 12, 2019
cf5e639
Rename set_task_start_time_otp to set_task_start_time_ctime
mattmundell Sep 12, 2019
92885d9
Rename set_scan_host_start_time_otp to set_scan_host_start_time_ctime
mattmundell Sep 12, 2019
226def1
Rename set_scan_host_end_time_otp to set_scan_host_end_time_ctime
mattmundell Sep 12, 2019
c8f67ac
Rename set_scan_end_time_otp to set_scan_end_time_ctime
mattmundell Sep 12, 2019
5586b9d
Update arg docs to match rename
mattmundell Sep 12, 2019
9027c58
Update doc references to OTP
mattmundell Sep 12, 2019
b161a43
Rename 'preference' iterator using 'config_preference'
mattmundell Sep 12, 2019
be4d6b1
Rename 'otp_preference' iterator using 'preference'
mattmundell Sep 12, 2019
0630d4c
Remove serve_gmp timeout that is no longer used
mattmundell Sep 12, 2019
1f574fb
Remove unused OTP headers
mattmundell Sep 12, 2019
6ea1e0f
Make delete_task_lock static
mattmundell Sep 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13025,19 +13025,19 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
g_free (s_name);
SEND_TO_CLIENT_OR_FAIL ("<preferences>");

init_preference_iterator (&prefs, config);
init_config_preference_iterator (&prefs, config);
while (next (&prefs))
{
const char *name, *hr_name, *value, *type, *def;
char *ovaldi_files = NULL;

hr_name = preference_iterator_hr_name (&prefs);
name = preference_iterator_name (&prefs);
value = preference_iterator_value (&prefs);
def = preference_iterator_default (&prefs);
hr_name = config_preference_iterator_hr_name (&prefs);
name = config_preference_iterator_name (&prefs);
value = config_preference_iterator_value (&prefs);
def = config_preference_iterator_default (&prefs);
if (!strcmp (name, "definitions_file"))
ovaldi_files = get_ovaldi_files ();
type = preference_iterator_type (&prefs);
type = config_preference_iterator_type (&prefs);
SENDF_TO_CLIENT_OR_FAIL
("<preference>"
"<nvt oid=\"\"><name/></nvt>"
Expand Down
11 changes: 1 addition & 10 deletions src/gmpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,16 +536,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
}

if (!ret)
{
/* Timeout periodically. This was needed in the past so that OTP
* scan handling processes could check if the client had stopped
* the task. */
struct timeval timeout;

timeout.tv_usec = 0;
timeout.tv_sec = 1;
ret = select (nfds, &readfds, &writefds, NULL, &timeout);
}
ret = select (nfds, &readfds, &writefds, NULL, NULL);
if ((ret < 0 && errno == EINTR) || ret == 0)
continue;
if (ret < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@
/**
* @brief Scanner port.
*
* Used if /etc/services "otp" and --port missing.
* Used if --scanner-port is missing.
*/
#define OPENVASSD_PORT 9391

/**
* @brief Manager port.
*
* Used if /etc/services "gmp" and --sport are missing.
* Used if /etc/services "otp" and --port are missing.
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
*/
#define GVMD_PORT 9390

Expand Down
44 changes: 22 additions & 22 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3346,23 +3346,23 @@ task_scanner_options (task_t task, target_t target)
iterator_t prefs;

config = task_config (task);
init_preference_iterator (&prefs, config);
init_config_preference_iterator (&prefs, config);
table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
while (next (&prefs))
{
char *name, *value = NULL;
const char *type;

name = g_strdup (preference_iterator_name (&prefs));
type = preference_iterator_type (&prefs);
name = g_strdup (config_preference_iterator_name (&prefs));
type = config_preference_iterator_type (&prefs);

if (g_str_has_prefix (type, "credential_"))
{
credential_t credential = 0;
iterator_t iter;
const char *uuid = preference_iterator_value (&prefs);
const char *uuid = config_preference_iterator_value (&prefs);

if (!strcmp (preference_iterator_value (&prefs), "0"))
if (!strcmp (config_preference_iterator_value (&prefs), "0"))
credential = target_ssh_credential (target);
else if (find_resource ("credential", uuid, &credential))
{
Expand Down Expand Up @@ -3409,16 +3409,16 @@ task_scanner_options (task_t task, target_t target)
{
char *fname;

if (!preference_iterator_value (&prefs))
if (!config_preference_iterator_value (&prefs))
continue;
fname = g_strdup_printf ("%s/%s", GVM_SCAP_DATA_DIR "/",
preference_iterator_value (&prefs));
config_preference_iterator_value (&prefs));
value = gvm_file_as_base64 (fname);
if (!value)
continue;
}
else
value = g_strdup (preference_iterator_value (&prefs));
value = g_strdup (config_preference_iterator_value (&prefs));
g_hash_table_insert (table, name, value);
}
cleanup_iterator (&prefs);
Expand Down Expand Up @@ -4003,12 +4003,12 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id,
/* Setup general scanner preferences */
scanner_options
= g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
init_otp_pref_iterator (&scanner_prefs_iter, config, "SERVER_PREFS");
init_preference_iterator (&scanner_prefs_iter, config, "SERVER_PREFS");
while (next (&scanner_prefs_iter))
{
const char *name, *value;
name = otp_pref_iterator_name (&scanner_prefs_iter);
value = otp_pref_iterator_value (&scanner_prefs_iter);
name = preference_iterator_name (&scanner_prefs_iter);
value = preference_iterator_value (&scanner_prefs_iter);
if (name && value)
{
const char *osp_value;
Expand Down Expand Up @@ -4056,15 +4056,15 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id,
cleanup_iterator (&families);

/* Setup VT preferences */
init_otp_pref_iterator (&prefs, config, "PLUGINS_PREFS");
init_preference_iterator (&prefs, config, "PLUGINS_PREFS");
while (next (&prefs))
{
const char *full_name, *value;
osp_vt_single_t *osp_vt;
gchar **split_name;

full_name = otp_pref_iterator_name (&prefs);
value = otp_pref_iterator_value (&prefs);
full_name = preference_iterator_name (&prefs);
value = preference_iterator_value (&prefs);
split_name = g_strsplit (full_name, ":", 4);

osp_vt = NULL;
Expand Down Expand Up @@ -4711,7 +4711,7 @@ run_task_prepare_report (task_t task, char **report_id, int from,
}

/**
* @brief Start a slave/GMP task.
* @brief Start a slave GMP task.
*
* A process is forked to run the task, but the forked process never returns.
*
Expand All @@ -4729,10 +4729,10 @@ run_task_prepare_report (task_t task, char **report_id, int from,
* -9 failed to fork.
*/
static int
run_slave_or_gmp_task (task_t task, int from, char **report_id,
gvm_connection_t *connection,
const gchar *slave_id,
const gchar *slave_name)
run_gmp_slave_task (task_t task, int from, char **report_id,
gvm_connection_t *connection,
const gchar *slave_id,
const gchar *slave_name)
{
int ret, pid;
task_status_t run_status;
Expand Down Expand Up @@ -4837,7 +4837,7 @@ run_slave_or_gmp_task (task_t task, int from, char **report_id,

uuid = report_uuid (global_current_report);
snprintf (title, sizeof (title),
"gvmd: OTP: Handling slave scan %s",
"gvmd: GMP: Handling slave scan %s",
uuid);
free (uuid);
proctitle_set (title);
Expand Down Expand Up @@ -4940,8 +4940,8 @@ run_gmp_task (task_t task, scanner_t scanner, int from, char **report_id)

connection.tls = 1;

ret = run_slave_or_gmp_task (task, from, report_id, &connection, scanner_id,
name);
ret = run_gmp_slave_task (task, from, report_id, &connection, scanner_id,
name);

free (connection.host_string);
free (connection.username);
Expand Down
53 changes: 11 additions & 42 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,33 +240,6 @@ manage_transaction_stop (gboolean);

/* Task structures. */

extern short scanner_active;

/** @todo Should be in otp.c/h. */
/**
* @brief A port.
*/
typedef struct
{
unsigned int number; ///< Port number.
port_protocol_t protocol; ///< Port protocol (TCP, UDP, ...).
char* string; ///< Original string describing port.
} port_t;

/** @todo Should be in otp.c/h. */
/**
* @brief The record of a message.
*/
typedef struct
{
char* host; ///< Host message describes.
char* hostname; ///< Hostname message describes.
port_t port; ///< The port.
char* description; ///< Description of the message.
char* oid; ///< NVT identifier.
} message_t;


/**
* @brief Task statuses, also used as scan/report statuses.
*
Expand Down Expand Up @@ -907,7 +880,7 @@ void
set_task_start_time_epoch (task_t, int);

void
set_task_start_time_otp (task_t, char*);
set_task_start_time_ctime (task_t, char*);

void
set_task_end_time (task_t task, char* time);
Expand Down Expand Up @@ -1021,10 +994,6 @@ request_delete_task (task_t*);
int
delete_task (task_t, int);

/* For otp.c. */
int
delete_task_lock (task_t, int);

void
append_to_task_comment (task_t, const char*, int);

Expand Down Expand Up @@ -1369,7 +1338,7 @@ char*
scan_end_time_uuid (const char *);

void
set_scan_start_time_otp (report_t, const char*);
set_scan_start_time_ctime (report_t, const char*);

void
set_scan_start_time_epoch (report_t, time_t);
Expand All @@ -1378,13 +1347,13 @@ void
set_scan_end_time (report_t, const char*);

void
set_scan_end_time_otp (report_t, const char*);
set_scan_end_time_ctime (report_t, const char*);

void
set_scan_end_time_epoch (report_t, time_t);

void
set_scan_host_start_time_otp (report_t, const char*, const char*);
set_scan_host_start_time_ctime (report_t, const char*, const char*);

int
scan_host_end_time (report_t, const char*);
Expand All @@ -1393,7 +1362,7 @@ void
set_scan_host_end_time (report_t, const char*, const char*);

void
set_scan_host_end_time_otp (report_t, const char*, const char*);
set_scan_host_end_time_ctime (report_t, const char*, const char*);

int
report_timestamp (const char*, gchar**);
Expand Down Expand Up @@ -1922,22 +1891,22 @@ manage_set_config_preference (const gchar *, const char*, const char*,
const char*);

void
init_preference_iterator (iterator_t *, config_t);
init_config_preference_iterator (iterator_t *, config_t);

const char*
preference_iterator_name (iterator_t *);
config_preference_iterator_name (iterator_t *);

const char*
preference_iterator_value (iterator_t *);
config_preference_iterator_value (iterator_t *);

const char*
preference_iterator_type (iterator_t *);
config_preference_iterator_type (iterator_t *);

const char*
preference_iterator_default (iterator_t *);
config_preference_iterator_default (iterator_t *);

const char*
preference_iterator_hr_name (iterator_t *);
config_preference_iterator_hr_name (iterator_t *);

int
manage_set_config (const gchar *, const char*, const char *, const char *);
Expand Down
7 changes: 0 additions & 7 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,13 +1311,6 @@ manage_create_sql_functions ()
" SELECT uuid_generate_v4 ()::text AS result;"
"$$ LANGUAGE SQL;");

sql ("CREATE OR REPLACE FUNCTION tag (text, text) RETURNS text AS $$"
/* Extract a tag from an OTP tag list. */
" SELECT split_part (unnest, '=', 2)"
" FROM unnest (string_to_array ($1, '|'))"
" WHERE split_part (unnest, '=', 1) = $2;"
"$$ LANGUAGE SQL;");

if (sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables"
" WHERE table_catalog = '%s'"
" AND table_schema = 'public'"
Expand Down
Loading