From 4c6d19b3b85f39c691c9c5bb9d5ea5e54a8ba79b Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 2 Sep 2017 06:42:59 +1000 Subject: [PATCH] NFSv4: Add support for chown/lchown/fchown Signed-off-by: Ronnie Sahlberg --- include/libnfs-private.h | 5 + lib/libnfs-sync.c | 9 +- lib/libnfs.c | 21 ++-- lib/nfs_v4.c | 208 +++++++++++++++++++++++++++++++++----- tests/Makefile.am | 11 +- tests/prog_chown.c | 93 +++++++++++++++++ tests/prog_fchown.c | 107 ++++++++++++++++++++ tests/prog_lchown.c | 93 +++++++++++++++++ tests/test_0400_chown.sh | 46 +++++++++ tests/test_0410_lchown.sh | 46 +++++++++ tests/test_0420_fchown.sh | 46 +++++++++ 11 files changed, 648 insertions(+), 37 deletions(-) create mode 100644 tests/prog_chown.c create mode 100644 tests/prog_fchown.c create mode 100644 tests/prog_lchown.c create mode 100755 tests/test_0400_chown.sh create mode 100755 tests/test_0410_lchown.sh create mode 100755 tests/test_0420_fchown.sh diff --git a/include/libnfs-private.h b/include/libnfs-private.h index 75ab50d..abc4099 100644 --- a/include/libnfs-private.h +++ b/include/libnfs-private.h @@ -477,12 +477,17 @@ int nfs4_chdir_async(struct nfs_context *nfs, const char *path, int nfs4_chmod_async_internal(struct nfs_context *nfs, const char *path, int no_follow, int mode, nfs_cb cb, void *private_data); +int nfs4_chown_async_internal(struct nfs_context *nfs, const char *path, + int no_follow, int uid, int gid, + nfs_cb cb, void *private_data); int nfs4_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); int nfs4_create_async(struct nfs_context *nfs, const char *path, int flags, int mode, nfs_cb cb, void *private_data); int nfs4_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data); +int nfs4_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, + int gid, nfs_cb cb, void *private_data); int nfs4_fstat64_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); int nfs4_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index c44b44f..20017fa 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -1308,7 +1308,8 @@ nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid) cb_data.is_finished = 0; if (nfs_chown_async(nfs, path, uid, gid, chown_cb, &cb_data) != 0) { - nfs_set_error(nfs, "nfs_chown_async failed"); + nfs_set_error(nfs, "nfs_chown_async failed. %s", + nfs_get_error(nfs)); return -1; } @@ -1328,7 +1329,8 @@ nfs_lchown(struct nfs_context *nfs, const char *path, int uid, int gid) cb_data.is_finished = 0; if (nfs_lchown_async(nfs, path, uid, gid, chown_cb, &cb_data) != 0) { - nfs_set_error(nfs, "nfs_lchown_async failed"); + nfs_set_error(nfs, "nfs_lchown_async failed. %s", + nfs_get_error(nfs)); return -1; } @@ -1363,7 +1365,8 @@ nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid) cb_data.is_finished = 0; if (nfs_fchown_async(nfs, nfsfh, uid, gid, fchown_cb, &cb_data) != 0) { - nfs_set_error(nfs, "nfs_fchown_async failed"); + nfs_set_error(nfs, "nfs_fchown_async failed. %s", + nfs_get_error(nfs)); return -1; } diff --git a/lib/libnfs.c b/lib/libnfs.c index aa8a9c6..5275658 100755 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -1450,9 +1450,12 @@ nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, case NFS_V3: return nfs3_chown_async_internal(nfs, path, 0, uid, gid, cb, private_data); + case NFS_V4: + return nfs4_chown_async_internal(nfs, path, 0, uid, gid, + cb, private_data); default: - nfs_set_error(nfs, "%s does not support NFSv4", - __FUNCTION__); + nfs_set_error(nfs, "%s does not support NFSv%d", + __FUNCTION__, nfs->version); return -1; } } @@ -1465,9 +1468,12 @@ nfs_lchown_async(struct nfs_context *nfs, const char *path, int uid, int gid, case NFS_V3: return nfs3_chown_async_internal(nfs, path, 1, uid, gid, cb, private_data); + case NFS_V4: + return nfs4_chown_async_internal(nfs, path, 1, uid, gid, + cb, private_data); default: - nfs_set_error(nfs, "%s does not support NFSv4", - __FUNCTION__); + nfs_set_error(nfs, "%s does not support NFSv%d", + __FUNCTION__, nfs->version); return -1; } } @@ -1480,9 +1486,12 @@ nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, case NFS_V3: return nfs3_fchown_async(nfs, nfsfh, uid, gid, cb, private_data); + case NFS_V4: + return nfs4_fchown_async(nfs, nfsfh, uid, gid, + cb, private_data); default: - nfs_set_error(nfs, "%s does not support NFSv4", - __FUNCTION__); + nfs_set_error(nfs, "%s does not support NFSv%d", + __FUNCTION__, nfs->version); return -1; } } diff --git a/lib/nfs_v4.c b/lib/nfs_v4.c index c2674b6..b919f47 100644 --- a/lib/nfs_v4.c +++ b/lib/nfs_v4.c @@ -726,6 +726,29 @@ nfs4_op_chmod(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh, return 1; } +static int +nfs4_op_chown(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh, + void *sabuf, int len) +{ + SETATTR4args *saargs; + static uint32_t mask[2] = {0, + 1 << (FATTR4_OWNER - 32) | + 1 << (FATTR4_OWNER_GROUP - 32)}; + + op[0].argop = OP_SETATTR; + saargs = &op[0].nfs_argop4_u.opsetattr; + saargs->stateid.seqid = fh->stateid.seqid; + memcpy(saargs->stateid.other, fh->stateid.other, 12); + + saargs->obj_attributes.attrmask.bitmap4_len = 2; + saargs->obj_attributes.attrmask.bitmap4_val = mask; + + saargs->obj_attributes.attr_vals.attrlist4_len = len; + saargs->obj_attributes.attr_vals.attrlist4_val = sabuf; + + return 1; +} + static int nfs4_op_readdir(struct nfs_context *nfs, nfs_argop4 *op, uint64_t cookie) { @@ -3894,28 +3917,6 @@ nfs4_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, return 0; } -static void -nfs4_chmod_close_cb(struct rpc_context *rpc, int status, void *command_data, - void *private_data) -{ - struct nfs4_cb_data *data = private_data; - struct nfs_context *nfs = data->nfs; - COMPOUND4res *res = command_data; - - assert(rpc->magic == RPC_CONTEXT_MAGIC); - - if (res) { - nfs_increment_seqid(nfs, res->status); - } - - if (check_nfs4_error(nfs, status, data, res, "CLOSE")) { - return; - } - - data->cb(0, nfs, NULL, data->private_data); - free_nfs4_cb_data(data); -} - static void nfs4_chmod_open_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) @@ -3940,7 +3941,7 @@ nfs4_chmod_open_cb(struct rpc_context *rpc, int status, void *command_data, args.argarray.argarray_len = i; args.argarray.argarray_val = op; - if (rpc_nfs4_compound_async(nfs->rpc, nfs4_chmod_close_cb, &args, + if (rpc_nfs4_compound_async(nfs->rpc, nfs4_close_cb, &args, data) != 0) { /* Not much we can do but leak one fd on the server :( */ data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data); @@ -4038,3 +4039,164 @@ nfs4_fchmod_async(struct nfs_context *nfs, struct nfsfh *fh, int mode, return 0; } + +#define CHOWN_BLOB_SIZE 64 +static int +nfs4_create_chown_buffer(struct nfs_context *nfs, struct nfs4_cb_data *data, + int uid, int gid) +{ + char *str; + int i, l; + uint32_t len; + + data->filler.blob3.val = malloc(CHOWN_BLOB_SIZE); + if (data->filler.blob3.val == NULL) { + nfs_set_error(nfs, "Out of memory"); + return -1; + } + data->filler.blob3.free = free; + memset(data->filler.blob3.val, 0, CHOWN_BLOB_SIZE); + + i = 0; + str = data->filler.blob3.val; + /* UID */ + l = snprintf(&str[i + 4], CHOWN_BLOB_SIZE - 4 - i, + "%d", uid); + if (l < 0) { + nfs_set_error(nfs, "snprintf failed"); + return -1; + } + len = htonl(l); + /* UID length prefix */ + memcpy(&str[i], &len, sizeof(uint32_t)); + i += 4 + l; + i = (i + 3) & ~0x03; + + /* GID */ + l = snprintf(&str[i + 4], CHOWN_BLOB_SIZE - 4 - i, + "%d", gid); + if (l < 0) { + nfs_set_error(nfs, "snprintf failed"); + return -1; + } + len = htonl(l); + /* GID length prefix */ + memcpy(&str[i], &len, sizeof(uint32_t)); + i += 4 + l; + i = (i + 3) & ~0x03; + + data->filler.blob3.len = i; + + return 0; +} + +static void +nfs4_chown_open_cb(struct rpc_context *rpc, int status, void *command_data, + void *private_data) +{ + struct nfs4_cb_data *data = private_data; + struct nfs_context *nfs = data->nfs; + struct nfsfh *fh = data->filler.blob0.val; + COMPOUND4res *res = command_data; + COMPOUND4args args; + nfs_argop4 op[4]; + int i; + + if (check_nfs4_error(nfs, status, data, res, "OPEN")) { + return; + } + + i = nfs4_op_putfh(nfs, &op[0], fh); + i += nfs4_op_chown(nfs, &op[i], fh, data->filler.blob3.val, + data->filler.blob3.len); + i += nfs4_op_close(nfs, &op[i], fh); + + memset(&args, 0, sizeof(args)); + args.argarray.argarray_len = i; + args.argarray.argarray_val = op; + + if (rpc_nfs4_compound_async(nfs->rpc, nfs4_close_cb, &args, + data) != 0) { + /* Not much we can do but leak one fd on the server :( */ + data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data); + free_nfs4_cb_data(data); + return; + } +} + +int +nfs4_chown_async_internal(struct nfs_context *nfs, const char *path, + int no_follow, int uid, int gid, + nfs_cb cb, void *private_data) +{ + struct nfs4_cb_data *data; + + data = init_cb_data_split_path(nfs, path); + if (data == NULL) { + return -1; + } + + data->cb = cb; + data->private_data = private_data; + data->open_cb = nfs4_chown_open_cb; + + if (no_follow) { + data->flags |= LOOKUP_FLAG_NO_FOLLOW; + } + + if (nfs4_create_chown_buffer(nfs, data, uid, gid) < 0) { + free_nfs4_cb_data(data); + return -1; + } + + if (nfs4_open_async_internal(nfs, data, O_WRONLY, 0) < 0) { + return -1; + } + + return 0; +} + +int +nfs4_fchown_async(struct nfs_context *nfs, struct nfsfh *fh, int uid, int gid, + nfs_cb cb, void *private_data) +{ + COMPOUND4args args; + nfs_argop4 op[2]; + struct nfs4_cb_data *data; + int i; + + data = malloc(sizeof(*data)); + if (data == NULL) { + nfs_set_error(nfs, "Out of memory."); + return -1; + } + memset(data, 0, sizeof(*data)); + + data->nfs = nfs; + data->cb = cb; + data->private_data = private_data; + + if (nfs4_create_chown_buffer(nfs, data, uid, gid) < 0) { + free_nfs4_cb_data(data); + return -1; + } + + memset(op, 0, sizeof(op)); + + i = nfs4_op_putfh(nfs, &op[0], fh); + i += nfs4_op_chown(nfs, &op[i], fh, data->filler.blob3.val, + data->filler.blob3.len); + + memset(&args, 0, sizeof(args)); + args.argarray.argarray_len = i; + args.argarray.argarray_val = op; + + if (rpc_nfs4_compound_async(nfs->rpc, nfs4_fsync_cb, &args, + data) != 0) { + data->filler.blob0.val = NULL; + free_nfs4_cb_data(data); + return -1; + } + + return 0; +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 117b28f..6bde99b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,11 +4,12 @@ AM_CPPFLAGS = -I${srcdir}/../include -I${srcdir}/../include/nfsc \ AM_CFLAGS = $(WARN_CFLAGS) LDADD = ../lib/libnfs.la -noinst_PROGRAMS = prog_chmod prog_create prog_fchmod prog_fstat \ - prog_ftruncate prog_lchmod prog_link prog_lseek prog_lstat \ - prog_mkdir prog_mknod prog_mount prog_open_read prog_open_write \ - prog_rename prog_rmdir prog_stat prog_statvfs prog_symlink \ - prog_timeout prog_truncate prog_unlink +noinst_PROGRAMS = prog_chmod prog_chown prog_create prog_fchmod prog_fchown \ + prog_fstat prog_ftruncate prog_lchmod prog_lchown prog_link \ + prog_lseek prog_lstat prog_mkdir prog_mknod prog_mount \ + prog_open_read prog_open_write prog_rename prog_rmdir \ + prog_stat prog_statvfs prog_symlink prog_timeout prog_truncate \ + prog_unlink EXTRA_PROGRAMS = ld_timeout CLEANFILES = ld_timeout.o ld_timeout.so diff --git a/tests/prog_chown.c b/tests/prog_chown.c new file mode 100644 index 0000000..74f6530 --- /dev/null +++ b/tests/prog_chown.c @@ -0,0 +1,93 @@ +/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ +/* + Copyright (C) by Ronnie Sahlberg 2017 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#define _FILE_OFFSET_BITS 64 +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libnfs.h" + +void usage(void) +{ + fprintf(stderr, "Usage: prog_chown " + "\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + struct nfs_context *nfs = NULL; + struct nfs_url *url = NULL; + int ret = 0; + int uid, gid; + + if (argc != 6) { + usage(); + } + + uid = strtol(argv[4], NULL, 10); + gid = strtol(argv[5], NULL, 10); + + nfs = nfs_init_context(); + if (nfs == NULL) { + printf("failed to init context\n"); + exit(1); + } + + url = nfs_parse_url_full(nfs, argv[1]); + if (url == NULL) { + fprintf(stderr, "%s\n", nfs_get_error(nfs)); + exit(1); + } + + if (nfs_mount(nfs, url->server, url->path) != 0) { + fprintf(stderr, "Failed to mount nfs share : %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_chdir(nfs, argv[2]) != 0) { + fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", + argv[2], nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_chown(nfs, argv[3], uid, gid)) { + fprintf(stderr, "Failed to chown(): %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + +finished: + nfs_destroy_url(url); + nfs_destroy_context(nfs); + + return ret; +} diff --git a/tests/prog_fchown.c b/tests/prog_fchown.c new file mode 100644 index 0000000..a2c025a --- /dev/null +++ b/tests/prog_fchown.c @@ -0,0 +1,107 @@ +/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ +/* + Copyright (C) by Ronnie Sahlberg 2017 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#define _FILE_OFFSET_BITS 64 +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libnfs.h" + +void usage(void) +{ + fprintf(stderr, "Usage: prog_fchown " + "\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + struct nfs_context *nfs = NULL; + struct nfs_url *url = NULL; + int ret = 0; + int uid, gid; + struct nfsfh *fh; + + if (argc != 6) { + usage(); + } + + uid = strtol(argv[4], NULL, 10); + gid = strtol(argv[5], NULL, 10); + + nfs = nfs_init_context(); + if (nfs == NULL) { + printf("failed to init context\n"); + exit(1); + } + + url = nfs_parse_url_full(nfs, argv[1]); + if (url == NULL) { + fprintf(stderr, "%s\n", nfs_get_error(nfs)); + exit(1); + } + + if (nfs_mount(nfs, url->server, url->path) != 0) { + fprintf(stderr, "Failed to mount nfs share : %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_chdir(nfs, argv[2]) != 0) { + fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", + argv[2], nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_open(nfs, argv[3], O_RDWR, &fh)) { + fprintf(stderr, "Failed to open file : %s\n", + nfs_get_error(nfs)); + exit(1); + } + + if (nfs_fchown(nfs, fh, uid, gid)) { + fprintf(stderr, "Failed to fchown(): %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_close(nfs, fh)) { + fprintf(stderr, "Failed to close(): %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + +finished: + nfs_destroy_url(url); + nfs_destroy_context(nfs); + + return ret; +} diff --git a/tests/prog_lchown.c b/tests/prog_lchown.c new file mode 100644 index 0000000..d3d2669 --- /dev/null +++ b/tests/prog_lchown.c @@ -0,0 +1,93 @@ +/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ +/* + Copyright (C) by Ronnie Sahlberg 2017 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#define _FILE_OFFSET_BITS 64 +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libnfs.h" + +void usage(void) +{ + fprintf(stderr, "Usage: prog_lchown " + "\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + struct nfs_context *nfs = NULL; + struct nfs_url *url = NULL; + int ret = 0; + int uid, gid; + + if (argc != 6) { + usage(); + } + + uid = strtol(argv[4], NULL, 10); + gid = strtol(argv[5], NULL, 10); + + nfs = nfs_init_context(); + if (nfs == NULL) { + printf("failed to init context\n"); + exit(1); + } + + url = nfs_parse_url_full(nfs, argv[1]); + if (url == NULL) { + fprintf(stderr, "%s\n", nfs_get_error(nfs)); + exit(1); + } + + if (nfs_mount(nfs, url->server, url->path) != 0) { + fprintf(stderr, "Failed to mount nfs share : %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_chdir(nfs, argv[2]) != 0) { + fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", + argv[2], nfs_get_error(nfs)); + ret = 1; + goto finished; + } + + if (nfs_lchown(nfs, argv[3], uid, gid)) { + fprintf(stderr, "Failed to lchown(): %s\n", + nfs_get_error(nfs)); + ret = 1; + goto finished; + } + +finished: + nfs_destroy_url(url); + nfs_destroy_context(nfs); + + return ret; +} diff --git a/tests/test_0400_chown.sh b/tests/test_0400_chown.sh new file mode 100755 index 0000000..93dd50e --- /dev/null +++ b/tests/test_0400_chown.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +. ./functions.sh + +echo "NFSv${VERS} Basic chown tests." + +start_share + +dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null + +echo -n "test chown(1000, 2000) ... " +./prog_chown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 1000 2000 || failure +success + +echo -n "Stat the file ... " +./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure +success + +echo -n "Verifying the uid is 1000 ... " +grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "Verifying the gid is 2000 ... " +grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "test chown(2000, 3000) ... " +./prog_chown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 2000 3000 || failure +success + +echo -n "Stat the file ... " +./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure +success + +echo -n "Verifying the uid is 2000 ... " +grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "Verifying the gid is 3000 ... " +grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure +success + + +stop_share + +exit 0 diff --git a/tests/test_0410_lchown.sh b/tests/test_0410_lchown.sh new file mode 100755 index 0000000..7d5cba6 --- /dev/null +++ b/tests/test_0410_lchown.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +. ./functions.sh + +echo "NFSv${VERS} Basic lchown tests." + +start_share + +dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null + +echo -n "test lchown(1000, 2000) ... " +./prog_lchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 1000 2000 || failure +success + +echo -n "Stat the file ... " +./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure +success + +echo -n "Verifying the uid is 1000 ... " +grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "Verifying the gid is 2000 ... " +grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "test lchown(2000, 3000) ... " +./prog_lchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 2000 3000 || failure +success + +echo -n "Stat the file ... " +./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure +success + +echo -n "Verifying the uid is 2000 ... " +grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "Verifying the gid is 3000 ... " +grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure +success + + +stop_share + +exit 0 diff --git a/tests/test_0420_fchown.sh b/tests/test_0420_fchown.sh new file mode 100755 index 0000000..3d8c271 --- /dev/null +++ b/tests/test_0420_fchown.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +. ./functions.sh + +echo "NFSv${VERS} Basic fchown tests." + +start_share + +dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null + +echo -n "test fchown(1000, 2000) ... " +./prog_fchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 1000 2000 || failure +success + +echo -n "Stat the file ... " +./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure +success + +echo -n "Verifying the uid is 1000 ... " +grep "nfs_uid:1000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "Verifying the gid is 2000 ... " +grep "nfs_gid:2000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "test fchown(2000, 3000) ... " +./prog_fchown "${TESTURL}/?uid=0&version=${VERS}" "." /testfile 2000 3000 || failure +success + +echo -n "Stat the file ... " +./prog_stat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure +success + +echo -n "Verifying the uid is 2000 ... " +grep "nfs_uid:2000" "${TESTDIR}/output" >/dev/null || failure +success + +echo -n "Verifying the gid is 3000 ... " +grep "nfs_gid:3000" "${TESTDIR}/output" >/dev/null || failure +success + + +stop_share + +exit 0