Submitted by: Akira Ikeuchi <a_ikeuchi@mic.mitsumi.co.jp> Reviewed by: Watanabe Kazuhiro <CQG00620@nifty.ne.jp>
189 lines
5.9 KiB
Groff
189 lines
5.9 KiB
Groff
.\" Copyright (c) 1983, 1991, 1993
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted provided that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
.\" must display the following acknowledgement:
|
|
.\" This product includes software developed by the University of
|
|
.\" California, Berkeley and its contributors.
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
.\" may be used to endorse or promote products derived from this software
|
|
.\" without specific prior written permission.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
.\" SUCH DAMAGE.
|
|
.\"
|
|
.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93
|
|
.\" %FreeBSD: src/lib/libc/sys/setuid.2,v 1.23 2004/07/05 17:12:52 ru Exp %
|
|
.\"
|
|
.\" $FreeBSD$
|
|
.Dd June 4, 1993
|
|
.Dt SETUID 2
|
|
.Os
|
|
.Sh ̾¾Î
|
|
.Nm setuid ,
|
|
.Nm seteuid ,
|
|
.Nm setgid ,
|
|
.Nm setegid
|
|
.Nd ¥æ¡¼¥¶ ID ¤È¥°¥ë¡¼¥× ID ¤òÀßÄꤹ¤ë
|
|
.Sh ¥é¥¤¥Ö¥é¥ê
|
|
.Lb libc
|
|
.Sh ½ñ¼°
|
|
.In sys/types.h
|
|
.In unistd.h
|
|
.Ft int
|
|
.Fn setuid "uid_t uid"
|
|
.Ft int
|
|
.Fn seteuid "uid_t euid"
|
|
.Ft int
|
|
.Fn setgid "gid_t gid"
|
|
.Ft int
|
|
.Fn setegid "gid_t egid"
|
|
.Sh ²òÀâ
|
|
.Fn setuid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¸½ºß¤Î¥×¥í¥»¥¹¤Î¼Â¥æ¡¼¥¶ ID ¤È¼Â¸ú¥æ¡¼¥¶ ID ¤È
|
|
ÂàÈò¥æ¡¼¥¶ ID ¤ò»ØÄꤷ¤¿ÃͤËÀßÄꤷ¤Þ¤¹¡£
|
|
.\" Comment out next block for !_POSIX_SAVED_IDS
|
|
.\" The real user ID and the saved set-user-ID are changed only if the
|
|
.\" effective user ID is that of the super user.
|
|
.\" I.e.
|
|
.\" .Fn setuid
|
|
.\" system call is equal to
|
|
.\" .Fn seteuid
|
|
.\" system call if the effective user ID is not that of the super user.
|
|
.\" End of block
|
|
.Fn setuid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬µöÍÆ¤µ¤ì¤ë¤Î¤Ï¡¢»ØÄê¤Î ID ¤¬¥×¥í¥»¥¹¤Î¼Â¥æ¡¼¥¶ ID
|
|
¤Þ¤¿¤Ï¼Â¸ú¥æ¡¼¥¶ ID ¤ËÅù¤·¤¤¾ì¹ç¡¢
|
|
¤Þ¤¿¤Ï¼Â¸ú¥æ¡¼¥¶ ID ¤¬¥¹¡¼¥Ñ¥æ¡¼¥¶¤Î¤â¤Î¤ÈÅù¤·¤¤¾ì¹ç¤Ç¤¹¡£
|
|
.\" Comment out next line for !_POSIX_SAVED_IDS
|
|
.\" or the saved set-user-ID
|
|
.\" Next line is for Appendix B.4.2.2 case.
|
|
.Pp
|
|
.Fn setgid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¸½ºß¤Î¥×¥í¥»¥¹¤Î¼Â¥°¥ë¡¼¥× ID ¤È¼Â¸ú¥°¥ë¡¼¥× ID ¤È
|
|
ÂàÈò¥°¥ë¡¼¥× ID ¤ò»ØÄꤷ¤¿ÃͤËÀßÄꤷ¤Þ¤¹¡£
|
|
.\" Comment out next block for !_POSIX_SAVED_IDS
|
|
.\" The real group ID and the saved set-group-ID are changed only if the
|
|
.\" effective user ID is that of the super user.
|
|
.\" I.e.
|
|
.\" .Fn setgid
|
|
.\" system call is equal to
|
|
.\" .Fn setegid
|
|
.\" system call if the effective user ID is not that of the super user.
|
|
.\" End of block
|
|
.Fn setgid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬µöÍÆ¤µ¤ì¤ë¤Î¤Ï¡¢»ØÄê¤Î ID ¤¬¥×¥í¥»¥¹¤Î¼Â¥°¥ë¡¼¥× ID
|
|
¤Þ¤¿¤Ï¼Â¸ú¥°¥ë¡¼¥× ID ¤ËÅù¤·¤¤¾ì¹ç¡¢
|
|
¤Þ¤¿¤Ï¼Â¸ú¥æ¡¼¥¶ ID ¤¬¥¹¡¼¥Ñ¥æ¡¼¥¶¤Î¤â¤Î¤ÈÅù¤·¤¤¾ì¹ç¤Ç¤¹¡£
|
|
.\" Comment out next line for !_POSIX_SAVED_IDS
|
|
.\" or the saved set-group-ID
|
|
.\" Next line is for Appendix B.4.2.2 case.
|
|
.Pp
|
|
.Fn seteuid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë
|
|
.Pq Fn setegid
|
|
¤Ï¡¢¸½ºß¤Î¥×¥í¥»¥¹¤Î¼Â¸ú¥æ¡¼¥¶ (¥°¥ë¡¼¥× ID) ¤òÀßÄꤷ¤Þ¤¹¡£
|
|
¼Â¸ú¥æ¡¼¥¶ ID ¤Ï¼Â¥æ¡¼¥¶ ID ¤Þ¤¿¤ÏÂàÈò¥æ¡¼¥¶ ID (
|
|
.Xr intro 2
|
|
¤È
|
|
.Xr execve 2
|
|
¤ò»²¾È ) ¤ÎÃͤËÀßÄê¤Ç¤¤Þ¤¹¡£
|
|
¤³¤ì¤òÍøÍѤ·¡¢¥æ¡¼¥¶ ID ÀßÄꤵ¤ì¤¿¼Â¹Ô²Äǽ¥Õ¥¡¥¤¥ë¤Î¼Â¸ú¥æ¡¼¥¶ ID ¤ò
|
|
¼Â¥æ¡¼¥¶ ID ¤ËÀÚ¤êÂØ¤¨¤¿¸å¤Ë¡¢¥æ¡¼¥¶ ID ÀßÄê¤ÎÃͤËÌá¤ë¤³¤È¤Ç¡¢
|
|
¸µ¤Î¸¢¸Â¤òÆÀ¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
|
|
Ʊ¤¸¤è¤¦¤Ë¡¢¼Â¸ú¥°¥ë¡¼¥× ID ¤Ï¡¢
|
|
¼Â¥°¥ë¡¼¥× ID ¤Þ¤¿¤ÏÂàÈò¥°¥ë¡¼¥× ID ¤ÎÃͤËÀßÄê¤Ç¤¤Þ¤¹¡£
|
|
.Sh Ìá¤êÃÍ
|
|
.Rv -std
|
|
.Sh ¥¨¥é¡¼
|
|
ËÜ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¼¡¤Î¾ì¹ç¤Ë¼ºÇÔ¤·¤Þ¤¹:
|
|
.Bl -tag -width Er
|
|
.It Bq Er EPERM
|
|
¥æ¡¼¥¶¤¬¥¹¡¼¥Ñ¥æ¡¼¥¶¤Ç¤Ê¤¤¾ì¹ç¡¢¤Þ¤¿¤Ï»ØÄꤵ¤ì¤¿ uid ¤¬¤½¤Î¼Â ID¡¢
|
|
¼Â¸ú ID¡¢¤Þ¤¿¤ÏÂàÈò ID ¤Ç¤Ê¤¤¾ì¹ç¡£
|
|
.El
|
|
.Sh ¥»¥¥å¥ê¥Æ¥£¤Ë´Ø¤¹¤ë¹Í»¡
|
|
¥Õ¥¡¥¤¥ë¤Ø¤ÎÆÉ¼è¤ê¤È½ñ¹þ¤ßµö²Ä¤Ï¡¢
|
|
.Xr open 2
|
|
¤¬¸Æ¤Ð¤ì¤¿»þ¤ËȽÃǤµ¤ì¤Þ¤¹¡£
|
|
°ìÅÙ¥Õ¥¡¥¤¥ëµ½Ò»Ò¤¬¥ª¡¼¥×¥ó¤µ¤ì¤ë¤È¡¢¸¢¸Â¤òÍ¤Æ¤â¤½¤Î¥×¥í¥»¥¹¤Î
|
|
ÆÉ¼è¤ê¤Þ¤¿¤Ï½ñ¹þ¤ßµö²Ä¤Ë¤Ï±Æ¶Á¤·¤Þ¤»¤ó¡£
|
|
»ØÄꤵ¤ì¤¿¥æ¡¼¥¶ ID ¤Ë¡¢¤½¤Î¥Õ¥¡¥¤¥ë¤Ø¤ÎÆÉ¼è¤ê¤Þ¤¿¤Ï½ñ¹þ¤ßµö²Ä¤¬
|
|
¤Ê¤¯¤È¤â¤Ç¤¹¡£
|
|
Ä̾盧¤ì¤é¤Î¥Õ¥¡¥¤¥ë¤Ï¡¢¿·¤·¤¤¥×¥í¥»¥¹¤Î¼Â¹Ô»þ¤Ë¥ª¡¼¥×¥ó¤µ¤ì¤¿¤Þ¤Þ¤È¤Ê¤ê¡¢
|
|
¤½¤Î·ë²Ì¡¢¥æ¡¼¥¶¤¬¤â¤·¤«¤¹¤ë¤ÈÍ×Ãí°Õ¤Ç¤¢¤ë¥Ç¡¼¥¿¤òÆÉ¤ó¤À¤ê½¤Àµ¤·¤¿¤ê
|
|
¤Ç¤¤Æ¤·¤Þ¤¤¤Þ¤¹¡£
|
|
.Pp
|
|
¤³¤ì¤é¤Î¥Õ¥¡¥¤¥ë¤¬
|
|
.Xr exec 3
|
|
¸Æ¤Ó½Ð¤·¤Î¸å¤Ç¤â¥ª¡¼¥×¥ó¤µ¤ì¤¿¤Þ¤Þ¤Ë¤µ¤ì¤ë¤Î¤òËɤ°¤Ë¤Ï¡¢
|
|
close-on-exec ¥Õ¥é¥°¤òÀßÄꤹ¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤:
|
|
.Bd -literal
|
|
void
|
|
pseudocode(void)
|
|
{
|
|
int fd;
|
|
/* ... */
|
|
|
|
fd = open("/path/to/sensitive/data", O_RDWR);
|
|
if (fd == -1)
|
|
err(1, "open");
|
|
|
|
/*
|
|
* close-on-exec ¥Õ¥é¥°¤ÎÀßÄê; ¤µ¤é¤Ê¤ë¾ðÊó¤Ï fcntl(2) ¤ò»²¾È¡£
|
|
*/
|
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
|
err(1, "fcntl(F_SETFD)");
|
|
/* ... */
|
|
execve(path, argv, environ);
|
|
}
|
|
.Ed
|
|
.Sh ´ØÏ¢¹àÌÜ
|
|
.Xr getgid 2 ,
|
|
.Xr getuid 2 ,
|
|
.Xr issetugid 2 ,
|
|
.Xr setregid 2 ,
|
|
.Xr setreuid 2
|
|
.Sh µ¬³Ê
|
|
.Fn setuid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤È
|
|
.Fn setgid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï
|
|
.St -p1003.1-90
|
|
»ÅÍͤȸߴ¹À¤¬¤¢¤ê¤Þ¤¹¡£
|
|
¤¿¤À¤·¡¢
|
|
.Li _POSIX_SAVED_IDS
|
|
.\" Uncomment next line for !_POSIX_SAVED_IDS
|
|
¤ÏÉÕÏ¿ B.4.2.2 ¤Îµö²Ä¤µ¤ì¤¿³ÈÄ¥¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£
|
|
.Fn seteuid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤È
|
|
.Fn setegid
|
|
¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢
|
|
.Li _POSIX_SAVED_IDS
|
|
¤Î
|
|
.Tn POSIX
|
|
¥³¥ó¥»¥×¥È¤ò´ðÁäˤ·¤Æ³ÈÄ¥¤·¤Æ¤¢¤ê¡¢µ¬³Ê¤Î¾Íè¤Î²þÄêÍѤËÄ󰯤µ¤ì¤Æ¤¤¤Þ¤¹¡£
|
|
.Sh Îò»Ë
|
|
.Fn setuid
|
|
´Ø¿ô¤È
|
|
.Fn setgid
|
|
´Ø¿ô¤Ï
|
|
.At v7
|
|
¤ÇÅо줷¤Þ¤·¤¿¡£
|