summaryrefslogtreecommitdiff
path: root/support/misc
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@hammerspace.com>2019-05-29 13:48:20 -0400
committerSteve Dickson <steved@redhat.com>2019-06-10 09:50:38 -0400
commitfcc28687c196628cee253e2b62d2030c385ea634 (patch)
treefc38d34161b4edafe136058a997099d5a9934369 /support/misc
parent9d9bc6f4498903be2ac3b78f5576416e0e1c0507 (diff)
downloadnfs-utils-fcc28687c196628cee253e2b62d2030c385ea634.tar.gz
Add a helper for resolving symlinked nfsd paths via realpath()
Add a helper to resolve symlinked nfsd paths when the user has set the "[exports] rootdir" nfs.conf option. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/misc')
-rw-r--r--support/misc/nfsd_path.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c
index 8ddafd6..2f41a79 100644
--- a/support/misc/nfsd_path.c
+++ b/support/misc/nfsd_path.c
@@ -1,6 +1,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <stdlib.h>
#include <unistd.h>
#include "config.h"
@@ -169,6 +170,40 @@ nfsd_path_lstat(const char *pathname, struct stat *statbuf)
return nfsd_run_stat(nfsd_wq, nfsd_lstatfunc, pathname, statbuf);
}
+struct nfsd_realpath_data {
+ const char *pathname;
+ char *resolved;
+ int err;
+};
+
+static void
+nfsd_realpathfunc(void *data)
+{
+ struct nfsd_realpath_data *d = data;
+
+ d->resolved = realpath(d->pathname, d->resolved);
+ if (!d->resolved)
+ d->err = errno;
+}
+
+char *
+nfsd_realpath(const char *path, char *resolved_path)
+{
+ struct nfsd_realpath_data data = {
+ path,
+ resolved_path,
+ 0
+ };
+
+ if (!nfsd_wq)
+ return realpath(path, resolved_path);
+
+ xthread_work_run_sync(nfsd_wq, nfsd_realpathfunc, &data);
+ if (!data.resolved)
+ errno = data.err;
+ return data.resolved;
+}
+
struct nfsd_read_data {
int fd;
char *buf;