setuidのヘルプ・マニュアル
日本語 英語
setuid --help
man setuid
SETUID(2) Linux Programmer’s Manual SETUID(2)
名前
setuid - ユーザー識別 (identity) を設定する
書式
#include
#include
int setuid(uid_t uid);
説明
setuid() は呼び出し元のプロセスの実効 (effective) ユーザー ID を設定す
る。もし呼び出し元プロセスの実効 UID が root ならば、実 (real) UID と保
存 (saved) set-user-ID も設定される。
Linux では、 setuid() は _POSIX_SAVED_IDS をもった POSIX 版のように実装
されている。これは (ルート以外の) set-user-ID プログラムにそのユーザ ー
の 特権を全て与え、特権の必要ない仕事をし、本来の実効ユーザー ID に安全
な方法で再び戻すことを許す。
ユーザーがルート (root) またはプログラムがルートに set-user-ID されてい
る ならば、特別の注意が払われる。 setuid() 関数は呼び出し者の実効ユーザ
ー ID をチェックし、それがスーパー・ユーザーならば、プロセスに関連す る
全てのユーザー ID に uid を設定する。これが行なわれた後にはプログラムが
再びルートの特権を得ることはできない。
このように、set-user-ID-root プログラムは一時的にルート特権を与え、ルー
ト でないように振舞うことができ、それから setuid() を使って再びルート特
権を得ることができないようにする。 (POSIX で な い 、BSD) コ ー ル は
seteuid(2) で行なうことができる。
返り値
成 功した場合は 0 が返される。エラーの場合は -1 が返され、 errno が適切
に設定される。
エラー
EAGAIN uid が現在のユーザー ID とマッチせず、この uid によってプロセ ス
がリソース上限 RLIMIT_NPROC を超えた。
EPERM ユ ー ザ ーが特権を持たず (Linux では CAP_SETUID ケーパビリティ
(capability) を持たず)、 uid が呼び出し元プロセスの実 UID または
保存 set-user-ID と一致しない。
準拠
SVr4, POSIX.1-2001. 4.4BSD のコールとは完全な互換性はない、 BSD のコー
ルは実 (real)、保存 (saved)、実効 (effective) ID の全てを設定する。
注意
Linux での注意
Linux はファイル・システム・ユーザー ID の概念を持つ。通常、これは実 効
ユ ーザー ID に等しい。 setuid() コールは呼び出し元のプロセスのファイル
・システム・ユーザー ID も設定する。 setfsuid(2) も参照すること。
uid が昔の実効 uid と異っていた場合、プロセスはコア・ダンプすることを禁
止される。
関連項目
getuid(2), seteuid(2), setfsuid(2), setreuid(2), capabilities(7), cre-
dentials(7)
Linux 2004-05-27 SETUID(2)
SETUID(2) Linux Programmer’s Manual SETUID(2)
NAME
setuid - set user identity
SYNOPSIS
#include
#include
int setuid(uid_t uid);
DESCRIPTION
setuid() sets the effective user ID of the calling process. If the
effective UID of the caller is root, the real UID and saved set-user-ID
are also set.
Under Linux, setuid() is implemented like the POSIX version with the
_POSIX_SAVED_IDS feature. This allows a set-user-ID (other than root)
program to drop all of its user privileges, do some un-privileged work,
and then re-engage the original effective user ID in a secure manner.
If the user is root or the program is set-user-ID-root, special care
must be taken. The setuid() function checks the effective user ID of
the caller and if it is the superuser, all process-related user ID’s
are set to uid. After this has occurred, it is impossible for the pro-
gram to regain root privileges.
Thus, a set-user-ID-root program wishing to temporarily drop root priv-
ileges, assume the identity of a non-root user, and then regain root
privileges afterwards cannot use setuid(). You can accomplish this
with the (non-POSIX, BSD) call seteuid(2).
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is
set appropriately.
ERRORS
EAGAIN The uid does not match the current uid and uid brings process
over its RLIMIT_NPROC resource limit.
EPERM The user is not privileged (Linux: does not have the CAP_SETUID
capability) and uid does not match the real UID or saved set-
user-ID of the calling process.
CONFORMING TO
SVr4, POSIX.1-2001. Not quite compatible with the 4.4BSD call, which
sets all of the real, saved, and effective user IDs.
NOTES
Linux Notes
Linux has the concept of file system user ID, normally equal to the
effective user ID. The setuid() call also sets the file system user ID
of the calling process. See setfsuid(2).
If uid is different from the old effective uid, the process will be
forbidden from leaving core dumps.
SEE ALSO
getuid(2), seteuid(2), setfsuid(2), setreuid(2), capabilities(7), cre-
dentials(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2004-05-27 SETUID(2)