1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Merge branch 'master' into bug-847

Conflicts:
	src/um/UserPool.cc
This commit is contained in:
Ruben S. Montero 2011-10-15 00:22:52 +02:00
commit 30a9162f5e
37 changed files with 261 additions and 72 deletions

View File

@ -99,8 +99,9 @@ public:
/** /**
* Bootstraps the database table(s) associated to the ACL Manager * Bootstraps the database table(s) associated to the ACL Manager
* @return 0 on success
*/ */
static void bootstrap(SqlDB * _db); static int bootstrap(SqlDB * _db);
/** /**
* Dumps the rule set in XML format. * Dumps the rule set in XML format.

View File

@ -103,12 +103,13 @@ private:
/** /**
* Bootstraps the database table(s) associated to the Group * Bootstraps the database table(s) associated to the Group
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
ostringstream oss(Group::db_bootstrap); ostringstream oss(Group::db_bootstrap);
db->exec(oss); return db->exec(oss);
}; };
/** /**

View File

@ -119,10 +119,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the Group pool * Bootstraps the database table(s) associated to the Group pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB * _db) static int bootstrap(SqlDB * _db)
{ {
Group::bootstrap(_db); return Group::bootstrap(_db);
}; };
/** /**

View File

@ -362,12 +362,13 @@ private:
/** /**
* Bootstraps the database table(s) associated to the Host * Bootstraps the database table(s) associated to the Host
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
ostringstream oss_host(Host::db_bootstrap); ostringstream oss_host(Host::db_bootstrap);
db->exec(oss_host); return db->exec(oss_host);
}; };
/** /**

View File

@ -82,10 +82,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the Host pool * Bootstraps the database table(s) associated to the Host pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB *_db) static int bootstrap(SqlDB *_db)
{ {
Host::bootstrap(_db); return Host::bootstrap(_db);
}; };
/** /**

View File

@ -375,12 +375,13 @@ private:
/** /**
* Bootstraps the database table(s) associated to the Image * Bootstraps the database table(s) associated to the Image
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
ostringstream oss_image(Image::db_bootstrap); ostringstream oss_image(Image::db_bootstrap);
db->exec(oss_image); return db->exec(oss_image);
}; };
/** /**

View File

@ -104,10 +104,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the Image pool * Bootstraps the database table(s) associated to the Image pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB *_db) static int bootstrap(SqlDB *_db)
{ {
Image::bootstrap(_db); return Image::bootstrap(_db);
}; };
/** /**

View File

@ -445,8 +445,10 @@ private:
/** /**
* Bootstraps the database control tables * Bootstraps the database control tables
*
* @return 0 on success
*/ */
void bootstrap(); int bootstrap();
/** /**
* Callback function for the check_db_version method. Stores the read * Callback function for the check_db_version method. Stores the read

View File

@ -188,12 +188,13 @@ private:
/** /**
* Bootstraps the database table(s) associated to the User * Bootstraps the database table(s) associated to the User
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
ostringstream oss_user(User::db_bootstrap); ostringstream oss_user(User::db_bootstrap);
db->exec(oss_user); return db->exec(oss_user);
}; };
/** /**

View File

@ -93,10 +93,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the User pool * Bootstraps the database table(s) associated to the User pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB * _db) static int bootstrap(SqlDB * _db)
{ {
User::bootstrap(_db); return User::bootstrap(_db);
}; };
/** /**

View File

@ -108,12 +108,13 @@ private:
/** /**
* Bootstraps the database table(s) associated to the VMTemplate * Bootstraps the database table(s) associated to the VMTemplate
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
ostringstream oss(VMTemplate::db_bootstrap); ostringstream oss(VMTemplate::db_bootstrap);
db->exec(oss); return db->exec(oss);
}; };
/** /**

View File

@ -104,10 +104,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the pool * Bootstraps the database table(s) associated to the pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB *_db) static int bootstrap(SqlDB *_db)
{ {
VMTemplate::bootstrap(_db); return VMTemplate::bootstrap(_db);
}; };
private: private:

View File

@ -784,14 +784,19 @@ private:
/** /**
* Bootstraps the database table(s) associated to the VirtualMachine * Bootstraps the database table(s) associated to the VirtualMachine
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
int rc;
ostringstream oss_vm(VirtualMachine::db_bootstrap); ostringstream oss_vm(VirtualMachine::db_bootstrap);
ostringstream oss_hist(History::db_bootstrap); ostringstream oss_hist(History::db_bootstrap);
db->exec(oss_vm); rc = db->exec(oss_vm);
db->exec(oss_hist); rc += db->exec(oss_hist);
return rc;
}; };
/** /**

View File

@ -122,10 +122,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the VirtualMachine pool * Bootstraps the database table(s) associated to the VirtualMachine pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB * _db) static int bootstrap(SqlDB * _db)
{ {
VirtualMachine::bootstrap(_db); return VirtualMachine::bootstrap(_db);
}; };
/** /**

View File

@ -236,14 +236,19 @@ private:
/** /**
* Bootstraps the database table(s) associated to the Virtual Network * Bootstraps the database table(s) associated to the Virtual Network
* @return 0 on success
*/ */
static void bootstrap(SqlDB * db) static int bootstrap(SqlDB * db)
{ {
int rc;
ostringstream oss_vnet(VirtualNetwork::db_bootstrap); ostringstream oss_vnet(VirtualNetwork::db_bootstrap);
ostringstream oss_lease(Leases::db_bootstrap); ostringstream oss_lease(Leases::db_bootstrap);
db->exec(oss_vnet); rc = db->exec(oss_vnet);
db->exec(oss_lease); rc += db->exec(oss_lease);
return rc;
}; };
/** /**

View File

@ -108,10 +108,11 @@ public:
/** /**
* Bootstraps the database table(s) associated to the VirtualNetwork pool * Bootstraps the database table(s) associated to the VirtualNetwork pool
* @return 0 on success
*/ */
static void bootstrap(SqlDB * _db) static int bootstrap(SqlDB * _db)
{ {
VirtualNetwork::bootstrap(_db); return VirtualNetwork::bootstrap(_db);
}; };
/** /**

View File

@ -654,6 +654,7 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \
src/onedb/2.9.80_to_2.9.85.rb \ src/onedb/2.9.80_to_2.9.85.rb \
src/onedb/2.9.85_to_2.9.90.rb \ src/onedb/2.9.85_to_2.9.90.rb \
src/onedb/2.9.90_to_3.0.rb \ src/onedb/2.9.90_to_3.0.rb \
src/onedb/3.0_to_3.1.0.rb \
src/onedb/onedb.rb \ src/onedb/onedb.rb \
src/onedb/onedb_backend.rb" src/onedb/onedb_backend.rb"

View File

@ -14,7 +14,7 @@ if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7"
OPTIONAL=%w{nokogiri} OPTIONAL=%w{nokogiri}
else else
SQLITE='sqlite3-ruby --version 1.2.0' SQLITE='sqlite3-ruby --version 1.2.0'
OPTIONAL=%w{nokogir xmlparser} OPTIONAL=%w{nokogiri xmlparser}
end end
GROUPS={ GROUPS={

View File

@ -474,11 +474,11 @@ int AclManager::del_rule(int oid, string& error_str)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void AclManager::bootstrap(SqlDB * _db) int AclManager::bootstrap(SqlDB * _db)
{ {
ostringstream oss(db_bootstrap); ostringstream oss(db_bootstrap);
_db->exec(oss); return _db->exec(oss);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -27,7 +27,7 @@ const char * Group::table = "group_pool";
const char * Group::db_names = "oid, name, body"; const char * Group::db_names = "oid, name, body";
const char * Group::db_bootstrap = "CREATE TABLE IF NOT EXISTS group_pool (" 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))"; "UNIQUE(name))";
/* ************************************************************************ */ /* ************************************************************************ */

