Commit 833c1fb4 authored by rvargas's avatar rvargas Committed by Commit bot

Remove implicit HANDLE conversions from remoting.

BUG=416722
R=garykac@chromium.org

Review URL: https://codereview.chromium.org/602763003

Cr-Commit-Position: refs/heads/master@{#296602}
parent d87803b7
......@@ -164,7 +164,7 @@ bool DaemonProcessWin::OnDesktopSessionAgentAttached(
base::ProcessHandle desktop_process_for_transit;
if (!DuplicateHandle(GetCurrentProcess(),
desktop_process,
network_process_,
network_process_.Get(),
&desktop_process_for_transit,
0,
FALSE,
......@@ -247,7 +247,7 @@ void DaemonProcessWin::DisableAutoStart() {
DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS;
ScopedScHandle service(
OpenService(scmanager, kWindowsServiceName, desired_access));
OpenService(scmanager.Get(), kWindowsServiceName, desired_access));
if (!service.IsValid()) {
PLOG(INFO) << "Failed to open to the '" << kWindowsServiceName
<< "' service";
......@@ -256,7 +256,7 @@ void DaemonProcessWin::DisableAutoStart() {
// Change the service start type to 'manual'. All |NULL| parameters below mean
// that there is no change to the corresponding service parameter.
if (!ChangeServiceConfig(service,
if (!ChangeServiceConfig(service.Get(),
SERVICE_NO_CHANGE,
SERVICE_DEMAND_START,
SERVICE_NO_CHANGE,
......@@ -280,9 +280,9 @@ bool DaemonProcessWin::InitializePairingRegistry() {
// Duplicate handles to the network process.
IPC::PlatformFileForTransit privileged_key = GetRegistryKeyForTransit(
network_process_, pairing_registry_privileged_key_);
network_process_.Get(), pairing_registry_privileged_key_);
IPC::PlatformFileForTransit unprivileged_key = GetRegistryKeyForTransit(
network_process_, pairing_registry_unprivileged_key_);
network_process_.Get(), pairing_registry_unprivileged_key_);
if (!(privileged_key && unprivileged_key))
return false;
......
......@@ -248,7 +248,7 @@ bool DesktopSessionProxy::AttachToDesktop(
}
base::win::ScopedHandle pipe(temp_handle);
IPC::ChannelHandle desktop_channel_handle(pipe);
IPC::ChannelHandle desktop_channel_handle(pipe.Get());
#elif defined(OS_POSIX)
// On posix: |desktop_pipe| is a valid file descriptor.
......
......@@ -573,7 +573,7 @@ void DesktopSessionWin::OnSessionDetached() {
void DesktopSessionWin::OnDesktopSessionAgentAttached(
IPC::PlatformFileForTransit desktop_pipe) {
if (!daemon_process()->OnDesktopSessionAgentAttached(id(),
desktop_process_,
desktop_process_.Get(),
desktop_pipe)) {
CrashDesktopProcess(FROM_HERE);
}
......
......@@ -53,7 +53,7 @@ bool CreateConnectedIpcChannel(
// Wrap the pipe into an IPC channel.
scoped_ptr<IPC::ChannelProxy> server =
IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe),
IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe.Get()),
IPC::Channel::MODE_SERVER,
listener,
io_task_runner);
......
......@@ -402,7 +402,7 @@ bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) {
#if defined(OS_WIN)
base::win::ScopedHandle pipe(reinterpret_cast<HANDLE>(pipe_handle));
IPC::ChannelHandle channel_handle(pipe);
IPC::ChannelHandle channel_handle(pipe.Get());
#elif defined(OS_POSIX)
base::FileDescriptor pipe(pipe_handle, true);
IPC::ChannelHandle channel_handle(channel_name, pipe);
......
......@@ -98,8 +98,8 @@ DWORD OpenService(ScopedScHandle* service_out) {
return error;
}
ScopedScHandle service(
::OpenServiceW(scmanager, kWindowsServiceName, SERVICE_QUERY_STATUS));
ScopedScHandle service(::OpenServiceW(scmanager.Get(), kWindowsServiceName,
SERVICE_QUERY_STATUS));
if (!service.IsValid()) {
DWORD error = GetLastError();
if (error != ERROR_SERVICE_DOES_NOT_EXIST) {
......@@ -153,7 +153,7 @@ DaemonController::State DaemonControllerDelegateWin::GetState() {
switch (error) {
case ERROR_SUCCESS: {
SERVICE_STATUS status;
if (::QueryServiceStatus(service, &status)) {
if (::QueryServiceStatus(service.Get(), &status)) {
return ConvertToDaemonState(status.dwCurrentState);
} else {
PLOG(ERROR) << "Failed to query the state of the '"
......
......@@ -54,7 +54,7 @@ bool LowerProcessIntegrityLevel(DWORD max_level) {
DWORD length = 0;
// Get the size of the buffer needed to hold the mandatory label.
BOOL result = GetTokenInformation(token, TokenIntegrityLevel,
BOOL result = GetTokenInformation(token.Get(), TokenIntegrityLevel,
mandatory_label.get(), length, &length);
if (!result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Allocate a buffer that is large enough.
......@@ -62,7 +62,7 @@ bool LowerProcessIntegrityLevel(DWORD max_level) {
mandatory_label.Swap(buffer);
// Get the the mandatory label.
result = GetTokenInformation(token, TokenIntegrityLevel,
result = GetTokenInformation(token.Get(), TokenIntegrityLevel,
mandatory_label.get(), length, &length);
}
if (!result) {
......@@ -79,8 +79,8 @@ bool LowerProcessIntegrityLevel(DWORD max_level) {
// Set the integrity level to |max_level| if needed.
if (*current_level > max_level) {
*current_level = max_level;
if (!SetTokenInformation(token, TokenIntegrityLevel, mandatory_label.get(),
length)) {
if (!SetTokenInformation(token.Get(), TokenIntegrityLevel,
mandatory_label.get(), length)) {
PLOG(ERROR) << "Failed to set the mandatory label";
return false;
}
......
......@@ -114,7 +114,7 @@ HRESULT ReadConfig(const base::FilePath& filename,
scoped_ptr<char[]> buffer(new char[kMaxConfigFileSize]);
DWORD size = kMaxConfigFileSize;
if (!::ReadFile(file, &buffer[0], size, &size, NULL)) {
if (!::ReadFile(file.Get(), &buffer[0], size, &size, NULL)) {
DWORD error = GetLastError();
PLOG(ERROR) << "Failed to read '" << filename.value() << "'";
return HRESULT_FROM_WIN32(error);
......@@ -177,7 +177,8 @@ HRESULT WriteConfigFileToTemp(const base::FilePath& filename,
}
DWORD written;
if (!WriteFile(file, content, static_cast<DWORD>(length), &written, NULL)) {
if (!WriteFile(file.Get(), content, static_cast<DWORD>(length), &written,
NULL)) {
DWORD error = GetLastError();
PLOG(ERROR) << "Failed to write to '" << filename.value() << "'";
return HRESULT_FROM_WIN32(error);
......@@ -372,7 +373,7 @@ STDMETHODIMP ElevatedController::StartDaemon() {
}
// Change the service start type to 'auto'.
if (!::ChangeServiceConfigW(service,
if (!::ChangeServiceConfigW(service.Get(),
SERVICE_NO_CHANGE,
SERVICE_AUTO_START,
SERVICE_NO_CHANGE,
......@@ -390,7 +391,7 @@ STDMETHODIMP ElevatedController::StartDaemon() {
}
// Start the service.
if (!StartService(service, 0, NULL)) {
if (!StartService(service.Get(), 0, NULL)) {
DWORD error = GetLastError();
if (error != ERROR_SERVICE_ALREADY_RUNNING) {
PLOG(ERROR) << "Failed to start the '" << kWindowsServiceName
......@@ -411,7 +412,7 @@ STDMETHODIMP ElevatedController::StopDaemon() {
}
// Change the service start type to 'manual'.
if (!::ChangeServiceConfigW(service,
if (!::ChangeServiceConfigW(service.Get(),
SERVICE_NO_CHANGE,
SERVICE_DEMAND_START,
SERVICE_NO_CHANGE,
......@@ -430,7 +431,7 @@ STDMETHODIMP ElevatedController::StopDaemon() {
// Stop the service.
SERVICE_STATUS status;
if (!ControlService(service, SERVICE_CONTROL_STOP, &status)) {
if (!ControlService(service.Get(), SERVICE_CONTROL_STOP, &status)) {
DWORD error = GetLastError();
if (error != ERROR_SERVICE_NOT_ACTIVE) {
PLOG(ERROR) << "Failed to stop the '" << kWindowsServiceName
......@@ -513,7 +514,7 @@ HRESULT ElevatedController::OpenService(ScopedScHandle* service_out) {
DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS |
SERVICE_START | SERVICE_STOP;
ScopedScHandle service(
::OpenServiceW(scmanager, kWindowsServiceName, desired_access));
::OpenServiceW(scmanager.Get(), kWindowsServiceName, desired_access));
if (!service.IsValid()) {
error = GetLastError();
PLOG(ERROR) << "Failed to open to the '" << kWindowsServiceName
......
......@@ -132,7 +132,7 @@ bool CopyProcessToken(DWORD desired_access, ScopedHandle* token_out) {
}
ScopedHandle process_token(temp_handle);
if (!DuplicateTokenEx(process_token,
if (!DuplicateTokenEx(process_token.Get(),
desired_access,
NULL,
SecurityImpersonation,
......@@ -165,7 +165,8 @@ bool CreatePrivilegedToken(ScopedHandle* token_out) {
}
// Enable the SE_TCB_NAME privilege.
if (!AdjustTokenPrivileges(privileged_token, FALSE, &state, 0, NULL, 0)) {
if (!AdjustTokenPrivileges(privileged_token.Get(), FALSE, &state, 0, NULL,
0)) {
PLOG(ERROR) << "Failed to enable SE_TCB_NAME privilege in a token";
return false;
}
......@@ -380,13 +381,13 @@ bool CreateRemoteSessionProcess(
if (!ConnectToExecutionServer(session_id, &pipe))
return false;
if (!SendCreateProcessRequest(pipe, application_name, command_line,
if (!SendCreateProcessRequest(pipe.Get(), application_name, command_line,
creation_flags, desktop_name)) {
return false;
}
PROCESS_INFORMATION process_information;
if (!ReceiveCreateProcessResponse(pipe, &process_information))
if (!ReceiveCreateProcessResponse(pipe.Get(), &process_information))
return false;
if (!ProcessCreateProcessResponse(creation_flags, &process_information)) {
......@@ -421,14 +422,14 @@ bool CreateSessionToken(uint32 session_id, ScopedHandle* token_out) {
if (!CreatePrivilegedToken(&privileged_token)) {
return false;
}
if (!ImpersonateLoggedOnUser(privileged_token)) {
if (!ImpersonateLoggedOnUser(privileged_token.Get())) {
PLOG(ERROR) << "Failed to impersonate the privileged token";
return false;
}
// Change the session ID of the token.
DWORD new_session_id = session_id;
if (!SetTokenInformation(session_token,
if (!SetTokenInformation(session_token.Get(),
TokenSessionId,
&new_session_id,
sizeof(new_session_id))) {
......
......@@ -83,7 +83,7 @@ bool CreateRestrictedToken(ScopedHandle* token_out) {
ScopedHandle token(temp_handle);
sandbox::RestrictedToken restricted_token;
if (restricted_token.Init(token) != ERROR_SUCCESS)
if (restricted_token.Init(token.Get()) != ERROR_SUCCESS)
return false;
// Remove all privileges in the token.
......@@ -245,7 +245,7 @@ void UnprivilegedProcessDelegate::LaunchProcess(
// Determine our logon SID, so we can grant it access to our window station
// and desktop.
ScopedSid logon_sid = GetLogonSid(token);
ScopedSid logon_sid = GetLogonSid(token.Get());
if (!logon_sid) {
PLOG(ERROR) << "Failed to retrieve the logon SID";
ReportFatalError();
......@@ -306,7 +306,7 @@ void UnprivilegedProcessDelegate::LaunchProcess(
ScopedHandle worker_thread;
if (!LaunchProcessWithToken(command_line.GetProgram(),
command_line.GetCommandLineString(),
token,
token.Get(),
&process_attributes,
&thread_attributes,
true,
......@@ -346,7 +346,7 @@ void UnprivilegedProcessDelegate::KillProcess() {
event_handler_ = NULL;
if (worker_process_.IsValid()) {
TerminateProcess(worker_process_, CONTROL_C_EXIT);
TerminateProcess(worker_process_.Get(), CONTROL_C_EXIT);
worker_process_.Close();
}
}
......@@ -361,7 +361,7 @@ bool UnprivilegedProcessDelegate::OnMessageReceived(
void UnprivilegedProcessDelegate::OnChannelConnected(int32 peer_pid) {
DCHECK(CalledOnValidThread());
DWORD pid = GetProcessId(worker_process_);
DWORD pid = GetProcessId(worker_process_.Get());
if (pid != static_cast<DWORD>(peer_pid)) {
LOG(ERROR) << "The actual client PID " << pid
<< " does not match the one reported by the client: "
......@@ -402,7 +402,7 @@ void UnprivilegedProcessDelegate::ReportProcessLaunched(
SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION;
HANDLE temp_handle;
if (!DuplicateHandle(GetCurrentProcess(),
worker_process_,
worker_process_.Get(),
GetCurrentProcess(),
&temp_handle,
desired_access,
......
......@@ -113,7 +113,7 @@ void WorkerProcessLauncher::OnProcessLaunched(
DCHECK(!process_watcher_.GetWatchedObject());
DCHECK(!worker_process_.IsValid());
if (!process_watcher_.StartWatching(worker_process, this)) {
if (!process_watcher_.StartWatching(worker_process.Get(), this)) {
StopWorker();
return;
}
......@@ -167,10 +167,10 @@ void WorkerProcessLauncher::OnObjectSignaled(HANDLE object) {
DCHECK(CalledOnValidThread());
DCHECK(!process_watcher_.GetWatchedObject());
DCHECK_EQ(exit_code_, CONTROL_C_EXIT);
DCHECK_EQ(worker_process_, object);
DCHECK_EQ(worker_process_.Get(), object);
// Get exit code of the worker process if it is available.
if (!::GetExitCodeProcess(worker_process_, &exit_code_)) {
if (!::GetExitCodeProcess(worker_process_.Get(), &exit_code_)) {
PLOG(INFO) << "Failed to query the exit code of the worker process";
exit_code_ = CONTROL_C_EXIT;
}
......
......@@ -262,14 +262,14 @@ void WorkerProcessLauncherTest::KillProcess() {
event_handler_ = NULL;
if (worker_process_.IsValid()) {
TerminateProcess(worker_process_, CONTROL_C_EXIT);
TerminateProcess(worker_process_.Get(), CONTROL_C_EXIT);
worker_process_.Close();
}
}
void WorkerProcessLauncherTest::TerminateWorker(DWORD exit_code) {
if (worker_process_.IsValid())
TerminateProcess(worker_process_, exit_code);
TerminateProcess(worker_process_.Get(), exit_code);
}
void WorkerProcessLauncherTest::ConnectClient() {
......@@ -362,11 +362,12 @@ void WorkerProcessLauncherTest::DoLaunchProcess() {
// Wrap the pipe into an IPC channel.
channel_server_ = IPC::ChannelProxy::Create(
IPC::ChannelHandle(pipe), IPC::Channel::MODE_SERVER, this, task_runner_);
IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, this,
task_runner_);
HANDLE temp_handle;
ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(),
worker_process_,
worker_process_.Get(),
GetCurrentProcess(),
&temp_handle,
0,
......
......@@ -188,7 +188,7 @@ bool WtsSessionProcessDelegate::Core::Initialize(uint32 session_id) {
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_ACTIVE_PROCESS |
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
info.BasicLimitInformation.ActiveProcessLimit = 2;
if (!SetInformationJobObject(job,
if (!SetInformationJobObject(job.Get(),
JobObjectExtendedLimitInformation,
&info,
sizeof(info))) {
......@@ -261,10 +261,10 @@ void WtsSessionProcessDelegate::Core::KillProcess() {
if (launch_elevated_) {
if (job_.IsValid())
TerminateJobObject(job_, CONTROL_C_EXIT);
TerminateJobObject(job_.Get(), CONTROL_C_EXIT);
} else {
if (worker_process_.IsValid())
TerminateProcess(worker_process_, CONTROL_C_EXIT);
TerminateProcess(worker_process_.Get(), CONTROL_C_EXIT);
}
worker_process_.Close();
......@@ -306,7 +306,7 @@ void WtsSessionProcessDelegate::Core::OnChannelConnected(int32 peer_pid) {
// protection against a malicious processed connecting to the pipe.
if (launch_elevated_) {
DWORD pid;
if (!get_named_pipe_client_pid_(pipe_, &pid)) {
if (!get_named_pipe_client_pid_(pipe_.Get(), &pid)) {
PLOG(ERROR) << "Failed to retrive PID of the client";
ReportFatalError();
return;
......@@ -380,7 +380,7 @@ void WtsSessionProcessDelegate::Core::DoLaunchProcess() {
// Wrap the pipe into an IPC channel.
scoped_ptr<IPC::ChannelProxy> channel(
IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe),
IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe.Get()),
IPC::Channel::MODE_SERVER,
this,
io_task_runner_));
......@@ -394,7 +394,7 @@ void WtsSessionProcessDelegate::Core::DoLaunchProcess() {
ScopedHandle worker_thread;
if (!LaunchProcessWithToken(command_line.GetProgram(),
command_line.GetCommandLineString(),
session_token_,
session_token_.Get(),
NULL,
NULL,
false,
......@@ -407,14 +407,14 @@ void WtsSessionProcessDelegate::Core::DoLaunchProcess() {
}
if (launch_elevated_) {
if (!AssignProcessToJobObject(job_, worker_process)) {
if (!AssignProcessToJobObject(job_.Get(), worker_process.Get())) {
PLOG(ERROR) << "Failed to assign the worker to the job object";
ReportFatalError();
return;
}
}
if (!ResumeThread(worker_thread)) {
if (!ResumeThread(worker_thread.Get())) {
PLOG(ERROR) << "Failed to resume the worker thread";
ReportFatalError();
return;
......@@ -513,7 +513,7 @@ void WtsSessionProcessDelegate::Core::ReportProcessLaunched(
SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION;
HANDLE temp_handle;
if (!DuplicateHandle(GetCurrentProcess(),
worker_process_,
worker_process_.Get(),
GetCurrentProcess(),
&temp_handle,
desired_access,
......
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