{"id":431,"date":"2016-08-29T09:49:15","date_gmt":"2016-08-29T01:49:15","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=431"},"modified":"2016-12-01T15:27:19","modified_gmt":"2016-12-01T07:27:19","slug":"%e6%94%b9%e5%8f%98uid%e5%92%8cgid","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=431","title":{"rendered":"\u6539\u53d8UID\u548cGID"},"content":{"rendered":"<p>\u5728UNIX\u7cfb\u7edf\u4e2d\uff0c\u6240\u6709\u7684\u6743\u9650\u90fd\u662f\u4f9d\u8d56\u4e8eUID\u548cGID\u7684\u3002<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\u5e94\u8be5\u8ba9\u7a0b\u5e8f\u4f7f\u7528\u6700\u5c0f\u6743\u9650\u6a21\u578b\u3002\u8fd9\u53ef\u4ee5\u51cf\u5c11\u4e00\u4e9b\u5b89\u5168\u98ce\u9669\u3002<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528<span style=\"color: #993300;\">setuid<\/span>\u548c<span style=\"color: #993300;\">setgid<\/span>\u51fd\u6570\u6539\u53d8\u5b9e\u9645UID\u3001\u5b9e\u9645GID\u3001\u6709\u6548UID\u548c\u6709\u6548GID\uff1a<\/p>\n<table class=\"allBorders\" style=\"height: 248px;\" border=\"1\" width=\"516\" rules=\"none\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<pre><span style=\"color: #993300;\">#include &lt;unistd.h&gt;\r\n\r\nint setuid(uid_t <span class=\"docEmphItalicAlt\">uid<\/span>);\r\n\r\nint setgid(gid_t <span class=\"docEmphItalicAlt\">gid<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Both return: 0 if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ec0\u4e48\u6837\u7684\u7528\u6237\u53ef\u4ee5\u6539\u53d8ID\u503c\uff1a<\/p>\n<ol>\n<li>\u5982\u679c\u8fdb\u7a0b\u62e5\u6709\u8d85\u7ea7\u7528\u6237\u7684\u6743\u9650<\/li>\n<li>\u5982\u679c\u8fdb\u7a0b\u6ca1\u6709\u8d85\u7ea7\u7528\u6237\u7684\u6743\u9650\uff0c\u4f46<em>uid<\/em>\u7b49\u4e8e\u5b9e\u9645UID\u6216saved set-user-ID\uff0c\u90a3\u4e48<span style=\"color: #993300;\">setuid<\/span>\u53ea\u80fd\u8bbe\u7f6e\u6709\u6548\u7528\u6237ID\u5230<em>uid<\/em>\u3002<\/li>\n<li>\u5982\u4e0d\u662f\u4ee5\u4e0a\u4e24\u79cd\u6761\u4ef6\uff0c<span style=\"color: #993300;\">errno<\/span>\u88ab\u8bbe\u7f6e\u6210<span style=\"color: #993300;\">EPERM<\/span>\uff0c\u5e76\u4e14\u8fd4\u56de1\u3002<\/li>\n<\/ol>\n<p>\u5728\u8fd9\u6211\u4eec\u5047\u5b9a<span style=\"color: #993300;\">_POSIX_SAVED_IDS<\/span>\u4e3a\u771f\uff0c\u5982\u679c\u4e0d\u652f\u6301\u8fd9\u4e2a\u529f\u80fd\uff0c\u90a3\u4e48\u5220\u9664\u4e4b\u524d\u6307\u5411saved set-user-ID\u7684\u6240\u6709\u7d22\u5f15\u3002<\/p>\n<p>\u5173\u4e8e\u5185\u6838\u7ef4\u62a4\u7684\u4e09\u79cd\u7528\u6237ID\u7684\u8bf4\u660e\uff1a<\/p>\n<ol>\n<li>\u53ea\u6709\u8d85\u7ea7\u7528\u6237\u8fdb\u7a0b\u53ef\u4ee5\u6539\u53d8\u5b9e\u9645\u7528\u6237ID\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u5b9e\u9645\u7528\u6237ID\u88ab<span style=\"color: #993300;\">login<\/span>\u7a0b\u5e8f\u8bbe\u7f6e\uff0c\u5f53\u767b\u8def\u7cfb\u7edf\u540e\u5c31\u4e0d\u518d\u6539\u53d8\u3002\u56e0\u4e3a<span style=\"color: #993300;\">login<\/span>\u662f\u8d85\u7ea7\u7528\u6237\u8fdb\u7a0b\uff0c\u6240\u4ee5\u5b83\u53ef\u4ee5\u4f7f\u7528<span style=\"color: #993300;\">setuid<\/span>\u8bbe\u7f6e\u4e09\u79cd\u7528\u6237ID<\/li>\n<li>\u5f53\u7a0b\u5e8f\u6587\u4ef6\u5df2\u7ecf\u8bbe\u7f6e\u4e86SUID\u4f4d\u65f6\uff0c\u6709\u6548\u7528\u6237ID\u7531<span style=\"color: #993300;\">exec<\/span>\u51fd\u6570\u8bbe\u7f6e\u3002\u5982\u679cSUID\u4f4d\u6ca1\u8bbe\u7f6e\uff0c\u90a3\u4e48\u6709\u6548ID\u4fdd\u7559\u5f53\u524d\u503c\u3002\u53ef\u4ee5\u968f\u65f6\u8c03\u7528setuid\u8bbe\u7f6e\u6709\u6548\u7528\u6237ID\u4e3a\u5b9e\u9645\u7528\u6237ID\u6216saved set-user-ID\u3002\u6b63\u5e38\u6765\u8bf4\u4e0d\u80fd\u8bbe\u7f6e\u6709\u6548\u7528\u6237ID\u5230\u968f\u673a\u503c\u3002<\/li>\n<li>saved set-user-ID\u662f\u7531exec\u51fd\u6570\u4ece\u6709\u6548\u7528\u6237ID\u90a3\u91cc\u590d\u5236\u6765\u7684\u3002\u5982\u679cSUID\u5df2\u7ecf\u8bbe\u7f6e\uff0c\u5728exec\u540e\u4fdd\u5b58\u6587\u4ef6\u7684UID\u5230\u6709\u6548\u7528\u6237ID\u4e2d\u3002<\/li>\n<\/ol>\n<p>\uff08\u8fd9\u91cc\u5173\u4e8esaved set-user-ID\u8fd8\u662f\u633a\u590d\u6742\u7684\uff0c\u4e3b\u8981\u662f\u6709\u4e00\u4e2a\u5173\u4e8e<span style=\"color: #993300;\">man<\/span>\u7684\u4f8b\u5b50\uff0c\u8fd8\u662f\u770bAPUE\u76848.11\u8282\u5427\uff01\uff09<\/p>\n<h2><span style=\"color: #993300;\">setreuid<\/span>\u548c<span style=\"color: #993300;\">setregid<\/span>\u51fd\u6570<\/h2>\n<p>\u5386\u53f2\u4e0a\uff0cBSD\u652f\u6301\u4f7f\u7528<span style=\"color: #993300;\">setreuid<\/span>\u51fd\u6570\u4ea4\u6362\u5b9e\u9645UID\u548c\u6709\u6548UID\u3002<\/p>\n<table class=\"allBorders\" style=\"height: 278px;\" border=\"1\" width=\"431\" rules=\"none\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<pre>   #include &lt;unistd.h&gt;\r\n\r\n   int setreuid(uid_t <span class=\"docEmphItalicAlt\">ruid<\/span>, uid_t <span class=\"docEmphItalicAlt\">euid<\/span>);\r\n\r\n   int setregid(gid_t <span class=\"docEmphItalicAlt\">rgid<\/span>, gid_t <span class=\"docEmphItalicAlt\">egid<\/span>);\r\n<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Both return: 0 if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u53c2\u6570\u8bbe\u7f6e\u62101\u8868\u793a\u4fdd\u7559\u76f8\u5e94\u7684ID\uff0c\u4e0d\u505a\u6539\u53d8\u3002<\/p>\n<p>\u89c4\u5219\u5f88\u7b80\u5355\uff1a\u4e00\u4e2a\u65e0\u7279\u6743\u7684\u7528\u6237\u53ef\u4ee5\u4ea4\u6362\u5b9e\u9645\u7528\u6237ID\u548c\u6709\u6548\u7528\u6237ID\u3002\u8fd9\u5141\u8bb8\u4e00\u4e2a\u8bbe\u7f6e\u4e86SUID\u7684\u7a0b\u5e8f\u4ea4\u6362UID\u548c\u6709\u6548UID\u5e76\u5728\u4e4b\u540e\u518d\u4ea4\u6362\u56de\u53bb\u3002\u5f53saved set-user-ID\u88ab\u5f15\u5165POSIX.1\u65f6\uff0c\u8fd9\u4e2a\u529f\u80fd\u88ab\u589e\u5f3a\u5230\u53ef\u4ee5\u4ea4\u6362\u6709\u6548\u7528\u6237ID\u548csaved set-user-ID\u3002<\/p>\n<h2><span style=\"color: #993300;\">seteuid<\/span>\u548c<span style=\"color: #993300;\">setegid<\/span>\u51fd\u6570<\/h2>\n<p>POSIX.1\u5305\u542b\u4e86<span style=\"color: #993300;\">seteuid<\/span>\u548c<span style=\"color: #993300;\">setegid<\/span>\u4e24\u4e2a\u51fd\u6570\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u7c7b\u4f3c\u4e8e<span style=\"color: #993300;\">setuid<\/span>\u548c<span style=\"color: #993300;\">setgid<\/span>\uff0c\u4f46\u662f\u53ea\u80fd\u6539\u53d8\u6709\u6548\u7528\u6237ID\u548c\u6709\u6548\u7528\u6237\u7ec4ID\u3002<\/p>\n<table class=\"allBorders\" style=\"height: 268px;\" border=\"1\" width=\"441\" rules=\"none\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<pre><span style=\"color: #993300;\">#include &lt;unistd.h&gt;\r\n\r\nint seteuid(uid_t <span class=\"docEmphItalicAlt\">uid<\/span>);\r\n\r\nint setegid(gid_t <span class=\"docEmphItalicAlt\">gid<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Both return: 0 if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5bf9\u4e8e\u65e0\u7279\u6743\u7528\u6237\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u8bbe\u7f6e\u6709\u6548\u7528\u6237ID\u6210\u5b9e\u9645\u7528\u6237ID\u6216\u5b83\u7684saved set-user-ID\u3002\u5bf9\u4e8e\u7279\u6743\u7528\u6237\uff0c\u6709\u6548\u7528\u6237ID\u53ea\u80fd\u8bbe\u7f6e\u6210<em>uid<\/em>\u3002\uff08\u5b83\u4e0d\u540c\u4e8e<span style=\"color: #993300;\">setuid<\/span>\u51fd\uff0c<span style=\"color: #993300;\">setuid<\/span>\u53ef\u4ee5\u6539\u53d8\u6240\u6709\u4e09\u79cd\u7528\u6237ID\u2014\u2014\u5b9e\u9645\u7528\u6237ID\u3001\u6709\u6548\u7528\u6237ID\u548csaved set-user-ID\uff09<\/p>\n<h2>\u4e0b\u56fe\u6c47\u603b\u4e86\u5404\u79cd\u6539\u53d8\u6237\u7528ID\u51fd\u6570\u7684\u529f\u80fd<\/h2>\n<figure id=\"attachment_437\" aria-describedby=\"caption-attachment-437\" style=\"width: 765px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-437\" src=\"http:\/\/blog.5x44.cn\/wp-content\/uploads\/2016\/08\/change_uid.jpg\" alt=\"Summary of all the functions that set the various user IDs\" width=\"765\" height=\"421\" srcset=\"https:\/\/www.5x44.cn\/wp-content\/uploads\/2016\/08\/change_uid.jpg 759w, https:\/\/www.5x44.cn\/wp-content\/uploads\/2016\/08\/change_uid-300x165.jpg 300w\" sizes=\"auto, (max-width: 765px) 100vw, 765px\" \/><figcaption id=\"caption-attachment-437\" class=\"wp-caption-text\">Summary of all the functions that set the various user IDs<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5728UNIX\u7cfb\u7edf\u4e2d\uff0c\u6240\u6709\u7684\u6743\u9650\u90fd\u662f\u4f9d\u8d56\u4e8eUID\u548cGID\u7684\u3002 \u4e00\u822c\u6765\u8bf4\u5e94\u8be5\u8ba9\u7a0b\u5e8f\u4f7f\u7528\u6700\u5c0f\u6743\u9650\u6a21\u578b\u3002\u8fd9\u53ef\u4ee5\u51cf\u5c11\u4e00\u4e9b\u5b89\u5168\u98ce\u9669\u3002 \u53ef\u4ee5\u4f7f\u7528setuid\u548csetgid\u51fd\u6570\u6539&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=431\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-431","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=431"}],"version-history":[{"count":5,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/431\/revisions"}],"predecessor-version":[{"id":438,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/431\/revisions\/438"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}