support/export/export.c - use of nfsd_path_prepend_root mentionned above to make exportent->e_realpath Signed-off-by: Christopher Bii <christopherbii@xxxxxxxx> --- support/export/export.c | 17 +++-------------- support/include/nfsd_path.h | 2 +- support/misc/nfsd_path.c | 26 +++++++++++--------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/support/export/export.c b/support/export/export.c index 3a4fb747..5da5780f 100644 --- a/support/export/export.c +++ b/support/export/export.c @@ -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 * diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h index 2b9b68af..214bde47 100644 --- a/support/include/nfsd_path.h +++ b/support/include/nfsd_path.h @@ -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); diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index ff946301..0f727d3b 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -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 -- 2.47.1