Rework the NFSv4 path lookup framework so it handles symlinks properly.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2017-07-10 20:09:07 +10:00
parent df94ae931a
commit 3ced39f567
16 changed files with 868 additions and 354 deletions

View File

@ -462,6 +462,8 @@ int nfs3_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh,
uint64_t count, const void *buf, nfs_cb cb,
void *private_data);
int nfs4_chdir_async(struct nfs_context *nfs, const char *path,
nfs_cb cb, void *private_data);
int nfs4_mount_async(struct nfs_context *nfs, const char *server,
const char *export, nfs_cb cb, void *private_data);
int nfs4_stat64_async(struct nfs_context *nfs, const char *path,

View File

@ -972,9 +972,11 @@ nfs_chdir_async(struct nfs_context *nfs, const char *path,
switch (nfs->version) {
case NFS_V3:
return nfs3_chdir_async(nfs, path, cb, private_data);
case NFS_V4:
return nfs4_chdir_async(nfs, path, cb, private_data);
default:
nfs_set_error(nfs, "%s does not support NFSv4",
__FUNCTION__);
nfs_set_error(nfs, "%s does not support NFSv%d",
__FUNCTION__, nfs->version);
return -1;
}
}

View File

@ -3582,7 +3582,7 @@ nfs3_mkdir_continue_internal(struct nfs_context *nfs,
struct nfs_cb_data *data)
{
char *str = data->continue_data;
int mode = data->continue_int;
int mode = (int)data->continue_int;
MKDIR3args args;
str = &str[strlen(str) + 1];

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ AM_CFLAGS = $(WARN_CFLAGS)
LDADD = ../lib/libnfs.la
noinst_PROGRAMS = prog_create prog_fstat prog_link prog_lstat prog_mkdir \
prog_mknod prog_open_read prog_rename prog_rmdir prog_stat \
prog_mknod prog_mount prog_open_read prog_rename prog_rmdir prog_stat \
prog_symlink prog_timeout prog_unlink
EXTRA_PROGRAMS = ld_timeout

View File

@ -2,6 +2,9 @@ TESTDIR=`pwd`/testdata
TESTSHARE="127.0.0.1:${TESTDIR}"
TESTURL="nfs://127.0.0.1${TESTDIR}"
# Which version of NFS to test for
VERS=${VERSION:-3}
start_share() {
rm -rf "${TESTDIR}" 2>/dev/null
mkdir "${TESTDIR}" 2>/dev/null

73
tests/prog_mount.c Normal file
View File

@ -0,0 +1,73 @@
/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2017
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "libnfs.h"
void usage(void)
{
fprintf(stderr, "Usage: prog_mount <url>\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct nfs_context *nfs = NULL;
struct nfs_url *url = NULL;
int ret = 0;
if (argc != 2) {
usage();
}
nfs = nfs_init_context();
if (nfs == NULL) {
printf("failed to init context\n");
exit(1);
}
url = nfs_parse_url_full(nfs, argv[1]);
if (url == NULL) {
fprintf(stderr, "%s\n", nfs_get_error(nfs));
exit(1);
}
if (nfs_mount(nfs, url->server, url->path) != 0) {
fprintf(stderr, "Failed to mount nfs share : %s\n",
nfs_get_error(nfs));
ret = 1;
goto finished;
}
finished:
nfs_destroy_url(url);
nfs_destroy_context(nfs);
return ret;
}

View File

@ -2,7 +2,7 @@
. ./functions.sh
echo "stat test on symlink"
echo "NFSv${VERS} Basic nfs_stat64() tests."
start_share
@ -12,7 +12,7 @@ ln -s testfile "${TESTDIR}/lstat1"
echo -n "test nfs_stat64() ... "
./prog_stat "${TESTURL}/" "." /testfile > "${TESTDIR}/output" || failure
./prog_stat "${TESTURL}/?version=${VERS}" "." /testfile > "${TESTDIR}/output" || failure
success
echo -n "test nfs_ino ... "

View File

@ -2,37 +2,47 @@
. ./functions.sh
echo "nfs_stat64() path tests"
echo "NFSv${VERS} nfs_stat64() path tests."
start_share
mkdir "${TESTDIR}/subdir"
mkdir "${TESTDIR}/subdir2"
echo -n "Test nfs_stat64() for a root file (abs) (1)... "
echo -n "test nfs_stat64() for a root file (abs) (1)... "
touch "${TESTDIR}/stat1"
./prog_stat "${TESTURL}/" "." /stat1 >/dev/null || failure
./prog_stat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null || failure
success
echo -n "Test nfs_stat64() for a root file (rel) (2)... "
./prog_stat "${TESTURL}/" "." stat1 >/dev/null || failure
echo -n "test nfs_stat64() for a root file (rel) (2)... "
./prog_stat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null || failure
success
echo -n "Test nfs_stat64() for a subdir file (abs) (3)... "
echo -n "test nfs_stat64() for a subdir file (abs) (3)... "
touch "${TESTDIR}/subdir/stat3"
./prog_stat "${TESTURL}/" "." /subdir/stat3 >/dev/null || failure
./prog_stat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null || failure
success
echo -n "Test nfs_stat64() for a subdir file (rel) (4)... "
./prog_stat "${TESTURL}/" "." subdir/stat3 >/dev/null || failure
echo -n "test nfs_stat64() for a subdir file (rel) (4)... "
./prog_stat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null || failure
success
echo -n "Test nfs_stat64() from a different cwd (rel) (5)... "
./prog_stat "${TESTURL}/" "subdir2" ../subdir/stat3 >/dev/null || failure
echo -n "test nfs_stat64() from a different cwd (rel) (5)... "
./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null || failure
success
echo -n "Test nfs_stat64() outside the share (rel) (6)... "
./prog_stat "${TESTURL}/" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure
echo -n "test nfs_stat64() outside the share (rel) (6)... "
./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure
success
echo -n "test nfs_lstat64() when target is a symlink (7)... "
touch "${TESTDIR}/stat7"
ln -s stat7 "${TESTDIR}/symlink7"
./prog_stat "${TESTURL}/?version=${VERS}" "." symlink7 >"${TESTDIR}/output" || failure
success
echo -n "test nfs_lstat() on the underlying file ... "
grep "nfs_mode:100664" "${TESTDIR}/output" >/dev/null || failure
success
stop_share

View File

@ -2,7 +2,7 @@
. ./functions.sh
echo "basic valgrind leak check for nfs_stat64()"
echo "NFSv${VERS} Basic valgrind leak check for nfs_stat64()"
start_share
@ -12,28 +12,28 @@ mkdir "${TESTDIR}/subdir2"
echo -n "test nfs_stat64() (1) ... "
touch "${TESTDIR}/stat1"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/" "." /stat1 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null 2>&1 || failure
success
echo -n "test nfs_stat64() (2) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/" "." stat1 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null 2>&1 || failure
success
echo -n "test nfs_stat64() (3) ... "
touch "${TESTDIR}/subdir/stat3"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/" "." /subdir/stat3 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_stat64() (4) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/" "." subdir/stat3 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_stat64() (5) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_stat64() (6) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/" "subdir2" ../../subdir/stat3 2>/dev/null || expr $? != 99 >/dev/null || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/stat3 2>/dev/null || expr $? != 99 >/dev/null || failure
success

View File

@ -2,7 +2,7 @@
. ./functions.sh
echo "stat test on symlink"
echo "NFSv${VERS} nfs_stat64() test on symlink."
start_share
@ -12,7 +12,7 @@ ln -s testfile "${TESTDIR}/lstat1"
echo -n "test nfs_stat64() ... "
./prog_stat "${TESTURL}/" "." /lstat1 > "${TESTDIR}/output" || failure
./prog_stat "${TESTURL}/?version=${VERS}" "." /lstat1 > "${TESTDIR}/output" || failure
success
echo -n "test nfs_ino ... "

View File

@ -2,7 +2,7 @@
. ./functions.sh
echo "basic lstat test"
echo "NFSv${VERS} Basic lstat test."
start_share
@ -12,7 +12,7 @@ ln -s testfile "${TESTDIR}/lstat1"
echo -n "test nfs_lstat64() ... "
./prog_lstat "${TESTURL}/" "." /lstat1 > "${TESTDIR}/output" || failure
./prog_lstat "${TESTURL}/?version=${VERS}" "." /lstat1 > "${TESTDIR}/output" || failure
success
echo -n "test nfs_ino ... "

View File

@ -2,39 +2,50 @@
. ./functions.sh
echo "nfs_lstat64() path tests"
echo "NFSv${VERS} nfs_lstat64() path tests."
start_share
mkdir "${TESTDIR}/subdir"
mkdir "${TESTDIR}/subdir2"
echo -n "Test nfs_lstat64() for a root file (abs) (1)... "
echo -n "test nfs_lstat64() for a root file (abs) (1)... "
ln -s foo "${TESTDIR}/stat1"
./prog_lstat "${TESTURL}/" "." /stat1 >/dev/null || failure
./prog_lstat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null || failure
success
echo -n "Test nfs_lstat64() for a root file (rel) (2)... "
./prog_lstat "${TESTURL}/" "." stat1 >/dev/null || failure
echo -n "test nfs_lstat64() for a root file (rel) (2)... "
./prog_lstat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null || failure
success
echo -n "Test nfs_lstat64() for a subdir file (abs) (3)... "
echo -n "test nfs_lstat64() for a subdir file (abs) (3)... "
ln -s foo "${TESTDIR}/subdir/stat3"
./prog_lstat "${TESTURL}/" "." /subdir/stat3 >/dev/null || failure
./prog_lstat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null || failure
success
echo -n "Test nfs_lstat64() for a subdir file (rel) (4)... "
./prog_lstat "${TESTURL}/" "." subdir/stat3 >/dev/null || failure
echo -n "test nfs_lstat64() for a subdir file (rel) (4)... "
./prog_lstat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null || failure
success
echo -n "Test nfs_lstat64() from a different cwd (rel) (5)... "
./prog_lstat "${TESTURL}/" "subdir2" ../subdir/stat3 >/dev/null || failure
echo -n "test nfs_lstat64() from a different cwd (rel) (5)... "
./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null || failure
success
echo -n "Test nfs_lstat64() outside the share (rel) (6)... "
./prog_lstat "${TESTURL}/" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure
echo -n "test nfs_lstat64() outside the share (rel) (6)... "
./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure
success
echo -n "test nfs_lstat64() when target is a symlink (7)... "
touch "${TESTDIR}/stat7"
ln -s stat7 "${TESTDIR}/symlink7"
./prog_lstat "${TESTURL}/?version=${VERS}" "." symlink7 >"${TESTDIR}/output" || failure
success
echo -n "test nfs_lstat64() report it is a symlink ... "
grep "nfs_mode:120777" "${TESTDIR}/output" >/dev/null || failure
success
stop_share
exit 0

View File

@ -2,7 +2,7 @@
. ./functions.sh
echo "basic valgrind leak check for nfs_lstat64()"
echo "NFSv${VERS} Basic valgrind leak check for nfs_lstat64()."
start_share
@ -12,28 +12,28 @@ mkdir "${TESTDIR}/subdir2"
echo -n "test nfs_lstat64() (1) ... "
ln -s foo "${TESTDIR}/stat1"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." /stat1 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null 2>&1 || failure
success
echo -n "test nfs_lstat64() (2) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." stat1 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null 2>&1 || failure
success
echo -n "test nfs_lstat64() (3) ... "
ln -s foo "${TESTDIR}/subdir/stat3"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." /subdir/stat3 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_lstat64() (4) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." subdir/stat3 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_lstat64() (5) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_lstat64() (6) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "subdir2" ../../subdir/stat3 2>/dev/null || expr $? != 99 >/dev/null || failure
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/stat3 2>/dev/null || expr $? != 99 >/dev/null || failure
success

23
tests/test_1000_mount_paths.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
. ./functions.sh
echo "NFSv${VERS} Basic mount path test."
start_share
echo -n "test nfs_mount() normal share ... "
./prog_mount "${TESTURL}/?version=${VERS}" || failure
success
mkdir "${TESTDIR}/subdir"
mkdir "${TESTDIR}/subdir/subdir2"
ln -s subdir "${TESTDIR}/symlink1"
echo -n "test nfs_mount() following a link ... "
./prog_mount "${TESTURL}/symlink1/subdir2/?version=${VERS}" || failure
success
stop_share
exit 0

20
tests/test_1010_chdir_paths.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
. ./functions.sh
echo "NFSv${VERS} Basic chdir path test."
start_share
mkdir "${TESTDIR}/subdir"
mkdir "${TESTDIR}/subdir/subdir2"
touch "${TESTDIR}/subdir/stat1"
ln -s subdir "${TESTDIR}/symlink1"
echo -n "Test nfs_stat64() from a different cwd (rel) (1)... "
./prog_stat "${TESTURL}/?version=${VERS}" "symlink1" stat1 >/dev/null || failure
success
stop_share
exit 0