SETREUID

Section: Linux Programmer's Manual (2)
Updated: 2017-09-15
Index JM Home Page
 

名前

setreuid, setregid - 実 (real) と実効 (effective) ユーザー (グループ) ID を設定する  

書式

#include <sys/types.h>
#include <unistd.h>

int setreuid(uid_t ruid, uid_t euid);
int setregid(gid_t rgid, gid_t egid);

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

setreuid(), setregid():

_XOPEN_SOURCE >= 500
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* Glibc versions <= 2.19: */ _BSD_SOURCE
 

説明

setreuid() は呼び出し元のプロセスの実 (real) ユーザー ID と 実効 (effective) ユーザー ID を設定する。

実ユーザー ID や実効ユーザー ID に -1 を与えた場合、 システムはその ID を変更しない。

非特権プロセスは実効ユーザー ID を実ユーザー ID または実効ユーザー ID または 保存 set-user-ID にしか設定できない。

非特権ユーザーは、実ユーザー ID を実ユーザー ID または 実効ユーザー ID にしか設定できない。

実ユーザーID が設定されたり (ruid が -1 ではない)、実効ユーザーID が前の実ユーザーID と 異った値に設定された場合、保存 set-user-ID には新しい実効ユーザーID の値が設定される。

これと全く同様に、 setregid() は呼び出し元のプロセスの実グループ ID と実効グループ ID を設定し、 上記の説明で「ユーザー」を「グループ」に読み替えたことが成り立つ。  

返り値

成功した場合は 0 が返される。エラーの場合は -1 が返され、 errno が適切に設定される。

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

エラー

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 (on Linux, does not have the necessary capability in its user namespace: CAP_SETUID in the case of setreuid(), or CAP_SETGID in the case of setregid()) and a change other than (i) swapping the effective user (group) ID with the real user (group) ID, or (ii) setting one to the value of the other or (iii) setting the effective user (group) ID to the value of the saved set-user-ID (saved set-group-ID) was specified.
 

準拠

POSIX.1-2001, POSIX.1-2008, 4.3BSD (setreuid() と setregid() 関数コールは 4.2BSD で初めて登場した)。  

注意

実効ユーザー (グループ) ID を保存ユーザー (グループ) ID に 設定することが、Linux 1.1.37 (1.1.38) から可能になった。

POSIX.1 では、 Linux が非特権プロセスに対して認めている ID の変更の全パターンを規定しているわけではない。 setreuid() では、実効ユーザー ID を実ユーザー ID もしくは保存 set-user-ID と 同じ値にすることができるが、 非特権プロセスが実ユーザー ID を実ユーザー ID、実効ユーザー ID、 保存 set-user-ID のどの値にも設定できるかは規定されていない。 setregid() では、実グループ ID を保存 set-group-ID と同じ値に変更でき、 実効グループ ID を実グループ ID や保存 set-group-ID と同じ値に変更できる。 どのような ID の変更が認められているかの正確な詳細は 実装ごとに異なる。

POSIX.1 では、これらのシステムコールが保存 set-user-ID や 保存 set-group-ID に与える影響については規定していない。

元々の Linux の setreuid() と setregid() システムコールは 16 ビットのグループ ID だけに対応していた。 その後、Linux 2.4 で、32 ビットの ID に対応した setreuid32() と setregid32() が追加された。 glibc の setreuid() と setregid() のラッパー関数は カーネルバージョンによるこの違いを吸収している。  

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 setreuid() and setregid()) 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).  

関連項目

getgid(2), getuid(2), seteuid(2), setgid(2), setresuid(2), setuid(2), capabilities(7), credentials(7), user_namespaces(7)  

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

ユーザー, setreuid, 実効, user, 設定, setregid, グループ, 呼び出し, 保存, group

Linux マニュアル 一覧

[man1] [man2] [man3] [man4] [man5] [man6] [man7] [man8]
[a] [b] [c] [d] [e] [f] [g] [h] [i] [j] [k] [l] [m] [n] [o] [p] [q] [r] [s] [t] [u] [v] [w] [x] [y] [z]

 

Index

名前
書式
説明
返り値
エラー
準拠
注意
C ライブラリとカーネルの違い
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 12:08:51 GMT, June 11, 2022