From f77771d5d1ee6fc4fe5c57b6be906c11a4721ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 24 Oct 2011 15:38:51 +0200 Subject: [PATCH] Bug #847: Allow to change the auth driver only in one.user.chauth --- src/cli/oneuser | 2 +- .../src/org/opennebula/client/user/User.java | 17 +++++++++++++++-- src/oca/ruby/OpenNebula/User.rb | 5 +++-- src/rm/RequestManagerUser.cc | 15 +++++++++------ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/cli/oneuser b/src/cli/oneuser index bed6e3ee80..9bb2ba4a70 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -275,7 +275,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do if rc.first == 0 pass = rc[1] else - exit_with_code *rc + pass = "" end end diff --git a/src/oca/java/src/org/opennebula/client/user/User.java b/src/oca/java/src/org/opennebula/client/user/User.java index cfcd85d979..d8eb40c148 100644 --- a/src/oca/java/src/org/opennebula/client/user/User.java +++ b/src/oca/java/src/org/opennebula/client/user/User.java @@ -151,7 +151,8 @@ public class User extends PoolElement{ * @param client XML-RPC Client. * @param id The user id (uid) of the target user we want to modify. * @param auth The new auth driver. - * @param password The new password. + * @param password The new password. If it is an empty string, + * the user password is not changed * @return If an error occurs the error message contains the reason. */ public static OneResponse chauth(Client client, @@ -229,7 +230,8 @@ public class User extends PoolElement{ * Changes the auth driver and the password of the given user * * @param auth The new auth driver. - * @param password The new password. + * @param password The new password. If it is an empty string, + * the user password is not changed * @return If an error occurs the error message contains the reason. */ public OneResponse chauth(String auth, String password) @@ -237,6 +239,17 @@ public class User extends PoolElement{ return chauth(client, id, auth, password); } + /** + * Changes the auth driver of the given user + * + * @param auth The new auth driver. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse chauth(String auth) + { + return chauth(auth, ""); + } + /** * Replaces the user template contents. * diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/OpenNebula/User.rb index 06f30a0331..8e71ff5c6b 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/OpenNebula/User.rb @@ -119,10 +119,11 @@ module OpenNebula # Changes the auth driver and the password of the given User # # @param auth [String] the new auth driver - # @param password [String] the new password + # @param password [String] the new password. If it is an empty string, + # the user password is not changed # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def chauth(auth, password) + def chauth(auth, password="") return Error.new('ID not defined') if !@pe_id rc = @client.call(USER_METHODS[:chauth],@pe_id, auth, password) diff --git a/src/rm/RequestManagerUser.cc b/src/rm/RequestManagerUser.cc index 91f7bfc012..01376a1d4b 100644 --- a/src/rm/RequestManagerUser.cc +++ b/src/rm/RequestManagerUser.cc @@ -88,15 +88,18 @@ int UserChangeAuth::user_action(User * user, string new_auth = xmlrpc_c::value_string(paramList.getString(2)); string new_pass = xmlrpc_c::value_string(paramList.getString(3)); - int rc; + int rc = 0; - if (new_auth == UserPool::CORE_AUTH) + if ( !new_pass.empty() ) { - new_pass = SSLTools::sha1_digest(new_pass); - } + if ( new_auth == UserPool::CORE_AUTH) + { + new_pass = SSLTools::sha1_digest(new_pass); + } - // The password may be invalid, try to change it first - rc = user->set_password(new_pass, error_str); + // The password may be invalid, try to change it first + rc = user->set_password(new_pass, error_str); + } if ( rc == 0 ) {