【发布时间】:2016-01-26 11:53:43
【问题描述】:
在 FreeBSD 上,如果 <em>file</em> 不是目录,chmod +t <em>file</em> 是特权操作:
$ echo >test
$ chmod +t test
chmod: test: Inappropriate file type or format
$ su
Password:
# chmod +t test
# ls -l test
-rw-r--r-T 1 fuz wheel 1 Jan 26 12:44 test
chmod(2) 记录了这种行为:
[EFTYPE] The effective user ID is not the super-user, the mode
includes the sticky bit (S_ISVTX), and path does not
refer to a directory.
同时,sticky(7) 解释说如果<em>file</em> 不是目录,S_ISVTX 将被忽略:
A special file mode, called the sticky bit (mode S_ISTXT), is used to
indicate special treatment for directories. It is ignored for regular
files. See chmod(2) or the file <sys/stat.h> for an explanation of file
modes.
在 FreeBSD 上将非目录标记为粘性是一项特权操作的历史或技术原因是什么?为什么在应该是EPERM 或ENOTDIR 的地方为此发明了一个额外的错误代码EFTYPE?
【问题讨论】:
-
从历史上看,最初的 Unix 不允许这样做。 V7 chmod 手册页说“设置此位的能力仅限于超级用户,因为图像消耗了交换空间”。我不能说为什么后代选择保留这个禁令,即使他们不支持这个功能。 OpenBSD 还禁止非 root 用户在文件上设置粘性位,返回 EFTYPE。 Solaris 会默默地忽略非 root 用户对文件设置粘性位的尝试(chmod() 返回 0 但没有效果)。
-
@MarkPlotnick 你能把这个变成答案吗?这回答了我的问题。