Commit f2e35655 authored by Yusuf Sengul's avatar Yusuf Sengul Committed by Commit Bot

Move GCPW bookkeeping out of forked process

Bug: 1097407
Change-Id: I80b0fa57cc19196b06b3cbec5afc7c4488ff7325
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255113
Commit-Queue: Yusuf Sengul <yusufsn@google.com>
Reviewed-by: default avatarRakesh Soma <rakeshsoma@google.com>
Cr-Commit-Position: refs/heads/master@{#781721}
parent 4b980955
......@@ -1987,7 +1987,7 @@ unsigned __stdcall CGaiaCredentialBase::WaitForLoginUI(void* param) {
}
// static
HRESULT CGaiaCredentialBase::SaveAccountInfo(const base::Value& properties) {
HRESULT CGaiaCredentialBase::PerformActions(const base::Value& properties) {
LOGFN(VERBOSE);
base::string16 sid = GetDictString(properties, kKeySID);
......@@ -2010,44 +2010,9 @@ HRESULT CGaiaCredentialBase::SaveAccountInfo(const base::Value& properties) {
base::string16 domain = GetDictString(properties, kKeyDomain);
// TODO(crbug.com/976744): Use the down scoped kKeyMdmAccessToken instead
// of login scoped token.
std::string access_token = GetDictStringUTF8(properties, kKeyAccessToken);
if (!access_token.empty()) {
// Update the password recovery information if possible.
HRESULT hr = PasswordRecoveryManager::Get()->StoreWindowsPasswordIfNeeded(
sid, access_token, password);
if (FAILED(hr) && hr != E_NOTIMPL)
LOGFN(ERROR) << "StoreWindowsPasswordIfNeeded hr=" << putHR(hr);
// Upload device details to gem database.
hr = GemDeviceDetailsManager::Get()->UploadDeviceDetails(access_token, sid,
username, domain);
DWORD device_upload_failures = 0;
GetUserProperty(sid, kRegDeviceDetailsUploadFailures,
&device_upload_failures);
if (FAILED(hr)) {
LOGFN(ERROR) << "UploadDeviceDetails hr=" << putHR(hr);
++device_upload_failures;
} else {
device_upload_failures = 0;
}
SetUserProperty(sid, kRegDeviceDetailsUploadStatus, SUCCEEDED(hr) ? 1 : 0);
SetUserProperty(sid, kRegDeviceDetailsUploadFailures,
device_upload_failures);
// Below setter is only used for unit testing.
GemDeviceDetailsManager::Get()->SetUploadStatusForTesting(hr);
} else {
LOGFN(ERROR) << "Access token is empty. Cannot save Windows password.";
}
// Load the user's profile so that their registry hive is available.
auto profile = ScopedUserProfile::Create(sid, domain, username, password);
SecurelyClearString(password);
if (!profile) {
LOGFN(ERROR) << "Could not load user profile";
return E_UNEXPECTED;
......@@ -2057,6 +2022,39 @@ HRESULT CGaiaCredentialBase::SaveAccountInfo(const base::Value& properties) {
if (FAILED(hr))
LOGFN(ERROR) << "profile.SaveAccountInfo failed (cont) hr=" << putHR(hr);
// TODO(crbug.com/976744): Use the down scoped kKeyMdmAccessToken instead
// of login scoped token.
std::string access_token = GetDictStringUTF8(properties, kKeyAccessToken);
if (access_token.empty()) {
LOGFN(ERROR) << "Access token is empty.";
return E_FAIL;
}
// Update the password recovery information if possible.
hr = PasswordRecoveryManager::Get()->StoreWindowsPasswordIfNeeded(
sid, access_token, password);
SecurelyClearString(password);
if (FAILED(hr) && hr != E_NOTIMPL)
LOGFN(ERROR) << "StoreWindowsPasswordIfNeeded hr=" << putHR(hr);
// Upload device details to gem database.
hr = GemDeviceDetailsManager::Get()->UploadDeviceDetails(access_token, sid,
username, domain);
DWORD device_upload_failures = 0;
GetUserProperty(sid, kRegDeviceDetailsUploadFailures,
&device_upload_failures);
if (FAILED(hr)) {
LOGFN(ERROR) << "UploadDeviceDetails hr=" << putHR(hr);
++device_upload_failures;
} else {
device_upload_failures = 0;
}
SetUserProperty(sid, kRegDeviceDetailsUploadStatus, SUCCEEDED(hr) ? 1 : 0);
SetUserProperty(sid, kRegDeviceDetailsUploadFailures, device_upload_failures);
// Below setter is only used for unit testing.
GemDeviceDetailsManager::Get()->SetUploadStatusForTesting(hr);
return hr;
}
......@@ -2068,9 +2066,9 @@ HRESULT CGaiaCredentialBase::PerformPostSigninActions(
HRESULT hr = S_OK;
if (com_initialized) {
hr = credential_provider::CGaiaCredentialBase::SaveAccountInfo(properties);
hr = credential_provider::CGaiaCredentialBase::PerformActions(properties);
if (FAILED(hr))
LOGFN(ERROR) << "SaveAccountInfo hr=" << putHR(hr);
LOGFN(ERROR) << "PerformActions hr=" << putHR(hr);
// Try to enroll the machine to MDM here. MDM requires a user to be signed
// on to an interactive session to succeed and when we call this function
......@@ -2099,10 +2097,11 @@ HRESULT CGaiaCredentialBase::PerformPostSigninActions(
// Registers OS user - gaia user association in HKEY_LOCAL_MACHINE registry
// hive.
HRESULT RegisterAssociation(const base::string16& sid,
const base::string16& id,
const base::string16& email,
const base::string16& token_handle) {
HRESULT
RegisterAssociation(const base::string16& sid,
const base::string16& id,
const base::string16& email,
const base::string16& token_handle) {
// Save token handle. This handle will be used later to determine if the
// the user has changed their password since the account was created.
HRESULT hr = SetUserProperty(sid, kUserTokenHandle, token_handle);
......
......@@ -97,8 +97,9 @@ class ATL_NO_VTABLE CGaiaCredentialBase
return authentication_results_;
}
// Saves gaia information in the OS account that was just created.
static HRESULT SaveAccountInfo(const base::Value& properties);
// Saves account association and user profile information. Makes various HTTP
// calls regarding device provisioning and password management.
static HRESULT PerformActions(const base::Value& properties);
// Returns true if the current credentials stored in |username_| and
// |password_| are valid and should succeed a local Windows logon. This
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment