aboutsummaryrefslogtreecommitdiffstats
path: root/guts
diff options
context:
space:
mode:
authorPeter Seebach <seebs@eee12.(none)>2010-04-03 15:49:46 -0500
committerPeter Seebach <seebs@eee12.(none)>2010-04-05 15:18:55 -0500
commit9517843c85e733df325aabe24b0fb16cc1beaf94 (patch)
tree3458a3e106fe6e5f398a144af5e77bcde8071c33 /guts
parentee4f4a62e8ac20ef1a231e1a8f774b08c3ceb275 (diff)
downloadpseudo-9517843c85e733df325aabe24b0fb16cc1beaf94.tar.gz
pseudo-9517843c85e733df325aabe24b0fb16cc1beaf94.tar.bz2
pseudo-9517843c85e733df325aabe24b0fb16cc1beaf94.zip
Make glob work.
Moved readlink fixup into a general-purpose function for removing chroot prefixes.
Diffstat (limited to 'guts')
-rw-r--r--guts/glob.c24
-rw-r--r--guts/glob64.c24
-rw-r--r--guts/readlinkat.c13
3 files changed, 47 insertions, 14 deletions
diff --git a/guts/glob.c b/guts/glob.c
index a8eec64..0012179 100644
--- a/guts/glob.c
+++ b/guts/glob.c
@@ -6,9 +6,31 @@
* wrap_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) {
* int rc = -1;
*/
+ char *rpattern = NULL;
+ int alloced = 0;
- rc = real_glob(pattern, flags, errfunc, pglob);
+ /* note: no canonicalization */
+ if (pattern && (*pattern == '/') && pseudo_chroot_len) {
+ size_t len = strlen(pattern) + pseudo_chroot_len + 2;
+ rpattern = malloc(len);
+ if (!rpattern) {
+ errno = ENOMEM;
+ return GLOB_NOSPACE;
+ }
+ snprintf(rpattern, len, "%s/%s", pseudo_chroot, pattern);
+ alloced = 1;
+ }
+ rc = real_glob(alloced ? rpattern : pattern, flags, errfunc, pglob);
+
+ free(rpattern);
+
+ if (rc == 0) {
+ unsigned int i;
+ for (i = 0; i < pglob->gl_pathc; ++i) {
+ pseudo_dechroot(pglob->gl_pathv[i], (size_t) -1);
+ }
+ }
/* return rc;
* }
*/
diff --git a/guts/glob64.c b/guts/glob64.c
index 8258d47..ccac6e4 100644
--- a/guts/glob64.c
+++ b/guts/glob64.c
@@ -6,9 +6,31 @@
* wrap_glob64(const char *pattern, int flags, int (*errfunc)(const char *, int), glob64_t *pglob) {
* int rc = -1;
*/
+ char *rpattern = NULL;
+ int alloced = 0;
- rc = real_glob64(pattern, flags, errfunc, pglob);
+ /* note: no canonicalization */
+ if (pattern && (*pattern == '/') && pseudo_chroot_len) {
+ size_t len = strlen(pattern) + pseudo_chroot_len + 2;
+ rpattern = malloc(len);
+ if (!rpattern) {
+ errno = ENOMEM;
+ return GLOB_NOSPACE;
+ }
+ snprintf(rpattern, len, "%s/%s", pseudo_chroot, pattern);
+ alloced = 1;
+ }
+ rc = real_glob64(alloced ? rpattern : pattern, flags, errfunc, pglob);
+
+ free(rpattern);
+
+ if (rc == 0) {
+ unsigned int i;
+ for (i = 0; i < pglob->gl_pathc; ++i) {
+ pseudo_dechroot(pglob->gl_pathv[i], (size_t) -1);
+ }
+ }
/* return rc;
* }
*/
diff --git a/guts/readlinkat.c b/guts/readlinkat.c
index 8009af5..d483ab5 100644
--- a/guts/readlinkat.c
+++ b/guts/readlinkat.c
@@ -9,18 +9,7 @@
rc = real_readlinkat(dirfd, path, buf, bufsiz);
if (rc > 0) {
- /* strip out a leading chrooted part */
- if (pseudo_chroot_len &&
- !memcmp(buf, pseudo_chroot, pseudo_chroot_len)) {
- if (buf[pseudo_chroot_len] == '/') {
- memmove(buf, buf + pseudo_chroot_len, rc - pseudo_chroot_len);
- rc -= pseudo_chroot_len;
- } else if (buf[pseudo_chroot_len] == '\0') {
- buf[0] = '/';
- rc = 1;
- }
- /* otherwise, it's not really a match... */
- }
+ rc = pseudo_dechroot(buf, rc);
}
/* return rc;