The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 17 | #include "builtins.h" |
| 18 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | #include <errno.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 20 | #include <fcntl.h> |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 21 | #include <mntent.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 22 | #include <net/if.h> |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 23 | #include <signal.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 24 | #include <stdio.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 25 | #include <stdlib.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <sys/socket.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | #include <sys/mount.h> |
| 29 | #include <sys/resource.h> |
Elliott Hughes | 3d74d7a | 2015-01-29 21:31:23 -0800 | [diff] [blame] | 30 | #include <sys/time.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 33 | #include <sys/wait.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 34 | #include <unistd.h> |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 35 | #include <linux/loop.h> |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 36 | #include <ext4_crypt_init_extensions.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 38 | #include <selinux/selinux.h> |
| 39 | #include <selinux/label.h> |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 40 | |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 41 | #include <fs_mgr.h> |
Elliott Hughes | 4f71319 | 2015-12-04 22:00:26 -0800 | [diff] [blame] | 42 | #include <android-base/stringprintf.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 43 | #include <cutils/partition_utils.h> |
| 44 | #include <cutils/android_reboot.h> |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 45 | #include <logwrap/logwrap.h> |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 46 | #include <private/android_filesystem_config.h> |
| 47 | |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame] | 48 | #include "action.h" |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 49 | #include "bootchart.h" |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 50 | #include "devices.h" |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 51 | #include "init.h" |
Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 52 | #include "init_parser.h" |
Colin Cross | ed8a7d8 | 2010-04-19 17:05:34 -0700 | [diff] [blame] | 53 | #include "log.h" |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 54 | #include "property_service.h" |
| 55 | #include "service.h" |
| 56 | #include "util.h" |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 57 | |
Nick Kralevich | bc60954 | 2015-01-31 21:39:46 -0800 | [diff] [blame] | 58 | #define chmod DO_NOT_USE_CHMOD_USE_FCHMODAT_SYMLINK_NOFOLLOW |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 59 | #define UNMOUNT_CHECK_MS 5000 |
| 60 | #define UNMOUNT_CHECK_TIMES 10 |
Nick Kralevich | bc60954 | 2015-01-31 21:39:46 -0800 | [diff] [blame] | 61 | |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 62 | // System call provided by bionic but not in any header file. |
| 63 | extern "C" int init_module(void *, unsigned long, const char *); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 64 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 65 | static int insmod(const char *filename, const char *options) { |
Tom Cherry | eaa3b4e | 2015-05-12 13:54:41 -0700 | [diff] [blame] | 66 | std::string module; |
Yabin Cui | 00ede7d | 2015-07-24 13:26:04 -0700 | [diff] [blame] | 67 | if (!read_file(filename, &module)) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 68 | return -1; |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 69 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 71 | // TODO: use finit_module for >= 3.8 kernels. |
| 72 | return init_module(&module[0], module.size(), options); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 75 | static int __ifupdown(const char *interface, int up) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 76 | struct ifreq ifr; |
| 77 | int s, ret; |
| 78 | |
| 79 | strlcpy(ifr.ifr_name, interface, IFNAMSIZ); |
| 80 | |
| 81 | s = socket(AF_INET, SOCK_DGRAM, 0); |
| 82 | if (s < 0) |
| 83 | return -1; |
| 84 | |
| 85 | ret = ioctl(s, SIOCGIFFLAGS, &ifr); |
| 86 | if (ret < 0) { |
| 87 | goto done; |
| 88 | } |
| 89 | |
| 90 | if (up) |
| 91 | ifr.ifr_flags |= IFF_UP; |
| 92 | else |
| 93 | ifr.ifr_flags &= ~IFF_UP; |
| 94 | |
| 95 | ret = ioctl(s, SIOCSIFFLAGS, &ifr); |
Elliott Hughes | 2462790 | 2015-02-04 10:25:09 -0800 | [diff] [blame] | 96 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | done: |
| 98 | close(s); |
| 99 | return ret; |
| 100 | } |
| 101 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 102 | static void unmount_and_fsck(const struct mntent *entry) { |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 103 | if (strcmp(entry->mnt_type, "f2fs") && strcmp(entry->mnt_type, "ext4")) |
| 104 | return; |
| 105 | |
| 106 | /* First, lazily unmount the directory. This unmount request finishes when |
| 107 | * all processes that open a file or directory in |entry->mnt_dir| exit. |
| 108 | */ |
| 109 | TEMP_FAILURE_RETRY(umount2(entry->mnt_dir, MNT_DETACH)); |
| 110 | |
| 111 | /* Next, kill all processes except init, kthreadd, and kthreadd's |
| 112 | * children to finish the lazy unmount. Killing all processes here is okay |
| 113 | * because this callback function is only called right before reboot(). |
| 114 | * It might be cleaner to selectively kill processes that actually use |
| 115 | * |entry->mnt_dir| rather than killing all, probably by reusing a function |
| 116 | * like killProcessesWithOpenFiles() in vold/, but the selinux policy does |
| 117 | * not allow init to scan /proc/<pid> files which the utility function |
| 118 | * heavily relies on. The policy does not allow the process to execute |
| 119 | * killall/pkill binaries either. Note that some processes might |
| 120 | * automatically restart after kill(), but that is not really a problem |
| 121 | * because |entry->mnt_dir| is no longer visible to such new processes. |
| 122 | */ |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 123 | ServiceManager::GetInstance().ForEachService([] (Service* s) { s->Stop(); }); |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 124 | TEMP_FAILURE_RETRY(kill(-1, SIGKILL)); |
| 125 | |
| 126 | int count = 0; |
| 127 | while (count++ < UNMOUNT_CHECK_TIMES) { |
| 128 | int fd = TEMP_FAILURE_RETRY(open(entry->mnt_fsname, O_RDONLY | O_EXCL)); |
| 129 | if (fd >= 0) { |
| 130 | /* |entry->mnt_dir| has sucessfully been unmounted. */ |
| 131 | close(fd); |
| 132 | break; |
| 133 | } else if (errno == EBUSY) { |
| 134 | /* Some processes using |entry->mnt_dir| are still alive. Wait for a |
| 135 | * while then retry. |
| 136 | */ |
| 137 | TEMP_FAILURE_RETRY( |
| 138 | usleep(UNMOUNT_CHECK_MS * 1000 / UNMOUNT_CHECK_TIMES)); |
| 139 | continue; |
| 140 | } else { |
| 141 | /* Cannot open the device. Give up. */ |
| 142 | return; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | int st; |
| 147 | if (!strcmp(entry->mnt_type, "f2fs")) { |
| 148 | const char *f2fs_argv[] = { |
| 149 | "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname, |
| 150 | }; |
| 151 | android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv, |
Yusuke Sato | d81c3c6 | 2015-08-14 01:22:53 -0700 | [diff] [blame] | 152 | &st, true, LOG_KLOG, true, NULL, NULL, 0); |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 153 | } else if (!strcmp(entry->mnt_type, "ext4")) { |
| 154 | const char *ext4_argv[] = { |
| 155 | "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname, |
| 156 | }; |
| 157 | android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv, |
Yusuke Sato | d81c3c6 | 2015-08-14 01:22:53 -0700 | [diff] [blame] | 158 | &st, true, LOG_KLOG, true, NULL, NULL, 0); |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 162 | static int do_class_start(const std::vector<std::string>& args) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 163 | /* Starting a class does not start services |
| 164 | * which are explicitly disabled. They must |
| 165 | * be started individually. |
| 166 | */ |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 167 | ServiceManager::GetInstance(). |
| 168 | ForEachServiceInClass(args[1], [] (Service* s) { s->StartIfNotDisabled(); }); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 172 | static int do_class_stop(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 173 | ServiceManager::GetInstance(). |
| 174 | ForEachServiceInClass(args[1], [] (Service* s) { s->Stop(); }); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 178 | static int do_class_reset(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 179 | ServiceManager::GetInstance(). |
| 180 | ForEachServiceInClass(args[1], [] (Service* s) { s->Reset(); }); |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 184 | static int do_domainname(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 185 | return write_file("/proc/sys/kernel/domainname", args[1].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 188 | static int do_enable(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 189 | Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]); |
| 190 | if (!svc) { |
JP Abgrall | 3beec7e | 2014-05-02 21:14:29 -0700 | [diff] [blame] | 191 | return -1; |
| 192 | } |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 193 | return svc->Enable(); |
JP Abgrall | 3beec7e | 2014-05-02 21:14:29 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 196 | static int do_exec(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 197 | Service* svc = ServiceManager::GetInstance().MakeExecOneshotService(args); |
| 198 | if (!svc) { |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 199 | return -1; |
| 200 | } |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 201 | if (!svc->Start()) { |
| 202 | return -1; |
| 203 | } |
| 204 | waiting_for_exec = true; |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 205 | return 0; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 208 | static int do_export(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 209 | return add_environment(args[1].c_str(), args[2].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 212 | static int do_hostname(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 213 | return write_file("/proc/sys/kernel/hostname", args[1].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 216 | static int do_ifup(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 217 | return __ifupdown(args[1].c_str(), 1); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 220 | static int do_insmod(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 221 | std::string options; |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 222 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 223 | if (args.size() > 2) { |
| 224 | options += args[2]; |
| 225 | for (std::size_t i = 3; i < args.size(); ++i) { |
| 226 | options += ' '; |
| 227 | options += args[i]; |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 231 | return insmod(args[1].c_str(), options.c_str()); |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 234 | static int do_mkdir(const std::vector<std::string>& args) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 235 | mode_t mode = 0755; |
Chia-chi Yeh | 27164dc | 2011-07-08 12:57:36 -0700 | [diff] [blame] | 236 | int ret; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 237 | |
| 238 | /* mkdir <path> [mode] [owner] [group] */ |
| 239 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 240 | if (args.size() >= 3) { |
| 241 | mode = std::stoul(args[2], 0, 8); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 244 | ret = make_dir(args[1].c_str(), mode); |
Chia-chi Yeh | 27164dc | 2011-07-08 12:57:36 -0700 | [diff] [blame] | 245 | /* chmod in case the directory already exists */ |
| 246 | if (ret == -1 && errno == EEXIST) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 247 | ret = fchmodat(AT_FDCWD, args[1].c_str(), mode, AT_SYMLINK_NOFOLLOW); |
Chia-chi Yeh | 27164dc | 2011-07-08 12:57:36 -0700 | [diff] [blame] | 248 | } |
| 249 | if (ret == -1) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 250 | return -errno; |
| 251 | } |
| 252 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 253 | if (args.size() >= 4) { |
| 254 | uid_t uid = decode_uid(args[3].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 255 | gid_t gid = -1; |
| 256 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 257 | if (args.size() == 5) { |
| 258 | gid = decode_uid(args[4].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 261 | if (lchown(args[1].c_str(), uid, gid) == -1) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 262 | return -errno; |
| 263 | } |
Benoit Goby | 5c8574b | 2012-08-14 15:43:46 -0700 | [diff] [blame] | 264 | |
| 265 | /* chown may have cleared S_ISUID and S_ISGID, chmod again */ |
| 266 | if (mode & (S_ISUID | S_ISGID)) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 267 | ret = fchmodat(AT_FDCWD, args[1].c_str(), mode, AT_SYMLINK_NOFOLLOW); |
Benoit Goby | 5c8574b | 2012-08-14 15:43:46 -0700 | [diff] [blame] | 268 | if (ret == -1) { |
| 269 | return -errno; |
| 270 | } |
| 271 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 274 | return e4crypt_set_directory_policy(args[1].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static struct { |
| 278 | const char *name; |
| 279 | unsigned flag; |
| 280 | } mount_flags[] = { |
| 281 | { "noatime", MS_NOATIME }, |
Lars Svensson | b6ee25e | 2011-07-14 13:39:09 +0200 | [diff] [blame] | 282 | { "noexec", MS_NOEXEC }, |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 283 | { "nosuid", MS_NOSUID }, |
| 284 | { "nodev", MS_NODEV }, |
| 285 | { "nodiratime", MS_NODIRATIME }, |
| 286 | { "ro", MS_RDONLY }, |
| 287 | { "rw", 0 }, |
| 288 | { "remount", MS_REMOUNT }, |
Jeff Sharkey | e50ac5f | 2012-08-14 11:34:34 -0700 | [diff] [blame] | 289 | { "bind", MS_BIND }, |
| 290 | { "rec", MS_REC }, |
| 291 | { "unbindable", MS_UNBINDABLE }, |
| 292 | { "private", MS_PRIVATE }, |
| 293 | { "slave", MS_SLAVE }, |
| 294 | { "shared", MS_SHARED }, |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 295 | { "defaults", 0 }, |
| 296 | { 0, 0 }, |
| 297 | }; |
| 298 | |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 299 | #define DATA_MNT_POINT "/data" |
| 300 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 301 | /* mount <type> <device> <path> <flags ...> <options> */ |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 302 | static int do_mount(const std::vector<std::string>& args) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 303 | char tmp[64]; |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 304 | const char *source, *target, *system; |
| 305 | const char *options = NULL; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 306 | unsigned flags = 0; |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 307 | std::size_t na = 0; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 308 | int n, i; |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 309 | int wait = 0; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 310 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 311 | for (na = 4; na < args.size(); na++) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 312 | for (i = 0; mount_flags[i].name; i++) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 313 | if (!args[na].compare(mount_flags[i].name)) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | flags |= mount_flags[i].flag; |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 319 | if (!mount_flags[i].name) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 320 | if (!args[na].compare("wait")) |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 321 | wait = 1; |
| 322 | /* if our last argument isn't a flag, wolf it up as an option string */ |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 323 | else if (na + 1 == args.size()) |
| 324 | options = args[na].c_str(); |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 325 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 328 | system = args[1].c_str(); |
| 329 | source = args[2].c_str(); |
| 330 | target = args[3].c_str(); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 331 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 332 | if (!strncmp(source, "mtd@", 4)) { |
| 333 | n = mtd_name_to_number(source + 4); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 334 | if (n < 0) { |
| 335 | return -1; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 336 | } |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 337 | |
Yabin Cui | e2d63af | 2015-02-17 19:27:51 -0800 | [diff] [blame] | 338 | snprintf(tmp, sizeof(tmp), "/dev/block/mtdblock%d", n); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 339 | |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 340 | if (wait) |
| 341 | wait_for_file(tmp, COMMAND_RETRY_TIMEOUT); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 342 | if (mount(tmp, target, system, flags, options) < 0) { |
| 343 | return -1; |
| 344 | } |
| 345 | |
Ken Sumrall | dd4d786 | 2011-02-17 18:09:47 -0800 | [diff] [blame] | 346 | goto exit_success; |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 347 | } else if (!strncmp(source, "loop@", 5)) { |
| 348 | int mode, loop, fd; |
| 349 | struct loop_info info; |
| 350 | |
| 351 | mode = (flags & MS_RDONLY) ? O_RDONLY : O_RDWR; |
Nick Kralevich | 45a884f | 2015-02-02 14:37:22 -0800 | [diff] [blame] | 352 | fd = open(source + 5, mode | O_CLOEXEC); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 353 | if (fd < 0) { |
| 354 | return -1; |
| 355 | } |
| 356 | |
| 357 | for (n = 0; ; n++) { |
Yabin Cui | e2d63af | 2015-02-17 19:27:51 -0800 | [diff] [blame] | 358 | snprintf(tmp, sizeof(tmp), "/dev/block/loop%d", n); |
Nick Kralevich | 45a884f | 2015-02-02 14:37:22 -0800 | [diff] [blame] | 359 | loop = open(tmp, mode | O_CLOEXEC); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 360 | if (loop < 0) { |
Tomasz Kondel | bfdcc40 | 2014-02-06 08:57:27 +0100 | [diff] [blame] | 361 | close(fd); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 362 | return -1; |
| 363 | } |
| 364 | |
| 365 | /* if it is a blank loop device */ |
| 366 | if (ioctl(loop, LOOP_GET_STATUS, &info) < 0 && errno == ENXIO) { |
| 367 | /* if it becomes our loop device */ |
| 368 | if (ioctl(loop, LOOP_SET_FD, fd) >= 0) { |
| 369 | close(fd); |
| 370 | |
| 371 | if (mount(tmp, target, system, flags, options) < 0) { |
| 372 | ioctl(loop, LOOP_CLR_FD, 0); |
| 373 | close(loop); |
| 374 | return -1; |
| 375 | } |
| 376 | |
| 377 | close(loop); |
Ken Sumrall | dd4d786 | 2011-02-17 18:09:47 -0800 | [diff] [blame] | 378 | goto exit_success; |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | close(loop); |
| 383 | } |
| 384 | |
| 385 | close(fd); |
| 386 | ERROR("out of loopback devices"); |
| 387 | return -1; |
| 388 | } else { |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 389 | if (wait) |
| 390 | wait_for_file(source, COMMAND_RETRY_TIMEOUT); |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 391 | if (mount(source, target, system, flags, options) < 0) { |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 392 | return -1; |
Jay Freeman (saurik) | e520d03 | 2008-11-20 03:37:30 +0000 | [diff] [blame] | 393 | } |
| 394 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 395 | } |
Ken Sumrall | dd4d786 | 2011-02-17 18:09:47 -0800 | [diff] [blame] | 396 | |
| 397 | exit_success: |
Ken Sumrall | dd4d786 | 2011-02-17 18:09:47 -0800 | [diff] [blame] | 398 | return 0; |
| 399 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 402 | static int wipe_data_via_recovery() { |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 403 | mkdir("/cache/recovery", 0700); |
Nick Kralevich | 45a884f | 2015-02-02 14:37:22 -0800 | [diff] [blame] | 404 | int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0600); |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 405 | if (fd >= 0) { |
Jeff Sharkey | d26135b | 2014-09-24 11:46:36 -0700 | [diff] [blame] | 406 | write(fd, "--wipe_data\n", strlen("--wipe_data\n") + 1); |
| 407 | write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1); |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 408 | close(fd); |
| 409 | } else { |
| 410 | ERROR("could not open /cache/recovery/command\n"); |
| 411 | return -1; |
| 412 | } |
| 413 | android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
| 414 | while (1) { pause(); } // never reached |
| 415 | } |
| 416 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 417 | static void import_late() { |
Tom Cherry | b8dd027 | 2015-07-22 14:23:33 -0700 | [diff] [blame] | 418 | static const std::vector<std::string> init_directories = { |
| 419 | "/system/etc/init", |
| 420 | "/vendor/etc/init", |
| 421 | "/odm/etc/init" |
| 422 | }; |
| 423 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 424 | Parser& parser = Parser::GetInstance(); |
Tom Cherry | b8dd027 | 2015-07-22 14:23:33 -0700 | [diff] [blame] | 425 | for (const auto& dir : init_directories) { |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 426 | parser.ParseConfig(dir.c_str()); |
Tom Cherry | b8dd027 | 2015-07-22 14:23:33 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 430 | /* |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 431 | * This function might request a reboot, in which case it will |
| 432 | * not return. |
| 433 | */ |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 434 | static int do_mount_all(const std::vector<std::string>& args) { |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 435 | pid_t pid; |
| 436 | int ret = -1; |
| 437 | int child_ret = -1; |
| 438 | int status; |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 439 | struct fstab *fstab; |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 440 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 441 | const char* fstabfile = args[1].c_str(); |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 442 | /* |
| 443 | * Call fs_mgr_mount_all() to mount all filesystems. We fork(2) and |
| 444 | * do the call in the child to provide protection to the main init |
| 445 | * process if anything goes wrong (crash or memory leak), and wait for |
| 446 | * the child to finish in the parent. |
| 447 | */ |
| 448 | pid = fork(); |
| 449 | if (pid > 0) { |
| 450 | /* Parent. Wait for the child to return */ |
Paul Lawrence | 40af092 | 2014-09-16 14:31:23 -0700 | [diff] [blame] | 451 | int wp_ret = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); |
| 452 | if (wp_ret < 0) { |
| 453 | /* Unexpected error code. We will continue anyway. */ |
Elliott Hughes | cd67f00 | 2015-03-20 17:05:56 -0700 | [diff] [blame] | 454 | NOTICE("waitpid failed rc=%d: %s\n", wp_ret, strerror(errno)); |
Paul Lawrence | 40af092 | 2014-09-16 14:31:23 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 457 | if (WIFEXITED(status)) { |
| 458 | ret = WEXITSTATUS(status); |
| 459 | } else { |
| 460 | ret = -1; |
| 461 | } |
| 462 | } else if (pid == 0) { |
| 463 | /* child, call fs_mgr_mount_all() */ |
| 464 | klog_set_level(6); /* So we can see what fs_mgr_mount_all() does */ |
Nan Liu | 12df1e1 | 2015-07-21 19:44:07 +0800 | [diff] [blame] | 465 | fstab = fs_mgr_read_fstab(fstabfile); |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 466 | child_ret = fs_mgr_mount_all(fstab); |
| 467 | fs_mgr_free_fstab(fstab); |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 468 | if (child_ret == -1) { |
| 469 | ERROR("fs_mgr_mount_all returned an error\n"); |
| 470 | } |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 471 | _exit(child_ret); |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 472 | } else { |
| 473 | /* fork failed, return an error */ |
| 474 | return -1; |
| 475 | } |
| 476 | |
Tom Cherry | b8dd027 | 2015-07-22 14:23:33 -0700 | [diff] [blame] | 477 | import_late(); |
| 478 | |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 479 | if (ret == FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION) { |
Paul Lawrence | 166fa3d | 2014-02-03 13:27:49 -0800 | [diff] [blame] | 480 | property_set("vold.decrypt", "trigger_encryption"); |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 481 | } else if (ret == FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED) { |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 482 | property_set("ro.crypto.state", "encrypted"); |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 483 | property_set("ro.crypto.type", "block"); |
Paul Lawrence | 13d5bb4 | 2014-01-30 10:43:52 -0800 | [diff] [blame] | 484 | property_set("vold.decrypt", "trigger_default_encryption"); |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 485 | } else if (ret == FS_MGR_MNTALL_DEV_NOT_ENCRYPTED) { |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 486 | property_set("ro.crypto.state", "unencrypted"); |
| 487 | /* If fs_mgr determined this is an unencrypted device, then trigger |
| 488 | * that action. |
| 489 | */ |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame] | 490 | ActionManager::GetInstance().QueueEventTrigger("nonencrypted"); |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 491 | } else if (ret == FS_MGR_MNTALL_DEV_NEEDS_RECOVERY) { |
| 492 | /* Setup a wipe via recovery, and reboot into recovery */ |
| 493 | ERROR("fs_mgr_mount_all suggested recovery, so wiping data via recovery.\n"); |
| 494 | ret = wipe_data_via_recovery(); |
| 495 | /* If reboot worked, there is no return. */ |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 496 | } else if (ret == FS_MGR_MNTALL_DEV_DEFAULT_FILE_ENCRYPTED) { |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 497 | if (e4crypt_install_keyring()) { |
| 498 | return -1; |
| 499 | } |
| 500 | property_set("ro.crypto.state", "encrypted"); |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 501 | property_set("ro.crypto.type", "file"); |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 502 | |
| 503 | // Although encrypted, we have device key, so we do not need to |
| 504 | // do anything different from the nonencrypted case. |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame] | 505 | ActionManager::GetInstance().QueueEventTrigger("nonencrypted"); |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 506 | } else if (ret == FS_MGR_MNTALL_DEV_NON_DEFAULT_FILE_ENCRYPTED) { |
| 507 | if (e4crypt_install_keyring()) { |
| 508 | return -1; |
| 509 | } |
| 510 | property_set("ro.crypto.state", "encrypted"); |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 511 | property_set("ro.crypto.type", "file"); |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 512 | property_set("vold.decrypt", "trigger_restart_min_framework"); |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 513 | } else if (ret > 0) { |
| 514 | ERROR("fs_mgr_mount_all returned unexpected error %d\n", ret); |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 515 | } |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 516 | /* else ... < 0: error */ |
Ken Sumrall | 0e9dd90 | 2012-04-17 17:20:16 -0700 | [diff] [blame] | 517 | |
| 518 | return ret; |
| 519 | } |
| 520 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 521 | static int do_swapon_all(const std::vector<std::string>& args) { |
Ken Sumrall | a76baaa | 2013-07-09 18:42:09 -0700 | [diff] [blame] | 522 | struct fstab *fstab; |
| 523 | int ret; |
| 524 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 525 | fstab = fs_mgr_read_fstab(args[1].c_str()); |
Ken Sumrall | a76baaa | 2013-07-09 18:42:09 -0700 | [diff] [blame] | 526 | ret = fs_mgr_swapon_all(fstab); |
| 527 | fs_mgr_free_fstab(fstab); |
| 528 | |
| 529 | return ret; |
| 530 | } |
| 531 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 532 | static int do_setprop(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 533 | const char* name = args[1].c_str(); |
| 534 | const char* value = args[2].c_str(); |
Yabin Cui | 00ede7d | 2015-07-24 13:26:04 -0700 | [diff] [blame] | 535 | property_set(name, value); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 539 | static int do_setrlimit(const std::vector<std::string>& args) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 540 | struct rlimit limit; |
| 541 | int resource; |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 542 | resource = std::stoi(args[1]); |
| 543 | limit.rlim_cur = std::stoi(args[2]); |
| 544 | limit.rlim_max = std::stoi(args[3]); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 545 | return setrlimit(resource, &limit); |
| 546 | } |
| 547 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 548 | static int do_start(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 549 | Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]); |
| 550 | if (!svc) { |
| 551 | ERROR("do_start: Service %s not found\n", args[1].c_str()); |
| 552 | return -1; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 553 | } |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 554 | if (!svc->Start()) |
| 555 | return -1; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 559 | static int do_stop(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 560 | Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]); |
| 561 | if (!svc) { |
| 562 | ERROR("do_stop: Service %s not found\n", args[1].c_str()); |
| 563 | return -1; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 564 | } |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 565 | svc->Stop(); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 569 | static int do_restart(const std::vector<std::string>& args) { |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 570 | Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]); |
| 571 | if (!svc) { |
| 572 | ERROR("do_restart: Service %s not found\n", args[1].c_str()); |
| 573 | return -1; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 574 | } |
Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 575 | svc->Restart(); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 579 | static int do_powerctl(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 580 | const char* command = args[1].c_str(); |
Nick Kralevich | ca8e66a | 2013-04-18 12:20:02 -0700 | [diff] [blame] | 581 | int len = 0; |
Yusuke Sato | f93d429 | 2015-07-21 15:50:59 -0700 | [diff] [blame] | 582 | unsigned int cmd = 0; |
| 583 | const char *reboot_target = ""; |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 584 | void (*callback_on_ro_remount)(const struct mntent*) = NULL; |
Nick Kralevich | ca8e66a | 2013-04-18 12:20:02 -0700 | [diff] [blame] | 585 | |
Nick Kralevich | ca8e66a | 2013-04-18 12:20:02 -0700 | [diff] [blame] | 586 | if (strncmp(command, "shutdown", 8) == 0) { |
| 587 | cmd = ANDROID_RB_POWEROFF; |
| 588 | len = 8; |
| 589 | } else if (strncmp(command, "reboot", 6) == 0) { |
| 590 | cmd = ANDROID_RB_RESTART2; |
| 591 | len = 6; |
| 592 | } else { |
| 593 | ERROR("powerctl: unrecognized command '%s'\n", command); |
| 594 | return -EINVAL; |
| 595 | } |
| 596 | |
| 597 | if (command[len] == ',') { |
Yusuke Sato | f93d429 | 2015-07-21 15:50:59 -0700 | [diff] [blame] | 598 | if (cmd == ANDROID_RB_POWEROFF && |
| 599 | !strcmp(&command[len + 1], "userrequested")) { |
| 600 | // The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED. |
| 601 | // Run fsck once the file system is remounted in read-only mode. |
| 602 | callback_on_ro_remount = unmount_and_fsck; |
| 603 | } else if (cmd == ANDROID_RB_RESTART2) { |
| 604 | reboot_target = &command[len + 1]; |
| 605 | } |
| 606 | } else if (command[len] != '\0') { |
Nick Kralevich | ca8e66a | 2013-04-18 12:20:02 -0700 | [diff] [blame] | 607 | ERROR("powerctl: unrecognized reboot target '%s'\n", &command[len]); |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 611 | return android_reboot_with_callback(cmd, 0, reboot_target, |
| 612 | callback_on_ro_remount); |
Nick Kralevich | ca8e66a | 2013-04-18 12:20:02 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 615 | static int do_trigger(const std::vector<std::string>& args) { |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame] | 616 | ActionManager::GetInstance().QueueEventTrigger(args[1]); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 617 | return 0; |
| 618 | } |
| 619 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 620 | static int do_symlink(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 621 | return symlink(args[1].c_str(), args[2].c_str()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 624 | static int do_rm(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 625 | return unlink(args[1].c_str()); |
Ken Sumrall | 203bad5 | 2011-01-18 17:37:41 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 628 | static int do_rmdir(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 629 | return rmdir(args[1].c_str()); |
Ken Sumrall | 203bad5 | 2011-01-18 17:37:41 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 632 | static int do_sysclktz(const std::vector<std::string>& args) { |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 633 | struct timezone tz; |
| 634 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 635 | memset(&tz, 0, sizeof(tz)); |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 636 | tz.tz_minuteswest = std::stoi(args[1]); |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 637 | if (settimeofday(NULL, &tz)) |
| 638 | return -1; |
| 639 | return 0; |
| 640 | } |
| 641 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 642 | static int do_verity_load_state(const std::vector<std::string>& args) { |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 643 | int mode = -1; |
| 644 | int rc = fs_mgr_load_verity_state(&mode); |
| 645 | if (rc == 0 && mode == VERITY_MODE_LOGGING) { |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame] | 646 | ActionManager::GetInstance().QueueEventTrigger("verity-logging"); |
Sami Tolvanen | 8ff0190 | 2015-02-16 11:03:34 +0000 | [diff] [blame] | 647 | } |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 648 | return rc; |
Sami Tolvanen | 8ff0190 | 2015-02-16 11:03:34 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 651 | static void verity_update_property(fstab_rec *fstab, const char *mount_point, |
| 652 | int mode, int status) { |
Sami Tolvanen | 4547423 | 2015-03-30 11:38:38 +0100 | [diff] [blame] | 653 | property_set(android::base::StringPrintf("partition.%s.verified", mount_point).c_str(), |
| 654 | android::base::StringPrintf("%d", mode).c_str()); |
Sami Tolvanen | acbf9be | 2015-03-19 10:00:34 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 657 | static int do_verity_update_state(const std::vector<std::string>& args) { |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 658 | return fs_mgr_update_verity_state(verity_update_property); |
Sami Tolvanen | acbf9be | 2015-03-19 10:00:34 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 661 | static int do_write(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 662 | const char* path = args[1].c_str(); |
| 663 | const char* value = args[2].c_str(); |
Yabin Cui | 00ede7d | 2015-07-24 13:26:04 -0700 | [diff] [blame] | 664 | return write_file(path, value); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 667 | static int do_copy(const std::vector<std::string>& args) { |
San Mehat | 7c44fe5 | 2009-08-26 16:39:25 -0700 | [diff] [blame] | 668 | char *buffer = NULL; |
| 669 | int rc = 0; |
| 670 | int fd1 = -1, fd2 = -1; |
| 671 | struct stat info; |
| 672 | int brtw, brtr; |
| 673 | char *p; |
| 674 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 675 | if (stat(args[1].c_str(), &info) < 0) |
San Mehat | 7c44fe5 | 2009-08-26 16:39:25 -0700 | [diff] [blame] | 676 | return -1; |
| 677 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 678 | if ((fd1 = open(args[1].c_str(), O_RDONLY|O_CLOEXEC)) < 0) |
San Mehat | 7c44fe5 | 2009-08-26 16:39:25 -0700 | [diff] [blame] | 679 | goto out_err; |
| 680 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 681 | if ((fd2 = open(args[2].c_str(), O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0660)) < 0) |
San Mehat | 7c44fe5 | 2009-08-26 16:39:25 -0700 | [diff] [blame] | 682 | goto out_err; |
| 683 | |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 684 | if (!(buffer = (char*) malloc(info.st_size))) |
San Mehat | 7c44fe5 | 2009-08-26 16:39:25 -0700 | [diff] [blame] | 685 | goto out_err; |
| 686 | |
| 687 | p = buffer; |
| 688 | brtr = info.st_size; |
| 689 | while(brtr) { |
| 690 | rc = read(fd1, p, brtr); |
| 691 | if (rc < 0) |
| 692 | goto out_err; |
| 693 | if (rc == 0) |
| 694 | break; |
| 695 | p += rc; |
| 696 | brtr -= rc; |
| 697 | } |
| 698 | |
| 699 | p = buffer; |
| 700 | brtw = info.st_size; |
| 701 | while(brtw) { |
| 702 | rc = write(fd2, p, brtw); |
| 703 | if (rc < 0) |
| 704 | goto out_err; |
| 705 | if (rc == 0) |
| 706 | break; |
| 707 | p += rc; |
| 708 | brtw -= rc; |
| 709 | } |
| 710 | |
| 711 | rc = 0; |
| 712 | goto out; |
| 713 | out_err: |
| 714 | rc = -1; |
| 715 | out: |
| 716 | if (buffer) |
| 717 | free(buffer); |
| 718 | if (fd1 >= 0) |
| 719 | close(fd1); |
| 720 | if (fd2 >= 0) |
| 721 | close(fd2); |
| 722 | return rc; |
| 723 | } |
| 724 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 725 | static int do_chown(const std::vector<std::string>& args) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 726 | /* GID is optional. */ |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 727 | if (args.size() == 3) { |
| 728 | if (lchown(args[2].c_str(), decode_uid(args[1].c_str()), -1) == -1) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 729 | return -errno; |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 730 | } else if (args.size() == 4) { |
| 731 | if (lchown(args[3].c_str(), decode_uid(args[1].c_str()), |
| 732 | decode_uid(args[2].c_str())) == -1) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 733 | return -errno; |
| 734 | } else { |
| 735 | return -1; |
| 736 | } |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | static mode_t get_mode(const char *s) { |
| 741 | mode_t mode = 0; |
| 742 | while (*s) { |
| 743 | if (*s >= '0' && *s <= '7') { |
| 744 | mode = (mode<<3) | (*s-'0'); |
| 745 | } else { |
| 746 | return -1; |
| 747 | } |
| 748 | s++; |
| 749 | } |
| 750 | return mode; |
| 751 | } |
| 752 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 753 | static int do_chmod(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 754 | mode_t mode = get_mode(args[1].c_str()); |
| 755 | if (fchmodat(AT_FDCWD, args[2].c_str(), mode, AT_SYMLINK_NOFOLLOW) < 0) { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 756 | return -errno; |
| 757 | } |
| 758 | return 0; |
| 759 | } |
| 760 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 761 | static int do_restorecon(const std::vector<std::string>& args) { |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 762 | int ret = 0; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 763 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 764 | for (auto it = std::next(args.begin()); it != args.end(); ++it) { |
| 765 | if (restorecon(it->c_str()) < 0) |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 766 | ret = -errno; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 767 | } |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 768 | return ret; |
| 769 | } |
| 770 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 771 | static int do_restorecon_recursive(const std::vector<std::string>& args) { |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 772 | int ret = 0; |
| 773 | |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 774 | for (auto it = std::next(args.begin()); it != args.end(); ++it) { |
| 775 | if (restorecon_recursive(it->c_str()) < 0) |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 776 | ret = -errno; |
| 777 | } |
| 778 | return ret; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 779 | } |
| 780 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 781 | static int do_loglevel(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 782 | int log_level = std::stoi(args[1]); |
Riley Andrews | 1bbef88 | 2014-06-26 13:55:03 -0700 | [diff] [blame] | 783 | if (log_level < KLOG_ERROR_LEVEL || log_level > KLOG_DEBUG_LEVEL) { |
| 784 | ERROR("loglevel: invalid log level'%d'\n", log_level); |
| 785 | return -EINVAL; |
| 786 | } |
| 787 | klog_set_level(log_level); |
| 788 | return 0; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Tom Cherry | af20a7c | 2015-09-01 15:05:34 -0700 | [diff] [blame] | 791 | static int do_load_persist_props(const std::vector<std::string>& args) { |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 792 | load_persist_props(); |
| 793 | return 0; |
Ken Sumrall | c5c5103 | 2011-03-08 17:01:29 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Tom Cherry | af20a7c | 2015-09-01 15:05:34 -0700 | [diff] [blame] | 796 | static int do_load_system_props(const std::vector<std::string>& args) { |
| 797 | load_system_props(); |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 798 | return 0; |
Riley Andrews | e4b7b29 | 2014-06-16 15:06:21 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 801 | static int do_wait(const std::vector<std::string>& args) { |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 802 | if (args.size() == 2) { |
| 803 | return wait_for_file(args[1].c_str(), COMMAND_RETRY_TIMEOUT); |
| 804 | } else if (args.size() == 3) { |
| 805 | return wait_for_file(args[1].c_str(), std::stoi(args[2])); |
Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 806 | } else |
| 807 | return -1; |
Colin Cross | cd0f173 | 2010-04-19 17:10:24 -0700 | [diff] [blame] | 808 | } |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 809 | |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 810 | /* |
| 811 | * Callback to make a directory from the ext4 code |
| 812 | */ |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 813 | static int do_installkeys_ensure_dir_exists(const char* dir) { |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 814 | if (make_dir(dir, 0700) && errno != EEXIST) { |
| 815 | return -1; |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
Paul Crowley | 749af8c | 2015-05-28 17:35:06 +0100 | [diff] [blame] | 821 | static bool is_file_crypto() { |
Yabin Cui | 0ff8590 | 2015-07-24 13:58:03 -0700 | [diff] [blame] | 822 | std::string value = property_get("ro.crypto.type"); |
| 823 | return value == "file"; |
Paul Crowley | 749af8c | 2015-05-28 17:35:06 +0100 | [diff] [blame] | 824 | } |
| 825 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 826 | static int do_installkey(const std::vector<std::string>& args) { |
Paul Crowley | 749af8c | 2015-05-28 17:35:06 +0100 | [diff] [blame] | 827 | if (!is_file_crypto()) { |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 828 | return 0; |
| 829 | } |
Tom Cherry | 96f6731 | 2015-07-30 13:52:55 -0700 | [diff] [blame] | 830 | return e4crypt_create_device_key(args[1].c_str(), |
Paul Lawrence | 806d10b | 2015-04-28 22:07:10 +0000 | [diff] [blame] | 831 | do_installkeys_ensure_dir_exists); |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 832 | } |
Paul Crowley | 749af8c | 2015-05-28 17:35:06 +0100 | [diff] [blame] | 833 | |
Tom Cherry | af20a7c | 2015-09-01 15:05:34 -0700 | [diff] [blame] | 834 | static int do_setusercryptopolicies(const std::vector<std::string>& args) { |
Paul Crowley | 749af8c | 2015-05-28 17:35:06 +0100 | [diff] [blame] | 835 | if (!is_file_crypto()) { |
| 836 | return 0; |
| 837 | } |
Tom Cherry | 087cd35 | 2015-08-03 14:19:35 -0700 | [diff] [blame] | 838 | return e4crypt_set_user_crypto_policies(args[1].c_str()); |
Paul Crowley | 749af8c | 2015-05-28 17:35:06 +0100 | [diff] [blame] | 839 | } |
Tom Cherry | af20a7c | 2015-09-01 15:05:34 -0700 | [diff] [blame] | 840 | |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 841 | BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { |
| 842 | constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max(); |
| 843 | static const Map builtin_functions = { |
| 844 | {"bootchart_init", {0, 0, do_bootchart_init}}, |
| 845 | {"chmod", {2, 2, do_chmod}}, |
| 846 | {"chown", {2, 3, do_chown}}, |
| 847 | {"class_reset", {1, 1, do_class_reset}}, |
| 848 | {"class_start", {1, 1, do_class_start}}, |
| 849 | {"class_stop", {1, 1, do_class_stop}}, |
| 850 | {"copy", {2, 2, do_copy}}, |
| 851 | {"domainname", {1, 1, do_domainname}}, |
| 852 | {"enable", {1, 1, do_enable}}, |
| 853 | {"exec", {1, kMax, do_exec}}, |
| 854 | {"export", {2, 2, do_export}}, |
| 855 | {"hostname", {1, 1, do_hostname}}, |
| 856 | {"ifup", {1, 1, do_ifup}}, |
| 857 | {"insmod", {1, kMax, do_insmod}}, |
| 858 | {"installkey", {1, 1, do_installkey}}, |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 859 | {"load_persist_props", {0, 0, do_load_persist_props}}, |
Tom Cherry | af20a7c | 2015-09-01 15:05:34 -0700 | [diff] [blame] | 860 | {"load_system_props", {0, 0, do_load_system_props}}, |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 861 | {"loglevel", {1, 1, do_loglevel}}, |
| 862 | {"mkdir", {1, 4, do_mkdir}}, |
| 863 | {"mount_all", {1, 1, do_mount_all}}, |
| 864 | {"mount", {3, kMax, do_mount}}, |
| 865 | {"powerctl", {1, 1, do_powerctl}}, |
| 866 | {"restart", {1, 1, do_restart}}, |
| 867 | {"restorecon", {1, kMax, do_restorecon}}, |
| 868 | {"restorecon_recursive", {1, kMax, do_restorecon_recursive}}, |
| 869 | {"rm", {1, 1, do_rm}}, |
| 870 | {"rmdir", {1, 1, do_rmdir}}, |
| 871 | {"setprop", {2, 2, do_setprop}}, |
| 872 | {"setrlimit", {3, 3, do_setrlimit}}, |
Tom Cherry | af20a7c | 2015-09-01 15:05:34 -0700 | [diff] [blame] | 873 | {"setusercryptopolicies", {1, 1, do_setusercryptopolicies}}, |
Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 874 | {"start", {1, 1, do_start}}, |
| 875 | {"stop", {1, 1, do_stop}}, |
| 876 | {"swapon_all", {1, 1, do_swapon_all}}, |
| 877 | {"symlink", {2, 2, do_symlink}}, |
| 878 | {"sysclktz", {1, 1, do_sysclktz}}, |
| 879 | {"trigger", {1, 1, do_trigger}}, |
| 880 | {"verity_load_state", {0, 0, do_verity_load_state}}, |
| 881 | {"verity_update_state", {0, 0, do_verity_update_state}}, |
| 882 | {"wait", {1, 2, do_wait}}, |
| 883 | {"write", {2, 2, do_write}}, |
| 884 | }; |
| 885 | return builtin_functions; |
| 886 | } |