从Java中的FileDescriptor获取路径 [英] Get path from FileDescriptor in Java

查看:877
本文介绍了从Java中的FileDescriptor获取路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的问题的一些快速背景知识:

Some quick background on my problem:

我正在编写一个将域类型强制规范转换为Java Security Manager代码的编译器.简而言之,DTE定义了类型"(对象),并为这些类型分配了路径.然后定义域"(主题),并定义各种类型的权限(rwxdc)域.我需要在JSM中尽可能地模仿这种行为.

I'm writing a compiler that converts Domain Type Enforcement specs into Java Security Manager code. In a nutshell, DTE defines "types" (objects), assigns paths to those types; then defines "domains" (subjects), and defines what permissions (rwxdc) domains have to various types. I need to emulate this behavior as closely as possible in the JSM.

目前,我正在研究写权限.我已经成功重写了JSM的checkWrite(String filename)方法.列表上的下一个是checkWrite(FileDescriptor filedescriptor),事实证明这比较棘手.由于DTE的定义方式,我需要路径信息来确定是否允许执行写操作.

Currently I'm working on write permissions. I've overridden the JSM's checkWrite(String filename) method successfully. Next on the list is checkWrite(FileDescriptor filedescriptor) and this one is proving trickier. Due to the way DTE is defined, I need path information to determine whether a write action is permissible.

  • 是否可以从FileDescriptor中提取路径数据?我猜不是-我检查了文档和各种教程,但没有发现任何建议可以帮助我获取此信息(不过,很高兴看到错误,这很高兴;但是那会很高兴)使我的工作更轻松).

  • Is it possible to extract path data from a FileDescriptor? I'm guessing no -- I've checked the documentation and various tutorials, and I've found nothing to suggest that there's any way for me to obtain this information (I'd be delighted to be shown wrong, however; that would make my job easier).

如果上述回答为否",那么有人可以提出可行的解决方法吗?例如,是否可以通过某种方式编写本机代码来执行所需的操作,并将其绑定到我的自定义JSM类中?我可以做类似高级"的事情,但是我需要一些入门的知识.

If the answer to the above is NO, could anyone suggest a viable workaround? For example, is there some way I could write native code to do what I want and tie this into my custom JSM class? I'm fine with doing something "advanced" like that, but I'd need some idea how to get started.

还是我的 only 选项基本上是拒绝使用FileDescriptor的所有写权限?我非常想避免这种情况,因为这是一个糟糕的解决方案,但是如果那是我需要知道的现实.

Or is my only option basically to deny all write permissions that use a FileDescriptor? I'd very much like to avoid this because it's a crummy solution, but if that's the reality I need to know.

非常感谢您的时间.

推荐答案

简短的回答是否",因为文件独立于用于访问该文件的路径(至少在任何重要的OS上)都是独立的.

The short answer is no, because a file is independent from the path used to access that file (at least on any OS that matters).

一种可能的解决方法是使用Aspect框架捕获打开文件的调用,并将引用的文件描述符放入WeakHashMap<FileDescriptor,File>中.然后,只要需要验证写入操作,您就可以简单地查看此地图.

One possible work-around is to trap the calls that open files, using an aspect framework, and put the referenced file descriptors into a WeakHashMap<FileDescriptor,File>. Then you simply look at this map whenever you need to validate a write.

这篇关于从Java中的FileDescriptor获取路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