Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 17 | #include <ctype.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <stdarg.h> |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 20 | #include <stdio.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <sys/mount.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 26 | #include <sys/wait.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 27 | #include <unistd.h> |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 28 | #include <fcntl.h> |
| 29 | #include <time.h> |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 30 | #include <selinux/selinux.h> |
| 31 | #include <ftw.h> |
| 32 | #include <sys/capability.h> |
| 33 | #include <sys/xattr.h> |
| 34 | #include <linux/xattr.h> |
| 35 | #include <inttypes.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 36 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 37 | #include "cutils/misc.h" |
| 38 | #include "cutils/properties.h" |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 39 | #include "edify/expr.h" |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 40 | #include "mincrypt/sha.h" |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 41 | #include "minzip/DirUtil.h" |
| 42 | #include "mtdutils/mounts.h" |
| 43 | #include "mtdutils/mtdutils.h" |
| 44 | #include "updater.h" |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 45 | #include "applypatch/applypatch.h" |
Dees_Troy | 512376c | 2013-09-03 19:39:41 +0000 | [diff] [blame] | 46 | #include "flashutils/flashutils.h" |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 47 | |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 48 | #ifdef USE_EXT4 |
| 49 | #include "make_ext4fs.h" |
| 50 | #endif |
| 51 | |
| 52 | // mount(fs_type, partition_type, location, mount_point) |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 53 | // |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 54 | // fs_type="yaffs2" partition_type="MTD" location=partition |
| 55 | // fs_type="ext4" partition_type="EMMC" location=device |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 56 | Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 57 | char* result = NULL; |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 58 | if (argc != 4) { |
| 59 | return ErrorAbort(state, "%s() expects 4 args, got %d", name, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 60 | } |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 61 | char* fs_type; |
| 62 | char* partition_type; |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 63 | char* location; |
| 64 | char* mount_point; |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 65 | if (ReadArgs(state, argv, 4, &fs_type, &partition_type, |
| 66 | &location, &mount_point) < 0) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 67 | return NULL; |
| 68 | } |
| 69 | |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 70 | if (strlen(fs_type) == 0) { |
| 71 | ErrorAbort(state, "fs_type argument to %s() can't be empty", name); |
| 72 | goto done; |
| 73 | } |
| 74 | if (strlen(partition_type) == 0) { |
| 75 | ErrorAbort(state, "partition_type argument to %s() can't be empty", |
| 76 | name); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 77 | goto done; |
| 78 | } |
| 79 | if (strlen(location) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 80 | ErrorAbort(state, "location argument to %s() can't be empty", name); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 81 | goto done; |
| 82 | } |
| 83 | if (strlen(mount_point) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 84 | ErrorAbort(state, "mount_point argument to %s() can't be empty", name); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 85 | goto done; |
| 86 | } |
| 87 | |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 88 | char *secontext = NULL; |
| 89 | |
| 90 | if (sehandle) { |
| 91 | selabel_lookup(sehandle, &secontext, mount_point, 0755); |
| 92 | setfscreatecon(secontext); |
| 93 | } |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 94 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 95 | mkdir(mount_point, 0755); |
| 96 | |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 97 | if (secontext) { |
| 98 | freecon(secontext); |
| 99 | setfscreatecon(NULL); |
| 100 | } |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 101 | |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 102 | if (strcmp(partition_type, "MTD") == 0) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 103 | mtd_scan_partitions(); |
| 104 | const MtdPartition* mtd; |
| 105 | mtd = mtd_find_partition_by_name(location); |
| 106 | if (mtd == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 107 | printf("%s: no mtd partition named \"%s\"", |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 108 | name, location); |
| 109 | result = strdup(""); |
| 110 | goto done; |
| 111 | } |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 112 | if (mtd_mount_partition(mtd, mount_point, fs_type, 0 /* rw */) != 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 113 | printf("mtd mount of %s failed: %s\n", |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 114 | location, strerror(errno)); |
| 115 | result = strdup(""); |
| 116 | goto done; |
| 117 | } |
| 118 | result = mount_point; |
| 119 | } else { |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 120 | if (mount(location, mount_point, fs_type, |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 121 | MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 122 | printf("%s: failed to mount %s at %s: %s\n", |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 123 | name, location, mount_point, strerror(errno)); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 124 | result = strdup(""); |
| 125 | } else { |
| 126 | result = mount_point; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | done: |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 131 | free(fs_type); |
| 132 | free(partition_type); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 133 | free(location); |
| 134 | if (result != mount_point) free(mount_point); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 135 | return StringValue(result); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 138 | |
| 139 | // is_mounted(mount_point) |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 140 | Value* IsMountedFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 141 | char* result = NULL; |
| 142 | if (argc != 1) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 143 | return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 144 | } |
| 145 | char* mount_point; |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 146 | if (ReadArgs(state, argv, 1, &mount_point) < 0) { |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 147 | return NULL; |
| 148 | } |
| 149 | if (strlen(mount_point) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 150 | ErrorAbort(state, "mount_point argument to unmount() can't be empty"); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 151 | goto done; |
| 152 | } |
| 153 | |
| 154 | scan_mounted_volumes(); |
| 155 | const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); |
| 156 | if (vol == NULL) { |
| 157 | result = strdup(""); |
| 158 | } else { |
| 159 | result = mount_point; |
| 160 | } |
| 161 | |
| 162 | done: |
| 163 | if (result != mount_point) free(mount_point); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 164 | return StringValue(result); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 168 | Value* UnmountFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 169 | char* result = NULL; |
| 170 | if (argc != 1) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 171 | return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 172 | } |
| 173 | char* mount_point; |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 174 | if (ReadArgs(state, argv, 1, &mount_point) < 0) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 175 | return NULL; |
| 176 | } |
| 177 | if (strlen(mount_point) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 178 | ErrorAbort(state, "mount_point argument to unmount() can't be empty"); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 179 | goto done; |
| 180 | } |
| 181 | |
| 182 | scan_mounted_volumes(); |
| 183 | const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); |
| 184 | if (vol == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 185 | printf("unmount of %s failed; no such volume\n", mount_point); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 186 | result = strdup(""); |
| 187 | } else { |
| 188 | unmount_mounted_volume(vol); |
| 189 | result = mount_point; |
| 190 | } |
| 191 | |
| 192 | done: |
| 193 | if (result != mount_point) free(mount_point); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 194 | return StringValue(result); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 195 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 196 | |
| 197 | |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 198 | // format(fs_type, partition_type, location, fs_size, mount_point) |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 199 | // |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 200 | // fs_type="yaffs2" partition_type="MTD" location=partition fs_size=<bytes> mount_point=<location> |
| 201 | // fs_type="ext4" partition_type="EMMC" location=device fs_size=<bytes> mount_point=<location> |
Ken Sumrall | 8f132ed | 2011-01-14 18:55:05 -0800 | [diff] [blame] | 202 | // if fs_size == 0, then make_ext4fs uses the entire partition. |
| 203 | // if fs_size > 0, that is the size to use |
| 204 | // if fs_size < 0, then reserve that many bytes at the end of the partition |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 205 | Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 206 | char* result = NULL; |
Stephen Smalley | 516e4e2 | 2012-04-03 13:35:11 -0400 | [diff] [blame] | 207 | if (argc != 5) { |
| 208 | return ErrorAbort(state, "%s() expects 5 args, got %d", name, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 209 | } |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 210 | char* fs_type; |
| 211 | char* partition_type; |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 212 | char* location; |
Ken Sumrall | 8f132ed | 2011-01-14 18:55:05 -0800 | [diff] [blame] | 213 | char* fs_size; |
Stephen Smalley | 516e4e2 | 2012-04-03 13:35:11 -0400 | [diff] [blame] | 214 | char* mount_point; |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 215 | |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 216 | if (ReadArgs(state, argv, 5, &fs_type, &partition_type, &location, &fs_size, &mount_point) < 0) { |
| 217 | return NULL; |
| 218 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 219 | |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 220 | if (strlen(fs_type) == 0) { |
| 221 | ErrorAbort(state, "fs_type argument to %s() can't be empty", name); |
| 222 | goto done; |
| 223 | } |
| 224 | if (strlen(partition_type) == 0) { |
| 225 | ErrorAbort(state, "partition_type argument to %s() can't be empty", |
| 226 | name); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 227 | goto done; |
| 228 | } |
| 229 | if (strlen(location) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 230 | ErrorAbort(state, "location argument to %s() can't be empty", name); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 231 | goto done; |
| 232 | } |
| 233 | |
Stephen Smalley | 516e4e2 | 2012-04-03 13:35:11 -0400 | [diff] [blame] | 234 | if (strlen(mount_point) == 0) { |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 235 | ErrorAbort(state, "mount_point argument to %s() can't be empty", name); |
| 236 | goto done; |
| 237 | } |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 238 | |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 239 | if (strcmp(partition_type, "MTD") == 0) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 240 | mtd_scan_partitions(); |
| 241 | const MtdPartition* mtd = mtd_find_partition_by_name(location); |
| 242 | if (mtd == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 243 | printf("%s: no mtd partition named \"%s\"", |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 244 | name, location); |
| 245 | result = strdup(""); |
| 246 | goto done; |
| 247 | } |
| 248 | MtdWriteContext* ctx = mtd_write_partition(mtd); |
| 249 | if (ctx == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 250 | printf("%s: can't write \"%s\"", name, location); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 251 | result = strdup(""); |
| 252 | goto done; |
| 253 | } |
| 254 | if (mtd_erase_blocks(ctx, -1) == -1) { |
| 255 | mtd_write_close(ctx); |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 256 | printf("%s: failed to erase \"%s\"", name, location); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 257 | result = strdup(""); |
| 258 | goto done; |
| 259 | } |
| 260 | if (mtd_write_close(ctx) != 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 261 | printf("%s: failed to close \"%s\"", name, location); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 262 | result = strdup(""); |
| 263 | goto done; |
| 264 | } |
| 265 | result = location; |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 266 | #ifdef USE_EXT4 |
| 267 | } else if (strcmp(fs_type, "ext4") == 0) { |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 268 | int status = make_ext4fs(location, atoll(fs_size), mount_point, sehandle); |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 269 | if (status != 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 270 | printf("%s: make_ext4fs failed (%d) on %s", |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 271 | name, status, location); |
| 272 | result = strdup(""); |
| 273 | goto done; |
| 274 | } |
| 275 | result = location; |
| 276 | #endif |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 277 | } else { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 278 | printf("%s: unsupported fs_type \"%s\" partition_type \"%s\"", |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 279 | name, fs_type, partition_type); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | done: |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 283 | free(fs_type); |
| 284 | free(partition_type); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 285 | if (result != location) free(location); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 286 | return StringValue(result); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 289 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 290 | Value* DeleteFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 291 | char** paths = malloc(argc * sizeof(char*)); |
| 292 | int i; |
| 293 | for (i = 0; i < argc; ++i) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 294 | paths[i] = Evaluate(state, argv[i]); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 295 | if (paths[i] == NULL) { |
| 296 | int j; |
| 297 | for (j = 0; j < i; ++i) { |
| 298 | free(paths[j]); |
| 299 | } |
| 300 | free(paths); |
| 301 | return NULL; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | bool recursive = (strcmp(name, "delete_recursive") == 0); |
| 306 | |
| 307 | int success = 0; |
| 308 | for (i = 0; i < argc; ++i) { |
| 309 | if ((recursive ? dirUnlinkHierarchy(paths[i]) : unlink(paths[i])) == 0) |
| 310 | ++success; |
| 311 | free(paths[i]); |
| 312 | } |
| 313 | free(paths); |
| 314 | |
| 315 | char buffer[10]; |
| 316 | sprintf(buffer, "%d", success); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 317 | return StringValue(strdup(buffer)); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 320 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 321 | Value* ShowProgressFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 322 | if (argc != 2) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 323 | return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 324 | } |
| 325 | char* frac_str; |
| 326 | char* sec_str; |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 327 | if (ReadArgs(state, argv, 2, &frac_str, &sec_str) < 0) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 328 | return NULL; |
| 329 | } |
| 330 | |
| 331 | double frac = strtod(frac_str, NULL); |
| 332 | int sec = strtol(sec_str, NULL, 10); |
| 333 | |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 334 | UpdaterInfo* ui = (UpdaterInfo*)(state->cookie); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 335 | fprintf(ui->cmd_pipe, "progress %f %d\n", frac, sec); |
| 336 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 337 | free(sec_str); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 338 | return StringValue(frac_str); |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 341 | Value* SetProgressFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 342 | if (argc != 1) { |
| 343 | return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); |
| 344 | } |
| 345 | char* frac_str; |
| 346 | if (ReadArgs(state, argv, 1, &frac_str) < 0) { |
| 347 | return NULL; |
| 348 | } |
| 349 | |
| 350 | double frac = strtod(frac_str, NULL); |
| 351 | |
| 352 | UpdaterInfo* ui = (UpdaterInfo*)(state->cookie); |
| 353 | fprintf(ui->cmd_pipe, "set_progress %f\n", frac); |
| 354 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 355 | return StringValue(frac_str); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 358 | // package_extract_dir(package_path, destination_path) |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 359 | Value* PackageExtractDirFn(const char* name, State* state, |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 360 | int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 361 | if (argc != 2) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 362 | return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 363 | } |
| 364 | char* zip_path; |
| 365 | char* dest_path; |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 366 | if (ReadArgs(state, argv, 2, &zip_path, &dest_path) < 0) return NULL; |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 367 | |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 368 | ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 369 | |
| 370 | // To create a consistent system image, never use the clock for timestamps. |
| 371 | struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default |
| 372 | |
| 373 | bool success = mzExtractRecursive(za, zip_path, dest_path, |
| 374 | MZ_EXTRACT_FILES_ONLY, ×tamp, |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 375 | NULL, NULL, sehandle); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 376 | free(zip_path); |
| 377 | free(dest_path); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 378 | return StringValue(strdup(success ? "t" : "")); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 381 | |
| 382 | // package_extract_file(package_path, destination_path) |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 383 | // or |
| 384 | // package_extract_file(package_path) |
| 385 | // to return the entire contents of the file as the result of this |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 386 | // function (the char* returned is actually a FileContents*). |
| 387 | Value* PackageExtractFileFn(const char* name, State* state, |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 388 | int argc, Expr* argv[]) { |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 389 | if (argc != 1 && argc != 2) { |
| 390 | return ErrorAbort(state, "%s() expects 1 or 2 args, got %d", |
| 391 | name, argc); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 392 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 393 | bool success = false; |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 394 | if (argc == 2) { |
| 395 | // The two-argument version extracts to a file. |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 396 | |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 397 | char* zip_path; |
| 398 | char* dest_path; |
| 399 | if (ReadArgs(state, argv, 2, &zip_path, &dest_path) < 0) return NULL; |
| 400 | |
| 401 | ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; |
| 402 | const ZipEntry* entry = mzFindZipEntry(za, zip_path); |
| 403 | if (entry == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 404 | printf("%s: no %s in package\n", name, zip_path); |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 405 | goto done2; |
| 406 | } |
| 407 | |
| 408 | FILE* f = fopen(dest_path, "wb"); |
| 409 | if (f == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 410 | printf("%s: can't open %s for write: %s\n", |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 411 | name, dest_path, strerror(errno)); |
| 412 | goto done2; |
| 413 | } |
| 414 | success = mzExtractZipEntryToFile(za, entry, fileno(f)); |
| 415 | fclose(f); |
| 416 | |
| 417 | done2: |
| 418 | free(zip_path); |
| 419 | free(dest_path); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 420 | return StringValue(strdup(success ? "t" : "")); |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 421 | } else { |
| 422 | // The one-argument version returns the contents of the file |
| 423 | // as the result. |
| 424 | |
| 425 | char* zip_path; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 426 | Value* v = malloc(sizeof(Value)); |
| 427 | v->type = VAL_BLOB; |
| 428 | v->size = -1; |
| 429 | v->data = NULL; |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 430 | |
| 431 | if (ReadArgs(state, argv, 1, &zip_path) < 0) return NULL; |
| 432 | |
| 433 | ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip; |
| 434 | const ZipEntry* entry = mzFindZipEntry(za, zip_path); |
| 435 | if (entry == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 436 | printf("%s: no %s in package\n", name, zip_path); |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 437 | goto done1; |
| 438 | } |
| 439 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 440 | v->size = mzGetZipEntryUncompLen(entry); |
| 441 | v->data = malloc(v->size); |
| 442 | if (v->data == NULL) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 443 | printf("%s: failed to allocate %ld bytes for %s\n", |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 444 | name, (long)v->size, zip_path); |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 445 | goto done1; |
| 446 | } |
| 447 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 448 | success = mzExtractZipEntryToBuffer(za, entry, |
| 449 | (unsigned char *)v->data); |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 450 | |
| 451 | done1: |
| 452 | free(zip_path); |
| 453 | if (!success) { |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 454 | free(v->data); |
| 455 | v->data = NULL; |
| 456 | v->size = -1; |
Doug Zongker | 6aece33 | 2010-02-01 14:40:12 -0800 | [diff] [blame] | 457 | } |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 458 | return v; |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 459 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 462 | // Create all parent directories of name, if necessary. |
| 463 | static int make_parents(char* name) { |
| 464 | char* p; |
| 465 | for (p = name + (strlen(name)-1); p > name; --p) { |
| 466 | if (*p != '/') continue; |
| 467 | *p = '\0'; |
| 468 | if (make_parents(name) < 0) return -1; |
| 469 | int result = mkdir(name, 0700); |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 470 | if (result == 0) printf("symlink(): created [%s]\n", name); |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 471 | *p = '/'; |
| 472 | if (result == 0 || errno == EEXIST) { |
| 473 | // successfully created or already existed; we're done |
| 474 | return 0; |
| 475 | } else { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 476 | printf("failed to mkdir %s: %s\n", name, strerror(errno)); |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 477 | return -1; |
| 478 | } |
| 479 | } |
| 480 | return 0; |
| 481 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 482 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 483 | // symlink target src1 src2 ... |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 484 | // unlinks any previously existing src1, src2, etc before creating symlinks. |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 485 | Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 486 | if (argc == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 487 | return ErrorAbort(state, "%s() expects 1+ args, got %d", name, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 488 | } |
| 489 | char* target; |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 490 | target = Evaluate(state, argv[0]); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 491 | if (target == NULL) return NULL; |
| 492 | |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 493 | char** srcs = ReadVarArgs(state, argc-1, argv+1); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 494 | if (srcs == NULL) { |
| 495 | free(target); |
| 496 | return NULL; |
| 497 | } |
| 498 | |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 499 | int bad = 0; |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 500 | int i; |
| 501 | for (i = 0; i < argc-1; ++i) { |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 502 | if (unlink(srcs[i]) < 0) { |
| 503 | if (errno != ENOENT) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 504 | printf("%s: failed to remove %s: %s\n", |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 505 | name, srcs[i], strerror(errno)); |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 506 | ++bad; |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 507 | } |
| 508 | } |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 509 | if (make_parents(srcs[i])) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 510 | printf("%s: failed to symlink %s to %s: making parents failed\n", |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 511 | name, srcs[i], target); |
| 512 | ++bad; |
| 513 | } |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 514 | if (symlink(target, srcs[i]) < 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 515 | printf("%s: failed to symlink %s to %s: %s\n", |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 516 | name, srcs[i], target, strerror(errno)); |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 517 | ++bad; |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 518 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 519 | free(srcs[i]); |
| 520 | } |
| 521 | free(srcs); |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 522 | if (bad) { |
| 523 | return ErrorAbort(state, "%s: some symlinks failed", name); |
| 524 | } |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 525 | return StringValue(strdup("")); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 528 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 529 | Value* SetPermFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 530 | char* result = NULL; |
| 531 | bool recursive = (strcmp(name, "set_perm_recursive") == 0); |
| 532 | |
| 533 | int min_args = 4 + (recursive ? 1 : 0); |
| 534 | if (argc < min_args) { |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 535 | return ErrorAbort(state, "%s() expects %d+ args, got %d", |
| 536 | name, min_args, argc); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 539 | char** args = ReadVarArgs(state, argc, argv); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 540 | if (args == NULL) return NULL; |
| 541 | |
| 542 | char* end; |
| 543 | int i; |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 544 | int bad = 0; |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 545 | |
| 546 | int uid = strtoul(args[0], &end, 0); |
| 547 | if (*end != '\0' || args[0][0] == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 548 | ErrorAbort(state, "%s: \"%s\" not a valid uid", name, args[0]); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 549 | goto done; |
| 550 | } |
| 551 | |
| 552 | int gid = strtoul(args[1], &end, 0); |
| 553 | if (*end != '\0' || args[1][0] == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 554 | ErrorAbort(state, "%s: \"%s\" not a valid gid", name, args[1]); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 555 | goto done; |
| 556 | } |
| 557 | |
| 558 | if (recursive) { |
| 559 | int dir_mode = strtoul(args[2], &end, 0); |
| 560 | if (*end != '\0' || args[2][0] == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 561 | ErrorAbort(state, "%s: \"%s\" not a valid dirmode", name, args[2]); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 562 | goto done; |
| 563 | } |
| 564 | |
| 565 | int file_mode = strtoul(args[3], &end, 0); |
| 566 | if (*end != '\0' || args[3][0] == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 567 | ErrorAbort(state, "%s: \"%s\" not a valid filemode", |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 568 | name, args[3]); |
| 569 | goto done; |
| 570 | } |
| 571 | |
| 572 | for (i = 4; i < argc; ++i) { |
| 573 | dirSetHierarchyPermissions(args[i], uid, gid, dir_mode, file_mode); |
| 574 | } |
| 575 | } else { |
| 576 | int mode = strtoul(args[2], &end, 0); |
| 577 | if (*end != '\0' || args[2][0] == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 578 | ErrorAbort(state, "%s: \"%s\" not a valid mode", name, args[2]); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 579 | goto done; |
| 580 | } |
| 581 | |
Doug Zongker | 0bbfe3d | 2009-06-25 13:37:31 -0700 | [diff] [blame] | 582 | for (i = 3; i < argc; ++i) { |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 583 | if (chown(args[i], uid, gid) < 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 584 | printf("%s: chown of %s to %d %d failed: %s\n", |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 585 | name, args[i], uid, gid, strerror(errno)); |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 586 | ++bad; |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 587 | } |
| 588 | if (chmod(args[i], mode) < 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 589 | printf("%s: chmod of %s to %o failed: %s\n", |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 590 | name, args[i], mode, strerror(errno)); |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 591 | ++bad; |
Doug Zongker | 60babf8 | 2009-09-18 15:11:24 -0700 | [diff] [blame] | 592 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | result = strdup(""); |
| 596 | |
| 597 | done: |
| 598 | for (i = 0; i < argc; ++i) { |
| 599 | free(args[i]); |
| 600 | } |
| 601 | free(args); |
| 602 | |
Doug Zongker | acd73ed | 2012-03-22 14:32:52 -0700 | [diff] [blame] | 603 | if (bad) { |
| 604 | free(result); |
| 605 | return ErrorAbort(state, "%s: some changes failed", name); |
| 606 | } |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 607 | return StringValue(result); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 610 | struct perm_parsed_args { |
| 611 | bool has_uid; |
| 612 | uid_t uid; |
| 613 | bool has_gid; |
| 614 | gid_t gid; |
| 615 | bool has_mode; |
| 616 | mode_t mode; |
| 617 | bool has_fmode; |
| 618 | mode_t fmode; |
| 619 | bool has_dmode; |
| 620 | mode_t dmode; |
| 621 | bool has_selabel; |
| 622 | char* selabel; |
| 623 | bool has_capabilities; |
| 624 | uint64_t capabilities; |
| 625 | }; |
| 626 | |
| 627 | static struct perm_parsed_args ParsePermArgs(int argc, char** args) { |
| 628 | int i; |
| 629 | struct perm_parsed_args parsed; |
| 630 | int bad = 0; |
| 631 | static int max_warnings = 20; |
| 632 | |
| 633 | memset(&parsed, 0, sizeof(parsed)); |
| 634 | |
| 635 | for (i = 1; i < argc; i += 2) { |
| 636 | if (strcmp("uid", args[i]) == 0) { |
| 637 | int64_t uid; |
| 638 | if (sscanf(args[i+1], "%" SCNd64, &uid) == 1) { |
| 639 | parsed.uid = uid; |
| 640 | parsed.has_uid = true; |
| 641 | } else { |
| 642 | printf("ParsePermArgs: invalid UID \"%s\"\n", args[i + 1]); |
| 643 | bad++; |
| 644 | } |
| 645 | continue; |
| 646 | } |
| 647 | if (strcmp("gid", args[i]) == 0) { |
| 648 | int64_t gid; |
| 649 | if (sscanf(args[i+1], "%" SCNd64, &gid) == 1) { |
| 650 | parsed.gid = gid; |
| 651 | parsed.has_gid = true; |
| 652 | } else { |
| 653 | printf("ParsePermArgs: invalid GID \"%s\"\n", args[i + 1]); |
| 654 | bad++; |
| 655 | } |
| 656 | continue; |
| 657 | } |
| 658 | if (strcmp("mode", args[i]) == 0) { |
| 659 | int32_t mode; |
| 660 | if (sscanf(args[i+1], "%" SCNi32, &mode) == 1) { |
| 661 | parsed.mode = mode; |
| 662 | parsed.has_mode = true; |
| 663 | } else { |
| 664 | printf("ParsePermArgs: invalid mode \"%s\"\n", args[i + 1]); |
| 665 | bad++; |
| 666 | } |
| 667 | continue; |
| 668 | } |
| 669 | if (strcmp("dmode", args[i]) == 0) { |
| 670 | int32_t mode; |
| 671 | if (sscanf(args[i+1], "%" SCNi32, &mode) == 1) { |
| 672 | parsed.dmode = mode; |
| 673 | parsed.has_dmode = true; |
| 674 | } else { |
| 675 | printf("ParsePermArgs: invalid dmode \"%s\"\n", args[i + 1]); |
| 676 | bad++; |
| 677 | } |
| 678 | continue; |
| 679 | } |
| 680 | if (strcmp("fmode", args[i]) == 0) { |
| 681 | int32_t mode; |
| 682 | if (sscanf(args[i+1], "%" SCNi32, &mode) == 1) { |
| 683 | parsed.fmode = mode; |
| 684 | parsed.has_fmode = true; |
| 685 | } else { |
| 686 | printf("ParsePermArgs: invalid fmode \"%s\"\n", args[i + 1]); |
| 687 | bad++; |
| 688 | } |
| 689 | continue; |
| 690 | } |
| 691 | if (strcmp("capabilities", args[i]) == 0) { |
| 692 | int64_t capabilities; |
| 693 | if (sscanf(args[i+1], "%" SCNi64, &capabilities) == 1) { |
| 694 | parsed.capabilities = capabilities; |
| 695 | parsed.has_capabilities = true; |
| 696 | } else { |
| 697 | printf("ParsePermArgs: invalid capabilities \"%s\"\n", args[i + 1]); |
| 698 | bad++; |
| 699 | } |
| 700 | continue; |
| 701 | } |
| 702 | if (strcmp("selabel", args[i]) == 0) { |
| 703 | if (args[i+1][0] != '\0') { |
| 704 | parsed.selabel = args[i+1]; |
| 705 | parsed.has_selabel = true; |
| 706 | } else { |
| 707 | printf("ParsePermArgs: invalid selabel \"%s\"\n", args[i + 1]); |
| 708 | bad++; |
| 709 | } |
| 710 | continue; |
| 711 | } |
| 712 | if (max_warnings != 0) { |
| 713 | printf("ParsedPermArgs: unknown key \"%s\", ignoring\n", args[i]); |
| 714 | max_warnings--; |
| 715 | if (max_warnings == 0) { |
| 716 | printf("ParsedPermArgs: suppressing further warnings\n"); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | return parsed; |
| 721 | } |
| 722 | |
| 723 | static int ApplyParsedPerms( |
| 724 | const char* filename, |
| 725 | const struct stat *statptr, |
| 726 | struct perm_parsed_args parsed) |
| 727 | { |
| 728 | int bad = 0; |
| 729 | |
Nick Kralevich | e461251 | 2013-09-10 15:34:19 -0700 | [diff] [blame] | 730 | /* ignore symlinks */ |
| 731 | if (S_ISLNK(statptr->st_mode)) { |
| 732 | return 0; |
| 733 | } |
| 734 | |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 735 | if (parsed.has_uid) { |
| 736 | if (chown(filename, parsed.uid, -1) < 0) { |
| 737 | printf("ApplyParsedPerms: chown of %s to %d failed: %s\n", |
| 738 | filename, parsed.uid, strerror(errno)); |
| 739 | bad++; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | if (parsed.has_gid) { |
| 744 | if (chown(filename, -1, parsed.gid) < 0) { |
| 745 | printf("ApplyParsedPerms: chgrp of %s to %d failed: %s\n", |
| 746 | filename, parsed.gid, strerror(errno)); |
| 747 | bad++; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | if (parsed.has_mode) { |
| 752 | if (chmod(filename, parsed.mode) < 0) { |
| 753 | printf("ApplyParsedPerms: chmod of %s to %d failed: %s\n", |
| 754 | filename, parsed.mode, strerror(errno)); |
| 755 | bad++; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | if (parsed.has_dmode && S_ISDIR(statptr->st_mode)) { |
| 760 | if (chmod(filename, parsed.dmode) < 0) { |
| 761 | printf("ApplyParsedPerms: chmod of %s to %d failed: %s\n", |
| 762 | filename, parsed.dmode, strerror(errno)); |
| 763 | bad++; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | if (parsed.has_fmode && S_ISREG(statptr->st_mode)) { |
| 768 | if (chmod(filename, parsed.fmode) < 0) { |
| 769 | printf("ApplyParsedPerms: chmod of %s to %d failed: %s\n", |
| 770 | filename, parsed.fmode, strerror(errno)); |
| 771 | bad++; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | if (parsed.has_selabel) { |
| 776 | // TODO: Don't silently ignore ENOTSUP |
| 777 | if (lsetfilecon(filename, parsed.selabel) && (errno != ENOTSUP)) { |
| 778 | printf("ApplyParsedPerms: lsetfilecon of %s to %s failed: %s\n", |
| 779 | filename, parsed.selabel, strerror(errno)); |
| 780 | bad++; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | if (parsed.has_capabilities && S_ISREG(statptr->st_mode)) { |
| 785 | if (parsed.capabilities == 0) { |
| 786 | if ((removexattr(filename, XATTR_NAME_CAPS) == -1) && (errno != ENODATA)) { |
| 787 | // Report failure unless it's ENODATA (attribute not set) |
| 788 | printf("ApplyParsedPerms: removexattr of %s to %" PRIx64 " failed: %s\n", |
| 789 | filename, parsed.capabilities, strerror(errno)); |
| 790 | bad++; |
| 791 | } |
| 792 | } else { |
| 793 | struct vfs_cap_data cap_data; |
| 794 | memset(&cap_data, 0, sizeof(cap_data)); |
| 795 | cap_data.magic_etc = VFS_CAP_REVISION | VFS_CAP_FLAGS_EFFECTIVE; |
| 796 | cap_data.data[0].permitted = (uint32_t) (parsed.capabilities & 0xffffffff); |
| 797 | cap_data.data[0].inheritable = 0; |
| 798 | cap_data.data[1].permitted = (uint32_t) (parsed.capabilities >> 32); |
| 799 | cap_data.data[1].inheritable = 0; |
| 800 | if (setxattr(filename, XATTR_NAME_CAPS, &cap_data, sizeof(cap_data), 0) < 0) { |
| 801 | printf("ApplyParsedPerms: setcap of %s to %" PRIx64 " failed: %s\n", |
| 802 | filename, parsed.capabilities, strerror(errno)); |
| 803 | bad++; |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | return bad; |
| 809 | } |
| 810 | |
| 811 | // nftw doesn't allow us to pass along context, so we need to use |
| 812 | // global variables. *sigh* |
| 813 | static struct perm_parsed_args recursive_parsed_args; |
| 814 | |
| 815 | static int do_SetMetadataRecursive(const char* filename, const struct stat *statptr, |
| 816 | int fileflags, struct FTW *pfwt) { |
| 817 | return ApplyParsedPerms(filename, statptr, recursive_parsed_args); |
| 818 | } |
| 819 | |
| 820 | static Value* SetMetadataFn(const char* name, State* state, int argc, Expr* argv[]) { |
| 821 | int i; |
| 822 | int bad = 0; |
| 823 | static int nwarnings = 0; |
| 824 | struct stat sb; |
| 825 | Value* result = NULL; |
| 826 | |
| 827 | bool recursive = (strcmp(name, "set_metadata_recursive") == 0); |
| 828 | |
| 829 | if ((argc % 2) != 1) { |
| 830 | return ErrorAbort(state, "%s() expects an odd number of arguments, got %d", |
| 831 | name, argc); |
| 832 | } |
| 833 | |
| 834 | char** args = ReadVarArgs(state, argc, argv); |
| 835 | if (args == NULL) return NULL; |
| 836 | |
| 837 | if (lstat(args[0], &sb) == -1) { |
| 838 | result = ErrorAbort(state, "%s: Error on lstat of \"%s\": %s", name, args[0], strerror(errno)); |
| 839 | goto done; |
| 840 | } |
| 841 | |
| 842 | struct perm_parsed_args parsed = ParsePermArgs(argc, args); |
| 843 | |
| 844 | if (recursive) { |
| 845 | recursive_parsed_args = parsed; |
| 846 | bad += nftw(args[0], do_SetMetadataRecursive, 30, FTW_CHDIR | FTW_DEPTH | FTW_PHYS); |
| 847 | memset(&recursive_parsed_args, 0, sizeof(recursive_parsed_args)); |
| 848 | } else { |
| 849 | bad += ApplyParsedPerms(args[0], &sb, parsed); |
| 850 | } |
| 851 | |
| 852 | done: |
| 853 | for (i = 0; i < argc; ++i) { |
| 854 | free(args[i]); |
| 855 | } |
| 856 | free(args); |
| 857 | |
| 858 | if (result != NULL) { |
| 859 | return result; |
| 860 | } |
| 861 | |
| 862 | if (bad > 0) { |
| 863 | return ErrorAbort(state, "%s: some changes failed", name); |
| 864 | } |
| 865 | |
| 866 | return StringValue(strdup("")); |
| 867 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 868 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 869 | Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 870 | if (argc != 1) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 871 | return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 872 | } |
| 873 | char* key; |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 874 | key = Evaluate(state, argv[0]); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 875 | if (key == NULL) return NULL; |
| 876 | |
| 877 | char value[PROPERTY_VALUE_MAX]; |
| 878 | property_get(key, value, ""); |
| 879 | free(key); |
| 880 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 881 | return StringValue(strdup(value)); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 885 | // file_getprop(file, key) |
| 886 | // |
| 887 | // interprets 'file' as a getprop-style file (key=value pairs, one |
| 888 | // per line, # comment lines and blank lines okay), and returns the value |
| 889 | // for 'key' (or "" if it isn't defined). |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 890 | Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 891 | char* result = NULL; |
| 892 | char* buffer = NULL; |
| 893 | char* filename; |
| 894 | char* key; |
| 895 | if (ReadArgs(state, argv, 2, &filename, &key) < 0) { |
| 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | struct stat st; |
| 900 | if (stat(filename, &st) < 0) { |
| 901 | ErrorAbort(state, "%s: failed to stat \"%s\": %s", |
| 902 | name, filename, strerror(errno)); |
| 903 | goto done; |
| 904 | } |
| 905 | |
| 906 | #define MAX_FILE_GETPROP_SIZE 65536 |
| 907 | |
| 908 | if (st.st_size > MAX_FILE_GETPROP_SIZE) { |
| 909 | ErrorAbort(state, "%s too large for %s (max %d)", |
| 910 | filename, name, MAX_FILE_GETPROP_SIZE); |
| 911 | goto done; |
| 912 | } |
| 913 | |
| 914 | buffer = malloc(st.st_size+1); |
| 915 | if (buffer == NULL) { |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 916 | ErrorAbort(state, "%s: failed to alloc %lld bytes", name, st.st_size+1); |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 917 | goto done; |
| 918 | } |
| 919 | |
| 920 | FILE* f = fopen(filename, "rb"); |
| 921 | if (f == NULL) { |
| 922 | ErrorAbort(state, "%s: failed to open %s: %s", |
| 923 | name, filename, strerror(errno)); |
| 924 | goto done; |
| 925 | } |
| 926 | |
| 927 | if (fread(buffer, 1, st.st_size, f) != st.st_size) { |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 928 | ErrorAbort(state, "%s: failed to read %lld bytes from %s", |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 929 | name, st.st_size+1, filename); |
| 930 | fclose(f); |
| 931 | goto done; |
| 932 | } |
| 933 | buffer[st.st_size] = '\0'; |
| 934 | |
| 935 | fclose(f); |
| 936 | |
| 937 | char* line = strtok(buffer, "\n"); |
| 938 | do { |
| 939 | // skip whitespace at start of line |
| 940 | while (*line && isspace(*line)) ++line; |
| 941 | |
| 942 | // comment or blank line: skip to next line |
| 943 | if (*line == '\0' || *line == '#') continue; |
| 944 | |
| 945 | char* equal = strchr(line, '='); |
| 946 | if (equal == NULL) { |
| 947 | ErrorAbort(state, "%s: malformed line \"%s\": %s not a prop file?", |
| 948 | name, line, filename); |
| 949 | goto done; |
| 950 | } |
| 951 | |
| 952 | // trim whitespace between key and '=' |
| 953 | char* key_end = equal-1; |
| 954 | while (key_end > line && isspace(*key_end)) --key_end; |
| 955 | key_end[1] = '\0'; |
| 956 | |
| 957 | // not the key we're looking for |
| 958 | if (strcmp(key, line) != 0) continue; |
| 959 | |
| 960 | // skip whitespace after the '=' to the start of the value |
| 961 | char* val_start = equal+1; |
| 962 | while(*val_start && isspace(*val_start)) ++val_start; |
| 963 | |
| 964 | // trim trailing whitespace |
| 965 | char* val_end = val_start + strlen(val_start)-1; |
| 966 | while (val_end > val_start && isspace(*val_end)) --val_end; |
| 967 | val_end[1] = '\0'; |
| 968 | |
| 969 | result = strdup(val_start); |
| 970 | break; |
| 971 | |
| 972 | } while ((line = strtok(NULL, "\n"))); |
| 973 | |
| 974 | if (result == NULL) result = strdup(""); |
| 975 | |
| 976 | done: |
| 977 | free(filename); |
| 978 | free(key); |
| 979 | free(buffer); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 980 | return StringValue(result); |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 984 | static bool write_raw_image_cb(const unsigned char* data, |
| 985 | int data_len, void* ctx) { |
| 986 | int r = mtd_write_data((MtdWriteContext*)ctx, (const char *)data, data_len); |
| 987 | if (r == data_len) return true; |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 988 | printf("%s\n", strerror(errno)); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 989 | return false; |
| 990 | } |
| 991 | |
Doug Zongker | 179b2d9 | 2011-04-12 15:49:04 -0700 | [diff] [blame] | 992 | // write_raw_image(filename_or_blob, partition) |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 993 | Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 994 | char* result = NULL; |
| 995 | |
Doug Zongker | 179b2d9 | 2011-04-12 15:49:04 -0700 | [diff] [blame] | 996 | Value* partition_value; |
| 997 | Value* contents; |
| 998 | if (ReadValueArgs(state, argv, 2, &contents, &partition_value) < 0) { |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 999 | return NULL; |
| 1000 | } |
| 1001 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 1002 | char* partition = NULL; |
Doug Zongker | 179b2d9 | 2011-04-12 15:49:04 -0700 | [diff] [blame] | 1003 | if (partition_value->type != VAL_STRING) { |
| 1004 | ErrorAbort(state, "partition argument to %s must be string", name); |
| 1005 | goto done; |
| 1006 | } |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 1007 | partition = partition_value->data; |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1008 | if (strlen(partition) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1009 | ErrorAbort(state, "partition argument to %s can't be empty", name); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1010 | goto done; |
| 1011 | } |
Doug Zongker | 179b2d9 | 2011-04-12 15:49:04 -0700 | [diff] [blame] | 1012 | if (contents->type == VAL_STRING && strlen((char*) contents->data) == 0) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1013 | ErrorAbort(state, "file argument to %s can't be empty", name); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1014 | goto done; |
| 1015 | } |
| 1016 | |
Dees_Troy | 76a1d41 | 2013-04-20 13:54:35 +0000 | [diff] [blame] | 1017 | char* filename = contents->data; |
| 1018 | if (0 == restore_raw_partition(NULL, partition, filename)) |
| 1019 | result = strdup(partition); |
| 1020 | else { |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1021 | result = strdup(""); |
| 1022 | goto done; |
| 1023 | } |
| 1024 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1025 | done: |
Doug Zongker | 179b2d9 | 2011-04-12 15:49:04 -0700 | [diff] [blame] | 1026 | if (result != partition) FreeValue(partition_value); |
| 1027 | FreeValue(contents); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1028 | return StringValue(result); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1031 | // apply_patch_space(bytes) |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1032 | Value* ApplyPatchSpaceFn(const char* name, State* state, |
| 1033 | int argc, Expr* argv[]) { |
| 1034 | char* bytes_str; |
| 1035 | if (ReadArgs(state, argv, 1, &bytes_str) < 0) { |
| 1036 | return NULL; |
| 1037 | } |
| 1038 | |
| 1039 | char* endptr; |
| 1040 | size_t bytes = strtol(bytes_str, &endptr, 10); |
| 1041 | if (bytes == 0 && endptr == bytes_str) { |
| 1042 | ErrorAbort(state, "%s(): can't parse \"%s\" as byte count\n\n", |
| 1043 | name, bytes_str); |
| 1044 | free(bytes_str); |
| 1045 | return NULL; |
| 1046 | } |
| 1047 | |
| 1048 | return StringValue(strdup(CacheSizeCheck(bytes) ? "" : "t")); |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | // apply_patch(srcfile, tgtfile, tgtsha1, tgtsize, sha1_1, patch_1, ...) |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1053 | Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1054 | if (argc < 6 || (argc % 2) == 1) { |
| 1055 | return ErrorAbort(state, "%s(): expected at least 6 args and an " |
| 1056 | "even number, got %d", |
| 1057 | name, argc); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1060 | char* source_filename; |
| 1061 | char* target_filename; |
| 1062 | char* target_sha1; |
| 1063 | char* target_size_str; |
| 1064 | if (ReadArgs(state, argv, 4, &source_filename, &target_filename, |
| 1065 | &target_sha1, &target_size_str) < 0) { |
| 1066 | return NULL; |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1067 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1068 | |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1069 | char* endptr; |
| 1070 | size_t target_size = strtol(target_size_str, &endptr, 10); |
| 1071 | if (target_size == 0 && endptr == target_size_str) { |
| 1072 | ErrorAbort(state, "%s(): can't parse \"%s\" as byte count", |
| 1073 | name, target_size_str); |
| 1074 | free(source_filename); |
| 1075 | free(target_filename); |
| 1076 | free(target_sha1); |
| 1077 | free(target_size_str); |
| 1078 | return NULL; |
| 1079 | } |
| 1080 | |
| 1081 | int patchcount = (argc-4) / 2; |
| 1082 | Value** patches = ReadValueVarArgs(state, argc-4, argv+4); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1083 | |
| 1084 | int i; |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1085 | for (i = 0; i < patchcount; ++i) { |
| 1086 | if (patches[i*2]->type != VAL_STRING) { |
| 1087 | ErrorAbort(state, "%s(): sha-1 #%d is not string", name, i); |
| 1088 | break; |
| 1089 | } |
| 1090 | if (patches[i*2+1]->type != VAL_BLOB) { |
| 1091 | ErrorAbort(state, "%s(): patch #%d is not blob", name, i); |
| 1092 | break; |
| 1093 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1094 | } |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1095 | if (i != patchcount) { |
| 1096 | for (i = 0; i < patchcount*2; ++i) { |
| 1097 | FreeValue(patches[i]); |
| 1098 | } |
| 1099 | free(patches); |
| 1100 | return NULL; |
| 1101 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1102 | |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1103 | char** patch_sha_str = malloc(patchcount * sizeof(char*)); |
| 1104 | for (i = 0; i < patchcount; ++i) { |
| 1105 | patch_sha_str[i] = patches[i*2]->data; |
| 1106 | patches[i*2]->data = NULL; |
| 1107 | FreeValue(patches[i*2]); |
| 1108 | patches[i] = patches[i*2+1]; |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1109 | } |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1110 | |
| 1111 | int result = applypatch(source_filename, target_filename, |
| 1112 | target_sha1, target_size, |
Doug Zongker | a3ccba6 | 2012-08-20 15:28:02 -0700 | [diff] [blame] | 1113 | patchcount, patch_sha_str, patches, NULL); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1114 | |
| 1115 | for (i = 0; i < patchcount; ++i) { |
| 1116 | FreeValue(patches[i]); |
| 1117 | } |
| 1118 | free(patch_sha_str); |
| 1119 | free(patches); |
| 1120 | |
| 1121 | return StringValue(strdup(result == 0 ? "t" : "")); |
| 1122 | } |
| 1123 | |
| 1124 | // apply_patch_check(file, [sha1_1, ...]) |
| 1125 | Value* ApplyPatchCheckFn(const char* name, State* state, |
| 1126 | int argc, Expr* argv[]) { |
| 1127 | if (argc < 1) { |
| 1128 | return ErrorAbort(state, "%s(): expected at least 1 arg, got %d", |
| 1129 | name, argc); |
| 1130 | } |
| 1131 | |
| 1132 | char* filename; |
| 1133 | if (ReadArgs(state, argv, 1, &filename) < 0) { |
| 1134 | return NULL; |
| 1135 | } |
| 1136 | |
| 1137 | int patchcount = argc-1; |
| 1138 | char** sha1s = ReadVarArgs(state, argc-1, argv+1); |
| 1139 | |
| 1140 | int result = applypatch_check(filename, patchcount, sha1s); |
| 1141 | |
| 1142 | int i; |
| 1143 | for (i = 0; i < patchcount; ++i) { |
| 1144 | free(sha1s[i]); |
| 1145 | } |
| 1146 | free(sha1s); |
| 1147 | |
| 1148 | return StringValue(strdup(result == 0 ? "t" : "")); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1151 | Value* UIPrintFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1152 | char** args = ReadVarArgs(state, argc, argv); |
| 1153 | if (args == NULL) { |
| 1154 | return NULL; |
| 1155 | } |
| 1156 | |
| 1157 | int size = 0; |
| 1158 | int i; |
| 1159 | for (i = 0; i < argc; ++i) { |
| 1160 | size += strlen(args[i]); |
| 1161 | } |
| 1162 | char* buffer = malloc(size+1); |
| 1163 | size = 0; |
| 1164 | for (i = 0; i < argc; ++i) { |
| 1165 | strcpy(buffer+size, args[i]); |
| 1166 | size += strlen(args[i]); |
| 1167 | free(args[i]); |
| 1168 | } |
| 1169 | free(args); |
| 1170 | buffer[size] = '\0'; |
| 1171 | |
| 1172 | char* line = strtok(buffer, "\n"); |
| 1173 | while (line) { |
| 1174 | fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe, |
| 1175 | "ui_print %s\n", line); |
| 1176 | line = strtok(NULL, "\n"); |
| 1177 | } |
| 1178 | fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe, "ui_print\n"); |
| 1179 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1180 | return StringValue(buffer); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 1183 | Value* WipeCacheFn(const char* name, State* state, int argc, Expr* argv[]) { |
| 1184 | if (argc != 0) { |
| 1185 | return ErrorAbort(state, "%s() expects no args, got %d", name, argc); |
| 1186 | } |
| 1187 | fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe, "wipe_cache\n"); |
| 1188 | return StringValue(strdup("t")); |
| 1189 | } |
| 1190 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1191 | Value* RunProgramFn(const char* name, State* state, int argc, Expr* argv[]) { |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1192 | if (argc < 1) { |
| 1193 | return ErrorAbort(state, "%s() expects at least 1 arg", name); |
| 1194 | } |
| 1195 | char** args = ReadVarArgs(state, argc, argv); |
| 1196 | if (args == NULL) { |
| 1197 | return NULL; |
| 1198 | } |
| 1199 | |
| 1200 | char** args2 = malloc(sizeof(char*) * (argc+1)); |
| 1201 | memcpy(args2, args, sizeof(char*) * argc); |
| 1202 | args2[argc] = NULL; |
| 1203 | |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1204 | printf("about to run program [%s] with %d args\n", args2[0], argc); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1205 | |
| 1206 | pid_t child = fork(); |
| 1207 | if (child == 0) { |
| 1208 | execv(args2[0], args2); |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1209 | printf("run_program: execv failed: %s\n", strerror(errno)); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1210 | _exit(1); |
| 1211 | } |
| 1212 | int status; |
| 1213 | waitpid(child, &status, 0); |
| 1214 | if (WIFEXITED(status)) { |
| 1215 | if (WEXITSTATUS(status) != 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1216 | printf("run_program: child exited with status %d\n", |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1217 | WEXITSTATUS(status)); |
| 1218 | } |
| 1219 | } else if (WIFSIGNALED(status)) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1220 | printf("run_program: child terminated by signal %d\n", |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1221 | WTERMSIG(status)); |
| 1222 | } |
| 1223 | |
| 1224 | int i; |
| 1225 | for (i = 0; i < argc; ++i) { |
| 1226 | free(args[i]); |
| 1227 | } |
| 1228 | free(args); |
| 1229 | free(args2); |
| 1230 | |
| 1231 | char buffer[20]; |
| 1232 | sprintf(buffer, "%d", status); |
| 1233 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1234 | return StringValue(strdup(buffer)); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1237 | // Take a sha-1 digest and return it as a newly-allocated hex string. |
| 1238 | static char* PrintSha1(uint8_t* digest) { |
| 1239 | char* buffer = malloc(SHA_DIGEST_SIZE*2 + 1); |
| 1240 | int i; |
| 1241 | const char* alphabet = "0123456789abcdef"; |
| 1242 | for (i = 0; i < SHA_DIGEST_SIZE; ++i) { |
| 1243 | buffer[i*2] = alphabet[(digest[i] >> 4) & 0xf]; |
| 1244 | buffer[i*2+1] = alphabet[digest[i] & 0xf]; |
| 1245 | } |
| 1246 | buffer[i*2] = '\0'; |
| 1247 | return buffer; |
| 1248 | } |
| 1249 | |
| 1250 | // sha1_check(data) |
| 1251 | // to return the sha1 of the data (given in the format returned by |
| 1252 | // read_file). |
| 1253 | // |
| 1254 | // sha1_check(data, sha1_hex, [sha1_hex, ...]) |
| 1255 | // returns the sha1 of the file if it matches any of the hex |
| 1256 | // strings passed, or "" if it does not equal any of them. |
| 1257 | // |
| 1258 | Value* Sha1CheckFn(const char* name, State* state, int argc, Expr* argv[]) { |
| 1259 | if (argc < 1) { |
| 1260 | return ErrorAbort(state, "%s() expects at least 1 arg", name); |
| 1261 | } |
| 1262 | |
| 1263 | Value** args = ReadValueVarArgs(state, argc, argv); |
| 1264 | if (args == NULL) { |
| 1265 | return NULL; |
| 1266 | } |
| 1267 | |
| 1268 | if (args[0]->size < 0) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1269 | printf("%s(): no file contents received", name); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1270 | return StringValue(strdup("")); |
| 1271 | } |
| 1272 | uint8_t digest[SHA_DIGEST_SIZE]; |
Doug Zongker | bac7fba | 2013-04-10 11:32:17 -0700 | [diff] [blame] | 1273 | SHA_hash(args[0]->data, args[0]->size, digest); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1274 | FreeValue(args[0]); |
| 1275 | |
| 1276 | if (argc == 1) { |
| 1277 | return StringValue(PrintSha1(digest)); |
| 1278 | } |
| 1279 | |
| 1280 | int i; |
| 1281 | uint8_t* arg_digest = malloc(SHA_DIGEST_SIZE); |
| 1282 | for (i = 1; i < argc; ++i) { |
| 1283 | if (args[i]->type != VAL_STRING) { |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1284 | printf("%s(): arg %d is not a string; skipping", |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1285 | name, i); |
| 1286 | } else if (ParseSha1(args[i]->data, arg_digest) != 0) { |
| 1287 | // Warn about bad args and skip them. |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 1288 | printf("%s(): error parsing \"%s\" as sha-1; skipping", |
| 1289 | name, args[i]->data); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1290 | } else if (memcmp(digest, arg_digest, SHA_DIGEST_SIZE) == 0) { |
| 1291 | break; |
| 1292 | } |
| 1293 | FreeValue(args[i]); |
| 1294 | } |
| 1295 | if (i >= argc) { |
| 1296 | // Didn't match any of the hex strings; return false. |
| 1297 | return StringValue(strdup("")); |
| 1298 | } |
| 1299 | // Found a match; free all the remaining arguments and return the |
| 1300 | // matched one. |
| 1301 | int j; |
| 1302 | for (j = i+1; j < argc; ++j) { |
| 1303 | FreeValue(args[j]); |
| 1304 | } |
| 1305 | return args[i]; |
| 1306 | } |
| 1307 | |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 1308 | // Read a local file and return its contents (the Value* returned |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1309 | // is actually a FileContents*). |
| 1310 | Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) { |
| 1311 | if (argc != 1) { |
| 1312 | return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); |
| 1313 | } |
| 1314 | char* filename; |
| 1315 | if (ReadArgs(state, argv, 1, &filename) < 0) return NULL; |
| 1316 | |
| 1317 | Value* v = malloc(sizeof(Value)); |
| 1318 | v->type = VAL_BLOB; |
| 1319 | |
| 1320 | FileContents fc; |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 1321 | if (LoadFileContents(filename, &fc, RETOUCH_DONT_MASK) != 0) { |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1322 | ErrorAbort(state, "%s() loading \"%s\" failed: %s", |
| 1323 | name, filename, strerror(errno)); |
| 1324 | free(filename); |
| 1325 | free(v); |
| 1326 | free(fc.data); |
| 1327 | return NULL; |
| 1328 | } |
| 1329 | |
| 1330 | v->size = fc.size; |
| 1331 | v->data = (char*)fc.data; |
| 1332 | |
| 1333 | free(filename); |
| 1334 | return v; |
| 1335 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1336 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1337 | void RegisterInstallFunctions() { |
| 1338 | RegisterFunction("mount", MountFn); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1339 | RegisterFunction("is_mounted", IsMountedFn); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1340 | RegisterFunction("unmount", UnmountFn); |
| 1341 | RegisterFunction("format", FormatFn); |
| 1342 | RegisterFunction("show_progress", ShowProgressFn); |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 1343 | RegisterFunction("set_progress", SetProgressFn); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1344 | RegisterFunction("delete", DeleteFn); |
| 1345 | RegisterFunction("delete_recursive", DeleteFn); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1346 | RegisterFunction("package_extract_dir", PackageExtractDirFn); |
| 1347 | RegisterFunction("package_extract_file", PackageExtractFileFn); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1348 | RegisterFunction("symlink", SymlinkFn); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 1349 | |
| 1350 | // Maybe, at some future point, we can delete these functions? They have been |
| 1351 | // replaced by perm_set and perm_set_recursive. |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1352 | RegisterFunction("set_perm", SetPermFn); |
| 1353 | RegisterFunction("set_perm_recursive", SetPermFn); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1354 | |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 1355 | // Usage: |
| 1356 | // set_metadata("filename", "key1", "value1", "key2", "value2", ...) |
| 1357 | // Example: |
| 1358 | // set_metadata("/system/bin/netcfg", "uid", 0, "gid", 3003, "mode", 02750, "selabel", "u:object_r:system_file:s0", "capabilities", 0x0); |
| 1359 | RegisterFunction("set_metadata", SetMetadataFn); |
| 1360 | |
| 1361 | // Usage: |
| 1362 | // set_metadata_recursive("dirname", "key1", "value1", "key2", "value2", ...) |
| 1363 | // Example: |
| 1364 | // set_metadata_recursive("/system", "uid", 0, "gid", 0, "fmode", 0644, "dmode", 0755, "selabel", "u:object_r:system_file:s0", "capabilities", 0x0); |
| 1365 | RegisterFunction("set_metadata_recursive", SetMetadataFn); |
| 1366 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1367 | RegisterFunction("getprop", GetPropFn); |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 1368 | RegisterFunction("file_getprop", FileGetPropFn); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1369 | RegisterFunction("write_raw_image", WriteRawImageFn); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1370 | |
| 1371 | RegisterFunction("apply_patch", ApplyPatchFn); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1372 | RegisterFunction("apply_patch_check", ApplyPatchCheckFn); |
| 1373 | RegisterFunction("apply_patch_space", ApplyPatchSpaceFn); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1374 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1375 | RegisterFunction("read_file", ReadFileFn); |
| 1376 | RegisterFunction("sha1_check", Sha1CheckFn); |
| 1377 | |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 1378 | RegisterFunction("wipe_cache", WipeCacheFn); |
| 1379 | |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1380 | RegisterFunction("ui_print", UIPrintFn); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1381 | |
| 1382 | RegisterFunction("run_program", RunProgramFn); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1383 | } |