OSDN Git Service

(split) LDP: Update release pages based on LDP 3.54 release
[linuxjm/LDP_man-pages.git] / release / man2 / chown.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\" and Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl)
3 .\" and Copyright (c) 2007, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified by Michael Haardt <michael@moria.de>
28 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified 1996-07-09 by Andries Brouwer <aeb@cwi.nl>
30 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
31 .\" Modified 1997-05-18 by Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
32 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" 2007-07-08, mtk, added an example program; updated SYNOPSIS
34 .\" 2008-05-08, mtk, Describe rules governing ownership of new files
35 .\"     (bsdgroups versus sysvgroups, and the effect of the parent
36 .\"     directory's set-group-ID permission bit).
37 .\"
38 .\"*******************************************************************
39 .\"
40 .\" This file was generated with po4a. Translate the source file.
41 .\"
42 .\"*******************************************************************
43 .\"
44 .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
45 .\"         all rights reserved.
46 .\" Translated 1996-06-24, Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
47 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
48 .\" Modified 2004-02-29, Yuichi SATO <ysato444@yahoo.co.jp>
49 .\" Updated & Modified Wed Dec 29 06:48:16 JST 2004 by Yuichi SATO
50 .\" Updated 2007-09-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.64
51 .\" Updated 2008-08-09, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
52 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
53 .\"
54 .TH CHOWN 2 2010\-11\-22 Linux "Linux Programmer's Manual"
55 .SH 名前
56 chown, fchown, lchown \- ファイルの所有者を変更する
57 .SH 書式
58 \fB#include <unistd.h>\fP
59 .sp
60 \fBint chown(const char *\fP\fIpath\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
61 .br
62 \fBint fchown(int \fP\fIfd\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
63 .br
64 \fBint lchown(const char *\fP\fIpath\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
65 .sp
66 .in -4n
67 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
68 .in
69 .sp
70 \fBfchown\fP(), \fBlchown\fP():
71 .PD 0
72 .ad l
73 .RS 4
74 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
75 .br
76 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
77 .RE
78 .ad
79 .PD
80 .SH 説明
81 これらのシステムコールは、いずれもファイルの所有者 (owner) とグループを変更する。システムコール間の違いは、ファイルの指定の仕方だけである。
82 .IP * 2
83 \fBchown\fP()  は \fIpath\fP で指定されたファイルの所有権を変更する。 \fIpath\fP
84 がシンボリック・リンクの場合は、リンクの展開が行われる。
85 .IP *
86 \fBfchown\fP()  はオープンされたファイルディスクリプタ \fIfd\fP により参照されるファイルの所有権を変更する。
87 .IP *
88 \fBlchown\fP()  は \fBchown\fP()  と同じだが、シンボリック・リンクを展開しない点が異なる。
89 .PP
90 特権を持つプロセス (Linux では \fBCAP_CHOWN\fP ケーパビリティ (capability) を持つプロセス) だけが
91 ファイルの所有者を変更できる。 ファイルの所有者は、その所有者が属しているグループのいずれかに ファイルのグループを変更することができる。 特権
92 (Linux では \fBCAP_CHOWN\fP)  を持つプロセスは、任意のグループに変更できる。
93
94 \fIowner\fP または \fIgroup\fP に \-1 が指定された場合、それらの ID は変更されない。
95
96 .\" In Linux 2.0 kernels, superuser was like everyone else
97 .\" In 2.2, up to 2.2.12, these bits were not cleared for superuser.
98 .\" Since 2.2.13, superuser is once more like everyone else.
99 非特権ユーザーにより実行ファイルの所有者またはグループが 変更された場合は \fBS_ISUID\fP と \fBISGID\fP モードビットはクリアされる。
100 POSIX はこの動作やルートが \fBchown\fP()  を行なった場合については特に指定されていない。 Linux
101 における動作はカーネルのバージョンに依存する。 非グループ実行ファイル (\fBS_IXGRP\fP ビットが設定されていないファイル) の場合には
102 \fBS_ISGID\fP ビットは強制ロック (mandatory locking) を意味している。 そしてそれは \fBchown\fP()
103 ではクリアできない。
104 .SH 返り値
105 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
106 .SH エラー
107 Depending on the filesystem, other errors can be returned.  The more general
108 errors for \fBchown\fP()  are listed below.
109 .TP 
110 \fBEACCES\fP
111 パス名の構成要素に検索許可がない (\fBpath_resolution\fP(7)  も見よ)。
112 .TP 
113 \fBEFAULT\fP
114 \fIpath\fP がアクセスできるアドレス空間外を指している。
115 .TP 
116 \fBELOOP\fP
117 \fIpath\fP を解決する際に遭遇したシンボリック・リンクが多過ぎる。
118 .TP 
119 \fBENAMETOOLONG\fP
120 \fIpath\fP が長過ぎる。
121 .TP 
122 \fBENOENT\fP
123 ファイルが存在しない。
124 .TP 
125 \fBENOMEM\fP
126 カーネルに十分なメモリがない。
127 .TP 
128 \fBENOTDIR\fP
129 パス名の構成要素がディレクトリではない。
130 .TP 
131 \fBEPERM\fP
132 呼び出したプロセスに所有者またはグループ (もしくはその両方) を変更するために 要求される許可 (上記を参照) がない。
133 .TP 
134 \fBEROFS\fP
135 The named file resides on a read\-only filesystem.
136 .PP
137 \fBfchown\fP()  で一般的なエラーを以下に挙げる:
138 .TP 
139 \fBEBADF\fP
140 ディスクリプターが有効でない。
141 .TP 
142 \fBEIO\fP
143 i ノード (inode) を変更する際に低レベル I/O エラーが発生した。
144 .TP 
145 \fBENOENT\fP
146 上記を参照。
147 .TP 
148 \fBEPERM\fP
149 上記を参照。
150 .TP 
151 \fBEROFS\fP
152 上記を参照。
153 .SH 準拠
154 4.4BSD, SVr4, POSIX.1\-2001.
155
156 .\" chown():
157 .\" SVr4 documents EINVAL, EINTR, ENOLINK and EMULTIHOP returns, but no
158 .\" ENOMEM.  POSIX.1 does not document ENOMEM or ELOOP error conditions.
159 .\" fchown():
160 .\" SVr4 documents additional EINVAL, EIO, EINTR, and ENOLINK
161 .\" error conditions.
162 4.4BSD 版ではスーパー・ユーザーのみが使用できる (つまり、普通のユーザーはファイルを手放すことはできない)。
163 .SH 注意
164 元々の Linux の \fBchown\fP(), \fBfchown\fP(), \fBlchown\fP() システムコールは、
165 16 ビットのユーザ ID とグループ ID だけに対応していた。
166 その後、 32 ビットの ID に対応した \fBchown32\fP(), \fBfchown32\fP(), \fBlchown32\fP()
167 が Linux 2.4 で追加された。
168 \fBchown\fP(), \fBfchown\fP(), and \fBlchown\fP() の glibc のラッパー関数は、
169 カーネルのバージョンによる違いを吸収している。
170
171 When a new file is created (by, for example, \fBopen\fP(2)  or \fBmkdir\fP(2)),
172 its owner is made the same as the filesystem user ID of the creating
173 process.  The group of the file depends on a range of factors, including the
174 type of filesystem, the options used to mount the filesystem, and whether or
175 not the set\-group\-ID permission bit is enabled on the parent directory.  If
176 the filesystem supports the \fI\-o\ grpid\fP (or, synonymously \fI\-o\ bsdgroups\fP)
177 and \fI\-o\ nogrpid\fP (or, synonymously \fI\-o\ sysvgroups\fP)  \fBmount\fP(8)
178 options, then the rules are as follows:
179 .IP * 2
180 If the filesystem is mounted with \fI\-o\ grpid\fP, then the group of a new file
181 is made the same as that of the parent directory.
182 .IP *
183 If the filesystem is mounted with \fI\-o\ nogrpid\fP and the set\-group\-ID bit is
184 disabled on the parent directory, then the group of a new file is made the
185 same as the process's filesystem GID.
186 .IP *
187 If the filesystem is mounted with \fI\-o\ nogrpid\fP and the set\-group\-ID bit is
188 enabled on the parent directory, then the group of a new file is made the
189 same as that of the parent directory.
190 .PP
191 As at Linux 2.6.25, the \fI\-o\ grpid\fP and \fI\-o\ nogrpid\fP mount options are
192 supported by ext2, ext3, ext4, and XFS.  Filesystems that don't support
193 these mount options follow the \fI\-o\ nogrpid\fP rules.
194 .PP
195 The \fBchown\fP()  semantics are deliberately violated on NFS filesystems which
196 have UID mapping enabled.  Additionally, the semantics of all system calls
197 which access the file contents are violated, because \fBchown\fP()  may cause
198 immediate access revocation on already open files.  Client side caching may
199 lead to a delay between the time where ownership have been changed to allow
200 access for a user and the time where the file can actually be accessed by
201 the user on other clients.
202
203 Linux の 2.1.81 より前のバージョン (特に 2.1.46 以前) では、 \fBchown\fP()  はシンボリック・リンクを追跡しない。
204 Linux 2.1.81 以降では \fBchown\fP()  はシンボリック・リンクを追跡し、新たなシステム・コール \fBlchown\fP()
205 はシンボリック・リンクを追跡しない。 Linux 2.1.86 以降ではこの新しいコール (古い \fBchown\fP()  と全く同じ動作を行なう)
206 は同じシステムコール番号を持ち \fBchown\fP()  は新しく導入された番号を持つ。
207 .SH 例
208 .PP
209 以下のプログラムは、 二つ目のコマンドライン引き数で指定された名前のファイルの所有者を、 一つ目のコマンドライン引き数で指定された値に変更する。
210 新しい所有者は、数字のユーザ ID かユーザ名のいずれかで指定できる (ユーザ名で指定した場合には、 \fBgetpwnam\fP(3)
211 を使ってシステムのパスワードファイルの検索が行われ、 ユーザ ID への変換が行われる)。
212 .nf
213
214 #include <pwd.h>
215 #include <stdio.h>
216 #include <stdlib.h>
217 #include <unistd.h>
218
219 int
220 main(int argc, char *argv[])
221 {
222     uid_t uid;
223     struct passwd *pwd;
224     char *endptr;
225
226     if (argc != 3 || argv[1][0] == \(aq\e0\(aq) {
227         fprintf(stderr, "%s <owner> <file>\en", argv[0]);
228         exit(EXIT_FAILURE);
229     }
230
231     uid = strtol(argv[1], &endptr, 10);  /* Allow a numeric string */
232
233     if (*endptr != \(aq\e0\(aq) {         /* Was not pure numeric string */
234         pwd = getpwnam(argv[1]);   /* Try getting UID for username */
235         if (pwd == NULL) {
236             perror("getpwnam");
237             exit(EXIT_FAILURE);
238         }
239
240         uid = pwd\->pw_uid;
241     }
242
243     if (chown(argv[2], uid, \-1) == \-1) {
244         perror("chown");
245         exit(EXIT_FAILURE);
246     }
247
248     exit(EXIT_SUCCESS);
249 }
250 .fi
251 .SH 関連項目
252 \fBchmod\fP(2), \fBfchownat\fP(2), \fBflock\fP(2), \fBpath_resolution\fP(7),
253 \fBsymlink\fP(7)
254 .SH この文書について
255 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
256 である。プロジェクトの説明とバグ報告に関する情報は
257 http://www.kernel.org/doc/man\-pages/ に書かれている。