1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

B #6085: Fix trim of VNC/SPICE password (#2460)

(cherry picked from commit 726a6a8547)
This commit is contained in:
Pavel Czerný 2023-01-26 09:57:28 +01:00 committed by Ruben S. Montero
parent af093bffcc
commit 59ec26c931
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
3 changed files with 27 additions and 13 deletions

View File

@ -141,6 +141,9 @@ public:
HOTPLUG_SAVEAS_STOPPED = 68
};
static const int MAX_VNC_PASSWD_LENGTH = 8;
static const int MAX_SPICE_PASSWD_LENGTH = 60;
/**
* Functions to convert to/from string the VM states
*/

View File

@ -426,15 +426,21 @@ int VirtualMachine::parse_graphics(string& error_str, Template * tmpl)
{
password = one_util::random_password();
if ( graphics->vector_value("TYPE") == "SPICE" )
{
// Spice password must be 60 characters maximum
graphics->replace("PASSWD", password.substr(0, 59));
}
else
{
graphics->replace("PASSWD", password);
}
graphics->replace("PASSWD", password);
}
string type = graphics->vector_value("TYPE");
one_util::tolower(type);
if ( type == "spice" && password.size() > MAX_SPICE_PASSWD_LENGTH )
{
// Spice password must be 60 characters maximum
graphics->replace("PASSWD", password.substr(0, MAX_SPICE_PASSWD_LENGTH));
}
else if ( type == "vnc" && password.size() > MAX_VNC_PASSWD_LENGTH )
{
// Vnc password must be 8 characters maximum
graphics->replace("PASSWD", password.substr(0, MAX_VNC_PASSWD_LENGTH));
}
return 0;

View File

@ -1706,21 +1706,26 @@ int LibVirtDriver::deployment_description_kvm(
port = graphics->vector_value("PORT");
one_util::tolower(type);
if ( random_passwrd && passwd.empty())
{
passwd = one_util::random_password();
if ( graphics->vector_value("TYPE") == "SPICE" )
if ( type == "spice" )
{
// Spice password must be 60 characters maximum
passwd = passwd.substr(0, 59);
passwd = passwd.substr(0, VirtualMachine::MAX_SPICE_PASSWD_LENGTH);
}
else if ( type == "vnc" )
{
// Vnc password must be 8 characters maximum
passwd = passwd.substr(0, VirtualMachine::MAX_VNC_PASSWD_LENGTH);
}
const_cast<VectorAttribute*>(graphics)->replace("PASSWD", passwd);
}
one_util::tolower(type);
if ( type == "vnc" || type == "spice" )
{
file << "\t\t<graphics type=" << one_util::escape_xml_attr(type);