// static
void LLPanelLogin::onSelectSavedLogin(LLUICtrl*, void*)
{
	// *NOTE: The paramters for this method are ignored. 
	LL_INFOS("AppInit") << "onSelectSavedLogin" << LL_ENDL;

	
	LLComboBox* combo = sInstance->getChild<LLComboBox>("username_combo");
	LLSD combo_val = combo->getSelectedValue();
	if (combo_val.isUndefined())
	{
		combo_val = combo->getValue();
	}

	
	std::string credName = combo_val.asString();
	
	if(combo_val.asString().find("@")<0)		
		return;


	// if they've selected another grid, we should load the credentials
	// for that grid and set them to the UI.
	if(sInstance)
	{
		LLPointer<LLCredential> credential = gSecAPIHandler->loadCredential(credName);
		if(credential->getIdentifier()["first_name"].asString().size()<=0 && credential->getIdentifier()["account_name"].asString().size()<=0 ) return;
		LLSD authenticator = credential->getAuthenticator();
		sInstance->setFields(credential);
	}

}
Exemple #2
0
// static
void LLPanelLogin::setFields(LLPointer<LLCredential> credential,
							 BOOL remember)
{
	if (!sInstance)
	{
		llwarns << "Attempted fillFields with no login view shown" << llendl;
		return;
	}
	LL_INFOS("Credentials") << "Setting login fields to " << *credential << LL_ENDL;

	LLSD identifier = credential->getIdentifier();
	if((std::string)identifier["type"] == "agent") 
	{
		std::string firstname = identifier["first_name"].asString();
		std::string lastname = identifier["last_name"].asString();
	    std::string login_id = firstname;
	    if (!lastname.empty() && lastname != "Resident")
	    {
		    // support traditional First Last name SLURLs
		    login_id += " ";
		    login_id += lastname;
	    }
		sInstance->getChild<LLComboBox>("username_combo")->setLabel(login_id);	
	}
	else if((std::string)identifier["type"] == "account")
	{
		sInstance->getChild<LLComboBox>("username_combo")->setLabel((std::string)identifier["account_name"]);		
	}
	else
	{
	  sInstance->getChild<LLComboBox>("username_combo")->setLabel(std::string());	
	}
	sInstance->addFavoritesToStartLocation();
	// if the password exists in the credential, set the password field with
	// a filler to get some stars
	LLSD authenticator = credential->getAuthenticator();
	LL_INFOS("Credentials") << "Setting authenticator field " << authenticator["type"].asString() << LL_ENDL;
	if(authenticator.isMap() && 
	   authenticator.has("secret") && 
	   (authenticator["secret"].asString().size() > 0))
	{
		
		// This is a MD5 hex digest of a password.
		// We don't actually use the password input field, 
		// fill it with MAX_PASSWORD characters so we get a 
		// nice row of asterixes.
		const std::string filler("123456789!123456");
		sInstance->getChild<LLUICtrl>("password_edit")->setValue(std::string("123456789!123456"));
	}
	else
	{
		sInstance->getChild<LLUICtrl>("password_edit")->setValue(std::string());		
	}
	sInstance->getChild<LLUICtrl>("remember_check")->setValue(remember);
}
// Save the credential to the credential store.  Save the authenticator also if requested.
// That feature is used to implement the 'remember password' functionality.
void LLSecAPIBasicHandler::saveCredential(LLPointer<LLCredential> cred, bool save_authenticator)
{
	LLSD credential = LLSD::emptyMap();
	credential["identifier"] = cred->getIdentifier(); 
	if (save_authenticator) 
	{
		credential["authenticator"] = cred->getAuthenticator();
	}
	LL_DEBUGS("SECAPI") << "Saving Credential " << cred->getGrid() << ":" << cred->userID() << " " << save_authenticator << LL_ENDL;
	setProtectedData("credential", cred->getGrid(), credential);
	//*TODO: If we're saving Agni credentials, should we write the
	// credentials to the legacy password.dat/etc?
	_writeProtectedData();
}
// static
void FSPanelLogin::getFields(LLPointer<LLCredential>& credential,
							 BOOL& remember)
{
	if (!sInstance)
	{
		LL_WARNS() << "Attempted getFields with no login view shown" << LL_ENDL;
		return;
	}
	
	// load the credential so we can pass back the stored password or hash if the user did
	// not modify the password field.
	credential = gSecAPIHandler->loadCredential(credentialName());

	LLSD identifier = LLSD::emptyMap();
	LLSD authenticator = LLSD::emptyMap();
	
	if(credential.notNull())
	{
		authenticator = credential->getAuthenticator();
	}

	std::string username = sInstance->getChild<LLUICtrl>("username_combo")->getValue().asString();
	LLStringUtil::trim(username);
	size_t arobase = username.find("@");
	if (arobase != std::string::npos)
	{
		username = username.substr(0, arobase);
	}
	std::string password = sInstance->getChild<LLUICtrl>("password_edit")->getValue().asString();
	sPassword = password;

	LL_INFOS("Credentials", "Authentication") << "retrieving username:"******"Credentials", "Authentication") << "account: " << username << LL_ENDL;
		// single username, so this is a 'clear' identifier
		identifier["type"] = CRED_IDENTIFIER_TYPE_ACCOUNT;
		identifier["account_name"] = username;
		
		if (FSPanelLogin::sInstance->mPasswordModified)
		{
			authenticator = LLSD::emptyMap();
			// password is plaintext
			authenticator["type"] = CRED_AUTHENTICATOR_TYPE_CLEAR;
			authenticator["secret"] = password;
		}
	}
	else
	{
		// Be lenient in terms of what separators we allow for two-word names
		// and allow legacy users to login with firstname.lastname
#ifdef OPENSIM
		if (LLGridManager::getInstance()->isInSecondLife())
		{
			separator_index = username.find_first_of(" ._");
		}
		else
		{
			separator_index = username.find_first_of(" .");
		}
#else
		separator_index = username.find_first_of(" ._");
#endif
		std::string first = username.substr(0, separator_index);
		std::string last;
		if (separator_index != username.npos)
		{
			last = username.substr(separator_index + 1, username.npos);
		LLStringUtil::trim(last);
		}
		else
		{
			// ...on Linden grids, single username users as considered to have
			// last name "Resident"
			// *TODO: Make login.cgi support "account_name" like above
			last = "Resident";
		}
		
		if (last.find_first_of(' ') == last.npos)
		{
			LL_INFOS("Credentials", "Authentication") << "agent: " << username << LL_ENDL;
			// traditional firstname / lastname
			identifier["type"] = CRED_IDENTIFIER_TYPE_AGENT;
			identifier["first_name"] = first;
			identifier["last_name"] = last;
		
			if (FSPanelLogin::sInstance->mPasswordModified)
			{
				authenticator = LLSD::emptyMap();
				authenticator["type"] = CRED_AUTHENTICATOR_TYPE_HASH;
				authenticator["algorithm"] = "md5";
				LLMD5 pass((const U8 *)password.c_str());
				char md5pass[33];               /* Flawfinder: ignore */
				pass.hex_digest(md5pass);
				authenticator["secret"] = md5pass;
			}
		}
	}
	credential = gSecAPIHandler->createCredential(credentialName(), identifier, authenticator);
	remember = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
}
// static
void FSPanelLogin::setFields(LLPointer<LLCredential> credential, bool from_startup /* = false*/)
{
	if (!sInstance)
	{
		LL_WARNS() << "Attempted setFields with no login view shown" << LL_ENDL;
		return;
	}
	LL_INFOS("Credentials") << "Setting login fields to " << *credential << LL_ENDL;

	std::string login_id;
	LLSD identifier = credential->getIdentifier();
	if (identifier["type"].asString() == "agent")
	{
		std::string firstname = identifier["first_name"].asString();
		std::string lastname = identifier["last_name"].asString();
		login_id = firstname;
		if (!lastname.empty() && lastname != "Resident")
		{
			// support traditional First Last name SLURLs
			login_id += " ";
			login_id += lastname;
		}
	}

	const std::string cred_name = credential->getCredentialName();
	LLComboBox* username_combo = sInstance->getChild<LLComboBox>("username_combo");
	if (!username_combo->selectByValue(cred_name))
	{
		username_combo->setTextEntry(login_id);
		sInstance->mPasswordModified = TRUE;
		sInstance->getChild<LLButton>("remove_user_btn")->setEnabled(FALSE);
	}
	sInstance->mPreviousUsername = username_combo->getValue().asString();
	sInstance->addFavoritesToStartLocation();
	// if the password exists in the credential, set the password field with
	// a filler to get some stars
	LLSD authenticator = credential->getAuthenticator();
	LL_INFOS("Credentials") << "Setting authenticator field " << authenticator["type"].asString() << LL_ENDL;
	bool remember;
	if (authenticator.isMap() &&
	   authenticator.has("secret") &&
	   (authenticator["secret"].asString().size() > 0))
	{
		
		// This is a MD5 hex digest of a password.
		// We don't actually use the password input field, 
		// fill it with MAX_PASSWORD_SL characters so we get a 
		// nice row of asterixes.
		const std::string filler("123456789!123456");
		sInstance->getChild<LLLineEditor>("password_edit")->setText(filler);
		remember = true;

		// We run into this case, if a user tries to login with a newly entered password
		// and the login fails with some error (except wrong credentials). In that case,
		// LLStartUp will bring us back here and provide us with the credentials that were
		// used for the login. In case we don't have credentials already saved for this
		// username OR the password hash is different, we have to set the password back
		// to the one the user entered or we will end up trying to login with the filler
		// as password!
		if (from_startup)
		{
			LLPointer<LLCredential> stored_credential = gSecAPIHandler->loadCredential(cred_name);
			if (stored_credential->getAuthenticator().size() == 0 ||
				(stored_credential->getAuthenticator().has("secret") && stored_credential->getAuthenticator()["secret"].asString() != authenticator["secret"].asString()))
			{
				sInstance->getChild<LLLineEditor>("password_edit")->setText(sPassword);
				sInstance->mPasswordModified = TRUE;
			}
		}
	}
	else
	{
		sInstance->getChild<LLLineEditor>("password_edit")->clear();
		remember = false;
	}
	if (from_startup)
	{
		remember = gSavedSettings.getBOOL("RememberPassword");
	}
	sInstance->getChild<LLUICtrl>("remember_check")->setValue(remember);
}
// static
void LLPanelLogin::getFields(LLPointer<LLCredential>& credential,
							 BOOL& remember)
{
	if (!sInstance)
	{
		llwarns << "Attempted getFields with no login view shown" << llendl;
		return;
	}
	
	// load the credential so we can pass back the stored password or hash if the user did
	// not modify the password field.
	
	credential = gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());

	LLSD identifier = LLSD::emptyMap();
	LLSD authenticator = LLSD::emptyMap();
	
	if(credential.notNull())
	{
		authenticator = credential->getAuthenticator();
	}

	std::string username = sInstance->getChild<LLUICtrl>("username_edit")->getValue().asString();
	LLStringUtil::trim(username);
	std::string password = sInstance->getChild<LLUICtrl>("password_edit")->getValue().asString();

	LL_INFOS2("Credentials", "Authentication") << "retrieving username:"******"Credentials", "Authentication") << "account: " << username << LL_ENDL;
		// single username, so this is a 'clear' identifier
		identifier["type"] = CRED_IDENTIFIER_TYPE_ACCOUNT;
		identifier["account_name"] = username;
		
		if (LLPanelLogin::sInstance->mPasswordModified)
		{
			authenticator = LLSD::emptyMap();
			// password is plaintext
			authenticator["type"] = CRED_AUTHENTICATOR_TYPE_CLEAR;
			authenticator["secret"] = password;
		}
	}
	else
	{
		std::string first = username.substr(0, separator_index);
		std::string last = username.substr(separator_index, username.npos);
		LLStringUtil::trim(last);
		
		if (last.find_first_of(' ') == last.npos)
		{
			LL_INFOS2("Credentials", "Authentication") << "agent: " << username << LL_ENDL;
			// traditional firstname / lastname
			identifier["type"] = CRED_IDENTIFIER_TYPE_AGENT;
			identifier["first_name"] = first;
			identifier["last_name"] = last;
		
			if (LLPanelLogin::sInstance->mPasswordModified)
			{
				authenticator = LLSD::emptyMap();
				authenticator["type"] = CRED_AUTHENTICATOR_TYPE_HASH;
				authenticator["algorithm"] = "md5";
				LLMD5 pass((const U8 *)password.c_str());
				char md5pass[33];               /* Flawfinder: ignore */
				pass.hex_digest(md5pass);
				authenticator["secret"] = md5pass;
			}
		}
	}
	credential = gSecAPIHandler->createCredential(LLGridManager::getInstance()->getGrid(), identifier, authenticator);
	remember = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
}
// static
void LLPanelLogin::getFields(LLPointer<LLCredential>& credential,
							 BOOL& remember)
{
	if (!sInstance)
	{
		llwarns << "Attempted getFields with no login view shown" << llendl;
		return;
	}
	
	// load the credential so we can pass back the stored password or hash if the user did
	// not modify the password field.
	
	credential = gSecAPIHandler->loadCredential(credential_name());

	LLSD identifier = LLSD::emptyMap();
	LLSD authenticator = LLSD::emptyMap();
	
	if(credential.notNull())
	{
		authenticator = credential->getAuthenticator();
	}

	std::string username = sInstance->getChild<LLComboBox>("username_combo")->getValue().asString();
	LLStringUtil::trim(username);
	U32 arobase = username.find("@");

	if(arobase>0) username = username.substr(0, arobase);

	std::string password = sInstance->getChild<LLUICtrl>("password_edit")->getValue().asString();

	LL_INFOS2("Credentials", "Authentication") << "retrieving username:"******"Credentials", "Authentication") << "account: " << username << LL_ENDL;
		// single username, so this is a 'clear' identifier
		identifier["type"] = CRED_IDENTIFIER_TYPE_ACCOUNT;
		identifier["account_name"] = username;
		
		if (LLPanelLogin::sInstance->mPasswordModified)
		{
			authenticator = LLSD::emptyMap();
			// password is plaintext
			authenticator["type"] = CRED_AUTHENTICATOR_TYPE_CLEAR;
			authenticator["secret"] = password;
		}
	}
	else
	{
		// Be lenient in terms of what separators we allow for two-word names
		// and allow legacy users to login with firstname.lastname
		separator_index = username.find_first_of(" ._");
		std::string first = username.substr(0, separator_index);
		std::string last;
		if (separator_index != username.npos)
		{
			last = username.substr(separator_index+1, username.npos);
		LLStringUtil::trim(last);
		}
		else
		{
			// ...on Linden grids, single username users as considered to have
			// last name "Resident"
			// *TODO: Make login.cgi support "account_name" like above
			last = "Resident";
		}
		
		if (last.find_first_of(' ') == last.npos)
		{
			LL_INFOS2("Credentials", "Authentication") << "agent: " << username << LL_ENDL;
			// traditional firstname / lastname
			identifier["type"] = CRED_IDENTIFIER_TYPE_AGENT;
			identifier["first_name"] = first;
			identifier["last_name"] = last;
		
			if (LLPanelLogin::sInstance->mPasswordModified)
			{
				authenticator = LLSD::emptyMap();
				authenticator["type"] = CRED_AUTHENTICATOR_TYPE_HASH;
				authenticator["algorithm"] = "md5";
				LLMD5 pass((const U8 *)password.c_str());
				char md5pass[33];               /* Flawfinder: ignore */
				pass.hex_digest(md5pass);
				authenticator["secret"] = md5pass;
			}
		}
	}

