在FreeBSD,chmod +t file
是特權操作,如果file
不是一個目錄:在FreeBSD上,爲什麼chmod + t在非目錄上是特權操作?
$ 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.
同時,粘(7)解釋瞭如果file
不是目錄,那麼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上將一個非目錄標記爲粘滯是一項特權操作,其歷史或技術原因是什麼?爲什麼在這個地方發明了一個額外的錯誤代碼EFTYPE
它應該是EPERM
或ENOTDIR
?
從歷史上看,最初的Unix不允許這樣做。 [V7 chmod](http://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/man/man2/chmod.2)手冊頁說:「設置此位的能力限於超級用戶 由於交換空間被圖像消耗 「。我不能說爲什麼後代選擇保留這種禁止,即使他們不支持這些功能。 OpenBSD也禁止非root用戶在文件上設置粘滯位,返回EFTYPE。 Solaris默默地忽略非root用戶嘗試設置文件上的粘滯位(chmod()返回0,但不起作用)。 –
@MarkPlotnick你可以把它變成答案嗎?這回答了我的問題。 – fuz