OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man2 / access.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\"                               1993 Michael Haardt, Ian Jackson.
5 .\" and Copyright (C) 2007 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 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 .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya
44 .\"         all rights reserved.
45 .\" Translated 1997-12-17, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
46 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
47 .\" Updated 2001-12-14, Kentaro Shirakata <argrath@ub32.org>
48 .\" Updated 2002-06-17, Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated 2005-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
50 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
51 .\" Updated 2007-09-04, Akihiro MOTOKI, LDP v2.64
52 .\"
53 .\"WORD:        permission              アクセス権
54 .\"WORD:        privileges              権限
55 .\"WORD:        user                    ユーザー
56 .\"WORD:        file system             ファイル・システム
57 .\"WORD:        object                  オブジェクト
58 .\"WORD:        symbolic link           シンボリック・リンク
59 .\"WORD:        refer                   参照する
60 .\"WORD:        mask                    マスク
61 .\"WORD:        path                    パス
62 .\"WORD:        effective user-ID       実効ユーザーID
63 .\"WORD:        real user-ID            実ユーザーID
64 .\"WORD:        uid                     ユーザー ID
65 .\"WORD:        gid                     グループ ID
66 .\"WORD:        directory               ディレクトリ
67 .\"WORD:        call                    コール
68 .\"WORD:        kernel                  カーネル
69 .\"WORD:        memory                  メモリ
70 .\"WORD:        dangling                参照先のない
71 .\"
72 .TH ACCESS 2 2007-07-10 "Linux" "Linux Programmer's Manual"
73 .\"O .SH NAME
74 .SH 名前
75 .\"O access \- check real user's permissions for a file
76 access \- ファイルに対する実ユーザーでのアクセス権をチェックする
77 .\"O .SH SYNOPSIS
78 .SH 書式
79 .nf
80 .B #include <unistd.h>
81 .sp
82 .BI "int access(const char *" pathname ", int " mode );
83 .fi
84 .\"O .SH DESCRIPTION
85 .SH 説明
86 .\"O .BR access ()
87 .\"O checks whether the calling process can access the file
88 .\"O .IR pathname .
89 .\"O If
90 .\"O .I pathname
91 .\"O is a symbolic link, it is dereferenced.
92 .BR access ()
93 は、呼び出し元プロセスがファイル
94 .I pathname
95 にアクセスできるかどうかをチェックする。
96 .I pathname
97 がシンボリック・リンクの場合、シンボリック・リンクは展開される。
98
99 .\"O The
100 .\"O .I mode
101 .\"O specifies the accessibility check(s) to be performed,
102 .\"O and is either the value
103 .\"O .BR F_OK ,
104 .\" F_OK is defined as 0 on every system that I know of.
105 .\"O or a mask consisting of the bitwise OR of one or more of
106 .\"O .BR R_OK ", " W_OK ", and " X_OK .
107 .I mode
108 はチェックを行うアクセス権を指定するもので、その値は
109 .BR F_OK 、
110 .\" 私が知っているすべてのシステムで F_OK は 0 に定義されている。
111 もしくは
112 .BR R_OK ", " W_OK ", " X_OK
113 の 1個以上のビット単位の論理和から構成されるマスクである。
114 .\"O .B F_OK
115 .\"O tests for the existence of the file.
116 .\"O .BR R_OK ", " W_OK ", and " X_OK
117 .\"O test whether the file exists and grants read, write, and
118 .\"O execute permissions, respectively.
119 .B F_OK
120 はファイルが存在するかどうかのみを検査する。
121 .BR R_OK ", " W_OK ", " X_OK
122 は、ファイルが存在して、それぞれ読み込み、書き込み、実行の許可があるか
123 を検査する。
124
125 .\"O The check is done using the calling process's
126 .\"O .I real
127 .\"O UID and GID, rather than the effective IDs as is done when
128 .\"O actually attempting an operation (e.g.,
129 .\"O .BR open (2))
130 .\"O on the file.
131 .\"O This allows set-user-ID programs to
132 .\"O easily determine the invoking user's authority.
133 チェックは、実際に操作が行われる際に使用される実効 (effective) ID でなく、
134 呼び出し元プロセスの
135 .I "実 (real)"
136 UID と
137 .I "実 (real)"
138 GID を使って行われる。
139 これにより、set-user-ID プログラムで、プログラムを起動するユーザの権限を
140 簡単に決定することができる。
141
142 .\"O If the calling process is privileged (i.e., its real UID is zero),
143 .\"O then an
144 .\"O .B X_OK
145 .\"O check is successful for a regular file if execute permission
146 .\"O is enabled for any of the file owner, group, or other.
147 呼び出し元プロセスが特権プロセス (つまり、プロセスの実 UID が 0) の場合、
148 通常のファイルに対する
149 .B X_OK
150 のチェックは、そのファイルの所有者、グループ、他人のいずれかの
151 実行許可が有効になっていれば成功する。
152 .\"O .SH "RETURN VALUE"
153 .SH 返り値
154 .\"O On success (all requested permissions granted), zero is returned.
155 .\"O On error (at least one bit in
156 .\"O .I mode
157 .\"O asked for a permission that is denied, or some other error occurred),
158 .\"O \-1 is returned, and
159 .\"O .I errno
160 .\"O is set appropriately.
161 成功した場合(全ての要求された許可が得られたら)、ゼロが返される。
162 エラーの場合 (少なくとも一つの
163 .I mode
164 で要求された許可がなかった場合や、他のエラーが起きた場合)、
165 \-1 が返され、
166 .I errno
167 が適切に設定される。
168 .\"O .SH ERRORS
169 .SH エラー
170 .\"O .BR access ()
171 .\"O shall fail if:
172 .BR access ()
173 は以下の場合に失敗する。
174 .TP
175 .B EACCES
176 .\"O The requested access would be denied to the file, or search permission
177 .\"O is denied for one of the directories in the path prefix of
178 .\"O .IR pathname .
179 .\"O (See also
180 .\"O .BR path_resolution (7).)
181 要求されたアクセスは
182 そのファイル自身に拒否されたか
183 .I pathname
184 へ至るまでディレクトリのいずれかに対する検索許可
185 (search permission) が得られなかった。
186 .RB ( path_resolution (7)
187 も参照のこと)
188 .TP
189 .B ELOOP
190 .\"O Too many symbolic links were encountered in resolving
191 .\"O .IR pathname .
192 .I pathname
193 を解決する際に遭遇したシンボリック・リンクが多過ぎる。
194 .TP
195 .B ENAMETOOLONG
196 .\"O .I pathname
197 .\"O is too long.
198 .I pathname
199 が長過ぎる。
200 .TP
201 .B ENOENT
202 .\"O A component of
203 .\"O .I pathname
204 .\"O does not exist or is a dangling symbolic link.
205 .I pathname
206 を構成するパスのいずれかが、存在しないか、
207 参照先のない (dangling) シンボリックリンクになっている。
208 .TP
209 .B ENOTDIR
210 .\"O A component used as a directory in
211 .\"O .I pathname
212 .\"O is not, in fact, a directory.
213 .I pathname
214 のディレクトリ部分が、実際にはディレクトリでない。
215 .TP
216 .B EROFS
217 .\"O Write permission was requested for a file on a read-only file system.
218 読み込み専用 (read-only) のファイル・システムに対して書き込み許可を
219 要求した。
220 .PP
221 .\"O .BR access ()
222 .\"O may fail if:
223 .BR access ()
224 は以下の理由により失敗することがある。
225 .TP
226 .B EFAULT
227 .\"O .I pathname
228 .\"O points outside your accessible address space.
229 .I pathname
230 がアクセス可能なアドレス空間の外を指している。
231 .TP
232 .B EINVAL
233 .\"O .I mode
234 .\"O was incorrectly specified.
235 .I mode
236 に不正な値が指定された。
237 .TP
238 .B EIO
239 .\"O An I/O error occurred.
240 I/O エラーが発生した。
241 .TP
242 .B ENOMEM
243 .\"O Insufficient kernel memory was available.
244 カーネルに十分なメモリがない。
245 .TP
246 .B ETXTBSY
247 .\"O Write access was requested to an executable which is being
248 .\"O executed.
249 実行中のファイルに対して書き込みを要求した。
250 .\"O .SH "CONFORMING TO"
251 .SH 準拠
252 SVr4, 4.3BSD, POSIX.1-2001.
253 .\"O .SH NOTES
254 .SH 注意
255 .PP
256 .\"O .BR Warning :
257 .\"O Using
258 .\"O .BR access ()
259 .\"O to check if a user is authorized to, for example,
260 .\"O open a file before actually doing so using
261 .\"O .BR open (2)
262 .\"O creates a security hole, because the user might exploit the short time
263 .\"O interval between checking and opening the file to manipulate it.
264 .BR 警告 :
265 あるユーザが、例えば
266 .BR open (2)
267 によるアクセスが可能かどうかを、(実際に行う前に)
268 .BR access ()
269 を使ってチェックするのは、セキュリティホールの原因になる。
270 なぜならチェックをしてから
271 実際にファイルのオープン操作をする間の短い間隔を悪用できるからである。
272 .\"O .BR "For this reason, the use of this system call should be avoided" .
273 .BR この理由があるので、このシステムコールを使うのは避けるべきである。
274 .PP
275 .\"O .BR access ()
276 .\"O returns an error if any of the access types in
277 .\"O .I mode
278 .\"O is denied, even if some of the other access types in
279 .\"O .I mode
280 .\"O are permitted.
281 .I mode
282 で指定されたアクセス種別のいずれか一つでも拒否されると、
283 たとえ
284 .I mode
285 で指定された他のアクセス種別が許可されたとしても、
286 .BR access ()
287 はエラーを返す。
288 .PP
289 .\"O If the calling process has appropriate privileges (i.e., is superuser),
290 .\"O POSIX.1-2001 permits implementation to indicate success for an
291 .\"O .B X_OK
292 .\"O check even if none of the execute file permission bits are set.
293 .\"O .\" HPU-UX 11 and Tru64 5.1 do this.
294 .\"O Linux does not do this.
295 POSIX.1-2001 では、
296 呼び出し元プロセスが適切な特権を持っている場合
297 (つまり、スーパーユーザの場合)、
298 たとえファイルの実行許可ビットが全くセットされていなくても
299 .B X_OK
300 のチェックとして成功を返す実装が認められている。
301 .\" HPU-UX 11 と Tru64 5.1 はこのようになっている。
302 Linux はこのようにはなっていない。
303 .PP
304 .\"O A file is only accessible if the permissions on each of the
305 .\"O directories in the path prefix of
306 .\"O .I pathname
307 .\"O grant search (i.e., execute) access.
308 .\"O If any directory is inaccessible, then the
309 .\"O .BR access ()
310 .\"O call will fail, regardless of the permissions on the file itself.
311 .I pathname
312 のプレフィックスを構成するディレクトリの全てに対して
313 検索アクセス (すなわち、実行アクセス) が許可された場合にのみ、
314 ファイルはアクセス可能となる。
315 いずれかのディレクトリがアクセス不可の場合、
316 ファイル自身のアクセス許可に関わらず、
317 .BR access ()
318 は失敗する。
319 .PP
320 .\"O Only access bits are checked, not the file type or contents.
321 .\"O Therefore, if a directory is found to be writable,
322 .\"O it probably means that files can be created in the directory,
323 .\"O and not that the directory can be written as a file.
324 .\"O Similarly, a DOS file may be found to be "executable," but the
325 .\"O .BR execve (2)
326 .\"O call will still fail.
327 アクセス・ビットのみがチェックされ、ファイルの種類や内容はチェックされない。
328 従って、ディレクトリが書き込み可能となった場合は、ディレクトリに
329 ファイルを作成することが可能なことを意味するのであり、ディレクトリに
330 ファイルとして書き込むことができるわけではない。
331 同様に DOS のファイルは「実行可能」と判断されるが、
332 .BR execve (2)
333 コールは失敗するだろう。
334 .PP
335 .\"O .BR access ()
336 .\"O may not work correctly on NFS file systems with UID mapping enabled,
337 .\"O because UID mapping is done on the server and hidden from the client,
338 .\"O which checks permissions.
339 .BR access ()
340 は、 UID マッピングを使用した NFS ファイル・システムでは正常に
341 機能しないかもしれない。なぜならば UID のマッピングはサーバーで
342 行なわれ、権利のチェックをするクライアントには見えないからである。
343 .\"O .SH BUGS
344 .SH バグ
345 .\"O In kernel 2.4 (and earlier) there is some strangeness in the handling of
346 .\"O .B X_OK
347 .\"O tests for superuser.
348 .\"O If all categories of execute permission are disabled
349 .\"O for a nondirectory file, then the only
350 .\"O .BR access ()
351 .\"O test that returns \-1 is when
352 .\"O .I mode
353 .\"O is specified as just
354 .\"O .BR X_OK ;
355 .\"O if
356 .\"O .B R_OK
357 .\"O or
358 .\"O .B W_OK
359 .\"O is also specified in
360 .\"O .IR mode ,
361 .\"O then
362 .\"O .BR access ()
363 .\"O returns 0 for such files.
364 .\"O .\" This behavior appears to have been an implementation accident.
365 .\"O Early 2.6 kernels (up to and including 2.6.3)
366 .\"O also behaved in the same way as kernel 2.4.
367 バージョン 2.4 (とそれ以前) のカーネルには、スーパーユーザでの
368 .B X_OK
369 のチェックの扱いに奇妙な点がある。
370 ディレクトリ以外のファイルで
371 (ユーザ、グループ、他人の) 全てのカテゴリについて
372 実行許可がない場合、
373 .BR access ()
374 のチェックで \-1 が返るのは
375 .I mode
376
377 .B X_OK
378 だけが指定されたときだけであり
379 .I mode
380
381 .B R_OK
382
383 .B W_OK
384 が一緒に指定された場合には
385 .BR access ()
386 は 0 を返す。
387 .\" この挙動は実装時の事故だったようである。
388 (バージョン 2.6.3 以前の) 初期の 2.6 系のカーネルも
389 2.4 系のカーネルと同様の動作をする。
390
391 .\"O In kernels before 2.6.20,
392 .\"O .BR access ()
393 .\"O ignored the effect of the
394 .\"O .B MS_NOEXEC
395 .\"O flag if it was used to
396 .\"O .BR mount (2)
397 .\"O the underlying file system.
398 .\"O Since kernel 2.6.20,
399 .\"O .BR access ()
400 .\"O honors this flag.
401 2.6.20 より前のカーネルでは、
402 ファイルが存在するファイルシステムを
403 .BR mount (2)
404 する際に指定された
405 .B MS_NOEXEC
406 フラグの効果を、
407 .BR access ()
408 は無視していた。
409 カーネル 2.6.20 以降では、
410 .BR access ()
411 はこのフラグを考慮するようになっている。
412 .\"O .SH "SEE ALSO"
413 .SH 関連項目
414 .BR chmod (2),
415 .BR chown (2),
416 .BR faccessat (2),
417 .BR open (2),
418 .BR setgid (2),
419 .BR setuid (2),
420 .BR stat (2),
421 .BR eauidaccess (3),
422 .BR credentials (7),
423 .BR path_resolution (7)