OSDN Git Service

e63af0414fcec98e0bb42e59e93558bbce9f4cdb
[linuxjm/LDP_man-pages.git] / release / man2 / access.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2007 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 1993-07-21 Rik Faith (faith@cs.unc.edu)
28 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
29 .\"   Removed note about old kernel (pre-1.1.44) using wrong id on path.
30 .\" Modified 1996-03-18 by Martin Schulze (joey@infodrom.north.de):
31 .\"   Stated more clearly how it behaves with symbolic links.
32 .\" Added correction due to Nick Duffek (nsd@bbc.com), aeb, 960426
33 .\" Modified 1996-09-07 by Michael Haardt:
34 .\"   Restrictions for NFS
35 .\" Modified 1997-09-09 by Joseph S. Myers <jsm28@cam.ac.uk>
36 .\" Modified 1998-01-13 by Michael Haardt:
37 .\"   Using access is often insecure
38 .\" Modified 2001-10-16 by aeb
39 .\" Modified 2002-04-23 by Roger Luethi <rl@hellgate.ch>
40 .\" Modified 2004-06-23 by Michael Kerrisk
41 .\" 2007-06-10, mtk, various parts rewritten, and added BUGS section.
42 .\"
43 .\"*******************************************************************
44 .\"
45 .\" This file was generated with po4a. Translate the source file.
46 .\"
47 .\"*******************************************************************
48 .\"
49 .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya
50 .\"         all rights reserved.
51 .\" Translated 1997-12-17, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
52 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
53 .\" Updated 2001-12-14, Kentaro Shirakata <argrath@ub32.org>
54 .\" Updated 2002-06-17, Kentaro Shirakata <argrath@ub32.org>
55 .\" Updated 2005-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
56 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
57 .\" Updated 2007-09-04, Akihiro MOTOKI, LDP v2.64
58 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
59 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
60 .\"
61 .TH ACCESS 2 2013\-09\-13 Linux "Linux Programmer's Manual"
62 .SH 名前
63 access \- ファイルに対する実ユーザーでのアクセス権をチェックする
64 .SH 書式
65 .nf
66 \fB#include <unistd.h>\fP
67 .sp
68 \fBint access(const char *\fP\fIpathname\fP\fB, int \fP\fImode\fP\fB);\fP
69 .fi
70 .SH 説明
71 \fBaccess\fP()  は、呼び出し元プロセスがファイル \fIpathname\fP にアクセスできるかどうかをチェックする。 \fIpathname\fP
72 がシンボリック・リンクの場合、シンボリック・リンクは展開される。
73
74 .\" F_OK is defined as 0 on every system that I know of.
75 \fImode\fP はチェックを行うアクセス権を指定するもので、その値は \fBF_OK\fP、 もしくは \fBR_OK\fP, \fBW_OK\fP, \fBX_OK\fP の
76 1個以上のビット単位の論理和から構成されるマスクである。 \fBF_OK\fP はファイルが存在するかどうかのみを検査する。 \fBR_OK\fP,
77 \fBW_OK\fP, \fBX_OK\fP は、ファイルが存在して、それぞれ読み込み、書き込み、実行の許可があるか を検査する。
78
79 チェックは、実際に操作が行われる際に使用される実効 (effective) ID でなく、 呼び出し元プロセスの \fI実 (real)\fP UID と
80 \fI実 (real)\fP GID を使って行われる。 これにより、set\-user\-ID プログラムで、プログラムを起動するユーザの権限を
81 簡単に決定することができる。
82
83 呼び出し元プロセスが特権プロセス (つまり、プロセスの実 UID が 0) の場合、 通常のファイルに対する \fBX_OK\fP
84 のチェックは、そのファイルの所有者、グループ、他人のいずれかの 実行許可が有効になっていれば成功する。
85 .SH 返り値
86 成功した場合 (要求した全てについて許可が得られたか、 \fImode\fP が \fBF_OK\fP でファイルが存在した場合)、ゼロが返される。 エラーの場合
87 (\fImode\fP の少なくとも一つのビットで要求した許可がなかった場合、 \fImode\fP が \fBF_OK\fP
88 でファイルが存在しなかった場合、他のエラーが起こった場合)、\-1 が返され、 \fIerrno\fP が適切に設定される。
89 .SH エラー
90 \fBaccess\fP()  は以下の場合に失敗する。
91 .TP 
92 \fBEACCES\fP
93 要求されたアクセスは そのファイル自身に拒否されたか \fIpathname\fP へ至るまでディレクトリのいずれかに対する検索許可 (search
94 permission) が得られなかった。 (\fBpath_resolution\fP(7)  も参照のこと)
95 .TP 
96 \fBELOOP\fP
97 \fIpathname\fP を解決するときに、解決すべきシンボリックリンクが多すぎた。
98 .TP 
99 \fBENAMETOOLONG\fP
100 \fIpathname\fP が長過ぎる。
101 .TP 
102 \fBENOENT\fP
103 \fIpathname\fP を構成するパスのいずれかが、存在しないか、 参照先のない (dangling) シンボリックリンクになっている。
104 .TP 
105 \fBENOTDIR\fP
106 \fIpathname\fP のディレクトリ部分が実際にはディレクトリでない。
107 .TP 
108 \fBEROFS\fP
109 Write permission was requested for a file on a read\-only filesystem.
110 .PP
111 \fBaccess\fP()  は以下の理由により失敗することがある。
112 .TP 
113 \fBEFAULT\fP
114 \fIpathname\fP がアクセス可能なアドレス空間の外を指している。
115 .TP 
116 \fBEINVAL\fP
117 \fImode\fP に不正な値が指定された。
118 .TP 
119 \fBEIO\fP
120 I/O エラーが発生した。
121 .TP 
122 \fBENOMEM\fP
123 カーネルに十分なメモリがない。
124 .TP 
125 \fBETXTBSY\fP
126 実行中のファイルに対して書き込みを要求した。
127 .SH 準拠
128 SVr4, 4.3BSD, POSIX.1\-2001.
129 .SH 注意
130 .PP
131 \fB警告\fP: あるユーザが、例えば \fBopen\fP(2) によるアクセスが可能かどうかを、
132 (実際に行う前に) \fBaccess\fP() を使ってチェックするのは、セキュリティホール
133 の原因になる。なぜならチェックをしてから 実際にファイルのオープン操作を
134 する間の短い間隔を悪用できるからである。 \fBこの理由があるので、この
135 システムコールを使うのは避けるべきである。\fP
136 (ここで説明した例の場合には、より安全な方法としては、
137 そのプロセスの実効ユーザ ID を実ユーザ ID に一時的に切り替えてから
138 \fBopen\fP(2) を呼び出す方法がある。)
139 .PP
140 \fBaccess\fP() は常にシンボリックリンクの展開を行う。
141 シンボリックリンクのアクセス許可を確認する必要がある場合は、
142 \fBAT_SYMLINK_NOFOLLOW\fP フラグ付きで \fBfaccessat\fP(2) を使うこと。
143 .PP
144 \fImode\fP で指定されたアクセス種別のいずれか一つでも拒否されると、 たとえ \fImode\fP で指定された他のアクセス種別が許可されたとしても、
145 \fBaccess\fP()  はエラーを返す。
146 .PP
147 .\" HPU-UX 11 and Tru64 5.1 do this.
148 POSIX.1\-2001 では、 呼び出し元プロセスが適切な特権を持っている場合 (つまり、スーパーユーザの場合)、
149 たとえファイルの実行許可ビットが全くセットされていなくても \fBX_OK\fP のチェックとして成功を返す実装が認められている。 Linux
150 はこのようにはなっていない。
151 .PP
152 \fIpathname\fP のプレフィックスを構成するディレクトリの全てに対して 検索アクセス (すなわち、実行アクセス) が許可された場合にのみ、
153 ファイルはアクセス可能となる。 いずれかのディレクトリがアクセス不可の場合、 ファイル自身のアクセス許可に関わらず、 \fBaccess\fP()
154 は失敗する。
155 .PP
156 アクセス・ビットのみがチェックされ、ファイルの種類や内容はチェックされない。 従って、ディレクトリが書き込み可能となった場合は、ディレクトリに
157 ファイルを作成することが可能なことを意味するのであり、ディレクトリに ファイルとして書き込むことができるわけではない。 同様に DOS
158 のファイルは「実行可能」と判断されるが、 \fBexecve\fP(2)  コールは失敗するだろう。
159 .PP
160 \fBaccess\fP()  may not work correctly on NFSv2 filesystems with UID mapping
161 enabled, because UID mapping is done on the server and hidden from the
162 client, which checks permissions.  (NFS versions 3 and higher perform the
163 check on the server.)  Similar problems can occur to FUSE mounts.
164 .SH バグ
165 .\" This behavior appears to have been an implementation accident.
166 バージョン 2.4 (とそれ以前) のカーネルには、スーパーユーザでの \fBX_OK\fP のチェックの扱いに奇妙な点がある。 ディレクトリ以外のファイルで
167 (ユーザ、グループ、他人の) 全てのカテゴリについて 実行許可がない場合、 \fBaccess\fP()  のチェックで \-1 が返るのは \fImode\fP に
168 \fBX_OK\fP だけが指定されたときだけであり \fImode\fP に \fBR_OK\fP や \fBW_OK\fP が一緒に指定された場合には
169 \fBaccess\fP()  は 0 を返す。 (バージョン 2.6.3 以前の) 初期の 2.6 系のカーネルも 2.4 系のカーネルと同様の動作をする。
170
171 In kernels before 2.6.20, \fBaccess\fP()  ignored the effect of the
172 \fBMS_NOEXEC\fP flag if it was used to \fBmount\fP(2)  the underlying filesystem.
173 Since kernel 2.6.20, \fBaccess\fP()  honors this flag.
174 .SH 関連項目
175 \fBchmod\fP(2), \fBchown\fP(2), \fBfaccessat\fP(2), \fBopen\fP(2), \fBsetgid\fP(2),
176 \fBsetuid\fP(2), \fBstat\fP(2), \fBeauidaccess\fP(3), \fBcredentials\fP(7),
177 \fBpath_resolution\fP(7)
178 .SH この文書について
179 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
180 である。プロジェクトの説明とバグ報告に関する情報は
181 http://www.kernel.org/doc/man\-pages/ に書かれている。