├── m4 └── .keep ├── bootstrap ├── aros ├── CMakeLists.txt ├── Makefile.AROS └── aros_compat.h ├── nlm ├── CMakeLists.txt └── Makefile.am ├── nsm ├── CMakeLists.txt └── Makefile.am ├── tls ├── CMakeLists.txt ├── Makefile.am └── tls-private.h ├── nfs4 ├── CMakeLists.txt ├── libnfs-raw-nfs4.c.fragment ├── libnfs-raw-nfs4.h.extra └── Makefile.am ├── mount ├── CMakeLists.txt └── Makefile.am ├── rquota ├── CMakeLists.txt └── Makefile.am ├── portmap ├── CMakeLists.txt └── Makefile.am ├── nfs ├── CMakeLists.txt ├── Makefile.am └── libnfs-raw-nfs.h.extra ├── win32 ├── CMakeLists.txt ├── nfs-cp │ ├── nfs-cp.vcxproj.user │ └── nfs-cp.vcxproj.filters ├── libnfs │ ├── libnfs.vcxproj.user │ └── x64 │ │ └── Debug │ │ └── libnfs.dll.recipe ├── nfs-cat │ ├── nfs-cat.vcxproj.user │ └── nfs-cat.vcxproj.filters ├── nfs-stat │ ├── nfs-stat.vcxproj.user │ └── nfs-stat.vcxproj.filters ├── nfs-ls │ ├── nfs-ls.vcxproj.user │ └── nfs-ls.vcxproj.filters ├── nfsclient-raw │ └── nfsclient-raw.vcxproj.filters ├── nfsclient-async │ └── nfsclient-async.vcxproj.filters ├── nfsclient-bcast │ └── nfsclient-bcast.vcxproj.filters ├── nfsclient-sync │ └── nfsclient-sync.vcxproj.filters ├── nfsclient-listservers │ └── nfsclient-listservers.vcxproj.filters ├── win32_errnowrapper.h └── version.rc.template ├── tests ├── README ├── test_0350_lseek.sh ├── test_0101_ls_discover_server.sh.disabled ├── test_0102_ls_discover_shares.sh ├── test_9990_build_rpm.sh.disabled ├── test_0291_read_update_pos.sh ├── test_1010_chdir_paths.sh ├── test_0100_ls_basic.sh ├── test_0332_ftruncate_valgrind_leak_check.sh ├── test_0110_readonly.sh ├── test_0300_write.sh ├── test_1000_mount_paths.sh ├── test_8000_timeout.sh.disabled ├── test_9910_valgrind_timeout.sh.disabled ├── test_8010_valgrind_parse_url_full.sh ├── functions.sh ├── test_0360_statvfs.sh ├── test_0340_truncate.sh ├── test_0290_read.sh ├── test_0330_ftruncate.sh ├── test_0224_open_O_APPEND.sh ├── test_8010_parse_url_full.sh ├── test_0223_open_O_TRUNC.sh ├── test_0380_lchmod.sh ├── test_0390_fchmod.sh ├── test_0211_fstat_paths.sh ├── Makefile.am ├── test_0410_lchown.sh ├── test_0420_fchown.sh ├── test_0430_access.sh ├── test_0440_access2.sh ├── test_0450_utimes.sh ├── test_0270_unlink.sh ├── test_0230_creat_paths.sh ├── test_0341_truncate_paths.sh ├── test_0202_stat_valgrind_leak_check.sh ├── test_0210_fstat.sh ├── CMakeLists.txt ├── test_0201_stat_paths.sh ├── test_0212_fstat_valgrind_leak_check.sh ├── test_0322_lstat_valgrind_leak_check.sh ├── test_0320_lstat.sh ├── test_0321_lstat_paths.sh ├── test_0200_stat.sh ├── test_0203_stat_symlink.sh ├── test_0222_open_valgrind_leak_check.sh ├── test_0272_unlink_valgrind_leak_check.sh ├── test_0460_opendir.sh ├── test_0370_chmod.sh ├── prog_parse_url_full.c ├── test_0225_open_O_CREAT.sh ├── prog_mount.c ├── test_0240_link.sh ├── test_0310_mknod.sh ├── test_0220_open_paths.sh ├── prog_mkdir.c ├── prog_rmdir.c ├── prog_unlink.c ├── prog_link.c ├── prog_rename.c ├── test_0400_chown.sh ├── test_9900_valgrind_leak_check_full.sh ├── test_0260_symlink_paths.sh ├── prog_chmod.c ├── prog_lchmod.c ├── ld_timeout.c ├── prog_chown.c ├── prog_ftruncate.c ├── prog_lchown.c ├── prog_mknod.c ├── prog_utimes.c ├── prog_truncate.c ├── prog_timeout.c ├── prog_access.c ├── prog_create.c ├── test_0242_link_valgrind_leak_check.sh ├── prog_opendir.c └── test_0280_mkdir_rmdir.sh ├── servers ├── Makefile.am ├── rpcbind │ ├── rpcbind_data.x │ ├── rpcbind_data.h │ ├── Makefile.am │ └── rpcbind_data.c ├── statd │ └── Makefile.am ├── nfsd │ ├── Makefile.am │ └── mountd.h └── libnfs-server.h ├── libnfs.pc.in ├── cmake ├── libnfs.pc.cmake ├── Macros.cmake └── FindNFS.cmake ├── include ├── Makefile.am ├── slist.h └── libnfs-multithreading.h ├── Makefile.am ├── INSTALL ├── utils ├── Makefile.am └── CMakeLists.txt ├── doc ├── Makefile.am ├── CMakeLists.txt ├── nfs-cat.1.xml ├── nfs-cp.1.xml ├── nfs-cat.1 └── nfs-cp.1 ├── .github └── workflows │ └── codeql.yml ├── .gitignore ├── ps2_ee ├── Makefile.PS2_EE ├── config.h └── ps2_compat.c ├── examples ├── CMakeLists.txt ├── nfsclient-listservers.c └── Makefile.am ├── lib ├── CMakeLists.txt ├── Makefile.am └── krb5-wrapper.h ├── LICENCE-BSD.txt ├── ps3_ppu ├── config.h └── ps3_compat.c └── COPYING /m4/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | exec autoreconf -vif 3 | -------------------------------------------------------------------------------- /aros/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES aros_compat.c) 2 | set(HEADERS aros_compat.h) 3 | 4 | core_add_library(aros) 5 | -------------------------------------------------------------------------------- /nlm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-nlm.c 2 | nlm.c) 3 | set(HEADERS libnfs-raw-nlm.h) 4 | 5 | core_add_library(nlm) 6 | -------------------------------------------------------------------------------- /nsm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-nsm.c 2 | nsm.c) 3 | set(HEADERS libnfs-raw-nsm.h) 4 | 5 | core_add_library(nsm) 6 | -------------------------------------------------------------------------------- /tls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES handshake.c 2 | ktls.c) 3 | set(INCLUDEDIRS ${GNUTLS_INCLUDE_DIR}) 4 | core_add_library(tls) 5 | -------------------------------------------------------------------------------- /nfs4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-nfs4.c 2 | nfs4.c) 3 | set(HEADERS libnfs-raw-nfs4.h) 4 | 5 | core_add_library(nfs4) 6 | -------------------------------------------------------------------------------- /mount/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-mount.c 2 | mount.c) 3 | set(HEADERS libnfs-raw-mount.h) 4 | 5 | core_add_library(mount) 6 | -------------------------------------------------------------------------------- /rquota/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-rquota.c 2 | rquota.c) 3 | set(HEADERS libnfs-raw-rquota.h) 4 | 5 | core_add_library(rquota) 6 | -------------------------------------------------------------------------------- /portmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-portmap.c 2 | portmap.c) 3 | set(HEADERS libnfs-raw-portmap.h) 4 | 5 | core_add_library(portmap) 6 | -------------------------------------------------------------------------------- /nfs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES libnfs-raw-nfs.c 2 | nfs.c 3 | nfsacl.c) 4 | set(HEADERS libnfs-raw-nfs.h) 5 | 6 | core_add_library(nfs) 7 | -------------------------------------------------------------------------------- /win32/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES win32_compat.c) 2 | set(HEADERS ../include/win32/win32_compat.h 3 | win32_errnowrapper.h) 4 | 5 | core_add_library(win32) 6 | -------------------------------------------------------------------------------- /win32/nfs-cp/nfs-cp.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /win32/libnfs/libnfs.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /win32/nfs-cat/nfs-cat.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /win32/nfs-stat/nfs-stat.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | Testsuite for libnfs. 2 | 3 | To run the tests: 4 | make VERSION=3 test 5 | or 6 | make VERSION=4 test 7 | 8 | The tests will ask for your password as it needs sudo access to 9 | run exportfs to create/remove the share we use for testing. 10 | -------------------------------------------------------------------------------- /servers/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = \ 2 | -I$(abs_top_srcdir)/include \ 3 | -I$(abs_top_srcdir)/include/nfsc \ 4 | -I$(abs_top_srcdir)/portmap \ 5 | "-D_U_=__attribute__((unused))" 6 | 7 | COMMON_LIBS = ../lib/libnfs.la -lpopt 8 | 9 | if HAVE_TLS 10 | COMMON_LIBS += -lgnutls 11 | endif 12 | 13 | SUBDIRS = nfsd rpcbind statd 14 | -------------------------------------------------------------------------------- /libnfs.pc.in: -------------------------------------------------------------------------------- 1 | # libnfs pkg-config file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libnfs 9 | Description: libnfs is a client library for accessing NFS shares over a network. 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -lnfs 14 | Cflags: -I${includedir} 15 | -------------------------------------------------------------------------------- /tests/test_0350_lseek.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic lseek test." 6 | 7 | start_share 8 | 9 | truncate -s 1024 "${TESTDIR}/testfile" 10 | 11 | echo -n "test nfs_lseek() ... " 12 | ./prog_lseek "${TESTURL}/?version=${VERS}" "." /testfile > /dev/null || failure 13 | success 14 | 15 | 16 | stop_share 17 | 18 | exit 0 19 | 20 | -------------------------------------------------------------------------------- /tests/test_0101_ls_discover_server.sh.disabled: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "discover servers test" 6 | 7 | start_share 8 | 9 | echo -n "Testing nfs-ls to discover servers ... " 10 | ../utils/nfs-ls -D nfs:// > "${TESTDIR}/output" || failure 11 | grep nfs:// "${TESTDIR}/output" > /dev/null || failure 12 | success 13 | 14 | stop_share 15 | 16 | exit 0 17 | -------------------------------------------------------------------------------- /win32/libnfs/x64/Debug/libnfs.dll.recipe: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | C:\Users\User\source\repos\sahlberg\libnfs\win32\libnfs\x64\Debug\libnfs.dll 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /servers/rpcbind/rpcbind_data.x: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | 3 | struct mapping { 4 | struct mapping *next; 5 | unsigned int port; 6 | unsigned int prog; 7 | unsigned int vers; 8 | string netid<>; 9 | string addr<>; 10 | string owner<>; 11 | }; 12 | 13 | typedef mapping *mapping_ptr; 14 | -------------------------------------------------------------------------------- /tests/test_0102_ls_discover_shares.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "discover shares test" 6 | 7 | start_share 8 | 9 | echo -n "Testing nfs-ls to discover shares on a server ... " 10 | ../utils/nfs-ls -D nfs://127.0.0.1 > "${TESTDIR}/output" || failure 11 | grep "${TESTURL}" "${TESTDIR}/output" > /dev/null || failure 12 | success 13 | 14 | stop_share 15 | 16 | exit 0 17 | -------------------------------------------------------------------------------- /tests/test_9990_build_rpm.sh.disabled: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "test we can build libnfs as an rpm" 6 | 7 | [ -f "/etc/redhat-release" ] || { 8 | echo "SKIPPED. This is not a red-hat based system" 9 | exit 0 10 | } 11 | 12 | echo -n "try building rpm packages ... " 13 | ../packaging/RPM/makerpms.sh >/dev/null 2>&1 || failure 14 | 15 | success 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /servers/statd/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = rpc.statd 2 | rpc_statd_SOURCES = rpc.statd.c 3 | 4 | AM_CPPFLAGS = \ 5 | -I$(abs_top_srcdir)/include/nfsc \ 6 | -I$(abs_top_srcdir)/nsm \ 7 | "-D_U_=__attribute__((unused))" 8 | 9 | COMMON_LIBS = ../../lib/libnfs.la -lpopt 10 | 11 | if HAVE_TLS 12 | COMMON_LIBS += -lgnutls 13 | endif 14 | 15 | rpc_statd_LDADD = ../libnfs-server.o $(COMMON_LIBS) -ltalloc -ltevent 16 | -------------------------------------------------------------------------------- /cmake/libnfs.pc.cmake: -------------------------------------------------------------------------------- 1 | # libnfs pkg-config file 2 | 3 | prefix=@CMAKE_INSTALL_PREFIX@ 4 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 5 | libdir=@INSTALL_LIB_DIR@ 6 | includedir=@INSTALL_INC_DIR@ 7 | 8 | Name: libnfs 9 | Description: libnfs is a client library for accessing NFS shares over a network. 10 | Version: @PROJECT_VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -lnfs @PKG_LIBLIST@ 14 | Cflags: -I${includedir} 15 | -------------------------------------------------------------------------------- /win32/nfs-ls/nfs-ls.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | nfs://10.10.10.11/data/SNAP-4 5 | WindowsLocalDebugger 6 | 7 | -------------------------------------------------------------------------------- /servers/nfsd/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = nfsd 2 | 3 | AM_CPPFLAGS = \ 4 | -I$(abs_top_srcdir)/include/nfsc \ 5 | -I$(abs_top_srcdir)/mount \ 6 | -I$(abs_top_srcdir)/nfs \ 7 | -I$(abs_top_srcdir)/nlm \ 8 | "-D_U_=__attribute__((unused))" 9 | 10 | COMMON_LIBS = ../../lib/libnfs.la -lpopt 11 | 12 | if HAVE_TLS 13 | COMMON_LIBS += -lgnutls 14 | endif 15 | 16 | nfsd_LDADD = ../libnfs-server.o mountd.o $(COMMON_LIBS) -ltalloc -ltevent 17 | -------------------------------------------------------------------------------- /tests/test_0291_read_update_pos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "basic test that read updates offset but pread does not" 6 | 7 | start_share 8 | 9 | echo -n "Create a 12byte file ... " 10 | dd if=/dev/urandom of="${TESTDIR}/file" bs=1 count=12 2>/dev/null || failure 11 | success 12 | 13 | echo -n "Verify how offset is updated " 14 | ./prog_read_update_pos "${TESTURL}/file" >/dev/null || failure 15 | success 16 | 17 | stop_share 18 | 19 | exit 0 20 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | nfscdir = $(includedir)/nfsc 2 | dist_nfsc_HEADERS = \ 3 | nfsc/libnfs.h \ 4 | nfsc/libnfs-raw.h \ 5 | nfsc/libnfs-zdr.h \ 6 | ../mount/libnfs-raw-mount.h \ 7 | ../portmap/libnfs-raw-portmap.h \ 8 | ../nfs/libnfs-raw-nfs.h \ 9 | ../nfs4/libnfs-raw-nfs4.h \ 10 | ../nlm/libnfs-raw-nlm.h \ 11 | ../nsm/libnfs-raw-nsm.h \ 12 | ../rquota/libnfs-raw-rquota.h 13 | 14 | dist_noinst_HEADERS = \ 15 | win32/win32_compat.h \ 16 | libnfs-private.h \ 17 | slist.h 18 | -------------------------------------------------------------------------------- /tests/test_1010_chdir_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic chdir path test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir/subdir2" 11 | touch "${TESTDIR}/subdir/stat1" 12 | ln -s subdir "${TESTDIR}/symlink1" 13 | 14 | echo -n "Test nfs_stat64() from a different cwd (rel) (1)... " 15 | ./prog_stat "${TESTURL}/?version=${VERS}" "symlink1" stat1 >/dev/null || failure 16 | success 17 | 18 | stop_share 19 | 20 | exit 0 21 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = doc mount nfs nfs4 nlm nsm portmap rquota 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | if HAVE_TLS 5 | SUBDIRS += tls 6 | endif 7 | SUBDIRS += lib include $(MAYBE_UTILS) . $(MAYBE_EXAMPLES) $(MAYBE_SERVERS) 8 | 9 | pkgconfigdir = $(libdir)/pkgconfig 10 | pkgconfig_DATA = libnfs.pc 11 | 12 | EXTRA_DIST = \ 13 | README \ 14 | COPYING \ 15 | LICENCE-BSD.txt \ 16 | LICENCE-GPL-3.txt \ 17 | LICENCE-LGPL-2.1.txt \ 18 | examples \ 19 | libnfs.pc.in 20 | 21 | test: $(SUBDIRS) 22 | cd tests; make test 23 | -------------------------------------------------------------------------------- /tests/test_0100_ls_basic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "basic ls test" 6 | 7 | start_share 8 | 9 | echo -n "Testing nfs-ls on root of export ... " 10 | ../utils/nfs-ls "${TESTURL}" > /dev/null || failure 11 | success 12 | 13 | echo -n "Create a file and verify nfs-ls can see it ... " 14 | touch "${TESTDIR}/testfile" 15 | ../utils/nfs-ls "${TESTURL}" > "${TESTDIR}/output" || failure 16 | grep testfile "${TESTDIR}/output" > /dev/null || failure 17 | success 18 | 19 | stop_share 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /tests/test_0332_ftruncate_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_ftruncate()." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test nfs_ftruncate() (1) ... " 12 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_ftruncate "${TESTURL}/?version=${VERS}" "." testfile 12377 >/dev/null 2>&1 || failure 13 | success 14 | 15 | stop_share 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /tests/test_0110_readonly.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic readonly test." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test nfs_ftruncate() on readonly mount ... " 12 | ./prog_ftruncate "${TESTURL}/?version=${VERS}\&readonly" "." testfile 12377 2>/dev/null && failure 13 | success 14 | 15 | echo -n "test readonly ... " 16 | ./prog_readonly "${TESTURL}/?version=${VERS}\&readonly" 17 | success 18 | 19 | stop_share 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /tests/test_0300_write.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_write() test." 6 | 7 | start_share 8 | 9 | echo -n "test writing to a file (1) ... " 10 | touch "${TESTDIR}/open1" 11 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /open1 O_WRONLY "kangabanga" >/dev/null || failure 12 | success 13 | 14 | echo -n "verify the data is correct ... " 15 | echo -n "kangabanga" > "${TESTDIR}/verify1" 16 | diff "${TESTDIR}/verify1" "${TESTDIR}/open1" || failure 17 | success 18 | 19 | stop_share 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | To install 2 | 3 | - mkdir build && cd build 4 | - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr .. 5 | - make && sudo make install 6 | 7 | To build with support debugging that enable example and test cases. 8 | 9 | - mkdir build && cd build 10 | - cmake -DENABLE_UTILS=yes \ 11 | -DENABLE_EXAMPLES=yes \ 12 | -DENABLE_TESTS=yes \ 13 | -DCMAKE_BUILD_TYPE=Debug \ 14 | -DCMAKE_VERBOSE_MAKEFILE=yes .. 15 | 16 | To build with multithreading support add -DENABLE_MULTITHREADING=yes 17 | 18 | - make 19 | - make test 20 | -------------------------------------------------------------------------------- /tests/test_1000_mount_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic mount path test." 6 | 7 | start_share 8 | 9 | echo -n "test nfs_mount() normal share ... " 10 | ./prog_mount "${TESTURL}/?version=${VERS}" || failure 11 | success 12 | 13 | mkdir "${TESTDIR}/subdir" 14 | mkdir "${TESTDIR}/subdir/subdir2" 15 | ln -s subdir "${TESTDIR}/symlink1" 16 | 17 | echo -n "test nfs_mount() following a link ... " 18 | ./prog_mount "${TESTURL}/symlink1/subdir2/?version=${VERS}" || failure 19 | success 20 | 21 | stop_share 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /tests/test_8000_timeout.sh.disabled: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic timeout test." 6 | 7 | if [ $VERS -eq 3 ]; then 8 | COUNT=28 9 | else 10 | COUNT=13 11 | fi 12 | 13 | start_share 14 | 15 | touch "${TESTDIR}/testfile" 16 | for IDX in `seq 1 $COUNT`; do 17 | echo -n "Test timeout at socket event ${IDX} ... " 18 | TIMEOUT_START=${IDX} LD_PRELOAD=./ld_timeout.so ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile >/dev/null 2>&1 && failure 19 | success 20 | done 21 | 22 | stop_share 23 | 24 | exit 0 25 | -------------------------------------------------------------------------------- /tests/test_9910_valgrind_timeout.sh.disabled: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind check of timeout handling." 6 | 7 | start_share 8 | 9 | touch "${TESTDIR}/testfile" 10 | for IDX in `seq 1 28`; do 11 | echo -n "Test memory leaks at socket event ${IDX} ... " 12 | TIMEOUT_START=${IDX} LD_PRELOAD=./ld_timeout.so libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_timeout "${TESTURL}/testfile?version=${VERS}" >/dev/null 2>&1 || failure 13 | success 14 | done 15 | 16 | stop_share 17 | 18 | exit 0 19 | -------------------------------------------------------------------------------- /tests/test_8010_valgrind_parse_url_full.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "URL Parsing valgrind leak check." 6 | 7 | echo -n "Testing parse_url_full for memory leaks ..." 8 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_parse_url_full "nfs://user@127.0.0.1/dir/file" "127.0.0.1" "0" "/dir" "/file" >/dev/null 2>&1 || failure 9 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_parse_url_full "nfs://user@127.0.0.1:8000/dir/file" "127.0.0.1" "8000" "/dir" "/file" >/dev/null 2>&1 || failure 10 | success 11 | -------------------------------------------------------------------------------- /utils/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = nfs-cat nfs-ls 2 | 3 | if HAVE_PTHREAD 4 | LIBS += -lpthread 5 | endif 6 | 7 | if !HAVE_WIN32 8 | bin_PROGRAMS += nfs-cp nfs-stat 9 | endif 10 | 11 | AM_CPPFLAGS = \ 12 | -I$(abs_top_srcdir)/include \ 13 | -I$(abs_top_srcdir)/include/nfsc \ 14 | -I$(abs_top_srcdir)/mount \ 15 | -I$(abs_top_srcdir)/win32 \ 16 | "-D_U_=__attribute__((unused))" 17 | 18 | COMMON_LIBS = ../lib/libnfs.la $(LIBSOCKET) 19 | 20 | nfs_cat_LDADD = $(COMMON_LIBS) 21 | nfs_ls_LDADD = $(COMMON_LIBS) 22 | nfs_cp_LDADD = $(COMMON_LIBS) 23 | nfs_stat_LDADD = $(COMMON_LIBS) 24 | -------------------------------------------------------------------------------- /tls/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libtls.la 2 | 3 | tls_SOURCES_GENERATED = 4 | tls_HEADERS_GENERATED = 5 | tls_GENERATED = $(tls_SOURCES_GENERATED) $(tls_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(nfs_GENERATED) tls-stamp 8 | 9 | libtls_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | 13 | libtls_la_SOURCES = \ 14 | $(tls_SOURCES_GENERATED) \ 15 | handshake.c ktls.c tls-private.h 16 | 17 | $(tls_GENERATED) : tls-stamp 18 | tls-stamp : tls.x 19 | rm -f $(nfs_GENERATED) 20 | touch tls-stamp 21 | -------------------------------------------------------------------------------- /win32/nfs-cp/nfs-cp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /win32/nfs-ls/nfs-ls.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/functions.sh: -------------------------------------------------------------------------------- 1 | TESTDIR=`pwd`/testdata 2 | TESTSHARE="127.0.0.1:${TESTDIR}" 3 | TESTURL="nfs://127.0.0.1${TESTDIR}" 4 | 5 | # Which version of NFS to test for 6 | VERS=${VERSION:-3} 7 | 8 | start_share() { 9 | rm -rf "${TESTDIR}" 2>/dev/null 10 | mkdir "${TESTDIR}" 2>/dev/null 11 | sudo exportfs -o rw,insecure,no_root_squash "${TESTSHARE}" 12 | } 13 | 14 | stop_share() { 15 | sudo exportfs -u "${TESTSHARE}" 16 | rm -rf "${TESTDIR}" 17 | } 18 | 19 | success() { 20 | echo "[OK]" 21 | } 22 | 23 | failure() { 24 | echo "[FAILED]" 25 | exit 1 26 | } 27 | 28 | -------------------------------------------------------------------------------- /win32/nfs-cat/nfs-cat.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /win32/nfs-stat/nfs-stat.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /win32/nfsclient-raw/nfsclient-raw.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /win32/nfsclient-async/nfsclient-async.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /win32/nfsclient-bcast/nfsclient-bcast.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /win32/nfsclient-sync/nfsclient-sync.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | XSLTPROC = /usr/bin/xsltproc 2 | 3 | EXTRA_DIST = nfs-cat.1 nfs-cat.1.xml nfs-cp.1 nfs-cp.1.xml nfs-ls.1 nfs-ls.1.xml 4 | 5 | # Manpages 6 | man1_MANS = nfs-cat.1 nfs-cp.1 nfs-ls.1 7 | 8 | doc: 9 | -test -z "$(XSLTPROC)" || $(XSLTPROC) -o nfs-cat.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl nfs-cat.1.xml 10 | -test -z "$(XSLTPROC)" || $(XSLTPROC) -o nfs-cp.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl nfs-cp.1.xml 11 | -test -z "$(XSLTPROC)" || $(XSLTPROC) -o nfs-ls.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl nfs-ls.1.xml 12 | -------------------------------------------------------------------------------- /win32/nfsclient-listservers/nfsclient-listservers.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/test_0360_statvfs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_statvfs() tests." 6 | 7 | start_share 8 | 9 | # check how big the local filesystem is and convert to 4kb blocks 10 | BLOCKS=`df -k . | tail -1 | cut -d ' ' -f 2` 11 | BLOCKS=`expr "$BLOCKS" "/" "4"` 12 | 13 | echo -n "test nfs_statvfs() ... " 14 | ./prog_statvfs "${TESTURL}/?version=${VERS}" "." / > "${TESTDIR}/output" || failure 15 | success 16 | 17 | echo -n "verify total number of blobs is correct ... " 18 | grep "blocks:$BLOCKS" "${TESTDIR}/output" >/dev/null || failure 19 | success 20 | 21 | 22 | stop_share 23 | 24 | exit 0 25 | -------------------------------------------------------------------------------- /nfs4/libnfs-raw-nfs4.c.fragment: -------------------------------------------------------------------------------- 1 | uint32_t 2 | zdr_READ4resok (ZDR *zdrs, READ4resok *objp) 3 | { 4 | uint32_t pos; 5 | 6 | if (!zdr_bool (zdrs, &objp->eof)) 7 | return FALSE; 8 | pos = zdr_getpos(zdrs); 9 | if (!zdr_uint32_t (zdrs, &objp->data.data_len)) 10 | return FALSE; 11 | zdr_setpos(zdrs, pos); 12 | 13 | return TRUE; 14 | } 15 | 16 | uint32_t 17 | zdr_WRITE4args (ZDR *zdrs, WRITE4args *objp) 18 | { 19 | if (!zdr_stateid4 (zdrs, &objp->stateid)) 20 | return FALSE; 21 | if (!zdr_offset4 (zdrs, &objp->offset)) 22 | return FALSE; 23 | if (!zdr_stable_how4 (zdrs, &objp->stable)) 24 | return FALSE; 25 | return TRUE; 26 | } 27 | -------------------------------------------------------------------------------- /tests/test_0340_truncate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_truncate() tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test nfs_truncate() ... " 12 | ./prog_truncate "${TESTURL}/?version=${VERS}" "." /testfile 1998 || failure 13 | success 14 | 15 | echo -n "test nfs_fstat64() ... " 16 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "test nfs_size ... " 20 | grep "nfs_size:1998" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | stop_share 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /tests/test_0290_read.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "basic read test" 6 | 7 | start_share 8 | 9 | echo -n "Create a 10M file ... " 10 | dd if=/dev/urandom of="${TESTDIR}/orig" bs=1M count=10 2>/dev/null || failure 11 | success 12 | 13 | echo -n "Copy file from the NFS server ... " 14 | ../utils/nfs-cp "${TESTURL}/orig" "${TESTDIR}/copy" >/dev/null || failure 15 | success 16 | 17 | echo -n "Verify the files are identical ... " 18 | ORIGSUM=`md5sum "${TESTDIR}/orig" | cut -d " " -f 1` 19 | COPYSUM=`md5sum "${TESTDIR}/copy" | cut -d " " -f 1` 20 | [ "${ORIGSUM}" != "${COPYSUM}" ] && failure 21 | success 22 | 23 | stop_share 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /tests/test_0330_ftruncate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_ftruncate() test." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test nfs_ftruncate() ... " 12 | ./prog_ftruncate "${TESTURL}/?version=${VERS}" "." testfile 12377 || failure 13 | success 14 | 15 | echo -n "test nfs_fstat64() ... " 16 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "verify nfs_size ... " 20 | grep "nfs_size:12377" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | stop_share 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /tests/test_0224_open_O_APPEND.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Open(O_APPEND) test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | 11 | echo -n "test open(O_APPEND) (1) ... " 12 | echo -n "GOAT:" > "${TESTDIR}/open1" 13 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /open1 O_WRONLY,O_APPEND "NieR" >/dev/null || failure 14 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /open1 O_WRONLY,O_APPEND "Automata" >/dev/null || failure 15 | success 16 | 17 | echo -n "verify it got appended ... " 18 | grep "GOAT:NieRAutomata" "${TESTDIR}/open1" >/dev/null || failure 19 | success 20 | 21 | stop_share 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_program(XSLTPROC_PROGRAM xsltproc) 2 | 3 | set(MANPAGES nfs-cat.1 4 | nfs-cp.1 5 | nfs-ls.1) 6 | 7 | set(DOCKBOOK_URL http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl) 8 | 9 | if(XSLTPROC_PROGRAM) 10 | foreach(TARGET ${MANPAGES}) 11 | file(COPY ${TARGET}.xml 12 | DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 13 | add_custom_command(OUTPUT ${TARGET} 14 | COMMAND ${XSLTPROC_PROGRAM} -o ${TARGET} ${DOCKBOOK_URL} ${TARGET}.xml) 15 | endforeach() 16 | 17 | add_custom_target(doc ALL DEPENDS ${MANPAGES}) 18 | endif() 19 | 20 | install(FILES ${MANPAGES} 21 | DESTINATION ${INSTALL_MAN_DIR}/man1/) 22 | -------------------------------------------------------------------------------- /utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(UTILITIES nfs-cat nfs-ls nfs-cp nfs-stat) 2 | 3 | 4 | foreach(TARGET ${UTILITIES}) 5 | add_executable(${TARGET} ${TARGET}.c) 6 | target_link_libraries(${TARGET} nfs) 7 | target_include_directories(${TARGET} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../mount") 8 | 9 | 10 | 11 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 12 | set_target_properties(${TARGET} PROPERTIES 13 | INSTALL_RPATH "${INSTALL_LIB_DIR}" 14 | BUILD_RPATH "${INSTALL_LIB_DIR}" 15 | ) 16 | endif() 17 | 18 | install(TARGETS ${TARGET} 19 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE 20 | DESTINATION ${INSTALL_BIN_DIR}) 21 | endforeach() 22 | -------------------------------------------------------------------------------- /tests/test_8010_parse_url_full.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "URL Parsing tests." 6 | 7 | echo -n "Parsing a url with a username ..." 8 | ./prog_parse_url_full "nfs://user@127.0.0.1/dir/file" "127.0.0.1" "0" "/dir" "/file" || failure 9 | success 10 | 11 | echo -n "Parsing a url with a port number ..." 12 | ./prog_parse_url_full "nfs://user@127.0.0.1:8000/dir/file" "127.0.0.1" "8000" "/dir" "/file" || failure 13 | success 14 | 15 | echo -n "Parsing a url with invalid port numbers ..." 16 | ./prog_parse_url_full "nfs://user@127.0.0.1:-1/dir/file" "127.0.0.1" "-1" "/dir" "/file" && failure || success 17 | ./prog_parse_url_full "nfs://user@127.0.0.1:65536/dir/file" "127.0.0.1" "65536" "/dir" "/file" && failure || success 18 | ./prog_parse_url_full "nfs://user@127.0.0.1:invalid/dir/file" "127.0.0.1" "0" "/dir" "/file" && failure || success 19 | -------------------------------------------------------------------------------- /tests/test_0223_open_O_TRUNC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Open(O_TRUNC) test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | 11 | echo -n "test open(O_WRONLY|O_TRUNC) (1) ... " 12 | echo -n "kangabanga" > "${TESTDIR}/open1" 13 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /open1 O_WRONLY,O_TRUNC "" >/dev/null || failure 14 | success 15 | 16 | echo -n "verify the file got truncated ... " 17 | expr `stat --printf="%s" "${TESTDIR}/open1"` "==" "0" >/dev/null || failure 18 | success 19 | 20 | echo -n "test open(O_RDONLY|O_TRUNC) (2) ... " 21 | echo -n "kangabanga" > "${TESTDIR}/open1" 22 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /open1 O_RDONLY,O_TRUNC "" >/dev/null || failure 23 | success 24 | 25 | echo -n "verify the file did not get truncated ... " 26 | expr `stat --printf="%s" "${TESTDIR}/open1"` "==" "10" >/dev/null || failure 27 | success 28 | 29 | stop_share 30 | 31 | exit 0 32 | -------------------------------------------------------------------------------- /cmake/Macros.cmake: -------------------------------------------------------------------------------- 1 | # Add sources to main application 2 | # Arguments: 3 | # name name of the library to add 4 | # Implicit arguments: 5 | # SOURCES the sources of the library 6 | # HEADERS the headers of the library (only for IDE support) 7 | # On return: 8 | # Library will be built and added to ${CORE_LIBRARIES} 9 | function(core_add_library name) 10 | set(name nfs_${name}) 11 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 12 | add_library(${name} OBJECT ${SOURCES} ${HEADERS}) 13 | target_include_directories(${name} PUBLIC $) 14 | target_include_directories(${name} PRIVATE ${INCLUDEDIRS}) 15 | set(CORE_LIBRARIES "${name};${CORE_LIBRARIES}" CACHE INTERNAL "") 16 | 17 | # no need to install core libs if we build shared library 18 | if(NOT BUILD_SHARED_LIBS) 19 | install(TARGETS ${name} EXPORT libnfs 20 | RUNTIME DESTINATION bin 21 | ARCHIVE DESTINATION lib 22 | LIBRARY DESTINATION lib) 23 | endif() 24 | endfunction() 25 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | schedule: 9 | - cron: "44 9 * * 6" 10 | 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | permissions: 16 | actions: read 17 | contents: read 18 | security-events: write 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | language: [ cpp ] 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v4 28 | 29 | - name: Initialize CodeQL 30 | uses: github/codeql-action/init@v3 31 | with: 32 | languages: ${{ matrix.language }} 33 | queries: +security-and-quality 34 | 35 | - name: Autobuild 36 | uses: github/codeql-action/autobuild@v3 37 | 38 | - name: Perform CodeQL Analysis 39 | uses: github/codeql-action/analyze@v3 40 | with: 41 | category: "/language:${{ matrix.language }}" 42 | -------------------------------------------------------------------------------- /servers/rpcbind/rpcbind_data.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Please do not edit this file. 4 | * It was generated using rpcgen. 5 | */ 6 | 7 | #ifndef _RPCBIND_DATA_H_RPCGEN 8 | #define _RPCBIND_DATA_H_RPCGEN 9 | 10 | #include 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | 18 | struct mapping { 19 | struct mapping *next; 20 | uint32_t port; 21 | uint32_t prog; 22 | uint32_t vers; 23 | char *netid; 24 | char *addr; 25 | char *owner; 26 | }; 27 | typedef struct mapping mapping; 28 | 29 | typedef mapping *mapping_ptr; 30 | 31 | /* the zdr functions */ 32 | 33 | #if defined(__STDC__) || defined(__cplusplus) 34 | extern uint32_t zdr_mapping (ZDR *, mapping*); 35 | extern uint32_t zdr_mapping_ptr (ZDR *, mapping_ptr*); 36 | 37 | #else /* K&R C */ 38 | extern uint32_t zdr_mapping (); 39 | extern uint32_t zdr_mapping_ptr (); 40 | 41 | #endif /* K&R C */ 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* !_RPCBIND_DATA_H_RPCGEN */ 48 | -------------------------------------------------------------------------------- /tests/test_0380_lchmod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic lchmod tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test lchmod(0600) ... " 12 | ./prog_lchmod "${TESTURL}/?version=${VERS}" "." /testfile 0600 || failure 13 | success 14 | 15 | echo -n "Stat the file ... " 16 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "Verifying the mode is 0600 ... " 20 | grep "nfs_mode:100600" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "test lchmod(0755) ... " 24 | ./prog_lchmod "${TESTURL}/?version=${VERS}" "." /testfile 0755 || failure 25 | success 26 | 27 | echo -n "Stat the file ... " 28 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 29 | success 30 | 31 | echo -n "Verifying the mode is 0755 ... " 32 | grep "nfs_mode:100755" "${TESTDIR}/output" >/dev/null || failure 33 | success 34 | 35 | 36 | stop_share 37 | 38 | exit 0 39 | -------------------------------------------------------------------------------- /tests/test_0390_fchmod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic fchmod tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test fchmod(0600) ... " 12 | ./prog_fchmod "${TESTURL}/?version=${VERS}" "." /testfile 0600 || failure 13 | success 14 | 15 | echo -n "Stat the file ... " 16 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "Verifying the mode is 0600 ... " 20 | grep "nfs_mode:100600" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "test fchmod(0755) ... " 24 | ./prog_fchmod "${TESTURL}/?version=${VERS}" "." /testfile 0755 || failure 25 | success 26 | 27 | echo -n "Stat the file ... " 28 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 29 | success 30 | 31 | echo -n "Verifying the mode is 0755 ... " 32 | grep "nfs_mode:100755" "${TESTDIR}/output" >/dev/null || failure 33 | success 34 | 35 | 36 | stop_share 37 | 38 | exit 0 39 | -------------------------------------------------------------------------------- /servers/rpcbind/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = rpcbind 2 | 3 | AM_CPPFLAGS = \ 4 | -I$(abs_top_srcdir)/include/nfsc \ 5 | -I$(abs_top_srcdir)/portmap \ 6 | "-D_U_=__attribute__((unused))" 7 | 8 | COMMON_LIBS = ../../lib/libnfs.la -lpopt 9 | 10 | if HAVE_TLS 11 | COMMON_LIBS += -lgnutls 12 | endif 13 | 14 | rpcbind_LDADD = ../libnfs-server.o rpcbind_data.o $(COMMON_LIBS) -ltalloc -ltevent 15 | 16 | compile_rpc: 17 | cat rpcbind_data.x | head -1 >rpcbind_data.h 18 | rpcgen -h rpcbind_data.x | sed -e "s/#include /#include /" | sed -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" -e "s/u_int/uint32_t/" >> rpcbind_data.h 19 | cat rpcbind_data.x | head -1 >rpcbind_data.c 20 | rpcgen -c rpcbind_data.x | sed -e "s/#include \".*portmap.h\"/#include \"libnfs-zdr.h\"\n#include \"libnfs-raw-portmap.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;//" -e "s/bool_t/uint32_t/g" -e "s/[ \t]*buf = / int32_t *buf;\n buf = /" -e "s/\(u_int \*\)/uint32_t \*/" >> rpcbind_data.c 21 | -------------------------------------------------------------------------------- /cmake/FindNFS.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindNFS 3 | # ------- 4 | # Finds the libnfs library 5 | # 6 | # This will will define the following variables:: 7 | # 8 | # NFS_FOUND - system has libnfs 9 | # NFS_INCLUDE_DIRS - the libnfs include directory 10 | # NFS_LIBRARIES - the libnfs libraries 11 | # NFS_DEFINITIONS - the libnfs compile definitions 12 | # 13 | 14 | if(PKG_CONFIG_FOUND) 15 | pkg_check_modules(PC_NFS libnfs QUIET) 16 | endif() 17 | 18 | find_path(NFS_INCLUDE_DIR nfsc/libnfs.h 19 | PATHS ${PC_NFS_INCLUDEDIR}) 20 | find_library(NFS_LIBRARY NAMES nfs 21 | PATHS ${PC_NFS_LIBDIR}) 22 | 23 | set(NFS_VERSION ${PC_NFS_VERSION}) 24 | 25 | include(FindPackageHandleStandardArgs) 26 | 27 | find_package_handle_standard_args(NFS 28 | REQUIRED_VARS NFS_LIBRARY NFS_INCLUDE_DIR 29 | VERSION_VAR NFS_VERSION) 30 | 31 | if(NFS_FOUND) 32 | set(NFS_LIBRARIES ${NFS_LIBRARY}) 33 | set(NFS_INCLUDE_DIRS ${NFS_INCLUDE_DIR}) 34 | set(NFS_DEFINITIONS -DHAVE_LIBNFS=1) 35 | endif() 36 | 37 | mark_as_advanced(NFS_INCLUDE_DIR NFS_LIBRARY) 38 | -------------------------------------------------------------------------------- /doc/nfs-cat.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | nfs-cat 6 | 1 7 | nfs-cat 8 | nfs-cat: read a file from nfs 9 | 10 | 11 | 12 | 13 | nfs-cat 14 | Utility to read a file off NFS 15 | 16 | 17 | 18 | 19 | nfs-cat <NFS-URL> 20 | 21 | 22 | 23 | 24 | DESCRIPTION 25 | 26 | nfs-cat is a utility to read a file off an NFS server. 27 | 28 | 29 | Example: Print the content of a file: 30 | 31 | $ nfs-cat nfs://127.0.0.1/data/tmp/foo.c 32 | 33 | 34 | 35 | 36 | SEE ALSO 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /nlm/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libnlm.la 2 | 3 | nlm_SOURCES_GENERATED = 4 | nlm_HEADERS_GENERATED = 5 | nlm_GENERATED = $(nlm_SOURCES_GENERATED) $(nlm_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(nlm_GENERATED) nlm-stamp 8 | 9 | libnlm_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | libnlm_la_SOURCES = \ 13 | $(nlm_SOURCES_GENERATED) \ 14 | nlm.c libnfs-raw-nlm.c libnfs-raw-nlm.h 15 | 16 | $(nlm_GENERATED) : nlm-stamp 17 | nlm-stamp : nlm.x 18 | rm -f $(nlm_GENERATED) 19 | touch nlm-stamp 20 | 21 | compile_rpc: 22 | cat nlm.x | head -29 >libnfs-raw-nlm.h 23 | rpcgen -h nlm.x | sed -e "s/#include /#include /" | sed -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" >> libnfs-raw-nlm.h 24 | cat nlm.x | head -29 >libnfs-raw-nlm.c 25 | rpcgen -c nlm.x | sed -e "s/#include \".*nlm.h\"/#include \"libnfs-xdr.h\"\n#include \"libnfs-raw-nlm.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;/register int32_t *buf;\n buf = NULL;/" -e "s/bool_t/uint32_t/g" >> libnfs-raw-nlm.c 26 | -------------------------------------------------------------------------------- /nsm/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libnsm.la 2 | 3 | nsm_SOURCES_GENERATED = 4 | nsm_HEADERS_GENERATED = 5 | nsm_GENERATED = $(nsm_SOURCES_GENERATED) $(nsm_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(nsm_GENERATED) nsm-stamp 8 | 9 | libnsm_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | libnsm_la_SOURCES = \ 13 | $(nsm_SOURCES_GENERATED) \ 14 | nsm.c libnfs-raw-nsm.c libnfs-raw-nsm.h 15 | 16 | $(nsm_GENERATED) : nsm-stamp 17 | nsm-stamp : nsm.x 18 | rm -f $(nsm_GENERATED) 19 | touch nsm-stamp 20 | 21 | compile_rpc: 22 | cat nsm.x | head -29 >libnfs-raw-nsm.h 23 | rpcgen -h nsm.x | sed -e "s/#include /#include /" | sed -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" >> libnfs-raw-nsm.h 24 | cat nsm.x | head -29 >libnfs-raw-nsm.c 25 | rpcgen -c nsm.x | sed -e "s/#include \".*nsm.h\"/#include \"libnfs-xdr.h\"\n#include \"libnfs-raw-nsm.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;/register int32_t *buf;\n buf = NULL;/" -e "s/bool_t/uint32_t/g" >> libnfs-raw-nsm.c 26 | -------------------------------------------------------------------------------- /mount/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libmount.la 2 | 3 | mount_SOURCES_GENERATED = 4 | mount_HEADERS_GENERATED = 5 | mount_GENERATED = $(mount_SOURCES_GENERATED) $(mount_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(mount_GENERATED) mount-stamp 8 | 9 | libmount_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | libmount_la_SOURCES = \ 13 | $(mount_SOURCES_GENERATED) \ 14 | mount.c libnfs-raw-mount.c libnfs-raw-mount.h 15 | 16 | $(mount_GENERATED) : mount-stamp 17 | mount-stamp : mount.x 18 | rm -f $(mount_GENERATED) 19 | touch mount-stamp 20 | 21 | compile_rpc: 22 | cat mount.x | head -29 >libnfs-raw-mount.h 23 | rpcgen -h mount.x | sed -e "s/#include /#include /" | sed -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" >> libnfs-raw-mount.h 24 | cat mount.x | head -29 >libnfs-raw-mount.c 25 | rpcgen -c mount.x | sed -e "s/#include \".*mount.h\"/#include \"libnfs-xdr.h\"\n#include \"libnfs-raw-mount.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;/register int32_t *buf;\n buf = NULL;/" -e "s/bool_t/uint32_t/g" >> libnfs-raw-mount.c 26 | -------------------------------------------------------------------------------- /rquota/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = librquota.la 2 | 3 | rquota_SOURCES_GENERATED = 4 | rquota_HEADERS_GENERATED = 5 | rquota_GENERATED = $(rquota_SOURCES_GENERATED) $(rquota_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(rquota_GENERATED) rquota-stamp 8 | 9 | librquota_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | librquota_la_SOURCES = \ 13 | $(rquota_SOURCES_GENERATED) \ 14 | rquota.c libnfs-raw-rquota.c libnfs-raw-rquota.h 15 | 16 | $(rquota_GENERATED) : rquota-stamp 17 | rquota-stamp : rquota.x 18 | rm -f $(rquota_GENERATED) 19 | touch rquota-stamp 20 | 21 | compile_rpc: 22 | cat rquota.x | head -29 >libnfs-raw-rquota.h 23 | rpcgen -h rquota.x | sed -e "s/#include /#include /" | sed -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" >> libnfs-raw-rquota.h 24 | cat rquota.x | head -29 >libnfs-raw-rquota.c 25 | rpcgen -c rquota.x | sed -e "s/#include \".*rquota.h\"/#include \"libnfs-xdr.h\"\n#include \"libnfs-raw-rquota.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;/register int32_t *buf;\n buf = NULL;/" -e "s/bool_t/uint32_t/g" >> libnfs-raw-rquota.c 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.in 3 | *.la 4 | *.a 5 | *.lo 6 | *.o 7 | *.obj 8 | *.lib 9 | *.dll 10 | *.ilk 11 | *.pdb 12 | *.ex? 13 | *-stamp 14 | libnfs-raw-*.x 15 | Makefile 16 | examples/nfsclient-raw 17 | examples/nfsclient-sync 18 | examples/nfsclient-async 19 | examples/nfsclient-bcast 20 | examples/nfsclient-listservers 21 | aclocal.m4 22 | autom4te.cache/ 23 | compile 24 | config.guess 25 | config.h.in~ 26 | config.log 27 | config.status 28 | config.sub 29 | configure 30 | depcomp 31 | install-sh 32 | libtool 33 | ltmain.sh 34 | missing 35 | stamp-h1 36 | 37 | libnfs.pc 38 | !libnfs.pc.in 39 | build 40 | /win32/libnfs/x64/Debug/libnfs.tlog/CL.command.1.tlog 41 | /win32/libnfs/x64/Debug/libnfs.tlog/libnfs.lastbuildstate 42 | /win32/libnfs/x64/Debug/libnfs.tlog/unsuccessfulbuild 43 | /win32/libnfs/x64/Debug/libnfs.log 44 | /win32/libnfs/x64/Debug/vc143.idb 45 | /win32/nfs-cp/x64/Debug/nfs-cp.tlog/CL.command.1.tlog 46 | *.tlog 47 | /win32/nfs-cp/x64/Debug/nfs-cp.exe.recipe 48 | /win32/nfs-cp/x64/Debug/nfs-cp.log 49 | /win32/nfs-cp/x64/Debug/vc143.idb 50 | /win32/nfs-ls/x64/Debug/nfs-ls.exe.recipe 51 | /win32/nfs-ls/x64/Debug/nfs-ls.log 52 | /win32/nfs-ls/x64/Debug/vc143.idb 53 | /win32/libnfs/x64/Debug/libnfs.vcxproj.FileListAbsolute.txt 54 | /win32/libnfs/x64/Debug/version.res 55 | -------------------------------------------------------------------------------- /doc/nfs-cp.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | nfs-cp 6 | 1 7 | nfs-cp 8 | nfs-cp: copy files to/from an NFS share 9 | 10 | 11 | 12 | 13 | nfs-cp 14 | Utility to copy files to/from and NFS server 15 | 16 | 17 | 18 | 19 | nfs-cp <src> <dst> 20 | 21 | 22 | 23 | 24 | DESCRIPTION 25 | 26 | nfs-cp is a utility to copy files to/from and NFS server. 27 | 28 | 29 | Examples: 30 | 31 | $ nfs-cp foo.c nfs://127.0.0.1/data/tmp/foo.c 32 | 33 | $ nfs-cp nfs://127.0.0.1/data/tmp/foo.c bob.c 34 | 35 | $ nfs-cp nfs://127.0.0.1/data/tmp/foo.c nfs://127.0.0.1/data/tmp/copy-of-foo.c 36 | 37 | 38 | 39 | 40 | SEE ALSO 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ps2_ee/Makefile.PS2_EE: -------------------------------------------------------------------------------- 1 | EE_CFLAGS = -DPS2_EE \ 2 | -D_U_=/**/ -I../include -I../include/nfsc \ 3 | -I../mount -I../nfs -I../nfs4 -I../portmap 4 | 5 | EE_LIB = libnfs.a 6 | EE_INCS = 7 | EE_OBJS = ../lib/init.o ../lib/pdu.o ../lib/socket.o \ 8 | ../lib/nfs_v3.o ../lib/nfs_v4.o \ 9 | ../lib/libnfs.o ../lib/libnfs-sync.o ../lib/libnfs-zdr.o \ 10 | ../mount/mount.o ../mount/libnfs-raw-mount.o \ 11 | ../portmap/portmap.o ../portmap/libnfs-raw-portmap.o \ 12 | ../nfs/nfs.o ../nfs/libnfs-raw-nfs.o \ 13 | ../nfs4/nfs4.o ../nfs4/libnfs-raw-nfs4.o ../nfs/nfsacl.o 14 | 15 | all: $(EE_LIB) $(EE_OBJS) 16 | 17 | install: all 18 | ifeq ($(PS2SDK),) 19 | @echo "$PS2SDK is not set. Can not install libnfs." 20 | @exit 1 21 | endif 22 | @echo Copying... 23 | @[ -d $(PS2SDK)/ee/include/nfsc ] || mkdir -p $(PS2SDK)/ee/include/nfsc 24 | @cp -frv ../include/nfsc/*.h $(PS2SDK)/ee/include/nfsc 25 | @cp -frv ../mount/*.h $(PS2SDK)/ee/include/nfsc 26 | @cp -frv ../portmap/*.h $(PS2SDK)/ee/include/nfsc 27 | @cp -frv ../nfs/*.h $(PS2SDK)/ee/include/nfsc 28 | @cp -frv ../nfs4/*.h $(PS2SDK)/ee/include/nfsc 29 | @cp -frv *.a $(PS2SDK)/ee/lib 30 | @echo Done! 31 | 32 | clean: 33 | rm -rf *.a $(EE_OBJS) 34 | 35 | reset: 36 | ps2client reset 37 | 38 | include $(PS2SDK)/samples/Makefile.pref 39 | include $(PS2SDK)/samples/Makefile.eeglobal 40 | 41 | -------------------------------------------------------------------------------- /tests/test_0211_fstat_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_fstat64() test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "test nfs_fstat64() for a root file (abs) (1)... " 13 | touch "${TESTDIR}/fstat1" 14 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." /fstat1 >/dev/null || failure 15 | success 16 | 17 | echo -n "test nfs_fstat64() for a root file (rel) (2)... " 18 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." fstat1 >/dev/null || failure 19 | success 20 | 21 | echo -n "test nfs_fstat64() for a subdir file (abs) (3)... " 22 | touch "${TESTDIR}/subdir/fstat3" 23 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." /subdir/fstat3 >/dev/null || failure 24 | success 25 | 26 | echo -n "test nfs_fstat64() for a subdir file (rel) (4)... " 27 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." subdir/fstat3 >/dev/null || failure 28 | success 29 | 30 | echo -n "test nfs_fstat64() from a different cwd (rel) (5)... " 31 | ./prog_fstat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/fstat3 >/dev/null || failure 32 | success 33 | 34 | echo -n "test nfs_fstat64() outside the share (rel) (6)... " 35 | ./prog_fstat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/fstat3 >/dev/null 2>&1 && failure 36 | success 37 | 38 | stop_share 39 | 40 | exit 0 41 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_library(TALLOC_LIBRARY talloc) 2 | find_library(TALLOC_EVENT_LIBRARY tevent) 3 | find_library(EVENT_LIBARY event) 4 | 5 | set(EXTRA_LIBRARIES "") 6 | 7 | set(EXAMPLES nfsclient-async 8 | nfsclient-raw 9 | nfsclient-sync 10 | nfsclient-bcast 11 | nfsclient-listservers 12 | nfs-io 13 | nfs-ln 14 | nfs-writefile 15 | nfs-nfsstat 16 | nfs-stats-cb 17 | portmap-client) 18 | 19 | if (ENABLE_MULTITHREADING) 20 | list(APPEND EXAMPLES nfs-pthreads-writefile 21 | nfs-pthreads-async-writefile 22 | nfs-pthreads-async-readfile) 23 | list(APPEND EXTRA_LIBRARIES pthread) 24 | endif() 25 | 26 | if(HAVE_TALLOC_TEVENT) 27 | list(APPEND EXAMPLES nfs4-cat-talloc) 28 | list(APPEND EXTRA_LIBRARIES ${TALLOC_EVENT_LIBRARY} ${TALLOC_LIBRARY}) 29 | endif() 30 | 31 | if(EVENT_LIBARY) 32 | list(APPEND EXAMPLES nfs4-cat 33 | rpcbind) 34 | list(APPEND EXTRA_LIBRARIES ${EVENT_LIBARY}) 35 | endif() 36 | 37 | include_directories(../mount 38 | ../nfs 39 | ../nfs4 40 | ../portmap 41 | ../rquota) 42 | 43 | foreach(TARGET ${EXAMPLES}) 44 | add_executable(${TARGET} ${TARGET}.c) 45 | target_link_libraries(${TARGET} nfs ${EXTRA_LIBRARIES}) 46 | endforeach() 47 | -------------------------------------------------------------------------------- /portmap/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libportmap.la 2 | 3 | portmap_SOURCES_GENERATED = 4 | portmap_HEADERS_GENERATED = 5 | portmap_GENERATED = $(portmap_SOURCES_GENERATED) $(portmap_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(portmap_GENERATED) portmap-stamp 8 | 9 | libportmap_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | libportmap_la_SOURCES = \ 13 | $(portmap_SOURCES_GENERATED) \ 14 | portmap.c libnfs-raw-portmap.c libnfs-raw-portmap.h 15 | 16 | $(portmap_GENERATED) : portmap-stamp 17 | portmap-stamp : portmap.x 18 | rm -f $(portmap_GENERATED) 19 | touch portmap-stamp 20 | 21 | compile_rpc: 22 | cat portmap.x | head -29 >libnfs-raw-portmap.h 23 | rpcgen -h portmap.x | sed -e "s/#include /#include /" | sed -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" -e "s/u_int/uint32_t/" >> libnfs-raw-portmap.h 24 | cat portmap.x | head -29 >libnfs-raw-portmap.c 25 | rpcgen -c portmap.x | sed -e "s/#include \".*portmap.h\"/#include \"libnfs-zdr.h\"\n#include \"libnfs-raw-portmap.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;//" -e "s/bool_t/uint32_t/g" -e "s/[ \t]*buf = / int32_t *buf;\n buf = /" -e "s/\(u_int \*\)/uint32_t \*/" >> libnfs-raw-portmap.c 26 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I${srcdir}/../include -I${srcdir}/../include/nfsc \ 2 | "-D_U_=__attribute__((unused))" \ 3 | "-D_R_(A,B)=__attribute__((format(printf,A,B)))" 4 | AM_CFLAGS = $(WARN_CFLAGS) 5 | LDADD = ../lib/libnfs.la 6 | 7 | noinst_PROGRAMS = prog_access prog_access2 prog_chmod prog_chown prog_create \ 8 | prog_fchmod prog_fchown prog_fstat prog_ftruncate prog_lchmod \ 9 | prog_lchown prog_link prog_lseek prog_lstat prog_mkdir \ 10 | prog_mknod prog_mount prog_opendir prog_open_read prog_open_write \ 11 | prog_rename prog_rmdir prog_stat prog_statvfs prog_symlink \ 12 | prog_timeout prog_truncate prog_unlink prog_utimes \ 13 | prog_read_update_pos prog_readonly prog_parse_url_full 14 | 15 | EXTRA_PROGRAMS = ld_timeout 16 | CLEANFILES = ld_timeout.o ld_timeout.so 17 | 18 | ld_timeout_SOURCES = ld_timeout.c 19 | ld_timeout_CFLAGS = $(AM_CFLAGS) -fPIC 20 | 21 | bin_SCRIPTS = ld_timeout.so 22 | 23 | ld_timeout.o: ld_timeout-ld_timeout.o 24 | $(LIBTOOL) --mode=link $(CC) -o $@ $^ 25 | 26 | ld_timeout.so: ld_timeout.o 27 | $(CC) -shared -o ld_timeout.so ld_timeout.o -ldl 28 | 29 | 30 | 31 | T = `ls test_*.sh` 32 | 33 | test: $(noinst_PROGRAMS) 34 | for TEST in $(T); do \ 35 | echo "Running $$TEST"; \ 36 | echo "--------------"; \ 37 | sh $$TEST || exit 1; \ 38 | echo "--------------"; \ 39 | echo; \ 40 | done 41 | -------------------------------------------------------------------------------- /tests/test_0410_lchown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic lchown tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test lchown(1000, 2000) ... " 12 | ./prog_lchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 1000 2000 || failure 13 | success 14 | 15 | echo -n "Stat the file ... " 16 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "Verifying the uid is 1000 ... " 20 | grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "Verifying the gid is 2000 ... " 24 | grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "test lchown(2000, 3000) ... " 28 | ./prog_lchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 2000 3000 || failure 29 | success 30 | 31 | echo -n "Stat the file ... " 32 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 33 | success 34 | 35 | echo -n "Verifying the uid is 2000 ... " 36 | grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure 37 | success 38 | 39 | echo -n "Verifying the gid is 3000 ... " 40 | grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | 44 | stop_share 45 | 46 | exit 0 47 | -------------------------------------------------------------------------------- /tests/test_0420_fchown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic fchown tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test fchown(1000, 2000) ... " 12 | ./prog_fchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 1000 2000 || failure 13 | success 14 | 15 | echo -n "Stat the file ... " 16 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "Verifying the uid is 1000 ... " 20 | grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "Verifying the gid is 2000 ... " 24 | grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "test fchown(2000, 3000) ... " 28 | ./prog_fchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 2000 3000 || failure 29 | success 30 | 31 | echo -n "Stat the file ... " 32 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 33 | success 34 | 35 | echo -n "Verifying the uid is 2000 ... " 36 | grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure 37 | success 38 | 39 | echo -n "Verifying the gid is 3000 ... " 40 | grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | 44 | stop_share 45 | 46 | exit 0 47 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES init.c 2 | krb5-wrapper.c 3 | libnfs.c 4 | libnfs-sync.c 5 | libnfs-zdr.c 6 | multithreading.c 7 | nfs_v3.c 8 | nfs_v4.c 9 | pdu.c 10 | socket.c 11 | ) 12 | 13 | # deal with version info in "dll" case 14 | if(WIN32 AND BUILD_SHARED_LIBS) 15 | configure_file(../win32/version.rc.template version.rc @ONLY) 16 | list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/version.rc libnfs-win32.def) 17 | endif() 18 | 19 | add_library(nfs ${SOURCES}) 20 | target_link_libraries(nfs PRIVATE ${CORE_LIBRARIES} PUBLIC ${SYSTEM_LIBRARIES}) 21 | 22 | # Set version properties for the library 23 | set_target_properties(nfs PROPERTIES 24 | VERSION ${PROJECT_VERSION} 25 | SOVERSION ${SOVERSION} 26 | ) 27 | 28 | # Set the output filename to "libnfs" consistently across platforms 29 | set_target_properties(nfs PROPERTIES 30 | OUTPUT_NAME "libnfs" # Ensures consistent output name (e.g., libnfs.dll on Windows, libnfs.so on Unix) 31 | PREFIX "" # Removes the "lib" prefix on Unix-like systems to avoid "liblibnfs.so" 32 | ) 33 | 34 | 35 | install(TARGETS nfs EXPORT libnfs 36 | RUNTIME DESTINATION bin 37 | ARCHIVE DESTINATION lib 38 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 39 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=$(WARN_CFLAGS) 2 | 3 | lib_LTLIBRARIES = libnfs.la 4 | 5 | libnfs_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 6 | -I$(abs_top_srcdir)/include/nfsc \ 7 | -I$(abs_top_srcdir)/mount \ 8 | -I$(abs_top_srcdir)/nfs \ 9 | -I$(abs_top_srcdir)/nfs4 \ 10 | -I$(abs_top_srcdir)/nlm \ 11 | -I$(abs_top_srcdir)/nsm \ 12 | -I$(abs_top_srcdir)/portmap \ 13 | -I$(abs_top_srcdir)/rquota \ 14 | -I$(abs_top_srcdir)/win32 \ 15 | "-D_U_=__attribute__((unused))" 16 | 17 | libnfs_la_SOURCES = \ 18 | init.c \ 19 | krb5-wrapper.c \ 20 | libnfs.c \ 21 | libnfs-sync.c \ 22 | libnfs-zdr.c \ 23 | multithreading.c \ 24 | nfs_v3.c \ 25 | nfs_v4.c \ 26 | pdu.c \ 27 | socket.c \ 28 | ../win32/win32_compat.c 29 | 30 | SOCURRENT=16 31 | SOREVISION=2 32 | SOAGE=0 33 | libnfs_la_LDFLAGS = -version-info $(SOCURRENT):$(SOREVISION):$(SOAGE) \ 34 | $(MAYBE_LIBKRB5) 35 | if HAVE_WIN32 36 | libnfs_la_LDFLAGS += -no-undefined 37 | endif 38 | 39 | libnfs_la_LIBADD = \ 40 | ../mount/libmount.la \ 41 | ../nfs/libnfs.la \ 42 | ../nfs4/libnfs4.la \ 43 | ../nlm/libnlm.la \ 44 | ../nsm/libnsm.la \ 45 | ../portmap/libportmap.la \ 46 | ../rquota/librquota.la \ 47 | $(LIBSOCKET) 48 | 49 | if HAVE_TLS 50 | libnfs_la_CPPFLAGS += -I$(abs_top_srcdir)/tls 51 | libnfs_la_LIBADD += ../tls/libtls.la -lgnutls 52 | endif 53 | -------------------------------------------------------------------------------- /nfs/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libnfs.la 2 | 3 | nfs_SOURCES_GENERATED = 4 | nfs_HEADERS_GENERATED = 5 | nfs_GENERATED = $(nfs_SOURCES_GENERATED) $(nfs_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(nfs_GENERATED) nfs-stamp 8 | 9 | libnfs_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | libnfs_la_SOURCES = \ 13 | $(nfs_SOURCES_GENERATED) \ 14 | nfs.c nfsacl.c libnfs-raw-nfs.c libnfs-raw-nfs.h 15 | 16 | $(nfs_GENERATED) : nfs-stamp 17 | nfs-stamp : nfs.x 18 | rm -f $(nfs_GENERATED) 19 | touch nfs-stamp 20 | 21 | compile_rpc: 22 | cat nfs.x | head -29 >libnfs-raw-nfs.h 23 | rpcgen -h nfs.x | sed -e "s/#include /#include /" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/#define _NFS_H_RPCGEN/#define _NFS_H_RPCGEN\n#include /g" -e "s/#define NFS3_COOKIEVERFSIZE 8/#define NFS3_COOKIEVERFSIZE 8\n\n/g" -e "s/ CLIENT / void /g" -e "s/SVCXPRT /void /g" -e "s/bool_t/uint32_t/g" | head -n -5 >> libnfs-raw-nfs.h 24 | cat libnfs-raw-nfs.h.extra >>libnfs-raw-nfs.h 25 | cat nfs.x | head -29 >libnfs-raw-nfs.c 26 | rpcgen -c nfs.x | sed -e "s/#include \".*nfs.h\"/#include \"libnfs-xdr.h\"\n#include \"libnfs-raw-nfs.h\"/" -e "s/xdr/zdr/g" -e "s/XDR/ZDR/g" -e "s/register int32_t \*buf;/register int32_t *buf;\n buf = NULL;/" -e "s/bool_t/uint32_t/g" >> libnfs-raw-nfs.c 27 | -------------------------------------------------------------------------------- /tests/test_0430_access.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic access tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test access(R_OK) on a readable file ... " 12 | chmod 400 "${TESTDIR}/testfile" 13 | ./prog_access "${TESTURL}/?version=${VERS}" "." /testfile R_OK || failure 14 | success 15 | 16 | echo -n "test access(W_OK) on a writeable file ... " 17 | chmod 200 "${TESTDIR}/testfile" 18 | ./prog_access "${TESTURL}/?version=${VERS}" "." /testfile W_OK || failure 19 | success 20 | 21 | echo -n "test access(X_OK) on an executable file ... " 22 | chmod 100 "${TESTDIR}/testfile" 23 | ./prog_access "${TESTURL}/?version=${VERS}" "." /testfile X_OK || failure 24 | success 25 | 26 | echo -n "test access(R_OK) on a non-readable file ... " 27 | chmod 300 "${TESTDIR}/testfile" 28 | ./prog_access "${TESTURL}/?version=${VERS}" "." /testfile R_OK 2>/dev/null && failure 29 | success 30 | 31 | echo -n "test access(W_OK) on a non-writeable file ... " 32 | chmod 500 "${TESTDIR}/testfile" 33 | ./prog_access "${TESTURL}/?version=${VERS}" "." /testfile W_OK 2>/dev/null && failure 34 | success 35 | 36 | echo -n "test access(X_OK) on a non-executable file ... " 37 | chmod 600 "${TESTDIR}/testfile" 38 | ./prog_access "${TESTURL}/?version=${VERS}" "." /testfile X_OK 2>/dev/null && failure 39 | success 40 | 41 | 42 | stop_share 43 | 44 | exit 0 45 | -------------------------------------------------------------------------------- /tests/test_0440_access2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic access2 tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test access2(R_OK) on a readable file ... " 12 | chmod 400 "${TESTDIR}/testfile" 13 | ./prog_access2 "${TESTURL}/?version=${VERS}" "." /testfile R_OK || failure 14 | success 15 | 16 | echo -n "test access2(W_OK) on a writeable file ... " 17 | chmod 200 "${TESTDIR}/testfile" 18 | ./prog_access2 "${TESTURL}/?version=${VERS}" "." /testfile W_OK || failure 19 | success 20 | 21 | echo -n "test access2(X_OK) on an executable file ... " 22 | chmod 100 "${TESTDIR}/testfile" 23 | ./prog_access2 "${TESTURL}/?version=${VERS}" "." /testfile X_OK || failure 24 | success 25 | 26 | echo -n "test access2(R_OK) on a non-readable file ... " 27 | chmod 300 "${TESTDIR}/testfile" 28 | ./prog_access2 "${TESTURL}/?version=${VERS}" "." /testfile R_OK 2>/dev/null && failure 29 | success 30 | 31 | echo -n "test access2(W_OK) on a non-writeable file ... " 32 | chmod 500 "${TESTDIR}/testfile" 33 | ./prog_access2 "${TESTURL}/?version=${VERS}" "." /testfile W_OK 2>/dev/null && failure 34 | success 35 | 36 | echo -n "test access2(X_OK) on a non-executable file ... " 37 | chmod 600 "${TESTDIR}/testfile" 38 | ./prog_access2 "${TESTURL}/?version=${VERS}" "." /testfile X_OK 2>/dev/null && failure 39 | success 40 | 41 | 42 | stop_share 43 | 44 | exit 0 45 | -------------------------------------------------------------------------------- /ps2_ee/config.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2021 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #ifndef __PS2_CONFIG_H__ 20 | 21 | #define HAVE_ARPA_INET_H 1 22 | #define HAVE_INTTYPES_H 1 23 | #define HAVE_MEMORY_H 1 24 | #define HAVE_NETDB_H 1 25 | #define HAVE_NETINET_IN_H 1 26 | #define HAVE_SOCKADDR_LEN 1 27 | #define HAVE_STDINT_H 1 28 | #define HAVE_STDLIB_H 1 29 | #define HAVE_STRINGS_H 1 30 | #define HAVE_STRING_H 1 31 | /* #define HAVE_SYS_SOCKET_H */ 32 | #define HAVE_SYS_STAT_H 1 33 | #define HAVE_SYS_TIME_H 1 34 | #define HAVE_SYS_TYPES_H 1 35 | #define HAVE_UNISTD_H 1 36 | #define HAVE_UTIME_H 1 37 | 38 | #endif /* __PS2_CONFIG_H__ */ 39 | -------------------------------------------------------------------------------- /tests/test_0450_utimes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_utimes() tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=${TESTDIR}/testfile count=1 bs=32768 2>/dev/null 10 | chmod 644 "${TESTDIR}/testfile" 11 | 12 | echo -n "test nfs_utimes() ... " 13 | ./prog_utimes "${TESTURL}/?version=${VERS}" "." /testfile 12345 23456 || failure 14 | success 15 | 16 | echo -n "test nfs_stat64() ... " 17 | ./prog_stat "${TESTURL}/?version=${VERS}" "." /testfile > "${TESTDIR}/output" || failure 18 | success 19 | 20 | echo -n "test nfs_atime ... " 21 | grep "nfs_atime:12345" "${TESTDIR}/output" >/dev/null || failure 22 | success 23 | 24 | echo -n "test nfs_mtime ... " 25 | grep "nfs_mtime:23456" "${TESTDIR}/output" >/dev/null || failure 26 | success 27 | 28 | mkdir ${TESTDIR}/testdir 29 | chmod 644 "${TESTDIR}/testdir" 30 | 31 | echo -n "test nfs_utimes() on dir ... " 32 | ./prog_utimes "${TESTURL}/?version=${VERS}" "." /testdir 12345 23456 || failure 33 | success 34 | 35 | echo -n "test nfs_stat64() on dir ... " 36 | ./prog_stat "${TESTURL}/?version=${VERS}" "." /testdir > "${TESTDIR}/output" || failure 37 | success 38 | 39 | echo -n "test nfs_atime on dir ... " 40 | grep "nfs_atime:12345" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | echo -n "test nfs_mtime on dir ... " 44 | grep "nfs_mtime:23456" "${TESTDIR}/output" >/dev/null || failure 45 | success 46 | 47 | 48 | stop_share 49 | 50 | exit 0 51 | -------------------------------------------------------------------------------- /nfs4/libnfs-raw-nfs4.h.extra: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(WIN32) && defined(libnfs_EXPORTS) 4 | #define EXTERN __declspec( dllexport ) 5 | #else 6 | #ifndef EXTERN 7 | #define EXTERN 8 | #endif 9 | #endif 10 | 11 | /* 12 | * NFSv4 ACL 13 | */ 14 | /* 15 | * Async nfs4 get acl 16 | * Function returns 17 | * 0 : The command was queued successfully. The callback will be invoked once 18 | * the command completes. 19 | * <0 : An error occured when trying to queue the command. 20 | * The callback will not be invoked. 21 | * 22 | * When the callback is invoked, status indicates the result: 23 | * 0 : Success. 24 | * data is fattr4_acl * 25 | * -errno : An error occured. 26 | * data is the error string. 27 | */ 28 | EXTERN int nfs4_getacl_async(struct nfs_context *nfs, struct nfsfh *nfsfh, 29 | nfs_cb cb, void *private_data); 30 | 31 | /* 32 | * Sync nfs4 get acl 33 | * Function returns 34 | * 0 : The operation was successful. 35 | * -errno : The command failed. 36 | * 37 | * If the command was successful, the returned data in nfs4acl must be freed 38 | * by calling nfs4_acl_free() 39 | */ 40 | EXTERN int nfs4_getacl(struct nfs_context *nfs, struct nfsfh *nfsfh, 41 | fattr4_acl *nfs4acl); 42 | 43 | EXTERN void nfs4_acl_free(fattr4_acl *nfs4acl); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* !_NFS4_H_RPCGEN */ 50 | -------------------------------------------------------------------------------- /tests/test_0270_unlink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_unlink() test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "Unlink a file from the root (abs) (1)... " 13 | touch "${TESTDIR}/unlink" 14 | ./prog_unlink "${TESTURL}/?version=${VERS}" "." /unlink || failure 15 | success 16 | 17 | echo -n "Verify the file is gone ... " 18 | ./prog_stat "${TESTURL}/?version=${VERS}" "." unlink 2>/dev/null && failure 19 | success 20 | 21 | echo -n "Unlink a file from the root (rel) (2)... " 22 | touch "${TESTDIR}/unlink" 23 | ./prog_unlink "${TESTURL}/?version=${VERS}" "." unlink || failure 24 | success 25 | 26 | echo -n "Unlink a file from a subdir (abs) (3)... " 27 | touch "${TESTDIR}/subdir/unlink" 28 | ./prog_unlink "${TESTURL}/?version=${VERS}" "." /subdir/unlink || failure 29 | success 30 | 31 | echo -n "Unlink a file from a subdir (rel) (4)... " 32 | touch "${TESTDIR}/subdir/unlink" 33 | ./prog_unlink "${TESTURL}/?version=${VERS}" "." subdir/unlink || failure 34 | success 35 | 36 | echo -n "Unlink a file from a different dir (rel) (5)... " 37 | touch "${TESTDIR}/subdir2/unlink" 38 | ./prog_unlink "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/unlink || failure 39 | success 40 | 41 | echo -n "Unlink a file from outside the share (rel) (6)... " 42 | ./prog_unlink "${TESTURL}/?version=${VERS}" "subdir" ../../subdir2/unlink 2>/dev/null && failure 43 | success 44 | 45 | stop_share 46 | 47 | exit 0 48 | -------------------------------------------------------------------------------- /LICENCE-BSD.txt: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions are met: 3 | 4 | 1. Redistributions of source code must retain the above copyright notice, this 5 | list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright notice, 7 | this list of conditions and the following disclaimer in the documentation 8 | and/or other materials provided with the distribution. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 11 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 13 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 14 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 15 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 16 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 17 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 18 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 19 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | The views and conclusions contained in the software and documentation are those 22 | of the authors and should not be interpreted as representing official policies, 23 | either expressed or implied, of the FreeBSD Project. 24 | -------------------------------------------------------------------------------- /tests/test_0230_creat_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic creat path tests." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "Create a file in root (abs) (1) ... " 13 | ./prog_create "${TESTURL}/?version=${VERS}" "." /creat1 0750 || failure 14 | success 15 | 16 | echo -n "Stat the new file ... " 17 | ./prog_stat "${TESTURL}/?version=${VERS}" "." creat1 > "${TESTDIR}/output" || failure 18 | success 19 | 20 | echo -n "Verifying it is a regular file ... " 21 | grep "nfs_mode:100750" "${TESTDIR}/output" >/dev/null || failure 22 | success 23 | 24 | echo -n "Remove the file ... " 25 | ./prog_unlink "${TESTURL}/?version=${VERS}" "." /creat1 || failure 26 | success 27 | 28 | echo -n "Create a file in root (rel) (2) ... " 29 | ./prog_create "${TESTURL}/?version=${VERS}" "." creat2 0750 || failure 30 | success 31 | 32 | echo -n "Create a file in subdirectory (abs) (3) ... " 33 | ./prog_create "${TESTURL}/?version=${VERS}" "." /subdir/creat3 0750 || failure 34 | success 35 | 36 | echo -n "Create a file in subdirectory (rel) (4) ... " 37 | ./prog_create "${TESTURL}/?version=${VERS}" "." subdir/creat4 0750 || failure 38 | success 39 | 40 | echo -n "Create a file from a different cwd (rel) (5) ... " 41 | ./prog_create "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/creat5 0750 || failure 42 | success 43 | 44 | echo -n "Create a file outside the share (rel) (6) ... " 45 | ./prog_create "${TESTURL}/?version=${VERS}" "subdir" ../../subdir2/creat6 0750 2>/dev/null && failure 46 | success 47 | 48 | 49 | stop_share 50 | 51 | exit 0 52 | -------------------------------------------------------------------------------- /win32/win32_errnowrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Ronnie Sahlberg 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | #ifndef WIN32_ERRNOWRAPPER_H_ 23 | #define WIN32_ERRNOWRAPPER_H_ 24 | 25 | #undef errno 26 | #define errno WSAGetLastError() 27 | #undef EAGAIN 28 | #undef EWOULDBLOCK 29 | #undef EINTR 30 | #undef EINPROGRESS 31 | 32 | #define EWOULDBLOCK WSAEWOULDBLOCK 33 | #define EAGAIN WSAEWOULDBLOCK //same on windows 34 | #define EINTR WSAEINTR 35 | #define EINPROGRESS WSAEWOULDBLOCK //does not map to WSAEINPROGRESS ! 36 | 37 | #endif //WIN32_ERRNOWRAPPER_H_ 38 | -------------------------------------------------------------------------------- /ps3_ppu/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #define HAVE_ARPA_INET_H 1 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #define HAVE_INTTYPES_H 1 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #define HAVE_MEMORY_H 1 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #define HAVE_NETDB_H 1 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #define HAVE_NETINET_IN_H 1 17 | 18 | /* Whether sockaddr struct has sa_len */ 19 | #define HAVE_SOCKADDR_LEN 1 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #define HAVE_STDINT_H 1 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #define HAVE_STDLIB_H 1 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #define HAVE_STRINGS_H 1 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #define HAVE_STRING_H 1 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #define HAVE_SYS_SOCKET_H 1 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #define HAVE_SYS_STAT_H 1 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #define HAVE_SYS_TIME_H 1 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #define HAVE_SYS_TYPES_H 1 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #define HAVE_UNISTD_H 1 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #define HAVE_UTIME_H 1 50 | -------------------------------------------------------------------------------- /tests/test_0341_truncate_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} nfs_truncate() path tests." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "test nfs_truncate() for a root file (abs) (1)... " 13 | touch "${TESTDIR}/trunc1" 14 | ./prog_truncate "${TESTURL}/?version=${VERS}" "." /trunc1 2027 >/dev/null || failure 15 | success 16 | 17 | echo -n "test nfs_truncate() for a root file (rel) (2)... " 18 | ./prog_truncate "${TESTURL}/?version=${VERS}" "." trunc1 2028 >/dev/null || failure 19 | success 20 | 21 | echo -n "test nfs_truncate() for a subdir file (abs) (3)... " 22 | touch "${TESTDIR}/subdir/trunc3" 23 | ./prog_truncate "${TESTURL}/?version=${VERS}" "." /subdir/trunc3 2029 >/dev/null || failure 24 | success 25 | 26 | echo -n "test nfs_truncate() for a subdir file (rel) (4)... " 27 | ./prog_truncate "${TESTURL}/?version=${VERS}" "." subdir/trunc3 2030 >/dev/null || failure 28 | success 29 | 30 | echo -n "test nfs_truncate() from a different cwd (rel) (5)... " 31 | ./prog_truncate "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/trunc3 2031 >/dev/null || failure 32 | success 33 | 34 | echo -n "test nfs_truncate() outside the share (rel) (6)... " 35 | ./prog_truncate "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/trunc3 2032 >/dev/null 2>&1 && failure 36 | success 37 | 38 | echo -n "test nfs_truncate() when target is a symlink (7)... " 39 | touch "${TESTDIR}/trunc7" 40 | ln -s trunc7 "${TESTDIR}/symlink7" 41 | ./prog_truncate "${TESTURL}/?version=${VERS}" "." symlink7 2033 || failure 42 | success 43 | 44 | stop_share 45 | 46 | exit 0 47 | -------------------------------------------------------------------------------- /nfs/libnfs-raw-nfs.h.extra: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(WIN32) && defined(libnfs_EXPORTS) 4 | #define EXTERN __declspec( dllexport ) 5 | #else 6 | #ifndef EXTERN 7 | #define EXTERN 8 | #endif 9 | #endif 10 | 11 | typedef struct { 12 | u_int ace_count; 13 | struct nfsacl_ace *ace; 14 | u_int default_ace_count; 15 | struct nfsacl_ace *default_ace; 16 | } fattr3_acl; 17 | 18 | /* 19 | * NFSv3 ACL 20 | */ 21 | /* 22 | * Async nfs3 get acl 23 | * Function returns 24 | * 0 : The command was queued successfully. The callback will be invoked once 25 | * the command completes. 26 | * <0 : An error occured when trying to queue the command. 27 | * The callback will not be invoked. 28 | * 29 | * When the callback is invoked, status indicates the result: 30 | * 0 : Success. 31 | * data is fattr3_acl * 32 | * -errno : An error occured. 33 | * data is the error string. 34 | */ 35 | EXTERN int nfs3_getacl_async(struct nfs_context *nfs, struct nfsfh *nfsfh, 36 | nfs_cb cb, void *private_data); 37 | 38 | /* 39 | * Sync nfs3 get acl 40 | * Function returns 41 | * 0 : The operation was successful. 42 | * -errno : The command failed. 43 | * 44 | * If the command was successful, the returned data in nfs3acl must be freed 45 | * by calling nfs3_acl_free() 46 | */ 47 | EXTERN int nfs3_getacl(struct nfs_context *nfs, struct nfsfh *nfsfh, 48 | fattr3_acl *nfs3acl); 49 | 50 | EXTERN void nfs3_acl_free(fattr3_acl *nfs3acl); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* !_NFS_H_RPCGEN */ 57 | -------------------------------------------------------------------------------- /tests/test_0202_stat_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_stat64()" 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo -n "test nfs_stat64() (1) ... " 14 | touch "${TESTDIR}/stat1" 15 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null 2>&1 || failure 16 | success 17 | 18 | echo -n "test nfs_stat64() (2) ... " 19 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null 2>&1 || failure 20 | success 21 | 22 | echo -n "test nfs_stat64() (3) ... " 23 | touch "${TESTDIR}/subdir/stat3" 24 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null 2>&1 || failure 25 | success 26 | 27 | echo -n "test nfs_stat64() (4) ... " 28 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null 2>&1 || failure 29 | success 30 | 31 | echo -n "test nfs_stat64() (5) ... " 32 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure 33 | success 34 | 35 | echo -n "test nfs_stat64() (6) ... " 36 | 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 37 | success 38 | 39 | 40 | stop_share 41 | 42 | exit 0 43 | -------------------------------------------------------------------------------- /tls/tls-private.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2024 by Linuxsmiths 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #ifndef __TLS_PRIVATE_H__ 20 | #define __TLS_PRIVATE_H__ 21 | 22 | /* 23 | * Use this instead of RPC_LOG() inside this file as we don't want to pass around 24 | * rpc_context structure to various functions here as they don't really need the 25 | * rpc_context. 26 | * Note that just like RPC_LOG TLS_LOG() is also controlled by debug= libnfs option. 27 | */ 28 | #define TLS_LOG(level, format, ...) \ 29 | do { \ 30 | if (level <= tls_log_level) { \ 31 | fprintf(stderr, "libnfs(tls):%d " format "\n", level, ## __VA_ARGS__); \ 32 | } \ 33 | } while (0) 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | extern int tls_log_level; 40 | extern int setup_ktls(gnutls_session_t session); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* __TLS_PRIVATE_H__ */ 47 | -------------------------------------------------------------------------------- /tests/test_0210_fstat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_fstat64() test." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | chmod 644 testdata/testfile 11 | 12 | echo -n "test nfs_fstat64() ... " 13 | ./prog_fstat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 14 | success 15 | 16 | echo -n "test nfs_ino ... " 17 | INO=`stat --printf="%i" testdata/testfile` 18 | grep "nfs_ino:$INO" "${TESTDIR}/output" >/dev/null || failure 19 | success 20 | 21 | echo -n "test nfs_mode ... " 22 | grep "nfs_mode:100644" "${TESTDIR}/output" >/dev/null || failure 23 | success 24 | 25 | echo -n "test nfs_nlink ... " 26 | grep "nfs_nlink:1" "${TESTDIR}/output" >/dev/null || failure 27 | success 28 | 29 | echo -n "test nfs_uid ... " 30 | grep "nfs_uid:$UID" "${TESTDIR}/output" >/dev/null || failure 31 | success 32 | 33 | echo -n "test nfs_gid ... " 34 | grep "nfs_gid:$GID" "${TESTDIR}/output" >/dev/null || failure 35 | success 36 | 37 | echo -n "test nfs_size ... " 38 | grep "nfs_size:32768" "${TESTDIR}/output" >/dev/null || failure 39 | success 40 | 41 | echo -n "test nfs_atime ... " 42 | ATIME=`stat --printf="%X" testdata/testfile` 43 | grep "nfs_atime:$ATIME" "${TESTDIR}/output" >/dev/null || failure 44 | success 45 | 46 | echo -n "test nfs_mtime ... " 47 | MTIME=`stat --printf="%Y" testdata/testfile` 48 | grep "nfs_mtime:$MTIME" "${TESTDIR}/output" >/dev/null || failure 49 | success 50 | 51 | echo -n "test nfs_ctime ... " 52 | CTIME=`stat --printf="%Z" testdata/testfile` 53 | grep "nfs_ctime:$CTIME" "${TESTDIR}/output" >/dev/null || failure 54 | success 55 | 56 | stop_share 57 | 58 | exit 0 59 | -------------------------------------------------------------------------------- /aros/Makefile.AROS: -------------------------------------------------------------------------------- 1 | AR=ar 2 | CC=gcc 3 | CFLAGS=-g -O0 -DAROS=1 -D_U_=" " -DHAVE_SOCKADDR_LEN -I. -Iinclude -Iinclude/nfsc -Iaros -Infs -Imount 4 | 5 | OBJS=lib/init.o lib/libnfs.o lib/libnfs-sync.o lib/libnfs-zdr.o lib/pdu.o lib/socket.o 6 | OBJS+=mount/mount.o mount/libnfs-raw-mount.o 7 | OBJS+=nfs/nfs.o nfs/nfsacl.o nfs/libnfs-raw-nfs.o 8 | OBJS+=nlm/nlm.o nlm/libnfs-raw-nlm.o 9 | OBJS+=portmap/portmap.o portmap/libnfs-raw-portmap.o 10 | OBJS+=rquota/rquota.o rquota/libnfs-raw-rquota.o 11 | OBJS+=aros/aros_compat.o 12 | 13 | EXAMPLES=examples/nfsclient-listservers examples/nfsclient-sync examples/nfs-cp examples/nfs-ls 14 | 15 | all: lib/libnfs.a $(EXAMPLES) 16 | 17 | lib/libnfs.a: $(OBJS) 18 | $(AR) cru $@ $(OBJS) 19 | 20 | .c.o: 21 | echo $(CC) $(CFLAGS) -c -o $@ $< 22 | $(CC) $(CFLAGS) -c -o $@ $< 23 | 24 | install: all 25 | cp lib/libnfs.a GCC:lib 26 | mkdir -p INCLUDE:nfsc 27 | cp include/nfsc/libnfs.h INCLUDE:nfsc 28 | cp include/nfsc/libnfs-raw.h INCLUDE:nfsc 29 | cp include/nfsc/libnfs-zdr.h INCLUDE:nfsc 30 | cp mount/libnfs-raw-mount.h INCLUDE:nfsc 31 | cp nlm/libnfs-raw-nlm.h INCLUDE:nfsc 32 | cp nfs/libnfs-raw-nfs.h INCLUDE:nfsc 33 | cp portmap/libnfs-raw-portmap.h INCLUDE:nfsc 34 | cp rquota/libnfs-raw-rquota.h INCLUDE:nfsc 35 | 36 | examples/nfsclient-listservers: examples/nfsclient-listservers.c lib/libnfs.a 37 | $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a 38 | 39 | examples/nfsclient-sync: examples/nfsclient-sync.c lib/libnfs.a 40 | $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a 41 | 42 | examples/nfs-ls: examples/nfs-ls.c lib/libnfs.a 43 | $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a 44 | 45 | examples/nfs-cp: examples/nfs-cp.c lib/libnfs.a 46 | $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a 47 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_library(DL_LIBRARY dl) 2 | 3 | set(TEST_PROGS prog_access 4 | prog_access2 5 | prog_chmod 6 | prog_chown 7 | prog_create 8 | prog_fchmod 9 | prog_fchown 10 | prog_fstat 11 | prog_ftruncate 12 | prog_lchmod 13 | prog_lchown 14 | prog_link 15 | prog_lseek 16 | prog_lstat 17 | prog_mkdir 18 | prog_mknod 19 | prog_mount 20 | prog_open_read 21 | prog_open_write 22 | prog_opendir 23 | prog_parse_url_full 24 | prog_read_update_pos 25 | prog_rename 26 | prog_rmdir 27 | prog_stat 28 | prog_statvfs 29 | prog_symlink 30 | prog_timeout 31 | prog_truncate 32 | prog_unlink 33 | prog_utimes) 34 | 35 | foreach(TARGET ${TEST_PROGS}) 36 | add_executable(${TARGET} ${TARGET}.c) 37 | target_link_libraries(${TARGET} nfs) 38 | endforeach() 39 | 40 | add_library(ld_timeout SHARED ld_timeout.c) 41 | set_target_properties(ld_timeout PROPERTIES PREFIX "") 42 | target_link_libraries(ld_timeout nfs ${DL_LIBRARY}) 43 | 44 | file(GLOB TESTS test_*.sh) 45 | 46 | file(COPY functions.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 47 | 48 | foreach(TEST ${TESTS}) 49 | file(COPY ${TEST} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 50 | add_test(NAME ${TEST} 51 | COMMAND ${TEST} 52 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 53 | endforeach() 54 | -------------------------------------------------------------------------------- /tests/test_0201_stat_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} nfs_stat64() path tests." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "test nfs_stat64() for a root file (abs) (1)... " 13 | touch "${TESTDIR}/stat1" 14 | ./prog_stat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null || failure 15 | success 16 | 17 | echo -n "test nfs_stat64() for a root file (rel) (2)... " 18 | ./prog_stat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null || failure 19 | success 20 | 21 | echo -n "test nfs_stat64() for a subdir file (abs) (3)... " 22 | touch "${TESTDIR}/subdir/stat3" 23 | ./prog_stat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null || failure 24 | success 25 | 26 | echo -n "test nfs_stat64() for a subdir file (rel) (4)... " 27 | ./prog_stat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null || failure 28 | success 29 | 30 | echo -n "test nfs_stat64() from a different cwd (rel) (5)... " 31 | ./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null || failure 32 | success 33 | 34 | echo -n "test nfs_stat64() outside the share (rel) (6)... " 35 | ./prog_stat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure 36 | success 37 | 38 | echo -n "test nfs_lstat64() when target is a symlink (7)... " 39 | touch "${TESTDIR}/stat7" 40 | ln -s stat7 "${TESTDIR}/symlink7" 41 | ./prog_stat "${TESTURL}/?version=${VERS}" "." symlink7 >"${TESTDIR}/output" || failure 42 | success 43 | 44 | echo -n "test nfs_lstat() on the underlying file ... " 45 | grep "nfs_mode:100644" "${TESTDIR}/output" >/dev/null || failure 46 | success 47 | 48 | stop_share 49 | 50 | exit 0 51 | -------------------------------------------------------------------------------- /examples/nfsclient-listservers.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) by Ronnie Sahlberg 2011 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, see . 16 | */ 17 | 18 | /* Example program showing sync interface to probe for all local servers 19 | */ 20 | #ifdef AROS 21 | #include "aros_compat.h" 22 | #endif 23 | 24 | #ifdef WIN32 25 | #include 26 | #pragma comment(lib, "ws2_32.lib") 27 | WSADATA wsaData; 28 | #endif 29 | 30 | #include 31 | #include 32 | #include "libnfs.h" 33 | 34 | int main(int argc _U_, char *argv[] _U_) 35 | { 36 | struct nfs_server_list *srvrs; 37 | struct nfs_server_list *srv; 38 | 39 | #ifdef WIN32 40 | if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { 41 | printf("Failed to start Winsock2\n"); 42 | exit(10); 43 | } 44 | #endif 45 | 46 | #ifdef AROS 47 | aros_init_socket(); 48 | #endif 49 | 50 | srvrs = nfs_find_local_servers(); 51 | for (srv=srvrs; srv; srv = srv->next) { 52 | printf("NFS SERVER @ %s\n", srv->addr); 53 | } 54 | free_nfs_srvr_list(srvrs); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/test_0212_fstat_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_fstat64()." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo -n "test nfs_fstat64() (1) ... " 14 | touch "${TESTDIR}/fstat1" 15 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_fstat "${TESTURL}/?version=${VERS}" "." /fstat1 >/dev/null 2>&1 || failure 16 | success 17 | 18 | echo -n "test nfs_fstat64() (2) ... " 19 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_fstat "${TESTURL}/?version=${VERS}" "." fstat1 >/dev/null 2>&1 || failure 20 | success 21 | 22 | echo -n "test nfs_fstat64() (3) ... " 23 | touch "${TESTDIR}/subdir/fstat3" 24 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_fstat "${TESTURL}/?version=${VERS}" "." /subdir/fstat3 >/dev/null 2>&1 || failure 25 | success 26 | 27 | echo -n "test nfs_fstat64() (4) ... " 28 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_fstat "${TESTURL}/?version=${VERS}" "." subdir/fstat3 >/dev/null 2>&1 || failure 29 | success 30 | 31 | echo -n "test nfs_fstat64() (5) ... " 32 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_fstat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/fstat3 >/dev/null 2>&1 || failure 33 | success 34 | 35 | echo -n "test nfs_fstat64() (6) ... " 36 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_fstat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/fstat3 2>/dev/null || expr $? != 99 >/dev/null || failure 37 | success 38 | 39 | 40 | stop_share 41 | 42 | exit 0 43 | -------------------------------------------------------------------------------- /tests/test_0322_lstat_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_lstat64()." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo -n "test nfs_lstat64() (1) ... " 14 | ln -s foo "${TESTDIR}/stat1" 15 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null 2>&1 || failure 16 | success 17 | 18 | echo -n "test nfs_lstat64() (2) ... " 19 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null 2>&1 || failure 20 | success 21 | 22 | echo -n "test nfs_lstat64() (3) ... " 23 | ln -s foo "${TESTDIR}/subdir/stat3" 24 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null 2>&1 || failure 25 | success 26 | 27 | echo -n "test nfs_lstat64() (4) ... " 28 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null 2>&1 || failure 29 | success 30 | 31 | echo -n "test nfs_lstat64() (5) ... " 32 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure 33 | success 34 | 35 | echo -n "test nfs_lstat64() (6) ... " 36 | 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 37 | success 38 | 39 | 40 | stop_share 41 | 42 | exit 0 43 | -------------------------------------------------------------------------------- /tests/test_0320_lstat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic lstat test." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | chmod 644 "${TESTDIR}/testfile" 11 | ln -s testfile "${TESTDIR}/lstat1" 12 | 13 | 14 | echo -n "test nfs_lstat64() ... " 15 | ./prog_lstat "${TESTURL}/?version=${VERS}" "." /lstat1 > "${TESTDIR}/output" || failure 16 | success 17 | 18 | echo -n "test nfs_ino ... " 19 | INO=`stat --printf="%i" testdata/lstat1` 20 | grep "nfs_ino:$INO" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "test nfs_mode ... " 24 | grep "nfs_mode:120777" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "test nfs_nlink ... " 28 | grep "nfs_nlink:1" "${TESTDIR}/output" >/dev/null || failure 29 | success 30 | 31 | echo -n "test nfs_uid ... " 32 | grep "nfs_uid:$UID" "${TESTDIR}/output" >/dev/null || failure 33 | success 34 | 35 | echo -n "test nfs_gid ... " 36 | grep "nfs_gid:$GID" "${TESTDIR}/output" >/dev/null || failure 37 | success 38 | 39 | echo -n "test nfs_size ... " 40 | grep "nfs_size:8" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | echo -n "test nfs_atime ... " 44 | ATIME=`stat --printf="%X" testdata/lstat1` 45 | grep "nfs_atime:$ATIME" "${TESTDIR}/output" >/dev/null || failure 46 | success 47 | 48 | echo -n "test nfs_mtime ... " 49 | MTIME=`stat --printf="%Y" testdata/lstat1` 50 | grep "nfs_mtime:$MTIME" "${TESTDIR}/output" >/dev/null || failure 51 | success 52 | 53 | echo -n "test nfs_ctime ... " 54 | CTIME=`stat --printf="%Z" testdata/lstat1` 55 | grep "nfs_ctime:$CTIME" "${TESTDIR}/output" >/dev/null || failure 56 | success 57 | 58 | stop_share 59 | 60 | exit 0 61 | -------------------------------------------------------------------------------- /nfs4/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libnfs4.la 2 | 3 | nfs4_SOURCES_GENERATED = 4 | nfs4_HEADERS_GENERATED = 5 | nfs4_GENERATED = $(nfs4_SOURCES_GENERATED) $(nfs4_HEADERS_GENERATED) 6 | 7 | CLEANFILES = $(nfs_GENERATED) nfs4-stamp 8 | 9 | libnfs4_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 10 | -I$(abs_top_srcdir)/include/nfsc \ 11 | -I$(abs_top_srcdir)/win32 12 | libnfs4_la_SOURCES = \ 13 | $(nfs4_SOURCES_GENERATED) \ 14 | nfs4.c libnfs-raw-nfs4.c libnfs-raw-nfs4.h 15 | 16 | $(nfs4_GENERATED) : nfs4-stamp 17 | nfs4-stamp : nfs4.x 18 | rm -f $(nfs_GENERATED) 19 | touch nfs4-stamp 20 | 21 | compile_rpc: 22 | cat nfs4.x | head -16 >libnfs-raw-nfs4.h 23 | rpcgen -h nfs4.x | sed \ 24 | -e "s/#include /#include /" \ 25 | -e "s/xdr/zdr/g" \ 26 | -e "s/XDR/ZDR/g" \ 27 | -e "s/#define _NFS_H_RPCGEN/#define _NFS_H_RPCGEN\n#include /g" \ 28 | -e "s/#define NFS3_COOKIEVERFSIZE 8/#define NFS3_COOKIEVERFSIZE 8\n\n/g" \ 29 | -e "s/ CLIENT / void /g" \ 30 | -e "s/SVCXPRT /void /g" \ 31 | -e "s/bool_t/uint32_t/g" | head --lines=-5 >>libnfs-raw-nfs4.h 32 | cat libnfs-raw-nfs4.h.extra >>libnfs-raw-nfs4.h 33 | cat nfs4.x | head -16 >libnfs-raw-nfs4.c 34 | rpcgen -c nfs4.x | sed \ 35 | -e "s/#include \".*nfs4.h\"/#include \"libnfs-xdr.h\"\n#include \"libnfs-raw-nfs4.h\"/" \ 36 | -e "s/xdr/zdr/g" \ 37 | -e "s/XDR/ZDR/g" \ 38 | -e "s/bool_t/uint32_t/g" \ 39 | -e "s/register int32_t \*buf;/register int32_t *buf;\n buf = NULL;/" \ 40 | -e "s/int i;//" >> libnfs-raw-nfs4.c 41 | sed -z -i -e "s/zdr_READ4resok/zzdr_READ4resok/" libnfs-raw-nfs4.c 42 | sed -z -i -e "s/zdr_WRITE4args/zzdr_WRITE4args/" libnfs-raw-nfs4.c 43 | cat libnfs-raw-nfs4.c.fragment >>libnfs-raw-nfs4.c 44 | -------------------------------------------------------------------------------- /tests/test_0321_lstat_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} nfs_lstat64() path tests." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "test nfs_lstat64() for a root file (abs) (1)... " 13 | ln -s foo "${TESTDIR}/stat1" 14 | ./prog_lstat "${TESTURL}/?version=${VERS}" "." /stat1 >/dev/null || failure 15 | success 16 | 17 | echo -n "test nfs_lstat64() for a root file (rel) (2)... " 18 | ./prog_lstat "${TESTURL}/?version=${VERS}" "." stat1 >/dev/null || failure 19 | success 20 | 21 | echo -n "test nfs_lstat64() for a subdir file (abs) (3)... " 22 | ln -s foo "${TESTDIR}/subdir/stat3" 23 | ./prog_lstat "${TESTURL}/?version=${VERS}" "." /subdir/stat3 >/dev/null || failure 24 | success 25 | 26 | echo -n "test nfs_lstat64() for a subdir file (rel) (4)... " 27 | ./prog_lstat "${TESTURL}/?version=${VERS}" "." subdir/stat3 >/dev/null || failure 28 | success 29 | 30 | echo -n "test nfs_lstat64() from a different cwd (rel) (5)... " 31 | ./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/stat3 >/dev/null || failure 32 | success 33 | 34 | echo -n "test nfs_lstat64() outside the share (rel) (6)... " 35 | ./prog_lstat "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure 36 | success 37 | 38 | echo -n "test nfs_lstat64() when target is a symlink (7)... " 39 | touch "${TESTDIR}/stat7" 40 | ln -s stat7 "${TESTDIR}/symlink7" 41 | ./prog_lstat "${TESTURL}/?version=${VERS}" "." symlink7 >"${TESTDIR}/output" || failure 42 | success 43 | 44 | echo -n "test nfs_lstat64() report it is a symlink ... " 45 | grep "nfs_mode:120777" "${TESTDIR}/output" >/dev/null || failure 46 | success 47 | 48 | 49 | stop_share 50 | 51 | exit 0 52 | -------------------------------------------------------------------------------- /tests/test_0200_stat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic nfs_stat64() tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | chmod 644 "${TESTDIR}/testfile" 11 | ln -s testfile "${TESTDIR}/lstat1" 12 | 13 | 14 | echo -n "test nfs_stat64() ... " 15 | ./prog_stat "${TESTURL}/?version=${VERS}" "." /testfile > "${TESTDIR}/output" || failure 16 | success 17 | 18 | echo -n "test nfs_ino ... " 19 | INO=`stat --printf="%i" testdata/testfile` 20 | grep "nfs_ino:$INO" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "test nfs_mode ... " 24 | grep "nfs_mode:100644" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "test nfs_nlink ... " 28 | grep "nfs_nlink:1" "${TESTDIR}/output" >/dev/null || failure 29 | success 30 | 31 | echo -n "test nfs_uid ... " 32 | grep "nfs_uid:$UID" "${TESTDIR}/output" >/dev/null || failure 33 | success 34 | 35 | echo -n "test nfs_gid ... " 36 | grep "nfs_gid:$GID" "${TESTDIR}/output" >/dev/null || failure 37 | success 38 | 39 | echo -n "test nfs_size ... " 40 | grep "nfs_size:32768" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | echo -n "test nfs_atime ... " 44 | ATIME=`stat --printf="%X" testdata/testfile` 45 | grep "nfs_atime:$ATIME" "${TESTDIR}/output" >/dev/null || failure 46 | success 47 | 48 | echo -n "test nfs_mtime ... " 49 | MTIME=`stat --printf="%Y" testdata/testfile` 50 | grep "nfs_mtime:$MTIME" "${TESTDIR}/output" >/dev/null || failure 51 | success 52 | 53 | echo -n "test nfs_ctime ... " 54 | CTIME=`stat --printf="%Z" testdata/testfile` 55 | grep "nfs_ctime:$CTIME" "${TESTDIR}/output" >/dev/null || failure 56 | success 57 | 58 | stop_share 59 | 60 | exit 0 61 | -------------------------------------------------------------------------------- /tests/test_0203_stat_symlink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} nfs_stat64() test on symlink." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null 10 | chmod 644 "${TESTDIR}/testfile" 11 | ln -s testfile "${TESTDIR}/lstat1" 12 | 13 | 14 | echo -n "test nfs_stat64() ... " 15 | ./prog_stat "${TESTURL}/?version=${VERS}" "." /lstat1 > "${TESTDIR}/output" || failure 16 | success 17 | 18 | echo -n "test nfs_ino ... " 19 | INO=`stat --printf="%i" testdata/testfile` 20 | grep "nfs_ino:$INO" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "test nfs_mode ... " 24 | grep "nfs_mode:100644" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "test nfs_nlink ... " 28 | grep "nfs_nlink:1" "${TESTDIR}/output" >/dev/null || failure 29 | success 30 | 31 | echo -n "test nfs_uid ... " 32 | grep "nfs_uid:$UID" "${TESTDIR}/output" >/dev/null || failure 33 | success 34 | 35 | echo -n "test nfs_gid ... " 36 | grep "nfs_gid:$GID" "${TESTDIR}/output" >/dev/null || failure 37 | success 38 | 39 | echo -n "test nfs_size ... " 40 | grep "nfs_size:32768" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | echo -n "test nfs_atime ... " 44 | ATIME=`stat --printf="%X" testdata/testfile` 45 | grep "nfs_atime:$ATIME" "${TESTDIR}/output" >/dev/null || failure 46 | success 47 | 48 | echo -n "test nfs_mtime ... " 49 | MTIME=`stat --printf="%Y" testdata/testfile` 50 | grep "nfs_mtime:$MTIME" "${TESTDIR}/output" >/dev/null || failure 51 | success 52 | 53 | echo -n "test nfs_ctime ... " 54 | CTIME=`stat --printf="%Z" testdata/testfile` 55 | grep "nfs_ctime:$CTIME" "${TESTDIR}/output" >/dev/null || failure 56 | success 57 | 58 | stop_share 59 | 60 | exit 0 61 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Libnfs components fall under two separate licences 2 | 3 | 4 | The library sources and include directories 5 | =========================================== 6 | The nfs client library itself, i.e. the lib and include directories, 7 | is licenced under GNU Lesser General Public License as published by 8 | the Free Software Foundation; either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | The protocol definition, .x, files 12 | ================================== 13 | These are based on old RFCs and studying how wireshark dissects various packets. 14 | These are distributed under the simplified BSD licence. 15 | 16 | The files generated from the .x files 17 | ===================================== 18 | The files that are generated from the .x sources, 19 | i.e. */libnfs-raw-.[ch] 20 | can be considered to be distributed under the simplified BSD licence. 21 | 22 | These files are only provided as a convenience, so that you do not need to 23 | install and run rpcgen on the *.x files locally. 24 | If you disagree with the simplified BSD licence I provide them under 25 | then just delete them and then generate identical copies of these files yourself 26 | using "make compile_rpc" in each protocol subdirectory. 27 | 28 | Then you can pick whatever licence you want on those files. 29 | 30 | The examples directory 31 | ================================ 32 | The utility and example applications using this library, i.e. the 33 | examples directory, are licenced under the GNU General Public License 34 | as published by the Free Software Foundation; either version 3 of the 35 | License, or (at your option) any later version. 36 | 37 | 38 | To avoid any confusion, every source file contains a licence boilerplate. 39 | 40 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = nfsclient-async nfsclient-raw nfsclient-sync \ 2 | nfsclient-bcast nfsclient-listservers nfs-fh nfs-io nfs-ln nfs4-cat \ 3 | portmap-client nfs-writefile nfs-stats-cb \ 4 | nfs-nfsstat nfs-cat-preadv 5 | 6 | if HAVE_TALLOC_TEVENT 7 | noinst_PROGRAMS += nfs4-cat-talloc 8 | endif 9 | 10 | if HAVE_PTHREAD 11 | LIBS += -lpthread 12 | noinst_PROGRAMS += nfs-pthreads-example nfs-pthreads-fstat \ 13 | nfs-pthreads-writefile nfs-pthreads-async-writefile 14 | endif 15 | 16 | AM_CPPFLAGS = \ 17 | -I$(abs_top_srcdir)/include \ 18 | -I$(abs_top_srcdir)/include/nfsc \ 19 | -I$(abs_top_srcdir)/include/win32 \ 20 | -I$(abs_top_srcdir)/mount \ 21 | -I$(abs_top_srcdir)/nfs \ 22 | -I$(abs_top_srcdir)/nfs4 \ 23 | -I$(abs_top_srcdir)/portmap \ 24 | -I$(abs_top_srcdir)/rquota \ 25 | "-D_U_=__attribute__((unused))" 26 | 27 | COMMON_LIBS = ../lib/libnfs.la -lpopt 28 | if HAVE_TLS 29 | COMMON_LIBS += -lgnutls 30 | endif 31 | nfs_writefile_LDADD = $(COMMON_LIBS) 32 | nfsclient_async_LDADD = $(COMMON_LIBS) 33 | nfsclient_raw_LDADD = $(COMMON_LIBS) 34 | nfsclient_sync_LDADD = $(COMMON_LIBS) 35 | nfsclient_bcast_LDADD = $(COMMON_LIBS) 36 | nfsclient_listservers_LDADD = $(COMMON_LIBS) 37 | nfs_fh_LDADD = $(COMMON_LIBS) 38 | nfs_io_LDADD = $(COMMON_LIBS) 39 | nfs_ln_LDADD = $(COMMON_LIBS) 40 | nfs4_cat_LDADD = $(COMMON_LIBS) -levent 41 | nfs4_cat_talloc_LDADD = $(COMMON_LIBS) -ltevent -ltalloc 42 | nfs_cat_preadv_LDADD = $(COMMON_LIBS) 43 | portmap_client_LDADD = $(COMMON_LIBS) 44 | nfs_pthreads_example_LDADD = $(COMMON_LIBS) 45 | nfs_pthreads_fstat_LDADD = $(COMMON_LIBS) 46 | nfs_pthreads_writefile_LDADD = $(COMMON_LIBS) 47 | nfs_pthreads_async_writefile_LDADD = $(COMMON_LIBS) 48 | nfs_stats_cb_LDADD = $(COMMON_LIBS) 49 | nfs_nfsstat_LDADD = $(COMMON_LIBS) 50 | -------------------------------------------------------------------------------- /tests/test_0222_open_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_open()." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo -n "test nfs_open() (1) ... " 14 | echo -n "kangabanga" > "${TESTDIR}/open1" 15 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/?version=${VERS}" "." /open1 O_RDONLY >/dev/null 2>&1 || failure 16 | success 17 | 18 | echo -n "test nfs_open() (2) ... " 19 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/?version=${VERS}" "." open1 O_RDONLY >/dev/null 2>&1 || failure 20 | success 21 | 22 | echo -n "test nfs_open() (3) ... " 23 | echo -n "kangabanga" > "${TESTDIR}/subdir/open3" 24 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/?version=${VERS}" "." /subdir/open3 O_RDONLY >/dev/null 2>&1 || failure 25 | success 26 | 27 | echo -n "test nfs_open() (4) ... " 28 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/?version=${VERS}" "." subdir/open3 O_RDONLY >/dev/null 2>&1 || failure 29 | success 30 | 31 | echo -n "test nfs_open() (5) ... " 32 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/open3 O_RDONLY >/dev/null 2>&1 || failure 33 | success 34 | 35 | echo -n "test nfs_open() (6) ... " 36 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/open3 O_RDONLY 2>/dev/null || expr $? != 99 >/dev/null || failure 37 | success 38 | 39 | 40 | stop_share 41 | 42 | exit 0 43 | -------------------------------------------------------------------------------- /tests/test_0272_unlink_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_unlink()." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo -n "test nfs_unlink() (1) ... " 14 | touch "${TESTDIR}/unlink" 15 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_unlink "${TESTURL}/?version=${VERS}" "." /unlink 2>/dev/null || failure 16 | success 17 | 18 | echo -n "test nfs_unlink() (2) ... " 19 | touch "${TESTDIR}/unlink" 20 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_unlink "${TESTURL}/?version=${VERS}" "." unlink 2>/dev/null || failure 21 | success 22 | 23 | echo -n "test nfs_unlink() (3) ... " 24 | touch "${TESTDIR}/subdir/unlink" 25 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_unlink "${TESTURL}/?version=${VERS}" "." /subdir/unlink 2>/dev/null || failure 26 | success 27 | 28 | echo -n "test nfs_unlink() (4) ... " 29 | touch "${TESTDIR}/subdir/unlink" 30 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_unlink "${TESTURL}/?version=${VERS}" "." subdir/unlink 2>/dev/null || failure 31 | success 32 | 33 | echo -n "test nfs_unlink() (5) ... " 34 | touch "${TESTDIR}/subdir2/unlink" 35 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_unlink "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/unlink 2>/dev/null || failure 36 | success 37 | 38 | echo -n "test nfs_unlink() (6) ... " 39 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_unlink "${TESTURL}/?version=${VERS}" "subdir" ../../subdir2/unlink 2>/dev/null || expr $? != 99 >/dev/null || failure 40 | success 41 | 42 | 43 | stop_share 44 | 45 | exit 0 46 | -------------------------------------------------------------------------------- /include/slist.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 by Ronnie Sahlberg 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation; either version 2.1 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, see . 16 | */ 17 | 18 | #ifndef _LIBNFS_SLIST_H_ 19 | #define _LIBNFS_SLIST_H_ 20 | 21 | #define LIBNFS_LIST_ADD(list, item) \ 22 | do { \ 23 | (item)->next = (*list); \ 24 | (*list) = (item); \ 25 | } while (0); 26 | 27 | #define LIBNFS_LIST_ADD_END(list, item) \ 28 | if ((*list) == NULL) { \ 29 | LIBNFS_LIST_ADD((list), (item)); \ 30 | } else { \ 31 | void *head = (*list); \ 32 | while ((*list)->next) \ 33 | (*list) = (*list)->next; \ 34 | (*list)->next = (item); \ 35 | (item)->next = NULL; \ 36 | (*list) = head; \ 37 | } 38 | 39 | #define LIBNFS_LIST_REMOVE(list, item) \ 40 | if ((*list) == (item)) { \ 41 | (*list) = (item)->next; \ 42 | } else { \ 43 | void *head = (*list); \ 44 | while ((*list)->next && (*list)->next != (item)) \ 45 | (*list) = (*list)->next; \ 46 | if ((*list)->next != NULL) { \ 47 | (*list)->next = (*list)->next->next; \ 48 | } \ 49 | (*list) = head; \ 50 | } 51 | 52 | #endif /* !_LIBNFS_SLIST_H_ */ 53 | -------------------------------------------------------------------------------- /tests/test_0460_opendir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # NFS servers generally want us to be root in order to create device nodes. 4 | # We can lie and impersonate root by setting uid=0 in the URL. 5 | 6 | . ./functions.sh 7 | 8 | echo "NFSv${VERS} Basic opendir test." 9 | 10 | start_share 11 | 12 | mkdir "${TESTDIR}/subdir" 13 | mkdir "${TESTDIR}/subdir/subdir2" 14 | touch "${TESTDIR}/subdir/subdir2/file" 15 | 16 | echo -n "Open '.' in the root directory (1)... " 17 | ./prog_opendir "${TESTURL}/?uid=0&version=${VERS}" "." "." > "${TESTDIR}/output" || failure 18 | success 19 | 20 | echo -n "Check the directory listing ... " 21 | grep "^subdir$" "${TESTDIR}/output" >/dev/null || failure 22 | success 23 | 24 | echo -n "Open a subdir in the root directory (2)... " 25 | ./prog_opendir "${TESTURL}/?uid=0&version=${VERS}" "." "subdir" > "${TESTDIR}/output" || failure 26 | success 27 | 28 | echo -n "Check the directory listing ... " 29 | grep "^subdir2$" "${TESTDIR}/output" >/dev/null || failure 30 | success 31 | 32 | echo -n "Open '.' in a subdir (3)... " 33 | ./prog_opendir "${TESTURL}/?uid=0&version=${VERS}" "subdir" "." > "${TESTDIR}/output" || failure 34 | success 35 | 36 | echo -n "Check the directory listing ... " 37 | grep "^subdir2$" "${TESTDIR}/output" >/dev/null || failure 38 | success 39 | 40 | echo -n "Open 'subdir2' in a subdir (4)... " 41 | ./prog_opendir "${TESTURL}/?uid=0&version=${VERS}" "subdir" "subdir2" > "${TESTDIR}/output" || failure 42 | success 43 | 44 | echo -n "Check the directory listing ... " 45 | grep "^file$" "${TESTDIR}/output" >/dev/null || failure 46 | success 47 | 48 | echo -n "Open '..' in a subdir (5)... " 49 | ./prog_opendir "${TESTURL}/?uid=0&version=${VERS}" "subdir/subdir2" ".." > "${TESTDIR}/output" || failure 50 | success 51 | 52 | echo -n "Check the directory listing ... " 53 | grep "^subdir2$" "${TESTDIR}/output" >/dev/null || failure 54 | success 55 | 56 | stop_share 57 | 58 | exit 0 59 | -------------------------------------------------------------------------------- /doc/nfs-cat.1: -------------------------------------------------------------------------------- 1 | '\" t 2 | .\" Title: nfs-cat 3 | .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] 4 | .\" Generator: DocBook XSL Stylesheets v1.78.1 5 | .\" Date: 05/24/2015 6 | .\" Manual: nfs-cat: read a file from nfs 7 | .\" Source: nfs-cat 8 | .\" Language: English 9 | .\" 10 | .TH "NFS\-CAT" "1" "05/24/2015" "nfs\-cat" "nfs\-cat: read a file from nfs" 11 | .\" ----------------------------------------------------------------- 12 | .\" * Define some portability stuff 13 | .\" ----------------------------------------------------------------- 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | .\" http://bugs.debian.org/507673 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | .ie \n(.g .ds Aq \(aq 19 | .el .ds Aq ' 20 | .\" ----------------------------------------------------------------- 21 | .\" * set default formatting 22 | .\" ----------------------------------------------------------------- 23 | .\" disable hyphenation 24 | .nh 25 | .\" disable justification (adjust text to left margin only) 26 | .ad l 27 | .\" ----------------------------------------------------------------- 28 | .\" * MAIN CONTENT STARTS HERE * 29 | .\" ----------------------------------------------------------------- 30 | .SH "NAME" 31 | nfs-cat \- Utility to read a file off NFS 32 | .SH "SYNOPSIS" 33 | .HP \w'\fBnfs\-cat\ \fR\ 'u 34 | \fBnfs\-cat \fR 35 | .SH "DESCRIPTION" 36 | .PP 37 | nfs\-cat is a utility to read a file off an NFS server\&. 38 | .PP 39 | Example: Print the content of a file: 40 | .sp 41 | .if n \{\ 42 | .RS 4 43 | .\} 44 | .nf 45 | $ nfs\-cat nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c 46 | 47 | .fi 48 | .if n \{\ 49 | .RE 50 | .\} 51 | .sp 52 | .SH "SEE ALSO" 53 | .PP 54 | \m[blue]\fB\%http://github.com/sahlberg/libnfs\fR\m[] 55 | -------------------------------------------------------------------------------- /tests/test_0370_chmod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic chmod tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=${TESTDIR}/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test chmod(0600) ... " 12 | ./prog_chmod "${TESTURL}/?version=${VERS}" "." /testfile 0600 || failure 13 | success 14 | 15 | echo -n "Stat the file ... " 16 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "Verifying the mode is 0600 ... " 20 | grep "nfs_mode:100600" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "test chmod(0755) ... " 24 | ./prog_chmod "${TESTURL}/?version=${VERS}" "." /testfile 0755 || failure 25 | success 26 | 27 | echo -n "Stat the file ... " 28 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 29 | success 30 | 31 | echo -n "Verifying the mode is 0755 ... " 32 | grep "nfs_mode:100755" "${TESTDIR}/output" >/dev/null || failure 33 | success 34 | 35 | mkdir ${TESTDIR}/testdir 36 | 37 | echo -n "test chmod(0600) on dir ... " 38 | ./prog_chmod "${TESTURL}/?version=${VERS}" "." /testdir 0600 || failure 39 | success 40 | 41 | echo -n "Stat the dir ... " 42 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testdir > "${TESTDIR}/output" || failure 43 | success 44 | 45 | echo -n "Verifying the mode is 0600 on dir ... " 46 | grep "nfs_mode:40600" "${TESTDIR}/output" >/dev/null || failure 47 | success 48 | 49 | echo -n "test chmod(0755) on dir ... " 50 | ./prog_chmod "${TESTURL}/?version=${VERS}" "." /testdir 0755 || failure 51 | success 52 | 53 | echo -n "Stat the dir ... " 54 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testdir > "${TESTDIR}/output" || failure 55 | success 56 | 57 | echo -n "Verifying the mode is 0755 on dir ... " 58 | grep "nfs_mode:40755" "${TESTDIR}/output" >/dev/null || failure 59 | success 60 | 61 | stop_share 62 | 63 | exit 0 64 | -------------------------------------------------------------------------------- /tests/prog_parse_url_full.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "libnfs.h" 6 | 7 | void usage(void) 8 | { 9 | fprintf(stderr, "Usage: prog_parse_url_full \n"); 10 | exit(1); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | struct nfs_context *nfs; 16 | struct nfs_url *nfs_url; 17 | int ret = 0; 18 | int expected_port; 19 | 20 | if (argc != 6) 21 | { 22 | usage(); 23 | } 24 | 25 | nfs = nfs_init_context(); 26 | if (nfs == NULL) { 27 | fprintf(stderr, "failed to init context\n"); 28 | return 1; 29 | } 30 | 31 | nfs_url = nfs_parse_url_full(nfs, argv[1]); 32 | if (nfs_url == NULL) { 33 | fprintf(stderr, "Failed to parse URL: %s\n", nfs_get_error(nfs)); 34 | nfs_destroy_context(nfs); 35 | return 1; 36 | } 37 | 38 | if (strcmp(nfs_url->server, argv[2]) != 0) { 39 | fprintf(stderr, "Unexpected server name: %s (expected: %s)\n", 40 | nfs_url->server ? nfs_url->server : "(null)", argv[2]); 41 | ret = 1; 42 | } 43 | 44 | expected_port = atoi(argv[3]); 45 | if (nfs_url->port != expected_port) { 46 | fprintf(stderr, "Unexpected port: %d (expected: %d)\n", 47 | nfs_url->port, expected_port); 48 | ret = 1; 49 | } 50 | 51 | if (strcmp(nfs_url->path, argv[4]) != 0) { 52 | fprintf(stderr, "Unexpected path: %s (expected: %s)\n", 53 | nfs_url->path ? nfs_url->path : "(null)", argv[4]); 54 | ret = 1; 55 | } 56 | 57 | if (strcmp(nfs_url->file, argv[5]) != 0) { 58 | fprintf(stderr, "Unexpected file: %s (expected: %s)\n", 59 | nfs_url->file ? nfs_url->file : "(null)", argv[5]); 60 | ret = 1; 61 | } 62 | 63 | nfs_destroy_url(nfs_url); 64 | nfs_destroy_context(nfs); 65 | 66 | return ret; 67 | } -------------------------------------------------------------------------------- /tests/test_0225_open_O_CREAT.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Open(O_CREAT) test." 6 | 7 | start_share 8 | 9 | rm ${TESTDIR}/create1 >/dev/null 2>&1 10 | 11 | echo -n "test open(O_RDWR|O_CREAT|O_EXCL) on a new file (1) ... " 12 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /create1 O_RDWR,O_CREAT,O_EXCL LordOfCinder >/dev/null || failure 13 | success 14 | 15 | echo -n "test open(O_RDWR|O_CREAT|O_EXCL) on an existing file (2) ... " 16 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /create1 O_RDWR,O_CREAT,O_EXCL LordOfCinder >/dev/null 2>&1 && failure 17 | success 18 | 19 | chmod 631 ${TESTDIR}/create1 >/dev/null 2>&1 20 | echo -n "test open(O_RDWR|O_CREAT) on an existing file (3) ... " 21 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /create1 O_RDWR,O_CREAT LordOfCinder >/dev/null || failure 22 | success 23 | 24 | echo -n "verify it did not affect the mode bits (4) ... " 25 | stat ${TESTDIR}/create1 | grep "0631/-rw--wx--x" >/dev/null || failure 26 | success 27 | 28 | echo -n "Verify the file content (5) ... " 29 | grep LordOfCinder "${TESTDIR}/create1" >/dev/null || failure 30 | success 31 | 32 | echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" > ${TESTDIR}/create1 33 | echo -n "test open(O_RDWR) on an existing file overwriting the start (6) ... " 34 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /create1 O_RDWR LordOfCinder >/dev/null || failure 35 | success 36 | 37 | echo -n "Verify the file content (7) ... " 38 | grep LordOfCinderxxxxxxxxxxx "${TESTDIR}/create1" >/dev/null || failure 39 | success 40 | 41 | echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" > ${TESTDIR}/create1 42 | echo -n "test open(O_RDWR,O_TRUNC) on an existing file (8) ... " 43 | ./prog_open_write "${TESTURL}/?version=${VERS}" "." /create1 O_WRONLY,O_TRUNC LordOfCinder >/dev/null || failure 44 | success 45 | 46 | echo -n "verify it got truncated (9) ... " 47 | stat ${TESTDIR}/create1 | grep "Size: 12" >/dev/null || failure 48 | success 49 | 50 | stop_share 51 | 52 | exit 0 53 | -------------------------------------------------------------------------------- /tests/prog_mount.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "libnfs.h" 32 | 33 | void usage(void) 34 | { 35 | fprintf(stderr, "Usage: prog_mount \n"); 36 | exit(1); 37 | } 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | struct nfs_context *nfs = NULL; 42 | struct nfs_url *url = NULL; 43 | int ret = 0; 44 | 45 | if (argc != 2) { 46 | usage(); 47 | } 48 | 49 | nfs = nfs_init_context(); 50 | if (nfs == NULL) { 51 | printf("failed to init context\n"); 52 | exit(1); 53 | } 54 | 55 | url = nfs_parse_url_full(nfs, argv[1]); 56 | if (url == NULL) { 57 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 58 | exit(1); 59 | } 60 | 61 | if (nfs_mount(nfs, url->server, url->path) != 0) { 62 | fprintf(stderr, "Failed to mount nfs share : %s\n", 63 | nfs_get_error(nfs)); 64 | ret = 1; 65 | goto finished; 66 | } 67 | 68 | finished: 69 | nfs_destroy_url(url); 70 | nfs_destroy_context(nfs); 71 | 72 | return ret; 73 | } 74 | -------------------------------------------------------------------------------- /tests/test_0240_link.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic link test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | echo "kangabanga" > "${TESTDIR}/testfile" 12 | 13 | echo -n "Link a root path (abs -> abs) (1) ... " 14 | ./prog_link "${TESTURL}/?version=${VERS}" "." /testfile /link1 || failure 15 | success 16 | 17 | echo -n "Link a root path (abs -> rel) (2) ... " 18 | ./prog_link "${TESTURL}/?version=${VERS}" "." /testfile link2 || failure 19 | success 20 | 21 | echo -n "Link a root path (rel -> abs) (3) ... " 22 | ./prog_link "${TESTURL}/?version=${VERS}" "." testfile /link3 || failure 23 | success 24 | 25 | echo -n "Link a root path (rel -> rel) (4) ... " 26 | ./prog_link "${TESTURL}/?version=${VERS}" "." testfile link4 || failure 27 | success 28 | 29 | echo -n "Link a subdir path (abs -> abs) (5) ... " 30 | ./prog_link "${TESTURL}/?version=${VERS}" "." /testfile /subdir/link5 || failure 31 | success 32 | 33 | echo -n "Link a subdir path (abs -> rel) (6) ... " 34 | ./prog_link "${TESTURL}/?version=${VERS}" "." /subdir/link5 subdir2/link6 || failure 35 | success 36 | 37 | echo -n "Link a subdir path (rel -> abs) (7) ... " 38 | ./prog_link "${TESTURL}/?version=${VERS}" "." subdir/link5 /subdir2/link7 || failure 39 | success 40 | 41 | echo -n "Link a subdir path (rel -> rel) (8) ... " 42 | ./prog_link "${TESTURL}/?version=${VERS}" "." subdir2/link7 subdir/link8 || failure 43 | success 44 | 45 | echo -n "Link from a different cwd (rel -> rel) (9) ... " 46 | ./prog_link "${TESTURL}/?version=${VERS}" "subdir2" link7 ../subdir/link9 || failure 47 | success 48 | 49 | echo -n "Link from outside the share (rel -> rel) (10) ... " 50 | ./prog_link "${TESTURL}/?version=${VERS}" "subdir2" ../../link7 ../subdir/link10 2>/dev/null && failure 51 | success 52 | 53 | echo -n "Link to outside the share (rel -> rel) (11) ... " 54 | ./prog_link "${TESTURL}/?version=${VERS}" "subdir2" link7 ../../subdir/link11 2>/dev/null && failure 55 | success 56 | 57 | 58 | stop_share 59 | 60 | exit 0 61 | 62 | -------------------------------------------------------------------------------- /doc/nfs-cp.1: -------------------------------------------------------------------------------- 1 | '\" t 2 | .\" Title: nfs-cp 3 | .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] 4 | .\" Generator: DocBook XSL Stylesheets v1.78.1 5 | .\" Date: 05/24/2015 6 | .\" Manual: nfs-cp: copy files to/from an NFS share 7 | .\" Source: nfs-cp 8 | .\" Language: English 9 | .\" 10 | .TH "NFS\-CP" "1" "05/24/2015" "nfs\-cp" "nfs\-cp: copy files to/from an" 11 | .\" ----------------------------------------------------------------- 12 | .\" * Define some portability stuff 13 | .\" ----------------------------------------------------------------- 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | .\" http://bugs.debian.org/507673 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | .ie \n(.g .ds Aq \(aq 19 | .el .ds Aq ' 20 | .\" ----------------------------------------------------------------- 21 | .\" * set default formatting 22 | .\" ----------------------------------------------------------------- 23 | .\" disable hyphenation 24 | .nh 25 | .\" disable justification (adjust text to left margin only) 26 | .ad l 27 | .\" ----------------------------------------------------------------- 28 | .\" * MAIN CONTENT STARTS HERE * 29 | .\" ----------------------------------------------------------------- 30 | .SH "NAME" 31 | nfs-cp \- Utility to copy files to/from and NFS server 32 | .SH "SYNOPSIS" 33 | .HP \w'\fBnfs\-cp\ \ \fR\ 'u 34 | \fBnfs\-cp \fR 35 | .SH "DESCRIPTION" 36 | .PP 37 | nfs\-cp is a utility to copy files to/from and NFS server\&. 38 | .PP 39 | Examples: 40 | .sp 41 | .if n \{\ 42 | .RS 4 43 | .\} 44 | .nf 45 | $ nfs\-cp foo\&.c nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c 46 | 47 | $ nfs\-cp nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c bob\&.c 48 | 49 | $ nfs\-cp nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c nfs://127\&.0\&.0\&.1/data/tmp/copy\-of\-foo\&.c 50 | 51 | .fi 52 | .if n \{\ 53 | .RE 54 | .\} 55 | .sp 56 | .SH "SEE ALSO" 57 | .PP 58 | \m[blue]\fB\%http://github.com/sahlberg/libnfs\fR\m[] 59 | -------------------------------------------------------------------------------- /servers/libnfs-server.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright 2025 Ronnie Sahlberg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the “Software”), 7 | to deal in the Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, publish, distribute, 9 | sublicense, and/or sell copies of the Software, and to permit persons 10 | to whom the Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | #ifndef _LIBNFS_SERVER_H_ 25 | #define _LIBNFS_SERVER_H_ 26 | 27 | #include 28 | #include 29 | 30 | struct libnfs_server_procs { 31 | uint32_t program; 32 | uint32_t version; 33 | struct service_proc *procs; 34 | int num_procs; 35 | }; 36 | 37 | struct libnfs_servers; 38 | 39 | #define TRANSPORT_TCP 1 40 | #define TRANSPORT_UDP 2 41 | #define TRANSPORT_TCP6 3 42 | #define TRANSPORT_UDP6 4 43 | 44 | struct libnfs_servers *libnfs_create_server(TALLOC_CTX *ctx, 45 | struct tevent_context *tevent, 46 | int port, char *name, 47 | int transports, 48 | struct libnfs_server_procs *server_procs); 49 | 50 | 51 | #endif /* _LIBNFS_SERVER_H_ */ 52 | 53 | -------------------------------------------------------------------------------- /servers/nfsd/mountd.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright 2025 Ronnie Sahlberg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the “Software”), 7 | to deal in the Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, publish, distribute, 9 | sublicense, and/or sell copies of the Software, and to permit persons 10 | to whom the Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef _MOUNT_H_ 26 | #define _MOUNT_H_ 27 | 28 | #include "libnfs.h" 29 | #include "libnfs-raw.h" 30 | #include "libnfs-raw-mount.h" 31 | #include "libnfs-raw-nfs.h" 32 | 33 | struct mountd_export { 34 | struct mountd_export *next; 35 | char *path; 36 | struct nfs_fh3 fh; 37 | }; 38 | 39 | struct mountd_client { 40 | struct mountd_client *next; 41 | char *client; 42 | char *path; 43 | }; 44 | 45 | struct mountd_state { 46 | struct tevent_context *tevent; 47 | struct mountd_export *exports; 48 | struct mountd_client *clients; 49 | pthread_mutex_t clients_mutex; 50 | }; 51 | 52 | struct mountd_state *mountd_init(TALLOC_CTX *ctx, struct tevent_context *tevent); 53 | struct mountd_export *mountd_add_export(struct mountd_state *mountd, char *path, int fh_len, char *fh); 54 | 55 | #endif /* _MOUNT_H_ */ 56 | -------------------------------------------------------------------------------- /tests/test_0310_mknod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # NFS servers generally want us to be root in order to create device nodes. 4 | # We can lie and impersonate root by setting uid=0 in the URL. 5 | 6 | . ./functions.sh 7 | 8 | echo "NFSv${VERS} Basic mknod test." 9 | 10 | start_share 11 | 12 | mkdir "${TESTDIR}/subdir" 13 | mkdir "${TESTDIR}/subdir2" 14 | 15 | echo -n "Create a chrdev in the root (abs) (1)... " 16 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "." /mknod1 020755 0x1234 || failure 17 | success 18 | 19 | echo -n "Stat the node ... " 20 | ./prog_stat "${TESTURL}/?version=${VERS}" "." mknod1 > "${TESTDIR}/output" || failure 21 | success 22 | 23 | echo -n "Testing nfs_mode and verify it is a CHRDEV ... " 24 | grep "nfs_mode:20755" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "Create a chrdev in the root (rel) (2)... " 28 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "." mknod2 020775 0x1234 || failure 29 | success 30 | 31 | echo -n "Create a chrdev in a subdirectory (abs) (3)... " 32 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "." /subdir/mknod3 020775 0x1234 || failure 33 | success 34 | 35 | echo -n "Create a chrdev in a subdirectory (abs) (4)... " 36 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "." subdir/mknod4 020775 0x1234 || failure 37 | success 38 | 39 | echo -n "Create a chrdev from a different cwd (abs) (5)... " 40 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "subdir" ../subdir2/mknod5 020775 0x1234 || failure 41 | success 42 | 43 | echo -n "Create a chrdev outside the share (abs) (6)... " 44 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "." ../subdir2/mknod6 020775 0x1234 2>/dev/null && failure 45 | success 46 | 47 | echo -n "Create a blkdev in the root (abs) (7)... " 48 | ./prog_mknod "${TESTURL}/?uid=0&version=${VERS}" "." /mknod7 060755 0x1234 || failure 49 | success 50 | 51 | echo -n "Stat the node ... " 52 | ./prog_stat "${TESTURL}/?version=${VERS}" "." mknod7 > "${TESTDIR}/output" || failure 53 | success 54 | 55 | echo -n "Testing nfs_mode and verify it is a BLKDEV ... " 56 | grep "nfs_mode:60755" "${TESTDIR}/output" >/dev/null || failure 57 | success 58 | 59 | stop_share 60 | 61 | exit 0 62 | -------------------------------------------------------------------------------- /tests/test_0220_open_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic open path tests." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "Open a file in root (abs) (1) ... " 13 | echo -n "kangabanga" > "${TESTDIR}/open1" 14 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." /open1 O_RDONLY >/dev/null || failure 15 | success 16 | 17 | echo -n "Open a file in root (rel) (2) ... " 18 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." open1 O_RDONLY >/dev/null || failure 19 | success 20 | 21 | echo -n "Open a file in a subdir (abs) (3) ... " 22 | echo -n "kangabanga" > "${TESTDIR}/subdir/open3" 23 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." /subdir/open3 O_RDONLY >/dev/null || failure 24 | success 25 | 26 | echo -n "Open a file in root (rel) (4) ... " 27 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." subdir/open3 O_RDONLY >/dev/null || failure 28 | success 29 | 30 | echo -n "Open a file from a different cwd (rel) (5) ... " 31 | ./prog_open_read "${TESTURL}/?version=${VERS}" "subdir2" ../subdir/open3 O_RDONLY >/dev/null || failure 32 | success 33 | 34 | echo -n "Open a file outside the share (rel) (5) ... " 35 | ./prog_open_read "${TESTURL}/?version=${VERS}" "subdir2" ../../subdir/open3 O_RDONLY >/dev/null 2>&1 && failure 36 | success 37 | 38 | echo -n "Create a directory symlink (rel) (6) ... " 39 | ./prog_symlink "${TESTURL}/?version=${VERS}" "." subdir /subdir4 || failure 40 | success 41 | 42 | echo -n "Open a file in a symlinked subdir (rel) (7) ... " 43 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." subdir4/open3 O_RDONLY >/dev/null || failure 44 | success 45 | 46 | echo -n "Create a file symlink (rel) (8) ... " 47 | ./prog_symlink "${TESTURL}/?version=${VERS}" "." open3 /subdir4/open8 || failure 48 | success 49 | 50 | echo -n "Open a symlinked file (rel) (9) ... " 51 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." subdir4/open8 O_RDONLY >/dev/null || failure 52 | success 53 | 54 | echo -n "Open a symlinked file with O_NOFOLLOW (rel) (10) ... " 55 | ./prog_open_read "${TESTURL}/?version=${VERS}" "." subdir/open8 O_RDONLY,O_NOFOLLOW 2>/dev/null && failure 56 | success 57 | 58 | 59 | stop_share 60 | 61 | exit 0 62 | -------------------------------------------------------------------------------- /ps3_ppu/ps3_compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 by Ronnie Sahlberg 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation; either version 2.1 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "ps3_compat.h" 27 | 28 | int nfs_getnameinfo(const struct sockaddr *sa, socklen_t salen, 29 | char *host, size_t hostlen, 30 | char *serv, size_t servlen, int flags) 31 | { 32 | struct sockaddr_in *sin = (struct sockaddr_in *)sa; 33 | 34 | if (host) { 35 | snprintf(host, hostlen, inet_ntoa(sin->sin_addr)); 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | int nfs_getaddrinfo(const char *node, const char*service, 42 | const struct addrinfo *hints, 43 | struct addrinfo **res) 44 | { 45 | struct sockaddr_in *sin; 46 | 47 | sin = malloc(sizeof(struct sockaddr_in)); 48 | sin->sin_len = sizeof(struct sockaddr_in); 49 | sin->sin_family=AF_INET; 50 | 51 | /* Some error checking would be nice */ 52 | sin->sin_addr.s_addr = inet_addr(node); 53 | 54 | sin->sin_port=0; 55 | if (service) { 56 | sin->sin_port=htons(atoi(service)); 57 | } 58 | 59 | *res = malloc(sizeof(struct addrinfo)); 60 | memset(*res, 0, sizeof(struct addrinfo)); 61 | 62 | (*res)->ai_family = AF_INET; 63 | (*res)->ai_addrlen = sizeof(struct sockaddr_in); 64 | (*res)->ai_addr = (struct sockaddr *)sin; 65 | 66 | return 0; 67 | } 68 | 69 | void nfs_freeaddrinfo(struct addrinfo *res) 70 | { 71 | free(res->ai_addr); 72 | free(res); 73 | } 74 | -------------------------------------------------------------------------------- /ps2_ee/ps2_compat.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2021 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #ifdef PS2_EE 20 | 21 | #define NEED_READV 22 | #define NEED_WRITEV 23 | #define NEED_POLL 24 | #define NEED_BE64TOH 25 | 26 | #include 27 | #include 28 | #include 29 | #include "ps2_compat.h" 30 | 31 | int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, 32 | char *host, socklen_t hostlen, 33 | char *serv, socklen_t servlen, int flags) 34 | { 35 | /* not implemented yet */ 36 | return -1; 37 | } 38 | 39 | int nfs_getaddrinfo(const char *node, const char*service, 40 | const struct addrinfo *hints, 41 | struct addrinfo **res) 42 | { 43 | struct sockaddr_in *sin; 44 | 45 | sin = malloc(sizeof(struct sockaddr_in)); 46 | sin->sin_len = sizeof(struct sockaddr_in); 47 | sin->sin_family=AF_INET; 48 | 49 | /* Some error checking would be nice */ 50 | sin->sin_addr.s_addr = inet_addr(node); 51 | 52 | sin->sin_port=0; 53 | if (service) { 54 | sin->sin_port=htons(atoi(service)); 55 | } 56 | 57 | *res = malloc(sizeof(struct addrinfo)); 58 | memset(*res, 0, sizeof(struct addrinfo)); 59 | 60 | (*res)->ai_family = AF_INET; 61 | (*res)->ai_addrlen = sizeof(struct sockaddr_in); 62 | (*res)->ai_addr = (struct sockaddr *)sin; 63 | 64 | return 0; 65 | } 66 | 67 | void nfs_freeaddrinfo(struct addrinfo *res) 68 | { 69 | free(res->ai_addr); 70 | free(res); 71 | } 72 | 73 | #endif /* PS2_EE */ 74 | -------------------------------------------------------------------------------- /win32/version.rc.template: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0 4 | #define VER_FILEVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0\0" 5 | 6 | #define VER_PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0 7 | #define VER_PRODUCTVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0\0" 8 | 9 | #define VER_PRIVATEBUILD 0 10 | #define VER_PRERELEASE 0 11 | 12 | #ifndef DEBUG 13 | #define VER_DEBUG 0 14 | #else 15 | #define VER_DEBUG VS_FF_DEBUG 16 | #endif 17 | 18 | VS_VERSION_INFO VERSIONINFO 19 | FILEVERSION VER_FILEVERSION 20 | PRODUCTVERSION VER_PRODUCTVERSION 21 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 22 | FILEFLAGS (VER_PRIVATEBUILD|VER_PRERELEASE|VER_DEBUG) 23 | FILEOS VOS__WINDOWS32 24 | FILETYPE VFT_DLL 25 | FILESUBTYPE VFT2_UNKNOWN 26 | BEGIN 27 | BLOCK "StringFileInfo" 28 | BEGIN 29 | BLOCK "040904E4" 30 | BEGIN 31 | VALUE "CompanyName", "https://github.com/sahlberg/libnfs" 32 | VALUE "FileDescription", "LIBNFS is a client library for accessing NFS shares over a network." 33 | VALUE "FileVersion", VER_FILEVERSION_STR 34 | VALUE "InternalName", "libnfs.dll" 35 | VALUE "LegalCopyright", "Copyright (C) 2019" 36 | VALUE "OriginalFilename", "libnfs.dll" 37 | VALUE "ProductName", "libnfs" 38 | VALUE "ProductVersion", VER_PRODUCTVERSION_STR 39 | END 40 | END 41 | 42 | BLOCK "VarFileInfo" 43 | BEGIN 44 | /* The following line should only be modified for localized versions. */ 45 | /* It consists of any number of WORD,WORD pairs, with each pair */ 46 | /* describing a language,codepage combination supported by the file. */ 47 | /* */ 48 | /* For example, a file might have values "0x409,1252" indicating that it */ 49 | /* supports English language (0x409) in the Windows ANSI codepage (1252). */ 50 | 51 | VALUE "Translation", 0x409, 1252 52 | 53 | END 54 | END -------------------------------------------------------------------------------- /aros/aros_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 by Ronnie Sahlberg 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation; either version 2.1 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, see . 16 | */ 17 | 18 | #ifndef AROS_COMPAT_H 19 | #define AROS_COMPAT_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define statvfs statfs 33 | #define ioctl IoctlSocket 34 | #define close CloseSocket 35 | 36 | #define inet_pton aros_inet_pton 37 | #define freeaddrinfo aros_freeaddrinfo 38 | #define getnameinfo aros_getnameinfo 39 | #define getaddrinfo aros_getaddrinfo 40 | 41 | extern struct Library * SocketBase; 42 | 43 | void aros_init_socket(void); 44 | 45 | #define f_flag f_flags 46 | #define f_favail f_ffree 47 | /* we dont have these at all */ 48 | #define f_fsid f_spare[0] 49 | #define f_frsize f_spare[0] 50 | #define f_namemax f_spare[0] 51 | 52 | #define POLLIN 0x0001 /* There is data to read */ 53 | #define POLLPRI 0x0002 /* There is urgent data to read */ 54 | #define POLLOUT 0x0004 /* Writing now will not block */ 55 | #define POLLERR 0x0008 /* Error condition */ 56 | #define POLLHUP 0x0010 /* Hung up */ 57 | #define POLLNVAL 0x0020 /* Invalid request: fd not open */ 58 | 59 | struct utimbuf { 60 | int actime; 61 | int modtime; 62 | }; 63 | 64 | struct pollfd { 65 | int fd; /* file descriptor */ 66 | short events; /* requested events */ 67 | short revents; /* returned events */ 68 | }; 69 | 70 | #define poll(x, y, z) aros_poll(x, y, z) 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /include/libnfs-multithreading.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2021 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #ifndef _LIBNFS_MULTITHREADING_H_ 20 | #define _LIBNFS_MULTITHREADING_H_ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #ifdef HAVE_MULTITHREADING 31 | 32 | #ifdef WIN32 33 | typedef HANDLE libnfs_thread_t; 34 | typedef HANDLE libnfs_mutex_t; 35 | typedef HANDLE libnfs_sem_t; 36 | typedef DWORD nfs_tid_t; 37 | #elif defined(HAVE_PTHREAD) 38 | #include 39 | typedef pthread_t libnfs_thread_t; 40 | typedef pthread_mutex_t libnfs_mutex_t; 41 | 42 | #if defined(__APPLE__) && defined(HAVE_DISPATCH_DISPATCH_H) 43 | #include 44 | typedef dispatch_semaphore_t libnfs_sem_t; 45 | #else 46 | #include 47 | typedef sem_t libnfs_sem_t; 48 | #endif 49 | #ifdef HAVE_PTHREAD_THREADID_NP 50 | typedef uint64_t nfs_tid_t; 51 | #else 52 | typedef pid_t nfs_tid_t; 53 | #endif 54 | #endif /* HAVE_PTHREAD */ 55 | 56 | nfs_tid_t nfs_mt_get_tid(void); 57 | int nfs_mt_mutex_init(libnfs_mutex_t *mutex); 58 | int nfs_mt_mutex_destroy(libnfs_mutex_t *mutex); 59 | int nfs_mt_mutex_lock(libnfs_mutex_t *mutex); 60 | int nfs_mt_mutex_unlock(libnfs_mutex_t *mutex); 61 | 62 | int nfs_mt_sem_init(libnfs_sem_t *sem, int value); 63 | int nfs_mt_sem_destroy(libnfs_sem_t *sem); 64 | int nfs_mt_sem_post(libnfs_sem_t *sem); 65 | int nfs_mt_sem_wait(libnfs_sem_t *sem); 66 | 67 | #endif /* HAVE_MULTITHREADING */ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* !_LIBNFS_MULTITHREADING_H_ */ 74 | -------------------------------------------------------------------------------- /tests/prog_mkdir.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_mkdir \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | 46 | if (argc != 4) { 47 | usage(); 48 | } 49 | 50 | nfs = nfs_init_context(); 51 | if (nfs == NULL) { 52 | printf("failed to init context\n"); 53 | exit(1); 54 | } 55 | 56 | url = nfs_parse_url_full(nfs, argv[1]); 57 | if (url == NULL) { 58 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 59 | exit(1); 60 | } 61 | 62 | if (nfs_mount(nfs, url->server, url->path) != 0) { 63 | fprintf(stderr, "Failed to mount nfs share : %s\n", 64 | nfs_get_error(nfs)); 65 | ret = 1; 66 | goto finished; 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | ret = 1; 73 | goto finished; 74 | } 75 | 76 | if (nfs_mkdir(nfs, argv[3])) { 77 | fprintf(stderr, "Failed to mkdir: %s\n", 78 | nfs_get_error(nfs)); 79 | ret = 1; 80 | goto finished; 81 | } 82 | 83 | finished: 84 | nfs_destroy_url(url); 85 | nfs_destroy_context(nfs); 86 | 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /tests/prog_rmdir.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_rmdir \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | 46 | if (argc != 4) { 47 | usage(); 48 | } 49 | 50 | nfs = nfs_init_context(); 51 | if (nfs == NULL) { 52 | printf("failed to init context\n"); 53 | exit(1); 54 | } 55 | 56 | url = nfs_parse_url_full(nfs, argv[1]); 57 | if (url == NULL) { 58 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 59 | exit(1); 60 | } 61 | 62 | if (nfs_mount(nfs, url->server, url->path) != 0) { 63 | fprintf(stderr, "Failed to mount nfs share : %s\n", 64 | nfs_get_error(nfs)); 65 | ret = 1; 66 | goto finished; 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | ret = 1; 73 | goto finished; 74 | } 75 | 76 | if (nfs_rmdir(nfs, argv[3])) { 77 | fprintf(stderr, "Failed to rmdir: %s\n", 78 | nfs_get_error(nfs)); 79 | ret = 1; 80 | goto finished; 81 | } 82 | 83 | finished: 84 | nfs_destroy_url(url); 85 | nfs_destroy_context(nfs); 86 | 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /tests/prog_unlink.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_unlink \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | 46 | if (argc != 4) { 47 | usage(); 48 | } 49 | 50 | nfs = nfs_init_context(); 51 | if (nfs == NULL) { 52 | printf("failed to init context\n"); 53 | exit(1); 54 | } 55 | 56 | url = nfs_parse_url_full(nfs, argv[1]); 57 | if (url == NULL) { 58 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 59 | exit(1); 60 | } 61 | 62 | if (nfs_mount(nfs, url->server, url->path) != 0) { 63 | fprintf(stderr, "Failed to mount nfs share : %s\n", 64 | nfs_get_error(nfs)); 65 | ret = 1; 66 | goto finished; 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | ret = 1; 73 | goto finished; 74 | } 75 | 76 | if (nfs_unlink(nfs, argv[3])) { 77 | fprintf(stderr, "Failed to unlink: %s\n", 78 | nfs_get_error(nfs)); 79 | ret = 1; 80 | goto finished; 81 | } 82 | 83 | finished: 84 | nfs_destroy_url(url); 85 | nfs_destroy_context(nfs); 86 | 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /tests/prog_link.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_link \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | 46 | if (argc != 5) { 47 | usage(); 48 | } 49 | 50 | nfs = nfs_init_context(); 51 | if (nfs == NULL) { 52 | printf("failed to init context\n"); 53 | exit(1); 54 | } 55 | 56 | url = nfs_parse_url_full(nfs, argv[1]); 57 | if (url == NULL) { 58 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 59 | exit(1); 60 | } 61 | 62 | if (nfs_mount(nfs, url->server, url->path) != 0) { 63 | fprintf(stderr, "Failed to mount nfs share : %s\n", 64 | nfs_get_error(nfs)); 65 | ret = 1; 66 | goto finished; 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | ret = 1; 73 | goto finished; 74 | } 75 | 76 | if (nfs_link(nfs, argv[3], argv[4])) { 77 | fprintf(stderr, "Failed to link: %s\n", 78 | nfs_get_error(nfs)); 79 | ret = 1; 80 | goto finished; 81 | } 82 | 83 | finished: 84 | nfs_destroy_url(url); 85 | nfs_destroy_context(nfs); 86 | 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /tests/prog_rename.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_rename \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | 46 | if (argc != 5) { 47 | usage(); 48 | } 49 | 50 | nfs = nfs_init_context(); 51 | if (nfs == NULL) { 52 | printf("failed to init context\n"); 53 | exit(1); 54 | } 55 | 56 | url = nfs_parse_url_full(nfs, argv[1]); 57 | if (url == NULL) { 58 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 59 | exit(1); 60 | } 61 | 62 | if (nfs_mount(nfs, url->server, url->path) != 0) { 63 | fprintf(stderr, "Failed to mount nfs share : %s\n", 64 | nfs_get_error(nfs)); 65 | ret = 1; 66 | goto finished; 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | ret = 1; 73 | goto finished; 74 | } 75 | 76 | if (nfs_rename(nfs, argv[3], argv[4])) { 77 | fprintf(stderr, "Failed to rename: %s\n", 78 | nfs_get_error(nfs)); 79 | ret = 1; 80 | goto finished; 81 | } 82 | 83 | finished: 84 | nfs_destroy_url(url); 85 | nfs_destroy_context(nfs); 86 | 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /tests/test_0400_chown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic chown tests." 6 | 7 | start_share 8 | 9 | dd if=/dev/zero of=${TESTDIR}/testfile count=1 bs=32768 2>/dev/null 10 | 11 | echo -n "test chown(1000, 2000) ... " 12 | ./prog_chown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 1000 2000 || failure 13 | success 14 | 15 | echo -n "Stat the file ... " 16 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 17 | success 18 | 19 | echo -n "Verifying the uid is 1000 ... " 20 | grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure 21 | success 22 | 23 | echo -n "Verifying the gid is 2000 ... " 24 | grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure 25 | success 26 | 27 | echo -n "test chown(2000, 3000) ... " 28 | ./prog_chown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 2000 3000 || failure 29 | success 30 | 31 | echo -n "Stat the file ... " 32 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure 33 | success 34 | 35 | echo -n "Verifying the uid is 2000 ... " 36 | grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure 37 | success 38 | 39 | echo -n "Verifying the gid is 3000 ... " 40 | grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure 41 | success 42 | 43 | mkdir ${TESTDIR}/testdir 44 | 45 | echo -n "test chown(1000, 2000) on dir ... " 46 | ./prog_chown "${TESTURL}/?uid=0&version=${VERS}" "." /testdir 1000 2000 || failure 47 | success 48 | 49 | echo -n "Stat the dir ... " 50 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testdir > "${TESTDIR}/output" || failure 51 | success 52 | 53 | echo -n "Verifying the uid is 1000 on dir ... " 54 | grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure 55 | success 56 | 57 | echo -n "Verifying the gid is 2000 on dir ... " 58 | grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure 59 | success 60 | 61 | echo -n "test chown(2000, 3000) on dir ... " 62 | ./prog_chown "${TESTURL}/?uid=0&version=${VERS}" "." /testdir 2000 3000 || failure 63 | success 64 | 65 | echo -n "Stat the dir ... " 66 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testdir > "${TESTDIR}/output" || failure 67 | success 68 | 69 | echo -n "Verifying the uid is 2000 on dir ... " 70 | grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure 71 | success 72 | 73 | echo -n "Verifying the gid is 3000 on dir ... " 74 | grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure 75 | success 76 | 77 | stop_share 78 | 79 | exit 0 80 | -------------------------------------------------------------------------------- /tests/test_9900_valgrind_leak_check_full.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo -n "Create 100 1M files ... " 14 | for IDX in `seq 1 100`; do 15 | dd if=/dev/zero of="${TESTDIR}/file.$IDX" bs=1M count=10 2>/dev/null || failure 16 | done 17 | success 18 | 19 | echo -n "Testing share enumeration for memory leaks ... " 20 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../utils/nfs-ls -D nfs://127.0.0.1 > "${TESTDIR}/output?version=${VERS}" 2>/dev/null || failure 21 | success 22 | 23 | echo -n "test nfs-ls for memory leaks ... " 24 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../utils/nfs-ls "${TESTURL}?version=${VERS}" >/dev/null 2>&1 || failure 25 | success 26 | 27 | echo -n "test nfs-cp for memory leaks ... " 28 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../utils/nfs-cp "${TESTURL}/file.99?version=${VERS}" "${TESTURL}/copy-of-file.99" >/dev/null 2>&1 || failure 29 | success 30 | 31 | echo -n "test nfs_truncate() for memory leaks ... " 32 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../examples/nfs-io trunc "${TESTURL}/copy-of-file.99?version=${VERS}" >/dev/null 2>&1 || failure 33 | success 34 | 35 | echo -n "test nfs_unlink() for memory leaks ... " 36 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../examples/nfs-io unlink "${TESTURL}/copy-of-file.99?version=${VERS}" >/dev/null 2>&1 || failure 37 | success 38 | 39 | echo -n "test nfs_mkdir() for memory leaks ... " 40 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../examples/nfs-io mkdir "${TESTURL}/testdir?version=${VERS}" >/dev/null 2>&1 || failure 41 | success 42 | 43 | echo -n "test nfs_rmdir() for memory leaks ... " 44 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ../examples/nfs-io rmdir "${TESTURL}/testdir?version=${VERS}" >/dev/null 2>&1 || failure 45 | success 46 | 47 | echo -n "test nfs_stat64() for memory leaks ... " 48 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_stat "${TESTURL}/?version=${VERS}" "." file.99 >/dev/null 2>&1 || failure 49 | success 50 | 51 | echo -n "test nfs_fstat64() for memory leaks ... " 52 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_fstat "${TESTURL}/?version=${VERS}" "." file.99 >/dev/null 2>&1 || failure 53 | success 54 | 55 | 56 | stop_share 57 | 58 | exit 0 59 | -------------------------------------------------------------------------------- /tests/test_0260_symlink_paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic symlink test." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "Create a symlink in root (abs) (1) ... " 13 | ./prog_symlink "${TESTURL}/?version=${VERS}" "." kangabanga /symlink1 || failure 14 | success 15 | 16 | echo -n "Verify the link ... " 17 | ls -l "${TESTDIR}/symlink1" | egrep "\-> kangabanga$" >/dev/null || failure 18 | success 19 | 20 | echo -n "Create a symlink in root (rel) (2) ... " 21 | ./prog_symlink "${TESTURL}/?version=${VERS}" "." kangabanga symlink2 || failure 22 | success 23 | 24 | echo -n "Verify the link ... " 25 | ls -l "${TESTDIR}/symlink2" | egrep "\-> kangabanga$" >/dev/null || failure 26 | success 27 | 28 | echo -n "Create a symlink from a subdir (abs) (3) ... " 29 | ./prog_symlink "${TESTURL}/?version=${VERS}" "." kangabanga /subdir/symlink3 || failure 30 | success 31 | 32 | echo -n "Verify the link ... " 33 | ls -l "${TESTDIR}/subdir/symlink3" | egrep "\-> kangabanga$" >/dev/null || failure 34 | success 35 | 36 | echo -n "Create a symlink from a subdir (rel) (4) ... " 37 | ./prog_symlink "${TESTURL}/?version=${VERS}" "." kangabanga subdir/symlink4 || failure 38 | success 39 | 40 | echo -n "Verify the link ... " 41 | ls -l "${TESTDIR}/subdir/symlink4" | egrep "\-> kangabanga$" >/dev/null || failure 42 | success 43 | 44 | echo -n "Create a symlink from a subdir (rel) (5) ... " 45 | ./prog_symlink "${TESTURL}/?version=${VERS}" "/subdir" kangabanga symlink5 || failure 46 | success 47 | 48 | echo -n "Verify the link ... " 49 | ls -l "${TESTDIR}/subdir/symlink5" | egrep "\-> kangabanga$" >/dev/null || failure 50 | success 51 | 52 | echo -n "Create a symlink in a parent directory (rel) (6) ... " 53 | ./prog_symlink "${TESTURL}/?version=${VERS}" "/subdir" kangabanga ../symlink6 || failure 54 | success 55 | 56 | echo -n "Verify the link ... " 57 | ls -l "${TESTDIR}/symlink6" | egrep "\-> kangabanga$" >/dev/null || failure 58 | success 59 | 60 | echo -n "Create a symlink from different cwd (rel) (7) ... " 61 | ./prog_symlink "${TESTURL}/?version=${VERS}" "/subdir" kangabanga ../subdir2/symlink7 || failure 62 | success 63 | 64 | echo -n "Verify the link ... " 65 | ls -l "${TESTDIR}/subdir2/symlink7" | egrep "\-> kangabanga$" >/dev/null || failure 66 | success 67 | 68 | echo -n "Create a symlink outside the share (rel) (8) ... " 69 | ./prog_symlink "${TESTURL}/?version=${VERS}" "/subdir" kangabanga ../../symlink8 2>/dev/null && failure 70 | success 71 | 72 | stop_share 73 | 74 | exit 0 75 | -------------------------------------------------------------------------------- /tests/prog_chmod.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_chmod " 37 | "\n"); 38 | exit(1); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct nfs_context *nfs = NULL; 44 | struct nfs_url *url = NULL; 45 | int ret = 0; 46 | int mode; 47 | 48 | if (argc != 5) { 49 | usage(); 50 | } 51 | 52 | mode = strtol(argv[4], NULL, 8); 53 | 54 | nfs = nfs_init_context(); 55 | if (nfs == NULL) { 56 | printf("failed to init context\n"); 57 | exit(1); 58 | } 59 | 60 | url = nfs_parse_url_full(nfs, argv[1]); 61 | if (url == NULL) { 62 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 63 | exit(1); 64 | } 65 | 66 | if (nfs_mount(nfs, url->server, url->path) != 0) { 67 | fprintf(stderr, "Failed to mount nfs share : %s\n", 68 | nfs_get_error(nfs)); 69 | ret = 1; 70 | goto finished; 71 | } 72 | 73 | if (nfs_chdir(nfs, argv[2]) != 0) { 74 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 75 | argv[2], nfs_get_error(nfs)); 76 | ret = 1; 77 | goto finished; 78 | } 79 | 80 | if (nfs_chmod(nfs, argv[3], mode)) { 81 | fprintf(stderr, "Failed to chmod(): %s\n", 82 | nfs_get_error(nfs)); 83 | ret = 1; 84 | goto finished; 85 | } 86 | 87 | finished: 88 | nfs_destroy_url(url); 89 | nfs_destroy_context(nfs); 90 | 91 | return ret; 92 | } 93 | -------------------------------------------------------------------------------- /tests/prog_lchmod.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_lchmod " 37 | "\n"); 38 | exit(1); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct nfs_context *nfs = NULL; 44 | struct nfs_url *url = NULL; 45 | int ret = 0; 46 | int mode; 47 | 48 | if (argc != 5) { 49 | usage(); 50 | } 51 | 52 | mode = strtol(argv[4], NULL, 8); 53 | 54 | nfs = nfs_init_context(); 55 | if (nfs == NULL) { 56 | printf("failed to init context\n"); 57 | exit(1); 58 | } 59 | 60 | url = nfs_parse_url_full(nfs, argv[1]); 61 | if (url == NULL) { 62 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 63 | exit(1); 64 | } 65 | 66 | if (nfs_mount(nfs, url->server, url->path) != 0) { 67 | fprintf(stderr, "Failed to mount nfs share : %s\n", 68 | nfs_get_error(nfs)); 69 | ret = 1; 70 | goto finished; 71 | } 72 | 73 | if (nfs_chdir(nfs, argv[2]) != 0) { 74 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 75 | argv[2], nfs_get_error(nfs)); 76 | ret = 1; 77 | goto finished; 78 | } 79 | 80 | if (nfs_lchmod(nfs, argv[3], mode)) { 81 | fprintf(stderr, "Failed to lchmod(): %s\n", 82 | nfs_get_error(nfs)); 83 | ret = 1; 84 | goto finished; 85 | } 86 | 87 | finished: 88 | nfs_destroy_url(url); 89 | nfs_destroy_context(nfs); 90 | 91 | return ret; 92 | } 93 | -------------------------------------------------------------------------------- /tests/ld_timeout.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2017 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _GNU_SOURCE 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #ifndef discard_const 37 | #define discard_const(ptr) ((void *)((intptr_t)(ptr))) 38 | #endif 39 | 40 | #define PRINTF(fmt, args...) \ 41 | do { \ 42 | fprintf(stderr,"ld_nfs: "); \ 43 | fprintf(stderr, (fmt), ##args); \ 44 | fprintf(stderr,"\n"); \ 45 | } while (0); 46 | 47 | int timeout_start = 0; 48 | 49 | int (*real_rpc_service)(struct rpc_context *rpc, int revents); 50 | 51 | int rpc_service(struct rpc_context *rpc, int revents) 52 | { 53 | static int call_idx = 0; 54 | 55 | call_idx++; 56 | if (call_idx >= timeout_start) { 57 | PRINTF("sleep for 1 seconds causing a timeout"); 58 | sleep(1); 59 | /* Strip off all the POLLINs so that we will not try 60 | * to process them in rpc_service and instead fall-through 61 | * to the rpc_timeout_scan() and handle the PDUs there 62 | * instead. 63 | */ 64 | revents &= ~POLLIN; 65 | } 66 | return real_rpc_service(rpc, revents); 67 | } 68 | 69 | 70 | static void __attribute__((constructor)) 71 | _init(void) 72 | { 73 | /* Start timing out calls at this index */ 74 | if (getenv("TIMEOUT_START") != NULL) { 75 | timeout_start = atoi(getenv("TIMEOUT_START")); 76 | } 77 | 78 | real_rpc_service = dlsym(RTLD_NEXT, "rpc_service"); 79 | } 80 | -------------------------------------------------------------------------------- /tests/prog_chown.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_chown " 37 | "\n"); 38 | exit(1); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct nfs_context *nfs = NULL; 44 | struct nfs_url *url = NULL; 45 | int ret = 0; 46 | int uid, gid; 47 | 48 | if (argc != 6) { 49 | usage(); 50 | } 51 | 52 | uid = strtol(argv[4], NULL, 10); 53 | gid = strtol(argv[5], NULL, 10); 54 | 55 | nfs = nfs_init_context(); 56 | if (nfs == NULL) { 57 | printf("failed to init context\n"); 58 | exit(1); 59 | } 60 | 61 | url = nfs_parse_url_full(nfs, argv[1]); 62 | if (url == NULL) { 63 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 64 | exit(1); 65 | } 66 | 67 | if (nfs_mount(nfs, url->server, url->path) != 0) { 68 | fprintf(stderr, "Failed to mount nfs share : %s\n", 69 | nfs_get_error(nfs)); 70 | ret = 1; 71 | goto finished; 72 | } 73 | 74 | if (nfs_chdir(nfs, argv[2]) != 0) { 75 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 76 | argv[2], nfs_get_error(nfs)); 77 | ret = 1; 78 | goto finished; 79 | } 80 | 81 | if (nfs_chown(nfs, argv[3], uid, gid)) { 82 | fprintf(stderr, "Failed to chown(): %s\n", 83 | nfs_get_error(nfs)); 84 | ret = 1; 85 | goto finished; 86 | } 87 | 88 | finished: 89 | nfs_destroy_url(url); 90 | nfs_destroy_context(nfs); 91 | 92 | return ret; 93 | } 94 | -------------------------------------------------------------------------------- /tests/prog_ftruncate.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "libnfs.h" 31 | 32 | void usage(void) 33 | { 34 | fprintf(stderr, "Usage: prog_ftruncate \n"); 35 | exit(1); 36 | } 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | struct nfs_context *nfs; 41 | struct nfsfh *nfsfh; 42 | struct nfs_url *url; 43 | uint64_t length; 44 | 45 | if (argc != 5) { 46 | usage(); 47 | } 48 | 49 | length = strtol(argv[4], NULL, 10); 50 | 51 | nfs = nfs_init_context(); 52 | if (nfs == NULL) { 53 | printf("failed to init context\n"); 54 | exit(1); 55 | } 56 | 57 | url = nfs_parse_url_full(nfs, argv[1]); 58 | if (url == NULL) { 59 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 60 | exit(1); 61 | } 62 | 63 | if (nfs_mount(nfs, url->server, url->path) != 0) { 64 | fprintf(stderr, "Failed to mount nfs share : %s\n", 65 | nfs_get_error(nfs)); 66 | exit(1); 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | exit(1); 73 | } 74 | 75 | if (nfs_open(nfs, argv[3], O_WRONLY, &nfsfh)) { 76 | fprintf(stderr, "Failed to open file : %s\n", 77 | nfs_get_error(nfs)); 78 | exit(1); 79 | } 80 | 81 | if (nfs_ftruncate(nfs, nfsfh, length)) { 82 | fprintf(stderr, "Failed to ftruncate file : %s\n", 83 | nfs_get_error(nfs)); 84 | exit(1); 85 | } 86 | 87 | nfs_destroy_url(url); 88 | nfs_close(nfs, nfsfh); 89 | nfs_destroy_context(nfs); 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /tests/prog_lchown.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_lchown " 37 | "\n"); 38 | exit(1); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct nfs_context *nfs = NULL; 44 | struct nfs_url *url = NULL; 45 | int ret = 0; 46 | int uid, gid; 47 | 48 | if (argc != 6) { 49 | usage(); 50 | } 51 | 52 | uid = strtol(argv[4], NULL, 10); 53 | gid = strtol(argv[5], NULL, 10); 54 | 55 | nfs = nfs_init_context(); 56 | if (nfs == NULL) { 57 | printf("failed to init context\n"); 58 | exit(1); 59 | } 60 | 61 | url = nfs_parse_url_full(nfs, argv[1]); 62 | if (url == NULL) { 63 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 64 | exit(1); 65 | } 66 | 67 | if (nfs_mount(nfs, url->server, url->path) != 0) { 68 | fprintf(stderr, "Failed to mount nfs share : %s\n", 69 | nfs_get_error(nfs)); 70 | ret = 1; 71 | goto finished; 72 | } 73 | 74 | if (nfs_chdir(nfs, argv[2]) != 0) { 75 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 76 | argv[2], nfs_get_error(nfs)); 77 | ret = 1; 78 | goto finished; 79 | } 80 | 81 | if (nfs_lchown(nfs, argv[3], uid, gid)) { 82 | fprintf(stderr, "Failed to lchown(): %s\n", 83 | nfs_get_error(nfs)); 84 | ret = 1; 85 | goto finished; 86 | } 87 | 88 | finished: 89 | nfs_destroy_url(url); 90 | nfs_destroy_context(nfs); 91 | 92 | return ret; 93 | } 94 | -------------------------------------------------------------------------------- /tests/prog_mknod.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_mknod " 37 | "\n"); 38 | exit(1); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct nfs_context *nfs = NULL; 44 | struct nfs_url *url = NULL; 45 | int ret = 0; 46 | int mode, dev; 47 | 48 | if (argc != 6) { 49 | usage(); 50 | } 51 | 52 | mode = strtol(argv[4], NULL, 8); 53 | dev = strtol(argv[5], NULL, 16); 54 | 55 | nfs = nfs_init_context(); 56 | if (nfs == NULL) { 57 | printf("failed to init context\n"); 58 | exit(1); 59 | } 60 | 61 | url = nfs_parse_url_full(nfs, argv[1]); 62 | if (url == NULL) { 63 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 64 | exit(1); 65 | } 66 | 67 | if (nfs_mount(nfs, url->server, url->path) != 0) { 68 | fprintf(stderr, "Failed to mount nfs share : %s\n", 69 | nfs_get_error(nfs)); 70 | ret = 1; 71 | goto finished; 72 | } 73 | 74 | if (nfs_chdir(nfs, argv[2]) != 0) { 75 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 76 | argv[2], nfs_get_error(nfs)); 77 | ret = 1; 78 | goto finished; 79 | } 80 | 81 | if (nfs_mknod(nfs, argv[3], mode, dev)) { 82 | fprintf(stderr, "Failed to unlink: %s\n", 83 | nfs_get_error(nfs)); 84 | ret = 1; 85 | goto finished; 86 | } 87 | 88 | finished: 89 | nfs_destroy_url(url); 90 | nfs_destroy_context(nfs); 91 | 92 | return ret; 93 | } 94 | -------------------------------------------------------------------------------- /lib/krb5-wrapper.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | #ifndef _KRB5_WRAPPER_H_ 3 | #define _KRB5_WRAPPER_H_ 4 | 5 | /* 6 | Copyright (C) 2024 by Ronnie Sahlberg 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 2.1 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this program; if not, see . 20 | */ 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #ifdef HAVE_LIBKRB5 26 | 27 | #ifndef _GNU_SOURCE 28 | #define _GNU_SOURCE 29 | #endif 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #if __APPLE__ 36 | #import 37 | #else 38 | #include 39 | 40 | static const gss_OID_desc gss_mech_spnego = { 41 | 6, "\x2b\x06\x01\x05\x05\x02" 42 | }; 43 | #endif 44 | 45 | static const gss_OID_desc spnego_mech_krb5 = { 46 | 9, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" 47 | }; 48 | 49 | struct private_auth_data { 50 | gss_ctx_id_t context; 51 | gss_cred_id_t cred; 52 | gss_name_t user_name; 53 | gss_name_t target_name; 54 | gss_const_OID mech_type; 55 | uint32_t req_flags; 56 | gss_buffer_desc output_token; 57 | char *g_server; 58 | int wanted_sec; 59 | }; 60 | 61 | void 62 | krb5_free_auth_data(struct private_auth_data *auth); 63 | 64 | struct private_auth_data * 65 | krb5_auth_init(struct rpc_context *rpc, 66 | const char *server, 67 | const char *user_name, 68 | int wanted_sec); 69 | 70 | void 71 | krb5_set_gss_error(struct rpc_context *rpc, char *func, 72 | uint32_t maj, uint32_t min); 73 | 74 | int 75 | krb5_auth_request(struct rpc_context *rpc, 76 | struct private_auth_data *auth_data, 77 | unsigned char *buf, int len); 78 | 79 | unsigned char * 80 | krb5_get_output_token_buffer(struct private_auth_data *auth_data); 81 | 82 | int 83 | krb5_get_output_token_length(struct private_auth_data *auth_data); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* HAVE_LIBKRB5 */ 90 | 91 | #endif /* _KRB5_WRAPPER_H_ */ 92 | -------------------------------------------------------------------------------- /tests/prog_utimes.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_utimes \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | int atime, mtime; 46 | struct timeval times[2]; 47 | 48 | if (argc != 6) { 49 | usage(); 50 | } 51 | 52 | atime = strtol(argv[4], NULL, 10); 53 | mtime = strtol(argv[5], NULL, 10); 54 | 55 | nfs = nfs_init_context(); 56 | if (nfs == NULL) { 57 | printf("failed to init context\n"); 58 | exit(1); 59 | } 60 | 61 | url = nfs_parse_url_full(nfs, argv[1]); 62 | if (url == NULL) { 63 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 64 | exit(1); 65 | } 66 | 67 | if (nfs_mount(nfs, url->server, url->path) != 0) { 68 | fprintf(stderr, "Failed to mount nfs share : %s\n", 69 | nfs_get_error(nfs)); 70 | ret = 1; 71 | goto finished; 72 | } 73 | 74 | if (nfs_chdir(nfs, argv[2]) != 0) { 75 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 76 | argv[2], nfs_get_error(nfs)); 77 | ret = 1; 78 | goto finished; 79 | } 80 | 81 | memset(×[0], 0, 2 * sizeof(struct timeval)); 82 | times[0].tv_sec = atime; 83 | times[1].tv_sec = mtime; 84 | 85 | if (nfs_utimes(nfs, argv[3], ×[0])) { 86 | fprintf(stderr, "Failed to access(): %s\n", 87 | nfs_get_error(nfs)); 88 | ret = 1; 89 | goto finished; 90 | } 91 | 92 | finished: 93 | nfs_destroy_url(url); 94 | nfs_destroy_context(nfs); 95 | 96 | return ret; 97 | } 98 | -------------------------------------------------------------------------------- /servers/rpcbind/rpcbind_data.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Please do not edit this file. 4 | * It was generated using rpcgen. 5 | */ 6 | 7 | #include "rpcbind_data.h" 8 | 9 | uint32_t 10 | zdr_mapping (ZDR *zdrs, mapping *objp) 11 | { 12 | 13 | 14 | 15 | if (zdrs->x_op == ZDR_ENCODE) { 16 | if (!zdr_pointer (zdrs, (char **)&objp->next, sizeof (mapping), (zdrproc_t) zdr_mapping)) 17 | return FALSE; 18 | int32_t *buf; 19 | buf = ZDR_INLINE (zdrs, 3 * BYTES_PER_ZDR_UNIT); 20 | if (buf == NULL) { 21 | if (!zdr_u_int (zdrs, &objp->port)) 22 | return FALSE; 23 | if (!zdr_u_int (zdrs, &objp->prog)) 24 | return FALSE; 25 | if (!zdr_u_int (zdrs, &objp->vers)) 26 | return FALSE; 27 | 28 | } else { 29 | IZDR_PUT_U_LONG(buf, objp->port); 30 | IZDR_PUT_U_LONG(buf, objp->prog); 31 | IZDR_PUT_U_LONG(buf, objp->vers); 32 | } 33 | if (!zdr_string (zdrs, &objp->netid, ~0)) 34 | return FALSE; 35 | if (!zdr_string (zdrs, &objp->addr, ~0)) 36 | return FALSE; 37 | if (!zdr_string (zdrs, &objp->owner, ~0)) 38 | return FALSE; 39 | return TRUE; 40 | } else if (zdrs->x_op == ZDR_DECODE) { 41 | if (!zdr_pointer (zdrs, (char **)&objp->next, sizeof (mapping), (zdrproc_t) zdr_mapping)) 42 | return FALSE; 43 | int32_t *buf; 44 | buf = ZDR_INLINE (zdrs, 3 * BYTES_PER_ZDR_UNIT); 45 | if (buf == NULL) { 46 | if (!zdr_u_int (zdrs, &objp->port)) 47 | return FALSE; 48 | if (!zdr_u_int (zdrs, &objp->prog)) 49 | return FALSE; 50 | if (!zdr_u_int (zdrs, &objp->vers)) 51 | return FALSE; 52 | 53 | } else { 54 | objp->port = IZDR_GET_U_LONG(buf); 55 | objp->prog = IZDR_GET_U_LONG(buf); 56 | objp->vers = IZDR_GET_U_LONG(buf); 57 | } 58 | if (!zdr_string (zdrs, &objp->netid, ~0)) 59 | return FALSE; 60 | if (!zdr_string (zdrs, &objp->addr, ~0)) 61 | return FALSE; 62 | if (!zdr_string (zdrs, &objp->owner, ~0)) 63 | return FALSE; 64 | return TRUE; 65 | } 66 | 67 | if (!zdr_pointer (zdrs, (char **)&objp->next, sizeof (mapping), (zdrproc_t) zdr_mapping)) 68 | return FALSE; 69 | if (!zdr_u_int (zdrs, &objp->port)) 70 | return FALSE; 71 | if (!zdr_u_int (zdrs, &objp->prog)) 72 | return FALSE; 73 | if (!zdr_u_int (zdrs, &objp->vers)) 74 | return FALSE; 75 | if (!zdr_string (zdrs, &objp->netid, ~0)) 76 | return FALSE; 77 | if (!zdr_string (zdrs, &objp->addr, ~0)) 78 | return FALSE; 79 | if (!zdr_string (zdrs, &objp->owner, ~0)) 80 | return FALSE; 81 | return TRUE; 82 | } 83 | 84 | uint32_t 85 | zdr_mapping_ptr (ZDR *zdrs, mapping_ptr *objp) 86 | { 87 | 88 | 89 | if (!zdr_pointer (zdrs, (char **)objp, sizeof (mapping), (zdrproc_t) zdr_mapping)) 90 | return FALSE; 91 | return TRUE; 92 | } 93 | -------------------------------------------------------------------------------- /tests/prog_truncate.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "libnfs.h" 31 | 32 | void usage(void) 33 | { 34 | fprintf(stderr, "Usage: prog_truncate \n"); 35 | exit(1); 36 | } 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | struct nfs_context *nfs; 41 | struct nfs_url *url; 42 | uint64_t length; 43 | struct nfs_stat_64 st; 44 | 45 | if (argc != 5) { 46 | usage(); 47 | } 48 | 49 | length = strtol(argv[4], NULL, 10); 50 | 51 | nfs = nfs_init_context(); 52 | if (nfs == NULL) { 53 | printf("failed to init context\n"); 54 | exit(1); 55 | } 56 | 57 | url = nfs_parse_url_full(nfs, argv[1]); 58 | if (url == NULL) { 59 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 60 | exit(1); 61 | } 62 | 63 | if (nfs_mount(nfs, url->server, url->path) != 0) { 64 | fprintf(stderr, "Failed to mount nfs share : %s\n", 65 | nfs_get_error(nfs)); 66 | exit(1); 67 | } 68 | 69 | if (nfs_chdir(nfs, argv[2]) != 0) { 70 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 71 | argv[2], nfs_get_error(nfs)); 72 | exit(1); 73 | } 74 | 75 | if (nfs_truncate(nfs, argv[3], length)) { 76 | fprintf(stderr, "Failed to truncate file : %s\n", 77 | nfs_get_error(nfs)); 78 | exit(1); 79 | } 80 | 81 | if (nfs_stat64(nfs, argv[3], &st)) { 82 | fprintf(stderr, "Failed to stat file : %s\n", 83 | nfs_get_error(nfs)); 84 | exit(1); 85 | } 86 | 87 | if (st.nfs_size != length) { 88 | fprintf(stderr, "Unexpected file size. Expected %d got %d\n", 89 | (int)length, (int)st.nfs_size); 90 | exit(1); 91 | } 92 | 93 | nfs_destroy_url(url); 94 | nfs_destroy_context(nfs); 95 | 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /tests/prog_timeout.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "libnfs.h" 32 | 33 | void usage(void) 34 | { 35 | fprintf(stderr, "Usage: prog_timeout \n"); 36 | exit(1); 37 | } 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | struct nfs_context *nfs = NULL; 42 | struct nfs_url *url = NULL; 43 | struct nfs_stat_64 st; 44 | 45 | if (argc != 2) { 46 | usage(); 47 | } 48 | 49 | nfs = nfs_init_context(); 50 | if (nfs == NULL) { 51 | printf("failed to init context\n"); 52 | exit(1); 53 | } 54 | 55 | nfs_set_timeout(nfs, 1000); 56 | 57 | url = nfs_parse_url_full(nfs, argv[argc - 1]); 58 | if (url == NULL) { 59 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 60 | exit(1); 61 | } 62 | 63 | if (nfs_mount(nfs, url->server, url->path) != 0) { 64 | fprintf(stderr, "Failed to mount nfs share : %s\n", 65 | nfs_get_error(nfs)); 66 | goto finished; 67 | } 68 | 69 | if (nfs_stat64(nfs, url->file, &st)) { 70 | fprintf(stderr, "Failed to stat file : %s\n", 71 | nfs_get_error(nfs)); 72 | goto finished; 73 | } 74 | 75 | printf("nfs_ino:%" PRIu64 "\n", st.nfs_ino); 76 | printf("nfs_mode:%" PRIo64 "\n", st.nfs_mode); 77 | printf("nfs_nlink:%" PRIu64 "\n", st.nfs_nlink); 78 | printf("nfs_uid:%" PRIu64 "\n", st.nfs_uid); 79 | printf("nfs_gid:%" PRIu64 "\n", st.nfs_gid); 80 | printf("nfs_size:%" PRIu64 "\n", st.nfs_size); 81 | printf("nfs_atime:%" PRIu64 "\n", st.nfs_atime); 82 | printf("nfs_mtime:%" PRIu64 "\n", st.nfs_mtime); 83 | printf("nfs_ctime:%" PRIu64 "\n", st.nfs_ctime); 84 | 85 | finished: 86 | nfs_destroy_url(url); 87 | nfs_destroy_context(nfs); 88 | 89 | /* Always return 0 as we want to catch valgrind 90 | * overriding this with return code 1 upon memory leaks. 91 | */ 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /tests/prog_access.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_access \n"); 37 | exit(1); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | struct nfs_context *nfs = NULL; 43 | struct nfs_url *url = NULL; 44 | int ret = 0; 45 | int flags = 0; 46 | 47 | if (argc != 5) { 48 | usage(); 49 | } 50 | 51 | if (strstr(argv[4], "R_OK")) { 52 | flags |= R_OK; 53 | } 54 | if (strstr(argv[4], "W_OK")) { 55 | flags |= W_OK; 56 | } 57 | if (strstr(argv[4], "X_OK")) { 58 | flags |= X_OK; 59 | } 60 | 61 | nfs = nfs_init_context(); 62 | if (nfs == NULL) { 63 | printf("failed to init context\n"); 64 | exit(1); 65 | } 66 | 67 | url = nfs_parse_url_full(nfs, argv[1]); 68 | if (url == NULL) { 69 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 70 | exit(1); 71 | } 72 | 73 | if (nfs_mount(nfs, url->server, url->path) != 0) { 74 | fprintf(stderr, "Failed to mount nfs share : %s\n", 75 | nfs_get_error(nfs)); 76 | ret = 1; 77 | goto finished; 78 | } 79 | 80 | if (nfs_chdir(nfs, argv[2]) != 0) { 81 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 82 | argv[2], nfs_get_error(nfs)); 83 | ret = 1; 84 | goto finished; 85 | } 86 | 87 | if (nfs_access(nfs, argv[3], flags)) { 88 | fprintf(stderr, "Failed to access(): %s\n", 89 | nfs_get_error(nfs)); 90 | ret = 1; 91 | goto finished; 92 | } 93 | 94 | finished: 95 | nfs_destroy_url(url); 96 | nfs_destroy_context(nfs); 97 | 98 | return ret; 99 | } 100 | -------------------------------------------------------------------------------- /tests/prog_create.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "libnfs.h" 33 | 34 | void usage(void) 35 | { 36 | fprintf(stderr, "Usage: prog_create " 37 | "\n"); 38 | exit(1); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct nfs_context *nfs = NULL; 44 | struct nfs_url *url = NULL; 45 | int ret = 0; 46 | int mode; 47 | struct nfsfh *fh; 48 | 49 | if (argc != 5) { 50 | usage(); 51 | } 52 | 53 | mode = strtol(argv[4], NULL, 8); 54 | 55 | nfs = nfs_init_context(); 56 | if (nfs == NULL) { 57 | printf("failed to init context\n"); 58 | exit(1); 59 | } 60 | 61 | url = nfs_parse_url_full(nfs, argv[1]); 62 | if (url == NULL) { 63 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 64 | exit(1); 65 | } 66 | 67 | if (nfs_mount(nfs, url->server, url->path) != 0) { 68 | fprintf(stderr, "Failed to mount nfs share : %s\n", 69 | nfs_get_error(nfs)); 70 | ret = 1; 71 | goto finished; 72 | } 73 | 74 | if (nfs_chdir(nfs, argv[2]) != 0) { 75 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 76 | argv[2], nfs_get_error(nfs)); 77 | ret = 1; 78 | goto finished; 79 | } 80 | 81 | if (nfs_creat(nfs, argv[3], mode, &fh)) { 82 | fprintf(stderr, "Failed to creat(): %s\n", 83 | nfs_get_error(nfs)); 84 | ret = 1; 85 | goto finished; 86 | } 87 | 88 | if (nfs_close(nfs, fh)) { 89 | fprintf(stderr, "Failed to close(): %s\n", 90 | nfs_get_error(nfs)); 91 | ret = 1; 92 | goto finished; 93 | } 94 | 95 | finished: 96 | nfs_destroy_url(url); 97 | nfs_destroy_context(nfs); 98 | 99 | return ret; 100 | } 101 | -------------------------------------------------------------------------------- /tests/test_0242_link_valgrind_leak_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic valgrind leak check for nfs_link()." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | 13 | echo "kangabanga" > "${TESTDIR}/testfile" 14 | echo -n "test nfs_link() (1) ... " 15 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." /testfile /link1 >/dev/null 2>&1 || failure 16 | success 17 | 18 | echo -n "test nfs_link() (2) ... " 19 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." /testfile link2 >/dev/null 2>&1 || failure 20 | success 21 | 22 | echo -n "test nfs_link() (3) ... " 23 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." testfile /link3 >/dev/null 2>&1 || failure 24 | success 25 | 26 | echo -n "test nfs_link() (4) ... " 27 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." testfile link4 >/dev/null 2>&1 || failure 28 | success 29 | 30 | echo -n "test nfs_link() (5) ... " 31 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." /testfile /subdir/link5 >/dev/null 2>&1 || failure 32 | success 33 | 34 | echo -n "test nfs_link() (6) ... " 35 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." /subdir/link5 subdir2/link6 >/dev/null 2>&1 || failure 36 | success 37 | 38 | echo -n "test nfs_link() (7) ... " 39 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." subdir/link5 /subdir2/link7 >/dev/null 2>&1 || failure 40 | success 41 | 42 | echo -n "test nfs_link() (8) ... " 43 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "." subdir2/link7 /subdir/link8 >/dev/null 2>&1 || failure 44 | success 45 | 46 | echo -n "test nfs_link() (9) ... " 47 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "subdir2" link7 ../subdir/link9 >/dev/null 2>&1 || failure 48 | success 49 | 50 | echo -n "test nfs_link() (10) ... " 51 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "subdir2" ../../link7 ../subdir/link10 2>/dev/null || expr $? != 99 >/dev/null || failure 52 | success 53 | 54 | echo -n "test nfs_link() (11) ... " 55 | libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_link "${TESTURL}/?version=${VERS}" "subdir2" link7 ../../subdir/link11 2>/dev/null || expr $? != 99 >/dev/null || failure 56 | success 57 | 58 | 59 | stop_share 60 | 61 | exit 0 62 | -------------------------------------------------------------------------------- /tests/prog_opendir.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) by Ronnie Sahlberg 2017 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #define _FILE_OFFSET_BITS 64 20 | #define _GNU_SOURCE 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "libnfs.h" 32 | 33 | void usage(void) 34 | { 35 | fprintf(stderr, "Usage: prog_opendir \n"); 36 | exit(1); 37 | } 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | struct nfs_context *nfs = NULL; 42 | struct nfs_url *url = NULL; 43 | struct nfsdirent *nfsdirent; 44 | struct nfsdir *nfsdir; 45 | int ret = 0; 46 | 47 | if (argc != 4) { 48 | usage(); 49 | } 50 | 51 | nfs = nfs_init_context(); 52 | if (nfs == NULL) { 53 | printf("failed to init context\n"); 54 | exit(1); 55 | } 56 | 57 | nfs_set_timeout(nfs, 300); 58 | 59 | url = nfs_parse_url_full(nfs, argv[1]); 60 | if (url == NULL) { 61 | fprintf(stderr, "%s\n", nfs_get_error(nfs)); 62 | exit(1); 63 | } 64 | 65 | if (nfs_mount(nfs, url->server, url->path) != 0) { 66 | fprintf(stderr, "Failed to mount nfs share : %s\n", 67 | nfs_get_error(nfs)); 68 | ret = 1; 69 | goto finished; 70 | } 71 | 72 | if (nfs_chdir(nfs, argv[2]) != 0) { 73 | fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", 74 | argv[2], nfs_get_error(nfs)); 75 | ret = 1; 76 | goto finished; 77 | } 78 | 79 | if (nfs_opendir(nfs, argv[3], &nfsdir)) { 80 | fprintf(stderr, "Failed to opendir() : %s\n", 81 | nfs_get_error(nfs)); 82 | ret = 1; 83 | goto finished; 84 | } 85 | 86 | while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) { 87 | if (!strcmp(nfsdirent->name, ".") || !strcmp(nfsdirent->name, "..")) { 88 | continue; 89 | } 90 | printf("%s\n", nfsdirent->name); 91 | } 92 | nfs_closedir(nfs, nfsdir); 93 | 94 | finished: 95 | nfs_destroy_url(url); 96 | nfs_destroy_context(nfs); 97 | 98 | return ret; 99 | } 100 | -------------------------------------------------------------------------------- /tests/test_0280_mkdir_rmdir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ./functions.sh 4 | 5 | echo "NFSv${VERS} Basic mkdir/rmdir tests." 6 | 7 | start_share 8 | 9 | mkdir "${TESTDIR}/subdir" 10 | mkdir "${TESTDIR}/subdir2" 11 | 12 | echo -n "test nfs_mkdir2() for a root directory (abs) (1) ... " 13 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "." /testdir || failure 14 | success 15 | 16 | echo -n "Stat the new directory ... " 17 | ./prog_stat "${TESTURL}/?version=${VERS}" "." testdir > "${TESTDIR}/output" || failure 18 | success 19 | 20 | echo -n "Verifying it is a directory ... " 21 | grep "nfs_mode:40" "${TESTDIR}/output" >/dev/null || failure 22 | success 23 | 24 | echo -n "test nfs_rmdir() for a root directory (abs) (2) ... " 25 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "." /testdir || failure 26 | success 27 | 28 | echo -n "test nfs_mkdir2() for a root directory (rel) (3) ... " 29 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "." testdir 2>/dev/null || failure 30 | success 31 | 32 | echo -n "test nfs_rmdir() for a root directory (rel) (4) ... " 33 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "." testdir 2>/dev/null || failure 34 | success 35 | 36 | echo -n "test nfs_mkdir2() in a subdirectory (abs) (5) ... " 37 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "." /subdir/testdir 2>/dev/null || failure 38 | success 39 | 40 | echo -n "test nfs_rmdir() for a subdirectory (abs) (6) ... " 41 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "." /subdir/testdir 2>/dev/null || failure 42 | success 43 | 44 | echo -n "test nfs_mkdir2() in a subdirectory (rel) (7) ... " 45 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "." subdir/testdir 2>/dev/null || failure 46 | success 47 | 48 | echo -n "test nfs_rmdir() for a subdirectory (rel) (8) ... " 49 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "." subdir/testdir 2>/dev/null || failure 50 | success 51 | 52 | echo -n "test nfs_mkdir2() from a different cwd (rel) (9) ... " 53 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/testdir 2>/dev/null || failure 54 | success 55 | 56 | echo -n "test nfs_rmdir() for a subdirectory (rel) (10) ... " 57 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "." subdir2/testdir 2>/dev/null || failure 58 | success 59 | 60 | echo -n "test nfs_mkdir2() outside of the share (rel) (11) ... " 61 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/../../testdir 2>/dev/null && failure 62 | success 63 | 64 | echo -n "test nfs_rmdir() outside of the share (rel) (12) ... " 65 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/../../testdir 2>/dev/null && failure 66 | success 67 | 68 | echo -n "test nfs_mkdir2() on an existing dir (rel) (13) ... " 69 | ./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" 2>/dev/null ../subdir2 && failure 70 | success 71 | 72 | echo -n "test nfs_rmdir() that does not exist (rel) (14) ... " 73 | ./prog_rmdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir3 2>/dev/null && failure 74 | success 75 | 76 | stop_share 77 | 78 | exit 0 79 | 80 | --------------------------------------------------------------------------------