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/browser/policy/policy_path_parser.h" | 5 #include "chrome/browser/policy/policy_path_parser.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 | 9 |
10 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
| 11 #import <SystemConfiguration/SCDynamicStore.h> |
| 12 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h> |
11 | 13 |
12 #include <string> | 14 #include <string> |
13 | 15 |
14 namespace policy { | 16 namespace policy { |
15 | 17 |
16 namespace path_parser { | 18 namespace path_parser { |
17 | 19 |
18 const char* kUserNamePolicyVarName = "${user_name}"; | 20 const char* kUserNamePolicyVarName = "${user_name}"; |
19 const char* kMachineNamePolicyVarName = "${machine_name}"; | 21 const char* kMachineNamePolicyVarName = "${machine_name}"; |
20 const char* kMacUsersDirectory = "${users}"; | 22 const char* kMacUsersDirectory = "${users}"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 NSString* username = NSUserName(); | 57 NSString* username = NSUserName(); |
56 if (username) { | 58 if (username) { |
57 result.replace(position, strlen(kUserNamePolicyVarName), | 59 result.replace(position, strlen(kUserNamePolicyVarName), |
58 base::SysNSStringToUTF8(username)); | 60 base::SysNSStringToUTF8(username)); |
59 } else { | 61 } else { |
60 LOG(ERROR) << "Username variable can not be resolved."; | 62 LOG(ERROR) << "Username variable can not be resolved."; |
61 } | 63 } |
62 } | 64 } |
63 position = result.find(kMachineNamePolicyVarName); | 65 position = result.find(kMachineNamePolicyVarName); |
64 if (position != std::string::npos) { | 66 if (position != std::string::npos) { |
65 NSString* machinename = [[NSHost currentHost] name]; | 67 SCDynamicStoreContext context = { 0, NULL, NULL, NULL }; |
| 68 SCDynamicStoreRef store = SCDynamicStoreCreate(kCFAllocatorDefault, |
| 69 CFSTR("policy_subsystem"), |
| 70 NULL, &context); |
| 71 CFStringRef machinename = SCDynamicStoreCopyLocalHostName(store); |
66 if (machinename) { | 72 if (machinename) { |
67 result.replace(position, strlen(kMachineNamePolicyVarName), | 73 result.replace(position, strlen(kMachineNamePolicyVarName), |
68 base::SysNSStringToUTF8(machinename)); | 74 base::SysCFStringRefToUTF8(machinename)); |
| 75 CFRelease(machinename); |
69 } else { | 76 } else { |
70 LOG(ERROR) << "Machine name variable can not be resolved."; | 77 LOG(ERROR) << "Machine name variable can not be resolved."; |
71 } | 78 } |
| 79 CFRelease(store); |
72 } | 80 } |
73 return result; | 81 return result; |
74 } | 82 } |
75 | 83 |
76 } // namespace path_parser | 84 } // namespace path_parser |
77 | 85 |
78 } // namespace policy | 86 } // namespace policy |
OLD | NEW |