blob: 750e04090963f06328214c6abf593f75456e4367 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
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
17#include <stdarg.h>
18#include <stdlib.h>
19#include <stdio.h>
20#include <string.h>
21#include <fcntl.h>
22#include <ctype.h>
23#include <errno.h>
Colin Cross504bc512010-04-13 19:35:09 -070024#include <time.h>
Nick Kralevichae76f6d2013-07-11 15:38:26 -070025#include <ftw.h>
William Roberts3792e6c2016-04-06 19:18:50 -070026#include <pwd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080027
Stephen Smalleye46f9d52012-01-13 08:48:47 -050028#include <selinux/label.h>
Stephen Smalleydbd37f22014-01-28 10:34:09 -050029#include <selinux/android.h>
Stephen Smalleye46f9d52012-01-13 08:48:47 -050030
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080031#include <sys/stat.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34#include <sys/un.h>
35
Elliott Hughes4f713192015-12-04 22:00:26 -080036#include <android-base/file.h>
37#include <android-base/strings.h>
Dan Albertc007bc32015-03-16 10:08:46 -070038
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080039/* for ANDROID_SOCKET_* */
40#include <cutils/sockets.h>
Elliott Hughes4f713192015-12-04 22:00:26 -080041#include <android-base/stringprintf.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042
Stephen Smalleye46f9d52012-01-13 08:48:47 -050043#include "init.h"
Colin Crossed8a7d82010-04-19 17:05:34 -070044#include "log.h"
Tom Cherryb7349902015-08-26 11:43:36 -070045#include "property_service.h"
Colin Crossf83d0b92010-04-21 12:04:20 -070046#include "util.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080047
Nick Kralevichd2104df2015-06-18 17:46:54 -070048static unsigned int do_decode_uid(const char *s)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080049{
50 unsigned int v;
51
52 if (!s || *s == '\0')
Nick Kralevichd2104df2015-06-18 17:46:54 -070053 return UINT_MAX;
William Roberts3792e6c2016-04-06 19:18:50 -070054
55 if (isalpha(s[0])) {
56 struct passwd* pwd = getpwnam(s);
57 if (!pwd)
58 return UINT_MAX;
59 return pwd->pw_uid;
60 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080061
62 errno = 0;
63 v = (unsigned int) strtoul(s, 0, 0);
64 if (errno)
Nick Kralevichd2104df2015-06-18 17:46:54 -070065 return UINT_MAX;
66 return v;
67}
68
69/*
70 * decode_uid - decodes and returns the given string, which can be either the
71 * numeric or name representation, into the integer uid or gid. Returns
72 * UINT_MAX on error.
73 */
74unsigned int decode_uid(const char *s) {
75 unsigned int v = do_decode_uid(s);
76 if (v == UINT_MAX) {
77 ERROR("decode_uid: Unable to find UID for '%s'. Returning UINT_MAX\n", s);
78 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079 return v;
80}
81
82/*
83 * create_socket - creates a Unix domain socket in ANDROID_SOCKET_DIR
84 * ("/dev/socket") as dictated in init.rc. This socket is inherited by the
85 * daemon. We communicate the file descriptor's value via the environment
86 * variable ANDROID_SOCKET_ENV_PREFIX<name> ("ANDROID_SOCKET_foo").
87 */
Stephen Smalley8348d272013-05-13 12:37:04 -040088int create_socket(const char *name, int type, mode_t perm, uid_t uid,
89 gid_t gid, const char *socketcon)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080090{
91 struct sockaddr_un addr;
Nick Kralevich9bcfd642016-02-24 15:50:52 -080092 int fd, ret, savederrno;
Stephen Smalley8348d272013-05-13 12:37:04 -040093 char *filecon;
94
Nick Kralevich83ccb1c2015-11-23 16:26:42 -080095 if (socketcon) {
96 if (setsockcreatecon(socketcon) == -1) {
97 ERROR("setsockcreatecon(\"%s\") failed: %s\n", socketcon, strerror(errno));
98 return -1;
99 }
100 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800101
102 fd = socket(PF_UNIX, type, 0);
103 if (fd < 0) {
104 ERROR("Failed to open socket '%s': %s\n", name, strerror(errno));
105 return -1;
106 }
107
Stephen Smalley8348d272013-05-13 12:37:04 -0400108 if (socketcon)
109 setsockcreatecon(NULL);
110
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800111 memset(&addr, 0 , sizeof(addr));
112 addr.sun_family = AF_UNIX;
113 snprintf(addr.sun_path, sizeof(addr.sun_path), ANDROID_SOCKET_DIR"/%s",
114 name);
115
116 ret = unlink(addr.sun_path);
117 if (ret != 0 && errno != ENOENT) {
118 ERROR("Failed to unlink old socket '%s': %s\n", name, strerror(errno));
119 goto out_close;
120 }
121
Stephen Smalley8348d272013-05-13 12:37:04 -0400122 filecon = NULL;
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500123 if (sehandle) {
Stephen Smalley8348d272013-05-13 12:37:04 -0400124 ret = selabel_lookup(sehandle, &filecon, addr.sun_path, S_IFSOCK);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500125 if (ret == 0)
Stephen Smalley8348d272013-05-13 12:37:04 -0400126 setfscreatecon(filecon);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500127 }
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500128
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800129 ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
Nick Kralevich9bcfd642016-02-24 15:50:52 -0800130 savederrno = errno;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800131
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500132 setfscreatecon(NULL);
Stephen Smalley8348d272013-05-13 12:37:04 -0400133 freecon(filecon);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500134
Nick Kralevich9bcfd642016-02-24 15:50:52 -0800135 if (ret) {
136 ERROR("Failed to bind socket '%s': %s\n", name, strerror(savederrno));
137 goto out_unlink;
138 }
139
140 ret = lchown(addr.sun_path, uid, gid);
141 if (ret) {
142 ERROR("Failed to lchown socket '%s': %s\n", addr.sun_path, strerror(errno));
143 goto out_unlink;
144 }
145 ret = fchmodat(AT_FDCWD, addr.sun_path, perm, AT_SYMLINK_NOFOLLOW);
146 if (ret) {
147 ERROR("Failed to fchmodat socket '%s': %s\n", addr.sun_path, strerror(errno));
148 goto out_unlink;
149 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800150
151 INFO("Created socket '%s' with mode '%o', user '%d', group '%d'\n",
152 addr.sun_path, perm, uid, gid);
153
154 return fd;
155
156out_unlink:
157 unlink(addr.sun_path);
158out_close:
159 close(fd);
160 return -1;
161}
162
Elliott Hughesf682b472015-02-06 12:19:48 -0800163bool read_file(const char* path, std::string* content) {
164 content->clear();
165
166 int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC));
167 if (fd == -1) {
168 return false;
169 }
170
171 // For security reasons, disallow world-writable
172 // or group-writable files.
Nick Kralevich38f368c2012-01-18 10:39:01 -0800173 struct stat sb;
Elliott Hughesf682b472015-02-06 12:19:48 -0800174 if (fstat(fd, &sb) == -1) {
175 ERROR("fstat failed for '%s': %s\n", path, strerror(errno));
176 return false;
Nick Kralevich38f368c2012-01-18 10:39:01 -0800177 }
178 if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
Elliott Hughesf682b472015-02-06 12:19:48 -0800179 ERROR("skipping insecure file '%s'\n", path);
180 return false;
Nick Kralevich38f368c2012-01-18 10:39:01 -0800181 }
182
Dan Albertc007bc32015-03-16 10:08:46 -0700183 bool okay = android::base::ReadFdToString(fd, content);
Elliott Hughes9fc83432015-05-15 19:16:40 -0700184 close(fd);
Elliott Hughesf682b472015-02-06 12:19:48 -0800185 return okay;
186}
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800187
Elliott Hughesf682b472015-02-06 12:19:48 -0800188int write_file(const char* path, const char* content) {
189 int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0600));
190 if (fd == -1) {
Nick Kralevicheedbe812015-04-25 14:10:03 -0700191 NOTICE("write_file: Unable to open '%s': %s\n", path, strerror(errno));
192 return -1;
Elliott Hughesf682b472015-02-06 12:19:48 -0800193 }
Nick Kralevicheedbe812015-04-25 14:10:03 -0700194 int result = android::base::WriteStringToFd(content, fd) ? 0 : -1;
195 if (result == -1) {
196 NOTICE("write_file: Unable to write to '%s': %s\n", path, strerror(errno));
197 }
Elliott Hughes9fc83432015-05-15 19:16:40 -0700198 close(fd);
Elliott Hughesf682b472015-02-06 12:19:48 -0800199 return result;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800200}
201
Colin Crossf24ed8c2010-04-12 18:51:06 -0700202#define MAX_MTD_PARTITIONS 16
203
204static struct {
205 char name[16];
206 int number;
207} mtd_part_map[MAX_MTD_PARTITIONS];
208
209static int mtd_part_count = -1;
210
211static void find_mtd_partitions(void)
212{
213 int fd;
214 char buf[1024];
215 char *pmtdbufp;
216 ssize_t pmtdsize;
217 int r;
218
Nick Kralevich45a884f2015-02-02 14:37:22 -0800219 fd = open("/proc/mtd", O_RDONLY|O_CLOEXEC);
Colin Crossf24ed8c2010-04-12 18:51:06 -0700220 if (fd < 0)
221 return;
222
223 buf[sizeof(buf) - 1] = '\0';
224 pmtdsize = read(fd, buf, sizeof(buf) - 1);
225 pmtdbufp = buf;
226 while (pmtdsize > 0) {
227 int mtdnum, mtdsize, mtderasesize;
228 char mtdname[16];
229 mtdname[0] = '\0';
230 mtdnum = -1;
231 r = sscanf(pmtdbufp, "mtd%d: %x %x %15s",
232 &mtdnum, &mtdsize, &mtderasesize, mtdname);
233 if ((r == 4) && (mtdname[0] == '"')) {
234 char *x = strchr(mtdname + 1, '"');
235 if (x) {
236 *x = 0;
237 }
238 INFO("mtd partition %d, %s\n", mtdnum, mtdname + 1);
239 if (mtd_part_count < MAX_MTD_PARTITIONS) {
240 strcpy(mtd_part_map[mtd_part_count].name, mtdname + 1);
241 mtd_part_map[mtd_part_count].number = mtdnum;
242 mtd_part_count++;
243 } else {
244 ERROR("too many mtd partitions\n");
245 }
246 }
247 while (pmtdsize > 0 && *pmtdbufp != '\n') {
248 pmtdbufp++;
249 pmtdsize--;
250 }
251 if (pmtdsize > 0) {
252 pmtdbufp++;
253 pmtdsize--;
254 }
255 }
256 close(fd);
257}
258
259int mtd_name_to_number(const char *name)
260{
261 int n;
262 if (mtd_part_count < 0) {
263 mtd_part_count = 0;
264 find_mtd_partitions();
265 }
266 for (n = 0; n < mtd_part_count; n++) {
267 if (!strcmp(name, mtd_part_map[n].name)) {
268 return mtd_part_map[n].number;
269 }
270 }
271 return -1;
272}
Colin Cross504bc512010-04-13 19:35:09 -0700273
Elliott Hughesda40c002015-03-27 23:20:44 -0700274time_t gettime() {
275 timespec now;
276 clock_gettime(CLOCK_MONOTONIC, &now);
277 return now.tv_sec;
278}
Colin Cross504bc512010-04-13 19:35:09 -0700279
Elliott Hughesda40c002015-03-27 23:20:44 -0700280uint64_t gettime_ns() {
281 timespec now;
282 clock_gettime(CLOCK_MONOTONIC, &now);
283 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec;
Colin Cross504bc512010-04-13 19:35:09 -0700284}
Colin Crossb0ab94b2010-04-08 16:16:20 -0700285
286int mkdir_recursive(const char *pathname, mode_t mode)
287{
288 char buf[128];
289 const char *slash;
290 const char *p = pathname;
291 int width;
292 int ret;
293 struct stat info;
294
295 while ((slash = strchr(p, '/')) != NULL) {
296 width = slash - pathname;
297 p = slash + 1;
298 if (width < 0)
299 break;
300 if (width == 0)
301 continue;
302 if ((unsigned int)width > sizeof(buf) - 1) {
303 ERROR("path too long for mkdir_recursive\n");
304 return -1;
305 }
306 memcpy(buf, pathname, width);
307 buf[width] = 0;
308 if (stat(buf, &info) != 0) {
Stephen Smalleye096e362012-06-11 13:37:39 -0400309 ret = make_dir(buf, mode);
Colin Crossb0ab94b2010-04-08 16:16:20 -0700310 if (ret && errno != EEXIST)
311 return ret;
312 }
313 }
Stephen Smalleye096e362012-06-11 13:37:39 -0400314 ret = make_dir(pathname, mode);
Colin Crossb0ab94b2010-04-08 16:16:20 -0700315 if (ret && errno != EEXIST)
316 return ret;
317 return 0;
318}
319
Johan Redestig93ca79b2012-04-18 16:41:19 +0200320/*
321 * replaces any unacceptable characters with '_', the
322 * length of the resulting string is equal to the input string
323 */
Colin Crossb0ab94b2010-04-08 16:16:20 -0700324void sanitize(char *s)
325{
Johan Redestig93ca79b2012-04-18 16:41:19 +0200326 const char* accept =
327 "abcdefghijklmnopqrstuvwxyz"
328 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
329 "0123456789"
330 "_-.";
331
Colin Crossb0ab94b2010-04-08 16:16:20 -0700332 if (!s)
333 return;
Johan Redestig93ca79b2012-04-18 16:41:19 +0200334
Christopher R. Palmer07f3fee2014-09-22 14:35:54 -0400335 while (*s) {
Johan Redestig93ca79b2012-04-18 16:41:19 +0200336 s += strspn(s, accept);
Christopher R. Palmer07f3fee2014-09-22 14:35:54 -0400337 if (*s) *s++ = '_';
Johan Redestig93ca79b2012-04-18 16:41:19 +0200338 }
Colin Crossb0ab94b2010-04-08 16:16:20 -0700339}
Johan Redestig93ca79b2012-04-18 16:41:19 +0200340
Chris Fries79f33842013-09-05 13:19:21 -0500341void make_link_init(const char *oldpath, const char *newpath)
Colin Crossb0ab94b2010-04-08 16:16:20 -0700342{
343 int ret;
344 char buf[256];
Dan Austina27bbd22016-03-24 11:28:46 -0700345 const char *slash;
Colin Crossb0ab94b2010-04-08 16:16:20 -0700346 int width;
347
348 slash = strrchr(newpath, '/');
349 if (!slash)
350 return;
351 width = slash - newpath;
352 if (width <= 0 || width > (int)sizeof(buf) - 1)
353 return;
354 memcpy(buf, newpath, width);
355 buf[width] = 0;
356 ret = mkdir_recursive(buf, 0755);
357 if (ret)
358 ERROR("Failed to create directory %s: %s (%d)\n", buf, strerror(errno), errno);
359
360 ret = symlink(oldpath, newpath);
361 if (ret && errno != EEXIST)
362 ERROR("Failed to symlink %s to %s: %s (%d)\n", oldpath, newpath, strerror(errno), errno);
363}
364
365void remove_link(const char *oldpath, const char *newpath)
366{
367 char path[256];
368 ssize_t ret;
369 ret = readlink(newpath, path, sizeof(path) - 1);
370 if (ret <= 0)
371 return;
372 path[ret] = 0;
373 if (!strcmp(path, oldpath))
374 unlink(newpath);
375}
Colin Crosscd0f1732010-04-19 17:10:24 -0700376
377int wait_for_file(const char *filename, int timeout)
378{
379 struct stat info;
Thierry Strudel91cf41c2015-05-22 15:56:14 -0700380 uint64_t timeout_time_ns = gettime_ns() + timeout * UINT64_C(1000000000);
Colin Crosscd0f1732010-04-19 17:10:24 -0700381 int ret = -1;
382
Thierry Strudel91cf41c2015-05-22 15:56:14 -0700383 while (gettime_ns() < timeout_time_ns && ((ret = stat(filename, &info)) < 0))
Colin Crosscd0f1732010-04-19 17:10:24 -0700384 usleep(10000);
385
386 return ret;
387}
Colin Crossf83d0b92010-04-21 12:04:20 -0700388
389void open_devnull_stdio(void)
390{
Nick Kraleviche34577c2015-04-25 16:24:53 -0700391 int fd = open("/sys/fs/selinux/null", O_RDWR);
392 if (fd == -1) {
Nick Kralevich3d9e2732016-03-03 10:40:12 -0800393 /* Fail silently.
394 * stdout/stderr isn't available, and because
395 * klog_init() is called after open_devnull_stdio(), we can't
396 * log to dmesg. Reordering klog_init() to be called before
397 * open_devnull_stdio() isn't an option either, as then klog_fd
398 * will be assigned 0 or 1, which will end up getting clobbered
399 * by the code below. There's nowhere good to log.
400 */
401
402 exit(1);
Colin Crossf83d0b92010-04-21 12:04:20 -0700403 }
404
Nick Kraleviche34577c2015-04-25 16:24:53 -0700405 dup2(fd, 0);
406 dup2(fd, 1);
407 dup2(fd, 2);
408 if (fd > 2) {
409 close(fd);
410 }
Colin Crossf83d0b92010-04-21 12:04:20 -0700411}
412
Elliott Hughese5ce30f2015-05-06 19:19:24 -0700413void import_kernel_cmdline(bool in_qemu,
414 std::function<void(const std::string&, const std::string&, bool)> fn) {
415 std::string cmdline;
416 android::base::ReadFileToString("/proc/cmdline", &cmdline);
Vladimir Chtchetkine2b995432011-09-28 09:55:31 -0700417
Elliott Hughese5ce30f2015-05-06 19:19:24 -0700418 for (const auto& entry : android::base::Split(android::base::Trim(cmdline), " ")) {
419 std::vector<std::string> pieces = android::base::Split(entry, "=");
420 if (pieces.size() == 2) {
421 fn(pieces[0], pieces[1], in_qemu);
422 }
Vladimir Chtchetkine2b995432011-09-28 09:55:31 -0700423 }
424}
Stephen Smalleye096e362012-06-11 13:37:39 -0400425
426int make_dir(const char *path, mode_t mode)
427{
428 int rc;
429
Stephen Smalleye096e362012-06-11 13:37:39 -0400430 char *secontext = NULL;
431
432 if (sehandle) {
433 selabel_lookup(sehandle, &secontext, path, mode);
434 setfscreatecon(secontext);
435 }
Stephen Smalleye096e362012-06-11 13:37:39 -0400436
437 rc = mkdir(path, mode);
438
Stephen Smalleye096e362012-06-11 13:37:39 -0400439 if (secontext) {
440 int save_errno = errno;
441 freecon(secontext);
442 setfscreatecon(NULL);
443 errno = save_errno;
444 }
Kenny Rootb5982bf2012-10-16 23:07:05 -0700445
Stephen Smalleye096e362012-06-11 13:37:39 -0400446 return rc;
447}
448
Stephen Smalleydbd37f22014-01-28 10:34:09 -0500449int restorecon(const char* pathname)
Stephen Smalleye096e362012-06-11 13:37:39 -0400450{
Stephen Smalley27a93652014-02-07 09:14:13 -0500451 return selinux_android_restorecon(pathname, 0);
Nick Kralevichae76f6d2013-07-11 15:38:26 -0700452}
453
454int restorecon_recursive(const char* pathname)
455{
Stephen Smalley27a93652014-02-07 09:14:13 -0500456 return selinux_android_restorecon(pathname, SELINUX_ANDROID_RESTORECON_RECURSE);
Nick Kralevichae76f6d2013-07-11 15:38:26 -0700457}
Andres Moralesdb5f5d42015-05-08 08:30:33 -0700458
459/*
460 * Writes hex_len hex characters (1/2 byte) to hex from bytes.
461 */
462std::string bytes_to_hex(const uint8_t* bytes, size_t bytes_len) {
463 std::string hex("0x");
464 for (size_t i = 0; i < bytes_len; i++)
465 android::base::StringAppendF(&hex, "%02x", bytes[i]);
466 return hex;
467}
Lee Campbellf13b1b32015-07-24 16:57:14 -0700468
469/*
470 * Returns true is pathname is a directory
471 */
472bool is_dir(const char* pathname) {
473 struct stat info;
474 if (stat(pathname, &info) == -1) {
475 return false;
476 }
477 return S_ISDIR(info.st_mode);
478}
Tom Cherryb7349902015-08-26 11:43:36 -0700479
480bool expand_props(const std::string& src, std::string* dst) {
481 const char* src_ptr = src.c_str();
482
483 if (!dst) {
484 return false;
485 }
486
487 /* - variables can either be $x.y or ${x.y}, in case they are only part
488 * of the string.
489 * - will accept $$ as a literal $.
490 * - no nested property expansion, i.e. ${foo.${bar}} is not supported,
491 * bad things will happen
492 */
493 while (*src_ptr) {
494 const char* c;
495
496 c = strchr(src_ptr, '$');
497 if (!c) {
498 dst->append(src_ptr);
499 return true;
500 }
501
502 dst->append(src_ptr, c);
503 c++;
504
505 if (*c == '$') {
506 dst->push_back(*(c++));
507 src_ptr = c;
508 continue;
509 } else if (*c == '\0') {
510 return true;
511 }
512
513 std::string prop_name;
514 if (*c == '{') {
515 c++;
516 const char* end = strchr(c, '}');
517 if (!end) {
518 // failed to find closing brace, abort.
519 ERROR("unexpected end of string in '%s', looking for }\n", src.c_str());
520 return false;
521 }
522 prop_name = std::string(c, end);
523 c = end + 1;
524 } else {
525 prop_name = c;
526 ERROR("using deprecated syntax for specifying property '%s', use ${name} instead\n",
527 c);
528 c += prop_name.size();
529 }
530
531 if (prop_name.empty()) {
532 ERROR("invalid zero-length prop name in '%s'\n", src.c_str());
533 return false;
534 }
535
536 std::string prop_val = property_get(prop_name.c_str());
537 if (prop_val.empty()) {
538 ERROR("property '%s' doesn't exist while expanding '%s'\n",
539 prop_name.c_str(), src.c_str());
540 return false;
541 }
542
543 dst->append(prop_val);
544 src_ptr = c;
545 }
546
547 return true;
548}