• <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讀書筆記

            国产成人精品久久二区二区| 精品无码久久久久久国产| 热久久最新网站获取| 久久亚洲国产成人影院| 久久久精品国产sm调教网站| 国产高潮国产高潮久久久91| 欧美麻豆久久久久久中文| 久久综合视频网| 久久精品国产影库免费看| 理论片午午伦夜理片久久| 久久久久无码精品国产| 久久久久久亚洲精品不卡| 日韩人妻无码一区二区三区久久| 91秦先生久久久久久久| 国产精品久久久久久久久久影院| 久久精品国产99国产电影网| 一级做a爰片久久毛片看看| 国产成人精品久久一区二区三区av| 久久久久久久久久久精品尤物 | 久久综合给合综合久久| 久久香蕉国产线看观看精品yw| 久久久久婷婷| 亚洲一本综合久久| 久久精品九九亚洲精品| 亚洲午夜久久久久久噜噜噜| 亚洲精品久久久www| 国产午夜精品理论片久久| 精品一区二区久久| 久久久久人妻一区精品色| 亚洲精品无码久久千人斩| 亚洲精品午夜国产VA久久成人| 久久久91精品国产一区二区三区 | 亚洲午夜久久久| 亚洲香蕉网久久综合影视| 久久亚洲AV无码西西人体| 秋霞久久国产精品电影院| 久久国产一区二区| 亚洲国产天堂久久综合网站| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 午夜视频久久久久一区| 久久国产热这里只有精品|