1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

Bug #848: Set name columns to 128 chars. The name length is checked for new objects

This commit is contained in:
Carlos Martín 2011-10-10 17:48:06 +02:00
parent 21bca20780
commit 771a4ac8d9
12 changed files with 64 additions and 9 deletions

View File

@ -27,7 +27,7 @@ const char * Group::table = "group_pool";
const char * Group::db_names = "oid, name, body";
const char * Group::db_bootstrap = "CREATE TABLE IF NOT EXISTS group_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, "
"oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, "
"UNIQUE(name))";
/* ************************************************************************ */

View File

@ -91,6 +91,11 @@ int GroupPool::allocate(string name, int * oid, string& error_str)
goto error_name;
}
if ( name.length() > 128 )
{
goto error_name_length;
}
// Check for duplicates
group = get(name, false);
@ -111,6 +116,10 @@ error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_name_length:
oss << "NAME is too long; max length is 128 chars.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by GROUP " << group->get_oid() << ".";

View File

@ -61,7 +61,7 @@ const char * Host::table = "host_pool";
const char * Host::db_names = "oid, name, body, state, last_mon_time";
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, "
"oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, state INTEGER, "
"last_mon_time INTEGER, UNIQUE(name))";
/* ------------------------------------------------------------------------ */

View File

@ -150,6 +150,11 @@ int HostPool::allocate (
goto error_name;
}
if ( hostname.length() > 128 )
{
goto error_name_length;
}
if ( im_mad_name.empty() )
{
goto error_im;
@ -187,6 +192,10 @@ error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_name_length:
oss << "NAME is too long; max length is 128 chars.";
goto error_common;
error_im:
oss << "IM_MAD_NAME cannot be empty.";
goto error_common;

View File

@ -74,7 +74,7 @@ const char * Image::table = "image_pool";
const char * Image::db_names = "oid, name, body, uid, gid, public";
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, "
"oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, "
"gid INTEGER, public INTEGER, UNIQUE(name,uid) )";
/* ------------------------------------------------------------------------ */
@ -235,7 +235,7 @@ error_size_format:
goto error_common;
error_path_and_source:
error_str = "Template malformed, PATH and SOURCE are mutuallly exclusive.";
error_str = "Template malformed, PATH and SOURCE are mutually exclusive.";
goto error_common;
error_common:

View File

@ -78,6 +78,11 @@ int ImagePool::allocate (
goto error_name;
}
if ( name.length() > 128 )
{
goto error_name_length;
}
// Check for duplicates
img_aux = get(name,uid,false);
@ -111,6 +116,10 @@ error_name:
goto error_common;
error_name_length:
oss << "NAME is too long; max length is 128 chars.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by IMAGE "
<< img_aux->get_oid() << ".";

View File

@ -238,7 +238,7 @@ void Nebula::start()
{
rc = 0;
NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database.");
NebulaLog::log("ONE",Log::INFO,"Bootstrapping OpenNebula database.");
rc += VirtualMachinePool::bootstrap(db);
rc += HostPool::bootstrap(db);

View File

@ -38,7 +38,7 @@ const char * User::table = "user_pool";
const char * User::db_names = "oid,name,body";
const char * User::db_bootstrap = "CREATE TABLE IF NOT EXISTS user_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name))";
"oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, UNIQUE(name))";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -146,6 +146,12 @@ int UserPool::allocate (
goto error_name;
}
if ( uname.length() > 128 )
{
error_str = "max length is 128 chars";
goto error_name;
}
user = get(uname,false);
if ( user !=0 )

View File

@ -96,7 +96,7 @@ const char * VirtualMachine::db_names =
"oid, name, body, uid, gid, last_poll, state, lcm_state";
const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
"vm_pool (oid INTEGER PRIMARY KEY, name TEXT, body TEXT, uid INTEGER, "
"vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, "
"gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER)";
/* -------------------------------------------------------------------------- */
@ -209,6 +209,10 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
replace_template_attribute("NAME", name);
}
else if ( name.length() > 128 )
{
goto error_name_length;
}
this->name = name;
@ -284,7 +288,11 @@ error_rollback:
error_leases_rollback:
release_network_leases();
goto error_common; // just to avoid compilation warnings
goto error_common;
error_name_length:
oss << "NAME is too long; max length is 128 chars.";
goto error_common;
error_common:
NebulaLog::log("ONE",Log::ERROR, error_str);

View File

@ -63,7 +63,7 @@ const char * VMTemplate::db_names = "oid, name, body, uid, gid, public";
const char * VMTemplate::db_bootstrap =
"CREATE TABLE IF NOT EXISTS template_pool (oid INTEGER PRIMARY KEY, "
"name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER)";
"name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, public INTEGER)";
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
@ -92,6 +92,11 @@ int VMTemplate::insert(SqlDB *db, string& error_str)
oss << "template-" << oid;
name = oss.str();
}
else if ( name.length() > 128 )
{
error_str = "NAME is too long; max length is 128 chars.";
return -1;
}
// ------------ PUBLIC --------------------

View File

@ -93,6 +93,11 @@ int VirtualNetworkPool::allocate (
goto error_name;
}
if ( name.length() > 128 )
{
goto error_name_length;
}
// Check for duplicates
vn_aux = get(name,uid,false);
@ -112,6 +117,10 @@ error_name:
goto error_common;
error_name_length:
oss << "NAME is too long; max length is 128 chars.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by NET "
<< vn_aux->get_oid() << ".";