【问题标题】:lsetxattr returns EPERM if attempt to set a value to symlink如果尝试将值设置为符号链接,lsetxattr 返回 EPERM
【发布时间】:2021-05-05 05:13:25
【问题描述】:

我正在测试将时间戳添加到 xattr 的简单程序。 lsetxattr 系统调用返回 EPERM 错误。这是预期的行为吗? 如何将 xattr 设置为符号链接,而不是点击链接?

#include <sys/types.h>
#include <attr/xattr.h>
#include <errno.h>
#include <time.h>
#include <stdio.h>

int main(int argc, char **argv){
    time_t t = time(NULL);
    if(lsetxattr(argv[1], "user.ts", &t, sizeof(time_t), 0) == -1){
        perror(argv[1]);
    }
    return(0);
}

示例:

> ls -l a b c
-rw-r--r-- 1 saka users 0 Feb  1 09:08 a
-rw-r--r-- 1 saka users 0 Feb  1 09:08 b
lrwxrwxrwx 1 saka users 1 Feb  1 09:08 c -> b
> ./ts a
> ./ts c
c: Operation not permitted

我在 3.10.0-862.14.4.el7.x86_64 上使用 xfs 或 ext3 进行了测试。

【问题讨论】:

    标签: c linux filesystems system-calls


    【解决方案1】:

    我猜是this:

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

    事实上,尝试在以lsetxattr(2) 为根的符号链接上设置trusted.foo 属性是可行的,而user.fooEPERM 失败。

    【讨论】:

      猜你喜欢
      • 2010-10-18
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 2023-01-29
      • 1970-01-01
      相关资源
      最近更新 更多