Robert Sesek | b1cd8fe1a | 2018-08-21 18:32:53 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "sandbox/mac/system_services.h" |
| 6 | |
| 7 | #include <Carbon/Carbon.h> |
| 8 | #include <CoreFoundation/CoreFoundation.h> |
| 9 | |
| 10 | #include "base/mac/mac_logging.h" |
| 11 | |
| 12 | extern "C" { |
| 13 | OSStatus SetApplicationIsDaemon(Boolean isDaemon); |
| 14 | void _LSSetApplicationLaunchServicesServerConnectionStatus( |
| 15 | uint64_t flags, |
| 16 | bool (^connection_allowed)(CFDictionaryRef options)); |
Robert Sesek | edfd32d | 2020-09-10 18:38:32 | [diff] [blame] | 17 | |
| 18 | // See |
| 19 | // https://github.com/WebKit/webkit/commit/8da694b0b3febcc262653d01a45e946ce91845ed. |
| 20 | void _CSCheckFixDisable() API_AVAILABLE(macosx(10.15)); |
Robert Sesek | b1cd8fe1a | 2018-08-21 18:32:53 | [diff] [blame] | 21 | } // extern "C" |
| 22 | |
| 23 | namespace sandbox { |
| 24 | |
| 25 | void DisableLaunchServices() { |
| 26 | // Allow the process to continue without a LaunchServices ASN. The |
| 27 | // INIT_Process function in HIServices will abort if it cannot connect to |
| 28 | // launchservicesd to get an ASN. By setting this flag, HIServices skips |
| 29 | // that. |
| 30 | OSStatus status = SetApplicationIsDaemon(true); |
| 31 | OSSTATUS_LOG_IF(ERROR, status != noErr, status) << "SetApplicationIsDaemon"; |
| 32 | |
| 33 | // Close any connections to launchservicesd and use an always-false predicate |
| 34 | // to discourage future attempts to connect. |
| 35 | _LSSetApplicationLaunchServicesServerConnectionStatus( |
| 36 | 0, ^bool(CFDictionaryRef options) { |
| 37 | return false; |
| 38 | }); |
| 39 | } |
| 40 | |
Robert Sesek | edfd32d | 2020-09-10 18:38:32 | [diff] [blame] | 41 | void DisableCoreServicesCheckFix() { |
| 42 | if (__builtin_available(macOS 10.15, *)) { |
| 43 | _CSCheckFixDisable(); |
| 44 | } |
| 45 | } |
| 46 | |
Robert Sesek | b1cd8fe1a | 2018-08-21 18:32:53 | [diff] [blame] | 47 | } // namespace sandbox |