1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\" and Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl)
5 .\" and Copyright (c) 2007, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
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).
38 .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
39 .\" all rights reserved.
40 .\" Translated 1996-06-24, Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
41 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
42 .\" Modified 2004-02-29, Yuichi SATO <ysato444@yahoo.co.jp>
43 .\" Updated & Modified Wed Dec 29 06:48:16 JST 2004 by Yuichi SATO
44 .\" Updated 2007-09-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.64
45 .\" Updated 2008-08-09, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
47 .TH CHOWN 2 2010-09-26 "Linux" "Linux Programmer's Manual"
49 chown, fchown, lchown \- ファイルの所有者を変更する
51 .B #include <unistd.h>
53 .BI "int chown(const char *" path ", uid_t " owner ", gid_t " group );
55 .BI "int fchown(int " fd ", uid_t " owner ", gid_t " group );
57 .BI "int lchown(const char *" path ", uid_t " owner ", gid_t " group );
61 .RB ( feature_test_macros (7)
70 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
71 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
73 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
78 これらのシステムコールは、ファイルの所有者 (owner) とグループを変更する。
79 システムコール間の違いは、ファイルの指定の仕方だけである。
86 がシンボリック・リンクの場合は、リンクの展開が行われる。
91 により参照されるファイルの所有権を変更する。
96 と同じだが、シンボリック・リンクを展開しない点が異なる。
100 ケーパビリティ (capability) を持つプロセス) だけが
102 ファイルの所有者は、その所有者が属しているグループのいずれかに
103 ファイルのグループを変更することができる。
106 を持つプロセスは、任意のグループに変更できる。
111 に \-1 が指定された場合、それらの ID は変更されない。
113 非特権ユーザーにより実行ファイルの所有者またはグループが
121 を行なった場合については特に指定されていない。
122 Linux における動作はカーネルのバージョンに依存する。
123 .\" Linux 2.0 カーネルでは、スーパー・ユーザーでの動作は
124 .\" 他のユーザーの場合と同じであった。
125 .\" 2.2 では、2.2.12 までは、スーパー・ユーザーの場合には
126 .\" これらのビットはクリアされなくなった。
127 .\" 2.2.13 以降では、スーパー・ユーザーでの動作は
128 .\" 再び他のユーザーの場合と同じになった。
131 ビットが設定されていないファイル) の場合には
133 ビットは強制ロック (mandatory locking) を意味している。
143 ファイルシステムによっては他のエラーが返される事がある。
149 の構成要素に検索許可 (search permission) がない
150 .RB ( path_resolution (7)
155 が割り当てられたアドレス空間外を指している。
159 を解決する際に遭遇したシンボリック・リンクが多過ぎる。
176 呼び出したプロセスに所有者またはグループ (もしくはその両方) を変更するために
180 指定したファイルが読み込み専用 (read-only) のファイル・システム上にある。
189 i ノード (inode) を変更する際に低レベル I/O エラーが発生した。
200 4.4BSD, SVr4, POSIX.1-2001.
202 4.4BSD 版ではスーパー・ユーザーのみが使用できる
203 (つまり、普通のユーザーはファイルを手放すことはできない)。
205 .\" SVr4 には EINVAL, EINTR, ENOLINK, EMULTIHOP を返すと記載されているが、
207 .\" POSIX.1 には ENOMEM, ELOOP について記載はない。
209 .\" SVr4 には他に EINVAL, EIO, EINTR, ENOLINK エラー状態についての記載がある。
214 などにより) 新しいファイルが作成されるとき、
215 その所有者は呼び出したプロセスのファイルシステム・ユーザ ID と
217 そのファイルのグループはいくつかの要因により決定される。
219 ファイルシステムの種類、そのファイルシステムのマウント時に
220 使用されたオプション、親ディレクトリで set-group-ID 許可ビットが
226 .RI ( "\-o\ bsdgroups"
229 .RI ( "\-o sysvgroups"
230 も同義語) に対応している場合、ルールは以下の通りとなる。
234 付きでマウントされている場合、新しいファイルのグループは
239 付きでマウントされており、親ディレクトリでは set-group-ID ビットが
240 無効になっている場合、新しいファイルのグループは
241 プロセスのファイルシステム GID と同じになる。
245 付きでマウントされており、親ディレクトリでは set-group-ID ビットが
246 有効になっている場合、新しいファイルのグループは
249 Linux 2.6.25 では、マウントオプション
254 ext2, ext3, ext4, XFS である。
255 これらのマウントオプションに対応していないファイルシステムでは、
262 さらにファイルの内容にアクセスする全てのシステム・コールを侵害する。
267 クライアント側のキャッシュにより所有権が変更されて
268 ユーザーのアクセスが許した時点と、実際に他のクライアントでユーザーによって
269 ファイルにアクセスできる時点との間に時間差があるかもしれない。
271 Linux の 2.1.81 より前のバージョン (特に 2.1.46 以前) では、
276 はシンボリック・リンクを追跡し、新たなシステム・コール
279 Linux 2.1.86 以降ではこの新しいコール (古い
281 と全く同じ動作を行なう) は同じシステムコール番号を持ち
287 二つ目のコマンドライン引き数で指定された名前のファイルの所有者を、
288 一つ目のコマンドライン引き数で指定された値に変更する。
289 新しい所有者は、数字のユーザ ID かユーザ名のいずれかで指定できる
292 を使ってシステムのパスワードファイルの検索が行われ、
302 main(int argc, char *argv[])
308 if (argc != 3 || argv[1][0] == \(aq\\0\(aq) {
309 fprintf(stderr, "%s <owner> <file>\\n", argv[0]);
313 uid = strtol(argv[1], &endptr, 10); /* Allow a numeric string */
315 if (*endptr != \(aq\\0\(aq) { /* Was not pure numeric string */
316 pwd = getpwnam(argv[1]); /* Try getting UID for username */
325 if (chown(argv[2], uid, \-1) == \-1) {
337 .BR path_resolution (7),