Saturday, August 7, 2010

selinux的restorecon根據

給未來的裕翔

當以restorecon對某個檔案或目錄進行恢復context時

它是以根據的

可用semanage fcontext -l來看那些根據, ex:
/var/www/nut-cgi-bin/upsstats\.cgi                 regular file       system_u:object_r:httpd_nutups_cgi_script_exec_t:s0
/var/www/perl(/.*)? all files system_u:object_r:httpd_sys_script_exec_t:s0
/var/www/svn(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0

今天如果我把/var/www/html的index.html複製到別的資料夾去, ex: /se-test

如果直接cp, 的context會變成:

unconfined_u:object_r:default_t:s0

如果用cp -a, 它的context會跟原本一樣:

unconfined_u:object_r:httpd_sys_content_t:s0

而那個/se-test是自己隨便建立的, context是

unconfined_u:object_r:default_t:s0

所以, 當我對裡面的檔案進行restorecon

index.html也只會變成unconfined_u:object_r:default_t:s0

不會變成unconfined_u:object_r:httpd_sys_content_t:s0

除了我手動chcon -t httpd_sys_content_t index.html

有辦法讓它(/se-test)預設就是httpd_sys_content_t嗎?

可以呦~^^

新增一個restorecon的根據

semanage fcontext -a -t httpd_sys_content_t '/se-test(/.*)?'

-a是add

-t是type

'/se-test(/.*)?'是什麼呢! 是什麼呢? 有誰知道是什麼嗎?

總之, restorecon的根據建立完成^^

之後對/se-test或裡面檔案進行restorecon就會變成

httpd_sys_content_t

No comments:

Post a Comment