mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-02 09:47:00 +03:00
Feature #2054: Add TOKEN_PASSWORD to all users
This commit is contained in:
parent
2d7674138b
commit
3a16a58c0c
@ -45,7 +45,7 @@ namespace one_util
|
||||
std::string * base64_encode(const std::string& in);
|
||||
|
||||
/**
|
||||
* Base 64 deencoding
|
||||
* Base 64 decoding
|
||||
* @param in the string to decode
|
||||
* @return a pointer to the decoded string (must be freed) or 0 in case of
|
||||
* error
|
||||
@ -53,6 +53,12 @@ namespace one_util
|
||||
std::string * base64_decode(const std::string& in);
|
||||
|
||||
std::string aes256cbc_encrypt(const std::string& in, const std::string password);
|
||||
|
||||
/**
|
||||
* Creates a random number, using time(0) as seed, and performs an sha1 hash
|
||||
* @return a new random password
|
||||
*/
|
||||
std::string random_password();
|
||||
};
|
||||
|
||||
#endif /* _NEBULA_UTIL_H_ */
|
||||
|
@ -198,3 +198,13 @@ string one_util::aes256cbc_encrypt(const string& in, const string password)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string one_util::random_password()
|
||||
{
|
||||
stringstream sstr;
|
||||
|
||||
srand(time(0));
|
||||
sstr << rand();
|
||||
|
||||
return sha1_digest(sstr.str());
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ UserPool::UserPool(SqlDB * db,
|
||||
|
||||
string filenames[4];
|
||||
string error_str;
|
||||
stringstream sstr;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
@ -142,10 +141,7 @@ UserPool::UserPool(SqlDB * db,
|
||||
goto error_one_name;
|
||||
}
|
||||
|
||||
srand(time(0));
|
||||
sstr << rand();
|
||||
|
||||
random = one_util::sha1_digest(sstr.str());
|
||||
random = one_util::random_password();
|
||||
|
||||
filenames[0] = nd.get_var_location() + "/.one/sunstone_auth";
|
||||
filenames[1] = nd.get_var_location() + "/.one/occi_auth";
|
||||
@ -296,6 +292,9 @@ int UserPool::allocate (
|
||||
// Build a new User object
|
||||
user = new User(-1, gid, uname, gname, upass, auth_driver, enabled);
|
||||
|
||||
// Set a password for the OneGate tokens
|
||||
user->add_template_attribute("TOKEN_PASSWORD", one_util::random_password());
|
||||
|
||||
// Insert the Object in the pool
|
||||
*oid = PoolSQL::allocate(user, error_str);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user