diff --git a/src/master/archivist/archivist.pl b/src/master/archivist/archivist.pl index 2cda66f25d6c4d2ac0348d6b431ab96e17f94110..13932f1b828450cbabbe9475dcf5cfa4330588d1 100755 --- a/src/master/archivist/archivist.pl +++ b/src/master/archivist/archivist.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl use common::sense; use DBI; +use DBD::Pg qw(:pg_types); # Import the DBD::Pg::PG_BYTEA constant (and other similar ones) use Config::IniFiles; use List::Util qw(sum); use Date::Format; @@ -473,9 +474,18 @@ if (fork == 0) { my $get_commands = $source->prepare('SELECT ssh_commands.id, start_time, end_time, login, password, remote, ts, success, command FROM ssh_commands JOIN ssh_sessions ON ssh_commands.session_id = ssh_sessions.id WHERE NOT archived'); my $mark_command = $source->prepare('UPDATE ssh_commands SET archived = TRUE WHERE id = ?'); my $store_command = $destination->prepare('INSERT INTO ssh_commands (session, timestamp, success, command) VALUES (?, ?, ?, ?)'); + # Make sure the params are considered the correct type. + # bind_param does two things here: + # * Sets the value of the parameter to NULL (which we'll override by calling execute with a new value). + # * Sets the data type for the column (which stays across the future calls to bind_param or execute). + $store_command->bind_param(4, undef, { pg_type => DBD::Pg::PG_BYTEA }); my $get_session = $destination->prepare('SELECT id, end_time FROM ssh_sessions WHERE start_time = ? AND login = ? AND password = ?'); + $get_session->bind_param(2, undef, { pg_type => DBD::Pg::PG_BYTEA }); + $get_session->bind_param(3, undef, { pg_type => DBD::Pg::PG_BYTEA }); my $update_session = $destination->prepare('UPDATE ssh_sessions SET end_time = ? WHERE id = ?'); my $store_session = $destination->prepare('INSERT INTO ssh_sessions (start_time, end_time, login, password, remote) VALUES (?, ?, ?, ?, ?) RETURNING id'); + $store_session->bind_param(3, undef, { pg_type => DBD::Pg::PG_BYTEA }); + $store_session->bind_param(4, undef, { pg_type => DBD::Pg::PG_BYTEA }); $get_commands->execute; my $count_commands = 0; my $count_sessions = 0; @@ -521,6 +531,12 @@ if (fork == 0) { my $get_passwords = $source->prepare("SELECT timestamp, server, remote, name, password, remote_port FROM fake_logs WHERE name IS NOT NULL AND password IS NOT NULL AND event = 'login' AND timestamp >= ?"); $get_passwords->execute($max_date); my $put_password = $destination->prepare("INSERT INTO fake_passwords (timestamp, server, remote, name, password, remote_port) VALUES (?, ?, ?, ?, ?, ?)"); + # Make sure the params are considered the correct type. + # bind_param does two things here: + # * Sets the value of the parameter to NULL (which we'll override by calling execute with a new value). + # * Sets the data type for the column (which stays across the future calls to bind_param or execute). + $put_password->bind_param(4, undef, { pg_type => DBD::Pg::PG_BYTEA }); + $put_password->bind_param(5, undef, { pg_type => DBD::Pg::PG_BYTEA }); my $passwords = -1; $put_password->execute_for_fetch(sub { $passwords ++; diff --git a/src/master/archivist/initdb b/src/master/archivist/initdb index bb0653ff694a7bbc5c65635bfcaec4308d4fcdef..aec5a3171472bbef6dbc275a1de74491b81af10e 100755 --- a/src/master/archivist/initdb +++ b/src/master/archivist/initdb @@ -342,8 +342,8 @@ CREATE TABLE fake_passwords ( server fake_server NOT NULL, remote INET NOT NULL, remote_port INT, - name TEXT NOT NULL, - password TEXT NOT NULL + name BYTEA NOT NULL, + password BYTEA NOT NULL ); CREATE TABLE fake_server_activity ( date DATE NOT NULL, @@ -361,8 +361,8 @@ CREATE TABLE ssh_sessions ( id INT NOT NULL PRIMARY KEY, start_time TIMESTAMP WITH TIME ZONE NOT NULL, end_time TIMESTAMP WITH TIME ZONE, - login TEXT NOT NULL, - password TEXT NOT NULL, + login BYTEA NOT NULL, + password BYTEA NOT NULL, remote INET, UNIQUE(start_time, login, password) ); @@ -373,7 +373,7 @@ CREATE TABLE ssh_commands ( session INT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL, success BOOL NOT NULL, - command TEXT NOT NULL, + command BYTEA NOT NULL, FOREIGN KEY (session) REFERENCES ssh_sessions(id) ON DELETE CASCADE );