diff --git a/src/authm_mad/one_auth_mad.rb b/src/authm_mad/one_auth_mad.rb index 81ea494ecf..46d8136344 100755 --- a/src/authm_mad/one_auth_mad.rb +++ b/src/authm_mad/one_auth_mad.rb @@ -107,9 +107,9 @@ class AuthDriver < OpenNebulaDriver #build path for the auth action #/var/lib/one/remotes/auth//authenticate authN_path = File.join(@local_scripts_path, driver) - - command = File.join(authN_path,ACTION[:authN].downcase) - command << ' ' << user << ' ' << password << ' ' << secret + + command = File.join(authN_path,ACTION[:authN].downcase) + command << " '" << user.gsub("'", '\'"\'"\'') << "' '" << password.gsub("'", '\'"\'"\'') << "' " << secret local_action(command, request_id, ACTION[:authN]) end diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb index 4231c105ce..046bdc9493 100644 --- a/src/authm_mad/remotes/quota/quota.rb +++ b/src/authm_mad/remotes/quota/quota.rb @@ -78,7 +78,13 @@ class Quota IMAGE_USAGE = { :STORAGE => { - :proc_info => lambda {|template| File.size(template['PATH']) }, + :proc_info => lambda {|template| + if template['TYPE'] == 'DATABLOCK' + template['SIZE'].to_i + else + File.size(template['PATH']) + end + }, :xpath => 'SIZE' } } diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 48b87abead..15e9c9c4a9 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -37,14 +37,14 @@ class OneUserHelper < OpenNebulaHelper::OneHelper return -1, "Can not read file: #{arg}" end else - password = arg + password = arg.dup end if options[:driver] == OpenNebula::User::X509_AUTH password.delete!("\s") end - if options[:sha1] + if options[:sha1] || options[:driver] == OpenNebula::User::CIPHER_AUTH require 'digest/sha1' password = Digest::SHA1.hexdigest(password) end @@ -166,7 +166,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "USER #{user['ID']} INFORMATION") puts str % ["ID", user.id.to_s] puts str % ["NAME", user.name] - puts str % ["GROUP", user.gid] + puts str % ["GROUP", user['GNAME']] puts str % ["PASSWORD", user['PASSWORD']] puts str % ["AUTH_DRIVER", user['AUTH_DRIVER']] diff --git a/src/cli/oneuser b/src/cli/oneuser index 293ecbcac1..75501a49fe 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -275,11 +275,25 @@ cmd=CommandParser::CmdParser.new(ARGV) do end chauth_desc = <<-EOT.unindent - Changes the User's auth driver + Changes the User's auth driver and its password (optional) + Examples: + oneuser chauth my_user core + oneuser chauth my_user core new_password + oneuser chauth my_user core -r /tmp/mypass + oneuser chauth my_user --ssh --key /home/oneadmin/.ssh/id_rsa + oneuser chauth my_user --ssh -r /tmp/public_key + oneuser chauth my_user --x509 --cert /tmp/my_cert.pem EOT - command :chauth, chauth_desc, :userid, :auth, [:password, nil], + command :chauth, chauth_desc, :userid, [:auth, nil], [:password, nil], :options=>create_options do + if options[:driver] + driver = options[:driver] + elsif args[1] + driver = args[1] + else + exit_with_code 0, "An Auth driver should be specified" + end helper = OneUserHelper.new @@ -297,7 +311,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.perform_action(args[0], options, "Auth driver and password changed") do |user| - user.chauth(args[1], pass) + user.chauth(driver, pass) end end diff --git a/src/cloud/common/CloudAuth.rb b/src/cloud/common/CloudAuth.rb index c11f7b4a54..f3fe29ca15 100644 --- a/src/cloud/common/CloudAuth.rb +++ b/src/cloud/common/CloudAuth.rb @@ -64,15 +64,16 @@ class CloudAuth begin require core_auth[0] @server_auth = Kernel.const_get(core_auth[1]).new_client - - token = @server_auth.login_token(expiration_time) - @oneadmin_client ||= OpenNebula::Client.new(token, @conf[:one_xmlrpc]) rescue => e raise e.message end end - def client(username) + # Generate a new OpenNebula client for the target User, if the username + # is nil the Client is generated for the server_admin + # ussername:: _String_ Name of the User + # [return] _Client_ + def client(username=nil) token = @server_auth.login_token(expiration_time,username) Client.new(token,@conf[:one_xmlrpc]) end @@ -97,7 +98,7 @@ class CloudAuth end def update_userpool_cache - @user_pool ||= OpenNebula::UserPool.new(@oneadmin_client) + @user_pool = OpenNebula::UserPool.new(client) rc = @user_pool.info if OpenNebula.is_error?(rc) diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/OpenNebula/User.rb index e9b44e8cef..51eb331ed4 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/OpenNebula/User.rb @@ -38,6 +38,9 @@ module OpenNebula # Driver name for default core authentication CORE_AUTH = "core" + # Driver name for default core authentication + CIPHER_AUTH = "server_cipher" + # Driver name for ssh authentication SSH_AUTH = "ssh" diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index d615d9dce0..33e630a53a 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -198,6 +198,8 @@ PoolObjectSQL * PoolSQL::get( } else { + map::iterator name_index; + objectsql = create(); objectsql->oid = oid; @@ -214,6 +216,19 @@ PoolObjectSQL * PoolSQL::get( } string okey = key(objectsql->name,objectsql->uid); + name_index = name_pool.find(okey); + + if ( name_index != name_pool.end() ) + { + name_index->second->lock(); + + PoolObjectSQL * tmp_ptr = name_index->second; + + name_pool.erase(okey); + pool.erase(tmp_ptr->oid); + + delete tmp_ptr; + } pool.insert(make_pair(objectsql->oid,objectsql)); name_pool.insert(make_pair(okey, objectsql)); diff --git a/src/pool/test/pool.cc b/src/pool/test/pool.cc index d689660cf4..15f5f47eef 100644 --- a/src/pool/test/pool.cc +++ b/src/pool/test/pool.cc @@ -170,7 +170,10 @@ public: //Should be set to MAX_POOL -1 for (int i=0 ; i < 14999 ; i++) { - create_allocate(i,"A Test object"); + ostringstream name; + name << "A Test object " << i; + + create_allocate(i,name.str()); obj_lock = pool->get(i, true); CPPUNIT_ASSERT(obj_lock != 0); @@ -178,16 +181,22 @@ public: for (int i=14999 ; i < 15200 ; i++) //Works with just 1 cache line { - create_allocate(i,"A Test object"); + ostringstream name; + name << "A Test object " << i; + + create_allocate(i,name.str()); } for (int i=14999; i < 15200 ; i++) { + ostringstream name; + name << "A Test object " << i; + obj = pool->get(i, true); CPPUNIT_ASSERT(obj != 0); CPPUNIT_ASSERT(obj->number == i); - CPPUNIT_ASSERT(obj->text == "A Test object"); + CPPUNIT_ASSERT(obj->text == name.str()); obj->unlock(); } diff --git a/src/tm_mad/ssh/tm_mv.sh b/src/tm_mad/ssh/tm_mv.sh index 3f10354e8b..11bb1a5068 100755 --- a/src/tm_mad/ssh/tm_mv.sh +++ b/src/tm_mad/ssh/tm_mv.sh @@ -35,9 +35,14 @@ DST_HOST=`arg_host $DST` DST_DIR=`dirname $DST_PATH` -log "Moving $SRC_PATH" -exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \ - "Unable to create directory $DST_DIR" -exec_and_log "$SCP -r $SRC $DST" \ - "Could not copy $SRC to $DST" -exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" +if full_src_and_dst_equal; then + log "Not moving $SRC to $DST, they are the same path" +else + log "Moving $SRC_PATH" + exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \ + "Unable to create directory $DST_DIR" + exec_and_log "$SCP -r $SRC $DST" \ + "Could not copy $SRC to $DST" + exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" +fi + diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh index 00ad3fb18a..5970606ffa 100644 --- a/src/tm_mad/tm_common.sh +++ b/src/tm_mad/tm_common.sh @@ -49,6 +49,20 @@ function fix_dir_slashes dirname "$1/file" | $SED 's/\/+/\//g' } +function get_compare_target +{ + echo "$1" | $SED 's/\/+/\//g' | $SED 's/\/images$//' +} + +function full_src_and_dst_equal +{ + s=`get_compare_target "$SRC"` + d=`get_compare_target "$DST"` + + [ "$s" == "$d" ] + +} + function fix_var_slashes { ONE_LOCAL_VAR=`fix_dir_slashes "$ONE_LOCAL_VAR"`