From: Jon Trulson Date: Sat, 25 Aug 2018 23:38:48 +0000 (-0600) Subject: dtfile: Fix up CopyCheckDeletePermission() and CheckDeletePermission X-Git-Tag: 2.3.0a~26^2~15 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a29bd8937a5feeac49302f3868c04c8282238026;p=oweals%2Fcde.git 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. --- diff --git a/cde/programs/dtfile/Trash.c b/cde/programs/dtfile/Trash.c index 61f30fbb..a6288193 100644 --- a/cde/programs/dtfile/Trash.c +++ b/cde/programs/dtfile/Trash.c @@ -46,7 +46,6 @@ * EraseDir * EraseObject * FileFromTrash - * FileSysType * InitializeTrash * MatchesSacredDirectory * MessageToFileList @@ -108,6 +107,7 @@ #else #if defined(__linux__) #include +#include #else #include #endif @@ -387,7 +387,6 @@ static void EmptyTrash( Tt_message msg) ; static int CheckDeletePermissionRecur( char *dir); -static int FileSysType(int dev); static void RestoreVerifyOk( Widget w, XtPointer client_data, @@ -4144,16 +4143,16 @@ CheckDeletePermission( 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; #else struct stat statbuf; #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 */ #elif defined(__NetBSD__) if (statvfs(parentdir,&statbuf) < 0) /* does not exist */ @@ -4168,8 +4167,10 @@ CheckDeletePermission( /* 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 (FileSysType(statbuf.st_dev) < 0) /* Root user and nfs */ + /* nothing - always check if root */ #endif { int fd = -1; @@ -4200,7 +4201,7 @@ CheckDeletePermission( return -1; /* copy destinationPath to tmp buffer */ - strcpy(fname, destinationPath); + snprintf(fname, PATH_MAX, "%s", destinationPath); return CheckDeletePermissionRecur(fname); } @@ -4268,28 +4269,6 @@ CheckDeletePermissionRecur( 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 RestoreObject( Widget w, diff --git a/cde/programs/dtfile/dtcopy/sharedFuncs.c b/cde/programs/dtfile/dtcopy/sharedFuncs.c index 31b1ca51..eea1a601 100644 --- a/cde/programs/dtfile/dtcopy/sharedFuncs.c +++ b/cde/programs/dtfile/dtcopy/sharedFuncs.c @@ -68,6 +68,7 @@ #endif #if defined(__linux__) #include +#include #endif #include @@ -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;