diff --git a/libresapi/src/api/RsControlModule.cpp b/libresapi/src/api/RsControlModule.cpp index 595509f09..f65c6058c 100644 --- a/libresapi/src/api/RsControlModule.cpp +++ b/libresapi/src/api/RsControlModule.cpp @@ -24,7 +24,9 @@ RsControlModule::RsControlModule(int argc, char **argv, StateTokenServer* sts, A mDataMtx("RsControlModule::mDataMtx"), mRunState(WAITING_INIT), mAutoLoginNextTime(false), - mWantPassword(false) + mWantPassword(false), + mPassword(""), + mPrevIsBad(false) { mStateToken = sts->getNewToken(); this->argc = argc; @@ -56,11 +58,14 @@ bool RsControlModule::processShouldExit() return mProcessShouldExit; } -bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool /* prev_is_bad */, std::string &password, bool& cancelled) +bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool prev_is_bad, std::string &password, bool& cancelled) { cancelled = false ; { RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** + + mPrevIsBad = prev_is_bad; + if(mFixedPassword != "") { password = mFixedPassword; @@ -70,18 +75,25 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string mWantPassword = true; mTitle = title; mKeyName = key_details; - mPassword = ""; + + if(mPassword != "") + { + password = mPassword; + mWantPassword = false; + mPassword = ""; + return true; + } + mStateTokenServer->replaceToken(mStateToken); } - bool wait = true; - while(wait) + int i = 0; + while(i<100) { usleep(5*1000); - RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** - wait = mWantPassword; - if(!wait && mPassword != "") + + if(mPassword != "") { password = mPassword; mPassword = ""; @@ -89,6 +101,7 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string mStateTokenServer->replaceToken(mStateToken); return true; } + i++; } return false; } @@ -175,8 +188,13 @@ void RsControlModule::run() std::cerr << "RsControlModule::run() LockAndLoadCertificates failed. Unexpected switch value: " << retVal << std::endl; break; } + + mLoadPeerId.clear(); + mPassword = ""; } + mFixedPassword = mPassword; + setRunState(WAITING_STARTUP); std::cerr << "RsControlModule: login ok, starting Retroshare worker threads..." << std::endl; @@ -302,12 +320,12 @@ void RsControlModule::handlePassword(Request &req, Response &resp) mPassword = passwd; mWantPassword = false; mStateTokenServer->replaceToken(mStateToken); - mFixedPassword = passwd; } resp.mDataStream << makeKeyValueReference("want_password", mWantPassword) - << makeKeyValueReference("key_name", mKeyName); + << makeKeyValueReference("key_name", mKeyName) + << makeKeyValueReference("prev_is_bad", mPrevIsBad); resp.mStateToken = mStateToken; resp.setOk(); } diff --git a/libresapi/src/api/RsControlModule.h b/libresapi/src/api/RsControlModule.h index 1323651fc..7e306405c 100644 --- a/libresapi/src/api/RsControlModule.h +++ b/libresapi/src/api/RsControlModule.h @@ -77,6 +77,7 @@ private: // to notify that a password callback is waiting // to answer the request, clear the flag and set the password bool mWantPassword; + bool mPrevIsBad; std::string mTitle; std::string mKeyName; std::string mPassword;