.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" and Copyright (C) 2009, 2010, 2014, 2015, Michael Kerrisk .\" All rights reserved. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" 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. .\" %%%LICENSE_END .\" .\" @(#)setregid.2 6.4 (Berkeley) 3/10/91 .\" .\" Modified Sat Jul 24 09:08:49 1993 by Rik Faith .\" Portions extracted from linux/kernel/sys.c: .\" Copyright (C) 1991, 1992 Linus Torvalds .\" May be distributed under the GNU General Public License .\" Changes: 1994-07-29 by Wilf .\" 1994-08-02 by Wilf due to change in kernel. .\" 2004-07-04 by aeb .\" 2004-05-27 by Michael Kerrisk .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated Fri Dec 12 00:18:45 JST 1997 .\" by HANATAKA Shinya .\" Updated & Modified Mon Jun 4 19:11:44 JST 2001 .\" by Yuichi SATO .\" Updated & Modified Wed Jan 5 00:37:49 JST 2005 .\" by Yuichi SATO .\" Updated 2010-04-23, Akihiro MOTOKI , LDP v3.24 .\" Updated 2012-04-30, Akihiro MOTOKI .\" .TH SETREUID 2 2017\-09\-15 Linux "Linux Programmer's Manual" .SH 名前 setreuid, setregid \- 実 (real) と実効 (effective) ユーザー (グループ) ID を設定する .SH 書式 \fB#include \fP .br \fB#include \fP .PP \fBint setreuid(uid_t \fP\fIruid\fP\fB, uid_t \fP\fIeuid\fP\fB);\fP .br \fBint setregid(gid_t \fP\fIrgid\fP\fB, gid_t \fP\fIegid\fP\fB);\fP .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBsetreuid\fP(), \fBsetregid\fP(): .RS 4 .ad l .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE\ >=\ 500 || /* Since glibc 2.19: */ _DEFAULT_SOURCE || /* Glibc versions <= 2.19: */ _BSD_SOURCE .ad .RE .SH 説明 \fBsetreuid\fP() は呼び出し元のプロセスの実 (real) ユーザー ID と 実効 (effective) ユーザー ID を設定する。 .PP 実ユーザー ID や実効ユーザー ID に \-1 を与えた場合、 システムはその ID を変更しない。 .PP 非特権プロセスは実効ユーザー ID を実ユーザー ID または実効ユーザー ID または 保存 set\-user\-ID にしか設定できない。 .PP 非特権ユーザーは、実ユーザー ID を実ユーザー ID または 実効ユーザー ID にしか設定できない。 .PP 実ユーザーID が設定されたり (\fIruid\fP が \-1 ではない)、実効ユーザーID が前の実ユーザーID と 異った値に設定された場合、保存 set\-user\-ID には新しい実効ユーザーID の値が設定される。 .PP これと全く同様に、 \fBsetregid\fP() は呼び出し元のプロセスの実グループ ID と実効グループ ID を設定し、 上記の説明で「ユーザー」を「グループ」に読み替えたことが成り立つ。 .SH 返り値 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。 .PP \fI注意\fP: 呼び出し元が UID 0 であっても \fBsetreuid\fP() が失敗する場合がある。 \fBsetreuid\fP() からのリターンが失敗かどうかの確認を省略することは重大なセキュリティ上のエラーとなる。 .SH エラー .TP \fBEAGAIN\fP この呼び出しで呼び出し元の実 UID が変更されるはずだったが (つまり、 \fIruid\fP が呼び出し元の実 UID と一致していない)、 必要なカーネルのデータ構造体の割り当てで一時的な失敗があった。 .TP \fBEAGAIN\fP \fIruid\fP は呼び出し元の実 UID と一致しておらず、 この呼び出しで実ユーザー ID \fIruid\fP に属するプロセス数が呼び出し元の \fBRLIMIT_NPROC\fP リソース上限を超過するところであった。 Linux 3.1 以降では、このエラーはもはや発生することはない (しかし、堅牢性が求められるアプリケーションではこのエラーを確認すべきである)。 \fBexecve\fP(2) の \fBEAGAIN\fP の説明を参照。 .TP \fBEINVAL\fP 対象のユーザー ID やグループ ID のうち 1 つ以上がこのユーザー名前空間で有効ではない。 .TP \fBEPERM\fP The calling process is not privileged (on Linux, does not have the necessary capability in its user namespace: \fBCAP_SETUID\fP in the case of \fBsetreuid\fP(), or \fBCAP_SETGID\fP in the case of \fBsetregid\fP()) 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. .SH 準拠 POSIX.1\-2001, POSIX.1\-2008, 4.3BSD (\fBsetreuid\fP() と \fBsetregid\fP() 関数コールは 4.2BSD で初めて登場した)。 .SH 注意 実効ユーザー (グループ) ID を保存ユーザー (グループ) ID に 設定することが、Linux 1.1.37 (1.1.38) から可能になった。 .PP POSIX.1 では、 Linux が非特権プロセスに対して認めている ID の変更の全パターンを規定しているわけではない。 \fBsetreuid\fP() では、実効ユーザー ID を実ユーザー ID もしくは保存 set\-user\-ID と 同じ値にすることができるが、 非特権プロセスが実ユーザー ID を実ユーザー ID、実効ユーザー ID、 保存 set\-user\-ID のどの値にも設定できるかは規定されていない。 \fBsetregid\fP() では、実グループ ID を保存 set\-group\-ID と同じ値に変更でき、 実効グループ ID を実グループ ID や保存 set\-group\-ID と同じ値に変更できる。 どのような ID の変更が認められているかの正確な詳細は 実装ごとに異なる。 .PP POSIX.1 では、これらのシステムコールが保存 set\-user\-ID や 保存 set\-group\-ID に与える影響については規定していない。 .PP .\" 元々の Linux の \fBsetreuid\fP() と \fBsetregid\fP() システムコールは 16 ビットのグループ ID だけに対応していた。 その後、Linux 2.4 で、32 ビットの ID に対応した \fBsetreuid32\fP() と \fBsetregid32\fP() が追加された。 glibc の \fBsetreuid\fP() と \fBsetregid\fP() のラッパー関数は カーネルバージョンによるこの違いを吸収している。 .SS "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 \fBsetreuid\fP() and \fBsetregid\fP()) 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 \fBnptl\fP(7). .SH 関連項目 \fBgetgid\fP(2), \fBgetuid\fP(2), \fBseteuid\fP(2), \fBsetgid\fP(2), \fBsetresuid\fP(2), \fBsetuid\fP(2), \fBcapabilities\fP(7), \fBcredentials\fP(7), \fBuser_namespaces\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。