Atributo estendido no link simbólico

5

Estou tentando definir alguns atributos estendidos em um link simbólico no Fedora 15.

De acordo com o uso de setfattr , existe uma opção -h para essa finalidade:

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

No entanto, a opção parece não funcionar. Usar -h em arquivos de links simbólicos apenas informa Operation not permitted sem definir o atributo estendido.

Por exemplo:

[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

Por que isso acontece?

    
por Gilles 12.07.2011 / 09:04

1 resposta

5

Eu encontrei este comentário em 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.
 */

Lá você tem isso; o kernel não permitirá definir atributos no namespace do usuário em nada além de um arquivo ou diretório regular.

xattr(7) fornece mais detalhes:

Atributos de usuário estendidos

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).
    
por 12.07.2011 / 19:29