diff --git a/src/cli/oneuser b/src/cli/oneuser index e3501b0439..1041b01e64 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -516,4 +516,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do 0 end + + passwdsearch_desc = <<-EOT.unindent + Searches for users with a specific auth driver that has the given + string in their password field + EOT + + command :passwdsearch, passwdsearch_desc, :driver, :password, + :options=>[CLIHelper::CSV_OPT, OpenNebulaHelper::XML] do + + options[:list] = ["ID", "NAME", "AUTH", "PASSWORD"] + options[:filter] = ["AUTH=#{args[0]}", "PASSWORD=#{args[1]}"] + + helper.list_pool(options) + end end diff --git a/src/oca/ruby/opennebula/user_pool.rb b/src/oca/ruby/opennebula/user_pool.rb index 86f916bfcb..34ac33f067 100644 --- a/src/oca/ruby/opennebula/user_pool.rb +++ b/src/oca/ruby/opennebula/user_pool.rb @@ -51,5 +51,27 @@ module OpenNebula end alias_method :info!, :info + + ####################################################################### + # Helpers to get information + ####################################################################### + + # Returns a list of user IDs that have the given password. info() needs + # to be called before. + # + # @param driver [String] auth driver to match + # @param password [String] password to match + # @return [Array] an array of IDs + def users_with_password(driver, password) + ids = [] + + each do |user| + if user["PASSWORD"] == password + ids << user["ID"] + end + end + + return ids + end end end