View File

@ -91,6 +91,11 @@ int GroupPool::allocate(string name, int * oid, string& error_str)
goto error_name; goto error_name;
} }
if ( name.length() > 128 )
{
goto error_name_length;
}
// Check for duplicates // Check for duplicates
group = get(name, false); group = get(name, false);
@ -111,6 +116,10 @@ error_name:
oss << "NAME cannot be empty."; oss << "NAME cannot be empty.";
goto error_common; goto error_common;
error_name_length:
oss << "NAME is too long; max length is 128 chars.";
goto error_common;
error_duplicated: error_duplicated:
oss << "NAME is already taken by GROUP " << group->get_oid() << "."; 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_names = "oid, name, body, state, last_mon_time";
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool (" 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))"; "last_mon_time INTEGER, UNIQUE(name))";
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

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

View File

@ -76,7 +76,7 @@ const char * Image::table = "image_pool";
const char * Image::db_names = "oid, name, body, uid, gid, public"; const char * Image::db_names = "oid, name, body, uid, gid, public";
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool (" 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) )"; "gid INTEGER, public INTEGER, UNIQUE(name,uid) )";
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
@ -226,7 +226,7 @@ error_size_format:
goto error_common; goto error_common;
error_path_and_source: 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; goto error_common;
error_common: error_common:

View File

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

View File

@ -236,17 +236,29 @@ void Nebula::start()
if( rc == -2 ) if( rc == -2 )
{ {
NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database."); rc = 0;
bootstrap(); NebulaLog::log("ONE",Log::INFO,"Bootstrapping OpenNebula database.");
VirtualMachinePool::bootstrap(db);
HostPool::bootstrap(db); rc += VirtualMachinePool::bootstrap(db);
VirtualNetworkPool::bootstrap(db); rc += HostPool::bootstrap(db);
GroupPool::bootstrap(db); rc += VirtualNetworkPool::bootstrap(db);
UserPool::bootstrap(db); rc += GroupPool::bootstrap(db);
ImagePool::bootstrap(db); rc += UserPool::bootstrap(db);
VMTemplatePool::bootstrap(db); rc += ImagePool::bootstrap(db);
AclManager::bootstrap(db); rc += VMTemplatePool::bootstrap(db);
rc += AclManager::bootstrap(db);
// Create the versioning table only if bootstrap went well
if ( rc == 0 )
{
rc += bootstrap();
}
if ( rc != 0 )
{
throw runtime_error("Error bootstrapping database.");
}
} }
} }
catch (exception&) catch (exception&)
@ -627,27 +639,30 @@ void Nebula::start()
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void Nebula::bootstrap() int Nebula::bootstrap()
{ {
int rc;
ostringstream oss; ostringstream oss;
oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, " oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, "
"last_oid BIGINT UNSIGNED)"; "last_oid BIGINT UNSIGNED)";
db->exec(oss); rc = db->exec(oss);
oss.str(""); oss.str("");
oss << "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, " oss << "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, "
"version VARCHAR(256), timestamp INTEGER, comment VARCHAR(256))"; "version VARCHAR(256), timestamp INTEGER, comment VARCHAR(256))";
db->exec(oss); rc += db->exec(oss);
oss.str(""); oss.str("");
oss << "INSERT INTO db_versioning (oid, version, timestamp, comment) " oss << "INSERT INTO db_versioning (oid, version, timestamp, comment) "
<< "VALUES (0, '" << db_version() << "', " << time(0) << "VALUES (0, '" << db_version() << "', " << time(0)
<< ", '" << version() << " daemon bootstrap')"; << ", '" << version() << " daemon bootstrap')";
db->exec(oss); rc += db->exec(oss);
return rc;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -32,7 +32,10 @@ module Migrator
# Image pool table: # Image pool table:
# CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER, UNIQUE(name,uid) ); # CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER, UNIQUE(name,uid) );
@db.fetch("SELECT * FROM image_pool") do |row| @db.run "ALTER TABLE image_pool RENAME TO old_image_pool;"
@db.run "CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER, UNIQUE(name,uid) );"
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Document.new(row[:body]) doc = Document.new(row[:body])
source = nil source = nil
@ -48,10 +51,17 @@ module Migrator
size_elem = doc.root.add_element("SIZE") size_elem = doc.root.add_element("SIZE")
size_elem.text = size size_elem.text = size
@db[:image_pool].filter(:oid => row[:oid]).update( @db[:image_pool].insert(
:body => doc.root.to_s) :oid => row[:oid],
:name => row[:name],
:body => doc.root.to_s,
:uid => row[:uid],
:gid => row[:gid],
:public => row[:public])
end end
@db.run "DROP TABLE old_image_pool;"
return true return true
end end
end end

View File

@ -29,7 +29,11 @@ module Migrator
# The tm_nfs driver has been renamed to tm_shared # The tm_nfs driver has been renamed to tm_shared
# CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, UNIQUE(name)); # CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, UNIQUE(name));
@db.fetch("SELECT * FROM host_pool") do |row| @db.run "ALTER TABLE host_pool RENAME TO old_host_pool;"
@db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, UNIQUE(name));"
@db.run "INSERT INTO host_pool SELECT * FROM old_host_pool;"
@db.fetch("SELECT * FROM old_host_pool") do |row|
doc = Document.new(row[:body]) doc = Document.new(row[:body])
source = nil source = nil
@ -43,6 +47,8 @@ module Migrator
} }
end end
@db.run "DROP TABLE old_host_pool;"
return true return true
end end
end end

