mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Bug #839: Add support in scheduler for auth tokens with protocol
(cherry picked from commit 2bb8ce1e88d0dc3a9a9eb9de2f9c3f81aec2b07b)
This commit is contained in:
parent
37618ecf45
commit
69933ac673
@ -96,7 +96,7 @@ private:
|
||||
|
||||
int read_oneauth(string &secret);
|
||||
|
||||
int split_secret(const string secret, string& user, string& pass);
|
||||
int split_secret(const string& secret);
|
||||
};
|
||||
|
||||
#endif /*ONECLIENT_H_*/
|
||||
|
@ -38,9 +38,6 @@ const int Client::MESSAGE_SIZE = 51200;
|
||||
|
||||
void Client::set_one_auth(string secret)
|
||||
{
|
||||
string user = "";
|
||||
string pass = "";
|
||||
|
||||
int rc = 0;
|
||||
|
||||
if( secret == "" )
|
||||
@ -50,18 +47,11 @@ void Client::set_one_auth(string secret)
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
rc = split_secret(secret, user, pass);
|
||||
rc = split_secret(secret);
|
||||
|
||||
if( rc == 0 )
|
||||
if( rc != 0 )
|
||||
{
|
||||
string sha1_pass = SSLTools::sha1_digest(pass);
|
||||
|
||||
one_auth = user + ":" + sha1_pass;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw runtime_error("Wrong format for auth token, must "
|
||||
"be <username>:<passwd>");
|
||||
throw runtime_error("Wrong format for auth token");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,23 +122,32 @@ int Client::read_oneauth(string &secret)
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int Client::split_secret(const string secret, string& user, string& pass)
|
||||
int Client::split_secret(const string& secret)
|
||||
{
|
||||
size_t pos;
|
||||
int rc = -1;
|
||||
|
||||
pos=secret.find(":");
|
||||
pos = secret.find(":");
|
||||
|
||||
if (pos != string::npos)
|
||||
if ( pos == string::npos )
|
||||
{
|
||||
user = secret.substr(0,pos);
|
||||
pass = secret.substr(pos+1);
|
||||
|
||||
rc = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
if ( secret.rfind(":") == pos )
|
||||
{
|
||||
string user = secret.substr(0,pos);
|
||||
string pass = secret.substr(pos+1);
|
||||
|
||||
string sha1_pass = SSLTools::sha1_digest(pass);
|
||||
|
||||
one_auth = user + ":" + sha1_pass;
|
||||
}
|
||||
else
|
||||
{
|
||||
one_auth = secret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user