1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-27 10:50:10 +03:00

Merge branch 'master' of opennebula.org:one

This commit is contained in:
Jaime Melis 2010-07-23 16:24:02 +02:00
commit 1663f7872a
7 changed files with 46 additions and 45 deletions

View File

@ -261,7 +261,8 @@ BIN_FILES="src/nebula/oned \
src/cli/oneuser \
src/cli/oneimage \
src/cli/onecluster \
share/scripts/one"
share/scripts/one \
src/authm_mad/oneauth"
#-------------------------------------------------------------------------------
# C/C++ OpenNebula API Library & Development files

View File

@ -57,10 +57,10 @@ class AuthorizationManager < OpenNebulaDriver
driver=Kernel.const_get(driver_name.to_sym)
@authenticate=driver.new
log('-', "Using '#{driver_prefix}' driver for authentication")
STDERR.puts "Using '#{driver_prefix}' driver for authentication"
rescue
log('-', "Driver '#{driver_prefix}' not found, "<<
"using SimpleAuth instead")
STDERR.puts "Driver '#{driver_prefix}' not found, "<<
"using SimpleAuth instead"
@authenticate=SimpleAuth.new
end
@ -72,7 +72,6 @@ class AuthorizationManager < OpenNebulaDriver
end
def action_authenticate(request_id, user_id, user, password, token)
STDERR.puts [user_id, user, password, token].inspect
auth=@authenticate.auth(user_id, user, password, token)
if auth==true
send_message('AUTHENTICATE', RESULT[:success],

View File

@ -32,17 +32,17 @@ $: << RUBY_LIB_LOCATION
require 'OpenNebula'
require 'client_utilities'
require 'command_parse'
require 'rubygems'
require 'sequel'
require 'quota'
require 'ssh_auth'
class OneAuthCli < CommandParse
COMMANDS_HELP=<<-EOT
COMMANDS_HELP=<<-EOT
Usage:
oneauth <command> [<parameters>]
Commands:
* create (Creates a new user)
@ -56,22 +56,14 @@ Commands:
* key (gets public key)
oneauth key
* help (prints help)
oneauth help
EOT
def text_commands
COMMANDS_HELP
end
def text_command_name
"oneauth"
end
def list_options
table=ShowTable.new(ShowTableUP)
table.print_help
end
def print_help
puts COMMANDS_HELP
end
def get_database
@ -88,9 +80,6 @@ def add_quota(uid, cpu, memory)
quota.set(uid.to_i, cpu.to_f, memory.to_i, nil)
end
oneauth_opts=OneAuthCli.new
oneauth_opts.parse(ARGV)
ops=oneauth_opts.options
result=[false, "Unknown error"]
@ -143,8 +132,12 @@ when "key"
exit 0
when "help"
print_help
exit 0
else
oneauth_opts.print_help
print_help
exit -1
end

View File

@ -14,16 +14,19 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# Password authentication module. This one just compares stored password
# with the token sent by the client.
class SimpleAuth
def initialize
end
# Method called by authentication driver. It should awnser true if
# successful or a string with the error message if failure. All
# parameters are string extracted from the authorization message.
#
# * user_id: OpenNebula user identifier
# * user: user name
# * password: password stored in OpenNebula dabatase
# * token: password sent by the client trying to connect
def auth(user_id, user, password, token)
STDERR.puts [user_id, user, password, token].inspect
STDERR.flush
t_user, t_password=token.split(':')
#auth=(user==t_user && password==t_password)
auth=(password==token)
auth="Invalid credentials" if auth!=true
auth

View File

@ -33,8 +33,6 @@ class SimplePermissions
end
def auth(uid, tokens)
STDERR.puts [uid, tokens].inspect
result=true
tokens.each do |token|
@ -60,7 +58,7 @@ class SimplePermissions
when 'USE'
if %w{VM NET IMAGE}.include? object
auth_result = ((owner == uid) || pub)
auth_result = ((owner == uid) | pub)
elsif object == 'HOST'
auth_result=true
end

View File

@ -19,6 +19,16 @@ require 'spec_common'
require 'client_mock'
require 'simple_permissions'
CONF=<<EOT
:database: sqlite://auth.db
:authentication: simple
:quota:
:enabled: false
:defaults:
:cpu: 10.0
:memory: 1048576
EOT
def gen_tokens(user_, action_, options={})
user=user_.to_s
action=action_.to_s.upcase
@ -48,8 +58,6 @@ def gen_tokens(user_, action_, options={})
]
tokens<<"HOST:#{id}:#{action}:#{user}:#{pub}" if options[:host]
#pp tokens
tokens
end
@ -58,7 +66,7 @@ describe SimplePermissions do
@db=Sequel.sqlite
mock_data=YAML::load(File.read('spec/oca_vms.yaml'))
client=ClientMock.new(mock_data)
@perm=SimplePermissions.new(@db, client)
@perm=SimplePermissions.new(@db, client, YAML::load(CONF))
end
it 'should let root manage everything' do

View File

@ -16,11 +16,10 @@ module OpenNebula
:delete => "image.delete"
}
IMAGE_STATES=%w{INIT LOCKED READY USED DISABLED}
IMAGE_STATES=%w{INIT READY USED DISABLED}
SHORT_IMAGE_STATES={
"INIT" => "init",
"LOCKED" => "lock",
"READY" => "rdy",
"USED" => "used",
"DISABLED" => "disa"
@ -181,8 +180,8 @@ module OpenNebula
# Constants and Class Methods
# ---------------------------------------------------------------------
FS_UTILS = {
:dd => "/bin/dd",
:mkfs => "/bin/mkfs"
:dd => "env dd",
:mkfs => "env mkfs"
}
def copy(path, source)
@ -223,7 +222,7 @@ module OpenNebula
command = ""
command << FS_UTILS[:dd]
command << " if=/dev/zero of=#{source} ibs=1 count=1"
command << " obs=1048576 oseek=#{size}"
command << " obs=1048576 seek=#{size}"
local_command=LocalCommand.run(command)