82
src/onedb/3.0_to_3.1.0.rb Normal file
View File

@ -0,0 +1,82 @@
# -------------------------------------------------------------------------- *
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# Licensed under the Apache License, Version 2.0 (the "License"); you may *
# not use this file except in compliance with the License. You may obtain *
# a copy of the License at *
# *
# http://www.apache.org/licenses/LICENSE-2.0 *
# *
# Unless required by applicable law or agreed to in writing, software *
# distributed under the License is distributed on an "AS IS" BASIS, *
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
# See the License for the specific language governing permissions and *
# limitations under the License. *
# -------------------------------------------------------------------------- *
require "rexml/document"
include REXML
module Migrator
def db_version
"3.1.0"
end
def one_version
"OpenNebula 3.1.0"
end
def up
[ [:group_pool, "group"],
[:host_pool, "host"],
[:image_pool, "image"],
[:network_pool, "network"],
[:template_pool,"template"],
[:user_pool, "user"],
[:vm_pool, "vm"]
].each { |pair|
# Check that all objects have names shorter that 128
check_names(pair[0], pair[1])
# Change the name column to 128 chars. In SQLite, ALTER COLUMN is
# not supported, but since the char limit is ignored,
# VARCHAR(128) and VARCHAR(256) are the same type
if ( self.class == BackEndMySQL )
@db.run "ALTER TABLE #{pair[0]} CHANGE name name VARCHAR(128);"
end
}
return true
end
def check_names(table, elem)
@db.run "CREATE TABLE migrator_tmp (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT);"
@db.fetch("SELECT * FROM #{table}") do |row|
if ( row[:name].length > 128 )
# Element name is bigger than 128 chars
new_name = "#{elem}-#{row[:oid]}-#{row[:name][0..99]}"
doc = Document.new(row[:body])
doc.root.each_element("NAME") { |e|
e.text = new_name
}
@db[:migrator_tmp].insert(
:oid => row[:oid],
:name => new_name,
:body => doc.root.to_s)
puts " > #{elem} ##{row[:oid]} had a name bigger than 128 chars and has been renamed to #{new_name[0..10]}..."
end
end
@db.fetch("SELECT * FROM migrator_tmp") do |row|
@db[table].filter(:oid => row[:oid]).update(
:name => row[:name],
:body => row[:body])
end
@db.run "DROP TABLE migrator_tmp"
end
end

