• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            那誰的技術博客

            感興趣領域:高性能服務器編程,存儲,算法,Linux內核
            隨筆 - 210, 文章 - 0, 評論 - 1183, 引用 - 0
            數據加載中……

            APUE2讀書筆記(一):real user ID, effective user ID,saved set-user-ID

            Unix中常見的幾個概念,下面做一個解釋.

            首先需要明確一點,這幾個概念都是和進程相關的.
            real user ID表示的是實際上進程的執行者是誰,effective user ID主要用于校驗該進程在執行時所獲得的文件訪問權限,也就是說當進程訪問文件時檢查權限時實際上檢查的該進程的"effective user ID",saved set-user-ID 僅在effective user ID發生改變時保存.

            一般情況下,real user ID就是進程的effective user ID,但是當要運行的可執行程序設置了"set-user-ID"位之后,進程的effective user ID變成該文件的屬主用戶id,同時該進程的"saved set-user-ID"變成此時進程的"effective user ID",也就是該可執行程序的屬主用戶ID,該進程在執行一些與文件訪問權限相關的操作時系統檢查的是進程的effective user ID.

            為什么需要一個"saved set-user-ID"?因為當進程沒有超級用戶權限的時候,進程在設置"effective user ID"時需要將需要設置的ID和該進程的"real user ID"或者"saved set-user-ID"進行比較.

            APUE2中進行的解釋是:
            1)If the process has superuser privileges, the setuid function sets the real user ID, effective user ID, and saved set-user-ID to uid.

            2)If the process does not have superuser privileges, but uid equals either the real user ID or the saved set-user-ID, setuid sets only the effective user ID to uid. The real user ID and the saved set-user-ID are not changed.

            3)If neither of these two conditions is true, errno is set to EPERM, and 1 is returned
            也就是說:
            1)當用戶具有超級用戶權限的時候,setuid 函數設置的id對三者都起效.
            2)否則,僅當該id為real user ID 或者saved set-user-ID時,該id對effective user ID起效.
            3)否則,setuid函數調用失敗.

            也就是說,這個saved set-user-ID更多的作用是在進程切換自己的effective user ID起作用.

            需要特別提醒的是:并沒有任何的API可以獲取到進程的saved set-user-ID,它僅僅是系統在調用setuid函數時進行比較而起作用的.
            APUE2中關于此事的原話如下:
            Note that we can obtain only the current value of the real user ID and the effective user ID with the functions getuid and geteuid from Section 8.2. We can't obtain the current value of the saved set-user-ID.


            舉一個例子說明問題,假設這樣的一種情況,系統中有兩個用戶A,B,還有一個由B創建的可執行程序proc,該可執行程序的set-
            user-id位已經進行了設置.

            當A用戶執行程序proc時,
            程序的real user ID = A的用戶ID,effective user ID = B的用戶ID,  saved set-user-ID=B的用戶ID.

            假如在該進程結束了對某些限制只能由用戶B訪問的文件操作后,程序將effective user ID設置回A,也就是說此時:
            程序的real user ID = A的用戶ID,effective user ID = A的用戶ID,  saved set-user-ID=B的用戶ID.

            這個改動之所以能成功,原因在于上面列舉出的情況2):該ID為進程的real user ID.

            最后,假設由于種種原因進程需要再次切換effective user ID為B,可是因為不能通過API獲取進程的saved set-user-ID(該值為B的用戶ID),所以只能通過兩種途徑獲得(可能還有別的途徑):
            a)在設置effective user ID變回A之前保存effective user ID,它的值為B的用戶ID.
            b)調用函數getpwnam( "B"),在返回的struct passwd *指針中成員pw_uid存放的就是用戶B的ID.
            這樣,這個調用setuid(B的用戶ID)就會成功,原因也在于上面說的情況2):該ID與進程的saved set-user-ID相同.

            APUE2中關于這幾個值的相關解釋在section4.4和section8.11中都有涉及.






            posted on 2007-12-20 23:24 那誰 閱讀(4980) 評論(0)  編輯 收藏 引用 所屬分類: Linux/Unix 、讀書筆記

            久久午夜无码鲁丝片秋霞| 亚洲伊人久久成综合人影院 | 性做久久久久久久久老女人| 久久狠狠一本精品综合网| 人妻丰满?V无码久久不卡| 伊人久久精品无码二区麻豆| 97精品伊人久久大香线蕉app| 日韩精品国产自在久久现线拍| 久久亚洲AV永久无码精品| 国产A三级久久精品| 狠狠色丁香久久综合婷婷| 女人高潮久久久叫人喷水| 久久99国产综合精品免费| 久久综合噜噜激激的五月天| 精品一区二区久久久久久久网站| 无码8090精品久久一区| 欧美一区二区精品久久| 人妻精品久久久久中文字幕一冢本| 久久久久中文字幕| 99久久精品免费看国产一区二区三区 | 一本色道久久综合亚洲精品| 日本道色综合久久影院| 久久精品久久久久观看99水蜜桃| 久久精品免费观看| 久久久亚洲AV波多野结衣| 久久精品国产欧美日韩| 久久国产精品-国产精品| 国内精品九九久久精品| 亚洲va久久久久| 久久久久久亚洲精品不卡 | 久久99精品国产麻豆蜜芽| 久久综合给合久久国产免费 | 精品精品国产自在久久高清| 99久久99久久精品国产片果冻| 午夜精品久久久久久| 久久久久国产一区二区三区| 久久中文字幕一区二区| 亚洲成色999久久网站| 伊人丁香狠狠色综合久久| 色综合色天天久久婷婷基地| 国产成人精品久久二区二区|