为什么“本地系统”帐户缺乏 NTFS 文件系统的权限(将 java 作为 Windows 服务运行)
由于 NTFS 权限,我在将 java 进程作为 Windows 服务运行时遇到问题。 (http://community.jboss.org/wiki/RunJBossAsAServiceOnWindows)。
该服务安装成功,但由于文件权限而出现启动问题。
- 如果我将 Windows 服务“登录”更改为我的帐户(例如域/登录),则该服务运行正常。
- 如果我将文件系统权限从 755 更改为 777,该服务可以正常运行。
示例日志
08:58:02,250 ERROR [MainDeployer] Could not make local copy for file:/J:/projects/devtools/pe64-jboss-4.2.2.GA/server/solr/conf/jboss-service.xml
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
“Yo No Comprende”。 我以为“本地系统”帐户是“root”。 (“本地系统”是默认帐户)
“chmod -R 777>>”不是一个选择。 (安全漏洞)
总结一下:
- “本地系统”和 Windows NTFS 文件权限有什么关系?
- 您可以将“本地系统”添加到“我的组”吗?
- 我的本地构建过程是否出了问题? (例如,Windows 版本的 UMask 不好?)
- 还有其他将 java 作为 Windows 服务运行的问题吗?
- 基于 Windows NT 的操作系统已经使用了 15 多年,为什么服务仍然如此痛苦?
更新/解决方案
事实证明,在后来的 Windows(Vista 和 Window 7)中,MSFT 关闭了一个安全漏洞,该漏洞允许服务获取任何人的“临时”文件。
“本地系统”帐户无权访问任何公共/预先创建的“临时”目录。
在 java 世界中,解决方案是:
- 创建您自己的临时目录。授予它足够的权限)
- 将“-Djava.io.tmpdir=/path/to/my/temp/dir”作为 jvm 参数传递。
谢谢
会
I have a problem running a java process as a windows service due to NTFS permissions.
(http://community.jboss.org/wiki/RunJBossAsAServiceOnWindows).
The service installs successfully, but has problems starting due to file permissions.
- If I change the windows-service "login" to my account (e.g. domain/login), the service runs fine.
- If I change the filesystem permisisons from 755 to 777, the service runs fine.
Example log
08:58:02,250 ERROR [MainDeployer] Could not make local copy for file:/J:/projects/devtools/pe64-jboss-4.2.2.GA/server/solr/conf/jboss-service.xml
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
"Yo No Comprende". I thought the "Local System" account was "root". ("Local System" is the default account)
"chmod -R 777 <>" is not an option. (security hole)
So to summarize:
- What is the deal with "Local System" and windows NTFS file permissions?
- Can you add "Local System" to "My group"
- Is my local build process doing something wrong? (e.g. the windows version of UMask is bad? )
- Any other gotchas running java as a windows service?
- After 15+ years of windows NT-based OS, why are services still such a pain?
Update/Solution
It turn out that in later Windows (Vista and Window 7), MSFT closed a security hole which allowed a service to get at anyone's "temp" files.
"Local System" account just doesn't have access to any common/pre-created "temp" directory.
The solution, in the java world:
- create your own temp directory. Grant it adequate permisions)
- pass "-Djava.io.tmpdir=/path/to/my/temp/dir" as a jvm argument.
thanks
will
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NTFS 权限的工作方式与 Ext2/3/4 权限略有不同。
具体来说,文件系统并不关心您是否是管理员...如果您的 SID 没有
创建文件
权限 或包含它的其他元权限之一(即Write
)在目录上,您无法创建新文件或将文件从另一个目录复制到该文件夹。它赋予您更改任何文件夹权限的权限。
NTFS permissions work a bit differently than Ext2/3/4 permissions.
Specifically, the file system doesn't care if you're an administrator or not... if your SID doesn't have the
Create Files
permission or one of the other meta-permissions that include it (i.e.Write
) on a directory, you can't create a new file or copy a file from another directory to said folder.What it does give you is the permission to change the permissions on any folder.
“本地系统”并不完全是根。它可以被拒绝(或不授予)权限,就像任何其他用户一样,Windows 将强制执行这些权限。 (尽管在这样做之前您最好知道自己在做什么 - 阻止错误的内容可能会使您的系统无法使用。)有时,通常当您从特权位置(例如桌面或其他位置)复制内容时, Windows 将关闭该文件夹的“继承权限”功能,并且该帐户将无法获得通常从根目录继承的权限。
确保该文件夹授予本地系统帐户将文件添加到要在其中创建该文件的文件夹的权限。至于你如何使用 Cygwin 做到这一点......我不确定。它是否有类似于 Linux 的
setfacl
命令 的东西?"Local System" isn't exactly root. It can be denied (or not granted) permissions, just like any other user, and Windows will enforce those permissions. (Though you better know what you're doing before you do so -- blocking the wrong stuff from it can make your system unusable.) Sometimes, often when you're copying stuff from a privileged location (like your desktop or something), Windows will turn off the "inherit permissions" thingie for the folder, and the account won't get the permissions it'd normally inherit from the root.
Make sure the folder grants the Local System account permission to add files to the folder where it wants to create that file. As for how you'd do that with Cygwin...i'm not sure. Does it have something akin to Linux's
setfacl
command?我不会为此使用 Cygwin。相反,我使用了 cacls 和 ntrights 的组合(来自 XP 资源工具包 - 在 2008/win 7 中仍然有效)。唯一的问题是您必须以管理员身份运行 Ant。这意味着您需要确保启动管理员级别的 cmd 提示符,否则您的安装程序必须提升。
在 Ant 中,我执行如下操作:
请注意,我无法让 cacls 与单独的参数一起使用。我必须指定整条线。另请注意处理带有空格的目录(例如 Program Files)的引号转义。
I wouldn't use Cygwin for this. Instead, I use a combination of
cacls
andntrights
(from the XP resource kit - still works in 2008 / win 7). The only issue is that you have to run Ant as an administrator. This means that you need to either make sure you start an admin level cmd prompt or your installer has to to elevate.In Ant, I do something like the following:
Note that I couldn't get cacls to work with individual args. I had to specify the whole line. Also note the quote escape to handle directories with spaces (e.g. Program Files).