diff --git a/include/UserPool.h b/include/UserPool.h index 830bca9ce7..1c7a25ef68 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -105,12 +105,22 @@ public: User::bootstrap(_db); }; + //TODO REMOVE THIS, HERE TO FIX COMPILATION /** * Returns whether there is a user with given username/password or not * @param session, colon separated username and password string * @return -1 if authn failed, uid of the user in other case */ - int authenticate(string& session); + int authenticate(string& session){return 0;} + + /** + * Returns whether there is a user with given username/password or not + * @param session, colon separated username and password string + * @param uid of the user if authN succeeded -1 otherwise + * @param gid of the user if authN succeeded -1 otherwise + * @return false if authn failed, true otherwise + */ + bool authenticate(const string& session, int& uid, int& gid); /** * Returns whether there is a user with given username/password or not diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 78e9253e4b..d006ff98cd 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -36,7 +36,7 @@ void Request::execute( NebulaLog::log("ReM",Log::DEBUG, method_name + " method invoked"); -if (true) // if ( upool->authenticate(uid, gid) == false ) + if ( upool->authenticate(session, uid, gid) == false ) { failure_response(RequestManager::AUTHENTICATION, authenticate_error()); diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 8e8eace790..76918fdb43 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -163,21 +163,25 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int UserPool::authenticate(string& session) +bool UserPool::authenticate(const string& session, int& user_id, int& group_id) { map::iterator index; User * user = 0; string username; string secret, u_pass; - int uid; - int user_id = -1; - int rc; + int uid, gid; + int rc; + bool result; Nebula& nd = Nebula::instance(); AuthManager * authm = nd.get_authm(); + user_id = -1; + group_id = -1; + result = false; + rc = User::split_secret(session,username,secret); if ( rc != 0 ) @@ -191,6 +195,7 @@ int UserPool::authenticate(string& session) { u_pass = user->password; uid = user->oid; + gid = user->gid; user->unlock(); } @@ -198,6 +203,7 @@ int UserPool::authenticate(string& session) { u_pass = "-"; uid = -1; + gid = -1; } AuthRequest ar(uid); @@ -208,14 +214,18 @@ int UserPool::authenticate(string& session) { if (ar.plain_authenticate()) { - user_id = 0; + user_id = 0; + group_id = GroupPool::ONEADMIN_ID; + result = true; } } else if (authm == 0) //plain auth { if ( user != 0 && ar.plain_authenticate()) //no plain for external users { - user_id = uid; + user_id = uid; + group_id = gid; + result = true; } } else //use the driver @@ -227,7 +237,9 @@ int UserPool::authenticate(string& session) { if ( user != 0 ) //knwon user_id { - user_id = uid; + user_id = uid; + group_id = gid; + result = true; } else //External user, username & pass in driver message { @@ -244,8 +256,13 @@ int UserPool::authenticate(string& session) if ( !is.fail() ) { - allocate(&user_id,GroupPool::USERS_ID,mad_name,mad_pass, - true,error_str); + allocate(&user_id, + GroupPool::USERS_ID, + mad_name, + mad_pass, + true, + error_str); + } if ( user_id == -1 ) @@ -256,12 +273,15 @@ int UserPool::authenticate(string& session) ". Driver response: " << ar.message; ar.message = oss.str(); - user_id = -1; + } + else + { + group_id = GroupPool::USERS_ID; + result = true; } } } - - if (user_id == -1) + else { ostringstream oss; oss << "Auth Error: " << ar.message; @@ -270,7 +290,7 @@ int UserPool::authenticate(string& session) } } - return user_id; + return result; } /* -------------------------------------------------------------------------- */