Example #1
0
bool CGUIPassword::IsProfileLockUnlocked(int iProfile, bool& bCanceled, bool prompt)
{
  if (g_passwordManager.bMasterUser)
    return true;
  int iProfileToCheck=iProfile;
  if (iProfile == -1)
    iProfileToCheck = CProfilesManager::Get().GetCurrentProfileIndex();
  if (iProfileToCheck == 0)
    return IsMasterLockUnlocked(prompt,bCanceled);
  else
  {
    CProfile *profile = CProfilesManager::Get().GetProfile(iProfileToCheck);
    if (!profile)
      return false;

    if (!prompt)
      return (profile->getLockMode() == LOCK_MODE_EVERYONE);

    if (profile->getDate().empty() &&
       (CProfilesManager::Get().GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE ||
        profile->getLockMode() == LOCK_MODE_EVERYONE))
    {
      // user hasn't set a password and this is the first time they've used this account
      // so prompt for password/settings
      if (CGUIDialogProfileSettings::ShowForProfile(iProfileToCheck, true))
        return true;
    }
    else
       if (CProfilesManager::Get().GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)
        return CheckLock(profile->getLockMode(),profile->getLockCode(),20095,bCanceled);
  }

  return true;
}
JSONRPC_STATUS CProfilesOperations::LoadProfile(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
  CStdString profilename = parameterObject["profile"].asString();
  int index = CProfilesManager::Get().GetProfileIndex(profilename);
  
  if (index < 0)
    return InvalidParams;

	// Init prompt
	bool bPrompt = false;
	bPrompt = parameterObject["prompt"].asBoolean();
    
	bool bCanceled;
  bool bLoadProfile(false);

  if (CProfilesManager::Get().GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE ||            // Password not needed
      (bPrompt && g_passwordManager.IsProfileLockUnlocked(index, bCanceled, bPrompt)))  // Password needed and user asked to enter it
    bLoadProfile = true;
	else if (!bCanceled && parameterObject.isMember("password"))  // Password needed and user provided it
	{
    const CVariant &passwordObject = parameterObject["password"];
	  CStdString strToVerify;  // Holds user saved password hash
		if (index == 0)
		  strToVerify = CProfilesManager::Get().GetMasterProfile().getLockCode();
		else
		{
	    CProfile *profile = CProfilesManager::Get().GetProfile(index);
		  strToVerify = profile->getLockCode();
		}

		CStdString password = passwordObject["value"].asString();
		
		// Create password hash from the provided password if md5 is not used
    CStdString md5pword2;
    CStdString encryption = passwordObject["encryption"].asString();
    if (encryption.Equals("none"))
		{
			XBMC::XBMC_MD5 md5state;
			md5state.append(password);
			md5state.getDigest(md5pword2);
		}
		else if (encryption.Equals("md5"))
			md5pword2 = password;

		// Verify profided password
    if (strToVerify.Equals(md5pword2))
		  bLoadProfile = true;
	}

  if (bLoadProfile)
  {
    CApplicationMessenger::Get().LoadProfile(index);
    return ACK;
  }
  return InvalidParams;
}