1 .\" Copyright (C), 1994, Graeme W. Wilford (Wilf).
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Fri Jul 29th 12:56:44 BST 1994 Wilf. <G.Wilford@ee.surrey.ac.uk>
24 .\" Changes inspired by patch from Richard Kettlewell
25 .\" <richard@greenend.org.uk>, aeb 970616.
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added notes on capability requirements
29 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
30 .\" all rights reserved.
31 .\" Translated Sat Mar 1 16:32:11 JST 1997
32 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
33 .\" Modified Sun Sep 28 20:26:49 JST 1997
34 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
35 .\" Updated & Modified Sat May 22 18:21:45 JST 2004
36 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
37 .\" Updated & Modified Wed Jan 5 00:51:28 JST 2005 by Yuichi SATO
38 .\" Updated 2010-04-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.24
40 .\"WORD: identity ¼±ÊÌ
41 .\"WORD: effective user ID ¼Â¸ú¥æ¡¼¥¶¡¼ID
42 .\"WORD: real user ID ¼Â¥æ¡¼¥¶¡¼ID
43 .\"WORD: saved user ID Êݸ¥æ¡¼¥¶¡¼ID
44 .\"WORD: implement ¼ÂÁõ
46 .\"WORD: super-user ¥¹¡¼¥Ñ¡¼¡¦¥æ¡¼¥¶¡¼
48 .TH SETUID 2 2010-02-21 "Linux" "Linux Programmer's Manual"
51 .\"O setuid \- set user identity
52 setuid \- ¥æ¡¼¥¶¡¼¼±ÊÌ (identity) ¤òÀßÄꤹ¤ë
55 .B #include <sys/types.h>
57 .B #include <unistd.h>
59 .BI "int setuid(uid_t " uid );
63 .\"O sets the effective user ID of the calling process.
64 .\"O If the effective UID of the caller is root,
65 .\"O the real UID and saved set-user-ID are also set.
67 ¤Ï¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¼Â¸ú (effective) ¥æ¡¼¥¶¡¼ ID ¤òÀßÄꤹ¤ë¡£
68 ¤â¤·¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î¼Â¸ú UID ¤¬ root ¤Ê¤é¤Ð¡¢
69 ¼Â (real) UID ¤ÈÊݸ (saved) set-user-ID ¤âÀßÄꤵ¤ì¤ë¡£
73 .\"O is implemented like the POSIX version with the
74 .\"O .B _POSIX_SAVED_IDS
76 .\"O This allows a set-user-ID (other than root) program to drop all of its user
77 .\"O privileges, do some un-privileged work, and then reengage the original
78 .\"O effective user ID in a secure manner.
83 ¤ò¤â¤Ã¤¿ POSIX ÈǤΤ褦¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¡£
84 ¤³¤ì¤Ï (¥ë¡¼¥È°Ê³°¤Î) set-user-ID ¥×¥í¥°¥é¥à¤Ë¤½¤Î¥æ¡¼¥¶¡¼¤ÎÆø¢¤ò
85 Á´¤ÆÍ¿¤¨¡¢Æø¢¤ÎɬÍפʤ¤»Å»ö¤ò¤·¡¢ËÜÍè¤Î¼Â¸ú¥æ¡¼¥¶¡¼ ID ¤Ë
86 °ÂÁ´¤ÊÊýË¡¤ÇºÆ¤ÓÌ᤹¤³¤È¤òµö¤¹¡£
88 .\"O If the user is root or the program is set-user-ID root, special care must be
92 .\"O function checks the effective user ID of the caller and if it is
93 .\"O the superuser, all process-related user ID's are set to
95 .\"O After this has occurred, it is impossible for the program to regain root
97 ¥æ¡¼¥¶¡¼¤¬ root ¤Þ¤¿¤Ï¥×¥í¥°¥é¥à¤¬ root ¤Ë set-user-ID ¤µ¤ì¤Æ¤¤¤ë¤Ê¤é¤Ð¡¢
98 ÆÃÊ̤ÎÃí°Õ¤¬Ê§¤ï¤ì¤ë¡£
100 ´Ø¿ô¤Ï¸Æ¤Ó½Ð¤·¼Ô¤Î¼Â¸ú¥æ¡¼¥¶¡¼ ID ¤ò¥Á¥§¥Ã¥¯¤·¡¢
101 ¤½¤ì¤¬¥¹¡¼¥Ñ¡¼¡¦¥æ¡¼¥¶¡¼¤Ê¤é¤Ð¡¢
102 ¥×¥í¥»¥¹¤Ë´ØÏ¢¤¹¤ëÁ´¤Æ¤Î¥æ¡¼¥¶¡¼ ID ¤Ë
105 ¤³¤ì¤¬¹Ô¤Ê¤ï¤ì¤¿¸å¤Ë¤Ï¥×¥í¥°¥é¥à¤¬ºÆ¤Ó¥ë¡¼¥È¤ÎÆø¢¤òÆÀ¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
107 .\"O Thus, a set-user-ID-root program wishing to temporarily drop root
108 .\"O privileges, assume the identity of an unprivileged user, and then regain
109 .\"O root privileges afterwards cannot use
111 .\"O You can accomplish this with
112 .\"O .BR seteuid (2).
113 ¤·¤¿¤¬¤Ã¤Æ¡¢set-user-ID-root ¥×¥í¥°¥é¥à¤Ç¡¢°ì»þŪ¤Ë¥ë¡¼¥ÈÆø¢¤ò²ò½ü¤·¡¢
114 ÈóÆø¢¥æ¡¼¥¶¤Ç¤¢¤ë¤«¤Î¤è¤¦¤Ë¿¶Éñ¤¤¡¢¸å¤Ç¥ë¡¼¥È¸¢¸Â¤ò¤â¤¦°ìÅÙÆÀ¤è¤¦¤È
117 ¤ò»È¤¦¤³¤È¤¬¤Ç¤¤Ê¤¤¡£¤½¤Î¾ì¹ç¤Ë¤Ï¡¢
120 .\"O .SH "RETURN VALUE"
122 .\"O On success, zero is returned.
123 .\"O On error, \-1 is returned, and
125 .\"O is set appropriately.
126 À®¸ù¤·¤¿¾ì¹ç¤Ï 0 ¤¬ÊÖ¤µ¤ì¤ë¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï \-1 ¤¬ÊÖ¤µ¤ì¡¢
135 .\"O does not match the current uid and
137 .\"O brings process over its
141 ¤¬¸½ºß¤Î¥æ¡¼¥¶¡¼ ID ¤È¥Þ¥Ã¥Á¤»¤º¡¢¤³¤Î
143 ¤Ë¤è¤Ã¤Æ¥×¥í¥»¥¹¤¬¥ê¥½¡¼¥¹¾å¸Â
148 .\"O The user is not privileged (Linux: does not have the
152 .\"O does not match the real UID or saved set-user-ID of the calling process.
153 ¥æ¡¼¥¶¡¼¤¬Æø¢¤ò»ý¤¿¤º
156 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£ (capability) ¤ò»ý¤¿¤º)¡¢
158 ¤¬¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î¼Â UID ¤Þ¤¿¤ÏÊݸ set-user-ID ¤È°ìÃפ·¤Ê¤¤¡£
159 .\"O .SH "CONFORMING TO"
161 .\"O SVr4, POSIX.1-2001.
162 .\"O Not quite compatible with the 4.4BSD call, which
163 .\"O sets all of the real, saved, and effective user IDs.
164 .\"O .\" SVr4 documents an additional EINVAL error condition.
166 4.4BSD ¤Î¥³¡¼¥ë¤È¤Ï´°Á´¤Ê¸ß´¹À¤Ï¤Ê¤¤¡¢
167 BSD ¤Î¥³¡¼¥ë¤Ï¼Â (real)¡¢Êݸ (saved)¡¢¼Â¸ú (effective) ID ¤ÎÁ´¤Æ¤òÀßÄꤹ¤ë¡£
168 .\" SVr4 ¤Ë¤Ï¾¤Ë EINVAL ¥¨¥é¡¼¤Ë¤Ä¤¤¤Æ¤Îµ½Ò¤¬¤¢¤ë¡£
173 .\"O Linux has the concept of file system user ID, normally equal to the
174 .\"O effective user ID.
177 .\"O call also sets the file system user ID of the calling process.
179 .\"O .BR setfsuid (2).
180 Linux ¤Ï¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¡¦¥æ¡¼¥¶¡¼ ID ¤Î³µÇ°¤ò»ý¤Ä¡£
181 Ä̾¤³¤ì¤Ï¼Â¸ú¥æ¡¼¥¶¡¼ ID ¤ËÅù¤·¤¤¡£
183 ¥³¡¼¥ë¤Ï¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¡¦¥æ¡¼¥¶¡¼ ID ¤âÀßÄꤹ¤ë¡£
189 .\"O is different from the old effective uid, the process will
190 .\"O be forbidden from leaving core dumps.
192 ¤¬ÀΤμ¸ú uid ¤È°Û¤Ã¤Æ¤¤¤¿¾ì¹ç¡¢¥×¥í¥»¥¹¤Ï¥³¥¢¡¦¥À¥ó¥×¤¹¤ë¤³¤È¤ò
200 .BR capabilities (7),