web-dev-qa-db-ja.com

シンボリックリンクの拡張属性

Fedora15のシンボリックリンクにいくつかの拡張属性を設定しようとしています。

setfattrの使用法によると、そのような目的のためのオプション-hがあります。

setfattr 2.4.44 -- set extended attributes
Usage: setfattr {-n name} [-v value] [-h] file...
       setfattr {-x name} [-h] file...
  -n, --name=name         set the value of the named extended attribute
  -x, --remove=name       remove the named extended attribute
  -v, --value=value       use value as the attribute value
  -h, --no-dereference    do not dereference symbolic links
      --restore=file      restore extended attributes
      --version           print version and exit
      --help              this help text

ただし、このオプションは機能していないようです。シンボリックリンクファイルで-hを使用すると、拡張属性を設定せずにOperation not permittedが報告されるだけです。

例えば:

[dummy@notebook test]$ ls -l
total 0
-rw-rw-r-- 1 dummy dummy 0 Jul 12 14:35 file
lrwxrwxrwx 1 dummy dummy 6 Jul 12 14:35 link -> ./file
[dummy@notebook test]$ setfattr -n user.name -v value1 file
[dummy@notebook test]$ getfattr -n user.name file
# file: file
user.name="value1"

[dummy@notebook test]$ setfattr -n user.name -v value2 link
[dummy@notebook test]$ getfattr -n user.name file
# file: file
user.name="value2"

[dummy@notebook test]$ setfattr -n user.name -v value3 -h link
setfattr: link: Operation not permitted
[dummy@notebook test]$ getfattr -n user.name -h link
link: user.name: Operation not permitted

どうしてこれなの?

5
dummyhuan

私はこのコメントをfs/xattr.cで見つけました:

_/* In user.* namespace, only regular files and directories can have
 * extended attributes. For sticky directories, only the owner and
 * privileged user can write attributes.
 */
_

そこにあります。カーネルは、通常のファイルまたはディレクトリ以外のユーザー名前空間に属性を設定することを許可しません。

xattr(7) 詳細を提供します:

拡張ユーザー属性

_Extended user attributes may be assigned to files and directories for
storing arbitrary additional information such as the mime type,
character set or encoding of a file.  The access permissions for user
attributes are defined by the file permission bits: read permission
is required to retrieve the attribute value, and writer permission is
required to change it.

The file permission bits of regular files and directories are
interpreted differently from the file permission bits of special
files and symbolic links.  For regular files and directories the file
permission bits define access to the file's contents, while for
device special files they define access to the device described by
the special file.  The file permissions of symbolic links are not
used in access checks.  These differences would allow users to
consume filesystem resources in a way not controllable by disk quotas
for group or world writable special files and directories.

For this reason, extended user attributes are allowed only for
regular files and directories, and access to extended user attributes
is restricted to the owner and to users with appropriate capabilities
for directories with the sticky bit set (see the chmod(1) manual page
for an explanation of the sticky bit).
_
5
psusi