seteuid

Section: System Calls (2)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

seteuid, setegid - 実効ユーザー ID や 実効グループ ID を設定する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <unistd.h>

int seteuid(uid_t euid);
int setegid(gid_t egid);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

seteuid(), setegid():

    _POSIX_C_SOURCE >= 200112L
        || /* glibc <= 2.19: */ _BSD_SOURCE
 

説明

seteuid() は呼び出し元のプロセスの実効ユーザー ID を設定する。 非特権プロセスの場合、実効ユーザー ID に設定できるのは、 実ユーザー ID・実効ユーザー ID・保存 set-user-ID のいずれかだけである。

setegid() は「ユーザー」ではなく「グループ」に対して全く同じことを行う。  

返り値

On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error.

注意: 呼び出し元が UID 0 であっても seteuid() が失敗する場合がある。 seteuid() からのリターンが失敗かどうかの確認を省略することは重大なセキュリティ上のエラーとなる。  

エラー

EINVAL
対象のユーザー ID かグループ ID がこのユーザー名前空間では有効ではない。
EPERM
In the case of seteuid(): the calling process is not privileged (does not have the CAP_SETUID capability in its user namespace) and euid does not match the current real user ID, current effective user ID, or current saved set-user-ID.
In the case of setegid(): the calling process is not privileged (does not have the CAP_SETGID capability in its user namespace) and egid does not match the current real group ID, current effective group ID, or current saved set-group-ID.
 

バージョン

実効ユーザー (グループ) ID を保存 set-user-ID (保存 set-group-ID) に 設定できるのは、Linux 1.1.37 (1.1.38) 以降である。 全てのシステムにおいて _POSIX_SAVED_IDS をチェックすべきである。

glibc 2.0 では、 seteuid(euid) は setreuid(-1, euid) と等価であり、保存 set-user-ID を変更するかもしれない。 glibc 2.1 では、 setresuid(-1, euid, -1) と等価であり、保存 set-user-ID 変更しない。 同様のことが setegid() にも言えるが、 glibc 2.2 か 2.3 で、 実装が setregid(-1, egid) から setresgid(-1, egid, -1) へ変更された点だけが違う (どの glibc バージョンで変更が行われたかは、ハードウェアアーキテクチャーによって異なる)。

POSIX.1 では、 seteuid() (setegid()) で、 euid (egid) として現在の実効ユーザー (グループ) ID と同じ値を指定可能である 必要はないとされており、いくつかの実装では euid (egid) として現在の実効ユーザー (グループ) ID と同じ値を 指定することができない。  

C ライブラリとカーネルの違い

On Linux, seteuid() and setegid() are implemented as library functions that call, respectively, setresuid(2) and setresgid(2).  

標準規格

POSIX.1-2024.  

歴史

POSIX.1-2001, 4.3BSD.  

関連項目

geteuid(2), setresuid(2), setreuid(2), setuid(2), capabilities(7), credentials(7), user_namespaces(7)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
バージョン
C ライブラリとカーネルの違い
標準規格
歴史
関連項目

This document was created by man2html, using the manual pages.