sudoersコマンドの2番目の形式はどのように呼び出されますか?

sudoersコマンドの2番目の形式はどのように呼び出されますか?

表 1 - 誰がどこで =(as_whom) 何を -lisa ALL=(ALL) /usr/bin/passwd *, !/usr/bin/passwd root

表2 - 誰がどこにいますか? -lisa ALL= /usr/bin/passwd [a-z0-9]*, !/usr/bin/passwd root

最初の形式では正規表現が機能せず、globbingのみが実行されますが、2番目の形式は正規表現をサポートしているようですが、その名前のドキュメントが見つからず、グループ指定子のみが必要です。

ベストアンサー1

~からman sudoers.5:

Wildcards

    sudo allows shell-style wildcards (aka meta or glob characters)
    to be used in host names, path names and command line arguments 
    in the sudoers file.  Wildcard matching is done via the glob(3) 
    and fnmatch(3) functions as specified by IEEE Std 1003.1 
    (“POSIX.1”).

    *         Matches any set of zero or more characters (including 
              white space).

    ?         Matches any single character (including white space).

    [...]     Matches any character in the specified range.

    [!...]    Matches any character not in the specified range.

    \x        For any character ‘x’, evaluates to ‘x’.  This is 
              used to escape special characters such as: ‘*’, ‘?’, 
              ‘[’, and ‘]’.

    Note that these are not regular expressions.  Unlike a regular 
    expression there is no way to match one or more characters 
    within a range.

最後のメモが面白いです。マニュアルページでは、引き続きコマンドライン引数のワイルドカードを慎重に使用する必要があることを説明し、ワイルドカードルールのいくつかの例外を定義します。

しかし、2行目が正規表現をサポートしているように見えるのは、一部の正規表現ルールと非常によく似ているためです。

正規表現を使用すると、式は通常[a-z0-9]*「a-z0-9の範囲内のすべての文字数」を意味しますが、この場合は「a-z0-9の範囲の1文字の後に0個以上の文字セットが続きます」を意味します。 。

おすすめ記事