1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

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

@ -46,7 +46,6 @@
* EraseDir * EraseDir
* EraseObject * EraseObject
* FileFromTrash * FileFromTrash
* FileSysType
* InitializeTrash * InitializeTrash
* MatchesSacredDirectory * MatchesSacredDirectory
* MessageToFileList * MessageToFileList
@ -108,6 +107,7 @@
#else #else
#if defined(__linux__) #if defined(__linux__)
#include <sys/vfs.h> #include <sys/vfs.h>
#include <linux/magic.h>
#else #else
#include <ustat.h> #include <ustat.h>
#endif #endif
@ -387,7 +387,6 @@ static void EmptyTrash(
Tt_message msg) ; Tt_message msg) ;
static int CheckDeletePermissionRecur( static int CheckDeletePermissionRecur(
char *dir); char *dir);
static int FileSysType(int dev);
static void RestoreVerifyOk( static void RestoreVerifyOk(
Widget w, Widget w,
XtPointer client_data, XtPointer client_data,
@ -4144,16 +4143,16 @@ CheckDeletePermission(
char *parentdir, char *parentdir,
char *destinationPath) char *destinationPath)
{ {
#if defined(__FreeBSD__) || defined(__OpenBSD__) #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
struct statfs statbuf; struct statfs statbuf;
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
struct statvfs statbuf; struct statvfs statbuf;
#else #else
struct stat statbuf; struct stat statbuf;
#endif #endif
char fname[1024]; char fname[PATH_MAX];
#if defined(__FreeBSD__) || defined(__OpenBSD__) #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
if (statfs(parentdir,&statbuf) < 0) /* does not exist */ if (statfs(parentdir,&statbuf) < 0) /* does not exist */
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
if (statvfs(parentdir,&statbuf) < 0) /* does not exist */ if (statvfs(parentdir,&statbuf) < 0) /* does not exist */
@ -4168,8 +4167,10 @@ CheckDeletePermission(
/* if NFS, need to check if server trusts root */ /* if NFS, need to check if server trusts root */
#if defined(CSRG_BASED) #if defined(CSRG_BASED)
if (!strcmp(statbuf.f_fstypename, "nfs")) /* Root user and nfs */ if (!strcmp(statbuf.f_fstypename, "nfs")) /* Root user and nfs */
#elif defined(__linux__)
if (statbuf.f_type == NFS_SUPER_MAGIC)
#else #else
if (FileSysType(statbuf.st_dev) < 0) /* Root user and nfs */ /* nothing - always check if root */
#endif #endif
{ {
int fd = -1; int fd = -1;
@ -4200,7 +4201,7 @@ CheckDeletePermission(
return -1; return -1;
/* copy destinationPath to tmp buffer */ /* copy destinationPath to tmp buffer */
strcpy(fname, destinationPath); snprintf(fname, PATH_MAX, "%s", destinationPath);
return CheckDeletePermissionRecur(fname); return CheckDeletePermissionRecur(fname);
} }
@ -4268,28 +4269,6 @@ CheckDeletePermissionRecur(
return 0; return 0;
} }
#if !defined(CSRG_BASED) && !defined(__linux__)
static int
FileSysType(
int dev)
{
struct ustat u1;
if(ustat(dev,&u1) < 0)
return -2;
return u1.f_tinode;
}
#else
static int
FileSysType(
int dev)
{
struct statfs u1;
if(statfs(dev,&u1) < 0)
return -2;
return u1.f_ffree;
}
#endif
static int static int
RestoreObject( RestoreObject(
Widget w, Widget w,

View file

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