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

            人妻少妇精品久久| 久久精品国产亚洲AV大全| 国产伊人久久| 伊人久久大香线蕉综合热线| 久久无码国产专区精品| 日韩精品久久无码人妻中文字幕| 97精品伊人久久大香线蕉app| 91精品国产91久久久久久| 亚洲欧洲久久av| 91久久精品91久久性色| 久久人人爽人人爽AV片| 潮喷大喷水系列无码久久精品 | 亚洲v国产v天堂a无码久久| 久久国产劲爆AV内射—百度| 一本色道久久88加勒比—综合| 少妇无套内谢久久久久| 国产高潮国产高潮久久久91 | 97精品伊人久久大香线蕉| 97精品伊人久久久大香线蕉 | 久久青草国产精品一区| 久久精品国产亚洲AV忘忧草18| 亚洲国产精品久久久久网站| 综合久久国产九一剧情麻豆| 久久夜色精品国产亚洲av| 久久亚洲中文字幕精品有坂深雪| 久久久无码精品午夜| 久久午夜电影网| AV无码久久久久不卡蜜桃| 少妇久久久久久被弄高潮| 亚洲伊人久久精品影院| 性高朝久久久久久久久久| 久久无码人妻精品一区二区三区| 久久久久久A亚洲欧洲AV冫 | 99久久精品国产麻豆| 久久久久久人妻无码| 亚洲精品白浆高清久久久久久| 国产精品伊人久久伊人电影| 亚洲AV日韩精品久久久久| 久久精品人人做人人爽电影| 伊人久久国产免费观看视频| 久久精品国产2020|