@@ -40,7 +40,7 @@ static int export_check(const nfs_export *exp, const struct addrinfo *ai,
static void
exportent_mkrealpath(struct exportent *eep)
{
- const char *chroot = nfsd_path_nfsd_rootdir();
+ const char *chroot = nfsd_path_rootdir();
char *ret = NULL;
if (chroot) {
@@ -11,7 +11,7 @@ struct statfs;
void nfsd_path_init(void);
-const char * nfsd_path_nfsd_rootdir(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);
@@ -20,57 +20,43 @@
#include "workqueue.h"
static struct xthread_workqueue *nfsd_wq;
+const char *rootdir;
+size_t rootdir_pathlen = 0;
-static int
-nfsd_path_isslash(const char *path)
-{
- return path[0] == '/' && path[1] == '/';
-}
-static int
-nfsd_path_isdot(const char *path)
+const char*
+nfsd_path_rootdir(void)
{
- return path[0] == '.' && path[1] == '/';
-}
+ return rootdir;
+};
-static const char *
-nfsd_path_strip(const char *path)
+/* Set rootdir global variable. Rootdir must be an absolute path
+ * and resolveable by realpath()
+ * */
+static void
+nfsd_rootdir_set(void)
{
- if (!path || *path == '\0')
- goto out;
- for (;;) {
- if (nfsd_path_isslash(path)) {
- path++;
- continue;
- }
- if (nfsd_path_isdot(path)) {
- path += 2;
- continue;
- }
- break;
- }
-out:
- return path;
-}
+ const char *path;
+ if (!(path = conf_get_str("exports", "rootdir")))
+ return;
-const char *
-nfsd_path_nfsd_rootdir(void)
-{
- const char *rootdir;
+ if (path[0] != '/')
+ xlog(L_FATAL, "%s: NFS export rootdir must be an absolute path. "
+ "Current value: \"%s\"", __func__, path);
- rootdir = nfsd_path_strip(conf_get_str("exports", "rootdir"));
- if (!rootdir || rootdir[0] == '\0')
- return NULL;
- if (rootdir[0] == '/' && rootdir[1] == '\0')
- return NULL;
- return rootdir;
+ if (!(rootdir = realpath(path, NULL))){
+ free((void*)rootdir);
+ xlog(L_FATAL, "realpath(): Unable to resolve root export path \"%s\"", path);
+ };
+
+ rootdir_pathlen = strlen(rootdir);
}
char *
nfsd_path_strip_root(char *pathname)
{
char buffer[PATH_MAX];
- const char *dir = nfsd_path_nfsd_rootdir();
+ const char *dir = nfsd_path_rootdir();
if (!dir)
goto out;
@@ -106,8 +92,7 @@ nfsd_path_prepend_dir(const char *dir, const char *pathname)
static void
nfsd_setup_workqueue(void)
{
- const char *rootdir = nfsd_path_nfsd_rootdir();
-
+ nfsd_rootdir_set();
if (!rootdir)
return;
Signed-off-by: Christopher Bii <christopherbii@hyub.org> --- support/export/export.c | 2 +- support/include/nfsd_path.h | 2 +- support/misc/nfsd_path.c | 65 ++++++++++++++----------------------- 3 files changed, 27 insertions(+), 42 deletions(-)