@@ -40,20 +40,9 @@ static int export_check(const nfs_export *exp, const struct addrinfo *ai,
static void
exportent_mkrealpath(struct exportent *eep)
{
- const char *chroot = nfsd_path_rootdir();
- char *ret = NULL;
-
- if (chroot) {
- char buffer[PATH_MAX];
- if (realpath(chroot, buffer))
- ret = nfsd_path_prepend_dir(buffer, eep->e_path);
- else
- xlog(D_GENERAL, "%s: failed to resolve path %s: %m",
- __func__, chroot);
- }
- if (!ret)
- ret = xstrdup(eep->e_path);
- eep->e_realpath = ret;
+ eep->e_realpath = nfsd_path_prepend_root(eep->e_path);
+ if (eep->e_realpath == eep->e_path)
+ eep->e_realpath = xstrdup(eep->e_path);
}
char *
@@ -13,7 +13,7 @@ void nfsd_path_init(void);
const char * nfsd_path_rootdir(void);
char * nfsd_path_strip_root(char *pathname);
-char * nfsd_path_prepend_dir(const char *dir, const char *pathname);
+char * nfsd_path_prepend_root(const char* pathname);
int nfsd_path_stat(const char *pathname, struct stat *statbuf);
int nfsd_path_lstat(const char *pathname, struct stat *statbuf);
@@ -63,22 +63,18 @@ nfsd_path_strip_root(char *pathname)
}
char *
-nfsd_path_prepend_dir(const char *dir, const char *pathname)
+nfsd_path_prepend_root(const char *pathname)
{
- size_t len, dirlen;
- char *ret;
-
- dirlen = strlen(dir);
- while (dirlen > 0 && dir[dirlen - 1] == '/')
- dirlen--;
- if (!dirlen)
- return NULL;
- while (pathname[0] == '/')
- pathname++;
- len = dirlen + strlen(pathname) + 1;
- ret = xmalloc(len + 1);
- snprintf(ret, len+1, "%.*s/%s", (int)dirlen, dir, pathname);
- return ret;
+ char* buff;
+
+ if (!rootdir)
+ return (char*)pathname;
+
+ buff = malloc(strlen(pathname) + rootdir_pathlen + 1);
+ memcpy(buff, rootdir, rootdir_pathlen);
+ strcpy(buff + rootdir_pathlen, pathname);
+
+ return buff;
}
static void
support/export/export.c - use of nfsd_path_prepend_root mentionned above to make exportent->e_realpath Signed-off-by: Christopher Bii <christopherbii@hyub.org> --- support/export/export.c | 17 +++-------------- support/include/nfsd_path.h | 2 +- support/misc/nfsd_path.c | 26 +++++++++++--------------- 3 files changed, 15 insertions(+), 30 deletions(-)