Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER |
| 18 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 19 | #include "VoldNativeService.h" |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 20 | #include "Benchmark.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 21 | #include "CheckEncryption.h" |
| 22 | #include "IdleMaint.h" |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 23 | #include "MoveStorage.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 24 | #include "Process.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 25 | #include "VolumeManager.h" |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 26 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 27 | #include "cryptfs.h" |
| 28 | #include "Ext4Crypt.h" |
| 29 | #include "MetadataCrypt.h" |
| 30 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 31 | #include <fstream> |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 32 | #include <thread> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 33 | |
| 34 | #include <android-base/logging.h> |
| 35 | #include <android-base/stringprintf.h> |
| 36 | #include <android-base/strings.h> |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 37 | #include <ext4_utils/ext4_crypt.h> |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 38 | #include <fs_mgr.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 39 | #include <private/android_filesystem_config.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 40 | #include <utils/Trace.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 41 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 42 | using android::base::StringPrintf; |
| 43 | using std::endl; |
| 44 | |
| 45 | namespace android { |
| 46 | namespace vold { |
| 47 | |
| 48 | namespace { |
| 49 | |
| 50 | constexpr const char* kDump = "android.permission.DUMP"; |
| 51 | |
| 52 | static binder::Status ok() { |
| 53 | return binder::Status::ok(); |
| 54 | } |
| 55 | |
| 56 | static binder::Status exception(uint32_t code, const std::string& msg) { |
| 57 | return binder::Status::fromExceptionCode(code, String8(msg.c_str())); |
| 58 | } |
| 59 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 60 | static binder::Status error(const std::string& msg) { |
| 61 | PLOG(ERROR) << msg; |
| 62 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 63 | } |
| 64 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 65 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 66 | if (status == 0) { |
| 67 | return binder::Status::ok(); |
| 68 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 69 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 73 | static binder::Status translateBool(bool status) { |
| 74 | if (status) { |
| 75 | return binder::Status::ok(); |
| 76 | } else { |
| 77 | return binder::Status::fromServiceSpecificError(status); |
| 78 | } |
| 79 | } |
| 80 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 81 | binder::Status checkPermission(const char* permission) { |
| 82 | pid_t pid; |
| 83 | uid_t uid; |
| 84 | |
| 85 | if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid), |
| 86 | reinterpret_cast<int32_t*>(&uid))) { |
| 87 | return ok(); |
| 88 | } else { |
| 89 | return exception(binder::Status::EX_SECURITY, |
| 90 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission)); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | binder::Status checkUid(uid_t expectedUid) { |
| 95 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 96 | if (uid == expectedUid || uid == AID_ROOT) { |
| 97 | return ok(); |
| 98 | } else { |
| 99 | return exception(binder::Status::EX_SECURITY, |
| 100 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
| 101 | } |
| 102 | } |
| 103 | |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 104 | binder::Status checkArgumentId(const std::string& id) { |
| 105 | if (id.empty()) { |
| 106 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing ID"); |
| 107 | } |
| 108 | for (const char& c : id) { |
| 109 | if (!std::isalnum(c) && c != ':' && c != ',') { |
| 110 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 111 | StringPrintf("ID %s is malformed", id.c_str())); |
| 112 | } |
| 113 | } |
| 114 | return ok(); |
| 115 | } |
| 116 | |
| 117 | binder::Status checkArgumentPath(const std::string& path) { |
| 118 | if (path.empty()) { |
| 119 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing path"); |
| 120 | } |
| 121 | if (path[0] != '/') { |
| 122 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 123 | StringPrintf("Path %s is relative", path.c_str())); |
| 124 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 125 | if ((path + '/').find("/../") != std::string::npos) { |
| 126 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 127 | StringPrintf("Path %s is shady", path.c_str())); |
| 128 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 129 | for (const char& c : path) { |
| 130 | if (c == '\0' || c == '\n') { |
| 131 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 132 | StringPrintf("Path %s is malformed", path.c_str())); |
| 133 | } |
| 134 | } |
| 135 | return ok(); |
| 136 | } |
| 137 | |
| 138 | binder::Status checkArgumentHex(const std::string& hex) { |
| 139 | // Empty hex strings are allowed |
| 140 | for (const char& c : hex) { |
| 141 | if (!std::isxdigit(c) && c != ':' && c != '-') { |
| 142 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 143 | StringPrintf("Hex %s is malformed", hex.c_str())); |
| 144 | } |
| 145 | } |
| 146 | return ok(); |
| 147 | } |
| 148 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 149 | #define ENFORCE_UID(uid) { \ |
| 150 | binder::Status status = checkUid((uid)); \ |
| 151 | if (!status.isOk()) { \ |
| 152 | return status; \ |
| 153 | } \ |
| 154 | } |
| 155 | |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 156 | #define CHECK_ARGUMENT_ID(id) { \ |
| 157 | binder::Status status = checkArgumentId((id)); \ |
| 158 | if (!status.isOk()) { \ |
| 159 | return status; \ |
| 160 | } \ |
| 161 | } |
| 162 | |
| 163 | #define CHECK_ARGUMENT_PATH(path) { \ |
| 164 | binder::Status status = checkArgumentPath((path)); \ |
| 165 | if (!status.isOk()) { \ |
| 166 | return status; \ |
| 167 | } \ |
| 168 | } |
| 169 | |
| 170 | #define CHECK_ARGUMENT_HEX(hex) { \ |
| 171 | binder::Status status = checkArgumentHex((hex)); \ |
| 172 | if (!status.isOk()) { \ |
| 173 | return status; \ |
| 174 | } \ |
| 175 | } |
| 176 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 177 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 178 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 179 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 180 | |
| 181 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 182 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 183 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 184 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 185 | } // namespace |
| 186 | |
| 187 | status_t VoldNativeService::start() { |
| 188 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 189 | status_t ret = BinderService<VoldNativeService>::publish(); |
| 190 | if (ret != android::OK) { |
| 191 | return ret; |
| 192 | } |
| 193 | sp<ProcessState> ps(ProcessState::self()); |
| 194 | ps->startThreadPool(); |
| 195 | ps->giveThreadPoolName(); |
| 196 | return android::OK; |
| 197 | } |
| 198 | |
| 199 | status_t VoldNativeService::dump(int fd, const Vector<String16> & /* args */) { |
| 200 | auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd)); |
| 201 | const binder::Status dump_permission = checkPermission(kDump); |
| 202 | if (!dump_permission.isOk()) { |
| 203 | out << dump_permission.toString8() << endl; |
| 204 | return PERMISSION_DENIED; |
| 205 | } |
| 206 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 207 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 208 | out << "vold is happy!" << endl; |
| 209 | out.flush(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 210 | return NO_ERROR; |
| 211 | } |
| 212 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 213 | binder::Status VoldNativeService::setListener( |
| 214 | const android::sp<android::os::IVoldListener>& listener) { |
| 215 | ENFORCE_UID(AID_SYSTEM); |
| 216 | ACQUIRE_LOCK; |
| 217 | |
| 218 | VolumeManager::Instance()->setListener(listener); |
| 219 | return ok(); |
| 220 | } |
| 221 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 222 | binder::Status VoldNativeService::monitor() { |
| 223 | ENFORCE_UID(AID_SYSTEM); |
| 224 | |
| 225 | // Simply acquire/release each lock for watchdog |
| 226 | { |
| 227 | ACQUIRE_LOCK; |
| 228 | } |
| 229 | { |
| 230 | ACQUIRE_CRYPT_LOCK; |
| 231 | } |
| 232 | |
| 233 | return ok(); |
| 234 | } |
| 235 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 236 | binder::Status VoldNativeService::reset() { |
| 237 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 238 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 239 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 240 | return translate(VolumeManager::Instance()->reset()); |
| 241 | } |
| 242 | |
| 243 | binder::Status VoldNativeService::shutdown() { |
| 244 | ENFORCE_UID(AID_SYSTEM); |
| 245 | ACQUIRE_LOCK; |
| 246 | |
| 247 | return translate(VolumeManager::Instance()->shutdown()); |
| 248 | } |
| 249 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 250 | // TODO: sanity-check these string arguments |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 251 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
| 252 | ENFORCE_UID(AID_SYSTEM); |
| 253 | ACQUIRE_LOCK; |
| 254 | |
| 255 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 256 | } |
| 257 | |
| 258 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
| 259 | ENFORCE_UID(AID_SYSTEM); |
| 260 | ACQUIRE_LOCK; |
| 261 | |
| 262 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 263 | } |
| 264 | |
Sudheer Shanka | ebaad1c | 2018-07-31 16:39:59 -0700 | [diff] [blame] | 265 | binder::Status VoldNativeService::onUserStarted(int32_t userId, |
| 266 | const std::vector<std::string>& packageNames) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 267 | ENFORCE_UID(AID_SYSTEM); |
| 268 | ACQUIRE_LOCK; |
| 269 | |
Sudheer Shanka | ebaad1c | 2018-07-31 16:39:59 -0700 | [diff] [blame] | 270 | return translate(VolumeManager::Instance()->onUserStarted(userId, packageNames)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
| 274 | ENFORCE_UID(AID_SYSTEM); |
| 275 | ACQUIRE_LOCK; |
| 276 | |
| 277 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 278 | } |
| 279 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 280 | // TODO: sanity-check these string arguments |
| 281 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
| 282 | const std::vector<int32_t>& appIds) { |
| 283 | ENFORCE_UID(AID_SYSTEM); |
| 284 | ACQUIRE_LOCK; |
| 285 | |
| 286 | return translate(VolumeManager::Instance()->addAppIds(packageNames, appIds)); |
| 287 | } |
| 288 | |
| 289 | // TODO: sanity-check these string arguments |
| 290 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
| 291 | const std::vector<std::string>& sandboxIds) { |
| 292 | ENFORCE_UID(AID_SYSTEM); |
| 293 | ACQUIRE_LOCK; |
| 294 | |
| 295 | return translate(VolumeManager::Instance()->addSandboxIds(appIds, sandboxIds)); |
| 296 | } |
| 297 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 298 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
| 299 | ENFORCE_UID(AID_SYSTEM); |
| 300 | ACQUIRE_LOCK; |
| 301 | |
| 302 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 303 | } |
| 304 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 305 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
| 306 | int32_t ratio) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 307 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 308 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 309 | ACQUIRE_LOCK; |
| 310 | |
| 311 | auto disk = VolumeManager::Instance()->findDisk(diskId); |
| 312 | if (disk == nullptr) { |
| 313 | return error("Failed to find disk " + diskId); |
| 314 | } |
| 315 | switch (partitionType) { |
| 316 | case PARTITION_TYPE_PUBLIC: return translate(disk->partitionPublic()); |
| 317 | case PARTITION_TYPE_PRIVATE: return translate(disk->partitionPrivate()); |
| 318 | case PARTITION_TYPE_MIXED: return translate(disk->partitionMixed(ratio)); |
| 319 | default: return error("Unknown type " + std::to_string(partitionType)); |
| 320 | } |
| 321 | } |
| 322 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 323 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
| 324 | const std::string& fsUuid) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 325 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 326 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 327 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 328 | ACQUIRE_LOCK; |
| 329 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 330 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 331 | } |
| 332 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 333 | binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags, |
| 334 | int32_t mountUserId) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 335 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 336 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 337 | ACQUIRE_LOCK; |
| 338 | |
| 339 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 340 | if (vol == nullptr) { |
| 341 | return error("Failed to find volume " + volId); |
| 342 | } |
| 343 | |
| 344 | vol->setMountFlags(mountFlags); |
| 345 | vol->setMountUserId(mountUserId); |
| 346 | |
| 347 | int res = vol->mount(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 348 | if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 349 | VolumeManager::Instance()->setPrimary(vol); |
| 350 | } |
| 351 | return translate(res); |
| 352 | } |
| 353 | |
| 354 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
| 355 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 356 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 357 | ACQUIRE_LOCK; |
| 358 | |
| 359 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 360 | if (vol == nullptr) { |
| 361 | return error("Failed to find volume " + volId); |
| 362 | } |
| 363 | return translate(vol->unmount()); |
| 364 | } |
| 365 | |
| 366 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
| 367 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 368 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 369 | ACQUIRE_LOCK; |
| 370 | |
| 371 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 372 | if (vol == nullptr) { |
| 373 | return error("Failed to find volume " + volId); |
| 374 | } |
| 375 | return translate(vol->format(fsType)); |
| 376 | } |
| 377 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 378 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 379 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 380 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 381 | } else { |
| 382 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 383 | if (vol == nullptr) { |
| 384 | return error("Failed to find volume " + volId); |
| 385 | } |
| 386 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 387 | return error("Volume " + volId + " not private"); |
| 388 | } |
| 389 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 390 | return error("Volume " + volId + " not mounted"); |
| 391 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 392 | *path = vol->getPath(); |
| 393 | if (path->empty()) { |
| 394 | return error("Volume " + volId + " missing path"); |
| 395 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 396 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 397 | return ok(); |
| 398 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 399 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 400 | binder::Status VoldNativeService::benchmark( |
| 401 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
| 402 | ENFORCE_UID(AID_SYSTEM); |
| 403 | CHECK_ARGUMENT_ID(volId); |
| 404 | ACQUIRE_LOCK; |
| 405 | |
| 406 | std::string path; |
| 407 | auto status = pathForVolId(volId, &path); |
| 408 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 409 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 410 | std::thread([=]() { |
| 411 | android::vold::Benchmark(path, listener); |
| 412 | }).detach(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 413 | return ok(); |
| 414 | } |
| 415 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 416 | binder::Status VoldNativeService::checkEncryption(const std::string& volId) { |
| 417 | ENFORCE_UID(AID_SYSTEM); |
| 418 | CHECK_ARGUMENT_ID(volId); |
| 419 | ACQUIRE_LOCK; |
| 420 | |
| 421 | std::string path; |
| 422 | auto status = pathForVolId(volId, &path); |
| 423 | if (!status.isOk()) return status; |
| 424 | return translate(android::vold::CheckEncryption(path)); |
| 425 | } |
| 426 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 427 | binder::Status VoldNativeService::moveStorage(const std::string& fromVolId, |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 428 | const std::string& toVolId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 429 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 430 | CHECK_ARGUMENT_ID(fromVolId); |
| 431 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 432 | ACQUIRE_LOCK; |
| 433 | |
| 434 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 435 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 436 | if (fromVol == nullptr) { |
| 437 | return error("Failed to find volume " + fromVolId); |
| 438 | } else if (toVol == nullptr) { |
| 439 | return error("Failed to find volume " + toVolId); |
| 440 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 441 | |
| 442 | std::thread([=]() { |
| 443 | android::vold::MoveStorage(fromVol, toVol, listener); |
| 444 | }).detach(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 445 | return ok(); |
| 446 | } |
| 447 | |
| 448 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
| 449 | ENFORCE_UID(AID_SYSTEM); |
| 450 | ACQUIRE_LOCK; |
| 451 | |
| 452 | std::string tmp; |
| 453 | switch (remountMode) { |
| 454 | case REMOUNT_MODE_NONE: tmp = "none"; break; |
| 455 | case REMOUNT_MODE_DEFAULT: tmp = "default"; break; |
| 456 | case REMOUNT_MODE_READ: tmp = "read"; break; |
| 457 | case REMOUNT_MODE_WRITE: tmp = "write"; break; |
| 458 | default: return error("Unknown mode " + std::to_string(remountMode)); |
| 459 | } |
| 460 | return translate(VolumeManager::Instance()->remountUid(uid, tmp)); |
| 461 | } |
| 462 | |
| 463 | binder::Status VoldNativeService::mkdirs(const std::string& path) { |
| 464 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 465 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 466 | ACQUIRE_LOCK; |
| 467 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 468 | return translate(VolumeManager::Instance()->mkdirs(path)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 469 | } |
| 470 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 471 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
| 472 | const std::string& sourceKey, int32_t ownerGid, std::string* _aidl_return) { |
| 473 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 474 | CHECK_ARGUMENT_PATH(sourcePath); |
| 475 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 476 | ACQUIRE_LOCK; |
| 477 | |
| 478 | return translate( |
| 479 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
| 480 | } |
| 481 | |
| 482 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
| 483 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 484 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 485 | ACQUIRE_LOCK; |
| 486 | |
| 487 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 488 | } |
| 489 | |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 490 | binder::Status VoldNativeService::fstrim(int32_t fstrimFlags, |
| 491 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 492 | ENFORCE_UID(AID_SYSTEM); |
| 493 | ACQUIRE_LOCK; |
| 494 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 495 | std::thread([=]() { |
| 496 | android::vold::Trim(listener); |
| 497 | }).detach(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 498 | return ok(); |
| 499 | } |
| 500 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 501 | binder::Status VoldNativeService::runIdleMaint( |
| 502 | const android::sp<android::os::IVoldTaskListener>& listener) { |
| 503 | ENFORCE_UID(AID_SYSTEM); |
| 504 | ACQUIRE_LOCK; |
| 505 | |
| 506 | std::thread([=]() { |
| 507 | android::vold::RunIdleMaint(listener); |
| 508 | }).detach(); |
| 509 | return ok(); |
| 510 | } |
| 511 | |
| 512 | binder::Status VoldNativeService::abortIdleMaint( |
| 513 | const android::sp<android::os::IVoldTaskListener>& listener) { |
| 514 | ENFORCE_UID(AID_SYSTEM); |
| 515 | ACQUIRE_LOCK; |
| 516 | |
| 517 | std::thread([=]() { |
| 518 | android::vold::AbortIdleMaint(listener); |
| 519 | }).detach(); |
| 520 | return ok(); |
| 521 | } |
| 522 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 523 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId, |
| 524 | android::base::unique_fd* _aidl_return) { |
| 525 | ENFORCE_UID(AID_SYSTEM); |
| 526 | ACQUIRE_LOCK; |
| 527 | |
| 528 | return translate(VolumeManager::Instance()->mountAppFuse(uid, pid, mountId, _aidl_return)); |
| 529 | } |
| 530 | |
| 531 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId) { |
| 532 | ENFORCE_UID(AID_SYSTEM); |
| 533 | ACQUIRE_LOCK; |
| 534 | |
| 535 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, pid, mountId)); |
| 536 | } |
| 537 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 538 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
| 539 | ENFORCE_UID(AID_SYSTEM); |
| 540 | ACQUIRE_CRYPT_LOCK; |
| 541 | |
| 542 | return translate(cryptfs_check_passwd(password.c_str())); |
| 543 | } |
| 544 | |
| 545 | binder::Status VoldNativeService::fdeRestart() { |
| 546 | ENFORCE_UID(AID_SYSTEM); |
| 547 | ACQUIRE_CRYPT_LOCK; |
| 548 | |
| 549 | // Spawn as thread so init can issue commands back to vold without |
| 550 | // causing deadlock, usually as a result of prep_data_fs. |
| 551 | std::thread(&cryptfs_restart).detach(); |
| 552 | return ok(); |
| 553 | } |
| 554 | |
| 555 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
| 556 | ENFORCE_UID(AID_SYSTEM); |
| 557 | ACQUIRE_CRYPT_LOCK; |
| 558 | |
| 559 | *_aidl_return = cryptfs_crypto_complete(); |
| 560 | return ok(); |
| 561 | } |
| 562 | |
| 563 | static int fdeEnableInternal(int32_t passwordType, const std::string& password, |
| 564 | int32_t encryptionFlags) { |
| 565 | bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0; |
| 566 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 567 | for (int tries = 0; tries < 2; ++tries) { |
| 568 | int rc; |
| 569 | if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 570 | rc = cryptfs_enable_default(noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 571 | } else { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 572 | rc = cryptfs_enable(passwordType, password.c_str(), noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | if (rc == 0) { |
| 576 | return 0; |
| 577 | } else if (tries == 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 578 | KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
| 582 | return -1; |
| 583 | } |
| 584 | |
| 585 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, |
| 586 | const std::string& password, int32_t encryptionFlags) { |
| 587 | ENFORCE_UID(AID_SYSTEM); |
| 588 | ACQUIRE_CRYPT_LOCK; |
| 589 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 590 | LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 591 | if (e4crypt_is_native()) { |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 592 | LOG(ERROR) << "e4crypt_is_native, fdeEnable invalid"; |
| 593 | return error("e4crypt_is_native, fdeEnable invalid"); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 594 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 595 | LOG(DEBUG) << "!e4crypt_is_native, spawning fdeEnableInternal"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 596 | |
| 597 | // Spawn as thread so init can issue commands back to vold without |
| 598 | // causing deadlock, usually as a result of prep_data_fs. |
| 599 | std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach(); |
| 600 | return ok(); |
| 601 | } |
| 602 | |
| 603 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
| 604 | const std::string& password) { |
| 605 | ENFORCE_UID(AID_SYSTEM); |
| 606 | ACQUIRE_CRYPT_LOCK; |
| 607 | |
| 608 | return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 609 | } |
| 610 | |
| 611 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
| 612 | ENFORCE_UID(AID_SYSTEM); |
| 613 | ACQUIRE_CRYPT_LOCK; |
| 614 | |
| 615 | return translate(cryptfs_verify_passwd(password.c_str())); |
| 616 | } |
| 617 | |
| 618 | binder::Status VoldNativeService::fdeGetField(const std::string& key, |
| 619 | std::string* _aidl_return) { |
| 620 | ENFORCE_UID(AID_SYSTEM); |
| 621 | ACQUIRE_CRYPT_LOCK; |
| 622 | |
| 623 | char buf[PROPERTY_VALUE_MAX]; |
| 624 | if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) { |
| 625 | return error(StringPrintf("Failed to read field %s", key.c_str())); |
| 626 | } else { |
| 627 | *_aidl_return = buf; |
| 628 | return ok(); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | binder::Status VoldNativeService::fdeSetField(const std::string& key, |
| 633 | const std::string& value) { |
| 634 | ENFORCE_UID(AID_SYSTEM); |
| 635 | ACQUIRE_CRYPT_LOCK; |
| 636 | |
| 637 | return translate(cryptfs_setfield(key.c_str(), value.c_str())); |
| 638 | } |
| 639 | |
| 640 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
| 641 | ENFORCE_UID(AID_SYSTEM); |
| 642 | ACQUIRE_CRYPT_LOCK; |
| 643 | |
| 644 | *_aidl_return = cryptfs_get_password_type(); |
| 645 | return ok(); |
| 646 | } |
| 647 | |
| 648 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
| 649 | ENFORCE_UID(AID_SYSTEM); |
| 650 | ACQUIRE_CRYPT_LOCK; |
| 651 | |
| 652 | const char* res = cryptfs_get_password(); |
| 653 | if (res != nullptr) { |
| 654 | *_aidl_return = res; |
| 655 | } |
| 656 | return ok(); |
| 657 | } |
| 658 | |
| 659 | binder::Status VoldNativeService::fdeClearPassword() { |
| 660 | ENFORCE_UID(AID_SYSTEM); |
| 661 | ACQUIRE_CRYPT_LOCK; |
| 662 | |
| 663 | cryptfs_clear_password(); |
| 664 | return ok(); |
| 665 | } |
| 666 | |
| 667 | binder::Status VoldNativeService::fbeEnable() { |
| 668 | ENFORCE_UID(AID_SYSTEM); |
| 669 | ACQUIRE_CRYPT_LOCK; |
| 670 | |
| 671 | return translateBool(e4crypt_initialize_global_de()); |
| 672 | } |
| 673 | |
| 674 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
| 675 | ENFORCE_UID(AID_SYSTEM); |
| 676 | ACQUIRE_CRYPT_LOCK; |
| 677 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 678 | if (!e4crypt_is_native()) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 679 | // Spawn as thread so init can issue commands back to vold without |
| 680 | // causing deadlock, usually as a result of prep_data_fs. |
| 681 | std::thread(&cryptfs_mount_default_encrypted).detach(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 682 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 683 | return ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | binder::Status VoldNativeService::initUser0() { |
| 687 | ENFORCE_UID(AID_SYSTEM); |
| 688 | ACQUIRE_CRYPT_LOCK; |
| 689 | |
| 690 | return translateBool(e4crypt_init_user0()); |
| 691 | } |
| 692 | |
| 693 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
| 694 | ENFORCE_UID(AID_SYSTEM); |
| 695 | ACQUIRE_CRYPT_LOCK; |
| 696 | |
| 697 | *_aidl_return = cryptfs_isConvertibleToFBE() != 0; |
| 698 | return ok(); |
| 699 | } |
| 700 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 701 | binder::Status VoldNativeService::mountFstab(const std::string& mountPoint) { |
| 702 | ENFORCE_UID(AID_SYSTEM); |
| 703 | ACQUIRE_LOCK; |
| 704 | |
| 705 | return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, false)); |
| 706 | } |
| 707 | |
| 708 | binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) { |
| 709 | ENFORCE_UID(AID_SYSTEM); |
| 710 | ACQUIRE_LOCK; |
| 711 | |
| 712 | return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, true)); |
| 713 | } |
| 714 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 715 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, |
| 716 | bool ephemeral) { |
| 717 | ENFORCE_UID(AID_SYSTEM); |
| 718 | ACQUIRE_CRYPT_LOCK; |
| 719 | |
| 720 | return translateBool(e4crypt_vold_create_user_key(userId, userSerial, ephemeral)); |
| 721 | } |
| 722 | |
| 723 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
| 724 | ENFORCE_UID(AID_SYSTEM); |
| 725 | ACQUIRE_CRYPT_LOCK; |
| 726 | |
| 727 | return translateBool(e4crypt_destroy_user_key(userId)); |
| 728 | } |
| 729 | |
| 730 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
| 731 | const std::string& token, const std::string& secret) { |
| 732 | ENFORCE_UID(AID_SYSTEM); |
| 733 | ACQUIRE_CRYPT_LOCK; |
| 734 | |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 735 | return translateBool(e4crypt_add_user_key_auth(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
| 739 | ENFORCE_UID(AID_SYSTEM); |
| 740 | ACQUIRE_CRYPT_LOCK; |
| 741 | |
| 742 | return translateBool(e4crypt_fixate_newest_user_key_auth(userId)); |
| 743 | } |
| 744 | |
| 745 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
| 746 | const std::string& token, const std::string& secret) { |
| 747 | ENFORCE_UID(AID_SYSTEM); |
| 748 | ACQUIRE_CRYPT_LOCK; |
| 749 | |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 750 | return translateBool(e4crypt_unlock_user_key(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
| 754 | ENFORCE_UID(AID_SYSTEM); |
| 755 | ACQUIRE_CRYPT_LOCK; |
| 756 | |
| 757 | return translateBool(e4crypt_lock_user_key(userId)); |
| 758 | } |
| 759 | |
| 760 | binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid, |
| 761 | int32_t userId, int32_t userSerial, int32_t flags) { |
| 762 | ENFORCE_UID(AID_SYSTEM); |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 763 | std::string empty_string = ""; |
| 764 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 765 | CHECK_ARGUMENT_HEX(uuid_); |
| 766 | |
| 767 | ACQUIRE_CRYPT_LOCK; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 768 | return translateBool(e4crypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
| 769 | } |
| 770 | |
| 771 | binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid, |
| 772 | int32_t userId, int32_t flags) { |
| 773 | ENFORCE_UID(AID_SYSTEM); |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 774 | std::string empty_string = ""; |
| 775 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 776 | CHECK_ARGUMENT_HEX(uuid_); |
| 777 | |
| 778 | ACQUIRE_CRYPT_LOCK; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 779 | return translateBool(e4crypt_destroy_user_storage(uuid_, userId, flags)); |
| 780 | } |
| 781 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 782 | } // namespace vold |
| 783 | } // namespace android |