﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-天下大事， 必作于细-随笔分类-Linux</title><link>http://www.cppblog.com/hongyoulee/category/11012.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 31 Jul 2009 07:56:20 GMT</lastBuildDate><pubDate>Fri, 31 Jul 2009 07:56:20 GMT</pubDate><ttl>60</ttl><item><title>LINUX核心</title><link>http://www.cppblog.com/hongyoulee/archive/2009/07/27/91365.html</link><dc:creator>友哥</dc:creator><author>友哥</author><pubDate>Mon, 27 Jul 2009 09:42:00 GMT</pubDate><guid>http://www.cppblog.com/hongyoulee/archive/2009/07/27/91365.html</guid><wfw:comment>http://www.cppblog.com/hongyoulee/comments/91365.html</wfw:comment><comments>http://www.cppblog.com/hongyoulee/archive/2009/07/27/91365.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/hongyoulee/comments/commentRss/91365.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/hongyoulee/services/trackbacks/91365.html</trackback:ping><description><![CDATA[<a href="http://net.pku.edu.cn/~yhf/lyceum/linuxK/tlk.html">http://net.pku.edu.cn/~yhf/lyceum/linuxK/tlk.html</a>
<img src ="http://www.cppblog.com/hongyoulee/aggbug/91365.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/hongyoulee/" target="_blank">友哥</a> 2009-07-27 17:42 <a href="http://www.cppblog.com/hongyoulee/archive/2009/07/27/91365.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>real user ID, effective user ID,saved set-user-ID</title><link>http://www.cppblog.com/hongyoulee/archive/2009/07/23/90976.html</link><dc:creator>友哥</dc:creator><author>友哥</author><pubDate>Thu, 23 Jul 2009 14:54:00 GMT</pubDate><guid>http://www.cppblog.com/hongyoulee/archive/2009/07/23/90976.html</guid><wfw:comment>http://www.cppblog.com/hongyoulee/comments/90976.html</wfw:comment><comments>http://www.cppblog.com/hongyoulee/archive/2009/07/23/90976.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/hongyoulee/comments/commentRss/90976.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/hongyoulee/services/trackbacks/90976.html</trackback:ping><description><![CDATA[<a href="http://hi.baidu.com/051156/blog/item/9813f7460452c6016a63e554.html">http://hi.baidu.com/051156/blog/item/9813f7460452c6016a63e554.html</a><br><a href="http://hi.baidu.com/051156/blog/item/9813f7460452c6016a63e554.html">http://hi.baidu.com/051156/blog/item/9813f7460452c6016a63e554.html</a><br><a href="http://sunlit.javaeye.com/blog/400898">http://sunlit.javaeye.com/blog/400898</a><br><br>
<p>Unix中，每个进程都包含三个ID：<strong>real user ID，effective user ID，saved set user ID</strong>。<br><br><strong>real user ID</strong>表示的是实际上进程的执行者是谁。<br><strong>effective user ID</strong>主要用于校验该进程在执行时所获得的文件访问权限,也就是说当进程需要访问文件，系统检查权限时实际上检查的该进程的"effective user ID"，或者是effective user ID 告诉系统，该进程在对资源访问时，具有等同于哪个用户的权限。<br><strong>saved set-user-ID</strong> 仅在effective user ID发生改变时保存。（这个看了后面的例子就明白了^_^）<br><br>一般情况下,real user ID就是进程的effective user ID,但是当要运行的可执行程序设置了"<span class=docEmphasis>set-user-ID</span>"位之后,进程的effective user ID变成该文件的属主用户id,同时该进程的"saved set-user-ID"变成此时进程的"effective user ID",也就是该可执行程序的属主用户ID,该进程在执行一些与文件访问权限相关的操作时系统检查的是进程的effective user ID.<br><br>为什么需要一个"saved set-user-ID"?因为当进程没有超级用户权限的时候,进程在设置"effective user ID"时需要将需要设置的ID和该进程的"real user ID"或者"saved set-user-ID"进行比较.<br><br>APUE2中进行的解释是:<br>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.</p>
<p>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.</p>
<p>3)If neither of these two conditions is true, errno is set to EPERM, and 1 is returned<br>也就是说:<br>1)当用户具有超级用户权限的时候,setuid 函数设置的id对三者都起效.<br>2)否则,仅当该id为real user ID 或者saved set-user-ID时,该id对effective user ID起效.<br>3)否则,setuid函数调用失败.<br><br>也就是说,这个saved set-user-ID更多的作用是在进程切换自己的effective user ID起作用.<br><br>需要特别提醒的是:并没有任何的API可以获取到进程的saved set-user-ID,它仅仅是系统在调用setuid函数时进行比较而起作用的.<br>APUE2中关于此事的原话如下:<br>Note that we can obtain only the current value of the real user ID and the effective user ID with the functions <tt><font face=NSimsun>getuid</font></tt> and <tt><font face=NSimsun>geteuid</font></tt> from Section 8.2. We can't obtain the current value of the saved set-user-ID.</p>
<p><br>举一个例子说明问题,假设这样的一种情况,系统中有两个用户A,B,还有一个由B创建的可执行程序proc,该可执行程序的set-<br>user-id位已经进行了设置.<br><br>当A用户执行程序proc时,<br>程序的real user ID = A的用户ID,effective user ID = B的用户ID, saved set-user-ID=B的用户ID.<br><br>假如在该进程结束了对某些限制只能由用户B访问的文件操作后,程序将effective user ID设置回A,也就是说此时:<br>程序的real user ID = A的用户ID,effective user ID = A的用户ID, saved set-user-ID=B的用户ID.<br><br>这个改动之所以能成功,原因在于上面列举出的情况2):该ID为进程的real user ID.<br><br>最后,假设由于种种原因进程需要再次切换effective user ID为B,可是因为不能通过API获取进程的saved set-user-ID(该值为B的用户ID),所以只能通过两种途径获得(可能还有别的途径):<br>a)在设置effective user ID变回A之前保存effective user ID,它的值为B的用户ID.<br>b)调用函数getpwnam( "B"),在返回的struct passwd *指针中成员pw_uid存放的就是用户B的ID.<br>这样,这个调用setuid(B的用户ID)就会成功,原因也在于上面说的情况2):该ID与进程的saved set-user-ID相同.</p>
<img src ="http://www.cppblog.com/hongyoulee/aggbug/90976.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/hongyoulee/" target="_blank">友哥</a> 2009-07-23 22:54 <a href="http://www.cppblog.com/hongyoulee/archive/2009/07/23/90976.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>系统学习Linux系列之Linux系统编程</title><link>http://www.cppblog.com/hongyoulee/archive/2009/07/06/89356.html</link><dc:creator>友哥</dc:creator><author>友哥</author><pubDate>Mon, 06 Jul 2009 05:41:00 GMT</pubDate><guid>http://www.cppblog.com/hongyoulee/archive/2009/07/06/89356.html</guid><wfw:comment>http://www.cppblog.com/hongyoulee/comments/89356.html</wfw:comment><comments>http://www.cppblog.com/hongyoulee/archive/2009/07/06/89356.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/hongyoulee/comments/commentRss/89356.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/hongyoulee/services/trackbacks/89356.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/yy_msdn/category/391487.aspx">http://blog.csdn.net/yy_msdn/category/391487.aspx</a>
<img src ="http://www.cppblog.com/hongyoulee/aggbug/89356.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/hongyoulee/" target="_blank">友哥</a> 2009-07-06 13:41 <a href="http://www.cppblog.com/hongyoulee/archive/2009/07/06/89356.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux目录名和常见后缀的渊源</title><link>http://www.cppblog.com/hongyoulee/archive/2009/06/27/88615.html</link><dc:creator>友哥</dc:creator><author>友哥</author><pubDate>Fri, 26 Jun 2009 16:26:00 GMT</pubDate><guid>http://www.cppblog.com/hongyoulee/archive/2009/06/27/88615.html</guid><wfw:comment>http://www.cppblog.com/hongyoulee/comments/88615.html</wfw:comment><comments>http://www.cppblog.com/hongyoulee/archive/2009/06/27/88615.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/hongyoulee/comments/commentRss/88615.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/hongyoulee/services/trackbacks/88615.html</trackback:ping><description><![CDATA[Unix已经有35年历史了。许多人认为它开始于中世纪，这个中世纪是相对于计算机技术的产生和发展来说的。在过去的时间里，Unix和它的子分支Linux收集有许多的历史和一些完全古老的语言。在这篇技巧文章中，我们将介绍一少部分古老的语言和它们的目的和作用，以及它们真正的来源。 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　RC &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　在Linux中，最为常用的缩略语也许是&#8220;rc&#8221;，它是&#8220;runcomm&#8221;的缩写――即名词&#8220;run &nbsp; command&#8221;(运行命令)的简写。今天，&#8220;rc&#8221;是任何脚本类文件的后缀，这些脚本通常在程序的启动阶段被调用，通常是Linux系统启动时。如 &nbsp; /etc/rs是Linux启动的主脚本，而.bashrc是当Linux的bash &nbsp; shell启动后所运行的脚本。.bashrc的前缀&#8220;.&#8221;是一个命名标准，它被设计用来在用户文件中隐藏那些用户指定的特殊文件;&#8220;ls&#8221;命令默认情况下不会列出此类文件，&#8220;rm&#8221;默认情况下也不会删除它们。许多程序在启动时，都需要&#8220;rc&#8221;后缀的初始文件或配置文件，这对于Unix的文件系统视图来说，没有什么神秘的。 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　ETC &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　在&#8220;etc/bin&#8221;中的&#8220;etc&#8221;真正代表的是&#8220;etcetera&#8221;(附加物)。在早期的Unix系统中，最为重要的目录是&#8220;bin&#8221;目录 &nbsp; (&#8220;bin&#8221;是&#8220;binaries&#8221;二进制文件――编译后的程序的缩写)，&#8220;etc&#8221;中则包含琐碎的程序，如启动、关机和管理。运行一个Linux必须的东西的列表是:一个二进制程序，etcetera，etcetera――换句话说，是一个底层的重要项目，通常添加一些次等重要的零碎事物。今天， &nbsp; &#8220;etc&#8221;包含了广泛的系统配置文件，这些配置文件几乎包含了系统配置的方方面面，同样非常重要。 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　Bin &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　今天，许多在Linux上运行的大型子系统，如GNOME或Oracle，所编译成的程序使用它们自己的&#8220;bin&#8221;目录(或者是 &nbsp; /usr/bin，或者是/usr/local/bin)作为标准的存放地。同样，现在也能够在这些目录看到脚本文件，因为&#8220;bin&#8221;目录通常添加到用户的PATH路径中，这样他们才能够正常的使用程序。因此运行脚本通常在bin中运行良好。 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　TTY &nbsp; <br>&nbsp; &nbsp; <br><clk style="FONT-SIZE: 12px">&nbsp; 　　在Linux中，TTY也许是跟终端有关系的最为混乱的术语。TTY是TeleTYpe的一个老缩写。Teletypes，或者 &nbsp; teletypewriters，原来指的是电传打字机，是通过串行线用打印机键盘通过阅读和发送信息的东西，和古老的电报机区别并不是很大。之后，当计算机只能以批处理方式运行时(当时穿孔卡片阅读器是唯一一种使程序载入运行的方式)，电传打字机成为唯一能够被使用的&#8220;实时&#8221;输入/输出设备。最终，电传打字机被键盘和显示器终端所取代，但在终端或 &nbsp; TTY接插的地方，操作系统仍然需要一个程序来监视串行端口。一个getty&#8220;Get &nbsp; TTY&#8221;的处理过程是:一个程序监视物理的TTY/终端接口。对一个虚拟<nobr oncontextmenu="return false" onmousemove=$cE.MoW() id=clickeyekey1 onmouseover=$cE.s(event,1) style="FONT-SIZE: 12px; COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick='$cE.defer(this);$cE.c(event,1,"",1)' onmouseout=$cE.OuK()>网络</nobr>沮丧服务器(VNC)来说，一个伪装的TTY(Pseudo-TTY，即家猫的TTY，也叫做&#8220;PTY&#8221;)是等价的终端。当你运行一个xterm(终端仿真程序)或GNOME终端程序时，PTY对虚拟的用户或者如xterm一样的伪终端来说，就像是一个TTY在运行。&#8220;Pseudo&#8221;的意思是&#8220;duplicating &nbsp; in &nbsp; a &nbsp; fake &nbsp; way&#8221;(用伪造的方法复制)，它相比&#8220;virtual&#8221;或&#8220;emulated&#8221;更能真实的说明问题。而在现在的计算中，它却处于被放弃的阶段。 &nbsp; </clk><br>&nbsp; &nbsp; <br>&nbsp; 　　Dev &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 　　从TTY留下的命令有&#8220;stty&#8221;，是&#8220;set &nbsp; tty&#8221;(设置TTY)的缩写，它能够生成一个配置文件/etc/initab(&#8220;initialization &nbsp; table&#8221;，初始表)，以配置gettys使用哪一个串口。在现代，直接附加在Linux窗口上的唯一终端通常是控制台，由于它是特殊的TTY，因此被命名为&#8220;console&#8221;。当然，一旦你启动X11，&#8220;console&#8221;TTY就会消失，再也不能使用串口协议。所有的TTY都被储存在&#8220;/dev&#8221;目录，它是&#8220;[physical] &nbsp; devices&#8221;([物理]设备)的缩写。以前，你必须在电脑后面的串口中接入一个新的终端时，手工修改和配置每一个设备文件。现在，Linux(和 &nbsp; Unix)在安装过程中就在此目录中创建了它所能向导的每一个设备的文件。这就是说，你很少需要自己创建它。&nbsp;&nbsp; 
<img src ="http://www.cppblog.com/hongyoulee/aggbug/88615.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/hongyoulee/" target="_blank">友哥</a> 2009-06-27 00:26 <a href="http://www.cppblog.com/hongyoulee/archive/2009/06/27/88615.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>