【问题标题】:How/why cygwin breaks windows permissions?cygwin 如何/为什么会破坏 Windows 权限?
【发布时间】:2021-04-13 22:08:47
【问题描述】:

我们“从现场”(即来自安装软件的系统管理员)抱怨 cygwin 在 NTFS(Windows 7/10/2008/2012 等)上“弄乱”了 Windows 权限。

问题用例

一般用例是这样的:

  • 系统管理员从 cygwin bash cmd 行启动一些“软件安装程序”
  • 安装程序运行良好
  • 系统管理员尝试启动 Windows 服务

结果: 服务启动失败

解决方法步骤

这些步骤似乎解决了问题:

  • Sysadmin 使用 windows ICACLS 命令重置 ntfs 权限:(在此示例中,“acme”是新创建的目录。此命令设置 acme 及其子级从文件夹“d:\instances”重新继承权限

    d:\instances> icacls acme /RESET /T /C /Q

  • 系统管理员启动服务

结果: Windows 服务启动

问题

  • 是什么让 cygwin 处理新写入文件的权限与 powershell 不同?是umask版本错误的问题吗?
  • 系统管理员能否提前采取措施确保 cygwin 正确设置权限?

提前致谢

【问题讨论】:

  • 一个 icacls 输出损坏和正确文件的示例可以提供一些提示。您确定从 cygwin 和 power shell 安装的用户相同吗?
  • 我有 90% 的把握“只有在用户 X 从 cygwin 安装时才会出现问题,但是,如果用户 X 使用 powershell,则会出现问题”。我也知道我们已经看到另一个用例的问题:a)“从 cygwin 安装 UserX”和 b)“用户 Y 无法删除文件,因为 UserX 拥有它们”。
  • cygwin.com/cygwin-ug-net/ntsec.html 上的“文件权限”一章解释了为什么 Cygwin 对 ACL 进行排序,这是不规范的。它既不破坏任何东西,也不违背定义。这是将 Posix 权限映射到 ACL 的唯一方法。

标签: security cygwin ntfs


【解决方案1】:

我找到了答案here;它指的是this mailing-list letter。

您需要编辑 Cygwin 的 /etc/fstab 并将“noacl”添加到安装选项列表中。

【讨论】:

  • 您应该在此处发布解决方案(并保留引用),因为 URL 可能会更改/消失,如果发生这种情况,答案将变得无效。
  • 请注意,设置“noacl”将不允许 Cygwin 使用 Posix 文件权限,如可执行位。 IE。您正在削减 Cygwin/Posix 功能,并且可能会遇到 Cygwin 工具的问题。
【解决方案2】:

为了补充 ulathek 的答案,这里是两个 URL 的复制粘贴:

第一:

How to fix incorrect Cygwin permission in Windows 7

Cygwin started to behave quite strangely after recent updates. I was not able to edit files in vim, because it was complaining that files are read only. Even cp -r didn’t work correctly. Permission of new directory was broken and I was not able to remove it. Pretty weird behavior.

E.g. ls -l

total 2
----------+ 1 georgik None 34 Jul 14 18:09 index.jade
----------+ 1 georgik None 109 Jul 14 17:40 layout.jade

Hm. It is clear that something is wrong with permission. Even owner has no permission on those files.

Output of mount command:

C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)

I found a solution at cygwin forum. It’s quite easy to fix it.

Open /etc/fstab and enter following line:

none /cygdrive cygdrive binary,noacl,posix=0,user 0 0

Save it. Close all cygwin terminals and start new terminal.

Output of mount:

C: on /cygdrive/c type ntfs (binary,noacl,posix=0,user,noumount,auto)

Output of ls -l

total 2
-rw-r--r-- 1 georgik None 34 Jul 14 18:09 index.jade
-rw-r--r-- 1 georgik None 109 Jul 14 17:40 layout.jade

第二:

7/14/2010 10:57 AM
> Drive Y is a mapping to a network location. Interestingly, ls -l
>> /cygdrive returns:
>>   d---------+ 1 ????????       ????????     24576 2010-07-09 11:18 c
>>   drwx------+ 1 Administrators Domain Users     0 2010-07-14 06:58 y
>>
>> The c folder looks weird, the y folder looks correct.
>>     
> Try ls -ln /cygdrive.  The user and group ownerships on the root of the
> C: drive are most likely not found in your passwd and group files.  The
> -n option for ls will print the user and group IDs rather than try to
> look up their names.  Unfortunately, I can't think of any way offhand to
> generate the passwd and group entries given only user and group IDs.
> Maybe someone else can comment on that.
>   

I think your answer is correct:
  $ ls -ln /cygdrive
  total 24
  d---------+ 1 4294967295 4294967295 24576 2010-07-09 11:18 c
  drwx------+ 1        544      10513     0 2010-07-14 11:45 y

I edited my /etc/fstab file (it contained only commented lines) and
added this line at the end of the file:
  none /cygdrive cygdrive binary,noacl,posix=0,user 0 0

I closed all my Cygwin processes, opened a new terminal and did an ls-l
on visitor.cpp again:
  -rw-r--r-- 1 cory Domain Users 3236 2010-07-11 22:37 visitor.cpp

Success!!! The permissions are now reported as 644 rather than 000 and I
can edit the file with Cygwin vim and not have bogus read-only issues.
Thank you Jeremy.

cory

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多