dtfile: Fix up CopyCheckDeletePermission() and CheckDeletePermission

Remove calls to bogus utility functions in cases where the user is
root and the filesystem in question is an NFS filesystem.

For now, __linux___ and CSRG_BASED machines will use statfs to
determine whether to test delete-ability.  For other systems, just do
the create/delete test always if the user is root.
This commit is contained in:
Jon Trulson
2018-08-25 17:38:48 -06:00
parent 9cb1f309f2
commit a29bd8937a
2 changed files with 14 additions and 54 deletions

View File

@@ -68,6 +68,7 @@
#endif
#if defined(__linux__)
#include <sys/vfs.h>
#include <linux/magic.h>
#endif
#include <dirent.h>
@@ -361,28 +362,6 @@ ImageInitialize( Display *display )
return ;
} /* end ImageInitialize */
#if !defined(CSRG_BASED) && !defined(__linux__)
static int
CopyFileSysType(
int dev)
{
struct ustat u1;
if(ustat(dev,&u1) < 0)
return -2;
return u1.f_tinode;
}
#else
static int
CopyFileSysType(
int dev)
{
struct statfs u1;
if(statfs(dev,&u1) < 0)
return -2;
return u1.f_ffree;
}
#endif
static int
CopyCheckDeletePermissionRecur(
char *destinationPath)
@@ -453,7 +432,7 @@ CopyCheckDeletePermission(
char *parentdir,
char *destinationPath)
{
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
struct statfs statbuf;
#elif defined(__NetBSD__)
struct statvfs statbuf;
@@ -462,7 +441,7 @@ CopyCheckDeletePermission(
#endif
char fname[PATH_MAX];
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
if (statfs(parentdir,&statbuf) < 0) /* does not exist */
#elif defined(__NetBSD__)
if (statvfs(parentdir,&statbuf) < 0) /* does not exist */
@@ -477,8 +456,10 @@ CopyCheckDeletePermission(
/* if NFS, need to check if server trusts root */
#if defined(CSRG_BASED)
if (!strcmp(statbuf.f_fstypename, "nfs")) /* Root user and nfs */
#elif defined(__linux__)
if (statbuf.f_type == NFS_SUPER_MAGIC)
#else
if (CopyFileSysType(statbuf.st_dev) < 0) /* Root user and nfs */
/* nothing - always check if root */
#endif
{
char *tmpfile;