View File

@ -80,7 +80,10 @@ sort results/one.db.3.0.tmpschema > results/one.db.3.0.schema
rm results/one.db.upgraded.tmpschema rm results/one.db.upgraded.tmpschema
rm results/one.db.3.0.tmpschema rm results/one.db.3.0.tmpschema
# Small cheat: the 3.0 schema had some columns with type VARCHAR(256), now it
# has changed to VARCHAR(128); but sqlite ignores the char limit
sed -i "s/name VARCHAR(256)/name VARCHAR(128)/" results/one.db.upgraded.schema
sed -i "s/name TEXT/name VARCHAR(128)/" results/one.db.upgraded.schema
# Perform a diff # Perform a diff
FILE=results/schema.diff FILE=results/schema.diff

View File

@ -80,14 +80,6 @@ start()
exit 1 exit 1
fi fi
sleep 1
ps $LASTPID &> /dev/null
if [ $? -ne 0 ]; then
echo "Error executing $OZONES_SERVER, please check the log $OZONES_LOG"
exit 1
fi
echo "ozones-server listening on $HOST:$PORT" echo "ozones-server listening on $HOST:$PORT"
} }

View File

@ -529,11 +529,11 @@ void Nebula::start()
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void Nebula::bootstrap() int Nebula::bootstrap()
{ {
ostringstream oss; ostringstream oss;
oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, " oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, "
"last_oid BIGINT UNSIGNED)"; "last_oid BIGINT UNSIGNED)";
db->exec(oss); return db->exec(oss);
} }

View File

@ -38,7 +38,7 @@ const char * User::table = "user_pool";
const char * User::db_names = "oid,name,body"; const char * User::db_names = "oid,name,body";
const char * User::db_bootstrap = "CREATE TABLE IF NOT EXISTS user_pool (" 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

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

View File

@ -96,7 +96,7 @@ const char * VirtualMachine::db_names =
"oid, name, body, uid, gid, last_poll, state, lcm_state"; "oid, name, body, uid, gid, last_poll, state, lcm_state";
const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS " 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)"; "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); replace_template_attribute("NAME", name);
} }
else if ( name.length() > 128 )
{
goto error_name_length;
}
this->name = name; this->name = name;
@ -284,7 +288,11 @@ error_rollback:
error_leases_rollback: error_leases_rollback:
release_network_leases(); 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: error_common:
NebulaLog::log("ONE",Log::ERROR, error_str); 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 = const char * VMTemplate::db_bootstrap =
"CREATE TABLE IF NOT EXISTS template_pool (oid INTEGER PRIMARY KEY, " "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; oss << "template-" << oid;
name = oss.str(); name = oss.str();
} }
else if ( name.length() > 128 )
{
error_str = "NAME is too long; max length is 128 chars.";
return -1;
}
// ------------ PUBLIC -------------------- // ------------ PUBLIC --------------------

View File

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