| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "util/win/exception_handler_server.h" | 15 #include "util/win/exception_handler_server.h" |
| 16 | 16 |
| 17 #include <string.h> | 17 #include <string.h> |
| 18 | 18 |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "minidump/minidump_file_writer.h" | 23 #include "minidump/minidump_file_writer.h" |
| 24 #include "snapshot/crashpad_info_client_options.h" | 24 #include "snapshot/crashpad_info_client_options.h" |
| 25 #include "snapshot/win/process_snapshot_win.h" | 25 #include "snapshot/win/process_snapshot_win.h" |
| 26 #include "util/file/file_writer.h" | 26 #include "util/file/file_writer.h" |
| 27 #include "util/misc/tri_state.h" | 27 #include "util/misc/tri_state.h" |
| 28 #include "util/misc/uuid.h" | 28 #include "util/misc/uuid.h" |
| 29 #include "util/win/registration_protocol_win.h" | 29 #include "util/win/registration_protocol_win.h" |
| 30 #include "util/win/xp_compat.h" |
| 30 | 31 |
| 31 namespace crashpad { | 32 namespace crashpad { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 decltype(GetNamedPipeClientProcessId)* GetNamedPipeClientProcessIdFunction() { | 36 decltype(GetNamedPipeClientProcessId)* GetNamedPipeClientProcessIdFunction() { |
| 36 static decltype(GetNamedPipeClientProcessId)* func = | 37 static decltype(GetNamedPipeClientProcessId)* func = |
| 37 reinterpret_cast<decltype(GetNamedPipeClientProcessId)*>(GetProcAddress( | 38 reinterpret_cast<decltype(GetNamedPipeClientProcessId)*>(GetProcAddress( |
| 38 GetModuleHandle(L"kernel32.dll"), "GetNamedPipeClientProcessId")); | 39 GetModuleHandle(L"kernel32.dll"), "GetNamedPipeClientProcessId")); |
| 39 return func; | 40 return func; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return false; | 336 return false; |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 | 339 |
| 339 // We attempt to open the process as us. This is the main case that should | 340 // We attempt to open the process as us. This is the main case that should |
| 340 // almost always succeed as the server will generally be more privileged. If | 341 // almost always succeed as the server will generally be more privileged. If |
| 341 // we're running as a different user, it may be that we will fail to open | 342 // we're running as a different user, it may be that we will fail to open |
| 342 // the process, but the client will be able to, so we make a second attempt | 343 // the process, but the client will be able to, so we make a second attempt |
| 343 // having impersonated the client. | 344 // having impersonated the client. |
| 344 HANDLE client_process = OpenProcess( | 345 HANDLE client_process = OpenProcess( |
| 345 PROCESS_ALL_ACCESS, false, message.registration.client_process_id); | 346 kXPProcessAllAccess, false, message.registration.client_process_id); |
| 346 if (!client_process) { | 347 if (!client_process) { |
| 347 if (!ImpersonateNamedPipeClient(service_context.pipe())) { | 348 if (!ImpersonateNamedPipeClient(service_context.pipe())) { |
| 348 PLOG(ERROR) << "ImpersonateNamedPipeClient"; | 349 PLOG(ERROR) << "ImpersonateNamedPipeClient"; |
| 349 return false; | 350 return false; |
| 350 } | 351 } |
| 351 HANDLE client_process = OpenProcess( | 352 HANDLE client_process = OpenProcess( |
| 352 PROCESS_ALL_ACCESS, false, message.registration.client_process_id); | 353 kXPProcessAllAccess, false, message.registration.client_process_id); |
| 353 PCHECK(RevertToSelf()); | 354 PCHECK(RevertToSelf()); |
| 354 if (!client_process) { | 355 if (!client_process) { |
| 355 LOG(ERROR) << "failed to open " << message.registration.client_process_id; | 356 LOG(ERROR) << "failed to open " << message.registration.client_process_id; |
| 356 return false; | 357 return false; |
| 357 } | 358 } |
| 358 } | 359 } |
| 359 | 360 |
| 360 internal::ClientData* client; | 361 internal::ClientData* client; |
| 361 { | 362 { |
| 362 base::AutoLock lock(*service_context.clients_lock()); | 363 base::AutoLock lock(*service_context.clients_lock()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { | 420 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { |
| 420 // This function is executed on the thread pool. | 421 // This function is executed on the thread pool. |
| 421 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); | 422 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); |
| 422 base::AutoLock lock(*client->lock()); | 423 base::AutoLock lock(*client->lock()); |
| 423 | 424 |
| 424 // Post back to the main thread to have it delete this client record. | 425 // Post back to the main thread to have it delete this client record. |
| 425 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); | 426 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); |
| 426 } | 427 } |
| 427 | 428 |
| 428 } // namespace crashpad | 429 } // namespace crashpad |
| OLD | NEW |