filetest-1.02 > filetest

名前

filetest - Perl pragma to control the filetest permission operators

filetest - ファイルテスト権限演算子を制御する Perl プラグマ

概要

    $can_perhaps_read = -r "file";      # use the mode bits
    {
        use filetest 'access';          # intuit harder
        $can_really_read = -r "file";
    }
    $can_perhaps_read = -r "file";      # use the mode bits again

説明

This pragma tells the compiler to change the behaviour of the filetest permission operators, -r -w -x -R -W -X (see perlfunc).

このプラグマはファイルテスト権限演算子 -r -w -x -R -W -X の (perlfunc 参照)振る舞いを変えることをコンパイラに伝えます。

The default behaviour of file test operators is to use the simple mode bits as returned by the stat() family of system calls. However, many operating systems have additional features to define more complex access rights, for example ACLs (Access Control Lists). For such environments, use filetest may help the permission operators to return results more consistent with other tools.

ファイルテスト演算子のデフォルトの振る舞いは、システムコールの stat() 系列から返された単純なモードビットを使うものです。 しかし、多くのオペレーティングシステムは、例えば ACL (Access Control List)のような、より複雑なアクセス権限を定義するための 追加の機能を持っています。 このような環境のために、use filetest は権限演算子が他のツールと より一貫性のある結果を返す助けをします。

The use filetest or no filetest statements affect file tests defined in their block, up to the end of the closest enclosing block (they are lexically block-scoped).

use filetestno filetest 文は、一番内側のブロックの終わりまで、 定義されたブロック内のファイルテストに影響を与えます (レキシカルブロック スコープを持ちます)。

Currently, only the access sub-pragma is implemented. It enables (or disables) the use of access() when available, that is, on most UNIX systems and other POSIX environments. See details below.

現在のところ、access 副プラグマのみが実装されています。 これは利用可能な(つまり、ほとんどの UNIX システムとその他の POSIX 環境の) 場合に access() の使用を有効に(または無効に)します。 詳しくは以下を参照してください。

これを注意深く検討する

The stat() mode bits are probably right for most of the files and directories found on your system, because few people want to use the additional features offered by access(). But you may encounter surprises if your program runs on a system that uses ACLs, since the stat() information won't reflect the actual permissions.

stat() モードビットはシステムで見付かるほとんどのファイルとディレクトリに 対しておそらく正しいです; なぜなら access() で提供される追加の機能を 使いたい人はほとんどいないからです。 しかし ACL を使うシステムでプログラムを動かすと、驚きに 遭遇するかもしれません; stat() 情報は実際の権限を反映していないからです。

There may be a slight performance decrease in the filetest operations when the filetest pragma is in effect, because checking bits is very cheap.

filetest プラグマが有効の時、ファイルテスト演算子の性能は少し低下します; ビットのチェックはとても安価だからです。

Also, note that using the file tests for security purposes is a lost cause from the start: there is a window open for race conditions (who is to say that the permissions will not change between the test and the real operation?). Therefore if you are serious about security, just try the real operation and test for its success - think in terms of atomic operations. Filetests are more useful for filesystem administrative tasks, when you have no need for the content of the elements on disk.

また、セキュリティの理由でファイルテストを使うことは最初から大義を 失っていることに注意してください: 競合条件のための窓が開いています (テストと実際の操作の間に権限が変更されないと誰が言えますか?)。 従って、セキュリティについて真剣に考えるなら、単に実際に操作を行って 成功したかどうかをテストしてください - アトミックな操作ということについて 考えてください。 ファイルテストはファイルシステム管理タスクでより有用です; ディスク上の 要素の内容には関係がない場合です。

"access" 副プラグマ

UNIX and POSIX systems provide an abstract access() operating system call, which should be used to query the read, write, and execute rights. This function hides various distinct approaches in additional operating system specific security features, like Access Control Lists (ACLs)

UNIX と POSIX のシステムは抽象 access() オペレーティングシステムコールを 提供しています; これは読み書き実行権限の問い合わせに使われます。 この関数は Access Control List (ACL) のようなオペレーティングシステムに 固有の追加のセキュリティ機能の様々な異なった手法を隠蔽します。

The extended filetest functionality is used by Perl only when the argument of the operators is a filename, not when it is a filehandle.

拡張されたファイルテスト機能は、演算子の引数がファイル名の時にのみ Perl によって使われます; ファイルハンドルの時は使われません。

Limitation with regard to _

(_ に関連する制限)

Because access() does not invoke stat() (at least not in a way visible to Perl), the stat result cache "_" is not set. This means that the outcome of the following two tests is different. The first has the stat bits of /etc/passwd in _, and in the second case this still contains the bits of /etc.

access() は(少なくとも Perl から見える形では) stat() を起動しないので、 stat の結果のキャッシュ "_" は設定されません。 これは、以下の二つのテストの結果が異なるということです。 前者は /etc/passwd の stat ビットが _ に保管されますが、後者は /etc のビットを含んでいます。

 { -d '/etc';
   -w '/etc/passwd';
   print -f _ ? 'Yes' : 'No';   # Yes
 }

 { use filetest 'access';
   -d '/etc';
   -w '/etc/passwd';
   print -f _ ? 'Yes' : 'No';   # No
 }

Of course, unless your OS does not implement access(), in which case the pragma is simply ignored. Best not to use _ at all in a file where the filetest pragma is active!

もちろん、OS が access() を実装していない限り、このプラグマは単に 無視されます。 filetest プラグマが有効なところではファイルに対して一切 _ を使わないのが 最良です!

As a side effect, as _ doesn't work, stacked filetest operators (-f -w $file) won't work either.

副作用として、_ が動作しないので、スタックしたファイルテスト演算子 (-f -w $file) は動作しません。

This limitation might be removed in a future version of perl.

この制限は将来のバージョンの perl では取り除かれるかもしれません。