// <FS:AW FIRE-6492 Firestorm doesn't always honor the start location option>
/*
	switch(LLSLURL(sInstance->getChild<LLComboBox>("start_location_combo")->getValue()).getType())
	{
		case LLSLURL::HOME_LOCATION:
		{
			identifier["startlocation"] = LLSLURL::SIM_LOCATION_HOME;
			break;
      		}
		case LLSLURL::LAST_LOCATION:
		{
			identifier["startlocation"] = LLSLURL::SIM_LOCATION_LAST;
			break;
	  	}
		case LLSLURL::INVALID:
		{
			break;
		}
		case LLSLURL::LOCATION:
		{
			break;
		}
		case LLSLURL::APP:
		{
			break;
		}
		case LLSLURL::HELP: 
		{
			break;
		}
	}
*/
// </FS:AW FIRE-6492 Firestorm doesn't always honor the start location option>

	credential = gSecAPIHandler->createCredential(credential_name(), identifier, authenticator);
	remember = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
}
// static
void LLPanelLogin::setFields(LLPointer<LLCredential> credential)
{
	if (!sInstance)
	{
		llwarns << "Attempted fillFields with no login view shown" << llendl;
		return;
	}

	
	LL_INFOS("Credentials") << "Setting login fields to " << *credential << LL_ENDL;

	LLSD identifier = credential->getIdentifier();
	if((std::string)identifier["type"] == "agent") 
	{
		std::string firstname = identifier["first_name"].asString();
		std::string lastname = identifier["last_name"].asString();
	    std::string login_id = firstname;
	    if (!lastname.empty() && lastname != "Resident")
	    {
		    // support traditional First Last name SLURLs
		    login_id += " ";
		    login_id += lastname;
	    }
	}
	std::string credName = credential->getCredentialName();
	sInstance->getChild<LLComboBox>("username_combo")->selectByValue(credName);
	


// <FS:AW FIRE-6492 Firestorm doesn't always honor the start location option>
/*	if(identifier.has("startlocation")){
		llinfos << "Settings startlocation to: " << identifier["startlocation"].asString() << llendl;
		LLStartUp::setStartSLURL(LLSLURL(identifier["startlocation"].asString()));
		updateLocationCombo(false);
	}
*/
// </FS:AW FIRE-6492 Firestorm doesn't always honor the start location option>
	sInstance->addFavoritesToStartLocation();
	// if the password exists in the credential, set the password field with
	// a filler to get some stars
	LLSD authenticator = credential->getAuthenticator();
	LL_INFOS("Credentials") << "Setting authenticator field " << authenticator["type"].asString() << LL_ENDL;
	bool remember;
	if(authenticator.isMap() && 
	   authenticator.has("secret") && 
	   (authenticator["secret"].asString().size() > 0))
	{
		
		// This is a MD5 hex digest of a password.
		// We don't actually use the password input field, 
		// fill it with MAX_PASSWORD characters so we get a 
		// nice row of asterixes.
		const std::string filler("123456789!123456");
		sInstance->getChild<LLUICtrl>("password_edit")->setValue(std::string("123456789!123456"));
		remember=true;
	}
	else
	{
		sInstance->getChild<LLUICtrl>("password_edit")->setValue(std::string());	
		remember=false;
	}
	sInstance->getChild<LLUICtrl>("remember_check")->setValue(remember);


		U32 arobase = credName.find("@");
	if (arobase != -1 && arobase +1 < credName.length())
		credName = credName.substr(arobase+1, credName.length() - arobase - 1);
// <SA: opensim>
	if(LLGridManager::getInstance()->getGrid() == credName)
	{
		return;
	}

	try
	{
		LLGridManager::getInstance()->setGridChoice(credName);
	}
	catch (LLInvalidGridName ex)
	{
		// do nothing
	}
// </SA: opensim>
	//updateServerCombo();	
	// grid changed so show new splash screen (possibly)
	updateServer();
	updateLoginPanelLinks();
	sInstance->addFavoritesToStartLocation();
	
}