.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" This manpage is Copyright (C) 1992 Drew Eckhardt; .\" 1993 Michael Haardt, Ian Jackson. .\" and Copyright (C) 2007 Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" Modified 1993-07-21 Rik Faith (faith@cs.unc.edu) .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com): .\" Removed note about old kernel (pre-1.1.44) using wrong id on path. .\" Modified 1996-03-18 by Martin Schulze (joey@infodrom.north.de): .\" Stated more clearly how it behaves with symbolic links. .\" Added correction due to Nick Duffek (nsd@bbc.com), aeb, 960426 .\" Modified 1996-09-07 by Michael Haardt: .\" Restrictions for NFS .\" Modified 1997-09-09 by Joseph S. Myers .\" Modified 1998-01-13 by Michael Haardt: .\" Using access is often insecure .\" Modified 2001-10-16 by aeb .\" Modified 2002-04-23 by Roger Luethi .\" Modified 2004-06-23 by Michael Kerrisk .\" 2007-06-10, mtk, various parts rewritten, and added BUGS section. .\" .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-12-17, HANATAKA Shinya .\" Modified 1998-05-11, HANATAKA Shinya .\" Updated 2001-12-14, Kentaro Shirakata .\" Updated 2002-06-17, Kentaro Shirakata .\" Updated 2005-02-23, Akihiro MOTOKI .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46 .\" Updated 2007-09-04, Akihiro MOTOKI, LDP v2.64 .\" .\"WORD: permission アクセス権 .\"WORD: privileges 権限 .\"WORD: user ユーザー .\"WORD: file system ファイル・システム .\"WORD: object オブジェクト .\"WORD: symbolic link シンボリック・リンク .\"WORD: refer 参照する .\"WORD: mask マスク .\"WORD: path パス .\"WORD: effective user-ID 実効ユーザーID .\"WORD: real user-ID 実ユーザーID .\"WORD: uid ユーザー ID .\"WORD: gid グループ ID .\"WORD: directory ディレクトリ .\"WORD: call コール .\"WORD: kernel カーネル .\"WORD: memory メモリ .\"WORD: dangling 参照先のない .\" .TH ACCESS 2 2007-07-10 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O access \- check real user's permissions for a file access \- ファイルに対する実ユーザーでのアクセス権をチェックする .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int access(const char *" pathname ", int " mode ); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O .BR access () .\"O checks whether the calling process can access the file .\"O .IR pathname . .\"O If .\"O .I pathname .\"O is a symbolic link, it is dereferenced. .BR access () は、呼び出し元プロセスがファイル .I pathname にアクセスできるかどうかをチェックする。 .I pathname がシンボリック・リンクの場合、シンボリック・リンクは展開される。 .\"O The .\"O .I mode .\"O specifies the accessibility check(s) to be performed, .\"O and is either the value .\"O .BR F_OK , .\" F_OK is defined as 0 on every system that I know of. .\"O or a mask consisting of the bitwise OR of one or more of .\"O .BR R_OK ", " W_OK ", and " X_OK . .I mode はチェックを行うアクセス権を指定するもので、その値は .BR F_OK 、 .\" 私が知っているすべてのシステムで F_OK は 0 に定義されている。 もしくは .BR R_OK ", " W_OK ", " X_OK の 1個以上のビット単位の論理和から構成されるマスクである。 .\"O .B F_OK .\"O tests for the existence of the file. .\"O .BR R_OK ", " W_OK ", and " X_OK .\"O test whether the file exists and grants read, write, and .\"O execute permissions, respectively. .B F_OK はファイルが存在するかどうかのみを検査する。 .BR R_OK ", " W_OK ", " X_OK は、ファイルが存在して、それぞれ読み込み、書き込み、実行の許可があるか を検査する。 .\"O The check is done using the calling process's .\"O .I real .\"O UID and GID, rather than the effective IDs as is done when .\"O actually attempting an operation (e.g., .\"O .BR open (2)) .\"O on the file. .\"O This allows set-user-ID programs to .\"O easily determine the invoking user's authority. チェックは、実際に操作が行われる際に使用される実効 (effective) ID でなく、 呼び出し元プロセスの .I "実 (real)" UID と .I "実 (real)" GID を使って行われる。 これにより、set-user-ID プログラムで、プログラムを起動するユーザの権限を 簡単に決定することができる。 .\"O If the calling process is privileged (i.e., its real UID is zero), .\"O then an .\"O .B X_OK .\"O check is successful for a regular file if execute permission .\"O is enabled for any of the file owner, group, or other. 呼び出し元プロセスが特権プロセス (つまり、プロセスの実 UID が 0) の場合、 通常のファイルに対する .B X_OK のチェックは、そのファイルの所有者、グループ、他人のいずれかの 実行許可が有効になっていれば成功する。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success (all requested permissions granted), zero is returned. .\"O On error (at least one bit in .\"O .I mode .\"O asked for a permission that is denied, or some other error occurred), .\"O \-1 is returned, and .\"O .I errno .\"O is set appropriately. 成功した場合(全ての要求された許可が得られたら)、ゼロが返される。 エラーの場合 (少なくとも一つの .I mode で要求された許可がなかった場合や、他のエラーが起きた場合)、 \-1 が返され、 .I errno が適切に設定される。 .\"O .SH ERRORS .SH エラー .\"O .BR access () .\"O shall fail if: .BR access () は以下の場合に失敗する。 .TP .B EACCES .\"O The requested access would be denied to the file, or search permission .\"O is denied for one of the directories in the path prefix of .\"O .IR pathname . .\"O (See also .\"O .BR path_resolution (7).) 要求されたアクセスは そのファイル自身に拒否されたか .I pathname へ至るまでディレクトリのいずれかに対する検索許可 (search permission) が得られなかった。 .RB ( path_resolution (7) も参照のこと) .TP .B ELOOP .\"O Too many symbolic links were encountered in resolving .\"O .IR pathname . .I pathname を解決する際に遭遇したシンボリック・リンクが多過ぎる。 .TP .B ENAMETOOLONG .\"O .I pathname .\"O is too long. .I pathname が長過ぎる。 .TP .B ENOENT .\"O A component of .\"O .I pathname .\"O does not exist or is a dangling symbolic link. .I pathname を構成するパスのいずれかが、存在しないか、 参照先のない (dangling) シンボリックリンクになっている。 .TP .B ENOTDIR .\"O A component used as a directory in .\"O .I pathname .\"O is not, in fact, a directory. .I pathname のディレクトリ部分が、実際にはディレクトリでない。 .TP .B EROFS .\"O Write permission was requested for a file on a read-only file system. 読み込み専用 (read-only) のファイル・システムに対して書き込み許可を 要求した。 .PP .\"O .BR access () .\"O may fail if: .BR access () は以下の理由により失敗することがある。 .TP .B EFAULT .\"O .I pathname .\"O points outside your accessible address space. .I pathname がアクセス可能なアドレス空間の外を指している。 .TP .B EINVAL .\"O .I mode .\"O was incorrectly specified. .I mode に不正な値が指定された。 .TP .B EIO .\"O An I/O error occurred. I/O エラーが発生した。 .TP .B ENOMEM .\"O Insufficient kernel memory was available. カーネルに十分なメモリがない。 .TP .B ETXTBSY .\"O Write access was requested to an executable which is being .\"O executed. 実行中のファイルに対して書き込みを要求した。 .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, 4.3BSD, POSIX.1-2001. .\"O .SH NOTES .SH 注意 .PP .\"O .BR Warning : .\"O Using .\"O .BR access () .\"O to check if a user is authorized to, for example, .\"O open a file before actually doing so using .\"O .BR open (2) .\"O creates a security hole, because the user might exploit the short time .\"O interval between checking and opening the file to manipulate it. .BR 警告 : あるユーザが、例えば .BR open (2) によるアクセスが可能かどうかを、(実際に行う前に) .BR access () を使ってチェックするのは、セキュリティホールの原因になる。 なぜならチェックをしてから 実際にファイルのオープン操作をする間の短い間隔を悪用できるからである。 .\"O .BR "For this reason, the use of this system call should be avoided" . .BR この理由があるので、このシステムコールを使うのは避けるべきである。 .PP .\"O .BR access () .\"O returns an error if any of the access types in .\"O .I mode .\"O is denied, even if some of the other access types in .\"O .I mode .\"O are permitted. .I mode で指定されたアクセス種別のいずれか一つでも拒否されると、 たとえ .I mode で指定された他のアクセス種別が許可されたとしても、 .BR access () はエラーを返す。 .PP .\"O If the calling process has appropriate privileges (i.e., is superuser), .\"O POSIX.1-2001 permits implementation to indicate success for an .\"O .B X_OK .\"O check even if none of the execute file permission bits are set. .\"O .\" HPU-UX 11 and Tru64 5.1 do this. .\"O Linux does not do this. POSIX.1-2001 では、 呼び出し元プロセスが適切な特権を持っている場合 (つまり、スーパーユーザの場合)、 たとえファイルの実行許可ビットが全くセットされていなくても .B X_OK のチェックとして成功を返す実装が認められている。 .\" HPU-UX 11 と Tru64 5.1 はこのようになっている。 Linux はこのようにはなっていない。 .PP .\"O A file is only accessible if the permissions on each of the .\"O directories in the path prefix of .\"O .I pathname .\"O grant search (i.e., execute) access. .\"O If any directory is inaccessible, then the .\"O .BR access () .\"O call will fail, regardless of the permissions on the file itself. .I pathname のプレフィックスを構成するディレクトリの全てに対して 検索アクセス (すなわち、実行アクセス) が許可された場合にのみ、 ファイルはアクセス可能となる。 いずれかのディレクトリがアクセス不可の場合、 ファイル自身のアクセス許可に関わらず、 .BR access () は失敗する。 .PP .\"O Only access bits are checked, not the file type or contents. .\"O Therefore, if a directory is found to be writable, .\"O it probably means that files can be created in the directory, .\"O and not that the directory can be written as a file. .\"O Similarly, a DOS file may be found to be "executable," but the .\"O .BR execve (2) .\"O call will still fail. アクセス・ビットのみがチェックされ、ファイルの種類や内容はチェックされない。 従って、ディレクトリが書き込み可能となった場合は、ディレクトリに ファイルを作成することが可能なことを意味するのであり、ディレクトリに ファイルとして書き込むことができるわけではない。 同様に DOS のファイルは「実行可能」と判断されるが、 .BR execve (2) コールは失敗するだろう。 .PP .\"O .BR access () .\"O may not work correctly on NFS file systems with UID mapping enabled, .\"O because UID mapping is done on the server and hidden from the client, .\"O which checks permissions. .BR access () は、 UID マッピングを使用した NFS ファイル・システムでは正常に 機能しないかもしれない。なぜならば UID のマッピングはサーバーで 行なわれ、権利のチェックをするクライアントには見えないからである。 .\"O .SH BUGS .SH バグ .\"O In kernel 2.4 (and earlier) there is some strangeness in the handling of .\"O .B X_OK .\"O tests for superuser. .\"O If all categories of execute permission are disabled .\"O for a nondirectory file, then the only .\"O .BR access () .\"O test that returns \-1 is when .\"O .I mode .\"O is specified as just .\"O .BR X_OK ; .\"O if .\"O .B R_OK .\"O or .\"O .B W_OK .\"O is also specified in .\"O .IR mode , .\"O then .\"O .BR access () .\"O returns 0 for such files. .\"O .\" This behavior appears to have been an implementation accident. .\"O Early 2.6 kernels (up to and including 2.6.3) .\"O also behaved in the same way as kernel 2.4. バージョン 2.4 (とそれ以前) のカーネルには、スーパーユーザでの .B X_OK のチェックの扱いに奇妙な点がある。 ディレクトリ以外のファイルで (ユーザ、グループ、他人の) 全てのカテゴリについて 実行許可がない場合、 .BR access () のチェックで \-1 が返るのは .I mode に .B X_OK だけが指定されたときだけであり .I mode に .B R_OK や .B W_OK が一緒に指定された場合には .BR access () は 0 を返す。 .\" この挙動は実装時の事故だったようである。 (バージョン 2.6.3 以前の) 初期の 2.6 系のカーネルも 2.4 系のカーネルと同様の動作をする。 .\"O In kernels before 2.6.20, .\"O .BR access () .\"O ignored the effect of the .\"O .B MS_NOEXEC .\"O flag if it was used to .\"O .BR mount (2) .\"O the underlying file system. .\"O Since kernel 2.6.20, .\"O .BR access () .\"O honors this flag. 2.6.20 より前のカーネルでは、 ファイルが存在するファイルシステムを .BR mount (2) する際に指定された .B MS_NOEXEC フラグの効果を、 .BR access () は無視していた。 カーネル 2.6.20 以降では、 .BR access () はこのフラグを考慮するようになっている。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR chmod (2), .BR chown (2), .BR faccessat (2), .BR open (2), .BR setgid (2), .BR setuid (2), .BR stat (2), .BR eauidaccess (3), .BR credentials (7), .BR path_resolution (7)