protected internal static FSDataInputStream ForceSecureOpenFSDataInputStream(FilePath file, string expectedOwner, string expectedGroup) { FSDataInputStream @in = rawFilesystem.Open(new Path(file.GetAbsolutePath())); bool success = false; try { NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(@in.GetFileDescriptor()); CheckStat(file, stat.GetOwner(), stat.GetGroup(), expectedOwner, expectedGroup); success = true; return(@in); } finally { if (!success) { @in.Close(); } } }
protected internal static FileInputStream ForceSecureOpenForRead(FilePath f, string expectedOwner, string expectedGroup) { FileInputStream fis = new FileInputStream(f); bool success = false; try { NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(fis.GetFD()); CheckStat(f, stat.GetOwner(), stat.GetGroup(), expectedOwner, expectedGroup); success = true; return(fis); } finally { if (!success) { fis.Close(); } } }
protected internal static RandomAccessFile ForceSecureOpenForRandomRead(FilePath f, string mode, string expectedOwner, string expectedGroup) { RandomAccessFile raf = new RandomAccessFile(f, mode); bool success = false; try { NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(raf.GetFD()); CheckStat(f, stat.GetOwner(), stat.GetGroup(), expectedOwner, expectedGroup); success = true; return(raf); } finally { if (!success) { raf.Close(); } } }