OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man2 / chown.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
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>
6 .\"
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.
10 .\"
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.
15 .\"
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
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
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 .\" 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
46 .\"
47 .TH CHOWN 2 2010-09-26 "Linux" "Linux Programmer's Manual"
48 .\"O .SH NAME
49 .SH 名前
50 .\"O chown, fchown, lchown \- change ownership of a file
51 chown, fchown, lchown \- ファイルの所有者を変更する
52 .\"O .SH SYNOPSIS
53 .SH 書式
54 .B #include <unistd.h>
55 .sp
56 .BI "int chown(const char *" path ", uid_t " owner ", gid_t " group );
57 .br
58 .BI "int fchown(int " fd ", uid_t " owner ", gid_t " group );
59 .br
60 .BI "int lchown(const char *" path ", uid_t " owner ", gid_t " group );
61 .sp
62 .in -4n
63 .\"O Feature Test Macro Requirements for glibc (see
64 .\"O .BR feature_test_macros (7)):
65 glibc 向けの機能検査マクロの要件
66 .RB ( feature_test_macros (7)
67 参照):
68 .in
69 .sp
70 .BR fchown (),
71 .BR lchown ():
72 .PD 0
73 .ad l
74 .RS 4
75 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
76 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
77 .br
78 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
79 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
80 .RE
81 .ad
82 .PD
83 .\"O .SH DESCRIPTION
84 .SH 説明
85 .\"O These system calls change the owner and group of a file.
86 .\"O The differ only in how the file is specified:
87 これらのシステムコールは、ファイルの所有者 (owner) とグループを変更する。
88 システムコール間の違いは、ファイルの指定の仕方だけである。
89 .IP * 2
90 .\"O .BR chown ()
91 .\"O changes the ownership of the file specified by
92 .\"O .IR path ,
93 .\"O which is dereferenced if it is a symbolic link.
94 .BR chown ()
95
96 .I path
97 で指定されたファイルの所有権を変更する。
98 .I path
99 がシンボリック・リンクの場合は、リンクの展開が行われる。
100 .IP *
101 .\"O .BR fchown ()
102 .\"O changes the ownership of the file referred to by the open file descriptor
103 .\"O .IR fd .
104 .BR fchown ()
105 はオープンされたファイルディスクリプタ
106 .I fd
107 により参照されるファイルの所有権を変更する。
108 .IP *
109 .\"O .BR lchown ()
110 .\"O is like
111 .\"O .BR chown (),
112 .\"O but does not dereference symbolic links.
113 .BR lchown ()
114
115 .BR chown ()
116 と同じだが、シンボリック・リンクを展開しない点が異なる。
117 .PP
118 .\"O Only a privileged process (Linux: one with the
119 .\"O .B CAP_CHOWN
120 .\"O capability) may change the owner of a file.
121 特権を持つプロセス (Linux では
122 .B CAP_CHOWN
123 ケーパビリティ (capability) を持つプロセス) だけが
124 ファイルの所有者を変更できる。
125 .\"O The owner of a file may change the group of the file
126 .\"O to any group of which that owner is a member.
127 ファイルの所有者は、その所有者が属しているグループのいずれかに
128 ファイルのグループを変更することができる。
129 .\"O A privileged process (Linux: with
130 .\"O .BR CAP_CHOWN )
131 .\"O may change the group arbitrarily.
132 特権 (Linux では
133 .BR CAP_CHOWN )
134 を持つプロセスは、任意のグループに変更できる。
135
136 .\"O If the
137 .\"O .I owner
138 .\"O or
139 .\"O .I group
140 .\"O is specified as \-1, then that ID is not changed.
141 .I owner
142 または
143 .I group
144 に \-1 が指定された場合、それらの ID は変更されない。
145
146 .\"O When the owner or group of an executable file are
147 .\"O changed by an unprivileged user the
148 .\"O .B S_ISUID
149 .\"O and
150 .\"O .B S_ISGID
151 .\"O mode bits are cleared.
152 .\"O POSIX does not specify whether
153 .\"O this also should happen when root does the
154 .\"O .BR chown ();
155 非特権ユーザーにより実行ファイルの所有者またはグループが
156 変更された場合は
157 .B S_ISUID
158
159 .B ISGID
160 モードビットはクリアされる。
161 POSIX はこの動作やルートが
162 .BR chown ()
163 を行なった場合については特に指定されていない。
164 .\"O the Linux behavior depends on the kernel version.
165 Linux における動作はカーネルのバージョンに依存する。
166 .\"O .\" In Linux 2.0 kernels, superuser was like everyone else
167 .\"O .\" In 2.2, up to 2.2.12, these bits were not cleared for superuser.
168 .\"O .\" Since 2.2.13, superuser is once more like everyone else.
169 .\" Linux 2.0 カーネルでは、スーパー・ユーザーでの動作は
170 .\" 他のユーザーの場合と同じであった。
171 .\" 2.2 では、2.2.12 までは、スーパー・ユーザーの場合には
172 .\" これらのビットはクリアされなくなった。
173 .\" 2.2.13 以降では、スーパー・ユーザーでの動作は
174 .\" 再び他のユーザーの場合と同じになった。
175 .\"O In case of a non-group-executable file (i.e., one for which the
176 .\"O .B S_IXGRP
177 .\"O bit is not set) the
178 .\"O .B S_ISGID
179 .\"O bit indicates mandatory locking, and is not cleared by a
180 .\"O .BR chown ().
181 非グループ実行ファイル
182 .RB ( S_IXGRP
183 ビットが設定されていないファイル) の場合には
184 .B S_ISGID
185 ビットは強制ロック (mandatory locking) を意味している。
186 そしてそれは
187 .BR chown ()
188 ではクリアできない。
189 .\"O .SH "RETURN VALUE"
190 .SH 返り値
191 .\"O On success, zero is returned.
192 .\"O On error, \-1 is returned, and
193 .\"O .I errno
194 .\"O is set appropriately.
195 成功すると、0 を返す。
196 失敗すると、\-1 を返し、
197 .I errno
198 に適切な値を設定する。
199 .\"O .SH ERRORS
200 .SH エラー
201 .\"O Depending on the file system, other errors can be returned.
202 .\"O The more general errors for
203 .\"O .BR chown ()
204 .\"O are listed below.
205 ファイルシステムによっては他のエラーが返される事がある。
206 .B chmod
207 で一般的なエラーを以下に挙げる。
208 .TP
209 .B EACCES
210 .\"O Search permission is denied on a component of the path prefix.
211 .\"O (See also
212 .\"O .BR path_resolution (7).)
213 .I path
214 の構成要素に検索許可 (search permission) がない
215 .RB ( path_resolution (7)
216 も参照)。
217 .TP
218 .B EFAULT
219 .\"O .I path
220 .\"O points outside your accessible address space.
221 .I path
222 が割り当てられたアドレス空間外を指している。
223 .TP
224 .B ELOOP
225 .\"O Too many symbolic links were encountered in resolving
226 .\"O .IR path .
227 .I path
228 を解決する際に遭遇したシンボリック・リンクが多過ぎる。
229 .TP
230 .B ENAMETOOLONG
231 .\"O .I path
232 .\"O is too long.
233 .I path
234 が長過ぎる。
235 .TP
236 .B ENOENT
237 .\"O The file does not exist.
238 ファイルが存在しない。
239 .TP
240 .B ENOMEM
241 .\"O Insufficient kernel memory was available.
242 カーネルに十分なメモリがない。
243 .TP
244 .B ENOTDIR
245 .\"O A component of the path prefix is not a directory.
246 .I path
247 の構成要素がディレクトリでない。
248 .TP
249 .B EPERM
250 .\"O The calling process did not have the required permissions
251 .\"O (see above) to change owner and/or group.
252 呼び出したプロセスに所有者またはグループ (もしくはその両方) を変更するために
253 要求される許可 (上記を参照) がない。
254 .TP
255 .B EROFS
256 .\"O The named file resides on a read-only file system.
257 指定したファイルが読み込み専用 (read-only) のファイル・システム上にある。
258 .PP
259 .\"O The general errors for
260 .\"O .BR fchown ()
261 .\"O are listed below:
262 .BR fchown ()
263 で一般的なエラーを以下に挙げる:
264 .TP
265 .B EBADF
266 .\"O The descriptor is not valid.
267 ディスクリプターが有効でない。
268 .TP
269 .B EIO
270 .\"O A low-level I/O error occurred while modifying the inode.
271 i ノード (inode) を変更する際に低レベル I/O エラーが発生した。
272 .TP
273 .B ENOENT
274 .\"O See above.
275 上記を参照。
276 .TP
277 .B EPERM
278 .\"O See above.
279 上記を参照。
280 .TP
281 .B EROFS
282 .\"O See above.
283 上記を参照。
284 .\"O .SH "CONFORMING TO"
285 .SH 準拠
286 4.4BSD, SVr4, POSIX.1-2001.
287
288 .\"O The 4.4BSD version can only be
289 .\"O used by the superuser (that is, ordinary users cannot give away files).
290 4.4BSD 版ではスーパー・ユーザーのみが使用できる
291 (つまり、普通のユーザーはファイルを手放すことはできない)。
292 .\"O .\" chown():
293 .\"O .\" SVr4 documents EINVAL, EINTR, ENOLINK and EMULTIHOP returns, but no
294 .\"O .\" ENOMEM.  POSIX.1 does not document ENOMEM or ELOOP error conditions.
295 .\" chown():
296 .\" SVr4 には EINVAL, EINTR, ENOLINK, EMULTIHOP を返すと記載されているが、
297 .\" ENOMEM はない。
298 .\" POSIX.1 には ENOMEM, ELOOP について記載はない。
299 .\"O .\" fchown():
300 .\"O .\" SVr4 documents additional EINVAL, EIO, EINTR, and ENOLINK
301 .\"O .\" error conditions.
302 .\" fchown():
303 .\" SVr4 には他に EINVAL, EIO, EINTR, ENOLINK エラー状態についての記載がある。
304 .\"O .SH NOTES
305 .SH 注意
306 .\"O When a new file is created (by, for example,
307 .\"O .BR open (2)
308 .\"O or
309 .\"O .BR mkdir (2)),
310 .\"O its owner is made the same as the file system user ID of the
311 .\"O creating process.
312 .RB ( open (2)
313
314 .BR mkdir (2)
315 などにより) 新しいファイルが作成されるとき、
316 その所有者は呼び出したプロセスのファイルシステム・ユーザ ID と
317 同じに設定される。
318 .\"O The group of the file depends on a range of factors,
319 .\"O including the type of file system,
320 .\"O the options used to mount the file system,
321 .\"O and whether or not the set-group-ID permission bit is enabled
322 .\"O on the parent directory.
323 そのファイルのグループはいくつかの要因により決定される。
324 その要因としては、
325 ファイルシステムの種類、そのファイルシステムのマウント時に
326 使用されたオプション、親ディレクトリで set-group-ID 許可ビットが
327 有効になっているどうか、がある。
328 .\"O If the file system supports the
329 .\"O .I "\-o\ grpid"
330 .\"O (or, synonymously
331 .\"O .IR "\-o\ bsdgroups" )
332 .\"O and
333 .\"O .I "\-o\ nogrpid"
334 .\"O (or, synonymously
335 .\"O .IR "\-o\ sysvgroups" )
336 .\"O .BR mount (8)
337 .\"O options, then the rules are as follows:
338 ファイルシステムが
339 .BR mount (8)
340 オプションの
341 .I "\-o\ grpid"
342 .RI ( "\-o\ bsdgroups"
343 も同義語) と
344 .I "\-o\ nogrpid"
345 .RI ( "\-o sysvgroups"
346 も同義語) に対応している場合、ルールは以下の通りとなる。
347 .IP * 2
348 .\"O If the file system is mounted with
349 .\"O .IR "\-o\ grpid" ,
350 .\"O then the group of a new file is made
351 .\"O the same as that of the parent directory.
352 ファイルシステムが
353 .I "\-o\ grpid"
354 付きでマウントされている場合、新しいファイルのグループは
355 親ディレクトリのグループと同じになる。
356 .IP *
357 .\"O If the file system is mounted with
358 .\"O .IR "\-o\ nogrpid"
359 .\"O and the set-group-ID bit is disabled on the parent directory,
360 .\"O then the group of a new file is made the same as the
361 .\"O process's file system GID.
362 ファイルシステムが
363 .I "\-o\ nogrpid"
364 付きでマウントされており、親ディレクトリでは set-group-ID ビットが
365 無効になっている場合、新しいファイルのグループは
366 プロセスのファイルシステム GID と同じになる。
367 .IP *
368 .\"O If the file system is mounted with
369 .\"O .IR "\-o\ nogrpid"
370 .\"O and the set-group-ID bit is enabled on the parent directory,
371 .\"O then the group of a new file is made
372 .\"O the same as that of the parent directory.
373 ファイルシステムが
374 .I "\-o\ nogrpid"
375 付きでマウントされており、親ディレクトリでは set-group-ID ビットが
376 有効になっている場合、新しいファイルのグループは
377 親ディレクトリのグループと同じになる。
378 .PP
379 .\"O As at Linux 2.6.25,
380 .\"O the
381 .\"O .IR "\-o\ grpid"
382 .\"O and
383 .\"O .IR "\-o\ nogrpid"
384 .\"O mount options are supported by ext2, ext3, ext4, and XFS.
385 .\"O File systems that don't support these mount options follow the
386 .\"O .IR "\-o\ nogrpid"
387 .\"O rules.
388 Linux 2.6.25 では、マウントオプション
389 .I "\-o\ grpid"
390
391 .I "\-o\ nogrpid"
392 に対応しているファイルシステムは
393 ext2, ext3, ext4, XFS である。
394 これらのマウントオプションに対応していないファイルシステムでは、
395 .I "\-o\ nogrpid"
396 に関するルールが適用される。
397 .PP
398 .\"O The
399 .\"O .BR chown ()
400 .\"O semantics are deliberately violated on NFS file systems
401 .\"O which have UID mapping enabled.
402 .\"O Additionally, the semantics of all system
403 .\"O calls which access the file contents are violated, because
404 .\"O .BR chown ()
405 .\"O may cause immediate access revocation on already open files.
406 .\"O Client side
407 .\"O caching may lead to a delay between the time where ownership have
408 .\"O been changed to allow access for a user and the time where the file can
409 .\"O actually be accessed by the user on other clients.
410 .BR chown ()
411 方式は UID マッピングを使用した
412 NFS ファイル・システムを侵害する。
413 さらにファイルの内容にアクセスする全てのシステム・コールを侵害する。
414 これは
415 .BR chown ()
416 が既にオープンされたファイルに対する
417 アクセスをただちに取り消すことによる。
418 クライアント側のキャッシュにより所有権が変更されて
419 ユーザーのアクセスが許した時点と、実際に他のクライアントでユーザーによって
420 ファイルにアクセスできる時点との間に時間差があるかもしれない。
421
422 .\"O In versions of Linux prior to 2.1.81 (and distinct from 2.1.46),
423 .\"O .BR chown ()
424 .\"O did not follow symbolic links.
425 Linux の 2.1.81 より前のバージョン (特に 2.1.46 以前) では、
426 .BR chown ()
427 はシンボリック・リンクを追跡しない。
428 .\"O Since Linux 2.1.81,
429 .\"O .BR chown ()
430 .\"O does follow symbolic links, and there is a new system call
431 .\"O .BR lchown ()
432 .\"O that does not follow symbolic links.
433 Linux 2.1.81 以降では
434 .BR chown ()
435 はシンボリック・リンクを追跡し、新たなシステム・コール
436 .BR lchown ()
437 はシンボリック・リンクを追跡しない。
438 .\"O Since Linux 2.1.86, this new call (that has the same semantics
439 .\"O as the old
440 .\"O .BR chown ())
441 .\"O has got the same syscall number, and
442 .\"O .BR chown ()
443 .\"O got the newly introduced number.
444 Linux 2.1.86 以降ではこの新しいコール (古い
445 .BR chown ()
446 と全く同じ動作を行なう) は同じシステムコール番号を持ち
447 .BR chown ()
448 は新しく導入された番号を持つ。
449 .\"O .SH EXAMPLE
450 .SH 例
451 .PP
452 .\"O The following program changes the ownership of the file named in
453 .\"O its second command-line argument to the value specified in its
454 .\"O first command-line argument.
455 .\"O The new owner can be specified either as a numeric user ID,
456 .\"O or as a username (which is converted to a user ID by using
457 .\"O .BR getpwnam (3)
458 .\"O to perform a lookup in the system password file).
459 以下のプログラムは、
460 二つ目のコマンドライン引き数で指定された名前のファイルの所有者を、
461 一つ目のコマンドライン引き数で指定された値に変更する。
462 新しい所有者は、数字のユーザ ID かユーザ名のいずれかで指定できる
463 (ユーザ名で指定した場合には、
464 .BR getpwnam (3)
465 を使ってシステムのパスワードファイルの検索が行われ、
466 ユーザ ID への変換が行われる)。
467 .nf
468
469 #include <pwd.h>
470 #include <stdio.h>
471 #include <stdlib.h>
472 #include <unistd.h>
473
474 int
475 main(int argc, char *argv[])
476 {
477     uid_t uid;
478     struct passwd *pwd;
479     char *endptr;
480
481     if (argc != 3 || argv[1][0] == \(aq\\0\(aq) {
482         fprintf(stderr, "%s <owner> <file>\\n", argv[0]);
483         exit(EXIT_FAILURE);
484     }
485
486     uid = strtol(argv[1], &endptr, 10);  /* Allow a numeric string */
487
488     if (*endptr != \(aq\\0\(aq) {         /* Was not pure numeric string */
489         pwd = getpwnam(argv[1]);   /* Try getting UID for username */
490         if (pwd == NULL) {
491             perror("getpwnam");
492             exit(EXIT_FAILURE);
493         }
494
495         uid = pwd\->pw_uid;
496     }
497
498     if (chown(argv[2], uid, \-1) == \-1) {
499         perror("chown");
500         exit(EXIT_FAILURE);
501     }
502
503     exit(EXIT_SUCCESS);
504 }
505 .fi
506 .\"O .SH "SEE ALSO"
507 .SH 関連項目
508 .BR chmod (2),
509 .BR fchownat (2),
510 .BR flock (2),
511 .BR path_resolution (7),
512 .BR symlink (7)