setresuid
Section: System Calls (2)
Updated: 2026-02-08
Index
JM Home Page
roff page
名前
setresuid, setresgid - set real, effective, and saved user or group ID
ライブラリ
標準 C ライブラリ (libc,~-lc)
書式
#define _GNU_SOURCE /* feature_test_macros(7) 参照 */
#include <unistd.h>
int setresuid(uid_t ruid, uid_t euid, uid_t suid);
int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
説明
setresuid() は呼び出し元のプロセスの実 (real) ユーザーID、実効 (effective) ユーザーID、 保存
set-user-ID を設定する。
An unprivileged process may change its real UID, effective UID, and saved
set-user-ID, each to one of: the current real UID, the current effective
UID, or the current saved set-user-ID.
特権プロセス (Linux では CAP_SETUID ケーパビリティ (capability) を持つ プロセス) は、自身の実 UID、実効
UID、保存 set-user-ID を任意の値に設定できる。
引数のどれかが -1 の場合はその値は変更されずに残される。
実 UID、実効 UID、保存 set-user-ID にどんな変更が行われたかに関わらず、 ファイルシステム UID は常に実効 UID
(可能であれば変更後の新しい実効 UID) と同じ値に設定される。
全く同じように、 setresgid() は呼び出し元のプロセスの実 GID、実効 GID、保存 set-group-ID を設定する
(さらにファイルシステム GID を実効 GID と同じ値に修正する)。 非特権プロセスは同様の制限を受ける。
返り値
On success, zero is returned. On error, -1 is returned, and errno is set
to indicate the error.
注意: 呼び出し元が UID 0 であっても setresuid() が失敗する場合がある。 setresuid()
からのリターンが失敗かどうかの確認を省略することは重大なセキュリティ上のエラーとなる。
エラー
- EAGAIN
-
この呼び出しで呼び出し元の実 UID が変更されるはずだったが (つまり、 ruid が呼び出し元の実 UID と一致していない)、
必要なカーネルのデータ構造体の割り当てで一時的な失敗があった。
- EAGAIN
-
ruid は呼び出し元の実 UID と一致しておらず、 この呼び出しで実ユーザー ID ruid に属するプロセス数が呼び出し元の
RLIMIT_NPROC リソース上限を超過するところであった。 Linux 3.1 以降では、このエラーはもはや発生することはない
(しかし、堅牢性が求められるアプリケーションではこのエラーを確認すべきである)。 execve(2) の EAGAIN の説明を参照。
- EINVAL
-
対象のユーザー ID やグループ ID のうち 1 つ以上がこのユーザー名前空間で有効ではない。
- EPERM
-
The calling process is not privileged (did not have the necessary capability
in its user namespace) and tried to change the IDs to values that are not
permitted. For setresuid(), the necessary capability is CAP_SETUID;
for setresgid(), it is CAP_SETGID.
バージョン
C ライブラリとカーネルの違い
At the kernel level, user IDs and group IDs are a per-thread attribute.
However, POSIX requires that all threads in a process share the same
credentials. The NPTL threading implementation handles the POSIX
requirements by providing wrapper functions for the various system calls
that change process UIDs and GIDs. These wrapper functions (including those
for setresuid() and setresgid()) employ a signal-based technique to
ensure that when one thread changes credentials, all of the other threads in
the process also change their credentials. For details, see nptl(7).
標準規格
POSIX.1-2024.
歴史
POSIX.1-2024. Linux 2.1.44, glibc 2.3.2. HP-UX, FreeBSD.
元々の Linux の setresuid() と setresgid() システムコールは
16 ビットのグループ ID だけに対応していた。
その後、Linux 2.4 で、32 ビットの ID に対応した
setresuid32() と setresgid32() が追加された。
glibc の setresuid() と setresgid() のラッパー関数は
カーネルバージョンによるこの違いを吸収している。
関連項目
getresuid(2), getuid(2), setfsgid(2), setfsuid(2),
setreuid(2), setuid(2), capabilities(7), credentials(7),
user_namespaces(7)
Index
- 名前
-
- ライブラリ
-
- 書式
-
- 説明
-
- 返り値
-
- エラー
-
- バージョン
-
- C ライブラリとカーネルの違い
-
- 標準規格
-
- 歴史
-
- 関連項目
-
This document was created by
man2html,
using the manual pages.