diff options
author | Trond Myklebust <trond.myklebust@hammerspace.com> | 2019-05-29 13:48:20 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2019-06-10 09:50:38 -0400 |
commit | fcc28687c196628cee253e2b62d2030c385ea634 (patch) | |
tree | fc38d34161b4edafe136058a997099d5a9934369 /support/misc | |
parent | 9d9bc6f4498903be2ac3b78f5576416e0e1c0507 (diff) | |
download | nfs-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.c | 35 |
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; |