OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/mac/cfbundle_blocker.h" | 5 #include "chrome/common/mac/cfbundle_blocker.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 base::mac::CFToNSCast(kCFBundleVersionKey)]; | 168 base::mac::CFToNSCast(kCFBundleVersionKey)]; |
169 if (![version isKindOfClass:[NSString class]]) { | 169 if (![version isKindOfClass:[NSString class]]) { |
170 // Deal with pranksters. | 170 // Deal with pranksters. |
171 version = nil; | 171 version = nil; |
172 } | 172 } |
173 | 173 |
174 if (IsBundlePathBlocked(path) && !IsBundleAllowed(bundle_id, version)) { | 174 if (IsBundlePathBlocked(path) && !IsBundleAllowed(bundle_id, version)) { |
175 NSString* bundle_id_print = bundle_id ? bundle_id : @"(nil)"; | 175 NSString* bundle_id_print = bundle_id ? bundle_id : @"(nil)"; |
176 NSString* version_print = version ? version : @"(nil)"; | 176 NSString* version_print = version ? version : @"(nil)"; |
177 | 177 |
178 LOG(INFO) << "Blocking attempt to load bundle " | 178 DLOG(INFO) << "Blocking attempt to load bundle " |
179 << [bundle_id_print UTF8String] | 179 << [bundle_id_print UTF8String] |
180 << " version " | 180 << " version " |
181 << [version_print UTF8String] | 181 << [version_print UTF8String] |
182 << " at " | 182 << " at " |
183 << [path fileSystemRepresentation]; | 183 << [path fileSystemRepresentation]; |
184 | 184 |
185 if (error) { | 185 if (error) { |
186 base::mac::ScopedCFTypeRef<CFStringRef> app_bundle_id( | 186 base::mac::ScopedCFTypeRef<CFStringRef> app_bundle_id( |
187 base::SysUTF8ToCFStringRef(base::mac::BaseBundleID())); | 187 base::SysUTF8ToCFStringRef(base::mac::BaseBundleID())); |
188 | 188 |
189 // 0xb10c10ad = "block load" | 189 // 0xb10c10ad = "block load" |
190 const CFIndex kBundleLoadBlocked = 0xb10c10ad; | 190 const CFIndex kBundleLoadBlocked = 0xb10c10ad; |
191 | 191 |
192 NSMutableDictionary* error_dict = | 192 NSMutableDictionary* error_dict = |
193 [NSMutableDictionary dictionaryWithCapacity:4]; | 193 [NSMutableDictionary dictionaryWithCapacity:4]; |
(...skipping 28 matching lines...) Expand all Loading... |
222 | 222 |
223 } // namespace | 223 } // namespace |
224 | 224 |
225 void EnableCFBundleBlocker() { | 225 void EnableCFBundleBlocker() { |
226 mach_error_t err = mach_override_ptr( | 226 mach_error_t err = mach_override_ptr( |
227 reinterpret_cast<void*>(_CFBundleLoadExecutableAndReturnError), | 227 reinterpret_cast<void*>(_CFBundleLoadExecutableAndReturnError), |
228 reinterpret_cast<void*>(ChromeCFBundleLoadExecutableAndReturnError), | 228 reinterpret_cast<void*>(ChromeCFBundleLoadExecutableAndReturnError), |
229 reinterpret_cast<void**>( | 229 reinterpret_cast<void**>( |
230 &g_original_underscore_cfbundle_load_executable_and_return_error)); | 230 &g_original_underscore_cfbundle_load_executable_and_return_error)); |
231 if (err != err_none) { | 231 if (err != err_none) { |
232 LOG(WARNING) << "mach_override _CFBundleLoadExecutableAndReturnError: " | 232 DLOG(WARNING) << "mach_override _CFBundleLoadExecutableAndReturnError: " |
233 << err; | 233 << err; |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 namespace { | 237 namespace { |
238 | 238 |
239 struct AllowedBundle { | 239 struct AllowedBundle { |
240 // The bundle identifier to permit. These are matched with a case-sensitive | 240 // The bundle identifier to permit. These are matched with a case-sensitive |
241 // literal comparison. "Children" of the declared bundle ID are permitted: | 241 // literal comparison. "Children" of the declared bundle ID are permitted: |
242 // if bundle_id here is @"org.chromium", it would match both @"org.chromium" | 242 // if bundle_id here is @"org.chromium", it would match both @"org.chromium" |
243 // and @"org.chromium.Chromium". | 243 // and @"org.chromium.Chromium". |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 // Nothing matched. | 324 // Nothing matched. |
325 return false; | 325 return false; |
326 } | 326 } |
327 | 327 |
328 } // namespace mac | 328 } // namespace mac |
329 } // namespace common | 329 } // namespace common |
330 } // namespace chrome | 330 } // namespace chrome |
OLD | NEW |