• <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 那誰 閱讀(4990) 評論(0)  編輯 收藏 引用 所屬分類: Linux/Unix讀書筆記

            久久久久久国产精品免费免费| 久久亚洲精品无码播放| 亚洲香蕉网久久综合影视| 亚洲伊人久久精品影院| 狠狠久久亚洲欧美专区| 激情综合色综合久久综合| 久久久亚洲AV波多野结衣| 狠狠狠色丁香婷婷综合久久俺| 青青草国产97免久久费观看| 久久久无码一区二区三区| 久久精品国产亚洲7777| 丁香色欲久久久久久综合网| 久久天堂电影网| 亚洲精品无码久久久久去q | 久久香蕉国产线看观看乱码| 久久久青草青青国产亚洲免观| 热re99久久精品国99热| 久久不见久久见免费影院www日本| 久久久噜噜噜久久中文字幕色伊伊| 99久久99这里只有免费费精品| 亚洲国产日韩综合久久精品| 蜜桃麻豆www久久| 无码精品久久久久久人妻中字| 久久婷婷五月综合97色直播| 午夜不卡888久久| 久久综合久久综合九色| 国产亚洲精久久久久久无码| 中文字幕无码免费久久| 国产精品成人久久久| 久久久久这里只有精品| 99久久婷婷国产一区二区| 成人久久综合网| 日本久久久久久中文字幕| 精品国际久久久久999波多野| 色诱久久久久综合网ywww| 少妇人妻综合久久中文字幕| 日本五月天婷久久网站| 久久人人爽人人爽人人片AV不 | 久久精品人妻一区二区三区| 97久久香蕉国产线看观看| 国产成年无码久久久久毛片|